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.

(cherry picked from commit b91b4944bd)
This commit is contained in:
wm4 authored and Diogo Franco (Kovensky) committed 2015-05-09 21:13:21 +09:00
1 parent f58646c85c
commit 1127bb41c2
5 files changed
+17 -36

No files matched your search

+8 -18
View File
@@ -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;
@@ -449,12 +444,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);
+3 -3
View File
@@ -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.
+2 -7
View File
@@ -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;
}
+3 -7
View File
@@ -444,7 +444,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 },
};
@@ -542,14 +542,10 @@ bool ca_layout_to_mp_chmap(struct ao *ao, AudioChannelLayout *layout,
return false;
}
int next_na = MP_SPEAKER_ID_NA0;
int next_na = MP_SPEAKER_ID_NA;
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);
+1 -1
View File
@@ -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. */
};