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/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "media/base/audio_buffer.h" | 9 #include "media/base/audio_buffer.h" |
10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 // kNormal: This is the starting state. Buffers are decoded. Decode errors | 223 // kNormal: This is the starting state. Buffers are decoded. Decode errors |
224 // are discarded. | 224 // are discarded. |
225 // kFlushCodec: There isn't any more input data. Call avcodec_decode_audio4 | 225 // kFlushCodec: There isn't any more input data. Call avcodec_decode_audio4 |
226 // until no more data is returned to flush out remaining | 226 // until no more data is returned to flush out remaining |
227 // frames. The input buffer is ignored at this point. | 227 // frames. The input buffer is ignored at this point. |
228 // kDecodeFinished: All calls return empty frames. | 228 // kDecodeFinished: All calls return empty frames. |
229 // kError: Unexpected error happened. | 229 // kError: Unexpected error happened. |
230 // | 230 // |
231 // These are the possible state transitions. | 231 // These are the possible state transitions. |
232 // | 232 // |
233 // kNormal -> kFlushCodec: | 233 // kNormal -> kFlushCodec: |
DaleCurtis
2014/06/16 18:18:08
Is this still a valid state?
xhwang
2014/06/17 18:56:35
Thanks for catching this. These comments are super
| |
234 // When buffer->end_of_stream() is first true. | 234 // When buffer->end_of_stream() is first true. |
235 // kNormal -> kError: | 235 // kNormal -> kError: |
236 // A decoding error occurs and decoding needs to stop. | 236 // A decoding error occurs and decoding needs to stop. |
237 // kFlushCodec -> kDecodeFinished: | 237 // kFlushCodec -> kDecodeFinished: |
238 // When avcodec_decode_audio4() returns 0 data. | 238 // When avcodec_decode_audio4() returns 0 data. |
239 // kFlushCodec -> kError: | 239 // kFlushCodec -> kError: |
240 // When avcodec_decode_audio4() errors out. | 240 // When avcodec_decode_audio4() errors out. |
241 // (any state) -> kNormal: | 241 // (any state) -> kNormal: |
242 // Any time Reset() is called. | 242 // Any time Reset() is called. |
243 | 243 |
(...skipping 14 matching lines...) Expand all Loading... | |
258 discard_helper_->TimeDeltaToFrames(-buffer->timestamp()); | 258 discard_helper_->TimeDeltaToFrames(-buffer->timestamp()); |
259 discard_helper_->Reset(discard_frames); | 259 discard_helper_->Reset(discard_frames); |
260 } | 260 } |
261 | 261 |
262 if (!FFmpegDecode(buffer)) { | 262 if (!FFmpegDecode(buffer)) { |
263 state_ = kError; | 263 state_ = kError; |
264 decode_cb.Run(kDecodeError); | 264 decode_cb.Run(kDecodeError); |
265 return; | 265 return; |
266 } | 266 } |
267 | 267 |
268 if (buffer->end_of_stream()) { | 268 if (buffer->end_of_stream()) |
269 state_ = kDecodeFinished; | 269 state_ = kDecodeFinished; |
270 output_cb_.Run(AudioBuffer::CreateEOSBuffer()); | |
271 } | |
272 | 270 |
273 decode_cb.Run(kOk); | 271 decode_cb.Run(kOk); |
274 } | 272 } |
275 | 273 |
276 bool FFmpegAudioDecoder::FFmpegDecode( | 274 bool FFmpegAudioDecoder::FFmpegDecode( |
277 const scoped_refptr<DecoderBuffer>& buffer) { | 275 const scoped_refptr<DecoderBuffer>& buffer) { |
278 AVPacket packet; | 276 AVPacket packet; |
279 av_init_packet(&packet); | 277 av_init_packet(&packet); |
280 if (buffer->end_of_stream()) { | 278 if (buffer->end_of_stream()) { |
281 packet.data = NULL; | 279 packet.data = NULL; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 DCHECK_GE(unread_frames, 0); | 348 DCHECK_GE(unread_frames, 0); |
351 if (unread_frames > 0) | 349 if (unread_frames > 0) |
352 output->TrimEnd(unread_frames); | 350 output->TrimEnd(unread_frames); |
353 av_frame_unref(av_frame_.get()); | 351 av_frame_unref(av_frame_.get()); |
354 } | 352 } |
355 | 353 |
356 // WARNING: |av_frame_| no longer has valid data at this point. | 354 // WARNING: |av_frame_| no longer has valid data at this point. |
357 const int decoded_frames = frame_decoded ? output->frame_count() : 0; | 355 const int decoded_frames = frame_decoded ? output->frame_count() : 0; |
358 if (IsEndOfStream(result, decoded_frames, buffer)) { | 356 if (IsEndOfStream(result, decoded_frames, buffer)) { |
359 DCHECK_EQ(packet.size, 0); | 357 DCHECK_EQ(packet.size, 0); |
360 output_cb_.Run(AudioBuffer::CreateEOSBuffer()); | |
361 } else if (discard_helper_->ProcessBuffers(buffer, output)) { | 358 } else if (discard_helper_->ProcessBuffers(buffer, output)) { |
362 output_cb_.Run(output); | 359 output_cb_.Run(output); |
363 } | 360 } |
364 } while (packet.size > 0); | 361 } while (packet.size > 0); |
365 | 362 |
366 return true; | 363 return true; |
367 } | 364 } |
368 | 365 |
369 void FFmpegAudioDecoder::ReleaseFFmpegResources() { | 366 void FFmpegAudioDecoder::ReleaseFFmpegResources() { |
370 codec_context_.reset(); | 367 codec_context_.reset(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 | 422 |
426 ResetTimestampState(); | 423 ResetTimestampState(); |
427 return true; | 424 return true; |
428 } | 425 } |
429 | 426 |
430 void FFmpegAudioDecoder::ResetTimestampState() { | 427 void FFmpegAudioDecoder::ResetTimestampState() { |
431 discard_helper_->Reset(config_.codec_delay()); | 428 discard_helper_->Reset(config_.codec_delay()); |
432 } | 429 } |
433 | 430 |
434 } // namespace media | 431 } // namespace media |
OLD | NEW |