ReactOS  0.4.14-dev-98-gb0d4763
dsoundrender.c
Go to the documentation of this file.
1 /*
2  * Direct Sound Audio Renderer
3  *
4  * Copyright 2004 Christian Costa
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #include "config.h"
22 
23 #include "quartz_private.h"
24 #include "pin.h"
25 
26 #include "uuids.h"
27 #include "vfwmsgs.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "dshow.h"
31 #include "evcode.h"
32 #include "strmif.h"
33 #include "dsound.h"
34 #include "amaudio.h"
35 
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
38 
40 
41 /* NOTE: buffer can still be filled completely,
42  * but we start waiting until only this amount is buffered
43  */
44 static const REFERENCE_TIME DSoundRenderer_Max_Fill = 150 * 10000;
45 
46 static const IBaseFilterVtbl DSoundRender_Vtbl;
47 static const IBasicAudioVtbl IBasicAudio_Vtbl;
48 static const IReferenceClockVtbl IReferenceClock_Vtbl;
49 static const IAMDirectSoundVtbl IAMDirectSound_Vtbl;
50 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl;
51 
52 typedef struct DSoundRenderImpl
53 {
55  BasicAudio basicAudio;
56 
58  IAMDirectSound IAMDirectSound_iface;
60 
61  IDirectSound8 *dsound;
66 
68 
70 
73 
77 
79 {
80  return CONTAINING_RECORD(iface, DSoundRenderImpl, renderer);
81 }
82 
84 {
85  return CONTAINING_RECORD(iface, DSoundRenderImpl, renderer.filter.IBaseFilter_iface);
86 }
87 
88 static inline DSoundRenderImpl *impl_from_IBasicAudio(IBasicAudio *iface)
89 {
90  return CONTAINING_RECORD(iface, DSoundRenderImpl, basicAudio.IBasicAudio_iface);
91 }
92 
94 {
95  return CONTAINING_RECORD(iface, DSoundRenderImpl, IReferenceClock_iface);
96 }
97 
98 static inline DSoundRenderImpl *impl_from_IAMDirectSound(IAMDirectSound *iface)
99 {
100  return CONTAINING_RECORD(iface, DSoundRenderImpl, IAMDirectSound_iface);
101 }
102 
104 {
105  return CONTAINING_RECORD(iface, DSoundRenderImpl, IAMFilterMiscFlags_iface);
106 }
107 
109  WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->renderer.pInputPin->pin.mtCurrent.pbFormat;
110  REFERENCE_TIME ret = 10000000;
111  ret = ret * pos / wfx->nAvgBytesPerSec;
112  return ret;
113 }
114 
116  WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->renderer.pInputPin->pin.mtCurrent.pbFormat;
118  ret *= wfx->nAvgBytesPerSec;
119  ret /= 10000000;
120  ret -= ret % wfx->nBlockAlign;
121  return ret;
122 }
123 
124 static void DSoundRender_UpdatePositions(DSoundRenderImpl *This, DWORD *seqwritepos, DWORD *minwritepos) {
125  WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->renderer.pInputPin->pin.mtCurrent.pbFormat;
126  BYTE *buf1, *buf2;
127  DWORD size1, size2, playpos, writepos, old_writepos, old_playpos, adv;
128  BOOL writepos_set = This->writepos < This->buf_size;
129 
130  /* Update position and zero */
131  old_writepos = This->writepos;
132  old_playpos = This->last_playpos;
133  if (old_writepos <= old_playpos)
134  old_writepos += This->buf_size;
135 
136  IDirectSoundBuffer_GetCurrentPosition(This->dsbuffer, &playpos, &writepos);
137  if (old_playpos > playpos) {
138  adv = This->buf_size + playpos - old_playpos;
139  This->play_time += time_from_pos(This, This->buf_size);
140  } else
141  adv = playpos - old_playpos;
142  This->last_playpos = playpos;
143  if (adv) {
144  TRACE("Moving from %u to %u: clearing %u bytes\n", old_playpos, playpos, adv);
145  IDirectSoundBuffer_Lock(This->dsbuffer, old_playpos, adv, (void**)&buf1, &size1, (void**)&buf2, &size2, 0);
146  memset(buf1, wfx->wBitsPerSample == 8 ? 128 : 0, size1);
147  memset(buf2, wfx->wBitsPerSample == 8 ? 128 : 0, size2);
148  IDirectSoundBuffer_Unlock(This->dsbuffer, buf1, size1, buf2, size2);
149  }
150  *minwritepos = writepos;
151  if (!writepos_set || old_writepos < writepos) {
152  if (writepos_set) {
153  This->writepos = This->buf_size;
154  FIXME("Underrun of data occurred!\n");
155  }
156  *seqwritepos = writepos;
157  } else
158  *seqwritepos = This->writepos;
159 }
160 
162 {
163  WAVEFORMATEX *wfx = (WAVEFORMATEX*)This->renderer.pInputPin->pin.mtCurrent.pbFormat;
164  DWORD writepos, min_writepos, playpos;
165  REFERENCE_TIME max_lag = 50 * 10000;
166  REFERENCE_TIME min_lag = 25 * 10000;
167  REFERENCE_TIME cur, writepos_t, delta_t;
168 
169  DSoundRender_UpdatePositions(This, &writepos, &min_writepos);
170  playpos = This->last_playpos;
171  if (This->renderer.filter.pClock == &This->IReferenceClock_iface) {
172  max_lag = min_lag;
173  cur = This->play_time + time_from_pos(This, playpos);
174  cur -= This->renderer.filter.rtStreamStart;
175  } else if (This->renderer.filter.pClock) {
176  IReferenceClock_GetTime(This->renderer.filter.pClock, &cur);
177  cur -= This->renderer.filter.rtStreamStart;
178  } else
179  write_at = -1;
180 
181  if (writepos == min_writepos)
182  max_lag = 0;
183 
184  *skip = 0;
185  if (write_at < 0) {
186  *ret_writepos = writepos;
187  goto end;
188  }
189 
190  if (writepos >= playpos)
191  writepos_t = cur + time_from_pos(This, writepos - playpos);
192  else
193  writepos_t = cur + time_from_pos(This, This->buf_size + writepos - playpos);
194 
195  /* write_at: Starting time of sample */
196  /* cur: current time of play position */
197  /* writepos_t: current time of our pointer play position */
198  delta_t = write_at - writepos_t;
199  if (delta_t >= -max_lag && delta_t <= max_lag) {
200  TRACE("Continuing from old position\n");
201  *ret_writepos = writepos;
202  } else if (delta_t < 0) {
203  REFERENCE_TIME past, min_writepos_t;
204  WARN("Delta too big %i/%i, overwriting old data or even skipping\n", (int)delta_t / 10000, (int)max_lag / 10000);
205  if (min_writepos >= playpos)
206  min_writepos_t = cur + time_from_pos(This, min_writepos - playpos);
207  else
208  min_writepos_t = cur + time_from_pos(This, This->buf_size - playpos + min_writepos);
209  past = min_writepos_t - write_at;
210  if (past >= 0) {
211  DWORD skipbytes = pos_from_time(This, past);
212  WARN("Skipping %u bytes\n", skipbytes);
213  *skip = skipbytes;
214  *ret_writepos = min_writepos;
215  } else {
216  DWORD aheadbytes = pos_from_time(This, -past);
217  WARN("Advancing %u bytes\n", aheadbytes);
218  *ret_writepos = (min_writepos + aheadbytes) % This->buf_size;
219  }
220  } else /* delta_t > 0 */ {
221  DWORD aheadbytes;
222  WARN("Delta too big %i/%i, too far ahead\n", (int)delta_t / 10000, (int)max_lag / 10000);
223  aheadbytes = pos_from_time(This, delta_t);
224  WARN("Advancing %u bytes\n", aheadbytes);
225  if (delta_t >= DSoundRenderer_Max_Fill)
226  return S_FALSE;
227  *ret_writepos = (min_writepos + aheadbytes) % This->buf_size;
228  }
229 end:
230  if (playpos > *ret_writepos)
231  *pfree = playpos - *ret_writepos;
232  else if (playpos == *ret_writepos)
233  *pfree = This->buf_size - wfx->nBlockAlign;
234  else
235  *pfree = This->buf_size + playpos - *ret_writepos;
236  if (time_from_pos(This, This->buf_size - *pfree) >= DSoundRenderer_Max_Fill) {
237  TRACE("Blocked: too full %i / %i\n", (int)(time_from_pos(This, This->buf_size - *pfree)/10000), (int)(DSoundRenderer_Max_Fill / 10000));
238  return S_FALSE;
239  }
240  return S_OK;
241 }
242 
244 {
245  while (This->renderer.filter.state == State_Running)
246  {
247  DWORD pos1, pos2;
248  DSoundRender_UpdatePositions(This, &pos1, &pos2);
249  if (pos1 == pos2)
250  break;
251 
252  This->in_loop = 1;
253  LeaveCriticalSection(&This->renderer.filter.csFilter);
254  LeaveCriticalSection(&This->renderer.csRenderLock);
255  WaitForSingleObject(This->blocked, 10);
256  EnterCriticalSection(&This->renderer.csRenderLock);
257  EnterCriticalSection(&This->renderer.filter.csFilter);
258  This->in_loop = 0;
259  }
260 
261  return S_OK;
262 }
263 
265 {
266  HRESULT hr;
267 
268  while (size && This->renderer.filter.state != State_Stopped) {
269  DWORD writepos, skip = 0, free, size1, size2, ret;
270  BYTE *buf1, *buf2;
271 
272  if (This->renderer.filter.state == State_Running)
273  hr = DSoundRender_GetWritePos(This, &writepos, tStart, &free, &skip);
274  else
275  hr = S_FALSE;
276 
277  if (hr != S_OK) {
278  This->in_loop = 1;
279  LeaveCriticalSection(&This->renderer.csRenderLock);
280  ret = WaitForSingleObject(This->blocked, 10);
281  EnterCriticalSection(&This->renderer.csRenderLock);
282  This->in_loop = 0;
283  if (This->renderer.pInputPin->flushing ||
284  This->renderer.filter.state == State_Stopped) {
285  return This->renderer.filter.state == State_Paused ? S_OK : VFW_E_WRONG_STATE;
286  }
287  if (ret != WAIT_TIMEOUT)
288  ERR("%x\n", ret);
289  continue;
290  }
291  tStart = -1;
292 
293  if (skip)
294  FIXME("Sample dropped %u of %u bytes\n", skip, size);
295  if (skip >= size)
296  return S_OK;
297  data += skip;
298  size -= skip;
299 
300  hr = IDirectSoundBuffer_Lock(This->dsbuffer, writepos, min(free, size), (void**)&buf1, &size1, (void**)&buf2, &size2, 0);
301  if (hr != DS_OK) {
302  ERR("Unable to lock sound buffer! (%x)\n", hr);
303  break;
304  }
305  memcpy(buf1, data, size1);
306  if (size2)
307  memcpy(buf2, data+size1, size2);
308  IDirectSoundBuffer_Unlock(This->dsbuffer, buf1, size1, buf2, size2);
309  This->writepos = (writepos + size1 + size2) % This->buf_size;
310  TRACE("Wrote %u bytes at %u, next at %u - (%u/%u)\n", size1+size2, writepos, This->writepos, free, size);
311  data += size1 + size2;
312  size -= size1 + size2;
313  }
314  return S_OK;
315 }
316 
318 {
319  /* We time ourselves do not use the base renderers timing */
320  return S_OK;
321 }
322 
323 
325 {
327  HRESULT hr;
328  AM_MEDIA_TYPE *amt;
329 
330  if (IMediaSample_GetMediaType(pSample, &amt) == S_OK)
331  {
332  AM_MEDIA_TYPE *orig = &This->renderer.pInputPin->pin.mtCurrent;
333  WAVEFORMATEX *origfmt = (WAVEFORMATEX *)orig->pbFormat;
334  WAVEFORMATEX *newfmt = (WAVEFORMATEX *)amt->pbFormat;
335 
336  if (origfmt->wFormatTag == newfmt->wFormatTag &&
337  origfmt->nChannels == newfmt->nChannels &&
338  origfmt->nBlockAlign == newfmt->nBlockAlign &&
339  origfmt->wBitsPerSample == newfmt->wBitsPerSample &&
340  origfmt->cbSize == newfmt->cbSize)
341  {
342  if (origfmt->nSamplesPerSec != newfmt->nSamplesPerSec)
343  {
345  newfmt->nSamplesPerSec);
346  if (FAILED(hr))
348  FreeMediaType(orig);
349  CopyMediaType(orig, amt);
350  IMediaSample_SetMediaType(pSample, NULL);
351  }
352  }
353  else
355  }
356  return S_OK;
357 }
358 
360 {
362  LPBYTE pbSrcStream = NULL;
363  LONG cbSrcStream = 0;
364  REFERENCE_TIME tStart, tStop;
365  HRESULT hr;
366 
367  TRACE("%p %p\n", iface, pSample);
368 
369  /* Slightly incorrect, Pause completes when a frame is received so we should signal
370  * pause completion here, but for sound playing a single frame doesn't make sense
371  */
372 
373  hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
374  if (FAILED(hr))
375  {
376  ERR("Cannot get pointer to sample data (%x)\n", hr);
377  return hr;
378  }
379 
380  hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
381  if (FAILED(hr)) {
382  ERR("Cannot get sample time (%x)\n", hr);
383  tStart = tStop = -1;
384  }
385 
386  IMediaSample_IsDiscontinuity(pSample);
387 
388  if (IMediaSample_IsPreroll(pSample) == S_OK)
389  {
390  TRACE("Preroll!\n");
391  return S_OK;
392  }
393 
394  cbSrcStream = IMediaSample_GetActualDataLength(pSample);
395  TRACE("Sample data ptr = %p, size = %d\n", pbSrcStream, cbSrcStream);
396 
397  hr = DSoundRender_SendSampleData(This, tStart, tStop, pbSrcStream, cbSrcStream);
398  if (This->renderer.filter.state == State_Running && This->renderer.filter.pClock && tStart >= 0) {
399  REFERENCE_TIME jitter, now = 0;
400  Quality q;
401  IReferenceClock_GetTime(This->renderer.filter.pClock, &now);
402  jitter = now - This->renderer.filter.rtStreamStart - tStart;
403  if (jitter <= -DSoundRenderer_Max_Fill)
404  jitter += DSoundRenderer_Max_Fill;
405  else if (jitter < 0)
406  jitter = 0;
407  q.Type = (jitter > 0 ? Famine : Flood);
408  q.Proportion = 1000;
409  q.Late = jitter;
410  q.TimeStamp = tStart;
411  IQualityControl_Notify((IQualityControl *)This->renderer.qcimpl, (IBaseFilter*)This, q);
412  }
413  return hr;
414 }
415 
417 {
419 
420  if (!IsEqualIID(&pmt->majortype, &MEDIATYPE_Audio))
421  return S_FALSE;
422 
423  format = (WAVEFORMATEX*)pmt->pbFormat;
424  TRACE("Format = %p\n", format);
425  TRACE("wFormatTag = %x %x\n", format->wFormatTag, WAVE_FORMAT_PCM);
426  TRACE("nChannels = %d\n", format->nChannels);
427  TRACE("nSamplesPerSec = %d\n", format->nSamplesPerSec);
428  TRACE("nAvgBytesPerSec = %d\n", format->nAvgBytesPerSec);
429  TRACE("nBlockAlign = %d\n", format->nBlockAlign);
430  TRACE("wBitsPerSample = %d\n", format->wBitsPerSample);
431 
432  if (!IsEqualIID(&pmt->subtype, &MEDIASUBTYPE_PCM))
433  return S_FALSE;
434 
435  return S_OK;
436 }
437 
439 {
441 
442  TRACE("(%p/%p)->()\n", This, iface);
443 
444  IDirectSoundBuffer_Stop(This->dsbuffer);
445  This->writepos = This->buf_size;
446  SetEvent(This->blocked);
447 }
448 
450 {
452 
453  TRACE("(%p)\n", This);
454 
455  if (This->renderer.pInputPin->pin.pConnectedTo)
456  {
457  if (This->renderer.filter.state == State_Paused)
458  {
459  /* Unblock our thread, state changing from paused to running doesn't need a reset for state change */
460  SetEvent(This->blocked);
461  }
462  IDirectSoundBuffer_Play(This->dsbuffer, 0, 0, DSBPLAY_LOOPING);
463  ResetEvent(This->blocked);
464  }
465 }
466 
468 {
470  const AM_MEDIA_TYPE * pmt = &This->renderer.pInputPin->pin.mtCurrent;
471  HRESULT hr = S_OK;
473  DSBUFFERDESC buf_desc;
474 
475  TRACE("(%p)->(%p)\n", This, pReceivePin);
476  dump_AM_MEDIA_TYPE(pmt);
477 
478  TRACE("MajorType %s\n", debugstr_guid(&pmt->majortype));
479  TRACE("SubType %s\n", debugstr_guid(&pmt->subtype));
480  TRACE("Format %s\n", debugstr_guid(&pmt->formattype));
481  TRACE("Size %d\n", pmt->cbFormat);
482 
483  format = (WAVEFORMATEX*)pmt->pbFormat;
484 
485  This->buf_size = format->nAvgBytesPerSec;
486 
487  memset(&buf_desc,0,sizeof(DSBUFFERDESC));
488  buf_desc.dwSize = sizeof(DSBUFFERDESC);
492  buf_desc.dwBufferBytes = This->buf_size;
493  buf_desc.lpwfxFormat = format;
494  hr = IDirectSound8_CreateSoundBuffer(This->dsound, &buf_desc, &This->dsbuffer, NULL);
495  This->writepos = This->buf_size;
496  if (FAILED(hr))
497  ERR("Can't create sound buffer (%x)\n", hr);
498 
499  if (SUCCEEDED(hr))
500  {
501  hr = IDirectSoundBuffer_SetVolume(This->dsbuffer, This->volume);
502  if (FAILED(hr))
503  ERR("Can't set volume to %d (%x)\n", This->volume, hr);
504 
505  hr = IDirectSoundBuffer_SetPan(This->dsbuffer, This->pan);
506  if (FAILED(hr))
507  ERR("Can't set pan to %d (%x)\n", This->pan, hr);
508  hr = S_OK;
509  }
510 
511  if (FAILED(hr) && hr != VFW_E_ALREADY_CONNECTED)
512  {
513  if (This->dsbuffer)
514  IDirectSoundBuffer_Release(This->dsbuffer);
515  This->dsbuffer = NULL;
516  }
517 
518  return hr;
519 }
520 
522 {
524 
525  TRACE("(%p)->()\n", iface);
526 
527  if (This->threadid) {
528  PostThreadMessageW(This->threadid, WM_APP, 0, 0);
529  LeaveCriticalSection(This->renderer.pInputPin->pin.pCritSec);
530  WaitForSingleObject(This->advisethread, INFINITE);
531  EnterCriticalSection(This->renderer.pInputPin->pin.pCritSec);
532  CloseHandle(This->advisethread);
533  }
534  if (This->dsbuffer)
535  IDirectSoundBuffer_Release(This->dsbuffer);
536  This->dsbuffer = NULL;
537 
538  return S_OK;
539 }
540 
542 {
544  HRESULT hr;
545 
546  TRACE("(%p)->()\n",iface);
547 
549  if (hr != S_OK)
550  {
551  ERR("%08x\n", hr);
552  return hr;
553  }
554 
556 
557  return hr;
558 }
559 
561 {
563 
564  TRACE("\n");
566  SetEvent(This->blocked);
567 
568  return S_OK;
569 }
570 
572 {
574 
575  TRACE("\n");
576 
578  if (This->renderer.filter.state != State_Stopped)
579  ResetEvent(This->blocked);
580 
581  if (This->dsbuffer)
582  {
583  LPBYTE buffer;
584  DWORD size;
585 
586  /* Force a reset */
588  memset(buffer, 0, size);
589  IDirectSoundBuffer_Unlock(This->dsbuffer, buffer, size, NULL, 0);
590  This->writepos = This->buf_size;
591  }
592 
593  return S_OK;
594 }
595 
599 
600  NULL,
601  NULL,
602  NULL,
605  NULL,
606  NULL,
607  NULL,
610 
616 };
617 
619 {
620  HRESULT hr;
621  DSoundRenderImpl * pDSoundRender;
622 
623  TRACE("(%p, %p)\n", pUnkOuter, ppv);
624 
625  *ppv = NULL;
626 
627  if (pUnkOuter)
628  return CLASS_E_NOAGGREGATION;
629 
630  pDSoundRender = CoTaskMemAlloc(sizeof(DSoundRenderImpl));
631  if (!pDSoundRender)
632  return E_OUTOFMEMORY;
633  ZeroMemory(pDSoundRender, sizeof(DSoundRenderImpl));
634 
635  hr = BaseRenderer_Init(&pDSoundRender->renderer, &DSoundRender_Vtbl, (IUnknown*)pDSoundRender, &CLSID_DSoundRender, (DWORD_PTR)(__FILE__ ": DSoundRenderImpl.csFilter"), &BaseFuncTable);
636 
637  BasicAudio_Init(&pDSoundRender->basicAudio,&IBasicAudio_Vtbl);
638  pDSoundRender->IReferenceClock_iface.lpVtbl = &IReferenceClock_Vtbl;
639  pDSoundRender->IAMDirectSound_iface.lpVtbl = &IAMDirectSound_Vtbl;
640  pDSoundRender->IAMFilterMiscFlags_iface.lpVtbl = &IAMFilterMiscFlags_Vtbl;
641 
642  if (SUCCEEDED(hr))
643  {
644  hr = DirectSoundCreate8(NULL, &pDSoundRender->dsound, NULL);
645  if (FAILED(hr))
646  ERR("Cannot create Direct Sound object (%x)\n", hr);
647  else
649  if (SUCCEEDED(hr)) {
650  IDirectSoundBuffer *buf;
651  DSBUFFERDESC buf_desc;
652  memset(&buf_desc,0,sizeof(DSBUFFERDESC));
653  buf_desc.dwSize = sizeof(DSBUFFERDESC);
654  buf_desc.dwFlags = DSBCAPS_PRIMARYBUFFER;
655  hr = IDirectSound8_CreateSoundBuffer(pDSoundRender->dsound, &buf_desc, &buf, NULL);
656  if (SUCCEEDED(hr)) {
659  }
660  hr = S_OK;
661  }
662  }
663 
664  if (SUCCEEDED(hr))
665  {
666  pDSoundRender->blocked = CreateEventW(NULL, TRUE, TRUE, NULL);
667 
668  if (!pDSoundRender->blocked || FAILED(hr))
669  {
670  IBaseFilter_Release(&pDSoundRender->renderer.filter.IBaseFilter_iface);
672  }
673 
674  *ppv = pDSoundRender;
675  }
676  else
677  {
678  BaseRendererImpl_Release(&pDSoundRender->renderer.filter.IBaseFilter_iface);
679  CoTaskMemFree(pDSoundRender);
680  }
681 
682  return hr;
683 }
684 
686 {
688  TRACE("(%p, %p)->(%s, %p)\n", This, iface, qzdebugstr_guid(riid), ppv);
689 
690  *ppv = NULL;
691 
692  if (IsEqualIID(riid, &IID_IBasicAudio))
693  *ppv = &This->basicAudio.IBasicAudio_iface;
694  else if (IsEqualIID(riid, &IID_IReferenceClock))
695  *ppv = &This->IReferenceClock_iface;
696  else if (IsEqualIID(riid, &IID_IAMDirectSound))
697  *ppv = &This->IAMDirectSound_iface;
698  else if (IsEqualIID(riid, &IID_IAMFilterMiscFlags))
699  *ppv = &This->IAMFilterMiscFlags_iface;
700  else
701  {
702  HRESULT hr;
704  if (SUCCEEDED(hr))
705  return hr;
706  }
707 
708  if (*ppv)
709  {
710  IUnknown_AddRef((IUnknown *)(*ppv));
711  return S_OK;
712  }
713 
714  if (!IsEqualIID(riid, &IID_IPin) && !IsEqualIID(riid, &IID_IVideoWindow))
715  FIXME("No interface for %s!\n", qzdebugstr_guid(riid));
716 
717  return E_NOINTERFACE;
718 }
719 
721 {
723  ULONG refCount = BaseRendererImpl_Release(iface);
724 
725  TRACE("(%p)->() Release from %d\n", This, refCount + 1);
726 
727  if (!refCount)
728  {
729  if (This->threadid) {
730  PostThreadMessageW(This->threadid, WM_APP, 0, 0);
731  WaitForSingleObject(This->advisethread, INFINITE);
732  CloseHandle(This->advisethread);
733  }
734 
735  if (This->dsbuffer)
736  IDirectSoundBuffer_Release(This->dsbuffer);
737  This->dsbuffer = NULL;
738  if (This->dsound)
739  IDirectSound8_Release(This->dsound);
740  This->dsound = NULL;
741 
742  BasicAudio_Destroy(&This->basicAudio);
743  CloseHandle(This->blocked);
744 
745  TRACE("Destroying Audio Renderer\n");
747 
748  return 0;
749  }
750  else
751  return refCount;
752 }
753 
755 {
756  HRESULT hr = S_OK;
758 
759  TRACE("(%p/%p)->()\n", This, iface);
760 
761  EnterCriticalSection(&This->renderer.csRenderLock);
762  if (This->renderer.filter.state != State_Paused)
763  {
764  if (This->renderer.filter.state == State_Stopped)
765  {
766  if (This->renderer.pInputPin->pin.pConnectedTo)
767  ResetEvent(This->renderer.evComplete);
768  This->renderer.pInputPin->end_of_stream = 0;
769  }
770 
771  hr = IDirectSoundBuffer_Stop(This->dsbuffer);
772  if (SUCCEEDED(hr))
773  This->renderer.filter.state = State_Paused;
774 
775  ResetEvent(This->blocked);
776  ResetEvent(This->renderer.RenderEvent);
777  }
778  ResetEvent(This->renderer.ThreadSignal);
779  LeaveCriticalSection(&This->renderer.csRenderLock);
780 
781  return hr;
782 }
783 
784 static const IBaseFilterVtbl DSoundRender_Vtbl =
785 {
801 };
802 
803 /*** IUnknown methods ***/
804 static HRESULT WINAPI Basicaudio_QueryInterface(IBasicAudio *iface,
805  REFIID riid,
806  LPVOID*ppvObj) {
808 
809  TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
810 
811  return DSoundRender_QueryInterface(&This->renderer.filter.IBaseFilter_iface, riid, ppvObj);
812 }
813 
814 static ULONG WINAPI Basicaudio_AddRef(IBasicAudio *iface) {
816 
817  TRACE("(%p/%p)->()\n", This, iface);
818 
819  return BaseFilterImpl_AddRef(&This->renderer.filter.IBaseFilter_iface);
820 }
821 
822 static ULONG WINAPI Basicaudio_Release(IBasicAudio *iface) {
824 
825  TRACE("(%p/%p)->()\n", This, iface);
826 
827  return DSoundRender_Release(&This->renderer.filter.IBaseFilter_iface);
828 }
829 
830 /*** IBasicAudio methods ***/
831 static HRESULT WINAPI Basicaudio_put_Volume(IBasicAudio *iface,
832  LONG lVolume) {
834 
835  TRACE("(%p/%p)->(%d)\n", This, iface, lVolume);
836 
837  if (lVolume > DSBVOLUME_MAX || lVolume < DSBVOLUME_MIN)
838  return E_INVALIDARG;
839 
840  if (This->dsbuffer) {
841  if (FAILED(IDirectSoundBuffer_SetVolume(This->dsbuffer, lVolume)))
842  return E_FAIL;
843  }
844 
845  This->volume = lVolume;
846  return S_OK;
847 }
848 
849 static HRESULT WINAPI Basicaudio_get_Volume(IBasicAudio *iface,
850  LONG *plVolume) {
852 
853  TRACE("(%p/%p)->(%p)\n", This, iface, plVolume);
854 
855  if (!plVolume)
856  return E_POINTER;
857 
858  *plVolume = This->volume;
859  return S_OK;
860 }
861 
862 static HRESULT WINAPI Basicaudio_put_Balance(IBasicAudio *iface,
863  LONG lBalance) {
865 
866  TRACE("(%p/%p)->(%d)\n", This, iface, lBalance);
867 
868  if (lBalance < DSBPAN_LEFT || lBalance > DSBPAN_RIGHT)
869  return E_INVALIDARG;
870 
871  if (This->dsbuffer) {
872  if (FAILED(IDirectSoundBuffer_SetPan(This->dsbuffer, lBalance)))
873  return E_FAIL;
874  }
875 
876  This->pan = lBalance;
877  return S_OK;
878 }
879 
880 static HRESULT WINAPI Basicaudio_get_Balance(IBasicAudio *iface,
881  LONG *plBalance) {
883 
884  TRACE("(%p/%p)->(%p)\n", This, iface, plBalance);
885 
886  if (!plBalance)
887  return E_POINTER;
888 
889  *plBalance = This->pan;
890  return S_OK;
891 }
892 
893 static const IBasicAudioVtbl IBasicAudio_Vtbl =
894 {
906 };
907 
914 };
915 static LONG cookie_counter = 1;
916 
918  DSoundRenderImpl *This = lpParam;
919  struct dsoundrender_timer head = {NULL};
920  MSG msg;
921 
922  TRACE("(%p): Main Loop\n", This);
923 
925  SetEvent(This->thread_wait);
926 
927  while (1)
928  {
929  HRESULT hr;
930  REFERENCE_TIME curtime = 0;
931  BOOL ret;
932  struct dsoundrender_timer *prev = &head, *cur;
933 
934  hr = IReferenceClock_GetTime(&This->IReferenceClock_iface, &curtime);
935  if (SUCCEEDED(hr)) {
936  TRACE("Time: %s\n", wine_dbgstr_longlong(curtime));
937  while (prev->next) {
938  cur = prev->next;
939  if (cur->start > curtime) {
940  TRACE("Skipping %p\n", cur);
941  prev = cur;
942  } else if (cur->periodicity) {
943  while (cur->start <= curtime) {
944  cur->start += cur->periodicity;
945  ReleaseSemaphore(cur->handle, 1, NULL);
946  }
947  prev = cur;
948  } else {
949  struct dsoundrender_timer *next = cur->next;
950  TRACE("Firing %p %s < %s\n", cur, wine_dbgstr_longlong(cur->start), wine_dbgstr_longlong(curtime));
951  SetEvent(cur->handle);
952  HeapFree(GetProcessHeap(), 0, cur);
953  prev->next = next;
954  }
955  }
956  }
957  if (!head.next)
959  else
961  while (ret) {
962  switch (LOWORD(msg.message) - WM_APP) {
963  case 0: TRACE("Exiting\n"); return 0;
964  case 1:
965  case 2: {
966  struct dsoundrender_timer *t = (struct dsoundrender_timer *)msg.wParam;
967  if (LOWORD(msg.message) - WM_APP == 1)
968  TRACE("Adding one-shot timer %p\n", t);
969  else
970  TRACE("Adding periodic timer %p\n", t);
971  t->next = head.next;
972  head.next = t;
973  break;
974  }
975  case 3:
976  prev = &head;
977  while (prev->next) {
978  cur = prev->next;
979  if (cur->cookie == msg.wParam) {
980  struct dsoundrender_timer *next = cur->next;
981  HeapFree(GetProcessHeap(), 0, cur);
982  prev->next = next;
983  break;
984  }
985  prev = cur;
986  }
987  break;
988  }
990  }
992  }
993  return 0;
994 }
995 
996 /*** IUnknown methods ***/
998  REFIID riid,
999  LPVOID*ppvObj)
1000 {
1002 
1003  TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
1004 
1005  return DSoundRender_QueryInterface(&This->renderer.filter.IBaseFilter_iface, riid, ppvObj);
1006 }
1007 
1009 {
1011 
1012  TRACE("(%p/%p)->()\n", This, iface);
1013 
1014  return BaseFilterImpl_AddRef(&This->renderer.filter.IBaseFilter_iface);
1015 }
1016 
1018 {
1020 
1021  TRACE("(%p/%p)->()\n", This, iface);
1022 
1023  return DSoundRender_Release(&This->renderer.filter.IBaseFilter_iface);
1024 }
1025 
1026 /*** IReferenceClock methods ***/
1029 {
1031  HRESULT hr = E_FAIL;
1032 
1033  TRACE("(%p/%p)->(%p)\n", This, iface, pTime);
1034  if (!pTime)
1035  return E_POINTER;
1036 
1037  if (This->dsbuffer) {
1038  DWORD writepos1, writepos2;
1039  EnterCriticalSection(&This->renderer.filter.csFilter);
1040  DSoundRender_UpdatePositions(This, &writepos1, &writepos2);
1041  if (This->renderer.pInputPin && This->renderer.pInputPin->pin.mtCurrent.pbFormat)
1042  {
1043  *pTime = This->play_time + time_from_pos(This, This->last_playpos);
1044  hr = S_OK;
1045  }
1046  else
1047  {
1048  ERR("pInputPin Disconnected\n");
1049  hr = E_FAIL;
1050  }
1051  LeaveCriticalSection(&This->renderer.filter.csFilter);
1052  }
1053  if (FAILED(hr))
1054  WARN("Could not get reference time (%x)!\n", hr);
1055 
1056  return hr;
1057 }
1058 
1060  REFERENCE_TIME rtBaseTime,
1061  REFERENCE_TIME rtStreamTime,
1062  HEVENT hEvent,
1063  DWORD_PTR *pdwAdviseCookie)
1064 {
1066  REFERENCE_TIME when = rtBaseTime + rtStreamTime;
1067  REFERENCE_TIME future;
1068  TRACE("(%p/%p)->(%s, %s, %p, %p)\n", This, iface, wine_dbgstr_longlong(rtBaseTime), wine_dbgstr_longlong(rtStreamTime), (void*)hEvent, pdwAdviseCookie);
1069 
1070  if (when <= 0)
1071  return E_INVALIDARG;
1072 
1073  if (!pdwAdviseCookie)
1074  return E_POINTER;
1075 
1076  EnterCriticalSection(&This->renderer.filter.csFilter);
1077  future = when - This->play_time;
1078  if (!This->threadid && This->dsbuffer) {
1079  This->thread_wait = CreateEventW(0, 0, 0, 0);
1080  This->advisethread = CreateThread(NULL, 0, DSoundAdviseThread, This, 0, &This->threadid);
1081  WaitForSingleObject(This->thread_wait, INFINITE);
1082  CloseHandle(This->thread_wait);
1083  }
1084  LeaveCriticalSection(&This->renderer.filter.csFilter);
1085  /* If it's in the past or the next millisecond, trigger immediately */
1086  if (future <= 10000) {
1088  *pdwAdviseCookie = 0;
1089  } else {
1090  struct dsoundrender_timer *t = HeapAlloc(GetProcessHeap(), 0, sizeof(*t));
1091  t->next = NULL;
1092  t->start = when;
1093  t->periodicity = 0;
1094  t->handle = (HANDLE)hEvent;
1096  PostThreadMessageW(This->threadid, WM_APP+1, (WPARAM)t, 0);
1097  *pdwAdviseCookie = t->cookie;
1098  }
1099 
1100  return S_OK;
1101 }
1102 
1104  REFERENCE_TIME rtStartTime,
1105  REFERENCE_TIME rtPeriodTime,
1106  HSEMAPHORE hSemaphore,
1107  DWORD_PTR *pdwAdviseCookie)
1108 {
1110  struct dsoundrender_timer *t;
1111 
1112  TRACE("(%p/%p)->(%s, %s, %p, %p)\n", This, iface, wine_dbgstr_longlong(rtStartTime), wine_dbgstr_longlong(rtPeriodTime), (void*)hSemaphore, pdwAdviseCookie);
1113 
1114  if (rtStartTime <= 0 || rtPeriodTime <= 0)
1115  return E_INVALIDARG;
1116 
1117  if (!pdwAdviseCookie)
1118  return E_POINTER;
1119 
1120  EnterCriticalSection(&This->renderer.filter.csFilter);
1121  if (!This->threadid && This->dsbuffer) {
1122  This->thread_wait = CreateEventW(0, 0, 0, 0);
1123  This->advisethread = CreateThread(NULL, 0, DSoundAdviseThread, This, 0, &This->threadid);
1124  WaitForSingleObject(This->thread_wait, INFINITE);
1125  CloseHandle(This->thread_wait);
1126  }
1127  LeaveCriticalSection(&This->renderer.filter.csFilter);
1128 
1129  t = HeapAlloc(GetProcessHeap(), 0, sizeof(*t));
1130  t->next = NULL;
1131  t->start = rtStartTime;
1132  t->periodicity = rtPeriodTime;
1133  t->handle = (HANDLE)hSemaphore;
1135  PostThreadMessageW(This->threadid, WM_APP+1, (WPARAM)t, 0);
1136  *pdwAdviseCookie = t->cookie;
1137 
1138  return S_OK;
1139 }
1140 
1142  DWORD_PTR dwAdviseCookie)
1143 {
1145 
1146  TRACE("(%p/%p)->(%p)\n", This, iface, (void*)dwAdviseCookie);
1147  if (!This->advisethread || !dwAdviseCookie)
1148  return S_FALSE;
1149  PostThreadMessageW(This->threadid, WM_APP+3, dwAdviseCookie, 0);
1150  return S_OK;
1151 }
1152 
1153 static const IReferenceClockVtbl IReferenceClock_Vtbl =
1154 {
1162 };
1163 
1164 /*** IUnknown methods ***/
1165 static HRESULT WINAPI AMDirectSound_QueryInterface(IAMDirectSound *iface,
1166  REFIID riid,
1167  LPVOID*ppvObj)
1168 {
1170 
1171  TRACE("(%p/%p)->(%s, %p)\n", This, iface, debugstr_guid(riid), ppvObj);
1172 
1173  return DSoundRender_QueryInterface(&This->renderer.filter.IBaseFilter_iface, riid, ppvObj);
1174 }
1175 
1176 static ULONG WINAPI AMDirectSound_AddRef(IAMDirectSound *iface)
1177 {
1179 
1180  TRACE("(%p/%p)->()\n", This, iface);
1181 
1182  return BaseFilterImpl_AddRef(&This->renderer.filter.IBaseFilter_iface);
1183 }
1184 
1185 static ULONG WINAPI AMDirectSound_Release(IAMDirectSound *iface)
1186 {
1188 
1189  TRACE("(%p/%p)->()\n", This, iface);
1190 
1191  return DSoundRender_Release(&This->renderer.filter.IBaseFilter_iface);
1192 }
1193 
1194 /*** IAMDirectSound methods ***/
1195 static HRESULT WINAPI AMDirectSound_GetDirectSoundInterface(IAMDirectSound *iface, IDirectSound **ds)
1196 {
1198 
1199  FIXME("(%p/%p)->(%p): stub\n", This, iface, ds);
1200 
1201  return E_NOTIMPL;
1202 }
1203 
1204 static HRESULT WINAPI AMDirectSound_GetPrimaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer **buf)
1205 {
1207 
1208  FIXME("(%p/%p)->(%p): stub\n", This, iface, buf);
1209 
1210  return E_NOTIMPL;
1211 }
1212 
1213 static HRESULT WINAPI AMDirectSound_GetSecondaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer **buf)
1214 {
1216 
1217  FIXME("(%p/%p)->(%p): stub\n", This, iface, buf);
1218 
1219  return E_NOTIMPL;
1220 }
1221 
1222 static HRESULT WINAPI AMDirectSound_ReleaseDirectSoundInterface(IAMDirectSound *iface, IDirectSound *ds)
1223 {
1225 
1226  FIXME("(%p/%p)->(%p): stub\n", This, iface, ds);
1227 
1228  return E_NOTIMPL;
1229 }
1230 
1231 static HRESULT WINAPI AMDirectSound_ReleasePrimaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer *buf)
1232 {
1234 
1235  FIXME("(%p/%p)->(%p): stub\n", This, iface, buf);
1236 
1237  return E_NOTIMPL;
1238 }
1239 
1240 static HRESULT WINAPI AMDirectSound_ReleaseSecondaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer *buf)
1241 {
1243 
1244  FIXME("(%p/%p)->(%p): stub\n", This, iface, buf);
1245 
1246  return E_NOTIMPL;
1247 }
1248 
1249 static HRESULT WINAPI AMDirectSound_SetFocusWindow(IAMDirectSound *iface, HWND hwnd, BOOL bgaudible)
1250 {
1252 
1253  FIXME("(%p/%p)->(%p,%d): stub\n", This, iface, hwnd, bgaudible);
1254 
1255  return E_NOTIMPL;
1256 }
1257 
1258 static HRESULT WINAPI AMDirectSound_GetFocusWindow(IAMDirectSound *iface, HWND *hwnd, BOOL *bgaudible)
1259 {
1261 
1262  FIXME("(%p/%p)->(%p,%p): stub\n", This, iface, hwnd, bgaudible);
1263 
1264  return E_NOTIMPL;
1265 }
1266 
1267 static const IAMDirectSoundVtbl IAMDirectSound_Vtbl =
1268 {
1280 };
1281 
1284  return IBaseFilter_QueryInterface(&This->renderer.filter.IBaseFilter_iface, riid, ppv);
1285 }
1286 
1289  return IBaseFilter_AddRef(&This->renderer.filter.IBaseFilter_iface);
1290 }
1291 
1294  return IBaseFilter_Release(&This->renderer.filter.IBaseFilter_iface);
1295 }
1296 
1299 }
1300 
1301 static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl = {
1306 };
HRESULT WINAPI BasicAudioImpl_GetTypeInfoCount(IBasicAudio *iface, UINT *pctinfo)
Definition: audio.c:49
#define IDirectSoundBuffer_Lock(p, a, b, c, d, e, f, g)
Definition: dsound.h:584
HRESULT WINAPI BaseRendererImpl_SetSyncSource(IBaseFilter *iface, IReferenceClock *clock)
Definition: renderer.c:537
REFERENCE_TIME periodicity
Definition: dsoundrender.c:911
static HRESULT WINAPI Basicaudio_QueryInterface(IBasicAudio *iface, REFIID riid, LPVOID *ppvObj)
Definition: dsoundrender.c:804
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
static DSoundRenderImpl * impl_from_IAMFilterMiscFlags(IAMFilterMiscFlags *iface)
Definition: dsoundrender.c:103
#define IDirectSound8_SetCooperativeLevel(p, a, b)
Definition: dsound.h:512
HRESULT WINAPI BasicAudio_Init(BasicAudio *pBasicAudio, const IBasicAudioVtbl *lpVtbl)
Definition: audio.c:36
void dump_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *pmt)
Definition: enummedia.c:27
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
HRESULT WINAPI DirectSoundCreate8(LPCGUID lpcGUID, LPDIRECTSOUND8 *ppDS, IUnknown *pUnkOuter)
Definition: directsound.c:504
#define CloseHandle
Definition: compat.h:398
#define E_NOINTERFACE
Definition: winerror.h:2364
#define DSBCAPS_CTRLVOLUME
Definition: dsound.h:213
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:422
static HRESULT WINAPI Basicaudio_get_Volume(IBasicAudio *iface, LONG *plVolume)
Definition: dsoundrender.c:849
#define DSBCAPS_GETCURRENTPOSITION2
Definition: dsound.h:220
static const REFERENCE_TIME DSoundRenderer_Max_Fill
Definition: dsoundrender.c:44
HRESULT hr
Definition: shlfolder.c:183
HRESULT DSoundRender_create(IUnknown *pUnkOuter, LPVOID *ppv)
Definition: dsoundrender.c:618
struct outqueuenode * head
Definition: adnsresfilter.c:66
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static HRESULT WINAPI DSoundRender_BreakConnect(BaseRenderer *iface)
Definition: dsoundrender.c:521
static HRESULT WINAPI AMDirectSound_SetFocusWindow(IAMDirectSound *iface, HWND hwnd, BOOL bgaudible)
REFIID riid
Definition: precomp.h:44
#define IDirectSoundBuffer_Release(p)
Definition: dsound.h:574
const char * qzdebugstr_guid(const GUID *id)
Definition: main.c:279
REFERENCE_TIME play_time
Definition: dsoundrender.c:67
HRESULT WINAPI BaseRendererImpl_GetState(IBaseFilter *iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
Definition: renderer.c:550
#define free
Definition: debug_ros.c:5
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1827
#define WARN(fmt,...)
Definition: debug.h:111
static ULONG WINAPI AMDirectSound_Release(IAMDirectSound *iface)
REFIID LPVOID * ppv
Definition: atlbase.h:39
GLdouble GLdouble t
Definition: gl.h:2047
static HRESULT WINAPI Basicaudio_get_Balance(IBasicAudio *iface, LONG *plBalance)
Definition: dsoundrender.c:880
#define ds
Definition: i386-dis.c:434
static HRESULT WINAPI AMFilterMiscFlags_QueryInterface(IAMFilterMiscFlags *iface, REFIID riid, void **ppv)
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static DWORD pos_from_time(DSoundRenderImpl *This, REFERENCE_TIME time)
Definition: dsoundrender.c:115
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1642
GLuint buffer
Definition: glext.h:5915
static const IBasicAudioVtbl IBasicAudio_Vtbl
Definition: dsoundrender.c:47
static REFERENCE_TIME time_from_pos(DSoundRenderImpl *This, DWORD pos)
Definition: dsoundrender.c:108
UINT_PTR WPARAM
Definition: windef.h:207
GLuint GLuint end
Definition: gl.h:1545
static HRESULT WINAPI AMDirectSound_ReleasePrimaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer *buf)
#define DSBCAPS_CTRLPAN
Definition: dsound.h:212
BasicAudio basicAudio
Definition: dsoundrender.c:55
__u16 time
Definition: mkdosfs.c:366
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define IDirectSound8_Release(p)
Definition: dsound.h:507
#define DSBVOLUME_MAX
Definition: dsound.h:229
#define E_FAIL
Definition: ddrawi.h:102
WINE_DEFAULT_DEBUG_CHANNEL(quartz)
static HRESULT DSoundRender_SendSampleData(DSoundRenderImpl *This, REFERENCE_TIME tStart, REFERENCE_TIME tStop, const BYTE *data, DWORD size)
Definition: dsoundrender.c:264
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
static VOID WINAPI DSoundRender_OnStartStreaming(BaseRenderer *iface)
Definition: dsoundrender.c:449
IDirectSound8 * dsound
Definition: dsoundrender.c:61
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:651
static DWORD WINAPI DSoundAdviseThread(LPVOID lpParam)
Definition: dsoundrender.c:917
static HANDLE hEvent
Definition: comm.c:54
#define PM_NOREMOVE
Definition: winuser.h:1181
#define VFW_E_ALREADY_CONNECTED
Definition: vfwmsgs.h:43
#define IDirectSoundBuffer_GetCurrentPosition(p, a, b)
Definition: dsound.h:577
ULONG WINAPI BaseRendererImpl_Release(IBaseFilter *iface)
Definition: renderer.c:296
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
static HRESULT WINAPI AMDirectSound_ReleaseSecondaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer *buf)
#define WAVE_FORMAT_PCM
Definition: constants.h:425
unsigned char * LPBYTE
Definition: typedefs.h:52
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
static HRESULT WINAPI ReferenceClock_Unadvise(IReferenceClock *iface, DWORD_PTR dwAdviseCookie)
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
HRESULT WINAPI BaseRendererImpl_EndFlush(BaseRenderer *iface)
Definition: renderer.c:599
HRESULT WINAPI BaseRendererImpl_FindPin(IBaseFilter *iface, LPCWSTR Id, IPin **ppPin)
Definition: renderer.c:421
HRESULT WINAPI BaseFilterImpl_GetClassID(IBaseFilter *iface, CLSID *pClsid)
Definition: filter.c:77
time_t now
Definition: finger.c:65
static void FreeMediaType(AM_MEDIA_TYPE *pMediaType)
Definition: filtergraph.c:692
static HRESULT WINAPI DSoundRender_BeginFlush(BaseRenderer *iface)
Definition: dsoundrender.c:560
HRESULT WINAPI BaseRendererImpl_QueryInterface(IBaseFilter *iface, REFIID riid, LPVOID *ppv)
Definition: renderer.c:280
#define FIXME(fmt,...)
Definition: debug.h:110
HRESULT WINAPI BaseRenderer_Init(BaseRenderer *This, const IBaseFilterVtbl *Vtbl, IUnknown *pUnkOuter, const CLSID *pClsid, DWORD_PTR DebugInfo, const BaseRendererFuncTable *pBaseFuncsTable)
Definition: renderer.c:241
WORD wBitsPerSample
Definition: audioclient.idl:45
_In_ PCCERT_CONTEXT _In_opt_ LPFILETIME pTime
Definition: wincrypt.h:4840
#define S_FALSE
Definition: winerror.h:2357
static LONG cookie_counter
Definition: dsoundrender.c:915
static ULONG WINAPI ReferenceClock_AddRef(IReferenceClock *iface)
#define E_INVALIDARG
Definition: ddrawi.h:101
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:136
#define IDirectSoundBuffer_SetVolume(p, a)
Definition: dsound.h:588
smooth NULL
Definition: ftsmooth.c:416
HWND WINAPI GetDesktopWindow(void)
Definition: window.c:652
static HRESULT WINAPI Basicaudio_put_Volume(IBasicAudio *iface, LONG lVolume)
Definition: dsoundrender.c:831
static const IAMDirectSoundVtbl IAMDirectSound_Vtbl
Definition: dsoundrender.c:49
static DSoundRenderImpl * impl_from_IReferenceClock(IReferenceClock *iface)
Definition: dsoundrender.c:93
static ULONG WINAPI Basicaudio_Release(IBasicAudio *iface)
Definition: dsoundrender.c:822
static HRESULT WINAPI DSoundRender_PrepareReceive(BaseRenderer *iface, IMediaSample *pSample)
Definition: dsoundrender.c:324
#define debugstr_guid
Definition: kernel32.h:35
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
DWORD nSamplesPerSec
Definition: audioclient.idl:42
static HRESULT WINAPI DSoundRender_ShouldDrawSampleNow(BaseRenderer *This, IMediaSample *pMediaSample, REFERENCE_TIME *pStartTime, REFERENCE_TIME *pEndTime)
Definition: dsoundrender.c:317
#define DSBCAPS_GLOBALFOCUS
Definition: dsound.h:219
static HRESULT WINAPI ReferenceClock_QueryInterface(IReferenceClock *iface, REFIID riid, LPVOID *ppvObj)
Definition: dsoundrender.c:997
#define DS_OK
Definition: dsound.h:116
HRESULT WINAPI BaseFilterImpl_QueryVendorInfo(IBaseFilter *iface, LPWSTR *pVendorInfo)
Definition: filter.c:178
#define TRACE(s)
Definition: solgame.cpp:4
#define DSBCAPS_PRIMARYBUFFER
Definition: dsound.h:206
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define DSBPLAY_LOOPING
Definition: dsound.h:189
DWORD_PTR HSEMAPHORE
Definition: axcore.idl:60
if(!(yy_init))
Definition: macro.lex.yy.c:714
LONGLONG REFERENCE_TIME
Definition: dmusicks.h:9
DWORD dwSize
Definition: dsound.h:288
LONG HRESULT
Definition: typedefs.h:77
IAMDirectSound IAMDirectSound_iface
Definition: dsoundrender.c:58
#define WINAPI
Definition: msvc.h:8
static DSoundRenderImpl * impl_from_IAMDirectSound(IAMDirectSound *iface)
Definition: dsoundrender.c:98
static HRESULT WINAPI DSoundRender_DoRenderSample(BaseRenderer *iface, IMediaSample *pSample)
Definition: dsoundrender.c:359
static DSoundRenderImpl * impl_from_BaseRenderer(BaseRenderer *iface)
Definition: dsoundrender.c:78
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
static const IAMFilterMiscFlagsVtbl IAMFilterMiscFlags_Vtbl
Definition: dsoundrender.c:50
LPWAVEFORMATEX lpwfxFormat
Definition: dsound.h:292
HRESULT WINAPI BasicAudio_Destroy(BasicAudio *pBasicAudio)
Definition: audio.c:44
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static HRESULT CopyMediaType(AM_MEDIA_TYPE *pDest, const AM_MEDIA_TYPE *pSrc)
Definition: filtergraph.c:706
static HRESULT WINAPI AMDirectSound_GetSecondaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer **buf)
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define DSBPAN_RIGHT
Definition: dsound.h:228
DWORD WINAPI MsgWaitForMultipleObjects(_In_ DWORD nCount, _In_reads_opt_(nCount) CONST HANDLE *pHandles, _In_ BOOL fWaitAll, _In_ DWORD dwMilliseconds, _In_ DWORD dwWakeMask)
int ret
static HRESULT WINAPI AMDirectSound_GetFocusWindow(IAMDirectSound *iface, HWND *hwnd, BOOL *bgaudible)
#define DSBVOLUME_MIN
Definition: dsound.h:230
struct DSoundRenderImpl DSoundRenderImpl
#define VFW_E_TYPE_NOT_ACCEPTED
Definition: vfwmsgs.h:81
static HRESULT DSoundRender_GetWritePos(DSoundRenderImpl *This, DWORD *ret_writepos, REFERENCE_TIME write_at, DWORD *pfree, DWORD *skip)
Definition: dsoundrender.c:161
HRESULT WINAPI BaseRendererImpl_EndOfStream(BaseRenderer *iface)
Definition: renderer.c:567
#define IReferenceClock_GetTime(p, a)
Definition: dmusicc.h:754
#define IDirectSoundBuffer_SetFrequency(p, a)
Definition: dsound.h:590
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static VOID WINAPI DSoundRender_OnStopStreaming(BaseRenderer *iface)
Definition: dsoundrender.c:438
static HRESULT WINAPI ReferenceClock_AdvisePeriodic(IReferenceClock *iface, REFERENCE_TIME rtStartTime, REFERENCE_TIME rtPeriodTime, HSEMAPHORE hSemaphore, DWORD_PTR *pdwAdviseCookie)
unsigned char BYTE
Definition: mem.h:68
HRESULT WINAPI BaseRendererImpl_Run(IBaseFilter *iface, REFERENCE_TIME tStart)
Definition: renderer.c:461
#define WM_APP
Definition: eventvwr.h:70
#define CLASS_E_NOAGGREGATION
Definition: winerror.h:2662
HRESULT WINAPI BaseFilterImpl_EnumPins(IBaseFilter *iface, IEnumPins **ppEnum)
Definition: filter.c:135
static HRESULT WINAPI DSoundRender_CheckMediaType(BaseRenderer *iface, const AM_MEDIA_TYPE *pmt)
Definition: dsoundrender.c:416
uint32_t DWORD_PTR
Definition: typedefs.h:63
#define IDirectSoundBuffer_SetPan(p, a)
Definition: dsound.h:589
static ULONG WINAPI ReferenceClock_Release(IReferenceClock *iface)
static ULONG WINAPI Basicaudio_AddRef(IBasicAudio *iface)
Definition: dsoundrender.c:814
#define WM_USER
Definition: winuser.h:1877
struct IDirectSoundBuffer * LPDIRECTSOUNDBUFFER
Definition: dsound.h:76
#define IDirectSoundBuffer_Stop(p)
Definition: dsound.h:591
HRESULT WINAPI BasicAudioImpl_Invoke(IBasicAudio *iface, DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExepInfo, UINT *puArgErr)
Definition: audio.c:70
static HRESULT WINAPI DSoundRender_Pause(IBaseFilter *iface)
Definition: dsoundrender.c:754
#define ERR(fmt,...)
Definition: debug.h:109
HRESULT WINAPI BaseRendererImpl_Stop(IBaseFilter *iface)
Definition: renderer.c:440
IAMFilterMiscFlags IAMFilterMiscFlags_iface
Definition: dsoundrender.c:59
#define S_OK
Definition: intsafe.h:59
static unsigned __int64 next
Definition: rand_nt.c:6
#define InterlockedIncrement
Definition: armddk.h:53
static const IBaseFilterVtbl DSoundRender_Vtbl
Definition: dsoundrender.c:46
static HRESULT WINAPI Basicaudio_put_Balance(IBasicAudio *iface, LONG lBalance)
Definition: dsoundrender.c:862
static ULONG WINAPI DSoundRender_Release(IBaseFilter *iface)
Definition: dsoundrender.c:720
Definition: axcore.idl:91
DWORD nAvgBytesPerSec
Definition: audioclient.idl:43
#define DSBCAPS_CTRLFREQUENCY
Definition: dsound.h:211
#define E_NOTIMPL
Definition: ddrawi.h:99
#define QS_POSTMESSAGE
Definition: winuser.h:888
static HRESULT WINAPI DSoundRender_EndOfStream(BaseRenderer *iface)
Definition: dsoundrender.c:541
HRESULT WINAPI BasicAudioImpl_GetTypeInfo(IBasicAudio *iface, UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
Definition: audio.c:56
HRESULT WINAPI BaseFilterImpl_QueryFilterInfo(IBaseFilter *iface, FILTER_INFO *pInfo)
Definition: filter.c:145
#define min(a, b)
Definition: monoChain.cc:55
HRESULT WINAPI BaseRendererImpl_BeginFlush(BaseRenderer *iface)
Definition: renderer.c:590
struct _DSBUFFERDESC DSBUFFERDESC
static DSoundRenderImpl * impl_from_IBasicAudio(IBasicAudio *iface)
Definition: dsoundrender.c:88
HRESULT WINAPI BasicAudioImpl_GetIDsOfNames(IBasicAudio *iface, REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
Definition: audio.c:63
static ULONG WINAPI AMFilterMiscFlags_AddRef(IAMFilterMiscFlags *iface)
BOOL WINAPI GetMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT)
ULONG WINAPI BaseFilterImpl_AddRef(IBaseFilter *iface)
Definition: filter.c:54
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:714
HRESULT WINAPI BaseFilterImpl_GetSyncSource(IBaseFilter *iface, IReferenceClock **ppClock)
Definition: filter.c:119
static void DSoundRender_UpdatePositions(DSoundRenderImpl *This, DWORD *seqwritepos, DWORD *minwritepos)
Definition: dsoundrender.c:124
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:542
#define skip(...)
Definition: atltest.h:64
#define msg(x)
Definition: auth_time.c:54
static HRESULT WINAPI AMDirectSound_QueryInterface(IAMDirectSound *iface, REFIID riid, LPVOID *ppvObj)
#define IDirectSound8_CreateSoundBuffer(p, a, b, c)
Definition: dsound.h:509
HRESULT WINAPI BaseFilterImpl_JoinFilterGraph(IBaseFilter *iface, IFilterGraph *pGraph, LPCWSTR pName)
Definition: filter.c:159
DWORD dwBufferBytes
Definition: dsound.h:290
unsigned int ULONG
Definition: retypes.h:1
BaseRenderer renderer
Definition: dsoundrender.c:54
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
static HRESULT WINAPI AMDirectSound_ReleaseDirectSoundInterface(IAMDirectSound *iface, IDirectSound *ds)
static const IReferenceClockVtbl IReferenceClock_Vtbl
Definition: dsoundrender.c:48
struct dsoundrender_timer * next
Definition: dsoundrender.c:909
IReferenceClock IReferenceClock_iface
Definition: dsoundrender.c:57
BOOL WINAPI PeekMessageW(_Out_ LPMSG, _In_opt_ HWND, _In_ UINT, _In_ UINT, _In_ UINT)
static HRESULT WINAPI DSoundRender_EndFlush(BaseRenderer *iface)
Definition: dsoundrender.c:571
#define PM_REMOVE
Definition: winuser.h:1182
static HRESULT DSoundRender_HandleEndOfStream(DSoundRenderImpl *This)
Definition: dsoundrender.c:243
static ULONG WINAPI AMDirectSound_AddRef(IAMDirectSound *iface)
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
DWORD dwFlags
Definition: dsound.h:289
#define VFW_E_WRONG_STATE
Definition: vfwmsgs.h:78
static DSoundRenderImpl * impl_from_IBaseFilter(IBaseFilter *iface)
Definition: dsoundrender.c:83
static HRESULT WINAPI DSoundRender_CompleteConnect(BaseRenderer *iface, IPin *pReceivePin)
Definition: dsoundrender.c:467
#define E_POINTER
Definition: winerror.h:2365
#define IDirectSoundBuffer_Play(p, a, b, c)
Definition: dsound.h:585
#define INFINITE
Definition: serial.h:102
static const BaseRendererFuncTable BaseFuncTable
Definition: dsoundrender.c:596
#define IDirectSoundBuffer_Unlock(p, a, b, c, d)
Definition: dsound.h:592
#define memset(x, y, z)
Definition: compat.h:39
LPDIRECTSOUNDBUFFER dsbuffer
Definition: dsoundrender.c:62
#define DSSCL_PRIORITY
Definition: dsound.h:248
static ULONG WINAPI AMFilterMiscFlags_Release(IAMFilterMiscFlags *iface)
BOOL WINAPI PostThreadMessageW(_In_ DWORD, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
const GUID IID_IPin
Definition: pincontrol.cpp:15
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:406
#define LOWORD(l)
Definition: pedump.c:82
#define DSBLOCK_ENTIREBUFFER
Definition: dsound.h:204
#define HeapFree(x, y, z)
Definition: compat.h:394
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
REFERENCE_TIME start
Definition: dsoundrender.c:910
static ULONG WINAPI AMFilterMiscFlags_GetMiscFlags(IAMFilterMiscFlags *iface)
static HRESULT WINAPI ReferenceClock_GetTime(IReferenceClock *iface, REFERENCE_TIME *pTime)
static HRESULT WINAPI ReferenceClock_AdviseTime(IReferenceClock *iface, REFERENCE_TIME rtBaseTime, REFERENCE_TIME rtStreamTime, HEVENT hEvent, DWORD_PTR *pdwAdviseCookie)
#define SUCCEEDED(hr)
Definition: intsafe.h:57
static HRESULT WINAPI DSoundRender_QueryInterface(IBaseFilter *iface, REFIID riid, LPVOID *ppv)
Definition: dsoundrender.c:685
static HRESULT WINAPI AMDirectSound_GetDirectSoundInterface(IAMDirectSound *iface, IDirectSound **ds)
DWORD_PTR HEVENT
Definition: axcore.idl:61
static HRESULT WINAPI AMDirectSound_GetPrimaryBufferInterface(IAMDirectSound *iface, IDirectSoundBuffer **buf)