sipxmedialib  Version 3.3
NetInTask.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2021 SIP Spectrum, Inc. www.sipspectrum.com
3 //
4 // Copyright (C) 2006-2016 SIPez LLC. All rights reserved.
5 //
6 // Copyright (C) 2004-2006 SIPfoundry Inc.
7 // Licensed by SIPfoundry under the LGPL license.
8 //
9 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
10 // Licensed to SIPfoundry under a Contributor Agreement.
11 //
12 // $$
14 
15 
16 #ifndef _INCLUDED_NETINTASK_H /* [ */
17 #define _INCLUDED_NETINTASK_H
18 
19 #include "rtcp/RtcpConfig.h"
20 
21 // SYSTEM INCLUDES
22 
23 // APPLICATION INCLUDES
24 #include "os/OsTask.h"
25 #include "os/OsLock.h"
26 #include "os/OsSocket.h"
27 #include "os/OsRWMutex.h"
28 #include "os/OsMutex.h"
29 #include "mp/MpTypes.h"
30 #include "mp/MpRtpBuf.h"
31 #include "mp/MpMisc.h"
32 
33 // DEFINES
34 #define IP_HEADER_SIZE 20
35 #define UDP_HEADER_SIZE 8
36 #define ETHERNET_MTU 1500
37 #define UDP_MTU (ETHERNET_MTU - IP_HEADER_SIZE - UDP_HEADER_SIZE)
38 #define RTP_MTU (UDP_MTU-12)
40 #define RTCP_MTU (UDP_MTU-12)
41 
42 #define RTP_DIR_IN 1
43 #define RTP_DIR_OUT 2
44 #define RTP_DIR_NEW 4
45 
46 // MACROS
47 // EXTERNAL FUNCTIONS
48 // EXTERNAL VARIABLES
49 // CONSTANTS
50 #define NET_TASK_MAX_MSG_LEN sizeof(netInTaskMsg)
51 #define NET_TASK_MAX_FD_PAIRS 300
52 
53 // FORWARD DECLARATIONS
54 class MprFromNet;
55 class OsConnectionSocket;
56 class OsServerSocket;
57 class OsSocket;
58 class OsNotification;
59 struct rtpSession;
60 
61 // STRUCTS
62 struct rtpSession {
63  uint8_t vpxcc;
64  uint8_t mpt;
68  OsSocket* socket;
69  int dir;
70  uint32_t packets;
71  uint32_t octets;
72  uint16_t cycles;
73 };
74 
75 struct netInTaskMsg {
76  OsSocket* pRtpSocket;
77  OsSocket* pRtcpSocket;
79  OsNotification* notify;
80  int fdRtp;
81  int fdRtcp;
82 };
83 
84 #ifndef INCLUDE_RTCP /* [ */
87  short seqNumCycles;
88  uint16_t highSeqNum;
89 };
90 
91 // TYPEDEFS
92 
95 #endif /* INCLUDE_RTCP ] */
96 
97 typedef struct rtpSession *rtpHandle;
98 
99 // FORWARD DECLARATIONS
100 extern uint32_t rand_timer32();
101 extern rtpHandle StartRtpSession(OsSocket* socket, int direction, char type);
102 extern void FinishRtpSession(rtpHandle h);
103 
109 class NetInTask : public OsTask
110 {
111 
112 /* //////////////////////////// PUBLIC //////////////////////////////////// */
113 public:
114 
115  static const int DEF_NET_IN_TASK_PRIORITY;
116  static const int DEF_NET_IN_TASK_OPTIONS;
117  static const int DEF_NET_IN_TASK_STACKSIZE;
118 
119 /* ============================ CREATORS ================================== */
121 
122 
124  static NetInTask* getNetInTask();
125 
127  static NetInTask* createNetInTask();
128 
130  OsStatus destroy();
131 
133  virtual ~NetInTask();
134 
136 
137 /* ============================ MANIPULATORS ============================== */
139 
140 
142  virtual int run(void* pArg);
143 
144  OsStatus addNetInputSources(OsSocket* pRtpSocket,
145  OsSocket* pRtcpSocket,
146  MprFromNet* fwdTo,
147  OsNotification* note);
148 
149  OsStatus removeNetInputSources(MprFromNet* fwdTo, OsNotification* note);
150 
152 
153 /* ============================ ACCESSORS ================================= */
155 
156 
158 
159 /* ============================ INQUIRY =================================== */
161 
162 
164 
165 /* //////////////////////////// PROTECTED ///////////////////////////////// */
166 protected:
167 
168  // Static data members used to enforce Singleton behavior
170  static OsRWMutex sLock;
172 
174  OsRWMutex sInstanceLock;
175 
177  OsConnectionSocket* mpWriteSocket;
178  OsConnectionSocket* mpReadSocket;
179  int mCmdPort;
180  OsMutex mEventMutex;
181 
184 
188 
190  NetInTask(
191  int prio = DEF_NET_IN_TASK_PRIORITY,
192  int options = DEF_NET_IN_TASK_OPTIONS,
193  int stack = DEF_NET_IN_TASK_STACKSIZE);
194 
196  static OsRWMutex& getStaticLockObj() { return sLock; }
197  OsRWMutex& getLockObj() { if (mUseInstanceLock) return sInstanceLock; else return sLock; }
198 
199  OsStatus get1Msg(OsSocket* pRxpSkt, MprFromNet* fwdTo, bool isRtcp, int ostc);
200  int findPoisonFds(int pipeFD);
201 
202 /* //////////////////////////// PRIVATE /////////////////////////////////// */
203 private:
204 
206  NetInTask(const NetInTask& rNetInTask);
207 
209  NetInTask& operator=(const NetInTask& rhs);
210 
211 };
212 
213 #endif /* _INCLUDED_NETINTASKH ] */
Definition: NetInTask.h:62
uint8_t vpxcc
Usually: ((2<<6) | (0<<5) | (0<<4) | 0)
Definition: NetInTask.h:63
int mNumFdPairs
Definition: NetInTask.h:183
uint16_t highSeqNum
Definition: NetInTask.h:88
rtpHandle StartRtpSession(OsSocket *socket, int direction, char type)
OsNotification * notify
Definition: NetInTask.h:79
uint16_t cycles
Definition: NetInTask.h:72
struct rtpSession * rtpHandle
Definition: NetInTask.h:97
#define NET_TASK_MAX_FD_PAIRS
Definition: NetInTask.h:51
static const int DEF_NET_IN_TASK_PRIORITY
default task priority
Definition: NetInTask.h:115
static const int DEF_NET_IN_TASK_STACKSIZE
default task stacksize
Definition: NetInTask.h:117
int mFlushedLimit
Definition: NetInTask.h:186
int mNumFlushed
Definition: NetInTask.h:185
RtpSeq seq
Definition: NetInTask.h:65
RtpTimestamp timestamp
Definition: NetInTask.h:66
RtpSRC ssrc
Definition: NetInTask.h:67
OsSocket * pRtpSocket
Definition: NetInTask.h:76
OsMutex mEventMutex
Definition: NetInTask.h:180
Definition: NetInTask.h:85
MprFromNet * fwdTo
Definition: NetInTask.h:78
static OsRWMutex & getStaticLockObj()
Return sLock object.
Definition: NetInTask.h:196
int fdRtcp
Definition: NetInTask.h:81
OsConnectionSocket * mpWriteSocket
Definition: NetInTask.h:177
OsSocket * socket
Definition: NetInTask.h:68
uint32_t RtpTimestamp
RTP timestamp.
Definition: MpTypes.h:60
uint32_t octets
Definition: NetInTask.h:71
Task that listen for packets in incoming RTP streams.
Definition: NetInTask.h:109
Definition: NetInTask.h:75
OsRWMutex & getLockObj()
Definition: NetInTask.h:197
OsConnectionSocket * mpReadSocket
Definition: NetInTask.h:178
uint16_t RtpSeq
RTP sequence number.
Definition: MpTypes.h:59
static NetInTask * spInstance
Definition: NetInTask.h:169
int mCmdPort
internal socket port number
Definition: NetInTask.h:179
bool mUseInstanceLock
Definition: NetInTask.h:187
struct __MprRtcpStats * MprRtcpStatsPtr
Definition: NetInTask.h:94
OsRWMutex sInstanceLock
Definition: NetInTask.h:174
The "From Network" media processing resource.
Definition: MprFromNet.h:55
short seqNumCycles
Definition: NetInTask.h:87
OsSocket * pRtcpSocket
Definition: NetInTask.h:77
uint32_t rand_timer32()
static const int DEF_NET_IN_TASK_OPTIONS
default task options
Definition: NetInTask.h:116
uint32_t RtpSRC
RTP SSRC or CSRC identifier.
Definition: MpTypes.h:61
int dir
Definition: NetInTask.h:69
RtpSRC ssrc
Definition: NetInTask.h:86
int fdRtp
Definition: NetInTask.h:80
uint8_t mpt
Usually: ((0<<7) | 0)
Definition: NetInTask.h:64
uint32_t packets
Definition: NetInTask.h:70
void FinishRtpSession(rtpHandle h)