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

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: 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.
DaleCurtis 2016/10/31 21:26:33 vp8 should benefit? I'd just exclude THEORA?
hubbe 2016/10/31 22:01:49 Replaced the if statement with a switch to remind
54 // with number of pixels. 54 // Only add more threads for those codecs that we know will benefit.
55 // Examples: 55 if (config.codec() == kCodecH264 || config.codec() == kCodecMPEG4 ||
56 // 4k: 12 threads 56 config.codec() == kCodecHEVC || config.codec() == kCodecMPEG2) {
57 // 1440p: 5 threads 57 // Normalize to three threads for 1080p content, then scale linearly
58 // 1080p: 3 threads 58 // with number of pixels.
59 // anything lower than 1080p: 2 threads 59 // Examples:
60 decode_threads = config.coded_size().width() * 60 // 4k: 12 threads
61 config.coded_size().height() * 3 / 1920 / 1080; 61 // 1440p: 5 threads
62 // 1080p: 3 threads
63 // anything lower than 1080p: 2 threads
64 decode_threads = config.coded_size().width() *
65 config.coded_size().height() * 3 / 1920 / 1080;
62 66
63 int cores = base::SysInfo::NumberOfProcessors(); 67 int cores = base::SysInfo::NumberOfProcessors();
64 // Leave two execution contexts for other things to run. 68 // Leave two execution contexts for other things to run.
65 decode_threads = std::min(decode_threads, cores - 2); 69 decode_threads = std::min(decode_threads, cores - 2);
66 // Use at least two threads, or ffmpeg will decode on the calling thread. 70 // Use at least two threads, or ffmpeg will decode on the calling thread.
67 decode_threads = std::max(decode_threads, kDecodeThreads); 71 decode_threads = std::max(decode_threads, kDecodeThreads);
72 }
68 } 73 }
69 74
70 decode_threads = std::max(decode_threads, 0); 75 decode_threads = std::max(decode_threads, 0);
71 decode_threads = std::min(decode_threads, kMaxDecodeThreads); 76 decode_threads = std::min(decode_threads, kMaxDecodeThreads);
72 return decode_threads; 77 return decode_threads;
73 } 78 }
74 79
75 static int GetVideoBufferImpl(struct AVCodecContext* s, 80 static int GetVideoBufferImpl(struct AVCodecContext* s,
76 AVFrame* frame, 81 AVFrame* frame,
77 int flags) { 82 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) { 411 if (!codec || avcodec_open2(codec_context_.get(), codec, NULL) < 0) {
407 ReleaseFFmpegResources(); 412 ReleaseFFmpegResources();
408 return false; 413 return false;
409 } 414 }
410 415
411 av_frame_.reset(av_frame_alloc()); 416 av_frame_.reset(av_frame_alloc());
412 return true; 417 return true;
413 } 418 }
414 419
415 } // namespace media 420 } // 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