diff options
author | XhmikosR <xhmikosr@users.sourceforge.net> | 2011-01-10 03:05:13 +0300 |
---|---|---|
committer | XhmikosR <xhmikosr@users.sourceforge.net> | 2011-01-10 03:05:13 +0300 |
commit | 0eb98dcebf3ff5c8fbdc1235474c0d5640f9a04c (patch) | |
tree | 65e403462fdb55541e4a98358c824aa8a15b8027 /src/filters/muxer | |
parent | 93411f0c1eef8de213410b0544b246dd7086be74 (diff) |
legacy branch: merge r2785-r2825,r2827 from trunk
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/branches/legacy@2830 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/filters/muxer')
-rw-r--r-- | src/filters/muxer/BaseMuxer/BaseMuxer.cpp | 259 | ||||
-rw-r--r-- | src/filters/muxer/BaseMuxer/BaseMuxerInputPin.cpp | 102 | ||||
-rw-r--r-- | src/filters/muxer/BaseMuxer/BaseMuxerInputPin.h | 3 | ||||
-rw-r--r-- | src/filters/muxer/BaseMuxer/BaseMuxerOutputPin.cpp | 235 | ||||
-rw-r--r-- | src/filters/muxer/BaseMuxer/BaseMuxerRelatedPin.h | 3 | ||||
-rw-r--r-- | src/filters/muxer/BaseMuxer/BitStream.cpp | 24 | ||||
-rw-r--r-- | src/filters/muxer/BaseMuxer/BitStream.h | 3 | ||||
-rw-r--r-- | src/filters/muxer/DSMMuxer/DSMMuxer.cpp | 123 | ||||
-rw-r--r-- | src/filters/muxer/MatroskaMuxer/MatroskaFile.cpp | 250 | ||||
-rw-r--r-- | src/filters/muxer/MatroskaMuxer/MatroskaFile.h | 730 | ||||
-rw-r--r-- | src/filters/muxer/MatroskaMuxer/MatroskaMuxer.cpp | 834 | ||||
-rw-r--r-- | src/filters/muxer/MatroskaMuxer/MatroskaMuxer.h | 3 | ||||
-rw-r--r-- | src/filters/muxer/WavDest/WavDest.cpp | 94 |
13 files changed, 1362 insertions, 1301 deletions
diff --git a/src/filters/muxer/BaseMuxer/BaseMuxer.cpp b/src/filters/muxer/BaseMuxer/BaseMuxer.cpp index fb596eaaa..4bcc3f90c 100644 --- a/src/filters/muxer/BaseMuxer/BaseMuxer.cpp +++ b/src/filters/muxer/BaseMuxer/BaseMuxer.cpp @@ -30,7 +30,9 @@ CBaseMuxerFilter::CBaseMuxerFilter(LPUNKNOWN pUnk, HRESULT* phr, const CLSID& cl : CBaseFilter(NAME("CBaseMuxerFilter"), pUnk, this, clsid)
, m_rtCurrent(0)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
m_pOutput.Attach(DNew CBaseMuxerOutputPin(L"Output", this, this, phr));
AddInput();
}
@@ -60,10 +62,11 @@ STDMETHODIMP CBaseMuxerFilter::NonDelegatingQueryInterface(REFIID riid, void** p void CBaseMuxerFilter::AddInput()
{
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBasePin* pPin = m_pInputs.GetNext(pos);
- if(!pPin->IsConnected()) return;
+ if(!pPin->IsConnected()) {
+ return;
+ }
}
CStringW name;
@@ -117,81 +120,77 @@ DWORD CBaseMuxerFilter::ThreadProc() POSITION pos;
- while(1)
- {
+ while(1) {
DWORD cmd = GetRequest();
- switch(cmd)
- {
- default:
- case CMD_EXIT:
- CAMThread::m_hThread = NULL;
- Reply(S_OK);
- return 0;
-
- case CMD_RUN:
- m_pActivePins.RemoveAll();
- m_pPins.RemoveAll();
-
- pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
- CBaseMuxerInputPin* pPin = m_pInputs.GetNext(pos);
- if(pPin->IsConnected())
- {
- m_pActivePins.AddTail(pPin);
- m_pPins.AddTail(pPin);
+ switch(cmd) {
+ default:
+ case CMD_EXIT:
+ CAMThread::m_hThread = NULL;
+ Reply(S_OK);
+ return 0;
+
+ case CMD_RUN:
+ m_pActivePins.RemoveAll();
+ m_pPins.RemoveAll();
+
+ pos = m_pInputs.GetHeadPosition();
+ while(pos) {
+ CBaseMuxerInputPin* pPin = m_pInputs.GetNext(pos);
+ if(pPin->IsConnected()) {
+ m_pActivePins.AddTail(pPin);
+ m_pPins.AddTail(pPin);
+ }
}
- }
- m_rtCurrent = 0;
+ m_rtCurrent = 0;
- Reply(S_OK);
+ Reply(S_OK);
- MuxInit();
+ MuxInit();
- try
- {
- MuxHeaderInternal();
+ try {
+ MuxHeaderInternal();
- while(!CheckRequest(NULL) && m_pActivePins.GetCount())
- {
- if(m_State == State_Paused) {
- Sleep(10);
- continue;
- }
+ while(!CheckRequest(NULL) && m_pActivePins.GetCount()) {
+ if(m_State == State_Paused) {
+ Sleep(10);
+ continue;
+ }
- CAutoPtr<MuxerPacket> pPacket = GetPacket();
- if(!pPacket) {
- Sleep(1);
- continue;
- }
+ CAutoPtr<MuxerPacket> pPacket = GetPacket();
+ if(!pPacket) {
+ Sleep(1);
+ continue;
+ }
- if(pPacket->IsTimeValid())
- m_rtCurrent = pPacket->rtStart;
+ if(pPacket->IsTimeValid()) {
+ m_rtCurrent = pPacket->rtStart;
+ }
- if(pPacket->IsEOS())
- m_pActivePins.RemoveAt(m_pActivePins.Find(pPacket->pPin));
+ if(pPacket->IsEOS()) {
+ m_pActivePins.RemoveAt(m_pActivePins.Find(pPacket->pPin));
+ }
- MuxPacketInternal(pPacket);
- }
+ MuxPacketInternal(pPacket);
+ }
- MuxFooterInternal();
- }
- catch(HRESULT hr)
- {
- CComQIPtr<IMediaEventSink>(m_pGraph)->Notify(EC_ERRORABORT, hr, 0);
- }
+ MuxFooterInternal();
+ } catch(HRESULT hr) {
+ CComQIPtr<IMediaEventSink>(m_pGraph)->Notify(EC_ERRORABORT, hr, 0);
+ }
- m_pOutput->DeliverEndOfStream();
+ m_pOutput->DeliverEndOfStream();
- pos = m_pRawOutputs.GetHeadPosition();
- while(pos) m_pRawOutputs.GetNext(pos)->DeliverEndOfStream();
+ pos = m_pRawOutputs.GetHeadPosition();
+ while(pos) {
+ m_pRawOutputs.GetNext(pos)->DeliverEndOfStream();
+ }
- m_pActivePins.RemoveAll();
- m_pPins.RemoveAll();
+ m_pActivePins.RemoveAll();
+ m_pPins.RemoveAll();
- break;
+ break;
}
}
@@ -205,19 +204,20 @@ void CBaseMuxerFilter::MuxHeaderInternal() {
TRACE(_T("MuxHeader\n"));
- if(CComQIPtr<IBitStream> pBitStream = m_pOutput->GetBitStream())
+ if(CComQIPtr<IBitStream> pBitStream = m_pOutput->GetBitStream()) {
MuxHeader(pBitStream);
+ }
MuxHeader();
//
POSITION pos = m_pPins.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
if(CBaseMuxerInputPin* pInput = m_pPins.GetNext(pos))
- if(CBaseMuxerRawOutputPin* pOutput = dynamic_cast<CBaseMuxerRawOutputPin*>(pInput->GetRelatedPin()))
+ if(CBaseMuxerRawOutputPin* pOutput = dynamic_cast<CBaseMuxerRawOutputPin*>(pInput->GetRelatedPin())) {
pOutput->MuxHeader(pInput->CurrentMediaType());
+ }
}
}
@@ -231,33 +231,36 @@ void CBaseMuxerFilter::MuxPacketInternal(const MuxerPacket* pPacket) !!(pPacket->flags & MuxerPacket::bogus),
pPacket->rtStart/10000, pPacket->rtStop/10000);
- if(CComQIPtr<IBitStream> pBitStream = m_pOutput->GetBitStream())
+ if(CComQIPtr<IBitStream> pBitStream = m_pOutput->GetBitStream()) {
MuxPacket(pBitStream, pPacket);
+ }
MuxPacket(pPacket);
if(CBaseMuxerInputPin* pInput = pPacket->pPin)
- if(CBaseMuxerRawOutputPin* pOutput = dynamic_cast<CBaseMuxerRawOutputPin*>(pInput->GetRelatedPin()))
+ if(CBaseMuxerRawOutputPin* pOutput = dynamic_cast<CBaseMuxerRawOutputPin*>(pInput->GetRelatedPin())) {
pOutput->MuxPacket(pInput->CurrentMediaType(), pPacket);
+ }
}
void CBaseMuxerFilter::MuxFooterInternal()
{
TRACE(_T("MuxFooter\n"));
- if(CComQIPtr<IBitStream> pBitStream = m_pOutput->GetBitStream())
+ if(CComQIPtr<IBitStream> pBitStream = m_pOutput->GetBitStream()) {
MuxFooter(pBitStream);
+ }
MuxFooter();
//
POSITION pos = m_pPins.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
if(CBaseMuxerInputPin* pInput = m_pPins.GetNext(pos))
- if(CBaseMuxerRawOutputPin* pOutput = dynamic_cast<CBaseMuxerRawOutputPin*>(pInput->GetRelatedPin()))
+ if(CBaseMuxerRawOutputPin* pOutput = dynamic_cast<CBaseMuxerRawOutputPin*>(pInput->GetRelatedPin())) {
pOutput->MuxFooter(pInput->CurrentMediaType());
+ }
}
}
@@ -268,24 +271,23 @@ CAutoPtr<MuxerPacket> CBaseMuxerFilter::GetPacket() int i = int(m_pActivePins.GetCount());
POSITION pos = m_pActivePins.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBaseMuxerInputPin* pPin = m_pActivePins.GetNext(pos);
CAutoLock cAutoLock(&pPin->m_csQueue);
- if(!pPin->m_queue.GetCount()) continue;
+ if(!pPin->m_queue.GetCount()) {
+ continue;
+ }
MuxerPacket* p = pPin->m_queue.GetHead();
- if(p->IsBogus() || !p->IsTimeValid() || p->IsEOS())
- {
+ if(p->IsBogus() || !p->IsTimeValid() || p->IsEOS()) {
pPinMin = pPin;
i = 0;
break;
}
- if(p->rtStart < rtMin)
- {
+ if(p->rtStart < rtMin) {
rtMin = p->rtStart;
pPinMin = pPin;
}
@@ -295,14 +297,13 @@ CAutoPtr<MuxerPacket> CBaseMuxerFilter::GetPacket() CAutoPtr<MuxerPacket> pPacket;
- if(pPinMin && i == 0)
- {
+ if(pPinMin && i == 0) {
pPacket = pPinMin->PopPacket();
- }
- else
- {
+ } else {
pos = m_pActivePins.GetHeadPosition();
- while(pos) m_pActivePins.GetNext(pos)->m_evAcceptPacket.Set();
+ while(pos) {
+ m_pActivePins.GetNext(pos)->m_evAcceptPacket.Set();
+ }
}
return pPacket;
@@ -319,25 +320,24 @@ CBasePin* CBaseMuxerFilter::GetPin(int n) {
CAutoLock cAutoLock(this);
- if(n >= 0 && n < (int)m_pInputs.GetCount())
- {
- if(POSITION pos = m_pInputs.FindIndex(n))
+ if(n >= 0 && n < (int)m_pInputs.GetCount()) {
+ if(POSITION pos = m_pInputs.FindIndex(n)) {
return m_pInputs.GetAt(pos);
+ }
}
n -= int(m_pInputs.GetCount());
- if(n == 0 && m_pOutput)
- {
+ if(n == 0 && m_pOutput) {
return m_pOutput;
}
n--;
- if(n >= 0 && n < (int)m_pRawOutputs.GetCount())
- {
- if(POSITION pos = m_pRawOutputs.FindIndex(n))
+ if(n >= 0 && n < (int)m_pRawOutputs.GetCount()) {
+ if(POSITION pos = m_pRawOutputs.FindIndex(n)) {
return m_pRawOutputs.GetAt(pos);
+ }
}
n -= int(m_pRawOutputs.GetCount());
@@ -350,7 +350,9 @@ STDMETHODIMP CBaseMuxerFilter::Stop() CAutoLock cAutoLock(this);
HRESULT hr = __super::Stop();
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
CallWorker(CMD_EXIT);
@@ -364,10 +366,11 @@ STDMETHODIMP CBaseMuxerFilter::Pause() FILTER_STATE fs = m_State;
HRESULT hr = __super::Pause();
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
- if(fs == State_Stopped && m_pOutput)
- {
+ if(fs == State_Stopped && m_pOutput) {
CAMThread::Create();
CallWorker(CMD_RUN);
}
@@ -380,7 +383,9 @@ STDMETHODIMP CBaseMuxerFilter::Run(REFERENCE_TIME tStart) CAutoLock cAutoLock(this);
HRESULT hr = __super::Run(tStart);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
return hr;
}
@@ -394,25 +399,32 @@ STDMETHODIMP CBaseMuxerFilter::GetCapabilities(DWORD* pCapabilities) STDMETHODIMP CBaseMuxerFilter::CheckCapabilities(DWORD* pCapabilities)
{
CheckPointer(pCapabilities, E_POINTER);
- if(*pCapabilities == 0) return S_OK;
+ if(*pCapabilities == 0) {
+ return S_OK;
+ }
DWORD caps;
GetCapabilities(&caps);
caps &= *pCapabilities;
return caps == 0 ? E_FAIL : caps == *pCapabilities ? S_OK : S_FALSE;
}
-STDMETHODIMP CBaseMuxerFilter::IsFormatSupported(const GUID* pFormat) {
+STDMETHODIMP CBaseMuxerFilter::IsFormatSupported(const GUID* pFormat)
+{
return !pFormat ? E_POINTER : *pFormat == TIME_FORMAT_MEDIA_TIME ? S_OK : S_FALSE;
}
-STDMETHODIMP CBaseMuxerFilter::QueryPreferredFormat(GUID* pFormat) {
+STDMETHODIMP CBaseMuxerFilter::QueryPreferredFormat(GUID* pFormat)
+{
return GetTimeFormat(pFormat);
}
-STDMETHODIMP CBaseMuxerFilter::GetTimeFormat(GUID* pFormat) {
+STDMETHODIMP CBaseMuxerFilter::GetTimeFormat(GUID* pFormat)
+{
return pFormat ? *pFormat = TIME_FORMAT_MEDIA_TIME, S_OK : E_POINTER;
}
-STDMETHODIMP CBaseMuxerFilter::IsUsingTimeFormat(const GUID* pFormat) {
+STDMETHODIMP CBaseMuxerFilter::IsUsingTimeFormat(const GUID* pFormat)
+{
return IsFormatSupported(pFormat);
}
-STDMETHODIMP CBaseMuxerFilter::SetTimeFormat(const GUID* pFormat) {
+STDMETHODIMP CBaseMuxerFilter::SetTimeFormat(const GUID* pFormat)
+{
return S_OK == IsFormatSupported(pFormat) ? S_OK : E_INVALIDARG;
}
STDMETHODIMP CBaseMuxerFilter::GetDuration(LONGLONG* pDuration)
@@ -422,11 +434,14 @@ STDMETHODIMP CBaseMuxerFilter::GetDuration(LONGLONG* pDuration) POSITION pos = m_pInputs.GetHeadPosition();
while(pos) {
REFERENCE_TIME rt = m_pInputs.GetNext(pos)->GetDuration();
- if(rt > *pDuration) *pDuration = rt;
+ if(rt > *pDuration) {
+ *pDuration = rt;
+ }
}
return S_OK;
}
-STDMETHODIMP CBaseMuxerFilter::GetStopPosition(LONGLONG* pStop) {
+STDMETHODIMP CBaseMuxerFilter::GetStopPosition(LONGLONG* pStop)
+{
return E_NOTIMPL;
}
STDMETHODIMP CBaseMuxerFilter::GetCurrentPosition(LONGLONG* pCurrent)
@@ -435,22 +450,25 @@ STDMETHODIMP CBaseMuxerFilter::GetCurrentPosition(LONGLONG* pCurrent) *pCurrent = m_rtCurrent;
return S_OK;
}
-STDMETHODIMP CBaseMuxerFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) {
+STDMETHODIMP CBaseMuxerFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat)
+{
return E_NOTIMPL;
}
STDMETHODIMP CBaseMuxerFilter::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags)
{
FILTER_STATE fs;
- if(SUCCEEDED(GetState(0, &fs)) && fs == State_Stopped)
- {
+ if(SUCCEEDED(GetState(0, &fs)) && fs == State_Stopped) {
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBasePin* pPin = m_pInputs.GetNext(pos);
CComQIPtr<IMediaSeeking> pMS = pPin->GetConnected();
- if(!pMS) pMS = GetFilterFromPin(pPin->GetConnected());
- if(pMS) pMS->SetPositions(pCurrent, dwCurrentFlags, pStop, dwStopFlags);
+ if(!pMS) {
+ pMS = GetFilterFromPin(pPin->GetConnected());
+ }
+ if(pMS) {
+ pMS->SetPositions(pCurrent, dwCurrentFlags, pStop, dwStopFlags);
+ }
}
return S_OK;
@@ -458,18 +476,23 @@ STDMETHODIMP CBaseMuxerFilter::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentF return VFW_E_WRONG_STATE;
}
-STDMETHODIMP CBaseMuxerFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop) {
+STDMETHODIMP CBaseMuxerFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CBaseMuxerFilter::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest) {
+STDMETHODIMP CBaseMuxerFilter::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CBaseMuxerFilter::SetRate(double dRate) {
+STDMETHODIMP CBaseMuxerFilter::SetRate(double dRate)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CBaseMuxerFilter::GetRate(double* pdRate) {
+STDMETHODIMP CBaseMuxerFilter::GetRate(double* pdRate)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CBaseMuxerFilter::GetPreroll(LONGLONG* pllPreroll) {
+STDMETHODIMP CBaseMuxerFilter::GetPreroll(LONGLONG* pllPreroll)
+{
return E_NOTIMPL;
}
diff --git a/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.cpp b/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.cpp index abfb8923e..e100bfe81 100644 --- a/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.cpp +++ b/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.cpp @@ -68,17 +68,21 @@ void CBaseMuxerInputPin::PushPacket(CAutoPtr<MuxerPacket> pPacket) for(int i = 0; m_pFilter->IsActive() && !m_bFlushing
&& !m_evAcceptPacket.Wait(1)
&& i < 1000;
- i++);
+ i++) {
+ ;
+ }
- if(!m_pFilter->IsActive() || m_bFlushing)
+ if(!m_pFilter->IsActive() || m_bFlushing) {
return;
+ }
CAutoLock cAutoLock(&m_csQueue);
m_queue.AddTail(pPacket);
- if(m_queue.GetCount() >= MAXQUEUESIZE)
+ if(m_queue.GetCount() >= MAXQUEUESIZE) {
m_evAcceptPacket.Reset();
+ }
}
CAutoPtr<MuxerPacket> CBaseMuxerInputPin::PopPacket()
@@ -87,46 +91,48 @@ CAutoPtr<MuxerPacket> CBaseMuxerInputPin::PopPacket() CAutoLock cAutoLock(&m_csQueue);
- if(m_queue.GetCount())
+ if(m_queue.GetCount()) {
pPacket = m_queue.RemoveHead();
+ }
- if(m_queue.GetCount() < MAXQUEUESIZE)
+ if(m_queue.GetCount() < MAXQUEUESIZE) {
m_evAcceptPacket.Set();
+ }
return pPacket;
}
HRESULT CBaseMuxerInputPin::CheckMediaType(const CMediaType* pmt)
{
- if(pmt->formattype == FORMAT_WaveFormatEx)
- {
+ if(pmt->formattype == FORMAT_WaveFormatEx) {
WORD wFormatTag = ((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag;
if((wFormatTag == WAVE_FORMAT_PCM
- || wFormatTag == WAVE_FORMAT_EXTENSIBLE
- || wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
- && pmt->subtype != FOURCCMap(wFormatTag)
- && !(pmt->subtype == MEDIASUBTYPE_PCM && wFormatTag == WAVE_FORMAT_EXTENSIBLE)
- && !(pmt->subtype == MEDIASUBTYPE_PCM && wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
- && pmt->subtype != MEDIASUBTYPE_DVD_LPCM_AUDIO
- && pmt->subtype != MEDIASUBTYPE_DOLBY_AC3
- && pmt->subtype != MEDIASUBTYPE_DTS)
- {
+ || wFormatTag == WAVE_FORMAT_EXTENSIBLE
+ || wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
+ && pmt->subtype != FOURCCMap(wFormatTag)
+ && !(pmt->subtype == MEDIASUBTYPE_PCM && wFormatTag == WAVE_FORMAT_EXTENSIBLE)
+ && !(pmt->subtype == MEDIASUBTYPE_PCM && wFormatTag == WAVE_FORMAT_IEEE_FLOAT)
+ && pmt->subtype != MEDIASUBTYPE_DVD_LPCM_AUDIO
+ && pmt->subtype != MEDIASUBTYPE_DOLBY_AC3
+ && pmt->subtype != MEDIASUBTYPE_DTS) {
return E_INVALIDARG;
}
}
return pmt->majortype == MEDIATYPE_Video
- || pmt->majortype == MEDIATYPE_Audio && pmt->formattype != FORMAT_VorbisFormat
- || pmt->majortype == MEDIATYPE_Text && pmt->subtype == MEDIASUBTYPE_NULL && pmt->formattype == FORMAT_None
- || pmt->majortype == MEDIATYPE_Subtitle
- ? S_OK
- : E_INVALIDARG;
+ || pmt->majortype == MEDIATYPE_Audio && pmt->formattype != FORMAT_VorbisFormat
+ || pmt->majortype == MEDIATYPE_Text && pmt->subtype == MEDIASUBTYPE_NULL && pmt->formattype == FORMAT_None
+ || pmt->majortype == MEDIATYPE_Subtitle
+ ? S_OK
+ : E_INVALIDARG;
}
HRESULT CBaseMuxerInputPin::BreakConnect()
{
HRESULT hr = __super::BreakConnect();
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
RemoveAll();
@@ -138,36 +144,37 @@ HRESULT CBaseMuxerInputPin::BreakConnect() HRESULT CBaseMuxerInputPin::CompleteConnect(IPin* pReceivePin)
{
HRESULT hr = __super::CompleteConnect(pReceivePin);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
// duration
m_rtDuration = 0;
CComQIPtr<IMediaSeeking> pMS;
- if((pMS = GetFilterFromPin(pReceivePin)) || (pMS = pReceivePin))
+ if((pMS = GetFilterFromPin(pReceivePin)) || (pMS = pReceivePin)) {
pMS->GetDuration(&m_rtDuration);
+ }
// properties
- for(CComPtr<IPin> pPin = pReceivePin; pPin; pPin = GetUpStreamPin(GetFilterFromPin(pPin)))
- {
- if(CComQIPtr<IDSMPropertyBag> pPB = pPin)
- {
+ for(CComPtr<IPin> pPin = pReceivePin; pPin; pPin = GetUpStreamPin(GetFilterFromPin(pPin))) {
+ if(CComQIPtr<IDSMPropertyBag> pPB = pPin) {
ULONG cProperties = 0;
- if(SUCCEEDED(pPB->CountProperties(&cProperties)) && cProperties > 0)
- {
- for(ULONG iProperty = 0; iProperty < cProperties; iProperty++)
- {
+ if(SUCCEEDED(pPB->CountProperties(&cProperties)) && cProperties > 0) {
+ for(ULONG iProperty = 0; iProperty < cProperties; iProperty++) {
PROPBAG2 PropBag;
memset(&PropBag, 0, sizeof(PropBag));
ULONG cPropertiesReturned = 0;
- if(FAILED(pPB->GetPropertyInfo(iProperty, 1, &PropBag, &cPropertiesReturned)))
+ if(FAILED(pPB->GetPropertyInfo(iProperty, 1, &PropBag, &cPropertiesReturned))) {
continue;
+ }
HRESULT hr;
CComVariant var;
- if(SUCCEEDED(pPB->Read(1, &PropBag, NULL, &var, &hr)) && SUCCEEDED(hr))
+ if(SUCCEEDED(pPB->Read(1, &PropBag, NULL, &var, &hr)) && SUCCEEDED(hr)) {
SetProperty(PropBag.pstrName, &var);
+ }
CoTaskMemFree(PropBag.pstrName);
}
@@ -208,47 +215,44 @@ STDMETHODIMP CBaseMuxerInputPin::Receive(IMediaSample* pSample) CAutoLock cAutoLock(&m_csReceive);
HRESULT hr = __super::Receive(pSample);
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
CAutoPtr<MuxerPacket> pPacket(DNew MuxerPacket(this));
long len = pSample->GetActualDataLength();
BYTE* pData = NULL;
- if(FAILED(pSample->GetPointer(&pData)) || !pData)
+ if(FAILED(pSample->GetPointer(&pData)) || !pData) {
return S_OK;
+ }
pPacket->pData.SetCount(len);
memcpy(pPacket->pData.GetData(), pData, len);
- if(S_OK == pSample->IsSyncPoint() || m_mt.majortype == MEDIATYPE_Audio && !m_mt.bTemporalCompression)
- {
+ if(S_OK == pSample->IsSyncPoint() || m_mt.majortype == MEDIATYPE_Audio && !m_mt.bTemporalCompression) {
pPacket->flags |= MuxerPacket::syncpoint;
}
- if(S_OK == pSample->GetTime(&pPacket->rtStart, &pPacket->rtStop))
- {
+ if(S_OK == pSample->GetTime(&pPacket->rtStart, &pPacket->rtStop)) {
pPacket->flags |= MuxerPacket::timevalid;
pPacket->rtStart += m_tStart;
pPacket->rtStop += m_tStart;
- if((pPacket->flags & MuxerPacket::syncpoint) && pPacket->rtStart < m_rtMaxStart)
- {
+ if((pPacket->flags & MuxerPacket::syncpoint) && pPacket->rtStart < m_rtMaxStart) {
pPacket->flags &= ~MuxerPacket::syncpoint;
pPacket->flags |= MuxerPacket::bogus;
}
m_rtMaxStart = max(m_rtMaxStart, pPacket->rtStart);
- }
- else if(pPacket->flags & MuxerPacket::syncpoint)
- {
+ } else if(pPacket->flags & MuxerPacket::syncpoint) {
pPacket->flags &= ~MuxerPacket::syncpoint;
pPacket->flags |= MuxerPacket::bogus;
}
- if(S_OK == pSample->IsDiscontinuity())
- {
+ if(S_OK == pSample->IsDiscontinuity()) {
pPacket->flags |= MuxerPacket::discontinuity;
}
@@ -264,7 +268,9 @@ STDMETHODIMP CBaseMuxerInputPin::EndOfStream() CAutoLock cAutoLock(&m_csReceive);
HRESULT hr = __super::EndOfStream();
- if(FAILED(hr)) return hr;
+ if(FAILED(hr)) {
+ return hr;
+ }
ASSERT(!m_fEOS);
diff --git a/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.h b/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.h index 1ae51ae1d..788c00b03 100644 --- a/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.h +++ b/src/filters/muxer/BaseMuxer/BaseMuxerInputPin.h @@ -26,8 +26,7 @@ class CBaseMuxerInputPin;
-struct MuxerPacket
-{
+struct MuxerPacket {
CBaseMuxerInputPin* pPin;
REFERENCE_TIME rtStart, rtStop;
CAtlArray<BYTE> pData;
diff --git a/src/filters/muxer/BaseMuxer/BaseMuxerOutputPin.cpp b/src/filters/muxer/BaseMuxer/BaseMuxerOutputPin.cpp index 108549d91..45d32cd11 100644 --- a/src/filters/muxer/BaseMuxer/BaseMuxerOutputPin.cpp +++ b/src/filters/muxer/BaseMuxer/BaseMuxerOutputPin.cpp @@ -40,10 +40,8 @@ CBaseMuxerOutputPin::CBaseMuxerOutputPin(LPCWSTR pName, CBaseFilter* pFilter, CC IBitStream* CBaseMuxerOutputPin::GetBitStream()
{
- if(!m_pBitStream)
- {
- if(CComQIPtr<IStream> pStream = GetConnected())
- {
+ if(!m_pBitStream) {
+ if(CComQIPtr<IStream> pStream = GetConnected()) {
m_pBitStream = DNew CBitStream(pStream, true);
}
}
@@ -69,9 +67,13 @@ HRESULT CBaseMuxerOutputPin::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_P pProperties->cbBuffer = 1;
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
+ if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) {
+ return hr;
+ }
- if(Actual.cbBuffer < pProperties->cbBuffer) return E_FAIL;
+ if(Actual.cbBuffer < pProperties->cbBuffer) {
+ return E_FAIL;
+ }
ASSERT(Actual.cBuffers == pProperties->cBuffers);
return NOERROR;
@@ -88,8 +90,12 @@ HRESULT CBaseMuxerOutputPin::GetMediaType(int iPosition, CMediaType* pmt) {
CAutoLock cAutoLock(m_pLock);
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
pmt->ResetFormatBuffer();
pmt->InitMediaType();
@@ -133,59 +139,50 @@ STDMETHODIMP CBaseMuxerRawOutputPin::NonDelegatingQueryInterface(REFIID riid, vo void CBaseMuxerRawOutputPin::MuxHeader(const CMediaType& mt)
{
CComQIPtr<IBitStream> pBitStream = GetBitStream();
- if(!pBitStream) return;
+ if(!pBitStream) {
+ return;
+ }
const BYTE utf8bom[3] = {0xef, 0xbb, 0xbf};
- if((mt.subtype == FOURCCMap('1CVA') || mt.subtype == FOURCCMap('1cva')) && mt.formattype == FORMAT_MPEG2_VIDEO)
- {
+ if((mt.subtype == FOURCCMap('1CVA') || mt.subtype == FOURCCMap('1cva')) && mt.formattype == FORMAT_MPEG2_VIDEO) {
MPEG2VIDEOINFO* vih = (MPEG2VIDEOINFO*)mt.Format();
- for(DWORD i = 0; i < vih->cbSequenceHeader-2; i += 2)
- {
+ for(DWORD i = 0; i < vih->cbSequenceHeader-2; i += 2) {
pBitStream->BitWrite(0x00000001, 32);
WORD size = (((BYTE*)vih->dwSequenceHeader)[i+0]<<8) | ((BYTE*)vih->dwSequenceHeader)[i+1];
pBitStream->ByteWrite(&((BYTE*)vih->dwSequenceHeader)[i+2], size);
i += size;
}
- }
- else if(mt.subtype == MEDIASUBTYPE_UTF8)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_UTF8) {
pBitStream->ByteWrite(utf8bom, sizeof(utf8bom));
- }
- else if(mt.subtype == MEDIASUBTYPE_SSA || mt.subtype == MEDIASUBTYPE_ASS || mt.subtype == MEDIASUBTYPE_ASS2)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_SSA || mt.subtype == MEDIASUBTYPE_ASS || mt.subtype == MEDIASUBTYPE_ASS2) {
SUBTITLEINFO* si = (SUBTITLEINFO*)mt.Format();
BYTE* p = (BYTE*)si + si->dwOffset;
- if(memcmp(utf8bom, p, 3) != 0)
+ if(memcmp(utf8bom, p, 3) != 0) {
pBitStream->ByteWrite(utf8bom, sizeof(utf8bom));
+ }
CStringA str((char*)p, mt.FormatLength() - (p - mt.Format()));
pBitStream->StrWrite(str + '\n', true);
- if(str.Find("[Events]") < 0)
+ if(str.Find("[Events]") < 0) {
pBitStream->StrWrite("\n\n[Events]\n", true);
- }
- else if(mt.subtype == MEDIASUBTYPE_SSF)
- {
+ }
+ } else if(mt.subtype == MEDIASUBTYPE_SSF) {
DWORD dwOffset = ((SUBTITLEINFO*)mt.pbFormat)->dwOffset;
try {
m_ssf.Parse(ssf::MemoryInputStream(mt.pbFormat + dwOffset, mt.cbFormat - dwOffset, false, false));
- }
- catch(ssf::Exception&) {}
- }
- else if(mt.subtype == MEDIASUBTYPE_VOBSUB)
- {
+ } catch(ssf::Exception&) {}
+ } else if(mt.subtype == MEDIASUBTYPE_VOBSUB) {
m_idx.RemoveAll();
- }
- else if(mt.majortype == MEDIATYPE_Audio
- && (mt.subtype == MEDIASUBTYPE_PCM
- || mt.subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO
- || mt.subtype == FOURCCMap(WAVE_FORMAT_EXTENSIBLE)
- || mt.subtype == FOURCCMap(WAVE_FORMAT_IEEE_FLOAT))
- && mt.formattype == FORMAT_WaveFormatEx)
- {
+ } else if(mt.majortype == MEDIATYPE_Audio
+ && (mt.subtype == MEDIASUBTYPE_PCM
+ || mt.subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO
+ || mt.subtype == FOURCCMap(WAVE_FORMAT_EXTENSIBLE)
+ || mt.subtype == FOURCCMap(WAVE_FORMAT_IEEE_FLOAT))
+ && mt.formattype == FORMAT_WaveFormatEx) {
pBitStream->BitWrite('RIFF', 32);
pBitStream->BitWrite(0, 32); // file length - 8, set later
pBitStream->BitWrite('WAVE', 32);
@@ -202,34 +199,46 @@ void CBaseMuxerRawOutputPin::MuxHeader(const CMediaType& mt) void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket* pPacket)
{
CComQIPtr<IBitStream> pBitStream = GetBitStream();
- if(!pBitStream) return;
+ if(!pBitStream) {
+ return;
+ }
const BYTE* pData = pPacket->pData.GetData();
const int DataSize = int(pPacket->pData.GetCount());
- if(mt.subtype == MEDIASUBTYPE_AAC && mt.formattype == FORMAT_WaveFormatEx)
- {
+ if(mt.subtype == MEDIASUBTYPE_AAC && mt.formattype == FORMAT_WaveFormatEx) {
WAVEFORMATEX* wfe = (WAVEFORMATEX*)mt.Format();
int profile = 0;
int srate_idx = 11;
- if(92017 <= wfe->nSamplesPerSec) srate_idx = 0;
- else if(75132 <= wfe->nSamplesPerSec) srate_idx = 1;
- else if(55426 <= wfe->nSamplesPerSec) srate_idx = 2;
- else if(46009 <= wfe->nSamplesPerSec) srate_idx = 3;
- else if(37566 <= wfe->nSamplesPerSec) srate_idx = 4;
- else if(27713 <= wfe->nSamplesPerSec) srate_idx = 5;
- else if(23004 <= wfe->nSamplesPerSec) srate_idx = 6;
- else if(18783 <= wfe->nSamplesPerSec) srate_idx = 7;
- else if(13856 <= wfe->nSamplesPerSec) srate_idx = 8;
- else if(11502 <= wfe->nSamplesPerSec) srate_idx = 9;
- else if(9391 <= wfe->nSamplesPerSec) srate_idx = 10;
+ if(92017 <= wfe->nSamplesPerSec) {
+ srate_idx = 0;
+ } else if(75132 <= wfe->nSamplesPerSec) {
+ srate_idx = 1;
+ } else if(55426 <= wfe->nSamplesPerSec) {
+ srate_idx = 2;
+ } else if(46009 <= wfe->nSamplesPerSec) {
+ srate_idx = 3;
+ } else if(37566 <= wfe->nSamplesPerSec) {
+ srate_idx = 4;
+ } else if(27713 <= wfe->nSamplesPerSec) {
+ srate_idx = 5;
+ } else if(23004 <= wfe->nSamplesPerSec) {
+ srate_idx = 6;
+ } else if(18783 <= wfe->nSamplesPerSec) {
+ srate_idx = 7;
+ } else if(13856 <= wfe->nSamplesPerSec) {
+ srate_idx = 8;
+ } else if(11502 <= wfe->nSamplesPerSec) {
+ srate_idx = 9;
+ } else if(9391 <= wfe->nSamplesPerSec) {
+ srate_idx = 10;
+ }
int channels = wfe->nChannels;
- if(wfe->cbSize >= 2)
- {
+ if(wfe->cbSize >= 2) {
BYTE* p = (BYTE*)(wfe+1);
profile = (p[0]>>3)-1;
srate_idx = ((p[0]&7)<<1)|((p[1]&0x80)>>7);
@@ -246,27 +255,22 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket* hdr[6] = 0xfc;
pBitStream->ByteWrite(hdr, sizeof(hdr));
- }
- else if((mt.subtype == FOURCCMap('1CVA') || mt.subtype == FOURCCMap('1cva')) && mt.formattype == FORMAT_MPEG2_VIDEO)
- {
+ } else if((mt.subtype == FOURCCMap('1CVA') || mt.subtype == FOURCCMap('1cva')) && mt.formattype == FORMAT_MPEG2_VIDEO) {
const BYTE* p = pData;
int i = DataSize;
- while(i >= 4)
- {
+ while(i >= 4) {
DWORD len = (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
i -= len + 4;
p += len + 4;
}
- if(i == 0)
- {
+ if(i == 0) {
p = pData;
i = DataSize;
- while(i >= 4)
- {
+ while(i >= 4) {
DWORD len = (p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3];
pBitStream->BitWrite(0x00000001, 32);
@@ -287,12 +291,12 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket* return;
}
- }
- else if(mt.subtype == MEDIASUBTYPE_UTF8 || mt.majortype == MEDIATYPE_Text)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_UTF8 || mt.majortype == MEDIATYPE_Text) {
CStringA str((char*)pData, DataSize);
str.Trim();
- if(str.IsEmpty()) return;
+ if(str.IsEmpty()) {
+ return;
+ }
DVD_HMSF_TIMECODE start = RT2HMSF(pPacket->rtStart, 25);
DVD_HMSF_TIMECODE stop = RT2HMSF(pPacket->rtStop, 25);
@@ -306,12 +310,12 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket* pBitStream->StrWrite(str, true);
return;
- }
- else if(mt.subtype == MEDIASUBTYPE_SSA || mt.subtype == MEDIASUBTYPE_ASS || mt.subtype == MEDIASUBTYPE_ASS2)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_SSA || mt.subtype == MEDIASUBTYPE_ASS || mt.subtype == MEDIASUBTYPE_ASS2) {
CStringA str((char*)pData, DataSize);
str.Trim();
- if(str.IsEmpty()) return;
+ if(str.IsEmpty()) {
+ return;
+ }
DVD_HMSF_TIMECODE start = RT2HMSF(pPacket->rtStart, 25);
DVD_HMSF_TIMECODE stop = RT2HMSF(pPacket->rtStop, 25);
@@ -320,7 +324,9 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket* CAtlList<CStringA> sl;
Explode(str, sl, ',', fields);
- if(sl.GetCount() < fields) return;
+ if(sl.GetCount() < fields) {
+ return;
+ }
CStringA readorder = sl.RemoveHead(); // TODO
CStringA layer = sl.RemoveHead();
@@ -329,11 +335,15 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket* CStringA left = sl.RemoveHead();
CStringA right = sl.RemoveHead();
CStringA top = sl.RemoveHead();
- if(fields == 10) top += ',' + sl.RemoveHead(); // bottom
+ if(fields == 10) {
+ top += ',' + sl.RemoveHead(); // bottom
+ }
CStringA effect = sl.RemoveHead();
str = sl.RemoveHead();
- if(mt.subtype == MEDIASUBTYPE_SSA) layer = "Marked=0";
+ if(mt.subtype == MEDIASUBTYPE_SSA) {
+ layer = "Marked=0";
+ }
str.Format("Dialogue: %s,%d:%02d:%02d.%02d,%d:%02d:%02d.%02d,%s,%s,%s,%s,%s,%s,%s\n",
layer,
@@ -345,20 +355,15 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket* pBitStream->StrWrite(str, true);
return;
- }
- else if(mt.subtype == MEDIASUBTYPE_SSF)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_SSF) {
float start = (float)pPacket->rtStart / 10000000;
float stop = (float)pPacket->rtStop / 10000000;
m_ssf.Append(ssf::WCharInputStream(UTF8To16(CStringA((char*)pData, DataSize))), start, stop, true);
return;
- }
- else if(mt.subtype == MEDIASUBTYPE_VOBSUB)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_VOBSUB) {
bool fTimeValid = pPacket->IsTimeValid();
- if(fTimeValid)
- {
+ if(fTimeValid) {
idx_t i;
i.rt = pPacket->rtStart;
i.fp = pBitStream->GetPos();
@@ -367,8 +372,7 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket* int DataSizeLeft = DataSize;
- while(DataSizeLeft > 0)
- {
+ while(DataSizeLeft > 0) {
int BytesAvail = 0x7ec - (fTimeValid ? 9 : 4);
int Size = min(BytesAvail, DataSizeLeft);
int Padding = 0x800 - Size - 20 - (fTimeValid ? 9 : 4);
@@ -378,13 +382,10 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket* pBitStream->BitWrite(0x000003f8, 32);
pBitStream->BitWrite(0x000001bd, 32);
- if(fTimeValid)
- {
+ if(fTimeValid) {
pBitStream->BitWrite(Size+9, 16);
pBitStream->BitWrite(0x8180052100010001ui64, 64);
- }
- else
- {
+ } else {
pBitStream->BitWrite(Size+4, 16);
pBitStream->BitWrite(0x810000, 24);
}
@@ -396,28 +397,28 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket* pData += Size;
DataSizeLeft -= Size;
- if(Padding > 0)
- {
+ if(Padding > 0) {
Padding -= 6;
ASSERT(Padding >= 0);
pBitStream->BitWrite(0x000001be, 32);
pBitStream->BitWrite(Padding, 16);
- while(Padding-- > 0) pBitStream->BitWrite(0xff, 8);
+ while(Padding-- > 0) {
+ pBitStream->BitWrite(0xff, 8);
+ }
}
fTimeValid = false;
}
return;
- }
- else if(mt.subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO) {
WAVEFORMATEX* wfe = (WAVEFORMATEX*)mt.Format();
// This code is probably totally broken for anything but 16 bits
for(int i = 0, bps = wfe->wBitsPerSample/8; i < DataSize; i += bps)
- for(int j = bps-1; j >= 0; j--)
+ for(int j = bps-1; j >= 0; j--) {
pBitStream->BitWrite(pData[i+j], 8);
+ }
return;
}
@@ -429,15 +430,16 @@ void CBaseMuxerRawOutputPin::MuxPacket(const CMediaType& mt, const MuxerPacket* void CBaseMuxerRawOutputPin::MuxFooter(const CMediaType& mt)
{
CComQIPtr<IBitStream> pBitStream = GetBitStream();
- if(!pBitStream) return;
+ if(!pBitStream) {
+ return;
+ }
if(mt.majortype == MEDIATYPE_Audio
&& (mt.subtype == MEDIASUBTYPE_PCM
- || mt.subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO
- || mt.subtype == FOURCCMap(WAVE_FORMAT_EXTENSIBLE)
- || mt.subtype == FOURCCMap(WAVE_FORMAT_IEEE_FLOAT))
- && mt.formattype == FORMAT_WaveFormatEx)
- {
+ || mt.subtype == MEDIASUBTYPE_DVD_LPCM_AUDIO
+ || mt.subtype == FOURCCMap(WAVE_FORMAT_EXTENSIBLE)
+ || mt.subtype == FOURCCMap(WAVE_FORMAT_IEEE_FLOAT))
+ && mt.formattype == FORMAT_WaveFormatEx) {
pBitStream->BitFlush();
ASSERT(pBitStream->GetPos() <= 0xffffffff);
@@ -450,30 +452,22 @@ void CBaseMuxerRawOutputPin::MuxFooter(const CMediaType& mt) size -= sizeof(RIFFLIST) + sizeof(RIFFCHUNK) + mt.FormatLength();
pBitStream->Seek(sizeof(RIFFLIST) + sizeof(RIFFCHUNK) + mt.FormatLength() + 4);
pBitStream->ByteWrite(&size, 4);
- }
- else if(mt.subtype == MEDIASUBTYPE_SSF)
- {
+ } else if(mt.subtype == MEDIASUBTYPE_SSF) {
ssf::WCharOutputStream s;
try {
m_ssf.Dump(s);
- }
- catch(ssf::Exception&) {}
+ } catch(ssf::Exception&) {}
CStringA str = UTF16To8(s.GetString());
pBitStream->StrWrite(str, true);
- }
- else if(mt.subtype == MEDIASUBTYPE_VOBSUB)
- {
- if(CComQIPtr<IFileSinkFilter> pFSF = GetFilterFromPin(GetConnected()))
- {
+ } else if(mt.subtype == MEDIASUBTYPE_VOBSUB) {
+ if(CComQIPtr<IFileSinkFilter> pFSF = GetFilterFromPin(GetConnected())) {
WCHAR* fn = NULL;
- if(SUCCEEDED(pFSF->GetCurFile(&fn, NULL)))
- {
+ if(SUCCEEDED(pFSF->GetCurFile(&fn, NULL))) {
CPathW p(fn);
p.RenameExtension(L".idx");
CoTaskMemFree(fn);
- if(FILE* f = _tfopen(CString((LPCWSTR)p), _T("w")))
- {
+ if(FILE* f = _tfopen(CString((LPCWSTR)p), _T("w"))) {
SUBTITLEINFO* si = (SUBTITLEINFO*)mt.Format();
_ftprintf(f, _T("%s\n"), _T("# VobSub index file, v7 (do not modify this line!)"));
@@ -481,15 +475,18 @@ void CBaseMuxerRawOutputPin::MuxFooter(const CMediaType& mt) fwrite(mt.Format() + si->dwOffset, mt.FormatLength() - si->dwOffset, 1, f);
CString iso6391 = ISO6392To6391(si->IsoLang);
- if(iso6391.IsEmpty()) iso6391 = _T("--");
+ if(iso6391.IsEmpty()) {
+ iso6391 = _T("--");
+ }
_ftprintf(f, _T("\nlangidx: 0\n\nid: %s, index: 0\n"), iso6391);
CString alt = CString(CStringW(si->TrackName));
- if(!alt.IsEmpty()) _ftprintf(f, _T("alt: %s\n"), alt);
+ if(!alt.IsEmpty()) {
+ _ftprintf(f, _T("alt: %s\n"), alt);
+ }
POSITION pos = m_idx.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
const idx_t& i = m_idx.GetNext(pos);
DVD_HMSF_TIMECODE start = RT2HMSF(i.rt, 25);
_ftprintf(f, _T("timestamp: %02d:%02d:%02d:%03d, filepos: %09I64x\n"),
diff --git a/src/filters/muxer/BaseMuxer/BaseMuxerRelatedPin.h b/src/filters/muxer/BaseMuxer/BaseMuxerRelatedPin.h index 3d911ccdd..d86985190 100644 --- a/src/filters/muxer/BaseMuxer/BaseMuxerRelatedPin.h +++ b/src/filters/muxer/BaseMuxer/BaseMuxerRelatedPin.h @@ -23,8 +23,7 @@ interface __declspec(uuid("EE6F2741-7DB4-4AAD-A3CB-545208EE4C0A"))
IBaseMuxerRelatedPin :
-public IUnknown
-{
+public IUnknown {
STDMETHOD(SetRelatedPin) (CBasePin* pPin) = 0;
STDMETHOD_(CBasePin*, GetRelatedPin) () = 0;
};
diff --git a/src/filters/muxer/BaseMuxer/BitStream.cpp b/src/filters/muxer/BaseMuxer/BitStream.cpp index d18fc53fa..355cc19ff 100644 --- a/src/filters/muxer/BaseMuxer/BitStream.cpp +++ b/src/filters/muxer/BaseMuxer/BitStream.cpp @@ -87,13 +87,14 @@ STDMETHODIMP CBitStream::ByteWrite(const void* pData, int len) BitFlush();
- if(len > 0)
- {
+ if(len > 0) {
ULONG cbWritten = 0;
hr = m_pStream->Write(pData, len, &cbWritten);
ASSERT(SUCCEEDED(hr));
- if(m_fThrowError && FAILED(hr)) throw hr;
+ if(m_fThrowError && FAILED(hr)) {
+ throw hr;
+ }
}
return hr;
@@ -114,14 +115,15 @@ STDMETHODIMP CBitStream::BitWrite(UINT64 data, int len) m_bitbuff |= data & ((1ui64 << len) - 1);
m_bitlen += len;
- while(m_bitlen >= 8)
- {
+ while(m_bitlen >= 8) {
BYTE b = (BYTE)(m_bitbuff >> (m_bitlen - 8));
hr = m_pStream->Write(&b, 1, NULL);
m_bitlen -= 8;
ASSERT(SUCCEEDED(hr));
- if(m_fThrowError && FAILED(hr)) throw E_FAIL;
+ if(m_fThrowError && FAILED(hr)) {
+ throw E_FAIL;
+ }
}
return hr;
@@ -131,15 +133,16 @@ STDMETHODIMP CBitStream::BitFlush() {
HRESULT hr = S_OK;
- if(m_bitlen > 0)
- {
+ if(m_bitlen > 0) {
ASSERT(m_bitlen < 8);
BYTE b = (BYTE)(m_bitbuff << (8 - m_bitlen));
hr = m_pStream->Write(&b, 1, NULL);
m_bitlen = 0;
ASSERT(SUCCEEDED(hr));
- if(m_fThrowError && FAILED(hr)) throw E_FAIL;
+ if(m_fThrowError && FAILED(hr)) {
+ throw E_FAIL;
+ }
}
return hr;
@@ -149,8 +152,7 @@ STDMETHODIMP CBitStream::StrWrite(LPCSTR pData, BOOL bFixNewLine) {
CStringA str = pData;
- if(bFixNewLine)
- {
+ if(bFixNewLine) {
str.Replace("\r", "");
str.Replace("\n", "\r\n");
}
diff --git a/src/filters/muxer/BaseMuxer/BitStream.h b/src/filters/muxer/BaseMuxer/BitStream.h index 02ffbe2ce..e2f186da2 100644 --- a/src/filters/muxer/BaseMuxer/BitStream.h +++ b/src/filters/muxer/BaseMuxer/BitStream.h @@ -23,8 +23,7 @@ interface __declspec(uuid("30AB78C7-5259-4594-AEFE-9C0FC2F08A5E"))
IBitStream :
-public IUnknown
-{
+public IUnknown {
STDMETHOD_(UINT64, GetPos) () = 0;
STDMETHOD_(UINT64, Seek) (UINT64 pos) = 0; // it's a _stream_, please don't seek if you don't have to
STDMETHOD(ByteWrite) (const void* pData, int len) = 0;
diff --git a/src/filters/muxer/DSMMuxer/DSMMuxer.cpp b/src/filters/muxer/DSMMuxer/DSMMuxer.cpp index 17fce671d..b3059b577 100644 --- a/src/filters/muxer/DSMMuxer/DSMMuxer.cpp +++ b/src/filters/muxer/DSMMuxer/DSMMuxer.cpp @@ -30,24 +30,20 @@ #ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_DirectShowMedia}
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, TRUE, &CLSID_NULL, NULL, 0, NULL},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CDSMMuxerFilter), L"MPC - DSM Muxer", MERIT_DO_NOT_USE, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CDSMMuxerFilter>, NULL, &sudFilter[0]}
};
@@ -69,14 +65,17 @@ CFilterApp theApp; #endif
-template<typename T> static T myabs(T n) {
+template<typename T> static T myabs(T n)
+{
return n >= 0 ? n : -n;
}
static int GetByteLength(UINT64 data, int min = 0)
{
int i = 7;
- while(i >= min && ((BYTE*)&data)[i] == 0) i--;
+ while(i >= min && ((BYTE*)&data)[i] == 0) {
+ i--;
+ }
return ++i;
}
@@ -89,7 +88,9 @@ CDSMMuxerFilter::CDSMMuxerFilter(LPUNKNOWN pUnk, HRESULT* phr, bool fAutoChap, b , m_fAutoChap(fAutoChap)
, m_fAutoRes(fAutoRes)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
}
CDSMMuxerFilter::~CDSMMuxerFilter()
@@ -123,18 +124,18 @@ void CDSMMuxerFilter::MuxFileInfo(IBitStream* pBS) int len = 1;
CSimpleMap<CStringA, CStringA> si;
- for(int i = 0; i < GetSize(); i++)
- {
+ for(int i = 0; i < GetSize(); i++) {
CStringA key = CStringA(CString(GetKeyAt(i))), value = UTF16To8(GetValueAt(i));
- if(key.GetLength() != 4) continue;
+ if(key.GetLength() != 4) {
+ continue;
+ }
si.Add(key, value);
len += 4 + value.GetLength() + 1;
}
MuxPacketHeader(pBS, DSMP_FILEINFO, len);
pBS->BitWrite(DSMF_VERSION, 8);
- for(int i = 0; i < si.GetSize(); i++)
- {
+ for(int i = 0; i < si.GetSize(); i++) {
CStringA key = si.GetKeyAt(i), value = si.GetValueAt(i);
pBS->ByteWrite((LPCSTR)key, 4);
pBS->ByteWrite((LPCSTR)value, value.GetLength()+1);
@@ -147,20 +148,19 @@ void CDSMMuxerFilter::MuxStreamInfo(IBitStream* pBS, CBaseMuxerInputPin* pPin) int len = 1;
CSimpleMap<CStringA, CStringA> si;
- for(int i = 0; i < pPin->GetSize(); i++)
- {
+ for(int i = 0; i < pPin->GetSize(); i++) {
CStringA key = CStringA(CString(pPin->GetKeyAt(i))), value = UTF16To8(pPin->GetValueAt(i));
- if(key.GetLength() != 4) continue;
+ if(key.GetLength() != 4) {
+ continue;
+ }
si.Add(key, value);
len += 4 + value.GetLength() + 1;
}
- if(len > 1)
- {
+ if(len > 1) {
MuxPacketHeader(pBS, DSMP_STREAMINFO, len);
pBS->BitWrite(pPin->GetID(), 8);
- for(int i = 0; i < si.GetSize(); i++)
- {
+ for(int i = 0; i < si.GetSize(); i++) {
CStringA key = si.GetKeyAt(i), value = si.GetValueAt(i);
pBS->ByteWrite((LPCSTR)key, 4);
pBS->ByteWrite((LPCSTR)value, value.GetLength()+1);
@@ -186,8 +186,7 @@ void CDSMMuxerFilter::MuxHeader(IBitStream* pBS) MuxFileInfo(pBS);
POSITION pos = m_pPins.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBaseMuxerInputPin* pPin = m_pPins.GetNext(pos);
const CMediaType& mt = pPin->CurrentMediaType();
@@ -214,19 +213,19 @@ void CDSMMuxerFilter::MuxHeader(IBitStream* pBS) CComQIPtr<IDSMChapterBag> pCB = (IUnknown*)(INonDelegatingUnknown*)this;
pos = m_pPins.GetHeadPosition();
- while(pos)
- {
- for(CComPtr<IPin> pPin = m_pPins.GetNext(pos)->GetConnected(); pPin; pPin = GetUpStreamPin(GetFilterFromPin(pPin)))
- {
- if(m_fAutoRes)
- {
+ while(pos) {
+ for(CComPtr<IPin> pPin = m_pPins.GetNext(pos)->GetConnected(); pPin; pPin = GetUpStreamPin(GetFilterFromPin(pPin))) {
+ if(m_fAutoRes) {
CComQIPtr<IDSMResourceBag> pPB = GetFilterFromPin(pPin);
- if(pPB && !pRBs.Find(pPB)) pRBs.AddTail(pPB);
+ if(pPB && !pRBs.Find(pPB)) {
+ pRBs.AddTail(pPB);
+ }
}
- if(m_fAutoChap)
- {
- if(!pCB || pCB->ChapGetCount() == 0) pCB = GetFilterFromPin(pPin);
+ if(m_fAutoChap) {
+ if(!pCB || pCB->ChapGetCount() == 0) {
+ pCB = GetFilterFromPin(pPin);
+ }
}
}
}
@@ -234,17 +233,14 @@ void CDSMMuxerFilter::MuxHeader(IBitStream* pBS) // resources
pos = pRBs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
IDSMResourceBag* pRB = pRBs.GetNext(pos);
- for(DWORD i = 0, j = pRB->ResGetCount(); i < j; i++)
- {
+ for(DWORD i = 0, j = pRB->ResGetCount(); i < j; i++) {
CComBSTR name, desc, mime;
BYTE* pData = NULL;
DWORD len = 0;
- if(SUCCEEDED(pRB->ResGet(i, &name, &desc, &mime, &pData, &len, NULL)))
- {
+ if(SUCCEEDED(pRB->ResGet(i, &name, &desc, &mime, &pData, &len, NULL))) {
CStringA utf8_name = UTF16To8(name);
CStringA utf8_desc = UTF16To8(desc);
CStringA utf8_mime = UTF16To8(mime);
@@ -270,20 +266,17 @@ void CDSMMuxerFilter::MuxHeader(IBitStream* pBS) // chapters
- if(pCB)
- {
+ if(pCB) {
CAtlList<CDSMChapter> chapters;
REFERENCE_TIME rtPrev = 0;
int len = 0;
pCB->ChapSort();
- for(DWORD i = 0; i < pCB->ChapGetCount(); i++)
- {
+ for(DWORD i = 0; i < pCB->ChapGetCount(); i++) {
CDSMChapter c;
CComBSTR name;
- if(SUCCEEDED(pCB->ChapGet(i, &c.rt, &name)))
- {
+ if(SUCCEEDED(pCB->ChapGet(i, &c.rt, &name))) {
REFERENCE_TIME rtDiff = c.rt - rtPrev;
rtPrev = c.rt;
c.rt = rtDiff;
@@ -293,13 +286,11 @@ void CDSMMuxerFilter::MuxHeader(IBitStream* pBS) }
}
- if(chapters.GetCount())
- {
+ if(chapters.GetCount()) {
MuxPacketHeader(pBS, DSMP_CHAPTERS, len);
pos = chapters.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CDSMChapter& c = chapters.GetNext(pos);
CStringA name = UTF16To8(c.name);
int irt = GetByteLength(myabs(c.rt));
@@ -315,18 +306,19 @@ void CDSMMuxerFilter::MuxHeader(IBitStream* pBS) void CDSMMuxerFilter::MuxPacket(IBitStream* pBS, const MuxerPacket* pPacket)
{
- if(pPacket->IsEOS())
+ if(pPacket->IsEOS()) {
return;
+ }
- if(pPacket->pPin->CurrentMediaType().majortype == MEDIATYPE_Text)
- {
+ if(pPacket->pPin->CurrentMediaType().majortype == MEDIATYPE_Text) {
CStringA str((char*)pPacket->pData.GetData(), pPacket->pData.GetCount());
str.Replace("\xff", " ");
str.Replace(" ", " ");
str.Replace(" ", " ");
str.Trim();
- if(str.IsEmpty())
+ if(str.IsEmpty()) {
return;
+ }
}
ASSERT(!pPacket->IsSyncPoint() || pPacket->IsTimeValid());
@@ -334,8 +326,7 @@ void CDSMMuxerFilter::MuxPacket(IBitStream* pBS, const MuxerPacket* pPacket) REFERENCE_TIME rtTimeStamp = _I64_MIN, rtDuration = 0;
int iTimeStamp = 0, iDuration = 0;
- if(pPacket->IsTimeValid())
- {
+ if(pPacket->IsTimeValid()) {
rtTimeStamp = pPacket->rtStart;
rtDuration = max(pPacket->rtStop - pPacket->rtStart, 0);
@@ -371,8 +362,7 @@ void CDSMMuxerFilter::MuxFooter(IBitStream* pBS) UINT64 fpPrev = 0, fp;
POSITION pos = m_isps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
IndexedSyncPoint& isp = m_isps.GetNext(pos);
TRACE(_T("sp[%d]: %I64d %I64x\n"), isp.id, isp.rt, isp.fp);
@@ -392,8 +382,7 @@ void CDSMMuxerFilter::MuxFooter(IBitStream* pBS) MuxPacketHeader(pBS, DSMP_SYNCPOINTS, len);
pos = isps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
IndexedSyncPoint& isp = isps.GetNext(pos);
int irt = GetByteLength(myabs(isp.rt));
@@ -416,8 +405,9 @@ void CDSMMuxerFilter::IndexSyncPoint(const MuxerPacket* p, __int64 fp) // FIXME: the very last syncpoints won't get moved to m_isps because there are no more syncpoints to trigger it!
- if(fp < 0 || !p || !p->IsTimeValid() || !p->IsSyncPoint())
+ if(fp < 0 || !p || !p->IsTimeValid() || !p->IsSyncPoint()) {
return;
+ }
ASSERT(p->rtStart >= m_rtPrevSyncPoint);
m_rtPrevSyncPoint = p->rtStart;
@@ -433,8 +423,7 @@ void CDSMMuxerFilter::IndexSyncPoint(const MuxerPacket* p, __int64 fp) SyncPoint& tail = !m_sps.IsEmpty() ? m_sps.GetTail() : sp;
REFERENCE_TIME rtfp = !m_isps.IsEmpty() ? m_isps.GetTail().rtfp : _I64_MIN;
- if(head.rtStart > rtfp + 1000000) // 100ms limit, just in case every stream had only keyframes, then sycnpoints would be too frequent
- {
+ if(head.rtStart > rtfp + 1000000) { // 100ms limit, just in case every stream had only keyframes, then sycnpoints would be too frequent
IndexedSyncPoint isp;
isp.id = head.id;
isp.rt = tail.rtStart;
@@ -445,12 +434,12 @@ void CDSMMuxerFilter::IndexSyncPoint(const MuxerPacket* p, __int64 fp) }
POSITION pos = m_sps.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
POSITION cur = pos;
SyncPoint& sp2 = m_sps.GetNext(pos);
- if(sp2.id == sp.id && sp2.rtStop <= sp.rtStop || sp2.rtStop <= sp.rtStart)
+ if(sp2.id == sp.id && sp2.rtStop <= sp.rtStop || sp2.rtStop <= sp.rtStart) {
m_sps.RemoveAt(cur);
+ }
}
m_sps.AddTail(sp);
diff --git a/src/filters/muxer/MatroskaMuxer/MatroskaFile.cpp b/src/filters/muxer/MatroskaMuxer/MatroskaFile.cpp index d1af9a3e4..14660e5b9 100644 --- a/src/filters/muxer/MatroskaMuxer/MatroskaFile.cpp +++ b/src/filters/muxer/MatroskaMuxer/MatroskaFile.cpp @@ -27,8 +27,9 @@ using namespace MatroskaWriter; static void bswap(BYTE* s, int len)
{
- for(BYTE* d = s + len-1; s < d; s++, d--)
+ for(BYTE* d = s + len-1; s < d; s++, d--) {
*s ^= *d, *d ^= *s, *s ^= *d;
+ }
}
//
@@ -65,17 +66,23 @@ HRESULT CID::HeaderWrite(IStream* pStream) MatroskaWriter::QWORD CBinary::Size(bool fWithHeader)
{
- if(GetCount() == 0) return 0;
+ if(GetCount() == 0) {
+ return 0;
+ }
MatroskaWriter::QWORD len = 0;
len += GetCount();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
HRESULT CBinary::Write(IStream* pStream)
{
- if(GetCount() == 0) return S_OK;
+ if(GetCount() == 0) {
+ return S_OK;
+ }
HeaderWrite(pStream);
return pStream->Write(GetData(), GetCount(), NULL);
@@ -83,17 +90,23 @@ HRESULT CBinary::Write(IStream* pStream) MatroskaWriter::QWORD CANSI::Size(bool fWithHeader)
{
- if(GetLength() == 0) return 0;
+ if(GetLength() == 0) {
+ return 0;
+ }
MatroskaWriter::QWORD len = 0;
len += GetLength();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
HRESULT CANSI::Write(IStream* pStream)
{
- if(GetLength() == 0) return S_OK;
+ if(GetLength() == 0) {
+ return S_OK;
+ }
HeaderWrite(pStream);
return pStream->Write((LPCSTR)*this, GetLength(), NULL);
@@ -101,17 +114,23 @@ HRESULT CANSI::Write(IStream* pStream) MatroskaWriter::QWORD CUTF8::Size(bool fWithHeader)
{
- if(GetLength() == 0) return 0;
+ if(GetLength() == 0) {
+ return 0;
+ }
MatroskaWriter::QWORD len = 0;
len += UTF16To8(*this).GetLength();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
HRESULT CUTF8::Write(IStream* pStream)
{
- if(GetLength() == 0) return S_OK;
+ if(GetLength() == 0) {
+ return S_OK;
+ }
HeaderWrite(pStream);
CStringA str = UTF16To8(*this);
@@ -121,18 +140,24 @@ HRESULT CUTF8::Write(IStream* pStream) template<class T, class BASE>
MatroskaWriter::QWORD CSimpleVar<T, BASE>::Size(bool fWithHeader)
{
- if(!m_fSet) return 0;
+ if(!m_fSet) {
+ return 0;
+ }
MatroskaWriter::QWORD len = 0;
len += sizeof(T);
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
template<class T, class BASE>
HRESULT CSimpleVar<T, BASE>::Write(IStream* pStream)
{
- if(!m_fSet) return S_OK;
+ if(!m_fSet) {
+ return S_OK;
+ }
HeaderWrite(pStream);
T val = m_val;
@@ -142,32 +167,33 @@ HRESULT CSimpleVar<T, BASE>::Write(IStream* pStream) MatroskaWriter::QWORD CUInt::Size(bool fWithHeader)
{
- if(!m_fSet) return 0;
+ if(!m_fSet) {
+ return 0;
+ }
MatroskaWriter::QWORD len = 0;
- if(m_val == 0)
- {
+ if(m_val == 0) {
len++;
- }
- else
- {
- for(int i = 8; i > 0; i--)
- {
- if(((0xffi64<<((i-1)*8))&m_val))
- {
+ } else {
+ for(int i = 8; i > 0; i--) {
+ if(((0xffi64<<((i-1)*8))&m_val)) {
len += i;
break;
}
}
}
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
HRESULT CUInt::Write(IStream* pStream)
{
- if(!m_fSet) return S_OK;
+ if(!m_fSet) {
+ return S_OK;
+ }
CID::Write(pStream);
CLength l(Size(false));
@@ -179,35 +205,37 @@ HRESULT CUInt::Write(IStream* pStream) MatroskaWriter::QWORD CInt::Size(bool fWithHeader)
{
- if(!m_fSet) return 0;
+ if(!m_fSet) {
+ return 0;
+ }
MatroskaWriter::QWORD len = 0;
- if(m_val == 0)
- {
+ if(m_val == 0) {
len++;
- }
- else
- {
+ } else {
UINT64 val = m_val >= 0 ? m_val : -m_val;
- for(int i = 8; i > 0; i--)
- {
- if(((0xffi64<<((i-1)*8))&val))
- {
+ for(int i = 8; i > 0; i--) {
+ if(((0xffi64<<((i-1)*8))&val)) {
len += i;
- if(m_val < 0 && !(m_val&(0x80<<(i-1))))
+ if(m_val < 0 && !(m_val&(0x80<<(i-1)))) {
len++;
+ }
break;
}
}
}
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
HRESULT CInt::Write(IStream* pStream)
{
- if(!m_fSet) return S_OK;
+ if(!m_fSet) {
+ return S_OK;
+ }
CID::Write(pStream);
CLength l(Size(false));
@@ -219,14 +247,13 @@ HRESULT CInt::Write(IStream* pStream) MatroskaWriter::QWORD CLength::Size(bool fWithHeader)
{
- if(m_len == 0x00FFFFFFFFFFFFFFi64)
+ if(m_len == 0x00FFFFFFFFFFFFFFi64) {
return 8;
+ }
MatroskaWriter::QWORD len = 0;
- for(int i = 1; i <= 8; i++)
- {
- if(!(m_len&(~((1i64<<(7*i))-1))) && (m_len&((1i64<<(7*i))-1)) != ((1i64<<(7*i))-1))
- {
+ for(int i = 1; i <= 8; i++) {
+ if(!(m_len&(~((1i64<<(7*i))-1))) && (m_len&((1i64<<(7*i))-1)) != ((1i64<<(7*i))-1)) {
len += i;
break;
}
@@ -267,7 +294,9 @@ MatroskaWriter::QWORD EBML::Size(bool fWithHeader) len += DocType.Size();
len += DocTypeVersion.Size();
len += DocTypeReadVersion.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -316,7 +345,9 @@ MatroskaWriter::QWORD Info::Size(bool fWithHeader) len += Title.Size();
len += MuxingApp.Size();
len += WritingApp.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -346,11 +377,11 @@ Segment::Segment(DWORD id) MatroskaWriter::QWORD Segment::Size(bool fWithHeader)
{
return 0x00FFFFFFFFFFFFFFi64;
-/*
- MatroskaWriter::QWORD len = 0;
- if(fWithHeader) len += HeaderSize(len);
- return len;
-*/
+ /*
+ MatroskaWriter::QWORD len = 0;
+ if(fWithHeader) len += HeaderSize(len);
+ return len;
+ */
}
HRESULT Segment::Write(IStream* pStream)
@@ -368,7 +399,9 @@ MatroskaWriter::QWORD Track::Size(bool fWithHeader) {
MatroskaWriter::QWORD len = 0;
len += TrackEntries.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -428,9 +461,15 @@ MatroskaWriter::QWORD TrackEntry::Size(bool fWithHeader) len += CodecDecodeAll.Size();
len += TrackOverlay.Size();
len += DefaultDuration.Size();
- if(DescType == TypeVideo) len += v.Size();
- if(DescType == TypeAudio) len += a.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(DescType == TypeVideo) {
+ len += v.Size();
+ }
+ if(DescType == TypeAudio) {
+ len += a.Size();
+ }
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -456,8 +495,12 @@ HRESULT TrackEntry::Write(IStream* pStream) CodecDecodeAll.Write(pStream);
TrackOverlay.Write(pStream);
DefaultDuration.Write(pStream);
- if(DescType == TypeVideo) v.Write(pStream);
- if(DescType == TypeAudio) a.Write(pStream);
+ if(DescType == TypeVideo) {
+ v.Write(pStream);
+ }
+ if(DescType == TypeAudio) {
+ a.Write(pStream);
+ }
return S_OK;
}
@@ -491,7 +534,9 @@ MatroskaWriter::QWORD Video::Size(bool fWithHeader) len += ColourSpace.Size();
len += GammaValue.Size();
len += FramePerSec.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -530,7 +575,9 @@ MatroskaWriter::QWORD Audio::Size(bool fWithHeader) len += Channels.Size();
len += ChannelPositions.Size();
len += BitDepth.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -560,7 +607,9 @@ MatroskaWriter::QWORD Cluster::Size(bool fWithHeader) len += Position.Size();
len += PrevSize.Size();
len += BlockGroups.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -593,7 +642,9 @@ MatroskaWriter::QWORD BlockGroup::Size(bool fWithHeader) len += ReferenceVirtual.Size();
len += CodecState.Size();
len += Block.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -619,23 +670,24 @@ MatroskaWriter::QWORD CBlock::Size(bool fWithHeader) {
MatroskaWriter::QWORD len = 0;
len += TrackNumber.Size() + 2 + 1; // TrackNumber + TimeCode + Lacing
- if(BlockData.GetCount() > 1)
- {
+ if(BlockData.GetCount() > 1) {
len += 1; // nBlockData
POSITION pos = BlockData.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBinary* b = BlockData.GetNext(pos);
- if(pos) len += b->GetCount()/255 + 1;
+ if(pos) {
+ len += b->GetCount()/255 + 1;
+ }
}
}
POSITION pos = BlockData.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBinary* b = BlockData.GetNext(pos);
len += b->GetCount();
}
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -648,20 +700,18 @@ HRESULT CBlock::Write(IStream* pStream) pStream->Write(&t, 2, NULL);
BYTE Lacing = 0;
BYTE n = BlockData.GetCount();
- if(n > 1) Lacing |= 2;
+ if(n > 1) {
+ Lacing |= 2;
+ }
pStream->Write(&Lacing, 1, NULL);
- if(n > 1)
- {
+ if(n > 1) {
pStream->Write(&n, 1, NULL);
POSITION pos = BlockData.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBinary* b = BlockData.GetNext(pos);
- if(pos)
- {
+ if(pos) {
int len = b->GetCount();
- while(len >= 0)
- {
+ while(len >= 0) {
n = min(len, 255);
pStream->Write(&n, 1, NULL);
len -= 255;
@@ -670,8 +720,7 @@ HRESULT CBlock::Write(IStream* pStream) }
}
POSITION pos = BlockData.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBinary* b = BlockData.GetNext(pos);
pStream->Write(b->GetData(), b->GetCount(), NULL);
}
@@ -687,7 +736,9 @@ MatroskaWriter::QWORD Cue::Size(bool fWithHeader) {
MatroskaWriter::QWORD len = 0;
len += CuePoints.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -709,7 +760,9 @@ MatroskaWriter::QWORD CuePoint::Size(bool fWithHeader) MatroskaWriter::QWORD len = 0;
len += CueTime.Size();
len += CueTrackPositions.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -737,8 +790,10 @@ MatroskaWriter::QWORD CueTrackPosition::Size(bool fWithHeader) len += CueClusterPosition.Size();
len += CueBlockNumber.Size();
len += CueCodecState.Size();
-// len += CueReferences.Size();
- if(fWithHeader) len += HeaderSize(len);
+ // len += CueReferences.Size();
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -749,7 +804,7 @@ HRESULT CueTrackPosition::Write(IStream* pStream) CueClusterPosition.Write(pStream);
CueBlockNumber.Write(pStream);
CueCodecState.Write(pStream);
-// CueReferences.Write(pStream);
+ // CueReferences.Write(pStream);
return S_OK;
}
@@ -762,7 +817,9 @@ MatroskaWriter::QWORD Seek::Size(bool fWithHeader) {
MatroskaWriter::QWORD len = 0;
len += SeekHeads.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -783,7 +840,9 @@ MatroskaWriter::QWORD SeekID::Size(bool fWithHeader) {
MatroskaWriter::QWORD len = 0;
len += m_id.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -805,7 +864,9 @@ MatroskaWriter::QWORD SeekHead::Size(bool fWithHeader) MatroskaWriter::QWORD len = 0;
len += ID.Size();
len += Position.Size();
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -825,15 +886,17 @@ Tags::Tags(DWORD id) MatroskaWriter::QWORD Tags::Size(bool fWithHeader)
{
MatroskaWriter::QWORD len = 0;
-// len += .Size();
- if(fWithHeader) len += HeaderSize(len);
+ // len += .Size();
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
HRESULT Tags::Write(IStream* pStream)
{
HeaderWrite(pStream);
-// .Write(pStream);
+ // .Write(pStream);
return S_OK;
}
@@ -847,7 +910,9 @@ MatroskaWriter::QWORD Void::Size(bool fWithHeader) {
MatroskaWriter::QWORD len = 0;
len += m_len;
- if(fWithHeader) len += HeaderSize(len);
+ if(fWithHeader) {
+ len += HeaderSize(len);
+ }
return len;
}
@@ -856,7 +921,8 @@ HRESULT Void::Write(IStream* pStream) HeaderWrite(pStream);
BYTE buff[64];
memset(buff, 0x80, sizeof(buff));
- for(int len = (int)m_len; len > 0; len -= sizeof(buff))
+ for(int len = (int)m_len; len > 0; len -= sizeof(buff)) {
pStream->Write(buff, (ULONG)min(sizeof(buff), len), NULL);
+ }
return S_OK;
}
diff --git a/src/filters/muxer/MatroskaMuxer/MatroskaFile.h b/src/filters/muxer/MatroskaMuxer/MatroskaFile.h index feb94cd6c..477d9c990 100644 --- a/src/filters/muxer/MatroskaMuxer/MatroskaFile.h +++ b/src/filters/muxer/MatroskaMuxer/MatroskaFile.h @@ -26,393 +26,395 @@ namespace MatroskaWriter
{
-typedef unsigned __int64 QWORD;
+ typedef unsigned __int64 QWORD;
-class CID
-{
-protected:
- DWORD m_id;
- QWORD HeaderSize(QWORD len);
- HRESULT HeaderWrite(IStream* pStream);
-
-public:
- CID(DWORD id);
- DWORD GetID() const {
- return m_id;
- }
- virtual QWORD Size(bool fWithHeader = true);
- virtual HRESULT Write(IStream* pStream);
-};
-
-class CLength : public CID
-{
- UINT64 m_len;
-public:
- CLength(UINT64 len = 0) : CID(0), m_len(len) {}
- operator UINT64() {
- return m_len;
- }
- QWORD Size(bool fWithHeader = false);
- HRESULT Write(IStream* pStream);
-};
-
-class CBinary : public CAtlArray<BYTE>, public CID
-{
-public:
- CBinary(DWORD id) : CID(id) {}
- CBinary& operator = (const CBinary& b) {
- Copy(b);
- return(*this);
- }
- operator BYTE*() {
- return (BYTE*)GetData();
- }
- CBinary& Set(CStringA str) {
- SetCount(str.GetLength()+1);
- strcpy((char*)GetData(), str);
- return(*this);
- }
-// CBinary& Set(CStringA str) {SetCount(str.GetLength()); memcpy((char*)GetData(), str, str.GetLength()); return(*this);}
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class CANSI : public CStringA, public CID
-{
-public:
- CANSI(DWORD id) : CID(id) {}
- CANSI& Set(CStringA str) {
- CStringA::operator = (str);
- return(*this);
- }
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class CUTF8 : public CStringW, public CID
-{
-public:
- CUTF8(DWORD id) : CID(id) {}
- CUTF8& Set(CStringW str) {
- CStringW::operator = (str);
- return(*this);
- }
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-template<class T, class BASE>
-class CSimpleVar : public CID
-{
-protected:
- T m_val;
- bool m_fSet;
-public:
- explicit CSimpleVar(DWORD id, T val = 0) : CID(id), m_val(val) {
- m_fSet = !!val;
- }
- operator T() {
- return m_val;
- }
- BASE& Set(T val) {
- m_val = val;
- m_fSet = true;
- return(*(BASE*)this);
- }
- void UnSet() {
- m_fSet = false;
- }
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class CUInt : public CSimpleVar<UINT64, CUInt>
-{
-public:
- explicit CUInt(DWORD id, UINT64 val = 0) : CSimpleVar<UINT64, CUInt>(id, val) {}
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ class CID
+ {
+ protected:
+ DWORD m_id;
+ QWORD HeaderSize(QWORD len);
+ HRESULT HeaderWrite(IStream* pStream);
+
+ public:
+ CID(DWORD id);
+ DWORD GetID() const {
+ return m_id;
+ }
+ virtual QWORD Size(bool fWithHeader = true);
+ virtual HRESULT Write(IStream* pStream);
+ };
+
+ class CLength : public CID
+ {
+ UINT64 m_len;
+ public:
+ CLength(UINT64 len = 0) : CID(0), m_len(len) {}
+ operator UINT64() {
+ return m_len;
+ }
+ QWORD Size(bool fWithHeader = false);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class CBinary : public CAtlArray<BYTE>, public CID
+ {
+ public:
+ CBinary(DWORD id) : CID(id) {}
+ CBinary& operator = (const CBinary& b) {
+ Copy(b);
+ return(*this);
+ }
+ operator BYTE*() {
+ return (BYTE*)GetData();
+ }
+ CBinary& Set(CStringA str) {
+ SetCount(str.GetLength()+1);
+ strcpy((char*)GetData(), str);
+ return(*this);
+ }
+ // CBinary& Set(CStringA str) {SetCount(str.GetLength()); memcpy((char*)GetData(), str, str.GetLength()); return(*this);}
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class CANSI : public CStringA, public CID
+ {
+ public:
+ CANSI(DWORD id) : CID(id) {}
+ CANSI& Set(CStringA str) {
+ CStringA::operator = (str);
+ return(*this);
+ }
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class CUTF8 : public CStringW, public CID
+ {
+ public:
+ CUTF8(DWORD id) : CID(id) {}
+ CUTF8& Set(CStringW str) {
+ CStringW::operator = (str);
+ return(*this);
+ }
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ template<class T, class BASE>
+ class CSimpleVar : public CID
+ {
+ protected:
+ T m_val;
+ bool m_fSet;
+ public:
+ explicit CSimpleVar(DWORD id, T val = 0) : CID(id), m_val(val) {
+ m_fSet = !!val;
+ }
+ operator T() {
+ return m_val;
+ }
+ BASE& Set(T val) {
+ m_val = val;
+ m_fSet = true;
+ return(*(BASE*)this);
+ }
+ void UnSet() {
+ m_fSet = false;
+ }
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class CUInt : public CSimpleVar<UINT64, CUInt>
+ {
+ public:
+ explicit CUInt(DWORD id, UINT64 val = 0) : CSimpleVar<UINT64, CUInt>(id, val) {}
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class CInt : public CSimpleVar<INT64, CInt>
-{
-public:
- explicit CInt(DWORD id, INT64 val = 0) : CSimpleVar<INT64, CInt>(id, val) {}
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ class CInt : public CSimpleVar<INT64, CInt>
+ {
+ public:
+ explicit CInt(DWORD id, INT64 val = 0) : CSimpleVar<INT64, CInt>(id, val) {}
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class CByte : public CSimpleVar<BYTE, CByte>
-{
-public:
- explicit CByte(DWORD id, BYTE val = 0) : CSimpleVar<BYTE, CByte>(id, val) {}
-};
+ class CByte : public CSimpleVar<BYTE, CByte>
+ {
+ public:
+ explicit CByte(DWORD id, BYTE val = 0) : CSimpleVar<BYTE, CByte>(id, val) {}
+ };
-class CShort : public CSimpleVar<short, CShort>
-{
-public:
- explicit CShort(DWORD id, short val = 0) : CSimpleVar<short, CShort>(id, val) {}
-};
+ class CShort : public CSimpleVar<short, CShort>
+ {
+ public:
+ explicit CShort(DWORD id, short val = 0) : CSimpleVar<short, CShort>(id, val) {}
+ };
-class CFloat : public CSimpleVar<float, CFloat>
-{
-public:
- explicit CFloat(DWORD id, float val = 0) : CSimpleVar<float, CFloat>(id, val) {}
-};
+ class CFloat : public CSimpleVar<float, CFloat>
+ {
+ public:
+ explicit CFloat(DWORD id, float val = 0) : CSimpleVar<float, CFloat>(id, val) {}
+ };
-template<class T>
-class CNode : public CAutoPtrList<T>
-{
-public:
- QWORD Size(bool fWithHeader = true)
+ template<class T>
+ class CNode : public CAutoPtrList<T>
{
- QWORD len = 0;
- POSITION pos = GetHeadPosition();
- while(pos) len += GetNext(pos)->Size(fWithHeader);
- return len;
- }
- HRESULT Write(IStream* pStream)
+ public:
+ QWORD Size(bool fWithHeader = true) {
+ QWORD len = 0;
+ POSITION pos = GetHeadPosition();
+ while(pos) {
+ len += GetNext(pos)->Size(fWithHeader);
+ }
+ return len;
+ }
+ HRESULT Write(IStream* pStream) {
+ HRESULT hr;
+ POSITION pos = GetHeadPosition();
+ while(pos) if(FAILED(hr = GetNext(pos)->Write(pStream))) {
+ return hr;
+ }
+ return S_OK;
+ }
+ };
+
+ class EBML : public CID
{
- HRESULT hr;
- POSITION pos = GetHeadPosition();
- while(pos) if(FAILED(hr = GetNext(pos)->Write(pStream))) return hr;
- return S_OK;
- }
-};
-
-class EBML : public CID
-{
-public:
- CUInt EBMLVersion, EBMLReadVersion;
- CUInt EBMLMaxIDLength, EBMLMaxSizeLength;
- CANSI DocType;
- CUInt DocTypeVersion, DocTypeReadVersion;
-
- EBML(DWORD id = 0x1A45DFA3);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class Info : public CID
-{
-public:
- CBinary SegmentUID, PrevUID, NextUID;
- CUTF8 SegmentFilename, PrevFilename, NextFilename;
- CUInt TimeCodeScale; // [ns], default: 1.000.000
- CFloat Duration;
- CInt DateUTC;
- CUTF8 Title, MuxingApp, WritingApp;
-
- Info(DWORD id = 0x1549A966);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class Video : public CID
-{
-public:
- CUInt FlagInterlaced, StereoMode;
- CUInt PixelWidth, PixelHeight, DisplayWidth, DisplayHeight, DisplayUnit;
- CUInt AspectRatioType;
- CUInt ColourSpace;
- CFloat GammaValue;
- CFloat FramePerSec;
-
- Video(DWORD id = 0xE0);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class Audio : public CID
-{
-public:
- CFloat SamplingFrequency;
- CFloat OutputSamplingFrequency;
- CUInt Channels;
- CBinary ChannelPositions;
- CUInt BitDepth;
-
- Audio(DWORD id = 0xE1);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class TrackEntry : public CID
-{
-public:
- enum {TypeVideo = 1, TypeAudio = 2, TypeComplex = 3, TypeLogo = 0x10, TypeSubtitle = 0x11, TypeControl = 0x20};
- CUInt TrackNumber, TrackUID, TrackType;
- CUInt FlagEnabled, FlagDefault, FlagLacing;
- CUInt MinCache, MaxCache;
- CUTF8 Name;
- CANSI Language;
- CBinary CodecID;
- CBinary CodecPrivate;
- CUTF8 CodecName;
- CUTF8 CodecSettings;
- CANSI CodecInfoURL;
- CANSI CodecDownloadURL;
- CUInt CodecDecodeAll;
- CUInt TrackOverlay;
- CUInt DefaultDuration;
- enum {NoDesc = 0, DescVideo = 1, DescAudio = 2};
- int DescType;
- Video v;
- Audio a;
-
- TrackEntry(DWORD id = 0xAE);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class Track : public CID
-{
-public:
- CNode<TrackEntry> TrackEntries;
+ public:
+ CUInt EBMLVersion, EBMLReadVersion;
+ CUInt EBMLMaxIDLength, EBMLMaxSizeLength;
+ CANSI DocType;
+ CUInt DocTypeVersion, DocTypeReadVersion;
+
+ EBML(DWORD id = 0x1A45DFA3);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class Info : public CID
+ {
+ public:
+ CBinary SegmentUID, PrevUID, NextUID;
+ CUTF8 SegmentFilename, PrevFilename, NextFilename;
+ CUInt TimeCodeScale; // [ns], default: 1.000.000
+ CFloat Duration;
+ CInt DateUTC;
+ CUTF8 Title, MuxingApp, WritingApp;
+
+ Info(DWORD id = 0x1549A966);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class Video : public CID
+ {
+ public:
+ CUInt FlagInterlaced, StereoMode;
+ CUInt PixelWidth, PixelHeight, DisplayWidth, DisplayHeight, DisplayUnit;
+ CUInt AspectRatioType;
+ CUInt ColourSpace;
+ CFloat GammaValue;
+ CFloat FramePerSec;
+
+ Video(DWORD id = 0xE0);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class Audio : public CID
+ {
+ public:
+ CFloat SamplingFrequency;
+ CFloat OutputSamplingFrequency;
+ CUInt Channels;
+ CBinary ChannelPositions;
+ CUInt BitDepth;
+
+ Audio(DWORD id = 0xE1);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class TrackEntry : public CID
+ {
+ public:
+ enum {TypeVideo = 1, TypeAudio = 2, TypeComplex = 3, TypeLogo = 0x10, TypeSubtitle = 0x11, TypeControl = 0x20};
+ CUInt TrackNumber, TrackUID, TrackType;
+ CUInt FlagEnabled, FlagDefault, FlagLacing;
+ CUInt MinCache, MaxCache;
+ CUTF8 Name;
+ CANSI Language;
+ CBinary CodecID;
+ CBinary CodecPrivate;
+ CUTF8 CodecName;
+ CUTF8 CodecSettings;
+ CANSI CodecInfoURL;
+ CANSI CodecDownloadURL;
+ CUInt CodecDecodeAll;
+ CUInt TrackOverlay;
+ CUInt DefaultDuration;
+ enum {NoDesc = 0, DescVideo = 1, DescAudio = 2};
+ int DescType;
+ Video v;
+ Audio a;
+
+ TrackEntry(DWORD id = 0xAE);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class Track : public CID
+ {
+ public:
+ CNode<TrackEntry> TrackEntries;
- Track(DWORD id = 0x1654AE6B);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ Track(DWORD id = 0x1654AE6B);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class CBlock : public CID
-{
-public:
- CLength TrackNumber;
- REFERENCE_TIME TimeCode, TimeCodeStop;
- CNode<CBinary> BlockData;
+ class CBlock : public CID
+ {
+ public:
+ CLength TrackNumber;
+ REFERENCE_TIME TimeCode, TimeCodeStop;
+ CNode<CBinary> BlockData;
- CBlock(DWORD id = 0xA1);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ CBlock(DWORD id = 0xA1);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class BlockGroup : public CID
-{
-public:
- CUInt BlockDuration;
- CUInt ReferencePriority;
- CInt ReferenceBlock;
- CInt ReferenceVirtual;
- CBinary CodecState;
- CBlock Block;
-// CNode<TimeSlice> TimeSlices;
-
- BlockGroup(DWORD id = 0xA0);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class Cluster : public CID
-{
-public:
- CUInt TimeCode, Position, PrevSize;
- CNode<BlockGroup> BlockGroups;
-
- Cluster(DWORD id = 0x1F43B675);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-/* class CueReference : public CID
- {
- public:
- CUInt CueRefTime, CueRefCluster, CueRefNumber, CueRefCodecState;
-
- CueReference(DWORD id = 0xDB);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
- };
-*/
-class CueTrackPosition : public CID
-{
-public:
- CUInt CueTrack, CueClusterPosition, CueBlockNumber, CueCodecState;
-// CNode<CueReference> CueReferences;
+ class BlockGroup : public CID
+ {
+ public:
+ CUInt BlockDuration;
+ CUInt ReferencePriority;
+ CInt ReferenceBlock;
+ CInt ReferenceVirtual;
+ CBinary CodecState;
+ CBlock Block;
+ // CNode<TimeSlice> TimeSlices;
+
+ BlockGroup(DWORD id = 0xA0);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class Cluster : public CID
+ {
+ public:
+ CUInt TimeCode, Position, PrevSize;
+ CNode<BlockGroup> BlockGroups;
+
+ Cluster(DWORD id = 0x1F43B675);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ /* class CueReference : public CID
+ {
+ public:
+ CUInt CueRefTime, CueRefCluster, CueRefNumber, CueRefCodecState;
+
+ CueReference(DWORD id = 0xDB);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+ */
+ class CueTrackPosition : public CID
+ {
+ public:
+ CUInt CueTrack, CueClusterPosition, CueBlockNumber, CueCodecState;
+ // CNode<CueReference> CueReferences;
- CueTrackPosition(DWORD id = 0xB7);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ CueTrackPosition(DWORD id = 0xB7);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class CuePoint : public CID
-{
-public:
- CUInt CueTime;
- CNode<CueTrackPosition> CueTrackPositions;
+ class CuePoint : public CID
+ {
+ public:
+ CUInt CueTime;
+ CNode<CueTrackPosition> CueTrackPositions;
- CuePoint(DWORD id = 0xBB);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ CuePoint(DWORD id = 0xBB);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class Cue : public CID
-{
-public:
- CNode<CuePoint> CuePoints;
+ class Cue : public CID
+ {
+ public:
+ CNode<CuePoint> CuePoints;
- Cue(DWORD id = 0x1C53BB6B);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ Cue(DWORD id = 0x1C53BB6B);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class SeekID : public CID
-{
- CID m_id;
-public:
- SeekID(DWORD id = 0x53AB);
- void Set(DWORD id) {
- m_id = id;
- }
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
-
-class SeekHead : public CID
-{
-public:
- SeekID ID;
- CUInt Position;
+ class SeekID : public CID
+ {
+ CID m_id;
+ public:
+ SeekID(DWORD id = 0x53AB);
+ void Set(DWORD id) {
+ m_id = id;
+ }
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
+
+ class SeekHead : public CID
+ {
+ public:
+ SeekID ID;
+ CUInt Position;
- SeekHead(DWORD id = 0x4DBB);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ SeekHead(DWORD id = 0x4DBB);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class Seek : public CID
-{
-public:
- CNode<SeekHead> SeekHeads;
+ class Seek : public CID
+ {
+ public:
+ CNode<SeekHead> SeekHeads;
- Seek(DWORD id = 0x114D9B74);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ Seek(DWORD id = 0x114D9B74);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class Segment : public CID
-{
-public:
- Segment(DWORD id = 0x18538067);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ class Segment : public CID
+ {
+ public:
+ Segment(DWORD id = 0x18538067);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class Tags : public CID
-{
-public:
- // TODO
+ class Tags : public CID
+ {
+ public:
+ // TODO
- Tags(DWORD id = 0x1254C367);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ Tags(DWORD id = 0x1254C367);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
-class Void : public CID
-{
- QWORD m_len;
-public:
- Void(QWORD len, DWORD id = 0xEC);
- QWORD Size(bool fWithHeader = true);
- HRESULT Write(IStream* pStream);
-};
+ class Void : public CID
+ {
+ QWORD m_len;
+ public:
+ Void(QWORD len, DWORD id = 0xEC);
+ QWORD Size(bool fWithHeader = true);
+ HRESULT Write(IStream* pStream);
+ };
}
diff --git a/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.cpp b/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.cpp index 68d3b89d2..d79d30b04 100644 --- a/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.cpp +++ b/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.cpp @@ -31,24 +31,20 @@ using namespace MatroskaWriter; #ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_Matroska}
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, TRUE, &CLSID_NULL, NULL, 0, NULL},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CMatroskaMuxerFilter), L"MPC - Matroska Muxer", MERIT_DO_NOT_USE, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{sudFilter[0].strName, sudFilter[0].clsID, CreateInstance<CMatroskaMuxerFilter>, NULL, &sudFilter[0]}
};
@@ -79,7 +75,9 @@ CMatroskaMuxerFilter::CMatroskaMuxerFilter(LPUNKNOWN pUnk, HRESULT* phr) , m_rtCurrent(0)
, m_fNegative(true), m_fPositive(false)
{
- if(phr) *phr = S_OK;
+ if(phr) {
+ *phr = S_OK;
+ }
m_pOutput.Attach(DNew CMatroskaMuxerOutputPin(NAME("CMatroskaMuxerOutputPin"), this, this, phr));
@@ -100,7 +98,7 @@ STDMETHODIMP CMatroskaMuxerFilter::NonDelegatingQueryInterface(REFIID riid, void *ppv = NULL;
return
-// QI(IAMFilterMiscFlags)
+ // QI(IAMFilterMiscFlags)
QI(IMediaSeeking)
QI(IMatroskaMuxer)
__super::NonDelegatingQueryInterface(riid, ppv);
@@ -111,11 +109,11 @@ UINT CMatroskaMuxerFilter::GetTrackNumber(CBasePin* pPin) UINT nTrackNumber = 0;
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
nTrackNumber++;
- if(m_pInputs.GetNext(pos) == pPin)
+ if(m_pInputs.GetNext(pos) == pPin) {
return nTrackNumber;
+ }
}
return 0;
@@ -124,10 +122,11 @@ UINT CMatroskaMuxerFilter::GetTrackNumber(CBasePin* pPin) void CMatroskaMuxerFilter::AddInput()
{
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CBasePin* pPin = m_pInputs.GetNext(pos);
- if(!pPin->IsConnected()) return;
+ if(!pPin->IsConnected()) {
+ return;
+ }
}
CStringW name;
@@ -147,14 +146,13 @@ CBasePin* CMatroskaMuxerFilter::GetPin(int n) {
CAutoLock cAutoLock(this);
- if(n >= 0 && n < (int)m_pInputs.GetCount())
- {
- if(POSITION pos = m_pInputs.FindIndex(n))
+ if(n >= 0 && n < (int)m_pInputs.GetCount()) {
+ if(POSITION pos = m_pInputs.FindIndex(n)) {
return m_pInputs.GetAt(pos);
+ }
}
- if(n == m_pInputs.GetCount() && m_pOutput)
- {
+ if(n == m_pInputs.GetCount() && m_pOutput) {
return m_pOutput;
}
@@ -167,8 +165,9 @@ STDMETHODIMP CMatroskaMuxerFilter::Stop() HRESULT hr;
- if(FAILED(hr = __super::Stop()))
+ if(FAILED(hr = __super::Stop())) {
return hr;
+ }
CallWorker(CMD_EXIT);
@@ -183,11 +182,11 @@ STDMETHODIMP CMatroskaMuxerFilter::Pause() HRESULT hr;
- if(FAILED(hr = __super::Pause()))
+ if(FAILED(hr = __super::Pause())) {
return hr;
+ }
- if(fs == State_Stopped && m_pOutput)
- {
+ if(fs == State_Stopped && m_pOutput) {
CAMThread::Create();
CallWorker(CMD_RUN);
}
@@ -201,8 +200,9 @@ STDMETHODIMP CMatroskaMuxerFilter::Run(REFERENCE_TIME tStart) HRESULT hr;
- if(FAILED(hr = __super::Run(tStart)))
+ if(FAILED(hr = __super::Run(tStart))) {
return hr;
+ }
return hr;
}
@@ -225,25 +225,32 @@ STDMETHODIMP CMatroskaMuxerFilter::GetCapabilities(DWORD* pCapabilities) STDMETHODIMP CMatroskaMuxerFilter::CheckCapabilities(DWORD* pCapabilities)
{
CheckPointer(pCapabilities, E_POINTER);
- if(*pCapabilities == 0) return S_OK;
+ if(*pCapabilities == 0) {
+ return S_OK;
+ }
DWORD caps;
GetCapabilities(&caps);
caps &= *pCapabilities;
return caps == 0 ? E_FAIL : caps == *pCapabilities ? S_OK : S_FALSE;
}
-STDMETHODIMP CMatroskaMuxerFilter::IsFormatSupported(const GUID* pFormat) {
+STDMETHODIMP CMatroskaMuxerFilter::IsFormatSupported(const GUID* pFormat)
+{
return !pFormat ? E_POINTER : *pFormat == TIME_FORMAT_MEDIA_TIME ? S_OK : S_FALSE;
}
-STDMETHODIMP CMatroskaMuxerFilter::QueryPreferredFormat(GUID* pFormat) {
+STDMETHODIMP CMatroskaMuxerFilter::QueryPreferredFormat(GUID* pFormat)
+{
return GetTimeFormat(pFormat);
}
-STDMETHODIMP CMatroskaMuxerFilter::GetTimeFormat(GUID* pFormat) {
+STDMETHODIMP CMatroskaMuxerFilter::GetTimeFormat(GUID* pFormat)
+{
return pFormat ? *pFormat = TIME_FORMAT_MEDIA_TIME, S_OK : E_POINTER;
}
-STDMETHODIMP CMatroskaMuxerFilter::IsUsingTimeFormat(const GUID* pFormat) {
+STDMETHODIMP CMatroskaMuxerFilter::IsUsingTimeFormat(const GUID* pFormat)
+{
return IsFormatSupported(pFormat);
}
-STDMETHODIMP CMatroskaMuxerFilter::SetTimeFormat(const GUID* pFormat) {
+STDMETHODIMP CMatroskaMuxerFilter::SetTimeFormat(const GUID* pFormat)
+{
return S_OK == IsFormatSupported(pFormat) ? S_OK : E_INVALIDARG;
}
STDMETHODIMP CMatroskaMuxerFilter::GetDuration(LONGLONG* pDuration)
@@ -253,11 +260,14 @@ STDMETHODIMP CMatroskaMuxerFilter::GetDuration(LONGLONG* pDuration) POSITION pos = m_pInputs.GetHeadPosition();
while(pos) {
REFERENCE_TIME rt = m_pInputs.GetNext(pos)->m_rtDur;
- if(rt > *pDuration) *pDuration = rt;
+ if(rt > *pDuration) {
+ *pDuration = rt;
+ }
}
return S_OK;
}
-STDMETHODIMP CMatroskaMuxerFilter::GetStopPosition(LONGLONG* pStop) {
+STDMETHODIMP CMatroskaMuxerFilter::GetStopPosition(LONGLONG* pStop)
+{
return E_NOTIMPL;
}
STDMETHODIMP CMatroskaMuxerFilter::GetCurrentPosition(LONGLONG* pCurrent)
@@ -266,25 +276,32 @@ STDMETHODIMP CMatroskaMuxerFilter::GetCurrentPosition(LONGLONG* pCurrent) *pCurrent = m_rtCurrent;
return S_OK;
}
-STDMETHODIMP CMatroskaMuxerFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) {
+STDMETHODIMP CMatroskaMuxerFilter::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CMatroskaMuxerFilter::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags) {
+STDMETHODIMP CMatroskaMuxerFilter::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CMatroskaMuxerFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop) {
+STDMETHODIMP CMatroskaMuxerFilter::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CMatroskaMuxerFilter::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest) {
+STDMETHODIMP CMatroskaMuxerFilter::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CMatroskaMuxerFilter::SetRate(double dRate) {
+STDMETHODIMP CMatroskaMuxerFilter::SetRate(double dRate)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CMatroskaMuxerFilter::GetRate(double* pdRate) {
+STDMETHODIMP CMatroskaMuxerFilter::GetRate(double* pdRate)
+{
return E_NOTIMPL;
}
-STDMETHODIMP CMatroskaMuxerFilter::GetPreroll(LONGLONG* pllPreroll) {
+STDMETHODIMP CMatroskaMuxerFilter::GetPreroll(LONGLONG* pllPreroll)
+{
return E_NOTIMPL;
}
@@ -320,14 +337,16 @@ DWORD CMatroskaMuxerFilter::ThreadProc() {
CComQIPtr<IStream> pStream;
- if(!m_pOutput || !(pStream = m_pOutput->GetConnected()))
- {
- while(1)
- {
+ if(!m_pOutput || !(pStream = m_pOutput->GetConnected())) {
+ while(1) {
DWORD cmd = GetRequest();
- if(cmd == CMD_EXIT) CAMThread::m_hThread = NULL;
+ if(cmd == CMD_EXIT) {
+ CAMThread::m_hThread = NULL;
+ }
Reply(S_OK);
- if(cmd == CMD_EXIT) return 0;
+ if(cmd == CMD_EXIT) {
+ return 0;
+ }
}
}
@@ -350,8 +369,11 @@ DWORD CMatroskaMuxerFilter::ThreadProc() // TODO
MatroskaWriter::QWORD voidlen = 100;
- if(rtDur > 0) voidlen += int(1.0 * rtDur / MAXCLUSTERTIME / 10000 + 0.5) * 20;
- else voidlen += int(1.0 * 1000*60*60*24 / MAXCLUSTERTIME + 0.5) * 20; // when no duration is known, allocate for 24 hours (~340k)
+ if(rtDur > 0) {
+ voidlen += int(1.0 * rtDur / MAXCLUSTERTIME / 10000 + 0.5) * 20;
+ } else {
+ voidlen += int(1.0 * 1000*60*60*24 / MAXCLUSTERTIME + 0.5) * 20; // when no duration is known, allocate for 24 hours (~340k)
+ }
ULONGLONG voidpos = GetStreamPosition(pStream);
{
Void v(voidlen);
@@ -421,257 +443,239 @@ DWORD CMatroskaMuxerFilter::ThreadProc() CAtlList<CMatroskaMuxerInputPin*> pActivePins;
POSITION pos = m_pInputs.GetHeadPosition();
- while(pos)
- {
+ while(pos) {
CMatroskaMuxerInputPin* pPin = m_pInputs.GetNext(pos);
- if(pPin->IsConnected()) pActivePins.AddTail(pPin);
+ if(pPin->IsConnected()) {
+ pActivePins.AddTail(pPin);
+ }
}
- while(1)
- {
+ while(1) {
DWORD cmd = GetRequest();
- switch(cmd)
- {
- default:
- case CMD_EXIT:
- CAMThread::m_hThread = NULL;
- Reply(S_OK);
- return 0;
-
- case CMD_RUN:
- Reply(S_OK);
-
- Cue cue;
- ULONGLONG lastcueclusterpos = (ULONGLONG)-1;
- INT64 lastcuetimecode = (INT64)-1;
- UINT64 nBlocksInCueTrack = 0;
+ switch(cmd) {
+ default:
+ case CMD_EXIT:
+ CAMThread::m_hThread = NULL;
+ Reply(S_OK);
+ return 0;
+
+ case CMD_RUN:
+ Reply(S_OK);
+
+ Cue cue;
+ ULONGLONG lastcueclusterpos = (ULONGLONG)-1;
+ INT64 lastcuetimecode = (INT64)-1;
+ UINT64 nBlocksInCueTrack = 0;
+
+ while(!CheckRequest(NULL)) {
+ if(m_State == State_Paused) {
+ Sleep(10);
+ continue;
+ }
- while(!CheckRequest(NULL))
- {
- if(m_State == State_Paused)
- {
- Sleep(10);
- continue;
- }
+ int nPinsGotSomething = 0, nPinsNeeded = 0;
+ CMatroskaMuxerInputPin* pPin = NULL;
+ REFERENCE_TIME rtMin = _I64_MAX;
- int nPinsGotSomething = 0, nPinsNeeded = 0;
- CMatroskaMuxerInputPin* pPin = NULL;
- REFERENCE_TIME rtMin = _I64_MAX;
+ pos = pActivePins.GetHeadPosition();
+ while(pos) {
+ CMatroskaMuxerInputPin* pTmp = pActivePins.GetNext(pos);
- pos = pActivePins.GetHeadPosition();
- while(pos)
- {
- CMatroskaMuxerInputPin* pTmp = pActivePins.GetNext(pos);
+ CAutoLock cAutoLock(&pTmp->m_csQueue);
- CAutoLock cAutoLock(&pTmp->m_csQueue);
+ if(pTmp->m_blocks.GetCount() == 0 && pTmp->m_fEndOfStreamReceived) {
+ pActivePins.RemoveAt(pActivePins.Find(pTmp));
+ continue;
+ }
- if(pTmp->m_blocks.GetCount() == 0 && pTmp->m_fEndOfStreamReceived)
- {
- pActivePins.RemoveAt(pActivePins.Find(pTmp));
- continue;
- }
+ if(pTmp->GetTrackEntry()->TrackType != TrackEntry::TypeSubtitle) {
+ nPinsNeeded++;
+ }
- if(pTmp->GetTrackEntry()->TrackType != TrackEntry::TypeSubtitle)
- nPinsNeeded++;
+ if(pTmp->m_blocks.GetCount() > 0) {
+ if(pTmp->GetTrackEntry()->TrackType != TrackEntry::TypeSubtitle) {
+ nPinsGotSomething++;
+ }
- if(pTmp->m_blocks.GetCount() > 0)
- {
- if(pTmp->GetTrackEntry()->TrackType != TrackEntry::TypeSubtitle)
- nPinsGotSomething++;
-
- if(pTmp->m_blocks.GetCount() > 0)
- {
- REFERENCE_TIME rt = pTmp->m_blocks.GetHead()->Block.TimeCode;
- if(rt < rtMin) {
- rtMin = rt;
- pPin = pTmp;
+ if(pTmp->m_blocks.GetCount() > 0) {
+ REFERENCE_TIME rt = pTmp->m_blocks.GetHead()->Block.TimeCode;
+ if(rt < rtMin) {
+ rtMin = rt;
+ pPin = pTmp;
+ }
}
}
}
- }
-
- if(pActivePins.GetCount() == 0)
- {
- break;
- }
-
- if(!pPin || nPinsNeeded > nPinsGotSomething || !pPin && nPinsGotSomething == 0)
- {
- Sleep(1);
- continue;
- }
- if(!fTracksWritten)
- {
- CNode<Track> Tracks;
- CAutoPtr<Track> pT(DNew Track());
- POSITION pos = pActivePins.GetHeadPosition();
- for(int i = 1; pos; i++)
- {
- CMatroskaMuxerInputPin* pPin = pActivePins.GetNext(pos);
+ if(pActivePins.GetCount() == 0) {
+ break;
+ }
- CAutoPtr<TrackEntry> pTE(DNew TrackEntry());
- *pTE = *pPin->GetTrackEntry();
- if(TrackNumber == 0 && pTE->TrackType == TrackEntry::TypeVideo)
- TrackNumber = pTE->TrackNumber;
- pT->TrackEntries.AddTail(pTE);
+ if(!pPin || nPinsNeeded > nPinsGotSomething || !pPin && nPinsGotSomething == 0) {
+ Sleep(1);
+ continue;
}
- Tracks.AddTail(pT);
- Tracks.Write(pStream);
- if(TrackNumber == 0) TrackNumber = 1;
+ if(!fTracksWritten) {
+ CNode<Track> Tracks;
+ CAutoPtr<Track> pT(DNew Track());
+ POSITION pos = pActivePins.GetHeadPosition();
+ for(int i = 1; pos; i++) {
+ CMatroskaMuxerInputPin* pPin = pActivePins.GetNext(pos);
+
+ CAutoPtr<TrackEntry> pTE(DNew TrackEntry());
+ *pTE = *pPin->GetTrackEntry();
+ if(TrackNumber == 0 && pTE->TrackType == TrackEntry::TypeVideo) {
+ TrackNumber = pTE->TrackNumber;
+ }
+ pT->TrackEntries.AddTail(pTE);
+ }
+ Tracks.AddTail(pT);
+ Tracks.Write(pStream);
- fTracksWritten = true;
- }
+ if(TrackNumber == 0) {
+ TrackNumber = 1;
+ }
- ASSERT(pPin);
+ fTracksWritten = true;
+ }
- CAutoPtr<BlockGroup> b;
+ ASSERT(pPin);
- {
- CAutoLock cAutoLock(&pPin->m_csQueue);
- b = pPin->m_blocks.RemoveHead();
- }
+ CAutoPtr<BlockGroup> b;
- if(b)
- {
- if(fFirstBlock)
{
- if(b->Block.TimeCode < 0 && m_fNegative || b->Block.TimeCode > 0 && m_fPositive)
- firstTimeCode = b->Block.TimeCode;
- fFirstBlock = false;
+ CAutoLock cAutoLock(&pPin->m_csQueue);
+ b = pPin->m_blocks.RemoveHead();
}
- b->Block.TimeCode -= firstTimeCode;
- b->Block.TimeCodeStop -= firstTimeCode;
-
- /*
- TRACE(_T("Muxing (%d): %I64d-%I64d dur=%I64d (c=%d, co=%dms), cnt=%d, ref=%d\n"),
- GetTrackNumber(pPin),
- (INT64)b->Block.TimeCode, (INT64)b->Block.TimeCodeStop, (UINT64)b->BlockDuration,
- (int)((b->Block.TimeCode)/MAXCLUSTERTIME), (int)(b->Block.TimeCode%MAXCLUSTERTIME),
- b->Block.BlockData.GetCount(), (int)b->ReferenceBlock);
- */
- if(b->Block.TimeCode < SHRT_MIN /*0*/) {
- ASSERT(0);
- continue;
- }
+ if(b) {
+ if(fFirstBlock) {
+ if(b->Block.TimeCode < 0 && m_fNegative || b->Block.TimeCode > 0 && m_fPositive) {
+ firstTimeCode = b->Block.TimeCode;
+ }
+ fFirstBlock = false;
+ }
- while((INT64)(c.TimeCode + MAXCLUSTERTIME) < b->Block.TimeCode)
- {
- if(!c.BlockGroups.IsEmpty())
- {
- sh.Attach(DNew SeekHead());
- sh->ID.Set(c.GetID()/*0x1F43B675*/);
- sh->Position.Set(GetStreamPosition(pStream) - segpos);
- seek.SeekHeads.AddTail(sh);
-
- c.Write(pStream); // TODO: write blocks
+ b->Block.TimeCode -= firstTimeCode;
+ b->Block.TimeCodeStop -= firstTimeCode;
+
+ /*
+ TRACE(_T("Muxing (%d): %I64d-%I64d dur=%I64d (c=%d, co=%dms), cnt=%d, ref=%d\n"),
+ GetTrackNumber(pPin),
+ (INT64)b->Block.TimeCode, (INT64)b->Block.TimeCodeStop, (UINT64)b->BlockDuration,
+ (int)((b->Block.TimeCode)/MAXCLUSTERTIME), (int)(b->Block.TimeCode%MAXCLUSTERTIME),
+ b->Block.BlockData.GetCount(), (int)b->ReferenceBlock);
+ */
+ if(b->Block.TimeCode < SHRT_MIN /*0*/) {
+ ASSERT(0);
+ continue;
}
- c.TimeCode.Set(c.TimeCode + MAXCLUSTERTIME);
- c.BlockGroups.RemoveAll();
- nBlocksInCueTrack = 0;
- }
+ while((INT64)(c.TimeCode + MAXCLUSTERTIME) < b->Block.TimeCode) {
+ if(!c.BlockGroups.IsEmpty()) {
+ sh.Attach(DNew SeekHead());
+ sh->ID.Set(c.GetID()/*0x1F43B675*/);
+ sh->Position.Set(GetStreamPosition(pStream) - segpos);
+ seek.SeekHeads.AddTail(sh);
- if(b->Block.TrackNumber == TrackNumber)
- {
- nBlocksInCueTrack++;
- }
+ c.Write(pStream); // TODO: write blocks
+ }
- if(b->ReferenceBlock == 0 && b->Block.TrackNumber == TrackNumber)
- {
- ULONGLONG clusterpos = GetStreamPosition(pStream) - segpos;
- if(lastcueclusterpos != clusterpos || lastcuetimecode + 1000 < b->Block.TimeCode)
- {
- CAutoPtr<CueTrackPosition> ctp(DNew CueTrackPosition());
- ctp->CueTrack.Set(b->Block.TrackNumber);
- ctp->CueClusterPosition.Set(clusterpos);
- if(c.BlockGroups.GetCount() > 0) ctp->CueBlockNumber.Set(nBlocksInCueTrack);
- CAutoPtr<CuePoint> cp(DNew CuePoint());
- cp->CueTime.Set(b->Block.TimeCode);
- cp->CueTrackPositions.AddTail(ctp);
- cue.CuePoints.AddTail(cp);
- lastcueclusterpos = clusterpos;
- lastcuetimecode = b->Block.TimeCode;
+ c.TimeCode.Set(c.TimeCode + MAXCLUSTERTIME);
+ c.BlockGroups.RemoveAll();
+ nBlocksInCueTrack = 0;
}
- }
- info.Duration.Set(max(info.Duration, (float)b->Block.TimeCodeStop));
+ if(b->Block.TrackNumber == TrackNumber) {
+ nBlocksInCueTrack++;
+ }
- m_rtCurrent = b->Block.TimeCode*10000;
+ if(b->ReferenceBlock == 0 && b->Block.TrackNumber == TrackNumber) {
+ ULONGLONG clusterpos = GetStreamPosition(pStream) - segpos;
+ if(lastcueclusterpos != clusterpos || lastcuetimecode + 1000 < b->Block.TimeCode) {
+ CAutoPtr<CueTrackPosition> ctp(DNew CueTrackPosition());
+ ctp->CueTrack.Set(b->Block.TrackNumber);
+ ctp->CueClusterPosition.Set(clusterpos);
+ if(c.BlockGroups.GetCount() > 0) {
+ ctp->CueBlockNumber.Set(nBlocksInCueTrack);
+ }
+ CAutoPtr<CuePoint> cp(DNew CuePoint());
+ cp->CueTime.Set(b->Block.TimeCode);
+ cp->CueTrackPositions.AddTail(ctp);
+ cue.CuePoints.AddTail(cp);
+ lastcueclusterpos = clusterpos;
+ lastcuetimecode = b->Block.TimeCode;
+ }
+ }
- b->Block.TimeCode -= c.TimeCode;
- c.BlockGroups.AddTail(b);
- }
- }
+ info.Duration.Set(max(info.Duration, (float)b->Block.TimeCodeStop));
- if(!c.BlockGroups.IsEmpty())
- {
- sh.Attach(DNew SeekHead());
- sh->ID.Set(c.GetID()/*0x1F43B675*/);
- sh->Position.Set(GetStreamPosition(pStream) - segpos);
- seek.SeekHeads.AddTail(sh);
+ m_rtCurrent = b->Block.TimeCode*10000;
- c.Write(pStream);
- }
+ b->Block.TimeCode -= c.TimeCode;
+ c.BlockGroups.AddTail(b);
+ }
+ }
- if(!cue.CuePoints.IsEmpty())
- {
- sh.Attach(DNew SeekHead());
- sh->ID.Set(cue.GetID()/*0x1C53BB6B*/);
- sh->Position.Set(GetStreamPosition(pStream) - segpos);
- seek.SeekHeads.AddTail(sh);
+ if(!c.BlockGroups.IsEmpty()) {
+ sh.Attach(DNew SeekHead());
+ sh->ID.Set(c.GetID()/*0x1F43B675*/);
+ sh->Position.Set(GetStreamPosition(pStream) - segpos);
+ seek.SeekHeads.AddTail(sh);
- cue.Write(pStream);
- }
+ c.Write(pStream);
+ }
- {
- Tags tags;
+ if(!cue.CuePoints.IsEmpty()) {
+ sh.Attach(DNew SeekHead());
+ sh->ID.Set(cue.GetID()/*0x1C53BB6B*/);
+ sh->Position.Set(GetStreamPosition(pStream) - segpos);
+ seek.SeekHeads.AddTail(sh);
- sh.Attach(DNew SeekHead());
- sh->ID.Set(tags.GetID());
- sh->Position.Set(GetStreamPosition(pStream) - segpos);
- seek.SeekHeads.AddTail(sh);
+ cue.Write(pStream);
+ }
- tags.Write(pStream);
- }
+ {
+ Tags tags;
- SetStreamPosition(pStream, voidpos);
- int len = (int)(voidlen - seek.Size());
- ASSERT(len >= 0 && len != 1);
- seek.Write(pStream);
+ sh.Attach(DNew SeekHead());
+ sh->ID.Set(tags.GetID());
+ sh->Position.Set(GetStreamPosition(pStream) - segpos);
+ seek.SeekHeads.AddTail(sh);
- if(len == 0)
- {
- // nothing to do
- }
- else if(len >= 2)
- {
- for(int i = 0; i < 8; i++)
- {
- if(len >= (1<<i*7)-2 && len <= (1<<(i+1)*7)-2)
- {
- Void(len-2-i).Write(pStream);
- break;
+ tags.Write(pStream);
+ }
+
+ SetStreamPosition(pStream, voidpos);
+ int len = (int)(voidlen - seek.Size());
+ ASSERT(len >= 0 && len != 1);
+ seek.Write(pStream);
+
+ if(len == 0) {
+ // nothing to do
+ } else if(len >= 2) {
+ for(int i = 0; i < 8; i++) {
+ if(len >= (1<<i*7)-2 && len <= (1<<(i+1)*7)-2) {
+ Void(len-2-i).Write(pStream);
+ break;
+ }
}
}
- }
- if(abs(m_rtCurrent - (REFERENCE_TIME)info.Duration*10000) > 10000000i64)
- {
- info.Duration.Set(m_rtCurrent / 10000 + 1);
- }
+ if(abs(m_rtCurrent - (REFERENCE_TIME)info.Duration*10000) > 10000000i64) {
+ info.Duration.Set(m_rtCurrent / 10000 + 1);
+ }
- SetStreamPosition(pStream, infopos);
- info.Write(pStream);
+ SetStreamPosition(pStream, infopos);
+ info.Write(pStream);
- // TODO: write some tags
+ // TODO: write some tags
- m_pOutput->DeliverEndOfStream();
+ m_pOutput->DeliverEndOfStream();
- break;
+ break;
}
}
@@ -708,31 +712,32 @@ STDMETHODIMP CMatroskaMuxerInputPin::NonDelegatingQueryInterface(REFIID riid, vo HRESULT CMatroskaMuxerInputPin::CheckMediaType(const CMediaType* pmt)
{
return pmt->majortype == MEDIATYPE_Video && (pmt->formattype == FORMAT_VideoInfo
- || pmt->formattype == FORMAT_VideoInfo2)
-// || pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_MPEG1Payload && pmt->formattype == FORMAT_MPEGVideo
-// || pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_MPEG2_VIDEO && pmt->formattype == FORMAT_MPEG2_VIDEO
- || pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_DiracVideo && pmt->formattype == FORMAT_DiracVideoInfo
- || pmt->majortype == MEDIATYPE_Audio && pmt->formattype == FORMAT_WaveFormatEx && pmt->subtype == FOURCCMap(((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag)
- || pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_Vorbis && pmt->formattype == FORMAT_VorbisFormat
- || pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_Vorbis2 && pmt->formattype == FORMAT_VorbisFormat2
- || pmt->majortype == MEDIATYPE_Audio && (pmt->subtype == MEDIASUBTYPE_14_4
- || pmt->subtype == MEDIASUBTYPE_28_8
- || pmt->subtype == MEDIASUBTYPE_ATRC
- || pmt->subtype == MEDIASUBTYPE_COOK
- || pmt->subtype == MEDIASUBTYPE_DNET
- || pmt->subtype == MEDIASUBTYPE_SIPR) && pmt->formattype == FORMAT_WaveFormatEx
- || pmt->majortype == MEDIATYPE_Text && pmt->subtype == MEDIASUBTYPE_NULL && pmt->formattype == FORMAT_None
- || pmt->majortype == MEDIATYPE_Subtitle && pmt->formattype == FORMAT_SubtitleInfo
- ? S_OK
- : E_INVALIDARG;
+ || pmt->formattype == FORMAT_VideoInfo2)
+ // || pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_MPEG1Payload && pmt->formattype == FORMAT_MPEGVideo
+ // || pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_MPEG2_VIDEO && pmt->formattype == FORMAT_MPEG2_VIDEO
+ || pmt->majortype == MEDIATYPE_Video && pmt->subtype == MEDIASUBTYPE_DiracVideo && pmt->formattype == FORMAT_DiracVideoInfo
+ || pmt->majortype == MEDIATYPE_Audio && pmt->formattype == FORMAT_WaveFormatEx && pmt->subtype == FOURCCMap(((WAVEFORMATEX*)pmt->pbFormat)->wFormatTag)
+ || pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_Vorbis && pmt->formattype == FORMAT_VorbisFormat
+ || pmt->majortype == MEDIATYPE_Audio && pmt->subtype == MEDIASUBTYPE_Vorbis2 && pmt->formattype == FORMAT_VorbisFormat2
+ || pmt->majortype == MEDIATYPE_Audio && (pmt->subtype == MEDIASUBTYPE_14_4
+ || pmt->subtype == MEDIASUBTYPE_28_8
+ || pmt->subtype == MEDIASUBTYPE_ATRC
+ || pmt->subtype == MEDIASUBTYPE_COOK
+ || pmt->subtype == MEDIASUBTYPE_DNET
+ || pmt->subtype == MEDIASUBTYPE_SIPR) && pmt->formattype == FORMAT_WaveFormatEx
+ || pmt->majortype == MEDIATYPE_Text && pmt->subtype == MEDIASUBTYPE_NULL && pmt->formattype == FORMAT_None
+ || pmt->majortype == MEDIATYPE_Subtitle && pmt->formattype == FORMAT_SubtitleInfo
+ ? S_OK
+ : E_INVALIDARG;
}
HRESULT CMatroskaMuxerInputPin::BreakConnect()
{
HRESULT hr;
- if(FAILED(hr = __super::BreakConnect()))
+ if(FAILED(hr = __super::BreakConnect())) {
return hr;
+ }
m_pTE.Free();
@@ -743,13 +748,15 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) {
HRESULT hr;
- if(FAILED(hr = __super::CompleteConnect(pPin)))
+ if(FAILED(hr = __super::CompleteConnect(pPin))) {
return hr;
+ }
m_rtDur = 0;
CComQIPtr<IMediaSeeking> pMS;
- if((pMS = GetFilterFromPin(pPin)) || (pMS = pPin))
+ if((pMS = GetFilterFromPin(pPin)) || (pMS = pPin)) {
pMS->GetDuration(&m_rtDur);
+ }
m_pTE.Free();
m_pTE.Attach(DNew TrackEntry());
@@ -761,22 +768,18 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) hr = E_FAIL;
- if(m_mt.majortype == MEDIATYPE_Video)
- {
+ if(m_mt.majortype == MEDIATYPE_Video) {
m_pTE->TrackType.Set(TrackEntry::TypeVideo);
if(m_mt.formattype == FORMAT_VideoInfo
- && m_mt.subtype == MEDIASUBTYPE_RV10 || m_mt.subtype == MEDIASUBTYPE_RV20
- || m_mt.subtype == MEDIASUBTYPE_RV30 || m_mt.subtype == MEDIASUBTYPE_RV40)
- {
+ && m_mt.subtype == MEDIASUBTYPE_RV10 || m_mt.subtype == MEDIASUBTYPE_RV20
+ || m_mt.subtype == MEDIASUBTYPE_RV30 || m_mt.subtype == MEDIASUBTYPE_RV40) {
m_pTE->CodecID.Set("V_REAL/RV00");
m_pTE->CodecID.SetAt(9, (BYTE)(m_mt.subtype.Data1>>16));
- if(m_mt.formattype == FORMAT_VideoInfo)
- {
+ if(m_mt.formattype == FORMAT_VideoInfo) {
VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)m_mt.pbFormat;
- if(m_mt.cbFormat > sizeof(VIDEOINFOHEADER))
- {
+ if(m_mt.cbFormat > sizeof(VIDEOINFOHEADER)) {
m_pTE->CodecPrivate.SetCount(m_mt.cbFormat - sizeof(VIDEOINFOHEADER));
memcpy(m_pTE->CodecPrivate, m_mt.pbFormat + sizeof(VIDEOINFOHEADER), m_pTE->CodecPrivate.GetCount());
}
@@ -784,14 +787,12 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->DescType = TrackEntry::DescVideo;
m_pTE->v.PixelWidth.Set(vih->bmiHeader.biWidth);
m_pTE->v.PixelHeight.Set(abs(vih->bmiHeader.biHeight));
- if(vih->AvgTimePerFrame > 0)
+ if(vih->AvgTimePerFrame > 0) {
m_pTE->v.FramePerSec.Set((float)(10000000.0 / vih->AvgTimePerFrame));
- }
- else if(m_mt.formattype == FORMAT_VideoInfo2)
- {
+ }
+ } else if(m_mt.formattype == FORMAT_VideoInfo2) {
VIDEOINFOHEADER2* vih = (VIDEOINFOHEADER2*)m_mt.pbFormat;
- if(m_mt.cbFormat > sizeof(VIDEOINFOHEADER2))
- {
+ if(m_mt.cbFormat > sizeof(VIDEOINFOHEADER2)) {
m_pTE->CodecPrivate.SetCount(m_mt.cbFormat - sizeof(VIDEOINFOHEADER2));
memcpy(m_pTE->CodecPrivate, m_mt.pbFormat + sizeof(VIDEOINFOHEADER2), m_pTE->CodecPrivate.GetCount());
}
@@ -799,21 +800,18 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->DescType = TrackEntry::DescVideo;
m_pTE->v.PixelWidth.Set(vih->bmiHeader.biWidth);
m_pTE->v.PixelHeight.Set(abs(vih->bmiHeader.biHeight));
- if(vih->AvgTimePerFrame > 0)
+ if(vih->AvgTimePerFrame > 0) {
m_pTE->v.FramePerSec.Set((float)(10000000.0 / vih->AvgTimePerFrame));
+ }
m_pTE->v.DisplayWidth.Set(vih->dwPictAspectRatioX);
m_pTE->v.DisplayHeight.Set(vih->dwPictAspectRatioY);
- }
- else
- {
+ } else {
ASSERT(0);
return hr;
}
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_VideoInfo)
- {
+ } else if(m_mt.formattype == FORMAT_VideoInfo) {
m_pTE->CodecID.Set("V_MS/VFW/FOURCC");
VIDEOINFOHEADER* vih = (VIDEOINFOHEADER*)m_mt.pbFormat;
@@ -823,13 +821,12 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->DescType = TrackEntry::DescVideo;
m_pTE->v.PixelWidth.Set(vih->bmiHeader.biWidth);
m_pTE->v.PixelHeight.Set(abs(vih->bmiHeader.biHeight));
- if(vih->AvgTimePerFrame > 0)
+ if(vih->AvgTimePerFrame > 0) {
m_pTE->v.FramePerSec.Set((float)(10000000.0 / vih->AvgTimePerFrame));
+ }
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_VideoInfo2)
- {
+ } else if(m_mt.formattype == FORMAT_VideoInfo2) {
m_pTE->CodecID.Set("V_MS/VFW/FOURCC");
VIDEOINFOHEADER2* vih = (VIDEOINFOHEADER2*)m_mt.pbFormat;
@@ -841,13 +838,12 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->v.PixelHeight.Set(abs(vih->bmiHeader.biHeight));
m_pTE->v.DisplayWidth.Set(vih->dwPictAspectRatioX);
m_pTE->v.DisplayHeight.Set(vih->dwPictAspectRatioY);
- if(vih->AvgTimePerFrame > 0)
+ if(vih->AvgTimePerFrame > 0) {
m_pTE->v.FramePerSec.Set((float)(10000000.0 / vih->AvgTimePerFrame));
+ }
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_DiracVideoInfo)
- {
+ } else if(m_mt.formattype == FORMAT_DiracVideoInfo) {
m_pTE->CodecID.Set("V_DIRAC");
DIRACINFOHEADER* vih = (DIRACINFOHEADER*)m_mt.pbFormat;
@@ -859,8 +855,9 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->v.PixelHeight.Set(abs(vih->hdr.bmiHeader.biHeight));
// m_pTE->v.DisplayWidth.Set(vih->dwPictAspectRatioX);
// m_pTE->v.DisplayHeight.Set(vih->dwPictAspectRatioY);
- if(vih->hdr.AvgTimePerFrame > 0)
+ if(vih->hdr.AvgTimePerFrame > 0) {
m_pTE->v.FramePerSec.Set((float)(10000000.0 / vih->hdr.AvgTimePerFrame));
+ }
hr = S_OK;
}
@@ -898,15 +895,12 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) hr = S_OK;
}
*/
- }
- else if(m_mt.majortype == MEDIATYPE_Audio)
- {
+ } else if(m_mt.majortype == MEDIATYPE_Audio) {
m_pTE->TrackType.Set(TrackEntry::TypeAudio);
if(m_mt.formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_AAC
- && m_mt.cbFormat >= sizeof(WAVEFORMATEX)+2)
- {
+ && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_AAC
+ && m_mt.cbFormat >= sizeof(WAVEFORMATEX)+2) {
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
BYTE* p = (BYTE*)(wfe+1);
@@ -918,8 +912,7 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) int exttype = 0;
int rate2 = rate1;
- if(wfe->cbSize >= 5)
- {
+ if(wfe->cbSize >= 5) {
profile = 4;
exttype = (p[2]<<3)|(p[3]>>5);
@@ -928,31 +921,29 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) ASSERT((p[4]>>7) == 1);
rate2 = ((p[4]>>3)&15);
- if(rate2 < rate1)
- {
+ if(rate2 < rate1) {
m_pTE->a.OutputSamplingFrequency.Set((float)nSamplesPerSec);
nSamplesPerSec /= 2;
}
}
- switch(profile)
- {
- default:
- case 0:
- m_pTE->CodecID.Set("A_AAC/MPEG2/MAIN");
- break;
- case 1:
- m_pTE->CodecID.Set("A_AAC/MPEG2/LC");
- break;
- case 2:
- m_pTE->CodecID.Set("A_AAC/MPEG2/SSR");
- break;
- case 3:
- m_pTE->CodecID.Set("A_AAC/MPEG4/LTP");
- break;
- case 4:
- m_pTE->CodecID.Set("A_AAC/MPEG4/LC/SBR");
- break;
+ switch(profile) {
+ default:
+ case 0:
+ m_pTE->CodecID.Set("A_AAC/MPEG2/MAIN");
+ break;
+ case 1:
+ m_pTE->CodecID.Set("A_AAC/MPEG2/LC");
+ break;
+ case 2:
+ m_pTE->CodecID.Set("A_AAC/MPEG2/SSR");
+ break;
+ case 3:
+ m_pTE->CodecID.Set("A_AAC/MPEG4/LTP");
+ break;
+ case 4:
+ m_pTE->CodecID.Set("A_AAC/MPEG4/LC/SBR");
+ break;
}
ASSERT(channels == wfe->nChannels);
@@ -963,10 +954,8 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3)
- {
+ } else if(m_mt.formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_DOLBY_AC3) {
m_pTE->CodecID.Set("A_AC3");
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
@@ -976,10 +965,8 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_DVD_DTS)
- {
+ } else if(m_mt.formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_DVD_DTS) {
m_pTE->CodecID.Set("A_DTS");
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
@@ -989,10 +976,8 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_FLAC)
- {
+ } else if(m_mt.formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_FLAC) {
m_pTE->CodecID.Set("A_FLAC");
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
@@ -1001,37 +986,33 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->a.Channels.Set(wfe->nChannels);
m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
- if(wfe->cbSize)
- {
+ if(wfe->cbSize) {
m_pTE->CodecPrivate.SetCount(wfe->cbSize);
memcpy(m_pTE->CodecPrivate, m_mt.pbFormat + sizeof(WAVEFORMATEX), wfe->cbSize);
}
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_WaveFormatEx
- && (m_mt.subtype == MEDIASUBTYPE_14_4
- || m_mt.subtype == MEDIASUBTYPE_28_8
- || m_mt.subtype == MEDIASUBTYPE_ATRC
- || m_mt.subtype == MEDIASUBTYPE_COOK
- || m_mt.subtype == MEDIASUBTYPE_DNET
- || m_mt.subtype == MEDIASUBTYPE_SIPR))
- {
+ } else if(m_mt.formattype == FORMAT_WaveFormatEx
+ && (m_mt.subtype == MEDIASUBTYPE_14_4
+ || m_mt.subtype == MEDIASUBTYPE_28_8
+ || m_mt.subtype == MEDIASUBTYPE_ATRC
+ || m_mt.subtype == MEDIASUBTYPE_COOK
+ || m_mt.subtype == MEDIASUBTYPE_DNET
+ || m_mt.subtype == MEDIASUBTYPE_SIPR)) {
CStringA id;
id.Format("A_REAL/%c%c%c%c",
- (char)((m_mt.subtype.Data1>>0)&0xff),
- (char)((m_mt.subtype.Data1>>8)&0xff),
- (char)((m_mt.subtype.Data1>>16)&0xff),
- (char)((m_mt.subtype.Data1>>24)&0xff));
+ (char)((m_mt.subtype.Data1>>0)&0xff),
+ (char)((m_mt.subtype.Data1>>8)&0xff),
+ (char)((m_mt.subtype.Data1>>16)&0xff),
+ (char)((m_mt.subtype.Data1>>24)&0xff));
m_pTE->CodecID.Set(id);
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
DWORD cbSize = sizeof(WAVEFORMATEX) + wfe->cbSize;
- if(m_mt.cbFormat > cbSize)
- {
- m_pTE->CodecPrivate.SetCount(m_mt.cbFormat - cbSize);
- memcpy(m_pTE->CodecPrivate, m_mt.pbFormat + cbSize, m_pTE->CodecPrivate.GetCount());
+ if(m_mt.cbFormat > cbSize) {
+ m_pTE->CodecPrivate.SetCount(m_mt.cbFormat - cbSize);
+ memcpy(m_pTE->CodecPrivate, m_mt.pbFormat + cbSize, m_pTE->CodecPrivate.GetCount());
}
m_pTE->DescType = TrackEntry::DescAudio;
m_pTE->a.SamplingFrequency.Set((float)wfe->nSamplesPerSec);
@@ -1039,10 +1020,8 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_WaveFormatEx
- && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_PCM)
- {
+ } else if(m_mt.formattype == FORMAT_WaveFormatEx
+ && ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_PCM) {
m_pTE->CodecID.Set("A_PCM/INT/LIT");
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
@@ -1052,9 +1031,7 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_WaveFormatEx)
- {
+ } else if(m_mt.formattype == FORMAT_WaveFormatEx) {
m_pTE->CodecID.Set("A_MS/ACM");
WAVEFORMATEX* wfe = (WAVEFORMATEX*)m_mt.pbFormat;
@@ -1066,9 +1043,7 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->a.BitDepth.Set(wfe->wBitsPerSample);
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_VorbisFormat)
- {
+ } else if(m_mt.formattype == FORMAT_VorbisFormat) {
m_pTE->CodecID.Set("A_VORBIS");
VORBISFORMAT* pvf = (VORBISFORMAT*)m_mt.pbFormat;
@@ -1079,9 +1054,7 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) // m_pTE->CodecPrivate will be filled later
hr = S_OK;
- }
- else if(m_mt.formattype == FORMAT_VorbisFormat2)
- {
+ } else if(m_mt.formattype == FORMAT_VorbisFormat2) {
m_pTE->CodecID.Set("A_VORBIS");
VORBISFORMAT2* pvf2 = (VORBISFORMAT2*)m_mt.pbFormat;
@@ -1091,8 +1064,12 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_pTE->a.BitDepth.Set(pvf2->BitsPerSample);
int len = 1;
- for(int i = 0; i < 2; i++) len += pvf2->HeaderSize[i]/255 + 1;
- for(int i = 0; i < 3; i++) len += pvf2->HeaderSize[i];
+ for(int i = 0; i < 2; i++) {
+ len += pvf2->HeaderSize[i]/255 + 1;
+ }
+ for(int i = 0; i < 3; i++) {
+ len += pvf2->HeaderSize[i];
+ }
m_pTE->CodecPrivate.SetCount(len);
BYTE* src = (BYTE*)m_mt.pbFormat + sizeof(VORBISFORMAT2);
@@ -1100,8 +1077,9 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) *dst++ = 2;
for(int i = 0; i < 2; i++)
- for(int len = pvf2->HeaderSize[i]; len >= 0; len -= 255)
+ for(int len = pvf2->HeaderSize[i]; len >= 0; len -= 255) {
*dst++ = min(len, 255);
+ }
memcpy(dst, src, pvf2->HeaderSize[0]);
dst += pvf2->HeaderSize[0];
@@ -1118,19 +1096,14 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) hr = S_OK;
}
- }
- else if(m_mt.majortype == MEDIATYPE_Text)
- {
+ } else if(m_mt.majortype == MEDIATYPE_Text) {
m_pTE->TrackType.Set(TrackEntry::TypeSubtitle);
- if(m_mt.formattype == FORMAT_None)
- {
+ if(m_mt.formattype == FORMAT_None) {
m_pTE->CodecID.Set("S_TEXT/ASCII");
hr = S_OK;
}
- }
- else if(m_mt.majortype == MEDIATYPE_Subtitle)
- {
+ } else if(m_mt.majortype == MEDIATYPE_Subtitle) {
m_pTE->TrackType.Set(TrackEntry::TypeSubtitle);
m_pTE->CodecID.Set(
@@ -1141,21 +1114,18 @@ HRESULT CMatroskaMuxerInputPin::CompleteConnect(IPin* pPin) m_mt.subtype == MEDIASUBTYPE_VOBSUB ? "S_VOBSUB" :
"");
- if(!m_pTE->CodecID.IsEmpty())
- {
+ if(!m_pTE->CodecID.IsEmpty()) {
hr = S_OK;
SUBTITLEINFO* psi = (SUBTITLEINFO*)m_mt.pbFormat;
- if(psi->dwOffset)
- {
+ if(psi->dwOffset) {
m_pTE->CodecPrivate.SetCount(m_mt.cbFormat - psi->dwOffset);
memcpy(m_pTE->CodecPrivate, m_mt.pbFormat + psi->dwOffset, m_pTE->CodecPrivate.GetCount());
}
}
}
- if(S_OK == hr)
- {
+ if(S_OK == hr) {
(static_cast<CMatroskaMuxerFilter*>(m_pFilter))->AddInput();
}
@@ -1204,23 +1174,26 @@ STDMETHODIMP CMatroskaMuxerInputPin::Receive(IMediaSample* pSample) CAutoLock cAutoLock(&m_csReceive);
- while(m_fActive)
- {
+ while(m_fActive) {
{
CAutoLock cAutoLock2(&m_csQueue);
- if(m_blocks.GetCount() < MAXBLOCKS)
+ if(m_blocks.GetCount() < MAXBLOCKS) {
break;
+ }
}
Sleep(1);
}
- if(!m_fActive) return S_FALSE;
+ if(!m_fActive) {
+ return S_FALSE;
+ }
HRESULT hr;
- if(FAILED(hr = __super::Receive(pSample)))
+ if(FAILED(hr = __super::Receive(pSample))) {
return hr;
+ }
BYTE* pData = NULL;
pSample->GetPointer(&pData);
@@ -1230,15 +1203,14 @@ STDMETHODIMP CMatroskaMuxerInputPin::Receive(IMediaSample* pSample) REFERENCE_TIME rtStart = -1, rtStop = -1;
hr = pSample->GetTime(&rtStart, &rtStop);
- if(FAILED(hr) || rtStart == -1 || rtStop == -1)
- {
+ if(FAILED(hr) || rtStart == -1 || rtStop == -1) {
TRACE(_T("No timestamp was set on the sample!!!"));
m_pFilter->NotifyEvent(EC_ERRORABORT, VFW_E_SAMPLE_TIME_NOT_SET, 0);
return VFW_E_SAMPLE_TIME_NOT_SET;
}
-// rtStart += m_tStart;
-// rtStop += m_tStart;
+ // rtStart += m_tStart;
+ // rtStop += m_tStart;
/**/
TRACE(_T("Received (%d): %I64d-%I64d (c=%d, co=%dms), len=%d, d%d p%d s%d\n"),
@@ -1249,29 +1221,31 @@ STDMETHODIMP CMatroskaMuxerInputPin::Receive(IMediaSample* pSample) pSample->IsPreroll() == S_OK ? 1 : 0,
pSample->IsSyncPoint() == S_OK ? 1 : 0);
- if(m_mt.subtype == MEDIASUBTYPE_Vorbis && m_pVorbisHdrs.GetCount() < 3)
- {
+ if(m_mt.subtype == MEDIASUBTYPE_Vorbis && m_pVorbisHdrs.GetCount() < 3) {
CAutoPtr<CBinary> data(DNew CBinary(0));
data->SetCount(len);
memcpy(data->GetData(), pData, len);
m_pVorbisHdrs.Add(data);
- if(m_pVorbisHdrs.GetCount() == 3)
- {
+ if(m_pVorbisHdrs.GetCount() == 3) {
int len = 1;
- for(int i = 0; i < 2; i++) len += m_pVorbisHdrs[i]->GetCount()/255 + 1;
- for(int i = 0; i < 3; i++) len += m_pVorbisHdrs[i]->GetCount();
+ for(int i = 0; i < 2; i++) {
+ len += m_pVorbisHdrs[i]->GetCount()/255 + 1;
+ }
+ for(int i = 0; i < 3; i++) {
+ len += m_pVorbisHdrs[i]->GetCount();
+ }
m_pTE->CodecPrivate.SetCount(len);
BYTE* dst = m_pTE->CodecPrivate.GetData();
*dst++ = 2;
for(int i = 0; i < 2; i++)
- for(int len = m_pVorbisHdrs[i]->GetCount(); len >= 0; len -= 255)
+ for(int len = m_pVorbisHdrs[i]->GetCount(); len >= 0; len -= 255) {
*dst++ = min(len, 255);
+ }
- for(int i = 0; i < 3; i++)
- {
+ for(int i = 0; i < 3; i++) {
memcpy(dst, m_pVorbisHdrs[i]->GetData(), m_pVorbisHdrs[i]->GetCount());
dst += m_pVorbisHdrs[i]->GetCount();
}
@@ -1281,21 +1255,21 @@ STDMETHODIMP CMatroskaMuxerInputPin::Receive(IMediaSample* pSample) }
if(m_mt.formattype == FORMAT_WaveFormatEx
- && (((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_PCM
- || ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_MPEGLAYER3))
- pSample->SetSyncPoint(TRUE); // HACK: some capture filters don't set this
+ && (((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_PCM
+ || ((WAVEFORMATEX*)m_mt.pbFormat)->wFormatTag == WAVE_FORMAT_MPEGLAYER3)) {
+ pSample->SetSyncPoint(TRUE); // HACK: some capture filters don't set this
+ }
CAutoPtr<BlockGroup> b(DNew BlockGroup());
-/*
- // TODO: test this with a longer capture (pcm, mp3)
- if(S_OK == pSample->IsSyncPoint() && rtStart < m_rtLastStart)
- {
- TRACE(_T("!!! timestamp went backwards, dropping this frame !!! rtStart (%I64) < m_rtLastStart (%I64)"), rtStart, m_rtLastStart);
- return S_OK;
- }
-*/
- if((S_OK != pSample->IsSyncPoint() || m_rtLastStart == rtStart) && m_rtLastStart >= 0 /*&& m_rtLastStart < rtStart*/)
- {
+ /*
+ // TODO: test this with a longer capture (pcm, mp3)
+ if(S_OK == pSample->IsSyncPoint() && rtStart < m_rtLastStart)
+ {
+ TRACE(_T("!!! timestamp went backwards, dropping this frame !!! rtStart (%I64) < m_rtLastStart (%I64)"), rtStart, m_rtLastStart);
+ return S_OK;
+ }
+ */
+ if((S_OK != pSample->IsSyncPoint() || m_rtLastStart == rtStart) && m_rtLastStart >= 0 /*&& m_rtLastStart < rtStart*/) {
ASSERT(m_rtLastStart - rtStart <= 0);
REFERENCE_TIME rtDiff = m_rtLastStart - rtStart;
b->ReferenceBlock.Set((rtDiff + (rtDiff >= 0 ? 5000 : -5000)) / 10000);
@@ -1306,8 +1280,7 @@ STDMETHODIMP CMatroskaMuxerInputPin::Receive(IMediaSample* pSample) b->Block.TimeCode = (rtStart + 5000) / 10000;
b->Block.TimeCodeStop = (rtStop + 5000) / 10000;
- if(m_pTE->TrackType == TrackEntry::TypeSubtitle)
- {
+ if(m_pTE->TrackType == TrackEntry::TypeSubtitle) {
b->BlockDuration.Set((rtStop - rtStart + 5000) / 10000);
}
@@ -1329,8 +1302,9 @@ STDMETHODIMP CMatroskaMuxerInputPin::EndOfStream() {
HRESULT hr;
- if(FAILED(hr = __super::EndOfStream()))
+ if(FAILED(hr = __super::EndOfStream())) {
return hr;
+ }
CAutoLock cAutoLock(&m_csQueue);
@@ -1371,9 +1345,13 @@ HRESULT CMatroskaMuxerOutputPin::DecideBufferSize(IMemAllocator* pAlloc, ALLOCAT pProperties->cbBuffer = 1;
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) return hr;
+ if(FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) {
+ return hr;
+ }
- if(Actual.cbBuffer < pProperties->cbBuffer) return E_FAIL;
+ if(Actual.cbBuffer < pProperties->cbBuffer) {
+ return E_FAIL;
+ }
ASSERT(Actual.cBuffers == pProperties->cBuffers);
return NOERROR;
@@ -1390,8 +1368,12 @@ HRESULT CMatroskaMuxerOutputPin::GetMediaType(int iPosition, CMediaType* pmt) {
CAutoLock cAutoLock(m_pLock);
- if(iPosition < 0) return E_INVALIDARG;
- if(iPosition > 0) return VFW_S_NO_MORE_ITEMS;
+ if(iPosition < 0) {
+ return E_INVALIDARG;
+ }
+ if(iPosition > 0) {
+ return VFW_S_NO_MORE_ITEMS;
+ }
pmt->ResetFormatBuffer();
pmt->InitMediaType();
diff --git a/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.h b/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.h index 4a29b8bb5..4c8eddbd4 100644 --- a/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.h +++ b/src/filters/muxer/MatroskaMuxer/MatroskaMuxer.h @@ -87,8 +87,7 @@ public: interface __declspec(uuid("38E2D43D-915D-493C-B373-888DB16EE3DC"))
IMatroskaMuxer :
-public IUnknown
-{
+public IUnknown {
STDMETHOD (CorrectTimeOffset) (bool fNegative, bool fPositive) = 0;
// TODO: chapters
};
diff --git a/src/filters/muxer/WavDest/WavDest.cpp b/src/filters/muxer/WavDest/WavDest.cpp index 9cd6e2833..05d68a2a5 100644 --- a/src/filters/muxer/WavDest/WavDest.cpp +++ b/src/filters/muxer/WavDest/WavDest.cpp @@ -27,29 +27,24 @@ #ifdef REGISTER_FILTER
-const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesIn[] = {
{&MEDIATYPE_Audio, &MEDIASUBTYPE_WAVE},
};
-const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] =
-{
+const AMOVIESETUP_MEDIATYPE sudPinTypesOut[] = {
{&MEDIATYPE_Stream, &MEDIASUBTYPE_WAVE},
};
-const AMOVIESETUP_PIN sudpPins[] =
-{
+const AMOVIESETUP_PIN sudpPins[] = {
{L"Input", FALSE, FALSE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesIn), sudPinTypesIn},
{L"Output", FALSE, TRUE, FALSE, FALSE, &CLSID_NULL, NULL, countof(sudPinTypesOut), sudPinTypesOut}
};
-const AMOVIESETUP_FILTER sudFilter[] =
-{
+const AMOVIESETUP_FILTER sudFilter[] = {
{&__uuidof(CWavDestFilter), L"MPC - WavDest", MERIT_DO_NOT_USE, countof(sudpPins), sudpPins, CLSID_LegacyAmFilterCategory}
};
-CFactoryTemplate g_Templates[] =
-{
+CFactoryTemplate g_Templates[] = {
{L"WavDest", &__uuidof(CWavDestFilter), CreateInstance<CWavDestFilter>, NULL, &sudFilter[0]}
};
@@ -78,26 +73,25 @@ CFilterApp theApp; CWavDestFilter::CWavDestFilter(LPUNKNOWN pUnk, HRESULT* phr)
: CTransformFilter(NAME("WavDest filter"), pUnk, __uuidof(this))
{
- if(SUCCEEDED(*phr))
- {
- if(CWavDestOutputPin* pOut = DNew CWavDestOutputPin(this, phr))
- {
- if(SUCCEEDED(*phr)) m_pOutput = pOut;
- else delete pOut;
- }
- else
- {
+ if(SUCCEEDED(*phr)) {
+ if(CWavDestOutputPin* pOut = DNew CWavDestOutputPin(this, phr)) {
+ if(SUCCEEDED(*phr)) {
+ m_pOutput = pOut;
+ } else {
+ delete pOut;
+ }
+ } else {
*phr = E_OUTOFMEMORY;
return;
}
- if(CTransformInputPin* pIn = DNew CTransformInputPin(NAME("Transform input pin"), this, phr, L"In"))
- {
- if(SUCCEEDED(*phr)) m_pInput = pIn;
- else delete pIn;
- }
- else
- {
+ if(CTransformInputPin* pIn = DNew CTransformInputPin(NAME("Transform input pin"), this, phr, L"In")) {
+ if(SUCCEEDED(*phr)) {
+ m_pInput = pIn;
+ } else {
+ delete pIn;
+ }
+ } else {
*phr = E_OUTOFMEMORY;
return;
}
@@ -119,8 +113,9 @@ HRESULT CWavDestFilter::Receive(IMediaSample* pSample) HRESULT hr = CTransformFilter::Receive(pSample);
// don't update the count if Deliver() downstream fails.
- if(hr != S_OK)
+ if(hr != S_OK) {
m_cbWavData = cbOld;
+ }
return hr;
}
@@ -130,14 +125,16 @@ HRESULT CWavDestFilter::Transform(IMediaSample* pIn, IMediaSample* pOut) REFERENCE_TIME rtStart, rtEnd;
HRESULT hr = Copy(pIn, pOut);
- if(FAILED(hr))
+ if(FAILED(hr)) {
return hr;
+ }
// Prepare it for writing
LONG lActual = pOut->GetActualDataLength();
- if(m_cbWavData + m_cbHeader + lActual < m_cbWavData + m_cbHeader ) // overflow
+ if(m_cbWavData + m_cbHeader + lActual < m_cbWavData + m_cbHeader ) { // overflow
return E_FAIL;
+ }
rtStart = m_cbWavData + m_cbHeader;
rtEnd = rtStart + lActual;
@@ -166,12 +163,14 @@ HRESULT CWavDestFilter::Copy(IMediaSample* pSource, IMediaSample* pDest) const // Copy the sample times
REFERENCE_TIME TimeStart, TimeEnd;
- if(NOERROR == pSource->GetTime(&TimeStart, &TimeEnd))
+ if(NOERROR == pSource->GetTime(&TimeStart, &TimeEnd)) {
pDest->SetTime(&TimeStart, &TimeEnd);
+ }
LONGLONG MediaStart, MediaEnd;
- if(pSource->GetMediaTime(&MediaStart, &MediaEnd) == NOERROR)
+ if(pSource->GetMediaTime(&MediaStart, &MediaEnd) == NOERROR) {
pDest->SetMediaTime(&MediaStart, &MediaEnd);
+ }
// Copy the media type
AM_MEDIA_TYPE* pMediaType;
@@ -195,8 +194,7 @@ HRESULT CWavDestFilter::GetMediaType(int iPosition, CMediaType* pMediaType) {
ASSERT(iPosition == 0 || iPosition == 1);
- if(iPosition == 0)
- {
+ if(iPosition == 0) {
pMediaType->SetType(&MEDIATYPE_Stream);
pMediaType->SetSubtype(&MEDIASUBTYPE_WAVE);
return S_OK;
@@ -207,8 +205,9 @@ HRESULT CWavDestFilter::GetMediaType(int iPosition, CMediaType* pMediaType) HRESULT CWavDestFilter::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties)
{
- if(m_pInput->IsConnected() == FALSE)
+ if(m_pInput->IsConnected() == FALSE) {
return E_UNEXPECTED;
+ }
ASSERT(pAlloc);
ASSERT(pProperties);
@@ -221,26 +220,23 @@ HRESULT CWavDestFilter::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPER CComPtr<IMemAllocator> pInAlloc;
ALLOCATOR_PROPERTIES InProps;
if(SUCCEEDED(hr = m_pInput->GetAllocator(&pInAlloc))
- && SUCCEEDED(hr = pInAlloc->GetProperties(&InProps)))
- {
+ && SUCCEEDED(hr = pInAlloc->GetProperties(&InProps))) {
pProperties->cbBuffer = InProps.cbBuffer;
- }
- else
- {
+ } else {
return hr;
}
ASSERT(pProperties->cbBuffer);
ALLOCATOR_PROPERTIES Actual;
- if(FAILED(hr = pAlloc->SetProperties(pProperties,&Actual)))
+ if(FAILED(hr = pAlloc->SetProperties(pProperties,&Actual))) {
return hr;
+ }
ASSERT(Actual.cBuffers == 1);
if(pProperties->cBuffers > Actual.cBuffers
- || pProperties->cbBuffer > Actual.cbBuffer)
- {
+ || pProperties->cbBuffer > Actual.cbBuffer) {
return E_FAIL;
}
@@ -271,17 +267,18 @@ HRESULT CWavDestFilter::StartStreaming() HRESULT CWavDestFilter::StopStreaming()
{
IStream* pStream;
- if (m_pOutput->IsConnected() == FALSE)
+ if (m_pOutput->IsConnected() == FALSE) {
return E_FAIL;
+ }
IPin* pDwnstrmInputPin = m_pOutput->GetConnected();
- if (!pDwnstrmInputPin)
+ if (!pDwnstrmInputPin) {
return E_FAIL;
+ }
HRESULT hr = ((IMemInputPin *) pDwnstrmInputPin)->QueryInterface(IID_IStream, (void **)&pStream);
- if(SUCCEEDED(hr))
- {
+ if(SUCCEEDED(hr)) {
BYTE *pb = (BYTE *)_alloca(m_cbHeader);
RIFFLIST *pRiffWave = (RIFFLIST *)pb;
@@ -324,8 +321,9 @@ STDMETHODIMP CWavDestOutputPin::EnumMediaTypes(IEnumMediaTypes** ppEnum) HRESULT CWavDestOutputPin::CheckMediaType(const CMediaType* pmt)
{
- if(pmt->majortype == MEDIATYPE_Stream && pmt->subtype == MEDIASUBTYPE_WAVE)
+ if(pmt->majortype == MEDIATYPE_Stream && pmt->subtype == MEDIASUBTYPE_WAVE) {
return S_OK;
- else
+ } else {
return S_FALSE;
+ }
}
|