@@ -617,9 +617,19 @@ refill(cubeb_stream * stm, void * input_buffer, long input_frames_count,
617617
618618int wasapi_stream_reset_default_device (cubeb_stream * stm);
619619
620+ /* Helper for making get_input_buffer work in exclusive mode */
621+ HRESULT get_next_packet_size (cubeb_stream * stm, PUINT32 next)
622+ {
623+ if (stm->input_stream_params .prefs & CUBEB_STREAM_PREF_EXCLUSIVE) {
624+ return stm->input_buffer_frame_count ;
625+ } else {
626+ return stm->capture_client ->GetNextPacketSize (next);
627+ }
628+ }
629+
620630/* This helper grabs all the frames available from a capture client, put them in
621631 * linear_input_buffer. linear_input_buffer should be cleared before the
622- * callback exits. This helper does not work with exclusive mode streams. */
632+ * callback exits. */
623633bool get_input_buffer (cubeb_stream * stm)
624634{
625635 XASSERT (has_input (stm));
@@ -636,9 +646,9 @@ bool get_input_buffer(cubeb_stream * stm)
636646 // single packet each time. However, if we're pulling from the stream we may
637647 // need to grab multiple packets worth of frames that have accumulated (so
638648 // need a loop).
639- for (hr = stm-> capture_client -> GetNextPacketSize ( &next);
649+ for (hr = get_next_packet_size (stm, &next);
640650 next > 0 ;
641- hr = stm-> capture_client -> GetNextPacketSize ( &next)) {
651+ hr = get_next_packet_size (stm, &next)) {
642652 if (hr == AUDCLNT_E_DEVICE_INVALIDATED) {
643653 // Application can recover from this error. More info
644654 // https://msdn.microsoft.com/en-us/library/windows/desktop/dd316605(v=vs.85).aspx
@@ -705,6 +715,9 @@ bool get_input_buffer(cubeb_stream * stm)
705715 return false ;
706716 }
707717 offset += packet_size;
718+
719+ if (stm->input_stream_params .prefs & CUBEB_STREAM_PREF_EXCLUSIVE)
720+ break ;
708721 }
709722
710723 XASSERT (stm->linear_input_buffer ->length () >= offset);
@@ -1395,8 +1408,11 @@ wasapi_get_min_latency(cubeb * ctx, cubeb_stream_params params, uint32_t * laten
13951408 return CUBEB_ERROR;
13961409 }
13971410
1398- /* The second parameter is for exclusive mode, that we don't use. */
1399- hr = client->GetDevicePeriod (&default_period, NULL );
1411+ if (params.prefs & CUBEB_STREAM_PREF_EXCLUSIVE)
1412+ hr = client->GetDevicePeriod (NULL , &default_period);
1413+ else
1414+ hr = client->GetDevicePeriod (&default_period, NULL );
1415+
14001416 if (FAILED (hr)) {
14011417 LOG (" Could not get device period: %lx" , hr);
14021418 return CUBEB_ERROR;
@@ -1531,7 +1547,7 @@ handle_channel_layout(cubeb_stream * stm, EDataFlow direction, com_heap_ptr<WAV
15311547
15321548 /* Check if wasapi will accept our channel layout request. */
15331549 WAVEFORMATEX * closest;
1534- HRESULT hr = audio_client->IsFormatSupported (AUDCLNT_SHAREMODE_SHARED,
1550+ HRESULT hr = audio_client->IsFormatSupported (stream_params-> prefs & CUBEB_STREAM_PREF_EXCLUSIVE ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
15351551 mix_format.get (),
15361552 &closest);
15371553 if (hr == S_FALSE) {
@@ -1665,6 +1681,13 @@ int setup_wasapi_stream_one_side(cubeb_stream * stm,
16651681 // audio according to layout.
16661682 LOG (" Channel count is different from the layout standard!\n " );
16671683 }
1684+
1685+
1686+ if (stream_params->prefs & CUBEB_STREAM_PREF_EXCLUSIVE)
1687+ LOG (" Setup requested=[f=%d r=%u c=%u] mix=[f=%d r=%u c=%u]" ,
1688+ stream_params->format , stream_params->rate , stream_params->channels ,
1689+ mix_params->format , mix_params->rate , mix_params->channels );
1690+ else
16681691 LOG (" Setup requested=[f=%d r=%u c=%u l=%s] mix=[f=%d r=%u c=%u l=%s]" ,
16691692 stream_params->format , stream_params->rate , stream_params->channels ,
16701693 CUBEB_CHANNEL_LAYOUT_MAPS[stream_params->layout ].name ,
@@ -1681,7 +1704,7 @@ int setup_wasapi_stream_one_side(cubeb_stream * stm,
16811704 flags |= AUDCLNT_STREAMFLAGS_EVENTCALLBACK;
16821705 }
16831706
1684- hr = audio_client->Initialize (AUDCLNT_SHAREMODE_SHARED,
1707+ hr = audio_client->Initialize (stream_params-> prefs & CUBEB_STREAM_PREF_EXCLUSIVE ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
16851708 flags,
16861709 frames_to_hns (stm, stm->latency ),
16871710 0 ,
0 commit comments