Beispiel #1
0
static void
remb_event_manager_calc_min (RembEventManager * manager)
{
  guint remb_min = 0;
  GstClockTime time = kms_utils_get_time_nsecs ();
  GstClockTime oldest_time = GST_CLOCK_TIME_NONE;
  GHashTableIter iter;
  gpointer key, v;

  g_hash_table_iter_init (&iter, manager->remb_hash);
  while (g_hash_table_iter_next (&iter, &key, &v)) {
    guint br = ((RembHashValue *) v)->bitrate;
    GstClockTime ts = ((RembHashValue *) v)->ts;

    if (time - ts > REMB_HASH_CLEAR_INTERVAL) {
      GST_TRACE ("Remove entry %" G_GUINT32_FORMAT, GPOINTER_TO_UINT (key));
      g_hash_table_iter_remove (&iter);
      continue;
    }

    if (remb_min == 0) {
      remb_min = br;
    } else {
      remb_min = MIN (remb_min, br);
    }

    oldest_time = MIN (oldest_time, ts);
  }

  manager->oldest_remb_value = oldest_time;
  remb_event_manager_set_min (manager, remb_min);
}
Beispiel #2
0
static void
remb_event_manager_update_min (RembEventManager * manager, guint bitrate,
    guint ssrc)
{
  RembHashValue *last_value, *value;

  g_mutex_lock (&manager->mutex);
  last_value = g_hash_table_lookup (manager->remb_hash,
      GUINT_TO_POINTER (ssrc));

  if (last_value != NULL && bitrate == last_value->bitrate) {
    last_value->ts = kms_utils_get_time_nsecs ();
    goto end;
  }

  value = remb_hash_value_create (bitrate);
  g_hash_table_insert (manager->remb_hash, GUINT_TO_POINTER (ssrc), value);

  if (bitrate > manager->remb_min) {
    remb_event_manager_calc_min (manager);
  } else {
    remb_event_manager_set_min (manager, bitrate);
  }

end:

  GST_TRACE_OBJECT (manager->pad, "remb_min: %" G_GUINT32_FORMAT,
      manager->remb_min);

  g_mutex_unlock (&manager->mutex);
}
Beispiel #3
0
static void
remb_event_manager_update_min (RembEventManager * manager, guint bitrate,
    guint ssrc)
{
  RembHashValue *last_value;
  GstClockTime time = kms_utils_get_time_nsecs ();
  gboolean new_br = TRUE;

  g_mutex_lock (&manager->mutex);
  last_value = g_hash_table_lookup (manager->remb_hash,
      GUINT_TO_POINTER (ssrc));

  if (last_value != NULL) {
    new_br = bitrate != last_value->bitrate;
    last_value->bitrate = bitrate;
    last_value->ts = kms_utils_get_time_nsecs ();
  } else {
    RembHashValue *value;

    value = remb_hash_value_create (bitrate);
    g_hash_table_insert (manager->remb_hash, GUINT_TO_POINTER (ssrc), value);
  }

  if (bitrate < manager->remb_min) {
    remb_event_manager_set_min (manager, bitrate);
  } else {
    gboolean calc_min;

    calc_min = new_br && (bitrate > manager->remb_min);
    calc_min = calc_min
        || (time - manager->oldest_remb_time > manager->clear_interval);
    if (calc_min) {
      remb_event_manager_calc_min (manager, bitrate);
    }
  }

  GST_TRACE_OBJECT (manager->pad, "remb_min: %" G_GUINT32_FORMAT,
      manager->remb_min);

  g_mutex_unlock (&manager->mutex);
}