x264enc: Avoid format decision per frame
authorSeungha Yang <seungha.yang@navercorp.com>
Tue, 18 Sep 2018 12:43:14 +0000 (21:43 +0900)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 22 Sep 2018 11:42:34 +0000 (12:42 +0100)
Avoid switch/case per frame for format decision and detect the format
only if where it could be changed. Note that, whenever encoder->input_state
is changed, gst_x264_enc_init_encoder() is called.

https://bugzilla.gnome.org/show_bug.cgi?id=797164

ext/x264/gstx264enc.c
ext/x264/gstx264enc.h

index 9e7986a..70a0277 100644 (file)
@@ -1582,7 +1582,8 @@ gst_x264_enc_init_encoder (GstX264Enc * encoder)
   encoder->x264param.i_bitdepth = GST_VIDEO_INFO_COMP_DEPTH (info, 0);
 #endif
   encoder->x264param.i_csp =
-      gst_x264_enc_gst_to_x264_video_format (info->finfo->format, NULL);
+      gst_x264_enc_gst_to_x264_video_format (info->finfo->format,
+      &encoder->x264_nplanes);
   if (info->fps_d == 0 || info->fps_n == 0) {
     /* No FPS so must use VFR
      * This raises latency apparently see http://mewiki.project357.com/wiki/X264_Encoding_Suggestions */
@@ -2378,7 +2379,7 @@ gst_x264_enc_handle_frame (GstVideoEncoder * video_enc,
   x264_picture_t pic_in;
   gint i_nal, i;
   FrameData *fdata;
-  gint nplanes = 0;
+  gint nplanes = encoder->x264_nplanes;
 
   if (G_UNLIKELY (encoder->x264enc == NULL))
     goto not_inited;
@@ -2393,8 +2394,7 @@ gst_x264_enc_handle_frame (GstVideoEncoder * video_enc,
   if (!fdata)
     goto invalid_frame;
 
-  pic_in.img.i_csp =
-      gst_x264_enc_gst_to_x264_video_format (info->finfo->format, &nplanes);
+  pic_in.img.i_csp = encoder->x264param.i_csp;
   pic_in.img.i_plane = nplanes;
   for (i = 0; i < nplanes; i++) {
     pic_in.img.plane[i] = GST_VIDEO_FRAME_COMP_DATA (&fdata->vframe, i);
index e8291a3..c7de48c 100644 (file)
@@ -123,6 +123,9 @@ struct _GstX264Enc
   const gchar *peer_profile;
   gboolean peer_intra_profile;
   gint peer_level_idc;
+
+  /* cached values to set x264_picture_t */
+  gint x264_nplanes;
 };
 
 struct _GstX264EncClass