Skip to content

Commit 9078f41

Browse files
Updated streamer example
1 parent f7a6a3f commit 9078f41

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

examples/streamer/main.cpp

+3-16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "helpers.hpp"
2121
#include "ArgParser.hpp"
2222

23+
#include <chrono>
24+
2325
using namespace rtc;
2426
using namespace std;
2527
using namespace std::chrono_literals;
@@ -351,26 +353,11 @@ shared_ptr<Stream> createStream(const string h264Samples, const unsigned fps, co
351353
for (auto clientTrack: tracks) {
352354
auto client = clientTrack.id;
353355
auto trackData = clientTrack.trackData;
354-
auto rtpConfig = trackData->sender->rtpConfig;
355-
356-
// sample time is in us, we need to convert it to seconds
357-
auto elapsedSeconds = double(sampleTime) / (1000 * 1000);
358-
// get elapsed time in clock rate
359-
uint32_t elapsedTimestamp = rtpConfig->secondsToTimestamp(elapsedSeconds);
360-
// set new timestamp
361-
rtpConfig->timestamp = rtpConfig->startTimestamp + elapsedTimestamp;
362-
363-
// get elapsed time in clock rate from last RTCP sender report
364-
auto reportElapsedTimestamp = rtpConfig->timestamp - trackData->sender->lastReportedTimestamp();
365-
// check if last report was at least 1 second ago
366-
if (rtpConfig->timestampToSeconds(reportElapsedTimestamp) > 1) {
367-
trackData->sender->setNeedsToReport();
368-
}
369356

370357
cout << "Sending " << streamType << " sample with size: " << to_string(sample.size()) << " to " << client << endl;
371358
try {
372359
// send sample
373-
trackData->track->send(sample);
360+
trackData->track->sendFrame(sample, std::chrono::duration<double, std::micro>(sampleTime));
374361
} catch (const std::exception &e) {
375362
cerr << "Unable to send "<< streamType << " packet: " << e.what() << endl;
376363
}

0 commit comments

Comments
 (0)