Commit 8e787d7f authored by Laurent Aimar's avatar Laurent Aimar

Factorized a bit es_out.c

parent 161e1a95
...@@ -1093,6 +1093,20 @@ static int EsOutProgramDel( es_out_t *out, int i_group ) ...@@ -1093,6 +1093,20 @@ static int EsOutProgramDel( es_out_t *out, int i_group )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
/* EsOutProgramFind
*/
static es_out_pgrm_t *EsOutProgramFind( es_out_t *p_out, int i_group )
{
es_out_sys_t *p_sys = p_out->p_sys;
for( int i = 0; i < p_sys->i_pgrm; i++ )
{
if( p_sys->pgrm[i]->i_id == i_group )
return p_sys->pgrm[i];
}
return EsOutProgramAdd( p_out, i_group );
}
/* EsOutProgramMeta: /* EsOutProgramMeta:
*/ */
static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm ) static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm )
...@@ -1114,7 +1128,7 @@ static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm ) ...@@ -1114,7 +1128,7 @@ static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm )
static void EsOutProgramMeta( es_out_t *out, int i_group, vlc_meta_t *p_meta ) static void EsOutProgramMeta( es_out_t *out, int i_group, vlc_meta_t *p_meta )
{ {
es_out_sys_t *p_sys = out->p_sys; es_out_sys_t *p_sys = out->p_sys;
es_out_pgrm_t *p_pgrm = NULL; es_out_pgrm_t *p_pgrm;
input_thread_t *p_input = p_sys->p_input; input_thread_t *p_input = p_sys->p_input;
char *psz_cat; char *psz_cat;
const char *psz_title = NULL; const char *psz_title = NULL;
...@@ -1132,16 +1146,9 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, vlc_meta_t *p_meta ) ...@@ -1132,16 +1146,9 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, vlc_meta_t *p_meta )
return; return;
} }
/* Find program */ /* Find program */
for( i = 0; i < p_sys->i_pgrm; i++ ) p_pgrm = EsOutProgramFind( out, i_group );
{ if( !p_pgrm )
if( p_sys->pgrm[i]->i_id == i_group ) return;
{
p_pgrm = p_sys->pgrm[i];
break;
}
}
if( p_pgrm == NULL )
p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
/* */ /* */
psz_title = vlc_meta_Get( p_meta, vlc_meta_Title); psz_title = vlc_meta_Get( p_meta, vlc_meta_Title);
...@@ -1255,21 +1262,14 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, vlc_epg_t *p_epg ) ...@@ -1255,21 +1262,14 @@ static void EsOutProgramEpg( es_out_t *out, int i_group, vlc_epg_t *p_epg )
{ {
es_out_sys_t *p_sys = out->p_sys; es_out_sys_t *p_sys = out->p_sys;
input_thread_t *p_input = p_sys->p_input; input_thread_t *p_input = p_sys->p_input;
es_out_pgrm_t *p_pgrm = NULL; es_out_pgrm_t *p_pgrm;
char *psz_cat; char *psz_cat;
int i; int i;
/* Find program */ /* Find program */
for( i = 0; i < p_sys->i_pgrm; i++ ) p_pgrm = EsOutProgramFind( out, i_group );
{ if( !p_pgrm )
if( p_sys->pgrm[i]->i_id == i_group ) return;
{
p_pgrm = p_sys->pgrm[i];
break;
}
}
if( p_pgrm == NULL )
p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
/* Merge EPG */ /* Merge EPG */
if( !p_pgrm->p_epg ) if( !p_pgrm->p_epg )
...@@ -1350,7 +1350,7 @@ static es_out_id_t *EsOutAdd( es_out_t *out, const es_format_t *fmt ) ...@@ -1350,7 +1350,7 @@ static es_out_id_t *EsOutAdd( es_out_t *out, const es_format_t *fmt )
} }
es_out_id_t *es = malloc( sizeof( *es ) ); es_out_id_t *es = malloc( sizeof( *es ) );
es_out_pgrm_t *p_pgrm = NULL; es_out_pgrm_t *p_pgrm;
int i; int i;
if( !es ) if( !es )
...@@ -1359,18 +1359,12 @@ static es_out_id_t *EsOutAdd( es_out_t *out, const es_format_t *fmt ) ...@@ -1359,18 +1359,12 @@ static es_out_id_t *EsOutAdd( es_out_t *out, const es_format_t *fmt )
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
/* Search the program */ /* Search the program */
for( i = 0; i < p_sys->i_pgrm; i++ ) p_pgrm = EsOutProgramFind( out, fmt->i_group );
{ if( !p_pgrm )
if( fmt->i_group == p_sys->pgrm[i]->i_id )
{
p_pgrm = p_sys->pgrm[i];
break;
}
}
if( p_pgrm == NULL )
{ {
/* Create a new one */ vlc_mutex_unlock( &p_sys->lock );
p_pgrm = EsOutProgramAdd( out, fmt->i_group ); free( es );
return NULL;
} }
/* Increase ref count for program */ /* Increase ref count for program */
...@@ -2173,22 +2167,16 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args ) ...@@ -2173,22 +2167,16 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
if( i_query == ES_OUT_SET_PCR ) if( i_query == ES_OUT_SET_PCR )
{ {
p_pgrm = p_sys->p_pgrm; p_pgrm = p_sys->p_pgrm;
if( !p_pgrm )
p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
} }
else else
{ {
int i;
i_group = (int)va_arg( args, int ); i_group = (int)va_arg( args, int );
for( i = 0; i < p_sys->i_pgrm; i++ ) p_pgrm = EsOutProgramFind( out, i_group );
{
if( p_sys->pgrm[i]->i_id == i_group )
{
p_pgrm = p_sys->pgrm[i];
break;
}
}
} }
if( p_pgrm == NULL ) if( !p_pgrm )
p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */ return VLC_EGENERIC;
i_pcr = (int64_t)va_arg( args, int64_t ); i_pcr = (int64_t)va_arg( args, int64_t );
/* search program /* search program
......
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