2005-02-10 18:13:18 +01:00
|
|
|
/*
|
|
|
|
* WAVE Parser Filter
|
|
|
|
*
|
|
|
|
* Copyright 2005 Christian Costa
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-02-10 18:13:18 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "quartz_private.h"
|
|
|
|
#include "pin.h"
|
|
|
|
|
|
|
|
#include "uuids.h"
|
|
|
|
#include "aviriff.h"
|
|
|
|
#include "vfwmsgs.h"
|
|
|
|
#include "mmsystem.h"
|
|
|
|
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "parser.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
|
|
|
|
2019-03-05 17:56:55 +01:00
|
|
|
static const WCHAR outputW[] = {'o','u','t','p','u','t',0};
|
2005-02-10 18:13:18 +01:00
|
|
|
|
|
|
|
typedef struct WAVEParserImpl
|
|
|
|
{
|
|
|
|
ParserImpl Parser;
|
|
|
|
LONGLONG StartOfFile; /* in media time */
|
|
|
|
LONGLONG EndOfFile;
|
2017-06-19 21:15:32 +02:00
|
|
|
DWORD nAvgBytesPerSec;
|
|
|
|
DWORD nBlockAlign;
|
2005-02-10 18:13:18 +01:00
|
|
|
} WAVEParserImpl;
|
|
|
|
|
2010-10-11 17:15:35 +02:00
|
|
|
static inline WAVEParserImpl *impl_from_IMediaSeeking( IMediaSeeking *iface )
|
|
|
|
{
|
2012-03-24 17:43:09 +01:00
|
|
|
return CONTAINING_RECORD(iface, WAVEParserImpl, Parser.sourceSeeking.IMediaSeeking_iface);
|
2010-10-11 17:15:35 +02:00
|
|
|
}
|
|
|
|
|
2012-05-21 15:21:13 +02:00
|
|
|
static inline WAVEParserImpl *impl_from_IBaseFilter( IBaseFilter *iface )
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, WAVEParserImpl, Parser.filter.IBaseFilter_iface);
|
|
|
|
}
|
|
|
|
|
2008-04-13 01:52:26 +02:00
|
|
|
static LONGLONG bytepos_to_duration(WAVEParserImpl *This, LONGLONG bytepos)
|
|
|
|
{
|
|
|
|
LONGLONG duration = BYTES_FROM_MEDIATIME(bytepos - This->StartOfFile);
|
|
|
|
duration *= 10000000;
|
2017-06-19 21:15:32 +02:00
|
|
|
duration /= This->nAvgBytesPerSec;
|
2008-04-13 01:52:26 +02:00
|
|
|
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONGLONG duration_to_bytepos(WAVEParserImpl *This, LONGLONG duration)
|
|
|
|
{
|
|
|
|
LONGLONG bytepos;
|
|
|
|
|
2017-06-19 21:15:32 +02:00
|
|
|
bytepos = This->nAvgBytesPerSec;
|
2008-04-13 01:52:26 +02:00
|
|
|
bytepos *= duration;
|
|
|
|
bytepos /= 10000000;
|
2017-06-19 21:15:32 +02:00
|
|
|
bytepos -= bytepos % This->nBlockAlign;
|
2008-04-13 01:52:26 +02:00
|
|
|
bytepos += BYTES_FROM_MEDIATIME(This->StartOfFile);
|
|
|
|
|
|
|
|
return MEDIATIME_FROM_BYTES(bytepos);
|
|
|
|
}
|
|
|
|
|
2008-04-19 04:30:25 +02:00
|
|
|
static HRESULT WAVEParser_Sample(LPVOID iface, IMediaSample * pSample, DWORD_PTR cookie)
|
2005-02-10 18:13:18 +01:00
|
|
|
{
|
2009-01-29 11:14:55 +01:00
|
|
|
WAVEParserImpl *This = iface;
|
2005-02-10 18:13:18 +01:00
|
|
|
LPBYTE pbSrcStream = NULL;
|
2008-04-22 22:57:11 +02:00
|
|
|
ULONG cbSrcStream = 0;
|
2005-02-10 18:13:18 +01:00
|
|
|
REFERENCE_TIME tStart, tStop;
|
|
|
|
HRESULT hr;
|
2008-04-22 22:57:11 +02:00
|
|
|
IMediaSample *newsample = NULL;
|
|
|
|
Parser_OutputPin *pOutputPin;
|
|
|
|
PullPin *pin = This->Parser.pInputPin;
|
2005-02-10 18:13:18 +01:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
IMediaSample_GetPointer(pSample, &pbSrcStream);
|
2005-02-10 18:13:18 +01:00
|
|
|
hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
|
|
|
|
|
|
|
|
cbSrcStream = IMediaSample_GetActualDataLength(pSample);
|
|
|
|
|
2008-05-06 20:01:59 +02:00
|
|
|
/* Flush occurring */
|
2008-04-22 22:57:11 +02:00
|
|
|
if (cbSrcStream == 0)
|
|
|
|
{
|
|
|
|
TRACE(".. Why do I need you?\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
2005-02-10 18:13:18 +01:00
|
|
|
|
2019-06-26 03:38:14 +02:00
|
|
|
pOutputPin = This->Parser.sources[0];
|
2005-02-10 18:13:18 +01:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = IMemAllocator_GetBuffer(pin->pAlloc, &newsample, NULL, NULL, 0);
|
2005-02-10 18:13:18 +01:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
if (SUCCEEDED(hr))
|
2005-02-10 18:13:18 +01:00
|
|
|
{
|
2008-04-22 22:57:11 +02:00
|
|
|
LONGLONG rtSampleStart = pin->rtNext;
|
|
|
|
/* Add 4 for the next header, which should hopefully work */
|
|
|
|
LONGLONG rtSampleStop = rtSampleStart + MEDIATIME_FROM_BYTES(IMediaSample_GetSize(newsample));
|
2005-02-10 18:13:18 +01:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
if (rtSampleStop > pin->rtStop)
|
|
|
|
rtSampleStop = MEDIATIME_FROM_BYTES(ALIGNUP(BYTES_FROM_MEDIATIME(pin->rtStop), pin->cbAlign));
|
2005-02-10 18:13:18 +01:00
|
|
|
|
2015-01-21 12:01:34 +01:00
|
|
|
IMediaSample_SetTime(newsample, &rtSampleStart, &rtSampleStop);
|
2005-02-10 18:13:18 +01:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
pin->rtCurrent = pin->rtNext;
|
|
|
|
pin->rtNext = rtSampleStop;
|
2005-02-10 18:13:18 +01:00
|
|
|
|
2015-09-12 13:24:24 +02:00
|
|
|
IMediaSample_SetPreroll(newsample, FALSE);
|
|
|
|
IMediaSample_SetDiscontinuity(newsample, FALSE);
|
|
|
|
IMediaSample_SetSyncPoint(newsample, TRUE);
|
2005-02-10 18:13:18 +01:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
hr = IAsyncReader_Request(pin->pReader, newsample, 0);
|
|
|
|
}
|
2008-04-16 22:39:10 +02:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
REFERENCE_TIME tAviStart, tAviStop;
|
2005-02-10 18:13:18 +01:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
IMediaSample_SetSyncPoint(pSample, TRUE);
|
|
|
|
pOutputPin->dwSamplesProcessed++;
|
2008-04-13 01:52:26 +02:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
tAviStart = bytepos_to_duration(This, tStart);
|
|
|
|
tAviStop = bytepos_to_duration(This, tStart + MEDIATIME_FROM_BYTES(IMediaSample_GetActualDataLength(pSample)));
|
2005-02-10 18:13:18 +01:00
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
IMediaSample_SetTime(pSample, &tAviStart, &tAviStop);
|
2005-02-10 18:13:18 +01:00
|
|
|
|
2010-10-05 21:37:56 +02:00
|
|
|
hr = BaseOutputPinImpl_Deliver(&pOutputPin->pin, pSample);
|
2008-04-30 23:34:19 +02:00
|
|
|
if (hr != S_OK && hr != S_FALSE && hr != VFW_E_WRONG_STATE)
|
2008-04-22 22:57:11 +02:00
|
|
|
ERR("Error sending sample (%x)\n", hr);
|
2008-04-30 23:34:19 +02:00
|
|
|
else if (hr != S_OK)
|
|
|
|
/* Unset progression if denied! */
|
|
|
|
This->Parser.pInputPin->rtCurrent = tStart;
|
2005-02-10 18:13:18 +01:00
|
|
|
}
|
|
|
|
|
2010-10-11 17:15:35 +02:00
|
|
|
if (tStop >= This->EndOfFile || (bytepos_to_duration(This, tStop) >= This->Parser.sourceSeeking.llStop) || hr == VFW_E_NOT_CONNECTED)
|
2005-03-02 11:12:12 +01:00
|
|
|
{
|
2008-11-04 23:22:53 +01:00
|
|
|
unsigned int i;
|
2005-03-02 11:12:12 +01:00
|
|
|
|
|
|
|
TRACE("End of file reached\n");
|
|
|
|
|
|
|
|
for (i = 0; i < This->Parser.cStreams; i++)
|
|
|
|
{
|
|
|
|
IPin* ppin;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2008-11-04 23:22:53 +01:00
|
|
|
TRACE("Send End Of Stream to output pin %u\n", i);
|
2005-03-02 11:12:12 +01:00
|
|
|
|
2019-06-26 03:38:14 +02:00
|
|
|
hr = IPin_ConnectedTo(&This->Parser.sources[i]->pin.pin.IPin_iface, &ppin);
|
2005-03-02 11:12:12 +01:00
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = IPin_EndOfStream(ppin);
|
|
|
|
IPin_Release(ppin);
|
|
|
|
}
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("%x\n", hr);
|
2005-03-02 11:12:12 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Force the pullpin thread to stop */
|
|
|
|
hr = S_FALSE;
|
|
|
|
}
|
|
|
|
|
2005-02-10 18:13:18 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WAVEParser_QueryAccept(LPVOID iface, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
|
|
|
if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Stream))
|
|
|
|
return S_FALSE;
|
|
|
|
if (IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_WAVE))
|
|
|
|
return S_OK;
|
|
|
|
if (IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_AU) || IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_AIFF))
|
|
|
|
FIXME("AU and AIFF files not supported yet!\n");
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
2010-10-11 17:15:35 +02:00
|
|
|
static HRESULT WINAPI WAVEParserImpl_seek(IMediaSeeking *iface)
|
2008-04-13 01:52:26 +02:00
|
|
|
{
|
2010-10-11 17:15:35 +02:00
|
|
|
WAVEParserImpl *This = impl_from_IMediaSeeking(iface);
|
2008-04-13 01:52:26 +02:00
|
|
|
PullPin *pPin = This->Parser.pInputPin;
|
|
|
|
LONGLONG newpos, curpos, endpos, bytepos;
|
2019-06-26 03:38:14 +02:00
|
|
|
IPin *peer;
|
2008-04-13 01:52:26 +02:00
|
|
|
|
2010-10-11 17:15:35 +02:00
|
|
|
newpos = This->Parser.sourceSeeking.llCurrent;
|
2008-04-13 01:52:26 +02:00
|
|
|
curpos = bytepos_to_duration(This, pPin->rtCurrent);
|
|
|
|
endpos = bytepos_to_duration(This, This->EndOfFile);
|
|
|
|
bytepos = duration_to_bytepos(This, newpos);
|
|
|
|
|
|
|
|
if (newpos > endpos)
|
|
|
|
{
|
2018-08-10 08:00:34 +02:00
|
|
|
WARN("Requesting position %s beyond end of stream %s\n",
|
|
|
|
wine_dbgstr_longlong(newpos), wine_dbgstr_longlong(endpos));
|
2008-04-13 01:52:26 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curpos/1000000 == newpos/1000000)
|
|
|
|
{
|
2018-08-10 08:00:34 +02:00
|
|
|
TRACE("Requesting position %s same as current position %s\n",
|
|
|
|
wine_dbgstr_longlong(newpos), wine_dbgstr_longlong(curpos));
|
2008-04-13 01:52:26 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Moving sound to %08u bytes!\n", (DWORD)BYTES_FROM_MEDIATIME(bytepos));
|
|
|
|
|
|
|
|
EnterCriticalSection(&pPin->thread_lock);
|
2012-04-04 15:27:25 +02:00
|
|
|
IPin_BeginFlush(&pPin->pin.IPin_iface);
|
2008-04-13 01:52:26 +02:00
|
|
|
|
|
|
|
/* Make sure this is done while stopped, BeginFlush takes care of this */
|
2010-10-07 21:47:33 +02:00
|
|
|
EnterCriticalSection(&This->Parser.filter.csFilter);
|
2019-06-26 03:38:14 +02:00
|
|
|
|
|
|
|
if ((peer = This->Parser.sources[0]->pin.pin.pConnectedTo))
|
|
|
|
IPin_NewSegment(peer, newpos, endpos, pPin->dRate);
|
2008-04-13 01:52:26 +02:00
|
|
|
|
|
|
|
pPin->rtStart = pPin->rtCurrent = bytepos;
|
2019-06-26 03:38:14 +02:00
|
|
|
This->Parser.sources[0]->dwSamplesProcessed = 0;
|
2010-10-07 21:47:33 +02:00
|
|
|
LeaveCriticalSection(&This->Parser.filter.csFilter);
|
2008-04-13 01:52:26 +02:00
|
|
|
|
|
|
|
TRACE("Done flushing\n");
|
2012-04-04 15:27:25 +02:00
|
|
|
IPin_EndFlush(&pPin->pin.IPin_iface);
|
2008-04-13 01:52:26 +02:00
|
|
|
LeaveCriticalSection(&pPin->thread_lock);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
static HRESULT WAVEParser_InputPin_PreConnect(IPin * iface, IPin * pConnectPin, ALLOCATOR_PROPERTIES *props)
|
2005-02-10 18:13:18 +01:00
|
|
|
{
|
2012-04-04 15:27:25 +02:00
|
|
|
PullPin *This = impl_PullPin_from_IPin(iface);
|
2005-02-10 18:13:18 +01:00
|
|
|
HRESULT hr;
|
|
|
|
RIFFLIST list;
|
|
|
|
RIFFCHUNK chunk;
|
|
|
|
LONGLONG pos = 0; /* in bytes */
|
|
|
|
PIN_INFO piOutput;
|
|
|
|
AM_MEDIA_TYPE amt;
|
2012-05-21 15:21:13 +02:00
|
|
|
WAVEParserImpl * pWAVEParser = impl_from_IBaseFilter(This->pin.pinInfo.pFilter);
|
2005-02-10 18:13:18 +01:00
|
|
|
|
|
|
|
piOutput.dir = PINDIR_OUTPUT;
|
2012-05-21 15:21:13 +02:00
|
|
|
piOutput.pFilter = &pWAVEParser->Parser.filter.IBaseFilter_iface;
|
2019-03-05 17:56:55 +01:00
|
|
|
lstrcpynW(piOutput.achName, outputW, ARRAY_SIZE(piOutput.achName));
|
2018-07-17 21:20:08 +02:00
|
|
|
|
2005-02-10 18:13:18 +01:00
|
|
|
hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(list), (BYTE *)&list);
|
|
|
|
pos += sizeof(list);
|
|
|
|
|
2008-04-11 00:45:32 +02:00
|
|
|
if (list.fcc != FOURCC_RIFF)
|
2005-02-10 18:13:18 +01:00
|
|
|
{
|
|
|
|
ERR("Input stream not a RIFF file\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
if (list.cb > 1 * 1024 * 1024 * 1024) /* cannot be more than 1Gb in size */
|
|
|
|
{
|
|
|
|
ERR("Input stream violates RIFF spec\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
if (list.fccListType != mmioFOURCC('W','A','V','E'))
|
|
|
|
{
|
|
|
|
ERR("Input stream not an WAVE RIFF file\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(chunk), (BYTE *)&chunk);
|
|
|
|
pos += sizeof(chunk);
|
|
|
|
if (chunk.fcc != mmioFOURCC('f','m','t',' '))
|
|
|
|
{
|
|
|
|
ERR("Expected 'fmt ' chunk, but got %.04s\n", (LPSTR)&chunk.fcc);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2008-03-12 21:32:07 +01:00
|
|
|
amt.majortype = MEDIATYPE_Audio;
|
|
|
|
amt.formattype = FORMAT_WaveFormatEx;
|
2019-03-05 17:57:00 +01:00
|
|
|
amt.bFixedSizeSamples = TRUE;
|
|
|
|
amt.bTemporalCompression = FALSE;
|
|
|
|
amt.lSampleSize = 1;
|
|
|
|
amt.pUnk = NULL;
|
2019-03-05 17:56:59 +01:00
|
|
|
amt.cbFormat = max(chunk.cb, sizeof(WAVEFORMATEX));
|
2005-02-10 18:13:18 +01:00
|
|
|
amt.pbFormat = CoTaskMemAlloc(amt.cbFormat);
|
2019-03-05 17:56:59 +01:00
|
|
|
memset(amt.pbFormat, 0, amt.cbFormat);
|
|
|
|
IAsyncReader_SyncRead(This->pReader, pos, chunk.cb, amt.pbFormat);
|
2008-03-12 21:32:07 +01:00
|
|
|
amt.subtype = MEDIATYPE_Audio;
|
2005-02-10 18:13:18 +01:00
|
|
|
amt.subtype.Data1 = ((WAVEFORMATEX*)amt.pbFormat)->wFormatTag;
|
|
|
|
|
|
|
|
pos += chunk.cb;
|
|
|
|
hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(chunk), (BYTE *)&chunk);
|
2019-03-04 03:11:49 +01:00
|
|
|
while (chunk.fcc != mmioFOURCC('d','a','t','a'))
|
2005-02-10 18:13:18 +01:00
|
|
|
{
|
2019-03-04 03:11:49 +01:00
|
|
|
FIXME("Ignoring %s chunk.\n", debugstr_fourcc(chunk.fcc));
|
|
|
|
pos += sizeof(chunk) + chunk.cb;
|
|
|
|
hr = IAsyncReader_SyncRead(This->pReader, pos, sizeof(chunk), (BYTE *)&chunk);
|
|
|
|
if (hr != S_OK)
|
|
|
|
return E_FAIL;
|
2005-02-10 18:13:18 +01:00
|
|
|
}
|
|
|
|
|
2018-08-10 08:00:33 +02:00
|
|
|
pWAVEParser->StartOfFile = MEDIATIME_FROM_BYTES(pos + sizeof(RIFFCHUNK));
|
|
|
|
pWAVEParser->EndOfFile = MEDIATIME_FROM_BYTES(pos + chunk.cb + sizeof(RIFFCHUNK));
|
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
props->cbAlign = ((WAVEFORMATEX*)amt.pbFormat)->nBlockAlign;
|
|
|
|
props->cbPrefix = 0;
|
|
|
|
props->cbBuffer = 4096;
|
2008-04-30 23:34:19 +02:00
|
|
|
props->cBuffers = 3;
|
2017-06-19 21:15:32 +02:00
|
|
|
pWAVEParser->nBlockAlign = ((WAVEFORMATEX*)amt.pbFormat)->nBlockAlign;
|
|
|
|
pWAVEParser->nAvgBytesPerSec = ((WAVEFORMATEX*)amt.pbFormat)->nAvgBytesPerSec;
|
2008-04-22 22:57:11 +02:00
|
|
|
hr = Parser_AddPin(&(pWAVEParser->Parser), &piOutput, props, &amt);
|
2008-04-13 01:52:26 +02:00
|
|
|
CoTaskMemFree(amt.pbFormat);
|
|
|
|
|
2010-10-11 17:15:35 +02:00
|
|
|
pWAVEParser->Parser.sourceSeeking.llCurrent = 0;
|
|
|
|
pWAVEParser->Parser.sourceSeeking.llStop = pWAVEParser->Parser.sourceSeeking.llDuration = bytepos_to_duration(pWAVEParser, pWAVEParser->EndOfFile);
|
|
|
|
TRACE("Duration: %u seconds\n", (DWORD)(pWAVEParser->Parser.sourceSeeking.llDuration / (LONGLONG)10000000));
|
2008-04-13 01:52:26 +02:00
|
|
|
|
|
|
|
This->rtStop = pWAVEParser->EndOfFile;
|
|
|
|
This->rtStart = pWAVEParser->StartOfFile;
|
|
|
|
|
2005-02-10 18:13:18 +01:00
|
|
|
TRACE("WAVE File ok\n");
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2007-04-07 06:24:59 +02:00
|
|
|
static HRESULT WAVEParser_Cleanup(LPVOID iface)
|
|
|
|
{
|
2009-01-29 11:14:55 +01:00
|
|
|
WAVEParserImpl *This = iface;
|
2007-04-07 06:24:59 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-22 22:57:11 +02:00
|
|
|
static HRESULT WAVEParser_first_request(LPVOID iface)
|
|
|
|
{
|
2009-01-29 11:14:55 +01:00
|
|
|
WAVEParserImpl *This = iface;
|
2008-04-22 22:57:11 +02:00
|
|
|
PullPin *pin = This->Parser.pInputPin;
|
|
|
|
HRESULT hr;
|
|
|
|
IMediaSample *sample;
|
|
|
|
|
|
|
|
if (pin->rtCurrent >= pin->rtStop)
|
|
|
|
{
|
|
|
|
/* Last sample has already been queued, request nothing more */
|
|
|
|
TRACE("Done!\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IMemAllocator_GetBuffer(pin->pAlloc, &sample, NULL, NULL, 0);
|
|
|
|
|
|
|
|
pin->rtNext = pin->rtCurrent;
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
LONGLONG rtSampleStart = pin->rtNext;
|
|
|
|
/* Add 4 for the next header, which should hopefully work */
|
|
|
|
LONGLONG rtSampleStop = rtSampleStart + MEDIATIME_FROM_BYTES(IMediaSample_GetSize(sample));
|
|
|
|
|
|
|
|
if (rtSampleStop > pin->rtStop)
|
|
|
|
rtSampleStop = MEDIATIME_FROM_BYTES(ALIGNUP(BYTES_FROM_MEDIATIME(pin->rtStop), pin->cbAlign));
|
|
|
|
|
2015-01-21 12:01:34 +01:00
|
|
|
IMediaSample_SetTime(sample, &rtSampleStart, &rtSampleStop);
|
2008-04-22 22:57:11 +02:00
|
|
|
|
|
|
|
pin->rtCurrent = pin->rtNext;
|
|
|
|
pin->rtNext = rtSampleStop;
|
|
|
|
|
|
|
|
IMediaSample_SetPreroll(sample, FALSE);
|
2019-06-26 03:38:14 +02:00
|
|
|
if (!This->Parser.sources[0]->dwSamplesProcessed++)
|
2008-04-22 22:57:11 +02:00
|
|
|
IMediaSample_SetDiscontinuity(sample, TRUE);
|
|
|
|
else
|
|
|
|
IMediaSample_SetDiscontinuity(sample, FALSE);
|
|
|
|
|
|
|
|
hr = IAsyncReader_Request(pin->pReader, sample, 0);
|
|
|
|
}
|
|
|
|
if (FAILED(hr))
|
2008-06-24 17:52:52 +02:00
|
|
|
ERR("Horsemen of the apocalypse came to bring error 0x%08x %p\n", hr, sample);
|
2008-04-22 22:57:11 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2008-04-16 05:39:36 +02:00
|
|
|
static HRESULT WAVEParser_disconnect(LPVOID iface)
|
|
|
|
{
|
|
|
|
/* TODO: Find and plug memory leaks */
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-04-23 20:23:43 +02:00
|
|
|
static const IBaseFilterVtbl WAVEParser_Vtbl =
|
|
|
|
{
|
2019-05-29 06:10:18 +02:00
|
|
|
BaseFilterImpl_QueryInterface,
|
|
|
|
BaseFilterImpl_AddRef,
|
2019-05-29 06:10:17 +02:00
|
|
|
BaseFilterImpl_Release,
|
2019-05-29 06:10:18 +02:00
|
|
|
BaseFilterImpl_GetClassID,
|
2008-04-23 20:23:43 +02:00
|
|
|
Parser_Stop,
|
|
|
|
Parser_Pause,
|
|
|
|
Parser_Run,
|
|
|
|
Parser_GetState,
|
|
|
|
Parser_SetSyncSource,
|
2019-05-29 06:10:18 +02:00
|
|
|
BaseFilterImpl_GetSyncSource,
|
|
|
|
BaseFilterImpl_EnumPins,
|
2018-07-05 00:34:41 +02:00
|
|
|
BaseFilterImpl_FindPin,
|
2019-05-29 06:10:18 +02:00
|
|
|
BaseFilterImpl_QueryFilterInfo,
|
|
|
|
BaseFilterImpl_JoinFilterGraph,
|
|
|
|
BaseFilterImpl_QueryVendorInfo,
|
2008-04-23 20:23:43 +02:00
|
|
|
};
|
|
|
|
|
2019-05-29 06:10:17 +02:00
|
|
|
static void wave_parser_destroy(BaseFilter *iface)
|
|
|
|
{
|
|
|
|
WAVEParserImpl *filter = impl_from_IBaseFilter(&iface->IBaseFilter_iface);
|
|
|
|
Parser_Destroy(&filter->Parser);
|
|
|
|
}
|
|
|
|
|
2019-05-28 06:09:58 +02:00
|
|
|
static const BaseFilterFuncTable wave_parser_func_table =
|
|
|
|
{
|
|
|
|
.filter_get_pin = parser_get_pin,
|
2019-05-29 06:10:17 +02:00
|
|
|
.filter_destroy = wave_parser_destroy,
|
2019-05-28 06:09:58 +02:00
|
|
|
};
|
|
|
|
|
2019-06-04 17:01:17 +02:00
|
|
|
HRESULT WAVEParser_create(IUnknown *outer, void **out)
|
2005-02-10 18:13:18 +01:00
|
|
|
{
|
2019-03-01 02:00:26 +01:00
|
|
|
static const WCHAR sink_name[] = {'i','n','p','u','t',' ','p','i','n',0};
|
2005-02-10 18:13:18 +01:00
|
|
|
HRESULT hr;
|
|
|
|
WAVEParserImpl * This;
|
|
|
|
|
2019-06-04 17:01:17 +02:00
|
|
|
*out = NULL;
|
2005-02-10 18:13:18 +01:00
|
|
|
|
|
|
|
/* Note: This memory is managed by the transform filter once created */
|
|
|
|
This = CoTaskMemAlloc(sizeof(WAVEParserImpl));
|
|
|
|
|
2019-06-04 17:01:17 +02:00
|
|
|
hr = Parser_Create(&This->Parser, &WAVEParser_Vtbl, outer, &CLSID_WAVEParser,
|
2019-05-28 06:09:58 +02:00
|
|
|
&wave_parser_func_table, sink_name, WAVEParser_Sample, WAVEParser_QueryAccept,
|
2019-03-01 02:00:26 +01:00
|
|
|
WAVEParser_InputPin_PreConnect, WAVEParser_Cleanup, WAVEParser_disconnect,
|
|
|
|
WAVEParser_first_request, NULL, NULL, WAVEParserImpl_seek, NULL);
|
2005-02-10 18:13:18 +01:00
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2019-06-04 17:01:17 +02:00
|
|
|
*out = &This->Parser.filter.IUnknown_inner;
|
2005-02-10 18:13:18 +01:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|