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 #ifndef SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ | 5 #ifndef SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ |
6 #define SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ | 6 #define SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ |
7 | 7 |
8 #include "services/media/framework/lpcm_util.h" | 8 #include "services/media/framework/lpcm_util.h" |
9 #include "services/media/framework_ffmpeg/ffmpeg_decoder_base.h" | 9 #include "services/media/framework_ffmpeg/ffmpeg_decoder_base.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 namespace media { | 12 namespace media { |
13 | 13 |
14 // Decoder implementation employing an ffmpeg audio decoder. | 14 // Decoder implementation employing an ffmpeg audio decoder. |
15 class FfmpegAudioDecoder : public FfmpegDecoderBase { | 15 class FfmpegAudioDecoder : public FfmpegDecoderBase { |
16 public: | 16 public: |
17 FfmpegAudioDecoder(AvCodecContextPtr av_codec_context); | 17 FfmpegAudioDecoder(AvCodecContextPtr av_codec_context); |
18 | 18 |
19 ~FfmpegAudioDecoder() override; | 19 ~FfmpegAudioDecoder() override; |
20 | 20 |
21 protected: | 21 protected: |
22 // FfmpegDecoderBase overrides. | 22 // FfmpegDecoderBase overrides. |
23 void Flush() override; | 23 void Flush() override; |
24 | 24 |
25 int Decode( | 25 int Decode(const AVPacket& av_packet, |
26 const AVPacket& av_packet, | 26 const ffmpeg::AvFramePtr& av_frame_ptr, |
27 const ffmpeg::AvFramePtr& av_frame_ptr, | 27 PayloadAllocator* allocator, |
28 PayloadAllocator* allocator, | 28 bool* frame_decoded_out) override; |
29 bool* frame_decoded_out) override; | |
30 | 29 |
31 PacketPtr CreateOutputPacket( | 30 PacketPtr CreateOutputPacket(const AVFrame& av_frame, |
32 const AVFrame& av_frame, | 31 PayloadAllocator* allocator) override; |
33 PayloadAllocator* allocator) override; | |
34 | 32 |
35 PacketPtr CreateOutputEndOfStreamPacket() override; | 33 PacketPtr CreateOutputEndOfStreamPacket() override; |
36 | 34 |
37 private: | 35 private: |
38 // Used to control deallocation of buffers. | 36 // Used to control deallocation of buffers. |
39 class AvBufferContext { | 37 class AvBufferContext { |
40 public: | 38 public: |
41 AvBufferContext(size_t size, PayloadAllocator* allocator) : | 39 AvBufferContext(size_t size, PayloadAllocator* allocator) |
42 size_(size), | 40 : size_(size), allocator_(allocator) { |
43 allocator_(allocator) { | |
44 DCHECK(allocator_); | 41 DCHECK(allocator_); |
45 if (size_ == 0) { | 42 if (size_ == 0) { |
46 buffer_ = nullptr; | 43 buffer_ = nullptr; |
47 } else { | 44 } else { |
48 buffer_ = static_cast<uint8_t*>( | 45 buffer_ = |
49 allocator_->AllocatePayloadBuffer(size_)); | 46 static_cast<uint8_t*>(allocator_->AllocatePayloadBuffer(size_)); |
50 } | 47 } |
51 } | 48 } |
52 | 49 |
53 ~AvBufferContext() { | 50 ~AvBufferContext() { |
54 if (allocator_ == nullptr) { | 51 if (allocator_ == nullptr) { |
55 // Previously released. | 52 // Previously released. |
56 return; | 53 return; |
57 } | 54 } |
58 | 55 |
59 if (size_ != 0) { | 56 if (size_ != 0) { |
(...skipping 25 matching lines...) Expand all Loading... |
85 PayloadAllocator* allocator_; | 82 PayloadAllocator* allocator_; |
86 }; | 83 }; |
87 | 84 |
88 // Align sample buffers on 32-byte boundaries. This is the value that Chromium | 85 // Align sample buffers on 32-byte boundaries. This is the value that Chromium |
89 // uses and is supposed to work for all processor architectures. Strangely, if | 86 // uses and is supposed to work for all processor architectures. Strangely, if |
90 // we were to tell ffmpeg to use the default (by passing 0), it aligns on 32 | 87 // we were to tell ffmpeg to use the default (by passing 0), it aligns on 32 |
91 // sample (not byte) boundaries. | 88 // sample (not byte) boundaries. |
92 static const int kChannelAlign = 32; | 89 static const int kChannelAlign = 32; |
93 | 90 |
94 // Callback used by the ffmpeg decoder to acquire a buffer. | 91 // Callback used by the ffmpeg decoder to acquire a buffer. |
95 static int AllocateBufferForAvFrame( | 92 static int AllocateBufferForAvFrame(AVCodecContext* av_codec_context, |
96 AVCodecContext* av_codec_context, | 93 AVFrame* av_frame, |
97 AVFrame* av_frame, | 94 int flags); |
98 int flags); | |
99 | 95 |
100 // Callback used by the ffmpeg decoder to release a buffer. | 96 // Callback used by the ffmpeg decoder to release a buffer. |
101 static void ReleaseBufferForAvFrame(void* opaque, uint8_t* buffer); | 97 static void ReleaseBufferForAvFrame(void* opaque, uint8_t* buffer); |
102 | 98 |
103 // The allocator used by avcodec_decode_audio4 to provide context for | 99 // The allocator used by avcodec_decode_audio4 to provide context for |
104 // AllocateBufferForAvFrame. This is set only during the call to | 100 // AllocateBufferForAvFrame. This is set only during the call to |
105 // avcodec_decode_audio4. | 101 // avcodec_decode_audio4. |
106 PayloadAllocator* allocator_; | 102 PayloadAllocator* allocator_; |
107 | 103 |
108 // For interleaving, if needed. | 104 // For interleaving, if needed. |
109 std::unique_ptr<LpcmUtil> lpcm_util_; | 105 std::unique_ptr<LpcmUtil> lpcm_util_; |
110 | 106 |
111 // For interleaving, if needed. | 107 // For interleaving, if needed. |
112 std::unique_ptr<StreamType> stream_type_; | 108 std::unique_ptr<StreamType> stream_type_; |
113 | 109 |
114 // Used to supply missing PTS. | 110 // Used to supply missing PTS. |
115 int64_t next_pts_= Packet::kUnknownPts; | 111 int64_t next_pts_ = Packet::kUnknownPts; |
116 }; | 112 }; |
117 | 113 |
118 } // namespace media | 114 } // namespace media |
119 } // namespace mojo | 115 } // namespace mojo |
120 | 116 |
121 #endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ | 117 #endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ |
OLD | NEW |