diff options
Diffstat (limited to 'audio')
52 files changed, 6930 insertions, 3541 deletions
diff --git a/audio/aframe.c b/audio/aframe.c index bc43bc98d2..03e8ab8ae8 100644 --- a/audio/aframe.c +++ b/audio/aframe.c @@ -18,9 +18,12 @@ #include <libavutil/frame.h> #include <libavutil/mem.h> +#include "config.h" + #include "common/common.h" #include "chmap.h" +#include "chmap_avchannel.h" #include "fmt-conversion.h" #include "format.h" #include "aframe.h" @@ -49,8 +52,7 @@ struct mp_aframe *mp_aframe_create(void) { struct mp_aframe *frame = talloc_zero(NULL, struct mp_aframe); frame->av_frame = av_frame_alloc(); - if (!frame->av_frame) - abort(); + MP_HANDLE_OOM(frame->av_frame); talloc_set_destructor(frame, free_frame); mp_aframe_reset(frame); return frame; @@ -100,6 +102,19 @@ void mp_aframe_unref_data(struct mp_aframe *frame) talloc_free(tmp); } +// Allocate this much data. Returns false for failure (data already allocated, +// invalid sample count or format, allocation failures). +// Normally you're supposed to use a frame pool and mp_aframe_pool_allocate(). +bool mp_aframe_alloc_data(struct mp_aframe *frame, int samples) +{ + if (mp_aframe_is_allocated(frame)) + return false; + struct mp_aframe_pool *p = mp_aframe_pool_create(NULL); + int r = mp_aframe_pool_allocate(p, frame, samples); + talloc_free(p); + return r >= 0; +} + // Return a new reference to the data in av_frame. av_frame itself is not // touched. Returns NULL if not representable, or if input is NULL. // Does not copy the timestamps. @@ -108,6 +123,16 @@ struct mp_aframe *mp_aframe_from_avframe(struct AVFrame *av_frame) if (!av_frame || av_frame->width > 0 || av_frame->height > 0) return NULL; +#if HAVE_AV_CHANNEL_LAYOUT + if (!av_channel_layout_check(&av_frame->ch_layout)) + return NULL; + + struct mp_chmap converted_map = { 0 }; + if (!mp_chmap_from_av_layout(&converted_map, &av_frame->ch_layout)) { + return NULL; + } +#endif + int format = af_from_avformat(av_frame->format); if (!format && av_frame->format != AV_SAMPLE_FMT_NONE) return NULL; @@ -119,12 +144,14 @@ struct mp_aframe *mp_aframe_from_avframe(struct AVFrame *av_frame) abort(); frame->format = format; +#if !HAVE_AV_CHANNEL_LAYOUT mp_chmap_from_lavc(&frame->chmap, frame->av_frame->channel_layout); -#if LIBAVUTIL_VERSION_MICRO >= 100 // FFmpeg being a stupid POS again if (frame->chmap.num != frame->av_frame->channels) mp_chmap_from_channels(&frame->chmap, av_frame->channels); +#else + frame->chmap = converted_map; #endif if (av_frame->opaque_ref) { @@ -193,10 +220,15 @@ void mp_aframe_config_copy(struct mp_aframe *dst, struct mp_aframe *src) dst->av_frame->sample_rate = src->av_frame->sample_rate; dst->av_frame->format = src->av_frame->format; + +#if !HAVE_AV_CHANNEL_LAYOUT dst->av_frame->channel_layout = src->av_frame->channel_layout; -#if LIBAVUTIL_VERSION_MICRO >= 100 // FFmpeg being a stupid POS again dst->av_frame->channels = src->av_frame->channels; +#else + if (av_channel_layout_copy(&dst->av_frame->ch_layout, + &src->av_frame->ch_layout) < 0) + abort(); #endif } @@ -306,14 +338,20 @@ bool mp_aframe_set_chmap(struct mp_aframe *frame, struct mp_chmap *in) return false; if (mp_aframe_is_allocated(frame) && in->num != frame->chmap.num) return false; + +#if !HAVE_AV_CHANNEL_LAYOUT uint64_t lavc_layout = mp_chmap_to_lavc_unchecked(in); if (!lavc_layout && in->num) return false; +#endif frame->chmap = *in; + +#if !HAVE_AV_CHANNEL_LAYOUT frame->av_frame->channel_layout = lavc_layout; -#if LIBAVUTIL_VERSION_MICRO >= 100 // FFmpeg being a stupid POS again frame->av_frame->channels = frame->chmap.num; +#else + mp_chmap_to_av_layout(&frame->av_frame->ch_layout, in); #endif return true; } @@ -410,10 +448,16 @@ void mp_aframe_skip_samples(struct mp_aframe *f, int samples) { assert(samples >= 0 && samples <= mp_aframe_get_size(f)); + if (av_frame_make_writable(f->av_frame) < 0) + return; // go complain to ffmpeg + int num_planes = mp_aframe_get_planes(f); size_t sstride = mp_aframe_get_sstride(f); - for (int n = 0; n < num_planes; n++) - f->av_frame->extended_data[n] += samples * sstride; + for (int n = 0; n < num_planes; n++) { + memmove(f->av_frame->extended_data[n], + f->av_frame->extended_data[n] + samples * sstride, + (f->av_frame->nb_samples - samples) * sstride); + } f->av_frame->nb_samples -= samples; @@ -421,6 +465,37 @@ void mp_aframe_skip_samples(struct mp_aframe *f, int samples) f->pts += samples / mp_aframe_get_effective_rate(f); } +// sanitize a floating point sample value +#define sanitizef(f) do { \ + if (!isnormal(f)) \ + (f) = 0; \ +} while (0) + +void mp_aframe_sanitize_float(struct mp_aframe *mpa) +{ + int format = af_fmt_from_planar(mp_aframe_get_format(mpa)); + if (format != AF_FORMAT_FLOAT && format != AF_FORMAT_DOUBLE) + return; + int num_planes = mp_aframe_get_planes(mpa); + uint8_t **planes = mp_aframe_get_data_rw(mpa); + if (!planes) + return; + for (int p = 0; p < num_planes; p++) { + void *ptr = planes[p]; + int total = mp_aframe_get_total_plane_samples(mpa); + switch (format) { + case AF_FORMAT_FLOAT: + for (int s = 0; s < total; s++) + sanitizef(((float *)ptr)[s]); + break; + case AF_FORMAT_DOUBLE: + for (int s = 0; s < total; s++) + sanitizef(((double *)ptr)[s]); + break; + } + } +} + // Return the timestamp of the sample just after the end of this frame. double mp_aframe_end_pts(struct mp_aframe *f) { @@ -448,13 +523,13 @@ void mp_aframe_clip_timestamps(struct mp_aframe *f, double start, double end) double rate = mp_aframe_get_effective_rate(f); if (f_end == MP_NOPTS_VALUE) return; - if (af_fmt_is_spdif(mp_aframe_get_format(f))) - return; if (end != MP_NOPTS_VALUE) { if (f_end >= end) { if (f->pts >= end) { f->av_frame->nb_samples = 0; } else { + if (af_fmt_is_spdif(mp_aframe_get_format(f))) + return; int new = (end - f->pts) * rate; f->av_frame->nb_samples = MPCLAMP(new, 0, f->av_frame->nb_samples); } @@ -466,6 +541,8 @@ void mp_aframe_clip_timestamps(struct mp_aframe *f, double start, double end) f->av_frame->nb_samples = 0; f->pts = f_end; } else { + if (af_fmt_is_spdif(mp_aframe_get_format(f))) + return; int skip = (start - f->pts) * rate; skip = MPCLAMP(skip, 0, f->av_frame->nb_samples); mp_aframe_skip_samples(f, skip); @@ -523,7 +600,7 @@ bool mp_aframe_set_silence(struct mp_aframe *f, int offset, int samples) bool mp_aframe_reverse(struct mp_aframe *f) { int format = mp_aframe_get_format(f); - size_t bps = af_fmt_to_bytes(format); + int bps = af_fmt_to_bytes(format); if (!af_fmt_is_pcm(format) || bps > 16) return false; @@ -592,7 +669,11 @@ int mp_aframe_pool_allocate(struct mp_aframe_pool *pool, struct mp_aframe *frame { int planes = mp_aframe_get_planes(frame); size_t sstride = mp_aframe_get_sstride(frame); - int plane_size = MP_ALIGN_UP(sstride * MPMAX(samples, 1), 32); + // FFmpeg hardcodes similar hidden possibly-requirements in a number of + // places: av_frame_get_buffer(), libavcodec's get_buffer(), mem.c, + // probably more. + int align_samples = MP_ALIGN_UP(MPMAX(samples, 1), 32); + int plane_size = MP_ALIGN_UP(sstride * align_samples, 64); int size = plane_size * planes; if (size <= 0 || mp_aframe_is_allocated(frame)) @@ -616,16 +697,23 @@ int mp_aframe_pool_allocate(struct mp_aframe_pool *pool, struct mp_aframe *frame AVFrame *av_frame = frame->av_frame; if (av_frame->extended_data != av_frame->data) av_freep(&av_frame->extended_data); // sigh - av_frame->extended_data = - av_mallocz_array(planes, sizeof(av_frame->extended_data[0])); - if (!av_frame->extended_data) - abort(); + if (planes > AV_NUM_DATA_POINTERS) { + av_frame->extended_data = + av_calloc(planes, sizeof(av_frame->extended_data[0])); + MP_HANDLE_OOM(av_frame->extended_data); + } else { + av_frame->extended_data = av_frame->data; + } av_frame->buf[0] = av_buffer_pool_get(pool->avpool); if (!av_frame->buf[0]) return -1; av_frame->linesize[0] = samples * sstride; for (int n = 0; n < planes; n++) av_frame->extended_data[n] = av_frame->buf[0]->data + n * plane_size; + if (planes > AV_NUM_DATA_POINTERS) { + for (int n = 0; n < AV_NUM_DATA_POINTERS; n++) + av_frame->data[n] = av_frame->extended_data[n]; + } av_frame->nb_samples = samples; return 0; diff --git a/audio/aframe.h b/audio/aframe.h index 21d4494f5f..d19c7e8bcb 100644 --- a/audio/aframe.h +++ b/audio/aframe.h @@ -20,6 +20,7 @@ struct AVFrame *mp_aframe_to_avframe_and_unref(struct mp_aframe *frame); struct AVFrame *mp_aframe_get_raw_avframe(struct mp_aframe *frame); bool mp_aframe_is_allocated(struct mp_aframe *frame); +bool mp_aframe_alloc_data(struct mp_aframe *frame, int samples); void mp_aframe_config_copy(struct mp_aframe *dst, struct mp_aframe *src); bool mp_aframe_config_equals(struct mp_aframe *a, struct mp_aframe *b); @@ -59,6 +60,7 @@ char *mp_aframe_format_str_buf(char *buf, size_t buf_size, struct mp_aframe *fmt #define mp_aframe_format_str(fmt) mp_aframe_format_str_buf((char[32]){0}, 32, (fmt)) void mp_aframe_skip_samples(struct mp_aframe *f, int samples); +void mp_aframe_sanitize_float(struct mp_aframe *f); double mp_aframe_end_pts(struct mp_aframe *f); double mp_aframe_duration(struct mp_aframe *f); void mp_aframe_clip_timestamps(struct mp_aframe *f, double start, double end); diff --git a/audio/audio_buffer.c b/audio/audio_buffer.c deleted file mode 100644 index a5591e1fe8..0000000000 --- a/audio/audio_buffer.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with mpv. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <stddef.h> -#include <limits.h> -#include <assert.h> - -#include "common/common.h" - -#include "chmap.h" -#include "audio_buffer.h" -#include "format.h" - -struct mp_audio_buffer { - int format; - struct mp_chmap channels; - int srate; - int sstride; - int num_planes; - uint8_t *data[MP_NUM_CHANNELS]; - int allocated; - int num_samples; -}; - -struct mp_audio_buffer *mp_audio_buffer_create(void *talloc_ctx) -{ - return talloc_zero(talloc_ctx, struct mp_audio_buffer); -} - -// Reinitialize the buffer, set a new format, drop old data. -// The audio data in fmt is not used, only the format. -void mp_audio_buffer_reinit_fmt(struct mp_audio_buffer *ab, int format, - const struct mp_chmap *channels, int srate) -{ - for (int n = 0; n < MP_NUM_CHANNELS; n++) - TA_FREEP(&ab->data[n]); - ab->format = format; - ab->channels = *channels; - ab->srate = srate; - ab->allocated = 0; - ab->num_samples = 0; - ab->sstride = af_fmt_to_bytes(ab->format); - ab->num_planes = 1; - if (af_fmt_is_planar(ab->format)) { - ab->num_planes = ab->channels.num; - } else { - ab->sstride *= ab->channels.num; - } -} - -// Make the total size of the internal buffer at least this number of samples. -void mp_audio_buffer_preallocate_min(struct mp_audio_buffer *ab, int samples) -{ - if (samples > ab->allocated) { - for (int n = 0; n < ab->num_planes; n++) { - ab->data[n] = talloc_realloc(ab, ab->data[n], char, - ab->sstride * samples); - } - ab->allocated = samples; - } -} - -// Get number of samples that can be written without forcing a resize of the -// internal buffer. -int mp_audio_buffer_get_write_available(struct mp_audio_buffer *ab) -{ - return ab->allocated - ab->num_samples; -} - -// All integer parameters are in samples. -// dst and src can overlap. -static void copy_planes(struct mp_audio_buffer *ab, - uint8_t **dst, int dst_offset, - uint8_t **src, int src_offset, int length) -{ - if (!length) - return; - - for (int n = 0; n < ab->num_planes; n++) { - memmove((char *)dst[n] + dst_offset * ab->sstride, - (char *)src[n] + src_offset * ab->sstride, - length * ab->sstride); - } -} - -// Append data to the end of the buffer. -// If the buffer is not large enough, it is transparently resized. -void mp_audio_buffer_append(struct mp_audio_buffer *ab, void **ptr, int samples) -{ - mp_audio_buffer_preallocate_min(ab, ab->num_samples + samples); - copy_planes(ab, ab->data, ab->num_samples, (uint8_t **)ptr, 0, samples); - ab->num_samples += samples; -} - -// Prepend silence to the start of the buffer. -void mp_audio_buffer_prepend_silence(struct mp_audio_buffer *ab, int samples) -{ - assert(samples >= 0); - mp_audio_buffer_preallocate_min(ab, ab->num_samples + samples); - copy_planes(ab, ab->data, samples, ab->data, 0, ab->num_samples); - ab->num_samples += samples; - for (int n = 0; n < ab->num_planes; n++) - af_fill_silence(ab->data[n], samples * ab->sstride, ab->format); -} - -void mp_audio_buffer_duplicate(struct mp_audio_buffer *ab, int samples) -{ - assert(samples >= 0 && samples <= ab->num_samples); - mp_audio_buffer_preallocate_min(ab, ab->num_samples + samples); - copy_planes(ab, ab->data, ab->num_samples, - ab->data, ab->num_samples - samples, samples); - ab->num_samples += samples; -} - -// Get the start of the current readable buffer. -void mp_audio_buffer_peek(struct mp_audio_buffer *ab, uint8_t ***ptr, - int *samples) -{ - *ptr = ab->data; - *samples = ab->num_samples; -} - -// Skip leading samples. (Used with mp_audio_buffer_peek() to read data.) -void mp_audio_buffer_skip(struct mp_audio_buffer *ab, int samples) -{ - assert(samples >= 0 && samples <= ab->num_samples); - copy_planes(ab, ab->data, 0, ab->data, samples, ab->num_samples - samples); - ab->num_samples -= samples; -} - -void mp_audio_buffer_clear(struct mp_audio_buffer *ab) -{ - ab->num_samples = 0; -} - -// Return number of buffered audio samples -int mp_audio_buffer_samples(struct mp_audio_buffer *ab) -{ - return ab->num_samples; -} - -// Return amount of buffered audio in seconds. -double mp_audio_buffer_seconds(struct mp_audio_buffer *ab) -{ - return ab->num_samples / (double)ab->srate; -} diff --git a/audio/audio_buffer.h b/audio/audio_buffer.h deleted file mode 100644 index 0d7b66a527..0000000000 --- a/audio/audio_buffer.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of mpv. - * - * mpv is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * mpv is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with mpv. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MP_AUDIO_BUFFER_H -#define MP_AUDIO_BUFFER_H - -struct mp_audio_buffer; -struct mp_chmap; - -struct mp_audio_buffer *mp_audio_buffer_create(void *talloc_ctx); -void mp_audio_buffer_reinit_fmt(struct mp_audio_buffer *ab, int format, - const struct mp_chmap *channels, int srate); -void mp_audio_buffer_preallocate_min(struct mp_audio_buffer *ab, int samples); -int mp_audio_buffer_get_write_available(struct mp_audio_buffer *ab); -void mp_audio_buffer_append(struct mp_audio_buffer *ab, void **ptr, int samples); -void mp_audio_buffer_prepend_silence(struct mp_audio_buffer *ab, int samples); -void mp_audio_buffer_duplicate(struct mp_audio_buffer *ab, int samples); -void mp_audio_buffer_peek(struct mp_audio_buffer *ab, uint8_t ***ptr, - int *samples); -void mp_audio_buffer_skip(struct mp_audio_buffer *ab, int samples); -void mp_audio_buffer_clear(struct mp_audio_buffer *ab); -int mp_audio_buffer_samples(struct mp_audio_buffer *ab); -double mp_audio_buffer_seconds(struct mp_audio_buffer *ab); - -#endif diff --git a/audio/chmap.c b/audio/chmap.c index edbe83eb68..a56d78dfe2 100644 --- a/audio/chmap.c +++ b/audio/chmap.c @@ -52,6 +52,11 @@ 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_TSL] = {"tsl", "top side left"}, + [MP_SPEAKER_ID_TSR] = {"tsr", "top side right"}, + [MP_SPEAKER_ID_BFC] = {"bfc", "bottom front center"}, + [MP_SPEAKER_ID_BFL] = {"bfl", "bottom front left"}, + [MP_SPEAKER_ID_BFR] = {"bfr", "bottom front right"}, [MP_SPEAKER_ID_NA] = {"na", "not available"}, }; @@ -83,7 +88,7 @@ static const char *const std_layout_names[][2] = { {"6.0(front)", "fl-fr-flc-frc-sl-sr"}, {"hexagonal", "fl-fr-fc-bl-br-bc"}, {"6.1", "fl-fr-fc-lfe-bc-sl-sr"}, - {"6.1(back)", "fl-fr-fc-lfe-bl-br-bc"}, // lavc calls this "6.1" too + {"6.1(back)", "fl-fr-fc-lfe-bl-br-bc"}, {"6.1(top)", "fl-fr-fc-lfe-bl-br-tc"}, // not in lavc {"6.1(front)", "fl-fr-lfe-flc-frc-sl-sr"}, {"7.0", "fl-fr-fc-bl-br-sl-sr"}, @@ -93,8 +98,13 @@ static const char *const std_layout_names[][2] = { {"7.1(alsa)", "fl-fr-bl-br-fc-lfe-sl-sr"}, // not in lavc {"7.1(wide)", "fl-fr-fc-lfe-bl-br-flc-frc"}, {"7.1(wide-side)", "fl-fr-fc-lfe-flc-frc-sl-sr"}, + {"7.1(top)", "fl-fr-fc-lfe-bl-br-tfl-tfr"}, {"7.1(rear)", "fl-fr-fc-lfe-bl-br-sdl-sdr"}, // not in lavc {"octagonal", "fl-fr-fc-bl-br-bc-sl-sr"}, + {"cube", "fl-fr-bl-br-tfl-tfr-tbl-tbr"}, + {"hexadecagonal", "fl-fr-fc-bl-br-bc-sl-sr-tfc-tfl-tfr-tbl-tbc-tbr-wl-wr"}, + {"downmix", "fl-fr"}, + {"22.2", "fl-fr-fc-lfe-bl-br-flc-frc-bc-sl-sr-tc-tfl-tfc-tfr-tbl-tbc-tbr-lfe2-tsl-tsr-bfc-bfl-bfr"}, {"auto", ""}, // not in lavc {0} }; @@ -229,8 +239,8 @@ void mp_chmap_set_unknown(struct mp_chmap *dst, int num_channels) } } -// Return the ffmpeg/libav channel layout as in <libavutil/channel_layout.h>. -// Speakers not representable by ffmpeg/libav are dropped. +// Return the ffmpeg channel layout as in <libavutil/channel_layout.h>. +// Speakers not representable by ffmpeg are dropped. // Warning: this ignores the order of the channels, and will return a channel // mask even if the order is different from libavcodec's. // Also, "unknown" channel maps are translated to non-sense channel @@ -253,7 +263,7 @@ uint64_t mp_chmap_to_lavc_unchecked(const struct mp_chmap *src) return mask; } -// Return the ffmpeg/libav channel layout as in <libavutil/channel_layout.h>. +// Return the ffmpeg channel layout as in <libavutil/channel_layout.h>. // Returns 0 if the channel order doesn't match lavc's or if it's invalid. uint64_t mp_chmap_to_lavc(const struct mp_chmap *src) { @@ -262,7 +272,7 @@ uint64_t mp_chmap_to_lavc(const struct mp_chmap *src) return mp_chmap_to_lavc_unchecked(src); } -// Set channel map from the ffmpeg/libav channel layout as in +// Set channel map from the ffmpeg channel layout as in // <libavutil/channel_layout.h>. // If the number of channels exceed MP_NUM_CHANNELS, set dst to empty. void mp_chmap_from_lavc(struct mp_chmap *dst, uint64_t src) @@ -470,6 +480,23 @@ char *mp_chmap_to_str_hr_buf(char *buf, size_t buf_size, const struct mp_chmap * return mp_chmap_to_str_buf(buf, buf_size, &map); } +mp_ch_layout_tuple *mp_iterate_builtin_layouts(void **opaque) +{ + uintptr_t i = (uintptr_t)*opaque; + + if (i >= MP_ARRAY_SIZE(std_layout_names) || + !std_layout_names[i][0]) + return NULL; + + *opaque = (void *)(i + 1); + + if (std_layout_names[i][1][0] == '\0') { + return mp_iterate_builtin_layouts(opaque); + } + + return &std_layout_names[i]; +} + void mp_chmap_print_help(struct mp_log *log) { mp_info(log, "Speakers:\n"); diff --git a/audio/chmap.h b/audio/chmap.h index dff69336d6..58a3f71907 100644 --- a/audio/chmap.h +++ b/audio/chmap.h @@ -22,7 +22,7 @@ #include <stdbool.h> #include "misc/bstr.h" -#define MP_NUM_CHANNELS 16 +#define MP_NUM_CHANNELS 64 // Speaker a channel can be assigned to. // This corresponds to WAVEFORMATEXTENSIBLE channel mask bit indexes. @@ -55,6 +55,11 @@ enum mp_speaker_id { MP_SPEAKER_ID_SDL, // SURROUND_DIRECT_LEFT MP_SPEAKER_ID_SDR, // SURROUND_DIRECT_RIGHT MP_SPEAKER_ID_LFE2, // LOW_FREQUENCY_2 + MP_SPEAKER_ID_TSL, // TOP_SIDE_LEFT + MP_SPEAKER_ID_TSR, // TOP_SIDE_RIGHT, + MP_SPEAKER_ID_BFC, // BOTTOM_FRONT_CENTER + MP_SPEAKER_ID_BFL, // BOTTOM_FRONT_LEFT + MP_SPEAKER_ID_BFR, // BOTTOM_FRONT_RIGHT // Speaker IDs >= 64 are not representable in WAVEFORMATEXTENSIBLE or libav*. @@ -75,6 +80,8 @@ struct mp_chmap { uint8_t speaker[MP_NUM_CHANNELS]; }; +typedef const char * const (mp_ch_layout_tuple)[2]; + #define MP_SP(speaker) MP_SPEAKER_ID_ ## speaker #define MP_CHMAP2(a, b) \ @@ -122,13 +129,28 @@ void mp_chmap_get_reorder(int src[MP_NUM_CHANNELS], const struct mp_chmap *from, int mp_chmap_diffn(const struct mp_chmap *a, const struct mp_chmap *b); char *mp_chmap_to_str_buf(char *buf, size_t buf_size, const struct mp_chmap *src); -#define mp_chmap_to_str(m) mp_chmap_to_str_buf((char[64]){0}, 64, (m)) +#define mp_chmap_to_str_(m, sz) mp_chmap_to_str_buf((char[sz]){0}, sz, (m)) +#define mp_chmap_to_str(m) mp_chmap_to_str_(m, MP_NUM_CHANNELS * 4) char *mp_chmap_to_str_hr_buf(char *buf, size_t buf_size, const struct mp_chmap *src); -#define mp_chmap_to_str_hr(m) mp_chmap_to_str_hr_buf((char[128]){0}, 128, (m)) +#define mp_chmap_to_str_hr_(m, sz) mp_chmap_to_str_hr_buf((char[sz]){0}, sz, |