int open_file_yuv( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
{
yuv_input_t *h = malloc(sizeof(yuv_input_t));
+ if( !h )
+ return -1;
h->width = p_param->i_width;
h->height = p_param->i_height;
h->next_frame = 0;
int open_file_y4m( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
{
int i, n, d;
- int interlaced;
char header[MAX_YUV4_HEADER+10];
char *tokstart, *tokend, *header_end;
y4m_input_t *h = malloc(sizeof(y4m_input_t));
+ if( !h )
+ return -1;
h->next_frame = 0;
case 'I': /* Interlace type */
switch(*tokstart++)
{
- case 'p': interlaced = 0; break;
+ case 'p': break;
case '?':
case 't':
case 'b':
case 'm':
- default: interlaced = 1;
+ default:
fprintf(stderr, "Warning, this sequence might be interlaced\n");
}
break;
tokstart = strchr(tokstart, 0x20);
break;
case 'A': /* Pixel aspect - 0:0 if unknown */
- if( sscanf(tokstart, "%d:%d", &n, &d) == 2 && n && d )
+ /* Don't override the aspect ratio if sar has been explicitly set on the commandline. */
+ if( sscanf(tokstart, "%d:%d", &n, &d) == 2 && n && d && !p_param->vui.i_sar_width && !p_param->vui.i_sar_height )
{
x264_reduce_fraction( &n, &d );
p_param->vui.i_sar_width = n;
/* Read frame header - without terminating '\n' */
if (fread(header, 1, slen, h->fh) != slen)
return -1;
-
+
header[slen] = 0;
if (strncmp(header, Y4M_FRAME_MAGIC, slen))
{
- fprintf(stderr, "Bad header magic (%08X <=> %s)\n",
+ fprintf(stderr, "Bad header magic (%"PRIx32" <=> %s)\n",
*((uint32_t*)header), header);
return -1;
}
-
+
/* Skip most of it */
while (i<MAX_FRAME_HEADER && fgetc(h->fh) != '\n')
i++;
int open_file_avis( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
{
avis_input_t *h = malloc(sizeof(avis_input_t));
+ if( !h )
+ return -1;
AVISTREAMINFO info;
int i;
x264_pthread_t tid;
int next_frame;
int frame_total;
+ int in_progress;
struct thread_input_arg_t *next_args;
} thread_input_t;
int open_file_thread( char *psz_filename, hnd_t *p_handle, x264_param_t *p_param )
{
thread_input_t *h = malloc(sizeof(thread_input_t));
- x264_picture_alloc( &h->pic, X264_CSP_I420, p_param->i_width, p_param->i_height );
+ if( !h || x264_picture_alloc( &h->pic, X264_CSP_I420, p_param->i_width, p_param->i_height ) < 0 )
+ {
+ fprintf( stderr, "x264 [error]: malloc failed\n" );
+ return -1;
+ }
h->p_read_frame = p_read_frame;
h->p_close_infile = p_close_infile;
h->p_handle = *p_handle;
+ h->in_progress = 0;
h->next_frame = -1;
h->next_args = malloc(sizeof(thread_input_arg_t));
+ if( !h->next_args )
+ return -1;
h->next_args->h = h;
h->next_args->status = 0;
h->frame_total = p_get_frame_total( h->p_handle );
return h->frame_total;
}
-void read_frame_thread_int( thread_input_arg_t *i )
+static void read_frame_thread_int( thread_input_arg_t *i )
{
i->status = i->h->p_read_frame( i->pic, i->h->p_handle, i->i_frame );
}
int read_frame_thread( x264_picture_t *p_pic, hnd_t handle, int i_frame )
{
thread_input_t *h = handle;
- UNUSED void *stuff;
int ret = 0;
if( h->next_frame >= 0 )
{
- x264_pthread_join( h->tid, &stuff );
+ x264_pthread_join( h->tid, NULL );
ret |= h->next_args->status;
+ h->in_progress = 0;
}
if( h->next_frame == i_frame )
h->next_frame =
h->next_args->i_frame = i_frame+1;
h->next_args->pic = &h->pic;
- x264_pthread_create( &h->tid, NULL, (void*)read_frame_thread_int, h->next_args );
+ if( x264_pthread_create( &h->tid, NULL, (void*)read_frame_thread_int, h->next_args ) )
+ return -1;
+ h->in_progress = 1;
}
else
h->next_frame = -1;
int close_file_thread( hnd_t handle )
{
thread_input_t *h = handle;
+ if( h->in_progress )
+ x264_pthread_join( h->tid, NULL );
h->p_close_infile( h->p_handle );
x264_picture_clean( &h->pic );
+ free( h->next_args );
free( h );
return 0;
}
} mp4_t;
-void recompute_bitrate_mp4(GF_ISOFile *p_file, int i_track)
+static void recompute_bitrate_mp4(GF_ISOFile *p_file, int i_track)
{
u32 i, count, di, timescale, time_wnd, rate;
u64 offset;
p_mp4->p_config->profile_compatibility = p_nalu[6];
p_mp4->p_config->AVCLevelIndication = p_nalu[7];
p_slot = (GF_AVCConfigSlot *)malloc(sizeof(GF_AVCConfigSlot));
+ if( !p_slot )
+ return -1;
p_slot->size = i_size - 4;
p_slot->data = (char *)malloc(p_slot->size);
+ if( !p_slot->data )
+ return -1;
memcpy(p_slot->data, p_nalu + 4, i_size - 4);
gf_list_add(p_mp4->p_config->sequenceParameterSets, p_slot);
p_slot = NULL;
if (!p_mp4->b_pps)
{
p_slot = (GF_AVCConfigSlot *)malloc(sizeof(GF_AVCConfigSlot));
+ if( !p_slot )
+ return -1;
p_slot->size = i_size - 4;
p_slot->data = (char *)malloc(p_slot->size);
+ if( !p_slot->data )
+ return -1;
memcpy(p_slot->data, p_nalu + 4, i_size - 4);
gf_list_add(p_mp4->p_config->pictureParameterSets, p_slot);
p_slot = NULL;
char b_writing_frame;
} mkv_t;
-int write_header_mkv( mkv_t *p_mkv )
+static int write_header_mkv( mkv_t *p_mkv )
{
int ret;
uint8_t *avcC;