• 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 /*********************************************************************************/
19 /*     -------------------------------------------------------------------       */
20 /*                        MPEG-4 ObjectDescriptor Class                          */
21 /*     -------------------------------------------------------------------       */
22 /*********************************************************************************/
23 
24 
25 #define IMPLEMENT_ObjectDescriptor
26 
27 #include "objectdescriptor.h"
28 #include "atomutils.h"
29 
30 #include "oscl_utf8conv.h"
31 
32 typedef Oscl_Vector<uint32, OsclMemAllocator> uint32VecType;
33 
34 // Constructor
ObjectDescriptor(MP4_FF_FILE * fp,bool all)35 ObjectDescriptor::ObjectDescriptor(MP4_FF_FILE *fp, bool all)
36         : BaseDescriptor(fp)
37 {
38     _pESIDVec = NULL;
39 
40     if (_success)
41     {
42 
43         _pparent = NULL;
44 
45         PV_MP4_FF_NEW(fp->auditCB, uint32VecType, (), _pESIDVec);
46 
47         // Check needed if directly reading in an ObjectDescriptor (all=true) or
48         // an InitialObjectDescriptor (all=false)
49         if (all)
50         {
51             _reserved = 0x1f;
52 
53             uint16 data;
54             if (!AtomUtils::read16(fp, data))
55                 _success = false;
56 
57             _objectDescriptorID = (uint16)(data >> 6);
58 
59             _urlFlag = false;
60             if (((data >> 5) & 0x0001) == 1)
61             {
62                 _urlFlag = true;
63             }
64 
65             if (_urlFlag)
66             {
67 
68                 if (!AtomUtils::read8(fp, _urlLength))
69                     _success = false;
70 
71                 _urlStringPtr = (uint8 *) oscl_malloc(_urlLength + 1); // +1 for the null termination
72 
73                 if (!AtomUtils::readByteData(fp, _urlLength, _urlStringPtr))
74                     _success = false;
75             }
76             else
77             {
78                 // Read in ESDescriptor references (i.e. ESIDs)
79                 int32 readIn = AtomUtils::getNumberOfBytesUsedToStoreSizeOfClass(_sizeOfClass);
80                 readIn += 1; // For tag
81                 readIn += 2; // For 10-bit ODID, etc.
82                 int32 delta = _sizeOfClass - readIn;
83 
84                 uint32  tag;
85 
86                 //check for the next byte to see if it is a tag or 0 for ES_ID
87                 tag = AtomUtils::peekNextNthBytes(fp,  0);
88                 if (tag == 0)   //ES_ID, old version
89                 {
90                     uint32 esid;
91                     for (int32 i = 0; i < delta; i += 4)
92                     {
93                         if (!AtomUtils::read32(fp, esid))
94                         {
95                             _success = false;
96                             break;
97                         }
98                         (*_pESIDVec).push_back(esid);
99                     }
100 
101                 }
102                 else
103                 {//new version ES_ID_Inc and ES_ID_Ref
104                     //currently I do the parse only
105                     ES_ID_Ref *esIDRef;
106                     while (delta > 0)
107                     {
108                         PV_MP4_FF_NEW(fp->auditCB, ES_ID_Ref, (fp), esIDRef);
109                         delta -= esIDRef->getSize();
110                         (*_pES_ID_Ref).push_back(esIDRef);
111                     }
112                 }
113 
114             }
115         }
116 
117         if (!_success)
118             _mp4ErrorCode = READ_OBJECT_DESCRIPTOR_FAILED;
119     }
120     else
121     {
122         _mp4ErrorCode = READ_OBJECT_DESCRIPTOR_FAILED;
123     }
124 
125 }
126 
127 // Destructor
~ObjectDescriptor()128 ObjectDescriptor::~ObjectDescriptor()
129 {
130     if (_pESIDVec != NULL)
131     {
132         PV_MP4_FF_TEMPLATED_DELETE(NULL, uint32VecType, Oscl_Vector, _pESIDVec);
133     }
134 }
135 
getUrlString() const136 OSCL_wHeapString<OsclMemAllocator> ObjectDescriptor::getUrlString() const
137 {
138 
139     // Need to convert from a Multibyte array pointer to a wide character array
140 
141     // allocate space for wide character buffer
142     OSCL_TCHAR *pwbuf = (OSCL_TCHAR*) oscl_malloc(_urlLength * sizeof(OSCL_TCHAR));
143 
144     if (!pwbuf)
145         return NULL;
146 
147     // convert utf8 character array to wide character array
148     oscl_UTF8ToUnicode((const char *)_urlStringPtr, _urlLength, pwbuf, _urlLength*sizeof(OSCL_TCHAR));
149 
150     // return newly created ZString
151     return OSCL_wHeapString<OsclMemAllocator>(pwbuf);
152 }
153