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

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

Issue 9632024: Create video and audio decoder threads on demand. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Log an error when Initialize is called more than once. Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); 44 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
45 std::string threads(cmd_line->GetSwitchValueASCII(switches::kVideoThreads)); 45 std::string threads(cmd_line->GetSwitchValueASCII(switches::kVideoThreads));
46 if (threads.empty() || !base::StringToInt(threads, &decode_threads)) 46 if (threads.empty() || !base::StringToInt(threads, &decode_threads))
47 return decode_threads; 47 return decode_threads;
48 48
49 decode_threads = std::max(decode_threads, 0); 49 decode_threads = std::max(decode_threads, 0);
50 decode_threads = std::min(decode_threads, kMaxDecodeThreads); 50 decode_threads = std::min(decode_threads, kMaxDecodeThreads);
51 return decode_threads; 51 return decode_threads;
52 } 52 }
53 53
54 FFmpegVideoDecoder::FFmpegVideoDecoder(MessageLoop* message_loop) 54 FFmpegVideoDecoder::FFmpegVideoDecoder(
55 : message_loop_(message_loop), 55 const base::Callback<MessageLoop*()>& message_loop_cb)
56 : message_loop_factory_cb_(message_loop_cb),
57 message_loop_(NULL),
56 state_(kUninitialized), 58 state_(kUninitialized),
57 codec_context_(NULL), 59 codec_context_(NULL),
58 av_frame_(NULL), 60 av_frame_(NULL),
59 frame_rate_numerator_(0), 61 frame_rate_numerator_(0),
60 frame_rate_denominator_(0) { 62 frame_rate_denominator_(0) {
61 } 63 }
62 64
63 FFmpegVideoDecoder::~FFmpegVideoDecoder() { 65 FFmpegVideoDecoder::~FFmpegVideoDecoder() {
64 ReleaseFFmpegResources(); 66 ReleaseFFmpegResources();
65 } 67 }
66 68
67 void FFmpegVideoDecoder::Initialize(DemuxerStream* demuxer_stream, 69 void FFmpegVideoDecoder::Initialize(DemuxerStream* demuxer_stream,
68 const PipelineStatusCB& pipeline_status_cb, 70 const PipelineStatusCB& pipeline_status_cb,
69 const StatisticsCB& statistics_cb) { 71 const StatisticsCB& statistics_cb) {
72 if (!message_loop_) {
73 message_loop_ = message_loop_factory_cb_.Run();
74 message_loop_factory_cb_.Reset();
75 } else {
76 // TODO(scherkus): initialization currently happens more than once in
77 // PipelineIntegrationTest.BasicPlayback.
78 LOG(ERROR) << "Initialize has already been called.";
79 }
80
70 if (MessageLoop::current() != message_loop_) { 81 if (MessageLoop::current() != message_loop_) {
71 message_loop_->PostTask(FROM_HERE, base::Bind( 82 message_loop_->PostTask(FROM_HERE, base::Bind(
72 &FFmpegVideoDecoder::Initialize, this, 83 &FFmpegVideoDecoder::Initialize, this,
73 make_scoped_refptr(demuxer_stream), pipeline_status_cb, statistics_cb)); 84 make_scoped_refptr(demuxer_stream), pipeline_status_cb, statistics_cb));
74 return; 85 return;
75 } 86 }
76 87
77 DCHECK(!demuxer_stream_); 88 DCHECK(!demuxer_stream_);
78 89
79 if (!demuxer_stream) { 90 if (!demuxer_stream) {
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() { 428 scoped_refptr<VideoFrame> FFmpegVideoDecoder::AllocateVideoFrame() {
418 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt); 429 VideoFrame::Format format = PixelFormatToVideoFormat(codec_context_->pix_fmt);
419 size_t width = codec_context_->width; 430 size_t width = codec_context_->width;
420 size_t height = codec_context_->height; 431 size_t height = codec_context_->height;
421 432
422 return VideoFrame::CreateFrame(format, width, height, 433 return VideoFrame::CreateFrame(format, width, height,
423 kNoTimestamp(), kNoTimestamp()); 434 kNoTimestamp(), kNoTimestamp());
424 } 435 }
425 436
426 } // namespace media 437 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698