提交 4f5df6fa authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Breaking things!

上级 a3d2de61
...@@ -66,7 +66,7 @@ module.exports = ...@@ -66,7 +66,7 @@ module.exports =
'max-len': [ 2, 86, 'max-len': [ 2, 86,
{ {
tabWidth: 2, tabWidth: 2,
comments: 86, comments: 90,
ignoreUrls: false, ignoreUrls: false,
ignoreStrings: false, ignoreStrings: false,
ignoreTemplateLiterals: false, ignoreTemplateLiterals: false,
......
# TODO in mediasoup v2 (server-side) # TODO in mediasoup v2 (server-side)
* Remove `gulp rtpcapabilities`.
* Should accept `peer.createTransport()` by passing a `transportId` number. The same for `Producer`. * Should accept `peer.createTransport()` by passing a `transportId` number. The same for `Producer`.
* May have to react on DTLS ALERT CLOSE in the server and make it "really" close the Transport and notify the client. Bufff... I don't like this... * May have to react on DTLS ALERT CLOSE in the server and make it "really" close the Transport and notify the client. Bufff... I don't like this...
......
...@@ -23,13 +23,13 @@ const workerFiles = ...@@ -23,13 +23,13 @@ const workerFiles =
]; ];
const nodeTests = const nodeTests =
[ [
'test/test-mediasoup.js', // 'test/test-mediasoup.js',
'test/test-Server.js', 'test/test-Server.js',
'test/test-Room.js', // 'test/test-Room.js',
'test/test-Peer.js', // 'test/test-Peer.js',
'test/test-Transport.js', // 'test/test-Transport.js',
'test/test-Producer.js', // 'test/test-Producer.js',
'test/test-utils.js' // 'test/test-utils.js'
]; ];
const workerCompilationDatabaseTemplate = 'worker/compile_commands_template.json'; const workerCompilationDatabaseTemplate = 'worker/compile_commands_template.json';
const workerHeaderFilterRegex = const workerHeaderFilterRegex =
...@@ -38,18 +38,6 @@ const workerHeaderFilterRegex = ...@@ -38,18 +38,6 @@ const workerHeaderFilterRegex =
'|handles/*.hpp|Channel/*.hpp|RTC/**/*.hpp)'; '|handles/*.hpp|Channel/*.hpp|RTC/**/*.hpp)';
const numCpus = os.cpus().length; const numCpus = os.cpus().length;
gulp.task('rtpcapabilities', () =>
{
const supportedRtpCapabilities = require('./lib/supportedRtpCapabilities');
return gulp.src('worker/src/RTC/Room.cpp')
// Let's generate valid syntax as expected by clang-format rules.
.pipe(replace(/(const std::string supportedRtpCapabilities =).*\r?\n.*/,
`$1\n\t\t\t R"(${JSON.stringify(supportedRtpCapabilities)})";`))
.pipe(gulp.dest('worker/src/RTC/'))
.pipe(touch());
});
gulp.task('lint:node', () => gulp.task('lint:node', () =>
{ {
return gulp.src(nodeFiles) return gulp.src(nodeFiles)
......
...@@ -22,7 +22,7 @@ class Room extends EventEmitter ...@@ -22,7 +22,7 @@ class Room extends EventEmitter
this._internal = internal; this._internal = internal;
// Room data. // Room data.
// - .capabilities // - .rtpCapabilities
this._data = data; this._data = data;
// Channel instance. // Channel instance.
...@@ -157,9 +157,9 @@ class Room extends EventEmitter ...@@ -157,9 +157,9 @@ class Room extends EventEmitter
return this._closed; return this._closed;
} }
get capabilities() get rtpCapabilities()
{ {
return this._data.capabilities; return this._data.rtpCapabilities;
} }
/** /**
...@@ -280,10 +280,7 @@ class Room extends EventEmitter ...@@ -280,10 +280,7 @@ class Room extends EventEmitter
// Store the Peer instance and remove it when closed. // Store the Peer instance and remove it when closed.
this._peers.set(peerName, peer); this._peers.set(peerName, peer);
peer.on('close', () => peer.on('close', () => this._peers.delete(peerName));
{
this._peers.delete(peerName);
});
// Listen for new Producers so we can associate new Consumers. // Listen for new Producers so we can associate new Consumers.
peer.on('newproducer', (producer) => peer.on('newproducer', (producer) =>
...@@ -343,7 +340,7 @@ class Room extends EventEmitter ...@@ -343,7 +340,7 @@ class Room extends EventEmitter
{ {
const response = const response =
{ {
rtpCapabilities : this.capabilities, rtpCapabilities : this.rtpCapabilities,
mandatoryCodecPayloadTypes : [] // TODO mandatoryCodecPayloadTypes : [] // TODO
}; };
......
...@@ -5,8 +5,9 @@ const path = require('path'); ...@@ -5,8 +5,9 @@ const path = require('path');
const EventEmitter = require('events').EventEmitter; const EventEmitter = require('events').EventEmitter;
const check = require('check-types'); const check = require('check-types');
const Logger = require('./Logger'); const Logger = require('./Logger');
const utils = require('./utils');
const errors = require('./errors'); const errors = require('./errors');
const utils = require('./utils');
const ortc = require('./ortc');
const Worker = require('./Worker'); const Worker = require('./Worker');
const DEFAULT_NUM_WORKERS = Object.keys(os.cpus()).length; const DEFAULT_NUM_WORKERS = Object.keys(os.cpus()).length;
...@@ -46,7 +47,7 @@ class Server extends EventEmitter ...@@ -46,7 +47,7 @@ class Server extends EventEmitter
this._closed = false; this._closed = false;
// Clone options. // Clone options.
options = utils.clone(options); options = utils.cloneObject(options);
// Update numWorkers (if given). // Update numWorkers (if given).
if (check.integer(options.numWorkers) && check.positive(options.numWorkers)) if (check.integer(options.numWorkers) && check.positive(options.numWorkers))
...@@ -229,6 +230,7 @@ class Server extends EventEmitter ...@@ -229,6 +230,7 @@ class Server extends EventEmitter
return Promise.all(promises); return Promise.all(promises);
} }
// TODO: REMOVE
/** /**
* Create a Room instance. * Create a Room instance.
* *
...@@ -252,6 +254,28 @@ class Server extends EventEmitter ...@@ -252,6 +254,28 @@ class Server extends EventEmitter
}); });
} }
/**
* Create a Room instance.
*
* @return {Room}
*/
Room(mediaCodecs)
{
logger.debug('Room()');
if (this._closed)
throw new errors.InvalidStateError('Server closed');
// This may throw.
const rtpCapabilities = ortc.generateRoomRtpCapabilities(mediaCodecs);
const worker = this._getRandomWorker();
const room = worker.Room({ rtpCapabilities });
this.emit('newroom', room);
return room;
}
_addWorker(worker) _addWorker(worker)
{ {
// Store the Worker instance and remove it when closed. // Store the Worker instance and remove it when closed.
......
...@@ -181,6 +181,7 @@ class Worker extends EventEmitter ...@@ -181,6 +181,7 @@ class Worker extends EventEmitter
}); });
} }
// TODO: REMOVE
createRoom(options) createRoom(options)
{ {
logger.debug('createRoom() [options:%o]', options); logger.debug('createRoom() [options:%o]', options);
...@@ -211,6 +212,40 @@ class Worker extends EventEmitter ...@@ -211,6 +212,40 @@ class Worker extends EventEmitter
throw error; throw error;
}); });
} }
/**
* Create a Room instance.
*
* @return {Room}
*/
Room(data)
{
logger.debug('Room()');
const internal =
{
roomId : utils.randomNumber()
};
const room = new Room(internal, data, this._channel);
// Store the Room instance and remove it when closed.
this._rooms.add(room);
room.on('close', () => this._rooms.delete(room));
this._channel.request('worker.createRoom', internal)
.then(() =>
{
logger.debug('"worker.createRoom" request succeeded');
})
.catch((error) =>
{
logger.error('"worker.createRoom" request failed: %s', error);
room.close(error, true);
});
return room;
}
} }
module.exports = Worker; module.exports = Worker;
'use strict';
const supportedRtpCapabilities = require('./supportedRtpCapabilities');
const DYNAMIC_PAYLOAD_TYPES =
[
100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115,
116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 96, 97, 98, 99, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71
];
/**
* Generate RTP capabilities for the room based on the given media codecs and
* mediasoup supported RTP capabilities. It may throw.
*
* @param {array<RoomMediaCodec>]} mediaCodecs
*
* @return {RTCRtpCapabilities}
*/
exports.generateRoomRtpCapabilities = function(mediaCodecs)
{
if (!Array.isArray(mediaCodecs))
throw new TypeError('mediaCodecs must be an Array');
const supportedCodecs = supportedRtpCapabilities.codecs;
const caps =
{
codecs : [],
headerExtensions : supportedRtpCapabilities.headerExtensions,
fecMechanisms : supportedRtpCapabilities.fecMechanisms
};
let dynamicPayloadTypeIdx = 0;
for (const mediaCodec of mediaCodecs)
{
if (typeof mediaCodecs !== 'object')
throw new TypeError('mediaCodec must be an Object');
const matchedSupportedCodec = supportedCodecs
.find((supportedCodec) =>
{
return matchCodecCapabilities(mediaCodec, supportedCodec);
});
if (!matchedSupportedCodec)
throw new Error(`RoomMediaCodec not supported [name:${mediaCodec.name}]`);
// Clone the supported codec.
const codec = Object.assign({}, matchedSupportedCodec);
// Normalize channels.
if (codec.kind !== 'audio')
delete codec.channels;
else if (!codec.channels)
codec.channels = 1;
// Merge the media codec parameters.
codec.parameters =
Object.assign({}, codec.parameters, mediaCodec.parameters);
// Ensure rtcpFeedback is an Array.
codec.rtcpFeedback = codec.rtcpFeedback || [];
// Assign a payload type.
if (typeof codec.preferredPayloadType !== 'number')
{
const pt = DYNAMIC_PAYLOAD_TYPES[dynamicPayloadTypeIdx++];
if (!pt)
throw new Error('cannot allocate more dynamic codec payload types');
codec.preferredPayloadType = pt;
}
// Append to the codec list.
caps.codecs.push(codec);
// Add a RTX video codec if video.
if (codec.kind === 'video')
{
const pt = DYNAMIC_PAYLOAD_TYPES[dynamicPayloadTypeIdx++];
if (!pt)
throw new Error('cannot allocate more dynamic codec payload types');
const rtxCodec =
{
kind : codec.kind,
name : 'rtx',
mimeType : `${codec.kind}/rtx`,
preferredPayloadType : pt,
clockRate : codec.clockRate,
parameters :
{
apt : codec.preferredPayloadType
}
};
// Append to the codec list.
caps.codecs.push(rtxCodec);
}
}
console.log(caps);
return caps;
};
function matchCodecCapabilities(codecA, codecB)
{
if (codecA.kind !== codecB.kind)
return false;
if (codecA.name.toLowerCase() !== codecB.name.toLowerCase())
return false;
if (codecA.clockRate !== codecB.clockRate)
return false;
if (
(codecA.channels > 1 || codecB.channels > 1) &&
codecA.channels !== codecB.channels)
{
return false;
}
// TODO: H264 parameters.
return true;
}
...@@ -5,124 +5,135 @@ const supportedRtpCapabilities = ...@@ -5,124 +5,135 @@ const supportedRtpCapabilities =
codecs : codecs :
[ [
{ {
kind : 'audio', kind : 'audio',
name : 'audio/opus', name : 'opus',
clockRate : 48000, mimeType : 'audio/opus',
numChannels : 2, clockRate : 48000,
rtcpFeedback : [] channels : 2
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/PCMU', name : 'PCMU',
clockRate : 8000, mimeType : 'audio/PCMU',
rtcpFeedback : [] preferredPayloadType : 0,
clockRate : 8000,
rtcpFeedback : []
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/PCMA', name : 'PCMA',
clockRate : 8000, mimeType : 'audio/PCMA',
rtcpFeedback : [] preferredPayloadType : 8,
clockRate : 8000,
rtcpFeedback : []
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/ISAC', name : 'ISAC',
mimeType : 'audio/ISAC',
clockRate : 32000, clockRate : 32000,
rtcpFeedback : [] rtcpFeedback : []
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/ISAC', name : 'ISAC',
clockRate : 16000, mimeType : 'audio/ISAC',
rtcpFeedback : [] clockRate : 16000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/G722', name : 'G722',
clockRate : 8000, mimeType : 'audio/G722',
rtcpFeedback : [] preferredPayloadType : 9,
clockRate : 8000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/iLBC', name : 'iLBC',
clockRate : 8000, mimeType : 'audio/iLBC',
rtcpFeedback : [] clockRate : 8000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/SILK', name : 'SILK',
clockRate : 24000, mimeType : 'audio/SILK',
rtcpFeedback : [] clockRate : 24000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/SILK', name : 'SILK',
clockRate : 16000, mimeType : 'audio/SILK',
rtcpFeedback : [] clockRate : 16000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/SILK', name : 'SILK',
clockRate : 12000, mimeType : 'audio/SILK',
rtcpFeedback : [] clockRate : 12000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/SILK', name : 'SILK',
clockRate : 8000, mimeType : 'audio/SILK',
rtcpFeedback : [] clockRate : 8000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/CN', name : 'CN',
clockRate : 32000, mimeType : 'audio/CN',
rtcpFeedback : [] preferredPayloadType : 13,
clockRate : 32000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/CN', name : 'CN',
clockRate : 16000, mimeType : 'audio/CN',
rtcpFeedback : [] preferredPayloadType : 13,
clockRate : 16000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/CN', name : 'CN',
clockRate : 8000, mimeType : 'audio/CN',
rtcpFeedback : [] preferredPayloadType : 13,
clockRate : 8000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/CN', name : 'CN',
clockRate : 32000, mimeType : 'audio/CN',
rtcpFeedback : [] preferredPayloadType : 13,
clockRate : 32000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/telephone-event', name : 'telephone-event',
clockRate : 48000, mimeType : 'audio/telephone-event',
rtcpFeedback : [] clockRate : 48000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/telephone-event', name : 'telephone-event',
clockRate : 32000, mimeType : 'audio/telephone-event',
rtcpFeedback : [] clockRate : 32000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/telephone-event', name : 'telephone-event',
clockRate : 16000, mimeType : 'audio/telephone-event',
rtcpFeedback : [] clockRate : 16000
}, },
{ {
kind : 'audio', kind : 'audio',
name : 'audio/telephone-event', name : 'telephone-event',
clockRate : 8000, mimeType : 'audio/telephone-event',
rtcpFeedback : [] clockRate : 8000
}, },
{ {
kind : 'video', kind : 'video',
name : 'video/VP8', name : 'VP8',
mimeType : 'video/VP8',
clockRate : 90000, clockRate : 90000,
rtcpFeedback : rtcpFeedback :
[ [
...@@ -139,7 +150,8 @@ const supportedRtpCapabilities = ...@@ -139,7 +150,8 @@ const supportedRtpCapabilities =
}, },
{ {
kind : 'video', kind : 'video',
name : 'video/VP9', name : 'VP9',
mimeType : 'video/VP9',
clockRate : 90000, clockRate : 90000,
rtcpFeedback : rtcpFeedback :
[ [
...@@ -156,7 +168,8 @@ const supportedRtpCapabilities = ...@@ -156,7 +168,8 @@ const supportedRtpCapabilities =
}, },
{ {
kind : 'video', kind : 'video',
name : 'video/H264', name : 'H264',
mimeType : 'video/H264',
clockRate : 90000, clockRate : 90000,
parameters : parameters :
{ {
...@@ -177,7 +190,8 @@ const supportedRtpCapabilities = ...@@ -177,7 +190,8 @@ const supportedRtpCapabilities =
}, },
{ {
kind : 'video', kind : 'video',
name : 'video/H264', name : 'H264',
mimeType : 'video/H264',
clockRate : 90000, clockRate : 90000,
parameters : parameters :
{ {
...@@ -198,7 +212,8 @@ const supportedRtpCapabilities = ...@@ -198,7 +212,8 @@ const supportedRtpCapabilities =
}, },
{ {
kind : 'video', kind : 'video',
name : 'video/H265', name : 'H265',
mimeType : 'video/H265',
clockRate : 90000, clockRate : 90000,
rtcpFeedback : rtcpFeedback :
[ [
......
...@@ -11,20 +11,17 @@ const randomNumberGenerator = randomNumber.generator( ...@@ -11,20 +11,17 @@ const randomNumberGenerator = randomNumber.generator(
integer : true integer : true
}); });
module.exports = exports.randomString = function(length)
{ {
randomString(length) return randomatic('a', length || 8);
{ };
return randomatic('a', length || 8);
},
randomNumber : randomNumberGenerator, exports.randomNumber = randomNumberGenerator;
clone(obj) exports.cloneObject = function(obj)
{ {
if (!obj || typeof obj !== 'object') if (typeof obj !== 'object')
return {}; return {};
else
return clone(obj, false); return clone(obj, false);
}
}; };
...@@ -2,139 +2,227 @@ ...@@ -2,139 +2,227 @@
const tap = require('tap'); const tap = require('tap');
const mediasoup = require('../'); const mediasoup = require('../');
const roomOptions = require('./data/options').roomOptions; // const roomOptions = require('./data/options').roomOptions;
tap.test( tap.test(
'server.updateSettings() with no options must succeed', { timeout: 2000 }, (t) => 'server.Room() with valid media codecs', { timeout: 2000 }, (t) =>
{ {
const server = mediasoup.Server(); const server = mediasoup.Server();
t.tearDown(() => server.close()); t.tearDown(() => server.close());
server.updateSettings() const mediaCodecs =
.then(() => [
{ {
t.pass('server.updateSettings() succeeded'); kind : 'audio',
t.end(); name : 'opus',
}) clockRate : 48000,
.catch((error) => t.fail(`server.updateSettings() failed: ${error}`)); channels : 2
}); },
tap.test(
'server.updateSettings() with valid options must succeed',
{ timeout: 2000 }, (t) =>
{
const server = mediasoup.Server();
t.tearDown(() => server.close());
server.updateSettings({ logLevel: 'warn' })
.then(() =>
{ {
t.pass('server.updateSettings() succeeded'); kind : 'audio',
t.end(); name : 'PCMU',
}) clockRate : 8000
.catch((error) => t.fail(`server.updateSettings() failed: ${error}`)); },
});
tap.test(
'server.updateSettings() with invalid options must fail', { timeout: 2000 }, (t) =>
{
const server = mediasoup.Server();
t.tearDown(() => server.close());
server.updateSettings({ logLevel: 'chicken' })
.then(() => t.fail('server.updateSettings() succeeded'))
.catch((error) =>
{ {
t.pass(`server.updateSettings() failed: ${error}`); kind : 'video',
t.end(); name : 'VP8',
}); clockRate : 90000,
}); parameters :
tap.test(
'server.updateSettings() in a closed server must fail', { timeout: 2000 }, (t) =>
{
const server = mediasoup.Server();
t.tearDown(() => server.close());
server.on('close', () =>
{
server.updateSettings({ logLevel: 'error' })
.then(() => t.fail('server.updateSettings() succeeded'))
.catch((error) =>
{ {
t.pass(`server.updateSettings() failed: ${error}`); foo : 123
t.type( }
error, mediasoup.errors.InvalidStateError, }
'server.updateSettings() must reject with InvalidStateError'); ];
t.end();
});
});
server.close();
});
tap.test( const expectedCodecs =
'server.createRoom() must succeed', { _timeout: 2000 }, (t) => [
{
const server = mediasoup.Server();
t.tearDown(() => server.close());
server.createRoom(roomOptions)
.then((room) =>
{ {
t.pass('server.createRoom() succeeded'); kind : 'audio',
name : 'opus',
room.on('close', (error) => mimeType : 'audio/opus',
preferredPayloadType : 100,
clockRate : 48000,
channels : 2,
parameters : {}
},
{
kind : 'audio',
name : 'PCMU',
mimeType : 'audio/PCMU',
preferredPayloadType : 0,
clockRate : 8000,
channels : 1,
parameters : {}
},
{
kind : 'video',
name : 'VP8',
mimeType : 'video/VP8',
preferredPayloadType : 101,
clockRate : 90000,
parameters :
{ {
t.error(error, 'room must close cleanly'); foo : 123
t.end(); }
}); },
// Wait a bit so Channel requests receive response
setTimeout(() => room.close(), 50);
})
.catch((error) => t.fail(`server.createRoom() failed: ${error}`));
});
tap.test(
'server.createRoom() in a closed server must fail', { timeout: 2000 }, (t) =>
{
const server = mediasoup.Server();
server.close();
server.createRoom(roomOptions)
.then(() => t.fail('server.createRoom() succeeded'))
.catch((error) =>
{ {
t.pass(`server.createRoom() failed: ${error}`); kind : 'video',
t.type( name : 'rtx',
error, mediasoup.errors.InvalidStateError, mimeType : 'video/rtx',
'server.createRoom() must reject with InvalidStateError'); preferredPayloadType : 102,
t.end(); clockRate : 90000,
}); parameters :
}); {
apt : 101
tap.test( }
'server.dump() must succeed', { timeout: 2000 }, (t) => }
{ ];
const server = mediasoup.Server({ numWorkers: 2 });
const room = server.Room(mediaCodecs);
const reducedCodecs = room.rtpCapabilities.codecs
.map((codec) =>
{
delete codec.rtcpFeedback;
t.tearDown(() => server.close()); return codec;
});
server.dump() t.same(reducedCodecs, expectedCodecs, 'room codecs match');
.then((data) => t.end();
{
t.pass('server.dump() succeeded');
t.equal(
Object.keys(data.workers).length, 2,
'server.dump() must retrieve two workers');
t.end();
})
.catch((error) => t.fail(`server.dump() failed: ${error}`));
}); });
// tap.test(
// 'server.updateSettings() with no options must succeed', { timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server();
// t.tearDown(() => server.close());
// server.updateSettings()
// .then(() =>
// {
// t.pass('server.updateSettings() succeeded');
// t.end();
// })
// .catch((error) => t.fail(`server.updateSettings() failed: ${error}`));
// });
// tap.test(
// 'server.updateSettings() with valid options must succeed',
// { timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server();
// t.tearDown(() => server.close());
// server.updateSettings({ logLevel: 'warn' })
// .then(() =>
// {
// t.pass('server.updateSettings() succeeded');
// t.end();
// })
// .catch((error) => t.fail(`server.updateSettings() failed: ${error}`));
// });
// tap.test(
// 'server.updateSettings() with invalid options must fail', { timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server();
// t.tearDown(() => server.close());
// server.updateSettings({ logLevel: 'chicken' })
// .then(() => t.fail('server.updateSettings() succeeded'))
// .catch((error) =>
// {
// t.pass(`server.updateSettings() failed: ${error}`);
// t.end();
// });
// });
// tap.test(
// 'server.updateSettings() in a closed server must fail', { timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server();
// t.tearDown(() => server.close());
// server.on('close', () =>
// {
// server.updateSettings({ logLevel: 'error' })
// .then(() => t.fail('server.updateSettings() succeeded'))
// .catch((error) =>
// {
// t.pass(`server.updateSettings() failed: ${error}`);
// t.type(
// error, mediasoup.errors.InvalidStateError,
// 'server.updateSettings() must reject with InvalidStateError');
// t.end();
// });
// });
// server.close();
// });
// tap.test(
// 'server.createRoom() must succeed', { _timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server();
// t.tearDown(() => server.close());
// server.createRoom(roomOptions)
// .then((room) =>
// {
// t.pass('server.createRoom() succeeded');
// room.on('close', (error) =>
// {
// t.error(error, 'room must close cleanly');
// t.end();
// });
// // Wait a bit so Channel requests receive response
// setTimeout(() => room.close(), 50);
// })
// .catch((error) => t.fail(`server.createRoom() failed: ${error}`));
// });
// tap.test(
// 'server.createRoom() in a closed server must fail', { timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server();
// server.close();
// server.createRoom(roomOptions)
// .then(() => t.fail('server.createRoom() succeeded'))
// .catch((error) =>
// {
// t.pass(`server.createRoom() failed: ${error}`);
// t.type(
// error, mediasoup.errors.InvalidStateError,
// 'server.createRoom() must reject with InvalidStateError');
// t.end();
// });
// });
// tap.test(
// 'server.dump() must succeed', { timeout: 2000 }, (t) =>
// {
// const server = mediasoup.Server({ numWorkers: 2 });
// t.tearDown(() => server.close());
// server.dump()
// .then((data) =>
// {
// t.pass('server.dump() succeeded');
// t.equal(
// Object.keys(data.workers).length, 2,
// 'server.dump() must retrieve two workers');
// t.end();
// })
// .catch((error) => t.fail(`server.dump() failed: ${error}`));
// });
...@@ -30,13 +30,6 @@ namespace RTC ...@@ -30,13 +30,6 @@ namespace RTC
virtual void OnRoomClosed(RTC::Room* room) = 0; virtual void OnRoomClosed(RTC::Room* room) = 0;
}; };
public:
static void ClassInit();
private:
static RTC::RtpCapabilities supportedRtpCapabilities;
static std::vector<uint8_t> availablePayloadTypes;
public: public:
Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data); Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId, Json::Value& data);
......
...@@ -11,13 +11,6 @@ ...@@ -11,13 +11,6 @@
namespace RTC namespace RTC
{ {
enum class Scope : uint8_t
{
ROOM_CAPABILITY = 1,
PEER_CAPABILITY,
RECEIVE
};
class Media class Media
{ {
public: public:
...@@ -38,7 +31,7 @@ namespace RTC ...@@ -38,7 +31,7 @@ namespace RTC
static std::map<Kind, Json::StaticString> kind2Json; static std::map<Kind, Json::StaticString> kind2Json;
}; };
class RtpCodecMime class RtpCodecMimeType
{ {
public: public:
enum class Type : uint8_t enum class Type : uint8_t
...@@ -84,19 +77,24 @@ namespace RTC ...@@ -84,19 +77,24 @@ namespace RTC
static std::map<Subtype, std::string> subtype2String; static std::map<Subtype, std::string> subtype2String;
public: public:
RtpCodecMime(){}; RtpCodecMimeType(){};
bool operator==(const RtpCodecMime& other) const bool operator==(const RtpCodecMimeType& other) const
{ {
return this->type == other.type && this->subtype == other.subtype; return this->type == other.type && this->subtype == other.subtype;
} }
bool operator!=(const RtpCodecMime& other) const bool operator!=(const RtpCodecMimeType& other) const
{ {
return !(*this == other); return !(*this == other);
} }
void SetName(const std::string& name); void SetMimeType(const std::string& mimeType);
const std::string& ToString() const
{
return this->mimeType;
}
const std::string& GetName() const const std::string& GetName() const
{ {
...@@ -121,6 +119,9 @@ namespace RTC ...@@ -121,6 +119,9 @@ namespace RTC
public: public:
Type type{ Type::UNSET }; Type type{ Type::UNSET };
Subtype subtype{ Subtype::UNSET }; Subtype subtype{ Subtype::UNSET };
private:
std::string mimeType;
std::string name; std::string name;
}; };
...@@ -156,31 +157,27 @@ namespace RTC ...@@ -156,31 +157,27 @@ namespace RTC
std::string parameter; std::string parameter;
}; };
class RtpCodecParameters class RtpCodecCapability
{ {
public: public:
RtpCodecParameters(){}; RtpCodecCapability(){};
RtpCodecParameters(Json::Value& data, RTC::Scope scope); RtpCodecCapability(Json::Value& data);
Json::Value ToJson() const; Json::Value ToJson() const;
bool Matches(RtpCodecParameters& codec, bool checkPayloadType = false); bool Matches(RtpCodecCapability& codec, bool checkPayloadType = false);
void ReduceRtcpFeedback(std::vector<RtcpFeedback>& supportedRtcpFeedback); void ReduceRtcpFeedback(std::vector<RtcpFeedback>& supportedRtcpFeedback);
private: private:
void CheckCodec(); void CheckCodec();
private:
RTC::Scope scope{ RTC::Scope::ROOM_CAPABILITY };
public: public:
Media::Kind kind{ Media::Kind::ALL }; Media::Kind kind{ Media::Kind::ALL };
RtpCodecMime mime; RtpCodecMimeType mime;
uint8_t payloadType{ 0 }; uint8_t payloadType{ 0 };
bool hasPayloadType{ false };
uint32_t clockRate{ 0 }; uint32_t clockRate{ 0 };
uint32_t maxptime{ 0 }; uint32_t maxptime{ 0 };
uint32_t ptime{ 0 }; uint32_t ptime{ 0 };
uint32_t numChannels{ 1 }; uint32_t channels{ 1 };
RTC::Parameters parameters; RTC::Parameters parameters;
std::vector<RtcpFeedback> rtcpFeedback; std::vector<RtcpFeedback> rtcpFeedback;
}; };
...@@ -204,21 +201,46 @@ namespace RTC ...@@ -204,21 +201,46 @@ namespace RTC
{ {
public: public:
RtpCapabilities(){}; RtpCapabilities(){};
RtpCapabilities(Json::Value& data, RTC::Scope scope); RtpCapabilities(Json::Value& data);
Json::Value ToJson() const; Json::Value ToJson() const;
void ReduceHeaderExtensions(std::vector<RtpHeaderExtension>& supportedHeaderExtensions); void ReduceHeaderExtensions(std::vector<RtpHeaderExtension>& supportedHeaderExtensions);
void ReduceFecMechanisms(std::vector<std::string>& supportedFecMechanisms); void ReduceFecMechanisms(std::vector<std::string>& supportedFecMechanisms);
private: private:
void ValidateCodecs(RTC::Scope scope); void ValidateCodecs();
public: public:
std::vector<RtpCodecParameters> codecs; std::vector<RtpCodecCapability> codecs;
std::vector<RtpHeaderExtension> headerExtensions; std::vector<RtpHeaderExtension> headerExtensions;
std::vector<std::string> fecMechanisms; std::vector<std::string> fecMechanisms;
}; };
class RtpCodecParameters
{
public:
RtpCodecParameters(){};
RtpCodecParameters(Json::Value& data);
Json::Value ToJson() const;
bool Matches(RtpCodecParameters& codec, bool checkPayloadType = false);
void ReduceRtcpFeedback(std::vector<RtcpFeedback>& supportedRtcpFeedback);
private:
void CheckCodec();
public:
Media::Kind kind{ Media::Kind::ALL };
RtpCodecMimeType mime;
uint8_t payloadType{ 0 };
uint32_t clockRate{ 0 };
uint32_t maxptime{ 0 };
uint32_t ptime{ 0 };
uint32_t channels{ 1 };
RTC::Parameters parameters;
std::vector<RtcpFeedback> rtcpFeedback;
};
class RtpFecParameters class RtpFecParameters
{ {
public: public:
......
...@@ -17,7 +17,7 @@ namespace RTC ...@@ -17,7 +17,7 @@ namespace RTC
uint32_t ssrc{ 0 }; uint32_t ssrc{ 0 };
uint8_t payloadType{ 0 }; uint8_t payloadType{ 0 };
RTC::RtpCodecMime mime; RTC::RtpCodecMimeType mime;
uint32_t clockRate{ 0 }; uint32_t clockRate{ 0 };
bool useNack{ false }; bool useNack{ false };
bool usePli{ false }; bool usePli{ false };
......
...@@ -46,8 +46,7 @@ ...@@ -46,8 +46,7 @@
'src/RTC/RtpDictionaries/Parameters.cpp', 'src/RTC/RtpDictionaries/Parameters.cpp',
'src/RTC/RtpDictionaries/RtcpFeedback.cpp', 'src/RTC/RtpDictionaries/RtcpFeedback.cpp',
'src/RTC/RtpDictionaries/RtcpParameters.cpp', 'src/RTC/RtpDictionaries/RtcpParameters.cpp',
'src/RTC/RtpDictionaries/RtpCapabilities.cpp', 'src/RTC/RtpDictionaries/RtpCodecMimeType.cpp',
'src/RTC/RtpDictionaries/RtpCodecMime.cpp',
'src/RTC/RtpDictionaries/RtpCodecParameters.cpp', 'src/RTC/RtpDictionaries/RtpCodecParameters.cpp',
'src/RTC/RtpDictionaries/RtpEncodingParameters.cpp', 'src/RTC/RtpDictionaries/RtpEncodingParameters.cpp',
'src/RTC/RtpDictionaries/RtpFecParameters.cpp', 'src/RTC/RtpDictionaries/RtpFecParameters.cpp',
......
...@@ -469,10 +469,7 @@ namespace RTC ...@@ -469,10 +469,7 @@ namespace RTC
{ {
auto& codec = this->rtpParameters->GetRtxCodecForEncoding(encoding); auto& codec = this->rtpParameters->GetRtxCodecForEncoding(encoding);
if (codec.hasPayloadType) this->rtpStream->SetRtx(codec.payloadType, encoding.rtx.ssrc);
{
this->rtpStream->SetRtx(codec.payloadType, encoding.rtx.ssrc);
}
} }
} }
......
...@@ -179,7 +179,7 @@ namespace RTC ...@@ -179,7 +179,7 @@ namespace RTC
try try
{ {
this->capabilities = RTC::RtpCapabilities(request->data, RTC::Scope::PEER_CAPABILITY); this->capabilities = RTC::RtpCapabilities(request->data);
} }
catch (const MediaSoupError& error) catch (const MediaSoupError& error)
{ {
......
...@@ -466,14 +466,10 @@ namespace RTC ...@@ -466,14 +466,10 @@ namespace RTC
return; return;
auto& codec = this->rtpParameters->GetRtxCodecForEncoding(encoding); auto& codec = this->rtpParameters->GetRtxCodecForEncoding(encoding);
auto rtpStream = this->rtpStreams[ssrc];
if (codec.hasPayloadType) rtpStream->SetRtx(codec.payloadType, encoding.rtx.ssrc);
{ this->rtxStreamMap[encoding.rtx.ssrc] = rtpStream;
auto rtpStream = this->rtpStreams[ssrc];
rtpStream->SetRtx(codec.payloadType, encoding.rtx.ssrc);
this->rtxStreamMap[encoding.rtx.ssrc] = rtpStream;
}
} }
} }
......
...@@ -30,7 +30,7 @@ namespace RTC ...@@ -30,7 +30,7 @@ namespace RTC
{ {
// NOTE: These lines are auto-generated from data/supportedCapabilities.js. // NOTE: These lines are auto-generated from data/supportedCapabilities.js.
const std::string supportedRtpCapabilities = const std::string supportedRtpCapabilities =
R"({"codecs":[{"kind":"audio","name":"audio/opus","clockRate":48000,"numChannels":2,"rtcpFeedback":[]},{"kind":"audio","name":"audio/PCMU","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/PCMA","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/ISAC","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/ISAC","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/G722","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/iLBC","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":24000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":12000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/SILK","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/CN","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":48000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"audio/telephone-event","clockRate":8000,"rtcpFeedback":[]},{"kind":"video","name":"video/VP8","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/VP9","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/H264","clockRate":90000,"parameters":{"packetizationMode":0},"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/H264","clockRate":90000,"parameters":{"packetizationMode":1},"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"video/H265","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]}],"headerExtensions":[{"kind":"audio","uri":"urn:ietf:params:rtp-hdrext:ssrc-audio-level","preferredId":1,"preferredEncrypt":false},{"kind":"video","uri":"urn:ietf:params:rtp-hdrext:toffset","preferredId":2,"preferredEncrypt":false},{"kind":"","uri":"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time","preferredId":3,"preferredEncrypt":false},{"kind":"video","uri":"urn:3gpp:video-orientation","preferredId":4,"preferredEncrypt":false},{"kind":"","uri":"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id","preferredId":5,"preferredEncrypt":false}],"fecMechanisms":[]})"; R"({"codecs":[{"kind":"audio","name":"opus","mimeType":"audio/opus","clockRate":48000,"channels":2,"rtcpFeedback":[]},{"kind":"audio","name":"PCMU","mimeType":"audio/PCMU","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"PCMA","mimeType":"audio/PCMA","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"ISAC","mimeType":"audio/ISAC","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"ISAC","mimeType":"audio/ISAC","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"G722","mimeType":"audio/G722","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"LBC","mimeType":"audio/iLBC","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"SILK","mimeType":"audio/SILK","clockRate":24000,"rtcpFeedback":[]},{"kind":"audio","name":"SILK","mimeType":"audio/SILK","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"SILK","mimeType":"audio/SILK","clockRate":12000,"rtcpFeedback":[]},{"kind":"audio","name":"SILK","mimeType":"audio/SILK","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"CN","mimeType":"audio/CN","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"CN","mimeType":"audio/CN","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"CN","mimeType":"audio/CN","clockRate":8000,"rtcpFeedback":[]},{"kind":"audio","name":"CN","mimeType":"audio/CN","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"telephone-event","mimeType":"audio/telephone-event","clockRate":48000,"rtcpFeedback":[]},{"kind":"audio","name":"telephone-event","mimeType":"audio/telephone-event","clockRate":32000,"rtcpFeedback":[]},{"kind":"audio","name":"telephone-event","mimeType":"audio/telephone-event","clockRate":16000,"rtcpFeedback":[]},{"kind":"audio","name":"telephone-event","mimeType":"audio/telephone-event","clockRate":8000,"rtcpFeedback":[]},{"kind":"video","name":"VP8","mimeType":"video/VP8","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"VP9","mimeType":"video/VP9","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"H264","mimeType":"video/H264","clockRate":90000,"parameters":{"packetizationMode":0},"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"H264","mimeType":"video/H264","clockRate":90000,"parameters":{"packetizationMode":1},"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]},{"kind":"video","name":"H265","mimeType":"video/H265","clockRate":90000,"rtcpFeedback":[{"type":"nack"},{"type":"nack","parameter":"pli"},{"type":"nack","parameter":"sli"},{"type":"nack","parameter":"rpsi"},{"type":"nack","parameter":"app"},{"type":"ccm","parameter":"fir"},{"type":"ack","parameter":"rpsi"},{"type":"ack","parameter":"app"},{"type":"goog-remb"}]}],"headerExtensions":[{"kind":"audio","uri":"urn:ietf:params:rtp-hdrext:ssrc-audio-level","preferredId":1,"preferredEncrypt":false},{"kind":"video","uri":"urn:ietf:params:rtp-hdrext:toffset","preferredId":2,"preferredEncrypt":false},{"kind":"","uri":"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time","preferredId":3,"preferredEncrypt":false},{"kind":"video","uri":"urn:3gpp:video-orientation","preferredId":4,"preferredEncrypt":false},{"kind":"","uri":"urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id","preferredId":5,"preferredEncrypt":false}],"fecMechanisms":[]})";
Json::CharReaderBuilder builder; Json::CharReaderBuilder builder;
Json::Value settings = Json::nullValue; Json::Value settings = Json::nullValue;
...@@ -59,7 +59,7 @@ namespace RTC ...@@ -59,7 +59,7 @@ namespace RTC
try try
{ {
Room::supportedRtpCapabilities = RTC::RtpCapabilities(json, RTC::Scope::ROOM_CAPABILITY); Room::supportedRtpCapabilities = RTC::RtpCapabilities(json);
} }
catch (const MediaSoupError& error) catch (const MediaSoupError& error)
{ {
...@@ -85,7 +85,7 @@ namespace RTC ...@@ -85,7 +85,7 @@ namespace RTC
for (auto& jsonMediaCodec : jsonMediaCodecs) for (auto& jsonMediaCodec : jsonMediaCodecs)
{ {
RTC::RtpCodecParameters mediaCodec(jsonMediaCodec, RTC::Scope::ROOM_CAPABILITY); RTC::RtpCodecParameters mediaCodec(jsonMediaCodec);
// Ignore feature codecs. // Ignore feature codecs.
if (mediaCodec.mime.IsFeatureCodec()) if (mediaCodec.mime.IsFeatureCodec())
...@@ -507,7 +507,7 @@ namespace RTC ...@@ -507,7 +507,7 @@ namespace RTC
static const std::string videoRtx = "video/rtx"; static const std::string videoRtx = "video/rtx";
rtxCodec.kind = RTC::Media::Kind::VIDEO; rtxCodec.kind = RTC::Media::Kind::VIDEO;
rtxCodec.mime.SetName(videoRtx); rtxCodec.mime.SetMimeType(videoRtx);
rtxCodec.clockRate = mediaCodec.clockRate; rtxCodec.clockRate = mediaCodec.clockRate;
rtxCodec.parameters.SetInteger(associatedPayloadType, mediaCodec.payloadType); rtxCodec.parameters.SetInteger(associatedPayloadType, mediaCodec.payloadType);
......
...@@ -10,7 +10,7 @@ namespace RTC ...@@ -10,7 +10,7 @@ namespace RTC
{ {
/* Instance methods. */ /* Instance methods. */
RtpCapabilities::RtpCapabilities(Json::Value& data, RTC::Scope scope) RtpCapabilities::RtpCapabilities(Json::Value& data)
{ {
MS_TRACE(); MS_TRACE();
...@@ -25,7 +25,7 @@ namespace RTC ...@@ -25,7 +25,7 @@ namespace RTC
for (auto& jsonCodec : jsonCodecs) for (auto& jsonCodec : jsonCodecs)
{ {
RtpCodecParameters codec(jsonCodec, scope); RtpCodecCapability codec(jsonCodec);
// Append to the codecs vector. // Append to the codecs vector.
this->codecs.push_back(codec); this->codecs.push_back(codec);
...@@ -64,7 +64,7 @@ namespace RTC ...@@ -64,7 +64,7 @@ namespace RTC
// Validate RTP capabilities. // Validate RTP capabilities.
ValidateCodecs(scope); ValidateCodecs();
} }
Json::Value RtpCapabilities::ToJson() const Json::Value RtpCapabilities::ToJson() const
...@@ -155,23 +155,20 @@ namespace RTC ...@@ -155,23 +155,20 @@ namespace RTC
this->fecMechanisms = updatedFecMechanisms; this->fecMechanisms = updatedFecMechanisms;
} }
inline void RtpCapabilities::ValidateCodecs(RTC::Scope scope) inline void RtpCapabilities::ValidateCodecs()
{ {
MS_TRACE(); MS_TRACE();
if (scope == RTC::Scope::PEER_CAPABILITY) // Payload types must be unique.
{
// Payload types must be unique.
std::unordered_set<uint8_t> payloadTypes; std::unordered_set<uint8_t> payloadTypes;
for (auto& codec : this->codecs) for (auto& codec : this->codecs)
{ {
if (payloadTypes.find(codec.payloadType) != payloadTypes.end()) if (payloadTypes.find(codec.payloadType) != payloadTypes.end())
MS_THROW_ERROR("duplicated codec.payloadType"); MS_THROW_ERROR("duplicated codec.payloadType");
else else
payloadTypes.insert(codec.payloadType); payloadTypes.insert(codec.payloadType);
}
} }
} }
} // namespace RTC } // namespace RTC
#define MS_CLASS "RTC::RtpCodecCapability"
// #define MS_LOG_DEV
#include "Logger.hpp"
#include "MediaSoupError.hpp"
#include "RTC/RtpDictionaries.hpp"
namespace RTC
{
/* Instance methods. */
RtpCodecCapability::RtpCodecCapability(Json::Value& data)
{
MS_TRACE();
static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringMimeType{ "mimeType" };
static const Json::StaticString JsonStringPayloadType{ "payloadType" };
static const Json::StaticString JsonStringClockRate{ "clockRate" };
static const Json::StaticString JsonStringMaxptime{ "maxptime" };
static const Json::StaticString JsonStringPtime{ "ptime" };
static const Json::StaticString JsonStringNumChannels{ "channels" };
static const Json::StaticString JsonStringParameters{ "parameters" };
static const Json::StaticString JsonStringRtcpFeedback{ "rtcpFeedback" };
if (!data.isObject())
MS_THROW_ERROR("RtpCodecCapability is not an object");
// `kind` is mandatory.
if (!data[JsonStringKind].isString())
MS_THROW_ERROR("missing RtpCodecCapability.kind");
std::string kind = data[JsonStringKind].asString();
// NOTE: This may throw.
this->kind = RTC::Media::GetKind(kind);
// `mimeType` is mandatory.
if (!data[JsonStringMimeType].isString())
MS_THROW_ERROR("missing RtpCodec.mimeType");
std::string mimeType = data[JsonStringMimeType].asString();
// Set MIME field.
// NOTE: This may throw.
this->mime.SetMimeType(mimeType);
if (!data[JsonStringPayloadType].isUInt())
MS_THROW_ERROR("missing RtpCodecCapability.payloadType");
this->payloadType = static_cast<uint8_t>(data[JsonStringPayloadType].asUInt());
// `clockRate` is mandatory.
if (!data[JsonStringClockRate].isUInt())
MS_THROW_ERROR("missing RtpCodecCapability.clockRate");
this->clockRate = uint32_t{ data[JsonStringClockRate].asUInt() };
// `maxptime` is optional.
if (data[JsonStringMaxptime].isUInt())
this->maxptime = uint32_t{ data[JsonStringMaxptime].asUInt() };
// `ptime` is optional.
if (data[JsonStringPtime].isUInt())
this->ptime = uint32_t{ data[JsonStringPtime].asUInt() };
// `channels` is optional.
if (data[JsonStringNumChannels].isUInt())
this->channels = uint32_t{ data[JsonStringNumChannels].asUInt() };
// `parameters` is optional.
if (data[JsonStringParameters].isObject())
this->parameters.Set(data[JsonStringParameters]);
// `rtcpFeedback` is optional.
if (data[JsonStringRtcpFeedback].isArray())
{
auto& jsonRtcpFeedback = data[JsonStringRtcpFeedback];
for (auto& i : jsonRtcpFeedback)
{
RTC::RtcpFeedback rtcpFeedback(i);
// Append to the rtcpFeedback vector.
this->rtcpFeedback.push_back(rtcpFeedback);
}
}
// Check codec.
CheckCodec();
}
Json::Value RtpCodecCapability::ToJson() const
{
MS_TRACE();
static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringMimeType{ "mimeType" };
static const Json::StaticString JsonStringName{ "name" };
static const Json::StaticString JsonStringPayloadType{ "payloadType" };
static const Json::StaticString JsonStringClockRate{ "clockRate" };
static const Json::StaticString JsonStringMaxptime{ "maxptime" };
static const Json::StaticString JsonStringPtime{ "ptime" };
static const Json::StaticString JsonStringNumChannels{ "channels" };
static const Json::StaticString JsonStringParameters{ "parameters" };
static const Json::StaticString JsonStringRtcpFeedback{ "rtcpFeedback" };
Json::Value json(Json::objectValue);
// Add `kind`.
json[JsonStringKind] = RTC::Media::GetJsonString(this->kind);
// Add `mimeType`.
json[JsonStringMimeType] = this->mime.ToString();
// Add `name`.
json[JsonStringName] = this->mime.GetName();
// Add `payloadType`.
json[JsonStringPayloadType] = Json::UInt{ this->payloadType };
// Add `clockRate`.
json[JsonStringClockRate] = Json::UInt{ this->clockRate };
// Add `maxptime`.
if (this->maxptime != 0u)
json[JsonStringMaxptime] = Json::UInt{ this->maxptime };
// Add `ptime`.
if (this->ptime != 0u)
json[JsonStringPtime] = Json::UInt{ this->ptime };
// Add `channels`.
if (this->channels > 1)
json[JsonStringNumChannels] = Json::UInt{ this->channels };
// Add `parameters`.
json[JsonStringParameters] = this->parameters.ToJson();
// Add `rtcpFeedback`.
json[JsonStringRtcpFeedback] = Json::arrayValue;
for (auto& entry : this->rtcpFeedback)
{
json[JsonStringRtcpFeedback].append(entry.ToJson());
}
return json;
}
bool RtpCodecCapability::Matches(RtpCodecCapability& codec, bool checkPayloadType)
{
MS_TRACE();
static std::string jsonStringPacketizationMode{ "packetizationMode" };
// MIME must match.
if (this->mime != codec.mime)
return false;
if (checkPayloadType)
{
if (this->payloadType != codec.payloadType)
return false;
}
// Clock rate must match.
if (this->clockRate != codec.clockRate)
return false;
// Per kind checks.
switch (this->kind)
{
case RTC::Media::Kind::AUDIO:
{
// Num channels must match.
if (this->channels != codec.channels)
return false;
break;
}
default:;
}
// Per MIME checks.
switch (this->mime.subtype)
{
case RTC::RtpCodecMimeType::Subtype::H264:
{
int32_t packetizationMode = this->parameters.GetInteger(jsonStringPacketizationMode);
int32_t givenPacketizationMode = codec.parameters.GetInteger(jsonStringPacketizationMode);
if (packetizationMode != givenPacketizationMode)
return false;
break;
}
default:;
}
return true;
}
void RtpCodecCapability::ReduceRtcpFeedback(std::vector<RTC::RtcpFeedback>& supportedRtcpFeedback)
{
MS_TRACE();
std::vector<RTC::RtcpFeedback> updatedRtcpFeedback;
for (auto& rtcpFeedbackItem : this->rtcpFeedback)
{
for (auto& supportedRtcpFeedbackItem : supportedRtcpFeedback)
{
if (rtcpFeedbackItem.type == supportedRtcpFeedbackItem.type &&
rtcpFeedbackItem.parameter == supportedRtcpFeedbackItem.parameter)
{
updatedRtcpFeedback.push_back(supportedRtcpFeedbackItem);
break;
}
}
}
this->rtcpFeedback = updatedRtcpFeedback;
}
inline void RtpCodecCapability::CheckCodec()
{
MS_TRACE();
static std::string jsonStringApt{ "apt" };
static std::string jsonStringPacketizationMode{ "packetizationMode" };
// Check per MIME parameters and set default values.
switch (this->mime.subtype)
{
case RTC::RtpCodecMimeType::Subtype::RTX:
{
// A RTX codec must have 'apt' parameter.
if (!this->parameters.HasInteger(jsonStringApt))
MS_THROW_ERROR("missing apt parameter in RTX RtpCodecCapability");
break;
}
case RTC::RtpCodecMimeType::Subtype::OPUS:
{
// Opus default channels is 2.
if (this->channels < 2)
this->channels = 2;
break;
}
case RTC::RtpCodecMimeType::Subtype::H264:
{
// H264 default packetizationMode is 0.
if (!this->parameters.HasInteger(jsonStringPacketizationMode))
this->parameters.SetInteger(jsonStringPacketizationMode, 0);
break;
}
default:;
}
}
} // namespace RTC
#define MS_CLASS "RTC::RtpCodecMime"
// #define MS_LOG_DEV
#include "Logger.hpp"
#include "MediaSoupError.hpp"
#include "Utils.hpp"
#include "RTC/RtpDictionaries.hpp"
namespace RTC
{
/* Class variables. */
// clang-format off
std::unordered_map<std::string, RtpCodecMime::Type> RtpCodecMime::string2Type =
{
{ "audio", RtpCodecMime::Type::AUDIO },
{ "video", RtpCodecMime::Type::VIDEO }
};
std::map<RtpCodecMime::Type, std::string> RtpCodecMime::type2String =
{
{ RtpCodecMime::Type::AUDIO, "audio" },
{ RtpCodecMime::Type::VIDEO, "video" }
};
std::unordered_map<std::string, RtpCodecMime::Subtype> RtpCodecMime::string2Subtype =
{
// Audio codecs:
{ "opus", RtpCodecMime::Subtype::OPUS },
{ "pcma", RtpCodecMime::Subtype::PCMA },
{ "pcmu", RtpCodecMime::Subtype::PCMU },
{ "isac", RtpCodecMime::Subtype::ISAC },
{ "g722", RtpCodecMime::Subtype::G722 },
{ "ilbc", RtpCodecMime::Subtype::ILBC },
{ "silk", RtpCodecMime::Subtype::SILK },
// Video codecs:
{ "vp8", RtpCodecMime::Subtype::VP8 },
{ "vp9", RtpCodecMime::Subtype::VP9 },
{ "h264", RtpCodecMime::Subtype::H264 },
{ "x-h264uc", RtpCodecMime::Subtype::X_H264UC },
{ "h265", RtpCodecMime::Subtype::H265 },
// Complementary codecs:
{ "cn", RtpCodecMime::Subtype::CN },
{ "telephone-event", RtpCodecMime::Subtype::TELEPHONE_EVENT },
// Feature codecs:
{ "rtx", RtpCodecMime::Subtype::RTX },
{ "ulpfec", RtpCodecMime::Subtype::ULPFEC },
{ "flexfec", RtpCodecMime::Subtype::FLEXFEC },
{ "x-ulpfecuc", RtpCodecMime::Subtype::X_ULPFECUC },
{ "red", RtpCodecMime::Subtype::RED }
};
std::map<RtpCodecMime::Subtype, std::string> RtpCodecMime::subtype2String =
{
// Audio codecs:
{ RtpCodecMime::Subtype::OPUS, "opus" },
{ RtpCodecMime::Subtype::PCMA, "PCMA" },
{ RtpCodecMime::Subtype::PCMU, "PCMU" },
{ RtpCodecMime::Subtype::ISAC, "ISAC" },
{ RtpCodecMime::Subtype::G722, "G722" },
{ RtpCodecMime::Subtype::ILBC, "iLBC" },
{ RtpCodecMime::Subtype::SILK, "SILK" },
// Video codecs:
{ RtpCodecMime::Subtype::VP8, "VP8" },
{ RtpCodecMime::Subtype::VP9, "VP9" },
{ RtpCodecMime::Subtype::H264, "H264" },
{ RtpCodecMime::Subtype::X_H264UC, "X-H264UC" },
{ RtpCodecMime::Subtype::H265, "H265" },
// Complementary codecs:
{ RtpCodecMime::Subtype::CN, "CN" },
{ RtpCodecMime::Subtype::TELEPHONE_EVENT, "telephone-event" },
// Feature codecs:
{ RtpCodecMime::Subtype::RTX, "rtx" },
{ RtpCodecMime::Subtype::ULPFEC, "ulpfec" },
{ RtpCodecMime::Subtype::FLEXFEC, "flexfec" },
{ RtpCodecMime::Subtype::X_ULPFECUC, "x-ulpfecuc" },
{ RtpCodecMime::Subtype::RED, "red" }
};
// clang-format on
/* Instance methods. */
void RtpCodecMime::SetName(const std::string& name)
{
MS_TRACE();
auto slashPos = name.find('/');
if (slashPos == std::string::npos || slashPos == 0 || slashPos == name.length() - 1)
MS_THROW_ERROR("wrong codec MIME");
std::string type = name.substr(0, slashPos);
std::string subtype = name.substr(slashPos + 1);
// Force lowcase names.
Utils::String::ToLowerCase(type);
Utils::String::ToLowerCase(subtype);
// Set MIME type.
{
auto it = RtpCodecMime::string2Type.find(type);
if (it != RtpCodecMime::string2Type.end())
this->type = it->second;
else
MS_THROW_ERROR("unknown codec MIME type '%s'", type.c_str());
}
// Set MIME subtype.
{
auto it = RtpCodecMime::string2Subtype.find(subtype);
if (it != RtpCodecMime::string2Subtype.end())
this->subtype = it->second;
else
MS_THROW_ERROR("unknown codec MIME subtype '%s'", subtype.c_str());
}
// Set name.
this->name = type2String[this->type] + "/" + subtype2String[this->subtype];
}
} // namespace RTC
#define MS_CLASS "RTC::RtpCodecMimeType"
// #define MS_LOG_DEV
#include "Logger.hpp"
#include "MediaSoupError.hpp"
#include "Utils.hpp"
#include "RTC/RtpDictionaries.hpp"
namespace RTC
{
/* Class variables. */
// clang-format off
std::unordered_map<std::string, RtpCodecMimeType::Type> RtpCodecMimeType::string2Type =
{
{ "audio", RtpCodecMimeType::Type::AUDIO },
{ "video", RtpCodecMimeType::Type::VIDEO }
};
std::map<RtpCodecMimeType::Type, std::string> RtpCodecMimeType::type2String =
{
{ RtpCodecMimeType::Type::AUDIO, "audio" },
{ RtpCodecMimeType::Type::VIDEO, "video" }
};
std::unordered_map<std::string, RtpCodecMimeType::Subtype> RtpCodecMimeType::string2Subtype =
{
// Audio codecs:
{ "opus", RtpCodecMimeType::Subtype::OPUS },
{ "pcma", RtpCodecMimeType::Subtype::PCMA },
{ "pcmu", RtpCodecMimeType::Subtype::PCMU },
{ "isac", RtpCodecMimeType::Subtype::ISAC },
{ "g722", RtpCodecMimeType::Subtype::G722 },
{ "ilbc", RtpCodecMimeType::Subtype::ILBC },
{ "silk", RtpCodecMimeType::Subtype::SILK },
// Video codecs:
{ "vp8", RtpCodecMimeType::Subtype::VP8 },
{ "vp9", RtpCodecMimeType::Subtype::VP9 },
{ "h264", RtpCodecMimeType::Subtype::H264 },
{ "x-h264uc", RtpCodecMimeType::Subtype::X_H264UC },
{ "h265", RtpCodecMimeType::Subtype::H265 },
// Complementary codecs:
{ "cn", RtpCodecMimeType::Subtype::CN },
{ "telephone-event", RtpCodecMimeType::Subtype::TELEPHONE_EVENT },
// Feature codecs:
{ "rtx", RtpCodecMimeType::Subtype::RTX },
{ "ulpfec", RtpCodecMimeType::Subtype::ULPFEC },
{ "flexfec", RtpCodecMimeType::Subtype::FLEXFEC },
{ "x-ulpfecuc", RtpCodecMimeType::Subtype::X_ULPFECUC },
{ "red", RtpCodecMimeType::Subtype::RED }
};
std::map<RtpCodecMimeType::Subtype, std::string> RtpCodecMimeType::subtype2String =
{
// Audio codecs:
{ RtpCodecMimeType::Subtype::OPUS, "opus" },
{ RtpCodecMimeType::Subtype::PCMA, "PCMA" },
{ RtpCodecMimeType::Subtype::PCMU, "PCMU" },
{ RtpCodecMimeType::Subtype::ISAC, "ISAC" },
{ RtpCodecMimeType::Subtype::G722, "G722" },
{ RtpCodecMimeType::Subtype::ILBC, "iLBC" },
{ RtpCodecMimeType::Subtype::SILK, "SILK" },
// Video codecs:
{ RtpCodecMimeType::Subtype::VP8, "VP8" },
{ RtpCodecMimeType::Subtype::VP9, "VP9" },
{ RtpCodecMimeType::Subtype::H264, "H264" },
{ RtpCodecMimeType::Subtype::X_H264UC, "X-H264UC" },
{ RtpCodecMimeType::Subtype::H265, "H265" },
// Complementary codecs:
{ RtpCodecMimeType::Subtype::CN, "CN" },
{ RtpCodecMimeType::Subtype::TELEPHONE_EVENT, "telephone-event" },
// Feature codecs:
{ RtpCodecMimeType::Subtype::RTX, "rtx" },
{ RtpCodecMimeType::Subtype::ULPFEC, "ulpfec" },
{ RtpCodecMimeType::Subtype::FLEXFEC, "flexfec" },
{ RtpCodecMimeType::Subtype::X_ULPFECUC, "x-ulpfecuc" },
{ RtpCodecMimeType::Subtype::RED, "red" }
};
// clang-format on
/* Instance methods. */
void RtpCodecMimeType::SetMimeType(const std::string& mimeType)
{
MS_TRACE();
auto slashPos = mimeType.find('/');
if (
slashPos == std::string::npos ||
slashPos == 0 || slashPos == mimeType.length() - 1)
{
MS_THROW_ERROR("wrong codec MIME");
}
std::string type = mimeType.substr(0, slashPos);
std::string subtype = mimeType.substr(slashPos + 1);
// Force lowcase names.
Utils::String::ToLowerCase(type);
Utils::String::ToLowerCase(subtype);
// Set MIME type.
{
auto it = RtpCodecMimeType::string2Type.find(type);
if (it != RtpCodecMimeType::string2Type.end())
this->type = it->second;
else
MS_THROW_ERROR("unknown codec MIME type '%s'", type.c_str());
}
// Set MIME subtype.
{
auto it = RtpCodecMimeType::string2Subtype.find(subtype);
if (it != RtpCodecMimeType::string2Subtype.end())
this->subtype = it->second;
else
MS_THROW_ERROR("unknown codec MIME subtype '%s'", subtype.c_str());
}
// Set mimeType and name.
this->mimeType = type2String[this->type] + "/" + subtype2String[this->subtype];
this->name = subtype;
}
} // namespace RTC
...@@ -9,65 +9,46 @@ namespace RTC ...@@ -9,65 +9,46 @@ namespace RTC
{ {
/* Instance methods. */ /* Instance methods. */
RtpCodecParameters::RtpCodecParameters(Json::Value& data, RTC::Scope scope) : scope(scope) RtpCodecParameters::RtpCodecParameters(Json::Value& data)
{ {
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringKind{ "kind" }; static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringName{ "name" }; static const Json::StaticString JsonStringMimeType{ "mimeType" };
static const Json::StaticString JsonStringPayloadType{ "payloadType" }; static const Json::StaticString JsonStringPayloadType{ "payloadType" };
static const Json::StaticString JsonStringClockRate{ "clockRate" }; static const Json::StaticString JsonStringClockRate{ "clockRate" };
static const Json::StaticString JsonStringMaxptime{ "maxptime" }; static const Json::StaticString JsonStringMaxptime{ "maxptime" };
static const Json::StaticString JsonStringPtime{ "ptime" }; static const Json::StaticString JsonStringPtime{ "ptime" };
static const Json::StaticString JsonStringNumChannels{ "numChannels" }; static const Json::StaticString JsonStringNumChannels{ "channels" };
static const Json::StaticString JsonStringParameters{ "parameters" }; static const Json::StaticString JsonStringParameters{ "parameters" };
static const Json::StaticString JsonStringRtcpFeedback{ "rtcpFeedback" }; static const Json::StaticString JsonStringRtcpFeedback{ "rtcpFeedback" };
if (!data.isObject()) if (!data.isObject())
MS_THROW_ERROR("RtpCodecParameters is not an object"); MS_THROW_ERROR("RtpCodecParameters is not an object");
if (this->scope == RTC::Scope::ROOM_CAPABILITY || this->scope == RTC::Scope::PEER_CAPABILITY) // `kind` is mandatory.
{ if (!data[JsonStringKind].isString())
// `kind` is mandatory. MS_THROW_ERROR("missing RtpCodecParameters.kind");
if (!data[JsonStringKind].isString())
MS_THROW_ERROR("missing RtpCodecParameters.kind");
std::string kind = data[JsonStringKind].asString(); std::string kind = data[JsonStringKind].asString();
// NOTE: This may throw. // NOTE: This may throw.
this->kind = RTC::Media::GetKind(kind); this->kind = RTC::Media::GetKind(kind);
}
// `name` is mandatory. // `mimeType` is mandatory.
if (!data[JsonStringName].isString()) if (!data[JsonStringMimeType].isString())
MS_THROW_ERROR("missing RtpCodec.name"); MS_THROW_ERROR("missing RtpCodec.mimeType");
std::string name = data[JsonStringName].asString(); std::string mimeType = data[JsonStringMimeType].asString();
// Set MIME field. // Set MIME field.
// NOTE: This may throw. // NOTE: This may throw.
this->mime.SetName(name); this->mime.SetMimeType(mimeType);
if (data[JsonStringPayloadType].isUInt()) if (!data[JsonStringPayloadType].isUInt())
{ MS_THROW_ERROR("missing RtpCodecParameters.payloadType");
this->payloadType = static_cast<uint8_t>(data[JsonStringPayloadType].asUInt());
this->hasPayloadType = true;
}
if (this->scope == RTC::Scope::PEER_CAPABILITY) this->payloadType = static_cast<uint8_t>(data[JsonStringPayloadType].asUInt());
{
if (!this->hasPayloadType)
MS_THROW_ERROR("missing RtpCodecParameters.payloadType");
}
if (this->scope == RTC::Scope::RECEIVE)
{
if (!data[JsonStringPayloadType].isUInt())
MS_THROW_ERROR("missing RtpCodecParameters.payloadType");
this->payloadType = static_cast<uint8_t>(data[JsonStringPayloadType].asUInt());
this->hasPayloadType = true;
}
// `clockRate` is mandatory. // `clockRate` is mandatory.
if (!data[JsonStringClockRate].isUInt()) if (!data[JsonStringClockRate].isUInt())
...@@ -83,9 +64,9 @@ namespace RTC ...@@ -83,9 +64,9 @@ namespace RTC
if (data[JsonStringPtime].isUInt()) if (data[JsonStringPtime].isUInt())
this->ptime = uint32_t{ data[JsonStringPtime].asUInt() }; this->ptime = uint32_t{ data[JsonStringPtime].asUInt() };
// `numChannels` is optional. // `channels` is optional.
if (data[JsonStringNumChannels].isUInt()) if (data[JsonStringNumChannels].isUInt())
this->numChannels = uint32_t{ data[JsonStringNumChannels].asUInt() }; this->channels = uint32_t{ data[JsonStringNumChannels].asUInt() };
// `parameters` is optional. // `parameters` is optional.
if (data[JsonStringParameters].isObject()) if (data[JsonStringParameters].isObject())
...@@ -114,31 +95,29 @@ namespace RTC ...@@ -114,31 +95,29 @@ namespace RTC
MS_TRACE(); MS_TRACE();
static const Json::StaticString JsonStringKind{ "kind" }; static const Json::StaticString JsonStringKind{ "kind" };
static const Json::StaticString JsonStringMimeType{ "mimeType" };
static const Json::StaticString JsonStringName{ "name" }; static const Json::StaticString JsonStringName{ "name" };
static const Json::StaticString JsonStringPayloadType{ "payloadType" }; static const Json::StaticString JsonStringPayloadType{ "payloadType" };
static const Json::StaticString JsonStringClockRate{ "clockRate" }; static const Json::StaticString JsonStringClockRate{ "clockRate" };
static const Json::StaticString JsonStringMaxptime{ "maxptime" }; static const Json::StaticString JsonStringMaxptime{ "maxptime" };
static const Json::StaticString JsonStringPtime{ "ptime" }; static const Json::StaticString JsonStringPtime{ "ptime" };
static const Json::StaticString JsonStringNumChannels{ "numChannels" }; static const Json::StaticString JsonStringNumChannels{ "channels" };
static const Json::StaticString JsonStringParameters{ "parameters" }; static const Json::StaticString JsonStringParameters{ "parameters" };
static const Json::StaticString JsonStringRtcpFeedback{ "rtcpFeedback" }; static const Json::StaticString JsonStringRtcpFeedback{ "rtcpFeedback" };
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
if (this->scope == RTC::Scope::ROOM_CAPABILITY || this->scope == RTC::Scope::PEER_CAPABILITY) // Add `kind`.
{ json[JsonStringKind] = RTC::Media::GetJsonString(this->kind);
// Add `kind`.
json[JsonStringKind] = RTC::Media::GetJsonString(this->kind); // Add `mimeType`.
} json[JsonStringMimeType] = this->mime.ToString();
// Add `name`. // Add `name`.
json[JsonStringName] = this->mime.GetName(); json[JsonStringName] = this->mime.GetName();
if (this->hasPayloadType) // Add `payloadType`.
{ json[JsonStringPayloadType] = Json::UInt{ this->payloadType };
// Add `payloadType`.
json[JsonStringPayloadType] = Json::UInt{ this->payloadType };
}
// Add `clockRate`. // Add `clockRate`.
json[JsonStringClockRate] = Json::UInt{ this->clockRate }; json[JsonStringClockRate] = Json::UInt{ this->clockRate };
...@@ -151,9 +130,9 @@ namespace RTC ...@@ -151,9 +130,9 @@ namespace RTC
if (this->ptime != 0u) if (this->ptime != 0u)
json[JsonStringPtime] = Json::UInt{ this->ptime }; json[JsonStringPtime] = Json::UInt{ this->ptime };
// Add `numChannels`. // Add `channels`.
if (this->numChannels > 1) if (this->channels > 1)
json[JsonStringNumChannels] = Json::UInt{ this->numChannels }; json[JsonStringNumChannels] = Json::UInt{ this->channels };
// Add `parameters`. // Add `parameters`.
json[JsonStringParameters] = this->parameters.ToJson(); json[JsonStringParameters] = this->parameters.ToJson();
...@@ -195,7 +174,7 @@ namespace RTC ...@@ -195,7 +174,7 @@ namespace RTC
case RTC::Media::Kind::AUDIO: case RTC::Media::Kind::AUDIO:
{ {
// Num channels must match. // Num channels must match.
if (this->numChannels != codec.numChannels) if (this->channels != codec.channels)
return false; return false;
break; break;
...@@ -207,7 +186,7 @@ namespace RTC ...@@ -207,7 +186,7 @@ namespace RTC
// Per MIME checks. // Per MIME checks.
switch (this->mime.subtype) switch (this->mime.subtype)
{ {
case RTC::RtpCodecMime::Subtype::H264: case RTC::RtpCodecMimeType::Subtype::H264:
{ {
int32_t packetizationMode = this->parameters.GetInteger(jsonStringPacketizationMode); int32_t packetizationMode = this->parameters.GetInteger(jsonStringPacketizationMode);
int32_t givenPacketizationMode = codec.parameters.GetInteger(jsonStringPacketizationMode); int32_t givenPacketizationMode = codec.parameters.GetInteger(jsonStringPacketizationMode);
...@@ -257,7 +236,7 @@ namespace RTC ...@@ -257,7 +236,7 @@ namespace RTC
// Check per MIME parameters and set default values. // Check per MIME parameters and set default values.
switch (this->mime.subtype) switch (this->mime.subtype)
{ {
case RTC::RtpCodecMime::Subtype::RTX: case RTC::RtpCodecMimeType::Subtype::RTX:
{ {
// A RTX codec must have 'apt' parameter. // A RTX codec must have 'apt' parameter.
if (!this->parameters.HasInteger(jsonStringApt)) if (!this->parameters.HasInteger(jsonStringApt))
...@@ -266,16 +245,16 @@ namespace RTC ...@@ -266,16 +245,16 @@ namespace RTC
break; break;
} }
case RTC::RtpCodecMime::Subtype::OPUS: case RTC::RtpCodecMimeType::Subtype::OPUS:
{ {
// Opus default numChannels is 2. // Opus default channels is 2.
if (this->numChannels < 2) if (this->channels < 2)
this->numChannels = 2; this->channels = 2;
break; break;
} }
case RTC::RtpCodecMime::Subtype::H264: case RTC::RtpCodecMimeType::Subtype::H264:
{ {
// H264 default packetizationMode is 0. // H264 default packetizationMode is 0.
if (!this->parameters.HasInteger(jsonStringPacketizationMode)) if (!this->parameters.HasInteger(jsonStringPacketizationMode))
......
...@@ -37,7 +37,7 @@ namespace RTC ...@@ -37,7 +37,7 @@ namespace RTC
for (auto& jsonCodec : jsonCodecs) for (auto& jsonCodec : jsonCodecs)
{ {
RTC::RtpCodecParameters codec(jsonCodec, RTC::Scope::RECEIVE); RTC::RtpCodecParameters codec(jsonCodec);
// Append to the codecs vector. // Append to the codecs vector.
this->codecs.push_back(codec); this->codecs.push_back(codec);
...@@ -184,7 +184,7 @@ namespace RTC ...@@ -184,7 +184,7 @@ namespace RTC
MS_WARN_DEV( MS_WARN_DEV(
"no matching peer codec capability found [payloadType:%" PRIu8 ", mime:%s]", "no matching peer codec capability found [payloadType:%" PRIu8 ", mime:%s]",
codec.payloadType, codec.payloadType,
codec.mime.GetName().c_str()); codec.mime.ToString().c_str());
removedCodecPayloadTypes.push_back(codec.payloadType); removedCodecPayloadTypes.push_back(codec.payloadType);
it = this->codecs.erase(it); it = this->codecs.erase(it);
...@@ -317,7 +317,7 @@ namespace RTC ...@@ -317,7 +317,7 @@ namespace RTC
switch (codec.mime.subtype) switch (codec.mime.subtype)
{ {
// A RTX codec must have 'apt' parameter pointing to a non RTX codec. // A RTX codec must have 'apt' parameter pointing to a non RTX codec.
case RTC::RtpCodecMime::Subtype::RTX: case RTC::RtpCodecMimeType::Subtype::RTX:
{ {
// NOTE: RtpCodecParameters already asserted that there is 'apt' parameter. // NOTE: RtpCodecParameters already asserted that there is 'apt' parameter.
int32_t apt = codec.parameters.GetInteger(jsonStringApt); int32_t apt = codec.parameters.GetInteger(jsonStringApt);
...@@ -329,11 +329,11 @@ namespace RTC ...@@ -329,11 +329,11 @@ namespace RTC
if (static_cast<int32_t>(codec.payloadType) == apt) if (static_cast<int32_t>(codec.payloadType) == apt)
{ {
if (codec.mime.subtype == RTC::RtpCodecMime::Subtype::RTX) if (codec.mime.subtype == RTC::RtpCodecMimeType::Subtype::RTX)
MS_THROW_ERROR("apt in RTX codec points to a RTX codec"); MS_THROW_ERROR("apt in RTX codec points to a RTX codec");
else if (codec.mime.subtype == RTC::RtpCodecMime::Subtype::ULPFEC) else if (codec.mime.subtype == RTC::RtpCodecMimeType::Subtype::ULPFEC)
MS_THROW_ERROR("apt in RTX codec points to a ULPFEC codec"); MS_THROW_ERROR("apt in RTX codec points to a ULPFEC codec");
else if (codec.mime.subtype == RTC::RtpCodecMime::Subtype::FLEXFEC) else if (codec.mime.subtype == RTC::RtpCodecMimeType::Subtype::FLEXFEC)
MS_THROW_ERROR("apt in RTX codec points to a FLEXFEC codec"); MS_THROW_ERROR("apt in RTX codec points to a FLEXFEC codec");
else else
break; break;
......
...@@ -187,7 +187,7 @@ namespace RTC ...@@ -187,7 +187,7 @@ namespace RTC
json[JsonStringSsrc] = Json::UInt{ this->ssrc }; json[JsonStringSsrc] = Json::UInt{ this->ssrc };
json[JsonStringPayloadType] = Json::UInt{ this->payloadType }; json[JsonStringPayloadType] = Json::UInt{ this->payloadType };
json[JsonStringMime] = this->mime.name; json[JsonStringMime] = this->mime.ToString();
json[JsonStringClockRate] = Json::UInt{ this->clockRate }; json[JsonStringClockRate] = Json::UInt{ this->clockRate };
json[JsonStringUseNack] = this->useNack; json[JsonStringUseNack] = this->useNack;
json[JsonStringUsePli] = this->usePli; json[JsonStringUsePli] = this->usePli;
......
...@@ -226,7 +226,7 @@ namespace RTC ...@@ -226,7 +226,7 @@ namespace RTC
this->nackGenerator.reset(new RTC::NackGenerator(this)); this->nackGenerator.reset(new RTC::NackGenerator(this));
// Request a full frame so dropped video packets don't cause lag. // Request a full frame so dropped video packets don't cause lag.
if (this->params.mime.type == RTC::RtpCodecMime::Type::VIDEO) if (this->params.mime.type == RTC::RtpCodecMimeType::Type::VIDEO)
{ {
MS_DEBUG_TAG(rtx, "stream initialized, triggering PLI [ssrc:%" PRIu32 "]", this->params.ssrc); MS_DEBUG_TAG(rtx, "stream initialized, triggering PLI [ssrc:%" PRIu32 "]", this->params.ssrc);
......
...@@ -118,7 +118,6 @@ void init() ...@@ -118,7 +118,6 @@ void init()
RTC::TcpServer::ClassInit(); RTC::TcpServer::ClassInit();
RTC::DtlsTransport::ClassInit(); RTC::DtlsTransport::ClassInit();
RTC::SrtpSession::ClassInit(); RTC::SrtpSession::ClassInit();
RTC::Room::ClassInit();
} }
void ignoreSignals() void ignoreSignals()
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论