-
-
Notifications
You must be signed in to change notification settings - Fork 392
/
Copy pathtrack.hpp
84 lines (61 loc) · 1.98 KB
/
track.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Copyright (c) 2020-2021 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
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef RTC_IMPL_TRACK_H
#define RTC_IMPL_TRACK_H
#include "channel.hpp"
#include "common.hpp"
#include "description.hpp"
#include "mediahandler.hpp"
#include "queue.hpp"
#if RTC_ENABLE_MEDIA
#include "dtlssrtptransport.hpp"
#endif
#include <atomic>
#include <shared_mutex>
namespace rtc::impl {
struct PeerConnection;
class Track final : public std::enable_shared_from_this<Track>, public Channel {
public:
Track(weak_ptr<PeerConnection> pc, Description::Media desc);
~Track();
void close();
void incoming(message_ptr message);
bool outgoing(message_ptr message);
optional<message_variant> receive() override;
optional<message_variant> peek() override;
size_t availableAmount() const override;
void flushPendingMessages() override;
message_variant trackMessageToVariant(message_ptr message);
void onFrame(std::function<void(binary data, FrameInfo frame)> callback);
bool isOpen() const;
bool isClosed() const;
size_t maxMessageSize() const;
string mid() const;
Description::Direction direction() const;
Description::Media description() const;
void setDescription(Description::Media desc);
shared_ptr<MediaHandler> getMediaHandler();
void setMediaHandler(shared_ptr<MediaHandler> handler);
#if RTC_ENABLE_MEDIA
void open(shared_ptr<DtlsSrtpTransport> transport);
#endif
bool transportSend(message_ptr message);
private:
const weak_ptr<PeerConnection> mPeerConnection;
#if RTC_ENABLE_MEDIA
weak_ptr<DtlsSrtpTransport> mDtlsSrtpTransport;
#endif
Description::Media mMediaDescription;
shared_ptr<MediaHandler> mMediaHandler;
mutable std::shared_mutex mMutex;
std::atomic<bool> mIsClosed = false;
Queue<message_ptr> mRecvQueue;
synchronized_callback<binary, FrameInfo> frameCallback;
};
} // namespace rtc::impl
#endif