Bug 1041882 - Remove Froyo-specific support from libcubeb. r=snorp, r=padenot

This commit is contained in:
Mike Taylor 2015-09-26 09:05:00 +02:00
parent fa4d767187
commit 550979e1ec
2 changed files with 12 additions and 95 deletions

View File

@ -52,9 +52,7 @@ enum event_type {
};
/**
* From https://android.googlesource.com/platform/frameworks/base/+/android-2.2.3_r2.1/include/media/AudioSystem.h
* and
* https://android.googlesource.com/platform/system/core/+/android-4.2.2_r1/include/system/audio.h
* From https://android.googlesource.com/platform/system/core/+/android-4.2.2_r1/include/system/audio.h
*/
#define AUDIO_STREAM_TYPE_MUSIC 3
@ -66,13 +64,6 @@ enum {
AUDIO_CHANNEL_OUT_STEREO_ICS = (AUDIO_CHANNEL_OUT_FRONT_LEFT_ICS | AUDIO_CHANNEL_OUT_FRONT_RIGHT_ICS)
} AudioTrack_ChannelMapping_ICS;
enum {
AUDIO_CHANNEL_OUT_FRONT_LEFT_Froyo = 0x4,
AUDIO_CHANNEL_OUT_FRONT_RIGHT_Froyo = 0x8,
AUDIO_CHANNEL_OUT_MONO_Froyo = AUDIO_CHANNEL_OUT_FRONT_LEFT_Froyo,
AUDIO_CHANNEL_OUT_STEREO_Froyo = (AUDIO_CHANNEL_OUT_FRONT_LEFT_Froyo | AUDIO_CHANNEL_OUT_FRONT_RIGHT_Froyo)
} AudioTrack_ChannelMapping_Froyo;
typedef enum {
AUDIO_FORMAT_PCM = 0x00000000,
AUDIO_FORMAT_PCM_SUB_16_BIT = 0x1,

View File

@ -56,19 +56,13 @@ struct AudioTrack {
* can get the minimum frame count with this signature, and we are
* running gingerbread. */
/* static */ status_t (*get_min_frame_count_gingerbread)(int* frame_count, int stream_type, uint32_t rate);
/* if this symbol is not availble, and the next one is, we know
* we are on a Froyo (Android 2.2) device. */
void* (*ctor)(void* instance, int, unsigned int, int, int, int, unsigned int, void (*)(int, void*, void*), void*, int, int);
void* (*ctor_froyo)(void* instance, int, unsigned int, int, int, int, unsigned int, void (*)(int, void*, void*), void*, int);
void* (*dtor)(void* instance);
void (*start)(void* instance);
void (*pause)(void* instance);
uint32_t (*latency)(void* instance);
status_t (*check)(void* instance);
status_t (*get_position)(void* instance, uint32_t* position);
/* only used on froyo. */
/* static */ int (*get_output_frame_count)(int* frame_count, int stream);
/* static */ int (*get_output_latency)(uint32_t* latency, int stream);
/* static */ int (*get_output_samplingrate)(int* samplerate, int stream);
status_t (*set_marker_position)(void* instance, unsigned int);
status_t (*set_volume)(void* instance, float left, float right);
@ -138,13 +132,6 @@ audiotrack_refill(int event, void* user, void* info)
}
}
/* We are running on froyo if we found the right AudioTrack constructor */
static int
audiotrack_version_is_froyo(cubeb * ctx)
{
return ctx->klass.ctor_froyo != NULL;
}
/* We are running on gingerbread if we found the gingerbread signature for
* getMinFrameCount */
static int
@ -157,35 +144,6 @@ int
audiotrack_get_min_frame_count(cubeb * ctx, cubeb_stream_params * params, int * min_frame_count)
{
status_t status;
/* Recent Android have a getMinFrameCount method. On Froyo, we have to compute it by hand. */
if (audiotrack_version_is_froyo(ctx)) {
int samplerate, frame_count, latency, min_buffer_count;
status = ctx->klass.get_output_frame_count(&frame_count, params->stream_type);
if (status) {
ALOG("error getting the output frame count.");
return CUBEB_ERROR;
}
status = ctx->klass.get_output_latency((uint32_t*)&latency, params->stream_type);
if (status) {
ALOG("error getting the output frame count.");
return CUBEB_ERROR;
}
status = ctx->klass.get_output_samplingrate(&samplerate, params->stream_type);
if (status) {
ALOG("error getting the output frame count.");
return CUBEB_ERROR;
}
/* Those numbers were found reading the Android source. It is the minimum
* numbers that will be accepted by the AudioTrack class, hence yielding the
* best latency possible.
* See https://android.googlesource.com/platform/frameworks/base/+/android-2.2.3_r2.1/media/libmedia/AudioTrack.cpp
* around line 181 for Android 2.2 */
min_buffer_count = latency / ((1000 * frame_count) / samplerate);
min_buffer_count = min_buffer_count < 2 ? min_buffer_count : 2;
*min_frame_count = (frame_count * params->rate * min_buffer_count) / samplerate;
return CUBEB_OK;
}
/* Recent Android have a getMinFrameCount method. */
if (!audiotrack_version_is_gingerbread(ctx)) {
status = ctx->klass.get_min_frame_count(min_frame_count, params->stream_type, params->rate);
@ -222,12 +180,8 @@ audiotrack_init(cubeb ** context, char const * context_name)
return CUBEB_ERROR;
}
/* Recent Android first, then Froyo. */
/* Recent Android first, then Gingerbread. */
DLSYM_DLERROR("_ZN7android10AudioTrackC1EijiiijPFviPvS1_ES1_ii", ctx->klass.ctor, ctx->library);
if (!ctx->klass.ctor) {
DLSYM_DLERROR("_ZN7android10AudioTrackC1EijiiijPFviPvS1_ES1_i", ctx->klass.ctor_froyo, ctx->library);
assert(ctx->klass.ctor_froyo);
}
DLSYM_DLERROR("_ZN7android10AudioTrackD1Ev", ctx->klass.dtor, ctx->library);
DLSYM_DLERROR("_ZNK7android10AudioTrack7latencyEv", ctx->klass.latency, ctx->library);
@ -235,16 +189,10 @@ audiotrack_init(cubeb ** context, char const * context_name)
DLSYM_DLERROR("_ZN7android11AudioSystem21getOutputSamplingRateEPii", ctx->klass.get_output_samplingrate, ctx->library);
/* |getMinFrameCount| is not available on Froyo, and is available on
* gingerbread and ICS with a different signature. */
if (audiotrack_version_is_froyo(ctx)) {
DLSYM_DLERROR("_ZN7android11AudioSystem19getOutputFrameCountEPii", ctx->klass.get_output_frame_count, ctx->library);
DLSYM_DLERROR("_ZN7android11AudioSystem16getOutputLatencyEPji", ctx->klass.get_output_latency, ctx->library);
} else {
DLSYM_DLERROR("_ZN7android10AudioTrack16getMinFrameCountEPi19audio_stream_type_tj", ctx->klass.get_min_frame_count, ctx->library);
if (!ctx->klass.get_min_frame_count) {
DLSYM_DLERROR("_ZN7android10AudioTrack16getMinFrameCountEPiij", ctx->klass.get_min_frame_count_gingerbread, ctx->library);
}
/* |getMinFrameCount| is available on gingerbread and ICS with different signatures. */
DLSYM_DLERROR("_ZN7android10AudioTrack16getMinFrameCountEPi19audio_stream_type_tj", ctx->klass.get_min_frame_count, ctx->library);
if (!ctx->klass.get_min_frame_count) {
DLSYM_DLERROR("_ZN7android10AudioTrack16getMinFrameCountEPiij", ctx->klass.get_min_frame_count_gingerbread, ctx->library);
}
DLSYM_DLERROR("_ZN7android10AudioTrack5startEv", ctx->klass.start, ctx->library);
@ -255,11 +203,10 @@ audiotrack_init(cubeb ** context, char const * context_name)
/* check that we have a combination of symbol that makes sense */
c = &ctx->klass;
if(!((c->ctor || c->ctor_froyo) && /* at least on ctor. */
if(!(c->ctor &&
c->dtor && c->latency && c->check &&
/* at least one way to get the minimum frame count to request. */
((c->get_output_frame_count && c->get_output_latency && c->get_output_samplingrate) ||
c->get_min_frame_count ||
(c->get_min_frame_count ||
c->get_min_frame_count_gingerbread) &&
c->start && c->pause && c->get_position && c->set_marker_position)) {
ALOG("Could not find all the symbols we need.");
@ -366,36 +313,15 @@ audiotrack_stream_init(cubeb * ctx, cubeb_stream ** stream, char const * stream_
assert(stm->instance && "cubeb: EOM");
/* gingerbread uses old channel layout enum */
if (audiotrack_version_is_froyo(ctx) || audiotrack_version_is_gingerbread(ctx)) {
if (audiotrack_version_is_gingerbread(ctx)) {
channels = stm->params.channels == 2 ? AUDIO_CHANNEL_OUT_STEREO_Legacy : AUDIO_CHANNEL_OUT_MONO_Legacy;
} else {
channels = stm->params.channels == 2 ? AUDIO_CHANNEL_OUT_STEREO_ICS : AUDIO_CHANNEL_OUT_MONO_ICS;
}
if (audiotrack_version_is_froyo(ctx)) {
ctx->klass.ctor_froyo(stm->instance,
stm->params.stream_type,
stm->params.rate,
AUDIO_FORMAT_PCM_16_BIT,
channels,
min_frame_count,
0,
audiotrack_refill,
stm,
0);
} else {
ctx->klass.ctor(stm->instance,
stm->params.stream_type,
stm->params.rate,
AUDIO_FORMAT_PCM_16_BIT,
channels,
min_frame_count,
0,
audiotrack_refill,
stm,
0,
0);
}
ctx->klass.ctor(stm->instance, stm->params.stream_type, stm->params.rate,
AUDIO_FORMAT_PCM_16_BIT, channels, min_frame_count, 0,
audiotrack_refill, stm, 0, 0);
assert((*(uint32_t*)((intptr_t)stm->instance + SIZE_AUDIOTRACK_INSTANCE - 4)) == 0xbaadbaad);