forked from paullouisageneau/libdatachannel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacinghandler.hpp
50 lines (35 loc) · 1.24 KB
/
pacinghandler.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Copyright (c) 2024 Sean DuBois <sean@siobud.com>
*
* 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
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef RTC_PACING_HANDLER_H
#define RTC_PACING_HANDLER_H
#if RTC_ENABLE_MEDIA
#include "mediahandler.hpp"
#include "utils.hpp"
#include <atomic>
#include <queue>
namespace rtc {
// Paced sending of RTP packets. Takes a stream of RTP packets that can an
// uneven bitrate. It then delivers these packets in a smoother manner by
// sending a fixed size of them on an interval
class RTC_CPP_EXPORT PacingHandler : public MediaHandler {
public:
PacingHandler(double bitsPerSecond, std::chrono::milliseconds sendInterval);
void outgoing(message_vector &messages, const message_callback &send) override;
private:
std::atomic<bool> mHaveScheduled = false;
double mBytesPerSecond;
double mBudget;
std::chrono::milliseconds mSendInterval;
std::chrono::time_point<std::chrono::high_resolution_clock> mLastRun;
std::mutex mMutex;
std::queue<message_ptr> mRtpBuffer;
void schedule(const message_callback &send);
};
} // namespace rtc
#endif // RTC_ENABLE_MEDIA
#endif // RTC_PACING_HANDLER_H