-
Notifications
You must be signed in to change notification settings - Fork 6
/
Session.h
107 lines (86 loc) · 3.46 KB
/
Session.h
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#pragma once
#include <map>
#include <unordered_map>
#include "Signalling/ServerSession.h"
#include "Config.h"
#include "SessionsSharedData.h"
class Session : public ServerSession
{
public:
typedef ::SessionAuthTokenData AuthTokenData;
typedef ::RecordMountpointData RecordMountpointData;
typedef SessionsSharedData SharedData;
Session(
const Config*,
SharedData*,
const CreatePeer& createPeer,
const rtsp::Session::SendRequest& sendRequest,
const rtsp::Session::SendResponse& sendResponse) noexcept;
Session(
const Config*,
SharedData*,
const CreatePeer& createPeer,
const CreatePeer& createRecordPeer,
const rtsp::Session::SendRequest& sendRequest,
const rtsp::Session::SendResponse& sendResponse) noexcept;
~Session();
protected:
bool listEnabled(const std::string& uri) noexcept override;
bool playEnabled(const std::string& uri) noexcept override;
bool recordEnabled(const std::string& uri) noexcept override;
bool subscribeEnabled(const std::string& uri) noexcept override;
bool authorizeAgent(const std::unique_ptr<rtsp::Request>& requestPtr) noexcept;
bool isValidCookie(const std::optional<std::string>& authCookie) noexcept;
bool authorize(const std::unique_ptr<rtsp::Request>&) noexcept override;
#if !defined(BUILD_AS_CAMERA_STREAMER) && !defined(BUILD_AS_V4L2_STREAMER)
bool onGetParameterRequest(
std::unique_ptr<rtsp::Request>&) noexcept override;
#endif
bool onListRequest(
std::unique_ptr<rtsp::Request>&) noexcept override;
bool onSubscribeRequest(
std::unique_ptr<rtsp::Request>&) noexcept override;
bool handleResponse(
const rtsp::Request&,
std::unique_ptr<rtsp::Response>&) noexcept override;
bool isProxyRequest(const rtsp::Request&) noexcept override;
bool handleProxyRequest(
std::unique_ptr<rtsp::Request>&) noexcept override;
private:
class SessionHandle;
struct ForwardedRequest {
std::string sourceUri;
rtsp::CSeq sourceCSeq;
std::weak_ptr<SessionHandle> sourceSession;
};
struct MediaSessionInfo {
std::weak_ptr<SessionHandle> mediaSessionOwner;
std::string uri;
rtsp::MediaSessionId mediaSession;
};
void startRecord(const std::string& uri, const rtsp::MediaSessionId& mediaSession) noexcept;
rtsp::MediaSessionId registerAgentMediaSession(
std::shared_ptr<SessionHandle>& agentSession,
const std::string& uri,
const rtsp::MediaSessionId& mediaSession) noexcept;
bool forwardRequest(
std::shared_ptr<SessionHandle>& sourceSession,
const std::string& sourceUri,
std::unique_ptr<rtsp::Request>& requestPtr) noexcept;
bool forwardResponse(
ForwardedRequest& sourceRequest,
const rtsp::Request&,
std::unique_ptr<rtsp::Response>&) noexcept;
void forwardTeardown(const MediaSessionInfo&) noexcept;
void teardownMediaSession(const rtsp::MediaSessionId&) noexcept override;
private:
const Config *const _config;
SharedData *const _sharedData;
std::shared_ptr<SessionHandle> _handle;
// reqest target side data
std::map<rtsp::CSeq, ForwardedRequest> _forwardedRequests;
// client side data
std::map<rtsp::MediaSessionId, MediaSessionInfo> _clientMediaSession2agentMediaSession;
// agent side data
std::map<rtsp::MediaSessionId, MediaSessionInfo> _agentMediaSessions2clientMediaSession;
};