summaryrefslogtreecommitdiffstats
path: root/libhb/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'libhb/common.c')
-rw-r--r--libhb/common.c172
1 files changed, 77 insertions, 95 deletions
diff --git a/libhb/common.c b/libhb/common.c
index 80b526c2a..60c2b4ed7 100644
--- a/libhb/common.c
+++ b/libhb/common.c
@@ -1671,26 +1671,10 @@ void hb_title_close( hb_title_t ** _t )
*_t = NULL;
}
-/*
- * Create a pristine job structure from a title
- * title_index is 1 based
- */
-hb_job_t * hb_job_init_by_index( hb_handle_t * h, int title_index )
-{
- hb_title_set_t *title_set = hb_get_title_set( h );
- hb_title_t * title = hb_list_item( title_set->list_title,
- title_index - 1 );
- return hb_job_init( title );
-}
-
-hb_job_t * hb_job_init( hb_title_t * title )
+static void job_setup( hb_job_t * job, hb_title_t * title )
{
- hb_job_t * job;
-
- if ( title == NULL )
- return NULL;
-
- job = calloc( sizeof( hb_job_t ), 1 );
+ if ( job == NULL || title == NULL )
+ return;
job->title = title;
@@ -1741,27 +1725,28 @@ hb_job_t * hb_job_init( hb_title_t * title )
job->list_attachment = hb_attachment_list_copy( title->list_attachment );
job->metadata = hb_metadata_copy( title->metadata );
-
- return job;
}
-/**
- * Clean up the job structure so that is is ready for setting up a new job.
- * Should be called by front-ends after hb_add().
- */
-/**********************************************************************
- * hb_job_reset
- **********************************************************************
- *
- *********************************************************************/
-void hb_job_reset( hb_job_t * job )
+static void job_clean( hb_job_t * job )
{
- if ( job )
+ if (job)
{
+ hb_chapter_t *chapter;
hb_audio_t *audio;
hb_subtitle_t *subtitle;
hb_filter_object_t *filter;
- hb_title_t * title = job->title;
+ hb_attachment_t *attachment;
+
+ free(job->file);
+ free(job->advanced_opts);
+
+ // clean up chapter list
+ while( ( chapter = hb_list_item( job->list_chapter, 0 ) ) )
+ {
+ hb_list_rem( job->list_chapter, chapter );
+ hb_chapter_close( &chapter );
+ }
+ hb_list_close( &job->list_chapter );
// clean up audio list
while( ( audio = hb_list_item( job->list_audio, 0 ) ) )
@@ -1769,6 +1754,7 @@ void hb_job_reset( hb_job_t * job )
hb_list_rem( job->list_audio, audio );
hb_audio_close( &audio );
}
+ hb_list_close( &job->list_audio );
// clean up subtitle list
while( ( subtitle = hb_list_item( job->list_subtitle, 0 ) ) )
@@ -1776,6 +1762,7 @@ void hb_job_reset( hb_job_t * job )
hb_list_rem( job->list_subtitle, subtitle );
hb_subtitle_close( &subtitle );
}
+ hb_list_close( &job->list_subtitle );
// clean up filter list
while( ( filter = hb_list_item( job->list_filter, 0 ) ) )
@@ -1783,9 +1770,62 @@ void hb_job_reset( hb_job_t * job )
hb_list_rem( job->list_filter, filter );
hb_filter_close( &filter );
}
+ hb_list_close( &job->list_filter );
+
+ // clean up attachment list
+ while( ( attachment = hb_list_item( job->list_attachment, 0 ) ) )
+ {
+ hb_list_rem( job->list_attachment, attachment );
+ hb_attachment_close( &attachment );
+ }
+ hb_list_close( &job->list_attachment );
+ // clean up metadata
hb_metadata_close( &job->metadata );
- job->metadata = hb_metadata_copy( title->metadata );
+ }
+}
+
+/*
+ * Create a pristine job structure from a title
+ * title_index is 1 based
+ */
+hb_job_t * hb_job_init_by_index( hb_handle_t * h, int title_index )
+{
+ hb_title_set_t *title_set = hb_get_title_set( h );
+ hb_title_t * title = hb_list_item( title_set->list_title,
+ title_index - 1 );
+ return hb_job_init( title );
+}
+
+hb_job_t * hb_job_init( hb_title_t * title )
+{
+ hb_job_t * job;
+
+ if ( title == NULL )
+ return NULL;
+
+ job = calloc( sizeof( hb_job_t ), 1 );
+ job_setup(job, title);
+
+ return job;
+}
+
+/**
+ * Clean up the job structure so that is is ready for setting up a new job.
+ * Should be called by front-ends after hb_add().
+ */
+/**********************************************************************
+ * hb_job_reset
+ **********************************************************************
+ *
+ *********************************************************************/
+void hb_job_reset( hb_job_t * job )
+{
+ if ( job )
+ {
+ hb_title_t * title = job->title;
+ job_clean(job);
+ job_setup(job, title);
}
}
@@ -1796,68 +1836,10 @@ void hb_job_reset( hb_job_t * job )
*********************************************************************/
void hb_job_close( hb_job_t ** _j )
{
- if (_j)
+ if (_j && *_j)
{
- hb_job_t * job = *_j;
-
- if (job)
- {
- hb_chapter_t *chapter;
- hb_audio_t *audio;
- hb_subtitle_t *subtitle;
- hb_filter_object_t *filter;
- hb_attachment_t *attachment;
-
- free(job->file);
- free(job->advanced_opts);
-
- // clean up chapter list
- while( ( chapter = hb_list_item( job->list_chapter, 0 ) ) )
- {
- hb_list_rem( job->list_chapter, chapter );
- hb_chapter_close( &chapter );
- }
- hb_list_close( &job->list_chapter );
-
- // clean up audio list
- while( ( audio = hb_list_item( job->list_audio, 0 ) ) )
- {
- hb_list_rem( job->list_audio, audio );
- hb_audio_close( &audio );
- }
- hb_list_close( &job->list_audio );
-
- // clean up subtitle list
- while( ( subtitle = hb_list_item( job->list_subtitle, 0 ) ) )
- {
- hb_list_rem( job->list_subtitle, subtitle );
- hb_subtitle_close( &subtitle );
- }
- hb_list_close( &job->list_subtitle );
-
- // clean up filter list
- while( ( filter = hb_list_item( job->list_filter, 0 ) ) )
- {
- hb_list_rem( job->list_filter, filter );
- hb_filter_close( &filter );
- }
- hb_list_close( &job->list_filter );
-
- // clean up attachment list
- while( ( attachment = hb_list_item( job->list_attachment, 0 ) ) )
- {
- hb_list_rem( job->list_attachment, attachment );
- hb_attachment_close( &attachment );
- }
- hb_list_close( &job->list_attachment );
-
- // clean up metadata
- if ( job->metadata )
- {
- hb_metadata_close( &job->metadata );
- }
- free( job );
- }
+ job_clean(*_j);
+ free( *_j );
_j = NULL;
}
}