1
0

atom_text.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. * Contributer has declined to give copyright information, and gives
  15. * it freely to the world.
  16. */
  17. #include "mp4common.h"
  18. MP4TextAtom::MP4TextAtom()
  19. : MP4Atom("text")
  20. {
  21. // The atom type "text" is used in two complete unrelated ways
  22. // i.e. it's real two atoms with the same name
  23. // To handle that we need to postpone property creation until
  24. // we know who our parent atom is (stsd or gmhd) which gives us
  25. // the context info we need to know who we are
  26. }
  27. void MP4TextAtom::AddPropertiesStsdType()
  28. {
  29. AddReserved("reserved1", 6); /* 0 */
  30. AddProperty(new MP4Integer16Property("dataReferenceIndex"));/* 1 */
  31. AddProperty(new MP4Integer32Property("displayFlags")); /* 2 */
  32. AddProperty(new MP4Integer32Property("textJustification")); /* 3 */
  33. AddProperty(new MP4Integer16Property("bgColorRed")); /* 4 */
  34. AddProperty(new MP4Integer16Property("bgColorGreen")); /* 5 */
  35. AddProperty(new MP4Integer16Property("bgColorBlue")); /* 6 */
  36. AddProperty(new MP4Integer16Property("defTextBoxTop")); /* 7 */
  37. AddProperty(new MP4Integer16Property("defTextBoxLeft")); /* 8 */
  38. AddProperty(new MP4Integer16Property("defTextBoxBottom")); /* 9 */
  39. AddProperty(new MP4Integer16Property("defTextBoxRight")); /* 10 */
  40. AddReserved("reserved2", 8); /* 11 */
  41. AddProperty(new MP4Integer16Property("fontNumber")); /* 12 */
  42. AddProperty(new MP4Integer16Property("fontFace")); /* 13 */
  43. AddReserved("reserved3", 1); /* 14 */
  44. AddReserved("reserved4", 2); /* 15 */
  45. AddProperty(new MP4Integer16Property("foreColorRed")); /* 16 */
  46. AddProperty(new MP4Integer16Property("foreColorGreen")); /* 17 */
  47. AddProperty(new MP4Integer16Property("foreColorBlue")); /* 18 */
  48. }
  49. void MP4TextAtom::AddPropertiesGmhdType()
  50. {
  51. AddProperty(new MP4BytesProperty("textData", 36)); /* 0 */
  52. }
  53. void MP4TextAtom::Generate()
  54. {
  55. if (!strcmp(m_pParentAtom->GetType(), "stsd")) {
  56. AddPropertiesStsdType();
  57. GenerateStsdType();
  58. } else if (!strcmp(m_pParentAtom->GetType(), "gmhd")) {
  59. AddPropertiesGmhdType();
  60. GenerateGmhdType();
  61. } else {
  62. VERBOSE_WARNING(m_pFile->GetVerbosity(),
  63. printf("Warning: text atom in unexpected context, can not generate"));
  64. }
  65. }
  66. void MP4TextAtom::GenerateStsdType()
  67. {
  68. // generate children
  69. MP4Atom::Generate();
  70. ((MP4Integer16Property*)m_pProperties[1])->SetValue(1);
  71. ((MP4Integer32Property*)m_pProperties[2])->SetValue(1);
  72. ((MP4Integer32Property*)m_pProperties[3])->SetValue(1);
  73. }
  74. void MP4TextAtom::GenerateGmhdType()
  75. {
  76. MP4Atom::Generate();
  77. // property 0 has non-zero fixed values
  78. static u_int8_t textData[36] = {
  79. 0x00, 0x01,
  80. 0x00, 0x00,
  81. 0x00, 0x00,
  82. 0x00, 0x00,
  83. 0x00, 0x00,
  84. 0x00, 0x00,
  85. 0x00, 0x00,
  86. 0x00, 0x00,
  87. 0x00, 0x01,
  88. 0x00, 0x00,
  89. 0x00, 0x00,
  90. 0x00, 0x00,
  91. 0x00, 0x00,
  92. 0x00, 0x00,
  93. 0x00, 0x00,
  94. 0x00, 0x00,
  95. 0x40, 0x00,
  96. 0x00, 0x00,
  97. };
  98. ((MP4BytesProperty*)m_pProperties[0])->SetValue(textData, sizeof(textData));
  99. }