vtenc: remove duplicated framerate and size variables
authorAndoni Morales Alastruey <amorales@fluendo.com>
Tue, 18 Apr 2023 07:59:36 +0000 (09:59 +0200)
committerTim-Philipp Müller <tim@centricular.com>
Mon, 19 Jun 2023 10:17:36 +0000 (11:17 +0100)
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4888>

subprojects/gst-plugins-bad/sys/applemedia/vtenc.c
subprojects/gst-plugins-bad/sys/applemedia/vtenc.h

index cc96351..7e5d579 100644 (file)
@@ -744,8 +744,8 @@ gst_vtenc_stop (GstVideoEncoder * enc)
     gst_video_codec_state_unref (self->input_state);
   self->input_state = NULL;
 
-  self->negotiated_width = self->negotiated_height = 0;
-  self->negotiated_fps_n = self->negotiated_fps_d = 0;
+  self->video_info.width = self->video_info.height = 0;
+  self->video_info.fps_n = self->video_info.fps_d = 0;
 
   gst_vtenc_clear_cached_caps_downstream (self);
 
@@ -928,10 +928,6 @@ gst_vtenc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
     gst_video_codec_state_unref (self->input_state);
   self->input_state = gst_video_codec_state_ref (state);
 
-  self->negotiated_width = state->info.width;
-  self->negotiated_height = state->info.height;
-  self->negotiated_fps_n = state->info.fps_n;
-  self->negotiated_fps_d = state->info.fps_d;
   self->video_info = state->info;
 
   GST_OBJECT_LOCK (self);
@@ -951,7 +947,7 @@ gst_vtenc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
 static gboolean
 gst_vtenc_is_negotiated (GstVTEnc * self)
 {
-  return self->negotiated_width != 0;
+  return self->video_info.width != 0;
 }
 
 /*
@@ -984,10 +980,10 @@ gst_vtenc_negotiate_downstream (GstVTEnc * self, CMSampleBufferRef sbuf)
   GstStructure *s;
   GstVideoCodecState *state;
 
-  if (self->caps_width == self->negotiated_width &&
-      self->caps_height == self->negotiated_height &&
-      self->caps_fps_n == self->negotiated_fps_n &&
-      self->caps_fps_d == self->negotiated_fps_d) {
+  if (self->caps_width == self->video_info.width &&
+      self->caps_height == self->video_info.height &&
+      self->caps_fps_n == self->video_info.fps_n &&
+      self->caps_fps_d == self->video_info.fps_d) {
     return TRUE;
   }
 
@@ -995,10 +991,10 @@ gst_vtenc_negotiate_downstream (GstVTEnc * self, CMSampleBufferRef sbuf)
   caps = gst_caps_make_writable (caps);
   s = gst_caps_get_structure (caps, 0);
   gst_structure_set (s,
-      "width", G_TYPE_INT, self->negotiated_width,
-      "height", G_TYPE_INT, self->negotiated_height,
+      "width", G_TYPE_INT, self->video_info.width,
+      "height", G_TYPE_INT, self->video_info.height,
       "framerate", GST_TYPE_FRACTION,
-      self->negotiated_fps_n, self->negotiated_fps_d, NULL);
+      self->video_info.fps_n, self->video_info.fps_d, NULL);
 
   switch (self->details->format_id) {
     case kCMVideoCodecType_H264:
@@ -1065,10 +1061,10 @@ gst_vtenc_negotiate_downstream (GstVTEnc * self, CMSampleBufferRef sbuf)
   gst_video_codec_state_unref (state);
   result = gst_video_encoder_negotiate (GST_VIDEO_ENCODER_CAST (self));
 
-  self->caps_width = self->negotiated_width;
-  self->caps_height = self->negotiated_height;
-  self->caps_fps_n = self->negotiated_fps_n;
-  self->caps_fps_d = self->negotiated_fps_d;
+  self->caps_width = self->video_info.width;
+  self->caps_height = self->video_info.height;
+  self->caps_fps_n = self->video_info.fps_n;
+  self->caps_fps_d = self->video_info.fps_d;
 
   return result;
 }
@@ -1296,9 +1292,9 @@ gst_vtenc_create_session (GstVTEnc * self)
     pb_attrs = CFDictionaryCreateMutable (NULL, 0,
         &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
     gst_vtutil_dict_set_i32 (pb_attrs, kCVPixelBufferWidthKey,
-        self->negotiated_width);
+        self->video_info.width);
     gst_vtutil_dict_set_i32 (pb_attrs, kCVPixelBufferHeightKey,
-        self->negotiated_height);
+        self->video_info.height);
   }
 
   /* This was set in gst_vtenc_negotiate_specific_format_details() */
@@ -1312,11 +1308,11 @@ gst_vtenc_create_session (GstVTEnc * self)
   }
 
   status = VTCompressionSessionCreate (NULL,
-      self->negotiated_width, self->negotiated_height,
+      self->video_info.width, self->video_info.height,
       self->specific_format_id, encoder_spec, pb_attrs, NULL,
       gst_vtenc_enqueue_buffer, self, &session);
   GST_INFO_OBJECT (self, "VTCompressionSessionCreate for %d x %d => %d",
-      self->negotiated_width, self->negotiated_height, (int) status);
+      self->video_info.width, self->video_info.height, (int) status);
   if (status != noErr) {
     GST_ERROR_OBJECT (self, "VTCompressionSessionCreate() returned: %d",
         (int) status);
@@ -1325,7 +1321,7 @@ gst_vtenc_create_session (GstVTEnc * self)
 
   if (self->profile_level) {
     gst_vtenc_session_configure_expected_framerate (self, session,
-        (gdouble) self->negotiated_fps_n / (gdouble) self->negotiated_fps_d);
+        (gdouble) self->video_info.fps_n / (gdouble) self->video_info.fps_d);
 
     /*
      * https://developer.apple.com/documentation/videotoolbox/kvtcompressionpropertykey_profilelevel
@@ -1723,8 +1719,8 @@ gst_vtenc_encode_frame (GstVTEnc * self, GstVideoCodecFrame * frame)
     }
 
     cv_ret =
-        CVPixelBufferCreate (NULL, self->negotiated_width,
-        self->negotiated_height, pixel_format_type, NULL, &pbuf);
+        CVPixelBufferCreate (NULL, self->video_info.width,
+        self->video_info.height, pixel_format_type, NULL, &pbuf);
 
     if (cv_ret != kCVReturnSuccess) {
       GST_ERROR_OBJECT (self, "CVPixelBufferCreate failed: %i", cv_ret);
@@ -1818,7 +1814,7 @@ gst_vtenc_encode_frame (GstVTEnc * self, GstVideoCodecFrame * frame)
       }
 
       cv_ret = CVPixelBufferCreateWithPlanarBytes (NULL,
-          self->negotiated_width, self->negotiated_height,
+          self->video_info.width, self->video_info.height,
           pixel_format_type,
           frame,
           GST_VIDEO_FRAME_SIZE (&vframe->videoframe),
index 288e661..e32300c 100644 (file)
@@ -74,8 +74,6 @@ struct _GstVTEnc
   gboolean dump_properties;
   gboolean dump_attributes;
 
-  gint negotiated_width, negotiated_height;
-  gint negotiated_fps_n, negotiated_fps_d;
   gint caps_width, caps_height;
   gint caps_fps_n, caps_fps_d;
   gboolean have_field_order;