Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1389)

Unified Diff: media/filters/ffmpeg_video_decoder.cc

Issue 2448453004: scale video threads with resolution (Closed)
Patch Set: comment update Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/ffmpeg_video_decoder.cc
diff --git a/media/filters/ffmpeg_video_decoder.cc b/media/filters/ffmpeg_video_decoder.cc
index a80c3654459f5345fba5d6f954a71c2f168b8a6d..16088ab8c66ffa0deab2dc1132fb455c96c34c67 100644
--- a/media/filters/ffmpeg_video_decoder.cc
+++ b/media/filters/ffmpeg_video_decoder.cc
@@ -16,6 +16,7 @@
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
+#include "base/sys_info.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/decoder_buffer.h"
#include "media/base/limits.h"
@@ -42,14 +43,22 @@ static const int kMaxDecodeThreads = 16;
// Returns the number of threads given the FFmpeg CodecID. Also inspects the
// command line for a valid --video-threads flag.
-static int GetThreadCount(AVCodecID codec_id) {
+static int GetThreadCount(const VideoDecoderConfig& config) {
// Refer to http://crbug.com/93932 for tsan suppressions on decoding.
int decode_threads = kDecodeThreads;
const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
std::string threads(cmd_line->GetSwitchValueASCII(switches::kVideoThreads));
- if (threads.empty() || !base::StringToInt(threads, &decode_threads))
- return decode_threads;
+ if (threads.empty() || !base::StringToInt(threads, &decode_threads)) {
+ decode_threads = config.coded_size().width() *
DaleCurtis 2016/10/27 18:11:34 Logic needs a description and some example values.
hubbe 2016/10/27 20:36:47 Done.
+ config.coded_size().height() * 3 / 1920 / 1080;
+
+ int cores = base::SysInfo::NumberOfProcessors();
+ // Leave two threads for other things to run.
+ decode_threads = std::min(decode_threads, cores - 2);
+ // Use at least two threads, or ffmpeg will decode on the calling thread.
+ decode_threads = std::max(decode_threads, kDecodeThreads);
+ }
decode_threads = std::max(decode_threads, 0);
decode_threads = std::min(decode_threads, kMaxDecodeThreads);
@@ -375,8 +384,9 @@ bool FFmpegVideoDecoder::ConfigureDecoder(bool low_delay) {
codec_context_.reset(avcodec_alloc_context3(NULL));
VideoDecoderConfigToAVCodecContext(config_, codec_context_.get());
- codec_context_->thread_count = GetThreadCount(codec_context_->codec_id);
- codec_context_->thread_type = low_delay ? FF_THREAD_SLICE : FF_THREAD_FRAME;
+ codec_context_->thread_count = GetThreadCount(config_);
+ codec_context_->thread_type =
+ FF_THREAD_SLICE | (low_delay ? 0 : FF_THREAD_FRAME);
codec_context_->opaque = this;
codec_context_->flags |= CODEC_FLAG_EMU_EDGE;
codec_context_->get_buffer2 = GetVideoBufferImpl;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698