]> granicus.if.org Git - handbrake/commitdiff
libhb: automatically add rendersub filter when required
authorjstebbins <jstebbins.hb@gmail.com>
Fri, 30 Jan 2015 16:35:13 +0000 (16:35 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Fri, 30 Jan 2015 16:35:13 +0000 (16:35 +0000)
This requires the addition of a filter->post_init function to inform
filters of the final job configuration after all filters have been
initialized.  Rendersub needs to know cropping, but cropping isn't known
till after crop_scale filter is initialized. Since crop_scale is initialized
*after* rendersub is initialized, post_init is needed.  Currently, rendersub
is the only filter that defines post_init.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6830 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/common.h
libhb/rendersub.c
libhb/work.c

index 0478d2b5d9fd586659db60e04e05eb67d525a9cc..4a55a6f8abe85fe7b022773c0bf5437b8884ce4d 100644 (file)
@@ -1148,13 +1148,14 @@ struct hb_filter_object_s
     char                  * settings;
 
 #ifdef __LIBHB__
-    int         (* init)  ( hb_filter_object_t *, hb_filter_init_t * );
+    int         (* init)      ( hb_filter_object_t *, hb_filter_init_t * );
+    int         (* post_init) ( hb_filter_object_t *, hb_job_t * );
 
-    int         (* work)  ( hb_filter_object_t *,
-                            hb_buffer_t **, hb_buffer_t ** );
+    int         (* work)      ( hb_filter_object_t *,
+                                hb_buffer_t **, hb_buffer_t ** );
 
-    void        (* close) ( hb_filter_object_t * );
-    int         (* info)  ( hb_filter_object_t *, hb_filter_info_t * );
+    void        (* close)     ( hb_filter_object_t * );
+    int         (* info)      ( hb_filter_object_t *, hb_filter_info_t * );
 
     hb_fifo_t   * fifo_in;
     hb_fifo_t   * fifo_out;
index ac05f635a590fdb230cdabf6cf743c0e9840d1f1..6dabf39a7433840a6d7450c9fc5cacf9617cadee 100644 (file)
@@ -75,6 +75,8 @@ static void pgssub_close( hb_filter_object_t * filter );
 static int hb_rendersub_init( hb_filter_object_t * filter,
                                  hb_filter_init_t * init );
 
+static int hb_rendersub_post_init( hb_filter_object_t * filter, hb_job_t *job );
+
 static int hb_rendersub_work( hb_filter_object_t * filter,
                                  hb_buffer_t ** buf_in,
                                  hb_buffer_t ** buf_out );
@@ -88,6 +90,7 @@ hb_filter_object_t hb_filter_render_sub =
     .name          = "Subtitle renderer",
     .settings      = NULL,
     .init          = hb_rendersub_init,
+    .post_init     = hb_rendersub_post_init,
     .work          = hb_rendersub_work,
     .close         = hb_rendersub_close,
 };
@@ -826,13 +829,14 @@ static int pgssub_work( hb_filter_object_t * filter,
 }
 
 static int hb_rendersub_init( hb_filter_object_t * filter,
-                                 hb_filter_init_t * init )
+                              hb_filter_init_t * init )
 {
     filter->private_data = calloc( 1, sizeof(struct hb_filter_private_s) );
     hb_filter_private_t * pv = filter->private_data;
     hb_subtitle_t *subtitle;
     int ii;
 
+    pv->crop[0] = pv->crop[1] = pv->crop[2] = pv->crop[3] = -1;
     if( filter->settings )
     {
         sscanf( filter->settings, "%d:%d:%d:%d",
@@ -893,6 +897,22 @@ static int hb_rendersub_init( hb_filter_object_t * filter,
     }
 }
 
+static int hb_rendersub_post_init( hb_filter_object_t * filter, hb_job_t *job )
+{
+    hb_filter_private_t * pv = filter->private_data;
+
+    if (pv->crop[0] == -1)
+        pv->crop[0] = job->crop[0];
+    if (pv->crop[1] == -1)
+        pv->crop[1] = job->crop[1];
+    if (pv->crop[2] == -1)
+        pv->crop[2] = job->crop[2];
+    if (pv->crop[3] == -1)
+        pv->crop[3] = job->crop[3];
+
+    return 0;
+}
+
 static int hb_rendersub_work( hb_filter_object_t * filter,
                                  hb_buffer_t ** buf_in,
                                  hb_buffer_t ** buf_out )
index 607658e704105506f0078ad77189bcbf91fccc85..39cd6829c0e55c1798906eefd1c6d091e9bcc6f7 100644 (file)
@@ -679,30 +679,13 @@ static void do_job(hb_job_t *job)
         }
         if (one_burned)
         {
-            int found = 0;
-            // Check that the HB_FILTER_RENDER_SUB is in the filter chain.
-            // We can not add it automatically because it needs crop
-            // values which only the frontend knows.
-            if (job->list_filter != NULL)
-            {
-                int ii;
-                for (ii = 0; ii < hb_list_count(job->list_filter); ii++)
-                {
-                    hb_filter_object_t *filter;
-                    filter = hb_list_item(job->list_filter, ii);
-                    if (filter->id == HB_FILTER_RENDER_SUB)
-                    {
-                        found = 1;
-                        break;
-                    }
-                }
-            }
-            if (!found)
-            {
-                // If this happens, it is a programming error that
-                // needs to be fixed in the frontend
-                hb_error("Subtitle burned, but no rendering filter");
-            }
+            // Add subtitle rendering filter
+            // Note that if the filter is already in the filter chain, this
+            // has no effect. Note also that this means the front-end is
+            // not required to add the subtitle rendering filter since
+            // we will always try to do it here.
+            hb_filter_object_t *filter = hb_filter_init(HB_FILTER_RENDER_SUB);
+            hb_add_filter(job, filter, NULL);
         }
     }
 
@@ -900,6 +883,23 @@ static void do_job(hb_job_t *job)
         memcpy(job->crop, init.crop, sizeof(int[4]));
         job->vrate = init.vrate;
         job->cfr = init.cfr;
+
+        // Perform filter post_init which informs filters of final
+        // job configuration. e.g. rendersub filter needs to know the
+        // final crop dimensions.
+        for( i = 0; i < hb_list_count( job->list_filter ); )
+        {
+            hb_filter_object_t * filter = hb_list_item( job->list_filter, i );
+            if (filter->post_init != NULL && filter->post_init(filter, job))
+            {
+                hb_log( "Failure to initialise filter '%s', disabling",
+                        filter->name );
+                hb_list_rem( job->list_filter, filter );
+                hb_filter_close( &filter );
+                continue;
+            }
+            i++;
+        }
     }
     else
     {