Reputation: 349
I'm trying to play out an incoming RTP audio stream using ffplay (or, alternatively, by using my own code which uses libav). The incoming stream is muxing RTP and RTCP packets. The playout works, but two local UDP ports are used:
This is the ffplay command:
ffplay -loglevel verbose -protocol_whitelist file,udp,rtp test.sdp
And the content of the SDP file:
v=0
o=- 0 0 IN IP4 192.168.51.51
s=RTP-INPUT-1
c=IN IP4 192.168.51.61
t=0 0
m=audio 8006 RTP/AVP 97
b=AS:96
a=rtpmap:97 opus/48000/1
a=rtcp-mux
Note the line a=rtcp-mux
. Even with this line present, two local UDP ports are used. I would expect this to be only 1 port.
I'm looking for a way to use only one UDP port.
Here's the relevant libav c++ code (I've left out error handling etc):
auto formatContext = avformat_alloc_context();
const AVInputFormat* format = av_find_input_format("sdp");
AVDictionary *formatOpts = nullptr;
av_dict_set(&formatOpts, "protocol_whitelist", "file,udp,rtp", 0);
int result = avformat_open_input(&formatContext, sdpFilepath, format, &formatOpts);
result = avformat_find_stream_info(formatContext, nullptr);
Upvotes: 1
Views: 1266
Reputation: 555
RTP always uses two ports, RTP flow is on an even-numbered port and RTCP control flow is on the next odd-numbered port.
Edit: https://www.rfc-editor.org/rfc/rfc8035 RFC8035 clarifies how to multiplex RTP and RTCP on a single IP address and port, referred to as RTP/RTCP multiplexing.
You are on the right track. After some digging in all those RFC, I suppose the best action is to check if the RTP stack of ffmpeg implements rfc5761 esp. section 4:
- Distinguishable RTP and RTCP Packets
When RTP and RTCP packets are multiplexed onto a single port, the
RTCP packet type field occupies the same position in the packet as
the combination of the RTP marker (M) bit and the RTP payload type
(PT). This field can be used to distinguish RTP and RTCP packets
when two restrictions are observed: 1) the RTP payload type values
used are distinct from the RTCP packet types used; and 2) for each
RTP payload type (PT), PT+128 is distinct from the RTCP packet types
used. The first constraint precludes a direct conflict between RTP
payload type and RTCP packet type; the second constraint precludes a
conflict between an RTP data packet with the marker bit set and an
RTCP packet.
Upvotes: 1