From bef5c89593089340290985cdae4678bb9778bc4f Mon Sep 17 00:00:00 2001 From: Paul Adenot Date: Mon, 7 Dec 2020 08:53:50 +0000 Subject: [PATCH] Bug 1681024 - Update libcubeb to revision 85f1cf4. r=cubeb-reviewers,kinetik Differential Revision: https://phabricator.services.mozilla.com/D98878 --- media/libcubeb/moz.yaml | 2 +- media/libcubeb/src/cubeb_aaudio.cpp | 25 ++++++++++++++++++++----- media/libcubeb/src/cubeb_wasapi.cpp | 17 +++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/media/libcubeb/moz.yaml b/media/libcubeb/moz.yaml index 678d312c06f2..c90f95e09a0a 100644 --- a/media/libcubeb/moz.yaml +++ b/media/libcubeb/moz.yaml @@ -19,5 +19,5 @@ origin: license: "ISC" # update.sh will update this value - release: "5c2cf26778af7f2c857870f6bb2c35755f3c1d54 (2020-12-01 14:05:01 +0000)" + release: "85f1cf48dffd749dd32798681955155e1a1a6ff5 (2020-12-07 08:11:33 +0000)" diff --git a/media/libcubeb/src/cubeb_aaudio.cpp b/media/libcubeb/src/cubeb_aaudio.cpp index 998f895e425f..f00f228a6bea 100644 --- a/media/libcubeb/src/cubeb_aaudio.cpp +++ b/media/libcubeb/src/cubeb_aaudio.cpp @@ -130,6 +130,7 @@ struct cubeb_stream { int64_t latest_input_latency = 0; bool voice_input; bool voice_output; + uint64_t previous_clock; }; struct cubeb { @@ -998,6 +999,7 @@ aaudio_stream_init(cubeb * ctx, cubeb_stream ** stream, stm->state_callback = state_callback; stm->voice_input = input_stream_params && !!(input_stream_params->prefs & CUBEB_STREAM_PREF_VOICE); stm->voice_output = output_stream_params && !!(output_stream_params->prefs & CUBEB_STREAM_PREF_VOICE); + stm->previous_clock = 0; LOG("cubeb stream prefs: voice_input: %s voice_output: %s", stm->voice_input ? "true" : "false", @@ -1238,6 +1240,11 @@ aaudio_stream_get_position(cubeb_stream * stm, uint64_t * position) // getTimestamp is only valid when the stream is playing. // Simply return the number of frames passed to aaudio *position = WRAP(AAudioStream_getFramesRead)(stream); + if (*position < stm->previous_clock) { + *position = stm->previous_clock; + } else { + stm->previous_clock = *position; + } return CUBEB_OK; case stream_state::INIT: assert(false && "Invalid stream"); @@ -1252,12 +1259,15 @@ aaudio_stream_get_position(cubeb_stream * stm, uint64_t * position) aaudio_result_t res; res = WRAP(AAudioStream_getTimestamp)(stream, CLOCK_MONOTONIC, &pos, &ns); if (res != AAUDIO_OK) { - // when we are in 'STARTING' state we try it and hope that the stream - // has internally started and gives us a valid timestamp. - // If that is not the case (invalid_state is returned) we simply - // fall back to the method we use for non-playing streams. - if (res == AAUDIO_ERROR_INVALID_STATE && state == stream_state::STARTING) { + // When the audio stream is not running, invalid_state is returned and we + // simply fall back to the method we use for non-playing streams. + if (res == AAUDIO_ERROR_INVALID_STATE) { *position = WRAP(AAudioStream_getFramesRead)(stream); + if (*position < stm->previous_clock) { + *position = stm->previous_clock; + } else { + stm->previous_clock = *position; + } return CUBEB_OK; } @@ -1266,6 +1276,11 @@ aaudio_stream_get_position(cubeb_stream * stm, uint64_t * position) } *position = pos; + if (*position < stm->previous_clock) { + *position = stm->previous_clock; + } else { + stm->previous_clock = *position; + } return CUBEB_OK; } diff --git a/media/libcubeb/src/cubeb_wasapi.cpp b/media/libcubeb/src/cubeb_wasapi.cpp index 5aea0a5a5bfb..30a6d06c7e20 100644 --- a/media/libcubeb/src/cubeb_wasapi.cpp +++ b/media/libcubeb/src/cubeb_wasapi.cpp @@ -2030,6 +2030,23 @@ int setup_wasapi_stream_one_side(cubeb_stream * stm, com_heap_ptr mix_format(tmp); mix_format->wBitsPerSample = stm->bytes_per_sample * 8; + if (mix_format->wFormatTag == WAVE_FORMAT_PCM || + mix_format->wFormatTag == WAVE_FORMAT_IEEE_FLOAT) { + switch (mix_format->wBitsPerSample) { + case 8: + case 16: + mix_format->wFormatTag = WAVE_FORMAT_PCM; + break; + case 32: + mix_format->wFormatTag = WAVE_FORMAT_IEEE_FLOAT; + break; + default: + LOG("%u bits per sample is incompatible with PCM wave formats", + mix_format->wBitsPerSample); + return CUBEB_ERROR; + } + } + if (mix_format->wFormatTag == WAVE_FORMAT_EXTENSIBLE) { WAVEFORMATEXTENSIBLE * format_pcm = reinterpret_cast(mix_format.get()); format_pcm->SubFormat = stm->waveformatextensible_sub_format;