Skip to content

Commit fbcd8f4

Browse files
committed
Implement outgoing CSeq in RTSP output, add session identifier to outgoing requests
1 parent 5ad91f8 commit fbcd8f4

2 files changed

Lines changed: 16 additions & 21 deletions

File tree

src/output/output_rtsp.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace Mist{
4242
}
4343

4444
OutRTSP::OutRTSP(Socket::Connection &myConn) : Output(myConn){
45+
outCSeq = 0;
4546
pausepoint = 0;
4647
setPacketOffset = false;
4748
packetOffset = 0;
@@ -123,36 +124,26 @@ namespace Mist{
123124
SDP::Track & sdpTrk = sdpState.tracks[thisIdx];
124125
sdpTrk.pack.setTimestamp((timestamp + offset) * SDP::getMultiplier(&M, thisIdx));
125126

126-
sdpTrk.pack.sendData([this, &sdpTrk](const char * data, size_t len){
127+
// Callback function used in sendData and sendRTCP_SR
128+
auto sendFunc = [this, &sdpTrk](const char * data, size_t len){
127129
if (sdpTrk.channel == -1){
128130
// UDP connection
129131
sdpTrk.data.SendNow(data, len);
130132
myConn.addUp(len);
131133
}else{
132-
// 1 byte '$', 1 byte channel, 2 bytes length
133-
char buf[] = "$$$$";
134+
// TCP Connection
135+
char buf[] = "$$$$"; // 1 byte '$', 1 byte channel, 2 bytes length
134136
buf[1] = sdpTrk.channel;
135137
((short *)buf)[1] = htons(len);
136138
myConn.SendNow(buf, 4);
137139
myConn.SendNow(data, len);
138140
}
139-
}, dataPointer, dataLen, meta.getCodec(thisIdx));
141+
};
142+
143+
sdpTrk.pack.sendData(sendFunc, dataPointer, dataLen, meta.getCodec(thisIdx));
140144

141145
if (Util::bootSecs() != sdpTrk.rtcpSent){
142-
sdpTrk.pack.sendRTCP_SR([this, &sdpTrk](const char * data, size_t len){
143-
if (sdpTrk.channel == -1){
144-
// UDP connection
145-
sdpTrk.rtcp.SendNow(data, len);
146-
myConn.addUp(len);
147-
}else{
148-
// 1 byte '$', 1 byte channel, 2 bytes length
149-
char buf[] = "$$$$";
150-
buf[1] = sdpTrk.channel;
151-
((short *)buf)[1] = htons(len);
152-
myConn.SendNow(buf, 4);
153-
myConn.SendNow(data, len);
154-
}
155-
});
146+
sdpTrk.pack.sendRTCP_SR(sendFunc);
156147
sdpTrk.rtcpSent = Util::bootSecs();
157148
}
158149

@@ -164,6 +155,8 @@ namespace Mist{
164155
HTTP_S.Clean();
165156
HTTP_S.SetHeader("Content-Type", "application/sdp");
166157
HTTP_S.SetHeader("Content-Base", reqUrl);
158+
HTTP_S.SetHeader("CSeq", ++outCSeq);
159+
if (sessName.size()){ HTTP_S.SetHeader("Session", sessName); }
167160
HTTP_S.method = "ANNOUNCE";
168161
HTTP_S.url = reqUrl;
169162
HTTP_S.protocol = "RTSP/1.0";
@@ -215,10 +208,10 @@ namespace Mist{
215208
streamName = HTTP_R.url.substr(found + 1, HTTP_R.url.substr(found + 1).find('/'));
216209
Util::sanitizeName(streamName);
217210
}
218-
if (streamName.size()){
219-
HTTP_S.SetHeader("Session", Secure::md5(HTTP_S.GetHeader("User-Agent") + getConnectedHost()) +
220-
"_" + streamName);
211+
if (streamName.size() && !sessName.size()){
212+
sessName = Secure::md5(HTTP_S.GetHeader("User-Agent") + getConnectedHost()) + "_" + streamName;
221213
}
214+
if (sessName.size()){ HTTP_S.SetHeader("Session", sessName); }
222215

223216
// allow setting of max lead time through buffer variable.
224217
// max lead time is set in MS, but the variable is in integer seconds for simplicity.

src/output/output_rtsp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace Mist{
2020
void incomingRTP(const uint64_t track, const RTP::Packet &p);
2121

2222
private:
23+
uint64_t outCSeq; ///< Sequence number for outgoing requests
24+
std::string sessName; ///< Session string for the RTSP session
2325
uint64_t pausepoint; ///< Position to pause at, when reached
2426
SDP::State sdpState;
2527
HTTP::Parser HTTP_R, HTTP_S;

0 commit comments

Comments
 (0)