Index: services/media/framework_ffmpeg/ffmpeg_decoder_base.h |
diff --git a/services/media/framework_ffmpeg/ffmpeg_decoder_base.h b/services/media/framework_ffmpeg/ffmpeg_decoder_base.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b41828afa07416000997c6bd16dd99e9aafdc786 |
--- /dev/null |
+++ b/services/media/framework_ffmpeg/ffmpeg_decoder_base.h |
@@ -0,0 +1,85 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_ |
+#define SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_ |
+ |
+#include "services/media/framework_ffmpeg/ffmpeg_decoder.h" |
+extern "C" { |
+#include "third_party/ffmpeg/libavcodec/avcodec.h" |
+} |
+ |
+namespace mojo { |
+namespace media { |
+ |
+// Abstract base class for ffmpeg-based decoders. |
+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.
|
+ public: |
+ FfmpegDecoderBase(AVCodecContext *av_codec_context); |
+ |
+ ~FfmpegDecoderBase() override; |
+ |
+ // Decoder implementation. |
+ Result Init(const StreamType& stream_type) override; |
+ |
+ std::unique_ptr<StreamType> output_stream_type() override; |
+ |
+ // Transform implementation. |
+ void Flush() override; |
+ |
+ bool TransformPacket( |
+ const PacketPtr& input, |
+ bool new_input, |
+ PayloadAllocator* allocator, |
+ PacketPtr* output) override; |
+ |
+ protected: |
+ struct AVCodecContextDeleter { |
+ inline void operator()(AVCodecContext* ptr) const { |
+ avcodec_free_context(&ptr); |
+ } |
+ }; |
+ |
+ struct AVFrameDeleter { |
+ inline void operator()(AVFrame* ptr) const { |
+ av_frame_free(&ptr); |
+ } |
+ }; |
+ |
+ // Decodes from av_packet_ into av_frame_. The result indicates how many |
+ // bytes were consumed from av_packet_. *frame_decoded_out indicates whether |
+ // av_frame_ contains a complete frame. |
+ virtual int Decode(PayloadAllocator* allocator, bool* frame_decoded_out) = 0; |
+ |
+ // Creates a Packet from av_frame_. |
+ virtual PacketPtr CreateOutputPacket(PayloadAllocator* allocator) = 0; |
+ |
+ std::unique_ptr<AVCodecContext, AVCodecContextDeleter> av_codec_context_; |
+ |
+ // Ffmpeg's representation of the input packet. |
+ AVPacket av_packet_; |
+ |
+ // Ffmpeg's representation of the output packet. |
+ std::unique_ptr<AVFrame, AVFrameDeleter> av_frame_; |
+ |
+ // Presentation time + duration from the previous packet. |
+ int64_t next_presentation_time_; |
+ |
+ private: |
+ // Prepares to process a new input packet. |
+ void PrepareInputPacket(const PacketPtr& input); |
+ |
+ // Finishes up after processing of an input packet has completed, possibly |
+ // producing a zero-size end-of-stream packet. Returns true to indicate that |
+ // a new input packet is required. |
+ bool UnprepareInputPacket(const PacketPtr& input, PacketPtr* output); |
+ |
+ // Creates an output packet from av_frame_. |
+ PacketPtr PacketFromAvFrame(PayloadAllocator* allocator); |
+}; |
+ |
+} // namespace media |
+} // namespace mojo |
+ |
+#endif // SERVICES_MEDIA_FRAMEWORK_FFMPEG_FFMPEG_DECODER_BASE_H_ |