sipxmedialib  Version 3.3
MprRtpStartReceiveMsg.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2007 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // $$
10 
11 #ifndef _MprRtpStartReceiveMsg_h_
12 #define _MprRtpStartReceiveMsg_h_
13 
14 // SYSTEM INCLUDES
15 
16 // APPLICATION INCLUDES
17 #include "mp/MpResourceMsg.h"
18 #include "sdp/SdpCodec.h"
19 #include "os/OsMsg.h"
20 
21 // DEFINES
22 // MACROS
23 // EXTERNAL FUNCTIONS
24 // EXTERNAL VARIABLES
25 // CONSTANTS
26 // STRUCTS
27 // TYPEDEFS
28 // FORWARD DECLARATIONS
29 
32 {
33  /* //////////////////////////// PUBLIC //////////////////////////////////// */
34 public:
35 
36  /* ============================ CREATORS ================================== */
38 
39 
41  MprRtpStartReceiveMsg(const UtlString& targetResourceName,
42  SdpCodec* codecs[],
43  int numCodecs,
44  OsSocket& rRtpSocket,
45  OsSocket& rRtcpSocket)
46  : MpResourceMsg(MPRM_START_RECEIVE_RTP, targetResourceName)
47  , mpCodecs(NULL)
48  , mNumCodecs(0)
49  , mpRtpSocket(&rRtpSocket)
50  , mpRtcpSocket(&rRtcpSocket)
51  {
52  assert(numCodecs > 0);
53  if(numCodecs > 0)
54  {
55  mpCodecs = new SdpCodec*[numCodecs];
56  int codecIndex;
57  for(codecIndex = 0; codecIndex < numCodecs; codecIndex++)
58  {
59  if(codecs[codecIndex])
60  {
61  mpCodecs[codecIndex] =
62  new SdpCodec(*(codecs[codecIndex]));
63  }
64 
65  // This should never occur:
66  else
67  {
68  assert(codecs[codecIndex] != NULL);
69  mpCodecs[codecIndex] = NULL;
70  }
71  }
72  mNumCodecs = numCodecs;
73  }
74  };
75 
78  : MpResourceMsg(resourceMsg)
79  , mpCodecs(NULL)
80  , mpRtpSocket(resourceMsg.mpRtpSocket)
81  , mpRtcpSocket(resourceMsg.mpRtcpSocket)
82  {
83  assert(resourceMsg.mNumCodecs > 0);
84  if(resourceMsg.mNumCodecs > 0)
85  {
86  // Make a codec array to copy into this message
87  mpCodecs = new SdpCodec*[resourceMsg.mNumCodecs];
88  int codecIndex;
89  for(codecIndex = 0; codecIndex < resourceMsg.mNumCodecs; codecIndex++)
90  {
91  if(resourceMsg.mpCodecs[codecIndex])
92  {
93  mpCodecs[codecIndex] = new SdpCodec(*(resourceMsg.mpCodecs[codecIndex]));
94  }
95 
96  // This should never occur:
97  else
98  {
99  assert(resourceMsg.mpCodecs[codecIndex] != NULL);
100  mpCodecs[codecIndex] = NULL;
101  }
102  }
103  mNumCodecs = resourceMsg.mNumCodecs;
104  }
105  };
106 
108  OsMsg* createCopy(void) const
109  {
110  return new MprRtpStartReceiveMsg(*this);
111  }
112 
115  {
116  if(mpCodecs)
117  {
118  int codecIndex;
119  for(codecIndex = 0; codecIndex < mNumCodecs; codecIndex++)
120  {
121  if(mpCodecs[codecIndex])
122  {
123  delete mpCodecs[codecIndex];
124  mpCodecs[codecIndex] = NULL;
125  }
126  }
127  delete[] mpCodecs;
128  mpCodecs = NULL;
129  }
130  };
131 
133 
134  /* ============================ MANIPULATORS ============================== */
136 
137 
140  {
141  if (this == &rhs)
142  return *this; // handle the assignment to self case
143 
144  MpResourceMsg::operator=(rhs); // assign fields for parent class
145 
146  // The target array is bigger free up the spare SdpCodecs
147  int codecIndex;
148  for(codecIndex = rhs.mNumCodecs; codecIndex < mNumCodecs; codecIndex++)
149  {
150  delete mpCodecs[codecIndex];
151  mpCodecs[codecIndex] = NULL;
152  }
153 
154  // The target array is not big enough, allocate a bigger one
155  if(mNumCodecs < rhs.mNumCodecs && rhs.mNumCodecs > 0)
156  {
157  SdpCodec** tempCodecArray = mpCodecs;
158  mpCodecs = new SdpCodec*[rhs.mNumCodecs];
159  // Move the existing codecs to the bigger array to avoid
160  // allocation of new ones
161  for(codecIndex = 0; codecIndex < mNumCodecs; codecIndex++)
162  {
163  mpCodecs[codecIndex] = tempCodecArray[codecIndex];
164  tempCodecArray[codecIndex] = NULL;
165  }
166  delete[] tempCodecArray;
167  tempCodecArray = NULL;
168  }
169 
170  // Copy the codecs from the source to the target
171  for(codecIndex = 0; codecIndex < rhs.mNumCodecs; codecIndex++)
172  {
173  if(mpCodecs[codecIndex])
174  {
175  *(mpCodecs[codecIndex]) = *(rhs.mpCodecs[codecIndex]);
176  }
177  else
178  {
179  mpCodecs[codecIndex] = new SdpCodec(*(rhs.mpCodecs[codecIndex]));
180  }
181  }
182 
183  mNumCodecs = rhs.mNumCodecs;
184  mpRtpSocket = rhs.mpRtpSocket;
186 
187  return *this;
188  }
189 
190  /* ============================ ACCESSORS ================================= */
192 
193 
194  void getCodecArray(int& codecCount, SdpCodec**& codecs)
195  {
196  codecCount = mNumCodecs;
197  codecs = mpCodecs;
198  }
199 
200  OsSocket* getRtpSocket(){return(mpRtpSocket);};
201 
202  OsSocket* getRtcpSocket(){return(mpRtcpSocket);};
203 
205 
206  /* ============================ INQUIRY =================================== */
208 
209 
211 
212  /* //////////////////////////// PROTECTED ///////////////////////////////// */
213 protected:
214 
215  /* //////////////////////////// PRIVATE /////////////////////////////////// */
216 private:
217  SdpCodec** mpCodecs;
219  OsSocket* mpRtpSocket;
220  OsSocket* mpRtcpSocket;
221 };
222 
223 /* ============================ INLINE METHODS ============================ */
224 
225 #endif // _MprRtpStartReceiveMsg_h_
MpResourceMsg & operator=(const MpResourceMsg &rhs)
Assignment operator.
Definition: MpResourceMsg.cpp:60
Message object used to communicate with the media processing task.
Definition: MpResourceMsg.h:30
int mNumCodecs
Definition: MprRtpStartReceiveMsg.h:218
OsSocket * mpRtcpSocket
Definition: MprRtpStartReceiveMsg.h:220
OsMsg * createCopy(void) const
Create a copy of this msg object (which may be of a derived type)
Definition: MprRtpStartReceiveMsg.h:108
Message object used to communicate with the media processing task.
Definition: MprRtpStartReceiveMsg.h:31
MprRtpStartReceiveMsg(const MprRtpStartReceiveMsg &resourceMsg)
Copy constructor.
Definition: MprRtpStartReceiveMsg.h:77
OsSocket * mpRtpSocket
Definition: MprRtpStartReceiveMsg.h:219
OsSocket * getRtcpSocket()
Definition: MprRtpStartReceiveMsg.h:202
void getCodecArray(int &codecCount, SdpCodec **&codecs)
Definition: MprRtpStartReceiveMsg.h:194
MprRtpStartReceiveMsg(const UtlString &targetResourceName, SdpCodec *codecs[], int numCodecs, OsSocket &rRtpSocket, OsSocket &rRtcpSocket)
Constructor.
Definition: MprRtpStartReceiveMsg.h:41
SdpCodec ** mpCodecs
Definition: MprRtpStartReceiveMsg.h:217
MprRtpStartReceiveMsg & operator=(const MprRtpStartReceiveMsg &rhs)
Assignment operator.
Definition: MprRtpStartReceiveMsg.h:139
~MprRtpStartReceiveMsg()
Destructor.
Definition: MprRtpStartReceiveMsg.h:114
OsSocket * getRtpSocket()
Definition: MprRtpStartReceiveMsg.h:200