Index: services/media/framework_ffmpeg/ffmpeg_audio_decoder.h |
diff --git a/services/media/framework_ffmpeg/ffmpeg_audio_decoder.h b/services/media/framework_ffmpeg/ffmpeg_audio_decoder.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..620ceff18cc2693005c5ce0b26f50317033ab4d9 |
--- /dev/null |
+++ b/services/media/framework_ffmpeg/ffmpeg_audio_decoder.h |
@@ -0,0 +1,65 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ |
+#define SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ |
+ |
+#include "services/media/framework/lpcm_util.h" |
+#include "services/media/framework_ffmpeg/ffmpeg_decoder_base.h" |
+ |
+namespace mojo { |
+namespace media { |
+ |
+// Decoder implementation employing an ffmpeg audio decoder. |
+class FfmpegAudioDecoder : public FfmpegDecoderBase { |
+ public: |
+ FfmpegAudioDecoder(AVCodecContext *av_codec_context); |
+ |
+ ~FfmpegAudioDecoder() override; |
+ |
+ protected: |
+ // FfmpegDecoderBase overrides. |
+ int Decode(PayloadAllocator* allocator, bool* frame_decoded_out) override; |
+ |
+ PacketPtr CreateOutputPacket(PayloadAllocator* allocator) override; |
+ |
+ private: |
+ // Align sample buffers on 32-byte boundaries. This is the value that Chromium |
+ // uses and is supposed to work for all processor architectures. Strangely, if |
+ // we were to tell ffmpeg to use the default (by passing 0), it aligns on 32 |
+ // sample (not byte) boundaries. |
+ static const int kChannelAlign = 32; |
+ |
+ // Callback used by the ffmpeg decoder to acquire a buffer. |
+ static int AllocateBufferForAvFrame( |
+ AVCodecContext* av_codec_context, |
+ AVFrame* av_frame, |
+ int flags); |
+ |
+ // Callback used by the ffmpeg decoder to release a buffer. |
+ static void ReleaseBufferForAvFrame(void* opaque, uint8_t* buffer); |
+ |
+ // Set only for the duration of avcodec_decode_audio4 to provide context for |
+ // AllocateBufferForAvFrame and ReleaseBufferForAvFrame. |
+ PayloadAllocator* allocator_; |
+ |
+ // AllocateBufferForAvFrame deposits the packet size here, because there's |
+ // no good evidence of it after avcodec_decode_audio4 completes. |
+ uint64_t packet_size_; |
+ |
+ // This is used to verify that an allocated buffer is being used as expected |
+ // by ffmpeg avcodec_decode_audio4. AllocateBufferForAvFrame sets it. |
+ void* packet_buffer_; |
+ |
+ // For interleaving, if needed. |
+ std::unique_ptr<LpcmUtil> lpcm_util_; |
+ |
+ // For interleaving, if needed. |
+ std::unique_ptr<StreamType> stream_type_; |
+}; |
+ |
+} // namespace media |
+} // namespace mojo |
+ |
+#endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ |