Skip to content

Commit

Permalink
Renamed maximumFragmentSize to maxFragmentSize
Browse files Browse the repository at this point in the history
  • Loading branch information
paullouisageneau committed Jan 20, 2024
1 parent 7ea19e9 commit cb86efc
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 62 deletions.
6 changes: 3 additions & 3 deletions include/rtc/av1rtppacketizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ class RTC_CPP_EXPORT AV1RtpPacketizer final : public RtpPacketizer {
// @note RTP configuration is used in packetization process which may change some configuration
// properties such as sequence number.
AV1RtpPacketizer(Packetization packetization, shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
uint16_t maxFragmentSize = NalUnits::defaultMaximumFragmentSize);

void outgoing(message_vector &messages, const message_callback &send) override;

private:
shared_ptr<NalUnits> splitMessage(binary_ptr message);
std::vector<shared_ptr<binary>> packetizeObu(binary_ptr message, uint16_t maximumFragmentSize);
std::vector<shared_ptr<binary>> packetizeObu(binary_ptr message, uint16_t maxFragmentSize);

const uint16_t maximumFragmentSize;
const uint16_t maxFragmentSize;
const Packetization packetization;
std::shared_ptr<binary> sequenceHeader;
};
Expand Down
8 changes: 4 additions & 4 deletions include/rtc/h264rtppacketizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ class RTC_CPP_EXPORT H264RtpPacketizer final : public RtpPacketizer {
/// properties such as sequence number.
/// @param separator NAL unit separator
/// @param rtpConfig RTP configuration
/// @param maximumFragmentSize maximum size of one NALU fragment
/// @param maxFragmentSize maximum size of one NALU fragment
H264RtpPacketizer(Separator separator, shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
uint16_t maxFragmentSize = NalUnits::defaultMaximumFragmentSize);

// For backward compatibility, do not use
[[deprecated]] H264RtpPacketizer(
shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
uint16_t maxFragmentSize = NalUnits::defaultMaximumFragmentSize);

void outgoing(message_vector &messages, const message_callback &send) override;

private:
shared_ptr<NalUnits> splitMessage(binary_ptr message);

const uint16_t maximumFragmentSize;
const uint16_t maxFragmentSize;
const Separator separator;
};

Expand Down
4 changes: 2 additions & 2 deletions include/rtc/h265nalunit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct RTC_CPP_EXPORT H265NalUnit : NalUnit {
/// Nal unit fragment A
struct RTC_CPP_EXPORT H265NalUnitFragment : H265NalUnit {
static std::vector<shared_ptr<H265NalUnitFragment>> fragmentsFrom(shared_ptr<H265NalUnit> nalu,
uint16_t maximumFragmentSize);
uint16_t maxFragmentSize);

enum class FragmentType { Start, Middle, End };

Expand Down Expand Up @@ -176,7 +176,7 @@ class RTC_CPP_EXPORT H265NalUnits : public std::vector<shared_ptr<H265NalUnit>>
static const uint16_t defaultMaximumFragmentSize =
uint16_t(RTC_DEFAULT_MTU - 12 - 8 - 40); // SRTP/UDP/IPv6

std::vector<shared_ptr<binary>> generateFragments(uint16_t maximumFragmentSize);
std::vector<shared_ptr<binary>> generateFragments(uint16_t maxFragmentSize);
};

} // namespace rtc
Expand Down
8 changes: 4 additions & 4 deletions include/rtc/h265rtppacketizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ class RTC_CPP_EXPORT H265RtpPacketizer final : public RtpPacketizer {
// properties such as sequence number.
// @param separator NAL unit separator
// @param rtpConfig RTP configuration
// @param maximumFragmentSize maximum size of one NALU fragment
// @param maxFragmentSize maximum size of one NALU fragment
H265RtpPacketizer(Separator separator, shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize = H265NalUnits::defaultMaximumFragmentSize);
uint16_t maxFragmentSize = H265NalUnits::defaultMaximumFragmentSize);

// for backward compatibility
[[deprecated]] H265RtpPacketizer(shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize = H265NalUnits::defaultMaximumFragmentSize);
uint16_t maxFragmentSize = H265NalUnits::defaultMaximumFragmentSize);

void outgoing(message_vector &messages, const message_callback &send) override;

private:
shared_ptr<H265NalUnits> splitMessage(binary_ptr message);

const uint16_t maximumFragmentSize;
const uint16_t maxFragmentSize;
const NalUnit::Separator separator;
};

Expand Down
4 changes: 2 additions & 2 deletions include/rtc/nalunit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ struct RTC_CPP_EXPORT NalUnit : binary {
/// Nal unit fragment A
struct RTC_CPP_EXPORT NalUnitFragmentA : NalUnit {
static std::vector<shared_ptr<NalUnitFragmentA>> fragmentsFrom(shared_ptr<NalUnit> nalu,
uint16_t maximumFragmentSize);
uint16_t maxFragmentSize);

enum class FragmentType { Start, Middle, End };

Expand Down Expand Up @@ -216,7 +216,7 @@ class RTC_CPP_EXPORT NalUnits : public std::vector<shared_ptr<NalUnit>> {
static const uint16_t defaultMaximumFragmentSize =
uint16_t(RTC_DEFAULT_MTU - 12 - 8 - 40); // SRTP/UDP/IPv6

std::vector<shared_ptr<binary>> generateFragments(uint16_t maximumFragmentSize);
std::vector<shared_ptr<binary>> generateFragments(uint16_t maxFragmentSize);
};

} // namespace rtc
Expand Down
8 changes: 5 additions & 3 deletions include/rtc/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ extern "C" {
#define RTC_DEFAULT_MTU 1280 // IPv6 minimum guaranteed MTU

#if RTC_ENABLE_MEDIA
#define RTC_DEFAULT_MAXIMUM_FRAGMENT_SIZE \
((uint16_t)(RTC_DEFAULT_MTU - 12 - 8 - 40)) // SRTP/UDP/IPv6
#define RTC_DEFAULT_MAXIMUM_PACKET_COUNT_FOR_NACK_CACHE ((unsigned)512)
#define RTC_DEFAULT_MAX_FRAGMENT_SIZE ((uint16_t)(RTC_DEFAULT_MTU - 12 - 8 - 40)) // SRTP/UDP/IPv6
#define RTC_DEFAULT_MAX_STORED_PACKET_COUNT 512
// Deprecated, do not use
#define RTC_DEFAULT_MAXIMUM_FRAGMENT_SIZE RTC_DEFAULT_MAX_FRAGMENT_SIZE
#define RTC_DEFAULT_MAXIMUM_PACKET_COUNT_FOR_NACK_CACHE RTC_DEFAULT_MAX_STORED_PACKET_COUNT
#endif

#ifdef _WIN32
Expand Down
10 changes: 5 additions & 5 deletions src/av1rtppacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ std::vector<binary_ptr> extractTemporalUnitObus(binary_ptr message) {
**/

std::vector<binary_ptr> AV1RtpPacketizer::packetizeObu(binary_ptr message,
uint16_t maximumFragmentSize) {
uint16_t maxFragmentSize) {

std::vector<shared_ptr<binary>> payloads{};
size_t messageIndex = 0;
Expand All @@ -144,7 +144,7 @@ std::vector<binary_ptr> AV1RtpPacketizer::packetizeObu(binary_ptr message,
}

auto payload = std::make_shared<binary>(
std::min(size_t(maximumFragmentSize), messageRemaining + metadataSize));
std::min(size_t(maxFragmentSize), messageRemaining + metadataSize));
auto payloadOffset = payloadHeaderSize;

payload->at(0) = byte(obuCount) << wBitshift;
Expand Down Expand Up @@ -187,8 +187,8 @@ std::vector<binary_ptr> AV1RtpPacketizer::packetizeObu(binary_ptr message,

AV1RtpPacketizer::AV1RtpPacketizer(AV1RtpPacketizer::Packetization packetization,
shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize)
: RtpPacketizer(rtpConfig), maximumFragmentSize(maximumFragmentSize),
uint16_t maxFragmentSize)
: RtpPacketizer(rtpConfig), maxFragmentSize(maxFragmentSize),
packetization(packetization) {}

void AV1RtpPacketizer::outgoing(message_vector &messages,
Expand All @@ -204,7 +204,7 @@ void AV1RtpPacketizer::outgoing(message_vector &messages,

std::vector<binary_ptr> fragments;
for (auto obu : obus) {
auto p = packetizeObu(obu, maximumFragmentSize);
auto p = packetizeObu(obu, maxFragmentSize);
fragments.insert(fragments.end(), p.begin(), p.end());
}

Expand Down
6 changes: 3 additions & 3 deletions src/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ int rtcSetH264Packetizer(int tr, const rtcPacketizerInit *init) {
// create packetizer
auto nalSeparator = init ? init->nalSeparator : RTC_NAL_SEPARATOR_LENGTH;
auto maxFragmentSize = init && init->maxFragmentSize ? init->maxFragmentSize
: RTC_DEFAULT_MAXIMUM_FRAGMENT_SIZE;
: RTC_DEFAULT_MAX_FRAGMENT_SIZE;
auto packetizer = std::make_shared<H264RtpPacketizer>(
static_cast<rtc::NalUnit::Separator>(nalSeparator), rtpConfig, maxFragmentSize);
track->setMediaHandler(packetizer);
Expand All @@ -1236,7 +1236,7 @@ int rtcSetH265Packetizer(int tr, const rtcPacketizerInit *init) {
// create packetizer
auto nalSeparator = init ? init->nalSeparator : RTC_NAL_SEPARATOR_LENGTH;
auto maxFragmentSize = init && init->maxFragmentSize ? init->maxFragmentSize
: RTC_DEFAULT_MAXIMUM_FRAGMENT_SIZE;
: RTC_DEFAULT_MAX_FRAGMENT_SIZE;
auto packetizer = std::make_shared<H265RtpPacketizer>(
static_cast<rtc::NalUnit::Separator>(nalSeparator), rtpConfig, maxFragmentSize);
track->setMediaHandler(packetizer);
Expand All @@ -1251,7 +1251,7 @@ int rtcSetAV1Packetizer(int tr, const rtcPacketizerInit *init) {
auto rtpConfig = createRtpPacketizationConfig(init);
// create packetizer
auto maxFragmentSize = init && init->maxFragmentSize ? init->maxFragmentSize
: RTC_DEFAULT_MAXIMUM_FRAGMENT_SIZE;
: RTC_DEFAULT_MAX_FRAGMENT_SIZE;
auto packetization = init->obuPacketization == RTC_OBU_PACKETIZED_TEMPORAL_UNIT
? AV1RtpPacketizer::Packetization::TemporalUnit
: AV1RtpPacketizer::Packetization::Obu;
Expand Down
10 changes: 5 additions & 5 deletions src/h264rtppacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ shared_ptr<NalUnits> H264RtpPacketizer::splitMessage(binary_ptr message) {
}

H264RtpPacketizer::H264RtpPacketizer(shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize)
: RtpPacketizer(std::move(rtpConfig)), maximumFragmentSize(maximumFragmentSize),
uint16_t maxFragmentSize)
: RtpPacketizer(std::move(rtpConfig)), maxFragmentSize(maxFragmentSize),
separator(Separator::Length) {}

H264RtpPacketizer::H264RtpPacketizer(Separator separator,
shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize)
: RtpPacketizer(rtpConfig), maximumFragmentSize(maximumFragmentSize), separator(separator) {}
uint16_t maxFragmentSize)
: RtpPacketizer(rtpConfig), maxFragmentSize(maxFragmentSize), separator(separator) {}

void H264RtpPacketizer::outgoing(message_vector &messages, [[maybe_unused]] const message_callback &send) {
message_vector result;
for(const auto &message : messages) {
auto nalus = splitMessage(message);
auto fragments = nalus->generateFragments(maximumFragmentSize);
auto fragments = nalus->generateFragments(maxFragmentSize);
if (fragments.size() == 0)
continue;

Expand Down
26 changes: 13 additions & 13 deletions src/h265nalunit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ H265NalUnitFragment::H265NalUnitFragment(FragmentType type, bool forbiddenBit, u
}

std::vector<shared_ptr<H265NalUnitFragment>>
H265NalUnitFragment::fragmentsFrom(shared_ptr<H265NalUnit> nalu, uint16_t maximumFragmentSize) {
assert(nalu->size() > maximumFragmentSize);
auto fragments_count = ceil(double(nalu->size()) / maximumFragmentSize);
maximumFragmentSize = uint16_t(int(ceil(nalu->size() / fragments_count)));
H265NalUnitFragment::fragmentsFrom(shared_ptr<H265NalUnit> nalu, uint16_t maxFragmentSize) {
assert(nalu->size() > maxFragmentSize);
auto fragments_count = ceil(double(nalu->size()) / maxFragmentSize);
maxFragmentSize = uint16_t(int(ceil(nalu->size() / fragments_count)));

// 3 bytes for FU indicator and FU header
maximumFragmentSize -= (H265_NAL_HEADER_SIZE + H265_FU_HEADER_SIZE);
maxFragmentSize -= (H265_NAL_HEADER_SIZE + H265_FU_HEADER_SIZE);
auto f = nalu->forbiddenBit();
uint8_t nuhLayerId = nalu->nuhLayerId() & 0x3F; // 6 bits
uint8_t nuhTempIdPlus1 = nalu->nuhTempIdPlus1() & 0x7; // 3 bits
Expand All @@ -48,19 +48,19 @@ H265NalUnitFragment::fragmentsFrom(shared_ptr<H265NalUnit> nalu, uint16_t maximu
FragmentType fragmentType;
if (offset == 0) {
fragmentType = FragmentType::Start;
} else if (offset + maximumFragmentSize < payload.size()) {
} else if (offset + maxFragmentSize < payload.size()) {
fragmentType = FragmentType::Middle;
} else {
if (offset + maximumFragmentSize > payload.size()) {
maximumFragmentSize = uint16_t(payload.size() - offset);
if (offset + maxFragmentSize > payload.size()) {
maxFragmentSize = uint16_t(payload.size() - offset);
}
fragmentType = FragmentType::End;
}
fragmentData = {payload.begin() + offset, payload.begin() + offset + maximumFragmentSize};
fragmentData = {payload.begin() + offset, payload.begin() + offset + maxFragmentSize};
auto fragment = std::make_shared<H265NalUnitFragment>(
fragmentType, f, nuhLayerId, nuhTempIdPlus1, naluType, fragmentData);
result.push_back(fragment);
offset += maximumFragmentSize;
offset += maxFragmentSize;
}
return result;
}
Expand All @@ -81,12 +81,12 @@ void H265NalUnitFragment::setFragmentType(FragmentType type) {
}
}

std::vector<shared_ptr<binary>> H265NalUnits::generateFragments(uint16_t maximumFragmentSize) {
std::vector<shared_ptr<binary>> H265NalUnits::generateFragments(uint16_t maxFragmentSize) {
vector<shared_ptr<binary>> result{};
for (auto nalu : *this) {
if (nalu->size() > maximumFragmentSize) {
if (nalu->size() > maxFragmentSize) {
std::vector<shared_ptr<H265NalUnitFragment>> fragments =
H265NalUnitFragment::fragmentsFrom(nalu, maximumFragmentSize);
H265NalUnitFragment::fragmentsFrom(nalu, maxFragmentSize);
result.insert(result.end(), fragments.begin(), fragments.end());
} else {
result.push_back(nalu);
Expand Down
10 changes: 5 additions & 5 deletions src/h265rtppacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ shared_ptr<H265NalUnits> H265RtpPacketizer::splitMessage(binary_ptr message) {
}

H265RtpPacketizer::H265RtpPacketizer(shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize)
: RtpPacketizer(std::move(rtpConfig)), maximumFragmentSize(maximumFragmentSize),
uint16_t maxFragmentSize)
: RtpPacketizer(std::move(rtpConfig)), maxFragmentSize(maxFragmentSize),
separator(NalUnit::Separator::Length) {}

H265RtpPacketizer::H265RtpPacketizer(NalUnit::Separator separator,
shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize)
: RtpPacketizer(std::move(rtpConfig)), maximumFragmentSize(maximumFragmentSize),
uint16_t maxFragmentSize)
: RtpPacketizer(std::move(rtpConfig)), maxFragmentSize(maxFragmentSize),
separator(separator) {}

void H265RtpPacketizer::outgoing(message_vector &messages, [[maybe_unused]] const message_callback &send) {
message_vector result;
for (const auto &message : messages) {
auto nalus = splitMessage(message);
auto fragments = nalus->generateFragments(maximumFragmentSize);
auto fragments = nalus->generateFragments(maxFragmentSize);
if (fragments.size() == 0)
continue;

Expand Down
26 changes: 13 additions & 13 deletions src/nalunit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ NalUnitFragmentA::NalUnitFragmentA(FragmentType type, bool forbiddenBit, uint8_t
}

std::vector<shared_ptr<NalUnitFragmentA>>
NalUnitFragmentA::fragmentsFrom(shared_ptr<NalUnit> nalu, uint16_t maximumFragmentSize) {
assert(nalu->size() > maximumFragmentSize);
auto fragments_count = ceil(double(nalu->size()) / maximumFragmentSize);
maximumFragmentSize = uint16_t(int(ceil(nalu->size() / fragments_count)));
NalUnitFragmentA::fragmentsFrom(shared_ptr<NalUnit> nalu, uint16_t maxFragmentSize) {
assert(nalu->size() > maxFragmentSize);
auto fragments_count = ceil(double(nalu->size()) / maxFragmentSize);
maxFragmentSize = uint16_t(int(ceil(nalu->size() / fragments_count)));

// 2 bytes for FU indicator and FU header
maximumFragmentSize -= 2;
maxFragmentSize -= 2;
auto f = nalu->forbiddenBit();
uint8_t nri = nalu->nri() & 0x03;
uint8_t naluType = nalu->unitType() & 0x1F;
Expand All @@ -46,19 +46,19 @@ NalUnitFragmentA::fragmentsFrom(shared_ptr<NalUnit> nalu, uint16_t maximumFragme
FragmentType fragmentType;
if (offset == 0) {
fragmentType = FragmentType::Start;
} else if (offset + maximumFragmentSize < payload.size()) {
} else if (offset + maxFragmentSize < payload.size()) {
fragmentType = FragmentType::Middle;
} else {
if (offset + maximumFragmentSize > payload.size()) {
maximumFragmentSize = uint16_t(payload.size() - offset);
if (offset + maxFragmentSize > payload.size()) {
maxFragmentSize = uint16_t(payload.size() - offset);
}
fragmentType = FragmentType::End;
}
fragmentData = {payload.begin() + offset, payload.begin() + offset + maximumFragmentSize};
fragmentData = {payload.begin() + offset, payload.begin() + offset + maxFragmentSize};
auto fragment =
std::make_shared<NalUnitFragmentA>(fragmentType, f, nri, naluType, fragmentData);
result.push_back(fragment);
offset += maximumFragmentSize;
offset += maxFragmentSize;
}
return result;
}
Expand All @@ -80,12 +80,12 @@ void NalUnitFragmentA::setFragmentType(FragmentType type) {
}
}

std::vector<shared_ptr<binary>> NalUnits::generateFragments(uint16_t maximumFragmentSize) {
std::vector<shared_ptr<binary>> NalUnits::generateFragments(uint16_t maxFragmentSize) {
vector<shared_ptr<binary>> result{};
for (auto nalu : *this) {
if (nalu->size() > maximumFragmentSize) {
if (nalu->size() > maxFragmentSize) {
std::vector<shared_ptr<NalUnitFragmentA>> fragments =
NalUnitFragmentA::fragmentsFrom(nalu, maximumFragmentSize);
NalUnitFragmentA::fragmentsFrom(nalu, maxFragmentSize);
result.insert(result.end(), fragments.begin(), fragments.end());
} else {
result.push_back(nalu);
Expand Down

0 comments on commit cb86efc

Please sign in to comment.