提交 2787bb82 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Add RtpCapabilities and impove RtpParameters

上级 ea2366c0
'use strict';
/**
* This file is not used by the JavaScript engine, but copied into the C++
* source code once JSONized by gulp.
*/
let defaultRtpCapabilities =
{
codecs :
[
{
kind : 'audio',
name : 'audio/opus',
preferredPayloadType : 100,
clockRate : 90000,
rtcpFeedback :
[
{ type: 'ccm', parameter: 'fir' },
{ type: 'nack', parameter: '' },
{ type: 'nack', parameter: 'pli' },
{ type: 'google-remb', parameter: '' }
]
}
]
};
module.exports = defaultRtpCapabilities;
...@@ -4,6 +4,8 @@ const gulp = require('gulp'); ...@@ -4,6 +4,8 @@ const gulp = require('gulp');
const jshint = require('gulp-jshint'); const jshint = require('gulp-jshint');
const jscs = require('gulp-jscs'); const jscs = require('gulp-jscs');
const stylish = require('gulp-jscs-stylish'); const stylish = require('gulp-jscs-stylish');
const replace = require('gulp-replace');
const touch = require('gulp-touch');
const shell = require('gulp-shell'); const shell = require('gulp-shell');
let tests = let tests =
...@@ -21,7 +23,7 @@ let tests = ...@@ -21,7 +23,7 @@ let tests =
gulp.task('lint', () => gulp.task('lint', () =>
{ {
let src = [ 'gulpfile.js', 'lib/**/*.js', 'test/**/*.js' ]; let src = [ 'gulpfile.js', 'lib/**/*.js', 'data/**/*.js', 'test/**/*.js' ];
return gulp.src(src) return gulp.src(src)
.pipe(jshint('.jshintrc')) .pipe(jshint('.jshintrc'))
...@@ -31,6 +33,16 @@ gulp.task('lint', () => ...@@ -31,6 +33,16 @@ gulp.task('lint', () =>
.pipe(jshint.reporter('fail')); .pipe(jshint.reporter('fail'));
}); });
gulp.task('capabilities', () =>
{
let capabilities = require('./data/defaultRtpCapabilities');
return gulp.src('worker/src/RTC/Room.cpp')
.pipe(replace(/(std::string capabilities =).*/, `$1 R"(${JSON.stringify(capabilities)})";`))
.pipe(gulp.dest('worker/src/RTC/'))
.pipe(touch());
});
gulp.task('test', shell.task( gulp.task('test', shell.task(
[ `tap --bail --color --reporter=spec ${tests.join(' ')}` ] [ `tap --bail --color --reporter=spec ${tests.join(' ')}` ]
)); ));
...@@ -47,4 +59,4 @@ gulp.task('t', gulp.series('test')); ...@@ -47,4 +59,4 @@ gulp.task('t', gulp.series('test'));
gulp.task('td', gulp.series('test-debug')); gulp.task('td', gulp.series('test-debug'));
gulp.task('default', gulp.series('lint')); gulp.task('default', gulp.series('capabilities', 'lint'));
...@@ -32,7 +32,9 @@ ...@@ -32,7 +32,9 @@
"gulp-jscs": "^3.0.2", "gulp-jscs": "^3.0.2",
"gulp-jscs-stylish": "^1.3.0", "gulp-jscs-stylish": "^1.3.0",
"gulp-jshint": "^2.0.1", "gulp-jshint": "^2.0.1",
"gulp-replace": "^0.5.4",
"gulp-shell": "^0.5.2", "gulp-shell": "^0.5.2",
"gulp-touch": "^1.0.1",
"jshint": "^2.9.1", "jshint": "^2.9.1",
"jshint-stylish": "^2.2.0", "jshint-stylish": "^2.2.0",
"tap": "^5.7.2" "tap": "^5.7.2"
......
...@@ -128,7 +128,7 @@ tap.test('rtpReceiver.receive() with full rtpParameters must succeed', { timeout ...@@ -128,7 +128,7 @@ tap.test('rtpReceiver.receive() with full rtpParameters must succeed', { timeout
codecs : codecs :
[ [
{ {
name : 'video/H264', name : 'video/VP9',
payloadType : 100, payloadType : 100,
clockRate : 90000, clockRate : 90000,
maxptime : 80, maxptime : 80,
...@@ -145,6 +145,7 @@ tap.test('rtpReceiver.receive() with full rtpParameters must succeed', { timeout ...@@ -145,6 +145,7 @@ tap.test('rtpReceiver.receive() with full rtpParameters must succeed', { timeout
{ {
profileLevelId : 2, profileLevelId : 2,
packetizationMode : 1, packetizationMode : 1,
aaa : 1.0,
foo : 'barœæ€', foo : 'barœæ€',
bar : true, bar : true,
baz : -123, baz : -123,
...@@ -166,7 +167,7 @@ tap.test('rtpReceiver.receive() with full rtpParameters must succeed', { timeout ...@@ -166,7 +167,7 @@ tap.test('rtpReceiver.receive() with full rtpParameters must succeed', { timeout
{ {
ssrc : 300000 ssrc : 300000
}, },
resolutionScale : 2.2, resolutionScale : 2,
framerateScale : 1.5, framerateScale : 1.5,
maxFramerate : 30, maxFramerate : 30,
active : false, active : false,
...@@ -179,12 +180,14 @@ tap.test('rtpReceiver.receive() with full rtpParameters must succeed', { timeout ...@@ -179,12 +180,14 @@ tap.test('rtpReceiver.receive() with full rtpParameters must succeed', { timeout
{ {
uri : 'urn:ietf:params:rtp-hdrext:foo', uri : 'urn:ietf:params:rtp-hdrext:foo',
id : 1234, id : 1234,
encrypt : false encrypt : false,
parameters : {}
}, },
{ {
uri : 'urn:ietf:params:rtp-hdrext:bar', uri : 'urn:ietf:params:rtp-hdrext:bar',
id : 5678, id : 5678,
encrypt : true encrypt : true,
parameters : {}
}, },
{ {
uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level', uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
...@@ -619,7 +622,7 @@ tap.test('two rtpReceiver.receive() over the same transport sharing PT values mu ...@@ -619,7 +622,7 @@ tap.test('two rtpReceiver.receive() over the same transport sharing PT values mu
codecs : codecs :
[ [
{ {
name : 'audio/ulaw', name : 'audio/PCMU',
payloadType : 101, payloadType : 101,
clockRate : 90000 clockRate : 90000
} }
...@@ -690,7 +693,7 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing ...@@ -690,7 +693,7 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing
payloadType : 100 payloadType : 100
}, },
{ {
name : 'audio/ulaw', name : 'audio/PCMU',
payloadType : 0 payloadType : 0
} }
] ]
...@@ -731,7 +734,7 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing ...@@ -731,7 +734,7 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing
payloadType : 100 payloadType : 100
}, },
{ {
name : 'audio/ulaw', name : 'audio/PCMU',
payloadType : 0 payloadType : 0
} }
], ],
...@@ -782,7 +785,7 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing ...@@ -782,7 +785,7 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing
payloadType : 100 payloadType : 100
}, },
{ {
name : 'audio/ulaw', name : 'audio/PCMU',
payloadType : 0 payloadType : 0
} }
], ],
...@@ -831,7 +834,7 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing ...@@ -831,7 +834,7 @@ tap.test('rtpReceiver.receive() should produce the expected RTP listener routing
payloadType : 100 payloadType : 100
}, },
{ {
name : 'audio/ulaw', name : 'audio/PCMU',
payloadType : 0 payloadType : 0
} }
], ],
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define MS_RTC_ROOM_H #define MS_RTC_ROOM_H
#include "common.h" #include "common.h"
#include "RTC/RtpDictionaries.h"
#include "RTC/Peer.h" #include "RTC/Peer.h"
#include "RTC/RtpReceiver.h" #include "RTC/RtpReceiver.h"
#include "RTC/RtpSender.h" #include "RTC/RtpSender.h"
...@@ -25,6 +26,12 @@ namespace RTC ...@@ -25,6 +26,12 @@ namespace RTC
virtual void onRoomClosed(RTC::Room* room) = 0; virtual void onRoomClosed(RTC::Room* room) = 0;
}; };
public:
static void ClassInit();
private:
static RTC::RtpCapabilities defaultRtpCapabilities;
public: public:
Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId); Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId);
virtual ~Room(); virtual ~Room();
......
...@@ -6,40 +6,114 @@ ...@@ -6,40 +6,114 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <unordered_map> #include <unordered_map>
#include <map>
#include <json/json.h> #include <json/json.h>
namespace RTC namespace RTC
{ {
class RtcpFeedback class Media
{ {
public: public:
RtcpFeedback(Json::Value& data); enum class Kind : uint8_t
virtual ~RtcpFeedback(); {
AUDIO = 1,
Json::Value toJson(); VIDEO,
DEPTH
};
public: public:
std::string type; static Kind GetKind(std::string& str);
std::string parameter; static Json::StaticString& GetJsonString(Kind kind);
private:
static std::unordered_map<std::string, Kind> string2Kind;
static std::map<Kind, Json::StaticString> kind2Json;
}; };
class RtpCodecParameters class RtpCodecMime
{ {
public: public:
enum class Subtype enum class Type : uint8_t
{
UNSET = 0,
AUDIO,
VIDEO
};
public:
enum class Subtype : uint16_t
{ {
MEDIA = 1, UNSET = 0,
RTX, // Audio codecs:
OPUS = 100,
PCMA,
PCMU,
ISAC,
G722,
// Video codecs:
VP8 = 200,
VP9,
H264,
H265,
// Feature codecs:
RTX = 1000,
ULPFEC, ULPFEC,
FLEXFEC, FLEXFEC,
RED, RED,
CN, CN,
DTMF TELEPHONE_EVENT
}; };
private: private:
static std::unordered_map<std::string, RtpCodecParameters::Subtype> string2Subtype; static std::unordered_map<std::string, Type> string2Type;
static std::map<Type, std::string> type2String;
static std::unordered_map<std::string, Subtype> string2Subtype;
static std::map<Subtype, std::string> subtype2String;
public:
RtpCodecMime() {};
virtual ~RtpCodecMime();
void SetName(std::string& name);
std::string& ToString()
{
return this->name;
}
bool IsMediaCodec()
{
return this->subtype >= Subtype::OPUS && this->subtype < Subtype::RTX;
}
bool IsFeatureCodec()
{
return this->subtype >= Subtype::RTX;
}
public:
Type type = Type::UNSET;
Subtype subtype = Subtype::UNSET;
private:
std::string name;
};
class RtcpFeedback
{
public:
RtcpFeedback(Json::Value& data);
virtual ~RtcpFeedback();
Json::Value toJson();
public:
std::string type;
std::string parameter;
};
class RtpCodecParameters
{
public: public:
RtpCodecParameters(Json::Value& data); RtpCodecParameters(Json::Value& data);
virtual ~RtpCodecParameters(); virtual ~RtpCodecParameters();
...@@ -57,7 +131,7 @@ namespace RTC ...@@ -57,7 +131,7 @@ namespace RTC
RTC::CustomParameters parameters; RTC::CustomParameters parameters;
public: public:
Subtype subtype; RtpCodecMime mime;
}; };
class RtpFecParameters class RtpFecParameters
...@@ -168,23 +242,64 @@ namespace RTC ...@@ -168,23 +242,64 @@ namespace RTC
Json::Value userParameters; Json::Value userParameters;
}; };
// class RtpCapabilities class RtpCodecCapability
// { {
// public: public:
// RtpCapabilities() {}; RtpCodecCapability(Json::Value& data);
// RtpCapabilities(Json::Value& data); virtual ~RtpCodecCapability();
// virtual ~RtpCapabilities();
Json::Value toJson();
// Json::Value toJson(); public:
Media::Kind kind;
std::string name;
uint8_t preferredPayloadType = 0;
uint32_t clockRate = 0;
uint32_t maxptime = 0;
uint32_t ptime = 0;
uint32_t numChannels = 0;
std::vector<RtcpFeedback> rtcpFeedback;
RTC::CustomParameters parameters;
uint16_t maxTemporalLayers = 0;
uint16_t maxSpatialLayers = 0;
bool svcMultiStreamSupport = false;
// private: public:
// void ValidateCodecs(); RtpCodecMime mime;
};
// public: class RtpHeaderExtension
// std::vector<RtpCodecCapability> codecs; {
// std::vector<RtpHeaderExtensionCapability> headerExtensions; public:
// std::vector<std::string> fecMechanisms; RtpHeaderExtension(Json::Value& data);
// }; virtual ~RtpHeaderExtension();
Json::Value toJson();
public:
Media::Kind kind;
std::string uri;
uint16_t preferredId = 0;
bool preferredEncrypt = false;
};
class RtpCapabilities
{
public:
RtpCapabilities() {};
RtpCapabilities(Json::Value& data);
virtual ~RtpCapabilities();
Json::Value toJson();
private:
void ValidateCodecs();
public:
std::vector<RtpCodecCapability> codecs;
std::vector<RtpHeaderExtension> headerExtensions;
std::vector<std::string> fecMechanisms;
};
} }
#endif #endif
#ifndef MS_RTC_RTP_KIND_H
#define MS_RTC_RTP_KIND_H
namespace RTC
{
enum class RtpKind
{
AUDIO = 1,
VIDEO
};
}
#endif
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#define MS_RTC_RTP_RECEIVER_H #define MS_RTC_RTP_RECEIVER_H
#include "common.h" #include "common.h"
#include "RTC/RtpKind.h"
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "RTC/RtpPacket.h" #include "RTC/RtpPacket.h"
#include "Channel/Request.h" #include "Channel/Request.h"
...@@ -32,7 +31,7 @@ namespace RTC ...@@ -32,7 +31,7 @@ namespace RTC
}; };
public: public:
RtpReceiver(Listener* listener, Channel::Notifier* notifier, uint32_t rtpReceiverId, std::string& kind); RtpReceiver(Listener* listener, Channel::Notifier* notifier, uint32_t rtpReceiverId, RTC::Media::Kind kind);
virtual ~RtpReceiver(); virtual ~RtpReceiver();
void Close(); void Close();
...@@ -50,8 +49,7 @@ namespace RTC ...@@ -50,8 +49,7 @@ namespace RTC
public: public:
// Passed by argument. // Passed by argument.
uint32_t rtpReceiverId; uint32_t rtpReceiverId;
// Others. RTC::Media::Kind kind;
RTC::RtpKind kind;
private: private:
// Passed by argument. // Passed by argument.
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#define MS_RTC_RTP_SENDER_H #define MS_RTC_RTP_SENDER_H
#include "common.h" #include "common.h"
#include "RTC/RtpKind.h"
#include "RTC/Transport.h" #include "RTC/Transport.h"
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "RTC/RtpPacket.h" #include "RTC/RtpPacket.h"
...@@ -26,7 +25,7 @@ namespace RTC ...@@ -26,7 +25,7 @@ namespace RTC
}; };
public: public:
RtpSender(Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::RtpKind kind); RtpSender(Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::Media::Kind kind);
virtual ~RtpSender(); virtual ~RtpSender();
void Close(); void Close();
...@@ -41,7 +40,7 @@ namespace RTC ...@@ -41,7 +40,7 @@ namespace RTC
public: public:
// Passed by argument. // Passed by argument.
uint32_t rtpSenderId; uint32_t rtpSenderId;
RTC::RtpKind kind; RTC::Media::Kind kind;
private: private:
// Passed by argument. // Passed by argument.
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "common.h" #include "common.h"
#include <string> #include <string>
#include <algorithm> // std::transform()
#include <cstring> // std::memcmp(), std::memcpy() #include <cstring> // std::memcmp(), std::memcpy()
#include <openssl/hmac.h> #include <openssl/hmac.h>
...@@ -257,6 +258,15 @@ namespace Utils ...@@ -257,6 +258,15 @@ namespace Utils
return crc ^ ~0U; return crc ^ ~0U;
} }
class String
{
public:
static void ToLowerCase(std::string& str)
{
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
}
};
} }
#endif #endif
...@@ -44,11 +44,16 @@ ...@@ -44,11 +44,16 @@
'src/RTC/Transport.cpp', 'src/RTC/Transport.cpp',
'src/RTC/TransportTuple.cpp', 'src/RTC/TransportTuple.cpp',
'src/RTC/UdpSocket.cpp', 'src/RTC/UdpSocket.cpp',
'src/RTC/RtpDictionaries/Media.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/RtpCodecCapability.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',
'src/RTC/RtpDictionaries/RtpHeaderExtension.cpp',
'src/RTC/RtpDictionaries/RtpHeaderExtensionParameters.cpp', 'src/RTC/RtpDictionaries/RtpHeaderExtensionParameters.cpp',
'src/RTC/RtpDictionaries/RtpParameters.cpp', 'src/RTC/RtpDictionaries/RtpParameters.cpp',
'src/RTC/RtpDictionaries/RtpRtxParameters.cpp', 'src/RTC/RtpDictionaries/RtpRtxParameters.cpp',
...@@ -83,10 +88,9 @@ ...@@ -83,10 +88,9 @@
'include/RTC/Peer.h', 'include/RTC/Peer.h',
'include/RTC/Room.h', 'include/RTC/Room.h',
'include/RTC/RtcpPacket.h', 'include/RTC/RtcpPacket.h',
'include/RTC/RtpKind.h', 'include/RTC/RtpDictionaries.h',
'include/RTC/RtpListener.h', 'include/RTC/RtpListener.h',
'include/RTC/RtpPacket.h', 'include/RTC/RtpPacket.h',
'include/RTC/RtpDictionaries.h',
'include/RTC/RtpReceiver.h', 'include/RTC/RtpReceiver.h',
'include/RTC/RtpSender.h', 'include/RTC/RtpSender.h',
'include/RTC/SrtpSession.h', 'include/RTC/SrtpSession.h',
......
#define MS_CLASS "RTC::Peer" #define MS_CLASS "RTC::Peer"
#include "RTC/Peer.h" #include "RTC/Peer.h"
#include "RTC/RtpKind.h" #include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
#include "Logger.h" #include "Logger.h"
...@@ -235,7 +235,7 @@ namespace RTC ...@@ -235,7 +235,7 @@ namespace RTC
// Create a RtpReceiver instance. // Create a RtpReceiver instance.
try try
{ {
rtpReceiver = new RTC::RtpReceiver(this, this->notifier, rtpReceiverId, kind); rtpReceiver = new RTC::RtpReceiver(this, this->notifier, rtpReceiverId, RTC::Media::GetKind(kind));
} }
catch (const MediaSoupError &error) catch (const MediaSoupError &error)
{ {
...@@ -396,8 +396,6 @@ namespace RTC ...@@ -396,8 +396,6 @@ namespace RTC
static const Json::StaticString k_rtpSenderId("rtpSenderId"); static const Json::StaticString k_rtpSenderId("rtpSenderId");
static const Json::StaticString k_kind("kind"); static const Json::StaticString k_kind("kind");
static const Json::StaticString v_audio("audio");
static const Json::StaticString v_video("video");
static const Json::StaticString k_rtpParameters("rtpParameters"); static const Json::StaticString k_rtpParameters("rtpParameters");
static const Json::StaticString k_peerName("peerName"); static const Json::StaticString k_peerName("peerName");
...@@ -414,15 +412,7 @@ namespace RTC ...@@ -414,15 +412,7 @@ namespace RTC
Json::Value event_data(Json::objectValue); Json::Value event_data(Json::objectValue);
event_data[k_rtpSenderId] = (Json::UInt)rtpSender->rtpSenderId; event_data[k_rtpSenderId] = (Json::UInt)rtpSender->rtpSenderId;
switch (rtpSender->kind) event_data[k_kind] = RTC::Media::GetJsonString(rtpSender->kind);
{
case RTC::RtpKind::AUDIO:
event_data[k_kind] = v_audio;
break;
case RTC::RtpKind::VIDEO:
event_data[k_kind] = v_video;
break;
}
event_data[k_rtpParameters] = rtpSender->GetParameters()->toJson(); event_data[k_rtpParameters] = rtpSender->GetParameters()->toJson();
event_data[k_peerName] = peerName; event_data[k_peerName] = peerName;
......
...@@ -8,6 +8,52 @@ ...@@ -8,6 +8,52 @@
namespace RTC namespace RTC
{ {
/* Class variables. */
RTC::RtpCapabilities Room::defaultRtpCapabilities;
/* Class methods. */
void Room::ClassInit()
{
MS_TRACE();
// Parse default RTP capabilities.
{
Json::CharReaderBuilder builder;
Json::Value settings = Json::nullValue;
Json::Value invalid_settings;
builder.strictMode(&settings);
Json::CharReader* jsonReader = builder.newCharReader();
// NOTE: This line is auto-generated frmo data/defaultRtpCapabilities.js.
const std::string capabilities = R"({"codecs":[{"kind":"audio","name":"audio/opus","preferredPayloadType":100,"clockRate":90000,"rtcpFeedback":[{"type":"ccm","parameter":"fir"},{"type":"nack","parameter":""},{"type":"nack","parameter":"pli"},{"type":"google-remb","parameter":""}]}]})";
Json::Value json;
std::string json_parse_error;
if (!jsonReader->parse(capabilities.c_str(), capabilities.c_str() + capabilities.length(), &json, &json_parse_error))
{
delete jsonReader;
MS_THROW_ERROR_STD("JSON parsing error in default RTP capabilities: %s", json_parse_error.c_str());
}
delete jsonReader;
try
{
Room::defaultRtpCapabilities = RTC::RtpCapabilities(json);
}
catch (const MediaSoupError &error)
{
MS_THROW_ERROR_STD("wrong default RTP capabilities: %s", error.what());
}
}
}
/* Instance methods. */ /* Instance methods. */
Room::Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId) : Room::Room(Listener* listener, Channel::Notifier* notifier, uint32_t roomId) :
......
#define MS_CLASS "RTC::Media"
#include "RTC/RtpDictionaries.h"
#include "Utils.h"
#include "MediaSoupError.h"
#include "Logger.h"
namespace RTC
{
/* Class variables. */
std::unordered_map<std::string, Media::Kind> Media::string2Kind =
{
{ "audio", Media::Kind::AUDIO },
{ "video", Media::Kind::VIDEO },
{ "depth", Media::Kind::DEPTH }
};
std::map<Media::Kind, Json::StaticString> Media::kind2Json =
{
{ Media::Kind::AUDIO, Json::StaticString("audio") },
{ Media::Kind::VIDEO, Json::StaticString("video") },
{ Media::Kind::DEPTH, Json::StaticString("depth") }
};
/* Class methods. */
Media::Kind Media::GetKind(std::string& str)
{
MS_TRACE();
auto it = Media::string2Kind.find(str);
if (it == Media::string2Kind.end())
MS_THROW_ERROR("invalid media kind");
return it->second;
}
Json::StaticString& Media::GetJsonString(Media::Kind kind)
{
MS_TRACE();
auto it = Media::kind2Json.find(kind);
if (it == Media::kind2Json.end())
MS_THROW_ERROR("invalid media kind");
return it->second;
}
}
#define MS_CLASS "RTC::RtpCapabilities"
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
#include "Logger.h"
#include <unordered_set>
namespace RTC
{
/* Instance methods. */
RtpCapabilities::RtpCapabilities(Json::Value& data)
{
MS_TRACE();
static const Json::StaticString k_codecs("codecs");
static const Json::StaticString k_headerExtensions("headerExtensions");
static const Json::StaticString k_fecMechanisms("fecMechanisms");
// `codecs` is mandatory.
if (data[k_codecs].isArray())
{
auto& json_codecs = data[k_codecs];
for (Json::UInt i = 0; i < json_codecs.size(); i++)
{
RtpCodecCapability codec(json_codecs[i]);
// Append to the codecs vector.
this->codecs.push_back(codec);
}
}
else
{
MS_THROW_ERROR("missing RtpCapabilities.codecs");
}
// `headerExtensions` is optional.
if (data[k_headerExtensions].isArray())
{
auto& json_array = data[k_headerExtensions];
for (Json::UInt i = 0; i < json_array.size(); i++)
{
RtpHeaderExtension headerExtension(json_array[i]);
// Append to the headerExtensions vector.
this->headerExtensions.push_back(headerExtension);
}
}
// `fecMechanisms` is optional.
if (data[k_fecMechanisms].isArray())
{
auto& json_array = data[k_fecMechanisms];
for (Json::UInt i = 0; i < json_array.size(); i++)
{
if (!json_array[i].isString())
MS_THROW_ERROR("invalid RtpCapabilities.fecMechanisms");
// Append to the fecMechanisms vector.
this->fecMechanisms.push_back(json_array[i].asString());
}
}
// Validate RTP capabilities.
ValidateCodecs();
}
RtpCapabilities::~RtpCapabilities()
{
MS_TRACE();
}
Json::Value RtpCapabilities::toJson()
{
MS_TRACE();
static const Json::StaticString k_codecs("codecs");
static const Json::StaticString k_headerExtensions("headerExtensions");
static const Json::StaticString k_fecMechanisms("fecMechanisms");
Json::Value json(Json::objectValue);
// Add `codecs`.
if (!this->codecs.empty())
{
json[k_codecs] = Json::arrayValue;
for (auto& entry : this->codecs)
{
json[k_codecs].append(entry.toJson());
}
}
// Add `headerExtensions`.
if (!this->headerExtensions.empty())
{
json[k_headerExtensions] = Json::arrayValue;
for (auto& entry : this->headerExtensions)
{
json[k_headerExtensions].append(entry.toJson());
}
}
// Add `fecMechanisms`.
if (!this->fecMechanisms.empty())
{
json[k_fecMechanisms] = Json::arrayValue;
for (auto& entry : this->fecMechanisms)
{
json[k_fecMechanisms].append(entry);
}
}
return json;
}
void RtpCapabilities::ValidateCodecs()
{
MS_TRACE();
// TODO
}
}
#define MS_CLASS "RTC::RtpCodecCapability"
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
#include "Logger.h"
namespace RTC
{
/* Instance methods. */
RtpCodecCapability::RtpCodecCapability(Json::Value& data)
{
MS_TRACE();
static const Json::StaticString k_kind("kind");
static const Json::StaticString k_name("name");
static const Json::StaticString k_preferredPayloadType("preferredPayloadType");
static const Json::StaticString k_clockRate("clockRate");
static const Json::StaticString k_maxptime("maxptime");
static const Json::StaticString k_ptime("ptime");
static const Json::StaticString k_numChannels("numChannels");
static const Json::StaticString k_rtcpFeedback("rtcpFeedback");
static const Json::StaticString k_parameters("parameters");
static const Json::StaticString k_maxTemporalLayers("maxTemporalLayers");
static const Json::StaticString k_maxSpatialLayers("maxSpatialLayers");
static const Json::StaticString k_svcMultiStreamSupport("svcMultiStreamSupport");
if (!data.isObject())
MS_THROW_ERROR("RtpCodecCapability is not an object");
// `kind` is mandatory.
if (!data[k_kind].isString())
MS_THROW_ERROR("missing RtpCodecCapability.kind");
std::string kind = data[k_kind].asString();
// NOTE: This may throw.
this->kind = RTC::Media::GetKind(kind);
// `name` is mandatory.
if (!data[k_name].isString())
MS_THROW_ERROR("missing RtpCodecCapability.name");
std::string name = data[k_name].asString();
// Set MIME field.
// NOTE: This may throw.
this->mime.SetName(name);
// Override/normalize given `name`.
this->name = this->mime.ToString();
// `preferredPayloadType` is mandatory.
if (!data[k_preferredPayloadType].isUInt())
MS_THROW_ERROR("missing RtpCodecCapability.preferredPayloadType");
this->preferredPayloadType = (uint8_t)data[k_preferredPayloadType].asUInt();
// `clockRate` is optional.
if (data[k_clockRate].isUInt())
this->clockRate = (uint32_t)data[k_clockRate].asUInt();
// `maxptime` is optional.
if (data[k_maxptime].isUInt())
this->maxptime = (uint32_t)data[k_maxptime].asUInt();
// `ptime` is optional.
if (data[k_ptime].isUInt())
this->ptime = (uint32_t)data[k_ptime].asUInt();
// `numChannels` is optional.
if (data[k_numChannels].isUInt())
this->numChannels = (uint32_t)data[k_numChannels].asUInt();
// `rtcpFeedback` is optional.
if (data[k_rtcpFeedback].isArray())
{
auto& json_rtcpFeedback = data[k_rtcpFeedback];
for (Json::UInt i = 0; i < json_rtcpFeedback.size(); i++)
{
RtcpFeedback rtcpFeedback(json_rtcpFeedback[i]);
// Append to the rtcpFeedback vector.
this->rtcpFeedback.push_back(rtcpFeedback);
}
}
// `parameters` is optional.
if (data[k_parameters].isObject())
RTC::FillCustomParameters(this->parameters, data[k_parameters]);
// `maxTemporalLayers` is optional.
if (data[k_maxTemporalLayers].isUInt())
this->maxTemporalLayers = (uint16_t)data[k_maxTemporalLayers].asUInt();
// `maxSpatialLayers` is optional.
if (data[k_maxSpatialLayers].isUInt())
this->maxSpatialLayers = (uint16_t)data[k_maxSpatialLayers].asUInt();
// `svcMultiStreamSupport` is optional.
if (data[k_svcMultiStreamSupport].isBool())
this->svcMultiStreamSupport = data[k_svcMultiStreamSupport].asBool();
}
RtpCodecCapability::~RtpCodecCapability()
{
MS_TRACE();
}
Json::Value RtpCodecCapability::toJson()
{
MS_TRACE();
static const Json::StaticString k_kind("kind");
static const Json::StaticString k_name("name");
static const Json::StaticString k_preferredPayloadType("preferredPayloadType");
static const Json::StaticString k_clockRate("clockRate");
static const Json::StaticString k_maxptime("maxptime");
static const Json::StaticString k_ptime("ptime");
static const Json::StaticString k_numChannels("numChannels");
static const Json::StaticString k_rtcpFeedback("rtcpFeedback");
static const Json::StaticString k_parameters("parameters");
static const Json::StaticString k_maxTemporalLayers("maxTemporalLayers");
static const Json::StaticString k_maxSpatialLayers("maxSpatialLayers");
static const Json::StaticString k_svcMultiStreamSupport("svcMultiStreamSupport");
Json::Value json(Json::objectValue);
// Add `kind`.
json[k_kind] = RTC::Media::GetJsonString(this->kind);
// Add `name`.
json[k_name] = this->name;
// Add `preferredPayloadType`.
json[k_preferredPayloadType] = (Json::UInt)this->preferredPayloadType;
// Add `clockRate`.
if (this->clockRate)
json[k_clockRate] = (Json::UInt)this->clockRate;
// Add `maxptime`.
if (this->maxptime)
json[k_maxptime] = (Json::UInt)this->maxptime;
// Add `ptime`.
if (this->ptime)
json[k_ptime] = (Json::UInt)this->ptime;
// Add `numChannels`.
if (this->numChannels)
json[k_numChannels] = (Json::UInt)this->numChannels;
// Add `rtcpFeedback`.
json[k_rtcpFeedback] = Json::arrayValue;
for (auto& entry : this->rtcpFeedback)
{
json[k_rtcpFeedback].append(entry.toJson());
}
// Add `parameters`.
Json::Value json_parameters(Json::objectValue);
for (auto& kv : this->parameters)
{
const std::string& key = kv.first;
auto& parameterValue = kv.second;
json_parameters[key] = parameterValue.toJson();
}
json[k_parameters] = json_parameters;
// Add `maxTemporalLayers` (if set).
if (this->maxTemporalLayers)
json[k_maxTemporalLayers] = (Json::UInt)this->maxTemporalLayers;
// Add `maxSpatialLayers` (if set).
if (this->maxSpatialLayers)
json[k_maxSpatialLayers] = (Json::UInt)this->maxSpatialLayers;
// Add `svcMultiStreamSupport` (if set).
if (this->svcMultiStreamSupport)
json[k_svcMultiStreamSupport] = true;
return json;
}
}
#define MS_CLASS "RTC::RtpCodecMime"
#include "RTC/RtpDictionaries.h"
#include "Utils.h"
#include "MediaSoupError.h"
#include "Logger.h"
namespace RTC
{
/* Class variables. */
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 },
// Video codecs:
{ "vp8", RtpCodecMime::Subtype::VP8 },
{ "vp9", RtpCodecMime::Subtype::VP9 },
{ "h264", RtpCodecMime::Subtype::H264 },
{ "h265", RtpCodecMime::Subtype::H265 },
// Feature codecs:
{ "rtx", RtpCodecMime::Subtype::RTX },
{ "ulpfec", RtpCodecMime::Subtype::ULPFEC },
{ "flexfec", RtpCodecMime::Subtype::FLEXFEC },
{ "red", RtpCodecMime::Subtype::RED },
{ "cn", RtpCodecMime::Subtype::CN },
{ "telephone-event", RtpCodecMime::Subtype::TELEPHONE_EVENT }
};
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" },
// Video codecs:
{ RtpCodecMime::Subtype::VP8, "VP8" },
{ RtpCodecMime::Subtype::VP9, "VP9" },
{ RtpCodecMime::Subtype::H264, "H264" },
{ RtpCodecMime::Subtype::H265, "H265" },
// Feature codecs:
{ RtpCodecMime::Subtype::RTX, "rtx" },
{ RtpCodecMime::Subtype::ULPFEC, "ulpfec" },
{ RtpCodecMime::Subtype::FLEXFEC, "flexfec" },
{ RtpCodecMime::Subtype::RED, "red" },
{ RtpCodecMime::Subtype::CN, "CN" },
{ RtpCodecMime::Subtype::TELEPHONE_EVENT, "telephone-event" }
};
/* Instance methods. */
RtpCodecMime::~RtpCodecMime()
{
MS_TRACE();
}
void RtpCodecMime::SetName(std::string& name)
{
MS_TRACE();
auto slash_pos = name.find('/');
if (slash_pos == std::string::npos || slash_pos == 0 || slash_pos == name.length() - 1)
MS_THROW_ERROR("wrong codec MIME");
std::string type = name.substr(0, slash_pos);
std::string subtype = name.substr(slash_pos + 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");
}
// 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");
}
// Set name.
this->name = type2String[this->type] + "/" + subtype2String[this->subtype];
}
}
...@@ -6,22 +6,6 @@ ...@@ -6,22 +6,6 @@
namespace RTC namespace RTC
{ {
/* Class variables. */
std::unordered_map<std::string, RtpCodecParameters::Subtype> RtpCodecParameters::string2Subtype =
{
{ "rtx", RtpCodecParameters::Subtype::RTX },
{ "RTX", RtpCodecParameters::Subtype::RTX },
{ "ulpfec", RtpCodecParameters::Subtype::ULPFEC },
{ "flexfec", RtpCodecParameters::Subtype::FLEXFEC },
{ "red", RtpCodecParameters::Subtype::RED },
{ "RED", RtpCodecParameters::Subtype::RED },
{ "cn", RtpCodecParameters::Subtype::CN },
{ "CN", RtpCodecParameters::Subtype::CN },
{ "telephone-event", RtpCodecParameters::Subtype::DTMF },
{ "dtmf", RtpCodecParameters::Subtype::DTMF }
};
/* Instance methods. */ /* Instance methods. */
RtpCodecParameters::RtpCodecParameters(Json::Value& data) RtpCodecParameters::RtpCodecParameters(Json::Value& data)
...@@ -44,21 +28,14 @@ namespace RTC ...@@ -44,21 +28,14 @@ namespace RTC
if (!data[k_name].isString()) if (!data[k_name].isString())
MS_THROW_ERROR("missing RtpCodecParameters.name"); MS_THROW_ERROR("missing RtpCodecParameters.name");
this->name = data[k_name].asString(); std::string name = data[k_name].asString();
// Get name MIME subtype.
auto slash_pos = this->name.find('/');
if (slash_pos == std::string::npos || slash_pos == 0 || slash_pos == this->name.length() - 1) // Set MIME field.
MS_THROW_ERROR("wrong RtpCodecParameters.name"); // NOTE: This may throw.
this->mime.SetName(name);
std::string subtype = this->name.substr(slash_pos + 1); // Override/normalize given `name`.
this->name = this->mime.ToString();
if (RtpCodecParameters::string2Subtype.find(subtype) == RtpCodecParameters::string2Subtype.end())
this->subtype = Subtype::MEDIA;
else
this->subtype = RtpCodecParameters::string2Subtype[subtype];
// `payloadType` is mandatory. // `payloadType` is mandatory.
if (!data[k_payloadType].isUInt()) if (!data[k_payloadType].isUInt())
...@@ -101,10 +78,10 @@ namespace RTC ...@@ -101,10 +78,10 @@ namespace RTC
RTC::FillCustomParameters(this->parameters, data[k_parameters]); RTC::FillCustomParameters(this->parameters, data[k_parameters]);
// Validate codec. // Validate codec.
switch (this->subtype) switch (this->mime.subtype)
{ {
// A RTX codec must have 'apt' parameter. // A RTX codec must have 'apt' parameter.
case Subtype::RTX: case RTC::RtpCodecMime::Subtype::RTX:
{ {
auto it = this->parameters.find("apt"); auto it = this->parameters.find("apt");
...@@ -164,20 +141,15 @@ namespace RTC ...@@ -164,20 +141,15 @@ namespace RTC
if (this->numChannels) if (this->numChannels)
json[k_numChannels] = (Json::UInt)this->numChannels; json[k_numChannels] = (Json::UInt)this->numChannels;
// Add `rtcpFeedback` (if any). // Add `rtcpFeedback`.
if (!this->rtcpFeedback.empty())
{
json[k_rtcpFeedback] = Json::arrayValue; json[k_rtcpFeedback] = Json::arrayValue;
for (auto& entry : this->rtcpFeedback) for (auto& entry : this->rtcpFeedback)
{ {
json[k_rtcpFeedback].append(entry.toJson()); json[k_rtcpFeedback].append(entry.toJson());
} }
}
// Add `parameters` (if any). // Add `parameters`.
if (this->parameters.size() > 0)
{
Json::Value json_parameters(Json::objectValue); Json::Value json_parameters(Json::objectValue);
for (auto& kv : this->parameters) for (auto& kv : this->parameters)
...@@ -189,7 +161,6 @@ namespace RTC ...@@ -189,7 +161,6 @@ namespace RTC
} }
json[k_parameters] = json_parameters; json[k_parameters] = json_parameters;
}
return json; return json;
} }
......
#define MS_CLASS "RTC::RtpHeaderExtension"
#include "RTC/RtpDictionaries.h"
#include "MediaSoupError.h"
#include "Logger.h"
namespace RTC
{
/* Instance methods. */
RtpHeaderExtension::RtpHeaderExtension(Json::Value& data)
{
MS_TRACE();
static const Json::StaticString k_kind("kind");
static const Json::StaticString k_uri("uri");
static const Json::StaticString k_preferredId("preferredId");
static const Json::StaticString k_preferredEncrypt("preferredEncrypt");
if (!data.isObject())
MS_THROW_ERROR("RtpHeaderExtension is not an object");
// `kind` is mandatory.
if (!data[k_kind].isString())
MS_THROW_ERROR("missing RtpCodecCapability.kind");
std::string kind = data[k_kind].asString();
// NOTE: This may throw.
this->kind = RTC::Media::GetKind(kind);
// `uri` is mandatory.
if (!data[k_uri].isString())
MS_THROW_ERROR("missing RtpHeaderExtension.uri");
this->uri = data[k_uri].asString();
if (this->uri.empty())
MS_THROW_ERROR("empty RtpHeaderExtension.uri");
// `preferredId` is mandatory.
if (!data[k_preferredId].asUInt())
MS_THROW_ERROR("missing RtpHeaderExtension.preferredId");
this->preferredId = (uint16_t)data[k_preferredId].asUInt();
// `preferredEncrypt` is optional.
if (data[k_preferredEncrypt].isBool())
this->preferredEncrypt = data[k_preferredEncrypt].asBool();
}
RtpHeaderExtension::~RtpHeaderExtension()
{
MS_TRACE();
}
Json::Value RtpHeaderExtension::toJson()
{
MS_TRACE();
static const Json::StaticString k_kind("kind");
static const Json::StaticString k_uri("uri");
static const Json::StaticString k_preferredId("preferredId");
static const Json::StaticString k_preferredEncrypt("preferredEncrypt");
Json::Value json(Json::objectValue);
// Add `kind`.
json[k_kind] = RTC::Media::GetJsonString(this->kind);
// Add `uri`.
json[k_uri] = this->uri;
// Add `preferredId`.
json[k_preferredId] = (Json::UInt)this->preferredId;
// Add `preferredEncrypt`.
json[k_preferredEncrypt] = this->preferredEncrypt;
return json;
}
}
...@@ -68,9 +68,7 @@ namespace RTC ...@@ -68,9 +68,7 @@ namespace RTC
// Add `encrypt`. // Add `encrypt`.
json[k_encrypt] = this->encrypt; json[k_encrypt] = this->encrypt;
// Add `parameters` (if any). // Add `parameters`.
if (this->parameters.size() > 0)
{
Json::Value json_parameters(Json::objectValue); Json::Value json_parameters(Json::objectValue);
for (auto& kv : this->parameters) for (auto& kv : this->parameters)
...@@ -82,7 +80,6 @@ namespace RTC ...@@ -82,7 +80,6 @@ namespace RTC
} }
json[k_parameters] = json_parameters; json[k_parameters] = json_parameters;
}
return json; return json;
} }
......
...@@ -191,10 +191,10 @@ namespace RTC ...@@ -191,10 +191,10 @@ namespace RTC
else else
payloadTypes.insert(codec.payloadType); payloadTypes.insert(codec.payloadType);
switch (codec.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 RtpCodecParameters::Subtype::RTX: case RTC::RtpCodecMime::Subtype::RTX:
{ {
// NOTE: RtpCodecParameters already asserted that there is 'apt' parameter. // NOTE: RtpCodecParameters already asserted that there is 'apt' parameter.
auto it = codec.parameters.find("apt"); auto it = codec.parameters.find("apt");
...@@ -207,11 +207,11 @@ namespace RTC ...@@ -207,11 +207,11 @@ namespace RTC
if ((int32_t)codec.payloadType == apt) if ((int32_t)codec.payloadType == apt)
{ {
if (codec.subtype == RtpCodecParameters::Subtype::RTX) if (codec.mime.subtype == RTC::RtpCodecMime::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.subtype == RtpCodecParameters::Subtype::ULPFEC) else if (codec.mime.subtype == RTC::RtpCodecMime::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.subtype == RtpCodecParameters::Subtype::FLEXFEC) else if (codec.mime.subtype == RTC::RtpCodecMime::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;
...@@ -240,7 +240,7 @@ namespace RTC ...@@ -240,7 +240,7 @@ namespace RTC
auto codec = *it; auto codec = *it;
// Must be a media codec. // Must be a media codec.
if (codec.subtype == RtpCodecParameters::Subtype::MEDIA) if (codec.mime.IsMediaCodec())
{ {
firstMediaPayloadType = codec.payloadType; firstMediaPayloadType = codec.payloadType;
hasFirstMediaPayloadType = true; hasFirstMediaPayloadType = true;
...@@ -286,7 +286,7 @@ namespace RTC ...@@ -286,7 +286,7 @@ namespace RTC
if (codec.payloadType == encoding.codecPayloadType) if (codec.payloadType == encoding.codecPayloadType)
{ {
// Must be a media codec. // Must be a media codec.
if (codec.subtype == RtpCodecParameters::Subtype::MEDIA) if (codec.mime.IsMediaCodec())
break; break;
else else
MS_THROW_ERROR("invalid encoding.codecPayloadType"); MS_THROW_ERROR("invalid encoding.codecPayloadType");
......
...@@ -9,19 +9,13 @@ namespace RTC ...@@ -9,19 +9,13 @@ namespace RTC
{ {
/* Instance methods. */ /* Instance methods. */
RtpReceiver::RtpReceiver(Listener* listener, Channel::Notifier* notifier, uint32_t rtpReceiverId, std::string& kind) : RtpReceiver::RtpReceiver(Listener* listener, Channel::Notifier* notifier, uint32_t rtpReceiverId, RTC::Media::Kind kind) :
rtpReceiverId(rtpReceiverId), rtpReceiverId(rtpReceiverId),
kind(kind),
listener(listener), listener(listener),
notifier(notifier) notifier(notifier)
{ {
MS_TRACE(); MS_TRACE();
if (kind == "audio")
this->kind = RTC::RtpKind::AUDIO;
else if (kind == "video")
this->kind = RTC::RtpKind::VIDEO;
else
MS_THROW_ERROR("unknown kind");
} }
RtpReceiver::~RtpReceiver() RtpReceiver::~RtpReceiver()
...@@ -60,8 +54,6 @@ namespace RTC ...@@ -60,8 +54,6 @@ namespace RTC
static Json::Value null_data(Json::nullValue); static Json::Value null_data(Json::nullValue);
static const Json::StaticString k_rtpReceiverId("rtpReceiverId"); static const Json::StaticString k_rtpReceiverId("rtpReceiverId");
static const Json::StaticString k_kind("kind"); static const Json::StaticString k_kind("kind");
static const Json::StaticString v_audio("audio");
static const Json::StaticString v_video("video");
static const Json::StaticString k_rtpParameters("rtpParameters"); static const Json::StaticString k_rtpParameters("rtpParameters");
static const Json::StaticString k_hasTransport("hasTransport"); static const Json::StaticString k_hasTransport("hasTransport");
static const Json::StaticString k_rtpRawEventEnabled("rtpRawEventEnabled"); static const Json::StaticString k_rtpRawEventEnabled("rtpRawEventEnabled");
...@@ -71,15 +63,7 @@ namespace RTC ...@@ -71,15 +63,7 @@ namespace RTC
json[k_rtpReceiverId] = (Json::UInt)this->rtpReceiverId; json[k_rtpReceiverId] = (Json::UInt)this->rtpReceiverId;
switch (this->kind) json[k_kind] = RTC::Media::GetJsonString(this->kind);
{
case RTC::RtpKind::AUDIO:
json[k_kind] = v_audio;
break;
case RTC::RtpKind::VIDEO:
json[k_kind] = v_video;
break;
}
if (this->rtpParameters) if (this->rtpParameters)
json[k_rtpParameters] = this->rtpParameters->toJson(); json[k_rtpParameters] = this->rtpParameters->toJson();
......
...@@ -8,7 +8,7 @@ namespace RTC ...@@ -8,7 +8,7 @@ namespace RTC
{ {
/* Instance methods. */ /* Instance methods. */
RtpSender::RtpSender(Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::RtpKind kind) : RtpSender::RtpSender(Listener* listener, Channel::Notifier* notifier, uint32_t rtpSenderId, RTC::Media::Kind kind) :
rtpSenderId(rtpSenderId), rtpSenderId(rtpSenderId),
kind(kind), kind(kind),
listener(listener), listener(listener),
...@@ -47,8 +47,6 @@ namespace RTC ...@@ -47,8 +47,6 @@ namespace RTC
static Json::Value null_data(Json::nullValue); static Json::Value null_data(Json::nullValue);
static const Json::StaticString k_rtpSenderId("rtpSenderId"); static const Json::StaticString k_rtpSenderId("rtpSenderId");
static const Json::StaticString k_kind("kind"); static const Json::StaticString k_kind("kind");
static const Json::StaticString v_audio("audio");
static const Json::StaticString v_video("video");
static const Json::StaticString k_rtpParameters("rtpParameters"); static const Json::StaticString k_rtpParameters("rtpParameters");
static const Json::StaticString k_hasTransport("hasTransport"); static const Json::StaticString k_hasTransport("hasTransport");
...@@ -56,15 +54,7 @@ namespace RTC ...@@ -56,15 +54,7 @@ namespace RTC
json[k_rtpSenderId] = (Json::UInt)this->rtpSenderId; json[k_rtpSenderId] = (Json::UInt)this->rtpSenderId;
switch (this->kind) json[k_kind] = RTC::Media::GetJsonString(this->kind);
{
case RTC::RtpKind::AUDIO:
json[k_kind] = v_audio;
break;
case RTC::RtpKind::VIDEO:
json[k_kind] = v_video;
break;
}
if (this->rtpParameters) if (this->rtpParameters)
json[k_rtpParameters] = this->rtpParameters->toJson(); json[k_rtpParameters] = this->rtpParameters->toJson();
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "Logger.h" #include "Logger.h"
#include <string> #include <string>
#include <map> #include <map>
#include <algorithm> // std::transform()
#include <cctype> // isprint() #include <cctype> // isprint()
#include <cerrno> #include <cerrno>
#include <unistd.h> // close() #include <unistd.h> // close()
...@@ -292,8 +291,8 @@ void Settings::SetLogLevel(std::string &level) ...@@ -292,8 +291,8 @@ void Settings::SetLogLevel(std::string &level)
{ {
MS_TRACE(); MS_TRACE();
// Downcase given level. // Lowcase given level.
std::transform(level.begin(), level.end(), level.begin(), ::tolower); Utils::String::ToLowerCase(level);
if (Settings::string2LogLevel.find(level) == Settings::string2LogLevel.end()) if (Settings::string2LogLevel.find(level) == Settings::string2LogLevel.end())
MS_THROW_ERROR("invalid value '%s' for logLevel", level.c_str()); MS_THROW_ERROR("invalid value '%s' for logLevel", level.c_str());
......
...@@ -115,11 +115,13 @@ void init() ...@@ -115,11 +115,13 @@ void init()
DepOpenSSL::ClassInit(); DepOpenSSL::ClassInit();
DepLibSRTP::ClassInit(); DepLibSRTP::ClassInit();
DepUsrSCTP::ClassInit(); DepUsrSCTP::ClassInit();
Utils::Crypto::ClassInit();
Utils::Crypto::ClassInit();
RTC::UdpSocket::ClassInit(); RTC::UdpSocket::ClassInit();
RTC::TcpServer::ClassInit(); RTC::TcpServer::ClassInit();
RTC::DtlsTransport::ClassInit(); RTC::DtlsTransport::ClassInit();
RTC::SrtpSession::ClassInit(); RTC::SrtpSession::ClassInit();
Utils::Crypto::ClassInit(); RTC::Room::ClassInit();
} }
void ignoreSignals() void ignoreSignals()
...@@ -159,12 +161,12 @@ void destroy() ...@@ -159,12 +161,12 @@ void destroy()
MS_TRACE(); MS_TRACE();
// Free static stuff. // Free static stuff.
RTC::DtlsTransport::ClassDestroy();
Utils::Crypto::ClassDestroy();
DepLibUV::ClassDestroy(); DepLibUV::ClassDestroy();
DepOpenSSL::ClassDestroy(); DepOpenSSL::ClassDestroy();
DepLibSRTP::ClassDestroy(); DepLibSRTP::ClassDestroy();
DepUsrSCTP::ClassDestroy(); DepUsrSCTP::ClassDestroy();
RTC::DtlsTransport::ClassDestroy();
Utils::Crypto::ClassDestroy();
} }
void exitSuccess() void exitSuccess()
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论