Commit 36cb0f52 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: mp4: add minimal support for exclusive tracks

VLC supports groups where mp4 defines switch groups.
As an es can't belong to multiple groups, but does in
switch groups, we don't really have a way to provide
the same track exclusion/alternative features without
duplicating es.

Priorities are then set in a way es/tracks from the same
cat/switchgroup are not all selected.

refs #3970
parent 7a3abe03
......@@ -37,6 +37,7 @@
#include <vlc_input.h>
#include <vlc_aout.h>
#include <assert.h>
#include <limits.h>
/*****************************************************************************
* Module descriptor
......@@ -2680,6 +2681,29 @@ static void MP4_TrackCreate( demux_t *p_demux, mp4_track_t *p_track,
p_track->b_enable = true;
p_track->fmt.i_priority = ES_PRIORITY_SELECTABLE_MIN;
}
else
{
const MP4_Box_t *p_tsel = MP4_BoxGet( p_box_trak, "udta/tsel" );
if ( p_tsel && BOXDATA(p_tsel) && BOXDATA(p_tsel)->i_switch_group )
{
p_track->i_switch_group = BOXDATA(p_tsel)->i_switch_group;
int i_priority = ES_PRIORITY_SELECTABLE_MIN;
for ( unsigned int i = 0; i < p_sys->i_tracks; i++ )
{
const mp4_track_t *p_other = &p_sys->track[i];
if( p_other && p_other != p_track &&
p_other->fmt.i_cat == p_track->fmt.i_cat &&
p_track->i_switch_group == p_other->i_switch_group )
i_priority = __MAX( i_priority, p_other->fmt.i_priority + 1 );
}
/* VLC only support ES priority for AUDIO_ES and SPU_ES.
If there's another VIDEO_ES in the same group, we need to unselect it then */
if ( p_track->fmt.i_cat == VIDEO_ES && i_priority > ES_PRIORITY_SELECTABLE_MIN )
p_track->fmt.i_priority = ES_PRIORITY_NOT_DEFAULTABLE;
else
p_track->fmt.i_priority = i_priority;
}
}
p_track->p_es = NULL;
if( TrackCreateES( p_demux,
......
......@@ -70,6 +70,7 @@ typedef struct
int b_enable; /* is the trak enable by default */
bool b_selected; /* is the trak being played */
bool b_chapter; /* True when used for chapter only */
uint32_t i_switch_group;
bool b_mac_encoding;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment