Skip to content

Commit

Permalink
Refactor media handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
paullouisageneau committed Oct 27, 2023
1 parent d2d17b2 commit af28d4c
Show file tree
Hide file tree
Showing 50 changed files with 654 additions and 1,538 deletions.
21 changes: 3 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ set(LIBDATACHANNEL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/configuration.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/datachannel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/description.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/mediahandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/global.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/message.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/peerconnection.cpp
Expand All @@ -75,20 +76,12 @@ set(LIBDATACHANNEL_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/rtppacketizationconfig.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/rtcpsrreporter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/rtppacketizer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/opusrtppacketizer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/opuspacketizationhandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/aacrtppacketizer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/h264rtppacketizer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/nalunit.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/h264packetizationhandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/h265rtppacketizer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/h265nalunit.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/h265packetizationhandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/av1rtppacketizer.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/av1packetizationhandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/mediachainablehandler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/mediahandlerelement.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/mediahandlerrootelement.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/nalunit.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/rtcpnackresponder.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/rtp.cpp
${CMAKE_CURRENT_SOURCE_DIR}/src/capi.cpp
Expand Down Expand Up @@ -117,20 +110,12 @@ set(LIBDATACHANNEL_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtppacketizationconfig.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtcpsrreporter.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtppacketizer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/opusrtppacketizer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/opuspacketizationhandler.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/aacrtppacketizer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h264rtppacketizer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/nalunit.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h264packetizationhandler.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h265rtppacketizer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h265nalunit.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/h265packetizationhandler.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/av1rtppacketizer.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/av1packetizationhandler.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/mediachainablehandler.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/mediahandlerelement.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/mediahandlerrootelement.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/nalunit.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/rtcpnackresponder.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/utils.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/rtc/plihandler.hpp
Expand Down
60 changes: 0 additions & 60 deletions include/rtc/aacrtppacketizer.hpp

This file was deleted.

32 changes: 0 additions & 32 deletions include/rtc/av1packetizationhandler.hpp

This file was deleted.

30 changes: 15 additions & 15 deletions include/rtc/av1rtppacketizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@

#if RTC_ENABLE_MEDIA

#include "mediahandlerrootelement.hpp"
#include "mediahandler.hpp"
#include "nalunit.hpp"
#include "rtppacketizer.hpp"

namespace rtc {

/// RTP packetization of AV1 payload
class RTC_CPP_EXPORT AV1RtpPacketizer final : public RtpPacketizer, public MediaHandlerRootElement {
shared_ptr<NalUnits> splitMessage(binary_ptr message);
const uint16_t maximumFragmentSize;

// RTP packetization of AV1 payload
class RTC_CPP_EXPORT AV1RtpPacketizer final : public RtpPacketizer {
public:
/// Default clock rate for AV1 in RTP
// Default clock rate for AV1 in RTP
inline static const uint32_t defaultClockRate = 90 * 1000;

// Define how OBUs are seperated in a AV1 Sample
Expand All @@ -32,23 +29,26 @@ class RTC_CPP_EXPORT AV1RtpPacketizer final : public RtpPacketizer, public Media
TemporalUnit = RTC_OBU_PACKETIZED_TEMPORAL_UNIT,
};

/// Constructs AV1 payload packetizer with given RTP configuration.
/// @note RTP configuration is used in packetization process which may change some configuration
/// properties such as sequence number.
/// @param rtpConfig RTP configuration
// Constructs AV1 payload packetizer with given RTP configuration.
// @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);

ChainedOutgoingProduct processOutgoingBinaryMessage(ChainedMessagesProduct messages,
message_ptr control) override;
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);

const uint16_t maximumFragmentSize;
const Packetization packetization;
std::shared_ptr<binary> sequenceHeader;

std::vector<shared_ptr<binary>> packetizeObu(binary_ptr message, uint16_t maximumFragmentSize);
};

// For backward compatibility, do not use
using AV1PacketizationHandler [[deprecated("Add AV1RtpPacketizer directly")]] = PacketizationHandler;

} // namespace rtc

#endif /* RTC_ENABLE_MEDIA */
Expand Down
4 changes: 4 additions & 0 deletions include/rtc/description.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class RTC_CPP_EXPORT Description {

std::vector<int> extIds();
ExtMap *extMap(int id);
const ExtMap *extMap(int id) const;
void addExtMap(ExtMap map);
void removeExtMap(int id);

Expand Down Expand Up @@ -208,6 +209,7 @@ class RTC_CPP_EXPORT Description {
bool hasPayloadType(int payloadType) const;
std::vector<int> payloadTypes() const;
RtpMap *rtpMap(int payloadType);
const RtpMap *rtpMap(int payloadType) const;
void addRtpMap(RtpMap map);
void removeRtpMap(int payloadType);
void removeFormat(const string &format);
Expand All @@ -233,7 +235,9 @@ class RTC_CPP_EXPORT Description {
void addAudioCodec(int payloadType, string codec, optional<string> profile = std::nullopt);

void addOpusCodec(int payloadType, optional<string> profile = DEFAULT_OPUS_AUDIO_PROFILE);

void addPCMACodec(int payloadType, optional<string> profile = std::nullopt);

void addPCMUCodec(int payloadType, optional<string> profile = std::nullopt);
void addAacCodec(int payloadType, optional<string> profile = std::nullopt);
};
Expand Down
32 changes: 0 additions & 32 deletions include/rtc/h264packetizationhandler.hpp

This file was deleted.

38 changes: 21 additions & 17 deletions include/rtc/h264rtppacketizer.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (c) 2020 Filip Klembara (in2core)
* Copyright (c) 2023 Paul-Louis Ageneau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -11,42 +12,45 @@

#if RTC_ENABLE_MEDIA

#include "mediahandlerrootelement.hpp"
#include "nalunit.hpp"
#include "rtppacketizer.hpp"

namespace rtc {

/// RTP packetization of h264 payload
class RTC_CPP_EXPORT H264RtpPacketizer final : public RtpPacketizer,
public MediaHandlerRootElement {
shared_ptr<NalUnits> splitMessage(binary_ptr message);
const uint16_t maximumFragmentSize;

// RTP packetization for H264
class RTC_CPP_EXPORT H264RtpPacketizer final : public RtpPacketizer {
public:
using Separator = NalUnit::Separator;

/// Default clock rate for H264 in RTP
// Default clock rate for H264 in RTP
inline static const uint32_t defaultClockRate = 90 * 1000;

// Constructs h264 payload packetizer with given RTP configuration.
// @note RTP configuration is used in packetization process which may change some configuration
// properties such as sequence number.
// @param separator NAL unit separator
// @param rtpConfig RTP configuration
// @param maximumFragmentSize maximum size of one NALU fragment
H264RtpPacketizer(Separator separator, shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);

/// Constructs h264 payload packetizer with given RTP configuration.
/// @note RTP configuration is used in packetization process which may change some configuration
/// properties such as sequence number.
/// @param rtpConfig RTP configuration
/// @param maximumFragmentSize maximum size of one NALU fragment
H264RtpPacketizer(shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);
// for backward compatibility, do not use
[[deprecated]] H264RtpPacketizer(
shared_ptr<RtpPacketizationConfig> rtpConfig,
uint16_t maximumFragmentSize = NalUnits::defaultMaximumFragmentSize);

ChainedOutgoingProduct processOutgoingBinaryMessage(ChainedMessagesProduct messages,
message_ptr control) override;
void outgoing(message_vector &messages, const message_callback &send) override;

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

const uint16_t maximumFragmentSize;
const Separator separator;
};

// For backward compatibility, do not use
using H264PacketizationHandler [[deprecated("Add H264RtpPacketizer directly")]] = PacketizationHandler;

} // namespace rtc

#endif /* RTC_ENABLE_MEDIA */
Expand Down
32 changes: 0 additions & 32 deletions include/rtc/h265packetizationhandler.hpp

This file was deleted.

Loading

0 comments on commit af28d4c

Please sign in to comment.