Changeset 3a60f493856344c3c11cb7401111dfbf7344ae92

Show
Ignore:
Timestamp:
18/01/04 03:20:28 (5 years ago)
Author:
Laurent Aimar <fenrir@videolan.org>
git-committer:
Laurent Aimar <fenrir@videolan.org> 1074392428 +0000
git-parent:

[f92f94bc18b2019269a3a2462db50a49bca9724f]

git-author:
Laurent Aimar <fenrir@videolan.org> 1074392428 +0000
Message:
  • duplicate : added a select option :) The format is
    selector[,selector] where 'selector' are from:
    • no-audio, noaudio, audio
    • no-video, novideo, video
    • no-spu, nospu, spu
    • es=num or es=num_start-num_end
    • prgm=num or prgm=num_start-num_end (you can also use program
      instead of prgm)

It applies for the last dst. selector1,selector2 means selector1 and

selector2.

Ex:

vlc file --sout '#duplicate{dst="1� dst", select="selection for 1� dst",

dst="2� dst", dst="3� dst", select="selection for 3� dst" }'

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/stream_out/duplicate.c

    r5ca0ebc r3a60f49  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001, 2002 VideoLAN 
    5  * $Id: duplicate.c,v 1.8 2003/12/22 14:32:56 sam Exp $ 
     5 * $Id: duplicate.c,v 1.9 2004/01/18 02:20:28 fenrir Exp $ 
    66 * 
    77 * Author: Laurent Aimar <fenrir@via.ecp.fr> 
     
    5858    int             i_nb_streams; 
    5959    sout_stream_t   **pp_streams; 
     60 
     61    int             i_nb_select; 
     62    char            **ppsz_select; 
     63 
     64    int             i_es; 
    6065}; 
    6166 
     
    6671}; 
    6772 
     73static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select, int i_es_number ); 
     74 
    6875/***************************************************************************** 
    6976 * Open: 
     
    7582    sout_cfg_t        *p_cfg; 
    7683 
    77     msg_Dbg( p_stream, "creating a duplication" ); 
     84    msg_Dbg( p_stream, "creating 'duplicate'" ); 
    7885 
    7986    p_sys = malloc( sizeof( sout_stream_sys_t ) ); 
     87 
    8088    p_sys->i_nb_streams = 0; 
    8189    p_sys->pp_streams   = NULL; 
     90    p_sys->i_nb_select  = 0; 
     91    p_sys->ppsz_select  = NULL; 
     92    p_sys->i_es         = 0; 
    8293 
    8394    for( p_cfg = p_stream->p_cfg; p_cfg != NULL; p_cfg = p_cfg->p_next ) 
     
    93104            { 
    94105                TAB_APPEND( p_sys->i_nb_streams, p_sys->pp_streams, s ); 
     106                TAB_APPEND( p_sys->i_nb_select,  p_sys->ppsz_select, NULL ); 
     107            } 
     108        } 
     109        else if( !strncmp( p_cfg->psz_name, "select", strlen( "select" ) ) ) 
     110        { 
     111            char *psz = p_cfg->psz_value; 
     112            if( p_sys->i_nb_select > 0 && psz && *psz ) 
     113            { 
     114                msg_Dbg( p_stream, " * apply selection %s", psz ); 
     115                p_sys->ppsz_select[p_sys->i_nb_select - 1] = strdup( psz ); 
    95116            } 
    96117        } 
     
    129150    { 
    130151        sout_stream_delete( p_sys->pp_streams[i] ); 
    131     } 
    132     free( p_sys->pp_streams ); 
     152        if( p_sys->ppsz_select[i] ) 
     153        { 
     154            free( p_sys->ppsz_select[i] ); 
     155        } 
     156    } 
     157    if( p_sys->pp_streams ) 
     158    { 
     159        free( p_sys->pp_streams ); 
     160    } 
     161    if( p_sys->ppsz_select ) 
     162    { 
     163        free( p_sys->ppsz_select ); 
     164    } 
    133165 
    134166    free( p_sys ); 
    135167} 
    136168 
     169/***************************************************************************** 
     170 * Add: 
     171 *****************************************************************************/ 
    137172static sout_stream_id_t * Add( sout_stream_t *p_stream, es_format_t *p_fmt ) 
    138173{ 
     
    145180    id->pp_ids   = NULL; 
    146181 
     182    msg_Dbg( p_stream, "duplicated a new stream codec=%4.4s (es=%d group=%d)", 
     183             (char*)&p_fmt->i_codec, 
     184             p_sys->i_es, 
     185             p_fmt->i_group ); 
    147186    for( i_stream = 0; i_stream < p_sys->i_nb_streams; i_stream++ ) 
    148187    { 
    149         void *id_new; 
    150  
    151         /* XXX not the same sout_stream_id_t definition ... */ 
    152         id_new = (void*)p_sys->pp_streams[i_stream]->pf_add( 
    153                             p_sys->pp_streams[i_stream], p_fmt ); 
     188        void *id_new = NULL; 
     189 
     190        if( ESSelected( p_fmt, p_sys->ppsz_select[i_stream], p_sys->i_es ) ) 
     191        { 
     192            sout_stream_t *out = p_sys->pp_streams[i_stream]; 
     193 
     194            id_new = (void*)out->pf_add( out, p_fmt ); 
     195            if( id_new ) 
     196            { 
     197                msg_Dbg( p_stream, "    - added for output %d", i_stream ); 
     198                i_valid_streams++; 
     199            } 
     200            else 
     201            { 
     202                msg_Dbg( p_stream, "    - failed for output %d", i_stream ); 
     203            } 
     204        } 
     205        else 
     206        { 
     207            msg_Dbg( p_stream, "    - ignored for output %d", i_stream ); 
     208        } 
    154209 
    155210        /* Append failed attempts as well to keep track of which pp_id 
    156211         * belongs to which duplicated stream */ 
    157212        TAB_APPEND( id->i_nb_ids, id->pp_ids, id_new ); 
    158         if( id_new ) i_valid_streams++; 
    159     } 
     213    } 
     214 
     215    p_sys->i_es++; 
    160216 
    161217    if( i_valid_streams <= 0 ) 
     
    168224} 
    169225 
     226/***************************************************************************** 
     227 * Del: 
     228 *****************************************************************************/ 
    170229static int Del( sout_stream_t *p_stream, sout_stream_id_t *id ) 
    171230{ 
     
    177236        if( id->pp_ids[i_stream] ) 
    178237        { 
    179             p_sys->pp_streams[i_stream]->pf_del( p_sys->pp_streams[i_stream], 
    180                                                 id->pp_ids[i_stream] ); 
     238            sout_stream_t *out = p_sys->pp_streams[i_stream]; 
     239            out->pf_del( out, id->pp_ids[i_stream] ); 
    181240        } 
    182241    } 
     
    187246} 
    188247 
     248/***************************************************************************** 
     249 * Send: 
     250 *****************************************************************************/ 
    189251static int Send( sout_stream_t *p_stream, sout_stream_id_t *id, 
    190252                 sout_buffer_t *p_buffer ) 
     
    230292    return VLC_SUCCESS; 
    231293} 
     294 
     295/***************************************************************************** 
     296 * Divers 
     297 *****************************************************************************/ 
     298static vlc_bool_t NumInRange( char *psz_range, int i_num ) 
     299{ 
     300    char *psz = strchr( psz_range, '-' ); 
     301    char *end; 
     302    int  i_start, i_stop; 
     303 
     304    if( psz ) 
     305    { 
     306        i_start = strtol( psz_range, &end, 0 ); 
     307        if( end == psz_range ) i_start = i_num; 
     308 
     309        i_stop  = strtol( psz,       &end, 0 ); 
     310        if( end == psz_range ) i_stop = i_num; 
     311    } 
     312    else 
     313    { 
     314        i_start = i_stop = strtol( psz_range, NULL, 0 ); 
     315    } 
     316 
     317    return i_start <= i_num && i_num <= i_stop ? VLC_TRUE : VLC_FALSE; 
     318} 
     319 
     320static vlc_bool_t ESSelected( es_format_t *fmt, char *psz_select, int i_es_number ) 
     321{ 
     322    char  *psz_dup; 
     323    char  *psz; 
     324 
     325    /* We have tree state variable : no tested (-1), failed(0), succeed(1) */ 
     326    int i_cat = -1; 
     327    int i_es  = -1; 
     328    int i_prgm= -1; 
     329 
     330    /* If empty all es are selected */ 
     331    if( psz_select == NULL || *psz_select == '\0' ) 
     332    { 
     333        return VLC_TRUE; 
     334    } 
     335    psz_dup = strdup( psz_select ); 
     336    psz     = psz_dup; 
     337 
     338    /* If non empty, parse the selection: 
     339     * We have selection[,selection[,..]] where following selection are recognized: 
     340     *      (no(-))audio 
     341     *      (no(-))spu 
     342     *      (no(-))video 
     343     *      (no(-))es=[start]-[end] or es=num 
     344     *      (no(-))prgm=[start]-[end] or prgm=num (program works too) 
     345     *      if a negative test failed we exit directly 
     346     */ 
     347    while( psz && *psz ) 
     348    { 
     349        char *p; 
     350 
     351        /* Skip space */ 
     352        while( *psz == ' ' || *psz == '\t' ) psz++; 
     353 
     354        /* Search end */ 
     355        p = strchr( psz, ',' ); 
     356        if( p == psz ) 
     357        { 
     358            /* Empty */ 
     359            psz = p + 1; 
     360            continue; 
     361        } 
     362        if( p ) 
     363        { 
     364            *p++ = '\0'; 
     365        } 
     366 
     367        if( !strncmp( psz, "no-audio", strlen( "no-audio" ) ) || 
     368            !strncmp( psz, "noaudio", strlen( "noaudio" ) ) ) 
     369        { 
     370            if( fmt->i_cat == AUDIO_ES ) 
     371            { 
     372                i_cat = 0; 
     373                break; 
     374            } 
     375        } 
     376        else if( !strncmp( psz, "no-video", strlen( "no-video" ) ) || 
     377                 !strncmp( psz, "novideo", strlen( "novideo" ) ) ) 
     378        { 
     379            if( fmt->i_cat == VIDEO_ES ) 
     380            { 
     381                i_cat = 0; 
     382                break; 
     383            } 
     384        } 
     385        else if( !strncmp( psz, "no-spu", strlen( "no-spu" ) ) || 
     386                 !strncmp( psz, "nospu", strlen( "nospu" ) ) ) 
     387        { 
     388            if( fmt->i_cat == SPU_ES ) 
     389            { 
     390                i_cat = 0; 
     391                break; 
     392            } 
     393        } 
     394        else if( !strncmp( psz, "audio", strlen( "audio" ) ) ) 
     395        { 
     396            if( i_cat != 1 ) 
     397            { 
     398                i_cat = fmt->i_cat == AUDIO_ES ? 1 : 0; 
     399            } 
     400        } 
     401        else if( !strncmp( psz, "video", strlen( "video" ) ) ) 
     402        { 
     403            if( i_cat != 1 ) 
     404            { 
     405                i_cat = fmt->i_cat == VIDEO_ES ? 1 : 0; 
     406            } 
     407        } 
     408        else if( !strncmp( psz, "spu", strlen( "spu" ) ) ) 
     409        { 
     410            if( i_cat != 1 ) 
     411            { 
     412                i_cat = fmt->i_cat == SPU_ES ? 1 : 0; 
     413            } 
     414        } 
     415        else if( strchr( psz, '=' ) != NULL ) 
     416        { 
     417            char *psz_arg = strchr( psz, '=' ); 
     418            *psz_arg++ = '\0'; 
     419 
     420            if( !strcmp( psz, "no-es" ) || !strcmp( psz, "es" ) ) 
     421            { 
     422                if( !NumInRange( psz_arg, i_es_number ) ) 
     423                { 
     424                    i_es = 0; 
     425                    break; 
     426                } 
     427            } 
     428            else if( !strcmp( psz, "es" ) ) 
     429            { 
     430                if( i_es != 1 ) 
     431                { 
     432                    i_es = NumInRange( psz_arg, i_es_number ) ? 1 : 0; 
     433                } 
     434            } 
     435            else if( !strcmp( psz, "no-prgm" ) || !strcmp( psz, "noprgm" ) || 
     436                      !strcmp( psz, "no-program" ) || !strcmp( psz, "noprogram" ) ) 
     437            { 
     438                if( fmt->i_group >= 0 && !NumInRange( psz_arg, fmt->i_group ) ) 
     439                { 
     440                    i_prgm = 0; 
     441                    break; 
     442                } 
     443            } 
     444            else if( !strcmp( psz, "program" ) || !strcmp( psz, "program" ) ) 
     445            { 
     446                if( fmt->i_group >= 0 && i_prgm != 1 ) 
     447                { 
     448                    i_prgm = NumInRange( psz_arg, fmt->i_group ) ? 1 : 0; 
     449                } 
     450            } 
     451        } 
     452        else 
     453        { 
     454            fprintf( stderr, "unknown args (%s)\n", psz ); 
     455        } 
     456        /* Next */ 
     457        psz = p; 
     458    } 
     459 
     460    free( psz_dup ); 
     461 
     462    if( i_cat == 0 || i_es == 0 || i_prgm == 0 ) 
     463    { 
     464        /* One test failed */ 
     465        return VLC_FALSE; 
     466    } 
     467    return VLC_TRUE; 
     468} 
     469 
     470