Skip to content

Instantly share code, notes, and snippets.

@tmm1
Last active July 4, 2017 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmm1/a6bc450513246bf356c2552fb371622b to your computer and use it in GitHub Desktop.
Save tmm1/a6bc450513246bf356c2552fb371622b to your computer and use it in GitHub Desktop.
diff --git a/audio/out/ao_opensles.c b/audio/out/ao_opensles.c
index 5357ab4920..172a543fac 100644
--- a/audio/out/ao_opensles.c
+++ b/audio/out/ao_opensles.c
@@ -49,6 +49,28 @@ static const int fmtmap[][2] = {
{ 0 }
};
+static const int speaker_map[][2] = {
+ {SL_SPEAKER_FRONT_LEFT, MP_SPEAKER_ID_FL},
+ {SL_SPEAKER_FRONT_RIGHT, MP_SPEAKER_ID_FR},
+ {SL_SPEAKER_FRONT_CENTER, MP_SPEAKER_ID_FC},
+ {SL_SPEAKER_BACK_CENTER, MP_SPEAKER_ID_BC},
+ {SL_SPEAKER_BACK_LEFT, MP_SPEAKER_ID_BL},
+ {SL_SPEAKER_BACK_RIGHT, MP_SPEAKER_ID_BR},
+ {SL_SPEAKER_LOW_FREQUENCY, MP_SPEAKER_ID_LFE},
+ {SL_SPEAKER_FRONT_LEFT_OF_CENTER, MP_SPEAKER_ID_FLC},
+ {SL_SPEAKER_FRONT_RIGHT_OF_CENTER, MP_SPEAKER_ID_FRC},
+ {SL_SPEAKER_SIDE_LEFT, MP_SPEAKER_ID_SL},
+ {SL_SPEAKER_SIDE_RIGHT, MP_SPEAKER_ID_SR},
+ {SL_SPEAKER_TOP_CENTER, MP_SPEAKER_ID_TC},
+ {SL_SPEAKER_TOP_FRONT_LEFT, MP_SPEAKER_ID_TFL},
+ {SL_SPEAKER_TOP_FRONT_RIGHT, MP_SPEAKER_ID_TFR},
+ {SL_SPEAKER_TOP_FRONT_CENTER, MP_SPEAKER_ID_TFC},
+ {SL_SPEAKER_TOP_BACK_LEFT, MP_SPEAKER_ID_TBL},
+ {SL_SPEAKER_TOP_BACK_RIGHT, MP_SPEAKER_ID_TBR},
+ {SL_SPEAKER_TOP_BACK_CENTER, MP_SPEAKER_ID_TBC},
+ {-1, -1}
+};
+
#define DESTROY(thing) \
if (p->thing) { \
(*p->thing)->Destroy(p->thing); \
@@ -112,6 +134,18 @@ static void buffer_callback(SLBufferQueueItf buffer_queue, void *context)
} \
}
+static SLuint32 mp_chmap_to_channelMask(struct mp_chmap channels)
+{
+ SLuint32 mask = 0;
+ for (int j = 0; j < channels.num; j++) {
+ for (int i = 0; speaker_map[i][1] >= 0; i++) {
+ if (speaker_map[i][1] == channels.speaker[j])
+ mask |= speaker_map[i][0];
+ }
+ }
+ return mask;
+}
+
static int init(struct ao *ao)
{
struct priv *p = ao->priv;
@@ -122,7 +156,7 @@ static int init(struct ao *ao)
SLDataSink audio_sink;
// This AO only supports two channels at the moment
- mp_chmap_from_channels(&ao->channels, 2);
+ //mp_chmap_from_channels(&ao->channels, 2);
CHK(slCreateEngine(&p->sl, 0, NULL, 0, NULL, NULL));
CHK((*p->sl)->Realize(p->sl, SL_BOOLEAN_FALSE));
@@ -134,7 +168,7 @@ static int init(struct ao *ao)
locator_buffer_queue.numBuffers = 2;
pcm.formatType = SL_DATAFORMAT_PCM;
- pcm.numChannels = 2;
+ pcm.numChannels = ao->channels.num;
int compatible_formats[AF_FORMAT_COUNT];
af_get_best_sample_formats(ao->format, compatible_formats);
@@ -151,7 +185,7 @@ static int init(struct ao *ao)
goto error;
}
pcm.containerSize = 8 * af_fmt_to_bytes(ao->format);
- pcm.channelMask = SL_SPEAKER_FRONT_LEFT | SL_SPEAKER_FRONT_RIGHT;
+ pcm.channelMask = mp_chmap_to_channelMask(ao->channels);
pcm.endianness = SL_BYTEORDER_LITTLEENDIAN;
if (p->cfg_sample_rate)
@@ -191,7 +225,7 @@ static int init(struct ao *ao)
SLboolean required[] = { SL_BOOLEAN_TRUE };
SLInterfaceID iid_array[] = { SL_IID_BUFFERQUEUE };
CHK((*p->engine)->CreateAudioPlayer(p->engine, &p->player, &audio_source,
- &audio_sink, 1, iid_array, required));
+ &audio_sink, 1, iid_array, required)); // TODO catch SL_RESULT_PARAMETER_INVALID and reconfigure as stereo
CHK((*p->player)->Realize(p->player, SL_BOOLEAN_FALSE));
CHK((*p->player)->GetInterface(p->player, SL_IID_PLAY, (void*)&p->play));
CHK((*p->player)->GetInterface(p->player, SL_IID_BUFFERQUEUE,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment