libs: encoder: allow to set bitrate on runtime
authorHyunjun Ko <zzoon@igalia.com>
Fri, 15 Sep 2017 06:38:18 +0000 (15:38 +0900)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Fri, 20 Oct 2017 11:22:51 +0000 (13:22 +0200)
In case of streaming, controlling bitrate dynamically for encoder might be
important to manage quality of the streaming.

This patch is to support such a scenario.

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

gst-libs/gst/vaapi/gstvaapiencoder.c

index 8befeee..46d40cf 100644 (file)
@@ -1122,18 +1122,14 @@ gst_vaapi_encoder_set_bitrate (GstVaapiEncoder * encoder, guint bitrate)
 {
   g_return_val_if_fail (encoder != NULL, 0);
 
-  if (encoder->bitrate != bitrate && encoder->num_codedbuf_queued > 0)
-    goto error_operation_failed;
+  if (encoder->bitrate != bitrate && encoder->num_codedbuf_queued > 0) {
+    GST_INFO ("Bitrate is changed to %d on runtime", bitrate);
+    encoder->bitrate = bitrate;
+    return gst_vaapi_encoder_reconfigure_internal (encoder);
+  }
 
   encoder->bitrate = bitrate;
   return GST_VAAPI_ENCODER_STATUS_SUCCESS;
-
-  /* ERRORS */
-error_operation_failed:
-  {
-    GST_ERROR ("could not change bitrate value after encoding started");
-    return GST_VAAPI_ENCODER_STATUS_ERROR_OPERATION_FAILED;
-  }
 }
 
 /**