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

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

Issue 10855051: Use enum instead of string in MessageLoopFactory::GetMessageLoop* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve comments. Created 8 years, 4 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_audio_decoder.h" 5 #include "media/filters/ffmpeg_audio_decoder.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback_helpers.h" 8 #include "base/callback_helpers.h"
9 #include "base/location.h"
10 #include "base/message_loop_proxy.h"
9 #include "media/base/audio_decoder_config.h" 11 #include "media/base/audio_decoder_config.h"
10 #include "media/base/data_buffer.h" 12 #include "media/base/data_buffer.h"
11 #include "media/base/decoder_buffer.h" 13 #include "media/base/decoder_buffer.h"
12 #include "media/base/demuxer.h" 14 #include "media/base/demuxer.h"
13 #include "media/base/pipeline.h" 15 #include "media/base/pipeline.h"
14 #include "media/ffmpeg/ffmpeg_common.h" 16 #include "media/ffmpeg/ffmpeg_common.h"
15 #include "media/filters/ffmpeg_glue.h" 17 #include "media/filters/ffmpeg_glue.h"
16 18
17 namespace media { 19 namespace media {
18 20
19 // Returns true if the decode result was end of stream. 21 // Returns true if the decode result was end of stream.
20 static inline bool IsEndOfStream(int result, int decoded_size, Buffer* input) { 22 static inline bool IsEndOfStream(int result, int decoded_size, Buffer* input) {
21 // Three conditions to meet to declare end of stream for this decoder: 23 // Three conditions to meet to declare end of stream for this decoder:
22 // 1. FFmpeg didn't read anything. 24 // 1. FFmpeg didn't read anything.
23 // 2. FFmpeg didn't output anything. 25 // 2. FFmpeg didn't output anything.
24 // 3. An end of stream buffer is received. 26 // 3. An end of stream buffer is received.
25 return result == 0 && decoded_size == 0 && input->IsEndOfStream(); 27 return result == 0 && decoded_size == 0 && input->IsEndOfStream();
26 } 28 }
27 29
28 FFmpegAudioDecoder::FFmpegAudioDecoder( 30 FFmpegAudioDecoder::FFmpegAudioDecoder(const MessageLoopCB& message_loop_cb)
29 const base::Callback<MessageLoop*()>& message_loop_cb)
30 : message_loop_factory_cb_(message_loop_cb), 31 : message_loop_factory_cb_(message_loop_cb),
31 message_loop_(NULL), 32 message_loop_(NULL),
32 codec_context_(NULL), 33 codec_context_(NULL),
33 bits_per_channel_(0), 34 bits_per_channel_(0),
34 channel_layout_(CHANNEL_LAYOUT_NONE), 35 channel_layout_(CHANNEL_LAYOUT_NONE),
35 samples_per_second_(0), 36 samples_per_second_(0),
36 bytes_per_frame_(0), 37 bytes_per_frame_(0),
37 output_timestamp_base_(kNoTimestamp()), 38 output_timestamp_base_(kNoTimestamp()),
38 total_frames_decoded_(0), 39 total_frames_decoded_(0),
39 last_input_timestamp_(kNoTimestamp()), 40 last_input_timestamp_(kNoTimestamp()),
40 output_bytes_to_drop_(0), 41 output_bytes_to_drop_(0),
41 av_frame_(NULL) { 42 av_frame_(NULL) {
42 } 43 }
43 44
44 void FFmpegAudioDecoder::Initialize( 45 void FFmpegAudioDecoder::Initialize(
45 const scoped_refptr<DemuxerStream>& stream, 46 const scoped_refptr<DemuxerStream>& stream,
46 const PipelineStatusCB& status_cb, 47 const PipelineStatusCB& status_cb,
47 const StatisticsCB& statistics_cb) { 48 const StatisticsCB& statistics_cb) {
48 // Ensure FFmpeg has been initialized 49 // Ensure FFmpeg has been initialized
49 FFmpegGlue::GetInstance(); 50 FFmpegGlue::GetInstance();
50 51
51 if (!message_loop_) { 52 if (!message_loop_) {
52 message_loop_ = message_loop_factory_cb_.Run(); 53 message_loop_ = base::ResetAndReturn(&message_loop_factory_cb_).Run();
53 message_loop_factory_cb_.Reset();
54 } else { 54 } else {
55 // TODO(scherkus): initialization currently happens more than once in 55 // TODO(scherkus): initialization currently happens more than once in
56 // PipelineIntegrationTest.BasicPlayback. 56 // PipelineIntegrationTest.BasicPlayback.
57 LOG(ERROR) << "Initialize has already been called."; 57 LOG(ERROR) << "Initialize has already been called.";
58 } 58 }
59 message_loop_->PostTask( 59 message_loop_->PostTask(
60 FROM_HERE, 60 FROM_HERE,
61 base::Bind(&FFmpegAudioDecoder::DoInitialize, this, 61 base::Bind(&FFmpegAudioDecoder::DoInitialize, this,
62 stream, status_cb, statistics_cb)); 62 stream, status_cb, statistics_cb));
63 } 63 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 void FFmpegAudioDecoder::DoReset(const base::Closure& closure) { 147 void FFmpegAudioDecoder::DoReset(const base::Closure& closure) {
148 avcodec_flush_buffers(codec_context_); 148 avcodec_flush_buffers(codec_context_);
149 output_timestamp_base_ = kNoTimestamp(); 149 output_timestamp_base_ = kNoTimestamp();
150 total_frames_decoded_ = 0; 150 total_frames_decoded_ = 0;
151 last_input_timestamp_ = kNoTimestamp(); 151 last_input_timestamp_ = kNoTimestamp();
152 output_bytes_to_drop_ = 0; 152 output_bytes_to_drop_ = 0;
153 closure.Run(); 153 closure.Run();
154 } 154 }
155 155
156 void FFmpegAudioDecoder::DoRead(const ReadCB& read_cb) { 156 void FFmpegAudioDecoder::DoRead(const ReadCB& read_cb) {
157 DCHECK_EQ(MessageLoop::current(), message_loop_); 157 DCHECK(message_loop_->BelongsToCurrentThread());
158 DCHECK(!read_cb.is_null()); 158 DCHECK(!read_cb.is_null());
159 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported."; 159 CHECK(read_cb_.is_null()) << "Overlapping decodes are not supported.";
160 160
161 read_cb_ = read_cb; 161 read_cb_ = read_cb;
162 ReadFromDemuxerStream(); 162 ReadFromDemuxerStream();
163 } 163 }
164 164
165 void FFmpegAudioDecoder::DoDecodeBuffer( 165 void FFmpegAudioDecoder::DoDecodeBuffer(
166 DemuxerStream::Status status, 166 DemuxerStream::Status status,
167 const scoped_refptr<DecoderBuffer>& input) { 167 const scoped_refptr<DecoderBuffer>& input) {
168 DCHECK_EQ(MessageLoop::current(), message_loop_); 168 DCHECK(message_loop_->BelongsToCurrentThread());
169 DCHECK(!read_cb_.is_null()); 169 DCHECK(!read_cb_.is_null());
170 170
171 if (status != DemuxerStream::kOk) { 171 if (status != DemuxerStream::kOk) {
172 DCHECK(!input); 172 DCHECK(!input);
173 // TODO(acolwell): Add support for reinitializing the decoder when 173 // TODO(acolwell): Add support for reinitializing the decoder when
174 // |status| == kConfigChanged. For now we just trigger a decode error. 174 // |status| == kConfigChanged. For now we just trigger a decode error.
175 AudioDecoder::Status decoder_status = 175 AudioDecoder::Status decoder_status =
176 (status == DemuxerStream::kAborted) ? kAborted : kDecodeError; 176 (status == DemuxerStream::kAborted) ? kAborted : kDecodeError;
177 base::ResetAndReturn(&read_cb_).Run(decoder_status, NULL); 177 base::ResetAndReturn(&read_cb_).Run(decoder_status, NULL);
178 return; 178 return;
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 &FFmpegAudioDecoder::DoDecodeBuffer, this, status, buffer)); 327 &FFmpegAudioDecoder::DoDecodeBuffer, this, status, buffer));
328 } 328 }
329 329
330 base::TimeDelta FFmpegAudioDecoder::GetNextOutputTimestamp() const { 330 base::TimeDelta FFmpegAudioDecoder::GetNextOutputTimestamp() const {
331 DCHECK(output_timestamp_base_ != kNoTimestamp()); 331 DCHECK(output_timestamp_base_ != kNoTimestamp());
332 double decoded_us = (total_frames_decoded_ / samples_per_second_) * 332 double decoded_us = (total_frames_decoded_ / samples_per_second_) *
333 base::Time::kMicrosecondsPerSecond; 333 base::Time::kMicrosecondsPerSecond;
334 return output_timestamp_base_ + base::TimeDelta::FromMicroseconds(decoded_us); 334 return output_timestamp_base_ + base::TimeDelta::FromMicroseconds(decoded_us);
335 } 335 }
336 } // namespace media 336 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698