summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2013-11-27 18:58:28 +0100
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2013-11-27 23:15:17 +0100
commitf10cca0e8843a44f8341e8c09d535b46738343a0 (patch)
tree785587b47e0e0d040cce292fbca619be6944a565
parent69220aa1cde79ce59ce10bf9c15ee20c9e212487 (diff)
downloadmpv-f10cca0e8843a44f8341e8c09d535b46738343a0.tar.bz2
mpv-f10cca0e8843a44f8341e8c09d535b46738343a0.tar.xz
ao_coreaudio: simplify ch label to speaker id conversion
Previous code was using the values of the AudioChannelLabel enum directly to create the channel bitmap. While this was quite smart it was pretty unreadable and fragile (what if Apple changes the values of those enums?). Change it to use a 'dumb' conversion table.
-rw-r--r--audio/out/ao_coreaudio_utils.c60
1 files changed, 37 insertions, 23 deletions
diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c
index 2a3cd99028..9fa54c726c 100644
--- a/audio/out/ao_coreaudio_utils.c
+++ b/audio/out/ao_coreaudio_utils.c
@@ -336,31 +336,45 @@ bool ca_change_format(struct ao *ao, AudioStreamID stream,
return format_set;
}
+static const int speaker_map[][2] = {
+ { kAudioChannelLabel_Left, MP_SPEAKER_ID_FL },
+ { kAudioChannelLabel_Right, MP_SPEAKER_ID_FR },
+ { kAudioChannelLabel_Center, MP_SPEAKER_ID_FC },
+ { kAudioChannelLabel_LFEScreen, MP_SPEAKER_ID_LFE },
+ { kAudioChannelLabel_LeftSurround, MP_SPEAKER_ID_BL },
+ { kAudioChannelLabel_RightSurround, MP_SPEAKER_ID_BR },
+ { kAudioChannelLabel_LeftCenter, MP_SPEAKER_ID_FLC },
+ { kAudioChannelLabel_RightCenter, MP_SPEAKER_ID_FRC },
+ { kAudioChannelLabel_CenterSurround, MP_SPEAKER_ID_BC },
+ { kAudioChannelLabel_LeftSurroundDirect, MP_SPEAKER_ID_SL },
+ { kAudioChannelLabel_RightSurroundDirect, MP_SPEAKER_ID_SR },
+ { kAudioChannelLabel_TopCenterSurround, MP_SPEAKER_ID_TC },
+ { kAudioChannelLabel_VerticalHeightLeft, MP_SPEAKER_ID_TFL },
+ { kAudioChannelLabel_VerticalHeightCenter, MP_SPEAKER_ID_TFC },
+ { kAudioChannelLabel_VerticalHeightRight, MP_SPEAKER_ID_TFR },
+ { kAudioChannelLabel_TopBackLeft, MP_SPEAKER_ID_TBL },
+ { kAudioChannelLabel_TopBackCenter, MP_SPEAKER_ID_TBC },
+ { kAudioChannelLabel_TopBackRight, MP_SPEAKER_ID_TBR },
+
+ // unofficial extensions
+ { kAudioChannelLabel_RearSurroundLeft, MP_SPEAKER_ID_SDL },
+ { kAudioChannelLabel_RearSurroundRight, MP_SPEAKER_ID_SDR },
+ { kAudioChannelLabel_LeftWide, MP_SPEAKER_ID_WL },
+ { kAudioChannelLabel_RightWide, MP_SPEAKER_ID_WR },
+ { kAudioChannelLabel_LFE2, MP_SPEAKER_ID_LFE2 },
+
+ { kAudioChannelLabel_HeadphonesLeft, MP_SPEAKER_ID_DL },
+ { kAudioChannelLabel_HeadphonesRight, MP_SPEAKER_ID_DR },
+
+ { kAudioChannelLabel_Unknown, -1 },
+};
+
static int ca_label_to_mp_speaker_id(AudioChannelLabel label)
{
- if (label == kAudioChannelLabel_UseCoordinates ||
- label == kAudioChannelLabel_Unknown ||
- label > kAudioChannelLabel_LFE2)
- return -1;
-
- if (label <= kAudioChannelLabel_TopBackRight) {
- return label - 1;
- } else {
- // Take care of extra labels after kAudioChannelLabel_TopBackRight
- switch (label) {
- case kAudioChannelLabel_RearSurroundLeft:
- return MP_SPEAKER_ID_SDL;
- case kAudioChannelLabel_RearSurroundRight:
- return MP_SPEAKER_ID_SDR;
- case kAudioChannelLabel_LeftWide:
- return MP_SPEAKER_ID_WL;
- case kAudioChannelLabel_RightWide:
- return MP_SPEAKER_ID_WR;
- case kAudioChannelLabel_LFE2:
- return kAudioChannelLabel_LFE2;
- }
- return -1;
- }
+ for (int i = 0; speaker_map[i][0] != kAudioChannelLabel_Unknown; i++)
+ if (speaker_map[i][0] == label)
+ return speaker_map[i][1];
+ return -1;
}
static bool ca_bitmap_from_ch_desc(struct ao *ao, AudioChannelLayout *layout,