зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1410456 - remove preferred sample rate implementation because makes use of dlopen. r=padenot
MozReview-Commit-ID: jBZ3oewbjh --HG-- extra : rebase_source : e983510c4c3e2e046302ea3c0732b25a0cfd2cb1
This commit is contained in:
Родитель
b3ae975aa1
Коммит
2b7cbda791
|
@ -154,7 +154,7 @@ struct cubeb_stream {
|
|||
cubeb_state_callback state_callback;
|
||||
|
||||
cubeb_resampler * resampler;
|
||||
unsigned int inputrate;
|
||||
unsigned int user_output_rate;
|
||||
unsigned int output_configured_rate;
|
||||
unsigned int latency_frames;
|
||||
int64_t lastPosition;
|
||||
|
@ -784,66 +784,6 @@ opensl_get_max_channel_count(cubeb * ctx, uint32_t * max_channels)
|
|||
return CUBEB_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
opensl_get_preferred_sample_rate(cubeb * ctx, uint32_t * rate)
|
||||
{
|
||||
/* https://android.googlesource.com/platform/ndk.git/+/master/docs/opensles/index.html
|
||||
* We don't want to deal with JNI here (and we don't have Java on b2g anyways),
|
||||
* so we just dlopen the library and get the two symbols we need. */
|
||||
int r;
|
||||
void * libmedia;
|
||||
uint32_t (*get_primary_output_samplingrate)();
|
||||
uint32_t (*get_output_samplingrate)(int * samplingRate, int streamType);
|
||||
|
||||
libmedia = dlopen("libmedia.so", RTLD_LAZY);
|
||||
if (!libmedia) {
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
/* uint32_t AudioSystem::getPrimaryOutputSamplingRate(void) */
|
||||
get_primary_output_samplingrate =
|
||||
dlsym(libmedia, "_ZN7android11AudioSystem28getPrimaryOutputSamplingRateEv");
|
||||
if (!get_primary_output_samplingrate) {
|
||||
/* fallback to
|
||||
* status_t AudioSystem::getOutputSamplingRate(int* samplingRate, int streamType)
|
||||
* if we cannot find getPrimaryOutputSamplingRate. */
|
||||
get_output_samplingrate =
|
||||
dlsym(libmedia, "_ZN7android11AudioSystem21getOutputSamplingRateEPj19audio_stream_type_t");
|
||||
if (!get_output_samplingrate) {
|
||||
/* Another signature exists, with a int instead of an audio_stream_type_t */
|
||||
get_output_samplingrate =
|
||||
dlsym(libmedia, "_ZN7android11AudioSystem21getOutputSamplingRateEPii");
|
||||
if (!get_output_samplingrate) {
|
||||
dlclose(libmedia);
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (get_primary_output_samplingrate) {
|
||||
*rate = get_primary_output_samplingrate();
|
||||
} else {
|
||||
/* We don't really know about the type, here, so we just pass music. */
|
||||
r = get_output_samplingrate((int *) rate, AUDIO_STREAM_TYPE_MUSIC);
|
||||
if (r) {
|
||||
dlclose(libmedia);
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
dlclose(libmedia);
|
||||
|
||||
/* Depending on which method we called above, we can get a zero back, yet have
|
||||
* a non-error return value, especially if the audio system is not
|
||||
* ready/shutting down (i.e. when we can't get our hand on the AudioFlinger
|
||||
* thread). */
|
||||
if (*rate == 0) {
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
return CUBEB_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
opensl_destroy(cubeb * ctx)
|
||||
{
|
||||
|
@ -939,14 +879,10 @@ opensl_configure_capture(cubeb_stream * stm, cubeb_stream_params * params)
|
|||
// api for input device this is a safe choice.
|
||||
stm->input_device_rate = stm->output_configured_rate;
|
||||
} else {
|
||||
// The output preferred rate is used for input only scenario. This is
|
||||
// the correct rate to use to get a fast track for input only.
|
||||
r = opensl_get_preferred_sample_rate(stm->context, &stm->input_device_rate);
|
||||
if (r != CUBEB_OK) {
|
||||
// If everything else fail use a safe choice for Android.
|
||||
// The output preferred rate is used for input only scenario. The
|
||||
// default rate expected to supported from all android devices.
|
||||
stm->input_device_rate = DEFAULT_SAMPLE_RATE;
|
||||
}
|
||||
}
|
||||
lDataFormat.samplesPerSec = stm->input_device_rate * 1000;
|
||||
res = (*stm->context->eng)->CreateAudioRecorder(stm->context->eng,
|
||||
&stm->recorderObj,
|
||||
|
@ -1056,7 +992,7 @@ opensl_configure_playback(cubeb_stream * stm, cubeb_stream_params * params) {
|
|||
assert(stm);
|
||||
assert(params);
|
||||
|
||||
stm->inputrate = params->rate;
|
||||
stm->user_output_rate = params->rate;
|
||||
stm->framesize = params->channels * sizeof(int16_t);
|
||||
stm->lastPosition = -1;
|
||||
stm->lastPositionTimeStamp = 0;
|
||||
|
@ -1093,7 +1029,7 @@ opensl_configure_playback(cubeb_stream * stm, cubeb_stream_params * params) {
|
|||
#endif
|
||||
assert(NELEMS(ids) == NELEMS(req));
|
||||
|
||||
uint32_t preferred_sampling_rate = stm->inputrate;
|
||||
uint32_t preferred_sampling_rate = stm->user_output_rate;
|
||||
SLresult res = SL_RESULT_CONTENT_UNSUPPORTED;
|
||||
if (preferred_sampling_rate) {
|
||||
res = (*stm->context->eng)->CreateAudioPlayer(stm->context->eng,
|
||||
|
@ -1106,12 +1042,9 @@ opensl_configure_playback(cubeb_stream * stm, cubeb_stream_params * params) {
|
|||
}
|
||||
|
||||
// Sample rate not supported? Try again with primary sample rate!
|
||||
if (res == SL_RESULT_CONTENT_UNSUPPORTED) {
|
||||
if (opensl_get_preferred_sample_rate(stm->context, &preferred_sampling_rate)) {
|
||||
// If fail default is used
|
||||
if (res == SL_RESULT_CONTENT_UNSUPPORTED &&
|
||||
preferred_sampling_rate != DEFAULT_SAMPLE_RATE) {
|
||||
preferred_sampling_rate = DEFAULT_SAMPLE_RATE;
|
||||
}
|
||||
|
||||
format.samplesPerSec = preferred_sampling_rate * 1000;
|
||||
res = (*stm->context->eng)->CreateAudioPlayer(stm->context->eng,
|
||||
&stm->playerObj,
|
||||
|
@ -1550,7 +1483,7 @@ opensl_stream_get_position(cubeb_stream * stm, uint64_t * position)
|
|||
stm->lastPosition = msec;
|
||||
}
|
||||
|
||||
samplerate = stm->inputrate;
|
||||
samplerate = stm->user_output_rate;
|
||||
|
||||
r = stm->context->get_output_latency(&mixer_latency, AUDIO_STREAM_TYPE_MUSIC);
|
||||
if (r) {
|
||||
|
@ -1558,7 +1491,7 @@ opensl_stream_get_position(cubeb_stream * stm, uint64_t * position)
|
|||
}
|
||||
|
||||
pthread_mutex_lock(&stm->mutex);
|
||||
int64_t maximum_position = stm->written * (int64_t)stm->inputrate / stm->output_configured_rate;
|
||||
int64_t maximum_position = stm->written * (int64_t)stm->user_output_rate / stm->output_configured_rate;
|
||||
pthread_mutex_unlock(&stm->mutex);
|
||||
assert(maximum_position >= 0);
|
||||
|
||||
|
@ -1617,7 +1550,7 @@ static struct cubeb_ops const opensl_ops = {
|
|||
.get_backend_id = opensl_get_backend_id,
|
||||
.get_max_channel_count = opensl_get_max_channel_count,
|
||||
.get_min_latency = NULL,
|
||||
.get_preferred_sample_rate = opensl_get_preferred_sample_rate,
|
||||
.get_preferred_sample_rate = NULL,
|
||||
.get_preferred_channel_layout = NULL,
|
||||
.enumerate_devices = NULL,
|
||||
.device_collection_destroy = NULL,
|
||||
|
|
Загрузка…
Ссылка в новой задаче