]> git.sesse.net Git - x264/blobdiff - input/thread.c
Bump dates to 2016
[x264] / input / thread.c
index 7d0373776290df1ae6ec27b566591422b54fd3bf..ad3b6f3f500b850dfb7ece984b4a71a272a9bf78 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * thread.c: threaded input
  *****************************************************************************
- * Copyright (C) 2003-2011 x264 project
+ * Copyright (C) 2003-2016 x264 project
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *          Loren Merritt <lorenm@u.washington.edu>
@@ -48,7 +48,7 @@ typedef struct thread_input_arg_t
 static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, cli_input_opt_t *opt )
 {
     thread_hnd_t *h = malloc( sizeof(thread_hnd_t) );
-    FAIL_IF_ERR( !h || cli_input.picture_alloc( &h->pic, info->csp, info->width, info->height ),
+    FAIL_IF_ERR( !h || cli_input.picture_alloc( &h->pic, *p_handle, info->csp, info->width, info->height ),
                  "x264", "malloc failed\n" )
     h->input = cli_input;
     h->p_handle = *p_handle;
@@ -59,8 +59,6 @@ static int open_file( char *psz_filename, hnd_t *p_handle, video_info_t *info, c
     h->next_args->h = h;
     h->next_args->status = 0;
     h->frame_total = info->num_frames;
-    thread_input.picture_alloc = h->input.picture_alloc;
-    thread_input.picture_clean = h->input.picture_clean;
 
     if( x264_threadpool_init( &h->pool, 1, NULL, NULL ) )
         return -1;
@@ -88,7 +86,11 @@ static int read_frame( cli_pic_t *p_pic, hnd_t handle, int i_frame )
     if( h->next_frame == i_frame )
         XCHG( cli_pic_t, *p_pic, h->pic );
     else
+    {
+        if( h->next_frame >= 0 )
+            thread_input.release_frame( &h->pic, handle );
         ret |= h->input.read_frame( p_pic, h->p_handle, i_frame );
+    }
 
     if( !h->frame_total || i_frame+1 < h->frame_total )
     {
@@ -111,15 +113,27 @@ static int release_frame( cli_pic_t *pic, hnd_t handle )
     return 0;
 }
 
+static int picture_alloc( cli_pic_t *pic, hnd_t handle, int csp, int width, int height )
+{
+    thread_hnd_t *h = handle;
+    return h->input.picture_alloc( pic, h->p_handle, csp, width, height );
+}
+
+static void picture_clean( cli_pic_t *pic, hnd_t handle )
+{
+    thread_hnd_t *h = handle;
+    h->input.picture_clean( pic, h->p_handle );
+}
+
 static int close_file( hnd_t handle )
 {
     thread_hnd_t *h = handle;
     x264_threadpool_delete( h->pool );
+    h->input.picture_clean( &h->pic, h->p_handle );
     h->input.close_file( h->p_handle );
-    h->input.picture_clean( &h->pic );
     free( h->next_args );
     free( h );
     return 0;
 }
 
-cli_input_t thread_input = { open_file, NULL, read_frame, release_frame, NULL, close_file };
+const cli_input_t thread_input = { open_file, picture_alloc, read_frame, release_frame, picture_clean, close_file };