omxvideoenc: restore OMX default target-bitrate if requested by user
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 29 Mar 2018 14:42:40 +0000 (16:42 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 23 Apr 2018 08:41:10 +0000 (10:41 +0200)
0xffffffff is the magic number in gst-omx meaning 'the default value
defined in OMX'. This works fine with OMX parameters which are only set
once when starting the component but not with configs which can be
changed while PLAYING.
Save the actual OMX default bitrate so we can restore it later if user
sets back 0xffffffff on the property.

Added GST_OMX_PROP_OMX_DEFAULT so we stop hardcoding magic numbers
everywhere.

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

omx/gstomx.h
omx/gstomxvideoenc.c
omx/gstomxvideoenc.h

index a5330bd..e1ea76b 100644 (file)
@@ -118,6 +118,11 @@ G_BEGIN_DECLS
 } G_STMT_END
 #endif
 
+/* If set on an element property means "use the OMX default value".
+ * If set on a default_* variable means that the default values hasn't been
+ * retrieved from OMX yet. */
+#define GST_OMX_PROP_OMX_DEFAULT G_MAXUINT32
+
 /* OMX_StateInvalid does not exist in 1.2.0 spec. The initial state is now
  * StateLoaded. Problem is that gst-omx still needs an initial state different
  * than StateLoaded. Otherwise gst_omx_component_set_state(StateLoaded) will
index 788ef83..b78ea5d 100644 (file)
@@ -518,6 +518,8 @@ gst_omx_video_enc_init (GstOMXVideoEnc * self)
   self->default_roi_quality = GST_OMX_VIDEO_ENC_DEFAULT_ROI_QUALITY;
 #endif
 
+  self->default_target_bitrate = GST_OMX_PROP_OMX_DEFAULT;
+
   g_mutex_init (&self->drain_lock);
   g_cond_init (&self->drain_cond);
 
@@ -746,9 +748,6 @@ gst_omx_video_enc_set_bitrate (GstOMXVideoEnc * self)
   gboolean result = TRUE;
 
   GST_OBJECT_LOCK (self);
-  if (self->control_rate == 0xffffffff && self->target_bitrate == 0xffffffff)
-    /* Keep defaults, nothing to do */
-    goto out;
 
   GST_OMX_INIT_STRUCT (&bitrate_param);
   bitrate_param.nPortIndex = self->enc_out_port->index;
@@ -764,10 +763,16 @@ gst_omx_video_enc_set_bitrate (GstOMXVideoEnc * self)
       bitrate_param.nPortIndex = self->enc_out_port->index;
     }
 #endif
+    if (self->default_target_bitrate == GST_OMX_PROP_OMX_DEFAULT)
+      /* Save the actual OMX default so we can restore it if needed */
+      self->default_target_bitrate = bitrate_param.nTargetBitrate;
+
     if (self->control_rate != 0xffffffff)
       bitrate_param.eControlRate = self->control_rate;
     if (self->target_bitrate != 0xffffffff)
       bitrate_param.nTargetBitrate = self->target_bitrate;
+    else
+      bitrate_param.nTargetBitrate = self->default_target_bitrate;
 
     err =
         gst_omx_component_set_parameter (self->enc,
@@ -790,7 +795,6 @@ gst_omx_video_enc_set_bitrate (GstOMXVideoEnc * self)
         gst_omx_error_to_string (err), err);
   }
 
-out:
   GST_OBJECT_UNLOCK (self);
   return result;
 }
@@ -1667,6 +1671,8 @@ gst_omx_video_enc_stop (GstVideoEncoder * encoder)
   g_cond_broadcast (&self->drain_cond);
   g_mutex_unlock (&self->drain_lock);
 
+  self->default_target_bitrate = GST_OMX_PROP_OMX_DEFAULT;
+
   gst_omx_component_get_state (self->enc, 5 * GST_SECOND);
 
   return TRUE;
index a732254..7cf2b4a 100644 (file)
@@ -94,6 +94,8 @@ struct _GstOMXVideoEnc
   gint default_roi_quality;
 #endif
 
+  guint32 default_target_bitrate;
+
   GstFlowReturn downstream_flow_ret;
 
   GstOMXBufferAllocation input_allocation;