summaryrefslogtreecommitdiffstats
path: root/libhb/scan.c
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2014-12-16 16:50:50 +0000
committerjstebbins <[email protected]>2014-12-16 16:50:50 +0000
commitf56efd7b52c89da8cac55b4d4a187f2c87fdfee6 (patch)
tree24eacb856704fa8e4b8b8f0edc76568916f70255 /libhb/scan.c
parentd0a975e42dcab93e1d2eead350fb1ba3951d977c (diff)
json: add json APIs
There are several changes to job and title structs that break current windows interop code. The interop code should be changed such that it only uses json APIs. So if there is any missing features (or bugs) in these APIs, please let me know. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6602 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/scan.c')
-rw-r--r--libhb/scan.c106
1 files changed, 57 insertions, 49 deletions
diff --git a/libhb/scan.c b/libhb/scan.c
index 8c8ce433f..d57f3ecba 100644
--- a/libhb/scan.c
+++ b/libhb/scan.c
@@ -42,15 +42,19 @@ static void UpdateState1(hb_scan_t *scan, int title);
static void UpdateState2(hb_scan_t *scan, int title);
static void UpdateState3(hb_scan_t *scan, int preview);
-static const char *aspect_to_string( double aspect )
+static const char *aspect_to_string(hb_rational_t *dar)
{
+ double aspect = (double)dar->num / dar->den;
switch ( (int)(aspect * 9.) )
{
case 9 * 4 / 3: return "4:3";
case 9 * 16 / 9: return "16:9";
}
static char arstr[32];
- sprintf( arstr, aspect >= 1.? "%.2f:1" : "1:%.2f", aspect );
+ if (aspect >= 1)
+ sprintf(arstr, "%.2f:1", aspect);
+ else
+ sprintf(arstr, "1:%.2f", 1. / aspect );
return arstr;
}
@@ -249,8 +253,8 @@ static void ScanFunc( void * _data )
hb_subtitle_t *subtitle = hb_list_item( title->list_subtitle, j );
if ( subtitle->source == VOBSUB || subtitle->source == PGSSUB )
{
- subtitle->width = title->width;
- subtitle->height = title->height;
+ subtitle->width = title->geometry.width;
+ subtitle->height = title->geometry.height;
}
}
}
@@ -460,11 +464,12 @@ static int has_resolution_change( info_list_t *info_list )
if( !info_list[0].count )
return 0;
- w = info_list[0].info.width;
- h = info_list[0].info.height;
+ w = info_list[0].info.geometry.width;
+ h = info_list[0].info.geometry.height;
for ( i = 1; info_list[i].count; ++i )
{
- if ( w != info_list[i].info.width || h != info_list[i].info.height )
+ if (w != info_list[i].info.geometry.width ||
+ h != info_list[i].info.geometry.height)
return 1;
}
return 0;
@@ -726,7 +731,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
remember_info( info_list, &vid_info );
- if( is_close_to( vid_info.rate_base, 900900, 100 ) &&
+ if( is_close_to( vid_info.rate.den, 900900, 100 ) &&
( vid_buf->s.flags & PIC_FLAG_REPEAT_FIRST_FIELD ) )
{
/* Potentially soft telecine material */
@@ -741,7 +746,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
doubled_frame_count++;
}
- if( is_close_to( vid_info.rate_base, 1126125, 100 ) )
+ if( is_close_to( vid_info.rate.den, 1126125, 100 ) )
{
// Frame FPS is 23.976 (meaning it's progressive), so start keeping
// track of how many are reporting at that speed. When enough
@@ -770,7 +775,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
/* Detect black borders */
int top, bottom, left, right;
- int h4 = vid_info.height / 4, w4 = vid_info.width / 4;
+ int h4 = vid_info.geometry.height / 4, w4 = vid_info.geometry.width / 4;
// When widescreen content is matted to 16:9 or 4:3 there's sometimes
// a thin border on the outer edge of the matte. On TV content it can be
@@ -780,7 +785,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
// we can crop the matte. The border width depends on the resolution
// (12 pixels on 1080i looks visually the same as 4 pixels on 480i)
// so we allow the border to be up to 1% of the frame height.
- const int border = vid_info.height / 100;
+ const int border = vid_info.geometry.height / 100;
for ( top = border; top < h4; ++top )
{
@@ -803,14 +808,14 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
}
for ( bottom = border; bottom < h4; ++bottom )
{
- if ( ! row_all_dark( vid_buf, vid_info.height - 1 - bottom ) )
+ if ( ! row_all_dark( vid_buf, vid_info.geometry.height - 1 - bottom ) )
break;
}
if ( bottom <= border )
{
for ( bottom = 0; bottom < border; ++bottom )
{
- if ( ! row_all_dark( vid_buf, vid_info.height - 1 - bottom ) )
+ if ( ! row_all_dark( vid_buf, vid_info.geometry.height - 1 - bottom ) )
break;
}
if ( bottom >= border )
@@ -825,7 +830,7 @@ static int DecodePreviews( hb_scan_t * data, hb_title_t * title, int flush )
}
for ( right = 0; right < w4; ++right )
{
- if ( ! column_all_dark( vid_buf, top, bottom, vid_info.width - 1 - right ) )
+ if ( ! column_all_dark( vid_buf, top, bottom, vid_info.geometry.width - 1 - right ) )
break;
}
@@ -878,36 +883,36 @@ skip_preview:
{
title->video_codec_name = strdup( vid_info.name );
}
- title->width = vid_info.width;
- title->height = vid_info.height;
- if ( vid_info.rate && vid_info.rate_base )
+ title->geometry.width = vid_info.geometry.width;
+ title->geometry.height = vid_info.geometry.height;
+ if (vid_info.rate.num && vid_info.rate.den)
{
- // if the frame rate is very close to one of our "common" framerates,
- // assume it actually is said frame rate; e.g. some 24000/1001 sources
- // may have a rate_base of 1126124 (instead of 1126125)
+ // if the frame rate is very close to one of our "common"
+ // framerates, assume it actually is said frame rate;
+ // e.g. some 24000/1001 sources may have a rate.den of 1126124
+ // instead of 1126125
const hb_rate_t *video_framerate = NULL;
while ((video_framerate = hb_video_framerate_get_next(video_framerate)) != NULL)
{
- if (is_close_to(vid_info.rate_base, video_framerate->rate, 100))
+ if (is_close_to(vid_info.rate.den, video_framerate->rate, 100))
{
- vid_info.rate_base = video_framerate->rate;
+ vid_info.rate.den = video_framerate->rate;
break;
}
}
- title->rate = vid_info.rate;
- title->rate_base = vid_info.rate_base;
- if( vid_info.rate_base == 900900 )
+ title->vrate = vid_info.rate;
+ if( vid_info.rate.den == 900900 )
{
if( npreviews >= 4 && pulldown_count >= npreviews / 4 )
{
- title->rate_base = 1126125;
+ title->vrate.den = 1126125;
hb_deep_log( 2, "Pulldown detected, setting fps to 23.976" );
}
if( npreviews >= 2 && progressive_count >= npreviews / 2 )
{
// We've already deduced that the frame rate is 23.976,
// so set it back again.
- title->rate_base = 1126125;
+ title->vrate.den = 1126125;
hb_deep_log( 2, "Title's mostly NTSC Film, setting fps to 23.976" );
}
}
@@ -915,16 +920,16 @@ skip_preview:
{
// We've detected that a significant number of the frames
// have been doubled in duration by repeat flags.
- title->rate_base = 2 * vid_info.rate_base;
- hb_deep_log( 2, "Repeat frames detected, setting fps to %.3f", (float)title->rate / title->rate_base );
+ title->vrate.den = 2 * vid_info.rate.den;
+ hb_deep_log(2, "Repeat frames detected, setting fps to %.3f",
+ (float)title->vrate.num / title->vrate.den );
}
}
title->video_bitrate = vid_info.bitrate;
- if( vid_info.pixel_aspect_width && vid_info.pixel_aspect_height )
+ if( vid_info.geometry.par.num && vid_info.geometry.par.den )
{
- title->pixel_aspect_width = vid_info.pixel_aspect_width;
- title->pixel_aspect_height = vid_info.pixel_aspect_height;
+ title->geometry.par = vid_info.geometry.par;
}
title->color_prim = vid_info.color_prim;
title->color_transfer = vid_info.color_transfer;
@@ -935,11 +940,10 @@ skip_preview:
// TODO: check video dimensions
title->opencl_support = !!hb_opencl_available();
- // compute the aspect ratio based on the storage dimensions and the
- // pixel aspect ratio (if supplied) or just storage dimensions if no PAR.
- title->aspect = (double)title->width / (double)title->height;
- title->aspect *= (double)title->pixel_aspect_width /
- (double)title->pixel_aspect_height;
+ // compute the aspect ratio based on the storage dimensions and PAR.
+ hb_reduce(&title->dar.num, &title->dar.den,
+ title->geometry.par.num * title->geometry.width,
+ title->geometry.height * title->geometry.par.den);
// For unknown reasons some French PAL DVDs put the original
// content's aspect ratio into the mpeg PAR even though it's
@@ -948,14 +952,18 @@ skip_preview:
// aspect ratio from the DVD metadata. So, if the aspect computed
// from the PAR is different from the container's aspect we use
// the container's aspect & recompute the PAR from it.
- if( title->container_aspect && (int)(title->aspect * 9) != (int)(title->container_aspect * 9) )
+ if (data->dvd &&
+ (title->dar.num != title->container_dar.num ||
+ title->dar.den != title->container_dar.den))
{
- hb_log("scan: content PAR gives wrong aspect %.2f; "
- "using container aspect %.2f", title->aspect,
- title->container_aspect );
- title->aspect = title->container_aspect;
- hb_reduce( &title->pixel_aspect_width, &title->pixel_aspect_height,
- (int)(title->aspect * title->height + 0.5), title->width );
+ hb_log("scan: content PAR gives wrong aspect %d:%d; "
+ "using container aspect %d:%d",
+ title->dar.num, title->dar.den,
+ title->container_dar.num, title->container_dar.den);
+ title->dar = title->container_dar;
+ hb_reduce(&title->geometry.par.num, &title->geometry.par.den,
+ title->geometry.height * title->dar.num,
+ title->geometry.width * title->dar.den);
}
// don't try to crop unless we got at least 3 previews
@@ -977,11 +985,11 @@ skip_preview:
hb_log( "scan: %d previews, %dx%d, %.3f fps, autocrop = %d/%d/%d/%d, "
"aspect %s, PAR %d:%d",
- npreviews, title->width, title->height, (float) title->rate /
- (float) title->rate_base,
+ npreviews, title->geometry.width, title->geometry.height,
+ (float)title->vrate.num / title->vrate.den,
title->crop[0], title->crop[1], title->crop[2], title->crop[3],
- aspect_to_string( title->aspect ), title->pixel_aspect_width,
- title->pixel_aspect_height );
+ aspect_to_string(&title->dar),
+ title->geometry.par.num, title->geometry.par.den);
if( interlaced_preview_count >= ( npreviews / 2 ) )
{
@@ -1092,7 +1100,7 @@ static void LookForAudio( hb_title_t * title, hb_buffer_t * b )
hb_fifo_flush( audio->priv.scan_cache );
hb_fifo_close( &audio->priv.scan_cache );
- audio->config.in.samplerate = info.rate;
+ audio->config.in.samplerate = info.rate.num;
audio->config.in.samples_per_frame = info.samples_per_frame;
audio->config.in.bitrate = info.bitrate;
audio->config.in.matrix_encoding = info.matrix_encoding;