You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.7KB

  1. /*
  2. * ISO Media common code
  3. * Copyright (c) 2001 Fabrice Bellard.
  4. * Copyright (c) 2002 Francois Revol <revol@free.fr>
  5. * Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "avformat.h"
  22. #include "riff.h"
  23. #include "isom.h"
  24. /* http://gpac.sourceforge.net/tutorial/mediatypes.htm */
  25. const CodecTag ff_mov_obj_type[] = {
  26. { CODEC_ID_MPEG4 , 32 },
  27. { CODEC_ID_H264 , 33 },
  28. { CODEC_ID_AAC , 64 },
  29. { CODEC_ID_MPEG2VIDEO, 96 }, /* MPEG2 Simple */
  30. { CODEC_ID_MPEG2VIDEO, 97 }, /* MPEG2 Main */
  31. { CODEC_ID_MPEG2VIDEO, 98 }, /* MPEG2 SNR */
  32. { CODEC_ID_MPEG2VIDEO, 99 }, /* MPEG2 Spatial */
  33. { CODEC_ID_MPEG2VIDEO, 100 }, /* MPEG2 High */
  34. { CODEC_ID_MPEG2VIDEO, 101 }, /* MPEG2 422 */
  35. { CODEC_ID_AAC , 102 }, /* MPEG2 AAC Main */
  36. { CODEC_ID_AAC , 103 }, /* MPEG2 AAC Low */
  37. { CODEC_ID_AAC , 104 }, /* MPEG2 AAC SSR */
  38. { CODEC_ID_MP3 , 105 },
  39. { CODEC_ID_MPEG1VIDEO, 106 },
  40. { CODEC_ID_MP2 , 107 },
  41. { CODEC_ID_MJPEG , 108 },
  42. { CODEC_ID_PCM_S16LE , 224 },
  43. { CODEC_ID_VORBIS , 221 },
  44. { CODEC_ID_AC3 , 226 },
  45. { CODEC_ID_PCM_ALAW , 227 },
  46. { CODEC_ID_PCM_MULAW , 228 },
  47. { CODEC_ID_PCM_S16BE , 230 },
  48. { CODEC_ID_H263 , 242 },
  49. { CODEC_ID_H261 , 243 },
  50. { 0, 0 },
  51. };
  52. /* map numeric codes from mdhd atom to ISO 639 */
  53. /* cf. QTFileFormat.pdf p253, qtff.pdf p205 */
  54. /* http://developer.apple.com/documentation/mac/Text/Text-368.html */
  55. /* deprecated by putting the code as 3*5bit ascii */
  56. static const char *mov_mdhd_language_map[] = {
  57. /* 0-9 */
  58. "eng", "fra", "ger", "ita", "dut", "sve", "spa", "dan", "por", "nor",
  59. "heb", "jpn", "ara", "fin", "gre", "ice", "mlt", "tur", "hr "/*scr*/, "chi"/*ace?*/,
  60. "urd", "hin", "tha", "kor", "lit", "pol", "hun", "est", "lav", NULL,
  61. "fo ", NULL, "rus", "chi", NULL, "iri", "alb", "ron", "ces", "slk",
  62. "slv", "yid", "sr ", "mac", "bul", "ukr", "bel", "uzb", "kaz", "aze",
  63. /*?*/
  64. "aze", "arm", "geo", "mol", "kir", "tgk", "tuk", "mon", NULL, "pus",
  65. "kur", "kas", "snd", "tib", "nep", "san", "mar", "ben", "asm", "guj",
  66. "pa ", "ori", "mal", "kan", "tam", "tel", NULL, "bur", "khm", "lao",
  67. /* roman? arabic? */
  68. "vie", "ind", "tgl", "may", "may", "amh", "tir", "orm", "som", "swa",
  69. /*==rundi?*/
  70. NULL, "run", NULL, "mlg", "epo", NULL, NULL, NULL, NULL, NULL,
  71. /* 100 */
  72. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  73. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  74. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "wel", "baq",
  75. "cat", "lat", "que", "grn", "aym", "tat", "uig", "dzo", "jav"
  76. };
  77. int ff_mov_iso639_to_lang(const char *lang, int mp4)
  78. {
  79. int i, code = 0;
  80. /* old way, only for QT? */
  81. for (i = 0; !mp4 && (i < (sizeof(mov_mdhd_language_map)/sizeof(char *))); i++) {
  82. if (mov_mdhd_language_map[i] && !strcmp(lang, mov_mdhd_language_map[i]))
  83. return i;
  84. }
  85. /* XXX:can we do that in mov too? */
  86. if (!mp4)
  87. return 0;
  88. /* handle undefined as such */
  89. if (lang[0] == '\0')
  90. lang = "und";
  91. /* 5bit ascii */
  92. for (i = 0; i < 3; i++) {
  93. unsigned char c = (unsigned char)lang[i];
  94. if (c < 0x60)
  95. return 0;
  96. if (c > 0x60 + 0x1f)
  97. return 0;
  98. code <<= 5;
  99. code |= (c - 0x60);
  100. }
  101. return code;
  102. }
  103. int ff_mov_lang_to_iso639(int code, char *to)
  104. {
  105. int i;
  106. /* is it the mangled iso code? */
  107. /* see http://www.geocities.com/xhelmboyx/quicktime/formats/mp4-layout.txt */
  108. if (code > 138) {
  109. for (i = 2; i >= 0; i--) {
  110. to[i] = 0x60 + (code & 0x1f);
  111. code >>= 5;
  112. }
  113. return 1;
  114. }
  115. /* old fashion apple lang code */
  116. if (code >= (sizeof(mov_mdhd_language_map)/sizeof(char *)))
  117. return 0;
  118. if (!mov_mdhd_language_map[code])
  119. return 0;
  120. strncpy(to, mov_mdhd_language_map[code], 4);
  121. return 1;
  122. }