Skip to content

Commit 6b0ff04

Browse files
author
Gaétan Collaud
committed
reuse the same session
1 parent ae2c709 commit 6b0ff04

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

src/client/rtsp/client.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default class RTSPClient extends BaseClient {
3232
};
3333
this.sampleQueues={};
3434
}
35-
35+
3636
static streamType() {
3737
return 'rtsp';
3838
}
@@ -428,6 +428,7 @@ export class RTSPClientSM extends StateMachine {
428428

429429
sendSetup() {
430430
let streams=[];
431+
let lastPromise = null;
431432

432433
// TODO: select first video and first audio tracks
433434
for (let track_type of this.tracks) {
@@ -438,7 +439,8 @@ export class RTSPClientSM extends StateMachine {
438439
if (!PayloadType.string_map[track.rtpmap[track.fmt[0]].name]) continue;
439440

440441
this.streams[track_type] = new RTSPStream(this, track);
441-
let setupPromise = this.streams[track_type].start();
442+
let setupPromise = this.streams[track_type].start(lastPromise);
443+
lastPromise = setupPromise;
442444
this.parent.sampleQueues[PayloadType.string_map[track.rtpmap[track.fmt[0]].name]]=[];
443445
this.rtpBuffer[track.fmt[0]]=[];
444446
streams.push(setupPromise.then(({track, data})=>{
@@ -562,4 +564,4 @@ export class RTSPClientSM extends StateMachine {
562564
}
563565
// this.remuxer.feedRTP();
564566
}
565-
}
567+
}

src/client/rtsp/stream.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ export class RTSPStream {
2727
this.track = null;
2828
}
2929

30-
start() {
31-
return this.sendSetup();//.then(this.sendPlay.bind(this));
30+
start(lastSetupPromise = null) {
31+
if (lastSetupPromise != null) {
32+
// if a setup was already made, use the same session
33+
return lastSetupPromise.then((obj) => this.sendSetup(obj.session))
34+
} else {
35+
return this.sendSetup();
36+
}
3237
}
3338

3439
stop() {
@@ -102,14 +107,18 @@ export class RTSPStream {
102107
return this.client.sendRequest(_cmd, this.getControlURL(), params);
103108
}
104109

105-
sendSetup() {
110+
sendSetup(session = null) {
106111
this.state = RTSPClient.STATE_SETUP;
107112
this.rtpChannel = this.client.interleaveChannelIndex;
108113
let interleavedChannels = this.client.interleaveChannelIndex++ + "-" + this.client.interleaveChannelIndex++;
109-
return this.client.sendRequest('SETUP', this.getSetupURL(this.track), {
114+
let params = {
110115
'Transport': `RTP/AVP/TCP;unicast;interleaved=${interleavedChannels}`,
111116
'Date': new Date().toUTCString()
112-
}).then((_data) => {
117+
};
118+
if(session){
119+
params.Session = session;
120+
}
121+
return this.client.sendRequest('SETUP', this.getSetupURL(this.track), params).then((_data) => {
113122
this.session = _data.headers['session'];
114123
let transport = _data.headers['transport'];
115124
if (transport) {
@@ -122,7 +131,7 @@ export class RTSPStream {
122131
let sessionParams = {};
123132
for (let chunk of sessionParamsChunks) {
124133
let kv = chunk.split('=');
125-
sessionParams[kv[0]]=kv[1];
134+
sessionParams[kv[0]] = kv[1];
126135
}
127136
if (sessionParams['timeout']) {
128137
this.keepaliveInterval = Number(sessionParams['timeout']) * 500; // * 1000 / 2
@@ -133,7 +142,7 @@ export class RTSPStream {
133142
}*/
134143
this.client.useRTPChannel(this.rtpChannel);
135144
this.startKeepAlive();
136-
return {track: this.track, data: _data};
145+
return {track: this.track, data: _data, session: this.session};
137146
});
138147
}
139148
}

0 commit comments

Comments
 (0)