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

Side by Side Diff: media/filters/ffmpeg_video_decoder.cc

Issue 2467623002: media: Only add more threads for codecs that benefit from it (Closed)
Patch Set: comments addressed Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/filters/ffmpeg_video_decoder.h" 5 #include "media/filters/ffmpeg_video_decoder.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 // Returns the number of threads given the FFmpeg CodecID. Also inspects the 44 // Returns the number of threads given the FFmpeg CodecID. Also inspects the
45 // command line for a valid --video-threads flag. 45 // command line for a valid --video-threads flag.
46 static int GetThreadCount(const VideoDecoderConfig& config) { 46 static int GetThreadCount(const VideoDecoderConfig& config) {
47 // Refer to http://crbug.com/93932 for tsan suppressions on decoding. 47 // Refer to http://crbug.com/93932 for tsan suppressions on decoding.
48 int decode_threads = kDecodeThreads; 48 int decode_threads = kDecodeThreads;
49 49
50 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); 50 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess();
51 std::string threads(cmd_line->GetSwitchValueASCII(switches::kVideoThreads)); 51 std::string threads(cmd_line->GetSwitchValueASCII(switches::kVideoThreads));
52 if (threads.empty() || !base::StringToInt(threads, &decode_threads)) { 52 if (threads.empty() || !base::StringToInt(threads, &decode_threads)) {
53 // Normalize to three threads for 1080p content, then scale linearly 53 // Some ffmpeg codecs don't actually benefit from using more threads.
54 // with number of pixels. 54 // Only add more threads for those codecs that we know will benefit.
55 // Examples: 55 switch (config.codec()) {
56 // 4k: 12 threads 56 case kUnknownVideoCodec:
57 // 1440p: 5 threads 57 case kCodecVC1:
58 // 1080p: 3 threads 58 case kCodecMPEG2:
59 // anything lower than 1080p: 2 threads 59 case kCodecHEVC:
60 decode_threads = config.coded_size().width() * 60 case kCodecVP9:
61 config.coded_size().height() * 3 / 1920 / 1080; 61 NOTREACHED();
DaleCurtis 2016/10/31 22:26:49 Actually, sorry we should drop the NOTREACHED(). I
hubbe 2016/10/31 22:36:35 Done.
62 break;
62 63
63 int cores = base::SysInfo::NumberOfProcessors(); 64 case kCodecTheora:
64 // Leave two execution contexts for other things to run. 65 // No extra threads for these codecs.
65 decode_threads = std::min(decode_threads, cores - 2); 66 break;
66 // Use at least two threads, or ffmpeg will decode on the calling thread. 67
67 decode_threads = std::max(decode_threads, kDecodeThreads); 68 case kCodecH264:
69 case kCodecMPEG4:
70 case kCodecVP8:
71 // Normalize to three threads for 1080p content, then scale linearly
72 // with number of pixels.
73 // Examples:
74 // 4k: 12 threads
75 // 1440p: 5 threads
76 // 1080p: 3 threads
77 // anything lower than 1080p: 2 threads
78 decode_threads = config.coded_size().width() *
79 config.coded_size().height() * 3 / 1920 / 1080;
80
81 int cores = base::SysInfo::NumberOfProcessors();
82 // Leave two execution contexts for other things to run.
83 decode_threads = std::min(decode_threads, cores - 2);
84 // Use at least two threads, or ffmpeg will decode on the calling
85 // thread.
86 decode_threads = std::max(decode_threads, kDecodeThreads);
87 }
68 } 88 }
69 89
70 decode_threads = std::max(decode_threads, 0); 90 decode_threads = std::max(decode_threads, 0);
71 decode_threads = std::min(decode_threads, kMaxDecodeThreads); 91 decode_threads = std::min(decode_threads, kMaxDecodeThreads);
72 return decode_threads; 92 return decode_threads;
73 } 93 }
74 94
75 static int GetVideoBufferImpl(struct AVCodecContext* s, 95 static int GetVideoBufferImpl(struct AVCodecContext* s,
76 AVFrame* frame, 96 AVFrame* frame,
77 int flags) { 97 int flags) {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) { 426 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) {
407 ReleaseFFmpegResources(); 427 ReleaseFFmpegResources();
408 return false; 428 return false;
409 } 429 }
410 430
411 av_frame_.reset(av_frame_alloc()); 431 av_frame_.reset(av_frame_alloc());
412 return true; 432 return true;
413 } 433 }
414 434
415 } // namespace media 435 } // namespace media
OLDNEW
« 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