/[resiprocate]/main/reflow/MediaStream.hxx
ViewVC logotype

Contents of /main/reflow/MediaStream.hxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11159 - (show annotations) (download)
Fri Apr 25 14:03:32 2014 UTC (5 years, 8 months ago) by sgodin
File MIME type: text/plain
File size: 5127 byte(s)
-modified asio and boost include file ordering to avoid multiply defined symbol errors on linking
 -in preparation for upgrade of asio drop and support for latest boost 
 -include asio/ssh.hpp everywhere asio.hpp is included
 -include boost headers before others, to ensure we are not redefining stdint definitions in some includes
  and not others

1 #if !defined(MediaStream_hxx)
2 #define MediaStream_hxx
3
4 #ifdef HAVE_CONFIG_H
5 #include "config.h"
6 #endif
7
8 #include <asio.hpp>
9 #ifdef USE_SSL
10 #include <asio/ssl.hpp>
11 #endif
12 #ifdef WIN32
13 #include <srtp.h>
14 #else
15 #include <srtp/srtp.h>
16 #endif
17
18 #include "dtls_wrapper/DtlsFactory.hxx"
19 #include "Flow.hxx"
20
21 using namespace reTurn;
22
23 namespace flowmanager
24 {
25
26 /**
27 This class represents a media stream, that consists of a series of componenets
28 or flows. For media streams based on RTP, there are two components per media
29 stream - one for RTP, and one for RTCP.
30
31 Author: Scott Godin (sgodin AT SipSpectrum DOT com)
32 */
33 class MediaStreamHandler
34 {
35 public:
36 MediaStreamHandler() {}
37 virtual ~MediaStreamHandler() {}
38
39 virtual void onMediaStreamReady(const StunTuple& rtpTuple, const StunTuple& rtcpTuple) = 0;
40 virtual void onMediaStreamError(unsigned int errorCode) = 0;
41 };
42
43 #define RTP_COMPONENT_ID 1
44 #define RTCP_COMPONENT_ID 2
45
46 class MediaStream
47 {
48 public:
49 enum NatTraversalMode
50 {
51 NoNatTraversal,
52 StunBindDiscovery,
53 TurnAllocation
54 };
55
56 enum SrtpCryptoSuite
57 {
58 SRTP_AES_CM_128_HMAC_SHA1_32,
59 SRTP_AES_CM_128_HMAC_SHA1_80
60 };
61
62 MediaStream(asio::io_service& ioService,
63 asio::ssl::context& sslContext,
64 MediaStreamHandler& mediaStreamHandler,
65 const StunTuple& localRtpBinding,
66 const StunTuple& localRtcpBinding, // pass in transport type = None to disable RTCP
67 dtls::DtlsFactory* dtlsFactory = 0,
68 NatTraversalMode natTraversalMode = NoNatTraversal,
69 const char* natTraversalServerHostname = 0,
70 unsigned short natTraversalServerPort = 0,
71 const char* stunUsername = 0,
72 const char* stunPassword = 0);
73 virtual ~MediaStream();
74
75 Flow* getRtpFlow() { return mRtpFlow; }
76 Flow* getRtcpFlow() { return mRtcpFlow; }
77
78 // SRTP methods - should be called before sending or receiving on RTP or RTCP flows
79 bool createOutboundSRTPSession(SrtpCryptoSuite cryptoSuite, const char* key, unsigned int keyLen);
80 bool createInboundSRTPSession(SrtpCryptoSuite cryptoSuite, const char* key, unsigned int keyLen);
81
82 protected:
83 friend class Flow;
84
85 // SRTP members
86 dtls::DtlsFactory* mDtlsFactory;
87 volatile bool mSRTPSessionInCreated;
88 volatile bool mSRTPSessionOutCreated;
89 resip::Mutex mMutex;
90 SrtpCryptoSuite mCryptoSuiteIn;
91 SrtpCryptoSuite mCryptoSuiteOut;
92 uint8_t mSRTPMasterKeyIn[SRTP_MASTER_KEY_LEN];
93 uint8_t mSRTPMasterKeyOut[SRTP_MASTER_KEY_LEN];
94 srtp_policy_t mSRTPPolicyIn;
95 srtp_policy_t mSRTPPolicyOut;
96 srtp_t mSRTPSessionIn;
97 srtp_t mSRTPSessionOut;
98
99 err_status_t srtpProtect(void* data, int* size, bool rtcp);
100 err_status_t srtpUnprotect(void* data, int* size, bool rtcp);
101
102 // Nat Traversal Members
103 NatTraversalMode mNatTraversalMode;
104 resip::Data mNatTraversalServerHostname;
105 unsigned short mNatTraversalServerPort;
106 resip::Data mStunUsername;
107 resip::Data mStunPassword;
108
109 private:
110 // Note: these member variables are set at creation time and never changed, thus
111 // they do not require mutex protection
112 MediaStreamHandler& mMediaStreamHandler;
113 bool mRtcpEnabled;
114
115 Flow* mRtpFlow;
116 Flow* mRtcpFlow;
117
118 virtual void onFlowReady(unsigned int componentId);
119 virtual void onFlowError(unsigned int componentId, unsigned int errorCode);
120 };
121
122 }
123
124 #endif
125
126
127 /* ====================================================================
128
129 Copyright (c) 2007-2008, Plantronics, Inc.
130 All rights reserved.
131
132 Redistribution and use in source and binary forms, with or without
133 modification, are permitted provided that the following conditions are
134 met:
135
136 1. Redistributions of source code must retain the above copyright
137 notice, this list of conditions and the following disclaimer.
138
139 2. Redistributions in binary form must reproduce the above copyright
140 notice, this list of conditions and the following disclaimer in the
141 documentation and/or other materials provided with the distribution.
142
143 3. Neither the name of Plantronics nor the names of its contributors
144 may be used to endorse or promote products derived from this
145 software without specific prior written permission.
146
147 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
148 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
149 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
150 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
151 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
152 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
153 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
154 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
155 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
156 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
157 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
158
159 ==================================================================== */

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27