1
0

ocidescriptors.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * The contents of this file are subject to the Mozilla Public
  3. * License Version 1.1 (the "License"); you may not use this file
  4. * except in compliance with the License. You may obtain a copy of
  5. * the License at http://www.mozilla.org/MPL/
  6. *
  7. * Software distributed under the License is distributed on an "AS
  8. * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9. * implied. See the License for the specific language governing
  10. * rights and limitations under the License.
  11. *
  12. * The Original Code is MPEG4IP.
  13. *
  14. * The Initial Developer of the Original Code is Cisco Systems Inc.
  15. * Portions created by Cisco Systems Inc. are
  16. * Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved.
  17. *
  18. * Contributor(s):
  19. * Dave Mackie [email protected]
  20. */
  21. #include "mp4common.h"
  22. MP4ContentClassDescriptor::MP4ContentClassDescriptor()
  23. : MP4Descriptor()
  24. {
  25. AddProperty( /* 0 */
  26. new MP4Integer32Property("classificationEntity"));
  27. AddProperty( /* 1 */
  28. new MP4Integer16Property("classificationTable"));
  29. AddProperty( /* 2 */
  30. new MP4BytesProperty("contentClassificationData"));
  31. }
  32. void MP4ContentClassDescriptor::Read(MP4File* pFile)
  33. {
  34. ReadHeader(pFile);
  35. /* byte properties need to know how long they are before reading */
  36. ((MP4BytesProperty*)m_pProperties[2])->SetValueSize(m_size - 6);
  37. ReadProperties(pFile);
  38. }
  39. MP4KeywordDescriptor::MP4KeywordDescriptor()
  40. : MP4Descriptor()
  41. {
  42. AddProperty( /* 0 */
  43. new MP4BytesProperty("languageCode", 3));
  44. AddProperty( /* 1 */
  45. new MP4BitfieldProperty("isUTF8String", 1));
  46. AddProperty( /* 2 */
  47. new MP4BitfieldProperty("reserved", 7));
  48. MP4Integer8Property* pCount =
  49. new MP4Integer8Property("keywordCount");
  50. AddProperty(pCount); /* 3 */
  51. MP4TableProperty* pTable = new MP4TableProperty("keywords", pCount);
  52. AddProperty(pTable); /* 4 */
  53. pTable->AddProperty( /* 4, 0 */
  54. new MP4StringProperty("string", Counted));
  55. SetReadMutate(2);
  56. }
  57. void MP4KeywordDescriptor::Mutate()
  58. {
  59. bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
  60. MP4Property* pProperty =
  61. ((MP4TableProperty*)m_pProperties[4])->GetProperty(0);
  62. ASSERT(pProperty);
  63. ((MP4StringProperty*)pProperty)->SetUnicode(!utf8Flag);
  64. }
  65. MP4RatingDescriptor::MP4RatingDescriptor()
  66. : MP4Descriptor()
  67. {
  68. AddProperty( /* 0 */
  69. new MP4Integer32Property("ratingEntity"));
  70. AddProperty( /* 1 */
  71. new MP4Integer16Property("ratingCriteria"));
  72. AddProperty( /* 2 */
  73. new MP4BytesProperty("ratingInfo"));
  74. }
  75. void MP4RatingDescriptor::Read(MP4File* pFile)
  76. {
  77. ReadHeader(pFile);
  78. /* byte properties need to know how long they are before reading */
  79. ((MP4BytesProperty*)m_pProperties[2])->SetValueSize(m_size - 6);
  80. ReadProperties(pFile);
  81. }
  82. MP4LanguageDescriptor::MP4LanguageDescriptor()
  83. : MP4Descriptor()
  84. {
  85. AddProperty( /* 0 */
  86. new MP4BytesProperty("languageCode", 3));
  87. }
  88. MP4ShortTextDescriptor::MP4ShortTextDescriptor()
  89. : MP4Descriptor()
  90. {
  91. AddProperty( /* 0 */
  92. new MP4BytesProperty("languageCode", 3));
  93. AddProperty( /* 1 */
  94. new MP4BitfieldProperty("isUTF8String", 1));
  95. AddProperty( /* 2 */
  96. new MP4BitfieldProperty("reserved", 7));
  97. AddProperty( /* 3 */
  98. new MP4StringProperty("eventName", Counted));
  99. AddProperty( /* 4 */
  100. new MP4StringProperty("eventText", Counted));
  101. SetReadMutate(2);
  102. }
  103. void MP4ShortTextDescriptor::Mutate()
  104. {
  105. bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
  106. ((MP4StringProperty*)m_pProperties[3])->SetUnicode(!utf8Flag);
  107. ((MP4StringProperty*)m_pProperties[4])->SetUnicode(!utf8Flag);
  108. }
  109. MP4ExpandedTextDescriptor::MP4ExpandedTextDescriptor()
  110. : MP4Descriptor()
  111. {
  112. AddProperty( /* 0 */
  113. new MP4BytesProperty("languageCode", 3));
  114. AddProperty( /* 1 */
  115. new MP4BitfieldProperty("isUTF8String", 1));
  116. AddProperty( /* 2 */
  117. new MP4BitfieldProperty("reserved", 7));
  118. MP4Integer8Property* pCount =
  119. new MP4Integer8Property("itemCount");
  120. AddProperty(pCount); /* 3 */
  121. MP4TableProperty* pTable = new MP4TableProperty("items", pCount);
  122. AddProperty(pTable); /* 4 */
  123. pTable->AddProperty( /* Table 0 */
  124. new MP4StringProperty("itemDescription", Counted));
  125. pTable->AddProperty( /* Table 1 */
  126. new MP4StringProperty("itemText", Counted));
  127. AddProperty( /* 5 */
  128. new MP4StringProperty("nonItemText"));
  129. ((MP4StringProperty*)m_pProperties[5])->SetExpandedCountedFormat(true);
  130. SetReadMutate(2);
  131. }
  132. void MP4ExpandedTextDescriptor::Mutate()
  133. {
  134. bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue();
  135. MP4Property* pProperty =
  136. ((MP4TableProperty*)m_pProperties[4])->GetProperty(0);
  137. ASSERT(pProperty);
  138. ((MP4StringProperty*)pProperty)->SetUnicode(!utf8Flag);
  139. pProperty = ((MP4TableProperty*)m_pProperties[4])->GetProperty(1);
  140. ASSERT(pProperty);
  141. ((MP4StringProperty*)pProperty)->SetUnicode(!utf8Flag);
  142. ((MP4StringProperty*)m_pProperties[5])->SetUnicode(!utf8Flag);
  143. }
  144. class MP4CreatorTableProperty : public MP4TableProperty {
  145. public:
  146. MP4CreatorTableProperty(char* name, MP4Integer8Property* pCountProperty) :
  147. MP4TableProperty(name, pCountProperty) {
  148. };
  149. protected:
  150. void ReadEntry(MP4File* pFile, u_int32_t index);
  151. void WriteEntry(MP4File* pFile, u_int32_t index);
  152. };
  153. MP4CreatorDescriptor::MP4CreatorDescriptor(u_int8_t tag)
  154. : MP4Descriptor(tag)
  155. {
  156. MP4Integer8Property* pCount =
  157. new MP4Integer8Property("creatorCount");
  158. AddProperty(pCount); /* 0 */
  159. MP4TableProperty* pTable = new MP4CreatorTableProperty("creators", pCount);
  160. AddProperty(pTable); /* 1 */
  161. pTable->AddProperty( /* Table 0 */
  162. new MP4BytesProperty("languageCode", 3, 3));
  163. pTable->AddProperty( /* Table 1 */
  164. new MP4BitfieldProperty("isUTF8String", 1));
  165. pTable->AddProperty( /* Table 2 */
  166. new MP4BitfieldProperty("reserved", 7));
  167. pTable->AddProperty( /* Table 3 */
  168. new MP4StringProperty("name", Counted));
  169. }
  170. void MP4CreatorTableProperty::ReadEntry(MP4File* pFile, u_int32_t index)
  171. {
  172. m_pProperties[0]->Read(pFile, index);
  173. m_pProperties[1]->Read(pFile, index);
  174. bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue(index);
  175. ((MP4StringProperty*)m_pProperties[3])->SetUnicode(!utf8Flag);
  176. m_pProperties[2]->Read(pFile, index);
  177. m_pProperties[3]->Read(pFile, index);
  178. }
  179. void MP4CreatorTableProperty::WriteEntry(MP4File* pFile, u_int32_t index)
  180. {
  181. bool utf8Flag = ((MP4BitfieldProperty*)m_pProperties[1])->GetValue(index);
  182. ((MP4StringProperty*)m_pProperties[3])->SetUnicode(!utf8Flag);
  183. MP4TableProperty::WriteEntry(pFile, index);
  184. }
  185. MP4CreationDescriptor::MP4CreationDescriptor(u_int8_t tag)
  186. : MP4Descriptor(tag)
  187. {
  188. AddProperty( /* 0 */
  189. new MP4BitfieldProperty("contentCreationDate", 40));
  190. }
  191. MP4SmpteCameraDescriptor::MP4SmpteCameraDescriptor()
  192. : MP4Descriptor()
  193. {
  194. MP4Integer8Property* pCount =
  195. new MP4Integer8Property("parameterCount");
  196. AddProperty(pCount);
  197. MP4TableProperty* pTable = new MP4TableProperty("parameters", pCount);
  198. AddProperty(pTable);
  199. pTable->AddProperty(
  200. new MP4Integer8Property("id"));
  201. pTable->AddProperty(
  202. new MP4Integer32Property("value"));
  203. }
  204. MP4UnknownOCIDescriptor::MP4UnknownOCIDescriptor()
  205. : MP4Descriptor()
  206. {
  207. AddProperty( /* 0 */
  208. new MP4BytesProperty("data"));
  209. }
  210. void MP4UnknownOCIDescriptor::Read(MP4File* pFile)
  211. {
  212. ReadHeader(pFile);
  213. /* byte properties need to know how long they are before reading */
  214. ((MP4BytesProperty*)m_pProperties[0])->SetValueSize(m_size);
  215. ReadProperties(pFile);
  216. }
  217. MP4Descriptor* CreateOCIDescriptor(u_int8_t tag)
  218. {
  219. MP4Descriptor* pDescriptor = NULL;
  220. switch (tag) {
  221. case MP4ContentClassDescrTag:
  222. pDescriptor = new MP4ContentClassDescriptor();
  223. break;
  224. case MP4KeywordDescrTag:
  225. pDescriptor = new MP4KeywordDescriptor();
  226. break;
  227. case MP4RatingDescrTag:
  228. pDescriptor = new MP4RatingDescriptor();
  229. break;
  230. case MP4LanguageDescrTag:
  231. pDescriptor = new MP4LanguageDescriptor();
  232. break;
  233. case MP4ShortTextDescrTag:
  234. pDescriptor = new MP4ShortTextDescriptor();
  235. break;
  236. case MP4ExpandedTextDescrTag:
  237. pDescriptor = new MP4ExpandedTextDescriptor();
  238. break;
  239. case MP4ContentCreatorDescrTag:
  240. case MP4OCICreatorDescrTag:
  241. pDescriptor = new MP4CreatorDescriptor(tag);
  242. break;
  243. case MP4ContentCreationDescrTag:
  244. case MP4OCICreationDescrTag:
  245. pDescriptor = new MP4CreationDescriptor(tag);
  246. break;
  247. case MP4SmpteCameraDescrTag:
  248. pDescriptor = new MP4SmpteCameraDescriptor();
  249. break;
  250. }
  251. if (pDescriptor == NULL) {
  252. if (tag >= MP4OCIDescrTagsStart && tag <= MP4OCIDescrTagsEnd) {
  253. pDescriptor = new MP4UnknownOCIDescriptor();
  254. pDescriptor->SetTag(tag);
  255. }
  256. }
  257. return pDescriptor;
  258. }