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
|
/*
* Copyright (C) 2010-2013 Hendrik Leppkes
* http://www.1f0.de
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#pragma once
#include "DecBase.h"
#include <map>
#define AVCODEC_MAX_THREADS 16
typedef struct {
REFERENCE_TIME rtStart;
REFERENCE_TIME rtStop;
} TimingCache;
class CDecAvcodec : public CDecBase
{
public:
CDecAvcodec(void);
virtual ~CDecAvcodec(void);
// ILAVDecoder
STDMETHODIMP InitDecoder(AVCodecID codec, const CMediaType *pmt);
STDMETHODIMP Decode(const BYTE *buffer, int buflen, REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, BOOL bSyncPoint, BOOL bDiscontinuity);
STDMETHODIMP Flush();
STDMETHODIMP EndOfStream();
STDMETHODIMP GetPixelFormat(LAVPixelFormat *pPix, int *pBpp);
STDMETHODIMP_(REFERENCE_TIME) GetFrameDuration();
STDMETHODIMP_(BOOL) IsInterlaced();
STDMETHODIMP_(const WCHAR*) GetDecoderName() { return L"avcodec"; }
STDMETHODIMP HasThreadSafeBuffers() { return S_OK; }
STDMETHODIMP SyncToProcessThread() { return m_pAVCtx && m_pAVCtx->active_thread_type ? S_OK : S_FALSE; }
// CDecBase
STDMETHODIMP Init();
protected:
virtual HRESULT AdditionaDecoderInit() { return S_FALSE; }
virtual HRESULT PostDecode() { return S_FALSE; }
virtual HRESULT HandleDXVA2Frame(LAVFrame *pFrame) { return S_FALSE; }
STDMETHODIMP DestroyDecoder();
private:
STDMETHODIMP ConvertPixFmt(AVFrame *pFrame, LAVFrame *pOutFrame);
protected:
AVCodecContext *m_pAVCtx = nullptr;
AVFrame *m_pFrame = nullptr;
AVCodecID m_nCodecId = AV_CODEC_ID_NONE;
private:
AVCodec *m_pAVCodec = nullptr;
AVCodecParserContext *m_pParser = nullptr;
BYTE *m_pFFBuffer = nullptr;
int m_nFFBufferSize = 0;
BYTE *m_pFFBuffer2 = nullptr;
int m_nFFBufferSize2 = 0;
SwsContext *m_pSwsContext = nullptr;
BOOL m_bHasPalette = FALSE;
// Timing settings
BOOL m_bFFReordering = FALSE;
BOOL m_bCalculateStopTime = FALSE;
BOOL m_bRVDropBFrameTimings = FALSE;
BOOL m_bInputPadded = FALSE;
BOOL m_bBFrameDelay = TRUE;
TimingCache m_tcBFrameDelay[2];
int m_nBFramePos = 0;
TimingCache m_tcThreadBuffer[AVCODEC_MAX_THREADS];
int m_CurrentThread = 0;
REFERENCE_TIME m_rtStartCache = AV_NOPTS_VALUE;
BOOL m_bResumeAtKeyFrame = FALSE;
BOOL m_bWaitingForKeyFrame = FALSE;
int m_iInterlaced = -1;
};
|