2005-02-01 15:22:00 +01:00
|
|
|
/*
|
|
|
|
* ACM Wrapper
|
|
|
|
*
|
|
|
|
* 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-01 15:22:00 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "quartz_private.h"
|
|
|
|
|
|
|
|
#include "uuids.h"
|
|
|
|
#include "mmreg.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "dshow.h"
|
|
|
|
#include "strmif.h"
|
|
|
|
#include "vfwmsgs.h"
|
|
|
|
#include "msacm.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
|
|
|
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper
|
2005-02-01 15:22:00 +01:00
|
|
|
{
|
2020-03-11 04:03:28 +01:00
|
|
|
struct strmbase_filter filter;
|
2010-10-07 21:48:19 +02:00
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
struct strmbase_source source;
|
|
|
|
IQualityControl source_IQualityControl_iface;
|
|
|
|
IQualityControl *source_qc_sink;
|
2020-03-28 18:02:04 +01:00
|
|
|
struct strmbase_passthrough passthrough;
|
2020-03-11 04:03:28 +01:00
|
|
|
|
|
|
|
struct strmbase_sink sink;
|
|
|
|
|
|
|
|
AM_MEDIA_TYPE mt;
|
2005-02-01 15:22:00 +01:00
|
|
|
HACMSTREAM has;
|
|
|
|
LPWAVEFORMATEX pWfOut;
|
2008-04-25 23:15:42 +02:00
|
|
|
|
|
|
|
LONGLONG lasttime_real;
|
|
|
|
LONGLONG lasttime_sent;
|
2020-04-01 06:48:15 +02:00
|
|
|
};
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2020-04-01 06:48:15 +02:00
|
|
|
static struct acm_wrapper *impl_from_strmbase_filter(struct strmbase_filter *iface)
|
2012-03-31 03:10:47 +02:00
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct acm_wrapper, filter);
|
2020-03-11 04:03:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT acm_wrapper_sink_query_interface(struct strmbase_pin *iface, REFIID iid, void **out)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_strmbase_filter(iface->filter);
|
2020-03-11 04:03:28 +01:00
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_IMemInputPin))
|
|
|
|
*out = &filter->sink.IMemInputPin_iface;
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT acm_wrapper_sink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
return S_OK;
|
2012-03-31 03:10:47 +02:00
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
static HRESULT WINAPI acm_wrapper_sink_Receive(struct strmbase_sink *iface, IMediaSample *pSample)
|
2005-02-01 15:22:00 +01:00
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *This = impl_from_strmbase_filter(iface->pin.filter);
|
2007-04-07 11:32:45 +02:00
|
|
|
IMediaSample* pOutSample = NULL;
|
2008-03-21 22:55:03 +01:00
|
|
|
DWORD cbDstStream, cbSrcStream;
|
2005-02-01 15:22:00 +01:00
|
|
|
LPBYTE pbDstStream;
|
2007-04-07 11:32:45 +02:00
|
|
|
LPBYTE pbSrcStream = NULL;
|
2005-02-01 15:22:00 +01:00
|
|
|
ACMSTREAMHEADER ash;
|
2008-04-19 01:07:05 +02:00
|
|
|
BOOL unprepare_header = FALSE, preroll;
|
2005-02-01 15:22:00 +01:00
|
|
|
MMRESULT res;
|
2007-04-07 11:32:45 +02:00
|
|
|
HRESULT hr;
|
2008-03-21 22:55:03 +01:00
|
|
|
LONGLONG tStart = -1, tStop = -1, tMed;
|
2010-11-07 15:02:47 +01:00
|
|
|
LONGLONG mtStart = -1, mtStop = -1, mtMed;
|
2008-07-05 01:59:22 +02:00
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
/* We do not expect pin connection state to change while the filter is
|
|
|
|
* running. This guarantee is necessary, since otherwise we would have to
|
|
|
|
* take the filter lock, and we can't take the filter lock from a streaming
|
|
|
|
* thread. */
|
|
|
|
if (!This->source.pMemInputPin)
|
|
|
|
{
|
|
|
|
WARN("Source is not connected, returning VFW_E_NOT_CONNECTED.\n");
|
|
|
|
return VFW_E_NOT_CONNECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->filter.state == State_Stopped)
|
|
|
|
return VFW_E_WRONG_STATE;
|
|
|
|
|
|
|
|
if (This->sink.flushing)
|
|
|
|
return S_FALSE;
|
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Cannot get pointer to sample data (%x)\n", hr);
|
2008-07-05 01:59:22 +02:00
|
|
|
return hr;
|
2007-04-07 11:32:45 +02:00
|
|
|
}
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2008-04-30 19:33:07 +02:00
|
|
|
preroll = (IMediaSample_IsPreroll(pSample) == S_OK);
|
2008-04-29 01:32:57 +02:00
|
|
|
|
2008-04-30 19:33:07 +02:00
|
|
|
IMediaSample_GetTime(pSample, &tStart, &tStop);
|
2010-11-07 15:02:47 +01:00
|
|
|
if (IMediaSample_GetMediaTime(pSample, &mtStart, &mtStop) != S_OK)
|
|
|
|
mtStart = mtStop = -1;
|
2008-04-30 19:33:07 +02:00
|
|
|
cbSrcStream = IMediaSample_GetActualDataLength(pSample);
|
2008-04-29 01:32:57 +02:00
|
|
|
|
2008-04-30 19:33:07 +02:00
|
|
|
/* Prevent discontinuities when codecs 'absorb' data but not give anything back in return */
|
|
|
|
if (IMediaSample_IsDiscontinuity(pSample) == S_OK)
|
2008-04-29 01:32:57 +02:00
|
|
|
{
|
2008-04-30 19:33:07 +02:00
|
|
|
This->lasttime_real = tStart;
|
|
|
|
This->lasttime_sent = tStart;
|
2008-04-29 01:32:57 +02:00
|
|
|
}
|
2008-04-30 19:33:07 +02:00
|
|
|
else if (This->lasttime_real == tStart)
|
|
|
|
tStart = This->lasttime_sent;
|
|
|
|
else
|
|
|
|
WARN("Discontinuity\n");
|
|
|
|
|
2008-04-25 23:15:42 +02:00
|
|
|
tMed = tStart;
|
2010-11-07 15:02:47 +01:00
|
|
|
mtMed = mtStart;
|
2008-04-25 23:15:42 +02:00
|
|
|
|
2010-05-20 01:14:09 +02:00
|
|
|
TRACE("Sample data ptr = %p, size = %d\n", pbSrcStream, cbSrcStream);
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2008-03-21 22:55:03 +01:00
|
|
|
ash.pbSrc = pbSrcStream;
|
|
|
|
ash.cbSrcLength = cbSrcStream;
|
|
|
|
|
|
|
|
while(hr == S_OK && ash.cbSrcLength)
|
2005-02-01 15:22:00 +01:00
|
|
|
{
|
2020-03-11 04:03:28 +01:00
|
|
|
hr = BaseOutputPinImpl_GetDeliveryBuffer(&This->source, &pOutSample, NULL, NULL, 0);
|
2008-07-05 01:59:22 +02:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Unable to get delivery buffer (%x)\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
IMediaSample_SetPreroll(pOutSample, preroll);
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
hr = IMediaSample_SetActualDataLength(pOutSample, 0);
|
2005-02-01 15:22:00 +01:00
|
|
|
assert(hr == S_OK);
|
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
hr = IMediaSample_GetPointer(pOutSample, &pbDstStream);
|
2005-02-01 15:22:00 +01:00
|
|
|
if (FAILED(hr)) {
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("Unable to get pointer to buffer (%x)\n", hr);
|
2005-02-01 15:22:00 +01:00
|
|
|
goto error;
|
|
|
|
}
|
2007-04-07 11:32:45 +02:00
|
|
|
cbDstStream = IMediaSample_GetSize(pOutSample);
|
2005-02-01 15:22:00 +01:00
|
|
|
|
|
|
|
ash.cbStruct = sizeof(ash);
|
|
|
|
ash.fdwStatus = 0;
|
|
|
|
ash.dwUser = 0;
|
|
|
|
ash.pbDst = pbDstStream;
|
|
|
|
ash.cbDstLength = cbDstStream;
|
|
|
|
|
|
|
|
if ((res = acmStreamPrepareHeader(This->has, &ash, 0))) {
|
|
|
|
ERR("Cannot prepare header %d\n", res);
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
unprepare_header = TRUE;
|
|
|
|
|
2008-04-01 23:49:54 +02:00
|
|
|
if (IMediaSample_IsDiscontinuity(pSample) == S_OK)
|
2008-04-19 01:13:25 +02:00
|
|
|
{
|
2008-04-01 23:49:54 +02:00
|
|
|
res = acmStreamConvert(This->has, &ash, ACM_STREAMCONVERTF_START);
|
2008-04-22 22:37:34 +02:00
|
|
|
IMediaSample_SetDiscontinuity(pOutSample, TRUE);
|
2008-04-19 01:13:25 +02:00
|
|
|
/* One sample could be converted to multiple packets */
|
|
|
|
IMediaSample_SetDiscontinuity(pSample, FALSE);
|
|
|
|
}
|
2008-04-01 23:49:54 +02:00
|
|
|
else
|
2008-04-22 22:37:34 +02:00
|
|
|
{
|
2008-04-01 23:49:54 +02:00
|
|
|
res = acmStreamConvert(This->has, &ash, 0);
|
2008-04-22 22:37:34 +02:00
|
|
|
IMediaSample_SetDiscontinuity(pOutSample, FALSE);
|
|
|
|
}
|
2008-04-01 23:49:54 +02:00
|
|
|
|
|
|
|
if (res)
|
|
|
|
{
|
2008-04-25 23:15:42 +02:00
|
|
|
if(res != MMSYSERR_MOREDATA)
|
|
|
|
ERR("Cannot convert data header %d\n", res);
|
|
|
|
goto error;
|
|
|
|
}
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2008-04-25 23:15:42 +02:00
|
|
|
TRACE("used in %u/%u, used out %u/%u\n", ash.cbSrcLengthUsed, ash.cbSrcLength, ash.cbDstLengthUsed, ash.cbDstLength);
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2008-04-25 23:15:42 +02:00
|
|
|
hr = IMediaSample_SetActualDataLength(pOutSample, ash.cbDstLengthUsed);
|
|
|
|
assert(hr == S_OK);
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2012-05-15 10:15:32 +02:00
|
|
|
/* Bug in acm codecs? It apparently uses the input, but doesn't necessarily output immediately */
|
2008-04-01 23:49:54 +02:00
|
|
|
if (!ash.cbSrcLengthUsed)
|
|
|
|
{
|
2008-04-25 23:15:42 +02:00
|
|
|
WARN("Sample was skipped? Outputted: %u\n", ash.cbDstLengthUsed);
|
2008-04-01 23:49:54 +02:00
|
|
|
ash.cbSrcLength = 0;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2020-01-31 02:05:17 +01:00
|
|
|
TRACE("Sample start time: %s.\n", debugstr_time(tStart));
|
2008-03-21 22:55:03 +01:00
|
|
|
if (ash.cbSrcLengthUsed == cbSrcStream)
|
|
|
|
{
|
|
|
|
IMediaSample_SetTime(pOutSample, &tStart, &tStop);
|
2008-04-26 00:14:54 +02:00
|
|
|
tStart = tMed = tStop;
|
2008-03-21 22:55:03 +01:00
|
|
|
}
|
|
|
|
else if (tStop != tStart)
|
|
|
|
{
|
|
|
|
tMed = tStop - tStart;
|
|
|
|
tMed = tStart + tMed * ash.cbSrcLengthUsed / cbSrcStream;
|
|
|
|
IMediaSample_SetTime(pOutSample, &tStart, &tMed);
|
|
|
|
tStart = tMed;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ERR("No valid timestamp found\n");
|
|
|
|
IMediaSample_SetTime(pOutSample, NULL, NULL);
|
|
|
|
}
|
2010-11-07 15:02:47 +01:00
|
|
|
|
|
|
|
if (mtStart < 0) {
|
|
|
|
IMediaSample_SetMediaTime(pOutSample, NULL, NULL);
|
|
|
|
} else if (ash.cbSrcLengthUsed == cbSrcStream) {
|
|
|
|
IMediaSample_SetMediaTime(pOutSample, &mtStart, &mtStop);
|
|
|
|
mtStart = mtMed = mtStop;
|
|
|
|
} else if (mtStop >= mtStart) {
|
|
|
|
mtMed = mtStop - mtStart;
|
|
|
|
mtMed = mtStart + mtMed * ash.cbSrcLengthUsed / cbSrcStream;
|
|
|
|
IMediaSample_SetMediaTime(pOutSample, &mtStart, &mtMed);
|
|
|
|
mtStart = mtMed;
|
|
|
|
} else {
|
|
|
|
IMediaSample_SetMediaTime(pOutSample, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2020-01-31 02:05:17 +01:00
|
|
|
TRACE("Sample stop time: %s\n", debugstr_time(tStart));
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
hr = IMemInputPin_Receive(This->source.pMemInputPin, pOutSample);
|
2008-03-10 09:50:57 +01:00
|
|
|
if (hr != S_OK && hr != VFW_E_NOT_CONNECTED) {
|
|
|
|
if (FAILED(hr))
|
|
|
|
ERR("Error sending sample (%x)\n", hr);
|
|
|
|
goto error;
|
2005-02-01 15:22:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
2007-03-13 18:21:17 +01:00
|
|
|
if (unprepare_header && (res = acmStreamUnprepareHeader(This->has, &ash, 0)))
|
|
|
|
ERR("Cannot unprepare header %d\n", res);
|
|
|
|
unprepare_header = FALSE;
|
2008-03-21 22:55:03 +01:00
|
|
|
ash.pbSrc += ash.cbSrcLengthUsed;
|
|
|
|
ash.cbSrcLength -= ash.cbSrcLengthUsed;
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2011-06-26 16:36:03 +02:00
|
|
|
IMediaSample_Release(pOutSample);
|
2007-04-07 11:32:45 +02:00
|
|
|
pOutSample = NULL;
|
2008-04-30 19:33:07 +02:00
|
|
|
|
2005-02-01 15:22:00 +01:00
|
|
|
}
|
|
|
|
|
2008-04-25 23:15:42 +02:00
|
|
|
This->lasttime_real = tStop;
|
|
|
|
This->lasttime_sent = tMed;
|
|
|
|
|
2005-02-01 15:22:00 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-12-10 17:35:11 +01:00
|
|
|
static BOOL is_audio_subtype(const GUID *guid)
|
2005-02-01 15:22:00 +01:00
|
|
|
{
|
2019-12-10 17:35:11 +01:00
|
|
|
return !memcmp(&guid->Data2, &MEDIATYPE_Audio.Data2, sizeof(GUID) - sizeof(int));
|
2005-02-01 15:22:00 +01:00
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
static HRESULT acm_wrapper_sink_connect(struct strmbase_sink *iface, IPin *peer, const AM_MEDIA_TYPE *mt)
|
2005-02-01 15:22:00 +01:00
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_strmbase_filter(iface->pin.filter);
|
2019-12-10 17:35:11 +01:00
|
|
|
const WAVEFORMATEX *wfx = (WAVEFORMATEX *)mt->pbFormat;
|
2010-10-07 21:48:19 +02:00
|
|
|
HACMSTREAM drv;
|
2019-12-10 17:35:11 +01:00
|
|
|
MMRESULT res;
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2019-12-10 17:35:11 +01:00
|
|
|
if (!IsEqualGUID(&mt->majortype, &MEDIATYPE_Audio) || !is_audio_subtype(&mt->subtype)
|
|
|
|
|| !IsEqualGUID(&mt->formattype, &FORMAT_WaveFormatEx) || !wfx
|
|
|
|
|| wfx->wFormatTag == WAVE_FORMAT_PCM || wfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE)
|
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
CopyMediaType(&filter->mt, mt);
|
|
|
|
filter->mt.subtype.Data1 = WAVE_FORMAT_PCM;
|
|
|
|
filter->pWfOut = (WAVEFORMATEX *)filter->mt.pbFormat;
|
2019-12-10 17:35:11 +01:00
|
|
|
filter->pWfOut->wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
filter->pWfOut->wBitsPerSample = 16;
|
|
|
|
filter->pWfOut->nBlockAlign = filter->pWfOut->wBitsPerSample * filter->pWfOut->nChannels / 8;
|
|
|
|
filter->pWfOut->cbSize = 0;
|
|
|
|
filter->pWfOut->nAvgBytesPerSec = filter->pWfOut->nChannels * filter->pWfOut->nSamplesPerSec
|
|
|
|
* (filter->pWfOut->wBitsPerSample / 8);
|
|
|
|
|
|
|
|
if ((res = acmStreamOpen(&drv, NULL, (WAVEFORMATEX *)wfx, filter->pWfOut, NULL, 0, 0, 0)))
|
2010-10-07 21:48:19 +02:00
|
|
|
{
|
2019-12-10 17:35:11 +01:00
|
|
|
ERR("Failed to open stream, error %u.\n", res);
|
2020-03-11 04:03:28 +01:00
|
|
|
FreeMediaType(&filter->mt);
|
2019-12-10 17:35:11 +01:00
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
2010-10-07 21:48:19 +02:00
|
|
|
}
|
|
|
|
|
2019-12-10 17:35:11 +01:00
|
|
|
filter->has = drv;
|
|
|
|
|
|
|
|
return S_OK;
|
2010-10-07 21:48:19 +02:00
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
static void acm_wrapper_sink_disconnect(struct strmbase_sink *iface)
|
2010-10-07 21:48:19 +02:00
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_strmbase_filter(iface->pin.filter);
|
2010-10-07 21:48:19 +02:00
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
if (filter->has)
|
|
|
|
acmStreamClose(filter->has, 0);
|
|
|
|
filter->has = 0;
|
|
|
|
filter->lasttime_real = filter->lasttime_sent = -1;
|
|
|
|
}
|
2010-10-07 21:48:19 +02:00
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
static const struct strmbase_sink_ops sink_ops =
|
|
|
|
{
|
|
|
|
.base.pin_query_interface = acm_wrapper_sink_query_interface,
|
|
|
|
.base.pin_query_accept = acm_wrapper_sink_query_accept,
|
|
|
|
.pfnReceive = acm_wrapper_sink_Receive,
|
|
|
|
.sink_connect = acm_wrapper_sink_connect,
|
|
|
|
.sink_disconnect = acm_wrapper_sink_disconnect,
|
|
|
|
};
|
2010-10-07 21:48:19 +02:00
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
static HRESULT acm_wrapper_source_query_interface(struct strmbase_pin *iface, REFIID iid, void **out)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_strmbase_filter(iface->filter);
|
2008-04-29 01:32:57 +02:00
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
if (IsEqualGUID(iid, &IID_IQualityControl))
|
|
|
|
*out = &filter->source_IQualityControl_iface;
|
|
|
|
else if (IsEqualGUID(iid, &IID_IMediaSeeking))
|
2020-03-28 18:02:04 +01:00
|
|
|
*out = &filter->passthrough.IMediaSeeking_iface;
|
2020-03-11 04:03:28 +01:00
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
2005-02-01 15:22:00 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
static HRESULT acm_wrapper_source_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
2010-10-13 17:46:27 +02:00
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_strmbase_filter(iface->filter);
|
2020-03-11 04:03:28 +01:00
|
|
|
|
|
|
|
if (IsEqualGUID(&mt->majortype, &filter->mt.majortype)
|
|
|
|
&& (IsEqualGUID(&mt->subtype, &filter->mt.subtype)
|
|
|
|
|| IsEqualGUID(&filter->mt.subtype, &GUID_NULL)))
|
|
|
|
return S_OK;
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT acm_wrapper_source_get_media_type(struct strmbase_pin *iface,
|
|
|
|
unsigned int index, AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_strmbase_filter(iface->filter);
|
2020-03-11 04:03:28 +01:00
|
|
|
|
|
|
|
if (index)
|
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
|
|
|
CopyMediaType(mt, &filter->mt);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI acm_wrapper_source_DecideBufferSize(struct strmbase_source *iface,
|
|
|
|
IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_strmbase_filter(iface->pin.filter);
|
2010-10-13 17:46:27 +02:00
|
|
|
ALLOCATOR_PROPERTIES actual;
|
|
|
|
|
|
|
|
if (!ppropInputRequest->cbAlign)
|
|
|
|
ppropInputRequest->cbAlign = 1;
|
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
if (ppropInputRequest->cbBuffer < filter->pWfOut->nAvgBytesPerSec / 2)
|
|
|
|
ppropInputRequest->cbBuffer = filter->pWfOut->nAvgBytesPerSec / 2;
|
2010-10-13 17:46:27 +02:00
|
|
|
|
|
|
|
if (!ppropInputRequest->cBuffers)
|
|
|
|
ppropInputRequest->cBuffers = 1;
|
|
|
|
|
|
|
|
return IMemAllocator_SetProperties(pAlloc, ppropInputRequest, &actual);
|
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
static const struct strmbase_source_ops source_ops =
|
|
|
|
{
|
|
|
|
.base.pin_query_interface = acm_wrapper_source_query_interface,
|
|
|
|
.base.pin_query_accept = acm_wrapper_source_query_accept,
|
|
|
|
.base.pin_get_media_type = acm_wrapper_source_get_media_type,
|
|
|
|
.pfnAttemptConnection = BaseOutputPinImpl_AttemptConnection,
|
|
|
|
.pfnDecideAllocator = BaseOutputPinImpl_DecideAllocator,
|
|
|
|
.pfnDecideBufferSize = acm_wrapper_source_DecideBufferSize,
|
|
|
|
};
|
|
|
|
|
2020-04-01 06:48:15 +02:00
|
|
|
static struct acm_wrapper *impl_from_source_IQualityControl(IQualityControl *iface)
|
2020-03-11 04:03:28 +01:00
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct acm_wrapper, source_IQualityControl_iface);
|
2020-03-11 04:03:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI acm_wrapper_source_qc_QueryInterface(IQualityControl *iface,
|
|
|
|
REFIID iid, void **out)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_source_IQualityControl(iface);
|
2020-03-11 04:03:28 +01:00
|
|
|
return IPin_QueryInterface(&filter->source.pin.IPin_iface, iid, out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI acm_wrapper_source_qc_AddRef(IQualityControl *iface)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_source_IQualityControl(iface);
|
2020-03-11 04:03:28 +01:00
|
|
|
return IPin_AddRef(&filter->source.pin.IPin_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI acm_wrapper_source_qc_Release(IQualityControl *iface)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_source_IQualityControl(iface);
|
2020-03-11 04:03:28 +01:00
|
|
|
return IPin_Release(&filter->source.pin.IPin_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI acm_wrapper_source_qc_Notify(IQualityControl *iface,
|
|
|
|
IBaseFilter *sender, Quality q)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_source_IQualityControl(iface);
|
2020-03-11 04:03:28 +01:00
|
|
|
IQualityControl *peer;
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TRACE("filter %p, sender %p, type %#x, proportion %u, late %s, timestamp %s.\n",
|
|
|
|
filter, sender, q.Type, q.Proportion, debugstr_time(q.Late), debugstr_time(q.TimeStamp));
|
|
|
|
|
|
|
|
if (filter->source_qc_sink)
|
|
|
|
return IQualityControl_Notify(filter->source_qc_sink, &filter->filter.IBaseFilter_iface, q);
|
|
|
|
|
|
|
|
if (filter->sink.pin.peer
|
|
|
|
&& SUCCEEDED(IPin_QueryInterface(filter->sink.pin.peer, &IID_IQualityControl, (void **)&peer)))
|
|
|
|
{
|
|
|
|
hr = IQualityControl_Notify(peer, &filter->filter.IBaseFilter_iface, q);
|
|
|
|
IQualityControl_Release(peer);
|
|
|
|
}
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI acm_wrapper_source_qc_SetSink(IQualityControl *iface, IQualityControl *sink)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_source_IQualityControl(iface);
|
2020-03-11 04:03:28 +01:00
|
|
|
|
|
|
|
TRACE("filter %p, sink %p.\n", filter, sink);
|
|
|
|
|
|
|
|
filter->source_qc_sink = sink;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IQualityControlVtbl source_qc_vtbl =
|
|
|
|
{
|
|
|
|
acm_wrapper_source_qc_QueryInterface,
|
|
|
|
acm_wrapper_source_qc_AddRef,
|
|
|
|
acm_wrapper_source_qc_Release,
|
|
|
|
acm_wrapper_source_qc_Notify,
|
|
|
|
acm_wrapper_source_qc_SetSink,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct strmbase_pin *acm_wrapper_get_pin(struct strmbase_filter *iface, unsigned int index)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_strmbase_filter(iface);
|
2020-03-11 04:03:28 +01:00
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
return &filter->sink.pin;
|
|
|
|
else if (index == 1)
|
|
|
|
return &filter->source.pin;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void acm_wrapper_destroy(struct strmbase_filter *iface)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_strmbase_filter(iface);
|
2020-03-11 04:03:28 +01:00
|
|
|
|
|
|
|
if (filter->sink.pin.peer)
|
|
|
|
IPin_Disconnect(filter->sink.pin.peer);
|
|
|
|
IPin_Disconnect(&filter->sink.pin.IPin_iface);
|
|
|
|
|
|
|
|
if (filter->source.pin.peer)
|
|
|
|
IPin_Disconnect(filter->source.pin.peer);
|
|
|
|
IPin_Disconnect(&filter->source.pin.IPin_iface);
|
|
|
|
|
|
|
|
strmbase_sink_cleanup(&filter->sink);
|
|
|
|
strmbase_source_cleanup(&filter->source);
|
2020-03-28 18:02:04 +01:00
|
|
|
strmbase_passthrough_cleanup(&filter->passthrough);
|
2020-03-11 04:03:28 +01:00
|
|
|
|
|
|
|
FreeMediaType(&filter->mt);
|
|
|
|
strmbase_filter_cleanup(&filter->filter);
|
|
|
|
free(filter);
|
2020-03-13 03:34:12 +01:00
|
|
|
|
|
|
|
InterlockedDecrement(&object_locks);
|
2020-03-11 04:03:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT acm_wrapper_init_stream(struct strmbase_filter *iface)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_strmbase_filter(iface);
|
2020-11-17 23:30:54 +01:00
|
|
|
HRESULT hr;
|
2020-03-11 04:03:28 +01:00
|
|
|
|
2020-11-17 23:30:54 +01:00
|
|
|
if (filter->source.pin.peer && FAILED(hr = IMemAllocator_Commit(filter->source.pAllocator)))
|
|
|
|
ERR("Failed to commit allocator, hr %#x.\n", hr);
|
2020-03-11 04:03:28 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT acm_wrapper_cleanup_stream(struct strmbase_filter *iface)
|
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *filter = impl_from_strmbase_filter(iface);
|
2020-03-11 04:03:28 +01:00
|
|
|
|
2020-11-17 23:30:54 +01:00
|
|
|
if (filter->source.pin.peer)
|
|
|
|
IMemAllocator_Decommit(filter->source.pAllocator);
|
2020-03-11 04:03:28 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct strmbase_filter_ops filter_ops =
|
|
|
|
{
|
|
|
|
.filter_get_pin = acm_wrapper_get_pin,
|
|
|
|
.filter_destroy = acm_wrapper_destroy,
|
|
|
|
.filter_init_stream = acm_wrapper_init_stream,
|
|
|
|
.filter_cleanup_stream = acm_wrapper_cleanup_stream,
|
2005-02-21 21:37:45 +01:00
|
|
|
};
|
|
|
|
|
2020-03-12 03:10:10 +01:00
|
|
|
HRESULT acm_wrapper_create(IUnknown *outer, IUnknown **out)
|
2005-02-01 15:22:00 +01:00
|
|
|
{
|
2020-04-01 06:48:15 +02:00
|
|
|
struct acm_wrapper *object;
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
if (!(object = calloc(1, sizeof(*object))))
|
|
|
|
return E_OUTOFMEMORY;
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
strmbase_filter_init(&object->filter, outer, &CLSID_ACMWrapper, &filter_ops);
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
strmbase_sink_init(&object->sink, &object->filter, L"In", &sink_ops, NULL);
|
|
|
|
|
|
|
|
strmbase_source_init(&object->source, &object->filter, L"Out", &source_ops);
|
|
|
|
object->source_IQualityControl_iface.lpVtbl = &source_qc_vtbl;
|
2020-03-28 18:02:04 +01:00
|
|
|
strmbase_passthrough_init(&object->passthrough, (IUnknown *)&object->source.pin.IPin_iface);
|
|
|
|
ISeekingPassThru_Init(&object->passthrough.ISeekingPassThru_iface, FALSE,
|
|
|
|
&object->sink.pin.IPin_iface);
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2020-03-11 04:03:28 +01:00
|
|
|
object->lasttime_real = object->lasttime_sent = -1;
|
|
|
|
|
|
|
|
TRACE("Created ACM wrapper %p.\n", object);
|
|
|
|
*out = &object->filter.IUnknown_inner;
|
|
|
|
|
|
|
|
return S_OK;
|
2005-02-01 15:22:00 +01:00
|
|
|
}
|