[vlc-devel] mms-asf.patch

Jean-Baptiste Kempf jb at videolan.org
Tue Jul 9 17:16:07 CEST 2013


On 09 Jul, Alain Degreffe wrote :
> Patch against vlc 2.0.7

Please rebase. Although it shoud not do anything.

> Will permit vlc to choose the best asf stream and the prefered
> language without using all mms stream options
> Better algo for bitrate sort


> Alain and Elodie

Who wrote the patch?

Please use git format-patch.

> --- asf.c	2013-07-09 16:52:23.068712154 +0200
> +++ ../New/asf.c	2013-07-09 16:24:44.000000000 +0200
> @@ -46,6 +46,9 @@
>      var_buffer_t buffer;
>      guid_t      guid;
>      uint64_t    i_size;
> +    

No trailing space, please.

> -    var_buffer_getmemory( &buffer, NULL, 30 - 16 );
> +    var_buffer_getmemory( &buffer, NULL, 30 - 16 ); 
idem

> @@ -93,8 +96,14 @@
>              int16_t i_count1, i_count2;
>              int i_subsize;
>  
> -            var_buffer_getmemory( &buffer, NULL, 84 - 24 );
> -
> +            var_buffer_getmemory( &buffer, NULL, 72 - 24);
> +            stream_number = var_buffer_get16( &buffer);
> +            lang_ID = var_buffer_get16( &buffer);
> +            
> +            hdr->stream[stream_number].i_lang_id = ( int ) lang_ID;
Do you need this cast?

> -        else if( guidcmp( &guid, &asf_object_stream_properties_guid ) )
> +        else if( guidcmp ( &guid, &asf_object_stream_properties_guid ) )

Useless change.

> +        else if ( guidcmp( &guid, &asf_object_language_list ) )

Nitpick: style

> +        {
> +            int  i_count;
> +            uint64_t i_langid_len;
> +            char * s_lang_str;
> +            int i_current_id;
> +            i_count = var_buffer_get16( &buffer );
> +
> +            for ( i_current_id = 0 ; i_current_id < i_count ; i_current_id++ )
> +            {
> +                i_langid_len = var_buffer_get8( &buffer );
> +                s_lang_str = malloc ( i_langid_len/2  * sizeof ( char ) );

Please check malloc return. And remove this sizeof horror.

> +                uint64_t i ;
> +                uint16_t c;

What is the use of c?

> +                for ( i = 0 ; i < i_langid_len ; i = i+2) 
style

> +                {
> +                    c = var_buffer_get16 ( &buffer );
> +                    s_lang_str[i/2]=GetWLE ( &c );
style

> +                }
> +                s_lang_str[i/2] = '\0';
> +                hdr->tablang[i_current_id] = malloc( i/2 * sizeof ( char ) ) ;

as above.

> +                memcpy ( hdr->tablang[i_current_id] , s_lang_str, i/2 + 1 );
> +                free( s_lang_str ) ;
> +            }
> +        }    
> +

> +void asf_ClearCandidate ( asf_candidate_t *cell )
> +{
> +    asf_candidate_t * tmp ;
> +    while (cell->is_next == 1)
> +    {
> +        tmp = cell ; 
> +        cell = tmp->next ;
> +        free(tmp);
> +    }
> +    free(cell); 
> +}
> +
>  void  asf_StreamSelect  ( asf_header_t *hdr,
>                                int i_bitrate_max,
> -                              bool b_all, bool b_audio, bool b_video )
> +                              bool b_all, bool b_audio, bool b_video , char * lang )
>  {
>      /* XXX FIXME use mututal eclusion information */
>      unsigned i;
>      int i_audio, i_video;
> -    int i_bitrate_total;
> +    int i_bitrate_var, i_bitrate_total;
>  #if 0
>      char *psz_stream;
>  #endif
>  
> -    i_audio = 0;
> -    i_video = 0;
> -    i_bitrate_total = 0;
>      if( b_all )
>      {
>          /* select all valid stream */
> @@ -214,78 +259,137 @@
>          }
>      }
>  
> -    /* big test:
> -     * select a stream if
> -     *    - no audio nor video stream
> -     *    - or:
> -     *         - if i_bitrate_max not set keep the highest bitrate
> -     *         - if i_bitrate_max is set, keep stream that make we used best
> -     *           quality regarding i_bitrate_max
> -     *
> -     * XXX: little buggy:
> -     *        - it doesn't use mutual exclusion info..
> -     *        - when selecting a better stream we could select
> -     *        something that make i_bitrate_total> i_bitrate_max
> -     */
> -    for( i = 1; i < 128; i++ )
> +    i_audio = -1;
> +    i_video = -1;
> +    i_bitrate_total = 0;
> +    i_bitrate_var = 0;
> +
> +    asf_candidate_t  * head_Candidatefavlang, * courant_Candidatefavlang ;
> +    asf_candidate_t  * head_Candidateotherlang,  * courant_Candidateotherlang ;
> +    asf_candidate_t  * head_CandidateVideo, * courant_CandidateVideo ;
> +
> +    head_Candidatefavlang = malloc( sizeof ( asf_candidate_t ) ) ;
See above.

> +    head_Candidatefavlang->is_next = 0;
> +    courant_Candidatefavlang = head_Candidatefavlang;
> +	    

No tabs in source code.

> +    head_Candidateotherlang = malloc( sizeof ( asf_candidate_t ) ) ;

See above.

> +    head_Candidateotherlang->is_next = 0;
> +    courant_Candidateotherlang = head_Candidateotherlang;
> +
> +    head_CandidateVideo = malloc( sizeof ( asf_candidate_t ) ) ;
> +    head_CandidateVideo->is_next = 0;
> +    courant_CandidateVideo = head_CandidateVideo;
> +
> +    for( i = 1 ; i < 128 ; i++ )
>      {
>          if( hdr->stream[i].i_cat == ASF_STREAM_UNKNOWN )
>          {
>              continue;
>          }
> -        else if( hdr->stream[i].i_cat == ASF_STREAM_AUDIO && b_audio &&
> -                 ( i_audio <= 0 ||
> -                    ( ( ( hdr->stream[i].i_bitrate > hdr->stream[i_audio].i_bitrate &&
> -                          ( i_bitrate_total + hdr->stream[i].i_bitrate - hdr->stream[i_audio].i_bitrate
> -                                            < i_bitrate_max || !i_bitrate_max) ) ||
> -                        ( hdr->stream[i].i_bitrate < hdr->stream[i_audio].i_bitrate &&
> -                              i_bitrate_max != 0 && i_bitrate_total > i_bitrate_max )
> -                      ) )  ) )
> +      
> +        /* audio */ 
> +        if ( hdr->stream[i].i_cat == ASF_STREAM_AUDIO && b_audio && ( hdr->stream[i].i_bitrate < i_bitrate_max || !i_bitrate_max ) )
> +        {
> +            if (lang != NULL && strcmp ( hdr->tablang[hdr->stream[i].i_lang_id], lang ) == 0 )
> +            {
> +                courant_Candidatefavlang->value = i ;
> +                courant_Candidatefavlang->is_next = 1 ;
> +                courant_Candidatefavlang->next  = malloc ( sizeof ( asf_candidate_t ) ) ;
> +                courant_Candidatefavlang = courant_Candidatefavlang->next ;
> +                courant_Candidatefavlang->is_next = 0 ;	    
> +            }
> +            else
> +            { 
> +                courant_Candidateotherlang->value = i ;
> +                courant_Candidateotherlang->is_next = 1 ;
> +                courant_Candidateotherlang->next  = malloc ( sizeof ( asf_candidate_t ) ) ;
> +                courant_Candidateotherlang = courant_Candidateotherlang->next ;
> +                courant_Candidateotherlang->is_next = 0 ;	
> +            }
> +        }

A bit of code duplication here...

> +        /* video */
> +        if ( hdr->stream[i].i_cat == ASF_STREAM_VIDEO && b_video && ( hdr->stream[i].i_bitrate < i_bitrate_max || !i_bitrate_max ) )
> +        {
> +            courant_CandidateVideo->value = i ;
> +            courant_CandidateVideo->is_next = 1 ;
> +            courant_CandidateVideo->next  = malloc ( sizeof ( asf_candidate_t ) ) ;
> +            courant_CandidateVideo = courant_CandidateVideo->next ;
> +            courant_CandidateVideo->is_next = 0 ;
> +        }
> +        else
>          {
> -            /* unselect old stream */
> -            if( i_audio > 0 )
> +            continue;
> +        }
> +    }
> +    
> +    if ( head_Candidatefavlang->is_next == 0 )
> +    {
> +        courant_Candidateotherlang = head_Candidateotherlang ;
> +        courant_CandidateVideo = head_CandidateVideo ;
> +        while ( courant_Candidateotherlang->is_next == 1 )
> +        {
> +            while (courant_CandidateVideo->is_next == 1 )
>              {
> -                hdr->stream[i_audio].i_selected = 0;
> -                if( hdr->stream[i_audio].i_bitrate> 0 )
> +                i_bitrate_var = hdr->stream[courant_Candidateotherlang->value].i_bitrate + hdr->stream[courant_CandidateVideo->value].i_bitrate;
> +                if (i_bitrate_var > i_bitrate_total && ( !i_bitrate_max || i_bitrate_var < i_bitrate_max) )
>                  {
> -                    i_bitrate_total -= hdr->stream[i_audio].i_bitrate;
> +                    i_audio = courant_Candidateotherlang->value;
> +                    i_video = courant_CandidateVideo->value;
> +                    i_bitrate_total = i_bitrate_var;
>                  }
> +                head_CandidateVideo = courant_CandidateVideo ;
> +                courant_CandidateVideo = courant_CandidateVideo->next ;
>              }
>  
> -            hdr->stream[i].i_selected = 1;
> -            if( hdr->stream[i].i_bitrate> 0 )
> +            i_bitrate_var = hdr->stream[courant_Candidateotherlang->value].i_bitrate ;
> +            if ( i_bitrate_var > i_bitrate_total && ( !i_bitrate_max || i_bitrate_var < i_bitrate_max ) )
>              {
> -                i_bitrate_total += hdr->stream[i].i_bitrate;
> +                i_audio = courant_Candidateotherlang->value;
> +                i_bitrate_total = i_bitrate_var;
>              }
> -            i_audio = i;
> +            head_Candidateotherlang = courant_Candidateotherlang ;
> +            courant_Candidateotherlang = courant_Candidateotherlang->next ;
>          }
> -        else if( hdr->stream[i].i_cat == ASF_STREAM_VIDEO && b_video &&
> -                 ( i_video <= 0 ||
> -                    (
> -                        ( ( hdr->stream[i].i_bitrate > hdr->stream[i_video].i_bitrate &&
> -                            ( i_bitrate_total + hdr->stream[i].i_bitrate - hdr->stream[i_video].i_bitrate
> -                                            < i_bitrate_max || !i_bitrate_max) ) ||
> -                          ( hdr->stream[i].i_bitrate < hdr->stream[i_video].i_bitrate &&
> -                            i_bitrate_max != 0 && i_bitrate_total > i_bitrate_max )
> -                        ) ) )  )
> +    }
> +    
> +    else
> +    {
> +        courant_Candidatefavlang = head_Candidatefavlang ;
> +        courant_CandidateVideo = head_CandidateVideo ;
> +        while ( courant_Candidatefavlang->is_next == 1 )
>          {
> -            /* unselect old stream */
> -            if( i_video > 0 )
> +            while (courant_CandidateVideo->is_next == 1)
>              {
> -                hdr->stream[i_video].i_selected = 0;
> -                if( hdr->stream[i_video].i_bitrate> 0 )
> +                i_bitrate_var = hdr->stream[courant_Candidatefavlang->value].i_bitrate + hdr->stream[courant_CandidateVideo->value].i_bitrate;
> +                if (i_bitrate_var > i_bitrate_total && ( !i_bitrate_max  || i_bitrate_var < i_bitrate_max ) )
>                  {
> -                    i_bitrate_total -= hdr->stream[i_video].i_bitrate;
> +                    i_audio = courant_Candidatefavlang->value;
> +                    i_video = courant_CandidateVideo->value;
> +                    i_bitrate_total = i_bitrate_var;
>                  }
> +                head_CandidateVideo = courant_CandidateVideo ;
> +                courant_CandidateVideo = courant_CandidateVideo->next ;
>              }
>  
> -            hdr->stream[i].i_selected = 1;
> -            if( hdr->stream[i].i_bitrate> 0 )
> +            i_bitrate_var = hdr->stream[courant_Candidatefavlang->value].i_bitrate ;
> +            if (i_bitrate_var > i_bitrate_total && ( !i_bitrate_max || i_bitrate_var < i_bitrate_max ) )
>              {
> -                i_bitrate_total += hdr->stream[i].i_bitrate;
> +                i_audio = courant_Candidatefavlang->value;
> +                i_bitrate_total = i_bitrate_var;
>              }
> -            i_video = i;
> +            
> +            head_Candidatefavlang = courant_Candidatefavlang ;
> +            courant_Candidatefavlang = courant_Candidatefavlang->next ;
>          }
> -
>      }
> + 
> +    /* select stream */
> +    if ( i_audio != -1 ) hdr->stream[i_audio].i_selected = 1;
> +    if ( i_video != -1 ) hdr->stream[i_video].i_selected = 1;
> +   
> +    /* clear structures */
> +    asf_ClearCandidate( head_Candidatefavlang );
> +    asf_ClearCandidate( head_Candidateotherlang );
> +    asf_ClearCandidate( head_CandidateVideo );
>  }
> --- asf.h	2013-07-09 16:52:23.068712154 +0200
> +++ ../New/asf.h	2013-07-09 14:45:14.000000000 +0200
> @@ -42,6 +42,7 @@
>      int i_cat;      /* ASF_STREAM_VIDEO, ASF_STREAM_AUDIO */
>      int i_bitrate;  /* -1 if unknown */
>      int i_selected;
> +    int i_lang_id;
>  } asf_stream_t;
>  
>  typedef struct
> @@ -52,13 +53,21 @@
>  
>      asf_stream_t stream[128];
>  
> +    char * tablang[128];
>  } asf_header_t;
>  
> +typedef struct asf_candidate_t
> +{
> +    int value ;

Sure that int is the best option here?

> +    int is_next ;

Use bool.

> +    struct asf_candidate_t *next ;
> +} asf_candidate_t ;
>  
>  void  GenerateGuid      ( guid_t * );
> +void  asf_ClearCandidate ( asf_candidate_t *);
>  void  asf_HeaderParse   ( asf_header_t *, uint8_t *, int );
>  void  asf_StreamSelect  ( asf_header_t *,
>                                int i_bitrate_max, bool b_all, bool b_audio,
> -                              bool b_video );
> +                              bool b_video , char * lang );
>  
>  #endif
> --- mmsh.c	2013-07-09 16:52:23.068712154 +0200
> +++ ../New/mmsh.c	2013-07-09 16:07:22.000000000 +0200
> @@ -464,9 +464,10 @@
>                         var_InheritInteger( p_access, "mms-maxbitrate" ),
>                         var_InheritBool( p_access, "mms-all" ),
>                         var_InheritBool( p_access, "audio" ),
> -                       var_InheritBool( p_access, "video" ) );
> +                       var_InheritBool( p_access, "video" ),
> +                       var_InheritString( p_access->p_parent, "audio-language" ) );
>  
> -    /* Check we have comptible asfh */
> +    /* Check we have compatible asfh */
>      for( i = 1; i < 128; i++ )
>      {
>          asf_stream_t *p_old = &old_asfh.stream[i];
> @@ -698,7 +699,7 @@
>      /* close this connection */
>      net_Close( p_sys->fd );
>      p_sys->fd = -1;
> -
> + 
Useless

>      /* *** parse header and get stream and their id *** */
>      /* get all streams properties,
>       *
> @@ -709,6 +710,7 @@
>      msg_Dbg( p_access, "packet count=%"PRId64" packet size=%d",
>               p_sys->asfh.i_data_packets_count,
>               p_sys->asfh.i_min_data_packet_size );
> +    msg_Dbg( p_access, "language to choose: %s", var_InheritString( p_access->p_parent, "audio-language" ) );
>  
>      if( p_sys->asfh.i_min_data_packet_size <= 0 )
>          goto error;
> @@ -717,7 +719,8 @@
>                         var_InheritInteger( p_access, "mms-maxbitrate" ),
>                         var_InheritBool( p_access, "mms-all" ),
>                         var_InheritBool( p_access, "audio" ),
> -                       var_InheritBool( p_access, "video" ) );
> +                       var_InheritBool( p_access, "video" ),
> +                       var_InheritString( p_access->p_parent, "audio-language" ) );
>      return VLC_SUCCESS;
>  
>  error:
> @@ -823,7 +826,7 @@
>                  i_select = 0;
>              }
>              net_Printf( p_access, p_sys->fd, NULL,
> -                        "ffff:%d:%d ", i, i_select );
> +                        "ffff:%x:%d ", i, i_select );

This should be in a different patch

>          }
>      }
>      net_Printf( p_access, p_sys->fd, NULL, "\r\n" );
> --- mmstu.c	2013-07-09 16:52:23.068712154 +0200
> +++ ../New/mmstu.c	2013-06-28 15:15:30.000000000 +0200
> @@ -791,7 +791,8 @@
>                             var_InheritInteger( p_access, "mms-maxbitrate" ),
>                             var_InheritBool( p_access, "mms-all" ),
>                             var_InheritBool( p_access, "audio" ),
> -                           var_InheritBool( p_access, "video" ) );
> +                           var_InheritBool( p_access, "video" ),
> +                           var_InheritString( p_access->p_parent, "audio-language" ) );
>  
>      /* *** now select stream we want to receive *** */
>      /* TODO take care of stream bitrate TODO */

> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> http://mailman.videolan.org/listinfo/vlc-devel


-- 
Best regards,

-- 
Jean-Baptiste Kempf
http://www.jbkempf.com/ - +33 672 704 734
Sent from my Electronic Device



More information about the vlc-devel mailing list