1 /* 2 * Copyright (C) 2001 Carlos Hasan. 3 * Copyright (C) 2001 François Revol. 4 * Copyright (C) 2001 Axel Dörfler. 5 * Copyright (C) 2004 Marcus Overhagen. 6 * Copyright (C) 2009 Stephan Aßmus <superstippi@gmx.de>. 7 * 8 * All rights reserved. Distributed under the terms of the MIT License. 9 */ 10 #ifndef AVCODEC_DECODER_H 11 #define AVCODEC_DECODER_H 12 13 //! libavcodec based decoder for Haiku 14 15 #include <MediaFormats.h> 16 17 extern "C" { 18 #include "avcodec.h" 19 #include "swscale.h" 20 } 21 22 #include "DecoderPlugin.h" 23 #include "ReaderPlugin.h" 24 25 #include "CodecTable.h" 26 #include "gfx_util.h" 27 28 29 class AVCodecDecoder : public Decoder { 30 public: 31 AVCodecDecoder(); 32 33 virtual ~AVCodecDecoder(); 34 35 virtual void GetCodecInfo(media_codec_info* mci); 36 37 virtual status_t Setup(media_format* ioEncodedFormat, 38 const void* infoBuffer, size_t infoSize); 39 40 virtual status_t NegotiateOutputFormat( 41 media_format* inOutFormat); 42 43 virtual status_t Decode(void* outBuffer, int64* outFrameCount, 44 media_header* mediaHeader, 45 media_decode_info* info); 46 47 virtual status_t SeekedTo(int64 trame, bigtime_t time); 48 49 50 private: 51 status_t _NegotiateAudioOutputFormat( 52 media_format* inOutFormat); 53 54 status_t _NegotiateVideoOutputFormat( 55 media_format* inOutFormat); 56 57 status_t _DecodeAudio(void* outBuffer, 58 int64* outFrameCount, 59 media_header* mediaHeader, 60 media_decode_info* info); 61 62 status_t _DecodeVideo(void* outBuffer, 63 int64* outFrameCount, 64 media_header* mediaHeader, 65 media_decode_info* info); 66 67 68 media_header fHeader; 69 media_format fInputFormat; 70 media_raw_video_format fOutputVideoFormat; 71 72 int64 fFrame; 73 bool fIsAudio; 74 75 // FFmpeg related members 76 AVCodec* fCodec; 77 AVCodecContext* fContext; 78 AVFrame* fInputPicture; 79 AVFrame* fOutputPicture; 80 81 bool fCodecInitDone; 82 83 gfx_convert_func fFormatConversionFunc; 84 SwsContext* fSwsContext; 85 86 char* fExtraData; 87 int fExtraDataSize; 88 int fBlockAlign; 89 90 bigtime_t fStartTime; 91 int32 fOutputFrameCount; 92 float fOutputFrameRate; 93 int fOutputFrameSize; 94 // sample size * channel count 95 96 const void* fChunkBuffer; 97 int32 fChunkBufferOffset; 98 size_t fChunkBufferSize; 99 bool fAudioDecodeError; 100 101 char* fOutputBuffer; 102 int32 fOutputBufferOffset; 103 int32 fOutputBufferSize; 104 105 AVPacket fTempPacket; 106 }; 107 108 #endif // AVCODEC_DECODER_H 109