Unverified 提交 3bdcb8a8 authored 作者: prtmD's avatar prtmD 提交者: GitHub

Add support for H264 SVC (#798)

上级 4556001e
......@@ -828,6 +828,7 @@ function matchCodecs(aCodec, bCodec, { strict = false, modify = false } = {}) {
break;
}
case 'video/h264':
case 'video/h264-svc':
{
if (strict) {
const aPacketizationMode = aCodec.parameters['packetization-mode'] || 0;
......
{"version":3,"file":"supportedRtpCapabilities.d.ts","sourceRoot":"","sources":["../src/supportedRtpCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,QAAA,MAAM,wBAAwB,EAAE,eAgX/B,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
\ No newline at end of file
{"version":3,"file":"supportedRtpCapabilities.d.ts","sourceRoot":"","sources":["../src/supportedRtpCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,QAAA,MAAM,wBAAwB,EAAE,eA+X/B,CAAC;AAEF,OAAO,EAAE,wBAAwB,EAAE,CAAC"}
\ No newline at end of file
......@@ -217,6 +217,21 @@ const supportedRtpCapabilities = {
{ type: 'transport-cc' }
]
},
{
kind: 'video',
mimeType: 'video/H264-SVC',
clockRate: 90000,
parameters: {
'level-asymmetry-allowed': 1
},
rtcpFeedback: [
{ type: 'nack' },
{ type: 'nack', parameter: 'pli' },
{ type: 'ccm', parameter: 'fir' },
{ type: 'goog-remb' },
{ type: 'transport-cc' }
]
},
{
kind: 'video',
mimeType: 'video/H265',
......
......@@ -1223,6 +1223,7 @@ function matchCodecs(
}
case 'video/h264':
case 'video/h264-svc':
{
if (strict)
{
......
......@@ -240,6 +240,21 @@ const supportedRtpCapabilities: RtpCapabilities =
{ type: 'transport-cc' }
]
},
{
kind : 'video',
mimeType : 'video/H264-SVC',
clockRate : 90000,
parameters : {
'level-asymmetry-allowed' : 1
},
rtcpFeedback : [
{ type: 'nack' },
{ type: 'nack', parameter: 'pli' },
{ type: 'ccm', parameter: 'fir' },
{ type: 'goog-remb' },
{ type: 'transport-cc' }
]
},
{
kind : 'video',
mimeType : 'video/H265',
......
......@@ -999,7 +999,7 @@ fn match_codecs(
return Err(());
}
}
MimeType::Video(MimeTypeVideo::H264) => {
MimeType::Video(MimeTypeVideo::H264 | MimeTypeVideo::H264Svc) => {
if strict {
let packetization_mode_a = codec_a
.parameters
......
......@@ -264,6 +264,9 @@ pub enum MimeTypeVideo {
/// H264
#[serde(rename = "video/H264")]
H264,
/// H264-SVC
#[serde(rename = "video/H264-SVC")]
H264Svc,
/// H265
#[serde(rename = "video/H265")]
H265,
......
......@@ -245,6 +245,22 @@ pub fn get_supported_rtp_capabilities() -> RtpCapabilities {
RtcpFeedback::TransportCc,
],
},
RtpCodecCapability::Video {
mime_type: MimeTypeVideo::H264Svc,
preferred_payload_type: None,
clock_rate: NonZeroU32::new(90000).unwrap(),
parameters: RtpCodecParametersParameters::from([(
"level-asymmetry-allowed",
1_u32.into(),
)]),
rtcp_feedback: vec![
RtcpFeedback::Nack,
RtcpFeedback::NackPli,
RtcpFeedback::CcmFir,
RtcpFeedback::GoogRemb,
RtcpFeedback::TransportCc,
],
},
RtpCodecCapability::Video {
mime_type: MimeTypeVideo::H265,
preferred_payload_type: None,
......
#ifndef MS_RTC_CODECS_H264_SVC_HPP
#define MS_RTC_CODECS_H264_SVC_HPP
#include "common.hpp"
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/RtpPacket.hpp"
#include "RTC/SeqManager.hpp"
namespace RTC
{
namespace Codecs
{
class H264_SVC
{
public:
struct PayloadDescriptor : public RTC::Codecs::PayloadDescriptor
{
~PayloadDescriptor() = default;
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 slIndex{ 0 }; // Temporal layer id.
uint8_t tlIndex{ 0 }; // Spatial layer id.
uint8_t tl0picidx{ 0 }; // TL0PICIDX
// Parsed values.
bool hasSlIndex{ false };
bool hasTlIndex{ false };
bool hasTl0picidx{ false };
bool isKeyFrame{ false };
// Extension fields.
uint8_t idr{ 0 };
uint8_t priorityId{ 0 };
uint8_t noIntLayerPredFlag{ true };
};
public:
static H264_SVC::PayloadDescriptor* Parse(
const uint8_t* data,
size_t len,
RTC::RtpPacket::FrameMarking* frameMarking = nullptr,
uint8_t frameMarkingLen = 0);
static std::unique_ptr<H264_SVC::PayloadDescriptor> ParseSingleNalu(
const uint8_t* data,
size_t len,
std::unique_ptr<H264_SVC::PayloadDescriptor> payloadDescriptor,
bool isStartBit); // useful in FU packet to indicate first packet. Set to true for other packets
static void ProcessRtpPacket(RTC::RtpPacket* packet);
public:
class EncodingContext : public RTC::Codecs::EncodingContext
{
public:
explicit EncodingContext(RTC::Codecs::EncodingContext::Params& params)
: RTC::Codecs::EncodingContext(params)
{
}
~EncodingContext() = default;
/* Pure virtual methods inherited from RTC::Codecs::EncodingContext. */
public:
void SyncRequired() override
{
}
public:
RTC::SeqManager<uint16_t> pictureIdManager;
bool syncRequired{ false };
};
public:
class PayloadDescriptorHandler : public RTC::Codecs::PayloadDescriptorHandler
{
public:
explicit PayloadDescriptorHandler(PayloadDescriptor* payloadDescriptor);
~PayloadDescriptorHandler() = default;
public:
void Dump() const override
{
this->payloadDescriptor->Dump();
}
bool Process(RTC::Codecs::EncodingContext* encodingContext, uint8_t* data, bool& marker) override;
void Restore(uint8_t* data) override;
uint8_t GetSpatialLayer() const override
{
// return 0u;
return this->payloadDescriptor->hasSlIndex ? this->payloadDescriptor->slIndex : 0u;
}
uint8_t GetTemporalLayer() const override
{
// return this->payloadDescriptor->tid;
return this->payloadDescriptor->hasTlIndex ? this->payloadDescriptor->tlIndex : 0u;
}
bool IsKeyFrame() const override
{
return this->payloadDescriptor->isKeyFrame;
}
private:
std::unique_ptr<PayloadDescriptor> payloadDescriptor;
};
};
} // namespace Codecs
} // namespace RTC
#endif
......@@ -3,6 +3,7 @@
#include "common.hpp"
#include "RTC/Codecs/H264.hpp"
#include "RTC/Codecs/H264_SVC.hpp"
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/Codecs/VP8.hpp"
#include "RTC/Codecs/VP9.hpp"
......@@ -29,6 +30,7 @@ namespace RTC
case RTC::RtpCodecMimeType::Subtype::VP8:
case RTC::RtpCodecMimeType::Subtype::VP9:
case RTC::RtpCodecMimeType::Subtype::H264:
case RTC::RtpCodecMimeType::Subtype::H264_SVC:
return true;
default:
return false;
......@@ -70,6 +72,12 @@ namespace RTC
break;
}
case RTC::RtpCodecMimeType::Subtype::H264_SVC:
{
RTC::Codecs::H264_SVC::ProcessRtpPacket(packet);
break;
}
default:;
}
......@@ -125,6 +133,7 @@ namespace RTC
switch (mimeType.subtype)
{
case RTC::RtpCodecMimeType::Subtype::VP9:
case RTC::RtpCodecMimeType::Subtype::H264_SVC:
return true;
default:
return false;
......@@ -165,6 +174,8 @@ namespace RTC
return new RTC::Codecs::VP9::EncodingContext(params);
case RTC::RtpCodecMimeType::Subtype::H264:
return new RTC::Codecs::H264::EncodingContext(params);
case RTC::RtpCodecMimeType::Subtype::H264_SVC:
return new RTC::Codecs::H264_SVC::EncodingContext(params);
default:
return nullptr;
}
......
......@@ -60,6 +60,7 @@ namespace RTC
VP8 = 200,
VP9,
H264,
H264_SVC,
X_H264UC,
H265,
// Complementary codecs:
......
......@@ -99,6 +99,7 @@ common_sources = [
'src/RTC/UdpSocket.cpp',
'src/RTC/WebRtcTransport.cpp',
'src/RTC/Codecs/H264.cpp',
'src/RTC/Codecs/H264_SVC.cpp',
'src/RTC/Codecs/VP8.cpp',
'src/RTC/Codecs/VP9.cpp',
'src/RTC/RtpDictionaries/Media.cpp',
......@@ -269,12 +270,15 @@ mediasoup_worker_test = executable(
'test/src/RTC/TestNackGenerator.cpp',
'test/src/RTC/TestRateCalculator.cpp',
'test/src/RTC/TestRtpPacket.cpp',
'test/src/RTC/TestRtpPacketH264Svc.cpp',
'test/src/RTC/TestRtpStreamSend.cpp',
'test/src/RTC/TestRtpStreamRecv.cpp',
'test/src/RTC/TestSeqManager.cpp',
'test/src/RTC/TestTrendCalculator.cpp',
'test/src/RTC/TestRtpEncodingParameters.cpp',
'test/src/RTC/Codecs/TestVP8.cpp',
'test/src/RTC/Codecs/TestH264.cpp',
'test/src/RTC/Codecs/TestH264_SVC.cpp',
'test/src/RTC/RTCP/TestFeedbackPsAfb.cpp',
'test/src/RTC/RTCP/TestFeedbackPsFir.cpp',
'test/src/RTC/RTCP/TestFeedbackPsLei.cpp',
......
#define MS_CLASS "RTC::Codecs::H264_SVC"
#include "RTC/Codecs/H264_SVC.hpp"
#include "Logger.hpp"
#include "Utils.hpp"
namespace RTC
{
namespace Codecs
{
/* Class methods. */
H264_SVC::PayloadDescriptor* H264_SVC::Parse(
const uint8_t* data, size_t len, RTC::RtpPacket::FrameMarking* frameMarking, uint8_t frameMarkingLen)
{
MS_TRACE();
if (len < 2)
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->tlIndex = frameMarking->tid;
payloadDescriptor->hasTlIndex = true;
if (frameMarkingLen >= 2)
{
payloadDescriptor->hasSlIndex = true;
payloadDescriptor->slIndex = frameMarking->lid >> 4 & 0x07;
}
if (frameMarkingLen == 3)
{
payloadDescriptor->hasTl0picidx = true;
payloadDescriptor->tl0picidx = frameMarking->tl0picidx;
}
// Detect key frame.
if (frameMarking->start && frameMarking->independent)
payloadDescriptor->isKeyFrame = true;
}
// NOTE: Unfortunately libwebrtc produces wrong Frame-Marking (without i=1 in
// keyframes) when it uses H264 hardware encoder (at least in Mac):
// https://bugs.chromium.org/p/webrtc/issues/detail?id=10746
//
// As a temporal workaround, always do payload parsing to detect keyframes if
// there is no frame-marking or if there is but keyframe was not detected above.
if (!frameMarking || !payloadDescriptor->isKeyFrame)
{
uint8_t nal = *data & 0x1F;
switch (nal)
{
// Single NAL unit packet.
// IDR (instantaneous decoding picture).
case 1:
case 5:
case 7:
case 14:
case 20:
{
payloadDescriptor =
H264_SVC::ParseSingleNalu(data, len, std::move(payloadDescriptor), true);
if (payloadDescriptor == nullptr)
return nullptr;
break;
}
// Aggreation packet.
// STAP-A.
case 24:
{
size_t offset{ 1 };
len -= 1;
// Iterate NAL units.
while (len >= 3)
{
auto naluSize = Utils::Byte::Get2Bytes(data, offset);
payloadDescriptor = H264_SVC::ParseSingleNalu(
(data + offset + sizeof(naluSize)),
(len - sizeof(naluSize)),
std::move(payloadDescriptor),
true);
if (payloadDescriptor == nullptr)
return nullptr;
if (payloadDescriptor->isKeyFrame)
{
break;
}
// Check if there is room for the indicated NAL unit size.
if (len < (naluSize + sizeof(naluSize)))
break;
offset += naluSize + sizeof(naluSize);
len -= naluSize + sizeof(naluSize);
}
break;
}
// Aggreation packet.
// FU-A, FU-B.
case 28:
case 29:
{
uint8_t startBit = *(data + 1) & 0x80;
if (startBit == 128)
{
payloadDescriptor = H264_SVC::ParseSingleNalu(
(data + 1), (len - 1), std::move(payloadDescriptor), (startBit == 128 ? true : false));
}
if (payloadDescriptor == nullptr)
return nullptr;
break;
}
}
}
return payloadDescriptor.release();
}
std::unique_ptr<H264_SVC::PayloadDescriptor> H264_SVC::ParseSingleNalu(
const uint8_t* data,
size_t len,
std::unique_ptr<H264_SVC::PayloadDescriptor> payloadDescriptor,
bool isStartBit)
{
uint8_t nal = *data & 0x1F;
switch (nal)
{
// Single NAL unit packet.
// IDR (instantaneous decoding picture).
case 5:
payloadDescriptor->isKeyFrame = true;
case 1:
{
payloadDescriptor->slIndex = 0;
payloadDescriptor->tlIndex = 0;
payloadDescriptor->hasSlIndex = false;
payloadDescriptor->hasTlIndex = false;
break;
}
case 14:
case 20:
{
size_t offset{ 1 };
uint8_t byte = data[offset];
payloadDescriptor->idr = byte >> 6 & 0x01;
payloadDescriptor->priorityId = byte & 0x06;
payloadDescriptor->isKeyFrame = (isStartBit && payloadDescriptor->idr) ? true : false;
if (len < ++offset + 1)
return nullptr;
byte = data[offset];
payloadDescriptor->noIntLayerPredFlag = byte >> 7 & 0x01;
payloadDescriptor->slIndex = byte >> 4 & 0x03;
if (len < ++offset + 1)
return nullptr;
byte = data[offset];
payloadDescriptor->tlIndex = byte >> 5 & 0x03;
payloadDescriptor->hasSlIndex = payloadDescriptor->slIndex ? true : false;
payloadDescriptor->hasTlIndex = payloadDescriptor->tlIndex ? true : false;
break;
}
case 7:
{
payloadDescriptor->isKeyFrame = isStartBit ? true : false;
break;
}
}
return payloadDescriptor;
}
void H264_SVC::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_SVC::Parse(data, len, frameMarking, frameMarkingLen);
if (!payloadDescriptor)
return;
auto* payloadDescriptorHandler = new PayloadDescriptorHandler(payloadDescriptor);
packet->SetPayloadDescriptorHandler(payloadDescriptorHandler);
}
/* Instance methods. */
void H264_SVC::PayloadDescriptor::Dump() const
{
MS_TRACE();
MS_DUMP("<PayloadDescriptor>");
MS_DUMP(
" s:%" PRIu8 "|e:%" PRIu8 "|i:%" PRIu8 "|d:%" PRIu8 "|b:%" PRIu8,
this->s,
this->e,
this->i,
this->d,
this->b);
MS_DUMP(" hasSlIndex : %s", this->hasSlIndex ? "true" : "false");
MS_DUMP(" hasTlIndex : %s", this->hasTlIndex ? "true" : "false");
MS_DUMP(" tl0picidx : %" PRIu8, this->tl0picidx);
MS_DUMP(" noIntLayerPredFlag : %" PRIu8, this->noIntLayerPredFlag);
MS_DUMP(" isKeyFrame : %s", this->isKeyFrame ? "true" : "false");
MS_DUMP("</PayloadDescriptor>");
}
H264_SVC::PayloadDescriptorHandler::PayloadDescriptorHandler(
H264_SVC::PayloadDescriptor* payloadDescriptor)
{
MS_TRACE();
this->payloadDescriptor.reset(payloadDescriptor);
}
bool H264_SVC::PayloadDescriptorHandler::Process(
RTC::Codecs::EncodingContext* encodingContext, uint8_t* /*data*/, bool& marker)
{
MS_TRACE();
auto* context = static_cast<RTC::Codecs::H264_SVC::EncodingContext*>(encodingContext);
MS_ASSERT(context->GetTargetSpatialLayer() >= 0, "target spatial layer cannot be -1");
MS_ASSERT(context->GetTargetTemporalLayer() >= 0, "target temporal layer cannot be -1");
auto packetSpatialLayer = GetSpatialLayer();
auto packetTemporalLayer = GetTemporalLayer();
auto tmpSpatialLayer = context->GetCurrentSpatialLayer();
auto tmpTemporalLayer = context->GetCurrentTemporalLayer();
// If packet spatial or temporal layer is higher than maximum announced
// one, drop the packet.
// clang-format off
if (
packetSpatialLayer >= context->GetSpatialLayers() ||
packetTemporalLayer >= context->GetTemporalLayers()
)
// clang-format on
{
MS_WARN_TAG(
rtp, "too high packet layers %" PRIu8 ":%" PRIu8, packetSpatialLayer, packetTemporalLayer);
return false;
}
// clang-format off
bool isOldPacket = false;
// Upgrade current spatial layer if needed.
if (context->GetTargetSpatialLayer() > context->GetCurrentSpatialLayer())
{
if (this->payloadDescriptor->isKeyFrame)
{
MS_DEBUG_DEV(
"upgrading tmpSpatialLayer from %" PRIu16 " to %" PRIu16 " (packet:%" PRIu8 ":%" PRIu8
")",
context->GetCurrentSpatialLayer(),
context->GetTargetSpatialLayer(),
packetSpatialLayer,
packetTemporalLayer);
tmpSpatialLayer = context->GetTargetSpatialLayer();
tmpTemporalLayer = 0; // Just in case.
}
}
// Downgrade current spatial layer if needed.
else if (context->GetTargetSpatialLayer() < context->GetCurrentSpatialLayer())
{
// In K-SVC we must wait for a keyframe.
if (context->IsKSvc())
{
if (this->payloadDescriptor->isKeyFrame)
// clang-format on
{
MS_DEBUG_DEV(
"downgrading tmpSpatialLayer from %" PRIu16 " to %" PRIu16 " (packet:%" PRIu8
":%" PRIu8 ") after keyframe (K-SVC)",
context->GetCurrentSpatialLayer(),
context->GetTargetSpatialLayer(),
packetSpatialLayer,
packetTemporalLayer);
tmpSpatialLayer = context->GetTargetSpatialLayer();
tmpTemporalLayer = 0; // Just in case.
}
}
// In full SVC we do not need a keyframe.
else
{
// clang-format off
if (
packetSpatialLayer == context->GetTargetSpatialLayer() &&
this->payloadDescriptor->e
)
// clang-format on
{
MS_DEBUG_DEV(
"downgrading tmpSpatialLayer from %" PRIu16 " to %" PRIu16 " (packet:%" PRIu8
":%" PRIu8 ") without keyframe (full SVC)",
context->GetCurrentSpatialLayer(),
context->GetTargetSpatialLayer(),
packetSpatialLayer,
packetTemporalLayer);
tmpSpatialLayer = context->GetTargetSpatialLayer();
tmpTemporalLayer = 0; // Just in case.
}
}
}
// Filter spatial layers higher than current one (unless old packet).
if (packetSpatialLayer > tmpSpatialLayer && !isOldPacket)
return false;
// Check and handle temporal layer (unless old packet).
if (!isOldPacket)
{
// Upgrade current temporal layer if needed.
if (context->GetTargetTemporalLayer() > context->GetCurrentTemporalLayer())
{
// clang-format off
if (
packetTemporalLayer >= context->GetCurrentTemporalLayer() + 1 &&
this->payloadDescriptor->s
)
// clang-format on
{
MS_DEBUG_DEV(
"upgrading tmpTemporalLayer from %" PRIu16 " to %" PRIu8 " (packet:%" PRIu8 ":%" PRIu8
")",
context->GetCurrentTemporalLayer(),
packetTemporalLayer,
packetSpatialLayer,
packetTemporalLayer);
tmpTemporalLayer = packetTemporalLayer;
}
}
// Downgrade current temporal layer if needed.
else if (context->GetTargetTemporalLayer() < context->GetCurrentTemporalLayer())
{
// clang-format off
if (
packetTemporalLayer == context->GetTargetTemporalLayer() &&
this->payloadDescriptor->e
)
// clang-format on
{
MS_DEBUG_DEV(
"downgrading tmpTemporalLayer from %" PRIu16 " to %" PRIu16 " (packet:%" PRIu8
":%" PRIu8 ")",
context->GetCurrentTemporalLayer(),
context->GetTargetTemporalLayer(),
packetSpatialLayer,
packetTemporalLayer);
tmpTemporalLayer = context->GetTargetTemporalLayer();
}
}
// Filter temporal layers higher than current one.
if (packetTemporalLayer > tmpTemporalLayer)
return false;
}
// Set marker bit if needed.
if (packetSpatialLayer == tmpSpatialLayer && this->payloadDescriptor->e)
marker = true;
// Update current spatial layer if needed.
if (tmpSpatialLayer != context->GetCurrentSpatialLayer())
context->SetCurrentSpatialLayer(tmpSpatialLayer);
// Update current temporal layer if needed.
if (tmpTemporalLayer != context->GetCurrentTemporalLayer())
context->SetCurrentTemporalLayer(tmpTemporalLayer);
return true;
}
void H264_SVC::PayloadDescriptorHandler::Restore(uint8_t* /*data*/)
{
MS_TRACE();
}
} // namespace Codecs
} // namespace RTC
......@@ -36,6 +36,7 @@ namespace RTC
{ "vp8", RtpCodecMimeType::Subtype::VP8 },
{ "vp9", RtpCodecMimeType::Subtype::VP9 },
{ "h264", RtpCodecMimeType::Subtype::H264 },
{ "h264-svc", RtpCodecMimeType::Subtype::H264_SVC },
{ "x-h264uc", RtpCodecMimeType::Subtype::X_H264UC },
{ "h265", RtpCodecMimeType::Subtype::H265 },
// Complementary codecs:
......@@ -63,6 +64,7 @@ namespace RTC
{ RtpCodecMimeType::Subtype::VP8, "VP8" },
{ RtpCodecMimeType::Subtype::VP9, "VP9" },
{ RtpCodecMimeType::Subtype::H264, "H264" },
{ RtpCodecMimeType::Subtype::H264_SVC, "H264-SVC" },
{ RtpCodecMimeType::Subtype::X_H264UC, "X-H264UC" },
{ RtpCodecMimeType::Subtype::H265, "H265" },
// Complementary codecs:
......
type,length,SId,TID,isIDR,firstSliceID,lastSliceID
7,13,-1,-1,-1,-1,-1
15,16,-1,-1,-1,-1,-1
8,10,-1,-1,-1,-1,-1
8,11,-1,-1,-1,-1,-1
14,9,-1,-1,-1,-1,-1
5,2023,0,0,1,0,0
20,4747,1,0,1,0,0
14,9,-1,-1,-1,-1,-1
1,144,0,1,0,0,0
20,514,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,148,0,2,0,0,0
20,716,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,310,0,0,0,0,0
20,1071,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,154,0,1,0,0,0
20,579,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,144,0,2,0,0,0
20,719,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,320,0,0,0,0,0
20,1039,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,148,0,1,0,0,0
20,594,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,179,0,2,0,0,0
20,707,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,252,0,0,0,0,0
20,1073,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,146,0,1,0,0,0
20,632,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,177,0,2,0,0,0
20,722,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,312,0,0,0,0,0
20,1157,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,179,0,1,0,0,0
20,716,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,207,0,2,0,0,0
20,857,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,368,0,0,0,0,0
20,1261,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,175,0,1,0,0,0
20,776,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,183,0,2,0,0,0
20,824,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,326,0,0,0,0,0
20,1258,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,188,0,1,0,0,0
20,676,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,189,0,2,0,0,0
20,828,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,333,0,0,0,0,0
20,1371,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,158,0,1,0,0,0
20,755,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,250,0,2,0,0,0
20,884,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,492,0,0,0,0,0
20,1744,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,274,0,1,0,0,0
20,1004,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,330,0,2,0,0,0
20,1122,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,580,0,0,0,0,0
20,1807,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,404,0,1,0,0,0
20,1397,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,462,0,2,0,0,0
20,1605,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,682,0,0,0,0,0
20,2205,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,439,0,1,0,0,0
20,1380,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,464,0,2,0,0,0
20,1525,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,694,0,0,0,0,0
20,2232,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,503,0,1,0,0,0
20,1488,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,548,0,2,0,0,0
20,1647,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,718,0,0,0,0,0
20,2207,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,624,0,1,0,0,0
20,1811,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,631,0,2,0,0,0
20,1739,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,790,0,0,0,0,0
20,2487,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,523,0,1,0,0,0
20,1684,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,563,0,2,0,0,0
20,1660,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,784,0,0,0,0,0
20,2331,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,535,0,1,0,0,0
20,1516,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,480,0,2,0,0,0
20,1579,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,679,0,0,0,0,0
20,2205,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,379,0,1,0,0,0
20,1363,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,393,0,2,0,0,0
20,1342,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,596,0,0,0,0,0
20,1902,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,351,0,1,0,0,0
20,1081,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,256,0,2,0,0,0
20,963,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,451,0,0,0,0,0
20,1590,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,185,0,1,0,0,0
20,704,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,182,0,2,0,0,0
20,687,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,415,0,0,0,0,0
20,1421,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,182,0,1,0,0,0
20,705,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,217,0,2,0,0,0
20,981,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,426,0,0,0,0,0
20,1702,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,162,0,1,0,0,0
20,588,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,155,0,2,0,0,0
20,710,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,284,0,0,0,0,0
20,1115,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,151,0,1,0,0,0
20,541,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,147,0,2,0,0,0
20,527,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,267,0,0,0,0,0
20,925,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,130,0,1,0,0,0
20,563,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,132,0,2,0,0,0
20,603,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,275,0,0,0,0,0
20,1089,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,111,0,1,0,0,0
20,594,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,162,0,2,0,0,0
20,620,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,265,0,0,0,0,0
20,1105,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,149,0,1,0,0,0
20,577,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,150,0,2,0,0,0
20,586,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,296,0,0,0,0,0
20,1009,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,86,0,1,0,0,0
20,474,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,160,0,2,0,0,0
20,481,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,278,0,0,0,0,0
20,934,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,117,0,1,0,0,0
20,500,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,155,0,2,0,0,0
20,559,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,233,0,0,0,0,0
20,932,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,107,0,1,0,0,0
20,470,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,91,0,2,0,0,0
20,574,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,202,0,0,0,0,0
20,982,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,132,0,1,0,0,0
20,558,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,132,0,2,0,0,0
20,564,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,255,0,0,0,0,0
20,1092,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,117,0,1,0,0,0
20,528,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,144,0,2,0,0,0
20,592,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,321,0,0,0,0,0
20,1253,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,164,0,1,0,0,0
20,694,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,174,0,2,0,0,0
20,680,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,317,0,0,0,0,0
20,1205,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,91,0,1,0,0,0
20,487,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,114,0,2,0,0,0
20,554,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,206,0,0,0,0,0
20,895,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,94,0,1,0,0,0
20,431,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,105,0,2,0,0,0
20,481,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,183,0,0,0,0,0
20,807,1,0,0,0,0
14,9,-1,-1,-1,-1,-1
1,86,0,1,0,0,0
20,424,1,1,0,0,0
14,9,-1,-1,-1,-1,-1
1,104,0,2,0,0,0
20,488,1,2,0,0,0
14,9,-1,-1,-1,-1,-1
1,191,0,0,0,0,0
20,790,1,0,0,0,0
......@@ -5,6 +5,8 @@
#include <fstream>
#include <string>
static int BUFFER_SIZE = 65536;
namespace helpers
{
inline bool readBinaryFile(const char* file, uint8_t* buffer, size_t* len)
......@@ -25,6 +27,123 @@ namespace helpers
return true;
}
inline bool addToBuffer(uint8_t* buf, int* size, uint8_t* data, size_t len)
{
if (*size + len > BUFFER_SIZE)
return false;
int i = 0;
if (len == 1)
{
buf[*size] = *data;
}
else
{
for (i = 0; i < len; i++)
{
buf[*size + i] = data[i];
}
}
*size += len;
return true;
}
inline bool readPayloadData(const char* file, int pos, int bytes, uint8_t* payload)
{
std::string filePath = "test/" + std::string(file);
#ifdef _WIN32
std::replace(filePath.begin(), filePath.end(), '/', '\\');
#endif
std::ifstream in(filePath, std::ios::ate | std::ios::binary);
if (!in)
return false;
in.seekg(pos, std::ios::beg);
in.read(reinterpret_cast<char*>(payload), bytes);
in.close();
return true;
}
inline bool writeRtpPacket(
const char* file,
uint8_t nalType,
size_t nalLength,
int32_t sid,
int32_t tid,
int32_t isIdr,
int32_t firstSliceId,
int32_t lastSliceId,
uint8_t* payload,
uint8_t* buf,
size_t* len)
{
std::string filePath = "test/" + std::string(file);
#ifdef _WIN32
std::replace(filePath.begin(), filePath.end(), '/', '\\');
#endif
uint8_t buffer[16] = { 144, 111, 92, 65, 98, 245, 71, 218, 159, 113, 8, 226, 190, 222, 0, 1 };
int packet_size = 0;
uint8_t oneByte = 0;
// write the RTP header
if (!addToBuffer(buf, &packet_size, buffer, 16))
return false;
// write ID and length of frame marking extension
// if first layer then length should be 0, else 1
oneByte = oneByte | 1 << 4;
if (sid != -1)
{
oneByte = oneByte | 0x01;
}
if (!addToBuffer(buf, &packet_size, &oneByte, 1))
return false;
// write SEIDB TID bits
oneByte = 0;
if (firstSliceId == 1)
oneByte = oneByte | 1 << 7;
if (lastSliceId == 1)
oneByte = oneByte | 1 << 6;
if (isIdr == 1)
oneByte = oneByte | 1 << 5;
if (tid != -1)
oneByte = oneByte | tid;
if (!addToBuffer(buf, &packet_size, &oneByte, 1))
return false;
// write DID QID bits
oneByte = 0;
if (sid != -1)
oneByte = oneByte | sid << 6;
if (!addToBuffer(buf, &packet_size, &oneByte, 1))
return false;
// write TL0PICIDX
oneByte = 0;
if (!addToBuffer(buf, &packet_size, &oneByte, 1))
return false;
// write payload
if (!addToBuffer(buf, &packet_size, payload, nalLength))
return false;
*len = packet_size;
return true;
}
} // namespace helpers
#endif
#include "common.hpp"
#include "RTC/Codecs/H264.hpp"
#include <catch2/catch.hpp>
#include <cstring> // std::memcmp()
using namespace RTC;
SCENARIO("parse H264 payload descriptor", "[codecs][h264]")
{
SECTION("parse payload descriptor")
{
// clang-format off
uint8_t originalBuffer[] =
{
0x07, 0x80, 0x11, 0x00
};
// clang-format on
//
// Keep a copy of the original buffer for comparing.
uint8_t buffer[4] = { 0 };
std::memcpy(buffer, originalBuffer, sizeof(buffer));
const auto* payloadDescriptor = Codecs::H264::Parse(buffer, sizeof(buffer));
REQUIRE(payloadDescriptor);
delete payloadDescriptor;
}
}
#include "common.hpp"
#include "RTC/Codecs/H264_SVC.hpp"
#include <catch2/catch.hpp>
#include <cstring> // std::memcmp()
using namespace RTC;
SCENARIO("parse H264_SVC payload descriptor", "[codecs][h264_svc]")
{
SECTION("parse payload descriptor for NALU 7")
{
// clang-format off
uint8_t originalBuffer[] =
{
0x67,0x42,0xc0,0x33
};
// clang-format on
// Keep a copy of the original buffer for comparing.
uint8_t buffer[4] = { 0 };
std::memcpy(buffer, originalBuffer, sizeof(buffer));
const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer));
REQUIRE(payloadDescriptor);
REQUIRE(payloadDescriptor->tlIndex == 0);
REQUIRE(payloadDescriptor->slIndex == 0);
REQUIRE(payloadDescriptor->isKeyFrame == true);
REQUIRE(payloadDescriptor->hasTlIndex == false);
REQUIRE(payloadDescriptor->hasSlIndex == false);
delete payloadDescriptor;
}
SECTION("parse payload descriptor for NALU 8")
{
// clang-format off
uint8_t originalBuffer[] =
{
0x68,0xce,0x01,0xa8
};
// clang-format on
// Keep a copy of the original buffer for comparing.
uint8_t buffer[4] = { 0 };
std::memcpy(buffer, originalBuffer, sizeof(buffer));
const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer));
REQUIRE(payloadDescriptor);
REQUIRE(payloadDescriptor->tlIndex == 0);
REQUIRE(payloadDescriptor->slIndex == 0);
REQUIRE(payloadDescriptor->isKeyFrame == false);
REQUIRE(payloadDescriptor->hasTlIndex == false);
REQUIRE(payloadDescriptor->hasSlIndex == false);
delete payloadDescriptor;
}
SECTION("parse payload descriptor for NALU 1")
{
// clang-format off
uint8_t originalBuffer[] =
{
0x81,0xe0,0x00,0x4e
};
// clang-format on
// Keep a copy of the original buffer for comparing.
uint8_t buffer[4] = { 0 };
std::memcpy(buffer, originalBuffer, sizeof(buffer));
const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer));
REQUIRE(payloadDescriptor);
REQUIRE(payloadDescriptor->tlIndex == 0);
REQUIRE(payloadDescriptor->slIndex == 0);
REQUIRE(payloadDescriptor->isKeyFrame == false);
REQUIRE(payloadDescriptor->hasTlIndex == false);
REQUIRE(payloadDescriptor->hasSlIndex == false);
delete payloadDescriptor;
}
SECTION("parse payload descriptor for NALU 5")
{
// clang-format off
uint8_t originalBuffer[] =
{
0x85,0xb8,0x00,0x04
};
// clang-format on
// Keep a copy of the original buffer for comparing.
uint8_t buffer[4] = { 0 };
std::memcpy(buffer, originalBuffer, sizeof(buffer));
const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer));
REQUIRE(payloadDescriptor);
REQUIRE(payloadDescriptor->tlIndex == 0);
REQUIRE(payloadDescriptor->slIndex == 0);
REQUIRE(payloadDescriptor->isKeyFrame == true);
REQUIRE(payloadDescriptor->hasTlIndex == false);
REQUIRE(payloadDescriptor->hasSlIndex == false);
delete payloadDescriptor;
}
SECTION("parse payload descriptor for NALU 14")
{
// clang-format off
uint8_t originalBuffer[] =
{
0x6e,0x80,0x90,0x20
};
// clang-format on
// Keep a copy of the original buffer for comparing.
uint8_t buffer[4] = { 0 };
std::memcpy(buffer, originalBuffer, sizeof(buffer));
const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer));
REQUIRE(payloadDescriptor);
REQUIRE(payloadDescriptor->idr == 0);
REQUIRE(payloadDescriptor->tlIndex == 1);
REQUIRE(payloadDescriptor->slIndex == 1);
REQUIRE(payloadDescriptor->isKeyFrame == false);
REQUIRE(payloadDescriptor->hasTlIndex == true);
REQUIRE(payloadDescriptor->hasSlIndex == true);
delete payloadDescriptor;
}
SECTION("parse payload descriptor for NALU 20")
{
// clang-format off
uint8_t originalBuffer[] =
{
0x74,0x80,0x90,0x20
};
// clang-format on
// Keep a copy of the original buffer for comparing.
uint8_t buffer[4] = { 0 };
std::memcpy(buffer, originalBuffer, sizeof(buffer));
const auto* payloadDescriptor = Codecs::H264_SVC::Parse(buffer, sizeof(buffer));
REQUIRE(payloadDescriptor);
REQUIRE(payloadDescriptor->idr == 0);
REQUIRE(payloadDescriptor->tlIndex == 1);
REQUIRE(payloadDescriptor->slIndex == 1);
REQUIRE(payloadDescriptor->isKeyFrame == false);
REQUIRE(payloadDescriptor->hasTlIndex == true);
REQUIRE(payloadDescriptor->hasSlIndex == true);
delete payloadDescriptor;
}
}
#include "common.hpp"
#include "helpers.hpp"
#include "RTC/Codecs/H264_SVC.hpp"
#include "RTC/RtpPacket.hpp"
#include <catch2/catch.hpp>
#include <cstring> // std::memset()
#include <string>
#include <vector>
using namespace RTC;
static uint8_t buffer[65536];
static uint8_t buffer2[65536];
SCENARIO("parse RTP packets with H264 SVC", "[parser][rtp]")
{
SECTION("parse I0-7.bin")
{
size_t len;
uint8_t extenLen;
uint8_t* extenValue;
if (!helpers::readBinaryFile("data/H264_SVC/I0-7.bin", buffer, &len))
FAIL("cannot open file");
RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet)
FAIL("not a RTP packet");
REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true);
REQUIRE(packet->GetPayloadType() == 111);
REQUIRE(packet->GetSequenceNumber() == 23617);
REQUIRE(packet->GetTimestamp() == 1660241882);
REQUIRE(packet->GetSsrc() == 2674985186);
REQUIRE(packet->GetHeaderExtensionId() == 0xBEDE);
REQUIRE(packet->GetHeaderExtensionLength() == 4);
REQUIRE(packet->HasOneByteExtensions());
REQUIRE(packet->HasTwoBytesExtensions() == false);
packet->SetFrameMarkingExtensionId(1);
extenValue = packet->GetExtension(1, extenLen);
REQUIRE(packet->HasExtension(1) == true);
REQUIRE(extenLen == 1);
REQUIRE(extenValue);
REQUIRE(extenValue[0] == 0xa0);
auto* payload = packet->GetPayload();
RtpPacket::FrameMarking* frameMarking{ nullptr };
uint8_t frameMarkingLen{ 0 };
// Read frame-marking.
packet->ReadFrameMarking(&frameMarking, frameMarkingLen);
const auto* payloadDescriptor =
Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen);
REQUIRE(payloadDescriptor);
REQUIRE(payloadDescriptor->s == 1);
REQUIRE(payloadDescriptor->e == 0);
REQUIRE(payloadDescriptor->i == 1);
REQUIRE(payloadDescriptor->d == 0);
REQUIRE(payloadDescriptor->b == 0);
REQUIRE(payloadDescriptor->hasTlIndex);
REQUIRE(payloadDescriptor->tlIndex == 0);
REQUIRE(payloadDescriptor->hasSlIndex == false);
REQUIRE(payloadDescriptor->isKeyFrame == true);
delete payloadDescriptor;
delete packet;
}
SECTION("parse I0-8.bin")
{
size_t len;
uint8_t extenLen;
uint8_t* extenValue;
if (!helpers::readBinaryFile("data/H264_SVC/I0-8.bin", buffer, &len))
FAIL("cannot open file");
RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet)
FAIL("not a RTP packet");
REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true);
REQUIRE(packet->GetPayloadType() == 111);
REQUIRE(packet->GetSequenceNumber() == 23617);
REQUIRE(packet->GetTimestamp() == 1660241882);
REQUIRE(packet->GetSsrc() == 2674985186);
REQUIRE(packet->GetHeaderExtensionId() == 0xBEDE);
REQUIRE(packet->GetHeaderExtensionLength() == 4);
REQUIRE(packet->HasOneByteExtensions());
REQUIRE(packet->HasTwoBytesExtensions() == false);
packet->SetFrameMarkingExtensionId(1);
extenValue = packet->GetExtension(1, extenLen);
REQUIRE(packet->HasExtension(1) == true);
REQUIRE(extenLen == 1);
REQUIRE(extenValue);
REQUIRE(extenValue[0] == 0x00);
auto* payload = packet->GetPayload();
RtpPacket::FrameMarking* frameMarking{ nullptr };
uint8_t frameMarkingLen{ 0 };
// Read frame-marking.
packet->ReadFrameMarking(&frameMarking, frameMarkingLen);
const auto* payloadDescriptor =
Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen);
REQUIRE(payloadDescriptor);
REQUIRE(payloadDescriptor->s == 0);
REQUIRE(payloadDescriptor->e == 0);
REQUIRE(payloadDescriptor->i == 0);
REQUIRE(payloadDescriptor->d == 0);
REQUIRE(payloadDescriptor->b == 0);
REQUIRE(payloadDescriptor->hasTlIndex);
REQUIRE(payloadDescriptor->tlIndex == 0);
REQUIRE(payloadDescriptor->hasSlIndex == false);
REQUIRE(payloadDescriptor->isKeyFrame == false);
delete payloadDescriptor;
delete packet;
}
SECTION("parse I0-5.bin")
{
size_t len;
uint8_t extenLen;
uint8_t* extenValue;
if (!helpers::readBinaryFile("data/H264_SVC/I0-5.bin", buffer, &len))
FAIL("cannot open file");
RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet)
FAIL("not a RTP packet");
REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true);
REQUIRE(packet->GetPayloadType() == 111);
REQUIRE(packet->GetSequenceNumber() == 23617);
REQUIRE(packet->GetTimestamp() == 1660241882);
REQUIRE(packet->GetSsrc() == 2674985186);
REQUIRE(packet->GetHeaderExtensionId() == 0xBEDE);
REQUIRE(packet->GetHeaderExtensionLength() == 4);
REQUIRE(packet->HasOneByteExtensions());
REQUIRE(packet->HasTwoBytesExtensions() == false);
packet->SetFrameMarkingExtensionId(1);
extenValue = packet->GetExtension(1, extenLen);
REQUIRE(packet->HasExtension(1) == true);
REQUIRE(extenLen == 1);
REQUIRE(extenValue);
REQUIRE(extenValue[0] == 0x60);
auto* payload = packet->GetPayload();
RtpPacket::FrameMarking* frameMarking{ nullptr };
uint8_t frameMarkingLen{ 0 };
// Read frame-marking.
packet->ReadFrameMarking(&frameMarking, frameMarkingLen);
const auto* payloadDescriptor =
Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen);
REQUIRE(payloadDescriptor);
REQUIRE(payloadDescriptor->s == 0);
REQUIRE(payloadDescriptor->e == 1);
REQUIRE(payloadDescriptor->i == 1);
REQUIRE(payloadDescriptor->d == 0);
REQUIRE(payloadDescriptor->b == 0);
REQUIRE(payloadDescriptor->isKeyFrame == true);
REQUIRE(payloadDescriptor->hasSlIndex == false);
REQUIRE(payloadDescriptor->hasTlIndex == false);
delete payloadDescriptor;
delete packet;
}
SECTION("parse I1-15.bin")
{
size_t len;
uint8_t extenLen;
uint8_t* extenValue;
if (!helpers::readBinaryFile("data/H264_SVC/I1-15.bin", buffer, &len))
FAIL("cannot open file");
RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet)
FAIL("not a RTP packet");
REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true);
REQUIRE(packet->GetPayloadType() == 111);
REQUIRE(packet->GetSequenceNumber() == 23617);
REQUIRE(packet->GetTimestamp() == 1660241882);
REQUIRE(packet->GetSsrc() == 2674985186);
REQUIRE(packet->GetHeaderExtensionId() == 0xBEDE);
REQUIRE(packet->GetHeaderExtensionLength() == 4);
REQUIRE(packet->HasOneByteExtensions());
REQUIRE(packet->HasTwoBytesExtensions() == false);
packet->SetFrameMarkingExtensionId(1);
extenValue = packet->GetExtension(1, extenLen);
REQUIRE(packet->HasExtension(1) == true);
REQUIRE(extenLen == 1);
REQUIRE(extenValue);
REQUIRE(extenValue[0] == 0x80);
auto* payload = packet->GetPayload();
RtpPacket::FrameMarking* frameMarking{ nullptr };
uint8_t frameMarkingLen{ 0 };
// Read frame-marking.
packet->ReadFrameMarking(&frameMarking, frameMarkingLen);
const auto* payloadDescriptor =
Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen);
REQUIRE(payloadDescriptor);
REQUIRE(payloadDescriptor->s == 1);
REQUIRE(payloadDescriptor->e == 0);
REQUIRE(payloadDescriptor->i == 0);
REQUIRE(payloadDescriptor->d == 0);
REQUIRE(payloadDescriptor->b == 0);
REQUIRE(payloadDescriptor->hasTlIndex);
REQUIRE(payloadDescriptor->tlIndex == 0);
REQUIRE(payloadDescriptor->hasSlIndex == false);
REQUIRE(payloadDescriptor->isKeyFrame == false);
delete payloadDescriptor;
delete packet;
}
SECTION("parse I0-14.bin")
{
size_t len;
uint8_t extenLen;
uint8_t* extenValue;
if (!helpers::readBinaryFile("data/H264_SVC/I0-14.bin", buffer, &len))
FAIL("cannot open file");
RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet)
FAIL("not a RTP packet");
REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true);
REQUIRE(packet->GetPayloadType() == 111);
REQUIRE(packet->GetSequenceNumber() == 23617);
REQUIRE(packet->GetTimestamp() == 1660241882);
REQUIRE(packet->GetSsrc() == 2674985186);
REQUIRE(packet->GetHeaderExtensionId() == 0xBEDE);
REQUIRE(packet->GetHeaderExtensionLength() == 4);
REQUIRE(packet->HasOneByteExtensions());
REQUIRE(packet->HasTwoBytesExtensions() == false);
packet->SetFrameMarkingExtensionId(1);
extenValue = packet->GetExtension(1, extenLen);
REQUIRE(packet->HasExtension(1) == true);
REQUIRE(extenLen == 1);
REQUIRE(extenValue);
REQUIRE(extenValue[0] == 0xa0);
auto* payload = packet->GetPayload();
RtpPacket::FrameMarking* frameMarking{ nullptr };
uint8_t frameMarkingLen{ 0 };
// Read frame-marking.
packet->ReadFrameMarking(&frameMarking, frameMarkingLen);
const auto* payloadDescriptor =
Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen);
REQUIRE(payloadDescriptor);
REQUIRE(payloadDescriptor->s == 1);
REQUIRE(payloadDescriptor->e == 0);
REQUIRE(payloadDescriptor->i == 1);
REQUIRE(payloadDescriptor->d == 0);
REQUIRE(payloadDescriptor->b == 0);
REQUIRE(payloadDescriptor->hasTlIndex);
REQUIRE(payloadDescriptor->tlIndex == 0);
REQUIRE(payloadDescriptor->hasSlIndex == false);
REQUIRE(payloadDescriptor->isKeyFrame == true);
delete payloadDescriptor;
delete packet;
}
SECTION("parse 2SL-I14.bin")
{
size_t len;
uint8_t extenLen;
uint8_t* extenValue;
if (!helpers::readBinaryFile("data/H264_SVC/2SL-I14.bin", buffer, &len))
FAIL("cannot open file");
RtpPacket* packet = RtpPacket::Parse(buffer, len);
if (!packet)
FAIL("not a RTP packet");
REQUIRE(packet->HasMarker() == false);
REQUIRE(packet->HasHeaderExtension() == true);
REQUIRE(packet->GetPayloadType() == 111);
REQUIRE(packet->GetSequenceNumber() == 23617);
REQUIRE(packet->GetTimestamp() == 1660241882);
REQUIRE(packet->GetSsrc() == 2674985186);
REQUIRE(packet->GetHeaderExtensionId() == 0xBEDE);
REQUIRE(packet->GetHeaderExtensionLength() == 4);
REQUIRE(packet->HasOneByteExtensions());
REQUIRE(packet->HasTwoBytesExtensions() == false);
packet->SetFrameMarkingExtensionId(1);
extenValue = packet->GetExtension(1, extenLen);
REQUIRE(packet->HasExtension(1) == true);
REQUIRE(extenLen == 2);
REQUIRE(extenValue);
REQUIRE(extenValue[0] == 0xa0);
auto* payload = packet->GetPayload();
RtpPacket::FrameMarking* frameMarking{ nullptr };
uint8_t frameMarkingLen{ 0 };
// Read frame-marking.
packet->ReadFrameMarking(&frameMarking, frameMarkingLen);
const auto* payloadDescriptor =
Codecs::H264_SVC::Parse(payload, sizeof(payload), frameMarking, frameMarkingLen);
REQUIRE(payloadDescriptor);
REQUIRE(payloadDescriptor->s == 1);
REQUIRE(payloadDescriptor->e == 0);
REQUIRE(payloadDescriptor->i == 1);
REQUIRE(payloadDescriptor->d == 0);
REQUIRE(payloadDescriptor->b == 0);
REQUIRE(payloadDescriptor->hasTlIndex);
REQUIRE(payloadDescriptor->tlIndex == 0);
REQUIRE(payloadDescriptor->hasSlIndex);
REQUIRE(payloadDescriptor->slIndex == 0);
REQUIRE(payloadDescriptor->isKeyFrame == true);
delete payloadDescriptor;
delete packet;
}
SECTION("create and test RTP files")
{
int32_t tmparray[7];
int32_t pos = 0, i = 0, rows = 0;
uint8_t type = 0;
int32_t bytes = 0;
int32_t sid = -1;
int32_t tid = -1;
int32_t isIdr = -1;
int32_t start = -1;
int32_t end = -1;
size_t len = 0;
std::fstream nf;
nf.open("data/H264_SVC/naluInfo/naluInfo.csv", std::ios::in);
if (nf.is_open())
{
std::string line, word;
getline(nf, line); // omit the header in the CSV
while (getline(nf, line))
{
std::stringstream s(line);
i = 0;
while (getline(s, word, ','))
{
tmparray[i++] = std::stoi(word);
}
type = tmparray[0];
bytes = tmparray[1];
sid = tmparray[2];
tid = tmparray[3];
isIdr = tmparray[4];
start = tmparray[5];
end = tmparray[6];
if (!helpers::readPayloadData(
"data/H264_SVC/naluInfo/naluInfo.264", pos + 4, bytes - 4, buffer))
FAIL("Failed to read payload data!\n");
// TODO: One additional byte is written as last value is omitted in the
// test bench
std::string strFile1 = "rtp-" + std::to_string(rows) + ".bin";
if (!helpers::writeRtpPacket(
strFile1.c_str(), type, bytes - 4, sid, tid, isIdr, start, end, buffer, buffer2, &len))
FAIL("Failed to write RTP packet!\n");
RtpPacket* packet = RtpPacket::Parse(buffer2, len);
if (!packet)
FAIL("not a RTP packet");
packet->SetFrameMarkingExtensionId(1);
auto* payload = packet->GetPayload();
RtpPacket::FrameMarking* frameMarking{ nullptr };
uint8_t frameMarkingLen{ 0 };
// Read frame-marking.
packet->ReadFrameMarking(&frameMarking, frameMarkingLen);
const auto* payloadDescriptor = Codecs::H264_SVC::Parse(
payload, packet->GetPayloadLength(), frameMarking, frameMarkingLen);
REQUIRE(payloadDescriptor);
// payloadDescriptor->Dump();
pos += bytes;
rows++;
delete payloadDescriptor;
delete packet;
}
nf.close();
}
}
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论