mirror of
https://github.com/mpv-player/mpv
synced 2025-01-31 04:02:06 +00:00
audio: remove UNKNOWN pseudo speakers
Reuse MP_SPEAKER_ID_NA for this. If all mp_chmap entries are set to NA, the channel layout has special "unknown channel layout" semantics, which are used to deal with some corner cases.
This commit is contained in:
parent
b91b4944bd
commit
55e777f10b
@ -144,12 +144,10 @@ bool mp_chmap_is_empty(const struct mp_chmap *src)
|
||||
bool mp_chmap_is_unknown(const struct mp_chmap *src)
|
||||
{
|
||||
for (int n = 0; n < src->num; n++) {
|
||||
int speaker = src->speaker[n];
|
||||
if (speaker >= MP_SPEAKER_ID_UNKNOWN0 &&
|
||||
speaker <= MP_SPEAKER_ID_UNKNOWN_LAST)
|
||||
return true;
|
||||
if (src->speaker[n] != MP_SPEAKER_ID_NA)
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
return mp_chmap_is_valid(src);
|
||||
}
|
||||
|
||||
// Note: empty channel maps compare as equal. Invalid ones can equal too.
|
||||
@ -240,6 +238,8 @@ void mp_chmap_from_channels_alsa(struct mp_chmap *dst, int num_channels)
|
||||
// Set *dst to an unknown layout for the given numbers of channels.
|
||||
// If the number of channels is invalid, an invalid map is set, and
|
||||
// mp_chmap_is_valid(dst) will return false.
|
||||
// A mp_chmap with all entries set to NA is treated specially in some
|
||||
// contexts (watch out for mp_chmap_is_unknown()).
|
||||
void mp_chmap_set_unknown(struct mp_chmap *dst, int num_channels)
|
||||
{
|
||||
if (num_channels < 0 || num_channels > MP_NUM_CHANNELS) {
|
||||
@ -247,7 +247,7 @@ void mp_chmap_set_unknown(struct mp_chmap *dst, int num_channels)
|
||||
} else {
|
||||
dst->num = num_channels;
|
||||
for (int n = 0; n < dst->num; n++)
|
||||
dst->speaker[n] = MP_SPEAKER_ID_UNKNOWN0 + n;
|
||||
dst->speaker[n] = MP_SPEAKER_ID_NA;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,15 +56,12 @@ enum mp_speaker_id {
|
||||
MP_SPEAKER_ID_SDR, // SURROUND_DIRECT_RIGHT
|
||||
MP_SPEAKER_ID_LFE2, // LOW_FREQUENCY_2
|
||||
|
||||
// Special mpv-specific speaker entries reserved for channels which have no
|
||||
// known meaning.
|
||||
MP_SPEAKER_ID_UNKNOWN0 = 64,
|
||||
MP_SPEAKER_ID_UNKNOWN_LAST = MP_SPEAKER_ID_UNKNOWN0 + MP_NUM_CHANNELS - 1,
|
||||
// Speaker IDs >= 64 are not representable in WAVEFORMATEXTENSIBLE or libav*.
|
||||
|
||||
// "Silent" channels. These are sometimes used to insert padding for
|
||||
// unused channels. Unlike other speaker types, multiple of these can
|
||||
// occur in a single mp_chmap.
|
||||
MP_SPEAKER_ID_NA,
|
||||
MP_SPEAKER_ID_NA = 64,
|
||||
|
||||
// Including the unassigned IDs in between. This is not a valid ID anymore,
|
||||
// but is still within uint8_t.
|
||||
|
@ -89,9 +89,7 @@ static void test_mp_chmap_sel_fallback_reject_unknown(void **state) {
|
||||
struct mp_chmap b;
|
||||
struct mp_chmap_sel s = {0};
|
||||
|
||||
a.num = 2;
|
||||
a.speaker[0] = MP_SPEAKER_ID_UNKNOWN0;
|
||||
a.speaker[1] = MP_SPEAKER_ID_UNKNOWN0 + 1;
|
||||
mp_chmap_set_unknown(&a, 2);
|
||||
|
||||
mp_chmap_from_str(&b, bstr0("5.1"));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user