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

Frame marking and H264 temporal layers (#305)

Fixes #298 
上级 163df732
...@@ -257,24 +257,39 @@ const supportedRtpCapabilities = ...@@ -257,24 +257,39 @@ const supportedRtpCapabilities =
preferredEncrypt : false, preferredEncrypt : false,
direction : 'inactive' // TODO: Enable when done. direction : 'inactive' // TODO: Enable when done.
}, },
// NOTE: Remove this once framemarking draft becomes RFC.
{
kind : 'video',
uri : 'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07',
preferredId : 6,
preferredEncrypt : false,
direction : 'sendrecv'
},
{
kind : 'video',
uri : 'urn:ietf:params:rtp-hdrext:framemarking',
preferredId : 7,
preferredEncrypt : false,
direction : 'sendrecv'
},
{ {
kind : 'audio', kind : 'audio',
uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level', uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
preferredId : 8, preferredId : 10,
preferredEncrypt : false, preferredEncrypt : false,
direction : 'sendrecv' direction : 'sendrecv'
}, },
{ {
kind : 'video', kind : 'video',
uri : 'urn:3gpp:video-orientation', uri : 'urn:3gpp:video-orientation',
preferredId : 9, preferredId : 11,
preferredEncrypt : false, preferredEncrypt : false,
direction : 'sendrecv' direction : 'sendrecv'
}, },
{ {
kind : 'video', kind : 'video',
uri : 'urn:ietf:params:rtp-hdrext:toffset', uri : 'urn:ietf:params:rtp-hdrext:toffset',
preferredId : 10, preferredId : 12,
preferredEncrypt : false, preferredEncrypt : false,
direction : 'sendrecv' direction : 'sendrecv'
} }
......
...@@ -221,19 +221,19 @@ const consumerDeviceCapabilities = ...@@ -221,19 +221,19 @@ const consumerDeviceCapabilities =
{ {
kind : 'audio', kind : 'audio',
uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level', uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
preferredId : 8, preferredId : 10,
preferredEncrypt : false preferredEncrypt : false
}, },
{ {
kind : 'video', kind : 'video',
uri : 'urn:3gpp:video-orientation', uri : 'urn:3gpp:video-orientation',
preferredId : 9, preferredId : 11,
preferredEncrypt : false preferredEncrypt : false
}, },
{ {
kind : 'video', kind : 'video',
uri : 'urn:ietf:params:rtp-hdrext:toffset', uri : 'urn:ietf:params:rtp-hdrext:toffset',
preferredId : 10, preferredId : 12,
preferredEncrypt : false preferredEncrypt : false
} }
], ],
...@@ -503,7 +503,7 @@ test('consumer.dump() succeeds', async () => ...@@ -503,7 +503,7 @@ test('consumer.dump() succeeds', async () =>
}, },
{ {
uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level', uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
id : 8, id : 10,
parameters : {}, parameters : {},
encrypt : false encrypt : false
} }
...@@ -564,13 +564,13 @@ test('consumer.dump() succeeds', async () => ...@@ -564,13 +564,13 @@ test('consumer.dump() succeeds', async () =>
}, },
{ {
uri : 'urn:3gpp:video-orientation', uri : 'urn:3gpp:video-orientation',
id : 9, id : 11,
parameters : {}, parameters : {},
encrypt : false encrypt : false
}, },
{ {
uri : 'urn:ietf:params:rtp-hdrext:toffset', uri : 'urn:ietf:params:rtp-hdrext:toffset',
id : 10, id : 12,
parameters : {}, parameters : {},
encrypt : false encrypt : false
} }
......
...@@ -173,7 +173,7 @@ const consumerDeviceCapabilities = ...@@ -173,7 +173,7 @@ const consumerDeviceCapabilities =
{ {
kind : 'audio', kind : 'audio',
uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level', uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
preferredId : 8, preferredId : 10,
preferredEncrypt : false preferredEncrypt : false
} }
] ]
...@@ -250,7 +250,7 @@ test('router.pipeToRouter() succeeds with audio', async () => ...@@ -250,7 +250,7 @@ test('router.pipeToRouter() succeeds with audio', async () =>
[ [
{ {
uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level', uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
id : 8 id : 10
} }
]); ]);
expect(pipeConsumer.rtpParameters.encodings).toEqual( expect(pipeConsumer.rtpParameters.encodings).toEqual(
...@@ -287,7 +287,7 @@ test('router.pipeToRouter() succeeds with audio', async () => ...@@ -287,7 +287,7 @@ test('router.pipeToRouter() succeeds with audio', async () =>
[ [
{ {
uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level', uri : 'urn:ietf:params:rtp-hdrext:ssrc-audio-level',
id : 8 id : 10
} }
]); ]);
expect(pipeProducer.rtpParameters.encodings).toEqual( expect(pipeProducer.rtpParameters.encodings).toEqual(
...@@ -337,13 +337,22 @@ test('router.pipeToRouter() succeeds with video', async () => ...@@ -337,13 +337,22 @@ test('router.pipeToRouter() succeeds with video', async () =>
]); ]);
expect(pipeConsumer.rtpParameters.headerExtensions).toEqual( expect(pipeConsumer.rtpParameters.headerExtensions).toEqual(
[ [
// NOTE: Remove this once framemarking draft becomes RFC.
{
uri : 'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07',
id : 6
},
{
uri : 'urn:ietf:params:rtp-hdrext:framemarking',
id : 7
},
{ {
uri : 'urn:3gpp:video-orientation', uri : 'urn:3gpp:video-orientation',
id : 9 id : 11
}, },
{ {
uri : 'urn:ietf:params:rtp-hdrext:toffset', uri : 'urn:ietf:params:rtp-hdrext:toffset',
id : 10 id : 12
} }
]); ]);
expect(pipeConsumer.rtpParameters.encodings).toEqual( expect(pipeConsumer.rtpParameters.encodings).toEqual(
...@@ -379,13 +388,22 @@ test('router.pipeToRouter() succeeds with video', async () => ...@@ -379,13 +388,22 @@ test('router.pipeToRouter() succeeds with video', async () =>
]); ]);
expect(pipeProducer.rtpParameters.headerExtensions).toEqual( expect(pipeProducer.rtpParameters.headerExtensions).toEqual(
[ [
// NOTE: Remove this once framemarking draft becomes RFC.
{
uri : 'http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07',
id : 6
},
{
uri : 'urn:ietf:params:rtp-hdrext:framemarking',
id : 7
},
{ {
uri : 'urn:3gpp:video-orientation', uri : 'urn:3gpp:video-orientation',
id : 9 id : 11
}, },
{ {
uri : 'urn:ietf:params:rtp-hdrext:toffset', uri : 'urn:ietf:params:rtp-hdrext:toffset',
id : 10 id : 12
} }
]); ]);
expect(pipeProducer.paused).toBe(true); expect(pipeProducer.paused).toBe(true);
......
...@@ -423,13 +423,13 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum ...@@ -423,13 +423,13 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
{ {
kind : 'video', kind : 'video',
uri : 'urn:3gpp:video-orientation', uri : 'urn:3gpp:video-orientation',
preferredId : 9, preferredId : 11,
preferredEncrypt : false preferredEncrypt : false
}, },
{ {
kind : 'video', kind : 'video',
uri : 'urn:ietf:params:rtp-hdrext:toffset', uri : 'urn:ietf:params:rtp-hdrext:toffset',
preferredId : 10, preferredId : 12,
preferredEncrypt : false preferredEncrypt : false
} }
] ]
...@@ -479,11 +479,11 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum ...@@ -479,11 +479,11 @@ test('getProducerRtpParametersMapping(), getConsumableRtpParameters(), getConsum
[ [
{ {
uri : 'urn:3gpp:video-orientation', uri : 'urn:3gpp:video-orientation',
id : 9 id : 11
}, },
{ {
uri : 'urn:ietf:params:rtp-hdrext:toffset', uri : 'urn:ietf:params:rtp-hdrext:toffset',
id : 10 id : 12
} }
]); ]);
......
...@@ -16,14 +16,29 @@ namespace RTC ...@@ -16,14 +16,29 @@ namespace RTC
{ {
/* Pure virtual methods inherited from RTC::Codecs::PayloadDescriptor. */ /* Pure virtual methods inherited from RTC::Codecs::PayloadDescriptor. */
~PayloadDescriptor() = default; ~PayloadDescriptor() = default;
void Dump() const; void Dump() const override;
// Fields in frame-marking extension.
uint8_t s : 1; // Start of Frame.
uint8_t e : 1; // End of Frame.
uint8_t i : 1; // Independent Frame.
uint8_t d : 1; // Discardable Frame.
uint8_t b : 1; // Base Layer Sync.
uint8_t tid{ 0 }; // Temporal layer id.
uint8_t lid{ 0 }; // Spatial layer id.
uint8_t tl0picidx{ 0 }; // TL0PICIDX
// Parsed values. // Parsed values.
bool hasLid{ false };
bool hasTl0picidx{ false };
bool isKeyFrame{ false }; bool isKeyFrame{ false };
}; };
public: public:
static H264::PayloadDescriptor* Parse(uint8_t* data, size_t len); static H264::PayloadDescriptor* Parse(
const uint8_t* data,
size_t len,
RTC::RtpPacket::FrameMarking* frameMarking = nullptr,
uint8_t frameMarkingLen = 0);
static void ProcessRtpPacket(RTC::RtpPacket* packet); static void ProcessRtpPacket(RTC::RtpPacket* packet);
public: public:
...@@ -35,6 +50,9 @@ namespace RTC ...@@ -35,6 +50,9 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */ /* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
public: public:
void SyncRequired() override; void SyncRequired() override;
public:
uint8_t currentTemporalLayer{ std::numeric_limits<uint8_t>::max() };
}; };
class PayloadDescriptorHandler : public RTC::Codecs::PayloadDescriptorHandler class PayloadDescriptorHandler : public RTC::Codecs::PayloadDescriptorHandler
...@@ -44,12 +62,12 @@ namespace RTC ...@@ -44,12 +62,12 @@ namespace RTC
~PayloadDescriptorHandler() = default; ~PayloadDescriptorHandler() = default;
public: public:
void Dump() const; void Dump() const override;
bool Encode(RTC::Codecs::EncodingContext* context, uint8_t* data); bool Encode(RTC::Codecs::EncodingContext* context, uint8_t* data) override;
void Restore(uint8_t* data); void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const; uint8_t GetSpatialLayer() const override;
uint8_t GetTemporalLayer() const; uint8_t GetTemporalLayer() const override;
bool IsKeyFrame() const; bool IsKeyFrame() const override;
private: private:
std::unique_ptr<PayloadDescriptor> payloadDescriptor; std::unique_ptr<PayloadDescriptor> payloadDescriptor;
...@@ -58,34 +76,26 @@ namespace RTC ...@@ -58,34 +76,26 @@ namespace RTC
/* Inline EncondingContext methods */ /* Inline EncondingContext methods */
inline void H264::EncodingContext::SyncRequired(){}; inline void H264::EncodingContext::SyncRequired()
/* Inline PayloadDescriptorHandler methods */
inline bool H264::PayloadDescriptorHandler::Encode(
RTC::Codecs::EncodingContext* /*encodingContext*/, uint8_t* /*data*/)
{
return true;
};
inline void H264::PayloadDescriptorHandler::Restore(uint8_t* /*data*/)
{ {
} }
/* Inline PayloadDescriptorHandler methods */
inline uint8_t H264::PayloadDescriptorHandler::GetSpatialLayer() const inline uint8_t H264::PayloadDescriptorHandler::GetSpatialLayer() const
{ {
return 0u; return 0u;
}; }
inline uint8_t H264::PayloadDescriptorHandler::GetTemporalLayer() const inline uint8_t H264::PayloadDescriptorHandler::GetTemporalLayer() const
{ {
return 0u; return this->payloadDescriptor->tid;
}; }
inline bool H264::PayloadDescriptorHandler::IsKeyFrame() const inline bool H264::PayloadDescriptorHandler::IsKeyFrame() const
{ {
return this->payloadDescriptor->isKeyFrame; return this->payloadDescriptor->isKeyFrame;
}; }
inline void H264::PayloadDescriptorHandler::Dump() const inline void H264::PayloadDescriptorHandler::Dump() const
{ {
......
...@@ -40,7 +40,7 @@ namespace RTC ...@@ -40,7 +40,7 @@ namespace RTC
{ {
/* Pure virtual methods inherited from RTC::Codecs::PayloadDescriptor. */ /* Pure virtual methods inherited from RTC::Codecs::PayloadDescriptor. */
~PayloadDescriptor() = default; ~PayloadDescriptor() = default;
void Dump() const; void Dump() const override;
// Rewrite the buffer with the given pictureId and tl0PictureIndex values. // Rewrite the buffer with the given pictureId and tl0PictureIndex values.
void Encode(uint8_t* data, uint16_t pictureId, uint8_t tl0PictureIndex) const; void Encode(uint8_t* data, uint16_t pictureId, uint8_t tl0PictureIndex) const;
...@@ -72,7 +72,11 @@ namespace RTC ...@@ -72,7 +72,11 @@ namespace RTC
}; };
public: public:
static VP8::PayloadDescriptor* Parse(const uint8_t* data, size_t len); static VP8::PayloadDescriptor* Parse(
const uint8_t* data,
size_t len,
RTC::RtpPacket::FrameMarking* frameMarking = nullptr,
uint8_t frameMarkingLen = 0);
static void ProcessRtpPacket(RTC::RtpPacket* packet); static void ProcessRtpPacket(RTC::RtpPacket* packet);
public: public:
...@@ -99,12 +103,12 @@ namespace RTC ...@@ -99,12 +103,12 @@ namespace RTC
~PayloadDescriptorHandler() = default; ~PayloadDescriptorHandler() = default;
public: public:
void Dump() const; void Dump() const override;
bool Encode(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data); bool Encode(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data) override;
void Restore(uint8_t* data); void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const; uint8_t GetSpatialLayer() const override;
uint8_t GetTemporalLayer() const; uint8_t GetTemporalLayer() const override;
bool IsKeyFrame() const; bool IsKeyFrame() const override;
private: private:
std::unique_ptr<PayloadDescriptor> payloadDescriptor; std::unique_ptr<PayloadDescriptor> payloadDescriptor;
...@@ -116,27 +120,24 @@ namespace RTC ...@@ -116,27 +120,24 @@ namespace RTC
inline void VP8::EncodingContext::SyncRequired() inline void VP8::EncodingContext::SyncRequired()
{ {
this->syncRequired = true; this->syncRequired = true;
}; }
/* Inline PayloadDescriptorHandler methods */ /* Inline PayloadDescriptorHandler methods */
inline uint8_t VP8::PayloadDescriptorHandler::GetSpatialLayer() const inline uint8_t VP8::PayloadDescriptorHandler::GetSpatialLayer() const
{ {
return 0u; return 0u;
}; }
inline uint8_t VP8::PayloadDescriptorHandler::GetTemporalLayer() const inline uint8_t VP8::PayloadDescriptorHandler::GetTemporalLayer() const
{ {
if (this->payloadDescriptor->hasTlIndex) return this->payloadDescriptor->hasTlIndex ? this->payloadDescriptor->tlIndex : 0u;
return this->payloadDescriptor->tlIndex; }
else
return 0u;
};
inline bool VP8::PayloadDescriptorHandler::IsKeyFrame() const inline bool VP8::PayloadDescriptorHandler::IsKeyFrame() const
{ {
return this->payloadDescriptor->isKeyFrame; return this->payloadDescriptor->isKeyFrame;
}; }
inline void VP8::PayloadDescriptorHandler::Dump() const inline void VP8::PayloadDescriptorHandler::Dump() const
{ {
......
...@@ -85,6 +85,7 @@ namespace RTC ...@@ -85,6 +85,7 @@ namespace RTC
RTC::RtpStreamRecv* CreateRtpStream( RTC::RtpStreamRecv* CreateRtpStream(
RTC::RtpPacket* packet, const RTC::RtpCodecParameters& mediaCodec, size_t encodingIdx); RTC::RtpPacket* packet, const RTC::RtpCodecParameters& mediaCodec, size_t encodingIdx);
void NotifyNewRtpStream(RTC::RtpStreamRecv* rtpStream); void NotifyNewRtpStream(RTC::RtpStreamRecv* rtpStream);
void PreProcessRtpPacket(RTC::RtpPacket* packet);
bool MangleRtpPacket(RTC::RtpPacket* packet, RTC::RtpStreamRecv* rtpStream) const; bool MangleRtpPacket(RTC::RtpPacket* packet, RTC::RtpStreamRecv* rtpStream) const;
void PostProcessRtpPacket(RTC::RtpPacket* packet); void PostProcessRtpPacket(RTC::RtpPacket* packet);
void EmitScore() const; void EmitScore() const;
......
...@@ -132,9 +132,11 @@ namespace RTC ...@@ -132,9 +132,11 @@ namespace RTC
REPAIRED_RTP_STREAM_ID = 3, REPAIRED_RTP_STREAM_ID = 3,
ABS_SEND_TIME = 4, ABS_SEND_TIME = 4,
TRANSPORT_CC_01 = 5, TRANSPORT_CC_01 = 5,
SSRC_AUDIO_LEVEL = 8, FRAME_MARKING_07 = 6, // NOTE: Remove once RFC.
VIDEO_ORIENTATION = 9, FRAME_MARKING = 7,
TOFFSET = 10 SSRC_AUDIO_LEVEL = 10,
VIDEO_ORIENTATION = 11,
TOFFSET = 12
}; };
private: private:
......
...@@ -7,13 +7,17 @@ namespace RTC ...@@ -7,13 +7,17 @@ namespace RTC
// the same Transport. Others are different for each Producer. // the same Transport. Others are different for each Producer.
struct RtpHeaderExtensionIds struct RtpHeaderExtensionIds
{ {
uint8_t mid{ 0u }; // 0 means no MID id. // 0 means no id.
uint8_t rid{ 0u }; // 0 means no RID id. uint8_t mid{ 0u };
uint8_t rrid{ 0u }; // 0 means no RRID id. uint8_t rid{ 0u };
uint8_t absSendTime{ 0u }; // 0 means no abs-send-time id. uint8_t rrid{ 0u };
uint8_t ssrcAudioLevel{ 0u }; // 0 means no ssrc-audio-level id. uint8_t absSendTime{ 0u };
uint8_t videoOrientation{ 0u }; // 0 means no video-orientation id. uint8_t transportWideCC01{ 0u };
uint8_t toffset{ 0u }; // 0 means no toffset id. uint8_t frameMarking07{ 0u }; // NOTE: Remove once RFC.
uint8_t frameMarking{ 0u };
uint8_t ssrcAudioLevel{ 0u };
uint8_t videoOrientation{ 0u };
uint8_t toffset{ 0u };
}; };
} // namespace RTC } // namespace RTC
......
...@@ -84,6 +84,29 @@ namespace RTC ...@@ -84,6 +84,29 @@ namespace RTC
uint8_t* value; uint8_t* value;
}; };
public:
/* Struct with frame-marking information. */
struct FrameMarking
{
#if defined(MS_LITTLE_ENDIAN)
uint8_t tid : 3;
uint8_t base : 1;
uint8_t discardable : 1;
uint8_t independent : 1;
uint8_t end : 1;
uint8_t start : 1;
#elif defined(MS_BIG_ENDIAN)
uint8_t start : 1;
uint8_t end : 1;
uint8_t independent : 1;
uint8_t discardable : 1;
uint8_t base : 1;
uint8_t tid : 3;
#endif
uint8_t lid;
uint8_t tl0picidx;
};
public: public:
static bool IsRtp(const uint8_t* data, size_t len); static bool IsRtp(const uint8_t* data, size_t len);
static RtpPacket* Parse(const uint8_t* data, size_t len); static RtpPacket* Parse(const uint8_t* data, size_t len);
...@@ -126,11 +149,14 @@ namespace RTC ...@@ -126,11 +149,14 @@ namespace RTC
void SetRidExtensionId(uint8_t id); void SetRidExtensionId(uint8_t id);
void SetRepairedRidExtensionId(uint8_t id); void SetRepairedRidExtensionId(uint8_t id);
void SetAbsSendTimeExtensionId(uint8_t id); void SetAbsSendTimeExtensionId(uint8_t id);
void SetFrameMarking07ExtensionId(uint8_t id); // NOTE: Remove once RFC.
void SetFrameMarkingExtensionId(uint8_t id);
void SetSsrcAudioLevelExtensionId(uint8_t id); void SetSsrcAudioLevelExtensionId(uint8_t id);
void SetVideoOrientationExtensionId(uint8_t id); void SetVideoOrientationExtensionId(uint8_t id);
bool ReadMid(std::string& mid) const; bool ReadMid(std::string& mid) const;
bool ReadRid(std::string& rid) const; bool ReadRid(std::string& rid) const;
bool ReadAbsSendTime(uint32_t& time) const; bool ReadAbsSendTime(uint32_t& time) const;
bool ReadFrameMarking(RtpPacket::FrameMarking** frameMarking, uint8_t& length) const;
bool ReadSsrcAudioLevel(uint8_t& volume, bool& voice) const; bool ReadSsrcAudioLevel(uint8_t& volume, bool& voice) const;
bool ReadVideoOrientation(bool& camera, bool& flip, uint16_t& rotation) const; bool ReadVideoOrientation(bool& camera, bool& flip, uint16_t& rotation) const;
uint8_t* GetExtension(uint8_t id, uint8_t& len) const; uint8_t* GetExtension(uint8_t id, uint8_t& len) const;
...@@ -162,6 +188,8 @@ namespace RTC ...@@ -162,6 +188,8 @@ namespace RTC
uint8_t ridExtensionId{ 0 }; uint8_t ridExtensionId{ 0 };
uint8_t rridExtensionId{ 0 }; uint8_t rridExtensionId{ 0 };
uint8_t absSendTimeExtensionId{ 0 }; uint8_t absSendTimeExtensionId{ 0 };
uint8_t frameMarking07ExtensionId{ 0 }; // NOTE: Remove once RFC.
uint8_t frameMarkingExtensionId{ 0 };
uint8_t ssrcAudioLevelExtensionId{ 0 }; uint8_t ssrcAudioLevelExtensionId{ 0 };
uint8_t videoOrientationExtensionId{ 0 }; uint8_t videoOrientationExtensionId{ 0 };
uint8_t* payload{ nullptr }; uint8_t* payload{ nullptr };
...@@ -326,6 +354,23 @@ namespace RTC ...@@ -326,6 +354,23 @@ namespace RTC
this->absSendTimeExtensionId = id; this->absSendTimeExtensionId = id;
} }
inline void RtpPacket::SetFrameMarkingExtensionId(uint8_t id)
{
if (id == 0u)
return;
this->frameMarkingExtensionId = id;
}
// NOTE: Remove once RFC.
inline void RtpPacket::SetFrameMarking07ExtensionId(uint8_t id)
{
if (id == 0u)
return;
this->frameMarking07ExtensionId = id;
}
inline void RtpPacket::SetSsrcAudioLevelExtensionId(uint8_t id) inline void RtpPacket::SetSsrcAudioLevelExtensionId(uint8_t id)
{ {
if (id == 0u) if (id == 0u)
...@@ -393,6 +438,24 @@ namespace RTC ...@@ -393,6 +438,24 @@ namespace RTC
return true; return true;
} }
inline bool RtpPacket::ReadFrameMarking(RtpPacket::FrameMarking** frameMarking, uint8_t& length) const
{
uint8_t extenLen;
uint8_t* extenValue = GetExtension(this->frameMarkingExtensionId, extenLen);
// NOTE: Remove this once framemarking draft becomes RFC.
if (!extenValue)
extenValue = GetExtension(this->frameMarking07ExtensionId, extenLen);
if (!extenValue || extenLen > 3)
return false;
*frameMarking = reinterpret_cast<RtpPacket::FrameMarking*>(extenValue);
length = extenLen;
return true;
}
inline bool RtpPacket::ReadSsrcAudioLevel(uint8_t& volume, bool& voice) const inline bool RtpPacket::ReadSsrcAudioLevel(uint8_t& volume, bool& voice) const
{ {
uint8_t extenLen; uint8_t extenLen;
......
...@@ -9,15 +9,48 @@ namespace RTC ...@@ -9,15 +9,48 @@ namespace RTC
{ {
namespace Codecs namespace Codecs
{ {
H264::PayloadDescriptor* H264::Parse(uint8_t* data, size_t len) /* Class methods. */
H264::PayloadDescriptor* H264::Parse(
const uint8_t* data, size_t len, RTC::RtpPacket::FrameMarking* frameMarking, uint8_t frameMarkingLen)
{ {
MS_TRACE(); MS_TRACE();
std::unique_ptr<PayloadDescriptor> payloadDescriptor(new PayloadDescriptor());
if (len < 2) if (len < 2)
return nullptr; return nullptr;
std::unique_ptr<PayloadDescriptor> payloadDescriptor(new PayloadDescriptor());
// Use frame-marking.
if (frameMarking)
{
// Read fields.
payloadDescriptor->s = frameMarking->start;
payloadDescriptor->e = frameMarking->end;
payloadDescriptor->i = frameMarking->independent;
payloadDescriptor->d = frameMarking->discardable;
payloadDescriptor->b = frameMarking->base;
payloadDescriptor->tid = frameMarking->tid;
if (frameMarkingLen >= 2)
{
payloadDescriptor->hasLid = true;
payloadDescriptor->lid = frameMarking->lid;
}
if (frameMarkingLen == 3)
{
payloadDescriptor->hasTl0picidx = true;
payloadDescriptor->tl0picidx = frameMarking->tl0picidx;
}
// Detect key frame.
if (frameMarking->start && frameMarking->independent)
payloadDescriptor->isKeyFrame = true;
}
else
// Parse payload otherwise.
{
uint8_t nal = *data & 0x1F; uint8_t nal = *data & 0x1F;
switch (nal) switch (nal)
...@@ -77,39 +110,103 @@ namespace RTC ...@@ -77,39 +110,103 @@ namespace RTC
break; break;
} }
} }
}
return payloadDescriptor.release(); return payloadDescriptor.release();
} }
void H264::ProcessRtpPacket(RTC::RtpPacket* packet)
{
MS_TRACE();
auto* data = packet->GetPayload();
auto len = packet->GetPayloadLength();
RtpPacket::FrameMarking* frameMarking{ nullptr };
uint8_t frameMarkingLen{ 0 };
// Read frame-marking.
packet->ReadFrameMarking(&frameMarking, frameMarkingLen);
PayloadDescriptor* payloadDescriptor = H264::Parse(data, len, frameMarking, frameMarkingLen);
if (!payloadDescriptor)
return;
auto* payloadDescriptorHandler = new PayloadDescriptorHandler(payloadDescriptor);
packet->SetPayloadDescriptorHandler(payloadDescriptorHandler);
}
/* Instance methods. */
void H264::PayloadDescriptor::Dump() const void H264::PayloadDescriptor::Dump() const
{ {
MS_TRACE(); MS_TRACE();
MS_DEBUG_DEV("<PayloadDescriptor>"); MS_DEBUG_DEV("<PayloadDescriptor>");
MS_DEBUG_DEV(" s : %s", this->s ? "true" : "false");
MS_DEBUG_DEV(" e : %s", this->e ? "true" : "false");
MS_DEBUG_DEV(" i : %s", this->i ? "true" : "false");
MS_DEBUG_DEV(" d : %s", this->d ? "true" : "false");
MS_DEBUG_DEV(" b : %s", this->b ? "true" : "false");
MS_DEBUG_DEV(" tid : %" PRIu8, this->tid);
if (this->hasLid)
MS_DEBUG_DEV(" lid : %" PRIu8, this->lid);
if (this->hasTl0picidx)
MS_DEBUG_DEV(" tl0picidx : %" PRIu8, this->tl0picidx);
MS_DEBUG_DEV(" isKeyFrame : %s", this->isKeyFrame ? "true" : "false"); MS_DEBUG_DEV(" isKeyFrame : %s", this->isKeyFrame ? "true" : "false");
MS_DEBUG_DEV("</PayloadDescriptor>"); MS_DEBUG_DEV("</PayloadDescriptor>");
} }
H264::PayloadDescriptorHandler::PayloadDescriptorHandler(H264::PayloadDescriptor* payloadDescriptor) H264::PayloadDescriptorHandler::PayloadDescriptorHandler(H264::PayloadDescriptor* payloadDescriptor)
{ {
MS_TRACE();
this->payloadDescriptor.reset(payloadDescriptor); this->payloadDescriptor.reset(payloadDescriptor);
} }
void H264::ProcessRtpPacket(RTC::RtpPacket* packet) bool H264::PayloadDescriptorHandler::Encode(
RTC::Codecs::EncodingContext* encodingContext, uint8_t* /*data*/)
{ {
MS_TRACE(); MS_TRACE();
auto data = packet->GetPayload(); auto* context = static_cast<RTC::Codecs::H264::EncodingContext*>(encodingContext);
auto len = packet->GetPayloadLength();
PayloadDescriptor* payloadDescriptor = Parse(data, len); // Check temporal layer.
// TODO: We should check incremental picture id here somehow and let it pass
// if so.
if (this->payloadDescriptor->tid > context->preferences.temporalLayer)
{
return false;
}
else if (context->currentTemporalLayer != context->preferences.temporalLayer)
{
// Payload descriptor contains the target temporal layer.
if (this->payloadDescriptor->tid == context->preferences.temporalLayer)
{
// Upgrade required. Drop current packet if base flag is not set.
// NOTE: It seems that Base Layer Sync flag is not set when in tid 0.
// clang-format off
if (
this->payloadDescriptor->tid > context->currentTemporalLayer &&
!this->payloadDescriptor->b &&
this->payloadDescriptor->tid == 0
)
// clang-format on
{
return false;
}
if (!payloadDescriptor) context->currentTemporalLayer = this->payloadDescriptor->tid;
return; }
}
auto* payloadDescriptorHandler = new PayloadDescriptorHandler(payloadDescriptor); return true;
}
packet->SetPayloadDescriptorHandler(payloadDescriptorHandler); void H264::PayloadDescriptorHandler::Restore(uint8_t* /*data*/)
{
MS_TRACE();
} }
} // namespace Codecs } // namespace Codecs
} // namespace RTC } // namespace RTC
...@@ -8,15 +8,21 @@ namespace RTC ...@@ -8,15 +8,21 @@ namespace RTC
{ {
namespace Codecs namespace Codecs
{ {
VP8::PayloadDescriptor* VP8::Parse(const uint8_t* data, size_t len) /* Class methods. */
VP8::PayloadDescriptor* VP8::Parse(
const uint8_t* data,
size_t len,
RTC::RtpPacket::FrameMarking* /*frameMarking*/,
uint8_t /*frameMarkingLen*/)
{ {
MS_TRACE(); MS_TRACE();
std::unique_ptr<PayloadDescriptor> payloadDescriptor(new PayloadDescriptor());
if (len < 1) if (len < 1)
return nullptr; return nullptr;
std::unique_ptr<PayloadDescriptor> payloadDescriptor(new PayloadDescriptor());
size_t offset{ 0 }; size_t offset{ 0 };
uint8_t byte = data[offset]; uint8_t byte = data[offset];
...@@ -99,6 +105,44 @@ namespace RTC ...@@ -99,6 +105,44 @@ namespace RTC
return payloadDescriptor.release(); return payloadDescriptor.release();
} }
void VP8::ProcessRtpPacket(RTC::RtpPacket* packet)
{
MS_TRACE();
auto* data = packet->GetPayload();
auto len = packet->GetPayloadLength();
RtpPacket::FrameMarking* frameMarking{ nullptr };
uint8_t frameMarkingLen{ 0 };
// Read frame-marking.
packet->ReadFrameMarking(&frameMarking, frameMarkingLen);
PayloadDescriptor* payloadDescriptor = VP8::Parse(data, len, frameMarking, frameMarkingLen);
if (!payloadDescriptor)
return;
auto* payloadDescriptorHandler = new PayloadDescriptorHandler(payloadDescriptor);
packet->SetPayloadDescriptorHandler(payloadDescriptorHandler);
// Modify the RtpPacket payload in order to always have two byte pictureId.
if (payloadDescriptor->hasOneBytePictureId)
{
// Shift the RTP payload one byte from the begining of the pictureId field.
packet->ShiftPayload(2, 1, true /*expand*/);
// Set the two byte pictureId marker bit.
data[2] = 0x80;
// Update the payloadDescriptor.
payloadDescriptor->hasOneBytePictureId = false;
payloadDescriptor->hasTwoBytesPictureId = true;
}
}
/* Instance methods. */
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
{ {
MS_TRACE(); MS_TRACE();
...@@ -135,7 +179,9 @@ namespace RTC ...@@ -135,7 +179,9 @@ namespace RTC
void VP8::PayloadDescriptor::Restore(uint8_t* data) const void VP8::PayloadDescriptor::Restore(uint8_t* data) const
{ {
this->Encode(data, this->pictureId, this->tl0PictureIndex); MS_TRACE();
Encode(data, this->pictureId, this->tl0PictureIndex);
} }
void VP8::PayloadDescriptor::Dump() const void VP8::PayloadDescriptor::Dump() const
...@@ -169,13 +215,17 @@ namespace RTC ...@@ -169,13 +215,17 @@ namespace RTC
VP8::PayloadDescriptorHandler::PayloadDescriptorHandler(VP8::PayloadDescriptor* payloadDescriptor) VP8::PayloadDescriptorHandler::PayloadDescriptorHandler(VP8::PayloadDescriptor* payloadDescriptor)
{ {
MS_TRACE();
this->payloadDescriptor.reset(payloadDescriptor); this->payloadDescriptor.reset(payloadDescriptor);
} }
bool VP8::PayloadDescriptorHandler::Encode( bool VP8::PayloadDescriptorHandler::Encode(
RTC::Codecs::EncodingContext* encodingContext, uint8_t* data) RTC::Codecs::EncodingContext* encodingContext, uint8_t* data)
{ {
auto* context = static_cast<EncodingContext*>(encodingContext); MS_TRACE();
auto* context = static_cast<RTC::Codecs::VP8::EncodingContext*>(encodingContext);
// Check whether pictureId and tl0PictureIndex sync is required. // Check whether pictureId and tl0PictureIndex sync is required.
if (context->syncRequired) if (context->syncRequired)
...@@ -186,12 +236,16 @@ namespace RTC ...@@ -186,12 +236,16 @@ namespace RTC
} }
// Incremental pictureId. Check the temporal layer. // Incremental pictureId. Check the temporal layer.
// clang-format off
if ( if (
this->payloadDescriptor->hasPictureId && this->payloadDescriptor->hasTlIndex && this->payloadDescriptor->hasPictureId &&
this->payloadDescriptor->hasTl0PictureIndex) this->payloadDescriptor->hasTlIndex &&
{ this->payloadDescriptor->hasTl0PictureIndex &&
if (RTC::SeqManager<uint16_t>::IsSeqHigherThan( RTC::SeqManager<uint16_t>::IsSeqHigherThan(
this->payloadDescriptor->pictureId, context->pictureIdManager.GetMaxInput())) this->payloadDescriptor->pictureId,
context->pictureIdManager.GetMaxInput())
)
// clang-format on
{ {
if (this->payloadDescriptor->tlIndex > context->preferences.temporalLayer) if (this->payloadDescriptor->tlIndex > context->preferences.temporalLayer)
{ {
...@@ -205,24 +259,24 @@ namespace RTC ...@@ -205,24 +259,24 @@ namespace RTC
// Payload descriptor contains the target temporal layer. // Payload descriptor contains the target temporal layer.
if (this->payloadDescriptor->tlIndex == context->preferences.temporalLayer) if (this->payloadDescriptor->tlIndex == context->preferences.temporalLayer)
{ {
// Upgrade required. // Upgrade required. Drop current packet if sync flag is not set.
if (context->currentTemporalLayer < this->payloadDescriptor->tlIndex) // clang-format off
{ if (
// Drop current packet if sync flag is not set. this->payloadDescriptor->tlIndex > context->currentTemporalLayer &&
if (this->payloadDescriptor->y != 1u) !this->payloadDescriptor->y
)
// clang-format on
{ {
context->pictureIdManager.Drop(this->payloadDescriptor->pictureId); context->pictureIdManager.Drop(this->payloadDescriptor->pictureId);
context->tl0PictureIndexManager.Drop(this->payloadDescriptor->tl0PictureIndex); context->tl0PictureIndexManager.Drop(this->payloadDescriptor->tl0PictureIndex);
return false; return false;
} }
}
context->currentTemporalLayer = this->payloadDescriptor->tlIndex; context->currentTemporalLayer = this->payloadDescriptor->tlIndex;
} }
} }
} }
}
// Update pictureId and tl0PictureIndex values. // Update pictureId and tl0PictureIndex values.
uint16_t pictureId; uint16_t pictureId;
...@@ -245,39 +299,10 @@ namespace RTC ...@@ -245,39 +299,10 @@ namespace RTC
}; };
void VP8::PayloadDescriptorHandler::Restore(uint8_t* data) void VP8::PayloadDescriptorHandler::Restore(uint8_t* data)
{
this->payloadDescriptor->Restore(data);
}
void VP8::ProcessRtpPacket(RTC::RtpPacket* packet)
{ {
MS_TRACE(); MS_TRACE();
auto data = packet->GetPayload(); this->payloadDescriptor->Restore(data);
auto len = packet->GetPayloadLength();
PayloadDescriptor* payloadDescriptor = Parse(data, len);
if (!payloadDescriptor)
return;
auto* payloadDescriptorHandler = new PayloadDescriptorHandler(payloadDescriptor);
packet->SetPayloadDescriptorHandler(payloadDescriptorHandler);
// Modify the RtpPacket payload in order to always have two byte pictureId.
if (payloadDescriptor->hasOneBytePictureId)
{
// Shift the RTP payload one byte from the begining of the pictureId field.
packet->ShiftPayload(2, 1, true /*expand*/);
// Set the two byte pictureId marker bit.
data[2] = 0x80;
// Update the payloadDescriptor.
payloadDescriptor->hasOneBytePictureId = false;
payloadDescriptor->hasTwoBytesPictureId = true;
}
} }
} // namespace Codecs } // namespace Codecs
} // namespace RTC } // namespace RTC
...@@ -171,6 +171,17 @@ namespace RTC ...@@ -171,6 +171,17 @@ namespace RTC
this->rtpHeaderExtensionIds.absSendTime = exten.id; this->rtpHeaderExtensionIds.absSendTime = exten.id;
} }
// NOTE: Remove this once framemarking draft becomes RFC.
if (this->rtpHeaderExtensionIds.frameMarking07 == 0u && exten.type == RTC::RtpHeaderExtensionUri::Type::FRAME_MARKING_07)
{
this->rtpHeaderExtensionIds.frameMarking07 = exten.id;
}
if (this->rtpHeaderExtensionIds.frameMarking == 0u && exten.type == RTC::RtpHeaderExtensionUri::Type::FRAME_MARKING)
{
this->rtpHeaderExtensionIds.frameMarking = exten.id;
}
if (this->rtpHeaderExtensionIds.ssrcAudioLevel == 0u && exten.type == RTC::RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL) if (this->rtpHeaderExtensionIds.ssrcAudioLevel == 0u && exten.type == RTC::RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL)
{ {
this->rtpHeaderExtensionIds.ssrcAudioLevel = exten.id; this->rtpHeaderExtensionIds.ssrcAudioLevel = exten.id;
...@@ -449,6 +460,9 @@ namespace RTC ...@@ -449,6 +460,9 @@ namespace RTC
return; return;
} }
// Pre-process the packet.
PreProcessRtpPacket(packet);
// Media packet. // Media packet.
if (packet->GetSsrc() == rtpStream->GetSsrc()) if (packet->GetSsrc() == rtpStream->GetSsrc())
{ {
...@@ -929,6 +943,18 @@ namespace RTC ...@@ -929,6 +943,18 @@ namespace RTC
this->listener->OnProducerNewRtpStream(this, static_cast<RTC::RtpStream*>(rtpStream), mappedSsrc); this->listener->OnProducerNewRtpStream(this, static_cast<RTC::RtpStream*>(rtpStream), mappedSsrc);
} }
inline void Producer::PreProcessRtpPacket(RTC::RtpPacket* packet)
{
MS_TRACE();
if (this->kind == RTC::Media::Kind::VIDEO)
{
// NOTE: Remove this once framemarking draft becomes RFC.
packet->SetFrameMarking07ExtensionId(this->rtpHeaderExtensionIds.frameMarking07);
packet->SetFrameMarkingExtensionId(this->rtpHeaderExtensionIds.frameMarking);
}
}
inline bool Producer::MangleRtpPacket(RTC::RtpPacket* packet, RTC::RtpStreamRecv* rtpStream) const inline bool Producer::MangleRtpPacket(RTC::RtpPacket* packet, RTC::RtpStreamRecv* rtpStream) const
{ {
MS_TRACE(); MS_TRACE();
...@@ -989,47 +1015,76 @@ namespace RTC ...@@ -989,47 +1015,76 @@ namespace RTC
} }
else if (this->kind == RTC::Media::Kind::VIDEO) else if (this->kind == RTC::Media::Kind::VIDEO)
{ {
// Proxy urn:3gpp:video-orientation. // Add http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time.
extenValue = packet->GetExtension(this->rtpHeaderExtensionIds.videoOrientation, extenLen); // NOTE: Just if this is simulcast or SVC.
if (this->type == RTC::RtpParameters::Type::SIMULCAST || this->type == RTC::RtpParameters::Type::SVC)
{
extenLen = 3u;
auto now = DepLibUV::GetTime();
auto absSendTime = static_cast<uint32_t>(((now << 18) + 500) / 1000) & 0x00FFFFFF;
Utils::Byte::Set3Bytes(bufferPtr, 0, absSendTime);
extensions.emplace_back(
static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::ABS_SEND_TIME), extenLen, bufferPtr);
}
// NOTE: Remove this once framemarking draft becomes RFC.
// Proxy urn:ietf:params:rtp-hdrext:framemarking.
extenValue = packet->GetExtension(this->rtpHeaderExtensionIds.frameMarking07, extenLen);
if (extenValue) if (extenValue)
{ {
std::memcpy(bufferPtr, extenValue, extenLen); std::memcpy(bufferPtr, extenValue, extenLen);
extensions.emplace_back( extensions.emplace_back(
static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::VIDEO_ORIENTATION), static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::FRAME_MARKING_07),
extenLen, extenLen,
bufferPtr); bufferPtr);
bufferPtr += extenLen; bufferPtr += extenLen;
} }
// Proxy urn:ietf:params:rtp-hdrext:toffset. // Proxy urn:ietf:params:rtp-hdrext:framemarking.
extenValue = packet->GetExtension(this->rtpHeaderExtensionIds.toffset, extenLen); extenValue = packet->GetExtension(this->rtpHeaderExtensionIds.frameMarking, extenLen);
if (extenValue) if (extenValue)
{ {
std::memcpy(bufferPtr, extenValue, extenLen); std::memcpy(bufferPtr, extenValue, extenLen);
extensions.emplace_back( extensions.emplace_back(
static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::TOFFSET), extenLen, bufferPtr); static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::FRAME_MARKING), extenLen, bufferPtr);
bufferPtr += extenLen; bufferPtr += extenLen;
} }
// Add http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time. // Proxy urn:3gpp:video-orientation.
// NOTE: Just if this is simulcast or SVC. extenValue = packet->GetExtension(this->rtpHeaderExtensionIds.videoOrientation, extenLen);
if (this->type == RTC::RtpParameters::Type::SIMULCAST || this->type == RTC::RtpParameters::Type::SVC)
if (extenValue)
{ {
extenLen = 3u; std::memcpy(bufferPtr, extenValue, extenLen);
auto now = DepLibUV::GetTime(); extensions.emplace_back(
auto absSendTime = static_cast<uint32_t>(((now << 18) + 500) / 1000) & 0x00FFFFFF; static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::VIDEO_ORIENTATION),
extenLen,
bufferPtr);
Utils::Byte::Set3Bytes(bufferPtr, 0, absSendTime); bufferPtr += extenLen;
}
// Proxy urn:ietf:params:rtp-hdrext:toffset.
extenValue = packet->GetExtension(this->rtpHeaderExtensionIds.toffset, extenLen);
if (extenValue)
{
std::memcpy(bufferPtr, extenValue, extenLen);
extensions.emplace_back( extensions.emplace_back(
static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::ABS_SEND_TIME), extenLen, bufferPtr); static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::TOFFSET), extenLen, bufferPtr);
bufferPtr += extenLen;
} }
} }
...@@ -1040,6 +1095,11 @@ namespace RTC ...@@ -1040,6 +1095,11 @@ namespace RTC
// be interested in after passing it to the Router). // be interested in after passing it to the Router).
packet->SetAbsSendTimeExtensionId( packet->SetAbsSendTimeExtensionId(
static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::ABS_SEND_TIME)); static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::ABS_SEND_TIME));
// NOTE: Remove this once framemarking draft becomes RFC.
packet->SetFrameMarking07ExtensionId(
static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::FRAME_MARKING_07));
packet->SetFrameMarkingExtensionId(
static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::FRAME_MARKING));
packet->SetSsrcAudioLevelExtensionId( packet->SetSsrcAudioLevelExtensionId(
static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL)); static_cast<uint8_t>(RTC::RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL));
packet->SetVideoOrientationExtensionId( packet->SetVideoOrientationExtensionId(
......
...@@ -17,6 +17,9 @@ namespace RTC ...@@ -17,6 +17,9 @@ namespace RTC
{ "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id", RtpHeaderExtensionUri::Type::REPAIRED_RTP_STREAM_ID }, { "urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id", RtpHeaderExtensionUri::Type::REPAIRED_RTP_STREAM_ID },
{ "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", RtpHeaderExtensionUri::Type::ABS_SEND_TIME }, { "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", RtpHeaderExtensionUri::Type::ABS_SEND_TIME },
{ "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01", RtpHeaderExtensionUri::Type::TRANSPORT_CC_01 }, { "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01", RtpHeaderExtensionUri::Type::TRANSPORT_CC_01 },
// NOTE: Remove this once framemarking draft becomes RFC.
{ "http://tools.ietf.org/html/draft-ietf-avtext-framemarking-07", RtpHeaderExtensionUri::Type::FRAME_MARKING_07 },
{ "urn:ietf:params:rtp-hdrext:framemarking", RtpHeaderExtensionUri::Type::FRAME_MARKING },
{ "urn:ietf:params:rtp-hdrext:ssrc-audio-level", RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL }, { "urn:ietf:params:rtp-hdrext:ssrc-audio-level", RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL },
{ "urn:3gpp:video-orientation", RtpHeaderExtensionUri::Type::VIDEO_ORIENTATION }, { "urn:3gpp:video-orientation", RtpHeaderExtensionUri::Type::VIDEO_ORIENTATION },
{ "urn:ietf:params:rtp-hdrext:toffset", RtpHeaderExtensionUri::Type::TOFFSET } { "urn:ietf:params:rtp-hdrext:toffset", RtpHeaderExtensionUri::Type::TOFFSET }
......
...@@ -222,6 +222,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -222,6 +222,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
REQUIRE(packet->GetHeaderExtensionLength() == 12); REQUIRE(packet->GetHeaderExtensionLength() == 12);
REQUIRE(packet->HasOneByteExtensions()); REQUIRE(packet->HasOneByteExtensions());
REQUIRE(packet->HasTwoBytesExtensions() == false); REQUIRE(packet->HasTwoBytesExtensions() == false);
REQUIRE(packet->GetPayloadLength() == 0);
delete packet; delete packet;
} }
...@@ -259,6 +260,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -259,6 +260,7 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
REQUIRE(packet->GetHeaderExtensionLength() == 16); REQUIRE(packet->GetHeaderExtensionLength() == 16);
REQUIRE(packet->HasOneByteExtensions() == false); REQUIRE(packet->HasOneByteExtensions() == false);
REQUIRE(packet->HasTwoBytesExtensions()); REQUIRE(packet->HasTwoBytesExtensions());
REQUIRE(packet->GetPayloadLength() == 0);
extenValue = packet->GetExtension(1, extenLen); extenValue = packet->GetExtension(1, extenLen);
REQUIRE(extenValue == nullptr); REQUIRE(extenValue == nullptr);
...@@ -724,4 +726,54 @@ SCENARIO("parse RTP packets", "[parser][rtp]") ...@@ -724,4 +726,54 @@ SCENARIO("parse RTP packets", "[parser][rtp]")
delete packet; delete packet;
} }
SECTION("read frame-marking extension")
{
// clang-format off
uint8_t buffer[] =
{
0b10010000, 0b00000001, 0, 8,
0, 0, 0, 4,
0, 0, 0, 5,
0xBE, 0xDE, 0, 1, // Header Extension
0b00110010, 0b10101011, 1, 5,
1, 2, 3, 4
};
// clang-format on
RtpPacket* packet = RtpPacket::Parse(buffer, sizeof(buffer));
if (!packet)
FAIL("not a RTP packet");
REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true);
REQUIRE(packet->GetPayloadType() == 1);
REQUIRE(packet->GetSequenceNumber() == 8);
REQUIRE(packet->GetTimestamp() == 4);
REQUIRE(packet->GetSsrc() == 5);
REQUIRE(packet->GetHeaderExtensionId() == 0xBEDE);
REQUIRE(packet->GetHeaderExtensionLength() == 4);
REQUIRE(packet->HasOneByteExtensions());
REQUIRE(packet->HasTwoBytesExtensions() == false);
REQUIRE(packet->GetPayloadLength() == 4);
packet->SetFrameMarkingExtensionId(3);
RtpPacket::FrameMarking* frameMarking;
uint8_t frameMarkingLen;
REQUIRE(packet->ReadFrameMarking(&frameMarking, frameMarkingLen) == true);
REQUIRE(frameMarkingLen == 3);
REQUIRE(frameMarking->start == 1);
REQUIRE(frameMarking->end == 0);
REQUIRE(frameMarking->independent == 1);
REQUIRE(frameMarking->discardable == 0);
REQUIRE(frameMarking->base == 1);
REQUIRE(frameMarking->tid == 3);
REQUIRE(frameMarking->lid == 1);
REQUIRE(frameMarking->tl0picidx == 5);
delete packet;
}
} }
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论