Backed out 2 changesets (bug 1828894) for cubeb related bp-hybrid bustages. CLOSED TREE

Backed out changeset 3200eba0be97 (bug 1828894)
Backed out changeset 6426d03a45ce (bug 1828894)
This commit is contained in:
Stanca Serban 2023-04-20 02:23:35 +03:00
Родитель 4ea1fca123
Коммит 2c574db450
4 изменённых файлов: 26 добавлений и 72 удалений

Просмотреть файл

@ -1,3 +1,13 @@
# HG changeset patch
# User Paul Adenot <paul@paul.cx>
# Date 1675704257 -3600
# Mon Feb 06 18:24:17 2023 +0100
# Node ID af331fb1ade15fff3f042f7881c12fdca6d86349
# Parent 56d3f31673a0d096e34564b0734d202a89d2ba47
Bug 1812120 - Disable the AAudio backend when running on Android <= 30. r?kinetik
Differential Revision: https://phabricator.services.mozilla.com/D168979
diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp
--- a/src/cubeb_aaudio.cpp --- a/src/cubeb_aaudio.cpp
+++ b/src/cubeb_aaudio.cpp +++ b/src/cubeb_aaudio.cpp
@ -15,11 +25,11 @@ diff --git a/src/cubeb_aaudio.cpp b/src/cubeb_aaudio.cpp
#include <cassert> #include <cassert>
#include <chrono> #include <chrono>
#include <condition_variable> #include <condition_variable>
#include <cstdint>
#include <cstring> #include <cstring>
#include <dlfcn.h> #include <dlfcn.h>
#include <inttypes.h> #include <memory>
@@ -1600,16 +1601,19 @@ const static struct cubeb_ops aaudio_ops #include <mutex>
@@ -1544,16 +1545,19 @@ const static struct cubeb_ops aaudio_ops
/*.stream_get_current_device =*/NULL, /*.stream_get_current_device =*/NULL,
/*.stream_device_destroy =*/NULL, /*.stream_device_destroy =*/NULL,
/*.stream_register_device_changed_callback =*/NULL, /*.stream_register_device_changed_callback =*/NULL,

Просмотреть файл

@ -9,8 +9,8 @@ origin:
description: "Cross platform audio library" description: "Cross platform audio library"
url: https://github.com/mozilla/cubeb url: https://github.com/mozilla/cubeb
license: ISC license: ISC
release: 479f8c5dec2c31ced12dbc4c64ff86ffb4ed50b7 (2023-04-19T11:37:43Z). release: 2071354a69aca7ed6df3b4222e305746c2113f60 (2023-03-21T20:02:06Z).
revision: 479f8c5dec2c31ced12dbc4c64ff86ffb4ed50b7 revision: 2071354a69aca7ed6df3b4222e305746c2113f60
vendoring: vendoring:
url: https://github.com/mozilla/cubeb url: https://github.com/mozilla/cubeb

Просмотреть файл

@ -16,10 +16,8 @@
#include <cassert> #include <cassert>
#include <chrono> #include <chrono>
#include <condition_variable> #include <condition_variable>
#include <cstdint>
#include <cstring> #include <cstring>
#include <dlfcn.h> #include <dlfcn.h>
#include <inttypes.h>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <thread> #include <thread>
@ -103,7 +101,6 @@ LIBAAUDIO_API_VISIT(MAKE_TYPEDEF)
#endif #endif
const uint8_t MAX_STREAMS = 16; const uint8_t MAX_STREAMS = 16;
const int64_t NS_PER_S = static_cast<int64_t>(1e9);
using unique_lock = std::unique_lock<std::mutex>; using unique_lock = std::unique_lock<std::mutex>;
using lock_guard = std::lock_guard<std::mutex>; using lock_guard = std::lock_guard<std::mutex>;
@ -138,7 +135,6 @@ struct cubeb_stream {
std::atomic<bool> in_use{false}; std::atomic<bool> in_use{false};
std::atomic<bool> latency_metrics_available{false}; std::atomic<bool> latency_metrics_available{false};
std::atomic<stream_state> state{stream_state::INIT}; std::atomic<stream_state> state{stream_state::INIT};
std::atomic<bool> in_data_callback{false};
triple_buffer<AAudioTimingInfo> timing_info; triple_buffer<AAudioTimingInfo> timing_info;
AAudioStream * ostream{}; AAudioStream * ostream{};
@ -184,47 +180,9 @@ struct cubeb {
struct cubeb_stream streams[MAX_STREAMS]; struct cubeb_stream streams[MAX_STREAMS];
}; };
struct AutoInCallback {
AutoInCallback(cubeb_stream * stm) : stm(stm)
{
stm->in_data_callback.store(true);
}
~AutoInCallback() { stm->in_data_callback.store(false); }
cubeb_stream * stm;
};
// Returns when aaudio_stream's state is equal to desired_state.
// poll_frequency_ns is the duration that is slept in between asking for
// state updates and getting the new state.
// When waiting for a stream to stop, it is best to pick a value similar
// to the callback time because STOPPED will happen after
// draining.
static int
wait_for_state_change(AAudioStream * aaudio_stream,
aaudio_stream_state_t desired_state,
int64_t poll_frequency_ns)
{
aaudio_stream_state_t new_state;
do {
aaudio_result_t res = WRAP(AAudioStream_waitForStateChange)(
aaudio_stream, AAUDIO_STREAM_STATE_UNKNOWN, &new_state,
poll_frequency_ns);
if (res != AAUDIO_OK) {
LOG("AAudioStream_waitForStateChanged: %s",
WRAP(AAudio_convertResultToText)(res));
return CUBEB_ERROR;
}
} while (new_state != desired_state);
LOG("wait_for_state_change: current state now: %s",
cubeb_AAudio_convertStreamStateToText(new_state));
return CUBEB_OK;
}
// Only allowed from state thread, while mutex on stm is locked // Only allowed from state thread, while mutex on stm is locked
static void static void
shutdown_with_error(cubeb_stream * stm) shutdown(cubeb_stream * stm)
{ {
if (stm->istream) { if (stm->istream) {
WRAP(AAudioStream_requestStop)(stm->istream); WRAP(AAudioStream_requestStop)(stm->istream);
@ -233,17 +191,6 @@ shutdown_with_error(cubeb_stream * stm)
WRAP(AAudioStream_requestStop)(stm->ostream); WRAP(AAudioStream_requestStop)(stm->ostream);
} }
int64_t poll_frequency_ns = NS_PER_S * stm->out_frame_size / stm->sample_rate;
if (stm->istream) {
wait_for_state_change(stm->istream, AAUDIO_STREAM_STATE_STOPPED,
poll_frequency_ns);
}
if (stm->ostream) {
wait_for_state_change(stm->ostream, AAUDIO_STREAM_STATE_STOPPED,
poll_frequency_ns);
}
assert(!stm->in_data_callback.load());
stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_ERROR); stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_ERROR);
stm->state.store(stream_state::SHUTDOWN); stm->state.store(stream_state::SHUTDOWN);
} }
@ -301,7 +248,7 @@ update_state(cubeb_stream * stm)
} }
if (old_state == stream_state::ERROR) { if (old_state == stream_state::ERROR) {
shutdown_with_error(stm); shutdown(stm);
return; return;
} }
@ -346,7 +293,7 @@ update_state(cubeb_stream * stm)
istate == AAUDIO_STREAM_STATE_DISCONNECTED) { istate == AAUDIO_STREAM_STATE_DISCONNECTED) {
LOG("Unexpected android input stream state %s", LOG("Unexpected android input stream state %s",
WRAP(AAudio_convertStreamStateToText)(istate)); WRAP(AAudio_convertStreamStateToText)(istate));
shutdown_with_error(stm); shutdown(stm);
return; return;
} }
@ -358,7 +305,7 @@ update_state(cubeb_stream * stm)
ostate == AAUDIO_STREAM_STATE_DISCONNECTED) { ostate == AAUDIO_STREAM_STATE_DISCONNECTED) {
LOG("Unexpected android output stream state %s", LOG("Unexpected android output stream state %s",
WRAP(AAudio_convertStreamStateToText)(istate)); WRAP(AAudio_convertStreamStateToText)(istate));
shutdown_with_error(stm); shutdown(stm);
return; return;
} }
@ -665,7 +612,6 @@ aaudio_duplex_data_cb(AAudioStream * astream, void * user_data,
void * audio_data, int32_t num_frames) void * audio_data, int32_t num_frames)
{ {
cubeb_stream * stm = (cubeb_stream *)user_data; cubeb_stream * stm = (cubeb_stream *)user_data;
AutoInCallback aic(stm);
assert(stm->ostream == astream); assert(stm->ostream == astream);
assert(stm->istream); assert(stm->istream);
assert(num_frames >= 0); assert(num_frames >= 0);
@ -747,7 +693,6 @@ aaudio_output_data_cb(AAudioStream * astream, void * user_data,
void * audio_data, int32_t num_frames) void * audio_data, int32_t num_frames)
{ {
cubeb_stream * stm = (cubeb_stream *)user_data; cubeb_stream * stm = (cubeb_stream *)user_data;
AutoInCallback aic(stm);
assert(stm->ostream == astream); assert(stm->ostream == astream);
assert(!stm->istream); assert(!stm->istream);
assert(num_frames >= 0); assert(num_frames >= 0);
@ -796,7 +741,6 @@ aaudio_input_data_cb(AAudioStream * astream, void * user_data,
void * audio_data, int32_t num_frames) void * audio_data, int32_t num_frames)
{ {
cubeb_stream * stm = (cubeb_stream *)user_data; cubeb_stream * stm = (cubeb_stream *)user_data;
AutoInCallback aic(stm);
assert(stm->istream == astream); assert(stm->istream == astream);
assert(!stm->ostream); assert(!stm->ostream);
assert(num_frames >= 0); assert(num_frames >= 0);
@ -1263,8 +1207,8 @@ aaudio_stream_start(cubeb_stream * stm)
break; break;
// If the state switched [DRAINING -> STOPPING] or [DRAINING/STOPPING -> // If the state switched [DRAINING -> STOPPING] or [DRAINING/STOPPING ->
// STOPPED] in the meantime, we can simply overwrite that since we // STOPPED] in the meantime, we can simply overwrite that since we restarted
// restarted the stream. // the stream.
case stream_state::STOPPING: case stream_state::STOPPING:
case stream_state::STOPPED: case stream_state::STOPPED:
continue; continue;
@ -1442,7 +1386,7 @@ aaudio_stream_get_position(cubeb_stream * stm, uint64_t * position)
stm->previous_clock = *position; stm->previous_clock = *position;
} }
LOG("aaudio_stream_get_position: %" PRIu64 " frames", *position); LOG("aaudio_stream_get_position: %ld", *position);
return CUBEB_OK; return CUBEB_OK;
} }

Просмотреть файл

@ -28,7 +28,7 @@ ARRAY_LENGTH(T(&)[N])
return N; return N;
} }
void delay(unsigned int ms) inline void delay(unsigned int ms)
{ {
#if defined(_WIN32) #if defined(_WIN32)
Sleep(ms); Sleep(ms);
@ -48,7 +48,7 @@ typedef struct {
uint32_t const layout; uint32_t const layout;
} layout_info; } layout_info;
int has_available_input_device(cubeb * ctx) inline int has_available_input_device(cubeb * ctx)
{ {
cubeb_device_collection devices; cubeb_device_collection devices;
int input_device_available = 0; int input_device_available = 0;
@ -80,7 +80,7 @@ int has_available_input_device(cubeb * ctx)
return !!input_device_available; return !!input_device_available;
} }
void print_log(const char * msg, ...) inline void print_log(const char * msg, ...)
{ {
va_list args; va_list args;
va_start(args, msg); va_start(args, msg);
@ -91,7 +91,7 @@ void print_log(const char * msg, ...)
/** Initialize cubeb with backend override. /** Initialize cubeb with backend override.
* Create call cubeb_init passing value for CUBEB_BACKEND env var as * Create call cubeb_init passing value for CUBEB_BACKEND env var as
* override. */ * override. */
int common_init(cubeb ** ctx, char const * ctx_name) inline int common_init(cubeb ** ctx, char const * ctx_name)
{ {
#ifdef ENABLE_NORMAL_LOG #ifdef ENABLE_NORMAL_LOG
if (cubeb_set_log_callback(CUBEB_LOG_NORMAL, print_log) != CUBEB_OK) { if (cubeb_set_log_callback(CUBEB_LOG_NORMAL, print_log) != CUBEB_OK) {