-
Notifications
You must be signed in to change notification settings - Fork 165
/
mp_common.h
executable file
·170 lines (149 loc) · 3.88 KB
/
mp_common.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* Copyright (C) 2012-2015 Doubango Telecom <http://www.doubango.org>
*
* This file is part of Open Source 'webrtc2sip' project
* <http://code.google.com/p/webrtc2sip/>
*
* 'webrtc2sip' is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 'webrtc2sip' is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with 'webrtc2sip'.
*/
#if !defined(_MEDIAPROXY_COMMON_H_)
#define _MEDIAPROXY_COMMON_H_
#include "mp_config.h"
#include "mp_object.h"
#include "Common.h"
#define MP_CAT_(A, B) A ## B
#define MP_CAT(A, B) MP_CAT_(A, B)
#define MP_STRING_(A) #A
#define MP_STRING(A) MP_STRING_(A)
typedef int32_t MPNetFd;
#define MPNetFd_IsValid(self) ((self) > 0)
#define kMPNetFdInvalid -1
#if !defined(MP_DTMF_TYPE_RFC4733)
# define MP_DTMF_TYPE_RFC4733 "rfc4733"
#endif
#if !defined(MP_DTMF_TYPE_RFC2833)
# define MP_DTMF_TYPE_RFC2833 "rfc2833"
#endif
namespace webrtc2sip {
typedef enum MPMediaType_e
{
MPMediaType_None = 0x00,
MPMediaType_Audio = (0x01<<0),
MPMediaType_Video = (0x01<<1),
MPMediaType_AudioVideo = (MPMediaType_Audio | MPMediaType_Video),
MPMediaType_All = 0xFF,
}
MPMediaType_t;
static enum twrap_media_type_e MPMediaType_GetNative(MPMediaType_t eType)
{
enum twrap_media_type_e eNativeType = twrap_media_none;
if((eType & MPMediaType_Audio)) eNativeType = (enum twrap_media_type_e)(eNativeType | twrap_media_audio);
if((eType & MPMediaType_Video)) eNativeType = (enum twrap_media_type_e)(eNativeType | twrap_media_video);
return eNativeType;
}
typedef enum MPPeerState_e
{
MPPeerState_None,
MPPeerState_Connecting,
MPPeerState_Connected,
MPPeerState_Terminated
}
MPPeerState_t;
typedef enum MPSessionState_e
{
MPSessionState_None,
MPSessionState_Connecting,
MPSessionState_Connected,
MPSessionState_Terminated
}
MPSessionState_t;
typedef enum MPDbType_e
{
MPDbType_None = 0x00,
MPDbType_File = (0x01 << 0),
MPDbType_Server = (0x01 << 1),
MPDbType_SQLite = (MPDbType_File | (0x01 << 2)),
MPDbType_MySql = (MPDbType_Server | (0x01 << 3)),
MPDbType_Oracle = (MPDbType_Server | (0x01 << 4)),
MPDbType_SqlServer = (MPDbType_Server | (0x01 << 5))
}
MPDbType_t;
typedef enum MPNetTransporType_e
{
MPNetTransporType_None,
MPNetTransporType_TCP,
MPNetTransporType_TLS
}
MPNetTransporType_t;
static bool MPNetTransporType_isStream(MPNetTransporType_t eType)
{
switch(eType)
{
case MPNetTransporType_TCP:
case MPNetTransporType_TLS:
return true;
default:
return false;
}
}
static MPSessionState_t MPPeerState_getSessionState(MPPeerState_t eState)
{
switch(eState)
{
case MPPeerState_Connecting: return MPSessionState_Connecting;
case MPPeerState_Connected: return MPSessionState_Connected;
case MPSessionState_Terminated: return MPSessionState_Terminated;
default: return MPSessionState_None;
}
}
//
// MPData
//
class MPData : public MPObject
{
public:
MPData(void** ppData, size_t nDataSize, bool bTakeOwnership = true)
: m_pDataPtr(NULL)
, m_nDataSize(0)
, m_bHaveOwnership(bTakeOwnership)
{
if(ppData)
{
m_pDataPtr = *ppData;
m_nDataSize = nDataSize;
if(m_bHaveOwnership)
{
*ppData = NULL;
}
}
}
virtual ~MPData()
{
if(m_bHaveOwnership)
{
if(m_pDataPtr)
{
free(m_pDataPtr);
}
}
}
virtual MP_INLINE const char* getObjectId() { return "MPData"; }
virtual MP_INLINE const void* getDataPtr(){ return m_pDataPtr; }
virtual MP_INLINE size_t getDataSize(){ return m_nDataSize; }
private:
void* m_pDataPtr;
size_t m_nDataSize;
bool m_bHaveOwnership;
};
} // namespace
#endif /* _MEDIAPROXY_COMMON_H_ */