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

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: use switch statement, add vp8/9 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 kCodecTheora:
59 // anything lower than 1080p: 2 threads 59 // No extra threads for these codecs.
60 decode_threads = config.coded_size().width() * 60 break;
61 config.coded_size().height() * 3 / 1920 / 1080;
62 61
63 int cores = base::SysInfo::NumberOfProcessors(); 62 case kCodecH264:
64 // Leave two execution contexts for other things to run. 63 case kCodecMPEG2:
65 decode_threads = std::min(decode_threads, cores - 2); 64 case kCodecMPEG4:
66 // Use at least two threads, or ffmpeg will decode on the calling thread. 65 case kCodecVP8:
67 decode_threads = std::max(decode_threads, kDecodeThreads); 66 case kCodecVP9:
67 case kCodecHEVC:
DaleCurtis 2016/10/31 22:07:57 Unknown, VC1, MPEG2, and HEVC should all be NOTREA
hubbe 2016/10/31 22:18:38 Done.
68 // Normalize to three threads for 1080p content, then scale linearly
69 // with number of pixels.
70 // Examples:
71 // 4k: 12 threads
72 // 1440p: 5 threads
73 // 1080p: 3 threads
74 // anything lower than 1080p: 2 threads
75 decode_threads = config.coded_size().width() *
76 config.coded_size().height() * 3 / 1920 / 1080;
77
78 int cores = base::SysInfo::NumberOfProcessors();
79 // Leave two execution contexts for other things to run.
80 decode_threads = std::min(decode_threads, cores - 2);
81 // Use at least two threads, or ffmpeg will decode on the calling
82 // thread.
83 decode_threads = std::max(decode_threads, kDecodeThreads);
84 }
68 } 85 }
69 86
70 decode_threads = std::max(decode_threads, 0); 87 decode_threads = std::max(decode_threads, 0);
71 decode_threads = std::min(decode_threads, kMaxDecodeThreads); 88 decode_threads = std::min(decode_threads, kMaxDecodeThreads);
72 return decode_threads; 89 return decode_threads;
73 } 90 }
74 91
75 static int GetVideoBufferImpl(struct AVCodecContext* s, 92 static int GetVideoBufferImpl(struct AVCodecContext* s,
76 AVFrame* frame, 93 AVFrame* frame,
77 int flags) { 94 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) { 423 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) {
407 ReleaseFFmpegResources(); 424 ReleaseFFmpegResources();
408 return false; 425 return false;
409 } 426 }
410 427
411 av_frame_.reset(av_frame_alloc()); 428 av_frame_.reset(av_frame_alloc());
412 return true; 429 return true;
413 } 430 }
414 431
415 } // namespace media 432 } // 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