[vlc-devel] [RFC PATCH 7/9] es_out: refactor EsOutProgramFind()
Thomas Guillem
thomas at gllm.fr
Thu Feb 13 10:12:37 CET 2020
On Wed, Feb 12, 2020, at 17:57, Rémi Denis-Courmont wrote:
> Le keskiviikkona 12. helmikuuta 2020, 16.43.25 EET Thomas Guillem a écrit :
> > Rename EsOutProgramFind() to EsOutProgramFindOrAdd().
>
> You can use "insert" (probably most common) or "search" (POSIX style) here.
It's better indeed, thanks!
>
> > Keep EsOutProgramFind() that will return NULL if the program is not found.
> >
> > This remove program search code duplication between EsOutProgramDel()
> > andEsOutProgramFind().
> >
> > This will be useful for next commits since the program search will become a
> > little more complicated.
> > ---
> > src/input/es_out.c | 54 +++++++++++++++++++++++-----------------------
> > 1 file changed, 27 insertions(+), 27 deletions(-)
> >
> > diff --git a/src/input/es_out.c b/src/input/es_out.c
> > index afb89b00e54..6a49be6ef75 100644
> > --- a/src/input/es_out.c
> > +++ b/src/input/es_out.c
> > @@ -1379,6 +1379,27 @@ static es_out_pgrm_t *EsOutProgramAdd( es_out_t *out,
> > int i_group ) return p_pgrm;
> > }
> >
> > +/* EsOutProgramFind
> > + */
> > +static es_out_pgrm_t *EsOutProgramFind( es_out_t *p_out, int i_group )
> > +{
> > + es_out_sys_t *p_sys = container_of(p_out, es_out_sys_t, out);
> > + es_out_pgrm_t *pgrm;
> > +
> > + vlc_list_foreach(pgrm, &p_sys->programs, node)
> > + if (pgrm->i_id == i_group)
> > + return pgrm;
> > + return NULL;
> > +}
> > +
> > +/* EsOutProgramFindOrAdd
> > + */
> > +static es_out_pgrm_t *EsOutProgramFindOrAdd( es_out_t *p_out, int i_group )
> > +{
> > + es_out_pgrm_t *pgrm = EsOutProgramFind( p_out, i_group );
> > + return pgrm ? pgrm : EsOutProgramAdd( p_out, i_group );
> > +}
> > +
> > /* EsOutDelProgram:
> > * Delete a program
> > */
> > @@ -1386,15 +1407,8 @@ static int EsOutProgramDel( es_out_t *out, int
> > i_group ) {
> > es_out_sys_t *p_sys = container_of(out, es_out_sys_t, out);
> > input_thread_t *p_input = p_sys->p_input;
> > - es_out_pgrm_t *p_pgrm = NULL, *pgrm;
> > -
> > - vlc_list_foreach(pgrm, &p_sys->programs, node)
> > - if (pgrm->i_id == i_group)
> > - {
> > - p_pgrm = pgrm;
> > - break;
> > - }
> >
> > + es_out_pgrm_t *p_pgrm = EsOutProgramFind( out, i_group );
> > if( p_pgrm == NULL )
> > return VLC_EGENERIC;
> >
> > @@ -1424,20 +1438,6 @@ 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 = container_of(p_out, es_out_sys_t, out);
> > - es_out_pgrm_t *pgrm;
> > -
> > - vlc_list_foreach(pgrm, &p_sys->programs, node)
> > - if (pgrm->i_id == i_group)
> > - return pgrm;
> > -
> > - return EsOutProgramAdd( p_out, i_group );
> > -}
> > -
> > /* EsOutProgramMeta:
> > */
> > static char *EsOutProgramGetMetaName( es_out_pgrm_t *p_pgrm )
> > @@ -1512,7 +1512,7 @@ static void EsOutProgramMeta( es_out_t *out, int
> > i_group, const vlc_meta_t *p_me /* Find program */
> > if( !EsOutIsProgramVisible( out, i_group ) )
> > return;
> > - p_pgrm = EsOutProgramFind( out, i_group );
> > + p_pgrm = EsOutProgramFindOrAdd( out, i_group );
> > if( !p_pgrm )
> > return;
> >
> > @@ -1621,7 +1621,7 @@ static void EsOutProgramEpgEvent( es_out_t *out, int
> > i_group, const vlc_epg_even /* Find program */
> > if( !EsOutIsProgramVisible( out, i_group ) )
> > return;
> > - p_pgrm = EsOutProgramFind( out, i_group );
> > + p_pgrm = EsOutProgramFindOrAdd( out, i_group );
> > if( !p_pgrm )
> > return;
> >
> > @@ -1639,7 +1639,7 @@ static void EsOutProgramEpg( es_out_t *out, int
> > i_group, const vlc_epg_t *p_epg /* Find program */
> > if( !EsOutIsProgramVisible( out, i_group ) )
> > return;
> > - p_pgrm = EsOutProgramFind( out, i_group );
> > + p_pgrm = EsOutProgramFindOrAdd( out, i_group );
> > if( !p_pgrm )
> > return;
> >
> > @@ -1917,7 +1917,7 @@ static es_out_id_t *EsOutAddLocked( es_out_t *out,
> > const es_format_t *fmt, es->fmt.i_original_fourcc = es->fmt.i_codec;
> >
> > /* Search the program */
> > - p_pgrm = EsOutProgramFind( out, fmt->i_group );
> > + p_pgrm = EsOutProgramFindOrAdd( out, fmt->i_group );
> > if( !p_pgrm )
> > {
> > es_format_Clean( &es->fmt );
> > @@ -3044,7 +3044,7 @@ static int EsOutVaControlLocked( es_out_t *out,
> > es_out_ctx_t *ctx, else
> > {
> > i_group = va_arg( args, int );
> > - p_pgrm = EsOutProgramFind( out, i_group );
> > + p_pgrm = EsOutProgramFindOrAdd( out, i_group );
> > }
> > if( !p_pgrm )
> > return VLC_EGENERIC;
>
>
> --
> 雷米‧德尼-库尔蒙
> http://www.remlab.net/
>
>
>
>
More information about the vlc-devel
mailing list