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(media_format* inOutFormat); 41 42 virtual status_t Decode(void* outBuffer, int64* outFrameCount, 43 media_header* mediaHeader, 44 media_decode_info* info); 45 46 virtual status_t SeekedTo(int64 trame, bigtime_t time); 47 48 49 private: 50 void _ResetTempPacket(); 51 52 status_t _NegotiateAudioOutputFormat(media_format* inOutFormat); 53 54 status_t _NegotiateVideoOutputFormat(media_format* inOutFormat); 55 56 status_t _DecodeAudio(void* outBuffer, int64* outFrameCount, 57 media_header* mediaHeader, 58 media_decode_info* info); 59 60 status_t _DecodeVideo(void* outBuffer, int64* outFrameCount, 61 media_header* mediaHeader, 62 media_decode_info* info); 63 64 status_t _DecodeNextAudioFrame(); 65 void _ApplyEssentialAudioContainerPropertiesToContext(); 66 status_t _ResetRawDecodedAudio(); 67 void _CheckAndFixConditionsThatHintAtBrokenAudioCodeBelow(); 68 void _MoveAudioFramesToRawDecodedAudioAndUpdateStartTimes(); 69 status_t _DecodeNextAudioFrameChunk(); 70 status_t _DecodeSomeAudioFramesIntoEmptyDecodedDataBuffer(); 71 void _UpdateMediaHeaderForAudioFrame(); 72 73 status_t _DecodeNextVideoFrame(); 74 void _ApplyEssentialVideoContainerPropertiesToContext(); 75 status_t _LoadNextChunkIfNeededAndAssignStartTime(); 76 status_t _CopyChunkToChunkBufferAndAddPadding(const void* chunk, 77 size_t chunkSize); 78 status_t _HandleNewVideoFrameAndUpdateSystemState(); 79 status_t _FlushOneVideoFrameFromDecoderBuffer(); 80 void _UpdateMediaHeaderForVideoFrame(); 81 status_t _DeinterlaceAndColorConvertVideoFrame(); 82 83 84 media_header fHeader; 85 // Contains the properties of the current 86 // decoded audio / video frame 87 88 media_format fInputFormat; 89 90 int64 fFrame; 91 bool fIsAudio; 92 93 // FFmpeg related members 94 AVCodec* fCodec; 95 AVCodecContext* fContext; 96 uint8_t* fDecodedData; 97 size_t fDecodedDataSizeInBytes; 98 AVFrame* fPostProcessedDecodedPicture; 99 AVFrame* fRawDecodedPicture; 100 AVFrame* fRawDecodedAudio; 101 102 bool fCodecInitDone; 103 104 gfx_convert_func fFormatConversionFunc; 105 SwsContext* fSwsContext; 106 107 char* fExtraData; 108 int fExtraDataSize; 109 int fBlockAlign; 110 111 color_space fOutputColorSpace; 112 int32 fOutputFrameCount; 113 float fOutputFrameRate; 114 int fOutputFrameSize; 115 // sample size * channel count 116 117 uint8_t* fChunkBuffer; 118 size_t fChunkBufferSize; 119 bool fAudioDecodeError; 120 121 AVFrame* fDecodedDataBuffer; 122 int32 fDecodedDataBufferOffset; 123 int32 fDecodedDataBufferSize; 124 125 AVPacket fTempPacket; 126 }; 127 128 #endif // AVCODEC_DECODER_H 129