[FFmpeg-devel] [RFC] Channel layouts
Aurelien Jacobs
aurel
Sat Aug 30 03:33:13 CEST 2008
Peter Ross wrote:
> On Fri, Aug 29, 2008 at 04:28:00PM +1000, Peter Ross wrote:
> > Hi.
> >
> > This patch adds the notion of channel layouts to libavcodec.
>
> Patch updated. Thanks for the feedback.
>
> Test wav/wma files for 7.1 and 5.1 can be found here:
> http://www.microsoft.com/windows/windowsmedia/howto/articles/Multichannel.aspx
>
> Audio coordinates space: my feeling is that this would be best implemented as
> an alternate/supplemental method of identifying the channel layout.
I agree. A function to map a list of coordinates to a list of channel
position should work fine in all common cases.
That can be added when needed.
> +void avcodec_get_channel_layout_string(char *buf, int buf_size, int nb_channels, int64_t channel_layout)
> +{
> + if (channel_layout==0)
> + channel_layout = avcodec_guess_channel_layout(nb_channels);
> + if (nb_channels==1 && channel_layout==CHANNEL_LAYOUT_MONO) {
> + snprintf(buf, buf_size, "mono");
> + }else if (nb_channels==2 && channel_layout==CHANNEL_LAYOUT_STEREO) {
> + snprintf(buf, buf_size, "stereo");
> + }else if (nb_channels==4 && channel_layout==CHANNEL_LAYOUT_QUAD) {
> + snprintf(buf, buf_size, "quad");
> + }else if (nb_channels==6 && channel_layout==CHANNEL_LAYOUT_5POINT1) {
> + snprintf(buf, buf_size, "5.1");
> + }else if (nb_channels==8 && channel_layout==(CHANNEL_LAYOUT_5POINT1|CHANNEL_LAYOUT_STEREO_DOWNMIX)) {
> + snprintf(buf, buf_size, "5.1+downmix");
> + }else if (nb_channels==8 && channel_layout==CHANNEL_LAYOUT_7POINT1) {
> + snprintf(buf, buf_size, "7.1");
> + }else if (nb_channels==8 && channel_layout==CHANNEL_LAYOUT_7POINT1_WIDE) {
> + snprintf(buf, buf_size, "7.1(wide)");
> + }else if (nb_channels==10 && channel_layout==(CHANNEL_LAYOUT_7POINT1|CHANNEL_LAYOUT_STEREO_DOWNMIX)) {
> + snprintf(buf, buf_size, "7.1+downmix");
> + }else{
Maybe this slightly ugly code could be replace with a
lookup table.
Something like:
static const struct {
int nb_channels;
int64_t layout;
char *string;
} layout_map[] = {
{ 1, CHANNEL_LAYOUT_MONO , "mono" },
{ 2, CHANNEL_LAYOUT_STEREO , "stereo" },
{ 4, CHANNEL_LAYOUT_QUAD , "quad" },
{ 6, CHANNEL_LAYOUT_5POINT1 , "5.1" },
{ 8, CHANNEL_LAYOUT_5POINT1|CHANNEL_LAYOUT_STEREO_DOWNMIX, "5.1+downmix" },
{ 8, CHANNEL_LAYOUT_7POINT1 , "7.1" },
{ 8, CHANNEL_LAYOUT_7POINT1_WIDE , "7.1(wide)" },
{ 10, CHANNEL_LAYOUT_7POINT1|CHANNEL_LAYOUT_STEREO_DOWNMIX, "7.1+downmix" },
{ 0 }
};
for (i=0; channel_layout_mapping[i].nb_channels; i++)
if (nb_channels == layout_map[i].nb_channels &&
channel_layout == layout_map[i].layout) {
snprintf(buf, buf_size, layout_map[i].string);
break;
}
Aurel
More information about the ffmpeg-devel
mailing list