| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "services/media/framework_ffmpeg/ffmpeg_audio_decoder.h" | 6 #include "services/media/framework_ffmpeg/ffmpeg_audio_decoder.h" |
| 7 | 7 |
| 8 namespace mojo { | 8 namespace mojo { |
| 9 namespace media { | 9 namespace media { |
| 10 | 10 |
| 11 FfmpegAudioDecoder::FfmpegAudioDecoder(AvCodecContextPtr av_codec_context) | 11 FfmpegAudioDecoder::FfmpegAudioDecoder(AvCodecContextPtr av_codec_context) |
| 12 : FfmpegDecoderBase(std::move(av_codec_context)) { | 12 : FfmpegDecoderBase(std::move(av_codec_context)) { |
| 13 DCHECK(context()); | 13 DCHECK(context()); |
| 14 DCHECK(context()->channels > 0); | 14 DCHECK(context()->channels > 0); |
| 15 | 15 |
| 16 context()->opaque = this; | 16 context()->opaque = this; |
| 17 context()->get_buffer2 = AllocateBufferForAvFrame; | 17 context()->get_buffer2 = AllocateBufferForAvFrame; |
| 18 context()->refcounted_frames = 1; | 18 context()->refcounted_frames = 1; |
| 19 | 19 |
| 20 if (av_sample_fmt_is_planar(context()->sample_fmt)) { | 20 if (av_sample_fmt_is_planar(context()->sample_fmt)) { |
| 21 // Prepare for interleaving. | 21 // Prepare for interleaving. |
| 22 stream_type_ = output_stream_type(); | 22 stream_type_ = output_stream_type(); |
| 23 lpcm_util_ = LpcmUtil::Create(*stream_type_->lpcm()); | 23 lpcm_util_ = LpcmUtil::Create(*stream_type_->audio()); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 FfmpegAudioDecoder::~FfmpegAudioDecoder() {} | 27 FfmpegAudioDecoder::~FfmpegAudioDecoder() {} |
| 28 | 28 |
| 29 void FfmpegAudioDecoder::Flush() { | 29 void FfmpegAudioDecoder::Flush() { |
| 30 FfmpegDecoderBase::Flush(); | 30 FfmpegDecoderBase::Flush(); |
| 31 next_pts_ = Packet::kUnknownPts; | 31 next_pts_ = Packet::kUnknownPts; |
| 32 } | 32 } |
| 33 | 33 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 80 |
| 81 AvBufferContext* av_buffer_context = | 81 AvBufferContext* av_buffer_context = |
| 82 reinterpret_cast<AvBufferContext*>(av_buffer_get_opaque(av_frame.buf[0])); | 82 reinterpret_cast<AvBufferContext*>(av_buffer_get_opaque(av_frame.buf[0])); |
| 83 | 83 |
| 84 if (lpcm_util_) { | 84 if (lpcm_util_) { |
| 85 // We need to interleave. The non-interleaved frames are in a buffer that | 85 // We need to interleave. The non-interleaved frames are in a buffer that |
| 86 // was allocated from the default allocator. That buffer will get released | 86 // was allocated from the default allocator. That buffer will get released |
| 87 // later in ReleaseBufferForAvFrame. We need a new buffer for the | 87 // later in ReleaseBufferForAvFrame. We need a new buffer for the |
| 88 // interleaved frames, which we get from the provided allocator. | 88 // interleaved frames, which we get from the provided allocator. |
| 89 DCHECK(stream_type_); | 89 DCHECK(stream_type_); |
| 90 DCHECK(stream_type_->lpcm()); | 90 DCHECK(stream_type_->audio()); |
| 91 payload_size = stream_type_->lpcm()->min_buffer_size(av_frame.nb_samples); | 91 payload_size = stream_type_->audio()->min_buffer_size(av_frame.nb_samples); |
| 92 payload_buffer = allocator->AllocatePayloadBuffer(payload_size); | 92 payload_buffer = allocator->AllocatePayloadBuffer(payload_size); |
| 93 | 93 |
| 94 lpcm_util_->Interleave(av_buffer_context->buffer(), | 94 lpcm_util_->Interleave(av_buffer_context->buffer(), |
| 95 av_buffer_context->size(), payload_buffer, | 95 av_buffer_context->size(), payload_buffer, |
| 96 av_frame.nb_samples); | 96 av_frame.nb_samples); |
| 97 } else { | 97 } else { |
| 98 // We don't need to interleave. The interleaved frames are in a buffer that | 98 // We don't need to interleave. The interleaved frames are in a buffer that |
| 99 // was allocated from the correct allocator. We take ownership of the buffer | 99 // was allocated from the correct allocator. We take ownership of the buffer |
| 100 // by calling Release here so that ReleaseBufferForAvFrame won't release it. | 100 // by calling Release here so that ReleaseBufferForAvFrame won't release it. |
| 101 payload_size = av_buffer_context->size(); | 101 payload_size = av_buffer_context->size(); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 DCHECK(av_buffer_context); | 193 DCHECK(av_buffer_context); |
| 194 // Either this buffer has already been released to someone else's ownership, | 194 // Either this buffer has already been released to someone else's ownership, |
| 195 // or it's the same as the buffer parameter. | 195 // or it's the same as the buffer parameter. |
| 196 DCHECK(av_buffer_context->buffer() == nullptr || | 196 DCHECK(av_buffer_context->buffer() == nullptr || |
| 197 av_buffer_context->buffer() == buffer); | 197 av_buffer_context->buffer() == buffer); |
| 198 delete av_buffer_context; | 198 delete av_buffer_context; |
| 199 } | 199 } |
| 200 | 200 |
| 201 } // namespace media | 201 } // namespace media |
| 202 } // namespace mojo | 202 } // namespace mojo |
| OLD | NEW |