The packetization-mode mode and three stream transmission modes in the sdp protocol

1. The sdp protocol in rtsp

The sdp name is the session description protocol, including the sip protocol, which is also used in the
rtsp protocol. The ps stream, ts stream, and naked stream are also called es streams. The es stream is more conventional and familiar with the rtp packet method of h264 or the h265 packet method. For h265 packet RTP, you can refer to the ffmpeg source code
rtsp protocol. If the transmission is h264 h265
The media name in the "m=" line is "video"
The encoding name in the "a=rtpmap" line is H264 h265
"a=rtpmap" line The clock frequency is generally 90000, and it can be other numbers, but the number 90000 is suitable for many frame rates, so use it.
Other parameters are included in "a=fmtp".

2. pm mode

packetization-mode:
indicates the supported packetization mode.
1. When the packetization-mode value is 0 or does not exist, a single NALU unit mode must be used.
2. When the packetization-mode value is 1, use non-interleaved (non-interleaved) packet mode 3.
When the value of packetization-mode is 2, use the interleaved (interleaved) packet mode.

profile-level-id:
This parameter is used to indicate the profile type and level of the H.264 stream. It is represented by Base16 (hexadecimal) 3 bytes. The first byte indicates the profile type of H.264, the second Three bytes represent the Profile level of H.264

We generally use packetization-mode = 1, non-interleaved mode

3. ps, ts, es transmission mode

The following code is used to restore the rtsp scene to transmit three different streams

int handle_cmd(string& cmd, string& CSeq, uint32_t sessionid, char* cmdres,int ps_n_ts)
	{
    
    
		#define BUFSIZE 8*1024

		int h26xtype = 96;
		if (cmd.compare("DESCRIBE") == 0)
		{
    
    
			const char * psnts;
			if (ps_n_ts == 1)
			{
    
    
				psnts = "a=rtpmap:32 MP2P/90000";
				h26xtype = 32;
			}
			else if (ps_n_ts == 2)
			{
    
    
				psnts = "a=rtpmap:96 H264/90000";
				h26xtype = 96;
			}
			else if (ps_n_ts == 3)
			{
    
    
				psnts = "a=rtpmap:33 MP2T/90000";
				h26xtype = 33;
			}
			char sdp[4096];
			sprintf(sdp, "v=0\r\n"
				"o=shyjx 22345 22345 IN IP4 %s\r\n"
				"s=H.264 Video, streamed by qb\r\n"
				"t=0 0\r\n"
				//"m=video 0 RTP/AVP 96\r\n"
				"%s\r\n"
				"c=IN IP4 0.0.0.0\r\n"
				"a=rtpmap:96 H264/90000\r\n"
				"a=fmtp:96 packetization-mode=1;\r\n"
				"a=control:stream", m_strlocalip.c_str(), psnts, h26xtype);
			return buildDescribeRes(cmdres, BUFSIZE, sdp, CSeq.c_str());
		}
		else if (cmd.compare("OPTIONS") == 0)
		{
    
    
			return buildOptionRes(cmdres, BUFSIZE, CSeq.c_str());
		}
		else if (cmd.compare("SETUP") == 0)
		{
    
    
			return buildSetupTcpRes(cmdres, BUFSIZE, 0, 1, sessionid, CSeq.c_str());
		}
		else if (cmd.compare("PLAY") == 0)
		{
    
    
			return buildPlayRes(cmdres, BUFSIZE, NULL, sessionid, CSeq.c_str());
		}
		else if (cmd.compare("TEARDOWN") == 0)
		{
    
    
			return buildTeardownRes(cmdres, BUFSIZE, sessionid, CSeq.c_str());
		}
		return -1;
	}

Guess you like

Origin blog.csdn.net/qianbo042311/article/details/125554119