ReactOS 0.4.15-dev-7788-g1ad9096
acmwrapper.c File Reference
#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 dependency graph for acmwrapper.c:

Go to the source code of this file.

Classes

struct  ACMWrapperImpl
 

Typedefs

typedef struct ACMWrapperImpl ACMWrapperImpl
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (quartz)
 
static ACMWrapperImplimpl_from_TransformFilter (TransformFilter *iface)
 
static HRESULT WINAPI ACMWrapper_Receive (TransformFilter *tf, IMediaSample *pSample)
 
static HRESULT WINAPI ACMWrapper_SetMediaType (TransformFilter *tf, PIN_DIRECTION dir, const AM_MEDIA_TYPE *pmt)
 
static HRESULT WINAPI ACMWrapper_CompleteConnect (TransformFilter *tf, PIN_DIRECTION dir, IPin *pin)
 
static HRESULT WINAPI ACMWrapper_BreakConnect (TransformFilter *tf, PIN_DIRECTION dir)
 
static HRESULT WINAPI ACMWrapper_DecideBufferSize (TransformFilter *tf, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
 
HRESULT ACMWrapper_create (IUnknown *pUnkOuter, LPVOID *ppv)
 

Variables

static const IBaseFilterVtbl ACMWrapper_Vtbl
 
static const TransformFilterFuncTable ACMWrapper_FuncsTable
 

Typedef Documentation

◆ ACMWrapperImpl

Function Documentation

◆ ACMWrapper_BreakConnect()

static HRESULT WINAPI ACMWrapper_BreakConnect ( TransformFilter tf,
PIN_DIRECTION  dir 
)
static

Definition at line 330 of file acmwrapper.c.

331{
333
334 TRACE("(%p)->(%i)\n", This,dir);
335
336 if (dir == PINDIR_INPUT)
337 {
338 if (This->has)
339 acmStreamClose(This->has, 0);
340
341 This->has = 0;
342 This->lasttime_real = This->lasttime_sent = -1;
343 }
344
345 return S_OK;
346}
static ACMWrapperImpl * impl_from_TransformFilter(TransformFilter *iface)
Definition: acmwrapper.c:56
unsigned int dir
Definition: maze.c:112
@ PINDIR_INPUT
Definition: axcore.idl:41
MMRESULT WINAPI acmStreamClose(HACMSTREAM has, DWORD fdwClose)
Definition: stream.c:65
HFONT tf
Definition: icontest.c:17
#define S_OK
Definition: intsafe.h:52
#define TRACE(s)
Definition: solgame.cpp:4

◆ ACMWrapper_CompleteConnect()

static HRESULT WINAPI ACMWrapper_CompleteConnect ( TransformFilter tf,
PIN_DIRECTION  dir,
IPin pin 
)
static

Definition at line 306 of file acmwrapper.c.

307{
310 HACMSTREAM drv;
311
312 TRACE("(%p)\n", This);
313
314 if (dir != PINDIR_INPUT)
315 return S_OK;
316
317 if (!(res = acmStreamOpen(&drv, NULL, This->pWfIn, This->pWfOut, NULL, 0, 0, 0)))
318 {
319 This->has = drv;
320
321 TRACE("Connection accepted\n");
322 return S_OK;
323 }
324
325 FIXME("acmStreamOpen returned %d\n", res);
326 TRACE("Unable to find a suitable ACM decompressor\n");
328}
#define FIXME(fmt,...)
Definition: debug.h:111
#define NULL
Definition: types.h:112
MMRESULT WINAPI acmStreamOpen(PHACMSTREAM phas, HACMDRIVER had, PWAVEFORMATEX pwfxSrc, PWAVEFORMATEX pwfxDst, PWAVEFILTER pwfltr, DWORD_PTR dwCallback, DWORD_PTR dwInstance, DWORD fdwOpen)
Definition: stream.c:149
GLuint res
Definition: glext.h:9613
UINT MMRESULT
Definition: mmsystem.h:962
#define VFW_E_TYPE_NOT_ACCEPTED
Definition: vfwmsgs.h:81

◆ ACMWrapper_create()

HRESULT ACMWrapper_create ( IUnknown pUnkOuter,
LPVOID ppv 
)

Definition at line 380 of file acmwrapper.c.

381{
382 HRESULT hr;
384
385 TRACE("(%p, %p)\n", pUnkOuter, ppv);
386
387 *ppv = NULL;
388
389 if (pUnkOuter)
391
393
394 if (FAILED(hr))
395 return hr;
396
397 *ppv = &This->tf.filter.IBaseFilter_iface;
398 This->lasttime_real = This->lasttime_sent = -1;
399
400 return hr;
401}
static const TransformFilterFuncTable ACMWrapper_FuncsTable
Definition: acmwrapper.c:365
static const IBaseFilterVtbl ACMWrapper_Vtbl
Definition: acmwrapper.c:54
REFIID LPVOID * ppv
Definition: atlbase.h:39
#define FAILED(hr)
Definition: intsafe.h:51
HRESULT hr
Definition: shlfolder.c:183
HRESULT TransformFilter_Construct(const IBaseFilterVtbl *filterVtbl, LONG filter_size, const CLSID *pClsid, const TransformFilterFuncTable *pFuncsTable, IBaseFilter **ppTransformFilter)
Definition: transform.c:263
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662

◆ ACMWrapper_DecideBufferSize()

static HRESULT WINAPI ACMWrapper_DecideBufferSize ( TransformFilter tf,
IMemAllocator pAlloc,
ALLOCATOR_PROPERTIES ppropInputRequest 
)
static

Definition at line 348 of file acmwrapper.c.

349{
352
353 if (!ppropInputRequest->cbAlign)
354 ppropInputRequest->cbAlign = 1;
355
356 if (ppropInputRequest->cbBuffer < pACM->pWfOut->nAvgBytesPerSec / 2)
357 ppropInputRequest->cbBuffer = pACM->pWfOut->nAvgBytesPerSec / 2;
358
359 if (!ppropInputRequest->cBuffers)
360 ppropInputRequest->cBuffers = 1;
361
362 return IMemAllocator_SetProperties(pAlloc, ppropInputRequest, &actual);
363}
LPWAVEFORMATEX pWfOut
Definition: acmwrapper.c:48
DWORD nAvgBytesPerSec
Definition: mmreg.h:81

◆ ACMWrapper_Receive()

static HRESULT WINAPI ACMWrapper_Receive ( TransformFilter tf,
IMediaSample pSample 
)
static

Definition at line 61 of file acmwrapper.c.

62{
64 AM_MEDIA_TYPE amt;
65 IMediaSample* pOutSample = NULL;
66 DWORD cbDstStream, cbSrcStream;
67 LPBYTE pbDstStream;
68 LPBYTE pbSrcStream = NULL;
70 BOOL unprepare_header = FALSE, preroll;
72 HRESULT hr;
73 LONGLONG tStart = -1, tStop = -1, tMed;
74 LONGLONG mtStart = -1, mtStop = -1, mtMed;
75
76 EnterCriticalSection(&This->tf.csReceive);
77 hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
78 if (FAILED(hr))
79 {
80 ERR("Cannot get pointer to sample data (%x)\n", hr);
81 LeaveCriticalSection(&This->tf.csReceive);
82 return hr;
83 }
84
85 preroll = (IMediaSample_IsPreroll(pSample) == S_OK);
86
87 IMediaSample_GetTime(pSample, &tStart, &tStop);
88 if (IMediaSample_GetMediaTime(pSample, &mtStart, &mtStop) != S_OK)
89 mtStart = mtStop = -1;
90 cbSrcStream = IMediaSample_GetActualDataLength(pSample);
91
92 /* Prevent discontinuities when codecs 'absorb' data but not give anything back in return */
93 if (IMediaSample_IsDiscontinuity(pSample) == S_OK)
94 {
95 This->lasttime_real = tStart;
96 This->lasttime_sent = tStart;
97 }
98 else if (This->lasttime_real == tStart)
99 tStart = This->lasttime_sent;
100 else
101 WARN("Discontinuity\n");
102
103 tMed = tStart;
104 mtMed = mtStart;
105
106 TRACE("Sample data ptr = %p, size = %d\n", pbSrcStream, cbSrcStream);
107
108 hr = IPin_ConnectionMediaType(This->tf.ppPins[0], &amt);
109 if (FAILED(hr))
110 {
111 ERR("Unable to retrieve media type\n");
112 LeaveCriticalSection(&This->tf.csReceive);
113 return hr;
114 }
115
116 ash.pbSrc = pbSrcStream;
117 ash.cbSrcLength = cbSrcStream;
118
119 while(hr == S_OK && ash.cbSrcLength)
120 {
121 hr = BaseOutputPinImpl_GetDeliveryBuffer((BaseOutputPin*)This->tf.ppPins[1], &pOutSample, NULL, NULL, 0);
122 if (FAILED(hr))
123 {
124 ERR("Unable to get delivery buffer (%x)\n", hr);
125 LeaveCriticalSection(&This->tf.csReceive);
126 return hr;
127 }
128 IMediaSample_SetPreroll(pOutSample, preroll);
129
130 hr = IMediaSample_SetActualDataLength(pOutSample, 0);
131 assert(hr == S_OK);
132
133 hr = IMediaSample_GetPointer(pOutSample, &pbDstStream);
134 if (FAILED(hr)) {
135 ERR("Unable to get pointer to buffer (%x)\n", hr);
136 goto error;
137 }
138 cbDstStream = IMediaSample_GetSize(pOutSample);
139
140 ash.cbStruct = sizeof(ash);
141 ash.fdwStatus = 0;
142 ash.dwUser = 0;
143 ash.pbDst = pbDstStream;
144 ash.cbDstLength = cbDstStream;
145
146 if ((res = acmStreamPrepareHeader(This->has, &ash, 0))) {
147 ERR("Cannot prepare header %d\n", res);
148 goto error;
149 }
150 unprepare_header = TRUE;
151
152 if (IMediaSample_IsDiscontinuity(pSample) == S_OK)
153 {
155 IMediaSample_SetDiscontinuity(pOutSample, TRUE);
156 /* One sample could be converted to multiple packets */
157 IMediaSample_SetDiscontinuity(pSample, FALSE);
158 }
159 else
160 {
161 res = acmStreamConvert(This->has, &ash, 0);
162 IMediaSample_SetDiscontinuity(pOutSample, FALSE);
163 }
164
165 if (res)
166 {
168 ERR("Cannot convert data header %d\n", res);
169 goto error;
170 }
171
172 TRACE("used in %u/%u, used out %u/%u\n", ash.cbSrcLengthUsed, ash.cbSrcLength, ash.cbDstLengthUsed, ash.cbDstLength);
173
174 hr = IMediaSample_SetActualDataLength(pOutSample, ash.cbDstLengthUsed);
175 assert(hr == S_OK);
176
177 /* Bug in acm codecs? It apparently uses the input, but doesn't necessarily output immediately */
178 if (!ash.cbSrcLengthUsed)
179 {
180 WARN("Sample was skipped? Outputted: %u\n", ash.cbDstLengthUsed);
181 ash.cbSrcLength = 0;
182 goto error;
183 }
184
185 TRACE("Sample start time: %u.%03u\n", (DWORD)(tStart/10000000), (DWORD)((tStart/10000)%1000));
186 if (ash.cbSrcLengthUsed == cbSrcStream)
187 {
188 IMediaSample_SetTime(pOutSample, &tStart, &tStop);
189 tStart = tMed = tStop;
190 }
191 else if (tStop != tStart)
192 {
193 tMed = tStop - tStart;
194 tMed = tStart + tMed * ash.cbSrcLengthUsed / cbSrcStream;
195 IMediaSample_SetTime(pOutSample, &tStart, &tMed);
196 tStart = tMed;
197 }
198 else
199 {
200 ERR("No valid timestamp found\n");
201 IMediaSample_SetTime(pOutSample, NULL, NULL);
202 }
203
204 if (mtStart < 0) {
205 IMediaSample_SetMediaTime(pOutSample, NULL, NULL);
206 } else if (ash.cbSrcLengthUsed == cbSrcStream) {
207 IMediaSample_SetMediaTime(pOutSample, &mtStart, &mtStop);
208 mtStart = mtMed = mtStop;
209 } else if (mtStop >= mtStart) {
210 mtMed = mtStop - mtStart;
211 mtMed = mtStart + mtMed * ash.cbSrcLengthUsed / cbSrcStream;
212 IMediaSample_SetMediaTime(pOutSample, &mtStart, &mtMed);
213 mtStart = mtMed;
214 } else {
215 IMediaSample_SetMediaTime(pOutSample, NULL, NULL);
216 }
217
218 TRACE("Sample stop time: %u.%03u\n", (DWORD)(tStart/10000000), (DWORD)((tStart/10000)%1000));
219
220 LeaveCriticalSection(&This->tf.csReceive);
221 hr = BaseOutputPinImpl_Deliver((BaseOutputPin*)This->tf.ppPins[1], pOutSample);
222 EnterCriticalSection(&This->tf.csReceive);
223
224 if (hr != S_OK && hr != VFW_E_NOT_CONNECTED) {
225 if (FAILED(hr))
226 ERR("Error sending sample (%x)\n", hr);
227 goto error;
228 }
229
230error:
231 if (unprepare_header && (res = acmStreamUnprepareHeader(This->has, &ash, 0)))
232 ERR("Cannot unprepare header %d\n", res);
233 unprepare_header = FALSE;
234 ash.pbSrc += ash.cbSrcLengthUsed;
235 ash.cbSrcLength -= ash.cbSrcLengthUsed;
236
237 IMediaSample_Release(pOutSample);
238 pOutSample = NULL;
239
240 }
241
242 This->lasttime_real = tStop;
243 This->lasttime_sent = tMed;
244
245 LeaveCriticalSection(&This->tf.csReceive);
246 return hr;
247}
#define WARN(fmt,...)
Definition: debug.h:112
#define ERR(fmt,...)
Definition: debug.h:110
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
MMRESULT WINAPI acmStreamPrepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwPrepare)
Definition: stream.c:299
MMRESULT WINAPI acmStreamConvert(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwConvert)
Definition: stream.c:89
MMRESULT WINAPI acmStreamUnprepareHeader(HACMSTREAM has, PACMSTREAMHEADER pash, DWORD fdwUnprepare)
Definition: stream.c:449
#define assert(x)
Definition: debug.h:53
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define error(str)
Definition: mkdosfs.c:1605
#define MMSYSERR_MOREDATA
Definition: mmsystem.h:117
#define ACM_STREAMCONVERTF_START
Definition: msacm.h:206
HRESULT WINAPI BaseOutputPinImpl_Deliver(BaseOutputPin *This, IMediaSample *pSample)
Definition: pin.c:574
HRESULT WINAPI BaseOutputPinImpl_GetDeliveryBuffer(BaseOutputPin *This, IMediaSample **ppSample, REFERENCE_TIME *tStart, REFERENCE_TIME *tStop, DWORD dwFlags)
Definition: pin.c:554
DWORD fdwStatus
Definition: msacm.h:551
DWORD cbSrcLengthUsed
Definition: msacm.h:555
DWORD cbStruct
Definition: msacm.h:550
LPBYTE pbDst
Definition: msacm.h:557
DWORD_PTR dwUser
Definition: msacm.h:552
DWORD cbDstLength
Definition: msacm.h:558
DWORD cbSrcLength
Definition: msacm.h:554
DWORD cbDstLengthUsed
Definition: msacm.h:559
LPBYTE pbSrc
Definition: msacm.h:553
unsigned char * LPBYTE
Definition: typedefs.h:53
int64_t LONGLONG
Definition: typedefs.h:68
#define VFW_E_NOT_CONNECTED
Definition: vfwmsgs.h:48
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)

◆ ACMWrapper_SetMediaType()

static HRESULT WINAPI ACMWrapper_SetMediaType ( TransformFilter tf,
PIN_DIRECTION  dir,
const AM_MEDIA_TYPE pmt 
)
static

Definition at line 249 of file acmwrapper.c.

250{
253
254 TRACE("(%p)->(%i %p)\n", This, dir, pmt);
255
256 if (dir != PINDIR_INPUT)
257 return S_OK;
258
259 /* Check root (GUID w/o FOURCC) */
260 if ((IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio)) &&
261 (!memcmp(((const char *)&pmt->subtype)+4, ((const char *)&MEDIATYPE_Audio)+4, sizeof(GUID)-4)) &&
262 (IsEqualIID(&pmt->formattype, &FORMAT_WaveFormatEx)))
263 {
264 HACMSTREAM drv;
265 WAVEFORMATEX *wfx = (WAVEFORMATEX*)pmt->pbFormat;
266 AM_MEDIA_TYPE* outpmt = &This->tf.pmt;
267
270 FreeMediaType(outpmt);
271
272 This->pWfIn = (LPWAVEFORMATEX)pmt->pbFormat;
273
274 /* HACK */
275 /* TRACE("ALIGN = %d\n", pACMWrapper->pWfIn->nBlockAlign); */
276 /* pACMWrapper->pWfIn->nBlockAlign = 1; */
277
278 /* Set output audio data to PCM */
279 CopyMediaType(outpmt, pmt);
280 outpmt->subtype.Data1 = WAVE_FORMAT_PCM;
281 This->pWfOut = (WAVEFORMATEX*)outpmt->pbFormat;
282 This->pWfOut->wFormatTag = WAVE_FORMAT_PCM;
283 This->pWfOut->wBitsPerSample = 16;
284 This->pWfOut->nBlockAlign = This->pWfOut->wBitsPerSample * This->pWfOut->nChannels / 8;
285 This->pWfOut->cbSize = 0;
286 This->pWfOut->nAvgBytesPerSec = This->pWfOut->nChannels * This->pWfOut->nSamplesPerSec
287 * (This->pWfOut->wBitsPerSample/8);
288
289 if (!(res = acmStreamOpen(&drv, NULL, This->pWfIn, This->pWfOut, NULL, 0, 0, 0)))
290 {
291 This->has = drv;
292
293 TRACE("Connection accepted\n");
294 return S_OK;
295 }
296 else
297 FIXME("acmStreamOpen returned %d\n", res);
298 FreeMediaType(outpmt);
299 TRACE("Unable to find a suitable ACM decompressor\n");
300 }
301
302 TRACE("Connection refused\n");
304}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define WAVE_FORMAT_PCM
Definition: constants.h:425
#define WAVE_FORMAT_EXTENSIBLE
Definition: ksmedia.h:651
if(dx< 0)
Definition: linetemp.h:194
struct _WAVEFORMATEX * LPWAVEFORMATEX
static void FreeMediaType(AM_MEDIA_TYPE *pMediaType)
Definition: filtergraph.c:692
static HRESULT CopyMediaType(AM_MEDIA_TYPE *pDest, const AM_MEDIA_TYPE *pSrc)
Definition: filtergraph.c:706
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95

◆ impl_from_TransformFilter()

static ACMWrapperImpl * impl_from_TransformFilter ( TransformFilter iface)
inlinestatic

Definition at line 56 of file acmwrapper.c.

57{
58 return CONTAINING_RECORD(iface, ACMWrapperImpl, tf);
59}
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by ACMWrapper_BreakConnect(), ACMWrapper_CompleteConnect(), ACMWrapper_DecideBufferSize(), ACMWrapper_Receive(), and ACMWrapper_SetMediaType().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( quartz  )

Variable Documentation

◆ ACMWrapper_FuncsTable

const TransformFilterFuncTable ACMWrapper_FuncsTable
static
Initial value:
= {
}
static HRESULT WINAPI ACMWrapper_Receive(TransformFilter *tf, IMediaSample *pSample)
Definition: acmwrapper.c:61
static HRESULT WINAPI ACMWrapper_BreakConnect(TransformFilter *tf, PIN_DIRECTION dir)
Definition: acmwrapper.c:330
static HRESULT WINAPI ACMWrapper_SetMediaType(TransformFilter *tf, PIN_DIRECTION dir, const AM_MEDIA_TYPE *pmt)
Definition: acmwrapper.c:249
static HRESULT WINAPI ACMWrapper_DecideBufferSize(TransformFilter *tf, IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
Definition: acmwrapper.c:348
static HRESULT WINAPI ACMWrapper_CompleteConnect(TransformFilter *tf, PIN_DIRECTION dir, IPin *pin)
Definition: acmwrapper.c:306

Definition at line 365 of file acmwrapper.c.

Referenced by ACMWrapper_create().

◆ ACMWrapper_Vtbl

static const IBaseFilterVtbl ACMWrapper_Vtbl
static
Initial value:
=
{
}
HRESULT WINAPI BaseFilterImpl_SetSyncSource(IBaseFilter *iface, IReferenceClock *pClock)
Definition: filter.c:101
HRESULT WINAPI TransformFilterImpl_Pause(IBaseFilter *iface)
Definition: transform.c:374
HRESULT WINAPI TransformFilterImpl_Run(IBaseFilter *iface, REFERENCE_TIME tStart)
Definition: transform.c:396
HRESULT WINAPI BaseFilterImpl_GetClassID(IBaseFilter *iface, CLSID *pClsid)
Definition: filter.c:77
HRESULT WINAPI BaseFilterImpl_QueryFilterInfo(IBaseFilter *iface, FILTER_INFO *pInfo)
Definition: filter.c:145
HRESULT WINAPI TransformFilterImpl_Stop(IBaseFilter *iface)
Definition: transform.c:354
HRESULT WINAPI TransformFilterImpl_FindPin(IBaseFilter *iface, LPCWSTR Id, IPin **ppPin)
Definition: transform.c:432
ULONG WINAPI BaseFilterImpl_AddRef(IBaseFilter *iface)
Definition: filter.c:54
HRESULT WINAPI BaseFilterImpl_GetState(IBaseFilter *iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
Definition: filter.c:87
ULONG WINAPI TransformFilterImpl_Release(IBaseFilter *iface)
Definition: transform.c:313
HRESULT WINAPI BaseFilterImpl_JoinFilterGraph(IBaseFilter *iface, IFilterGraph *pGraph, LPCWSTR pName)
Definition: filter.c:159
HRESULT WINAPI TransformFilterImpl_QueryInterface(IBaseFilter *iface, REFIID riid, LPVOID *ppv)
Definition: transform.c:288
HRESULT WINAPI BaseFilterImpl_QueryVendorInfo(IBaseFilter *iface, LPWSTR *pVendorInfo)
Definition: filter.c:178
HRESULT WINAPI BaseFilterImpl_GetSyncSource(IBaseFilter *iface, IReferenceClock **ppClock)
Definition: filter.c:119
HRESULT WINAPI BaseFilterImpl_EnumPins(IBaseFilter *iface, IEnumPins **ppEnum)
Definition: filter.c:135

Definition at line 54 of file acmwrapper.c.

Referenced by ACMWrapper_create().