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 "config.h"
|
|
|
|
|
|
|
|
#include "quartz_private.h"
|
|
|
|
#include "pin.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/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "transform.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
|
|
|
|
|
|
|
/* FIXME: Improve buffers management */
|
|
|
|
#define OUTPUT_BUFFER_SIZE 15000
|
|
|
|
#define INPUT_BUFFER_SIZE 4096
|
|
|
|
|
|
|
|
typedef struct ACMWrapperImpl
|
|
|
|
{
|
|
|
|
TransformFilterImpl tf;
|
|
|
|
HACMSTREAM has;
|
|
|
|
LPWAVEFORMATEX pWfIn;
|
|
|
|
LPWAVEFORMATEX pWfOut;
|
|
|
|
BYTE buffer[INPUT_BUFFER_SIZE];
|
|
|
|
DWORD max_size;
|
|
|
|
DWORD current_size;
|
|
|
|
BOOL reinit_codec; /* FIXME: Should use sync points instead */
|
|
|
|
} ACMWrapperImpl;
|
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
static HRESULT ACMWrapper_ProcessSampleData(TransformFilterImpl* pTransformFilter, IMediaSample *pSample)
|
2005-02-01 15:22:00 +01:00
|
|
|
{
|
|
|
|
ACMWrapperImpl* This = (ACMWrapperImpl*)pTransformFilter;
|
|
|
|
AM_MEDIA_TYPE amt;
|
2007-04-07 11:32:45 +02:00
|
|
|
IMediaSample* pOutSample = NULL;
|
2005-02-01 15:22:00 +01:00
|
|
|
DWORD cbDstStream;
|
|
|
|
LPBYTE pbDstStream;
|
2007-04-07 11:32:45 +02:00
|
|
|
DWORD cbSrcStream = 0;
|
|
|
|
LPBYTE pbSrcStream = NULL;
|
2005-02-01 15:22:00 +01:00
|
|
|
ACMSTREAMHEADER ash;
|
|
|
|
DWORD offset = 0;
|
|
|
|
BOOL stop = FALSE;
|
|
|
|
BOOL unprepare_header = FALSE;
|
|
|
|
MMRESULT res;
|
2007-04-07 11:32:45 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Cannot get pointer to sample data (%x)\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
cbSrcStream = IMediaSample_GetActualDataLength(pSample);
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
TRACE("Sample data ptr = %p, size = %ld\n", pbSrcStream, (long)cbSrcStream);
|
2005-02-01 15:22:00 +01:00
|
|
|
|
|
|
|
hr = IPin_ConnectionMediaType(This->tf.ppPins[0], &amt);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
ERR("Unable to retrieve media type\n");
|
2007-03-13 18:21:17 +01:00
|
|
|
return hr;
|
2005-02-01 15:22:00 +01:00
|
|
|
}
|
|
|
|
|
2007-04-03 15:53:22 +02:00
|
|
|
while(hr == S_OK && !stop)
|
2005-02-01 15:22:00 +01:00
|
|
|
{
|
|
|
|
DWORD rem_buf = This->max_size - This->current_size;
|
2007-04-07 11:32:45 +02:00
|
|
|
DWORD rem_smp = cbSrcStream - offset;
|
2005-02-01 15:22:00 +01:00
|
|
|
DWORD copy_size = min(rem_buf, rem_smp);
|
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
memcpy(This->buffer + This->current_size, pbSrcStream + offset, copy_size);
|
2005-02-01 15:22:00 +01:00
|
|
|
This->current_size += copy_size;
|
|
|
|
offset += copy_size;
|
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
if (offset >= cbSrcStream)
|
2005-02-01 15:22:00 +01:00
|
|
|
stop = TRUE;
|
|
|
|
if (This->current_size < This->max_size)
|
|
|
|
break;
|
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
hr = OutputPin_GetDeliveryBuffer((OutputPin*)This->tf.ppPins[1], &pOutSample, NULL, NULL, 0);
|
2005-02-01 15:22:00 +01:00
|
|
|
if (FAILED(hr)) {
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("Unable to get delivery buffer (%x)\n", hr);
|
2007-03-13 18:21:17 +01:00
|
|
|
return hr;
|
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.pbSrc = This->buffer;
|
|
|
|
ash.cbSrcLength = This->current_size;
|
|
|
|
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;
|
|
|
|
|
|
|
|
if ((res = acmStreamConvert(This->has, &ash, This->reinit_codec ? ACM_STREAMCONVERTF_START : 0))) {
|
2008-03-10 09:50:57 +01:00
|
|
|
if(res != MMSYSERR_MOREDATA)
|
|
|
|
ERR("Cannot convert data header %d\n", res);
|
2005-02-01 15:22:00 +01:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
This->reinit_codec = FALSE;
|
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("used in %u, used out %u\n", ash.cbSrcLengthUsed, ash.cbDstLengthUsed);
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
hr = IMediaSample_SetActualDataLength(pOutSample, ash.cbDstLengthUsed);
|
2005-02-01 15:22:00 +01:00
|
|
|
assert(hr == S_OK);
|
|
|
|
|
|
|
|
if (ash.cbSrcLengthUsed < ash.cbSrcLength) {
|
|
|
|
This->current_size = ash.cbSrcLength - ash.cbSrcLengthUsed;
|
|
|
|
memmove(This->buffer, This->buffer + ash.cbSrcLengthUsed, This->current_size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
This->current_size = 0;
|
|
|
|
|
2008-03-10 09:50:57 +01:00
|
|
|
hr = OutputPin_SendSample((OutputPin*)This->tf.ppPins[1], pOutSample);
|
|
|
|
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;
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
if (pOutSample)
|
|
|
|
IMediaSample_Release(pOutSample);
|
|
|
|
pOutSample = NULL;
|
2005-02-01 15:22:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT ACMWrapper_ConnectInput(TransformFilterImpl* pTransformFilter, const AM_MEDIA_TYPE * pmt)
|
|
|
|
{
|
|
|
|
ACMWrapperImpl* This = (ACMWrapperImpl*)pTransformFilter;
|
|
|
|
MMRESULT res;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pmt);
|
|
|
|
|
2006-09-22 19:50:12 +02:00
|
|
|
/* Check root (GUID w/o FOURCC) */
|
2005-02-01 15:22:00 +01:00
|
|
|
if ((IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio)) &&
|
2006-09-22 19:50:12 +02:00
|
|
|
(!memcmp(((const char *)&pmt->subtype)+4, ((const char *)&MEDIATYPE_Audio)+4, sizeof(GUID)-4)) &&
|
2005-02-01 15:22:00 +01:00
|
|
|
(IsEqualIID(&pmt->formattype, &FORMAT_WaveFormatEx)))
|
|
|
|
{
|
|
|
|
HACMSTREAM drv;
|
|
|
|
AM_MEDIA_TYPE* outpmt = &((OutputPin*)This->tf.ppPins[1])->pin.mtCurrent;
|
|
|
|
This->pWfIn = (LPWAVEFORMATEX)pmt->pbFormat;
|
|
|
|
|
|
|
|
/* HACK */
|
|
|
|
/* TRACE("ALIGN = %d\n", pACMWrapper->pWfIn->nBlockAlign); */
|
|
|
|
/* pACMWrapper->pWfIn->nBlockAlign = 1; */
|
|
|
|
|
|
|
|
/* Set output audio data to PCM */
|
|
|
|
CopyMediaType(outpmt, pmt);
|
|
|
|
outpmt->subtype.Data1 = WAVE_FORMAT_PCM;
|
|
|
|
This->pWfOut = (WAVEFORMATEX*)outpmt->pbFormat;
|
|
|
|
This->pWfOut->wFormatTag = WAVE_FORMAT_PCM;
|
|
|
|
This->pWfOut->wBitsPerSample = 16;
|
2005-02-22 15:50:16 +01:00
|
|
|
This->pWfOut->nBlockAlign = 4;
|
2005-02-01 15:22:00 +01:00
|
|
|
This->pWfOut->cbSize = 0;
|
|
|
|
This->pWfOut->nAvgBytesPerSec = This->pWfOut->nChannels * This->pWfOut->nSamplesPerSec
|
|
|
|
* (This->pWfOut->wBitsPerSample/8);
|
|
|
|
|
|
|
|
if (!(res = acmStreamOpen(&drv, NULL, This->pWfIn, This->pWfOut, NULL, 0, 0, 0)))
|
|
|
|
{
|
|
|
|
This->has = drv;
|
|
|
|
|
|
|
|
if ((res = acmStreamSize(drv, OUTPUT_BUFFER_SIZE, &This->max_size, ACM_STREAMSIZEF_DESTINATION))) {
|
2005-02-10 20:19:35 +01:00
|
|
|
ERR("Cannot retrieve input buffer size error %d!\n", res);
|
2005-02-01 15:22:00 +01:00
|
|
|
This->max_size = INPUT_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("input buffer size %d\n", This->max_size);
|
2005-02-22 15:50:16 +01:00
|
|
|
|
|
|
|
/* Update buffer size of media samples in output */
|
|
|
|
((OutputPin*)This->tf.ppPins[1])->allocProps.cbBuffer = OUTPUT_BUFFER_SIZE;
|
2005-02-01 15:22:00 +01:00
|
|
|
|
|
|
|
TRACE("Connection accepted\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FIXME("acmStreamOpen returned %d\n", res);
|
2005-06-05 21:18:34 +02:00
|
|
|
FreeMediaType(outpmt);
|
2005-02-01 15:22:00 +01:00
|
|
|
TRACE("Unable to find a suitable ACM decompressor\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Connection refused\n");
|
2007-06-05 05:11:25 +02:00
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
2005-02-01 15:22:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT ACMWrapper_Cleanup(TransformFilterImpl* pTransformFilter)
|
|
|
|
{
|
|
|
|
ACMWrapperImpl* This = (ACMWrapperImpl*)pTransformFilter;
|
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
|
|
|
if (This->has)
|
|
|
|
acmStreamClose(This->has, 0);
|
|
|
|
|
|
|
|
This->has = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2006-11-29 11:05:43 +01:00
|
|
|
static const TransformFuncsTable ACMWrapper_FuncsTable = {
|
2005-02-21 21:37:45 +01:00
|
|
|
NULL,
|
|
|
|
ACMWrapper_ProcessSampleData,
|
|
|
|
NULL,
|
2007-04-03 09:06:16 +02:00
|
|
|
NULL,
|
2005-02-21 21:37:45 +01:00
|
|
|
ACMWrapper_ConnectInput,
|
|
|
|
ACMWrapper_Cleanup
|
|
|
|
};
|
|
|
|
|
2005-02-01 15:22:00 +01:00
|
|
|
HRESULT ACMWrapper_create(IUnknown * pUnkOuter, LPVOID * ppv)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
ACMWrapperImpl* This;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", pUnkOuter, ppv);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (pUnkOuter)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
|
|
|
|
/* Note: This memory is managed by the transform filter once created */
|
|
|
|
This = CoTaskMemAlloc(sizeof(ACMWrapperImpl));
|
2007-02-18 07:17:32 +01:00
|
|
|
ZeroMemory(This, sizeof(ACMWrapperImpl));
|
2005-02-01 15:22:00 +01:00
|
|
|
|
|
|
|
This->reinit_codec = TRUE;
|
|
|
|
|
2005-02-21 21:37:45 +01:00
|
|
|
hr = TransformFilter_Create(&(This->tf), &CLSID_ACMWrapper, &ACMWrapper_FuncsTable);
|
2005-02-01 15:22:00 +01:00
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
*ppv = (LPVOID)This;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|