From 8166487a00f63c50cf0a4f5c720f9301403d13b4 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Wed, 10 Dec 2014 19:44:01 +1100 Subject: [PATCH] vtenc: report latency --- sys/applemedia/vtenc.c | 36 +++++++++++++++++++++++++++++++++++- sys/applemedia/vtenc.h | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/sys/applemedia/vtenc.c b/sys/applemedia/vtenc.c index 2207687a01..1a9912d5a4 100644 --- a/sys/applemedia/vtenc.c +++ b/sys/applemedia/vtenc.c @@ -249,7 +249,7 @@ gst_vtenc_init (GstVTEnc * self) /* These could be controlled by properties later */ self->dump_properties = FALSE; self->dump_attributes = FALSE; - + self->latency_frames = -1; self->session = NULL; } @@ -342,6 +342,7 @@ gst_vtenc_set_quality (GstVTEnc * self, gdouble quality) { GST_OBJECT_LOCK (self); self->quality = quality; + GST_INFO_OBJECT (self, "setting quality %f", quality); if (self->session != NULL) { gst_vtenc_session_configure_property_double (self, self->session, kVTCompressionPropertyKey_Quality, quality); @@ -897,6 +898,37 @@ gst_vtenc_session_configure_property_double (GstVTEnc * self, return status; } +static void +gst_vtenc_update_latency (GstVTEnc * self) +{ + OSStatus status; + CFNumberRef value; + int frames = 0; + GstClockTime frame_duration; + GstClockTime latency; + + if (self->video_info.fps_d == 0) { + GST_INFO_OBJECT (self, "framerate not known, can't set latency"); + return; + } + + status = VTSessionCopyProperty (self->session, + kVTCompressionPropertyKey_NumberOfPendingFrames, NULL, &value); + CFNumberGetValue (value, kCFNumberSInt32Type, &frames); + if (self->latency_frames == -1 || self->latency_frames != frames) { + self->latency_frames = frames; + frame_duration = gst_util_uint64_scale (GST_SECOND, + self->video_info.fps_d, self->video_info.fps_n); + latency = frame_duration * frames; + GST_INFO_OBJECT (self, + "latency status %d frames %d fps %d/%d time %" GST_TIME_FORMAT, status, + frames, self->video_info.fps_n, self->video_info.fps_d, + GST_TIME_ARGS (latency)); + gst_video_encoder_set_latency (GST_VIDEO_ENCODER (self), latency, latency); + } + CFRelease (value); +} + static GstFlowReturn gst_vtenc_encode_frame (GstVTEnc * self, GstVideoCodecFrame * frame) { @@ -1082,6 +1114,8 @@ gst_vtenc_encode_frame (GstVTEnc * self, GstVideoCodecFrame * frame) gst_video_codec_frame_unref (outframe); break; } + + gst_vtenc_update_latency (self); } ret = diff --git a/sys/applemedia/vtenc.h b/sys/applemedia/vtenc.h index 01f89e6bc7..f2873cdf60 100644 --- a/sys/applemedia/vtenc.h +++ b/sys/applemedia/vtenc.h @@ -63,6 +63,7 @@ struct _GstVTEnc gdouble quality; gint max_keyframe_interval; GstClockTime max_keyframe_interval_duration; + gint latency_frames; gboolean dump_properties; gboolean dump_attributes;