summaryrefslogtreecommitdiffstats
path: root/macosx
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 /macosx
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 'macosx')
-rw-r--r--macosx/ChapterTitles.m17
-rw-r--r--macosx/Controller.m62
-rw-r--r--macosx/HBPreviewController.m4
3 files changed, 38 insertions, 45 deletions
diff --git a/macosx/ChapterTitles.m b/macosx/ChapterTitles.m
index 893c2dc22..2fcd77272 100644
--- a/macosx/ChapterTitles.m
+++ b/macosx/ChapterTitles.m
@@ -29,18 +29,18 @@
if (!title)
return;
- int count = hb_list_count( title->list_chapter );
+ hb_job_t * job = title->job;
+ int count = hb_list_count( job->list_chapter );
for( i = 0; i < count; i++ )
{
- hb_chapter_t *chapter = hb_list_item( title->list_chapter, i );
+ hb_chapter_t *chapter = hb_list_item( job->list_chapter, i );
- if( chapter != NULL && chapter->title[0] == '\0' )
+ if( chapter != NULL && chapter->title == NULL )
{
chapterString = [NSString stringWithFormat:@"Chapter %2d",(i+1)];
- strncpy( chapter->title, [chapterString UTF8String], 1023);
- chapter->title[1023] = '\0';
+ hb_chapter_set_title( chapter, [chapterString UTF8String]);
}
}
@@ -67,12 +67,11 @@
{
if( fTitle )
{
- hb_chapter_t *chapter = hb_list_item( fTitle->list_chapter, rowIndex );
+ hb_chapter_t *chapter = hb_list_item( fTitle->job->list_chapter, rowIndex );
if( chapter != NULL )
{
- strncpy( chapter->title, [anObject UTF8String], 1023);
- chapter->title[1023] = '\0';
+ hb_chapter_set_title( chapter, [anObject UTF8String]);
}
}
}
@@ -92,7 +91,7 @@
{
if( fTitle )
{
- hb_chapter_t *chapter = hb_list_item( fTitle->list_chapter, rowIndex );
+ hb_chapter_t *chapter = hb_list_item( fTitle->job->list_chapter, rowIndex );
if( chapter != NULL )
{
diff --git a/macosx/Controller.m b/macosx/Controller.m
index c3edceb1a..dea32a40c 100644
--- a/macosx/Controller.m
+++ b/macosx/Controller.m
@@ -1982,13 +1982,13 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It
- (IBAction) showNewScan:(id)sender
{
- hb_list_t * list;
+ hb_title_set_t * title_set;
hb_title_t * title = NULL;
int feature_title=0; // Used to store the main feature title
- list = hb_get_titles( fHandle );
+ title_set = hb_get_title_set( fHandle );
- if( !hb_list_count( list ) )
+ if( !hb_list_count( title_set->list_title ) )
{
/* We display a message if a valid dvd source was not chosen */
[fSrcDVD2Field setStringValue: @"No Valid Source Found"];
@@ -2036,9 +2036,9 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It
[[fWindow toolbar] validateVisibleItems];
[fSrcTitlePopUp removeAllItems];
- for( int i = 0; i < hb_list_count( list ); i++ )
+ for( int i = 0; i < hb_list_count( title_set->list_title ); i++ )
{
- title = (hb_title_t *) hb_list_item( list, i );
+ title = (hb_title_t *) hb_list_item( title_set->list_title, i );
currentSource = [NSString stringWithUTF8String: title->name];
/*Set DVD Name at top of window with the browsedSourceDisplayName grokked right before -performScan */
@@ -2081,7 +2081,7 @@ static NSString * ChooseSourceIdentifier = @"Choose Source It
}
/* See if this is the main feature according to libhb */
- if (title->index == title->job->feature)
+ if (title->index == title_set->feature)
{
feature_title = i;
}
@@ -2503,10 +2503,10 @@ fWorkingCount = 0;
*/
int i;
NSMutableArray *ChapterNamesArray = [[NSMutableArray alloc] init];
- int chaptercount = hb_list_count( fTitle->list_chapter );
+ int chaptercount = hb_list_count( fTitle->job->list_chapter );
for( i = 0; i < chaptercount; i++ )
{
- hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( fTitle->list_chapter, i );
+ hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( fTitle->job->list_chapter, i );
if( chapter != NULL )
{
[ChapterNamesArray addObject:[NSString stringWithUTF8String:chapter->title]];
@@ -2844,7 +2844,7 @@ fWorkingCount = 0;
NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:currentQueueEncodeIndex];
[self writeToActivityLog: "Preset: %s", [[queueToApply objectForKey:@"PresetName"] UTF8String]];
[self writeToActivityLog: "processNewQueueEncode number of passes expected is: %d", ([[queueToApply objectForKey:@"VideoTwoPass"] intValue] + 1)];
- job->file = [[queueToApply objectForKey:@"DestinationPath"] UTF8String];
+ hb_job_set_file(job, [[queueToApply objectForKey:@"DestinationPath"] UTF8String]);
[self prepareJob];
/*
@@ -2852,16 +2852,14 @@ fWorkingCount = 0;
*/
if( job->indepth_scan == 1 )
{
- char *x264opts_tmp;
+ NSString *advanced_opts_tmp = [NSString stringWithUTF8String: job->advanced_opts];
/*
* When subtitle scan is enabled do a fast pre-scan job
* which will determine which subtitles to enable, if any.
*/
job->pass = -1;
- x264opts_tmp = job->advanced_opts;
-
- job->advanced_opts = NULL;
+ hb_job_set_advanced_opts(job, NULL);
job->indepth_scan = 1;
@@ -2870,7 +2868,7 @@ fWorkingCount = 0;
* Add the pre-scan job
*/
hb_add( fQueueEncodeLibhb, job );
- job->advanced_opts = x264opts_tmp;
+ hb_job_set_advanced_opts(job, [advanced_opts_tmp UTF8String] );
}
@@ -2900,8 +2898,10 @@ fWorkingCount = 0;
[queueToApply setObject:[NSNumber numberWithInt:1] forKey:@"Status"];
[self saveQueueFileItem];
- /* we need to clean up the various lists after the job(s) have been set */
- hb_reset_job( job );
+ /* libhb makes a copy of the job. So we need to free any resource
+ * that were allocated in construction of the job. This empties
+ * the audio, subtitle, and filter lists */
+ hb_job_reset(job);
/* We should be all setup so let 'er rip */
[self doRip];
@@ -3231,13 +3231,11 @@ fWorkingCount = 0;
/* Lets use this as per Nyx, Thanks Nyx! */
/* For previews we ignore the turbo option for the first pass of two since we only use 1 pass */
job->fastfirstpass = 0;
- job->advanced_opts = strdup( [[fAdvancedOptions optionsString] UTF8String] );
-
-
+ hb_job_set_advanced_opts(job, [[fAdvancedOptions optionsString] UTF8String] );
}
else if( job->vcodec & HB_VCODEC_FFMPEG_MASK )
{
- job->advanced_opts = strdup( [[fAdvancedOptions optionsStringLavc] UTF8String] );
+ hb_job_set_advanced_opts(job, [[fAdvancedOptions optionsStringLavc] UTF8String] );
}
/* Video settings */
@@ -3689,11 +3687,10 @@ bool one_burned = FALSE;
id tempObject;
while (tempObject = [enumerator nextObject])
{
- hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( title->list_chapter, i );
+ hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( job->list_chapter, i );
if( chapter != NULL )
{
- strncpy( chapter->title, [tempObject UTF8String], 1023);
- chapter->title[1023] = '\0';
+ hb_chapter_set_title( chapter, [tempObject UTF8String] );
}
i++;
}
@@ -3726,13 +3723,13 @@ bool one_burned = FALSE;
{
job->fastfirstpass = 0;
}
- job->advanced_opts = strdup( [[queueToApply objectForKey:@"x264Option"] UTF8String] );
+ hb_job_set_advanced_opts( job, [[queueToApply objectForKey:@"x264Option"] UTF8String] );
}
else if( job->vcodec & HB_VCODEC_FFMPEG_MASK )
{
if ([queueToApply objectForKey:@"lavcOption"])
{
- job->advanced_opts = strdup( [[queueToApply objectForKey:@"lavcOption"] UTF8String] );
+ hb_job_set_advanced_opts( job, [[queueToApply objectForKey:@"lavcOption"] UTF8String] );
}
}
@@ -4579,7 +4576,6 @@ bool one_burned = FALSE;
}
/* Start Get and set the initial pic size for display */
- hb_job_t * job = title->job;
fTitle = title;
/* Set Auto Crop to on upon selecting a new title */
@@ -4587,12 +4583,12 @@ bool one_burned = FALSE;
/* We get the originial output picture width and height and put them
in variables for use with some presets later on */
- PicOrigOutputWidth = job->width;
- PicOrigOutputHeight = job->height;
- AutoCropTop = job->crop[0];
- AutoCropBottom = job->crop[1];
- AutoCropLeft = job->crop[2];
- AutoCropRight = job->crop[3];
+ PicOrigOutputWidth = title->width;
+ PicOrigOutputHeight = title->height;
+ AutoCropTop = title->crop[0];
+ AutoCropBottom = title->crop[1];
+ AutoCropLeft = title->crop[2];
+ AutoCropRight = title->crop[3];
/* Reset the new title in fPictureController && fPreviewController*/
[fPictureController SetTitle:title];
@@ -4614,8 +4610,6 @@ bool one_burned = FALSE;
userInfo: [NSDictionary dictionaryWithObjectsAndKeys:
[NSData dataWithBytesNoCopy: &fTitle length: sizeof(fTitle) freeWhenDone: NO], keyTitleTag,
nil]]];
-
-
[fVidRatePopUp selectItemAtIndex: 0];
/* we run the picture size values through calculatePictureSizing to get all picture setting information*/
diff --git a/macosx/HBPreviewController.m b/macosx/HBPreviewController.m
index 7b59f712b..d7a07dc8a 100644
--- a/macosx/HBPreviewController.m
+++ b/macosx/HBPreviewController.m
@@ -698,7 +698,7 @@
buffer = (uint8_t *) realloc( buffer, bufferSize );
}
- hb_get_preview( handle, title, pictureIndex, buffer );
+ hb_get_preview( handle, title->job, pictureIndex, buffer );
// Create an NSBitmapImageRep and copy the libhb image into it, converting it from
// libhb's format to one suitable for NSImage. Along the way, we'll strip off the
@@ -907,7 +907,7 @@
hb_add( fPreviewLibhb, job );
/* we need to clean up the various lists after the job(s) have been set */
- hb_reset_job( job );
+ hb_job_reset( job );
[fEncodingControlBox setHidden: NO];
[fPictureControlBox setHidden: YES];