From e96406eda4f143f101bd44372f7b2d542183000a Mon Sep 17 00:00:00 2001 From: Martin Storsjö Date: Tue, 1 Jan 2013 23:41:29 +0200 Subject: rtsp: Add support for depacketizing RTP data via custom IO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To use this, set sdpflags=custom_io to the sdp demuxer. During the avformat_open_input call, the SDP is read from the AVFormatContext AVIOContext (ctx->pb) - after the avformat_open_input call, during the av_read_frame() calls, the same ctx->pb is used for reading packets (and sending back RTCP RR packets). Normally, one would use this with a read-only AVIOContext for the SDP during the avformat_open_input call, then close that one and replace it with a read-write one for the packets after the avformat_open_input call has returned. This allows using the RTP depacketizers as "pure" demuxers, without having them tied to the libavformat network IO. Signed-off-by: Martin Storsjö --- libavformat/rtpdec.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'libavformat/rtpdec.c') diff --git a/libavformat/rtpdec.c b/libavformat/rtpdec.c index 77df188cb9..08150b734a 100644 --- a/libavformat/rtpdec.c +++ b/libavformat/rtpdec.c @@ -226,7 +226,8 @@ static int rtp_valid_packet_in_sequence(RTPStatistics *s, uint16_t seq) return 1; } -int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd, int count) +int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd, + AVIOContext *avio, int count) { AVIOContext *pb; uint8_t *buf; @@ -242,7 +243,7 @@ int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd, int count) uint32_t fraction; uint64_t ntp_time = s->last_rtcp_ntp_time; // TODO: Get local ntp time? - if (!fd || (count < 1)) + if ((!fd && !avio) || (count < 1)) return -1; /* TODO: I think this is way too often; RFC 1889 has algorithm for this */ @@ -255,7 +256,9 @@ int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd, int count) return -1; s->last_octet_count = s->octet_count; - if (avio_open_dyn_buf(&pb) < 0) + if (!fd) + pb = avio; + else if (avio_open_dyn_buf(&pb) < 0) return -1; // Receiver Report @@ -312,6 +315,8 @@ int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, URLContext *fd, int count) avio_w8(pb, 0); avio_flush(pb); + if (!fd) + return 0; len = avio_close_dyn_buf(pb, &buf); if ((len > 0) && buf) { int av_unused result; -- cgit v1.2.3