summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-05-07 23:07:14 +0200
committerwm4 <wm4@nowhere>2015-05-07 23:07:14 +0200
commitb91b4944bd7ddf6fef4c4254d457117017292c0a (patch)
tree9df3f41d12fe7dc3599d1a0794e1b2b2eb9f1b5e
parent34770887410cab45e2779d43a83aa4f6bdecf926 (diff)
downloadmpv-b91b4944bd7ddf6fef4c4254d457117017292c0a.tar.bz2
mpv-b91b4944bd7ddf6fef4c4254d457117017292c0a.tar.xz
audio: define only a single NA speaker ID
Remove the requirement from mp_chmap that speaker entries must be unique. Use this to get rid of all the redundant NA speaker IDs.
-rw-r--r--audio/chmap.c26
-rw-r--r--audio/chmap.h6
-rw-r--r--audio/out/ao_alsa.c9
-rw-r--r--audio/out/ao_coreaudio_chmap.c7
-rw-r--r--audio/out/ao_sndio.c2
5 files changed, 16 insertions, 34 deletions
diff --git a/audio/chmap.c b/audio/chmap.c
index 7e62dab74a..a36a6d9bdf 100644
--- a/audio/chmap.c
+++ b/audio/chmap.c
@@ -50,6 +50,7 @@ static const char *const speaker_names[MP_SPEAKER_ID_COUNT][2] = {
[MP_SPEAKER_ID_SDL] = {"sdl", "surround direct left"},
[MP_SPEAKER_ID_SDR] = {"sdr", "surround direct right"},
[MP_SPEAKER_ID_LFE2] = {"lfe2", "low frequency 2"},
+ [MP_SPEAKER_ID_NA] = {"na", "not available"},
};
// Names taken from libavutil/channel_layout.c (Not accessible by API.)
@@ -127,7 +128,8 @@ bool mp_chmap_is_valid(const struct mp_chmap *src)
int sp = src->speaker[n];
if (sp >= MP_SPEAKER_ID_COUNT || mapped[sp])
return false;
- mapped[sp] = true;
+ if (sp != MP_SPEAKER_ID_NA)
+ mapped[sp] = true;
}
return src->num > 0;
}
@@ -196,7 +198,7 @@ void mp_chmap_remove_na(struct mp_chmap *map)
struct mp_chmap new = {0};
for (int n = 0; n < map->num; n++) {
int sp = map->speaker[n];
- if (!(sp >= MP_SPEAKER_ID_NA0 && sp <= MP_SPEAKER_ID_NA_LAST))
+ if (sp != MP_SPEAKER_ID_NA)
new.speaker[new.num++] = map->speaker[n];
}
*map = new;
@@ -206,15 +208,8 @@ void mp_chmap_remove_na(struct mp_chmap *map)
void mp_chmap_fill_na(struct mp_chmap *map, int num)
{
assert(num <= MP_NUM_CHANNELS);
- while (map->num < num) {
- int sp = map->num ? map->speaker[map->num - 1] : -1;
- if (sp >= MP_SPEAKER_ID_NA0 && sp < MP_SPEAKER_ID_NA_LAST) {
- sp += 1;
- } else {
- sp = MP_SPEAKER_ID_NA0;
- }
- map->speaker[map->num++] = sp;
- }
+ while (map->num < num)
+ map->speaker[map->num++] = MP_SPEAKER_ID_NA;
}
// Set *dst to a standard layout with the given number of channels.
@@ -306,7 +301,7 @@ uint64_t mp_chmap_to_lavc_unchecked(const struct mp_chmap *src)
mp_chmap_from_channels(&t, t.num);
uint64_t mask = 0;
for (int n = 0; n < t.num; n++) {
- if (t.speaker[n] < 64) // ignore MP_SPEAKER_ID_NA* etc.
+ if (t.speaker[n] < 64) // ignore MP_SPEAKER_ID_NA etc.
mask |= 1ULL << t.speaker[n];
}
return mask;
@@ -440,12 +435,7 @@ char *mp_chmap_to_str_buf(char *buf, size_t buf_size, const struct mp_chmap *src
const char *s = sp < MP_SPEAKER_ID_COUNT ? speaker_names[sp][0] : NULL;
char sp_buf[10];
if (!s) {
- const char *prefix = "sp";
- if (sp >= MP_SPEAKER_ID_NA0 && sp <= MP_SPEAKER_ID_NA_LAST) {
- sp -= MP_SPEAKER_ID_NA0;
- prefix = "na";
- }
- snprintf(sp_buf, sizeof(sp_buf), "%s%d", prefix, sp);
+ snprintf(sp_buf, sizeof(sp_buf), "sp%d", sp);
s = sp_buf;
}
mp_snprintf_cat(buf, buf_size, "%s%s", n > 0 ? "-" : "", s);
diff --git a/audio/chmap.h b/audio/chmap.h
index 296b2a1712..d3ce5cdb21 100644
--- a/audio/chmap.h
+++ b/audio/chmap.h
@@ -62,9 +62,9 @@ enum mp_speaker_id {
MP_SPEAKER_ID_UNKNOWN_LAST = MP_SPEAKER_ID_UNKNOWN0 + MP_NUM_CHANNELS - 1,
// "Silent" channels. These are sometimes used to insert padding for
- // unused channels.
- MP_SPEAKER_ID_NA0,
- MP_SPEAKER_ID_NA_LAST = MP_SPEAKER_ID_NA0 + MP_NUM_CHANNELS - 1,
+ // unused channels. Unlike other speaker types, multiple of these can
+ // occur in a single mp_chmap.
+ MP_SPEAKER_ID_NA,
// Including the unassigned IDs in between. This is not a valid ID anymore,
// but is still within uint8_t.
diff --git a/audio/out/ao_alsa.c b/audio/out/ao_alsa.c
index e31e8012f8..2a7d694d95 100644
--- a/audio/out/ao_alsa.c
+++ b/audio/out/ao_alsa.c
@@ -252,7 +252,7 @@ static const int alsa_to_mp_channels[][2] = {
{SND_CHMAP_TRR, MP_SP(TBR)},
{SND_CHMAP_TRC, MP_SP(TBC)},
{SND_CHMAP_MONO, MP_SP(FC)},
- {SND_CHMAP_NA, MP_SPEAKER_ID_NA0},
+ {SND_CHMAP_NA, MP_SPEAKER_ID_NA},
{SND_CHMAP_LAST, MP_SPEAKER_ID_COUNT}
};
@@ -283,14 +283,9 @@ static int mp_chmap_from_alsa(struct mp_chmap *dst, snd_pcm_chmap_t *src)
if (src->channels > MP_NUM_CHANNELS)
return -1;
- int next_na = MP_SPEAKER_ID_NA0;
-
dst->num = src->channels;
- for (int c = 0; c < dst->num; c++) {
+ for (int c = 0; c < dst->num; c++)
dst->speaker[c] = find_mp_channel(src->pos[c]);
- if (dst->speaker[c] == MP_SPEAKER_ID_NA0)
- dst->speaker[c] = next_na++;
- }
return 0;
}
diff --git a/audio/out/ao_coreaudio_chmap.c b/audio/out/ao_coreaudio_chmap.c
index f50bf4f3cc..8da0c4c6f0 100644
--- a/audio/out/ao_coreaudio_chmap.c
+++ b/audio/out/ao_coreaudio_chmap.c
@@ -51,7 +51,7 @@ static const int speaker_map[][2] = {
{ kAudioChannelLabel_HeadphonesLeft, MP_SPEAKER_ID_DL },
{ kAudioChannelLabel_HeadphonesRight, MP_SPEAKER_ID_DR },
- { kAudioChannelLabel_Unknown, MP_SPEAKER_ID_NA0 },
+ { kAudioChannelLabel_Unknown, MP_SPEAKER_ID_NA },
{ 0, -1 },
};
@@ -150,12 +150,9 @@ static bool ca_layout_to_mp_chmap(struct ao *ao, AudioChannelLayout *layout,
return false;
}
- int next_na = MP_SPEAKER_ID_NA0;
for (int n = 0; n < l->mNumberChannelDescriptions; n++) {
AudioChannelLabel label = l->mChannelDescriptions[n].mChannelLabel;
- uint8_t speaker = ca_label_to_mp_speaker_id(label);
- if (speaker == MP_SPEAKER_ID_NA0 && next_na < MP_SPEAKER_ID_NA_LAST)
- speaker = next_na++;
+ int speaker = ca_label_to_mp_speaker_id(label);
if (speaker < 0) {
MP_VERBOSE(ao, "channel label=%u unusable to build channel "
"bitmap, skipping layout\n", (unsigned) label);
diff --git a/audio/out/ao_sndio.c b/audio/out/ao_sndio.c
index bbe616aebf..abce0efd36 100644
--- a/audio/out/ao_sndio.c
+++ b/audio/out/ao_sndio.c
@@ -99,7 +99,7 @@ static const struct mp_chmap sndio_layouts[MP_NUM_CHANNELS + 1] = {
MP_CHMAP8(FL, FR, BL, BR, FC, LFE, SL, SR), // 7.1
/* above is the fixed channel assignment for sndio, since we need to fill
all channels and cannot insert silence, not all layouts are supported.
- NOTE: MP_SPEAKER_ID_NA0-7 could be used to add padding channels. Keep
+ NOTE: MP_SPEAKER_ID_NA could be used to add padding channels. Keep
in mind that they don't actually contain silence. */
};