Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 // When use_system_ffmpeg==1, libav's AVFrame doesn't have channels field. | 38 // When use_system_ffmpeg==1, libav's AVFrame doesn't have channels field. |
| 39 return av_get_channel_layout_nb_channels(frame->channel_layout); | 39 return av_get_channel_layout_nb_channels(frame->channel_layout); |
| 40 #else | 40 #else |
| 41 return frame->channels; | 41 return frame->channels; |
| 42 #endif | 42 #endif |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Called by FFmpeg's allocation routine to free a buffer. |opaque| is the | 45 // Called by FFmpeg's allocation routine to free a buffer. |opaque| is the |
| 46 // AudioBuffer allocated, so unref it. | 46 // AudioBuffer allocated, so unref it. |
| 47 static void ReleaseAudioBufferImpl(void* opaque, uint8_t* data) { | 47 static void ReleaseAudioBufferImpl(void* opaque, uint8_t* data) { |
| 48 scoped_refptr<AudioBuffer> buffer; | 48 if (opaque) |
| 49 buffer.swap(reinterpret_cast<AudioBuffer**>(&opaque)); | 49 static_cast<AudioBuffer*>(opaque)->Release(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Called by FFmpeg's allocation routine to allocate a buffer. Uses | 52 // Called by FFmpeg's allocation routine to allocate a buffer. Uses |
| 53 // AVCodecContext.opaque to get the object reference in order to call | 53 // AVCodecContext.opaque to get the object reference in order to call |
| 54 // GetAudioBuffer() to do the actual allocation. | 54 // GetAudioBuffer() to do the actual allocation. |
| 55 static int GetAudioBuffer(struct AVCodecContext* s, AVFrame* frame, int flags) { | 55 static int GetAudioBuffer(struct AVCodecContext* s, AVFrame* frame, int flags) { |
| 56 DCHECK(s->codec->capabilities & CODEC_CAP_DR1); | 56 DCHECK(s->codec->capabilities & CODEC_CAP_DR1); |
| 57 DCHECK_EQ(s->codec_type, AVMEDIA_TYPE_AUDIO); | 57 DCHECK_EQ(s->codec_type, AVMEDIA_TYPE_AUDIO); |
| 58 | 58 |
| 59 // Since this routine is called by FFmpeg when a buffer is required for audio | 59 // Since this routine is called by FFmpeg when a buffer is required for audio |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 av_malloc(number_of_planes * sizeof(*frame->extended_data))); | 117 av_malloc(number_of_planes * sizeof(*frame->extended_data))); |
| 118 int i = 0; | 118 int i = 0; |
| 119 for (; i < AV_NUM_DATA_POINTERS; ++i) | 119 for (; i < AV_NUM_DATA_POINTERS; ++i) |
| 120 frame->extended_data[i] = frame->data[i] = buffer->channel_data()[i]; | 120 frame->extended_data[i] = frame->data[i] = buffer->channel_data()[i]; |
| 121 for (; i < number_of_planes; ++i) | 121 for (; i < number_of_planes; ++i) |
| 122 frame->extended_data[i] = buffer->channel_data()[i]; | 122 frame->extended_data[i] = buffer->channel_data()[i]; |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Now create an AVBufferRef for the data just allocated. It will own the | 125 // Now create an AVBufferRef for the data just allocated. It will own the |
| 126 // reference to the AudioBuffer object. | 126 // reference to the AudioBuffer object. |
| 127 void* opaque = NULL; | 127 AudioBuffer* opaque = buffer.get(); |
| 128 buffer.swap(reinterpret_cast<AudioBuffer**>(&opaque)); | 128 opaque->AddRef(); |
|
xhwang
2017/03/03 18:36:08
This is hard to read (not saying it's worse than b
dcheng
2017/03/03 18:45:19
Eh... this seems Good Enough (tm) for the use case
| |
| 129 frame->buf[0] = av_buffer_create( | 129 frame->buf[0] = av_buffer_create( |
| 130 frame->data[0], buffer_size_in_bytes, ReleaseAudioBufferImpl, opaque, 0); | 130 frame->data[0], buffer_size_in_bytes, ReleaseAudioBufferImpl, opaque, 0); |
| 131 return 0; | 131 return 0; |
| 132 } | 132 } |
| 133 | 133 |
| 134 FFmpegAudioDecoder::FFmpegAudioDecoder( | 134 FFmpegAudioDecoder::FFmpegAudioDecoder( |
| 135 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 135 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 136 const scoped_refptr<MediaLog>& media_log) | 136 const scoped_refptr<MediaLog>& media_log) |
| 137 : task_runner_(task_runner), | 137 : task_runner_(task_runner), |
| 138 state_(kUninitialized), | 138 state_(kUninitialized), |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 // Opus codec delay is handled by ffmpeg. | 435 // Opus codec delay is handled by ffmpeg. |
| 436 const int codec_delay = | 436 const int codec_delay = |
| 437 config_.codec() == kCodecOpus ? 0 : config_.codec_delay(); | 437 config_.codec() == kCodecOpus ? 0 : config_.codec_delay(); |
| 438 discard_helper_.reset( | 438 discard_helper_.reset( |
| 439 new AudioDiscardHelper(config_.samples_per_second(), codec_delay, | 439 new AudioDiscardHelper(config_.samples_per_second(), codec_delay, |
| 440 config_.codec() == kCodecVorbis)); | 440 config_.codec() == kCodecVorbis)); |
| 441 discard_helper_->Reset(codec_delay); | 441 discard_helper_->Reset(codec_delay); |
| 442 } | 442 } |
| 443 | 443 |
| 444 } // namespace media | 444 } // namespace media |
| OLD | NEW |