Skip to content

Commit

Permalink
Merge pull request Streamedian#75 from gaetancollaud/feature/rtsp_ses…
Browse files Browse the repository at this point in the history
…sion

Reuse the same session for all RTSP tracks
  • Loading branch information
kreopt authored Mar 18, 2018
2 parents ae2c709 + 6b0ff04 commit 68ac0a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/client/rtsp/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class RTSPClient extends BaseClient {
};
this.sampleQueues={};
}

static streamType() {
return 'rtsp';
}
Expand Down Expand Up @@ -428,6 +428,7 @@ export class RTSPClientSM extends StateMachine {

sendSetup() {
let streams=[];
let lastPromise = null;

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

this.streams[track_type] = new RTSPStream(this, track);
let setupPromise = this.streams[track_type].start();
let setupPromise = this.streams[track_type].start(lastPromise);
lastPromise = setupPromise;
this.parent.sampleQueues[PayloadType.string_map[track.rtpmap[track.fmt[0]].name]]=[];
this.rtpBuffer[track.fmt[0]]=[];
streams.push(setupPromise.then(({track, data})=>{
Expand Down Expand Up @@ -562,4 +564,4 @@ export class RTSPClientSM extends StateMachine {
}
// this.remuxer.feedRTP();
}
}
}
23 changes: 16 additions & 7 deletions src/client/rtsp/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ export class RTSPStream {
this.track = null;
}

start() {
return this.sendSetup();//.then(this.sendPlay.bind(this));
start(lastSetupPromise = null) {
if (lastSetupPromise != null) {
// if a setup was already made, use the same session
return lastSetupPromise.then((obj) => this.sendSetup(obj.session))
} else {
return this.sendSetup();
}
}

stop() {
Expand Down Expand Up @@ -102,14 +107,18 @@ export class RTSPStream {
return this.client.sendRequest(_cmd, this.getControlURL(), params);
}

sendSetup() {
sendSetup(session = null) {
this.state = RTSPClient.STATE_SETUP;
this.rtpChannel = this.client.interleaveChannelIndex;
let interleavedChannels = this.client.interleaveChannelIndex++ + "-" + this.client.interleaveChannelIndex++;
return this.client.sendRequest('SETUP', this.getSetupURL(this.track), {
let params = {
'Transport': `RTP/AVP/TCP;unicast;interleaved=${interleavedChannels}`,
'Date': new Date().toUTCString()
}).then((_data) => {
};
if(session){
params.Session = session;
}
return this.client.sendRequest('SETUP', this.getSetupURL(this.track), params).then((_data) => {
this.session = _data.headers['session'];
let transport = _data.headers['transport'];
if (transport) {
Expand All @@ -122,7 +131,7 @@ export class RTSPStream {
let sessionParams = {};
for (let chunk of sessionParamsChunks) {
let kv = chunk.split('=');
sessionParams[kv[0]]=kv[1];
sessionParams[kv[0]] = kv[1];
}
if (sessionParams['timeout']) {
this.keepaliveInterval = Number(sessionParams['timeout']) * 500; // * 1000 / 2
Expand All @@ -133,7 +142,7 @@ export class RTSPStream {
}*/
this.client.useRTPChannel(this.rtpChannel);
this.startKeepAlive();
return {track: this.track, data: _data};
return {track: this.track, data: _data, session: this.session};
});
}
}

0 comments on commit 68ac0a3

Please sign in to comment.