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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
/*
* Copyright (C) 2010-2014 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.
*
* Initial design and concept by Gabest and the MPC-HC Team, copyright under GPLv2
* Contributions by Ti-BEN from the XBMC DSPlayer Project, also under GPLv2
*/
#pragma once
#include <vector>
#include <string>
#include "PacketQueue.h"
#include "StreamParser.h"
#include "moreuuids.h"
#include "LAVSplitter.h"
#include "ILAVPinInfo.h"
#include "IBitRateInfo.h"
class CLAVOutputPin
: public CBaseOutputPin
, public ILAVPinInfo
, public IBitRateInfo
, IMediaSeeking
, protected CAMThread
{
public:
CLAVOutputPin(std::vector<CMediaType>& mts, LPCWSTR pName, CBaseFilter *pFilter, CCritSec *pLock, HRESULT *phr, CBaseDemuxer::StreamType pinType = CBaseDemuxer::unknown,const char* container = "", bool bFirst = false);
virtual ~CLAVOutputPin();
DECLARE_IUNKNOWN;
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
// IQualityControl
STDMETHODIMP Notify(IBaseFilter* pSender, Quality q) { return E_NOTIMPL; }
// CBaseOutputPin
HRESULT DecideAllocator(IMemInputPin * pPin, IMemAllocator ** pAlloc);
HRESULT DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties);
HRESULT CheckMediaType(const CMediaType* pmt);
HRESULT GetMediaType(int iPosition, CMediaType* pmt);
HRESULT Active();
HRESULT Inactive();
STDMETHODIMP Connect(IPin * pReceivePin, const AM_MEDIA_TYPE *pmt);
HRESULT CompleteConnect(IPin *pReceivePin);
// IMediaSeeking
STDMETHODIMP GetCapabilities(DWORD* pCapabilities);
STDMETHODIMP CheckCapabilities(DWORD* pCapabilities);
STDMETHODIMP IsFormatSupported(const GUID* pFormat);
STDMETHODIMP QueryPreferredFormat(GUID* pFormat);
STDMETHODIMP GetTimeFormat(GUID* pFormat);
STDMETHODIMP IsUsingTimeFormat(const GUID* pFormat);
STDMETHODIMP SetTimeFormat(const GUID* pFormat);
STDMETHODIMP GetDuration(LONGLONG* pDuration);
STDMETHODIMP GetStopPosition(LONGLONG* pStop);
STDMETHODIMP GetCurrentPosition(LONGLONG* pCurrent);
STDMETHODIMP ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat);
STDMETHODIMP SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags);
STDMETHODIMP GetPositions(LONGLONG* pCurrent, LONGLONG* pStop);
STDMETHODIMP GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest);
STDMETHODIMP SetRate(double dRate);
STDMETHODIMP GetRate(double* pdRate);
STDMETHODIMP GetPreroll(LONGLONG* pllPreroll);
// ILAVPinInfo
STDMETHODIMP_(DWORD) GetStreamFlags();
STDMETHODIMP_(int) GetPixelFormat();
STDMETHODIMP_(int) GetVersion() { return 1; }
STDMETHODIMP_(int) GetHasBFrames();
// IBitRateInfo
STDMETHODIMP_(DWORD) GetCurrentBitRate() { return m_BitRate.nCurrentBitRate; }
STDMETHODIMP_(DWORD) GetAverageBitRate() { return m_BitRate.nAverageBitRate; }
size_t QueueCount();
HRESULT QueuePacket(Packet *pPacket);
HRESULT QueueEndOfStream();
bool IsDiscontinuous();
DWORD GetQueueLowLimit() const { return m_dwQueueLow; }
DWORD GetStreamId() { return m_streamId; };
void SetStreamId(DWORD newStreamId) { m_streamId = newStreamId; };
void SetNewMediaTypes(std::vector<CMediaType> pmts) { CAutoLock lock(&m_csMT); m_mts = pmts; SetQueueSizes(); }
void SendMediaType(CMediaType *mt) { CAutoLock lock(&m_csMT); m_newMT = mt;}
void SetStreamMediaType(CMediaType *mt) { CAutoLock lock(&m_csMT); m_StreamMT = *mt; }
CMediaType& GetActiveMediaType() { return m_mt; }
BOOL IsVideoPin() { return m_pinType == CBaseDemuxer::video; }
BOOL IsAudioPin() { return m_pinType == CBaseDemuxer::audio; }
BOOL IsSubtitlePin(){ return m_pinType == CBaseDemuxer::subpic; }
CBaseDemuxer::StreamType GetPinType() { return m_pinType; }
HRESULT QueueFromParser(Packet *pPacket) { m_queue.Queue(pPacket); return S_OK; }
HRESULT GetQueueSize(int& samples, int& size);
public:
// Packet handling functions
virtual HRESULT DeliverBeginFlush();
virtual HRESULT DeliverEndFlush();
virtual HRESULT DeliverNewSegment(REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
void SetQueueSizes();
REFERENCE_TIME m_rtPrev = AV_NOPTS_VALUE;
protected:
virtual HRESULT DeliverPacket(Packet *pPacket);
private:
enum {CMD_EXIT};
DWORD ThreadProc();
void MakeISCRHappy();
private:
CCritSec m_csMT;
std::vector<CMediaType> m_mts;
CPacketQueue m_queue;
CMediaType m_StreamMT;
std::string m_containerFormat;
bool m_bFirstPin = false;
// Flush control
bool m_fFlushing = false;
bool m_fFlushed = false;
CAMEvent m_eEndFlush{TRUE};
HRESULT m_hrDeliver = S_OK;
int m_nBuffers = 1;
DWORD m_dwQueueLow = MIN_PACKETS_IN_QUEUE;
DWORD m_dwQueueHigh = MAX_PACKETS_IN_QUEUE;
DWORD m_dwQueueMaxMem = 256;
DWORD m_streamId = 0;
CMediaType *m_newMT = nullptr;
CBaseDemuxer::StreamType m_pinType;
CStreamParser m_Parser;
BOOL m_bPacketAllocator = FALSE;
// IBitRateInfo
struct BitRateInfo {
UINT64 nTotalBytesDelivered = 0;
REFERENCE_TIME rtTotalTimeDelivered = 0;
UINT64 nBytesSinceLastDeliverTime = 0;
REFERENCE_TIME rtLastDeliverTime = Packet::INVALID_TIME;
DWORD nCurrentBitRate = 0;
DWORD nAverageBitRate = 0;
} m_BitRate;
};
|