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