From d969fc65f88a18b61ba8551cb073e56f40460b1b Mon Sep 17 00:00:00 2001 From: "Carsten \"Tomcat\" Book" Date: Thu, 28 Nov 2013 09:06:42 +0100 Subject: [PATCH] Backed out changeset de7d74796ced (bug 923992) for frequent mochitest-1 orange on a CLOSED TREE --- media/libcubeb/README_MOZILLA | 2 +- media/libcubeb/src/cubeb_wasapi.cpp | 125 ++++++++++------------------ 2 files changed, 47 insertions(+), 80 deletions(-) diff --git a/media/libcubeb/README_MOZILLA b/media/libcubeb/README_MOZILLA index f9d69b1c54fe..28678f96ed46 100644 --- a/media/libcubeb/README_MOZILLA +++ b/media/libcubeb/README_MOZILLA @@ -5,4 +5,4 @@ Makefile.in build files for the Mozilla build system. The cubeb git repository is: git://github.com/kinetiknz/cubeb.git -The git commit ID used was 6ba033d2a3ebd10c1d4a2b9d2032c3675c9176ce. +The git commit ID used was 8c78a282aa0320e997436d6832024efe1527ca1c. diff --git a/media/libcubeb/src/cubeb_wasapi.cpp b/media/libcubeb/src/cubeb_wasapi.cpp index 79e565732fce..7ace6de8bf94 100644 --- a/media/libcubeb/src/cubeb_wasapi.cpp +++ b/media/libcubeb/src/cubeb_wasapi.cpp @@ -88,6 +88,7 @@ extern cubeb_ops const wasapi_ops; struct cubeb { cubeb_ops const * ops; + IMMDevice * device; /* Library dynamically opened to increase the render * thread priority, and the two function pointers we need. */ HMODULE mmcss_module; @@ -423,38 +424,13 @@ BOOL WINAPI revert_mm_thread_characteristics_noop(HANDLE mmcss_handle) { return true; } - -HRESULT get_default_endpoint(IMMDevice ** device) -{ - IMMDeviceEnumerator * enumerator; - HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), - NULL, CLSCTX_INPROC_SERVER, - IID_PPV_ARGS(&enumerator)); - if (FAILED(hr)) { - LOG("Could not get device enumerator."); - return hr; - } - /* eMultimedia is okay for now ("Music, movies, narration, [...]"). - * We will need to change this when we distinguish streams by use-case, other - * possible values being eConsole ("Games, system notification sounds [...]") - * and eCommunication ("Voice communication"). */ - hr = enumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, device); - if (FAILED(hr)) { - LOG("Could not get default audio endpoint."); - SafeRelease(enumerator); - return hr; - } - - SafeRelease(enumerator); - - return ERROR_SUCCESS; -} } // namespace anonymous extern "C" { int wasapi_init(cubeb ** context, char const * context_name) { HRESULT hr; + IMMDeviceEnumerator * enumerator = NULL; hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); if (FAILED(hr)) { @@ -466,6 +442,29 @@ int wasapi_init(cubeb ** context, char const * context_name) ctx->ops = &wasapi_ops; + hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), + NULL, CLSCTX_INPROC_SERVER, + IID_PPV_ARGS(&enumerator)); + if (FAILED(hr)) { + LOG("Could not get device enumerator."); + wasapi_destroy(ctx); + return CUBEB_ERROR; + } + + /* eMultimedia is okay for now ("Music, movies, narration, [...]"). + * We will need to change this when we distinguish streams by use-case, other + * possible values being eConsole ("Games, system notification sounds [...]") + * and eCommunication ("Voice communication"). */ + hr = enumerator->GetDefaultAudioEndpoint(eRender, + eMultimedia, + &ctx->device); + if (FAILED(hr)) { + LOG("Could not get default audio endpoint."); + SafeRelease(enumerator); + wasapi_destroy(ctx); + return CUBEB_ERROR; + } + ctx->mmcss_module = LoadLibraryA("Avrt.dll"); if (ctx->mmcss_module) { @@ -486,6 +485,8 @@ int wasapi_init(cubeb ** context, char const * context_name) ctx->set_mm_thread_characteristics = &set_mm_thread_characteristics_noop; ctx->revert_mm_thread_characteristics = &revert_mm_thread_characteristics_noop; } + + SafeRelease(enumerator); *context = ctx; @@ -497,6 +498,7 @@ namespace { void wasapi_destroy(cubeb * context) { + SafeRelease(context->device); if (context->mmcss_module) { FreeLibrary(context->mmcss_module); } @@ -511,28 +513,21 @@ char const* wasapi_get_backend_id(cubeb * context) int wasapi_get_max_channel_count(cubeb * ctx, uint32_t * max_channels) { + HRESULT hr; IAudioClient * client; WAVEFORMATEX * mix_format; assert(ctx && max_channels); - IMMDevice * device; - HRESULT hr = get_default_endpoint(&device); - if (FAILED(hr)) { - return CUBEB_ERROR; - } - - hr = device->Activate(__uuidof(IAudioClient), - CLSCTX_INPROC_SERVER, - NULL, (void **)&client); - SafeRelease(device); + hr = ctx->device->Activate(__uuidof(IAudioClient), + CLSCTX_INPROC_SERVER, + NULL, (void **)&client); if (FAILED(hr)) { return CUBEB_ERROR; } hr = client->GetMixFormat(&mix_format); if (FAILED(hr)) { - SafeRelease(client); return CUBEB_ERROR; } @@ -551,26 +546,16 @@ wasapi_get_min_latency(cubeb * ctx, cubeb_stream_params params, uint32_t * laten IAudioClient * client; REFERENCE_TIME default_period; - IMMDevice * device; - hr = get_default_endpoint(&device); - if (FAILED(hr)) { - return CUBEB_ERROR; - } + hr = ctx->device->Activate(__uuidof(IAudioClient), + CLSCTX_INPROC_SERVER, + NULL, (void **)&client); - hr = device->Activate(__uuidof(IAudioClient), - CLSCTX_INPROC_SERVER, - NULL, (void **)&client); - SafeRelease(device); if (FAILED(hr)) { return CUBEB_ERROR; } /* The second parameter is for exclusive mode, that we don't use. */ - hr = client->GetDevicePeriod(&default_period, NULL); - if (FAILED(hr)) { - SafeRelease(client); - return CUBEB_ERROR; - } + hr= client->GetDevicePeriod(&default_period, NULL); /* According to the docs, the best latency we can achieve is by synchronizing * the stream and the engine. @@ -589,21 +574,16 @@ wasapi_get_preferred_sample_rate(cubeb * ctx, uint32_t * rate) IAudioClient * client; WAVEFORMATEX * mix_format; - IMMDevice * device; - hr = get_default_endpoint(&device); - if (FAILED(hr)) { - return CUBEB_ERROR; - }; + hr = ctx->device->Activate(__uuidof(IAudioClient), + CLSCTX_INPROC_SERVER, + NULL, (void **)&client); - hr = device->Activate(__uuidof(IAudioClient), - CLSCTX_INPROC_SERVER, - NULL, (void **)&client); - SafeRelease(device); if (FAILED(hr)) { return CUBEB_ERROR; } hr = client->GetMixFormat(&mix_format); + if (FAILED(hr)) { SafeRelease(client); return CUBEB_ERROR; @@ -731,19 +711,11 @@ wasapi_stream_init(cubeb * context, cubeb_stream ** stream, return CUBEB_ERROR; } - IMMDevice * device; - hr = get_default_endpoint(&device); - if (FAILED(hr)) { - wasapi_stream_destroy(stm); - return CUBEB_ERROR; - } - /* Get a client. We will get all other interfaces we need from * this pointer. */ - hr = device->Activate(__uuidof(IAudioClient), - CLSCTX_INPROC_SERVER, - NULL, (void **)&stm->client); - SafeRelease(device); + hr = context->device->Activate(__uuidof(IAudioClient), + CLSCTX_INPROC_SERVER, + NULL, (void **)&stm->client); if (FAILED(hr)) { LOG("Could not activate the device to get an audio client."); wasapi_stream_destroy(stm); @@ -752,12 +724,7 @@ wasapi_stream_init(cubeb * context, cubeb_stream ** stream, /* We have to distinguish between the format the mixer uses, * and the format the stream we want to play uses. */ - hr = stm->client->GetMixFormat(&mix_format); - if (FAILED(hr)) { - LOG("Could not fetch current mix format from the audio client."); - wasapi_stream_destroy(stm); - return CUBEB_ERROR; - } + stm->client->GetMixFormat(&mix_format); handle_channel_layout(stm, &mix_format, &stream_params); @@ -843,7 +810,7 @@ wasapi_stream_init(cubeb * context, cubeb_stream ** stream, } hr = stm->client->GetService(__uuidof(IAudioRenderClient), - (void **)&stm->render_client); + (void **)&stm->render_client); if (FAILED(hr)) { LOG("Could not get the render client."); wasapi_stream_destroy(stm); @@ -851,7 +818,7 @@ wasapi_stream_init(cubeb * context, cubeb_stream ** stream, } hr = stm->client->GetService(__uuidof(IAudioClock), - (void **)&stm->audio_clock); + (void **)&stm->audio_clock); if (FAILED(hr)) { LOG("Could not get the IAudioClock."); wasapi_stream_destroy(stm);