On Wed, 23 Nov 2016, Luca Barbato wrote:
Move the actual data parsing and the queued stream selection
in separate functions.
---
Before I continue chopping that function in smaller bits I want your opinion.
The plan is to further reshape this quite complex loop so at least it is easier
to see what's happening.
Then I'd add move the receive buffer size as an option and possibly keep the
networking side in a separate thread to avoid overruns when the bitrate is much
larger than the current design expects.
I'm not too eager about this in particular, but some refactoring here
probably can be good, as long as it doesn't break anything.
libavformat/rtsp.c | 106 ++++++++++++++++++++++++++++++++---------------------
libavformat/rtsp.h | 1 +
2 files changed, 66 insertions(+), 41 deletions(-)
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 7e59857..15ea393 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -2043,11 +2043,68 @@ static int pick_stream(AVFormatContext *s, RTSPStream
**rtsp_st,
return AVERROR(EAGAIN);
}
+static int64_t parse_packet(RTSPState *rt, AVPacket *pkt)
+{
+ int ret;
I'm not sure this name is quite right; this only does the simpler version
of parsing out more packets out of the existing buffers; further down in
ff_rtsp_fetch_packet there's the full version which also sends RTCP RR and
other RTCP feedback, and syncs the RTCP based timestamps for other
streams.
Ideally I guess we should integrate both of them into the same function,
and just do the RTCP sync and feedback if a specific flag is set to the
function.
+
+ if (rt->transport == RTSP_TRANSPORT_RDT) {
+ ret = ff_rdt_parse_packet(rt->cur_transport_priv, pkt, NULL, 0);
+ } else if (rt->transport == RTSP_TRANSPORT_RTP) {
+ ret = ff_rtp_parse_packet(rt->cur_transport_priv, pkt, NULL, 0);
+ } else if (CONFIG_RTPDEC && rt->ts) {
+ ret = ff_mpegts_parse_packet(rt->ts, pkt,
+ rt->recvbuf + rt->recvbuf_pos,
+ rt->recvbuf_len - rt->recvbuf_pos);
+ if (ret >= 0) {
+ rt->recvbuf_pos += ret;
+ ret = rt->recvbuf_pos < rt->recvbuf_len;
+ }
+ } else
+ ret = -1;
+
+ if (ret == 0) {
+ rt->cur_transport_priv = NULL;
+ return 0;
+ } else if (ret == 1)
+ return 0;
+
+ return ret;
+}
+
+static int select_queue_stream(AVFormatContext *s)
+{
+ RTSPState *rt = s->priv_data;
+ int i;
+ int64_t wait_end;
+ int64_t first_queue_time = 0;
+
+ for (i = 0; i < rt->nb_rtsp_streams; i++) {
+ RTPDemuxContext *rtpctx = rt->rtsp_streams[i]->transport_priv;
+ int64_t queue_time;
+ if (!rtpctx)
+ continue;
+ queue_time = ff_rtp_queued_packet_time(rtpctx);
+ if (queue_time && (queue_time - first_queue_time < 0 ||
+ !first_queue_time)) {
+ first_queue_time = queue_time;
+ rt->first_queue_st = rt->rtsp_streams[i];
+ }
+ }
+ if (first_queue_time) {
+ wait_end = first_queue_time + s->max_delay;
+ } else {
+ wait_end = 0;
+ rt->first_queue_st = NULL;
+ }
I'd prefer this to pass first_queue_st as a pointer to this function,
keeping it as a local variable in the caller for now.
// Martin
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel