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 UserDataAtom Class */
21 /* ------------------------------------------------------------------- */
22 /*********************************************************************************/
23 /*
24 This UserDataAtom Class is a container atom for informative user-data.
25 */
26
27
28 #define __IMPLEMENT_PVUserDataAtom__
29
30 #include "pvuserdataatom.h"
31 #include "atomdefs.h"
32
33
34
35
36 // Stream-in Constructor
PVUserDataAtom(MP4_FF_FILE * fp,uint32 size,uint32 type)37 PVUserDataAtom::PVUserDataAtom(MP4_FF_FILE *fp, uint32 size, uint32 type)
38 : Atom(fp, size, type)
39 {
40 _success = true;
41
42 uint32 _count = getDefaultSize();
43
44 if (!AtomUtils::readNullTerminatedUnicodeString(fp, _version))
45 {
46 _success = false;
47 _mp4ErrorCode = READ_PV_USER_DATA_ATOM_FAILED;
48 return;
49 }
50 _count += (_version.get_size() * 2 + 2);
51
52 if (!AtomUtils::readNullTerminatedUnicodeString(fp, _title))
53 {
54 _success = false;
55 _mp4ErrorCode = READ_PV_USER_DATA_ATOM_FAILED;
56 return;
57 }
58 _count += (_title.get_size() * 2 + 2);
59
60 if (!AtomUtils::readNullTerminatedUnicodeString(fp, _author))
61 {
62 _success = false;
63 _mp4ErrorCode = READ_PV_USER_DATA_ATOM_FAILED;
64 return;
65 }
66 _count += (_author.get_size() * 2 + 2);
67
68 if (!AtomUtils::readNullTerminatedUnicodeString(fp, _copyright))
69 {
70 _success = false;
71 _mp4ErrorCode = READ_PV_USER_DATA_ATOM_FAILED;
72 return;
73 }
74 _count += (_copyright.get_size() * 2 + 2);
75
76 if (!AtomUtils::readNullTerminatedUnicodeString(fp, _description))
77 {
78 _success = false;
79 _mp4ErrorCode = READ_PV_USER_DATA_ATOM_FAILED;
80 return;
81 }
82 _count += (_description.get_size() * 2 + 2);
83
84 if (!AtomUtils::readNullTerminatedUnicodeString(fp, _rating))
85 {
86 _success = false;
87 _mp4ErrorCode = READ_PV_USER_DATA_ATOM_FAILED;
88 return;
89 }
90 _count += (_rating.get_size() * 2 + 2);
91
92 if (!AtomUtils::readNullTerminatedUnicodeString(fp, _creationDate))
93 {
94 _success = false;
95 _mp4ErrorCode = READ_PV_USER_DATA_ATOM_FAILED;
96 return;
97 }
98 _count += (_creationDate.get_size() * 2 + 2);
99
100 while (_count < _size)
101 {
102 uint8 data;
103 if (!AtomUtils::read8(fp, data))
104 {
105 _success = false;
106 _mp4ErrorCode = READ_PV_USER_DATA_ATOM_FAILED;
107 return;
108 }
109 _count++;
110 }
111 }
112
113 // Copy constructor
PVUserDataAtom(PVUserDataAtom & atom)114 PVUserDataAtom::PVUserDataAtom(PVUserDataAtom &atom)
115 : Atom(PVUSER_DATA_ATOM)
116 {
117 MP4FFParserOriginalCharEnc charType;
118 _version = atom.getPVVersion();
119 _title = atom.getPVTitle(charType);
120 _author = atom.getPVAuthor(charType);
121 _copyright = atom.getPVCopyright(charType);
122 _description = atom.getPVDescription(charType);
123 _rating = atom.getPVRating(charType);
124 }
125
126 // Destructor
~PVUserDataAtom()127 PVUserDataAtom::~PVUserDataAtom()
128 {
129
130 }
131
PVContentTypeAtom(MP4_FF_FILE * fp,uint32 size,uint32 type)132 PVContentTypeAtom::PVContentTypeAtom(MP4_FF_FILE *fp, uint32 size, uint32 type)
133 : Atom(fp, size, type)
134 {
135 _success = true;
136
137 //Initialize to an undefined value - all content with this atom, ought to contain
138 //a valid content type
139 _contentType = 0xFFFFFFFF;
140
141 uint32 _count = getDefaultSize();
142
143 if (!AtomUtils::read32(fp, _contentType))
144 {
145 _success = false;
146 _mp4ErrorCode = READ_PV_CONTENT_TYPE_ATOM_FAILED;
147 return;
148 }
149 _count += sizeof(_contentType);
150
151 while (_count < _size)
152 {
153 uint8 data;
154 if (!AtomUtils::read8(fp, data))
155 {
156 _success = false;
157 _mp4ErrorCode = READ_PV_CONTENT_TYPE_ATOM_FAILED;
158 return;
159 }
160 _count++;
161 }
162 }
163