]> git.sesse.net Git - vlc/blobdiff - modules/codec/x264.c
Remove qnx modules.
[vlc] / modules / codec / x264.c
index 9fb96185ce83ccebb8ba06a16932218d9f6a41f6..2c6f320c2ca193a8241d3f17e8a760bc4462ceae 100644 (file)
@@ -240,6 +240,12 @@ static void Close( vlc_object_t * );
 #define WEIGHTB_TEXT N_("Weighted prediction for B-frames")
 #define WEIGHTB_LONGTEXT N_( "Weighted prediction for B-frames.")
 
+#define WEIGHTP_TEXT N_("Weighted prediction for P-frames")
+#define WEIGHTP_LONGTEXT N_(" Weighted prediction for P-frames: "\
+    " - 0: Disabled\n"\
+    " - 1: Blind offset\n"\
+    " - 2: Smart analysis\n" )
+
 #define ME_TEXT N_("Integer pixel motion estimation method")
 #define ME_LONGTEXT N_( "Selects the motion estimation algorithm: "\
     " - dia: diamond search, radius 1 (fast)\n" \
@@ -355,6 +361,11 @@ static void Close( vlc_object_t * );
 #define AUD_TEXT N_("Access unit delimiters")
 #define AUD_LONGTEXT N_( "Generate access unit delimiter NAL units.")
 
+#define LOOKAHEAD_TEXT N_("Framecount to use on frametype lookahead")
+#define LOOKAHEAD_LONGTEXT N_("Framecount to use on frametype lookahead. " \
+    "Currently default is lower than x264 default because unmuxable output" \
+    "doesn't handle larger values that well yet" )
+
 static const char *const enc_me_list[] =
   { "dia", "hex", "umh", "esa", "tesa" };
 static const char *const enc_me_list_text[] =
@@ -539,6 +550,10 @@ vlc_module_begin ()
     add_bool( SOUT_CFG_PREFIX "weightb", true, NULL, WEIGHTB_TEXT,
               WEIGHTB_LONGTEXT, false )
 
+    add_integer( SOUT_CFG_PREFIX "weightp", 2, NULL, WEIGHTP_TEXT,
+              WEIGHTP_LONGTEXT, false )
+        change_integer_range( 0, 2 )
+
     add_string( SOUT_CFG_PREFIX "me", "hex", NULL, ME_TEXT,
                 ME_LONGTEXT, false )
         change_string_list( enc_me_list, enc_me_list_text, 0 );
@@ -575,6 +590,10 @@ vlc_module_begin ()
                  TRELLIS_LONGTEXT, false )
         change_integer_range( 0, 2 )
 
+    add_integer( SOUT_CFG_PREFIX "lookahead", 5, NULL, LOOKAHEAD_TEXT,
+                 LOOKAHEAD_LONGTEXT, false )
+        change_integer_range( 0, 60 )
+
     add_bool( SOUT_CFG_PREFIX "fast-pskip", true, NULL, FAST_PSKIP_TEXT,
               FAST_PSKIP_LONGTEXT, false )
 
@@ -640,8 +659,8 @@ static const char *const ppsz_sout_options[] = {
     "pre-scenecut", "psnr", "qblur", "qp", "qcomp", "qpstep", "qpmax",
     "qpmin", "qp-max", "qp-min", "quiet", "ratetol", "ref", "scenecut",
     "sps-id", "ssim", "stats", "subme", "subpel", "tolerance", "trellis",
-    "verbose", "vbv-bufsize", "vbv-init", "vbv-maxrate", "weightb", "aq-mode",
-    "aq-strength", "psy-rd", "profile", NULL
+    "verbose", "vbv-bufsize", "vbv-init", "vbv-maxrate", "weightb", "weightp", "aq-mode",
+    "aq-strength", "psy-rd", "profile", "lookahead", NULL
 };
 
 static block_t *Encode( encoder_t *, picture_t * );
@@ -651,14 +670,16 @@ struct encoder_sys_t
     x264_t          *h;
     x264_param_t    param;
 
-    int             i_buffer;
-    uint8_t         *p_buffer;
-
     mtime_t         i_interpolated_dts;
 
     char *psz_stat_name;
 };
 
+#ifdef PTW32_STATIC_LIB
+static vlc_mutex_t pthread_win32_mutex = VLC_STATIC_MUTEX;
+static int pthread_win32_count = 0;
+#endif
+
 /*****************************************************************************
  * Open: probe the encoder
  *****************************************************************************/
@@ -693,7 +714,6 @@ static int  Open ( vlc_object_t *p_this )
         return VLC_ENOMEM;
     p_sys->i_interpolated_dts = 0;
     p_sys->psz_stat_name = NULL;
-    p_sys->p_buffer = NULL;
 
     x264_param_default( &p_sys->param );
     p_sys->param.i_width  = p_enc->fmt_in.video.i_width;
@@ -841,6 +861,7 @@ static int  Open ( vlc_object_t *p_this )
     {
        p_sys->param.i_bframe_pyramid = X264_B_PYRAMID_NORMAL;
     }
+    free( psz_val );
 #else
     p_sys->param.b_bframe_pyramid = var_GetBool( p_enc, SOUT_CFG_PREFIX "bpyramid" );
  #endif
@@ -916,6 +937,9 @@ static int  Open ( vlc_object_t *p_this )
     p_sys->param.analyse.b_ssim = var_GetBool( p_enc, SOUT_CFG_PREFIX "ssim" );
     p_sys->param.analyse.b_weighted_bipred = var_GetBool( p_enc,
                                     SOUT_CFG_PREFIX "weightb" );
+#if X264_BUILD >= 79
+    p_sys->param.analyse.i_weighted_pred = var_GetInteger( p_enc, SOUT_CFG_PREFIX "weightp" );
+#endif
     p_sys->param.i_bframe_adaptive = var_GetInteger( p_enc,
                                     SOUT_CFG_PREFIX "b-adapt" );
 
@@ -995,16 +1019,13 @@ static int  Open ( vlc_object_t *p_this )
     p_sys->param.analyse.b_transform_8x8 = var_GetBool( p_enc,
                                     SOUT_CFG_PREFIX "8x8dct" );
 
-    if( p_enc->fmt_in.video.i_aspect > 0 )
+    if( p_enc->fmt_in.video.i_sar_num > 0 &&
+        p_enc->fmt_in.video.i_sar_den > 0 )
     {
-        int64_t i_num, i_den;
         unsigned int i_dst_num, i_dst_den;
-
-        i_num = p_enc->fmt_in.video.i_aspect *
-            (int64_t)p_enc->fmt_in.video.i_height;
-        i_den = VOUT_ASPECT_FACTOR * p_enc->fmt_in.video.i_width;
-        vlc_ureduce( &i_dst_num, &i_dst_den, i_num, i_den, 0 );
-
+        vlc_ureduce( &i_dst_num, &i_dst_den,
+                     p_enc->fmt_in.video.i_sar_num,
+                     p_enc->fmt_in.video.i_sar_den, 0 );
         p_sys->param.vui.i_sar_width = i_dst_num;
         p_sys->param.vui.i_sar_height = i_dst_den;
     }
@@ -1040,6 +1061,9 @@ static int  Open ( vlc_object_t *p_this )
             p_sys->param.analyse.b_transform_8x8 = 0;
             p_sys->param.b_cabac = 0;
             p_sys->param.i_bframe = 0;
+#if X264_BUILD >= 79
+            p_sys->param.analyse.i_weighted_pred = X264_WEIGHTP_NONE;
+#endif
         }
         else if (!strcasecmp( psz_val, "main" ) )
         {
@@ -1095,36 +1119,27 @@ static int  Open ( vlc_object_t *p_this )
        but only once for the whole application. Since pthreadw32
        doesn't keep a refcount, do it ourselves. */
 #ifdef PTW32_STATIC_LIB
-    vlc_value_t lock, count;
+    vlc_mutex_lock( &pthread_win32_mutex );
 
-    var_Create( p_enc->p_libvlc, "pthread_win32_mutex", VLC_VAR_MUTEX );
-    var_Get( p_enc->p_libvlc, "pthread_win32_mutex", &lock );
-    vlc_mutex_lock( lock.p_address );
-
-    var_Create( p_enc->p_libvlc, "pthread_win32_count", VLC_VAR_INTEGER );
-    var_Get( p_enc->p_libvlc, "pthread_win32_count", &count );
-
-    if( count.i_int == 0 )
+    if( pthread_win32_count == 0 )
     {
         msg_Dbg( p_enc, "initializing pthread-win32" );
         if( !pthread_win32_process_attach_np() || !pthread_win32_thread_attach_np() )
         {
             msg_Warn( p_enc, "pthread Win32 Initialization failed" );
-            vlc_mutex_unlock( lock.p_address );
+            vlc_mutex_unlock( &pthread_win32_mutex );
             return VLC_EGENERIC;
         }
     }
 
-    count.i_int++;
-    var_Set( p_enc->p_libvlc, "pthread_win32_count", count );
-    vlc_mutex_unlock( lock.p_address );
-
+    pthread_win32_count++;
+    vlc_mutex_unlock( &pthread_win32_mutex );
 #endif
 
     /* Set lookahead value to lower than default,
      * as rtp-output without mux doesn't handle
      * difference that well yet*/
-    p_sys->param.rc.i_lookahead=5;
+    p_sys->param.rc.i_lookahead= var_GetInteger( p_enc, SOUT_CFG_PREFIX "lookahead" );
 
     /* Open the encoder */
     p_sys->h = x264_encoder_open( &p_sys->param );
@@ -1136,16 +1151,6 @@ static int  Open ( vlc_object_t *p_this )
         return VLC_EGENERIC;
     }
 
-    /* alloc mem */
-    p_sys->i_buffer = 4 * p_enc->fmt_in.video.i_width *
-        p_enc->fmt_in.video.i_height + 1000;
-    p_sys->p_buffer = malloc( p_sys->i_buffer );
-    if( !p_sys->p_buffer )
-    {
-        Close( VLC_OBJECT(p_enc) );
-        return VLC_ENOMEM;
-    }
-
     /* get the globals headers */
     p_enc->fmt_out.i_extra = 0;
     p_enc->fmt_out.p_extra = NULL;
@@ -1157,7 +1162,7 @@ static int  Open ( vlc_object_t *p_this )
         Close( VLC_OBJECT(p_enc) );
         return VLC_ENOMEM;
     }
-    void *p_tmp = p_enc->fmt_out.p_extra;
+    uint8_t *p_tmp = p_enc->fmt_out.p_extra;
     for( i = 0; i < i_nal; i++ )
     {
         memcpy( p_tmp, nal[i].p_payload, nal[i].i_payload );
@@ -1193,15 +1198,20 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
 
     if( !i_nal ) return NULL;
 
+
+    /* Get size of block we need */
     for( i = 0, i_out = 0; i < i_nal; i++ )
-    {
-        memcpy( p_sys->p_buffer + i_out, nal[i].p_payload, nal[i].i_payload );
         i_out += nal[i].i_payload;
-    }
 
     p_block = block_New( p_enc, i_out );
     if( !p_block ) return NULL;
-    memcpy( p_block->p_buffer, p_sys->p_buffer, i_out );
+
+    /* copy encoded data directly to block */
+    for( i = 0, i_out = 0; i < i_nal; i++ )
+    {
+        memcpy( p_block->p_buffer + i_out, nal[i].p_payload, nal[i].i_payload );
+        i_out += nal[i].i_payload;
+    }
 
     if( pic.i_type == X264_TYPE_IDR || pic.i_type == X264_TYPE_I )
         p_block->i_flags |= BLOCK_FLAG_TYPE_I;
@@ -1227,6 +1237,7 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
         }
         else
         {
+#if 1       /* XXX: remove me when 0 is a valid timestamp (see #3135) */
             if( p_sys->i_interpolated_dts )
             {
                 p_block->i_dts = p_sys->i_interpolated_dts;
@@ -1236,7 +1247,9 @@ static block_t *Encode( encoder_t *p_enc, picture_t *p_pict )
                 /* Let's put something sensible */
                 p_block->i_dts = p_block->i_pts;
             }
-
+#else
+            p_block->i_dts = p_sys->i_interpolated_dts;
+#endif
             p_sys->i_interpolated_dts += p_block->i_length;
         }
     }
@@ -1262,24 +1275,18 @@ static void Close( vlc_object_t *p_this )
         x264_encoder_close( p_sys->h );
 
 #ifdef PTW32_STATIC_LIB
-    vlc_value_t lock, count;
-
-    var_Get( p_enc->p_libvlc, "pthread_win32_mutex", &lock );
-    vlc_mutex_lock( lock.p_address );
+    vlc_mutex_lock( &pthread_win32_mutex );
+    pthread_win32_count--;
 
-    var_Get( p_enc->p_libvlc, "pthread_win32_count", &count );
-    count.i_int--;
-    var_Set( p_enc->p_libvlc, "pthread_win32_count", count );
-
-    if( count.i_int == 0 )
+    if( pthread_win32_count == 0 )
     {
         pthread_win32_thread_detach_np();
         pthread_win32_process_detach_np();
         msg_Dbg( p_enc, "pthread-win32 deinitialized" );
     }
-    vlc_mutex_unlock( lock.p_address );
+
+    vlc_mutex_unlock( &pthread_win32_mutex );
 #endif
 
-    free( p_sys->p_buffer );
     free( p_sys );
 }