summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-14 17:36:03 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-14 17:36:03 +0000
commitc486315a4356883fb1d4a968e21c6f1135e8d696 (patch)
tree4298c313134f5d76616170234329478c71824e6c
parent8e090d8fc1957f191a88fcc6d0593f4d7f06d634 (diff)
downloadchromium_src-c486315a4356883fb1d4a968e21c6f1135e8d696.zip
chromium_src-c486315a4356883fb1d4a968e21c6f1135e8d696.tar.gz
chromium_src-c486315a4356883fb1d4a968e21c6f1135e8d696.tar.bz2
Enabled mulithreaded video decoding.
For simplicity we're going with two threads regardless of CPU architecture. We measured performance gains even on P4s and if you have a multi-core machine you're golden. Review URL: http://codereview.chromium.org/113386 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16068 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--media/filters/ffmpeg_video_decoder.cc18
1 files changed, 17 insertions, 1 deletions
diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc
index d65a692..89d44df 100644
--- a/media/filters/ffmpeg_video_decoder.cc
+++ b/media/filters/ffmpeg_video_decoder.cc
@@ -9,6 +9,20 @@
namespace media {
+// Always try to use two threads for video decoding. There is little reason
+// not to since current day CPUs tend to be multi-core and we measured
+// performance benefits on older machines such as P4s with hyperthreading.
+//
+// Handling decoding on separate threads also frees up the pipeline thread to
+// continue processing. Although it'd be nice to have the option of a single
+// decoding thread, FFmpeg treats having one thread the same as having zero
+// threads (i.e., avcodec_decode_video() will execute on the calling thread).
+// Yet another reason for having two threads :)
+//
+// TODO(scherkus): some video codecs might not like avcodec_thread_init() being
+// called on them... should attempt to find out which ones those are!
+static const int kDecodeThreads = 2;
+
FFmpegVideoDecoder::FFmpegVideoDecoder()
: DecoderBase<VideoDecoder, VideoFrame>(NULL),
width_(0),
@@ -44,7 +58,9 @@ bool FFmpegVideoDecoder::OnInitialize(DemuxerStream* demuxer_stream) {
codec_context_ = ffmpeg_demuxer_stream->av_stream()->codec;
codec_context_->flags2 |= CODEC_FLAG2_FAST; // Enable faster H264 decode.
AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id);
- if (!codec || avcodec_open(codec_context_, codec) < 0) {
+ if (!codec ||
+ avcodec_thread_init(codec_context_, kDecodeThreads) < 0 ||
+ avcodec_open(codec_context_, codec) < 0) {
host_->Error(media::PIPELINE_ERROR_DECODE);
return false;
}