127f6fb6cSStephan Aßmus /* 227f6fb6cSStephan Aßmus * Copyright (C) 2001 Carlos Hasan. 327f6fb6cSStephan Aßmus * Copyright (C) 2001 François Revol. 427f6fb6cSStephan Aßmus * Copyright (C) 2001 Axel Dörfler. 527f6fb6cSStephan Aßmus * Copyright (C) 2004 Marcus Overhagen. 627f6fb6cSStephan Aßmus * Copyright (C) 2009 Stephan Aßmus <superstippi@gmx.de>. 727f6fb6cSStephan Aßmus * 827f6fb6cSStephan Aßmus * All rights reserved. Distributed under the terms of the MIT License. 927f6fb6cSStephan Aßmus */ 1027f6fb6cSStephan Aßmus #ifndef AVCODEC_DECODER_H 1127f6fb6cSStephan Aßmus #define AVCODEC_DECODER_H 1227f6fb6cSStephan Aßmus 1327f6fb6cSStephan Aßmus //! libavcodec based decoder for Haiku 1427f6fb6cSStephan Aßmus 1527f6fb6cSStephan Aßmus #include <MediaFormats.h> 1627f6fb6cSStephan Aßmus 17dfddb9f4SStephan Aßmus extern "C" { 18c1e73fbfSStephan Aßmus #include "avcodec.h" 19dfddb9f4SStephan Aßmus #include "swscale.h" 20dfddb9f4SStephan Aßmus } 21dfddb9f4SStephan Aßmus 2227f6fb6cSStephan Aßmus #include "DecoderPlugin.h" 2327f6fb6cSStephan Aßmus #include "ReaderPlugin.h" 2427f6fb6cSStephan Aßmus 2527f6fb6cSStephan Aßmus #include "CodecTable.h" 26c1e73fbfSStephan Aßmus #include "gfx_util.h" 2727f6fb6cSStephan Aßmus 2827f6fb6cSStephan Aßmus 2927f6fb6cSStephan Aßmus class AVCodecDecoder : public Decoder { 3027f6fb6cSStephan Aßmus public: 3127f6fb6cSStephan Aßmus AVCodecDecoder(); 3227f6fb6cSStephan Aßmus 3327f6fb6cSStephan Aßmus virtual ~AVCodecDecoder(); 3427f6fb6cSStephan Aßmus 3527f6fb6cSStephan Aßmus virtual void GetCodecInfo(media_codec_info* mci); 3627f6fb6cSStephan Aßmus 3727f6fb6cSStephan Aßmus virtual status_t Setup(media_format* ioEncodedFormat, 3827f6fb6cSStephan Aßmus const void* infoBuffer, size_t infoSize); 3927f6fb6cSStephan Aßmus 406defcb6cSColin Günther virtual status_t NegotiateOutputFormat(media_format* inOutFormat); 4127f6fb6cSStephan Aßmus 4227f6fb6cSStephan Aßmus virtual status_t Decode(void* outBuffer, int64* outFrameCount, 4327f6fb6cSStephan Aßmus media_header* mediaHeader, 4427f6fb6cSStephan Aßmus media_decode_info* info); 4527f6fb6cSStephan Aßmus 462e54e93fSStephan Aßmus virtual status_t SeekedTo(int64 trame, bigtime_t time); 4727f6fb6cSStephan Aßmus 4827f6fb6cSStephan Aßmus 4912a9eb5dSStephan Aßmus private: 50f345d827SColin Günther void _ResetTempPacket(); 51f345d827SColin Günther 526defcb6cSColin Günther status_t _NegotiateAudioOutputFormat(media_format* inOutFormat); 5312a9eb5dSStephan Aßmus 546defcb6cSColin Günther status_t _NegotiateVideoOutputFormat(media_format* inOutFormat); 5512a9eb5dSStephan Aßmus 566defcb6cSColin Günther status_t _DecodeAudio(void* outBuffer, int64* outFrameCount, 5712a9eb5dSStephan Aßmus media_header* mediaHeader, 5812a9eb5dSStephan Aßmus media_decode_info* info); 5912a9eb5dSStephan Aßmus 606defcb6cSColin Günther status_t _DecodeVideo(void* outBuffer, int64* outFrameCount, 6112a9eb5dSStephan Aßmus media_header* mediaHeader, 6212a9eb5dSStephan Aßmus media_decode_info* info); 63172c55faSColin Günther status_t _DecodeNextVideoFrame(); 646defcb6cSColin Günther status_t _LoadNextVideoChunkIfNeededAndUpdateStartTime(); 656defcb6cSColin Günther // TODO: Remove the "Video" word once 666defcb6cSColin Günther // the audio path is responsible for 676defcb6cSColin Günther // freeing the chunk buffer, too. 68*6063c02eSColin Günther status_t _CopyChunkToVideoChunkBufferAndAddPadding( 69*6063c02eSColin Günther const void* chunk, size_t chunkSize); 702d83b841SColin Günther // TODO: Remove the "Video" word once 716defcb6cSColin Günther // the audio path is responsible for 722d83b841SColin Günther // freeing the chunk buffer, too. 73a335ec82SColin Günther void _HandleNewVideoFrameAndUpdateSystemState(); 74a335ec82SColin Günther status_t _FlushOneVideoFrameFromDecoderBuffer(); 75254a5340SColin Günther void _UpdateMediaHeaderForVideoFrame(); 760adda4f6SColin Günther void _DeinterlaceAndColorConvertVideoFrame(); 77172c55faSColin Günther 7812a9eb5dSStephan Aßmus 7927f6fb6cSStephan Aßmus media_header fHeader; 80254a5340SColin Günther // Contains the properties of the current 81254a5340SColin Günther // decoded audio / video frame 82254a5340SColin Günther 8327f6fb6cSStephan Aßmus media_format fInputFormat; 8427f6fb6cSStephan Aßmus 8527f6fb6cSStephan Aßmus int64 fFrame; 8612a9eb5dSStephan Aßmus bool fIsAudio; 8727f6fb6cSStephan Aßmus 8812a9eb5dSStephan Aßmus // FFmpeg related members 8927f6fb6cSStephan Aßmus AVCodec* fCodec; 9012a9eb5dSStephan Aßmus AVCodecContext* fContext; 91172c55faSColin Günther uint8_t* fDecodedData; 92172c55faSColin Günther size_t fDecodedDataSizeInBytes; 93172c55faSColin Günther AVFrame* fPostProcessedDecodedPicture; 94172c55faSColin Günther AVFrame* fRawDecodedPicture; 9527f6fb6cSStephan Aßmus 9627f6fb6cSStephan Aßmus bool fCodecInitDone; 9727f6fb6cSStephan Aßmus 9812a9eb5dSStephan Aßmus gfx_convert_func fFormatConversionFunc; 99dfddb9f4SStephan Aßmus SwsContext* fSwsContext; 10027f6fb6cSStephan Aßmus 10127f6fb6cSStephan Aßmus char* fExtraData; 10227f6fb6cSStephan Aßmus int fExtraDataSize; 10327f6fb6cSStephan Aßmus int fBlockAlign; 10427f6fb6cSStephan Aßmus 10527f6fb6cSStephan Aßmus bigtime_t fStartTime; 10662320bdeSColin Günther color_space fOutputColorSpace; 10727f6fb6cSStephan Aßmus int32 fOutputFrameCount; 10827f6fb6cSStephan Aßmus float fOutputFrameRate; 10912a9eb5dSStephan Aßmus int fOutputFrameSize; 11012a9eb5dSStephan Aßmus // sample size * channel count 11127f6fb6cSStephan Aßmus 11227f6fb6cSStephan Aßmus const void* fChunkBuffer; 1132d83b841SColin Günther uint8_t* fVideoChunkBuffer; 1142d83b841SColin Günther // TODO: Remove and use fChunkBuffer again 1156defcb6cSColin Günther // (with type uint8_t*) once the audio path is 1162d83b841SColin Günther // responsible for freeing the chunk buffer, 1172d83b841SColin Günther // too. 11827f6fb6cSStephan Aßmus int32 fChunkBufferOffset; 11927f6fb6cSStephan Aßmus size_t fChunkBufferSize; 120967fcd2cSStephan Aßmus bool fAudioDecodeError; 12127f6fb6cSStephan Aßmus 122b95fa248SJérôme Duval AVFrame* fOutputFrame; 12327f6fb6cSStephan Aßmus int32 fOutputBufferOffset; 12427f6fb6cSStephan Aßmus int32 fOutputBufferSize; 12527f6fb6cSStephan Aßmus 126954d70d8SStephan Aßmus AVPacket fTempPacket; 12727f6fb6cSStephan Aßmus }; 12827f6fb6cSStephan Aßmus 12927f6fb6cSStephan Aßmus #endif // AVCODEC_DECODER_H 130