reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
MediaStream.hxx
Go to the documentation of this file.
1#if !defined(MediaStream_hxx)
2#define MediaStream_hxx
3
4#ifdef HAVE_CONFIG_H
5#include "config.h"
6#endif
7
8// !slg! At least for builds in Visual Studio on windows this include needs to be above ASIO includes since inlined shared_from_this has
9// a different linkage signature if included after - haven't investigated the full details as to exactly why this happens
10#include <memory>
11
12namespace asio
13{
14 class io_context;
16#ifdef USE_SSL
17 namespace ssl
18 {
19 class context;
20 }
21#endif
22}
23
24#include "Srtp2Helper.hxx"
25
27#include "FlowContext.hxx"
28#include "Flow.hxx"
31
32using namespace reTurn;
33
34namespace flowmanager
35{
36
38{
39public:
42
43 virtual void onMediaStreamReady(const StunTuple& rtpTuple, const StunTuple& rtcpTuple) = 0;
44 virtual void onMediaStreamError(unsigned int errorCode) = 0;
45};
46
47#define RTP_COMPONENT_ID 1
48#define RTCP_COMPONENT_ID 2
49
58{
59public:
66
67 MediaStream(asio::io_context& ioService,
68 asio::ssl::context& sslContext,
71 const StunTuple& localRtcpBinding, // pass in transport type = None to disable RTCP
73 NatTraversalMode natTraversalMode = NoNatTraversal,
74 const char* natTraversalServerHostname = 0,
75 unsigned short natTraversalServerPort = 0,
76 const char* stunUsername = 0,
77 const char* stunPassword = 0,
78 bool forceCOMedia = false,
79 std::shared_ptr<RTCPEventLoggingHandler> rtcpEventLoggingHandler = nullptr,
80 std::shared_ptr<FlowContext> context = nullptr,
81 bool validateTlsServerHostname = true); // for TURN over TLS: see FlowManager::setValidateTlsServerHostname
82 virtual ~MediaStream();
83
84 Flow* getRtpFlow() { return mRtpFlow; }
85 Flow* getRtcpFlow() { return mRtcpFlow; }
86
87 // SRTP methods - should be called before sending or receiving on RTP or RTCP flows
90
91protected:
92 friend class Flow;
93
94 // SRTP members
96 volatile bool mSRTPSessionInCreated;
107
108 srtp_err_status_t srtpProtect(void* data, int* size, bool rtcp);
109 srtp_err_status_t srtpUnprotect(void* data, int* size, bool rtcp);
110
111 // Nat Traversal Members
119
120private:
121 // Note: these member variables are set at creation time and never changed, thus
122 // they do not require mutex protection
123 MediaStreamHandler& mMediaStreamHandler;
124 bool mRtcpEnabled;
125
126 // Null until created: activating the RTP flow can call onFlowReady before the constructor
127 // has set both
128 Flow* mRtpFlow = nullptr;
129 Flow* mRtcpFlow = nullptr;
130
131 virtual void onFlowReady(unsigned int componentId);
132 virtual void onFlowError(unsigned int componentId, unsigned int errorCode);
133};
134
135}
136
137#endif
138
139
140/* ====================================================================
141
142 Copyright (c) 2008-2026 SIP Spectrum, Inc. https://www.sipspectrum.com
143 Copyright (c) 2007-2008, Plantronics, Inc.
144 All rights reserved.
145
146 Redistribution and use in source and binary forms, with or without
147 modification, are permitted provided that the following conditions are
148 met:
149
150 1. Redistributions of source code must retain the above copyright
151 notice, this list of conditions and the following disclaimer.
152
153 2. Redistributions in binary form must reproduce the above copyright
154 notice, this list of conditions and the following disclaimer in the
155 documentation and/or other materials provided with the distribution.
156
157 3. Neither the name of Plantronics nor the names of its contributors
158 may be used to endorse or promote products derived from this
159 software without specific prior written permission.
160
161 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
162 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
163 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
164 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
165 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
166 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
167 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
168 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
169 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
170 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
171 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
172
173 ==================================================================== */
This class represents a Flow that is created by the Flow Manager.
Definition Flow.hxx:45
virtual void onMediaStreamError(unsigned int errorCode)=0
virtual void onMediaStreamReady(const StunTuple &rtpTuple, const StunTuple &rtcpTuple)=0
This class represents a media stream, that consists of a series of componenets or flows.
bool createInboundSRTPSession(resip::MediaConstants::SrtpCryptoSuite cryptoSuite, const char *key, size_t keyLen)
bool createOutboundSRTPSession(resip::MediaConstants::SrtpCryptoSuite cryptoSuite, const char *key, size_t keyLen)
unsigned short mNatTraversalServerPort
NatTraversalMode mNatTraversalMode
uint8_t mSRTPMasterKeyIn[SRTP_MASTER_KEY_LEN]
srtp_err_status_t srtpProtect(void *data, int *size, bool rtcp)
volatile bool mSRTPSessionInCreated
resip::MediaConstants::SrtpCryptoSuite mCryptoSuiteOut
srtp_err_status_t srtpUnprotect(void *data, int *size, bool rtcp)
dtls::DtlsFactory * mDtlsFactory
uint8_t mSRTPMasterKeyOut[SRTP_MASTER_KEY_LEN]
volatile bool mSRTPSessionOutCreated
resip::Data mNatTraversalServerHostname
resip::MediaConstants::SrtpCryptoSuite mCryptoSuiteIn
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
io_context io_service
This class is used during media sessions that use Dtls-Srtp for a media transport.
Definition ErrorCode.hxx:4
std::mutex Mutex
A semaphore that can be locked by only one thread at a time.
Definition Mutex.hxx:37
unsigned char uint8_t
Definition stdint.h:83
void list()
Definition userAdmin.cxx:66