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