Explorar el Código

Merge pull request #753 from paullouisageneau/deprecate-starttime

Deprecate start time mechanism for RTP packetization
Paul-Louis Ageneau hace 2 años
padre
commit
44df6fe9e7

+ 21 - 2
examples/streamer/fileparser.cpp

@@ -21,10 +21,15 @@
 
 using namespace std;
 
-FileParser::FileParser(string directory, string extension, uint32_t samplesPerSecond, bool loop): sampleDuration_us(1000 * 1000 / samplesPerSecond), StreamSource() {
+FileParser::FileParser(string directory, string extension, uint32_t samplesPerSecond, bool loop) {
     this->directory = directory;
     this->extension = extension;
     this->loop = loop;
+    this->sampleDuration_us = 1000 * 1000 / samplesPerSecond;
+}
+
+FileParser::~FileParser() {
+	stop();
 }
 
 void FileParser::start() {
@@ -33,7 +38,8 @@ void FileParser::start() {
 }
 
 void FileParser::stop() {
-    StreamSource::stop();
+    sample = {};
+    sampleTime_us = 0;
     counter = -1;
 }
 
@@ -57,3 +63,16 @@ void FileParser::loadNextSample() {
     sample = *reinterpret_cast<vector<byte> *>(&fileContents);
     sampleTime_us += sampleDuration_us;
 }
+
+rtc::binary FileParser::getSample() {
+	return sample;
+}
+
+uint64_t FileParser::getSampleTime_us() {
+	return sampleTime_us;
+}
+
+uint64_t FileParser::getSampleDuration_us() {
+	return sampleDuration_us;
+}
+

+ 12 - 4
examples/streamer/fileparser.hpp

@@ -26,15 +26,23 @@
 class FileParser: public StreamSource {
     std::string directory;
     std::string extension;
+    uint64_t sampleDuration_us;
+    uint64_t sampleTime_us = 0;
     uint32_t counter = -1;
     bool loop;
     uint64_t loopTimestampOffset = 0;
+protected:
+    rtc::binary sample = {};
 public:
-    const uint64_t sampleDuration_us;
-    virtual void start();
-    virtual void stop();
     FileParser(std::string directory, std::string extension, uint32_t samplesPerSecond, bool loop);
-    virtual void loadNextSample();
+    virtual ~FileParser();
+    virtual void start() override;
+    virtual void stop() override;
+    virtual void loadNextSample() override;
+
+    rtc::binary getSample() override;
+    uint64_t getSampleTime_us() override;
+    uint64_t getSampleDuration_us() override;
 };
 
 #endif /* fileparser_hpp */

+ 6 - 3
examples/streamer/helpers.hpp

@@ -25,9 +25,9 @@
 
 struct ClientTrackData {
     std::shared_ptr<rtc::Track> track;
-	std::shared_ptr<rtc::RtcpSrReporter> sender;
+    std::shared_ptr<rtc::RtcpSrReporter> sender;
 
-	ClientTrackData(std::shared_ptr<rtc::Track> track, std::shared_ptr<rtc::RtcpSrReporter> sender);
+    ClientTrackData(std::shared_ptr<rtc::Track> track, std::shared_ptr<rtc::RtcpSrReporter> sender);
 };
 
 struct Client {
@@ -43,10 +43,13 @@ struct Client {
     }
     std::optional<std::shared_ptr<ClientTrackData>> video;
     std::optional<std::shared_ptr<ClientTrackData>> audio;
-    std::optional<std::shared_ptr<rtc::DataChannel>> dataChannel{};
+    std::optional<std::shared_ptr<rtc::DataChannel>> dataChannel;
+
     void setState(State state);
     State getState();
 
+    uint32_t rtpStartTimestamp = 0;
+
 private:
     std::shared_mutex _mutex;
     State state = State::Waiting;

+ 4 - 17
examples/streamer/main.cpp

@@ -364,17 +364,17 @@ shared_ptr<Stream> createStream(const string h264Samples, const unsigned fps, co
             for (auto clientTrack: tracks) {
                 auto client = clientTrack.id;
                 auto trackData = clientTrack.trackData;
+                auto rtpConfig = trackData->sender->rtpConfig;
+
                 // sample time is in us, we need to convert it to seconds
                 auto elapsedSeconds = double(sampleTime) / (1000 * 1000);
-                auto rtpConfig = trackData->sender->rtpConfig;
                 // get elapsed time in clock rate
                 uint32_t elapsedTimestamp = rtpConfig->secondsToTimestamp(elapsedSeconds);
-
                 // set new timestamp
                 rtpConfig->timestamp = rtpConfig->startTimestamp + elapsedTimestamp;
 
                 // get elapsed time in clock rate from last RTCP sender report
-                auto reportElapsedTimestamp = rtpConfig->timestamp - trackData->sender->previousReportedTimestamp;
+                auto reportElapsedTimestamp = rtpConfig->timestamp - trackData->sender->lastReportedTimestamp();
                 // check if last report was at least 1 second ago
                 if (rtpConfig->timestampToSeconds(reportElapsedTimestamp) > 1) {
                     trackData->sender->setNeedsToReport();
@@ -426,7 +426,7 @@ void sendInitialNalus(shared_ptr<Stream> stream, shared_ptr<ClientTrackData> vid
 
     // send previous NALU key frame so users don't have to wait to see stream works
     if (!initialNalus.empty()) {
-        const double frameDuration_s = double(h264->sampleDuration_us) / (1000 * 1000);
+        const double frameDuration_s = double(h264->getSampleDuration_us()) / (1000 * 1000);
         const uint32_t frameTimestampDuration = video->sender->rtpConfig->secondsToTimestamp(frameDuration_s);
         video->sender->rtpConfig->timestamp = video->sender->rtpConfig->startTimestamp - frameTimestampDuration * 2;
         video->track->send(initialNalus);
@@ -447,20 +447,7 @@ void addToStream(shared_ptr<Client> client, bool isAddingVideo) {
 
         // Audio and video tracks are collected now
         assert(client->video.has_value() && client->audio.has_value());
-
         auto video = client->video.value();
-        auto audio = client->audio.value();
-
-        auto currentTime_us = double(currentTimeInMicroSeconds());
-        auto currentTime_s = currentTime_us / (1000 * 1000);
-
-        // set start time of stream
-        video->sender->rtpConfig->setStartTime(currentTime_s, RtpPacketizationConfig::EpochStart::T1970);
-        audio->sender->rtpConfig->setStartTime(currentTime_s, RtpPacketizationConfig::EpochStart::T1970);
-
-        // start stat recording of RTCP SR
-        video->sender->startRecording();
-        audio->sender->startRecording();
 
         if (avStream.has_value()) {
             sendInitialNalus(avStream.value(), video);

+ 2 - 10
examples/streamer/stream.cpp

@@ -39,16 +39,8 @@ void usleep(__int64 usec)
 #include <unistd.h>
 #endif
 
-void StreamSource::stop() {
-    sampleTime_us = 0;
-    sample = {};
-}
-
-StreamSource::~StreamSource() {
-    stop();
-}
-
-Stream::Stream(std::shared_ptr<StreamSource> video, std::shared_ptr<StreamSource> audio): std::enable_shared_from_this<Stream>(), video(video), audio(audio) { }
+Stream::Stream(std::shared_ptr<StreamSource> video, std::shared_ptr<StreamSource> audio):
+	std::enable_shared_from_this<Stream>(), video(video), audio(audio) { }
 
 Stream::~Stream() {
     stop();

+ 7 - 9
examples/streamer/stream.hpp

@@ -24,19 +24,15 @@
 
 class StreamSource {
 protected:
-    uint64_t sampleTime_us = 0;
-    rtc::binary sample = {};
 
 public:
-    StreamSource() { }
     virtual void start() = 0;
-    virtual void stop();
+    virtual void stop() = 0;
     virtual void loadNextSample() = 0;
 
-    inline uint64_t getSampleTime_us() { return sampleTime_us; }
-    inline rtc::binary getSample() { return sample; }
-
-    ~StreamSource();
+    virtual uint64_t getSampleTime_us() = 0;
+    virtual uint64_t getSampleDuration_us() = 0;
+	virtual rtc::binary getSample() = 0;
 };
 
 class Stream: std::enable_shared_from_this<Stream> {
@@ -48,12 +44,14 @@ class Stream: std::enable_shared_from_this<Stream> {
 public:
     const std::shared_ptr<StreamSource> audio;
     const std::shared_ptr<StreamSource> video;
+
     Stream(std::shared_ptr<StreamSource> video, std::shared_ptr<StreamSource> audio);
+    ~Stream();
+
     enum class StreamSourceType {
         Audio,
         Video
     };
-    ~Stream();
 
 private:
     rtc::synchronized_callback<StreamSourceType, uint64_t, rtc::binary> sampleHandler;

+ 0 - 16
include/rtc/rtc.h

@@ -292,13 +292,6 @@ typedef struct {
 
 } rtcPacketizationHandlerInit;
 
-typedef struct {
-	double seconds;     // Start time in seconds
-	bool since1970;     // true if seconds since 1970
-	                    // false if seconds since 1900
-	uint32_t timestamp; // Start timestamp
-} rtcStartTime;
-
 typedef struct {
 	uint32_t ssrc;
 	const char *name;    // optional
@@ -318,12 +311,6 @@ RTC_EXPORT int rtcChainRtcpSrReporter(int tr);
 // Chain RtcpNackResponder to handler chain for given track
 RTC_EXPORT int rtcChainRtcpNackResponder(int tr, unsigned int maxStoredPacketsCount);
 
-/// Set start time for RTP stream
-RTC_EXPORT int rtcSetRtpConfigurationStartTime(int id, const rtcStartTime *startTime);
-
-// Start stats recording for RTCP Sender Reporter
-RTC_EXPORT int rtcStartRtcpSenderReporterRecording(int id);
-
 // Transform seconds to timestamp using track's clock rate, result is written to timestamp
 RTC_EXPORT int rtcTransformSecondsToTimestamp(int id, double seconds, uint32_t *timestamp);
 
@@ -333,9 +320,6 @@ RTC_EXPORT int rtcTransformTimestampToSeconds(int id, uint32_t timestamp, double
 // Get current timestamp, result is written to timestamp
 RTC_EXPORT int rtcGetCurrentTrackTimestamp(int id, uint32_t *timestamp);
 
-// Get start timestamp for track identified by given id, result is written to timestamp
-RTC_EXPORT int rtcGetTrackStartTimestamp(int id, uint32_t *timestamp);
-
 // Set RTP timestamp for track identified by given id
 RTC_EXPORT int rtcSetTrackRtpTimestamp(int id, uint32_t timestamp);
 

+ 10 - 19
include/rtc/rtcpsrreporter.hpp

@@ -28,23 +28,10 @@
 namespace rtc {
 
 class RTC_CPP_EXPORT RtcpSrReporter final : public MediaHandlerElement {
-	bool needsToReport = false;
-
-	uint32_t packetCount = 0;
-	uint32_t payloadOctets = 0;
-	double timeOffset = 0;
-
-	uint32_t mPreviousReportedTimestamp = 0;
-
 	void addToReport(RtpHeader *rtp, uint32_t rtpSize);
 	message_ptr getSenderReport(uint32_t timestamp);
 
 public:
-	static uint64_t secondsToNTP(double seconds);
-
-	/// Timestamp of previous sender report
-	const uint32_t &previousReportedTimestamp = mPreviousReportedTimestamp;
-
 	/// RTP configuration
 	const shared_ptr<RtpPacketizationConfig> rtpConfig;
 
@@ -53,14 +40,18 @@ public:
 	ChainedOutgoingProduct processOutgoingBinaryMessage(ChainedMessagesProduct messages,
 	                                                    message_ptr control) override;
 
-	/// Set `needsToReport` flag. Sender report will be sent before next RTP packet with same
-	/// timestamp.
+	uint32_t lastReportedTimestamp() const;
 	void setNeedsToReport();
 
-	/// Set offset to compute NTS for RTCP SR packets. Offset represents relation between real start
-	/// time and timestamp of the stream in RTP packets
-	/// @note `time_offset = rtpConfig->startTime - rtpConfig->timestampToSeconds(rtpConfig->timestamp)`
-	void startRecording();
+	// deprecated, do not call
+	[[deprecated]] void startRecording();
+	[[deprecated]] uint32_t previousReportedTimestamp() const { return lastReportedTimestamp(); }
+
+private:
+	uint32_t mPacketCount = 0;
+	uint32_t mPayloadOctets = 0;
+	uint32_t mLastReportedTimestamp = 0;
+	bool mNeedsToReport = false;
 };
 
 } // namespace rtc

+ 18 - 29
include/rtc/rtppacketizationconfig.hpp

@@ -25,27 +25,24 @@
 
 namespace rtc {
 
-/// RTP configuration used in packetization process
+// RTP configuration used in packetization process
 class RTC_CPP_EXPORT RtpPacketizationConfig {
-	uint32_t mStartTimestamp = 0;
-	double mStartTime = 0;
-	RtpPacketizationConfig(const RtpPacketizationConfig &) = delete;
-
 public:
 	const SSRC ssrc;
 	const std::string cname;
 	const uint8_t payloadType;
 	const uint32_t clockRate;
-	const double &startTime = mStartTime;
-	const uint32_t &startTimestamp = mStartTimestamp;
 	const uint8_t videoOrientationId;
 
-	/// current sequence number
+	// current sequence number
 	uint16_t sequenceNumber;
 
-	/// current timestamp
+	// current timestamp
 	uint32_t timestamp;
 
+	// start timestamp
+	uint32_t startTimestamp;
+
 	/// Current video orientation
 	///
 	/// Bit#       7  6  5  4  3  2  1  0
@@ -66,35 +63,18 @@ public:
 	///   3 - 270 degrees
 	uint8_t videoOrientation = 0;
 
-	// For backward compatibility, do not use
-	const double &startTime_s = mStartTime;
-
-	enum class EpochStart : uint64_t {
-		T1970 = 2208988800, // number of seconds between 1970 and 1900
-		T1900 = 0
-	};
-
-	/// Creates relation between time and timestamp mapping given start time and start timestamp
-	/// @param startTime Start time of the stream
-	/// @param epochStart Type of used epoch
-	/// @param startTimestamp Corresponding timestamp for given start time (current timestamp will
-	/// be used if value is nullopt)
-	void setStartTime(double startTime, EpochStart epochStart,
-	                  optional<uint32_t> startTimestamp = std::nullopt);
-
 	/// Construct RTP configuration used in packetization process
 	/// @param ssrc SSRC of source
 	/// @param cname CNAME of source
 	/// @param payloadType Payload type of source
 	/// @param clockRate Clock rate of source used in timestamps
-	/// @param sequenceNumber Initial sequence number of RTP packets (random number is choosed if
 	/// nullopt)
-	/// @param timestamp Initial timastamp of RTP packets (random number is choosed if nullopt)
+	/// @param videoOrientationId Video orientation (see above)
 	RtpPacketizationConfig(SSRC ssrc, std::string cname, uint8_t payloadType, uint32_t clockRate,
-	                       optional<uint16_t> sequenceNumber = std::nullopt,
-	                       optional<uint32_t> timestamp = std::nullopt,
 	                       uint8_t videoOrientationId = 0);
 
+	RtpPacketizationConfig(const RtpPacketizationConfig &) = delete;
+
 	/// Convert timestamp to seconds
 	/// @param timestamp Timestamp
 	/// @param clockRate Clock rate for timestamp calculation
@@ -112,6 +92,15 @@ public:
 	/// Convert seconds to timestamp
 	/// @param seconds Number of seconds
 	uint32_t secondsToTimestamp(double seconds);
+
+	// deprecated, do not use
+	double startTime = 0.;
+	enum class EpochStart : uint64_t {
+		T1970 = 2208988800, // number of seconds between 1970 and 1900
+		T1900 = 0
+	};
+	[[deprecated]] void setStartTime(double startTime, EpochStart epochStart,
+	                                 optional<uint32_t> startTimestamp = std::nullopt);
 };
 
 } // namespace rtc

+ 7 - 31
src/capi.cpp

@@ -300,9 +300,11 @@ createRtpPacketizationConfig(const rtcPacketizationHandlerInit *init) {
 	if (!init->cname)
 		throw std::invalid_argument("Unexpected null pointer for cname");
 
-	return std::make_shared<RtpPacketizationConfig>(init->ssrc, init->cname, init->payloadType,
-	                                                init->clockRate, init->sequenceNumber,
-	                                                init->timestamp);
+	auto config = std::make_shared<RtpPacketizationConfig>(init->ssrc, init->cname,
+	                                                       init->payloadType, init->clockRate);
+	config->sequenceNumber = init->sequenceNumber;
+	config->timestamp = init->timestamp;
+	return config;
 }
 
 #endif // RTC_ENABLE_MEDIA
@@ -1162,24 +1164,6 @@ int rtcChainRtcpNackResponder(int tr, unsigned int maxStoredPacketsCount) {
 	});
 }
 
-int rtcSetRtpConfigurationStartTime(int id, const rtcStartTime *startTime) {
-	return wrap([&] {
-		auto config = getRtpConfig(id);
-		auto epoch = startTime->since1970 ? RtpPacketizationConfig::EpochStart::T1970
-		                                  : RtpPacketizationConfig::EpochStart::T1900;
-		config->setStartTime(startTime->seconds, epoch, startTime->timestamp);
-		return RTC_ERR_SUCCESS;
-	});
-}
-
-int rtcStartRtcpSenderReporterRecording(int id) {
-	return wrap([id] {
-		auto sender = getRtcpSrReporter(id);
-		sender->startRecording();
-		return RTC_ERR_SUCCESS;
-	});
-}
-
 int rtcTransformSecondsToTimestamp(int id, double seconds, uint32_t *timestamp) {
 	return wrap([&] {
 		auto config = getRtpConfig(id);
@@ -1204,14 +1188,6 @@ int rtcGetCurrentTrackTimestamp(int id, uint32_t *timestamp) {
 	});
 }
 
-int rtcGetTrackStartTimestamp(int id, uint32_t *timestamp) {
-	return wrap([&] {
-		auto config = getRtpConfig(id);
-		*timestamp = config->startTimestamp;
-		return RTC_ERR_SUCCESS;
-	});
-}
-
 int rtcSetTrackRtpTimestamp(int id, uint32_t timestamp) {
 	return wrap([&] {
 		auto config = getRtpConfig(id);
@@ -1220,10 +1196,10 @@ int rtcSetTrackRtpTimestamp(int id, uint32_t timestamp) {
 	});
 }
 
-int rtcGetPreviousTrackSenderReportTimestamp(int id, uint32_t *timestamp) {
+int rtcGetLastTrackSenderReportTimestamp(int id, uint32_t *timestamp) {
 	return wrap([&] {
 		auto sender = getRtcpSrReporter(id);
-		*timestamp = sender->previousReportedTimestamp;
+		*timestamp = sender->lastReportedTimestamp();
 		return RTC_ERR_SUCCESS;
 	});
 }

+ 33 - 22
src/rtcpsrreporter.cpp

@@ -21,13 +21,25 @@
 #include "rtcpsrreporter.hpp"
 
 #include <cassert>
+#include <chrono>
 #include <cmath>
 
+namespace {
+
+uint64_t ntp_time() {
+	const auto now = std::chrono::system_clock::now();
+	const double secs = std::chrono::duration<double>(now.time_since_epoch()).count();
+	// Assume the epoch is 01/01/1970 and adds the number of seconds between 1900 and 1970
+	return uint64_t(std::floor((secs + 2208988800.) * double(uint64_t(1) << 32)));
+}
+
+} // namespace
+
 namespace rtc {
 
 ChainedOutgoingProduct RtcpSrReporter::processOutgoingBinaryMessage(ChainedMessagesProduct messages,
                                                                     message_ptr control) {
-	if (needsToReport) {
+	if (std::exchange(mNeedsToReport, false)) {
 		auto timestamp = rtpConfig->timestamp;
 		auto sr = getSenderReport(timestamp);
 		if (control) {
@@ -35,7 +47,6 @@ ChainedOutgoingProduct RtcpSrReporter::processOutgoingBinaryMessage(ChainedMessa
 		} else {
 			control = sr;
 		}
-		needsToReport = false;
 	}
 	for (auto message : *messages) {
 		auto rtp = reinterpret_cast<RtpHeader *>(message->data());
@@ -44,37 +55,26 @@ ChainedOutgoingProduct RtcpSrReporter::processOutgoingBinaryMessage(ChainedMessa
 	return {messages, control};
 }
 
-void RtcpSrReporter::startRecording() {
-	mPreviousReportedTimestamp = rtpConfig->timestamp;
-	timeOffset = rtpConfig->startTime - rtpConfig->timestampToSeconds(rtpConfig->timestamp);
-}
-
 void RtcpSrReporter::addToReport(RtpHeader *rtp, uint32_t rtpSize) {
-	packetCount += 1;
+	mPacketCount += 1;
 	assert(!rtp->padding());
-	payloadOctets += rtpSize - uint32_t(rtp->getSize());
+	mPayloadOctets += rtpSize - uint32_t(rtp->getSize());
 }
 
 RtcpSrReporter::RtcpSrReporter(shared_ptr<RtpPacketizationConfig> rtpConfig)
-    : MediaHandlerElement(), rtpConfig(rtpConfig) {}
-
-uint64_t RtcpSrReporter::secondsToNTP(double seconds) {
-	return uint64_t(std::round(seconds * double(uint64_t(1) << 32)));
+    : MediaHandlerElement(), rtpConfig(rtpConfig) {
+	mLastReportedTimestamp = rtpConfig->timestamp;
 }
 
-void RtcpSrReporter::setNeedsToReport() { needsToReport = true; }
-
 message_ptr RtcpSrReporter::getSenderReport(uint32_t timestamp) {
 	auto srSize = RtcpSr::Size(0);
 	auto msg = make_message(srSize + RtcpSdes::Size({{uint8_t(rtpConfig->cname.size())}}),
 	                        Message::Control);
 	auto sr = reinterpret_cast<RtcpSr *>(msg->data());
-	auto timestamp_s = rtpConfig->timestampToSeconds(timestamp);
-	auto currentTime = timeOffset + timestamp_s;
-	sr->setNtpTimestamp(secondsToNTP(currentTime));
+	sr->setNtpTimestamp(ntp_time());
 	sr->setRtpTimestamp(timestamp);
-	sr->setPacketCount(packetCount);
-	sr->setOctetCount(payloadOctets);
+	sr->setPacketCount(mPacketCount);
+	sr->setOctetCount(mPayloadOctets);
 	sr->preparePacket(rtpConfig->ssrc, 0);
 
 	auto sdes = reinterpret_cast<RtcpSdes *>(msg->data() + srSize);
@@ -85,11 +85,22 @@ message_ptr RtcpSrReporter::getSenderReport(uint32_t timestamp) {
 	item->setText(rtpConfig->cname);
 	sdes->preparePacket(1);
 
-	mPreviousReportedTimestamp = timestamp;
-
+	mLastReportedTimestamp = timestamp;
 	return msg;
 }
 
+void RtcpSrReporter::setNeedsToReport() {
+	mNeedsToReport = true;
+}
+
+void RtcpSrReporter::startRecording() {
+	// Dummy
+}
+
+uint32_t RtcpSrReporter::lastReportedTimestamp() const {
+	return mLastReportedTimestamp;
+}
+
 } // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */

+ 20 - 27
src/rtppacketizationconfig.cpp

@@ -21,39 +21,24 @@
 #include "rtppacketizationconfig.hpp"
 
 #include <cassert>
+#include <limits>
+#include <random>
 
 namespace rtc {
 
 RtpPacketizationConfig::RtpPacketizationConfig(SSRC ssrc, string cname, uint8_t payloadType,
-                                               uint32_t clockRate,
-                                               optional<uint16_t> sequenceNumber,
-                                               optional<uint32_t> timestamp,
-                                               uint8_t videoOrientationId)
-    : ssrc(ssrc), cname(cname), payloadType(payloadType), clockRate(clockRate), videoOrientationId(videoOrientationId) {
+                                               uint32_t clockRate, uint8_t videoOrientationId)
+    : ssrc(ssrc), cname(cname), payloadType(payloadType), clockRate(clockRate),
+      videoOrientationId(videoOrientationId) {
 	assert(clockRate > 0);
-	srand((unsigned)time(NULL));
-	if (sequenceNumber.has_value()) {
-		this->sequenceNumber = sequenceNumber.value();
-	} else {
-		this->sequenceNumber = rand();
-	}
-	if (timestamp.has_value()) {
-		this->timestamp = timestamp.value();
-	} else {
-		this->timestamp = rand();
-	}
-	this->mStartTimestamp = this->timestamp;
-}
 
-void RtpPacketizationConfig::setStartTime(double startTime, EpochStart epochStart,
-                                          optional<uint32_t> startTimestamp) {
-	this->mStartTime = startTime + double(static_cast<uint64_t>(epochStart));
-	if (startTimestamp.has_value()) {
-		this->mStartTimestamp = startTimestamp.value();
-		timestamp = this->startTimestamp;
-	} else {
-		this->mStartTimestamp = timestamp;
-	}
+	// RFC 3550: The initial value of the sequence number SHOULD be random (unpredictable) to make
+	// known-plaintext attacks on encryption more difficult [...] The initial value of the timestamp
+	// SHOULD be random, as for the sequence number.
+	std::default_random_engine rng(std::random_device{}());
+	std::uniform_int_distribution<uint32_t> dist(0, std::numeric_limits<uint32_t>::max());
+	sequenceNumber = static_cast<uint16_t>(dist(rng));
+	timestamp = startTimestamp = dist(rng);
 }
 
 double RtpPacketizationConfig::getSecondsFromTimestamp(uint32_t timestamp, uint32_t clockRate) {
@@ -72,6 +57,14 @@ uint32_t RtpPacketizationConfig::secondsToTimestamp(double seconds) {
 	return RtpPacketizationConfig::getTimestampFromSeconds(seconds, clockRate);
 }
 
+void RtpPacketizationConfig::setStartTime(double startTime, EpochStart epochStart,
+                                          optional<uint32_t> startTimestamp) {
+	// Deprecated dummy function
+	this->startTime = startTime + double(static_cast<uint64_t>(epochStart));
+	if (startTimestamp.has_value())
+		this->timestamp = this->startTimestamp = startTimestamp.value();
+}
+
 } // namespace rtc
 
 #endif /* RTC_ENABLE_MEDIA */