| 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_DECODER_BASE_H_ | 5 #ifndef SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_ |
| 6 #define SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_ | 6 #define SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_ |
| 7 | 7 |
| 8 #include "services/media/framework/parts/decoder.h" | 8 #include "services/media/framework/parts/decoder.h" |
| 9 #include "services/media/framework_ffmpeg/av_frame.h" |
| 10 #include "services/media/framework_ffmpeg/av_packet.h" |
| 9 #include "services/media/framework_ffmpeg/ffmpeg_type_converters.h" | 11 #include "services/media/framework_ffmpeg/ffmpeg_type_converters.h" |
| 10 extern "C" { | 12 extern "C" { |
| 11 #include "third_party/ffmpeg/libavcodec/avcodec.h" | 13 #include "third_party/ffmpeg/libavcodec/avcodec.h" |
| 12 } | 14 } |
| 13 | 15 |
| 14 namespace mojo { | 16 namespace mojo { |
| 15 namespace media { | 17 namespace media { |
| 16 | 18 |
| 17 // Abstract base class for ffmpeg-based decoders. | 19 // Abstract base class for ffmpeg-based decoders. |
| 18 class FfmpegDecoderBase : public Decoder { | 20 class FfmpegDecoderBase : public Decoder { |
| 19 public: | 21 public: |
| 20 FfmpegDecoderBase(AvCodecContextPtr av_codec_context); | 22 FfmpegDecoderBase(AvCodecContextPtr av_codec_context); |
| 21 | 23 |
| 22 ~FfmpegDecoderBase() override; | 24 ~FfmpegDecoderBase() override; |
| 23 | 25 |
| 24 // Decoder implementation. | 26 // Decoder implementation. |
| 25 std::unique_ptr<StreamType> output_stream_type() override; | 27 std::unique_ptr<StreamType> output_stream_type() override; |
| 26 | 28 |
| 27 // Transform implementation. | 29 // Transform implementation. |
| 28 void Flush() override; | 30 void Flush() override; |
| 29 | 31 |
| 30 bool TransformPacket( | 32 bool TransformPacket( |
| 31 const PacketPtr& input, | 33 const PacketPtr& input, |
| 32 bool new_input, | 34 bool new_input, |
| 33 PayloadAllocator* allocator, | 35 PayloadAllocator* allocator, |
| 34 PacketPtr* output) override; | 36 PacketPtr* output) override; |
| 35 | 37 |
| 36 protected: | 38 protected: |
| 37 struct AVFrameDeleter { | |
| 38 inline void operator()(AVFrame* ptr) const { | |
| 39 av_frame_free(&ptr); | |
| 40 } | |
| 41 }; | |
| 42 | |
| 43 using AvFramePtr = std::unique_ptr<AVFrame, AVFrameDeleter>; | |
| 44 | |
| 45 // Decodes from av_packet into av_frame_ptr. The result indicates how many | 39 // Decodes from av_packet into av_frame_ptr. The result indicates how many |
| 46 // bytes were consumed from av_packet_. *frame_decoded_out indicates whether | 40 // bytes were consumed from av_packet_. *frame_decoded_out indicates whether |
| 47 // av_frame_ptr contains a complete frame. | 41 // av_frame_ptr contains a complete frame. |
| 48 virtual int Decode( | 42 virtual int Decode( |
| 49 const AVPacket& av_packet, | 43 const AVPacket& av_packet, |
| 50 const AvFramePtr& av_frame_ptr, | 44 const ffmpeg::AvFramePtr& av_frame_ptr, |
| 51 PayloadAllocator* allocator, | 45 PayloadAllocator* allocator, |
| 52 bool* frame_decoded_out) = 0; | 46 bool* frame_decoded_out) = 0; |
| 53 | 47 |
| 54 // Creates a Packet from av_frame. | 48 // Creates a Packet from av_frame. |
| 55 virtual PacketPtr CreateOutputPacket( | 49 virtual PacketPtr CreateOutputPacket( |
| 56 const AVFrame& av_frame, | 50 const AVFrame& av_frame, |
| 57 PayloadAllocator* allocator) = 0; | 51 PayloadAllocator* allocator) = 0; |
| 58 | 52 |
| 59 // Creates an end-of-stream packet with no payload. | 53 // Creates an end-of-stream packet with no payload. |
| 60 virtual PacketPtr CreateOutputEndOfStreamPacket() = 0; | 54 virtual PacketPtr CreateOutputEndOfStreamPacket() = 0; |
| 61 | 55 |
| 62 // The ffmpeg codec context. | 56 // The ffmpeg codec context. |
| 63 const AvCodecContextPtr& context() { | 57 const AvCodecContextPtr& context() { |
| 64 return av_codec_context_; | 58 return av_codec_context_; |
| 65 } | 59 } |
| 66 | 60 |
| 67 private: | 61 private: |
| 68 // Prepares to process a new input packet. | 62 // Prepares to process a new input packet. |
| 69 void PrepareInputPacket(const PacketPtr& input); | 63 void PrepareInputPacket(const PacketPtr& input); |
| 70 | 64 |
| 71 // Finishes up after processing of an input packet has completed, possibly | 65 // Finishes up after processing of an input packet has completed, possibly |
| 72 // producing a zero-size end-of-stream packet. Returns true to indicate that | 66 // producing a zero-size end-of-stream packet. Returns true to indicate that |
| 73 // a new input packet is required. | 67 // a new input packet is required. |
| 74 bool UnprepareInputPacket(const PacketPtr& input, PacketPtr* output); | 68 bool UnprepareInputPacket(const PacketPtr& input, PacketPtr* output); |
| 75 | 69 |
| 76 AvCodecContextPtr av_codec_context_; | 70 AvCodecContextPtr av_codec_context_; |
| 77 AVPacket av_packet_; | 71 AVPacket av_packet_; |
| 78 AvFramePtr av_frame_ptr_; | 72 ffmpeg::AvFramePtr av_frame_ptr_; |
| 79 }; | 73 }; |
| 80 | 74 |
| 81 } // namespace media | 75 } // namespace media |
| 82 } // namespace mojo | 76 } // namespace mojo |
| 83 | 77 |
| 84 #endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_ | 78 #endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_ |
| OLD | NEW |