diff options
author | Paul Adenot <[email protected]> | 2020-09-02 16:34:22 +0200 |
---|---|---|
committer | Paul Adenot <[email protected]> | 2020-09-09 14:30:03 +0200 |
commit | c7fe95cca45df46fcce87b47326e96934b213865 (patch) | |
tree | 45a86d27c0e9b078bbb373e59ecb70a61e4f7d94 | |
parent | 2c08cb6b578432c740d055b5a09d5b595cf05752 (diff) | |
download | cubeb-c7fe95cca45df46fcce87b47326e96934b213865.tar.gz cubeb-c7fe95cca45df46fcce87b47326e96934b213865.zip |
Only perform device matching when using a bluetooth handsfree device
-rw-r--r-- | src/cubeb_wasapi.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/cubeb_wasapi.cpp b/src/cubeb_wasapi.cpp index 2c84ce2..b8ab887 100644 --- a/src/cubeb_wasapi.cpp +++ b/src/cubeb_wasapi.cpp @@ -193,6 +193,7 @@ int wasapi_stream_start(cubeb_stream * stm); void close_wasapi_stream(cubeb_stream * stm); int setup_wasapi_stream(cubeb_stream * stm); ERole pref_to_role(cubeb_stream_prefs param); +int wasapi_create_device(cubeb * ctx, cubeb_device_info& ret, IMMDeviceEnumerator * enumerator, IMMDevice * dev); static int wasapi_enumerate_devices(cubeb * context, cubeb_device_type type, cubeb_device_collection * out); static int wasapi_device_collection_destroy(cubeb * ctx, cubeb_device_collection * collection); static char const * wstr_to_utf8(wchar_t const * str); @@ -247,7 +248,10 @@ struct cubeb_stream { cubeb_stream_params output_stream_params = { CUBEB_SAMPLE_FLOAT32NE, 0, 0, CUBEB_LAYOUT_UNDEFINED, CUBEB_STREAM_PREF_NONE }; /* A MMDevice role for this stream: either communication or console here. */ ERole role; + /* True if this stream will transport voice-data. */ bool voice; + /* True if the input device of this stream is using bluetooth handsfree. */ + bool input_bluetooth_handsfree; /* The input and output device, or NULL for default. */ std::unique_ptr<const wchar_t[]> input_device_id; std::unique_ptr<const wchar_t[]> output_device_id; @@ -2053,8 +2057,10 @@ int setup_wasapi_stream_one_side(cubeb_stream * stm, // Rather high-latency to prevent constant under-runs in this particular // case of an input device using bluetooth handsfree. latency = default_period * 4; + stm->input_bluetooth_handsfree = true; } else { latency = std::max(latency, minimum_period); + stm->input_bluetooth_handsfree = false; } #if 0 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1590902 @@ -2109,6 +2115,12 @@ void wasapi_find_matching_output_device(cubeb_stream * stm) { cubeb_device_info * input_device; cubeb_device_collection collection; + // Only try to match to an output device if the input device is a bluetooth + // device that is using the handsfree protocol + if (!stm->input_bluetooth_handsfree) { + return; + } + wchar_t * tmp = nullptr; hr = stm->input_device->GetId(&tmp); if (FAILED(hr)) { @@ -2121,7 +2133,6 @@ void wasapi_find_matching_output_device(cubeb_stream * stm) { return; } - int rv = wasapi_enumerate_devices(stm->context, (cubeb_device_type)(CUBEB_DEVICE_TYPE_INPUT|CUBEB_DEVICE_TYPE_OUTPUT), &collection); // Find the input device, and then find the output device with the same group @@ -2375,8 +2386,8 @@ wasapi_stream_init(cubeb * context, cubeb_stream ** stream, stm->data_callback = data_callback; stm->state_callback = state_callback; stm->user_ptr = user_ptr; - stm->role = eConsole; + stm->input_bluetooth_handsfree = false; HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, |