atom_stsc.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. MP4StscAtom::MP4StscAtom()
  23. : MP4Atom("stsc")
  24. {
  25. AddVersionAndFlags();
  26. MP4Integer32Property* pCount =
  27. new MP4Integer32Property("entryCount");
  28. AddProperty(pCount);
  29. MP4TableProperty* pTable = new MP4TableProperty("entries", pCount);
  30. AddProperty(pTable);
  31. pTable->AddProperty(
  32. new MP4Integer32Property("firstChunk"));
  33. pTable->AddProperty(
  34. new MP4Integer32Property("samplesPerChunk"));
  35. pTable->AddProperty(
  36. new MP4Integer32Property("sampleDescriptionIndex"));
  37. // As an optimization we add an implicit property to this table,
  38. // "firstSample" that corresponds to the first sample of the firstChunk
  39. MP4Integer32Property* pSample =
  40. new MP4Integer32Property("firstSample");
  41. pSample->SetImplicit();
  42. pTable->AddProperty(pSample);
  43. }
  44. void MP4StscAtom::Read()
  45. {
  46. // Read as usual
  47. MP4Atom::Read();
  48. // Compute the firstSample values for later use
  49. u_int32_t count =
  50. ((MP4Integer32Property*)m_pProperties[2])->GetValue();
  51. MP4Integer32Property* pFirstChunk = (MP4Integer32Property*)
  52. ((MP4TableProperty*)m_pProperties[3])->GetProperty(0);
  53. MP4Integer32Property* pSamplesPerChunk = (MP4Integer32Property*)
  54. ((MP4TableProperty*)m_pProperties[3])->GetProperty(1);
  55. MP4Integer32Property* pFirstSample = (MP4Integer32Property*)
  56. ((MP4TableProperty*)m_pProperties[3])->GetProperty(3);
  57. MP4SampleId sampleId = 1;
  58. for (u_int32_t i = 0; i < count; i++) {
  59. pFirstSample->SetValue(sampleId, i);
  60. if (i < count - 1) {
  61. sampleId +=
  62. (pFirstChunk->GetValue(i+1) - pFirstChunk->GetValue(i))
  63. * pSamplesPerChunk->GetValue(i);
  64. }
  65. }
  66. }