Unverified 提交 10d43256 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Add VP9 SVC support (#311)

上级 9672fbdb
# Changelog # Changelog
### 3.0.13 (work in progress) ### 3.1.0 (work in progress)
* Add SVC support. It includes VP9 full SVC and VP9 K-SVC as implemented by libwebrtc.
* Prefer Python 2 (if available) over Python 3. This is because there are yet pending issues with gyp + Python 3. * Prefer Python 2 (if available) over Python 3. This is because there are yet pending issues with gyp + Python 3.
......
...@@ -116,9 +116,16 @@ class Channel extends EnhancedEventEmitter ...@@ -116,9 +116,16 @@ class Channel extends EnhancedEventEmitter
this._workerLogger.error(nsPayload.toString('utf8', 1)); this._workerLogger.error(nsPayload.toString('utf8', 1));
break; break;
// 88 = 'X' (a dump log).
case 88:
// eslint-disable-next-line no-console
console.log(nsPayload.toString('utf8', 1));
break;
default: default:
this._workerLogger.error( // eslint-disable-next-line no-console
'unexpected data: %s', nsPayload.toString('utf8')); console.warn(
`worker[pid:${pid}] unexpected data: %s`, nsPayload.toString('utf8'));
} }
} }
catch (error) catch (error)
......
const ScalabilityModeRegex = new RegExp('^[LS](\\d+)T(\\d+)'); const ScalabilityModeRegex =
new RegExp('^[LS]([1-9]\\d{0,1})T([1-9]\\d{0,1})(_KEY)?');
exports.parse = function(scalabilityMode) exports.parse = function(scalabilityMode)
{ {
const match = ScalabilityModeRegex.exec(scalabilityMode); const match = ScalabilityModeRegex.exec(scalabilityMode);
if (!match) if (!match)
return { spatialLayers: 1, temporalLayers: 1 }; {
return {
spatialLayers : 1,
temporalLayers : 1,
ksvc : false
};
}
return { return {
spatialLayers : Number(match[1]), spatialLayers : Number(match[1]),
temporalLayers : Number(match[2]) temporalLayers : Number(match[2]),
ksvc : Boolean(match[3])
}; };
}; };
...@@ -588,7 +588,8 @@ test('consumer.dump() succeeds', async () => ...@@ -588,7 +588,8 @@ test('consumer.dump() succeeds', async () =>
}, },
scalabilityMode : 'S4T1', scalabilityMode : 'S4T1',
spatialLayers : 4, spatialLayers : 4,
temporalLayers : 1 temporalLayers : 1,
ksvc : false
} }
]); ]);
expect(data.consumableRtpEncodings).toBeType('array'); expect(data.consumableRtpEncodings).toBeType('array');
......
...@@ -599,7 +599,8 @@ test('producer.dump() succeeds', async () => ...@@ -599,7 +599,8 @@ test('producer.dump() succeeds', async () =>
rtx : { ssrc: 22222223 }, rtx : { ssrc: 22222223 },
scalabilityMode : 'L1T3', scalabilityMode : 'L1T3',
spatialLayers : 1, spatialLayers : 1,
temporalLayers : 3 temporalLayers : 3,
ksvc : false
}, },
{ codecPayloadType: 112, ssrc: 22222224, rtx: { ssrc: 22222225 } }, { codecPayloadType: 112, ssrc: 22222224, rtx: { ssrc: 22222225 } },
{ codecPayloadType: 112, ssrc: 22222226, rtx: { ssrc: 22222227 } }, { codecPayloadType: 112, ssrc: 22222226, rtx: { ssrc: 22222227 } },
......
...@@ -30,11 +30,35 @@ test('mediasoup.getSupportedRtpCapabilities() returns the mediasoup RTP capabili ...@@ -30,11 +30,35 @@ test('mediasoup.getSupportedRtpCapabilities() returns the mediasoup RTP capabili
expect(rtpCapabilities2).not.toEqual(rtpCapabilities); expect(rtpCapabilities2).not.toEqual(rtpCapabilities);
}, 500); }, 500);
test('mediasoup.parseScalabilityMode() works', () => test('parseScalabilityMode() works', () =>
{ {
expect(parseScalabilityMode('L1T3')).toEqual({ spatialLayers: 1, temporalLayers: 3 }); expect(parseScalabilityMode('L1T3'))
expect(parseScalabilityMode('L3T2_KEY')).toEqual({ spatialLayers: 3, temporalLayers: 2 }); .toEqual({ spatialLayers: 1, temporalLayers: 3, ksvc: false });
expect(parseScalabilityMode('S2T3')).toEqual({ spatialLayers: 2, temporalLayers: 3 });
expect(parseScalabilityMode('foo')).toEqual({ spatialLayers: 1, temporalLayers: 1 }); expect(parseScalabilityMode('L3T2_KEY'))
expect(parseScalabilityMode(null)).toEqual({ spatialLayers: 1, temporalLayers: 1 }); .toEqual({ spatialLayers: 3, temporalLayers: 2, ksvc: true });
expect(parseScalabilityMode('S2T3'))
.toEqual({ spatialLayers: 2, temporalLayers: 3, ksvc: false });
expect(parseScalabilityMode('foo'))
.toEqual({ spatialLayers: 1, temporalLayers: 1, ksvc: false });
expect(parseScalabilityMode(null))
.toEqual({ spatialLayers: 1, temporalLayers: 1, ksvc: false });
expect(parseScalabilityMode('S0T3'))
.toEqual({ spatialLayers: 1, temporalLayers: 1, ksvc: false });
expect(parseScalabilityMode('S1T0'))
.toEqual({ spatialLayers: 1, temporalLayers: 1, ksvc: false });
expect(parseScalabilityMode('L20T3'))
.toEqual({ spatialLayers: 20, temporalLayers: 3, ksvc: false });
expect(parseScalabilityMode('S200T3'))
.toEqual({ spatialLayers: 1, temporalLayers: 1, ksvc: false });
expect(parseScalabilityMode('L4T7_KEY_SHIFT'))
.toEqual({ spatialLayers: 4, temporalLayers: 7, ksvc: true });
}, 500); }, 500);
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -50,6 +50,13 @@ ...@@ -50,6 +50,13 @@
* Example: * Example:
* MS_DEBUG_DEV("Producer closed [producerId:%" PRIu32 "]", producerId); * MS_DEBUG_DEV("Producer closed [producerId:%" PRIu32 "]", producerId);
* *
* MS_DUMP(...)
*
* Logs always. Useful for Dump() methods.
*
* Example:
* MS_DUMP("foo");
*
* MS_ERROR(...) * MS_ERROR(...)
* *
* Logs an error if the current log level is satisfied (or if the current * Logs an error if the current log level is satisfied (or if the current
...@@ -306,6 +313,22 @@ public: ...@@ -306,6 +313,22 @@ public:
#define MS_WARN_DEV_STD(desc, ...) {} #define MS_WARN_DEV_STD(desc, ...) {}
#endif #endif
#define MS_DUMP(desc, ...) \
do \
{ \
int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "X" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \
Logger::channel->SendLog(Logger::buffer, loggerWritten); \
} \
while (false)
#define MS_DUMP_STD(desc, ...) \
do \
{ \
std::fprintf(stdout, _MS_LOG_STR_DESC desc _MS_LOG_SEPARATOR_CHAR_STD, _MS_LOG_ARG, ##__VA_ARGS__); \
std::fflush(stdout); \
} \
while (false)
#define MS_ERROR(desc, ...) \ #define MS_ERROR(desc, ...) \
do \ do \
{ \ { \
...@@ -358,6 +381,8 @@ public: ...@@ -358,6 +381,8 @@ public:
#define MS_DEBUG_DEV MS_DEBUG_DEV_STD #define MS_DEBUG_DEV MS_DEBUG_DEV_STD
#undef MS_WARN_DEV #undef MS_WARN_DEV
#define MS_WARN_DEV MS_WARN_DEV_STD #define MS_WARN_DEV MS_WARN_DEV_STD
#undef MS_DUMP
#define MS_DUMP MS_DUMP_STD
#undef MS_ERROR #undef MS_ERROR
#define MS_ERROR MS_ERROR_STD #define MS_ERROR MS_ERROR_STD
#endif #endif
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "RTC/Codecs/H264.hpp" #include "RTC/Codecs/H264.hpp"
#include "RTC/Codecs/PayloadDescriptorHandler.hpp" #include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/Codecs/VP8.hpp" #include "RTC/Codecs/VP8.hpp"
#include "RTC/Codecs/VP9.hpp"
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
...@@ -14,26 +15,109 @@ namespace RTC ...@@ -14,26 +15,109 @@ namespace RTC
{ {
bool CanBeKeyFrame(const RTC::RtpCodecMimeType& mimeType); bool CanBeKeyFrame(const RTC::RtpCodecMimeType& mimeType);
void ProcessRtpPacket(RTC::RtpPacket* packet, const RTC::RtpCodecMimeType& mimeType); void ProcessRtpPacket(RTC::RtpPacket* packet, const RTC::RtpCodecMimeType& mimeType);
EncodingContext* GetEncodingContext(const RTC::RtpCodecMimeType& mimeType); bool IsValidTypeForCodec(RTC::RtpParameters::Type type, const RTC::RtpCodecMimeType& mimeType);
EncodingContext* GetEncodingContext(
const RTC::RtpCodecMimeType& mimeType, uint8_t spatialLayers, uint8_t temporalLayers);
/* Inline namespace methods. */ /* Inline namespace methods. */
inline bool CanBeKeyFrame(const RTC::RtpCodecMimeType& mimeType) inline bool CanBeKeyFrame(const RTC::RtpCodecMimeType& mimeType)
{ {
if (mimeType.type != RTC::RtpCodecMimeType::Type::VIDEO) switch (mimeType.type)
return false; {
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
case RTC::RtpCodecMimeType::Subtype::VP9:
case RTC::RtpCodecMimeType::Subtype::H264:
return true;
default:
return false;
}
}
switch (mimeType.subtype) default:
{
return false;
}
}
}
inline bool IsValidTypeForCodec(RTC::RtpParameters::Type type, const RTC::RtpCodecMimeType& mimeType)
{
switch (type)
{ {
case RTC::RtpCodecMimeType::Subtype::VP8: case RTC::RtpParameters::Type::NONE:
case RTC::RtpCodecMimeType::Subtype::H264: {
return false;
}
case RTC::RtpParameters::Type::SIMPLE:
{
return true; return true;
}
case RTC::RtpParameters::Type::SIMULCAST:
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP8:
case RTC::RtpCodecMimeType::Subtype::H264:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
case RTC::RtpParameters::Type::SVC:
{
switch (mimeType.type)
{
case RTC::RtpCodecMimeType::Type::VIDEO:
{
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP9:
return true;
default:
return false;
}
}
default:
{
return false;
}
}
}
case RTC::RtpParameters::Type::PIPE:
{
return true;
}
default: default:
{
return false; return false;
}
} }
} }
inline EncodingContext* GetEncodingContext(const RTC::RtpCodecMimeType& mimeType) inline EncodingContext* GetEncodingContext(
const RTC::RtpCodecMimeType& mimeType, RTC::Codecs::EncodingContext::Params& params)
{ {
switch (mimeType.type) switch (mimeType.type)
{ {
...@@ -42,9 +126,11 @@ namespace RTC ...@@ -42,9 +126,11 @@ namespace RTC
switch (mimeType.subtype) switch (mimeType.subtype)
{ {
case RTC::RtpCodecMimeType::Subtype::VP8: case RTC::RtpCodecMimeType::Subtype::VP8:
return new RTC::Codecs::VP8::EncodingContext(); return new RTC::Codecs::VP8::EncodingContext(params);
case RTC::RtpCodecMimeType::Subtype::VP9:
return new RTC::Codecs::VP9::EncodingContext(params);
case RTC::RtpCodecMimeType::Subtype::H264: case RTC::RtpCodecMimeType::Subtype::H264:
return new RTC::Codecs::H264::EncodingContext(); return new RTC::Codecs::H264::EncodingContext(params);
default: default:
return nullptr; return nullptr;
} }
......
...@@ -30,6 +30,7 @@ namespace RTC ...@@ -30,6 +30,7 @@ namespace RTC
uint8_t tl0picidx{ 0 }; // TL0PICIDX uint8_t tl0picidx{ 0 }; // TL0PICIDX
// Parsed values. // Parsed values.
bool hasLid{ false }; bool hasLid{ false };
bool hasTid{ false };
bool hasTl0picidx{ false }; bool hasTl0picidx{ false };
bool isKeyFrame{ false }; bool isKeyFrame{ false };
}; };
...@@ -46,6 +47,7 @@ namespace RTC ...@@ -46,6 +47,7 @@ namespace RTC
class EncodingContext : public RTC::Codecs::EncodingContext class EncodingContext : public RTC::Codecs::EncodingContext
{ {
public: public:
EncodingContext(RTC::Codecs::EncodingContext::Params& params);
~EncodingContext() = default; ~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */ /* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
...@@ -62,7 +64,7 @@ namespace RTC ...@@ -62,7 +64,7 @@ namespace RTC
public: public:
void Dump() const override; void Dump() const override;
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data) override; bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
void Restore(uint8_t* data) override; void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override; uint8_t GetSpatialLayer() const override;
uint8_t GetTemporalLayer() const override; uint8_t GetTemporalLayer() const override;
...@@ -75,6 +77,11 @@ namespace RTC ...@@ -75,6 +77,11 @@ namespace RTC
/* Inline EncondingContext methods. */ /* Inline EncondingContext methods. */
inline H264::EncodingContext::EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
inline void H264::EncodingContext::SyncRequired() inline void H264::EncodingContext::SyncRequired()
{ {
} }
......
...@@ -19,10 +19,21 @@ namespace RTC ...@@ -19,10 +19,21 @@ namespace RTC
class EncodingContext class EncodingContext
{ {
public: public:
EncodingContext() = default; struct Params
{
uint8_t spatialLayers{ 1u };
uint8_t temporalLayers{ 1u };
bool ksvc{ false };
};
public:
EncodingContext(RTC::Codecs::EncodingContext::Params& params);
virtual ~EncodingContext() = default; virtual ~EncodingContext() = default;
public: public:
uint8_t GetSpatialLayers() const;
uint8_t GetTemporalLayers() const;
bool IsKSvc() const;
int16_t GetTargetSpatialLayer() const; int16_t GetTargetSpatialLayer() const;
int16_t GetTargetTemporalLayer() const; int16_t GetTargetTemporalLayer() const;
int16_t GetCurrentSpatialLayer() const; int16_t GetCurrentSpatialLayer() const;
...@@ -34,6 +45,7 @@ namespace RTC ...@@ -34,6 +45,7 @@ namespace RTC
virtual void SyncRequired() = 0; virtual void SyncRequired() = 0;
private: private:
Params params;
int16_t targetSpatialLayer{ -1 }; int16_t targetSpatialLayer{ -1 };
int16_t targetTemporalLayer{ -1 }; int16_t targetTemporalLayer{ -1 };
int16_t currentSpatialLayer{ -1 }; int16_t currentSpatialLayer{ -1 };
...@@ -42,6 +54,26 @@ namespace RTC ...@@ -42,6 +54,26 @@ namespace RTC
/* Inline instance methods. */ /* Inline instance methods. */
inline EncodingContext::EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: params(params)
{
}
inline uint8_t EncodingContext::GetSpatialLayers() const
{
return this->params.spatialLayers;
}
inline uint8_t EncodingContext::GetTemporalLayers() const
{
return this->params.temporalLayers;
}
inline bool EncodingContext::IsKSvc() const
{
return this->params.ksvc;
}
inline int16_t EncodingContext::GetTargetSpatialLayer() const inline int16_t EncodingContext::GetTargetSpatialLayer() const
{ {
return this->targetSpatialLayer; return this->targetSpatialLayer;
...@@ -88,12 +120,12 @@ namespace RTC ...@@ -88,12 +120,12 @@ namespace RTC
virtual ~PayloadDescriptorHandler() = default; virtual ~PayloadDescriptorHandler() = default;
public: public:
virtual void Dump() const = 0; virtual void Dump() const = 0;
virtual bool Process(RTC::Codecs::EncodingContext* context, uint8_t* data) = 0; virtual bool Process(RTC::Codecs::EncodingContext* context, uint8_t* data, bool& marker) = 0;
virtual void Restore(uint8_t* data) = 0; virtual void Restore(uint8_t* data) = 0;
virtual uint8_t GetSpatialLayer() const = 0; virtual uint8_t GetSpatialLayer() const = 0;
virtual uint8_t GetTemporalLayer() const = 0; virtual uint8_t GetTemporalLayer() const = 0;
virtual bool IsKeyFrame() const = 0; virtual bool IsKeyFrame() const = 0;
}; };
} // namespace Codecs } // namespace Codecs
} // namespace RTC } // namespace RTC
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
Single octet PictureID (M = 0) Dual octet PictureID (M = 1) Single octet PictureID (M = 0) Dual octet PictureID (M = 1)
=============================== ============================ ============================== ============================
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+
...@@ -83,6 +83,7 @@ namespace RTC ...@@ -83,6 +83,7 @@ namespace RTC
class EncodingContext : public RTC::Codecs::EncodingContext class EncodingContext : public RTC::Codecs::EncodingContext
{ {
public: public:
EncodingContext(RTC::Codecs::EncodingContext::Params& params);
~EncodingContext() = default; ~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */ /* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
...@@ -104,7 +105,7 @@ namespace RTC ...@@ -104,7 +105,7 @@ namespace RTC
public: public:
void Dump() const override; void Dump() const override;
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data) override; bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
void Restore(uint8_t* data) override; void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override; uint8_t GetSpatialLayer() const override;
uint8_t GetTemporalLayer() const override; uint8_t GetTemporalLayer() const override;
...@@ -117,6 +118,11 @@ namespace RTC ...@@ -117,6 +118,11 @@ namespace RTC
/* Inline EncondingContext methods. */ /* Inline EncondingContext methods. */
inline VP8::EncodingContext::EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
inline void VP8::EncodingContext::SyncRequired() inline void VP8::EncodingContext::SyncRequired()
{ {
this->syncRequired = true; this->syncRequired = true;
......
#ifndef MS_RTC_CODECS_VP9_HPP
#define MS_RTC_CODECS_VP9_HPP
#include "common.hpp"
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/SeqManager.hpp"
/* https://tools.ietf.org/html/draft-ietf-payload-vp9-06
* VP9 Payload Descriptor
*
Flexible mode (with the F bit below set to 1)
=============================================
0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+
|I|P|L|F|B|E|V|-| (REQUIRED)
+-+-+-+-+-+-+-+-+
I: |M| PICTURE ID | (REQUIRED)
+-+-+-+-+-+-+-+-+
M: | EXTENDED PID | (RECOMMENDED)
+-+-+-+-+-+-+-+-+
L: | TID |U| SID |D| (CONDITIONALLY RECOMMENDED)
+-+-+-+-+-+-+-+-+ -\
P,F: | P_DIFF |N| (CONDITIONALLY REQUIRED) - up to 3 times
+-+-+-+-+-+-+-+-+ -/
V: | SS |
| .. |
+-+-+-+-+-+-+-+-+
Non-flexible mode (with the F bit below set to 0)
=================================================
0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+
|I|P|L|F|B|E|V|-| (REQUIRED)
+-+-+-+-+-+-+-+-+
I: |M| PICTURE ID | (RECOMMENDED)
+-+-+-+-+-+-+-+-+
M: | EXTENDED PID | (RECOMMENDED)
+-+-+-+-+-+-+-+-+
L: | TID |U| SID |D| (CONDITIONALLY RECOMMENDED)
+-+-+-+-+-+-+-+-+
| TL0PICIDX | (CONDITIONALLY REQUIRED)
+-+-+-+-+-+-+-+-+
V: | SS |
| .. |
+-+-+-+-+-+-+-+-+
*/
namespace RTC
{
namespace Codecs
{
class VP9
{
public:
struct PayloadDescriptor : public RTC::Codecs::PayloadDescriptor
{
/* Pure virtual methods inherited from RTC::Codecs::PayloadDescriptor. */
~PayloadDescriptor() = default;
void Dump() const override;
// Header.
uint8_t i : 1; // I: Picture ID (PID) present.
uint8_t p : 1; // P: Inter-picture predicted layer frame.
uint8_t l : 1; // L: Layer indices present.
uint8_t f : 1; // F: Flexible mode.
uint8_t b : 1; // B: Start of a layer frame.
uint8_t e : 1; // E: End of a layer frame.
uint8_t v : 1; // V: Scalability structure (SS) data present.
// Extension fields.
uint16_t pictureId{ 0 };
uint8_t slIndex{ 0 };
uint8_t tlIndex{ 0 };
uint8_t tl0PictureIndex;
uint8_t switchingUpPoint : 1;
uint8_t interLayerDependency : 1;
// Parsed values.
bool isKeyFrame{ false };
bool hasPictureId{ false };
bool hasOneBytePictureId{ false };
bool hasTwoBytesPictureId{ false };
bool hasSlIndex{ false };
bool hasTl0PictureIndex{ false };
bool hasTlIndex{ false };
};
public:
static VP9::PayloadDescriptor* Parse(
const uint8_t* data,
size_t len,
RTC::RtpPacket::FrameMarking* frameMarking = nullptr,
uint8_t frameMarkingLen = 0);
static void ProcessRtpPacket(RTC::RtpPacket* packet);
public:
class EncodingContext : public RTC::Codecs::EncodingContext
{
public:
EncodingContext(RTC::Codecs::EncodingContext::Params& params);
~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
public:
void SyncRequired() override;
public:
RTC::SeqManager<uint16_t> pictureIdManager;
bool syncRequired{ false };
};
class PayloadDescriptorHandler : public RTC::Codecs::PayloadDescriptorHandler
{
public:
explicit PayloadDescriptorHandler(PayloadDescriptor* payloadDescriptor);
~PayloadDescriptorHandler() = default;
public:
void Dump() const override;
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override;
uint8_t GetTemporalLayer() const override;
bool IsKeyFrame() const override;
private:
std::unique_ptr<PayloadDescriptor> payloadDescriptor;
};
};
/* Inline EncondingContext methods. */
inline VP9::EncodingContext::EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
inline void VP9::EncodingContext::SyncRequired()
{
this->syncRequired = true;
}
/* Inline PayloadDescriptorHandler methods. */
inline void VP9::PayloadDescriptorHandler::Dump() const
{
this->payloadDescriptor->Dump();
}
inline uint8_t VP9::PayloadDescriptorHandler::GetSpatialLayer() const
{
return this->payloadDescriptor->hasSlIndex ? this->payloadDescriptor->slIndex : 0u;
}
inline uint8_t VP9::PayloadDescriptorHandler::GetTemporalLayer() const
{
return this->payloadDescriptor->hasTlIndex ? this->payloadDescriptor->tlIndex : 0u;
}
inline bool VP9::PayloadDescriptorHandler::IsKeyFrame() const
{
return this->payloadDescriptor->isKeyFrame;
}
} // namespace Codecs
} // namespace RTC
#endif
...@@ -211,6 +211,7 @@ namespace RTC ...@@ -211,6 +211,7 @@ namespace RTC
std::string scalabilityMode; std::string scalabilityMode;
uint8_t spatialLayers{ 1 }; uint8_t spatialLayers{ 1 };
uint8_t temporalLayers{ 1 }; uint8_t temporalLayers{ 1 };
bool ksvc{ false };
}; };
class RtpHeaderExtensionParameters class RtpHeaderExtensionParameters
......
...@@ -79,9 +79,10 @@ namespace RTC ...@@ -79,9 +79,10 @@ namespace RTC
uint32_t jitter{ 0 }; uint32_t jitter{ 0 };
uint8_t firSeqNumber{ 0 }; uint8_t firSeqNumber{ 0 };
uint32_t reportedPacketLost{ 0 }; uint32_t reportedPacketLost{ 0 };
bool inactive{ false }; // Stream is inactive.
std::unique_ptr<RTC::NackGenerator> nackGenerator; std::unique_ptr<RTC::NackGenerator> nackGenerator;
Timer* inactivityCheckPeriodicTimer{ nullptr }; Timer* inactivityCheckPeriodicTimer{ nullptr };
bool inactive{ false }; // Stream is inactive.
uint64_t lastPacketAt{ 0 }; // Time last valid packet arrived.
TransmissionCounter transmissionCounter; TransmissionCounter transmissionCounter;
}; };
......
...@@ -72,7 +72,6 @@ namespace RTC ...@@ -72,7 +72,6 @@ namespace RTC
std::unordered_map<uint32_t, int16_t> mapMappedSsrcSpatialLayer; std::unordered_map<uint32_t, int16_t> mapMappedSsrcSpatialLayer;
std::vector<RTC::RtpStreamSend*> rtpStreams; std::vector<RTC::RtpStreamSend*> rtpStreams;
std::vector<RTC::RtpStream*> producerRtpStreams; // Indexed by spatial layer. std::vector<RTC::RtpStream*> producerRtpStreams; // Indexed by spatial layer.
bool keyFrameSupported{ false };
bool syncRequired{ false }; bool syncRequired{ false };
RTC::SeqManager<uint16_t> rtpSeqManager; RTC::SeqManager<uint16_t> rtpSeqManager;
int16_t preferredSpatialLayer{ -1 }; int16_t preferredSpatialLayer{ -1 };
......
#ifndef MS_RTC_SVC_CONSUMER_HPP
#define MS_RTC_SVC_CONSUMER_HPP
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/Consumer.hpp"
#include "RTC/RtpStreamSend.hpp"
#include "RTC/SeqManager.hpp"
#include <map>
namespace RTC
{
class SvcConsumer : public RTC::Consumer, public RTC::RtpStreamSend::Listener
{
public:
SvcConsumer(const std::string& id, RTC::Consumer::Listener* listener, json& data);
~SvcConsumer() override;
public:
void FillJson(json& jsonObject) const override;
void FillJsonStats(json& jsonArray) const override;
void FillJsonScore(json& jsonObject) const override;
void HandleRequest(Channel::Request* request) override;
bool IsActive() const override;
void ProducerRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerNewRtpStream(RTC::RtpStream* rtpStream, uint32_t mappedSsrc) override;
void ProducerRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override;
void ProducerRtcpSenderReport(RTC::RtpStream* rtpStream, bool first) override;
void SetExternallyManagedBitrate() override;
int16_t GetBitratePriority() const override;
uint32_t UseAvailableBitrate(uint32_t bitrate) override;
uint32_t IncreaseLayer(uint32_t bitrate) override;
void ApplyLayers() override;
void SendRtpPacket(RTC::RtpPacket* packet) override;
void SendProbationRtpPacket(uint16_t seq) override;
void GetRtcp(RTC::RTCP::CompoundPacket* packet, RTC::RtpStreamSend* rtpStream, uint64_t now) override;
std::vector<RTC::RtpStreamSend*> GetRtpStreams() override;
void NeedWorstRemoteFractionLost(uint32_t mappedSsrc, uint8_t& worstRemoteFractionLost) override;
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) override;
void ReceiveKeyFrameRequest(RTC::RTCP::FeedbackPs::MessageType messageType, uint32_t ssrc) override;
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report) override;
uint32_t GetTransmissionRate(uint64_t now) override;
private:
void UserOnTransportConnected() override;
void UserOnTransportDisconnected() override;
void UserOnPaused() override;
void UserOnResumed() override;
void CreateRtpStream();
void RequestKeyFrame();
void MayChangeLayers(bool force = false);
bool RecalculateTargetLayers(int16_t& newTargetSpatialLayer, int16_t& newTargetTemporalLayer) const;
void UpdateTargetLayers(int16_t newTargetSpatialLayer, int16_t newTargetTemporalLayer);
void EmitScore() const;
void EmitLayersChange() const;
/* Pure virtual methods inherited from RtpStreamSend::Listener. */
public:
void OnRtpStreamScore(RTC::RtpStream* rtpStream, uint8_t score, uint8_t previousScore) override;
void OnRtpStreamRetransmitRtpPacket(
RTC::RtpStreamSend* rtpStream, RTC::RtpPacket* packet, bool probation = false) override;
private:
// Allocated by this.
RTC::RtpStreamSend* rtpStream{ nullptr };
// Others.
std::vector<RTC::RtpStreamSend*> rtpStreams;
RTC::RtpStream* producerRtpStream{ nullptr };
bool syncRequired{ false };
RTC::SeqManager<uint16_t> rtpSeqManager;
int16_t preferredSpatialLayer{ -1 };
int16_t preferredTemporalLayer{ -1 };
int16_t provisionalTargetSpatialLayer{ -1 };
int16_t provisionalTargetTemporalLayer{ -1 };
std::unique_ptr<RTC::Codecs::EncodingContext> encodingContext;
bool externallyManagedBitrate{ false };
};
/* Inline methods. */
inline bool SvcConsumer::IsActive() const
{
return (RTC::Consumer::IsActive() && this->producerRtpStream);
}
inline std::vector<RTC::RtpStreamSend*> SvcConsumer::GetRtpStreams()
{
return this->rtpStreams;
}
} // namespace RTC
#endif
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
'src/RTC/SimulcastConsumer.cpp', 'src/RTC/SimulcastConsumer.cpp',
'src/RTC/SrtpSession.cpp', 'src/RTC/SrtpSession.cpp',
'src/RTC/StunMessage.cpp', 'src/RTC/StunMessage.cpp',
'src/RTC/SvcConsumer.cpp',
'src/RTC/TcpConnection.cpp', 'src/RTC/TcpConnection.cpp',
'src/RTC/TcpServer.cpp', 'src/RTC/TcpServer.cpp',
'src/RTC/Transport.cpp', 'src/RTC/Transport.cpp',
...@@ -63,6 +64,7 @@ ...@@ -63,6 +64,7 @@
'src/RTC/Codecs/Codecs.cpp', 'src/RTC/Codecs/Codecs.cpp',
'src/RTC/Codecs/H264.cpp', 'src/RTC/Codecs/H264.cpp',
'src/RTC/Codecs/VP8.cpp', 'src/RTC/Codecs/VP8.cpp',
'src/RTC/Codecs/VP9.cpp',
'src/RTC/RtpDictionaries/Media.cpp', 'src/RTC/RtpDictionaries/Media.cpp',
'src/RTC/RtpDictionaries/Parameters.cpp', 'src/RTC/RtpDictionaries/Parameters.cpp',
'src/RTC/RtpDictionaries/RtcpFeedback.cpp', 'src/RTC/RtpDictionaries/RtcpFeedback.cpp',
...@@ -152,6 +154,7 @@ ...@@ -152,6 +154,7 @@
'include/RTC/SimulcastConsumer.hpp', 'include/RTC/SimulcastConsumer.hpp',
'include/RTC/SrtpSession.hpp', 'include/RTC/SrtpSession.hpp',
'include/RTC/StunMessage.hpp', 'include/RTC/StunMessage.hpp',
'include/RTC/SvcConsumer.hpp',
'include/RTC/TcpConnection.hpp', 'include/RTC/TcpConnection.hpp',
'include/RTC/TcpServer.hpp', 'include/RTC/TcpServer.hpp',
'include/RTC/Transport.hpp', 'include/RTC/Transport.hpp',
...@@ -162,6 +165,7 @@ ...@@ -162,6 +165,7 @@
'include/RTC/Codecs/PayloadDescriptorHandler.hpp', 'include/RTC/Codecs/PayloadDescriptorHandler.hpp',
'include/RTC/Codecs/H264.hpp', 'include/RTC/Codecs/H264.hpp',
'include/RTC/Codecs/VP8.hpp', 'include/RTC/Codecs/VP8.hpp',
'include/RTC/Codecs/VP9.hpp',
'include/RTC/RTCP/Packet.hpp', 'include/RTC/RTCP/Packet.hpp',
'include/RTC/RTCP/CompoundPacket.hpp', 'include/RTC/RTCP/CompoundPacket.hpp',
'include/RTC/RTCP/SenderReport.hpp', 'include/RTC/RTCP/SenderReport.hpp',
......
...@@ -26,6 +26,13 @@ namespace RTC ...@@ -26,6 +26,13 @@ namespace RTC
break; break;
} }
case RTC::RtpCodecMimeType::Subtype::VP9:
{
RTC::Codecs::VP9::ProcessRtpPacket(packet);
break;
}
case RTC::RtpCodecMimeType::Subtype::H264: case RTC::RtpCodecMimeType::Subtype::H264:
{ {
RTC::Codecs::H264::ProcessRtpPacket(packet); RTC::Codecs::H264::ProcessRtpPacket(packet);
......
...@@ -32,6 +32,8 @@ namespace RTC ...@@ -32,6 +32,8 @@ namespace RTC
payloadDescriptor->b = frameMarking->base; payloadDescriptor->b = frameMarking->base;
payloadDescriptor->tid = frameMarking->tid; payloadDescriptor->tid = frameMarking->tid;
payloadDescriptor->hasTid = true;
if (frameMarkingLen >= 2) if (frameMarkingLen >= 2)
{ {
payloadDescriptor->hasLid = true; payloadDescriptor->hasLid = true;
...@@ -143,19 +145,22 @@ namespace RTC ...@@ -143,19 +145,22 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<PayloadDescriptor>"); MS_DUMP("<PayloadDescriptor>");
MS_DEBUG_DEV(" s : %s", this->s ? "true" : "false"); MS_DUMP(
MS_DEBUG_DEV(" e : %s", this->e ? "true" : "false"); " s:%" PRIu8 "|e:%" PRIu8 "|i:%" PRIu8 "|d:%" PRIu8 "|b:%" PRIu8,
MS_DEBUG_DEV(" i : %s", this->i ? "true" : "false"); this->s,
MS_DEBUG_DEV(" d : %s", this->d ? "true" : "false"); this->e,
MS_DEBUG_DEV(" b : %s", this->b ? "true" : "false"); this->i,
MS_DEBUG_DEV(" tid : %" PRIu8, this->tid); this->d,
this->b);
if (this->hasTid)
MS_DUMP(" tid : %" PRIu8, this->tid);
if (this->hasLid) if (this->hasLid)
MS_DEBUG_DEV(" lid : %" PRIu8, this->lid); MS_DUMP(" lid : %" PRIu8, this->lid);
if (this->hasTl0picidx) if (this->hasTl0picidx)
MS_DEBUG_DEV(" tl0picidx : %" PRIu8, this->tl0picidx); MS_DUMP(" tl0picidx : %" PRIu8, this->tl0picidx);
MS_DEBUG_DEV(" isKeyFrame : %s", this->isKeyFrame ? "true" : "false"); MS_DUMP(" isKeyFrame : %s", this->isKeyFrame ? "true" : "false");
MS_DEBUG_DEV("</PayloadDescriptor>"); MS_DUMP("</PayloadDescriptor>");
} }
H264::PayloadDescriptorHandler::PayloadDescriptorHandler(H264::PayloadDescriptor* payloadDescriptor) H264::PayloadDescriptorHandler::PayloadDescriptorHandler(H264::PayloadDescriptor* payloadDescriptor)
...@@ -166,7 +171,7 @@ namespace RTC ...@@ -166,7 +171,7 @@ namespace RTC
} }
bool H264::PayloadDescriptorHandler::Process( bool H264::PayloadDescriptorHandler::Process(
RTC::Codecs::EncodingContext* encodingContext, uint8_t* /*data*/) RTC::Codecs::EncodingContext* encodingContext, uint8_t* /*data*/, bool& /*marker*/)
{ {
MS_TRACE(); MS_TRACE();
...@@ -174,11 +179,20 @@ namespace RTC ...@@ -174,11 +179,20 @@ namespace RTC
MS_ASSERT(context->GetTargetTemporalLayer() >= 0, "target temporal layer cannot be -1"); MS_ASSERT(context->GetTargetTemporalLayer() >= 0, "target temporal layer cannot be -1");
// If a key frame, update current temporal layer. // Check if the payload should contain temporal layer info.
if (this->payloadDescriptor->isKeyFrame) if (context->GetTemporalLayers() > 1 && !this->payloadDescriptor->hasTid)
context->SetCurrentTemporalLayer(context->GetTargetTemporalLayer()); {
MS_WARN_TAG(rtp, "stream is supposed to have >1 temporal layers but does not have tid field");
return false;
}
if (this->payloadDescriptor->tid > context->GetTargetTemporalLayer()) // clang-format off
if (
this->payloadDescriptor->hasTid &&
this->payloadDescriptor->tid > context->GetTargetTemporalLayer()
)
// clang-format on
{ {
return false; return false;
} }
...@@ -188,6 +202,7 @@ namespace RTC ...@@ -188,6 +202,7 @@ namespace RTC
// //
// clang-format off // clang-format off
// else if ( // else if (
// this->payloadDescriptor->hasTid &&
// this->payloadDescriptor->tid > context->GetCurrentTemporalLayer() && // this->payloadDescriptor->tid > context->GetCurrentTemporalLayer() &&
// !this->payloadDescriptor->b // !this->payloadDescriptor->b
// ) // )
...@@ -197,8 +212,15 @@ namespace RTC ...@@ -197,8 +212,15 @@ namespace RTC
// } // }
// Update/fix current temporal layer. // Update/fix current temporal layer.
if (this->payloadDescriptor->tid > context->GetCurrentTemporalLayer()) // clang-format off
if (
this->payloadDescriptor->hasTid &&
this->payloadDescriptor->tid > context->GetCurrentTemporalLayer()
)
// clang-format on
{
context->SetCurrentTemporalLayer(this->payloadDescriptor->tid); context->SetCurrentTemporalLayer(this->payloadDescriptor->tid);
}
if (context->GetCurrentTemporalLayer() > context->GetTargetTemporalLayer()) if (context->GetCurrentTemporalLayer() > context->GetTargetTemporalLayer())
context->SetCurrentTemporalLayer(context->GetTargetTemporalLayer()); context->SetCurrentTemporalLayer(context->GetTargetTemporalLayer());
......
...@@ -95,9 +95,14 @@ namespace RTC ...@@ -95,9 +95,14 @@ namespace RTC
payloadDescriptor->keyIndex = byte & 0x1F; payloadDescriptor->keyIndex = byte & 0x1F;
} }
// clang-format off
if ( if (
(len >= ++offset + 1) && payloadDescriptor->start && (len >= ++offset + 1) &&
payloadDescriptor->partitionIndex == 0 && (!(data[offset] & 0x01))) payloadDescriptor->start &&
payloadDescriptor->partitionIndex == 0 &&
(!(data[offset] & 0x01))
)
// clang-format on
{ {
payloadDescriptor->isKeyFrame = true; payloadDescriptor->isKeyFrame = true;
} }
...@@ -147,29 +152,25 @@ namespace RTC ...@@ -147,29 +152,25 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<PayloadDescriptor>"); MS_DUMP("<PayloadDescriptor>");
MS_DEBUG_DEV(" extended : %" PRIu8, this->extended); MS_DUMP(
MS_DEBUG_DEV(" nonReference : %" PRIu8, this->nonReference); " i:%" PRIu8 "|l:%" PRIu8 "|t:%" PRIu8 "|k:%" PRIu8, this->i, this->l, this->t, this->k);
MS_DEBUG_DEV(" start : %" PRIu8, this->start); MS_DUMP(" extended : %" PRIu8, this->extended);
MS_DEBUG_DEV(" partitionIndex : %" PRIu8, this->partitionIndex); MS_DUMP(" nonReference : %" PRIu8, this->nonReference);
MS_DEBUG_DEV( MS_DUMP(" start : %" PRIu8, this->start);
" i|l|t|k : %" PRIu8 "|%" PRIu8 "|%" PRIu8 "|%" PRIu8, MS_DUMP(" partitionIndex : %" PRIu8, this->partitionIndex);
this->i, MS_DUMP(" pictureId : %" PRIu16, this->pictureId);
this->l, MS_DUMP(" tl0PictureIndex : %" PRIu8, this->tl0PictureIndex);
this->t, MS_DUMP(" tlIndex : %" PRIu8, this->tlIndex);
this->k); MS_DUMP(" y : %" PRIu8, this->y);
MS_DEBUG_DEV(" pictureId : %" PRIu16, this->pictureId); MS_DUMP(" keyIndex : %" PRIu8, this->keyIndex);
MS_DEBUG_DEV(" tl0PictureIndex : %" PRIu8, this->tl0PictureIndex); MS_DUMP(" isKeyFrame : %s", this->isKeyFrame ? "true" : "false");
MS_DEBUG_DEV(" tlIndex : %" PRIu8, this->tlIndex); MS_DUMP(" hasPictureId : %s", this->hasPictureId ? "true" : "false");
MS_DEBUG_DEV(" y : %" PRIu8, this->y); MS_DUMP(" hasOneBytePictureId : %s", this->hasOneBytePictureId ? "true" : "false");
MS_DEBUG_DEV(" keyIndex : %" PRIu8, this->keyIndex); MS_DUMP(" hasTwoBytesPictureId : %s", this->hasTwoBytesPictureId ? "true" : "false");
MS_DEBUG_DEV(" isKeyFrame : %s", this->isKeyFrame ? "true" : "false"); MS_DUMP(" hasTl0PictureIndex : %s", this->hasTl0PictureIndex ? "true" : "false");
MS_DEBUG_DEV(" hasPictureId : %s", this->hasPictureId ? "true" : "false"); MS_DUMP(" hasTlIndex : %s", this->hasTlIndex ? "true" : "false");
MS_DEBUG_DEV(" hasOneBytePictureId : %s", this->hasOneBytePictureId ? "true" : "false"); MS_DUMP("</PayloadDescriptor>");
MS_DEBUG_DEV(" hasTwoBytesPictureId : %s", this->hasTwoBytesPictureId ? "true" : "false");
MS_DEBUG_DEV(" hasTl0PictureIndex : %s", this->hasTl0PictureIndex ? "true" : "false");
MS_DEBUG_DEV(" hasTlIndex : %s", this->hasTlIndex ? "true" : "false");
MS_DEBUG_DEV("</PayloadDescriptor>");
} }
void VP8::PayloadDescriptor::Encode(uint8_t* data, uint16_t pictureId, uint8_t tl0PictureIndex) const void VP8::PayloadDescriptor::Encode(uint8_t* data, uint16_t pictureId, uint8_t tl0PictureIndex) const
...@@ -221,7 +222,7 @@ namespace RTC ...@@ -221,7 +222,7 @@ namespace RTC
} }
bool VP8::PayloadDescriptorHandler::Process( bool VP8::PayloadDescriptorHandler::Process(
RTC::Codecs::EncodingContext* encodingContext, uint8_t* data) RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& /*marker*/)
{ {
MS_TRACE(); MS_TRACE();
...@@ -229,6 +230,15 @@ namespace RTC ...@@ -229,6 +230,15 @@ namespace RTC
MS_ASSERT(context->GetTargetTemporalLayer() >= 0, "target temporal layer cannot be -1"); MS_ASSERT(context->GetTargetTemporalLayer() >= 0, "target temporal layer cannot be -1");
// Check if the payload should contain temporal layer info.
if (context->GetTemporalLayers() > 1 && !this->payloadDescriptor->hasTlIndex)
{
MS_WARN_TAG(
rtp, "stream is supposed to have >1 temporal layers but does not have TlIndex field");
return false;
}
// Check whether pictureId and tl0PictureIndex sync is required. // Check whether pictureId and tl0PictureIndex sync is required.
// clang-format off // clang-format off
if ( if (
...@@ -244,17 +254,13 @@ namespace RTC ...@@ -244,17 +254,13 @@ namespace RTC
context->syncRequired = false; context->syncRequired = false;
} }
// If a key frame, update current temporal layer.
if (this->payloadDescriptor->isKeyFrame)
context->SetCurrentTemporalLayer(context->GetTargetTemporalLayer());
// Incremental pictureId. Check the temporal layer. // Incremental pictureId. Check the temporal layer.
// clang-format off // clang-format off
if ( if (
this->payloadDescriptor->hasPictureId && this->payloadDescriptor->hasPictureId &&
this->payloadDescriptor->hasTlIndex && this->payloadDescriptor->hasTlIndex &&
this->payloadDescriptor->hasTl0PictureIndex && this->payloadDescriptor->hasTl0PictureIndex &&
RTC::SeqManager<uint16_t>::IsSeqHigherThan( !RTC::SeqManager<uint16_t>::IsSeqLowerThan(
this->payloadDescriptor->pictureId, this->payloadDescriptor->pictureId,
context->pictureIdManager.GetMaxInput()) context->pictureIdManager.GetMaxInput())
) )
...@@ -310,8 +316,15 @@ namespace RTC ...@@ -310,8 +316,15 @@ namespace RTC
} }
// Update/fix current temporal layer. // Update/fix current temporal layer.
if (this->payloadDescriptor->tlIndex > context->GetCurrentTemporalLayer()) // clang-format off
if (
this->payloadDescriptor->hasTlIndex &&
this->payloadDescriptor->tlIndex > context->GetCurrentTemporalLayer()
)
// clang-format on
{
context->SetCurrentTemporalLayer(this->payloadDescriptor->tlIndex); context->SetCurrentTemporalLayer(this->payloadDescriptor->tlIndex);
}
if (context->GetCurrentTemporalLayer() > context->GetTargetTemporalLayer()) if (context->GetCurrentTemporalLayer() > context->GetTargetTemporalLayer())
context->SetCurrentTemporalLayer(context->GetTargetTemporalLayer()); context->SetCurrentTemporalLayer(context->GetTargetTemporalLayer());
......
差异被折叠。
...@@ -278,6 +278,7 @@ namespace RTC ...@@ -278,6 +278,7 @@ namespace RTC
return; return;
error: error:
if (bne != nullptr) if (bne != nullptr)
BN_free(bne); BN_free(bne);
...@@ -338,6 +339,7 @@ namespace RTC ...@@ -338,6 +339,7 @@ namespace RTC
return; return;
error: error:
MS_THROW_ERROR("error reading DTLS certificate and private key PEM files"); MS_THROW_ERROR("error reading DTLS certificate and private key PEM files");
} }
...@@ -479,6 +481,7 @@ namespace RTC ...@@ -479,6 +481,7 @@ namespace RTC
return; return;
error: error:
if (DtlsTransport::sslCtx != nullptr) if (DtlsTransport::sslCtx != nullptr)
{ {
SSL_CTX_free(DtlsTransport::sslCtx); SSL_CTX_free(DtlsTransport::sslCtx);
...@@ -611,6 +614,7 @@ namespace RTC ...@@ -611,6 +614,7 @@ namespace RTC
return; return;
error: error:
// NOTE: At this point SSL_set_bio() was not called so we must free BIOs as // NOTE: At this point SSL_set_bio() was not called so we must free BIOs as
// well. // well.
if (this->sslBioFromNetwork != nullptr) if (this->sslBioFromNetwork != nullptr)
...@@ -655,15 +659,15 @@ namespace RTC ...@@ -655,15 +659,15 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<DtlsTransport>"); MS_DUMP("<DtlsTransport>");
MS_DEBUG_DEV( MS_DUMP(
" [role:%s, running:%s, handshake done:%s, connected:%s]", " [role:%s, running:%s, handshake done:%s, connected:%s]",
(this->localRole == Role::SERVER ? "server" (this->localRole == Role::SERVER ? "server"
: (this->localRole == Role::CLIENT ? "client" : "none")), : (this->localRole == Role::CLIENT ? "client" : "none")),
IsRunning() ? "yes" : "no", IsRunning() ? "yes" : "no",
this->handshakeDone ? "yes" : "no", this->handshakeDone ? "yes" : "no",
this->state == DtlsState::CONNECTED ? "yes" : "no"); this->state == DtlsState::CONNECTED ? "yes" : "no");
MS_DEBUG_DEV("</DtlsTransport>"); MS_DUMP("</DtlsTransport>");
} }
void DtlsTransport::Run(Role localRole) void DtlsTransport::Run(Role localRole)
......
...@@ -20,6 +20,11 @@ namespace RTC ...@@ -20,6 +20,11 @@ namespace RTC
if (this->rtpParameters.encodings.size() != this->consumableRtpEncodings.size()) if (this->rtpParameters.encodings.size() != this->consumableRtpEncodings.size())
MS_THROW_TYPE_ERROR("number of rtpParameters.encodings and consumableRtpEncodings do not match"); MS_THROW_TYPE_ERROR("number of rtpParameters.encodings and consumableRtpEncodings do not match");
auto& encoding = this->rtpParameters.encodings[0];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
this->keyFrameSupported = RTC::Codecs::CanBeKeyFrame(mediaCodec->mimeType);
// Create RtpStreamSend instances. // Create RtpStreamSend instances.
CreateRtpStreams(); CreateRtpStreams();
} }
...@@ -467,8 +472,6 @@ namespace RTC ...@@ -467,8 +472,6 @@ namespace RTC
if (rtxCodec && encoding.hasRtx) if (rtxCodec && encoding.hasRtx)
rtpStream->SetRtx(rtxCodec->payloadType, encoding.rtx.ssrc); rtpStream->SetRtx(rtxCodec->payloadType, encoding.rtx.ssrc);
this->keyFrameSupported = RTC::Codecs::CanBeKeyFrame(mediaCodec->mimeType);
this->mapMappedSsrcRtpStream[encoding.ssrc] = rtpStream; this->mapMappedSsrcRtpStream[encoding.ssrc] = rtpStream;
this->rtpStreams.push_back(rtpStream); this->rtpStreams.push_back(rtpStream);
this->mapRtpStreamSyncRequired[rtpStream] = false; this->mapRtpStreamSyncRequired[rtpStream] = false;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "MediaSoupErrors.hpp" #include "MediaSoupErrors.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/Notifier.hpp" #include "Channel/Notifier.hpp"
#include "RTC/Codecs/Codecs.hpp"
#include <cstring> // std::memcpy() #include <cstring> // std::memcpy()
namespace RTC namespace RTC
...@@ -40,6 +41,17 @@ namespace RTC ...@@ -40,6 +41,17 @@ namespace RTC
// Evaluate type. // Evaluate type.
this->type = RTC::RtpParameters::GetType(this->rtpParameters); this->type = RTC::RtpParameters::GetType(this->rtpParameters);
auto& encoding = this->rtpParameters.encodings[0];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
if (!RTC::Codecs::IsValidTypeForCodec(this->type, mediaCodec->mimeType))
{
MS_THROW_TYPE_ERROR(
"%s codec not supported for %s",
mediaCodec->mimeType.ToString().c_str(),
RTC::RtpParameters::GetTypeString(this->type).c_str());
}
auto jsonRtpMappingIt = data.find("rtpMapping"); auto jsonRtpMappingIt = data.find("rtpMapping");
if (jsonRtpMappingIt == data.end() || !jsonRtpMappingIt->is_object()) if (jsonRtpMappingIt == data.end() || !jsonRtpMappingIt->is_object())
......
...@@ -90,16 +90,14 @@ namespace RTC ...@@ -90,16 +90,14 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<ByePacket>"); MS_DUMP("<ByePacket>");
#ifdef MS_LOG_DEV
for (auto ssrc : this->ssrcs) for (auto ssrc : this->ssrcs)
{ {
MS_DEBUG_DEV(" ssrc : %" PRIu32, ssrc); MS_DUMP(" ssrc : %" PRIu32, ssrc);
} }
#endif
if (!this->reason.empty()) if (!this->reason.empty())
MS_DEBUG_DEV(" reason : %s", this->reason.c_str()); MS_DUMP(" reason : %s", this->reason.c_str());
MS_DEBUG_DEV("</ByePacket>"); MS_DUMP("</ByePacket>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -87,7 +87,7 @@ namespace RTC ...@@ -87,7 +87,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<CompoundPacket>"); MS_DUMP("<CompoundPacket>");
if (HasSenderReport()) if (HasSenderReport())
{ {
...@@ -104,7 +104,7 @@ namespace RTC ...@@ -104,7 +104,7 @@ namespace RTC
if (this->sdesPacket.GetCount() != 0u) if (this->sdesPacket.GetCount() != 0u)
this->sdesPacket.Dump(); this->sdesPacket.Dump();
MS_DEBUG_DEV("</CompoundPacket>"); MS_DUMP("</CompoundPacket>");
} }
void CompoundPacket::AddSenderReport(SenderReport* report) void CompoundPacket::AddSenderReport(SenderReport* report)
......
...@@ -88,9 +88,9 @@ namespace RTC ...@@ -88,9 +88,9 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV(" sender ssrc : %" PRIu32, GetSenderSsrc()); MS_DUMP(" sender ssrc : %" PRIu32, GetSenderSsrc());
MS_DEBUG_DEV(" media ssrc : %" PRIu32, GetMediaSsrc()); MS_DUMP(" media ssrc : %" PRIu32, GetMediaSsrc());
MS_DEBUG_DEV(" size : %zu", this->GetSize()); MS_DUMP(" size : %zu", this->GetSize());
} }
/* Specialization for Ps class. */ /* Specialization for Ps class. */
......
...@@ -83,13 +83,13 @@ namespace RTC ...@@ -83,13 +83,13 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<%s>", FeedbackPsPacket::MessageType2String(Item::messageType).c_str()); MS_DUMP("<%s>", FeedbackPsPacket::MessageType2String(Item::messageType).c_str());
FeedbackPsPacket::Dump(); FeedbackPsPacket::Dump();
for (auto* item : this->items) for (auto* item : this->items)
{ {
item->Dump(); item->Dump();
} }
MS_DEBUG_DEV("</%s>", FeedbackPsPacket::MessageType2String(Item::messageType).c_str()); MS_DUMP("</%s>", FeedbackPsPacket::MessageType2String(Item::messageType).c_str());
} }
// explicit instantiation to have all FeedbackRtpPacket definitions in this file. // explicit instantiation to have all FeedbackRtpPacket definitions in this file.
......
...@@ -60,9 +60,9 @@ namespace RTC ...@@ -60,9 +60,9 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackPsAfbPacket>"); MS_DUMP("<FeedbackPsAfbPacket>");
FeedbackPsPacket::Dump(); FeedbackPsPacket::Dump();
MS_DEBUG_DEV("</FeedbackPsAfbPacket>"); MS_DUMP("</FeedbackPsAfbPacket>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -41,10 +41,10 @@ namespace RTC ...@@ -41,10 +41,10 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackPsFirItem>"); MS_DUMP("<FeedbackPsFirItem>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, this->GetSsrc()); MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc());
MS_DEBUG_DEV(" sequence number : %" PRIu8, this->GetSequenceNumber()); MS_DUMP(" sequence number : %" PRIu8, this->GetSequenceNumber());
MS_DEBUG_DEV("</FeedbackPsFirItem>"); MS_DUMP("</FeedbackPsFirItem>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -33,9 +33,9 @@ namespace RTC ...@@ -33,9 +33,9 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackPsLeiItem>"); MS_DUMP("<FeedbackPsLeiItem>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, this->GetSsrc()); MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc());
MS_DEBUG_DEV("</FeedbackPsLeiItem>"); MS_DUMP("</FeedbackPsLeiItem>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -32,9 +32,9 @@ namespace RTC ...@@ -32,9 +32,9 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackPsPliPacket>"); MS_DUMP("<FeedbackPsPliPacket>");
FeedbackPsPacket::Dump(); FeedbackPsPacket::Dump();
MS_DEBUG_DEV("</FeedbackPsPliPacket>"); MS_DUMP("</FeedbackPsPliPacket>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -137,16 +137,14 @@ namespace RTC ...@@ -137,16 +137,14 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackPsRembPacket>"); MS_DUMP("<FeedbackPsRembPacket>");
FeedbackPsPacket::Dump(); FeedbackPsPacket::Dump();
MS_DEBUG_DEV(" bitrate (bps): %" PRIu64, this->bitrate); MS_DUMP(" bitrate (bps): %" PRIu64, this->bitrate);
#ifdef MS_LOG_DEV
for (auto ssrc : this->ssrcs) for (auto ssrc : this->ssrcs)
{ {
MS_DEBUG_DEV(" ssrc: %" PRIu32, ssrc); MS_DUMP(" ssrc: %" PRIu32, ssrc);
} }
#endif MS_DUMP("</FeedbackPsRembPacket>");
MS_DEBUG_DEV("</FeedbackPsRembPacket>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -76,11 +76,11 @@ namespace RTC ...@@ -76,11 +76,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackPsRpsiItem>"); MS_DUMP("<FeedbackPsRpsiItem>");
MS_DEBUG_DEV(" padding bits : %" PRIu8, this->header->paddingBits); MS_DUMP(" padding bits : %" PRIu8, this->header->paddingBits);
MS_DEBUG_DEV(" payload type : %" PRIu8, this->GetPayloadType()); MS_DUMP(" payload type : %" PRIu8, this->GetPayloadType());
MS_DEBUG_DEV(" length : %zu", this->GetLength()); MS_DUMP(" length : %zu", this->GetLength());
MS_DEBUG_DEV("</FeedbackPsRpsiItem>"); MS_DUMP("</FeedbackPsRpsiItem>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -39,11 +39,11 @@ namespace RTC ...@@ -39,11 +39,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackPsSliItem>"); MS_DUMP("<FeedbackPsSliItem>");
MS_DEBUG_DEV(" first : %" PRIu16, this->first); MS_DUMP(" first : %" PRIu16, this->first);
MS_DEBUG_DEV(" number : %" PRIu16, this->number); MS_DUMP(" number : %" PRIu16, this->number);
MS_DEBUG_DEV(" picture id : %" PRIu8, this->pictureId); MS_DUMP(" picture id : %" PRIu8, this->pictureId);
MS_DEBUG_DEV("</FeedbackPsSliItem>"); MS_DUMP("</FeedbackPsSliItem>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -40,11 +40,11 @@ namespace RTC ...@@ -40,11 +40,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackPsTstItem>"); MS_DUMP("<FeedbackPsTstItem>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, this->GetSsrc()); MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc());
MS_DEBUG_DEV(" sequence number : %" PRIu32, this->GetSequenceNumber()); MS_DUMP(" sequence number : %" PRIu32, this->GetSequenceNumber());
MS_DEBUG_DEV(" index : %" PRIu32, this->GetIndex()); MS_DUMP(" index : %" PRIu32, this->GetIndex());
MS_DEBUG_DEV("</FeedbackPsTstItem>"); MS_DUMP("</FeedbackPsTstItem>");
} }
/* Specialization for Tstr class. */ /* Specialization for Tstr class. */
......
...@@ -50,12 +50,12 @@ namespace RTC ...@@ -50,12 +50,12 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackPsVbcmItem>"); MS_DUMP("<FeedbackPsVbcmItem>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, this->GetSsrc()); MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc());
MS_DEBUG_DEV(" sequence number : %" PRIu8, this->GetSequenceNumber()); MS_DUMP(" sequence number : %" PRIu8, this->GetSequenceNumber());
MS_DEBUG_DEV(" payload type : %" PRIu8, this->GetPayloadType()); MS_DUMP(" payload type : %" PRIu8, this->GetPayloadType());
MS_DEBUG_DEV(" length : %" PRIu16, this->GetLength()); MS_DUMP(" length : %" PRIu16, this->GetLength());
MS_DEBUG_DEV("</FeedbackPsVbcmItem>"); MS_DUMP("</FeedbackPsVbcmItem>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -73,13 +73,13 @@ namespace RTC ...@@ -73,13 +73,13 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<%s>", FeedbackRtpPacket::MessageType2String(Item::messageType).c_str()); MS_DUMP("<%s>", FeedbackRtpPacket::MessageType2String(Item::messageType).c_str());
FeedbackRtpPacket::Dump(); FeedbackRtpPacket::Dump();
for (auto* item : this->items) for (auto* item : this->items)
{ {
item->Dump(); item->Dump();
} }
MS_DEBUG_DEV("</%s>", FeedbackRtpPacket::MessageType2String(Item::messageType).c_str()); MS_DUMP("</%s>", FeedbackRtpPacket::MessageType2String(Item::messageType).c_str());
} }
// Explicit instantiation to have all FeedbackRtpPacket definitions in this file. // Explicit instantiation to have all FeedbackRtpPacket definitions in this file.
......
...@@ -23,15 +23,15 @@ namespace RTC ...@@ -23,15 +23,15 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackRtpEcnItem>"); MS_DUMP("<FeedbackRtpEcnItem>");
MS_DEBUG_DEV(" sequence number : %" PRIu32, this->GetSequenceNumber()); MS_DUMP(" sequence number : %" PRIu32, this->GetSequenceNumber());
MS_DEBUG_DEV(" ect0 counter : %" PRIu32, this->GetEct0Counter()); MS_DUMP(" ect0 counter : %" PRIu32, this->GetEct0Counter());
MS_DEBUG_DEV(" ect1 counter : %" PRIu32, this->GetEct1Counter()); MS_DUMP(" ect1 counter : %" PRIu32, this->GetEct1Counter());
MS_DEBUG_DEV(" ecn ce counter : %" PRIu16, this->GetEcnCeCounter()); MS_DUMP(" ecn ce counter : %" PRIu16, this->GetEcnCeCounter());
MS_DEBUG_DEV(" not ect counter : %" PRIu16, this->GetNotEctCounter()); MS_DUMP(" not ect counter : %" PRIu16, this->GetNotEctCounter());
MS_DEBUG_DEV(" lost packets : %" PRIu16, this->GetLostPackets()); MS_DUMP(" lost packets : %" PRIu16, this->GetLostPackets());
MS_DEBUG_DEV(" duplicated packets : %" PRIu16, this->GetDuplicatedPackets()); MS_DUMP(" duplicated packets : %" PRIu16, this->GetDuplicatedPackets());
MS_DEBUG_DEV("</FeedbackRtpEcnItem>"); MS_DUMP("</FeedbackRtpEcnItem>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -36,10 +36,10 @@ namespace RTC ...@@ -36,10 +36,10 @@ namespace RTC
std::bitset<16> nackBitset(this->GetLostPacketBitmask()); std::bitset<16> nackBitset(this->GetLostPacketBitmask());
MS_DEBUG_DEV("<FeedbackRtpNackItem>"); MS_DUMP("<FeedbackRtpNackItem>");
MS_DEBUG_DEV(" pid : %" PRIu16, this->GetPacketId()); MS_DUMP(" pid : %" PRIu16, this->GetPacketId());
MS_DEBUG_DEV(" bpl : %s", nackBitset.to_string().c_str()); MS_DUMP(" bpl : %s", nackBitset.to_string().c_str());
MS_DEBUG_DEV("</FeedbackRtpNackItem>"); MS_DUMP("</FeedbackRtpNackItem>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -30,9 +30,9 @@ namespace RTC ...@@ -30,9 +30,9 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackRtpSrReqPacket>"); MS_DUMP("<FeedbackRtpSrReqPacket>");
FeedbackRtpPacket::Dump(); FeedbackRtpPacket::Dump();
MS_DEBUG_DEV("</FeedbackRtpSrReqPacket>"); MS_DUMP("</FeedbackRtpSrReqPacket>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -33,10 +33,10 @@ namespace RTC ...@@ -33,10 +33,10 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackRtpTlleiItem>"); MS_DUMP("<FeedbackRtpTlleiItem>");
MS_DEBUG_DEV(" pid: %" PRIu16, this->GetPacketId()); MS_DUMP(" pid: %" PRIu16, this->GetPacketId());
MS_DEBUG_DEV(" bpl: %" PRIu16, this->GetLostPacketBitmask()); MS_DUMP(" bpl: %" PRIu16, this->GetLostPacketBitmask());
MS_DEBUG_DEV("</FeedbackRtpTlleiItem>"); MS_DUMP("</FeedbackRtpTlleiItem>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -68,11 +68,11 @@ namespace RTC ...@@ -68,11 +68,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<FeedbackRtpTmmbItem>"); MS_DUMP("<FeedbackRtpTmmbItem>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, this->GetSsrc()); MS_DUMP(" ssrc : %" PRIu32, this->GetSsrc());
MS_DEBUG_DEV(" bitrate : %" PRIu64, this->GetBitrate()); MS_DUMP(" bitrate : %" PRIu64, this->GetBitrate());
MS_DEBUG_DEV(" overhead : %" PRIu16, this->GetOverhead()); MS_DUMP(" overhead : %" PRIu16, this->GetOverhead());
MS_DEBUG_DEV("</FeedbackRtpTmmbItem>"); MS_DUMP("</FeedbackRtpTmmbItem>");
} }
/* Specialization for Tmmbr class. */ /* Specialization for Tmmbr class. */
......
...@@ -36,15 +36,15 @@ namespace RTC ...@@ -36,15 +36,15 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<ReceiverReport>"); MS_DUMP("<ReceiverReport>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, GetSsrc()); MS_DUMP(" ssrc : %" PRIu32, GetSsrc());
MS_DEBUG_DEV(" fraction lost : %" PRIu8, GetFractionLost()); MS_DUMP(" fraction lost : %" PRIu8, GetFractionLost());
MS_DEBUG_DEV(" total lost : %" PRIu32, GetTotalLost()); MS_DUMP(" total lost : %" PRIu32, GetTotalLost());
MS_DEBUG_DEV(" last seq : %" PRIu32, GetLastSeq()); MS_DUMP(" last seq : %" PRIu32, GetLastSeq());
MS_DEBUG_DEV(" jitter : %" PRIu32, GetJitter()); MS_DUMP(" jitter : %" PRIu32, GetJitter());
MS_DEBUG_DEV(" lsr : %" PRIu32, GetLastSenderReport()); MS_DUMP(" lsr : %" PRIu32, GetLastSenderReport());
MS_DEBUG_DEV(" dlsr : %" PRIu32, GetDelaySinceLastSenderReport()); MS_DUMP(" dlsr : %" PRIu32, GetDelaySinceLastSenderReport());
MS_DEBUG_DEV("</ReceiverReport>"); MS_DUMP("</ReceiverReport>");
} }
size_t ReceiverReport::Serialize(uint8_t* buffer) size_t ReceiverReport::Serialize(uint8_t* buffer)
...@@ -133,13 +133,13 @@ namespace RTC ...@@ -133,13 +133,13 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<ReceiverReportPacket>"); MS_DUMP("<ReceiverReportPacket>");
MS_DEBUG_DEV(" ssrc: %" PRIu32, static_cast<uint32_t>(ntohl(this->ssrc))); MS_DUMP(" ssrc: %" PRIu32, static_cast<uint32_t>(ntohl(this->ssrc)));
for (auto* report : this->reports) for (auto* report : this->reports)
{ {
report->Dump(); report->Dump();
} }
MS_DEBUG_DEV("</ReceiverReportPacket>"); MS_DUMP("</ReceiverReportPacket>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -87,11 +87,11 @@ namespace RTC ...@@ -87,11 +87,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<SdesItem>"); MS_DUMP("<SdesItem>");
MS_DEBUG_DEV(" type : %s", SdesItem::Type2String(this->GetType()).c_str()); MS_DUMP(" type : %s", SdesItem::Type2String(this->GetType()).c_str());
MS_DEBUG_DEV(" length : %" PRIu8, this->header->length); MS_DUMP(" length : %" PRIu8, this->header->length);
MS_DEBUG_DEV(" value : %.*s", this->header->length, this->header->value); MS_DUMP(" value : %.*s", this->header->length, this->header->value);
MS_DEBUG_DEV("</SdesItem>"); MS_DUMP("</SdesItem>");
} }
size_t SdesItem::Serialize(uint8_t* buffer) size_t SdesItem::Serialize(uint8_t* buffer)
...@@ -169,13 +169,13 @@ namespace RTC ...@@ -169,13 +169,13 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<SdesChunk>"); MS_DUMP("<SdesChunk>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, static_cast<uint32_t>(ntohl(this->ssrc))); MS_DUMP(" ssrc : %" PRIu32, static_cast<uint32_t>(ntohl(this->ssrc)));
for (auto* item : this->items) for (auto* item : this->items)
{ {
item->Dump(); item->Dump();
} }
MS_DEBUG_DEV("</SdesChunk>"); MS_DUMP("</SdesChunk>");
} }
/* Class methods. */ /* Class methods. */
...@@ -228,12 +228,12 @@ namespace RTC ...@@ -228,12 +228,12 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<SdesPacket>"); MS_DUMP("<SdesPacket>");
for (auto* chunk : this->chunks) for (auto* chunk : this->chunks)
{ {
chunk->Dump(); chunk->Dump();
} }
MS_DEBUG_DEV("</SdesPacket>"); MS_DUMP("</SdesPacket>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -35,14 +35,14 @@ namespace RTC ...@@ -35,14 +35,14 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<SenderReport>"); MS_DUMP("<SenderReport>");
MS_DEBUG_DEV(" ssrc : %" PRIu32, GetSsrc()); MS_DUMP(" ssrc : %" PRIu32, GetSsrc());
MS_DEBUG_DEV(" ntp sec : %" PRIu32, GetNtpSec()); MS_DUMP(" ntp sec : %" PRIu32, GetNtpSec());
MS_DEBUG_DEV(" ntp frac : %" PRIu32, GetNtpFrac()); MS_DUMP(" ntp frac : %" PRIu32, GetNtpFrac());
MS_DEBUG_DEV(" rtp ts : %" PRIu32, GetRtpTs()); MS_DUMP(" rtp ts : %" PRIu32, GetRtpTs());
MS_DEBUG_DEV(" packet count : %" PRIu32, GetPacketCount()); MS_DUMP(" packet count : %" PRIu32, GetPacketCount());
MS_DEBUG_DEV(" octet count : %" PRIu32, GetOctetCount()); MS_DUMP(" octet count : %" PRIu32, GetOctetCount());
MS_DEBUG_DEV("</SenderReport>"); MS_DUMP("</SenderReport>");
} }
size_t SenderReport::Serialize(uint8_t* buffer) size_t SenderReport::Serialize(uint8_t* buffer)
...@@ -97,12 +97,12 @@ namespace RTC ...@@ -97,12 +97,12 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<SenderReportPacket>"); MS_DUMP("<SenderReportPacket>");
for (auto* report : this->reports) for (auto* report : this->reports)
{ {
report->Dump(); report->Dump();
} }
MS_DEBUG_DEV("</SenderReportPacket>"); MS_DUMP("</SenderReportPacket>");
} }
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
...@@ -68,7 +68,7 @@ namespace RTC ...@@ -68,7 +68,7 @@ namespace RTC
std::string scalabilityMode = jsonScalabilityModeIt->get<std::string>(); std::string scalabilityMode = jsonScalabilityModeIt->get<std::string>();
static const std::regex ScalabilityModeRegex( static const std::regex ScalabilityModeRegex(
"^[LS](\\d+)T(\\d+).*", std::regex_constants::ECMAScript); "^[LS]([1-9]\\d{0,1})T([1-9]\\d{0,1})(_KEY)?.*", std::regex_constants::ECMAScript);
std::smatch match; std::smatch match;
...@@ -82,6 +82,7 @@ namespace RTC ...@@ -82,6 +82,7 @@ namespace RTC
{ {
this->spatialLayers = std::stoul(match[1].str()); this->spatialLayers = std::stoul(match[1].str());
this->temporalLayers = std::stoul(match[2].str()); this->temporalLayers = std::stoul(match[2].str());
this->ksvc = match.size() >= 4 && match[3].str() == "_KEY";
} }
catch (std::exception& e) catch (std::exception& e)
{ {
...@@ -132,6 +133,7 @@ namespace RTC ...@@ -132,6 +133,7 @@ namespace RTC
jsonObject["scalabilityMode"] = this->scalabilityMode; jsonObject["scalabilityMode"] = this->scalabilityMode;
jsonObject["spatialLayers"] = this->spatialLayers; jsonObject["spatialLayers"] = this->spatialLayers;
jsonObject["temporalLayers"] = this->temporalLayers; jsonObject["temporalLayers"] = this->temporalLayers;
jsonObject["ksvc"] = this->ksvc;
} }
} }
} // namespace RTC } // namespace RTC
...@@ -35,12 +35,19 @@ namespace RTC ...@@ -35,12 +35,19 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// TODO: This is very basic and must be updated to detect SVC and so on.
if (rtpParameters.encodings.size() == 1) if (rtpParameters.encodings.size() == 1)
return RtpParameters::Type::SIMPLE; {
auto& encoding = rtpParameters.encodings[0];
if (encoding.spatialLayers > 1 || encoding.temporalLayers > 1)
return RtpParameters::Type::SVC;
else
return RtpParameters::Type::SIMPLE;
}
else if (rtpParameters.encodings.size() > 1) else if (rtpParameters.encodings.size() > 1)
{
return RtpParameters::Type::SIMULCAST; return RtpParameters::Type::SIMULCAST;
}
return RtpParameters::Type::NONE; return RtpParameters::Type::NONE;
} }
......
...@@ -153,22 +153,22 @@ namespace RTC ...@@ -153,22 +153,22 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<RtpPacket>"); MS_DUMP("<RtpPacket>");
MS_DEBUG_DEV(" padding : %s", this->header->padding ? "true" : "false"); MS_DUMP(" padding : %s", this->header->padding ? "true" : "false");
if (HasHeaderExtension()) if (HasHeaderExtension())
{ {
MS_DEBUG_DEV( MS_DUMP(
" header extension : id:%" PRIu16 ",length:%zu", " header extension : id:%" PRIu16 ",length:%zu",
GetHeaderExtensionId(), GetHeaderExtensionId(),
GetHeaderExtensionLength()); GetHeaderExtensionLength());
} }
if (HasOneByteExtensions()) if (HasOneByteExtensions())
{ {
MS_DEBUG_DEV(" RFC5285 ext style : One-Byte Header"); MS_DUMP(" RFC5285 ext style : One-Byte Header");
} }
if (HasTwoBytesExtensions()) if (HasTwoBytesExtensions())
{ {
MS_DEBUG_DEV(" RFC5285 ext style : Two-Bytes Header"); MS_DUMP(" RFC5285 ext style : Two-Bytes Header");
} }
if (HasOneByteExtensions() || HasTwoBytesExtensions()) if (HasOneByteExtensions() || HasTwoBytesExtensions())
{ {
...@@ -200,7 +200,7 @@ namespace RTC ...@@ -200,7 +200,7 @@ namespace RTC
extIds.begin(), extIds.end() - 1, std::ostream_iterator<std::string>(extIdsStream, ",")); extIds.begin(), extIds.end() - 1, std::ostream_iterator<std::string>(extIdsStream, ","));
extIdsStream << extIds.back(); extIdsStream << extIds.back();
MS_DEBUG_DEV(" RFC5285 ext ids : %s", extIdsStream.str().c_str()); MS_DUMP(" RFC5285 ext ids : %s", extIdsStream.str().c_str());
} }
} }
if (this->midExtensionId != 0u) if (this->midExtensionId != 0u)
...@@ -208,37 +208,34 @@ namespace RTC ...@@ -208,37 +208,34 @@ namespace RTC
std::string mid; std::string mid;
if (ReadMid(mid)) if (ReadMid(mid))
MS_DEBUG_DEV( MS_DUMP(" mid : extId:%" PRIu8 ",value:%s", this->midExtensionId, mid.c_str());
" mid : extId:%" PRIu8 ",value:%s", this->midExtensionId, mid.c_str());
} }
if (this->ridExtensionId != 0u) if (this->ridExtensionId != 0u)
{ {
std::string rid; std::string rid;
if (ReadRid(rid)) if (ReadRid(rid))
MS_DEBUG_DEV( MS_DUMP(" rid : extId:%" PRIu8 ",value:%s", this->ridExtensionId, rid.c_str());
" rid : extId:%" PRIu8 ",value:%s", this->ridExtensionId, rid.c_str());
} }
if (this->rridExtensionId != 0u) if (this->rridExtensionId != 0u)
{ {
std::string rid; std::string rid;
if (ReadRid(rid)) if (ReadRid(rid))
MS_DEBUG_DEV( MS_DUMP(" rrid : extId:%" PRIu8 ",value:%s", this->rridExtensionId, rid.c_str());
" rrid : extId:%" PRIu8 ",value:%s", this->rridExtensionId, rid.c_str());
} }
if (this->absSendTimeExtensionId != 0u) if (this->absSendTimeExtensionId != 0u)
{ {
MS_DEBUG_DEV(" absSendTime : extId:%" PRIu8, this->absSendTimeExtensionId); MS_DUMP(" absSendTime : extId:%" PRIu8, this->absSendTimeExtensionId);
} }
// Remove once it becomes RFC. // Remove once it becomes RFC.
if (this->frameMarking07ExtensionId != 0u) if (this->frameMarking07ExtensionId != 0u)
{ {
MS_DEBUG_DEV(" frameMarking07 : extId:%" PRIu8, this->frameMarking07ExtensionId); MS_DUMP(" frameMarking07 : extId:%" PRIu8, this->frameMarking07ExtensionId);
} }
if (this->frameMarkingExtensionId != 0u) if (this->frameMarkingExtensionId != 0u)
{ {
MS_DEBUG_DEV(" frameMarking : extId:%" PRIu8, this->frameMarkingExtensionId); MS_DUMP(" frameMarking : extId:%" PRIu8, this->frameMarkingExtensionId);
} }
if (this->ssrcAudioLevelExtensionId != 0u) if (this->ssrcAudioLevelExtensionId != 0u)
{ {
...@@ -246,11 +243,13 @@ namespace RTC ...@@ -246,11 +243,13 @@ namespace RTC
bool voice; bool voice;
if (ReadSsrcAudioLevel(volume, voice)) if (ReadSsrcAudioLevel(volume, voice))
MS_DEBUG_DEV( {
MS_DUMP(
" ssrcAudioLevel : extId:%" PRIu8 ",volume:%" PRIu8 ",voice:%s", " ssrcAudioLevel : extId:%" PRIu8 ",volume:%" PRIu8 ",voice:%s",
this->ssrcAudioLevelExtensionId, this->ssrcAudioLevelExtensionId,
volume, volume,
voice ? "true" : "false"); voice ? "true" : "false");
}
} }
if (this->videoOrientationExtensionId != 0u) if (this->videoOrientationExtensionId != 0u)
{ {
...@@ -259,26 +258,30 @@ namespace RTC ...@@ -259,26 +258,30 @@ namespace RTC
uint16_t rotation; uint16_t rotation;
if (ReadVideoOrientation(camera, flip, rotation)) if (ReadVideoOrientation(camera, flip, rotation))
MS_DEBUG_DEV( {
MS_DUMP(
" videoOrientation : extId:%" PRIu8 ",camera:%s,flip:%s,rotation:%" PRIu16, " videoOrientation : extId:%" PRIu8 ",camera:%s,flip:%s,rotation:%" PRIu16,
this->videoOrientationExtensionId, this->videoOrientationExtensionId,
camera ? "true" : "false", camera ? "true" : "false",
flip ? "true" : "false", flip ? "true" : "false",
rotation); rotation);
}
} }
MS_DEBUG_DEV(" csrc count : %" PRIu8, this->header->csrcCount); MS_DUMP(" csrc count : %" PRIu8, this->header->csrcCount);
MS_DEBUG_DEV(" marker : %s", HasMarker() ? "true" : "false"); MS_DUMP(" marker : %s", HasMarker() ? "true" : "false");
MS_DEBUG_DEV(" payload type : %" PRIu8, GetPayloadType()); MS_DUMP(" payload type : %" PRIu8, GetPayloadType());
MS_DEBUG_DEV(" sequence number : %" PRIu16, GetSequenceNumber()); MS_DUMP(" sequence number : %" PRIu16, GetSequenceNumber());
MS_DEBUG_DEV(" timestamp : %" PRIu32, GetTimestamp()); MS_DUMP(" timestamp : %" PRIu32, GetTimestamp());
MS_DEBUG_DEV(" ssrc : %" PRIu32, GetSsrc()); MS_DUMP(" ssrc : %" PRIu32, GetSsrc());
MS_DEBUG_DEV(" payload size : %zu bytes", GetPayloadLength()); MS_DUMP(" payload size : %zu bytes", GetPayloadLength());
if (this->header->padding != 0u) if (this->header->padding != 0u)
{ {
MS_DEBUG_DEV(" padding size : %" PRIu8 " bytes", this->payloadPadding); MS_DUMP(" padding size : %" PRIu8 " bytes", this->payloadPadding);
} }
MS_DEBUG_DEV(" packet size : %zu bytes", GetSize()); MS_DUMP(" packet size : %zu bytes", GetSize());
MS_DEBUG_DEV("</RtpPacket>"); MS_DUMP(" spatial layer : %" PRIu8, GetSpatialLayer());
MS_DUMP(" temporal layer : %" PRIu8, GetTemporalLayer());
MS_DUMP("</RtpPacket>");
} }
void RtpPacket::SetExtensions(uint8_t type, const std::vector<GenericExtension>& extensions) void RtpPacket::SetExtensions(uint8_t type, const std::vector<GenericExtension>& extensions)
...@@ -598,7 +601,19 @@ namespace RTC ...@@ -598,7 +601,19 @@ namespace RTC
if (!this->payloadDescriptorHandler) if (!this->payloadDescriptorHandler)
return true; return true;
return this->payloadDescriptorHandler->Process(context, this->payload); bool marker{ false };
if (this->payloadDescriptorHandler->Process(context, this->payload, marker))
{
if (marker)
SetMarker(true);
return true;
}
else
{
return false;
}
} }
void RtpPacket::RestorePayload() void RtpPacket::RestorePayload()
......
...@@ -9,10 +9,6 @@ ...@@ -9,10 +9,6 @@
namespace RTC namespace RTC
{ {
/* Static. */
static constexpr uint16_t InactivityCheckPeriod{ 250 };
/* TransmissionCounter methods. */ /* TransmissionCounter methods. */
RtpStreamRecv::TransmissionCounter::TransmissionCounter(uint8_t spatialLayers, uint8_t temporalLayers) RtpStreamRecv::TransmissionCounter::TransmissionCounter(uint8_t spatialLayers, uint8_t temporalLayers)
...@@ -69,29 +65,19 @@ namespace RTC ...@@ -69,29 +65,19 @@ namespace RTC
uint32_t rate{ 0u }; uint32_t rate{ 0u };
// clang-format off // Return 0 if specified layers are not being received.
for ( {
uint8_t spatialLayerIdx{ 0u }; auto& counter = this->spatialLayerCounters[spatialLayer][temporalLayer];
(
spatialLayerIdx < this->spatialLayerCounters.size() && if (counter.GetBitrate(now) == 0)
spatialLayerIdx <= spatialLayer return 0u;
); }
++spatialLayerIdx
) for (uint8_t sIdx{ 0u }; sIdx <= spatialLayer; ++sIdx)
// clang-format on
{ {
// clang-format off for (uint8_t tIdx{ 0u }; tIdx <= temporalLayer; ++tIdx)
for (
uint8_t temporalLayerIdx{ 0u };
(
temporalLayerIdx < this->spatialLayerCounters[spatialLayerIdx].size() &&
(spatialLayerIdx < spatialLayer || temporalLayerIdx <= temporalLayer)
);
++temporalLayerIdx
)
// clang-format on
{ {
auto& temporalLayerCounter = this->spatialLayerCounters[spatialLayerIdx][temporalLayerIdx]; auto& temporalLayerCounter = this->spatialLayerCounters[sIdx][tIdx];
rate += temporalLayerCounter.GetBitrate(now); rate += temporalLayerCounter.GetBitrate(now);
} }
...@@ -154,14 +140,15 @@ namespace RTC ...@@ -154,14 +140,15 @@ namespace RTC
if (this->params.useNack) if (this->params.useNack)
this->nackGenerator.reset(new RTC::NackGenerator(this)); this->nackGenerator.reset(new RTC::NackGenerator(this));
// Set the RTP inactivity check periodic timer.
this->inactivityCheckPeriodicTimer = new Timer(this);
// Run the RTP inactivity periodic timer (unless DTX is enabled). // Run the RTP inactivity periodic timer (unless DTX is enabled).
if (!this->params.useDtx) if (!this->params.useDtx)
{ {
this->inactive = false; this->inactivityCheckPeriodicTimer = new Timer(this);
this->inactivityCheckPeriodicTimer->Start(InactivityCheckPeriod, InactivityCheckPeriod);
// First check on 2 seconds, then every 150 ms.
this->inactivityCheckPeriodicTimer->Start(2000, 150);
this->inactive = false;
this->lastPacketAt = DepLibUV::GetTime();
} }
} }
...@@ -238,21 +225,24 @@ namespace RTC ...@@ -238,21 +225,24 @@ namespace RTC
} }
} }
// Ensure the inactivityCheckPeriodicTimer runs (unless DTX is enabled).
if (!this->params.useDtx && !this->inactivityCheckPeriodicTimer->IsActive())
{
this->inactive = false;
this->inactivityCheckPeriodicTimer->Restart();
ResetScore(10, true);
}
// Calculate Jitter. // Calculate Jitter.
CalculateJitter(packet->GetTimestamp()); CalculateJitter(packet->GetTimestamp());
// Increase transmission counter. // Increase transmission counter.
this->transmissionCounter.Update(packet); this->transmissionCounter.Update(packet);
// Ensure the inactivityCheckPeriodicTimer runs.
if (this->inactivityCheckPeriodicTimer && this->inactive)
{
this->inactivityCheckPeriodicTimer->Restart();
this->inactive = false;
ResetScore(10, /*notify*/ true);
}
// Update last packet arrival.
this->lastPacketAt = DepLibUV::GetTime();
return true; return true;
} }
...@@ -337,6 +327,18 @@ namespace RTC ...@@ -337,6 +327,18 @@ namespace RTC
// Increase transmission counter. // Increase transmission counter.
this->transmissionCounter.Update(packet); this->transmissionCounter.Update(packet);
// Ensure the inactivityCheckPeriodicTimer runs.
if (this->inactivityCheckPeriodicTimer && this->inactive)
{
this->inactivityCheckPeriodicTimer->Restart();
this->inactive = false;
ResetScore(10, /*notify*/ true);
}
// Update last packet arrival.
this->lastPacketAt = DepLibUV::GetTime();
return true; return true;
} }
...@@ -498,19 +500,18 @@ namespace RTC ...@@ -498,19 +500,18 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
this->inactive = true; if (this->inactivityCheckPeriodicTimer)
this->inactivityCheckPeriodicTimer->Stop(); this->inactivityCheckPeriodicTimer->Stop();
} }
void RtpStreamRecv::Resume() void RtpStreamRecv::Resume()
{ {
MS_TRACE(); MS_TRACE();
// Restart the RTP inactivity periodic timer (unless DTX is enabled). if (this->inactivityCheckPeriodicTimer && !this->inactive)
if (!this->params.useDtx)
{ {
this->inactive = false;
this->inactivityCheckPeriodicTimer->Restart(); this->inactivityCheckPeriodicTimer->Restart();
this->lastPacketAt = DepLibUV::GetTime();
} }
} }
...@@ -648,18 +649,17 @@ namespace RTC ...@@ -648,18 +649,17 @@ namespace RTC
if (timer == this->inactivityCheckPeriodicTimer) if (timer == this->inactivityCheckPeriodicTimer)
{ {
auto now = DepLibUV::GetTime(); auto diff = DepLibUV::GetTime() - this->lastPacketAt;
// If no RTP is being received reset the score. if (diff > 400)
if (this->transmissionCounter.GetBitrate(now) == 0)
{ {
this->inactive = true;
this->inactivityCheckPeriodicTimer->Stop(); this->inactivityCheckPeriodicTimer->Stop();
this->inactive = true;
if (GetScore() != 0) if (GetScore() != 0)
MS_WARN_2TAGS(rtp, score, "RTP inactivity detected, resetting score to 0"); MS_WARN_2TAGS(rtp, score, "RTP inactivity detected, resetting score to 0");
ResetScore(0, true); ResetScore(0, /*notify*/ true);
} }
} }
} }
......
...@@ -82,7 +82,7 @@ namespace RTC ...@@ -82,7 +82,7 @@ namespace RTC
if (it != this->dropped.end()) if (it != this->dropped.end())
{ {
MS_WARN_TAG(rtp, "trying to send a dropped input"); MS_DEBUG_DEV("trying to send a dropped input");
return false; return false;
} }
......
...@@ -21,6 +21,11 @@ namespace RTC ...@@ -21,6 +21,11 @@ namespace RTC
if (this->consumableRtpEncodings.size() != 1) if (this->consumableRtpEncodings.size() != 1)
MS_THROW_TYPE_ERROR("invalid consumableRtpEncodings with size != 1"); MS_THROW_TYPE_ERROR("invalid consumableRtpEncodings with size != 1");
auto& encoding = this->rtpParameters.encodings[0];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
this->keyFrameSupported = RTC::Codecs::CanBeKeyFrame(mediaCodec->mimeType);
// Create RtpStreamSend instance for sending a single stream to the remote. // Create RtpStreamSend instance for sending a single stream to the remote.
CreateRtpStream(); CreateRtpStream();
} }
...@@ -308,11 +313,7 @@ namespace RTC ...@@ -308,11 +313,7 @@ namespace RTC
this->syncRequired = true; this->syncRequired = true;
if (IsActive()) if (IsActive())
{
this->rtpStream->Resume();
RequestKeyFrame(); RequestKeyFrame();
}
} }
void SimpleConsumer::UserOnTransportDisconnected() void SimpleConsumer::UserOnTransportDisconnected()
...@@ -336,11 +337,7 @@ namespace RTC ...@@ -336,11 +337,7 @@ namespace RTC
this->syncRequired = true; this->syncRequired = true;
if (IsActive()) if (IsActive())
{
this->rtpStream->Resume();
RequestKeyFrame(); RequestKeyFrame();
}
} }
void SimpleConsumer::CreateRtpStream() void SimpleConsumer::CreateRtpStream()
...@@ -422,8 +419,6 @@ namespace RTC ...@@ -422,8 +419,6 @@ namespace RTC
if (rtxCodec && encoding.hasRtx) if (rtxCodec && encoding.hasRtx)
this->rtpStream->SetRtx(rtxCodec->payloadType, encoding.rtx.ssrc); this->rtpStream->SetRtx(rtxCodec->payloadType, encoding.rtx.ssrc);
this->keyFrameSupported = RTC::Codecs::CanBeKeyFrame(mediaCodec->mimeType);
} }
void SimpleConsumer::RequestKeyFrame() void SimpleConsumer::RequestKeyFrame()
......
...@@ -324,7 +324,7 @@ namespace RTC ...@@ -324,7 +324,7 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<StunMessage>"); MS_DUMP("<StunMessage>");
std::string klass; std::string klass;
switch (this->klass) switch (this->klass)
...@@ -344,15 +344,14 @@ namespace RTC ...@@ -344,15 +344,14 @@ namespace RTC
} }
if (this->method == Method::BINDING) if (this->method == Method::BINDING)
{ {
MS_DEBUG_DEV(" Binding %s", klass.c_str()); MS_DUMP(" Binding %s", klass.c_str());
} }
else else
{ {
// This prints the unknown method number. Example: TURN Allocate => 0x003. // This prints the unknown method number. Example: TURN Allocate => 0x003.
MS_DEBUG_DEV( MS_DUMP(" %s with unknown method %#.3x", klass.c_str(), static_cast<uint16_t>(this->method));
" %s with unknown method %#.3x", klass.c_str(), static_cast<uint16_t>(this->method));
} }
MS_DEBUG_DEV(" size: %zu bytes", this->size); MS_DUMP(" size: %zu bytes", this->size);
static char transactionId[25]; static char transactionId[25];
...@@ -361,19 +360,19 @@ namespace RTC ...@@ -361,19 +360,19 @@ namespace RTC
// NOTE: n must be 3 because snprintf adds a \0 after printed chars. // NOTE: n must be 3 because snprintf adds a \0 after printed chars.
std::snprintf(transactionId + (i * 2), 3, "%.2x", this->transactionId[i]); std::snprintf(transactionId + (i * 2), 3, "%.2x", this->transactionId[i]);
} }
MS_DEBUG_DEV(" transactionId: %s", transactionId); MS_DUMP(" transactionId: %s", transactionId);
if (this->errorCode != 0u) if (this->errorCode != 0u)
MS_DEBUG_DEV(" errorCode: %" PRIu16, this->errorCode); MS_DUMP(" errorCode: %" PRIu16, this->errorCode);
if (!this->username.empty()) if (!this->username.empty())
MS_DEBUG_DEV(" username: %s", this->username.c_str()); MS_DUMP(" username: %s", this->username.c_str());
if (this->priority != 0u) if (this->priority != 0u)
MS_DEBUG_DEV(" priority: %" PRIu32, this->priority); MS_DUMP(" priority: %" PRIu32, this->priority);
if (this->iceControlling != 0u) if (this->iceControlling != 0u)
MS_DEBUG_DEV(" iceControlling: %" PRIu64, this->iceControlling); MS_DUMP(" iceControlling: %" PRIu64, this->iceControlling);
if (this->iceControlled != 0u) if (this->iceControlled != 0u)
MS_DEBUG_DEV(" iceControlled: %" PRIu64, this->iceControlled); MS_DUMP(" iceControlled: %" PRIu64, this->iceControlled);
if (this->hasUseCandidate) if (this->hasUseCandidate)
MS_DEBUG_DEV(" useCandidate"); MS_DUMP(" useCandidate");
if (this->xorMappedAddress != nullptr) if (this->xorMappedAddress != nullptr)
{ {
int family; int family;
...@@ -382,7 +381,7 @@ namespace RTC ...@@ -382,7 +381,7 @@ namespace RTC
Utils::IP::GetAddressInfo(this->xorMappedAddress, family, ip, port); Utils::IP::GetAddressInfo(this->xorMappedAddress, family, ip, port);
MS_DEBUG_DEV(" xorMappedAddress: %s : %" PRIu16, ip.c_str(), port); MS_DUMP(" xorMappedAddress: %s : %" PRIu16, ip.c_str(), port);
} }
if (this->messageIntegrity != nullptr) if (this->messageIntegrity != nullptr)
{ {
...@@ -393,12 +392,12 @@ namespace RTC ...@@ -393,12 +392,12 @@ namespace RTC
std::snprintf(messageIntegrity + (i * 2), 3, "%.2x", this->messageIntegrity[i]); std::snprintf(messageIntegrity + (i * 2), 3, "%.2x", this->messageIntegrity[i]);
} }
MS_DEBUG_DEV(" messageIntegrity: %s", messageIntegrity); MS_DUMP(" messageIntegrity: %s", messageIntegrity);
} }
if (this->hasFingerprint) if (this->hasFingerprint)
MS_DEBUG_DEV(" has fingerprint"); MS_DUMP(" has fingerprint");
MS_DEBUG_DEV("</StunMessage>"); MS_DUMP("</StunMessage>");
} }
StunMessage::Authentication StunMessage::CheckAuthentication( StunMessage::Authentication StunMessage::CheckAuthentication(
......
差异被折叠。
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
#include "RTC/SimpleConsumer.hpp" #include "RTC/SimpleConsumer.hpp"
#include "RTC/SimulcastConsumer.hpp" #include "RTC/SimulcastConsumer.hpp"
#include "RTC/SvcConsumer.hpp"
namespace RTC namespace RTC
{ {
...@@ -287,7 +288,8 @@ namespace RTC ...@@ -287,7 +288,8 @@ namespace RTC
case RTC::RtpParameters::Type::SVC: case RTC::RtpParameters::Type::SVC:
{ {
MS_THROW_TYPE_ERROR("not yet implemented type 'svc'"); // This may throw.
consumer = new RTC::SvcConsumer(consumerId, this, request->data);
break; break;
} }
......
...@@ -930,7 +930,7 @@ namespace RTC ...@@ -930,7 +930,7 @@ namespace RTC
// Then redistribute the remaining bitrate by allowing Consumers to increase // Then redistribute the remaining bitrate by allowing Consumers to increase
// layer by layer. // layer by layer.
while (remainingBitrate >= 5000) while (remainingBitrate >= 2000)
{ {
auto previousRemainingBitrate = remainingBitrate; auto previousRemainingBitrate = remainingBitrate;
...@@ -951,7 +951,7 @@ namespace RTC ...@@ -951,7 +951,7 @@ namespace RTC
remainingBitrate -= usedBitrate; remainingBitrate -= usedBitrate;
// No more. // No more.
if (remainingBitrate < 5000) if (remainingBitrate < 2000)
break; break;
} }
......
...@@ -131,15 +131,15 @@ void TcpConnection::Close() ...@@ -131,15 +131,15 @@ void TcpConnection::Close()
void TcpConnection::Dump() const void TcpConnection::Dump() const
{ {
MS_DEBUG_DEV("<TcpConnection>"); MS_DUMP("<TcpConnection>");
MS_DEBUG_DEV( MS_DUMP(
" [TCP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 ", status:%s]", " [TCP, local:%s :%" PRIu16 ", remote:%s :%" PRIu16 ", status:%s]",
this->localIp.c_str(), this->localIp.c_str(),
static_cast<uint16_t>(this->localPort), static_cast<uint16_t>(this->localPort),
this->peerIp.c_str(), this->peerIp.c_str(),
static_cast<uint16_t>(this->peerPort), static_cast<uint16_t>(this->peerPort),
(!this->closed) ? "open" : "closed"); (!this->closed) ? "open" : "closed");
MS_DEBUG_DEV("</TcpConnection>"); MS_DUMP("</TcpConnection>");
} }
void TcpConnection::Setup( void TcpConnection::Setup(
......
...@@ -90,14 +90,14 @@ void TcpServer::Close() ...@@ -90,14 +90,14 @@ void TcpServer::Close()
void TcpServer::Dump() const void TcpServer::Dump() const
{ {
MS_DEBUG_DEV("<TcpServer>"); MS_DUMP("<TcpServer>");
MS_DEBUG_DEV( MS_DUMP(
" [TCP, local:%s :%" PRIu16 ", status:%s, connections:%zu]", " [TCP, local:%s :%" PRIu16 ", status:%s, connections:%zu]",
this->localIp.c_str(), this->localIp.c_str(),
static_cast<uint16_t>(this->localPort), static_cast<uint16_t>(this->localPort),
(!this->closed) ? "open" : "closed", (!this->closed) ? "open" : "closed",
this->connections.size()); this->connections.size());
MS_DEBUG_DEV("</TcpServer>"); MS_DUMP("</TcpServer>");
} }
bool TcpServer::SetLocalAddress() bool TcpServer::SetLocalAddress()
......
...@@ -117,13 +117,13 @@ void UdpSocket::Close() ...@@ -117,13 +117,13 @@ void UdpSocket::Close()
void UdpSocket::Dump() const void UdpSocket::Dump() const
{ {
MS_DEBUG_DEV("<UdpSocket>"); MS_DUMP("<UdpSocket>");
MS_DEBUG_DEV( MS_DUMP(
" [UDP, local:%s :%" PRIu16 ", status:%s]", " [UDP, local:%s :%" PRIu16 ", status:%s]",
this->localIp.c_str(), this->localIp.c_str(),
static_cast<uint16_t>(this->localPort), static_cast<uint16_t>(this->localPort),
(!this->closed) ? "open" : "closed"); (!this->closed) ? "open" : "closed");
MS_DEBUG_DEV("</UdpSocket>"); MS_DUMP("</UdpSocket>");
} }
void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* addr) void UdpSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* addr)
...@@ -324,6 +324,7 @@ inline void UdpSocket::OnUvSendError(int error) // NOLINT(misc-unused-parameters ...@@ -324,6 +324,7 @@ inline void UdpSocket::OnUvSendError(int error) // NOLINT(misc-unused-parameters
if (this->closed) if (this->closed)
return; return;
#ifdef MS_LOG_DEV #ifdef MS_LOG_DEV
MS_DEBUG_DEV("send error: %s", uv_strerror(error)); MS_DEBUG_DEV("send error: %s", uv_strerror(error));
#endif #endif
......
...@@ -39,7 +39,7 @@ public: ...@@ -39,7 +39,7 @@ public:
{ {
return; return;
}; };
bool Process(Codecs::EncodingContext* /*context*/, uint8_t* /*data*/) bool Process(Codecs::EncodingContext* /*context*/, uint8_t* /*data*/, bool& /*marker*/)
{ {
return true; return true;
}; };
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论