| 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" | |
| 8 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 9 #include "base/location.h" | |
| 10 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 11 #include "media/base/audio_buffer.h" | 9 #include "media/base/audio_buffer.h" |
| 12 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
| 13 #include "media/base/audio_decoder_config.h" | 11 #include "media/base/audio_decoder_config.h" |
| 14 #include "media/base/audio_timestamp_helper.h" | 12 #include "media/base/audio_timestamp_helper.h" |
| 15 #include "media/base/bind_to_current_loop.h" | 13 #include "media/base/bind_to_current_loop.h" |
| 16 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
| 17 #include "media/base/demuxer.h" | |
| 18 #include "media/base/limits.h" | 15 #include "media/base/limits.h" |
| 19 #include "media/base/pipeline.h" | |
| 20 #include "media/base/sample_format.h" | 16 #include "media/base/sample_format.h" |
| 21 #include "media/ffmpeg/ffmpeg_common.h" | 17 #include "media/ffmpeg/ffmpeg_common.h" |
| 22 #include "media/filters/ffmpeg_glue.h" | 18 #include "media/filters/ffmpeg_glue.h" |
| 23 | 19 |
| 24 namespace media { | 20 namespace media { |
| 25 | 21 |
| 26 // Returns true if the decode result was end of stream. | 22 // Returns true if the decode result was end of stream. |
| 27 static inline bool IsEndOfStream(int result, | 23 static inline bool IsEndOfStream(int result, |
| 28 int decoded_size, | 24 int decoded_size, |
| 29 const scoped_refptr<DecoderBuffer>& input) { | 25 const scoped_refptr<DecoderBuffer>& input) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 void* opaque = NULL; | 112 void* opaque = NULL; |
| 117 buffer.swap(reinterpret_cast<AudioBuffer**>(&opaque)); | 113 buffer.swap(reinterpret_cast<AudioBuffer**>(&opaque)); |
| 118 frame->buf[0] = av_buffer_create( | 114 frame->buf[0] = av_buffer_create( |
| 119 frame->data[0], buffer_size_in_bytes, ReleaseAudioBufferImpl, opaque, 0); | 115 frame->data[0], buffer_size_in_bytes, ReleaseAudioBufferImpl, opaque, 0); |
| 120 return 0; | 116 return 0; |
| 121 } | 117 } |
| 122 | 118 |
| 123 FFmpegAudioDecoder::FFmpegAudioDecoder( | 119 FFmpegAudioDecoder::FFmpegAudioDecoder( |
| 124 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) | 120 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) |
| 125 : task_runner_(task_runner), | 121 : task_runner_(task_runner), |
| 126 weak_factory_(this), | |
| 127 state_(kUninitialized), | 122 state_(kUninitialized), |
| 128 bytes_per_channel_(0), | 123 bytes_per_channel_(0), |
| 129 channel_layout_(CHANNEL_LAYOUT_NONE), | 124 channel_layout_(CHANNEL_LAYOUT_NONE), |
| 130 channels_(0), | 125 channels_(0), |
| 131 samples_per_second_(0), | 126 samples_per_second_(0), |
| 132 av_sample_format_(0), | 127 av_sample_format_(0), |
| 133 last_input_timestamp_(kNoTimestamp()), | 128 last_input_timestamp_(kNoTimestamp()), |
| 134 output_frames_to_drop_(0) {} | 129 output_frames_to_drop_(0) {} |
| 135 | 130 |
| 136 FFmpegAudioDecoder::~FFmpegAudioDecoder() { | 131 FFmpegAudioDecoder::~FFmpegAudioDecoder() { |
| 137 DCHECK_EQ(state_, kUninitialized); | 132 DCHECK_EQ(state_, kUninitialized); |
| 138 DCHECK(!codec_context_); | 133 DCHECK(!codec_context_); |
| 139 DCHECK(!av_frame_); | 134 DCHECK(!av_frame_); |
| 140 } | 135 } |
| 141 | 136 |
| 142 void FFmpegAudioDecoder::Initialize(const AudioDecoderConfig& config, | 137 void FFmpegAudioDecoder::Initialize(const AudioDecoderConfig& config, |
| 143 const PipelineStatusCB& status_cb) { | 138 const PipelineStatusCB& status_cb) { |
| 144 DCHECK(task_runner_->BelongsToCurrentThread()); | 139 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 145 DCHECK(!config.is_encrypted()); | 140 DCHECK(!config.is_encrypted()); |
| 146 | 141 |
| 147 FFmpegGlue::InitializeFFmpeg(); | 142 FFmpegGlue::InitializeFFmpeg(); |
| 148 weak_this_ = weak_factory_.GetWeakPtr(); | |
| 149 | 143 |
| 150 config_ = config; | 144 config_ = config; |
| 151 PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb); | 145 PipelineStatusCB initialize_cb = BindToCurrentLoop(status_cb); |
| 152 | 146 |
| 153 if (!config.IsValidConfig() || !ConfigureDecoder()) { | 147 if (!config.IsValidConfig() || !ConfigureDecoder()) { |
| 154 initialize_cb.Run(DECODER_ERROR_NOT_SUPPORTED); | 148 initialize_cb.Run(DECODER_ERROR_NOT_SUPPORTED); |
| 155 return; | 149 return; |
| 156 } | 150 } |
| 157 | 151 |
| 158 // Success! | 152 // Success! |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 return true; | 534 return true; |
| 541 } | 535 } |
| 542 | 536 |
| 543 void FFmpegAudioDecoder::ResetTimestampState() { | 537 void FFmpegAudioDecoder::ResetTimestampState() { |
| 544 output_timestamp_helper_->SetBaseTimestamp(kNoTimestamp()); | 538 output_timestamp_helper_->SetBaseTimestamp(kNoTimestamp()); |
| 545 last_input_timestamp_ = kNoTimestamp(); | 539 last_input_timestamp_ = kNoTimestamp(); |
| 546 output_frames_to_drop_ = 0; | 540 output_frames_to_drop_ = 0; |
| 547 } | 541 } |
| 548 | 542 |
| 549 } // namespace media | 543 } // namespace media |
| OLD | NEW |