diff options
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/audioconvert.c | 41 | ||||
-rw-r--r-- | libavutil/audioconvert.h | 24 | ||||
-rw-r--r-- | libavutil/avutil.h | 2 |
3 files changed, 61 insertions, 6 deletions
diff --git a/libavutil/audioconvert.c b/libavutil/audioconvert.c index 7dc7e9f..e17f52e 100644 --- a/libavutil/audioconvert.c +++ b/libavutil/audioconvert.c @@ -182,11 +182,7 @@ void av_get_channel_layout_string(char *buf, int buf_size, int av_get_channel_layout_nb_channels(uint64_t channel_layout) { - int count; - uint64_t x = channel_layout; - for (count = 0; x; count++) - x &= x-1; // unset lowest set bit - return count; + return av_popcount64(channel_layout); } int64_t av_get_default_channel_layout(int nb_channels) { @@ -196,3 +192,38 @@ int64_t av_get_default_channel_layout(int nb_channels) { return channel_layout_map[i].layout; return 0; } + +int av_get_channel_layout_channel_index(uint64_t channel_layout, + uint64_t channel) +{ + if (!(channel_layout & channel) || + av_get_channel_layout_nb_channels(channel) != 1) + return AVERROR(EINVAL); + channel_layout &= channel - 1; + return av_get_channel_layout_nb_channels(channel_layout); +} + +const char *av_get_channel_name(uint64_t channel) +{ + int i; + if (av_get_channel_layout_nb_channels(channel) != 1) + return NULL; + for (i = 0; i < 64; i++) + if ((1ULL<<i) & channel) + return get_channel_name(i); + return NULL; +} + +uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index) +{ + int i; + + if (av_get_channel_layout_nb_channels(channel_layout) <= index) + return 0; + + for (i = 0; i < 64; i++) { + if ((1ULL << i) & channel_layout && !index--) + return 1ULL << i; + } + return 0; +} diff --git a/libavutil/audioconvert.h b/libavutil/audioconvert.h index 319cc8a..03e080c 100644 --- a/libavutil/audioconvert.h +++ b/libavutil/audioconvert.h @@ -150,6 +150,30 @@ int av_get_channel_layout_nb_channels(uint64_t channel_layout); int64_t av_get_default_channel_layout(int nb_channels); /** + * Get the index of a channel in channel_layout. + * + * @param channel a channel layout describing exactly one channel which must be + * present in channel_layout. + * + * @return index of channel in channel_layout on success, a negative AVERROR + * on error. + */ +int av_get_channel_layout_channel_index(uint64_t channel_layout, + uint64_t channel); + +/** + * Get the channel with the given index in channel_layout. + */ +uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index); + +/** + * Get the name of a given channel. + * + * @return channel name on success, NULL on error. + */ +const char *av_get_channel_name(uint64_t channel); + +/** * @} */ diff --git a/libavutil/avutil.h b/libavutil/avutil.h index 2e83d1f..02b9c7b 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -153,7 +153,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 51 -#define LIBAVUTIL_VERSION_MINOR 56 +#define LIBAVUTIL_VERSION_MINOR 57 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ |