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
|
/*
* Copyright (C) 2010-2015 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 "decoders/ILAVDecoder.h"
#include "SynchronizedQueue.h"
class CLAVVideo;
class CDecodeThread : public ILAVVideoCallback, protected CAMThread, protected CCritSec
{
public:
CDecodeThread(CLAVVideo *pLAVVideo);
~CDecodeThread();
// Parts of ILAVDecoder
STDMETHODIMP_(const WCHAR*) GetDecoderName() { return m_pDecoder ? m_pDecoder->GetDecoderName() : nullptr; }
STDMETHODIMP_(long) GetBufferCount() { return m_pDecoder ? m_pDecoder->GetBufferCount() : 4; }
STDMETHODIMP_(BOOL) IsInterlaced() { return m_pDecoder ? m_pDecoder->IsInterlaced() : TRUE; }
STDMETHODIMP GetPixelFormat(LAVPixelFormat *pPix, int *pBpp) { ASSERT(m_pDecoder); return m_pDecoder->GetPixelFormat(pPix, pBpp); }
STDMETHODIMP_(REFERENCE_TIME) GetFrameDuration() { ASSERT(m_pDecoder); return m_pDecoder->GetFrameDuration(); }
STDMETHODIMP HasThreadSafeBuffers() { return m_pDecoder ? m_pDecoder->HasThreadSafeBuffers() : S_FALSE; }
STDMETHODIMP SetDirectOutput(BOOL bDirect) { return m_pDecoder ? m_pDecoder->SetDirectOutput(bDirect) : S_FALSE; }
STDMETHODIMP CreateDecoder(const CMediaType *pmt, AVCodecID codec);
STDMETHODIMP Close();
STDMETHODIMP Decode(IMediaSample *pSample);
STDMETHODIMP Flush();
STDMETHODIMP EndOfStream();
STDMETHODIMP InitAllocator(IMemAllocator **ppAlloc);
STDMETHODIMP PostConnect(IPin *pPin);
STDMETHODIMP_(BOOL) IsHWDecoderActive() { return m_bHWDecoder; }
// ILAVVideoCallback
STDMETHODIMP AllocateFrame(LAVFrame **ppFrame);
STDMETHODIMP ReleaseFrame(LAVFrame **ppFrame);
STDMETHODIMP Deliver(LAVFrame *pFrame);
STDMETHODIMP_(LPWSTR) GetFileExtension();
STDMETHODIMP_(DWORD) GetDecodeFlags();
STDMETHODIMP_(CMediaType&) GetInputMediaType();
STDMETHODIMP GetLAVPinInfo(LAVPinInfo &info);
STDMETHODIMP_(CBasePin*) GetOutputPin();
STDMETHODIMP_(CMediaType&) GetOutputMediaType();
STDMETHODIMP DVDStripPacket(BYTE*& p, long& len);
STDMETHODIMP_(LAVFrame*) GetFlushFrame();
STDMETHODIMP ReleaseAllDXVAResources();
STDMETHODIMP_(DWORD) GetGPUDeviceIndex();
protected:
DWORD ThreadProc();
private:
STDMETHODIMP CreateDecoderInternal(const CMediaType *pmt, AVCodecID codec);
STDMETHODIMP PostConnectInternal(IPin *pPin);
STDMETHODIMP DecodeInternal(IMediaSample *pSample);
STDMETHODIMP ClearQueues();
STDMETHODIMP ProcessOutput();
bool HasSample();
void PutSample(IMediaSample *pSample);
IMediaSample* GetSample();
void ReleaseSample();
bool CheckForEndOfSequence(IMediaSample *pSample);
private:
enum {CMD_CREATE_DECODER, CMD_CLOSE_DECODER, CMD_FLUSH, CMD_EOS, CMD_EXIT, CMD_INIT_ALLOCATOR, CMD_POST_CONNECT, CMD_REINIT};
CLAVVideo *m_pLAVVideo = nullptr;
ILAVDecoder *m_pDecoder = nullptr;
AVCodecID m_Codec = AV_CODEC_ID_NONE;
BOOL m_bHWDecoder = FALSE;
BOOL m_bHWDecoderFailed = FALSE;
BOOL m_bWMV9Failed = FALSE;
BOOL m_bSyncToProcess = TRUE;
BOOL m_bDecoderNeedsReInit = FALSE;
CAMEvent m_evInput{TRUE};
CAMEvent m_evDeliver{FALSE};
CAMEvent m_evSample{FALSE};
CAMEvent m_evDecodeDone{TRUE};
CAMEvent m_evEOSDone{TRUE};
CCritSec m_ThreadCritSec;
struct {
const CMediaType *pmt = nullptr;
AVCodecID codec = AV_CODEC_ID_NONE;
IMemAllocator **allocator = nullptr;
IPin *pin = nullptr;
} m_ThreadCallContext;
CSynchronizedQueue<LAVFrame *> m_Output;
CCritSec m_SampleCritSec;
IMediaSample *m_NextSample = nullptr;
IMediaSample *m_TempSample[2];
IMediaSample *m_FailedSample = nullptr;
std::wstring m_processName;
};
|