[vlc-devel] commit: Factorized a bit es_out.c (Laurent Aimar )
git version control
git at videolan.org
Sun Mar 8 19:36:41 CET 2009
vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Sun Mar 8 15:59:27 2009 +0100| [8e787d7f2bbc87ce29881559f0665fc352326460] | committer: Laurent Aimar
Factorized a bit es_out.c
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8e787d7f2bbc87ce29881559f0665fc352326460
---
src/input/es_out.c | 80 ++++++++++++++++++++++------------------------------
1 files changed, 34 insertions(+), 46 deletions(-)
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 0e159b3..271dd59 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -1093,6 +1093,20 @@ static int EsOutProgramDel( es_out_t *out, int i_group )
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:
*/
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 )
{
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;
char *psz_cat;
const char *psz_title = NULL;
@@ -1132,16 +1146,9 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, vlc_meta_t *p_meta )
return;
}
/* Find program */
- for( i = 0; i < p_sys->i_pgrm; i++ )
- {
- if( p_sys->pgrm[i]->i_id == i_group )
- {
- p_pgrm = p_sys->pgrm[i];
- break;
- }
- }
- if( p_pgrm == NULL )
- p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
+ p_pgrm = EsOutProgramFind( out, i_group );
+ if( !p_pgrm )
+ return;
/* */
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 )
{
es_out_sys_t *p_sys = out->p_sys;
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;
int i;
/* Find program */
- for( i = 0; i < p_sys->i_pgrm; i++ )
- {
- if( p_sys->pgrm[i]->i_id == i_group )
- {
- p_pgrm = p_sys->pgrm[i];
- break;
- }
- }
- if( p_pgrm == NULL )
- p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
+ p_pgrm = EsOutProgramFind( out, i_group );
+ if( !p_pgrm )
+ return;
/* Merge EPG */
if( !p_pgrm->p_epg )
@@ -1349,8 +1349,8 @@ static es_out_id_t *EsOutAdd( es_out_t *out, const es_format_t *fmt )
return NULL;
}
- es_out_id_t *es = malloc( sizeof( *es ) );
- es_out_pgrm_t *p_pgrm = NULL;
+ es_out_id_t *es = malloc( sizeof( *es ) );
+ es_out_pgrm_t *p_pgrm;
int i;
if( !es )
@@ -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 );
/* Search the program */
- for( i = 0; i < p_sys->i_pgrm; i++ )
- {
- if( fmt->i_group == p_sys->pgrm[i]->i_id )
- {
- p_pgrm = p_sys->pgrm[i];
- break;
- }
- }
- if( p_pgrm == NULL )
+ p_pgrm = EsOutProgramFind( out, fmt->i_group );
+ if( !p_pgrm )
{
- /* Create a new one */
- p_pgrm = EsOutProgramAdd( out, fmt->i_group );
+ vlc_mutex_unlock( &p_sys->lock );
+ free( es );
+ return NULL;
}
/* Increase ref count for program */
@@ -2173,22 +2167,16 @@ static int EsOutControlLocked( es_out_t *out, int i_query, va_list args )
if( i_query == ES_OUT_SET_PCR )
{
p_pgrm = p_sys->p_pgrm;
+ if( !p_pgrm )
+ p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
}
else
{
- int i;
i_group = (int)va_arg( args, int );
- for( i = 0; i < p_sys->i_pgrm; i++ )
- {
- if( p_sys->pgrm[i]->i_id == i_group )
- {
- p_pgrm = p_sys->pgrm[i];
- break;
- }
- }
+ p_pgrm = EsOutProgramFind( out, i_group );
}
- if( p_pgrm == NULL )
- p_pgrm = EsOutProgramAdd( out, i_group ); /* Create it */
+ if( !p_pgrm )
+ return VLC_EGENERIC;
i_pcr = (int64_t)va_arg( args, int64_t );
/* search program
More information about the vlc-devel
mailing list