diff options
author | fbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-19 21:06:27 +0000 |
---|---|---|
committer | fbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-19 21:06:27 +0000 |
commit | 5ca641d40b260bf10e18cbde7a16c0ec662de95a (patch) | |
tree | 986e6c5034f32cf71ddeb91affad1961f6748b7c /media | |
parent | 26571791f60a08657ba061d062ac60cf6fc7bc16 (diff) | |
download | chromium_src-5ca641d40b260bf10e18cbde7a16c0ec662de95a.zip chromium_src-5ca641d40b260bf10e18cbde7a16c0ec662de95a.tar.gz chromium_src-5ca641d40b260bf10e18cbde7a16c0ec662de95a.tar.bz2 |
Change default to three threads for video decoding and add command line --video-threads.
BUG=44128
TEST=player_wtl.exe --video-threads=6 d:\mediatests\crowd\crowd2.mp4
Review URL: http://codereview.chromium.org/2080008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47723 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/base/media_switches.cc | 7 | ||||
-rw-r--r-- | media/base/media_switches.h | 10 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decode_engine.cc | 24 | ||||
-rw-r--r-- | media/filters/ffmpeg_video_decode_engine_unittest.cc | 6 | ||||
-rw-r--r-- | media/test/ffmpeg_tests/ffmpeg_tests.cc | 2 |
5 files changed, 34 insertions, 15 deletions
diff --git a/media/base/media_switches.cc b/media/base/media_switches.cc index 7fa286e..3b684ce 100644 --- a/media/base/media_switches.cc +++ b/media/base/media_switches.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,6 +11,11 @@ namespace switches { const char kAlsaDevice[] = "alsa-device"; #endif +// Enable hardware decoding using OpenMax API. +// In practice this is for ChromeOS ARM. const char kEnableOpenMax[] = "enable-openmax"; +// Set number of threads to use for video decoding. +const char kVideoThreads[] = "video-threads"; + } // namespace switches diff --git a/media/base/media_switches.h b/media/base/media_switches.h index 28e3bb6..6e0e0d3 100644 --- a/media/base/media_switches.h +++ b/media/base/media_switches.h @@ -1,11 +1,11 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // Defines all the "media" command-line switches. -#ifndef MEDIA_BASE_SWITCHES_H_ -#define MEDIA_BASE_SWITCHES_H_ +#ifndef MEDIA_BASE_MEDIA_SWITCHES_H_ +#define MEDIA_BASE_MEDIA_SWITCHES_H_ #include "build/build_config.h" @@ -16,7 +16,9 @@ extern const char kAlsaDevice[]; #endif extern const char kEnableOpenMax[]; +extern const char kVideoThreads[]; + } // namespace switches -#endif // MEDIA_BASE_SWITCHES_H_ +#endif // MEDIA_BASE_MEDIA_SWITCHES_H_ diff --git a/media/filters/ffmpeg_video_decode_engine.cc b/media/filters/ffmpeg_video_decode_engine.cc index bf6089a..3313c27 100644 --- a/media/filters/ffmpeg_video_decode_engine.cc +++ b/media/filters/ffmpeg_video_decode_engine.cc @@ -4,10 +4,12 @@ #include "media/filters/ffmpeg_video_decode_engine.h" +#include "base/command_line.h" #include "base/task.h" #include "media/base/buffers.h" #include "media/base/callback.h" #include "media/base/limits.h" +#include "media/base/media_switches.h" #include "media/ffmpeg/ffmpeg_common.h" #include "media/ffmpeg/ffmpeg_util.h" #include "media/filters/ffmpeg_demuxer.h" @@ -24,8 +26,9 @@ FFmpegVideoDecodeEngine::~FFmpegVideoDecodeEngine() { void FFmpegVideoDecodeEngine::Initialize(AVStream* stream, Task* done_cb) { AutoTaskRunner done_runner(done_cb); + CHECK(state_ == kCreated); - // Always try to use two threads for video decoding. There is little reason + // Always try to use three 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. // @@ -33,10 +36,10 @@ void FFmpegVideoDecodeEngine::Initialize(AVStream* stream, Task* done_cb) { // 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 :) - static const int kDecodeThreads = 2; + // Yet another reason for having three threads :) + static const int kDecodeThreads = 3; + static const int kMaxDecodeThreads = 16; - CHECK(state_ == kCreated); codec_context_ = stream->codec; codec_context_->flags2 |= CODEC_FLAG2_FAST; // Enable faster H264 decode. @@ -47,10 +50,18 @@ void FFmpegVideoDecodeEngine::Initialize(AVStream* stream, Task* done_cb) { AVCodec* codec = avcodec_find_decoder(codec_context_->codec_id); - // TODO(fbarchard): On next ffmpeg roll, retest Theora multi-threading. + // TODO(fbarchard): Improve thread logic based on size / codec. int decode_threads = (codec_context_->codec_id == CODEC_ID_THEORA) ? 1 : kDecodeThreads; + const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); + std::string threads(cmd_line->GetSwitchValueASCII(switches::kVideoThreads)); + if ((!threads.empty() && + !StringToInt(threads, &decode_threads)) || + decode_threads < 0 || decode_threads > kMaxDecodeThreads) { + decode_threads = kDecodeThreads; + } + // We don't allocate AVFrame on the stack since different versions of FFmpeg // may change the size of AVFrame, causing stack corruption. The solution is // to let FFmpeg allocate the structure via avcodec_alloc_frame(). @@ -66,10 +77,11 @@ void FFmpegVideoDecodeEngine::Initialize(AVStream* stream, Task* done_cb) { } } +// TODO(fbarchard): Find way to remove this memcpy of the entire image. static void CopyPlane(size_t plane, scoped_refptr<VideoFrame> video_frame, const AVFrame* frame) { - DCHECK(video_frame->width() % 2 == 0); + DCHECK_EQ(video_frame->width() % 2, 0u); const uint8* source = frame->data[plane]; const size_t source_stride = frame->linesize[plane]; uint8* dest = video_frame->data(plane); diff --git a/media/filters/ffmpeg_video_decode_engine_unittest.cc b/media/filters/ffmpeg_video_decode_engine_unittest.cc index f1d1680..4d16a7e 100644 --- a/media/filters/ffmpeg_video_decode_engine_unittest.cc +++ b/media/filters/ffmpeg_video_decode_engine_unittest.cc @@ -65,7 +65,7 @@ class FFmpegVideoDecodeEngineTest : public testing::Test { .WillOnce(Return(&codec_)); EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) .WillOnce(Return(&yuv_frame_)); - EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) + EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 3)) .WillOnce(Return(0)); EXPECT_CALL(*MockFFmpeg::get(), AVCodecOpen(&codec_context_, &codec_)) .WillOnce(Return(0)); @@ -121,7 +121,7 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_InitThreadFails) { .WillOnce(Return(&codec_)); EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) .WillOnce(Return(&yuv_frame_)); - EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) + EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 3)) .WillOnce(Return(-1)); EXPECT_CALL(*MockFFmpeg::get(), AVFree(&yuv_frame_)) .Times(1); @@ -139,7 +139,7 @@ TEST_F(FFmpegVideoDecodeEngineTest, Initialize_OpenDecoderFails) { .WillOnce(Return(&codec_)); EXPECT_CALL(*MockFFmpeg::get(), AVCodecAllocFrame()) .WillOnce(Return(&yuv_frame_)); - EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 2)) + EXPECT_CALL(*MockFFmpeg::get(), AVCodecThreadInit(&codec_context_, 3)) .WillOnce(Return(0)); EXPECT_CALL(*MockFFmpeg::get(), AVCodecOpen(&codec_context_, &codec_)) .WillOnce(Return(-1)); diff --git a/media/test/ffmpeg_tests/ffmpeg_tests.cc b/media/test/ffmpeg_tests/ffmpeg_tests.cc index abfbeff..73dd46d 100644 --- a/media/test/ffmpeg_tests/ffmpeg_tests.cc +++ b/media/test/ffmpeg_tests/ffmpeg_tests.cc @@ -87,7 +87,7 @@ int main(int argc, const char** argv) { } // Default flags that match Chrome defaults. - int video_threads = 2; + int video_threads = 3; int verbose_level = AV_LOG_FATAL; int max_frames = 0; int max_loops = 0; |