From 320d4c011cf196a05e0c69337bec841d4fcedd54 Mon Sep 17 00:00:00 2001 From: jstebbins Date: Fri, 6 Jul 2012 23:29:10 +0000 Subject: [PATCH] bugfix branch: fix comb detection crash hb_detect_comb() could crash because the dimensions of the video buffer don't have to match the dimensions returned by work object info() method if the video has segments of differeing resolutions. git-svn-id: svn://svn.handbrake.fr/HandBrake/branches/0.9.x@4814 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- libhb/hb.c | 4 +++- libhb/hb.h | 2 +- libhb/internal.h | 8 ++++++-- libhb/scan.c | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libhb/hb.c b/libhb/hb.c index 7055e5cf7..7a4bba99a 100644 --- a/libhb/hb.c +++ b/libhb/hb.c @@ -819,8 +819,10 @@ void hb_get_preview( hb_handle_t * h, hb_title_t * title, int picture, * @param prog_diff Sensitivity for detecting different colors on progressive frames * @param prog_threshold Sensitivity for flagging progressive frames as combed */ -int hb_detect_comb( hb_buffer_t * buf, int width, int height, int color_equal, int color_diff, int threshold, int prog_equal, int prog_diff, int prog_threshold ) +int hb_detect_comb( hb_buffer_t * buf, int color_equal, int color_diff, int threshold, int prog_equal, int prog_diff, int prog_threshold ) { + int width = buf->width; + int height = buf->height; int j, k, n, off, cc_1, cc_2, cc[3]; // int flag[3] ; // debugging flag uint16_t s1, s2, s3, s4; diff --git a/libhb/hb.h b/libhb/hb.h index 0a3af6019..382aec58a 100644 --- a/libhb/hb.h +++ b/libhb/hb.h @@ -57,7 +57,7 @@ hb_list_t * hb_get_titles( hb_handle_t * ); /* hb_detect_comb() Analyze a frame for interlacing artifacts, returns true if they're found. Taken from Thomas Oestreich's 32detect filter in the Transcode project. */ -int hb_detect_comb( hb_buffer_t * buf, int width, int height, int color_equal, int color_diff, int threshold, int prog_equal, int prog_diff, int prog_threshold ); +int hb_detect_comb( hb_buffer_t * buf, int color_equal, int color_diff, int threshold, int prog_equal, int prog_diff, int prog_threshold ); void hb_get_preview_by_index( hb_handle_t *, int, int, uint8_t * ); void hb_get_preview( hb_handle_t *, hb_title_t *, int, diff --git a/libhb/internal.h b/libhb/internal.h index 75635d73c..3a199b208 100644 --- a/libhb/internal.h +++ b/libhb/internal.h @@ -147,8 +147,12 @@ static inline hb_buffer_t * hb_video_buffer_init( int width, int height ) // if we do "/2". The code here matches the calculation for // PIX_FMT_YUV420P in ffmpeg's avpicture_fill() which is required // for most of HB's filters to work right. - return hb_buffer_init( width * height + ( ( width+1 ) >> 1 ) * - ( ( height+1 ) >> 1 ) * 2 ); + hb_buffer_t * b = hb_buffer_init( width * height + ( ( width+1 ) >> 1 ) * + ( ( height+1 ) >> 1 ) * 2 ); + b->width = width; + b->height = height; + + return b; } // this routine 'moves' data from src to dst by interchanging 'data', diff --git a/libhb/scan.c b/libhb/scan.c index 9f4fb73cc..8c8231695 100644 --- a/libhb/scan.c +++ b/libhb/scan.c @@ -736,7 +736,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title ) } /* Check preview for interlacing artifacts */ - if( hb_detect_comb( vid_buf, vid_info.width, vid_info.height, 10, 30, 9, 10, 30, 9 ) ) + if( hb_detect_comb( vid_buf, 10, 30, 9, 10, 30, 9 ) ) { hb_deep_log( 2, "Interlacing detected in preview frame %i", i+1); interlaced_preview_count++; -- 2.40.0