test: rtpbin_buffer_list: add test to verify that stats are correct

Add a test to verify that stats about sent and received packets are
correct even when using buffer lists.

NOTE: the newly introduced get_session_source_stats() selects the
desired source (sender or receiver) by filtering them by type (using the
get_sender parameter) rather than by ssrc because this simplifies the
code and it's good enough for testing purposes as there is usually one
source per type in the test setup.

Filtering by ssrc would have required handling asynchronous signals like
"on-new-sender-ssrc", with the relative locking, just to retrieve the
actual ssrc of the sender.
This commit is contained in:
Antonio Ospite 2019-04-02 12:51:04 +02:00
parent 0fae88b5fd
commit 6f12f1cecc

View file

@ -269,6 +269,45 @@ sink_chain_list (GstPad * pad, GstObject * parent, GstBufferList * list)
return GST_FLOW_OK;
}
/* Get the stats of the **first** source of the given type (get_sender) */
static void
get_session_source_stats (GstElement * rtpbin, guint session,
gboolean get_sender, GstStructure ** source_stats)
{
GstElement *rtpsession;
GstStructure *stats;
GValueArray *stats_arr;
guint i;
g_signal_emit_by_name (rtpbin, "get-session", session, &rtpsession);
fail_if (rtpsession == NULL);
g_object_get (rtpsession, "stats", &stats, NULL);
stats_arr =
g_value_get_boxed (gst_structure_get_value (stats, "source-stats"));
g_assert (stats_arr != NULL);
fail_unless (stats_arr->n_values >= 1);
*source_stats = NULL;
for (i = 0; i < stats_arr->n_values; i++) {
GstStructure *tmp_source_stats;
gboolean is_sender;
tmp_source_stats = g_value_dup_boxed (&stats_arr->values[i]);
gst_structure_get (tmp_source_stats, "is-sender", G_TYPE_BOOLEAN,
&is_sender, NULL);
/* Return the stats of the **first** source of the given type. */
if (is_sender == get_sender) {
*source_stats = tmp_source_stats;
break;
}
gst_structure_free (tmp_source_stats);
}
gst_structure_free (stats);
gst_object_unref (rtpsession);
}
GST_START_TEST (test_bufferlist)
{
@ -277,6 +316,9 @@ GST_START_TEST (test_bufferlist)
GstPad *sinkpad;
GstCaps *caps;
GstBufferList *list;
GstStructure *stats;
guint64 packets_sent;
guint64 packets_received;
list = create_buffer_list ();
fail_unless (list != NULL);
@ -307,6 +349,17 @@ GST_START_TEST (test_bufferlist)
fail_unless (gst_pad_push_list (srcpad, list) == GST_FLOW_OK);
fail_if (chain_list_func_called == FALSE);
/* make sure that stats about the number of sent packets are OK too */
get_session_source_stats (rtpbin, 0, TRUE, &stats);
fail_if (stats == NULL);
gst_structure_get (stats,
"packets-sent", G_TYPE_UINT64, &packets_sent,
"packets-received", G_TYPE_UINT64, &packets_received, NULL);
fail_unless (packets_sent == 2);
fail_unless (packets_received == 2);
gst_structure_free (stats);
gst_pad_set_active (sinkpad, FALSE);
gst_pad_set_active (srcpad, FALSE);