11/* GStreamer
2+ * Copyright (C) 2016 Erick Arroyo <erick.arroyo@ridgerun.com>
23 * Copyright (C) 2016 Carlos Rodriguez <carlos.rodriguez@ridgerun.com>
4+ * Copyright (C) 2020 Jennifer Caballero <jennifer.caballero@ridgerun.com>
35 *
46 * This library is free software; you can redistribute it and/or
57 * modify it under the terms of the GNU Library General Public
2729#include <gst/app/gstappsink.h>
2830
2931/*
30- * Given two pipelines, play the first one, wait and the play
32+ * Given two pipelines, play the first one, wait and then play
3133 * the other one, it should not be delay in the video when it is display
34+ * only if the stream-sync property is set to compensate-ts (2)
3235 */
33- GST_START_TEST (interpipe_synchronization )
36+ GST_START_TEST (interpipe_stream_sync_compensate_ts )
3437{
3538 GstPipeline * sink1 ;
3639 GstPipeline * sink2 ;
3740 GstPipeline * src ;
3841 GstElement * vtsrc1 ;
3942 GstElement * vtsrc2 ;
43+
4044 GstElement * intersrc ;
4145 GstElement * asink ;
4246 GstSample * outsample ;
@@ -61,7 +65,9 @@ GST_START_TEST (interpipe_synchronization)
6165 /* Create one source pipeline */
6266 src =
6367 GST_PIPELINE (gst_parse_launch
64- ("interpipesrc name=intersrc listen-to=intersink1 block-switch=false allow-renegotiation=true format=3 ! capsfilter caps=video/x-raw,width=[320,1920],height=[240,1080],framerate=(fraction)5/1 ! "
68+ ("interpipesrc name=intersrc listen-to=intersink1 stream-sync=compensate-ts "
69+ "block-switch=false allow-renegotiation=true format=3 ! capsfilter "
70+ "caps=video/x-raw,width=[320,1920],height=[240,1080],framerate=(fraction)5/1 ! "
6571 "appsink name=asink drop=true async=false sync=true" , & error ));
6672 fail_if (error );
6773 intersrc = gst_bin_get_by_name (GST_BIN (src ), "intersrc" );
@@ -73,38 +79,60 @@ GST_START_TEST (interpipe_synchronization)
7379 * completed. It's used here to guarantee a secuential pipeline initialization
7480 * and avoid concurrency errors.
7581 */
76- fail_if (GST_STATE_CHANGE_FAILURE == gst_element_set_state (GST_ELEMENT (src ),
77- GST_STATE_PLAYING ));
78- fail_if (GST_STATE_CHANGE_FAILURE == gst_element_get_state (GST_ELEMENT (src ),
79- NULL , NULL , GST_CLOCK_TIME_NONE ));
8082 fail_if (GST_STATE_CHANGE_FAILURE ==
8183 gst_element_set_state (GST_ELEMENT (sink1 ), GST_STATE_PLAYING ));
8284 fail_if (GST_STATE_CHANGE_FAILURE ==
8385 gst_element_get_state (GST_ELEMENT (sink1 ), NULL , NULL ,
8486 GST_CLOCK_TIME_NONE ));
87+ fail_if (GST_STATE_CHANGE_FAILURE == gst_element_set_state (GST_ELEMENT (src ),
88+ GST_STATE_PLAYING ));
89+ fail_if (GST_STATE_CHANGE_FAILURE == gst_element_get_state (GST_ELEMENT (src ),
90+ NULL , NULL , GST_CLOCK_TIME_NONE ));
8591 fail_if (GST_STATE_CHANGE_FAILURE ==
8692 gst_element_set_state (GST_ELEMENT (sink2 ), GST_STATE_PLAYING ));
8793 fail_if (GST_STATE_CHANGE_FAILURE ==
88- gst_element_get_state (GST_ELEMENT (sink1 ), NULL , NULL ,
94+ gst_element_get_state (GST_ELEMENT (sink2 ), NULL , NULL ,
8995 GST_CLOCK_TIME_NONE ));
9096
9197 /* Verifies if the caps are set correctly to the listeners
9298 */
9399 outsample = gst_app_sink_pull_sample (GST_APP_SINK (asink ));
94100 buffer = gst_sample_get_buffer (outsample );
95101 fail_if (!buffer );
96- buffer_timestamp1 = GST_BUFFER_DTS (buffer );
97- GST_ERROR ("Buffer timestamp (dts): %" GST_TIME_FORMAT ,
98- GST_TIME_ARGS (GST_BUFFER_DTS (buffer )));
102+ buffer_timestamp1 = GST_BUFFER_PTS (buffer );
99103 fail_if (buffer_timestamp1 == 0 );
104+ gst_sample_unref (outsample );
105+
106+ /* Disconnect interpipesrc and flush old buffers */
107+ g_object_set (G_OBJECT (intersrc ), "listen-to" , NULL , NULL );
108+ fail_if (!gst_element_send_event (GST_ELEMENT (src ), gst_event_new_flush_start ()));
109+ fail_if (!gst_element_send_event (GST_ELEMENT (src ), gst_event_new_flush_stop (FALSE)));
100110
101111 /* Change to another video src */
102112 g_object_set (G_OBJECT (intersrc ), "listen-to" , "intersink2" , NULL );
113+
103114 outsample = gst_app_sink_pull_sample (GST_APP_SINK (asink ));
104115 buffer = gst_sample_get_buffer (outsample );
105116 buffer_timestamp2 = GST_BUFFER_PTS (buffer );
106117 fail_if (buffer_timestamp2 == 0 );
118+
107119 fail_if (buffer_timestamp2 < buffer_timestamp1 );
120+ gst_sample_unref (outsample );
121+
122+ /* Disconnect interpipesrc and flush old buffers */
123+ g_object_set (G_OBJECT (intersrc ), "listen-to" , NULL , NULL );
124+ fail_if (!gst_element_send_event (GST_ELEMENT (src ), gst_event_new_flush_start ()));
125+ fail_if (!gst_element_send_event (GST_ELEMENT (src ), gst_event_new_flush_stop (FALSE)));
126+
127+ /* Now change to the first video src and pull another buffer */
128+ g_object_set (G_OBJECT (intersrc ), "listen-to" , "intersink1" , NULL );
129+
130+ outsample = gst_app_sink_pull_sample (GST_APP_SINK (asink ));
131+ buffer = gst_sample_get_buffer (outsample );
132+ buffer_timestamp1 = GST_BUFFER_PTS (buffer );
133+ fail_if (buffer_timestamp1 == 0 );
134+
135+ fail_if (buffer_timestamp1 < buffer_timestamp2 );
108136
109137 /* Stop pipelines */
110138 fail_if (GST_STATE_CHANGE_FAILURE ==
@@ -131,11 +159,10 @@ static Suite *
131159gst_interpipe_suite (void )
132160{
133161 Suite * suite = suite_create ("Interpipe" );
134- TCase * tc = tcase_create ("interpipe_synchronization " );
162+ TCase * tc1 = tcase_create ("interpipe_stream_sync " );
135163
136- tcase_set_timeout (tc , 0 );
137- suite_add_tcase (suite , tc );
138- tcase_add_test (tc , interpipe_synchronization );
164+ suite_add_tcase (suite , tc1 );
165+ tcase_add_test (tc1 , interpipe_stream_sync_compensate_ts );
139166
140167 return suite ;
141168}
0 commit comments