| OLD | NEW |
| 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 "media/base/audio_decoder_config.h" | 8 #include "media/base/audio_decoder_config.h" |
| 9 #include "media/base/data_buffer.h" | 9 #include "media/base/data_buffer.h" |
| 10 #include "media/base/demuxer.h" | 10 #include "media/base/demuxer.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 : message_loop_factory_cb_(message_loop_cb), | 50 : message_loop_factory_cb_(message_loop_cb), |
| 51 message_loop_(NULL), | 51 message_loop_(NULL), |
| 52 codec_context_(NULL), | 52 codec_context_(NULL), |
| 53 bits_per_channel_(0), | 53 bits_per_channel_(0), |
| 54 channel_layout_(CHANNEL_LAYOUT_NONE), | 54 channel_layout_(CHANNEL_LAYOUT_NONE), |
| 55 samples_per_second_(0), | 55 samples_per_second_(0), |
| 56 decoded_audio_size_(AVCODEC_MAX_AUDIO_FRAME_SIZE), | 56 decoded_audio_size_(AVCODEC_MAX_AUDIO_FRAME_SIZE), |
| 57 decoded_audio_(static_cast<uint8*>(av_malloc(decoded_audio_size_))) { | 57 decoded_audio_(static_cast<uint8*>(av_malloc(decoded_audio_size_))) { |
| 58 } | 58 } |
| 59 | 59 |
| 60 FFmpegAudioDecoder::~FFmpegAudioDecoder() { | |
| 61 av_free(decoded_audio_); | |
| 62 | |
| 63 // TODO(scherkus): should we require Stop() to be called? this might end up | |
| 64 // getting called on a random thread due to refcounting. | |
| 65 if (codec_context_) { | |
| 66 av_free(codec_context_->extradata); | |
| 67 avcodec_close(codec_context_); | |
| 68 av_free(codec_context_); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 void FFmpegAudioDecoder::Initialize( | 60 void FFmpegAudioDecoder::Initialize( |
| 73 const scoped_refptr<DemuxerStream>& stream, | 61 const scoped_refptr<DemuxerStream>& stream, |
| 74 const PipelineStatusCB& status_cb, | 62 const PipelineStatusCB& status_cb, |
| 75 const StatisticsCB& statistics_cb) { | 63 const StatisticsCB& statistics_cb) { |
| 76 if (!message_loop_) { | 64 if (!message_loop_) { |
| 77 message_loop_ = message_loop_factory_cb_.Run(); | 65 message_loop_ = message_loop_factory_cb_.Run(); |
| 78 message_loop_factory_cb_.Reset(); | 66 message_loop_factory_cb_.Reset(); |
| 79 } else { | 67 } else { |
| 80 // TODO(scherkus): initialization currently happens more than once in | 68 // TODO(scherkus): initialization currently happens more than once in |
| 81 // PipelineIntegrationTest.BasicPlayback. | 69 // PipelineIntegrationTest.BasicPlayback. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 104 | 92 |
| 105 int FFmpegAudioDecoder::samples_per_second() { | 93 int FFmpegAudioDecoder::samples_per_second() { |
| 106 return samples_per_second_; | 94 return samples_per_second_; |
| 107 } | 95 } |
| 108 | 96 |
| 109 void FFmpegAudioDecoder::Reset(const base::Closure& closure) { | 97 void FFmpegAudioDecoder::Reset(const base::Closure& closure) { |
| 110 message_loop_->PostTask(FROM_HERE, base::Bind( | 98 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 111 &FFmpegAudioDecoder::DoReset, this, closure)); | 99 &FFmpegAudioDecoder::DoReset, this, closure)); |
| 112 } | 100 } |
| 113 | 101 |
| 102 FFmpegAudioDecoder::~FFmpegAudioDecoder() { |
| 103 av_free(decoded_audio_); |
| 104 |
| 105 // TODO(scherkus): should we require Stop() to be called? this might end up |
| 106 // getting called on a random thread due to refcounting. |
| 107 if (codec_context_) { |
| 108 av_free(codec_context_->extradata); |
| 109 avcodec_close(codec_context_); |
| 110 av_free(codec_context_); |
| 111 } |
| 112 } |
| 113 |
| 114 void FFmpegAudioDecoder::DoInitialize( | 114 void FFmpegAudioDecoder::DoInitialize( |
| 115 const scoped_refptr<DemuxerStream>& stream, | 115 const scoped_refptr<DemuxerStream>& stream, |
| 116 const PipelineStatusCB& status_cb, | 116 const PipelineStatusCB& status_cb, |
| 117 const StatisticsCB& statistics_cb) { | 117 const StatisticsCB& statistics_cb) { |
| 118 demuxer_stream_ = stream; | 118 demuxer_stream_ = stream; |
| 119 const AudioDecoderConfig& config = stream->audio_decoder_config(); | 119 const AudioDecoderConfig& config = stream->audio_decoder_config(); |
| 120 statistics_cb_ = statistics_cb; | 120 statistics_cb_ = statistics_cb; |
| 121 | 121 |
| 122 // TODO(scherkus): this check should go in Pipeline prior to creating | 122 // TODO(scherkus): this check should go in Pipeline prior to creating |
| 123 // decoder objects. | 123 // decoder objects. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } | 294 } |
| 295 | 295 |
| 296 void FFmpegAudioDecoder::DeliverSamples(const scoped_refptr<Buffer>& samples) { | 296 void FFmpegAudioDecoder::DeliverSamples(const scoped_refptr<Buffer>& samples) { |
| 297 // Reset the callback before running to protect against reentrancy. | 297 // Reset the callback before running to protect against reentrancy. |
| 298 ReadCB read_cb = read_cb_; | 298 ReadCB read_cb = read_cb_; |
| 299 read_cb_.Reset(); | 299 read_cb_.Reset(); |
| 300 read_cb.Run(samples); | 300 read_cb.Run(samples); |
| 301 } | 301 } |
| 302 | 302 |
| 303 } // namespace media | 303 } // namespace media |
| OLD | NEW |