-
-
Notifications
You must be signed in to change notification settings - Fork 338
/
AVCodecDecoder.h
134 lines (97 loc) · 3.5 KB
/
AVCodecDecoder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Copyright (C) 2001 Carlos Hasan.
* Copyright (C) 2001 François Revol.
* Copyright (C) 2001 Axel Dörfler.
* Copyright (C) 2004 Marcus Overhagen.
* Copyright (C) 2009 Stephan Aßmus <superstippi@gmx.de>.
* Copyright (C) 2015 Adrien Destugues <pulkomandy@pulkomandy.tk>.
*
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef AVCODEC_DECODER_H
#define AVCODEC_DECODER_H
//! libavcodec based decoder for Haiku
#include <MediaFormats.h>
extern "C" {
#include "avcodec.h"
#include "swresample.h"
}
#include "DecoderPlugin.h"
#include "ReaderPlugin.h"
#include "CodecTable.h"
#include "gfx_util.h"
class AVCodecDecoder : public Decoder {
public:
AVCodecDecoder();
virtual ~AVCodecDecoder();
virtual void GetCodecInfo(media_codec_info* mci);
virtual status_t Setup(media_format* ioEncodedFormat,
const void* infoBuffer, size_t infoSize);
virtual status_t NegotiateOutputFormat(media_format* inOutFormat);
virtual status_t Decode(void* outBuffer, int64* outFrameCount,
media_header* mediaHeader,
media_decode_info* info);
virtual status_t SeekedTo(int64 trame, bigtime_t time);
private:
void _ResetTempPacket();
status_t _NegotiateAudioOutputFormat(media_format* inOutFormat);
status_t _NegotiateVideoOutputFormat(media_format* inOutFormat);
status_t _DecodeAudio(void* outBuffer, int64* outFrameCount,
media_header* mediaHeader,
media_decode_info* info);
status_t _DecodeVideo(void* outBuffer, int64* outFrameCount,
media_header* mediaHeader,
media_decode_info* info);
status_t _DecodeNextAudioFrame();
void _ApplyEssentialAudioContainerPropertiesToContext();
status_t _ResetRawDecodedAudio();
void _CheckAndFixConditionsThatHintAtBrokenAudioCodeBelow();
void _MoveAudioFramesToRawDecodedAudioAndUpdateStartTimes();
status_t _DecodeNextAudioFrameChunk();
status_t _DecodeSomeAudioFramesIntoEmptyDecodedDataBuffer();
void _UpdateMediaHeaderForAudioFrame();
status_t _DecodeNextVideoFrame();
void _ApplyEssentialVideoContainerPropertiesToContext();
status_t _LoadNextChunkIfNeededAndAssignStartTime();
status_t _CopyChunkToChunkBufferAndAddPadding(const void* chunk,
size_t chunkSize);
status_t _HandleNewVideoFrameAndUpdateSystemState();
status_t _FlushOneVideoFrameFromDecoderBuffer();
void _UpdateMediaHeaderForVideoFrame();
status_t _DeinterlaceAndColorConvertVideoFrame();
media_header fHeader;
// Contains the properties of the current
// decoded audio / video frame
media_format fInputFormat;
int64 fFrame;
bool fIsAudio;
// FFmpeg related members
AVCodec* fCodec;
AVCodecContext* fContext;
SwrContext* fResampleContext;
uint8_t* fDecodedData;
size_t fDecodedDataSizeInBytes;
AVFrame* fPostProcessedDecodedPicture;
AVFrame* fRawDecodedPicture;
AVFrame* fRawDecodedAudio;
bool fCodecInitDone;
gfx_convert_func fFormatConversionFunc;
#if USE_SWS_FOR_COLOR_SPACE_CONVERSION
SwsContext* fSwsContext;
#endif
char* fExtraData;
int fExtraDataSize;
int fBlockAlign;
color_space fOutputColorSpace;
int32 fOutputFrameCount;
float fOutputFrameRate;
int fOutputFrameSize;
// sample size * channel count
uint8_t* fChunkBuffer;
size_t fChunkBufferSize;
bool fAudioDecodeError;
AVFrame* fDecodedDataBuffer;
int32 fDecodedDataBufferSize;
AVPacket fTempPacket;
};
#endif // AVCODEC_DECODER_H