summaryrefslogtreecommitdiffstats
path: root/libhb/scan.c
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2012-11-12 08:22:07 +0000
committerjstebbins <[email protected]>2012-11-12 08:22:07 +0000
commitab5445d6f279a3477c08f069ff3329b696cb9ac8 (patch)
tree28b1f1aa52db4f2f0d35a35950f6486955703426 /libhb/scan.c
parentcf1f034f914348d0f0bfcd5f8902f0a3fb519273 (diff)
Improve management of titles and jobs
Cleans up several several unavoidable memory leaks caused by old api. Clearly separates titles from jobs. Titles are set during scan and never modified now. Since titles are immutable, this lead to API some changes. For example, We were setting chapter names in the title from the front ends. Now these get set in the job. These new APIs allow us to start moving away from our use of title->job. Eventually, I would like to eliminate title->job completely, but the mac ui is too tightly tied to using this field to allow removing it at this time. So there is temporarily a convenience function used only by the mac ui that allows it to continue using title->job and also use the new APIs. New APIs: typedef struct hb_title_set_s hb_title_set_t; struct hb_title_set_s { hb_list_t * list_title; int feature; // Detected DVD feature title }; hb_title_set_t * hb_get_title_set( hb_handle_t * ); This is just something I added to clean up how "feature title" info is passed. hb_job_t * hb_job_init( hb_title_t * title ); Initializes a new job with default settings from the title. hb_job_t * hb_job_init_by_index( hb_handle_t *h, int title_index ); Same as hb_job_init(). For use by win Interop lib. void hb_job_reset( hb_job_t * job ); Convenience function for the MacUi. Clears audio, subtitle, and filter lists. The macui still uses title->job because it is so intricately tied to it. So I created this convenience function that it can call after adding a job. void hb_job_close( hb_job_t ** job ); Releases the job an all resources it contains. void hb_job_set_advanced_opts( hb_job_t *job, const char *advanced_opts ); Makes a copy of "advanced_opts" and stores in job. Freed by hb_job_close(). void hb_job_set_file( hb_job_t *job, const char *file ); Makes a copy of "file" and stores in job. Freed by hb_job_close(). void hb_chapter_set_title(hb_chapter_t *chapter, const char *title); Makes a copy of "title" and stores in chapter. Freed by hb_chapter_close(). Recommended usage (cli and lingui are updated to do this): job = hb_job_init( title ); // set job settings ... hb_add(h, job); hb_job_close( &job ); I have also added new APIs for managing metadata. These are used to add metadata to a job. void hb_metadata_set_name( hb_metadata_t *metadata, const char *name ); void hb_metadata_set_artist( hb_metadata_t *metadata, const char *artist ); void hb_metadata_set_composer( hb_metadata_t *metadata, const char *composer ); void hb_metadata_set_release_date( hb_metadata_t *metadata, const char *release_date ); void hb_metadata_set_comment( hb_metadata_t *metadata, const char *comment ); void hb_metadata_set_genre( hb_metadata_t *metadata, const char *genre ); void hb_metadata_set_album( hb_metadata_t *metadata, const char *album ); void hb_metadata_set_coverart( hb_metadata_t *metadata, const uint8_t *coverart, int size ); Example: job = hb_job_init( &job ); // set job settings ... hb_metadata_set_artist( job->metadata, "Danny Elfman" ); hb_add(h, job); hb_job_close( &job ); Some APIs have changed in order to avoid using title incorrectly and use the new hb_title_set_t. -void hb_autopassthru_apply_settings( hb_job_t * job, hb_title_t * title ); +void hb_autopassthru_apply_settings( hb_job_t * job ); -void hb_get_preview( hb_handle_t *, hb_title_t *, int, uint8_t * ); +void hb_get_preview( hb_handle_t *, hb_job_t *, int, uint8_t * ); hb_thread_t * hb_scan_init( hb_handle_t *, volatile int * die, const char * path, int title_index, - hb_list_t * list_title, int preview_count, + hb_title_set_t * title_set, int preview_count, int store_previews, uint64_t min_duration ); These APIs have been removed. Win Interop will need some changes. I think what I've provided will be suffecient, but let me know if it's not. -void hb_get_preview_by_index( hb_handle_t *, int, int, uint8_t * ); -void hb_set_anamorphic_size_by_index( hb_handle_t *, int, - int *output_width, int *output_height, - int *output_par_width, int *output_par_height ); git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5058 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/scan.c')
-rw-r--r--libhb/scan.c104
1 files changed, 31 insertions, 73 deletions
diff --git a/libhb/scan.c b/libhb/scan.c
index 10ed35391..0163af406 100644
--- a/libhb/scan.c
+++ b/libhb/scan.c
@@ -18,7 +18,7 @@ typedef struct
char * path;
int title_index;
- hb_list_t * list_title;
+ hb_title_set_t * title_set;
hb_bd_t * bd;
hb_dvd_t * dvd;
@@ -51,7 +51,7 @@ static const char *aspect_to_string( double aspect )
hb_thread_t * hb_scan_init( hb_handle_t * handle, volatile int * die,
const char * path, int title_index,
- hb_list_t * list_title, int preview_count,
+ hb_title_set_t * title_set, int preview_count,
int store_previews, uint64_t min_duration )
{
hb_scan_t * data = calloc( sizeof( hb_scan_t ), 1 );
@@ -60,7 +60,7 @@ hb_thread_t * hb_scan_init( hb_handle_t * handle, volatile int * die,
data->die = die;
data->path = strdup( path );
data->title_index = title_index;
- data->list_title = list_title;
+ data->title_set = title_set;
data->preview_count = preview_count;
data->store_previews = store_previews;
@@ -88,7 +88,8 @@ static void ScanFunc( void * _data )
if( data->title_index )
{
/* Scan this title only */
- hb_list_add( data->list_title, hb_bd_title_scan( data->bd,
+ hb_list_add( data->title_set->list_title,
+ hb_bd_title_scan( data->bd,
data->title_index, 0 ) );
}
else
@@ -96,10 +97,12 @@ static void ScanFunc( void * _data )
/* Scan all titles */
for( i = 0; i < hb_bd_title_count( data->bd ); i++ )
{
- hb_list_add( data->list_title, hb_bd_title_scan( data->bd,
+ hb_list_add( data->title_set->list_title,
+ hb_bd_title_scan( data->bd,
i + 1, data->min_title_duration ) );
}
- feature = hb_bd_main_feature( data->bd, data->list_title );
+ feature = hb_bd_main_feature( data->bd,
+ data->title_set->list_title );
}
}
else if( ( data->dvd = hb_dvd_init( data->path ) ) )
@@ -109,7 +112,8 @@ static void ScanFunc( void * _data )
if( data->title_index )
{
/* Scan this title only */
- hb_list_add( data->list_title, hb_dvd_title_scan( data->dvd,
+ hb_list_add( data->title_set->list_title,
+ hb_dvd_title_scan( data->dvd,
data->title_index, 0 ) );
}
else
@@ -117,10 +121,12 @@ static void ScanFunc( void * _data )
/* Scan all titles */
for( i = 0; i < hb_dvd_title_count( data->dvd ); i++ )
{
- hb_list_add( data->list_title, hb_dvd_title_scan( data->dvd,
+ hb_list_add( data->title_set->list_title,
+ hb_dvd_title_scan( data->dvd,
i + 1, data->min_title_duration ) );
}
- feature = hb_dvd_main_feature( data->dvd, data->list_title );
+ feature = hb_dvd_main_feature( data->dvd,
+ data->title_set->list_title );
}
}
else if ( ( data->batch = hb_batch_init( data->path ) ) )
@@ -131,7 +137,7 @@ static void ScanFunc( void * _data )
title = hb_batch_title_scan( data->batch, data->title_index );
if ( title )
{
- hb_list_add( data->list_title, title );
+ hb_list_add( data->title_set->list_title, title );
}
}
else
@@ -144,7 +150,7 @@ static void ScanFunc( void * _data )
title = hb_batch_title_scan( data->batch, i + 1 );
if ( title != NULL )
{
- hb_list_add( data->list_title, title );
+ hb_list_add( data->title_set->list_title, title );
}
}
}
@@ -156,7 +162,7 @@ static void ScanFunc( void * _data )
{
title = hb_stream_title_scan( data->stream, title );
if ( title )
- hb_list_add( data->list_title, title );
+ hb_list_add( data->title_set->list_title, title );
}
else
{
@@ -166,7 +172,7 @@ static void ScanFunc( void * _data )
}
}
- for( i = 0; i < hb_list_count( data->list_title ); )
+ for( i = 0; i < hb_list_count( data->title_set->list_title ); )
{
int j;
hb_state_t state;
@@ -176,7 +182,7 @@ static void ScanFunc( void * _data )
{
goto finish;
}
- title = hb_list_item( data->list_title, i );
+ title = hb_list_item( data->title_set->list_title, i );
#define p state.param.scanning
/* Update the UI */
@@ -185,7 +191,7 @@ static void ScanFunc( void * _data )
p.title_count = data->dvd ? hb_dvd_title_count( data->dvd ) :
data->bd ? hb_bd_title_count( data->bd ) :
data->batch ? hb_batch_title_count( data->batch ) :
- hb_list_count(data->list_title);
+ hb_list_count(data->title_set->list_title);
hb_set_state( data->h, &state );
#undef p
@@ -194,7 +200,7 @@ static void ScanFunc( void * _data )
if( !DecodePreviews( data, title ) )
{
/* TODO: free things */
- hb_list_rem( data->list_title, title );
+ hb_list_rem( data->title_set->list_title, title );
for( j = 0; j < hb_list_count( title->list_audio ); j++)
{
audio = hb_list_item( title->list_audio, j );
@@ -247,64 +253,16 @@ static void ScanFunc( void * _data )
i++;
}
- /* Init jobs templates */
- for( i = 0; i < hb_list_count( data->list_title ); i++ )
- {
- hb_job_t * job;
-
- title = hb_list_item( data->list_title, i );
- job = calloc( sizeof( hb_job_t ), 1 );
- title->job = job;
-
- job->title = title;
- job->feature = feature;
+ data->title_set->feature = feature;
- /* Set defaults settings */
- job->chapter_start = 1;
- job->chapter_end = hb_list_count( title->list_chapter );
-
- /* Autocrop by default. Gnark gnark */
- memcpy( job->crop, title->crop, 4 * sizeof( int ) );
-
- /* Preserve a source's pixel aspect, if it's available. */
- if( title->pixel_aspect_width && title->pixel_aspect_height )
- {
- job->anamorphic.par_width = title->pixel_aspect_width;
- job->anamorphic.par_height = title->pixel_aspect_height;
- }
-
- if( title->aspect != 0 && title->aspect != 1. &&
- !job->anamorphic.par_width && !job->anamorphic.par_height)
- {
- hb_reduce( &job->anamorphic.par_width, &job->anamorphic.par_height,
- (int)(title->aspect * title->height + 0.5), title->width );
- }
-
- job->width = title->width - job->crop[2] - job->crop[3];
- hb_fix_aspect( job, HB_KEEP_WIDTH );
- if( job->height > title->height - job->crop[0] - job->crop[1] )
- {
- job->height = title->height - job->crop[0] - job->crop[1];
- hb_fix_aspect( job, HB_KEEP_HEIGHT );
- }
-
- hb_log( "scan: title (%d) job->width:%d, job->height:%d",
- i, job->width, job->height );
-
- job->keep_ratio = 1;
-
- job->vcodec = HB_VCODEC_FFMPEG_MPEG4;
- job->vquality = -1.0;
- job->vbitrate = 1000;
- job->pass = 0;
- job->vrate = title->rate;
- job->vrate_base = title->rate_base;
-
- job->list_audio = hb_list_init();
- job->list_subtitle = hb_list_init();
- job->list_filter = hb_list_init();
-
- job->mux = HB_MUX_MP4;
+ /* Mark title scan complete and init jobs */
+ for( i = 0; i < hb_list_count( data->title_set->list_title ); i++ )
+ {
+ title = hb_list_item( data->title_set->list_title, i );
+ title->flags |= HBTF_SCAN_COMPLETE;
+#if defined(HB_TITLE_JOBS)
+ title->job = hb_job_init( title );
+#endif
}
finish: