| 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/util/lpcm_util.h" | 8 #include "services/media/framework/util/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 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 const ffmpeg::AvFramePtr& av_frame_ptr, | 26 const ffmpeg::AvFramePtr& av_frame_ptr, |
| 27 PayloadAllocator* allocator, | 27 PayloadAllocator* allocator, |
| 28 bool* frame_decoded_out) override; | 28 bool* frame_decoded_out) override; |
| 29 | 29 |
| 30 PacketPtr CreateOutputPacket(const AVFrame& av_frame, | 30 PacketPtr CreateOutputPacket(const AVFrame& av_frame, |
| 31 PayloadAllocator* allocator) override; | 31 PayloadAllocator* allocator) override; |
| 32 | 32 |
| 33 PacketPtr CreateOutputEndOfStreamPacket() override; | 33 PacketPtr CreateOutputEndOfStreamPacket() override; |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 // Used to control deallocation of buffers. | |
| 37 class AvBufferContext { | |
| 38 public: | |
| 39 AvBufferContext(size_t size, PayloadAllocator* allocator) | |
| 40 : size_(size), allocator_(allocator) { | |
| 41 DCHECK(allocator_); | |
| 42 if (size_ == 0) { | |
| 43 buffer_ = nullptr; | |
| 44 } else { | |
| 45 buffer_ = | |
| 46 static_cast<uint8_t*>(allocator_->AllocatePayloadBuffer(size_)); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 ~AvBufferContext() { | |
| 51 if (allocator_ == nullptr) { | |
| 52 // Previously released. | |
| 53 return; | |
| 54 } | |
| 55 | |
| 56 if (size_ != 0) { | |
| 57 DCHECK(buffer_ != nullptr); | |
| 58 allocator_->ReleasePayloadBuffer(size_, buffer_); | |
| 59 return; | |
| 60 } | |
| 61 | |
| 62 DCHECK(buffer_ == nullptr); | |
| 63 } | |
| 64 | |
| 65 uint8_t* buffer() { return buffer_; } | |
| 66 | |
| 67 size_t size() { return size_; } | |
| 68 | |
| 69 // Releases ownership of the buffer. | |
| 70 uint8_t* Release() { | |
| 71 DCHECK(allocator_) << "AvBufferContext released twice"; | |
| 72 uint8_t* result = buffer_; | |
| 73 buffer_ = nullptr; | |
| 74 size_ = 0; | |
| 75 allocator_ = nullptr; | |
| 76 return result; | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 uint8_t* buffer_; | |
| 81 size_t size_; | |
| 82 PayloadAllocator* allocator_; | |
| 83 }; | |
| 84 | |
| 85 // Align sample buffers on 32-byte boundaries. This is the value that Chromium | 36 // Align sample buffers on 32-byte boundaries. This is the value that Chromium |
| 86 // uses and is supposed to work for all processor architectures. Strangely, if | 37 // uses and is supposed to work for all processor architectures. Strangely, if |
| 87 // we were to tell ffmpeg to use the default (by passing 0), it aligns on 32 | 38 // we were to tell ffmpeg to use the default (by passing 0), it aligns on 32 |
| 88 // sample (not byte) boundaries. | 39 // sample (not byte) boundaries. |
| 89 static const int kChannelAlign = 32; | 40 static const int kChannelAlign = 32; |
| 90 | 41 |
| 91 // Callback used by the ffmpeg decoder to acquire a buffer. | 42 // Callback used by the ffmpeg decoder to acquire a buffer. |
| 92 static int AllocateBufferForAvFrame(AVCodecContext* av_codec_context, | 43 static int AllocateBufferForAvFrame(AVCodecContext* av_codec_context, |
| 93 AVFrame* av_frame, | 44 AVFrame* av_frame, |
| 94 int flags); | 45 int flags); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 108 std::unique_ptr<StreamType> stream_type_; | 59 std::unique_ptr<StreamType> stream_type_; |
| 109 | 60 |
| 110 // Used to supply missing PTS. | 61 // Used to supply missing PTS. |
| 111 int64_t next_pts_ = Packet::kUnknownPts; | 62 int64_t next_pts_ = Packet::kUnknownPts; |
| 112 }; | 63 }; |
| 113 | 64 |
| 114 } // namespace media | 65 } // namespace media |
| 115 } // namespace mojo | 66 } // namespace mojo |
| 116 | 67 |
| 117 #endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ | 68 #endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_AUDIO_DECODER_H_ |
| OLD | NEW |