Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
b181cd35
Commit
b181cd35
authored
Jun 27, 2018
by
Marton Balint
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ffmpeg: factorize input thread creation and destruction
Signed-off-by:
Marton Balint
<
cus@passwd.hu
>
parent
9f0077cc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
26 deletions
+40
-26
ffmpeg.c
fftools/ffmpeg.c
+40
-26
No files found.
fftools/ffmpeg.c
View file @
b181cd35
...
...
@@ -4053,49 +4053,63 @@ static void *input_thread(void *arg)
return
NULL
;
}
static
void
free_input_thread
(
int
i
)
{
InputFile
*
f
=
input_files
[
i
];
AVPacket
pkt
;
if
(
!
f
||
!
f
->
in_thread_queue
)
return
;
av_thread_message_queue_set_err_send
(
f
->
in_thread_queue
,
AVERROR_EOF
);
while
(
av_thread_message_queue_recv
(
f
->
in_thread_queue
,
&
pkt
,
0
)
>=
0
)
av_packet_unref
(
&
pkt
);
pthread_join
(
f
->
thread
,
NULL
);
f
->
joined
=
1
;
av_thread_message_queue_free
(
&
f
->
in_thread_queue
);
}
static
void
free_input_threads
(
void
)
{
int
i
;
for
(
i
=
0
;
i
<
nb_input_files
;
i
++
)
{
InputFile
*
f
=
input_files
[
i
]
;
AVPacket
pkt
;
for
(
i
=
0
;
i
<
nb_input_files
;
i
++
)
free_input_thread
(
i
)
;
}
if
(
!
f
||
!
f
->
in_thread_queue
)
continue
;
av_thread_message_queue_set_err_send
(
f
->
in_thread_queue
,
AVERROR_EOF
);
while
(
av_thread_message_queue_recv
(
f
->
in_thread_queue
,
&
pkt
,
0
)
>=
0
)
av_packet_unref
(
&
pkt
);
static
int
init_input_thread
(
int
i
)
{
int
ret
;
InputFile
*
f
=
input_files
[
i
];
pthread_join
(
f
->
thread
,
NULL
);
f
->
joined
=
1
;
if
(
nb_input_files
==
1
)
return
0
;
if
(
f
->
ctx
->
pb
?
!
f
->
ctx
->
pb
->
seekable
:
strcmp
(
f
->
ctx
->
iformat
->
name
,
"lavfi"
))
f
->
non_blocking
=
1
;
ret
=
av_thread_message_queue_alloc
(
&
f
->
in_thread_queue
,
f
->
thread_queue_size
,
sizeof
(
AVPacket
));
if
(
ret
<
0
)
return
ret
;
if
((
ret
=
pthread_create
(
&
f
->
thread
,
NULL
,
input_thread
,
f
)))
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.
\n
"
,
strerror
(
ret
));
av_thread_message_queue_free
(
&
f
->
in_thread_queue
);
return
AVERROR
(
ret
);
}
return
0
;
}
static
int
init_input_threads
(
void
)
{
int
i
,
ret
;
if
(
nb_input_files
==
1
)
return
0
;
for
(
i
=
0
;
i
<
nb_input_files
;
i
++
)
{
InputFile
*
f
=
input_files
[
i
];
if
(
f
->
ctx
->
pb
?
!
f
->
ctx
->
pb
->
seekable
:
strcmp
(
f
->
ctx
->
iformat
->
name
,
"lavfi"
))
f
->
non_blocking
=
1
;
ret
=
av_thread_message_queue_alloc
(
&
f
->
in_thread_queue
,
f
->
thread_queue_size
,
sizeof
(
AVPacket
));
ret
=
init_input_thread
(
i
);
if
(
ret
<
0
)
return
ret
;
if
((
ret
=
pthread_create
(
&
f
->
thread
,
NULL
,
input_thread
,
f
)))
{
av_log
(
NULL
,
AV_LOG_ERROR
,
"pthread_create failed: %s. Try to increase `ulimit -v` or decrease `ulimit -s`.
\n
"
,
strerror
(
ret
));
av_thread_message_queue_free
(
&
f
->
in_thread_queue
);
return
AVERROR
(
ret
);
}
}
return
0
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment