Commit 321259c1 authored by Martin Storsjö's avatar Martin Storsjö

rtsp: Return a queued packet if it has been in the queue for longer than max_delay

Originally committed as revision 25295 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 58ee0991
...@@ -1674,7 +1674,7 @@ static int rtsp_read_header(AVFormatContext *s, ...@@ -1674,7 +1674,7 @@ static int rtsp_read_header(AVFormatContext *s,
} }
static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
uint8_t *buf, int buf_size) uint8_t *buf, int buf_size, int64_t wait_end)
{ {
RTSPState *rt = s->priv_data; RTSPState *rt = s->priv_data;
RTSPStream *rtsp_st; RTSPStream *rtsp_st;
...@@ -1685,6 +1685,8 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, ...@@ -1685,6 +1685,8 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
for (;;) { for (;;) {
if (url_interrupt_cb()) if (url_interrupt_cb())
return AVERROR(EINTR); return AVERROR(EINTR);
if (wait_end && wait_end - av_gettime() < 0)
return AVERROR(EAGAIN);
FD_ZERO(&rfds); FD_ZERO(&rfds);
if (rt->rtsp_hd) { if (rt->rtsp_hd) {
tcp_fd = fd_max = url_get_file_handle(rt->rtsp_hd); tcp_fd = fd_max = url_get_file_handle(rt->rtsp_hd);
...@@ -1800,7 +1802,8 @@ static int rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -1800,7 +1802,8 @@ static int rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
{ {
RTSPState *rt = s->priv_data; RTSPState *rt = s->priv_data;
int ret, len; int ret, len;
RTSPStream *rtsp_st; RTSPStream *rtsp_st, *first_queue_st = NULL;
int64_t wait_end = 0;
if (rt->nb_byes == rt->nb_rtsp_streams) if (rt->nb_byes == rt->nb_rtsp_streams)
return AVERROR_EOF; return AVERROR_EOF;
...@@ -1820,6 +1823,22 @@ static int rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -1820,6 +1823,22 @@ static int rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
rt->cur_transport_priv = NULL; rt->cur_transport_priv = NULL;
} }
if (rt->transport == RTSP_TRANSPORT_RTP) {
int i;
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 = ff_rtp_queued_packet_time(rtpctx);
if (queue_time && (queue_time - first_queue_time < 0 ||
!first_queue_time)) {
first_queue_time = queue_time;
first_queue_st = rt->rtsp_streams[i];
}
}
if (first_queue_time)
wait_end = first_queue_time + s->max_delay;
}
/* read next RTP packet */ /* read next RTP packet */
redo: redo:
if (!rt->recvbuf) { if (!rt->recvbuf) {
...@@ -1837,11 +1856,17 @@ static int rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -1837,11 +1856,17 @@ static int rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
#endif #endif
case RTSP_LOWER_TRANSPORT_UDP: case RTSP_LOWER_TRANSPORT_UDP:
case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:
len = udp_read_packet(s, &rtsp_st, rt->recvbuf, RECVBUF_SIZE); len = udp_read_packet(s, &rtsp_st, rt->recvbuf, RECVBUF_SIZE, wait_end);
if (len >=0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP) if (len >=0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP)
rtp_check_and_send_back_rr(rtsp_st->transport_priv, len); rtp_check_and_send_back_rr(rtsp_st->transport_priv, len);
break; break;
} }
if (len == AVERROR(EAGAIN) && first_queue_st &&
rt->transport == RTSP_TRANSPORT_RTP) {
rtsp_st = first_queue_st;
ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, NULL, 0);
goto end;
}
if (len < 0) if (len < 0)
return len; return len;
if (len == 0) if (len == 0)
...@@ -1878,6 +1903,7 @@ static int rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -1878,6 +1903,7 @@ static int rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
} }
} }
} }
end:
if (ret < 0) if (ret < 0)
goto redo; goto redo;
if (ret == 1) if (ret == 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment