[vlc-devel] [PATCHv2 07/13] input/input: move .sub/.idx/.cdg check

Thomas Guillem thomas at gllm.fr
Wed May 4 13:52:58 CEST 2016


Not good: comparing file extension with URI.

This check need to done per accesses and in subtitles.c where we know
the filename with extension for sure.

On Tue, May 3, 2016, at 19:02, Thomas Guillem wrote:
> This check can now be used for slaves coming from the demuxer.
> ---
>  src/input/input.c     | 60
>  ++++++++++++++++++++++++++++++++++++++++++++++++++-
>  src/input/subtitles.c | 46 ---------------------------------------
>  2 files changed, 59 insertions(+), 47 deletions(-)
> 
> diff --git a/src/input/input.c b/src/input/input.c
> index 9542985..5d1b379 100644
> --- a/src/input/input.c
> +++ b/src/input/input.c
> @@ -947,6 +947,64 @@ static int SlaveCompare(const void *a, const void
> *b)
>  #endif
>  }
>  
> +static void SlaveSort( input_item_slave **pp_slaves, int i_slaves )
> +{
> +    for( int i = 0; i < i_slaves; i++ )
> +    {
> +        input_item_slave *p_slave = pp_slaves[i];
> +
> +        if( p_slave == NULL || p_slave->i_type != SLAVE_TYPE_SPU )
> +            continue;
> +
> +        bool b_reject = false;
> +        char *psz_ext = strrchr( p_slave->psz_uri, '.' );
> +        if( !psz_ext )
> +            continue;
> +        psz_ext++;
> +
> +        if( !strcasecmp( psz_ext, "sub" ) )
> +        {
> +            /* Drop .sub slaves if a .idx exists */
> +            for( int j = 0; j < i_slaves; j++ )
> +            {
> +                input_item_slave *p_sub_inner = pp_slaves[j];
> +
> +                if( p_sub_inner == NULL )
> +                    continue;
> +
> +                /* check that the filenames without extension match */
> +                if( strncasecmp( p_slave->psz_uri, p_sub_inner->psz_uri,
> +                    strlen( p_slave->psz_uri ) - 3 ) )
> +                    continue;
> +
> +                char *psz_ext_inner = strrchr( p_sub_inner->psz_uri, '.'
> );
> +                if( !psz_ext_inner )
> +                    continue;
> +                psz_ext_inner++;
> +
> +                /* check that we have an idx file */
> +                if( !strcasecmp( psz_ext_inner, "idx" ) )
> +                {
> +                    b_reject = true;
> +                    break;
> +                }
> +            }
> +        }
> +        else if( !strcasecmp( psz_ext, "cdg" ) )
> +        {
> +            if( p_slave->i_priority < SLAVE_PRIORITY_MATCH_ALL )
> +                b_reject = true;
> +        }
> +        if( b_reject )
> +        {
> +            pp_slaves[i] = NULL;
> +            input_item_slave_Delete( p_slave );
> +        }
> +    }
> +
> +    qsort( pp_slaves, i_slaves, sizeof(input_item_slave*), SlaveCompare
> );
> +}
> +
>  static void LoadSubtitles( input_thread_t *p_input )
>  {
>      /* Load subtitles */
> @@ -1007,7 +1065,7 @@ static void LoadSubtitles( input_thread_t *p_input
> )
>          }
>          free( psz_autopath );
>  
> -        qsort( pp_slaves, i_slaves, sizeof(input_item_slave*),
> SlaveCompare );
> +        SlaveSort( pp_slaves, i_slaves );
>  
>          /* add all detected subtitles */
>          for( int i = 0; i < i_slaves && pp_slaves[i] != NULL; i++ )
> diff --git a/src/input/subtitles.c b/src/input/subtitles.c
> index 0803f5b..fb7c18a 100644
> --- a/src/input/subtitles.c
> +++ b/src/input/subtitles.c
> @@ -351,52 +351,6 @@ int subtitles_Detect( input_thread_t *p_this, char
> *psz_path, const char *psz_na
>      free( f_fname_noext );
>      free( psz_fname );
>  
> -    for( int i = 0; i < i_slaves; i++ )
> -    {
> -        input_item_slave *p_sub = pp_slaves[i];
> -
> -        bool b_reject = false;
> -        char *psz_ext = strrchr( p_sub->psz_uri, '.' );
> -        if( !psz_ext )
> -            continue;
> -        psz_ext++;
> -
> -        if( !strcasecmp( psz_ext, "sub" ) )
> -        {
> -            for( int j = 0; j < i_slaves; j++ )
> -            {
> -                input_item_slave *p_sub_inner = pp_slaves[j];
> -
> -                /* check that the filenames without extension match */
> -                if( strncasecmp( p_sub->psz_uri, p_sub_inner->psz_uri,
> -                    strlen( p_sub->psz_uri ) - 3 ) )
> -                    continue;
> -
> -                char *psz_ext_inner = strrchr( p_sub_inner->psz_uri, '.'
> );
> -                if( !psz_ext_inner )
> -                    continue;
> -                psz_ext_inner++;
> -
> -                /* check that we have an idx file */
> -                if( !strcasecmp( psz_ext_inner, "idx" ) )
> -                {
> -                    b_reject = true;
> -                    break;
> -                }
> -            }
> -        }
> -        else if( !strcasecmp( psz_ext, "cdg" ) )
> -        {
> -            if( p_sub->i_priority < SLAVE_PRIORITY_MATCH_ALL )
> -                b_reject = true;
> -        }
> -        if( b_reject )
> -        {
> -            pp_slaves[i] = NULL;
> -            input_item_slave_Delete( p_sub );
> -        }
> -    }
> -
>      *ppp_slaves = pp_slaves; /* in case of realloc */
>      *p_slaves = i_slaves;
>      return VLC_SUCCESS;
> -- 
> 2.8.0.rc3
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel


More information about the vlc-devel mailing list