OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ |
| 6 #define SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ |
| 7 |
| 8 #include "services/media/framework/lpcm_util.h" |
| 9 #include "services/media/framework_ffmpeg/ffmpeg_decoder_base.h" |
| 10 |
| 11 namespace mojo { |
| 12 namespace media { |
| 13 |
| 14 // Decoder implementation employing an ffmpeg audio decoder. |
| 15 class FfmpegAudioDecoder : public FfmpegDecoderBase { |
| 16 public: |
| 17 FfmpegAudioDecoder(AVCodecContext *av_codec_context); |
| 18 |
| 19 ~FfmpegAudioDecoder() override; |
| 20 |
| 21 protected: |
| 22 // FfmpegDecoderBase overrides. |
| 23 int Decode(PayloadAllocator* allocator, bool* frame_decoded_out) override; |
| 24 |
| 25 PacketPtr CreateOutputPacket(PayloadAllocator* allocator) override; |
| 26 |
| 27 private: |
| 28 // Align sample buffers on 32-byte boundaries. This is the value that Chromium |
| 29 // uses and is supposed to work for all processor architectures. Strangely, if |
| 30 // we were to tell ffmpeg to use the default (by passing 0), it aligns on 32 |
| 31 // sample (not byte) boundaries. |
| 32 static const int kChannelAlign = 32; |
| 33 |
| 34 // Callback used by the ffmpeg decoder to acquire a buffer. |
| 35 static int AllocateBufferForAvFrame( |
| 36 AVCodecContext* av_codec_context, |
| 37 AVFrame* av_frame, |
| 38 int flags); |
| 39 |
| 40 // Callback used by the ffmpeg decoder to release a buffer. |
| 41 static void ReleaseBufferForAvFrame(void* opaque, uint8_t* buffer); |
| 42 |
| 43 // Set only for the duration of avcodec_decode_audio4 to provide context for |
| 44 // AllocateBufferForAvFrame and ReleaseBufferForAvFrame. |
| 45 PayloadAllocator* allocator_; |
| 46 |
| 47 // AllocateBufferForAvFrame deposits the packet size here, because there's |
| 48 // no good evidence of it after avcodec_decode_audio4 completes. |
| 49 uint64_t packet_size_; |
| 50 |
| 51 // This is used to verify that an allocated buffer is being used as expected |
| 52 // by ffmpeg avcodec_decode_audio4. AllocateBufferForAvFrame sets it. |
| 53 void* packet_buffer_; |
| 54 |
| 55 // For interleaving, if needed. |
| 56 std::unique_ptr<LpcmUtil> lpcm_util_; |
| 57 |
| 58 // For interleaving, if needed. |
| 59 std::unique_ptr<StreamType> stream_type_; |
| 60 }; |
| 61 |
| 62 } // namespace media |
| 63 } // namespace mojo |
| 64 |
| 65 #endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ |
OLD | NEW |