Skip to content

Commit ea53ac6

Browse files
authored
fix: SDP information in RFC 4566 is indicated to end with CRLF (0x0d0a) (#376)
1 parent 63b6abe commit ea53ac6

6 files changed

Lines changed: 46 additions & 29 deletions

File tree

librtsp/source/sdp/sdp-aac.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ int sdp_aac_latm(uint8_t *data, int bytes, const char* proto, unsigned short por
1818
// this parameter SHALL NOT be considered as the definitive sampling rate.
1919
// profile-level-id --> ISO/IEC 14496-3:2009 audioProfileLevelIndication values
2020
static const char* pattern =
21-
"m=audio %hu %s %d\n"
22-
"a=rtpmap:%d MP4A-LATM/%d/%d\n"
21+
"m=audio %hu %s %d\r\n"
22+
"a=rtpmap:%d MP4A-LATM/%d/%d\r\n"
2323
"a=fmtp:%d profile-level-id=%d;object=%d;cpresent=0;config=";
2424

2525
int r, n;
@@ -54,8 +54,11 @@ int sdp_aac_latm(uint8_t *data, int bytes, const char* proto, unsigned short por
5454
return -ENOMEM; // don't have enough memory
5555
n += (int)base16_encode((char*)data + n, config, r);
5656

57-
if (n < bytes)
58-
data[n++] = '\n';
57+
if (n + 2 > bytes)
58+
return -ENOMEM; // don't have enough memory
59+
60+
data[n++] = '\r';
61+
data[n++] = '\n';
5962
return n;
6063
}
6164

@@ -71,8 +74,8 @@ int sdp_aac_generic(uint8_t *data, int bytes, const char* proto, unsigned short
7174
// If an MPEG-4 audio stream is transported, the rate SHOULD be set to the same value as the sampling rate of the audio stream.
7275
// If an MPEG-4 video stream transported, it is RECOMMENDED that the rate be set to 90 kHz.
7376
static const char* pattern =
74-
"m=audio %hu %s %d\n"
75-
"a=rtpmap:%d mpeg4-generic/%d/%d\n"
77+
"m=audio %hu %s %d\r\n"
78+
"a=rtpmap:%d mpeg4-generic/%d/%d\r\n"
7679
"a=fmtp:%d streamtype=5;profile-level-id=%d;mode=AAC-hbr;sizeLength=13;indexLength=3;indexDeltaLength=3;config=";
7780

7881
int r, n;
@@ -95,8 +98,11 @@ int sdp_aac_generic(uint8_t *data, int bytes, const char* proto, unsigned short
9598
// decoder configuration data AudioSpecificConfig()
9699
n += (int)base16_encode((char*)data + n, extra, extra_size);
97100

98-
if (n < bytes)
99-
data[n++] = '\n';
101+
if (n + 2 > bytes)
102+
return -ENOMEM; // don't have enough memory
103+
104+
data[n++] = '\r';
105+
data[n++] = '\n';
100106
return n;
101107
}
102108

@@ -137,9 +143,9 @@ void sdp_aac_test(void)
137143
//const unsigned char aachbr[] = { "11B0" }; // 48000/6 streamtype=5; profile-level-id=16
138144

139145
const uint8_t config[] = { 0x11, 0x90, };
140-
//const char* mpeg4_generic_sdp = "m=audio 0 RTP/AVP 96\na=rtpmap:96 mpeg4-generic/48000/2\na=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1190; SizeLength=13; IndexLength=3; IndexDeltaLength=3; Profile=1\n";
141-
const char* mpeg4_generic_sdp = "m=audio 0 RTP/AVP 96\na=rtpmap:96 mpeg4-generic/48000/2\na=fmtp:96 streamtype=5;profile-level-id=41;mode=AAC-hbr;sizeLength=13;indexLength=3;indexDeltaLength=3;config=1190\n";
142-
//const char* mp4a_latm_sdp = "m=audio 0 RTP/AVP 96\na=rtpmap:96 MP4A-LATM/48000/2\na=fmtp:96 profile-level-id=9;object=8;cpresent=0;config=9128B1071070\n";
146+
//const char* mpeg4_generic_sdp = "m=audio 0 RTP/AVP 96\r\na=rtpmap:96 mpeg4-generic/48000/2\r\na=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1190; SizeLength=13; IndexLength=3; IndexDeltaLength=3; Profile=1\r\n";
147+
const char* mpeg4_generic_sdp = "m=audio 0 RTP/AVP 96\r\na=rtpmap:96 mpeg4-generic/48000/2\r\na=fmtp:96 streamtype=5;profile-level-id=41;mode=AAC-hbr;sizeLength=13;indexLength=3;indexDeltaLength=3;config=1190\r\n";
148+
//const char* mp4a_latm_sdp = "m=audio 0 RTP/AVP 96\r\na=rtpmap:96 MP4A-LATM/48000/2\r\na=fmtp:96 profile-level-id=9;object=8;cpresent=0;config=9128B1071070\r\n";
143149
uint8_t buffer[256];
144150
//struct mpeg4_aac_t aac;
145151
//int n;

librtsp/source/sdp/sdp-g7xx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99

1010
int sdp_g711u(uint8_t *data, int bytes, const char* proto, unsigned short port)
1111
{
12-
static const char* pattern = "m=audio %hu %s 0\n";
12+
static const char* pattern = "m=audio %hu %s 0\r\n";
1313
return snprintf((char*)data, bytes, pattern, port, proto && *proto ? proto : "RTP/AVP");
1414
}
1515

1616
int sdp_g711a(uint8_t *data, int bytes, const char* proto, unsigned short port)
1717
{
18-
static const char* pattern = "m=audio %hu %s 8\n";
18+
static const char* pattern = "m=audio %hu %s 8\r\n";
1919
return snprintf((char*)data, bytes, pattern, port, proto && *proto ? proto : "RTP/AVP");
2020
}

librtsp/source/sdp/sdp-h264.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
int sdp_h264(uint8_t *data, int bytes, const char* proto, unsigned short port, int payload, int frequence, const void* extra, int extra_size)
1414
{
1515
static const char* pattern =
16-
"m=video %hu %s %d\n"
17-
"a=rtpmap:%d H264/90000\n"
16+
"m=video %hu %s %d\r\n"
17+
"a=rtpmap:%d H264/90000\r\n"
1818
"a=fmtp:%d packetization-mode=1;profile-level-id=%02X%02X%02X;sprop-parameter-sets=";
1919

2020
int r, n;
@@ -47,8 +47,12 @@ int sdp_h264(uint8_t *data, int bytes, const char* proto, unsigned short port, i
4747
n += (int)base64_encode((char*)data + n, avc.pps[i].data, avc.pps[i].bytes);
4848
}
4949

50-
if (n < bytes)
51-
data[n++] = '\n';
50+
if (n + 2 > bytes)
51+
return -ENOMEM; // don't have enough memory
52+
53+
data[n++] = '\r';
54+
data[n++] = '\n';
55+
5256
return n;
5357
}
5458

@@ -81,7 +85,7 @@ int sdp_h264_load(uint8_t* data, int bytes, const char* config)
8185
#if defined(_DEBUG) || defined(DEBUG)
8286
void sdp_h264_test(void)
8387
{
84-
const char* sdp = "m=video 0 RTP/AVP 96\na=rtpmap:96 H264/90000\na=fmtp:96 packetization-mode=1;profile-level-id=64001F;sprop-parameter-sets=Z2QAH6zZQFAFumoCGgKAAAADAIAAAB5HjBjL,aO+8sA==\n";
88+
const char* sdp = "m=video 0 RTP/AVP 96\r\na=rtpmap:96 H264/90000\r\na=fmtp:96 packetization-mode=1;profile-level-id=64001F;sprop-parameter-sets=Z2QAH6zZQFAFumoCGgKAAAADAIAAAB5HjBjL,aO+8sA==\r\n";
8589
const char* config = "Z2QAH6zZQFAFumoCGgKAAAADAIAAAB5HjBjL,aO+8sA==";
8690
static const uint8_t extra[] = { 0x01, 0x64, 0x00, 0x1f, 0xff, 0xe1, 0x00, 0x1b, 0x67, 0x64, 0x00, 0x1f, 0xac, 0xd9, 0x40, 0x50, 0x05, 0xba, 0x6a, 0x02, 0x1a, 0x02, 0x80, 0x00, 0x00, 0x03, 0x00, 0x80, 0x00, 0x00, 0x1e, 0x47, 0x8c, 0x18, 0xcb, 0x01, 0x00, 0x04, 0x68, 0xef, 0xbc, 0xb0 };
8791
static const uint8_t ps[] = { 0x00, 0x00, 0x00, 0x1, 0x67, 0x64, 0x00, 0x1f, 0xac, 0xd9, 0x40, 0x50, 0x05, 0xba, 0x6a, 0x02, 0x1a, 0x02, 0x80, 0x00, 0x00, 0x03, 0x00, 0x80, 0x00, 0x00, 0x1e, 0x47, 0x8c, 0x18, 0xcb, 0x00, 0x00, 0x00, 0x1, 0x68, 0xef, 0xbc, 0xb0 };

librtsp/source/sdp/sdp-h265.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
int sdp_h265(uint8_t *data, int bytes, const char* proto, unsigned short port, int payload, int frequence, const void* extra, int extra_size)
1414
{
1515
static const char* pattern =
16-
"m=video %hu %s %d\n"
17-
"a=rtpmap:%d H265/90000\n"
16+
"m=video %hu %s %d\r\n"
17+
"a=rtpmap:%d H265/90000\r\n"
1818
"a=fmtp:%d";
1919

2020
const uint8_t nalu[] = { 32/*vps*/, 33/*sps*/, 34/*pps*/ };
@@ -50,8 +50,11 @@ int sdp_h265(uint8_t *data, int bytes, const char* proto, unsigned short port, i
5050
}
5151
}
5252

53-
if(n < bytes)
54-
data[n++] = '\n';
53+
if (n + 2 > bytes)
54+
return -ENOMEM; // don't have enough memory
55+
56+
data[n++] = '\r';
57+
data[n++] = '\n';
5558
return n;
5659
}
5760

librtsp/source/sdp/sdp-h266.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
int sdp_h266(uint8_t *data, int bytes, const char* proto, unsigned short port, int payload, int frequence, const void* extra, int extra_size)
1414
{
1515
static const char* pattern =
16-
"m=video %hu %s %d\n"
17-
"a=rtpmap:%d H266/90000\n"
16+
"m=video %hu %s %d\r\n"
17+
"a=rtpmap:%d H266/90000\r\n"
1818
"a=fmtp:%d";
1919

2020
const uint8_t nalu[] = { 13/*dci*/, 14/*vps*/, 15/*sps*/, 16/*pps*/ };
@@ -50,8 +50,12 @@ int sdp_h266(uint8_t *data, int bytes, const char* proto, unsigned short port, i
5050
}
5151
}
5252

53-
if(n < bytes)
54-
data[n++] = '\n';
53+
if (n + 2 > bytes)
54+
return -ENOMEM; // don't have enough memory
55+
56+
data[n++] = '\r';
57+
data[n++] = '\n';
58+
5559
return n;
5660
}
5761

librtsp/source/sdp/sdp-opus.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ int sdp_opus(uint8_t *data, int bytes, const char* proto, unsigned short port, i
1616
can be declared via fmtp parameters (both default to mono), but
1717
receivers MUST be able to receive and process stereo packets. */
1818
static const char* pattern =
19-
"m=audio %hu %s %d\n"
20-
"a=rtpmap:%d opus/%d/2\n";
19+
"m=audio %hu %s %d\r\n"
20+
"a=rtpmap:%d opus/%d/2\r\n";
2121

2222
int n;
2323

2424
sample_rate = sample_rate ? sample_rate : 48000;
2525
n = snprintf((char*)data, bytes, pattern, port, proto && *proto ? proto : "RTP/AVP", payload, payload, sample_rate);
2626
if (2 == channel_count)
27-
n += snprintf((char*)data + n, bytes - n, "a=fmtp:%d sprop-stereo=1\n", payload);
27+
n += snprintf((char*)data + n, bytes - n, "a=fmtp:%d sprop-stereo=1\r\n", payload);
2828
return n;
2929
}

0 commit comments

Comments
 (0)