From 4ee261a441c645849caeae9a5cc3c6df9fa834af Mon Sep 17 00:00:00 2001 From: Francois Cartegnie Date: Tue, 18 Dec 2018 16:21:02 +0100 Subject: [PATCH] demux: mp4: use static mapping table per layout --- modules/demux/mp4/coreaudio.h | 16 +++++++++++++--- modules/demux/mp4/essetup.c | 38 +++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/modules/demux/mp4/coreaudio.h b/modules/demux/mp4/coreaudio.h index 1852ffeca6..e77dfcc3e0 100644 --- a/modules/demux/mp4/coreaudio.h +++ b/modules/demux/mp4/coreaudio.h @@ -42,6 +42,16 @@ enum CoreAudio_Bitmap_TOPBACKRIGHT = (1<<17), }; +static const uint32_t pi_vlc_chan_order_CoreAudio[] = +{ + AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER, + AOUT_CHAN_LFE, + AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, + AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_REARCENTER, + AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT, + 0 +}; + static const struct { uint32_t i_bitmap; @@ -76,8 +86,9 @@ enum CoreAudio_Layout static inline int CoreAudio_Bitmap_to_vlc_bitmap( uint32_t i_corebitmap, uint16_t *pi_mapping, uint8_t *pi_channels, - uint32_t p_chans[AOUT_CHAN_MAX + 1] ) + const uint32_t **pp_chans_order ) { + *pp_chans_order = pi_vlc_chan_order_CoreAudio; *pi_mapping = 0; *pi_channels = 0; for (uint8_t i=0;ilayout.i_channels_layout_tag == CoreAudio_Layout_BITMAP ) + uint16_t i_vlc_mapping = 0; + uint8_t i_channels = 0; + const uint32_t *p_rg_chans_order = NULL; + + if ( BOXDATA(p_chan)->layout.i_channels_layout_tag == CoreAudio_Layout_BITMAP && + CoreAudio_Bitmap_to_vlc_bitmap( BOXDATA(p_chan)->layout.i_channels_bitmap, + &i_vlc_mapping, &i_channels, + &p_rg_chans_order ) != VLC_SUCCESS ) { - uint32_t rgi_chans_sequence[AOUT_CHAN_MAX + 1]; - memset(rgi_chans_sequence, 0, sizeof(rgi_chans_sequence)); - uint16_t i_vlc_mapping = 0; - uint8_t i_channels = 0; - - if( CoreAudio_Bitmap_to_vlc_bitmap( BOXDATA(p_chan)->layout.i_channels_bitmap, - &i_vlc_mapping, &i_channels, - rgi_chans_sequence ) != VLC_SUCCESS ) - { - msg_Warn( p_demux, "discarding chan mapping" ); - } - - if( aout_CheckChannelReorder( rgi_chans_sequence, NULL, i_vlc_mapping, - p_track->rgi_chans_reordering ) && - aout_BitsPerSample( p_track->fmt.i_codec ) ) - { - p_track->b_chans_reorder = true; - p_track->fmt.audio.i_channels = i_channels; - p_track->fmt.audio.i_physical_channels = i_vlc_mapping; - } + msg_Warn( p_demux, "discarding chan mapping" ); + } + if( aout_BitsPerSample( p_track->fmt.i_codec ) && i_vlc_mapping > 0 && + aout_CheckChannelReorder( p_rg_chans_order, NULL, i_vlc_mapping, + p_track->rgi_chans_reordering ) ) + { + p_track->b_chans_reorder = true; + p_track->fmt.audio.i_channels = i_channels; + p_track->fmt.audio.i_physical_channels = i_vlc_mapping; } } -- 2.11.4.GIT