Commit Graph

96 Commits

Author SHA1 Message Date
Anton Khirnov
cc14ee03a7 lavc: split slice and frame threading functions into separate files 2013-11-04 08:51:26 +01:00
Anton Khirnov
5cd6513f5b pthread: drop avcodec_ prefixes from static functions 2013-11-04 08:51:26 +01:00
Anton Khirnov
a1504eee41 lavc: deprecate AVCodecContext.debug_mv
It has been unused since 37045e4229.
2013-10-31 20:22:51 +01:00
Ben Jackson
5152196b2b pthread: Avoid spurious wakeups
pthread_wait_cond can wake up unexpectedly (Wikipedia: Spurious_wakeup).

The FF_THREAD_SLICE thread mechanism could spontaneously execute
jobs or allow the caller of avctx->execute to return before all
jobs were complete.

Test both cases to ensure the wakeup is real.

Signed-off-by: Ben Jackson <ben@ben.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2013-10-21 15:28:03 +02:00
Derek Buitenhuis
eb90a2091f pthread: Fix deadlock during thread initialization
Sometimes, if pthread_create() failed, then pthread_cond_wait() could
accidentally be called in the worker threads after the uninit function
had already called pthread_cond_broadcast(), leading to a deadlock.

Don't call pthread_cond_wait() if c->done is set.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2013-10-13 05:50:00 -04:00
Diego Biurrun
7950e519bb Disable deprecation warnings for cases where a replacement is available 2013-08-02 19:19:02 +02:00
Sean McGovern
50612484e0 pthread: Rename thread_init to avoid symbol collision
The AIX threads library exposes a function with the same name.

Signed-off-by: Martin Storsjö <martin@martin.st>
2013-07-17 00:13:31 +03:00
Anton Khirnov
2a6eaeaa85 Move get_logical_cpus() from lavc/pthread to lavu/cpu.
It will be useful in lavfi, and could conceivably be useful to the user
applications as well.
2013-05-24 09:28:00 +02:00
Anton Khirnov
90f9a5830b w32pthreads: move from lavc to compat/
It will be used in other places than lavc.
2013-05-24 09:26:54 +02:00
Anton Khirnov
db8e336e5f pthread: reindent 2013-05-17 07:44:50 +02:00
Anton Khirnov
30e256430e lavc/pthread: remove obsolete checks
Those were useful when avcodec_thread_init() was a public functions. It
was deprecated and removed some time ago, so those checks are not needed
anymore.
2013-05-17 07:44:40 +02:00
Janne Grunau
94660c3524 threads: always call thread_finish_setup for intra codecs
Intra codecs do not need an update_thread_context() function and never
call ff_thread_finish_setup(). They rely on ff_thread_get_buffer()
calling it. So call it even if the get_buffer2 function pointer is
avcodec_default_get_buffer2 and it has not been called before.
2013-04-22 17:11:20 +02:00
Janne Grunau
05fa79b844 hwaccel: fix use with frame based multithreading
Allows use of AVHWAccel based decoders with frame based multithreading.
The decoders will be forced into an non-concurrent mode by delaying
ff_thread_finish_setup() calls after decoding of the current frame
is finished.

This wastes memory by unnecessarily using multiple threads and thus
copies of the decoder context but allows seamless switching between
hardware accelerated and frame threaded software decoding when the
hardware decoder does not support the stream.
2013-03-26 19:44:50 +01:00
Hendrik Leppkes
c71c80f53b pthread: unref already decoded frames when flushing the decoder
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2013-03-19 11:19:08 +01:00
Anton Khirnov
fce68c9355 pthread: unref the decoded but not returned frames on close.
Fixes memleaks when frame mt is used and the decoder is not flushed at
the end.
2013-03-11 18:30:35 +01:00
Anton Khirnov
759001c534 lavc decoders: work with refcounted frames. 2013-03-08 07:38:30 +01:00
Anton Khirnov
1a5e913016 pthread: avoid copying input packets when possible. 2013-03-08 07:35:14 +01:00
Anton Khirnov
e6b1c3bbe7 pthread: make ff_thread_release_buffer idempotent.
I.e. don't do anything on already released frames.
2013-01-29 07:32:10 +01:00
Anton Khirnov
594d4d5df3 lavc: add a wrapper for AVCodecContext.get_buffer().
It will be useful in the upcoming transition to refcounted AVFrames.
2012-12-04 21:41:59 +01:00
Anton Khirnov
7a1a9dd56c pthread: make sure AVFrame.extended_data is set properly.
Signed-off-by: Luca Barbato <lu_zero@gentoo.org>
2012-09-25 12:03:23 +02:00
Mans Rullgard
11434c9b13 pthread: add const to AVCodec pointers
Signed-off-by: Mans Rullgard <mans@mansr.com>
2012-08-18 14:20:57 +01:00
Martin Storsjö
1d9c2dc89a Don't include common.h from avutil.h
Signed-off-by: Martin Storsjö <martin@martin.st>
2012-08-15 22:32:06 +03:00
Diego Biurrun
d246c18ea6 Avoid C99 variable declarations within for statements.
We generally do not declare variables within for statements and
there are compilers that choke on such constructs.
2012-06-14 23:36:04 +02:00
Sean McGovern
b68c4ac293 pthread: warn on high thread counts
Signed-off-by: Diego Biurrun <diego@biurrun.de>
2012-05-07 10:35:01 +02:00
Mans Rullgard
95510be8c3 avcodec: remove AVCodecContext.dsp_mask
This removes all references to AVCodecContext.dsp_mask and marks
it for eviction at the next version bump.  It has been superseded
by av_set_cpu_flag_mask() which, unlike this field, works everywhere.

Signed-off-by: Mans Rullgard <mans@mansr.com>
2012-04-21 18:30:01 +01:00
Dale Curtis
97ae370078 pthread: Fix crash due to fctx->delaying not being cleared.
Reproducible with test case and ffplay -threads 2. Stack trace:
http://pastebin.com/PexZ4Uc0

Test case:
http://commondatastorage.googleapis.com/dalecurtis-shared/crash.ogm

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2012-04-12 21:32:01 -07:00
Alexander Strange
147ee4cf06 pthread: Immediately release all frames in ff_thread_flush()
Before this, they were only added to the delayed release queue and not
freed until later. This could lead to unnecessary memory use or buffer
exhaustion.

Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2012-03-24 15:29:51 -07:00
Ronald S. Bultje
2ee01fbded pthread: free progress if buffer allocation failed.
Else we run out of progress variables after a few failed buffer
allocations.

Signed-off-by: Anton Khirnov <anton@khirnov.net>
2012-03-24 21:29:35 +01:00
Ronald S. Bultje
bc1ef85520 lavc/avconv: support changing frame sizes in codecs with frame mt.
Signed-off-by: Anton Khirnov <anton@khirnov.net>
2012-03-24 21:29:16 +01:00
Uoti Urpala
05b9a89ed7 threads: fix old frames returned after avcodec_flush_buffers()
Calling avcodec_flush_buffers() and then avcodec_decode_video2() with
a 0-sized packet (to get remaining buffered frames) could incorrectly
return an old frame from before the avcodec_flush_buffers() call. Add
a loop in ff_thread_flush() to zero the got_frame field of each thread
to ensure the old frames will not be returned.

Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
2012-03-16 15:38:18 -07:00
Anton Khirnov
02beb9826b lavc: deprecate AVCodecContext.sub_id.
In most places where it's used, it's as a pointless write-only field.

Only rv10 decoder actually reads from it, but it stores some internal
version info in it. There is no reason for it to be in a public field.
2012-03-04 21:02:45 +01:00
Anton Khirnov
b1edfce08a lavc: reorder AVCodecContext fields.
Put related fields together, move the important ones closer to the
beginning, try to eliminate holes.
2012-02-27 07:09:43 +01:00
Janne Grunau
afb8b207d6 threads: update slice_count and slice_offset from user context
They are used to signal the number of slices and offsets of each slice
out of band to the decoder.
2012-01-21 13:26:44 +01:00
Diego Biurrun
3dc99a18d4 cosmetics: drop some pointless parentheses 2012-01-07 22:13:07 +01:00
Daniel Verkamp
02e8f4272c win32: detect number of CPUs using affinity
Signed-off-by: Janne Grunau <janne-libav@jannau.net>
2012-01-03 14:25:57 +01:00
Janne Grunau
b12d217339 threads: limit the number of automatic threads to MAX_AUTO_THREADS
The extra thread added in {frame_}*thread_init was not taken into
account. Explicitly sets thread_count to 1 if only one CPU core was
detected. Also fixes two typos in comments.
2012-01-01 21:11:43 +01:00
Janne Grunau
b4d44a45f9 threads: introduce CODEC_CAP_AUTO_THREADS and add it to libx264
Some external codecs have their own code to determine the best number
of threads. This number is not necessary the number of cpu cores.
Thread_count will be only 0 if the codec has CODEC_CAP_AUTO_THREADS.
2012-01-01 14:37:37 +01:00
Janne Grunau
bcc7396065 threads: add sysconf based number of CPUs detection
Can act as fallback and should work on a couple of Unix systems.
2011-12-31 17:40:12 +01:00
Janne Grunau
937ff3a18a threads: always include necessary headers for number of CPUs detection
Since the conditions for the actual usage are more specific a less
preferred method can be used. This would cause compilation errors
because necessary headers are not included.
2011-12-31 17:40:12 +01:00
Janne Grunau
06bb590558 threads: test for sys/param.h and include it for sysctl on OpenBSD 2011-12-27 16:09:41 +01:00
Stefano Sabatini
8a4a5f6ff7 lavc: add format field to AVFrame
The format is a per-frame property, having it in AVFrame simplify the
operation of extraction of that information, since avoids the need to
access the codec/stream context.
2011-12-25 16:18:57 +01:00
Stefano Sabatini
3a2ddf7c2c lavc: add width and height fields to AVFrame
width and height are per-frame properties, setting these values in
AVFrame simplify the operation of extraction of that information,
since avoids the need to check the codec/stream context.
2011-12-25 16:18:57 +01:00
Stefano Sabatini
b58dbb5b03 lavc: add a sample_aspect_ratio field to AVFrame
The sample aspect ratio is a per-frame property, so it makes sense to
define it in AVFrame rather than in the codec/stream context.
Simplify application-level sample aspect ratio information extraction,
and allow further simplifications.
2011-12-25 16:18:57 +01:00
Janne Grunau
7052618c7e threads: check defines before using them in automatic thread detection 2011-12-23 14:41:03 +01:00
Janne Grunau
846dca1aa3 pthread: include sys/types.h before sys/sysctl.h
Fixes compilation on FreeBSD with clang 3.
2011-12-23 14:40:39 +01:00
Janne Grunau
b9e2226972 bsd: use number of logical CPUs as automatic thread count 2011-12-22 21:50:07 +01:00
Janne Grunau
ad29ecbff0 windows: use number of CPUs as automatic thread count 2011-12-22 21:50:07 +01:00
Janne Grunau
ea4d5f4837 linux: use number of CPUs as automatic thread count
Use sched_getaffinity to determine the number of logical CPUs.
Limits the number of threads to 16 since slice threading of H.264
seems to be buggy with more than 16 threads.
2011-12-22 21:50:07 +01:00
Janne Grunau
f77f640b30 pthreads: reset active_thread_type when slice thread_init returrns early 2011-12-22 21:50:07 +01:00
Mans Rullgard
8400b126ac avcodec: deprecate AVFrame.age
This was intended as an optimisation for skipped blocks in MPEG2
P-frames and never used elsewhere.  Removing this "optimisation"
speeds up MPEG2 decoding by 1-2% (ARM Cortex-A9).

Signed-off-by: Mans Rullgard <mans@mansr.com>
2011-12-18 22:14:33 +00:00