• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 #ifndef __SDP_INFO_H__
19 #include "sdp_info.h"
20 #endif
21 
22 #ifndef SDPPARSER_CONFIG_H_INCLUDED
23 #include "sdpparser_config.h"
24 #endif
25 
26 #ifndef SDPPARSER_HAS_REAL_MEDIA_SUPPORT
27 #error "sdp config file missing"
28 #endif
29 
30 #if SDPPARSER_HAS_REAL_MEDIA_SUPPORT
31 #ifndef RM_MEDIAINFO_H
32 #include "rm_media_info.h"
33 #endif
34 #endif
35 
36 
37 OSCL_EXPORT_REF
SDPInfo()38 SDPInfo::SDPInfo()
39 {
40     numMediaObjects = 0;
41     iMediaObjectIndex = 0;
42     segmentCount = 0;
43     for (int ii = 0; ii < MAX_SEGMENTS; ii++)
44     {
45         segmentInfo[ii].segmentActive = true;
46         segmentInfo[ii].segmentPayloadOrderPref = false;
47     }
48 }
49 
50 OSCL_EXPORT_REF
SDPInfo(const SDPInfo & sourceSdpInfo)51 SDPInfo::SDPInfo(const SDPInfo &sourceSdpInfo)
52 {
53     //expecting the = oper of sessionDescription to be overloaded
54     session_info = sourceSdpInfo.session_info;
55     SdpFilename = sourceSdpInfo.SdpFilename;
56     segmentCount = sourceSdpInfo.segmentCount;
57     iMediaObjectIndex = sourceSdpInfo.iMediaObjectIndex;
58     numMediaObjects = sourceSdpInfo.numMediaObjects;
59 
60     for (int jj = 0; jj < MAX_SEGMENTS; jj++)
61     {
62         segmentInfo[jj] = sourceSdpInfo.segmentInfo[jj];
63     }
64 
65     for (int ii = 0; ii < MAX_MEDIA_OBJECTS; ii++)
66     {
67         Oscl_Vector< mediaInfo *, SDPParserAlloc>& destMediaInfoVect = pMediaInfo[ii];
68         const Oscl_Vector< mediaInfo *, SDPParserAlloc>& srcMediaInfoVect = sourceSdpInfo.pMediaInfo[ii];
69         const int32 srcMediaInfoVectSz = srcMediaInfoVect.size();
70         for (int ss = 0; ss < srcMediaInfoVectSz; ss++)
71         {
72             mediaInfo* destMediaInfo = NULL;
73             const char *mimeType = srcMediaInfoVect[ss]->getMIMEType();
74             bool alternateMedia = (0 == ss) ? false : true;
75 
76             if (!oscl_strncmp(mimeType, "AAC", oscl_strlen("AAC")) || !oscl_strncmp(mimeType, "MP4A-LATM", oscl_strlen("MP4A-LATM")))
77             {
78                 aac_mediaInfo *pSourceAAC = OSCL_REINTERPRET_CAST(aac_mediaInfo*, srcMediaInfoVect[ss]);
79                 void *memory = alloc(sizeof(aac_mediaInfo), alternateMedia);
80                 aac_mediaInfo *pAAC = OSCL_PLACEMENT_NEW(memory, aac_mediaInfo());
81                 *pAAC = *pSourceAAC;
82                 destMediaInfo = pAAC;
83             }
84             else if (!oscl_strncmp(mimeType, "AMR", oscl_strlen("AMR")))
85             {
86                 amr_mediaInfo *pSourceAMR = OSCL_REINTERPRET_CAST(amr_mediaInfo*, srcMediaInfoVect[ss]);
87                 void *memory = alloc(sizeof(amr_mediaInfo), alternateMedia);
88                 amr_mediaInfo *pAMR = OSCL_PLACEMENT_NEW(memory, amr_mediaInfo());
89                 *pAMR = *pSourceAMR;
90                 destMediaInfo = pAMR;
91             }
92             else if (!oscl_strncmp(mimeType, "MP4V-ES", oscl_strlen("MP4V-ES")))
93             {
94                 m4v_mediaInfo *pSourceM4V = OSCL_REINTERPRET_CAST(m4v_mediaInfo*, srcMediaInfoVect[ss]);
95                 void *memory = alloc(sizeof(m4v_mediaInfo), alternateMedia);
96                 m4v_mediaInfo *pM4V = OSCL_PLACEMENT_NEW(memory, m4v_mediaInfo());
97                 *pM4V = *pSourceM4V;
98                 destMediaInfo = pM4V;
99             }
100             else if (!oscl_strncmp(mimeType, "H263-1998", oscl_strlen("H263-1998")) || !oscl_strncmp(mimeType, "H263-2000", oscl_strlen("H263-2000")))
101             {
102                 h263_mediaInfo *pSourceH263 = OSCL_REINTERPRET_CAST(h263_mediaInfo*, srcMediaInfoVect[ss]);
103                 void *memory = alloc(sizeof(h263_mediaInfo), alternateMedia);
104                 h263_mediaInfo *pH263 = OSCL_PLACEMENT_NEW(memory, h263_mediaInfo());
105                 *pH263 = *pSourceH263;
106                 destMediaInfo = pH263;
107             }
108             else if (!oscl_strncmp(mimeType, "PVMP4V-ES", oscl_strlen("PVMP4V-ES")))
109             {
110                 m4v_mediaInfo *pSourceM4V = OSCL_REINTERPRET_CAST(m4v_mediaInfo*, srcMediaInfoVect[ss]);
111                 void *memory = alloc(sizeof(m4v_mediaInfo), alternateMedia);
112                 m4v_mediaInfo *pM4V = OSCL_PLACEMENT_NEW(memory, m4v_mediaInfo());
113                 *pM4V = *pSourceM4V;
114                 destMediaInfo = pM4V;
115             }
116             else if (!oscl_strncmp(mimeType, "mpeg4-generic", oscl_strlen("mpeg4-generic")))
117             {
118                 rfc3640_mediaInfo *pSourceRFC3640 = OSCL_REINTERPRET_CAST(rfc3640_mediaInfo*, srcMediaInfoVect[ss]);
119                 void *memory = alloc(sizeof(rfc3640_mediaInfo), alternateMedia);
120                 rfc3640_mediaInfo *pRFC3640 = OSCL_PLACEMENT_NEW(memory, rfc3640_mediaInfo());
121                 *pRFC3640 = *pSourceRFC3640;
122                 destMediaInfo = pRFC3640;
123             }
124             else if (!oscl_strncmp(mimeType, "X-MP4V-IMAGE", oscl_strlen("X-MP4V-IMAGE")))
125             {
126                 still_image_mediaInfo *pSourceImage = OSCL_REINTERPRET_CAST(still_image_mediaInfo*, srcMediaInfoVect[ss]);
127                 void *memory = alloc(sizeof(still_image_mediaInfo), alternateMedia);
128                 still_image_mediaInfo *pImage = OSCL_PLACEMENT_NEW(memory, still_image_mediaInfo());
129                 *pImage = *pSourceImage;
130                 destMediaInfo = pImage;
131             }
132 #if SDPPARSER_HAS_REAL_MEDIA_SUPPORT
133             else if (!oscl_strncmp(mimeType, "x-pn-realaudio", oscl_strlen("x-pn-realaudio")) || !oscl_strncmp(mimeType, "x-pn-realvideo", oscl_strlen("x-pn-realvideo")))
134             {
135                 rm_mediaInfo *rmSource = OSCL_REINTERPRET_CAST(rm_mediaInfo*, srcMediaInfoVect[ss]);
136                 void *memory = alloc(sizeof(rm_mediaInfo), alternateMedia);
137                 rm_mediaInfo *prm = OSCL_PLACEMENT_NEW(memory, rm_mediaInfo());
138                 *prm = *rmSource;
139                 destMediaInfo = prm;
140             }
141 #endif
142             if (destMediaInfo)
143                 destMediaInfoVect.push_back(destMediaInfo);
144         }
145     }
146 }
147 
148 
149 OSCL_EXPORT_REF
~SDPInfo()150 SDPInfo::~SDPInfo()
151 {
152     int ii = 0;
153     int ss = 0;
154     for (ii = 0; ii < numMediaObjects; ii++)
155     {
156         for (ss = 0; ss < (int)pMediaInfo[ii].size(); ss++)
157         {
158             pMediaInfo[ii][ss]->~mediaInfo();
159             dealloc(pMediaInfo[ii][ss]);
160         }
161     }
162     numMediaObjects = 0;
163 
164 }
165 
166 OSCL_EXPORT_REF
freeLastMediaInfoObject(void)167 void SDPInfo::freeLastMediaInfoObject(void)
168 {
169     if (numMediaObjects < 0)
170     {
171         return;
172     }
173 
174     for (int ss = 0; ss < (int)pMediaInfo[numMediaObjects].size(); ss++)
175     {
176         pMediaInfo[numMediaObjects][ss]->~mediaInfo();
177         dealloc(pMediaInfo[numMediaObjects][ss]);
178     }
179 }
180 
181 OSCL_EXPORT_REF
getSessionInfo()182 sessionDescription* SDPInfo::getSessionInfo()
183 {
184     return &session_info;
185 }
186 
187 OSCL_EXPORT_REF
getMediaInfo(int Object)188 Oscl_Vector<mediaInfo *, SDPParserAlloc> SDPInfo::getMediaInfo(int Object)
189 {
190     if ((Object >= 0) && (Object < MAX_MEDIA_OBJECTS))
191     {
192         return pMediaInfo[Object];
193     }
194     else
195     {
196         return 0;
197     }
198 }
199 
200 OSCL_EXPORT_REF
getMediaArray()201 Oscl_Vector<mediaInfo *, SDPParserAlloc> * SDPInfo::getMediaArray()
202 {
203     return pMediaInfo;
204 }
205 
206 OSCL_EXPORT_REF
getNumMediaObjects()207 int SDPInfo::getNumMediaObjects()
208 {
209     return numMediaObjects;
210 }
211 
212 OSCL_EXPORT_REF
dealloc(void * ptr)213 void SDPInfo::dealloc(void *ptr)
214 {
215     oscl_free(ptr);
216 }
217 
218 OSCL_EXPORT_REF
getMediaInfoBasedOnID(uint32 trackID)219 mediaInfo* SDPInfo::getMediaInfoBasedOnID(uint32 trackID)
220 {
221     int numObjects = getNumMediaObjects();
222 
223     for (int i = 0; i < numObjects; i++)
224     {
225         Oscl_Vector<mediaInfo*, SDPParserAlloc> mediaInfoVec;
226         mediaInfoVec = getMediaInfo(i);
227 
228         for (uint32 j = 0; j < mediaInfoVec.size(); j++)
229         {
230             mediaInfo* minfo = mediaInfoVec[j];
231 
232             if (minfo != NULL)
233             {
234                 if (minfo->getMediaInfoID() == trackID)
235                 {
236                     return minfo;
237                 }
238             }
239         }
240     }
241     return NULL;
242 }
243 
244 OSCL_EXPORT_REF
getMediaInfoBasedOnDependsOnID(uint32 trackID)245 mediaInfo* SDPInfo::getMediaInfoBasedOnDependsOnID(uint32 trackID)
246 {
247     if (trackID == 0)
248     {
249         return NULL;
250     }
251 
252     int numObjects = getNumMediaObjects();
253 
254     for (int i = 0; i < numObjects; i++)
255     {
256         Oscl_Vector<mediaInfo*, SDPParserAlloc> mediaInfoVec;
257         mediaInfoVec = getMediaInfo(i);
258 
259         for (uint32 j = 0; j < mediaInfoVec.size(); j++)
260         {
261             mediaInfo* minfo = mediaInfoVec[j];
262 
263             if (minfo != NULL)
264             {
265                 if ((uint32)(minfo->getControlTrackID()) == trackID)
266                 {
267                     return minfo;
268                 }
269             }
270         }
271     }
272     return NULL;
273 }
274 
275 OSCL_EXPORT_REF
alloc(const int size,bool alternateMedia)276 void * SDPInfo::alloc(const int size, bool alternateMedia)
277 {
278     OSCL_UNUSED_ARG(alternateMedia);
279 
280     if (numMediaObjects < MAX_MEDIA_OBJECTS)
281     {
282         void *mem = oscl_malloc(size * sizeof(char));
283         if (mem != NULL)
284         {
285             iMediaObjectIndex++;
286             pMediaInfo[numMediaObjects].push_back((mediaInfo *)mem);
287         }
288         return mem;
289     }
290     else
291     {
292         return NULL;
293     }
294 }
295 
296 OSCL_EXPORT_REF
IncrementAlternateMediaInfoVectorIndex()297 void SDPInfo::IncrementAlternateMediaInfoVectorIndex()
298 {
299     pMediaInfo[numMediaObjects][0]->setSegmentNumber(segmentCount);
300     numMediaObjects++;
301 }
302 
303 OSCL_EXPORT_REF
copyFmDefMedia(mediaInfo * media)304 void SDPInfo::copyFmDefMedia(mediaInfo *media)
305 {
306     *media = *pMediaInfo[numMediaObjects][0];
307 }
308 
309 OSCL_EXPORT_REF
reset()310 void SDPInfo::reset()
311 {
312     session_info.resetSessionDescription();
313     int ii = 0;
314     int ss = 0;
315     for (ii = 0; ii < numMediaObjects; ii++)
316     {
317         for (ss = 0; ss < (int)pMediaInfo[ii].size(); ss++)
318         {
319             pMediaInfo[ii][ss]->~mediaInfo();
320             dealloc(pMediaInfo[ii][ss]);
321         }
322     }
323     numMediaObjects = 0;
324 }
325 
326 OSCL_EXPORT_REF
getMediaObjectIndex()327 uint32 SDPInfo::getMediaObjectIndex()
328 {
329     return iMediaObjectIndex;
330 }
331 
332 OSCL_EXPORT_REF
getMediaInfoInSegment(int segment,Oscl_Vector<mediaInfo *,SDPParserAlloc> & segmentMediaInfo)333 bool SDPInfo::getMediaInfoInSegment(int segment, Oscl_Vector< mediaInfo *, SDPParserAlloc>& segmentMediaInfo)
334 {
335     if (segmentCount == 0)
336         return false;
337     for (int ii = 0; ii < numMediaObjects; ii++)
338     {
339         if (pMediaInfo[ii][0]->getSegmentNumber() == (uint)segment)
340         {
341             segmentMediaInfo.push_back(pMediaInfo[ii][0]);
342         }
343     }
344     return true;
345 }
346 
347 OSCL_EXPORT_REF
setSegmentCount(int count)348 void SDPInfo::setSegmentCount(int count)
349 {
350     segmentCount = count;
351 }
352 
353 OSCL_EXPORT_REF
getSegmentCount()354 int SDPInfo::getSegmentCount()
355 {
356     return segmentCount;
357 }
358 
359 OSCL_EXPORT_REF
setSegmentActive(int segment,bool status)360 bool SDPInfo::setSegmentActive(int segment, bool status)
361 {
362     if (segment <= segmentCount)
363     {
364         segmentInfo[segment].segmentActive = status;
365         return true;
366     }
367     else
368         return false;
369 }
370 
371 OSCL_EXPORT_REF
isSegmentActive(int segment)372 bool SDPInfo::isSegmentActive(int segment)
373 {
374     if (segment <= segmentCount)
375         return segmentInfo[segment].segmentActive;
376     else
377         return false;
378 }
379 
380 OSCL_EXPORT_REF
setSegmentPayloadOrderPref(int segment,int * payloadArray,int len)381 bool SDPInfo::setSegmentPayloadOrderPref(int segment, int* payloadArray, int len)
382 {
383     segmentInfo[segment].segmentPayloadOrderPref = false;
384     if (segment <= segmentCount)
385     {
386         Oscl_Vector< mediaInfo *, SDPParserAlloc> segmentMediaInfo;
387         if (getMediaInfoInSegment(segment, segmentMediaInfo) == true)
388         {
389             for (int ii = 0; ii < len; ii++)
390             {
391                 for (uint32 jj = 0; jj < segmentMediaInfo.size(); jj++)
392                 {
393                     if (segmentMediaInfo[jj]->getPayloadSpecificInfoVector()[0]->getPayloadNumber() == (uint32)payloadArray[ii])
394                     {
395                         segmentMediaInfo[jj]->setPayloadPreference(ii);
396                         break;
397                     }
398                 }
399             }
400         }
401     }
402     else
403         return false;
404     segmentInfo[segment].segmentPayloadOrderPref = true;
405     return true;
406 }
407 
408 OSCL_EXPORT_REF
isPayloadOrderPreferenceSet(int segment)409 bool SDPInfo::isPayloadOrderPreferenceSet(int segment)
410 {
411     if (segment <= segmentCount)
412         return segmentInfo[segment].segmentPayloadOrderPref;
413     else
414         return false;
415 }
416 
417 OSCL_EXPORT_REF
getPreferedMediaInfo(int segment)418 mediaInfo* SDPInfo::getPreferedMediaInfo(int segment)
419 {
420     mediaInfo* media = NULL;
421     Oscl_Vector< mediaInfo *, SDPParserAlloc> segmentMediaInfo;
422     if (getMediaInfoInSegment(segment, segmentMediaInfo) == true)
423     {
424         for (uint32 jj = 0; jj < segmentMediaInfo.size(); jj++)
425         {
426             if (segmentMediaInfo[jj]->isMatched() == true)
427             {
428                 media = segmentMediaInfo[jj];
429                 break;
430             }
431         }
432     }
433     return media;
434 }
435 
436 OSCL_EXPORT_REF
getPreferedPayloadNumber(int segment)437 int SDPInfo::getPreferedPayloadNumber(int segment)
438 {
439     int payload = -1;
440     Oscl_Vector< mediaInfo *, SDPParserAlloc> segmentMediaInfo;
441     if (getMediaInfoInSegment(segment, segmentMediaInfo) == true)
442     {
443         for (uint32 jj = 0; jj < segmentMediaInfo.size(); jj++)
444         {
445             if (segmentMediaInfo[jj]->isMatched() == true)
446             {
447                 payload = segmentMediaInfo[jj]->getPayloadSpecificInfoVector()[0]->getPayloadNumber();
448                 break;
449             }
450         }
451     }
452     return payload;
453 }
454 
455 OSCL_EXPORT_REF
getSdpFilename(uint32 & retsize)456 const oscl_wchar * SDPInfo::getSdpFilename(uint32 &retsize)
457 {
458     retsize = SdpFilename.get_size();
459     return SdpFilename.get_cstr();
460 }
461 
462 OSCL_EXPORT_REF
setSDPFilename(OSCL_wString & aURL)463 void SDPInfo::setSDPFilename(OSCL_wString& aURL)
464 {
465     SdpFilename = aURL;
466 }
467