Changeset 2fd187de931769cef2128cd7f0ede41f71732fda

Show
Ignore:
Timestamp:
07/17/07 23:40:03 (1 year ago)
Author:
Antoine Cellerier <dionoea@videolan.org>
git-committer:
Antoine Cellerier <dionoea@videolan.org> 1184708403 +0000
git-parent:

[fd84e3b73a8fd3461dc11321320922f43ff2a6de]

git-author:
Antoine Cellerier <dionoea@videolan.org> 1184708403 +0000
Message:

Add aspect ratio and chroma option to the rawvid demux.
Add some sanity checks to the options' values.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/demux/rawvid.c

    r3b0deb5 r2fd187d  
    66 * 
    77 * Authors: Gildas Bazin <gbazin@videolan.org> 
     8 *          Antoine Cellerier <dionoea at videolan d.t org> 
    89 * 
    910 * This program is free software; you can redistribute it and/or modify 
     
    2930#include <vlc/vlc.h> 
    3031#include <vlc_demux.h> 
     32#include <vlc_vout.h>                                     /* vout_InitFormat */ 
    3133 
    3234/***************************************************************************** 
     
    4749#define HEIGHT_LONGTEXT N_("This specifies the height in pixels of the raw " \ 
    4850    "video stream.") 
     51 
     52#define CHROMA_TEXT N_("Force chroma (Use carefully)") 
     53#define CHROMA_LONGTEXT N_("Force chroma. This is a four character string.") 
     54 
     55#define ASPECT_RATIO_TEXT N_("Aspect ratio") 
     56#define ASPECT_RATIO_LONGTEXT N_( \ 
     57    "Aspect ratio (4:3, 16:9). Default is square pixels." ) 
    4958 
    5059vlc_module_begin(); 
     
    5968    add_integer( "rawvid-width", 176, 0, WIDTH_TEXT, WIDTH_LONGTEXT, 0 ); 
    6069    add_integer( "rawvid-height", 144, 0, HEIGHT_TEXT, HEIGHT_LONGTEXT, 0 ); 
     70    add_string( "rawvid-chroma", NULL, NULL, CHROMA_TEXT, CHROMA_LONGTEXT, 
     71                VLC_TRUE ); 
     72    add_string( "rawvid-aspect-ratio", NULL, NULL, 
     73                ASPECT_RATIO_TEXT, ASPECT_RATIO_LONGTEXT, VLC_TRUE ); 
    6174vlc_module_end(); 
    6275 
     
    89102    demux_sys_t *p_sys; 
    90103    int i_width, i_height; 
    91     vlc_value_t val; 
    92104    char *psz_ext; 
     105    char *psz_chroma; 
     106    uint32_t i_chroma; 
     107    char *psz_aspect_ratio; 
     108    unsigned int i_aspect; 
    93109 
    94110    /* Check for YUV file extension */ 
     
    106122    p_sys->i_pcr = 1; 
    107123 
    108     var_Create( p_demux, "rawvid-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT ); 
    109     var_Get( p_demux, "rawvid-fps", &val ); 
    110     p_sys->f_fps = val.f_float; 
    111     var_Create( p_demux, "rawvid-width", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT ); 
    112     var_Get( p_demux, "rawvid-width", &val ); 
    113     i_width = val.i_int; 
    114     var_Create( p_demux, "rawvid-height", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT); 
    115     var_Get( p_demux, "rawvid-height", &val ); 
    116     i_height = val.i_int; 
    117  
    118     /* Only handle YV12 for now */ 
    119     es_format_Init( &p_sys->fmt_video, VIDEO_ES, VLC_FOURCC('Y','V','1','2') ); 
    120     p_sys->fmt_video.video.i_width  = i_width; 
    121     p_sys->fmt_video.video.i_height = i_height; 
    122     p_sys->frame_size = i_width * i_height * 3 / 2; 
     124    p_sys->f_fps = var_CreateGetFloat( p_demux, "rawvid-fps" ); 
     125 
     126    i_width = var_CreateGetInteger( p_demux, "rawvid-width" ); 
     127    i_height = var_CreateGetInteger( p_demux, "rawvid-height" ); 
     128    if( i_width <= 0 || i_height <= 0 ) 
     129    { 
     130        msg_Err( p_demux, "width and height must be strictly positive." ); 
     131        free( p_sys ); 
     132        return VLC_EGENERIC; 
     133    } 
     134 
     135    psz_chroma = var_CreateGetString( p_demux, "rawvid-chroma" ); 
     136    psz_aspect_ratio = var_CreateGetString( p_demux, "rawvid-aspect-ratio" ); 
     137 
     138    if( psz_aspect_ratio && *psz_aspect_ratio ) 
     139    { 
     140        char *psz_parser = strchr( psz_aspect_ratio, ':' ); 
     141        if( psz_parser ) 
     142        { 
     143            *psz_parser++ = '\0'; 
     144            i_aspect = atoi( psz_aspect_ratio ) * VOUT_ASPECT_FACTOR 
     145                       / atoi( psz_parser ); 
     146        } 
     147        else 
     148        { 
     149            i_aspect = atof( psz_aspect_ratio ) * VOUT_ASPECT_FACTOR; 
     150        } 
     151    } 
     152    else 
     153    { 
     154        i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height; 
     155    } 
     156    free( psz_aspect_ratio ); 
     157 
     158    if( psz_chroma && strlen( psz_chroma ) >= 4 ) 
     159    { 
     160        memcpy( &i_chroma, psz_chroma, 4 ); 
     161        msg_Dbg( p_demux, "Forcing chroma to 0x%.8x (%4.4s)", i_chroma, 
     162                 (char*)&i_chroma ); 
     163    } 
     164    else 
     165    { 
     166        i_chroma = VLC_FOURCC('Y','V','1','2'); 
     167        msg_Dbg( p_demux, "Using default chroma 0x%.8x (%4.4s)", i_chroma, 
     168                 (char*)&i_chroma ); 
     169    } 
     170    free( psz_chroma ); 
     171 
     172    es_format_Init( &p_sys->fmt_video, VIDEO_ES, i_chroma ); 
     173    vout_InitFormat( &p_sys->fmt_video.video, i_chroma, i_width, i_height, 
     174                     i_aspect ); 
     175    if( !p_sys->fmt_video.video.i_bits_per_pixel ) 
     176    { 
     177        msg_Err( p_demux, "Unsupported chroma 0x%.8x (%4.4s)", i_chroma, 
     178                 (char*)&i_chroma ); 
     179        free( p_sys ); 
     180        return VLC_EGENERIC; 
     181    } 
     182    p_sys->frame_size = i_width * i_height 
     183                        * p_sys->fmt_video.video.i_bits_per_pixel / 8; 
    123184    p_sys->p_es_video = es_out_Add( p_demux->out, &p_sys->fmt_video ); 
    124185