1
0

3gp.cpp 3.9 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. * 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. * 3GPP features implementation is based on 3GPP's TS26.234-v5.60,
  19. * and was contributed by Ximpo Group Ltd.
  20. *
  21. * Portions created by Ximpo Group Ltd. are
  22. * Copyright (C) Ximpo Group Ltd. 2003, 2004. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. * Ximpo Group Ltd. [email protected]
  26. */
  27. #include "mp4common.h"
  28. #define _3GP_MAJOR_BRAND "3gp5"
  29. #define _3GP_MINOR_VERSION 0x0001
  30. void MP4File::Make3GPCompliant(const MP4_FILENAME_CHAR* fileName, char* majorBrand, u_int32_t minorVersion, char** supportedBrands, u_int32_t supportedBrandsCount, bool deleteIodsAtom)
  31. {
  32. char brand[5] = "3gp5";
  33. char* _3gpSupportedBrands[1] = { (char*)&brand };
  34. if (majorBrand) {
  35. if (!supportedBrands || !supportedBrandsCount) {
  36. throw new MP4Error("Invalid parameters", "MP4File::Make3GPCompliant");
  37. }
  38. }
  39. MakeFtypAtom(
  40. majorBrand ? majorBrand : (char*)brand,
  41. majorBrand ? minorVersion : _3GP_MINOR_VERSION,
  42. majorBrand ? supportedBrands : (char**)_3gpSupportedBrands,
  43. majorBrand ? supportedBrandsCount : 1);
  44. if (deleteIodsAtom) {
  45. // Delete the iods atom, if it exists....
  46. MP4Atom* iodsAtom = m_pRootAtom->FindAtomMP4("moov.iods");
  47. if (iodsAtom) {
  48. MP4Atom* moovAtom = m_pRootAtom->FindAtomMP4("moov");
  49. ASSERT(moovAtom);
  50. moovAtom->DeleteChildAtom(iodsAtom);
  51. }
  52. }
  53. }
  54. void MP4File::MakeFtypAtom(char* majorBrand, u_int32_t minorVersion, char** supportedBrands, u_int32_t supportedBrandsCount)
  55. {
  56. bool rewriteNeeded = false;
  57. u_int32_t currentSupportedBrandsCount;
  58. u_int32_t i;
  59. MP4Atom* ftypAtom = m_pRootAtom->FindAtomMP4("ftyp");
  60. if (ftypAtom == NULL) {
  61. ftypAtom = InsertChildAtom(m_pRootAtom, "ftyp", 0);
  62. }
  63. if (majorBrand == NULL)
  64. return;
  65. MP4StringProperty* pMajorBrandProperty;
  66. if (!ftypAtom->FindProperty(
  67. "ftyp.majorBrand",
  68. (MP4Property**)&pMajorBrandProperty))
  69. return;
  70. pMajorBrandProperty->SetValue(majorBrand);
  71. MP4Integer32Property* pMinorVersionProperty;
  72. if (!ftypAtom->FindProperty(
  73. "ftype.minorVersion",
  74. (MP4Property**)&pMinorVersionProperty))
  75. return;
  76. pMinorVersionProperty->SetValue(minorVersion);
  77. MP4Integer32Property* pCompatibleBrandsCountProperty;
  78. if (!ftypAtom->FindProperty(
  79. "ftyp.compatibleBrandsCount",
  80. (MP4Property**)&pCompatibleBrandsCountProperty)) return;
  81. currentSupportedBrandsCount = pCompatibleBrandsCountProperty->GetValue();
  82. MP4TableProperty* pCompatibleBrandsProperty;
  83. if (!ftypAtom->FindProperty(
  84. "ftyp.compatibleBrands",
  85. (MP4Property**)&pCompatibleBrandsProperty)) return;
  86. MP4StringProperty* pBrandProperty = (MP4StringProperty*)
  87. pCompatibleBrandsProperty->GetProperty(0);
  88. ASSERT(pBrandProperty);
  89. for (i = 0 ; i < ((currentSupportedBrandsCount > supportedBrandsCount) ? supportedBrandsCount : currentSupportedBrandsCount) ; i++) {
  90. pBrandProperty->SetValue(supportedBrands[i], i);
  91. }
  92. if (i < supportedBrandsCount) {
  93. for ( ; i < supportedBrandsCount ; i++) {
  94. pBrandProperty->AddValue(supportedBrands[i]);
  95. }
  96. }
  97. if (currentSupportedBrandsCount != supportedBrandsCount) {
  98. rewriteNeeded = true;
  99. pBrandProperty->SetCount(supportedBrandsCount);
  100. pCompatibleBrandsCountProperty->SetReadOnly(false);
  101. pCompatibleBrandsCountProperty->SetValue(supportedBrandsCount);
  102. pCompatibleBrandsCountProperty->SetReadOnly(true);
  103. }
  104. }