Skip to content

Commit

Permalink
Updated streamer example
Browse files Browse the repository at this point in the history
  • Loading branch information
paullouisageneau committed Oct 19, 2024
1 parent f952dff commit 42fa417
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions examples/streamer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "helpers.hpp"
#include "ArgParser.hpp"

#include <chrono>

using namespace rtc;
using namespace std;
using namespace std::chrono_literals;
Expand Down Expand Up @@ -351,26 +353,11 @@ 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);
// 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->lastReportedTimestamp();
// check if last report was at least 1 second ago
if (rtpConfig->timestampToSeconds(reportElapsedTimestamp) > 1) {
trackData->sender->setNeedsToReport();
}

cout << "Sending " << streamType << " sample with size: " << to_string(sample.size()) << " to " << client << endl;
try {
// send sample
trackData->track->send(sample);
trackData->track->sendFrame(sample, std::chrono::duration<double, std::micro>(sampleTime));
} catch (const std::exception &e) {
cerr << "Unable to send "<< streamType << " packet: " << e.what() << endl;
}
Expand Down

0 comments on commit 42fa417

Please sign in to comment.