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 * Copyright (C) 2015 Adrien Destugues <pulkomandy@pulkomandy.tk>.
9 * All rights reserved. Distributed under the terms of the MIT License.
11 #ifndef AVCODEC_DECODER_H
12 #define AVCODEC_DECODER_H
14 //! libavcodec based decoder for Haiku
17 #include <MediaFormats.h>
22 #if LIBAVCODEC_VERSION_INT >= ((57 << 16) | (0 << 8))
24 #include "buffersink.h"
25 #include "buffersrc.h"
27 #include "swresample.h"
32 #include "DecoderPlugin.h"
33 #include "ReaderPlugin.h"
35 #include "CodecTable.h"
40 #define USE_SWS_FOR_COLOR_SPACE_CONVERSION 1
42 #define USE_SWS_FOR_COLOR_SPACE_CONVERSION 0
43 // NOTE: David's color space conversion is much faster than the FFmpeg
44 // version. Perhaps the SWS code can be used for unsupported conversions?
45 // Otherwise the alternative code could simply be removed from this file.
49 class AVCodecDecoder
: public Decoder
{
53 virtual ~AVCodecDecoder();
55 virtual void GetCodecInfo(media_codec_info
* mci
);
57 virtual status_t
Setup(media_format
* ioEncodedFormat
,
58 const void* infoBuffer
, size_t infoSize
);
60 virtual status_t
NegotiateOutputFormat(media_format
* inOutFormat
);
62 virtual status_t
Decode(void* outBuffer
, int64
* outFrameCount
,
63 media_header
* mediaHeader
,
64 media_decode_info
* info
);
66 virtual status_t
SeekedTo(int64 trame
, bigtime_t time
);
70 void _ResetTempPacket();
72 status_t
_NegotiateAudioOutputFormat(media_format
* inOutFormat
);
74 status_t
_NegotiateVideoOutputFormat(media_format
* inOutFormat
);
76 status_t
_DecodeAudio(void* outBuffer
, int64
* outFrameCount
,
77 media_header
* mediaHeader
,
78 media_decode_info
* info
);
80 status_t
_DecodeVideo(void* outBuffer
, int64
* outFrameCount
,
81 media_header
* mediaHeader
,
82 media_decode_info
* info
);
84 status_t
_DecodeNextAudioFrame();
85 void _ApplyEssentialAudioContainerPropertiesToContext();
86 status_t
_ResetRawDecodedAudio();
87 void _CheckAndFixConditionsThatHintAtBrokenAudioCodeBelow();
88 void _MoveAudioFramesToRawDecodedAudioAndUpdateStartTimes();
89 status_t
_DecodeNextAudioFrameChunk();
90 status_t
_DecodeSomeAudioFramesIntoEmptyDecodedDataBuffer();
91 void _UpdateMediaHeaderForAudioFrame();
93 status_t
_DecodeNextVideoFrame();
94 void _ApplyEssentialVideoContainerPropertiesToContext();
95 status_t
_LoadNextChunkIfNeededAndAssignStartTime();
96 status_t
_CopyChunkToChunkBufferAndAddPadding(const void* chunk
,
98 status_t
_HandleNewVideoFrameAndUpdateSystemState();
99 status_t
_FlushOneVideoFrameFromDecoderBuffer();
100 void _UpdateMediaHeaderForVideoFrame();
101 status_t
_DeinterlaceAndColorConvertVideoFrame();
103 #if LIBAVCODEC_VERSION_INT >= ((57 << 16) | (0 << 8))
104 // video deinterlace filter graph
105 status_t
_InitFilterGraph(enum AVPixelFormat pixfmt
,
106 int32 width
, int32 height
);
107 status_t
_ProcessFilterGraph(AVPicture
*dst
,
108 const AVPicture
*src
, enum AVPixelFormat pixfmt
,
109 int32 width
, int32 height
);
112 media_header fHeader
;
113 // Contains the properties of the current
114 // decoded audio / video frame
116 media_format fInputFormat
;
121 // FFmpeg related members
123 AVCodecContext
* fContext
;
124 SwrContext
* fResampleContext
;
125 uint8_t* fDecodedData
;
126 size_t fDecodedDataSizeInBytes
;
127 AVFrame
* fPostProcessedDecodedPicture
;
128 AVFrame
* fRawDecodedPicture
;
129 AVFrame
* fRawDecodedAudio
;
133 gfx_convert_func fFormatConversionFunc
;
134 #if USE_SWS_FOR_COLOR_SPACE_CONVERSION
135 SwsContext
* fSwsContext
;
142 color_space fOutputColorSpace
;
143 int32 fOutputFrameCount
;
144 float fOutputFrameRate
;
145 int fOutputFrameSize
;
146 // sample size * channel count
148 // sample size * channel count
149 // or just sample size for planar formats
151 uint8_t* fChunkBuffer
;
152 size_t fChunkBufferSize
;
153 bool fAudioDecodeError
;
155 AVFrame
* fDecodedDataBuffer
;
156 int32 fDecodedDataBufferOffset
;
157 int32 fDecodedDataBufferSize
;
159 AVPacket fTempPacket
;
161 #if LIBAVCODEC_VERSION_INT >= ((57 << 16) | (0 << 8))
162 // video deinterlace feature
163 AVFilterContext
* fBufferSinkContext
;
164 AVFilterContext
* fBufferSourceContext
;
165 AVFilterGraph
* fFilterGraph
;
166 AVFrame
* fFilterFrame
;
169 enum AVPixelFormat fLastPixfmt
;
173 #endif // AVCODEC_DECODER_H