Commit fdf11136 authored by Laurent Aimar's avatar Laurent Aimar

Cleaned up a bit rawvideo demuxer.

Used vlc_fourcc_t.
Protected a macro.
Used var_CreateGetNonEmptyString where needed.
Cosmetics.
parent 68ae0c21
...@@ -107,7 +107,7 @@ struct preset_t ...@@ -107,7 +107,7 @@ struct preset_t
unsigned u_fps_den; unsigned u_fps_den;
unsigned u_ar_num; unsigned u_ar_num;
unsigned u_ar_den; unsigned u_ar_den;
int i_chroma; vlc_fourcc_t i_chroma;
}; };
static const struct preset_t p_presets[] = static const struct preset_t p_presets[] =
...@@ -131,7 +131,7 @@ static int Open( vlc_object_t * p_this ) ...@@ -131,7 +131,7 @@ static int Open( vlc_object_t * p_this )
int i_width=-1, i_height=-1; int i_width=-1, i_height=-1;
unsigned u_fps_num=0, u_fps_den=1; unsigned u_fps_num=0, u_fps_den=1;
char *psz_ext; char *psz_ext;
uint32_t i_chroma; vlc_fourcc_t i_chroma;
unsigned int i_aspect = 0; unsigned int i_aspect = 0;
const struct preset_t *p_preset = NULL; const struct preset_t *p_preset = NULL;
const uint8_t *p_peek; const uint8_t *p_peek;
...@@ -189,23 +189,25 @@ static int Open( vlc_object_t * p_this ) ...@@ -189,23 +189,25 @@ static int Open( vlc_object_t * p_this )
/* override presets if yuv4mpeg2 */ /* override presets if yuv4mpeg2 */
if( b_y4m ) if( b_y4m )
{ {
char *psz; char *psz = stream_ReadLine( p_demux->s );
char *buf; char *psz_buf;
int a = 1; int a = 1;
int b = 1; int b = 1;
psz = stream_ReadLine( p_demux->s );
/* The string will start with "YUV4MPEG2" */
assert( strlen(psz) >= 9 );
/* NB, it is not possible to handle interlaced here, since the /* NB, it is not possible to handle interlaced here, since the
* interlaced picture flags are in picture_t not block_t */ * interlaced picture flags are in picture_t not block_t */
#define READ_FRAC( key, num, den ) \ #define READ_FRAC( key, num, den ) do { \
buf = strstr( psz+9, key );\ psz_buf = strstr( psz+9, key );\
if( buf )\ if( psz_buf )\
{\ {\
char *end = strchr( buf+1, ' ' );\ char *end = strchr( psz_buf+1, ' ' );\
char *sep;\ char *sep;\
if( end ) *end = '\0';\ if( end ) *end = '\0';\
sep = strchr( buf+1, ':' );\ sep = strchr( psz_buf+1, ':' );\
if( sep )\ if( sep )\
{\ {\
*sep = '\0';\ *sep = '\0';\
...@@ -215,48 +217,53 @@ static int Open( vlc_object_t * p_this ) ...@@ -215,48 +217,53 @@ static int Open( vlc_object_t * p_this )
{\ {\
den = 1;\ den = 1;\
}\ }\
num = atoi( buf+2 );\ num = atoi( psz_buf+2 );\
if( sep ) *sep = ':';\ if( sep ) *sep = ':';\
if( end ) *end = ' ';\ if( end ) *end = ' ';\
} } } while(0)
READ_FRAC( " W", i_width, a ) READ_FRAC( " W", i_width, a );
READ_FRAC( " H", i_height, a ) READ_FRAC( " H", i_height, a );
READ_FRAC( " F", u_fps_num, u_fps_den ) READ_FRAC( " F", u_fps_num, u_fps_den );
READ_FRAC( " A", a, b ) READ_FRAC( " A", a, b );
#undef READ_FRAC
/* Try to calculate aspect ratio here, rather than store ratio /* Try to calculate aspect ratio here, rather than store ratio
* in u_ar_{num,den}, since width may be overridden by then. * in u_ar_{num,den}, since width may be overridden by then.
* Plus, a:b is sar. */ * Plus, a:b is sar. */
if( b != 0 ) if( b != 0 )
i_aspect = VOUT_ASPECT_FACTOR * a * i_width / (b * i_height); i_aspect = VOUT_ASPECT_FACTOR * a * i_width / (b * i_height);
buf = strstr( psz+9, " C" ); psz_buf = strstr( psz+9, " C" );
if( buf ) if( psz_buf )
{ {
char *end = strchr( buf+1, ' ' ); static const struct { const char *psz_name; vlc_fourcc_t i_fcc; } formats[] =
if( end ) *end = '\0'; {
buf+=2; { "420jpeg", VLC_FOURCC('I','4','2','0') },
if( !strncmp( buf, "420jpeg", 7 ) ) { { "420paldv", VLC_FOURCC('I','4','2','0') },
i_chroma = VLC_FOURCC('I','4','2','0'); { "420", VLC_FOURCC('I','4','2','0') },
} { "422", VLC_FOURCC('I','4','2','2') },
else if( !strncmp( buf, "420paldv", 8 ) ) { { "444", VLC_FOURCC('I','4','4','4') },
i_chroma = VLC_FOURCC('I','4','2','0'); { "mono", VLC_FOURCC('G','R','E','Y') },
} { NULL, 0 }
else if( !strncmp( buf, "420", 3 ) ) { };
i_chroma = VLC_FOURCC('I','4','2','0'); bool b_found = false;
} char *psz_end = strchr( psz_buf+1, ' ' );
else if( !strncmp( buf, "422", 3 ) ) { if( psz_end )
i_chroma = VLC_FOURCC('I','4','2','2'); *psz_end = '\0';
} psz_buf += 2;
else if( !strncmp( buf, "444", 3 ) ) {
i_chroma = VLC_FOURCC('I','4','4','4'); for( int i = 0; formats[i].psz_name != NULL; i++ )
} {
else if( !strncmp( buf, "mono", 4 ) ) { if( !strncmp( psz_buf, formats[i].psz_name, strlen(formats[i].psz_name) ) )
i_chroma = VLC_FOURCC('G','R','E','Y'); {
} i_chroma = formats[i].i_fcc;
else { b_found = true;
msg_Warn( p_demux, "Unknown YUV4MPEG2 chroma type \"%s\"", buf ); break;
}
} }
if( end ) *end = ' '; if( !b_found )
msg_Warn( p_demux, "Unknown YUV4MPEG2 chroma type \"%s\"", psz_buf );
if( psz_end )
*psz_end = ' ';
} }
free( psz ); free( psz );
...@@ -271,7 +278,7 @@ static int Open( vlc_object_t * p_this ) ...@@ -271,7 +278,7 @@ static int Open( vlc_object_t * p_this )
if( i_tmp ) i_height = i_tmp; if( i_tmp ) i_height = i_tmp;
char *psz_tmp; char *psz_tmp;
psz_tmp = var_CreateGetString( p_demux, "rawvid-chroma" ); psz_tmp = var_CreateGetNonEmptyString( p_demux, "rawvid-chroma" );
if( psz_tmp ) if( psz_tmp )
{ {
if( strlen( psz_tmp ) != 4 ) if( strlen( psz_tmp ) != 4 )
...@@ -286,8 +293,9 @@ static int Open( vlc_object_t * p_this ) ...@@ -286,8 +293,9 @@ static int Open( vlc_object_t * p_this )
free( psz_tmp ); free( psz_tmp );
} }
psz_tmp = var_CreateGetString( p_demux, "rawvid-fps" ); psz_tmp = var_CreateGetNonEmptyString( p_demux, "rawvid-fps" );
if( psz_tmp ) { if( psz_tmp )
{
char *p_ptr; char *p_ptr;
/* fps can either be n/d or q.f /* fps can either be n/d or q.f
* for accuracy, avoid representation in float */ * for accuracy, avoid representation in float */
...@@ -314,7 +322,7 @@ static int Open( vlc_object_t * p_this ) ...@@ -314,7 +322,7 @@ static int Open( vlc_object_t * p_this )
free( psz_tmp ); free( psz_tmp );
} }
psz_tmp = var_CreateGetString( p_demux, "rawvid-aspect-ratio" ); psz_tmp = var_CreateGetNonEmptyString( p_demux, "rawvid-aspect-ratio" );
if( psz_tmp ) if( psz_tmp )
{ {
char *psz_denominator = strchr( psz_tmp, ':' ); char *psz_denominator = strchr( psz_tmp, ':' );
...@@ -403,13 +411,17 @@ static int Demux( demux_t *p_demux ) ...@@ -403,13 +411,17 @@ static int Demux( demux_t *p_demux )
if( p_sys->b_y4m ) if( p_sys->b_y4m )
{ {
/* Skip the frame header */ /* Skip the frame header */
unsigned char psz_buf[10]; /* Skip "FRAME" */
psz_buf[9] = '\0'; if( stream_Read( p_demux->s, NULL, 5 ) < 5 )
stream_Read( p_demux->s, psz_buf, strlen( "FRAME" ) ); return 0;
while( psz_buf[0] != 0x0a ) /* Find \n */
for( ;; )
{ {
if( stream_Read( p_demux->s, psz_buf, 1 ) < 1 ) uint8_t b;
if( stream_Read( p_demux->s, &b, 1 ) < 1 )
return 0; return 0;
if( b == 0x0a )
break;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment