Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.
/ kms-core Public archive

prevent buffer increase when CPU loaded #7

Merged
merged 1 commit into from
Jul 27, 2017
Merged

Conversation

kc7bfi
Copy link

@kc7bfi kc7bfi commented Jul 5, 2017

Prevent frames from building up in the buffer if the CPU falls behind.

Prior discussion: https://groups.google.com/g/kurento/c/_IsI7tcdLVw/m/N_GB6SKLBAAJ
Related: Kurento/kms-elements#11
Followed by: #9

For testing purposes, I have a VM configured with one CPU. When I attempt to run three high-definition videos through KMS, the CPU becomes over taxed and KMS begins to buffer the incoming video. This leads to huge delays in displaying the video. I've seen as much as 2 minutes of video being buffered inside KMS and the player running at almost half speed and 2 minutes behind the live video. This also causes huge memory accumulation within KMS, often in the tens of gigabytes range. There seem to be two issues leading to the buffering of video and the delayed delivery of video to the browser.

  1. I've set a 500ms network buffer on the rtspsrc gstreamer filter. However, as latency grows, the delay increases and packets seem to accumulate in the rtpjitterbuffer. The first "fix" is to allow the rtspsrc to discard packets at the latency level and not to increase it beyond the set network buffer size. I made a change in the kmsplayerendpoint.c file:
element_added (GstBin * bin, GstElement * element, gpointer data)
{
  KmsPlayerEndpoint *self = KMS_PLAYER_ENDPOINT (data);


  if (g_strcmp0 (gst_plugin_feature_get_name (GST_PLUGIN_FEATURE
              (gst_element_get_factory (element))), RTSPSRC) == 0) {
    g_object_set (G_OBJECT (element), "latency", self->priv->network_cache,
        "drop-on-latency", TRUE, NULL);
  }
}

The change was to add "drop-on-latency" to the g_object_set command.

  1. There is a queue element just before the vp8 encoder which can buffer up to 1 second of video. Other places where the queue element is used, KMS restricts the amount of buffering either to a smaller number or smaller time frame. When the vp8 encoder falls behind, packets can stack up in the queue and new frames will block until space is available in the queue. I made a change to lower the amount of buffering the queue can hold and to allow it to discard old frames when the buffer fills up. The change is made in the kms_enc_tree_bin_configure function in the kmsenctreebin.c file:
  queue = gst_element_factory_make ("queue", NULL);
  g_object_set (queue, "leaky", 2, "max-size-buffers", 1, NULL);

These two fixes allow KMS to better handle high CPU load when decoding, transcoding, and delivering video. It also keeps KMS from consuming an increasing amount of memory due to the indefinite buffering of video.

@jenkinskurento
Copy link

Hi there. Thanks for your PR.

I'm waiting for a Kurento member to verify that this patch is reasonable to test. If it is, they should reply with check out please on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

@jenkinskurento
Copy link

There were no errors, go have a cup of coffee...

@j1elo j1elo merged commit d25a8cf into Kurento:master Jul 27, 2017
prlanzarin added a commit to prlanzarin/kms-core that referenced this pull request Nov 11, 2019
Fixed config-interval prop type checking in basertpendpoint
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants