Cogs.Core
RTSP.h
1#pragma once
2
3#include "Base.h"
4
5#include "Foundation/Memory/MemoryBuffer.h"
6#include "Foundation/Network/Connection.h"
7#include "Foundation/Platform/Threads.h"
8
9#include <algorithm>
10#include <deque>
11#include <map>
12#include <string>
13#include <vector>
14
15typedef void CURL;
16
17namespace Cogs{
18 class COGSCORE_DLL_API RTSP : public Network::ConnectionTCP {
19 public:
21 std::string media_name; // m=video 0 RTP/AVP 96
22 std::string media_type; // video audio
23 std::string control_id;
24 uint32_t rtp_payload_type; // 96, 97, 98, 99
25 std::string encoding_name; // H264, MPA
26 uint32_t rtp_clock_rate; // 90000 Hz
27 uint32_t packetization_mode; // 1
28 uint32_t profile_level_id;
29 std::string vps;
30 std::string sps;
31 std::string pps;
32 uint16_t server_port[2] = {};
33 uint16_t client_port[2] = {};
34 uint32_t ssrc = 0;
35 uint8_t ip[4];
36 };
37
39 bool operator()(const std::string& lhs, const std::string& rhs) const {
40 std::string s1;
41 std::string s2;
42
43 s1.resize(lhs.size());
44 s2.resize(rhs.size());
45
46 std::transform(lhs.begin(), lhs.end(), s1.begin(), [](unsigned char c){ return std::tolower(c); });
47 std::transform(rhs.begin(), rhs.end(), s2.begin(), [](unsigned char c){ return std::tolower(c); });
48
49 return s1 < s2;
50 }
51 };
52
54 using HeaderMap = std::map<std::string, std::string, CaseInsensitiveCompare>;
55
56 std::string firstLine;
57 HeaderMap headers;
58 void* userData = nullptr;
59 bool finishedHeaders = false;
60 bool finishedBody = false;
61
62 void reset() {
63 MemoryBuffer::clear();
64 firstLine.clear();
65 headers.clear();
66 userData = nullptr;
67 finishedHeaders = false;
68 finishedBody = false;
69 }
70 };
71
72 using MediaList = std::vector<MediaDescription>;
73
74 RTSP(std::string_view url, std::string_view userAgent = "Cogs/1.0");
75 ~RTSP();
76
77 bool sendSetup(MediaDescription& mediaDescription, const std::string& mediaURL, uint16_t client_port_a, uint16_t client_port_b);
78 bool sendPlay();
79 bool sendPause();
80 bool sendTeardown();
81
82 bool isActive() const { return is_active; }
83
84 const std::string& getOriginalURL() const { return originalURL; }
85 const MediaList& getMediaDescriptions() const { return mediaDescriptions; }
86
87 protected:
89 bool has_describe : 1;
90 bool has_setup : 1;
91 bool has_play : 1;
92 bool has_pause : 1;
93 bool has_teardown : 1;
94 bool has_set_parameter : 1;
95 bool has_get_parameter : 1;
96 bool is_active : 1;
97 bool has_video : 1;
98 bool has_audio : 1;
99
100 virtual bool processOutgoing() override;
101 virtual bool processIncoming() override;
102 virtual void processIncomingMessage(Message& message);
103
104 virtual void receivedMediaDescriptions() = 0;
105 virtual void receivedStreamSetup(MediaDescription& md) = 0;
106
107 void queueMessage(Message* message);
108
109 private:
110 std::deque<Message*> queuedMessages;
111 Cogs::Mutex queueMutex;
113 Message* outgoingMessage = nullptr;
114 std::deque<Message*> sentMessages;
117 std::string originalURL;
118 std::string userInfo;
119 std::string hostname;
120 std::string resourcePath;
121 uint16_t hostPort = 554;
122 std::string agentString;
123 int sequenceNumber = 0;
124 std::string sessionID;
125 int64_t timeout = 60000;
126 int64_t keepAliveTime = 0;
127
128 void addStandardHeaders(Message& message);
129 bool breakdownURL(std::string_view uri);
130 std::string buildURL(std::string_view method);
131 void parseSDP(const std::string& sdp);
132
133 void sendOptions();
134 void sendDescribe();
135 };
136}
Cogs::Mutex queueMutex
Mutex protecting the message queue.
Definition: RTSP.h:111
std::string sessionID
Server generated session identifier.
Definition: RTSP.h:124
std::string resourcePath
Path on the server to the resource we are accessing.
Definition: RTSP.h:120
std::string userInfo
user:pass part of the URL.
Definition: RTSP.h:118
std::string originalURL
URL with which this RTSP object was constructed.
Definition: RTSP.h:117
Message incomingMessage
The message currently being received.
Definition: RTSP.h:116
std::deque< Message * > queuedMessages
List of messages waiting to be sent.
Definition: RTSP.h:110
std::string hostname
Hostname of the RTSP server.
Definition: RTSP.h:119
MediaList mediaDescriptions
List of media descriptions.
Definition: RTSP.h:88
Memory::MemoryBuffer outgoingBuffer
Memory buffer used when sending data.
Definition: RTSP.h:112
Memory::MemoryBuffer incomingBuffer
Memory buffer used when receiving data.
Definition: RTSP.h:115
std::deque< Message * > sentMessages
List of sent messages.
Definition: RTSP.h:114
std::string agentString
User agent string passed in requests.
Definition: RTSP.h:122
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
std::string firstLine
Request-line for requests, status-line for responses.
Definition: RTSP.h:56
HeaderMap headers
List of headers to be sent or received.
Definition: RTSP.h:57