Synchronizing appsrcs that subscribe to appsink on different times

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Synchronizing appsrcs that subscribe to appsink on different times

Mert Can Ergun
I have tried to build a system to allow gst-rtsp-server plugin to host the
same source element on different mapping points.

My system consists of a source pipeline that is built as "videotestsrc !
appsink caps=\"video/x-raw,width=640,height=512,format=GRAY8\""
This source pipeline is kept seperate from RTSPMediaFactory pipelines. Its
state it changed to PLAYING as soon as a client connects to the server,
and server builds up an appsrc accordingly. And its state is changed back
to NULL when there are no more clients left on the server.

RTSPMediaFactory pipelines are built as "appsrc name=appsrc0/1 caps=\"same
as source\" ! some specific elements for each pipeline ! x264enc !
rtph264pay name=pay0". I listen media-configure signal in order to capture
newly built appsrcs so I can register them to a list and use _push_sample
to pass buffers around.

I will name client1(C1) as the client who connects to the first mapping
point(M1), and client2(C2) as the client who connects to the second
mapping point(M2).

The working scenario is:
C1 connects to M1 at t0. C2 connects to M2 at a time t1 which meets the
condition: t1 - t2 < 0:08 (approximately). In this scenario; both VLC
players are able to stream the video to the user.

Non working scenario is
C1 connects to M1 at t0. C2 connects to M2 at time t1 > t0 + 0:10 (again,
approximately). In this scenario; C1 is able to continue playing fine, but
C2 is not able to stream any video. After a while, C2 drops without any
error(OPTIONS,DESCRIBE,SETUP,PLAY sequences are done fine, but no data
arrives to the C2).
Via logs I am able to see that samples are sent fine and GST_FLOW_OK
answer is returned to them on the appsink side.

How can I solve this seemingly synchronization problem to achive multiple
mapping(mount) point RTSP server on the same source pipeline?

-------------------------------
Mert Can Ergun
Yazilim Gelistirme Muhendisi

Mikro-Tasar&#305;m Elektronik San. ve Tic. A.&#350;.
ODTU-Teknokent ODTU-MET Alani
A-1 Blok 4. Bolum Ofis 3/A
TR-06530 Ankara
T: +90 312 286 0103
F: +90 312 286 0104
U: www.mikro-tasarim.com.tr
E: [hidden email]
-------------------------------

_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: Synchronizing appsrcs that subscribe to appsink on different times

Sebastian Dröge-3
On Wed, 2016-12-14 at 12:54 +0200, Mert Can Ergun wrote:

> How can I solve this seemingly synchronization problem to achive multiple
> mapping(mount) point RTSP server on the same source pipeline?

You need to translate timestamps from one pipeline to the other. In the
simplest case if both are running on the same clock this means
basically (between the appsink and appsrc):

1) Get running time for the PTS/DTS based on the segment
2) Convert to clock time with the base time of the appsink
3) Either add the configured latency of the appsink pipeline to the
clock time, or configure that latency as the min-latency of the appsrc
4) Convert to running time of the appsrc with the base time of it
5) Convert the running time to a buffer PTS/DTS based on a default [0,-
1] segment for the appsrc (that's what it is configured to by default)

If both pipelines are running with different clocks, then an additional
step is needed between 3) and 4).

--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (981 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Synchronizing appsrcs that subscribe to appsink on different times

Mert Can Ergun
Hi Sebastian,
I tested various pipelines connected to the same source pipeline for their clock pointers and they seemed to have the same clock.
Then I started a counter inside my source pipeline for each client and tagged each buffer with following three lines.

        GST_BUFFER_TIMESTAMP(buf) = timestamps[i];
        GST_BUFFER_DURATION(buf) = bufferDuration;
        timestamps[i] += GST_BUFFER_DURATION(buf);

The system seems to be working now.
Reply | Threaded
Open this post in threaded view
|

Re: Synchronizing appsrcs that subscribe to appsink on different times

Sebastian Dröge-3
On Thu, 2016-12-29 at 22:47 -0800, Mert Can Ergun wrote:

> Hi Sebastian,
> I tested various pipelines connected to the same source pipeline for
> their
> clock pointers and they seemed to have the same clock.
> Then I started a counter inside my source pipeline for each client
> and
> tagged each buffer with following three lines.
>
> GST_BUFFER_TIMESTAMP(buf) = timestamps[i];
> GST_BUFFER_DURATION(buf) = bufferDuration;
> timestamps[i] += GST_BUFFER_DURATION(buf);
>
> The system seems to be working now. 
That's not going to work reliable for a long run unless you're lucky.
There's an accumulating error with the durations at least, possibly
more problems.

--
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel

signature.asc (981 bytes) Download Attachment