summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2014-07-02 19:34:16 +0200
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2014-07-02 21:43:08 +0200
commit4f5f034ba2556fdbd3247922694da01576f4f9cd (patch)
tree8324761c21906fd172a6bacec27db3853a82fc6a /audio
parentc8fc02612e498ec3fc366ed2e32392fd81b1ae8c (diff)
downloadmpv-4f5f034ba2556fdbd3247922694da01576f4f9cd.tar.bz2
mpv-4f5f034ba2556fdbd3247922694da01576f4f9cd.tar.xz
ao_coreaudio: move channel mapping away from utils
Channel mapping functions are only used in the AUHAL based coreaudio, so move them there.
Diffstat (limited to 'audio')
-rw-r--r--audio/out/ao_coreaudio.c128
-rw-r--r--audio/out/ao_coreaudio_utils.c123
-rw-r--r--audio/out/ao_coreaudio_utils.h3
3 files changed, 128 insertions, 126 deletions
diff --git a/audio/out/ao_coreaudio.c b/audio/out/ao_coreaudio.c
index c8feb56e7a..59846cd605 100644
--- a/audio/out/ao_coreaudio.c
+++ b/audio/out/ao_coreaudio.c
@@ -35,6 +35,9 @@ struct priv {
int opt_list;
};
+bool ca_layout_to_mp_chmap(struct ao *ao, AudioChannelLayout *layout,
+ struct mp_chmap *chmap);
+
static OSStatus render_cb_lpcm(void *ctx, AudioUnitRenderActionFlags *aflags,
const AudioTimeStamp *ts, UInt32 bus,
UInt32 frames, AudioBufferList *buffer_list)
@@ -244,6 +247,131 @@ static void uninit(struct ao *ao)
AudioComponentInstanceDispose(p->audio_unit);
}
+// Channel Mapping functions
+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)
+{
+ for (int i = 0; speaker_map[i][1] >= 0; i++)
+ if (speaker_map[i][0] == label)
+ return speaker_map[i][1];
+ return -1;
+}
+
+static void ca_log_layout(struct ao *ao, AudioChannelLayout *layout)
+{
+ if (!mp_msg_test(ao->log, MSGL_V))
+ return;
+
+ AudioChannelDescription *descs = layout->mChannelDescriptions;
+
+ MP_VERBOSE(ao, "layout: tag: <%d>, bitmap: <%d>, "
+ "descriptions <%d>\n",
+ layout->mChannelLayoutTag,
+ layout->mChannelBitmap,
+ layout->mNumberChannelDescriptions);
+
+ for (int i = 0; i < layout->mNumberChannelDescriptions; i++) {
+ AudioChannelDescription d = descs[i];
+ MP_VERBOSE(ao, " - description %d: label <%d, %d>, flags: <%u>, "
+ "coords: <%f, %f, %f>\n", i,
+ d.mChannelLabel,
+ ca_label_to_mp_speaker_id(d.mChannelLabel),
+ d.mChannelFlags,
+ d.mCoordinates[0],
+ d.mCoordinates[1],
+ d.mCoordinates[2]);
+ }
+}
+
+bool ca_layout_to_mp_chmap(struct ao *ao, AudioChannelLayout *layout,
+ struct mp_chmap *chmap)
+{
+ AudioChannelLayoutTag tag = layout->mChannelLayoutTag;
+ uint32_t layout_size = sizeof(layout);
+ OSStatus err;
+
+ if (tag == kAudioChannelLayoutTag_UseChannelBitmap) {
+ err = AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
+ sizeof(uint32_t),
+ &layout->mChannelBitmap,
+ &layout_size,
+ layout);
+ CHECK_CA_ERROR("failed to convert channel bitmap to descriptions");
+ } else if (tag != kAudioChannelLayoutTag_UseChannelDescriptions) {
+ err = AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
+ sizeof(AudioChannelLayoutTag),
+ &layout->mChannelLayoutTag,
+ &layout_size,
+ layout);
+ CHECK_CA_ERROR("failed to convert channel tag to descriptions");
+ }
+
+ ca_log_layout(ao, layout);
+
+ // If the channel layout uses channel descriptions, from my
+ // experiments there are there three possibile cases:
+ // * The description has a label kAudioChannelLabel_Unknown:
+ // Can't do anything about this (looks like non surround
+ // layouts are like this).
+ // * The description uses positional information: this in
+ // theory could be used but one would have to map spatial
+ // positions to labels which is not really feasible.
+ // * The description has a well known label which can be mapped
+ // to the waveextensible definition: this is the kind of
+ // descriptions we process here.
+
+ for (int n = 0; n < layout->mNumberChannelDescriptions; n++) {
+ AudioChannelLabel label = layout->mChannelDescriptions[n].mChannelLabel;
+ uint8_t speaker = ca_label_to_mp_speaker_id(label);
+ if (label == kAudioChannelLabel_Unknown)
+ continue;
+ if (speaker < 0) {
+ MP_VERBOSE(ao, "channel label=%d unusable to build channel "
+ "bitmap, skipping layout\n", label);
+ } else {
+ chmap->speaker[n] = speaker;
+ chmap->num = n + 1;
+ }
+ }
+
+ return chmap->num > 0;
+coreaudio_error:
+ ca_log_layout(ao, layout);
+ return false;
+}
+
#define OPT_BASE_STRUCT struct priv
const struct ao_driver audio_out_coreaudio = {
diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c
index 235e7fba42..da06656e9d 100644
--- a/audio/out/ao_coreaudio_utils.c
+++ b/audio/out/ao_coreaudio_utils.c
@@ -175,126 +175,3 @@ void ca_print_asbd(struct ao *ao, const char *description,
talloc_free(format);
}
-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)
-{
- for (int i = 0; speaker_map[i][1] >= 0; i++)
- if (speaker_map[i][0] == label)
- return speaker_map[i][1];
- return -1;
-}
-
-static void ca_log_layout(struct ao *ao, AudioChannelLayout *layout)
-{
- if (!mp_msg_test(ao->log, MSGL_V))
- return;
-
- AudioChannelDescription *descs = layout->mChannelDescriptions;
-
- MP_VERBOSE(ao, "layout: tag: <%d>, bitmap: <%d>, "
- "descriptions <%d>\n",
- layout->mChannelLayoutTag,
- layout->mChannelBitmap,
- layout->mNumberChannelDescriptions);
-
- for (int i = 0; i < layout->mNumberChannelDescriptions; i++) {
- AudioChannelDescription d = descs[i];
- MP_VERBOSE(ao, " - description %d: label <%d, %d>, flags: <%u>, "
- "coords: <%f, %f, %f>\n", i,
- d.mChannelLabel,
- ca_label_to_mp_speaker_id(d.mChannelLabel),
- d.mChannelFlags,
- d.mCoordinates[0],
- d.mCoordinates[1],
- d.mCoordinates[2]);
- }
-}
-
-bool ca_layout_to_mp_chmap(struct ao *ao, AudioChannelLayout *layout,
- struct mp_chmap *chmap)
-{
- AudioChannelLayoutTag tag = layout->mChannelLayoutTag;
- uint32_t layout_size = sizeof(layout);
- OSStatus err;
-
- if (tag == kAudioChannelLayoutTag_UseChannelBitmap) {
- err = AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForBitmap,
- sizeof(uint32_t),
- &layout->mChannelBitmap,
- &layout_size,
- layout);
- CHECK_CA_ERROR("failed to convert channel bitmap to descriptions");
- } else if (tag != kAudioChannelLayoutTag_UseChannelDescriptions) {
- err = AudioFormatGetProperty(kAudioFormatProperty_ChannelLayoutForTag,
- sizeof(AudioChannelLayoutTag),
- &layout->mChannelLayoutTag,
- &layout_size,
- layout);
- CHECK_CA_ERROR("failed to convert channel tag to descriptions");
- }
-
- ca_log_layout(ao, layout);
-
- // If the channel layout uses channel descriptions, from my
- // experiments there are there three possibile cases:
- // * The description has a label kAudioChannelLabel_Unknown:
- // Can't do anything about this (looks like non surround
- // layouts are like this).
- // * The description uses positional information: this in
- // theory could be used but one would have to map spatial
- // positions to labels which is not really feasible.
- // * The description has a well known label which can be mapped
- // to the waveextensible definition: this is the kind of
- // descriptions we process here.
-
- for (int n = 0; n < layout->mNumberChannelDescriptions; n++) {
- AudioChannelLabel label = layout->mChannelDescriptions[n].mChannelLabel;
- uint8_t speaker = ca_label_to_mp_speaker_id(label);
- if (label == kAudioChannelLabel_Unknown)
- continue;
- if (speaker < 0) {
- MP_VERBOSE(ao, "channel label=%d unusable to build channel "
- "bitmap, skipping layout\n", label);
- } else {
- chmap->speaker[n] = speaker;
- chmap->num = n + 1;
- }
- }
-
- return chmap->num > 0;
-coreaudio_error:
- ca_log_layout(ao, layout);
- return false;
-}
diff --git a/audio/out/ao_coreaudio_utils.h b/audio/out/ao_coreaudio_utils.h
index 6d0f65c455..2c746195fc 100644
--- a/audio/out/ao_coreaudio_utils.h
+++ b/audio/out/ao_coreaudio_utils.h
@@ -53,7 +53,4 @@ void ca_fill_asbd(struct ao *ao, AudioStreamBasicDescription *asbd);
void ca_print_asbd(struct ao *ao, const char *description,
const AudioStreamBasicDescription *asbd);
-bool ca_layout_to_mp_chmap(struct ao *ao, AudioChannelLayout *layout,
- struct mp_chmap *chmap);
-
#endif /* MPV_COREAUDIO_UTILS_H */