1
0

atom_stz2.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. /*
  23. * This is used for the 4 bit sample size below. We need the sampleCount
  24. * to be correct for the number of samples, but the table size needs to
  25. * be correct to read and write it.
  26. */
  27. class MP4HalfSizeTableProperty : public MP4TableProperty
  28. {
  29. public:
  30. MP4HalfSizeTableProperty(char *name, MP4IntegerProperty *pCountProperty) :
  31. MP4TableProperty(name, pCountProperty) {};
  32. // The count is half the actual size
  33. u_int32_t GetCount() {
  34. return (m_pCountProperty->GetValue() + 1)/ 2;
  35. };
  36. void SetCount(u_int32_t count) {
  37. m_pCountProperty->SetValue(count * 2);
  38. };
  39. };
  40. MP4Stz2Atom::MP4Stz2Atom()
  41. : MP4Atom("stz2")
  42. {
  43. AddVersionAndFlags(); /* 0, 1 */
  44. AddReserved("reserved", 3); /* 2 */
  45. AddProperty( /* 3 */
  46. new MP4Integer8Property("fieldSize"));
  47. MP4Integer32Property* pCount =
  48. new MP4Integer32Property("sampleCount");
  49. AddProperty(pCount); /* 4 */
  50. }
  51. void MP4Stz2Atom::Read()
  52. {
  53. ReadProperties(0, 4);
  54. uint8_t fieldSize =
  55. ((MP4Integer8Property *)m_pProperties[3])->GetValue();
  56. // uint32_t sampleCount = 0;
  57. MP4Integer32Property* pCount =
  58. (MP4Integer32Property *)m_pProperties[4];
  59. MP4TableProperty *pTable;
  60. if (fieldSize != 4) {
  61. pTable = new MP4TableProperty("entries", pCount);
  62. } else {
  63. // 4 bit field size uses a special table.
  64. pTable = new MP4HalfSizeTableProperty("entries", pCount);
  65. }
  66. AddProperty(pTable);
  67. if (fieldSize == 16) {
  68. pTable->AddProperty( /* 5/0 */
  69. new MP4Integer16Property("entrySize"));
  70. } else {
  71. pTable->AddProperty( /* 5/0 */
  72. new MP4Integer8Property("entrySize"));
  73. }
  74. ReadProperties(4);
  75. Skip(); // to end of atom
  76. }