From 15450dbe916e971793989dc44762e1bda23ca153 Mon Sep 17 00:00:00 2001 From: Loren Merritt Date: Sat, 19 Feb 2005 06:18:22 +0000 Subject: [PATCH] Always use the tempfile and rename method for multipass stats, so that VfW knows whether the previous pass completed. git-svn-id: svn://svn.videolan.org/x264/trunk@131 df754926-b1dd-0310-bc7b-ec298dee348c --- encoder/ratecontrol.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/encoder/ratecontrol.c b/encoder/ratecontrol.c index b169c674..b7edc590 100644 --- a/encoder/ratecontrol.c +++ b/encoder/ratecontrol.c @@ -46,6 +46,9 @@ #ifdef _MSC_VER #define exp2f(x) pow( 2, (x) ) #endif +#ifdef WIN32 // POSIX says that rename() removes the destination, but win32 doesn't. +#define rename(src,dst) (unlink(dst), rename(src,dst)) +#endif typedef struct { @@ -335,14 +338,9 @@ int x264_ratecontrol_new( x264_t *h ) * and move it to the real name only when it's complete */ if( h->param.rc.b_stat_write ) { - if( h->param.rc.b_stat_read && !strcmp( h->param.rc.psz_stat_in, h->param.rc.psz_stat_out ) ) - { - rc->psz_stat_file_tmpname = x264_malloc( strlen(h->param.rc.psz_stat_out) + 5 ); - strcpy( rc->psz_stat_file_tmpname, h->param.rc.psz_stat_out ); - strcat( rc->psz_stat_file_tmpname, ".new" ); - } - else - rc->psz_stat_file_tmpname = h->param.rc.psz_stat_out; + rc->psz_stat_file_tmpname = x264_malloc( strlen(h->param.rc.psz_stat_out) + 6 ); + strcpy( rc->psz_stat_file_tmpname, h->param.rc.psz_stat_out ); + strcat( rc->psz_stat_file_tmpname, ".temp" ); rc->p_stat_file_out = fopen( rc->psz_stat_file_tmpname, "wb" ); if( rc->p_stat_file_out == NULL ) @@ -362,12 +360,13 @@ void x264_ratecontrol_delete( x264_t *h ) if( rc->p_stat_file_out ) { fclose( rc->p_stat_file_out ); - if( rc->psz_stat_file_tmpname != h->param.rc.psz_stat_out ) - { - if( h->i_frame >= rc->num_entries - h->param.i_bframe ) - rename( rc->psz_stat_file_tmpname, h->param.rc.psz_stat_out ); - x264_free( rc->psz_stat_file_tmpname ); - } + if( h->i_frame >= rc->num_entries - h->param.i_bframe ) + if( rename( rc->psz_stat_file_tmpname, h->param.rc.psz_stat_out ) != 0 ) + { + x264_log( h, X264_LOG_ERROR, "failed to rename \"%s\" to \"%s\"\n", + rc->psz_stat_file_tmpname, h->param.rc.psz_stat_out ); + } + x264_free( rc->psz_stat_file_tmpname ); } if( rc->entry ) x264_free(rc->entry); -- 2.47.3