vtenc: remove keyframe enforcement workaround
authorOle André Vadla Ravnås <oravnas@cisco.com>
Mon, 8 Nov 2010 20:22:13 +0000 (21:22 +0100)
committerOle André Vadla Ravnås <oravnas@cisco.com>
Mon, 8 Nov 2010 22:58:25 +0000 (23:58 +0100)
Was only needed for old iOS where the H.264 encoder didn't support
kVTEncodeFrameOptionKey_ForceKeyFrame.

sys/applemedia/vtenc.c
sys/applemedia/vtenc.h

index 45e0eff..2253cf2 100644 (file)
@@ -508,14 +508,6 @@ gst_vtenc_create_session (GstVTEnc * self)
   if (status != kVTSuccess)
     goto beach;
 
-  GST_OBJECT_LOCK (self);
-  if (GST_ELEMENT_CLOCK (self) != NULL) {
-    self->last_create_session = gst_clock_get_time (GST_ELEMENT_CLOCK (self));
-  } else {
-    self->last_create_session = GST_CLOCK_TIME_NONE;
-  }
-  GST_OBJECT_UNLOCK (self);
-
   if (self->dump_properties) {
     gst_vtenc_session_dump_properties (self, session);
 
@@ -752,32 +744,9 @@ gst_vtenc_encode_frame (GstVTEnc * self, GstBuffer * buf)
 
   self->expect_keyframe = CFDictionaryContainsKey (self->options,
       *(vt->kVTEncodeFrameOptionKey_ForceKeyFrame));
-  if (self->expect_keyframe) {
+  if (self->expect_keyframe)
     gst_vtenc_clear_cached_caps_downstream (self);
 
-    if (self->reset_on_force_keyframe) {
-      VTCompressionSessionRef session;
-
-      gst_vtenc_destroy_session (self, &self->session);
-
-      if (GST_CLOCK_TIME_IS_VALID (self->last_create_session) &&
-          GST_ELEMENT_CLOCK (self) != NULL) {
-        GstClockTime now = gst_clock_get_time (GST_ELEMENT_CLOCK (self));
-        GstClockTimeDiff diff = GST_CLOCK_DIFF (self->last_create_session, now);
-        if (diff < VTENC_MIN_RESET_INTERVAL) {
-          GST_OBJECT_UNLOCK (self);
-          goto skip_frame;
-        }
-      }
-
-      GST_OBJECT_UNLOCK (self);
-      session = gst_vtenc_create_session (self);
-      GST_OBJECT_LOCK (self);
-
-      self->session = session;
-    }
-  }
-
   vt_status = self->ctx->vt->VTCompressionSessionEncodeFrame (self->session,
       pbuf, ts, duration, self->options, NULL, NULL);
 
@@ -789,11 +758,6 @@ gst_vtenc_encode_frame (GstVTEnc * self, GstBuffer * buf)
   self->ctx->vt->VTCompressionSessionCompleteFrames (self->session,
       *(self->ctx->cm->kCMTimeInvalid));
 
-  if (!self->expect_keyframe) {
-    CFDictionaryRemoveValue (self->options,
-        *(self->ctx->vt->kVTEncodeFrameOptionKey_ForceKeyFrame));
-  }
-
   GST_OBJECT_UNLOCK (self);
 
   cv->CVPixelBufferRelease (pbuf);
@@ -803,17 +767,6 @@ gst_vtenc_encode_frame (GstVTEnc * self, GstBuffer * buf)
 
   return self->cur_flowret;
 
-skip_frame:
-  {
-    GST_DEBUG_OBJECT (self, "skipping frame");
-
-    cv->CVPixelBufferRelease (pbuf);
-
-    gst_buffer_unref (buf);
-    self->cur_inbuf = NULL;
-
-    return GST_FLOW_OK;
-  }
 cv_error:
   {
     gst_buffer_unref (buf);
@@ -835,14 +788,18 @@ gst_vtenc_output_buffer (void *data, int a2, int a3, int a4,
   if (sbuf == NULL)
     goto beach;
 
-  if (!gst_vtenc_negotiate_downstream (self, sbuf))
-    goto beach;
-
   is_keyframe = gst_vtenc_buffer_is_keyframe (self, sbuf);
-  if (self->expect_keyframe && !is_keyframe)
-    goto expected_keyframe;
+  if (self->expect_keyframe) {
+    if (!is_keyframe)
+      goto beach;
+    CFDictionaryRemoveValue (self->options,
+        *(self->ctx->vt->kVTEncodeFrameOptionKey_ForceKeyFrame));
+  }
   self->expect_keyframe = FALSE;
 
+  if (!gst_vtenc_negotiate_downstream (self, sbuf))
+    goto beach;
+
   buf = gst_core_media_buffer_new (self->ctx, sbuf);
   gst_buffer_set_caps (buf, GST_PAD_CAPS (self->srcpad));
   gst_buffer_copy_metadata (buf, self->cur_inbuf, GST_BUFFER_COPY_TIMESTAMPS);
@@ -857,18 +814,8 @@ gst_vtenc_output_buffer (void *data, int a2, int a3, int a4,
   self->cur_flowret = gst_pad_push (self->srcpad, buf);
   GST_OBJECT_LOCK (self);
 
-  return kVTSuccess;
-
 beach:
   return kVTSuccess;
-
-expected_keyframe:
-  {
-    GST_INFO_OBJECT (self, "expected keyframe but output was not, "
-        "enabling reset_on_force_keyframe");
-    self->reset_on_force_keyframe = TRUE;
-    return kVTSuccess;
-  }
 }
 
 static gboolean
index b430e85..19d1c7c 100644 (file)
@@ -67,8 +67,6 @@ struct _GstVTEnc
 
   gboolean dump_properties;
   gboolean dump_attributes;
-  gboolean reset_on_force_keyframe;
-  GstClockTime last_create_session;
 
   gint negotiated_width, negotiated_height;
   gint negotiated_fps_n, negotiated_fps_d;