x264enc: Remove x264 backward compatibility support
authorNicolas Dufresne <nicolas.dufresne@collabora.com>
Wed, 18 Apr 2012 21:09:12 +0000 (17:09 -0400)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Mon, 18 Jun 2012 15:01:20 +0000 (16:01 +0100)
ext/x264/gstx264enc.c
ext/x264/gstx264enc.h

index ac7e620..3859f45 100644 (file)
 #include <gst/pbutils/pbutils.h>
 #include <gst/video/video.h>
 
-#if X264_BUILD >= 71
-#define X264_DELAYED_FRAMES_API
-#endif
-
-#if X264_BUILD >= 76
-#define X264_ENC_NALS 1
-#endif
-
-#if X264_BUILD >= 69
-#define X264_MB_RC
-#endif
-
-#if X264_BUILD >= 78
-/* b-pyramid was available before but was changed from boolean here */
-#define X264_B_PYRAMID
-#endif
-
-#if X264_BUILD >= 80
-#define X264_ENH_THREADING
-#endif
-
-#if X264_BUILD >= 82
-#define X264_INTRA_REFRESH
-#endif
-
-#if X264_BUILD >= 86
-#define X264_PRESETS
-#endif
-
-#if X264_BUILD >= 95
-#define FORCE_INTRA_API
-#endif
-
 #include <string.h>
 #include <stdlib.h>
 
@@ -310,8 +277,6 @@ gst_x264_enc_analyse_get_type (void)
   return analyse_type;
 }
 
-#ifdef X264_PRESETS
-
 #define GST_X264_ENC_PROFILE_TYPE (gst_x264_enc_profile_get_type())
 static GType
 gst_x264_enc_profile_get_type (void)
@@ -458,9 +423,6 @@ gst_x264_enc_build_tunings_string (GstX264Enc * x264enc)
         x264enc->tunings->str);
 }
 
-#endif
-
-
 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
     GST_PAD_SINK,
     GST_PAD_ALWAYS,
@@ -606,8 +568,6 @@ gst_x264_enc_class_init (GstX264EncClass * klass)
           0, 10000, ARG_VBV_BUF_CAPACITY_DEFAULT,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS |
           GST_PARAM_MUTABLE_PLAYING));
-
-#ifdef X264_PRESETS
   g_object_class_install_property (gobject_class, ARG_SPEED_PRESET,
       g_param_spec_enum ("speed-preset", "Speed/quality preset",
           "Preset name for speed/quality tradeoff options (can affect decode "
@@ -631,7 +591,6 @@ gst_x264_enc_class_init (GstX264EncClass * klass)
           "if downstream elements do not specify a profile in their caps (DEPRECATED)",
           GST_X264_ENC_PROFILE_TYPE, ARG_PROFILE_DEFAULT,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-#endif /* X264_PRESETS */
   g_object_class_install_property (gobject_class, ARG_OPTION_STRING,
       g_param_spec_string ("option-string", "Option string",
           "String of x264 options (overridden by element properties)",
@@ -647,7 +606,6 @@ gst_x264_enc_class_init (GstX264EncClass * klass)
   /* NOTE: this first string append doesn't require the ':' delimiter but the
    * rest do */
   g_string_append_printf (x264enc_defaults, "threads=%d", ARG_THREADS_DEFAULT);
-#ifdef X264_ENH_THREADING
   g_object_class_install_property (gobject_class, ARG_SLICED_THREADS,
       g_param_spec_boolean ("sliced-threads", "Sliced Threads",
           "Low latency but lower efficiency threading",
@@ -662,7 +620,6 @@ gst_x264_enc_class_init (GstX264EncClass * klass)
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_string_append_printf (x264enc_defaults, ":sync-lookahead=%d",
       ARG_SYNC_LOOKAHEAD_DEFAULT);
-#endif
   g_object_class_install_property (gobject_class, ARG_STATS_FILE,
       g_param_spec_string ("stats-file", "Stats File",
           "Filename for multipass statistics (deprecated, use multipass-cache-file)",
@@ -680,7 +637,6 @@ gst_x264_enc_class_init (GstX264EncClass * klass)
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_string_append_printf (x264enc_defaults, ":annexb=%d",
       ARG_BYTE_STREAM_DEFAULT);
-#ifdef X264_INTRA_REFRESH
   g_object_class_install_property (gobject_class, ARG_INTRA_REFRESH,
       g_param_spec_boolean ("intra-refresh", "Intra Refresh",
           "Use Periodic Intra Refresh instead of IDR frames",
@@ -688,7 +644,6 @@ gst_x264_enc_class_init (GstX264EncClass * klass)
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_string_append_printf (x264enc_defaults, ":intra-refresh=%d",
       ARG_INTRA_REFRESH_DEFAULT);
-#endif
   g_object_class_install_property (gobject_class, ARG_ME,
       g_param_spec_enum ("me", "Motion Estimation",
           "Integer pixel motion estimation method", GST_X264_ENC_ME_TYPE,
@@ -735,13 +690,8 @@ gst_x264_enc_class_init (GstX264EncClass * klass)
       g_param_spec_boolean ("b-pyramid", "B-Pyramid",
           "Keep some B-frames as references", ARG_B_PYRAMID_DEFAULT,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-#ifdef X264_B_PYRAMID
   g_string_append_printf (x264enc_defaults, ":b-pyramid=%s",
       x264_b_pyramid_names[ARG_B_PYRAMID_DEFAULT]);
-#else
-  g_string_append_printf (x264enc_defaults, ":b-pyramid=%d",
-      ARG_B_PYRAMID_DEFAULT);
-#endif /* X264_B_PYRAMID */
   g_object_class_install_property (gobject_class, ARG_WEIGHTB,
       g_param_spec_boolean ("weightb", "Weighted B-Frames",
           "Weighted prediction for B-frames", ARG_WEIGHTB_DEFAULT,
@@ -803,7 +753,6 @@ gst_x264_enc_class_init (GstX264EncClass * klass)
           ARG_PB_FACTOR_DEFAULT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_string_append_printf (x264enc_defaults, ":pb-factor=%f",
       ARG_PB_FACTOR_DEFAULT);
-#ifdef X264_MB_RC
   g_object_class_install_property (gobject_class, ARG_RC_MB_TREE,
       g_param_spec_boolean ("mb-tree", "Macroblock Tree",
           "Macroblock-Tree ratecontrol",
@@ -817,7 +766,6 @@ gst_x264_enc_class_init (GstX264EncClass * klass)
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
   g_string_append_printf (x264enc_defaults, ":rc-lookahead=%d",
       ARG_RC_LOOKAHEAD_DEFAULT);
-#endif
   g_object_class_install_property (gobject_class, ARG_NR,
       g_param_spec_uint ("noise-reduction", "Noise Reduction",
           "Noise reduction strength",
@@ -918,10 +866,6 @@ gst_x264_enc_init (GstX264Enc * encoder, GstX264EncClass * klass)
   encoder->psy_tune = ARG_PSY_TUNE_DEFAULT;
   encoder->tune = ARG_TUNE_DEFAULT;
 
-  /* resources */
-  encoder->buffer_size = 100000;
-  encoder->buffer = g_malloc (encoder->buffer_size);
-
   x264_param_default (&encoder->x264param);
 
   /* log callback setup; part of parameters */
@@ -971,8 +915,6 @@ gst_x264_enc_finalize (GObject * object)
 
   g_free (encoder->mp_cache_file);
   encoder->mp_cache_file = NULL;
-  g_free (encoder->buffer);
-  encoder->buffer = NULL;
 
   gst_x264_enc_close_encoder (encoder);
 
@@ -1045,7 +987,6 @@ gst_x264_enc_init_encoder (GstX264Enc * encoder)
 
   GST_OBJECT_LOCK (encoder);
 
-#ifdef X264_PRESETS
   gst_x264_enc_build_tunings_string (encoder);
 
   /* set x264 parameters and use preset/tuning if present */
@@ -1065,7 +1006,6 @@ gst_x264_enc_init_encoder (GstX264Enc * encoder)
 
   /* if no preset nor tuning, use property defaults */
   if (!encoder->speed_preset && !encoder->tunings->len) {
-#endif /* X264_PRESETS */
     GST_DEBUG_OBJECT (encoder, "Applying x264enc_defaults");
     if (x264enc_defaults->len
         && gst_x264_enc_parse_options (encoder,
@@ -1074,19 +1014,15 @@ gst_x264_enc_init_encoder (GstX264Enc * encoder)
           "x264enc_defaults string contains errors. This is a bug.");
       goto unlock_and_return;
     }
-#ifdef X264_PRESETS
   } else {
     /* When using presets we need to respect the default output format */
     encoder->x264param.b_aud = encoder->au_nalu;
     encoder->x264param.b_annexb = encoder->byte_stream;
   }
-#endif /* X264_PRESETS */
 
-#if X264_BUILD >= 81
   /* setup appropriate timebase for gstreamer */
   encoder->x264param.i_timebase_num = 1;
   encoder->x264param.i_timebase_den = 1000000000;
-#endif
 
   /* apply option-string property */
   if (encoder->option_string_prop && encoder->option_string_prop->len) {
@@ -1176,9 +1112,7 @@ gst_x264_enc_init_encoder (GstX264Enc * encoder)
     case 1:
       encoder->x264param.rc.b_stat_read = 0;
       encoder->x264param.rc.b_stat_write = 1;
-#ifdef X264_PRESETS
       x264_param_apply_fastfirstpass (&encoder->x264param);
-#else
       encoder->x264param.i_frame_reference = 1;
       encoder->x264param.analyse.b_transform_8x8 = 0;
       encoder->x264param.analyse.inter = 0;
@@ -1187,7 +1121,6 @@ gst_x264_enc_init_encoder (GstX264Enc * encoder)
           MIN (2, encoder->x264param.analyse.i_subpel_refine);
       encoder->x264param.analyse.i_trellis = 0;
       encoder->x264param.analyse.b_fast_pskip = 1;
-#endif /* X264_PRESETS */
       break;
     case 2:
       encoder->x264param.rc.b_stat_read = 1;
@@ -1199,25 +1132,6 @@ gst_x264_enc_init_encoder (GstX264Enc * encoder)
       break;
   }
 
-#if X264_BUILD >= 81 && X264_BUILD < 106
-  /* When vfr is disabled, libx264 ignores buffer timestamps. This causes
-   * issues with rate control in libx264 with our nanosecond timebase. This
-   * has been fixed upstream in libx264 but this workaround is required for
-   * pre-fix versions. */
-  if (!encoder->x264param.b_vfr_input) {
-    if (encoder->x264param.i_fps_num == 0) {
-      GST_ELEMENT_ERROR (encoder, STREAM, ENCODE,
-          ("Constant framerate is required."),
-          ("The framerate caps (%d/%d) indicate VFR but VFR is disabled in libx264. (Is the zerolatency tuning in use?)",
-              encoder->x264param.i_fps_num, encoder->x264param.i_fps_den));
-      return FALSE;
-    }
-    encoder->x264param.i_timebase_num = encoder->x264param.i_fps_den;
-    encoder->x264param.i_timebase_den = encoder->x264param.i_fps_num;
-  }
-#endif
-
-#ifdef X264_PRESETS
   if (encoder->peer_profile) {
     if (x264_param_apply_profile (&encoder->x264param, encoder->peer_profile))
       GST_WARNING_OBJECT (encoder, "Bad downstream profile name: %s",
@@ -1228,7 +1142,6 @@ gst_x264_enc_init_encoder (GstX264Enc * encoder)
       GST_WARNING_OBJECT (encoder, "Bad profile name: %s",
           x264_profile_names[encoder->profile - 1]);
   }
-#endif /* X264_PRESETS */
 
   /* If using an intra profile, all frames are intra frames */
   if (encoder->peer_intra_profile)
@@ -1310,15 +1223,9 @@ gst_x264_enc_set_profile_and_level (GstX264Enc * encoder, GstCaps * caps)
   if (i_nal == 3 && nal[sps_ni].i_type != 7)
     sps_ni = 1;
 
-  /* old style API: nal's are not encapsulated, and have no sync/size prefix,
-   * new style API: nal's are encapsulated, and have 4-byte size prefix */
-#ifndef X264_ENC_NALS
-  sps = nal[sps_ni].p_payload;
-#else
   sps = nal[sps_ni].p_payload + 4;
   /* skip NAL unit type */
   sps++;
-#endif
 
   gst_codec_utils_h264_caps_set_level_and_profile (caps, sps, 3);
 
@@ -1337,9 +1244,6 @@ gst_x264_enc_header_buf (GstX264Enc * encoder)
   int header_return;
   int i_size;
   int nal_size;
-#ifndef X264_ENC_NALS
-  int i_data;
-#endif
   guint8 *buffer, *sps;
   gulong buffer_size;
   gint sei_ni = 2, sps_ni = 0, pps_ni = 1;
@@ -1380,15 +1284,9 @@ gst_x264_enc_header_buf (GstX264Enc * encoder)
   buffer_size = (nal[sps_ni].i_payload + nal[pps_ni].i_payload) * 4 + 100;
   buffer = g_malloc (buffer_size);
 
-  /* old style API: nal's are not encapsulated, and have no sync/size prefix,
-   * new style API: nal's are encapsulated, and have 4-byte size prefix */
-#ifndef X264_ENC_NALS
-  sps = nal[sps_ni].p_payload;
-#else
   sps = nal[sps_ni].p_payload + 4;
   /* skip NAL unit type */
   sps++;
-#endif
 
   buffer[0] = 1;                /* AVC Decoder Configuration Record ver. 1 */
   buffer[1] = sps[0];           /* profile_idc                             */
@@ -1400,25 +1298,17 @@ gst_x264_enc_header_buf (GstX264Enc * encoder)
 
   buffer[i_size++] = 0xe0 | 1;  /* number of SPSs */
 
-#ifndef X264_ENC_NALS
-  i_data = buffer_size - i_size - 2;
-  nal_size = x264_nal_encode (buffer + i_size + 2, &i_data, 0, &nal[sps_ni]);
-#else
   nal_size = nal[sps_ni].i_payload - 4;
   memcpy (buffer + i_size + 2, nal[sps_ni].p_payload + 4, nal_size);
-#endif
+
   GST_WRITE_UINT16_BE (buffer + i_size, nal_size);
   i_size += nal_size + 2;
 
   buffer[i_size++] = 1;         /* number of PPSs */
 
-#ifndef X264_ENC_NALS
-  i_data = buffer_size - i_size - 2;
-  nal_size = x264_nal_encode (buffer + i_size + 2, &i_data, 0, &nal[pps_ni]);
-#else
   nal_size = nal[pps_ni].i_payload - 4;
   memcpy (buffer + i_size + 2, nal[pps_ni].p_payload + 4, nal_size);
-#endif
+
   GST_WRITE_UINT16_BE (buffer + i_size, nal_size);
   i_size += nal_size + 2;
 
@@ -1751,10 +1641,6 @@ gst_x264_enc_encode_frame (GstX264Enc * encoder, x264_picture_t * pic_in,
   x264_picture_t pic_out;
   x264_nal_t *nal;
   int i_size;
-#ifndef X264_ENC_NALS
-  int nal_size;
-  gint i;
-#endif
   int encoder_return;
   GstFlowReturn ret;
   guint8 *data;
@@ -1774,14 +1660,10 @@ gst_x264_enc_encode_frame (GstX264Enc * encoder, x264_picture_t * pic_in,
   if (pic_in && input_frame) {
     if (GST_VIDEO_CODEC_FRAME_IS_FORCE_KEYFRAME (input_frame)) {
       GST_INFO ("Forcing key frame");
-#ifdef FORCE_INTRA_API
       if (encoder->intra_refresh)
         x264_encoder_intra_refresh (encoder->x264enc);
       else
         pic_in->i_type = X264_TYPE_IDR;
-#else
-      pic_in->i_type = X264_TYPE_IDR;
-#endif
     }
   }
   GST_OBJECT_UNLOCK (encoder);
@@ -1805,33 +1687,9 @@ gst_x264_enc_encode_frame (GstX264Enc * encoder, x264_picture_t * pic_in,
     ret = GST_FLOW_OK;
     goto out;
   }
-#ifndef X264_ENC_NALS
-  i_size = 0;
-  for (i = 0; i < *i_nal; i++) {
-    gint i_data = encoder->buffer_size - i_size - 4;
-
-    if (i_data < nal[i].i_payload * 2) {
-      encoder->buffer_size += 2 * nal[i].i_payload;
-      encoder->buffer = g_realloc (encoder->buffer, encoder->buffer_size);
-      i_data = encoder->buffer_size - i_size - 4;
-    }
-
-    nal_size =
-        x264_nal_encode (encoder->buffer + i_size + 4, &i_data, 0, &nal[i]);
-    g_assert (encoder->current_byte_stream !=
-        GST_X264_ENC_STREAM_FORMAT_FROM_PROPERTY);
-    if (encoder->current_byte_stream == GST_X264_ENC_STREAM_FORMAT_BYTE_STREAM)
-      GST_WRITE_UINT32_BE (encoder->buffer + i_size, 1);
-    else
-      GST_WRITE_UINT32_BE (encoder->buffer + i_size, nal_size);
 
-    i_size += nal_size + 4;
-  }
-  data = encoder->buffer;
-#else
   i_size = encoder_return;
   data = nal[0].p_payload;
-#endif
 
   frame = gst_video_encoder_get_frame (GST_VIDEO_ENCODER (encoder),
       GPOINTER_TO_INT (pic_out.opaque));
@@ -1851,11 +1709,7 @@ gst_x264_enc_encode_frame (GstX264Enc * encoder, x264_picture_t * pic_in,
   memcpy (GST_BUFFER_DATA (out_buf), data, i_size);
   frame->output_buffer = out_buf;
 
-#ifdef X264_INTRA_REFRESH
   if (pic_out.b_keyframe) {
-#else
-  if (pic_out.i_type == X264_TYPE_IDR) {
-#endif
     GST_INFO ("Output keyframe");
     GST_VIDEO_CODEC_FRAME_SET_SYNC_POINT (frame);
   }
@@ -1877,13 +1731,8 @@ gst_x264_enc_flush_frames (GstX264Enc * encoder, gboolean send)
   if (encoder->x264enc)
     do {
       flow_ret = gst_x264_enc_encode_frame (encoder, NULL, NULL, &i_nal, send);
-#ifdef X264_DELAYED_FRAMES_API
     } while (flow_ret == GST_FLOW_OK
         && x264_encoder_delayed_frames (encoder->x264enc) > 0);
-#else
-      /* note that this doesn't flush all frames for > 1 delayed frame */
-    } while (flow_ret == GST_FLOW_OK && i_nal > 0);
-#endif
 }
 
 static gboolean
@@ -2043,13 +1892,8 @@ gst_x264_enc_set_property (GObject * object, guint prop_id,
       break;
     case ARG_B_PYRAMID:
       encoder->b_pyramid = g_value_get_boolean (value);
-#ifdef X264_B_PYRAMID
       g_string_append_printf (encoder->option_string, ":b-pyramid=%s",
           x264_b_pyramid_names[encoder->b_pyramid]);
-#else
-      g_string_append_printf (encoder->option_string, ":b-pyramid=%d",
-          encoder->b_pyramid);
-#endif /* X264_B_PYRAMID */
       break;
     case ARG_WEIGHTB:
       encoder->weightb = g_value_get_boolean (value);
index 47c1710..ff86252 100644 (file)
@@ -97,9 +97,6 @@ struct _GstX264Enc
   /* input description */
   GstVideoCodecState *input_state;
 
-  guint8 *buffer;
-  gulong buffer_size;
-
   /* configuration changed  while playing */
   gboolean reconfig;