• 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 VisualSampleEntry Class                         */
21 /*     -------------------------------------------------------------------       */
22 /*********************************************************************************/
23 /*
24     This VisualSampleEntry Class is used for visual streams.
25 */
26 
27 
28 #define IMPLEMENT_VisualSampleEntry
29 
30 #include "visualsampleentry.h"
31 #include "atomutils.h"
32 #include "atomdefs.h"
33 
34 #include "h263decoderspecificinfo.h"
35 
36 
VisualSampleEntry(MP4_FF_FILE * fp,uint32 size,uint32 type)37 VisualSampleEntry::VisualSampleEntry(MP4_FF_FILE *fp, uint32 size, uint32 type)
38         : SampleEntry(fp, size, type)
39 {
40     _pes = NULL;
41 
42     if (_success)
43     {
44         _pparent = NULL;
45 
46         // Read in all reserved members
47         for (int32 i = 0; i < 4; i++)
48         {
49             if (!AtomUtils::read32(fp, _reserved1[i]))
50             {
51                 _success = false;
52                 break;
53             }
54         }
55 
56         if (_success)
57         {
58             if (!AtomUtils::read32read32(fp, _reserved2, _reserved3))
59                 _success = false;
60             if (!AtomUtils::read32read32(fp, _reserved4, _reserved5))
61                 _success = false;
62             if (!AtomUtils::read16(fp, _reserved6))
63                 _success = false;
64 
65             for (int32 i = 0; i < 32; i++)
66             {
67                 if (!AtomUtils::read8(fp, _reserved7[i]))
68                 {
69                     _success = false;
70                     break;
71                 }
72             }
73 
74             if (!AtomUtils::read16read16(fp, _reserved8, _reserved9))
75                 _success = false;
76         }
77 
78         if (_success)
79         {
80             uint32 atomType = UNKNOWN_ATOM;
81             uint32 atomSize = 0;
82 
83             AtomUtils::getNextAtomType(fp, atomSize, atomType);
84 
85             if (atomType == ESD_ATOM)
86             {
87 
88                 PV_MP4_FF_NEW(fp->auditCB, ESDAtom, (fp, atomSize, atomType), _pes);
89                 if (!_pes->MP4Success())
90                 {
91                     _mp4ErrorCode = _pes->GetMP4Error();
92                     _success = false;
93                 }
94                 else
95                 {
96                     if (_pes->getObjectTypeIndication() == H263_VIDEO)
97                     {
98                         const ESDescriptor *_pdescriptor = _pes->getESDescriptorPtr();
99                         if (NULL != _pdescriptor)
100                         {
101                             H263DecoderSpecificInfo *_pH263decSpecificInfo =
102                                 (H263DecoderSpecificInfo *)(_pdescriptor->getDecoderSpecificInfo());
103                             if (NULL != _pH263decSpecificInfo)
104                             {
105                                 if (_pH263decSpecificInfo->_max_height <= 0)
106                                     _pH263decSpecificInfo->_max_height = (uint16)((_reserved2 << 16) >> 16);
107                                 if (_pH263decSpecificInfo->_max_width <= 0)
108                                     _pH263decSpecificInfo->_max_width = (uint16)(_reserved2 >> 16);
109                             }
110                         }
111                     }
112                     _pes->setParent(this);
113                 }
114             }
115             else
116             {
117                 _success = false;
118                 _mp4ErrorCode = READ_VISUAL_SAMPLE_ENTRY_FAILED;
119             }
120         }
121         else
122         {
123             _mp4ErrorCode = READ_VISUAL_SAMPLE_ENTRY_FAILED;
124         }
125     }
126     else
127     {
128         _mp4ErrorCode = READ_VISUAL_SAMPLE_ENTRY_FAILED;
129     }
130 
131 }
132 
133 // Destructor
~VisualSampleEntry()134 VisualSampleEntry::~VisualSampleEntry()
135 {
136     if (_pes != NULL)
137     {
138         // Cleanup ESDAtom
139         PV_MP4_FF_DELETE(NULL, ESDAtom, _pes);
140     }
141 }
142 
getESID() const143 uint32 VisualSampleEntry::getESID() const
144 {
145     if (_pes != NULL)
146     {
147         if (_pes->getESDescriptorPtr() != NULL)
148         {
149             return _pes->getESDescriptorPtr()->getESID();
150         }
151         else
152         {
153             return 0;
154         }
155     }
156     else
157     {
158         return 0;
159     }
160 }
161 
getWidth() const162 uint16 VisualSampleEntry::getWidth() const
163 {
164     uint32 width = _reserved2 & 0xFFFF0000;
165     uint32 ret = width >> 16;
166     return (uint16)ret;
167 
168 }
169 
170