- var_Create( p_demux, "rawvid-fps", VLC_VAR_FLOAT | VLC_VAR_DOINHERIT );
- var_Get( p_demux, "rawvid-fps", &val );
- p_sys->f_fps = val.f_float;
- var_Create( p_demux, "rawvid-width", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
- var_Get( p_demux, "rawvid-width", &val );
- i_width = val.i_int;
- var_Create( p_demux, "rawvid-height", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT);
- var_Get( p_demux, "rawvid-height", &val );
- i_height = val.i_int;
-
- /* Only handle YV12 for now */
- es_format_Init( &p_sys->fmt_video, VIDEO_ES, VLC_FOURCC('Y','V','1','2') );
- p_sys->fmt_video.video.i_width = i_width;
- p_sys->fmt_video.video.i_height = i_height;
- p_sys->frame_size = i_width * i_height * 3 / 2;
+ p_sys->b_y4m = b_y4m;
+ p_sys->f_fps = var_CreateGetFloat( p_demux, "rawvid-fps" );
+ i_width = var_CreateGetInteger( p_demux, "rawvid-width" );
+ i_height = var_CreateGetInteger( p_demux, "rawvid-height" );
+ psz_chroma = var_CreateGetString( p_demux, "rawvid-chroma" );
+ psz_aspect_ratio = var_CreateGetString( p_demux, "rawvid-aspect-ratio" );
+
+ if( b_y4m )
+ {
+ char *psz;
+ char *buf;
+ int a = 1;
+ int b = 1;
+ psz = stream_ReadLine( p_demux->s );
+
+ /* TODO: handle interlacing */
+
+#define READ_FRAC( key, num, den ) \
+ buf = strstr( psz+9, key );\
+ if( buf )\
+ {\
+ char *end = strchr( buf+1, ' ' );\
+ char *sep;\
+ if( end ) *end = '\0';\
+ sep = strchr( buf+1, ':' );\
+ if( sep )\
+ {\
+ *sep = '\0';\
+ den = atoi( sep+1 );\
+ }\
+ else\
+ {\
+ den = 1;\
+ }\
+ num = atoi( buf+2 );\
+ if( sep ) *sep = ':';\
+ if( end ) *end = ' ';\
+ }
+ READ_FRAC( " W", i_width, a )
+ READ_FRAC( " H", i_height, a )
+ READ_FRAC( " F", a, b )
+ p_sys->f_fps = (double)a/(double)b;
+ READ_FRAC( " A", a, b )
+ if( b != 0 ) i_aspect = a * VOUT_ASPECT_FACTOR / b;
+
+ buf = strstr( psz+9, " C" );
+ if( buf )
+ {
+ char *end = strchr( buf+1, ' ' );
+ if( end ) *end = '\0';
+ buf+=2;
+ if( !strncmp( buf, "420jpeg", 7 ) )
+ {
+ psz_chroma = strdup( "I420" );
+ }
+ else if( !strncmp( buf, "420paldv", 8 ) )
+ {
+ psz_chroma = strdup( "I420" );
+ }
+ else if( !strncmp( buf, "420", 3 ) )
+ {
+ psz_chroma = strdup( "I420" );
+ }
+ else if( !strncmp( buf, "422", 3 ) )
+ {
+ psz_chroma = strdup( "I422" );
+ }
+ else if( !strncmp( buf, "444", 3 ) )
+ {
+ psz_chroma = strdup( "I444" );
+ }
+ else if( !strncmp( buf, "mono", 4 ) )
+ {
+ psz_chroma = strdup( "GREY" );
+ }
+ else
+ {
+ msg_Warn( p_demux, "Unknown YUV4MPEG2 chroma type \"%s\"",
+ buf );
+ }
+ if( end ) *end = ' ';
+ }
+
+ free( psz );
+ }
+
+ if( p_preset && *p_preset->psz_ext )
+ {
+ if( !i_width ) i_width = p_preset->i_width;
+ if( !i_height ) i_height = p_preset->i_height;
+ if( !p_sys->f_fps ) p_sys->f_fps = p_preset->f_fps;
+ if( !*psz_aspect_ratio )
+ {
+ free( psz_aspect_ratio );
+ psz_aspect_ratio = strdup( psz_aspect_ratio );
+ }
+ if( !*psz_chroma )
+ {
+ free( psz_chroma );
+ psz_chroma = strdup( psz_chroma );
+ }
+ }
+
+ if( i_width <= 0 || i_height <= 0 )
+ {
+ msg_Err( p_demux, "width and height must be strictly positive." );
+ free( psz_aspect_ratio );
+ free( psz_chroma );
+ free( p_sys );
+ return VLC_EGENERIC;
+ }
+
+ if( !i_aspect )
+ {
+ if( psz_aspect_ratio && *psz_aspect_ratio )
+ {
+ char *psz_parser = strchr( psz_aspect_ratio, ':' );
+ if( psz_parser )
+ {
+ *psz_parser++ = '\0';
+ i_aspect = atoi( psz_aspect_ratio ) * VOUT_ASPECT_FACTOR
+ / atoi( psz_parser );
+ }
+ else
+ {
+ i_aspect = atof( psz_aspect_ratio ) * VOUT_ASPECT_FACTOR;
+ }
+ }
+ else
+ {
+ i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
+ }
+ }
+ free( psz_aspect_ratio );
+
+ if( psz_chroma && strlen( psz_chroma ) >= 4 )
+ {
+ memcpy( &i_chroma, psz_chroma, 4 );
+ msg_Dbg( p_demux, "Forcing chroma to 0x%.8x (%4.4s)", i_chroma,
+ (char*)&i_chroma );
+ }
+ else
+ {
+ i_chroma = VLC_FOURCC('Y','V','1','2');
+ msg_Dbg( p_demux, "Using default chroma 0x%.8x (%4.4s)", i_chroma,
+ (char*)&i_chroma );
+ }
+ free( psz_chroma );
+
+ es_format_Init( &p_sys->fmt_video, VIDEO_ES, i_chroma );
+ vout_InitFormat( &p_sys->fmt_video.video, i_chroma, i_width, i_height,
+ i_aspect );
+ if( !p_sys->fmt_video.video.i_bits_per_pixel )
+ {
+ msg_Err( p_demux, "Unsupported chroma 0x%.8x (%4.4s)", i_chroma,
+ (char*)&i_chroma );
+ free( p_sys );
+ return VLC_EGENERIC;
+ }
+ p_sys->frame_size = i_width * i_height
+ * p_sys->fmt_video.video.i_bits_per_pixel / 8;