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',
......
差异被折叠。
......@@ -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;
}
}
差异被折叠。
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论