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.

455 lines
17KB

  1. /*
  2. * RIFF codec tags
  3. * Copyright (c) 2000 Fabrice Bellard.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "avformat.h"
  20. #include "avcodec.h"
  21. #include "riff.h"
  22. /* Note: when encoding, the first matching tag is used, so order is
  23. important if multiple tags possible for a given codec. */
  24. const CodecTag codec_bmp_tags[] = {
  25. { CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
  26. { CODEC_ID_H264, MKTAG('h', '2', '6', '4') },
  27. { CODEC_ID_H264, MKTAG('X', '2', '6', '4') },
  28. { CODEC_ID_H264, MKTAG('x', '2', '6', '4') },
  29. { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') },
  30. { CODEC_ID_H264, MKTAG('V', 'S', 'S', 'H') },
  31. { CODEC_ID_H263, MKTAG('H', '2', '6', '3') },
  32. { CODEC_ID_H263P, MKTAG('H', '2', '6', '3') },
  33. { CODEC_ID_H263I, MKTAG('I', '2', '6', '3') }, /* intel h263 */
  34. { CODEC_ID_H261, MKTAG('H', '2', '6', '1') },
  35. /* added based on MPlayer */
  36. { CODEC_ID_H263P, MKTAG('U', '2', '6', '3') },
  37. { CODEC_ID_H263P, MKTAG('v', 'i', 'v', '1') },
  38. { CODEC_ID_MPEG4, MKTAG('F', 'M', 'P', '4')},
  39. { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X'), .invalid_asf = 1 },
  40. { CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0'), .invalid_asf = 1 },
  41. { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D'), .invalid_asf = 1 },
  42. { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
  43. { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
  44. { CODEC_ID_MPEG4, MKTAG(0x04, 0, 0, 0) }, /* some broken avi use this */
  45. /* added based on MPlayer */
  46. { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', '1') },
  47. { CODEC_ID_MPEG4, MKTAG('B', 'L', 'Z', '0') },
  48. { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
  49. { CODEC_ID_MPEG4, MKTAG('U', 'M', 'P', '4') },
  50. { CODEC_ID_MPEG4, MKTAG('W', 'V', '1', 'F') },
  51. { CODEC_ID_MPEG4, MKTAG('S', 'E', 'D', 'G') },
  52. { CODEC_ID_MPEG4, MKTAG('R', 'M', 'P', '4') },
  53. { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3'), .invalid_asf = 1 }, /* default signature when using MSMPEG4 */
  54. { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
  55. /* added based on MPlayer */
  56. { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') },
  57. { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '5') },
  58. { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '6') },
  59. { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '4') },
  60. { CODEC_ID_MSMPEG4V3, MKTAG('A', 'P', '4', '1') },
  61. { CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '1') },
  62. { CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '0') },
  63. { CODEC_ID_MSMPEG4V2, MKTAG('M', 'P', '4', '2') },
  64. /* added based on MPlayer */
  65. { CODEC_ID_MSMPEG4V2, MKTAG('D', 'I', 'V', '2') },
  66. { CODEC_ID_MSMPEG4V1, MKTAG('M', 'P', 'G', '4') },
  67. { CODEC_ID_WMV1, MKTAG('W', 'M', 'V', '1') },
  68. /* added based on MPlayer */
  69. { CODEC_ID_WMV2, MKTAG('W', 'M', 'V', '2') },
  70. { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'd') },
  71. { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', 'd') },
  72. { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'l') },
  73. { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '2', '5') },
  74. { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '1') },
  75. { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '2') },
  76. { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', 'g', '2') },
  77. { CODEC_ID_MPEG2VIDEO, MKTAG('M', 'P', 'E', 'G') },
  78. { CODEC_ID_MPEG1VIDEO, MKTAG('P', 'I', 'M', '1') },
  79. { CODEC_ID_MPEG1VIDEO, MKTAG('V', 'C', 'R', '2') },
  80. { CODEC_ID_MPEG1VIDEO, 0x10000001 },
  81. { CODEC_ID_MPEG2VIDEO, 0x10000002 },
  82. { CODEC_ID_MPEG2VIDEO, MKTAG('D', 'V', 'R', ' ') },
  83. { CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') },
  84. { CODEC_ID_MJPEG, MKTAG('L', 'J', 'P', 'G') },
  85. { CODEC_ID_LJPEG, MKTAG('L', 'J', 'P', 'G') },
  86. { CODEC_ID_MJPEG, MKTAG('J', 'P', 'G', 'L') }, /* Pegasus lossless JPEG */
  87. { CODEC_ID_MJPEG, MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - decoder */
  88. { CODEC_ID_JPEGLS, MKTAG('M', 'J', 'L', 'S') }, /* JPEG-LS custom FOURCC for avi - encoder */
  89. { CODEC_ID_HUFFYUV, MKTAG('H', 'F', 'Y', 'U') },
  90. { CODEC_ID_FFVHUFF, MKTAG('F', 'F', 'V', 'H') },
  91. { CODEC_ID_CYUV, MKTAG('C', 'Y', 'U', 'V') },
  92. { CODEC_ID_RAWVIDEO, MKTAG('I', '4', '2', '0') },
  93. { CODEC_ID_RAWVIDEO, MKTAG('Y', 'U', 'Y', '2') },
  94. { CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '2', '2') },
  95. { CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'V', 'Y') },
  96. { CODEC_ID_RAWVIDEO, MKTAG('I', 'Y', 'U', 'V') },
  97. { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '1') },
  98. { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '2') },
  99. { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') },
  100. { CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') },
  101. { CODEC_ID_ASV1, MKTAG('A', 'S', 'V', '1') },
  102. { CODEC_ID_ASV2, MKTAG('A', 'S', 'V', '2') },
  103. { CODEC_ID_VCR1, MKTAG('V', 'C', 'R', '1') },
  104. { CODEC_ID_FFV1, MKTAG('F', 'F', 'V', '1') },
  105. { CODEC_ID_XAN_WC4, MKTAG('X', 'x', 'a', 'n') },
  106. { CODEC_ID_MSRLE, MKTAG('m', 'r', 'l', 'e') },
  107. { CODEC_ID_MSRLE, MKTAG(0x1, 0x0, 0x0, 0x0) },
  108. { CODEC_ID_MSVIDEO1, MKTAG('M', 'S', 'V', 'C') },
  109. { CODEC_ID_MSVIDEO1, MKTAG('m', 's', 'v', 'c') },
  110. { CODEC_ID_MSVIDEO1, MKTAG('C', 'R', 'A', 'M') },
  111. { CODEC_ID_MSVIDEO1, MKTAG('c', 'r', 'a', 'm') },
  112. { CODEC_ID_MSVIDEO1, MKTAG('W', 'H', 'A', 'M') },
  113. { CODEC_ID_MSVIDEO1, MKTAG('w', 'h', 'a', 'm') },
  114. { CODEC_ID_CINEPAK, MKTAG('c', 'v', 'i', 'd') },
  115. { CODEC_ID_TRUEMOTION1, MKTAG('D', 'U', 'C', 'K') },
  116. { CODEC_ID_MSZH, MKTAG('M', 'S', 'Z', 'H') },
  117. { CODEC_ID_ZLIB, MKTAG('Z', 'L', 'I', 'B') },
  118. { CODEC_ID_SNOW, MKTAG('S', 'N', 'O', 'W') },
  119. { CODEC_ID_4XM, MKTAG('4', 'X', 'M', 'V') },
  120. { CODEC_ID_FLV1, MKTAG('F', 'L', 'V', '1') },
  121. { CODEC_ID_FLASHSV, MKTAG('F', 'S', 'V', '1') },
  122. { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') },
  123. { CODEC_ID_TSCC, MKTAG('t', 's', 'c', 'c') },
  124. { CODEC_ID_ULTI, MKTAG('U', 'L', 'T', 'I') },
  125. { CODEC_ID_VIXL, MKTAG('V', 'I', 'X', 'L') },
  126. { CODEC_ID_QPEG, MKTAG('Q', 'P', 'E', 'G') },
  127. { CODEC_ID_QPEG, MKTAG('Q', '1', '.', '0') },
  128. { CODEC_ID_QPEG, MKTAG('Q', '1', '.', '1') },
  129. { CODEC_ID_WMV3, MKTAG('W', 'M', 'V', '3') },
  130. { CODEC_ID_LOCO, MKTAG('L', 'O', 'C', 'O') },
  131. { CODEC_ID_WNV1, MKTAG('W', 'N', 'V', '1') },
  132. { CODEC_ID_AASC, MKTAG('A', 'A', 'S', 'C') },
  133. { CODEC_ID_INDEO2, MKTAG('R', 'T', '2', '1') },
  134. { CODEC_ID_FRAPS, MKTAG('F', 'P', 'S', '1') },
  135. { CODEC_ID_THEORA, MKTAG('t', 'h', 'e', 'o') },
  136. { CODEC_ID_TRUEMOTION2, MKTAG('T', 'M', '2', '0') },
  137. { CODEC_ID_CSCD, MKTAG('C', 'S', 'C', 'D') },
  138. { CODEC_ID_ZMBV, MKTAG('Z', 'M', 'B', 'V') },
  139. { CODEC_ID_KMVC, MKTAG('K', 'M', 'V', 'C') },
  140. { CODEC_ID_CAVS, MKTAG('C', 'A', 'V', 'S') },
  141. { CODEC_ID_RAWVIDEO, 0 },
  142. { CODEC_ID_NONE, 0 },
  143. };
  144. const CodecTag codec_wav_tags[] = {
  145. { CODEC_ID_MP2, 0x50 },
  146. { CODEC_ID_MP3, 0x55 },
  147. { CODEC_ID_AC3, 0x2000 },
  148. { CODEC_ID_DTS, 0x2001 },
  149. { CODEC_ID_PCM_S16LE, 0x01 },
  150. { CODEC_ID_PCM_U8, 0x01 }, /* must come after s16le in this list */
  151. { CODEC_ID_PCM_S24LE, 0x01 },
  152. { CODEC_ID_PCM_S32LE, 0x01 },
  153. { CODEC_ID_PCM_ALAW, 0x06 },
  154. { CODEC_ID_PCM_MULAW, 0x07 },
  155. { CODEC_ID_ADPCM_MS, 0x02 },
  156. { CODEC_ID_ADPCM_IMA_WAV, 0x11 },
  157. { CODEC_ID_ADPCM_YAMAHA, 0x20 },
  158. { CODEC_ID_ADPCM_G726, 0x45 },
  159. { CODEC_ID_ADPCM_IMA_DK4, 0x61 }, /* rogue format number */
  160. { CODEC_ID_ADPCM_IMA_DK3, 0x62 }, /* rogue format number */
  161. { CODEC_ID_WMAV1, 0x160 },
  162. { CODEC_ID_WMAV2, 0x161 },
  163. { CODEC_ID_AAC, 0x706d },
  164. { CODEC_ID_MPEG4AAC, 0xff },
  165. { CODEC_ID_VORBIS, ('V'<<8)+'o' }, //HACK/FIXME, does vorbis in WAV/AVI have an (in)official id?
  166. { CODEC_ID_SONIC, 0x2048 },
  167. { CODEC_ID_SONIC_LS, 0x2048 },
  168. { CODEC_ID_ADPCM_CT, 0x200 },
  169. { CODEC_ID_ADPCM_SWF, ('S'<<8)+'F' },
  170. { CODEC_ID_TRUESPEECH, 0x22 },
  171. // for NuppelVideo (nuv.c)
  172. { CODEC_ID_PCM_S16LE, MKTAG('R', 'A', 'W', 'A') },
  173. { CODEC_ID_MP3, MKTAG('L', 'A', 'M', 'E') },
  174. { 0, 0 },
  175. };
  176. unsigned int codec_get_tag(const CodecTag *tags, int id)
  177. {
  178. while (tags->id != CODEC_ID_NONE) {
  179. if (tags->id == id)
  180. return tags->tag;
  181. tags++;
  182. }
  183. return 0;
  184. }
  185. unsigned int codec_get_asf_tag(const CodecTag *tags, unsigned int id)
  186. {
  187. while (tags->id != CODEC_ID_NONE) {
  188. if (!tags->invalid_asf && tags->id == id)
  189. return tags->tag;
  190. tags++;
  191. }
  192. return 0;
  193. }
  194. enum CodecID codec_get_id(const CodecTag *tags, unsigned int tag)
  195. {
  196. while (tags->id != CODEC_ID_NONE) {
  197. if( toupper((tag >> 0)&0xFF) == toupper((tags->tag >> 0)&0xFF)
  198. && toupper((tag >> 8)&0xFF) == toupper((tags->tag >> 8)&0xFF)
  199. && toupper((tag >>16)&0xFF) == toupper((tags->tag >>16)&0xFF)
  200. && toupper((tag >>24)&0xFF) == toupper((tags->tag >>24)&0xFF))
  201. return tags->id;
  202. tags++;
  203. }
  204. return CODEC_ID_NONE;
  205. }
  206. unsigned int codec_get_bmp_tag(int id)
  207. {
  208. return codec_get_tag(codec_bmp_tags, id);
  209. }
  210. unsigned int codec_get_wav_tag(int id)
  211. {
  212. return codec_get_tag(codec_wav_tags, id);
  213. }
  214. enum CodecID codec_get_bmp_id(unsigned int tag)
  215. {
  216. return codec_get_id(codec_bmp_tags, tag);
  217. }
  218. enum CodecID codec_get_wav_id(unsigned int tag)
  219. {
  220. return codec_get_id(codec_wav_tags, tag);
  221. }
  222. #ifdef CONFIG_MUXERS
  223. offset_t start_tag(ByteIOContext *pb, const char *tag)
  224. {
  225. put_tag(pb, tag);
  226. put_le32(pb, 0);
  227. return url_ftell(pb);
  228. }
  229. void end_tag(ByteIOContext *pb, offset_t start)
  230. {
  231. offset_t pos;
  232. pos = url_ftell(pb);
  233. url_fseek(pb, start - 4, SEEK_SET);
  234. put_le32(pb, (uint32_t)(pos - start));
  235. url_fseek(pb, pos, SEEK_SET);
  236. }
  237. /* WAVEFORMATEX header */
  238. /* returns the size or -1 on error */
  239. int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
  240. {
  241. int bps, blkalign, bytespersec;
  242. int hdrsize = 18;
  243. if(!enc->codec_tag || enc->codec_tag > 0xffff)
  244. enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id);
  245. if(!enc->codec_tag)
  246. return -1;
  247. put_le16(pb, enc->codec_tag);
  248. put_le16(pb, enc->channels);
  249. put_le32(pb, enc->sample_rate);
  250. if (enc->codec_id == CODEC_ID_PCM_U8 ||
  251. enc->codec_id == CODEC_ID_PCM_ALAW ||
  252. enc->codec_id == CODEC_ID_PCM_MULAW) {
  253. bps = 8;
  254. } else if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {
  255. bps = 0;
  256. } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV || enc->codec_id == CODEC_ID_ADPCM_MS || enc->codec_id == CODEC_ID_ADPCM_G726 || enc->codec_id == CODEC_ID_ADPCM_YAMAHA) { //
  257. bps = 4;
  258. } else if (enc->codec_id == CODEC_ID_PCM_S24LE) {
  259. bps = 24;
  260. } else if (enc->codec_id == CODEC_ID_PCM_S32LE) {
  261. bps = 32;
  262. } else {
  263. bps = 16;
  264. }
  265. if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {
  266. blkalign = enc->frame_size; //this is wrong, but seems many demuxers dont work if this is set correctly
  267. //blkalign = 144 * enc->bit_rate/enc->sample_rate;
  268. } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { //
  269. blkalign = 1;
  270. } else if (enc->block_align != 0) { /* specified by the codec */
  271. blkalign = enc->block_align;
  272. } else
  273. blkalign = enc->channels*bps >> 3;
  274. if (enc->codec_id == CODEC_ID_PCM_U8 ||
  275. enc->codec_id == CODEC_ID_PCM_S24LE ||
  276. enc->codec_id == CODEC_ID_PCM_S32LE ||
  277. enc->codec_id == CODEC_ID_PCM_S16LE) {
  278. bytespersec = enc->sample_rate * blkalign;
  279. } else {
  280. bytespersec = enc->bit_rate / 8;
  281. }
  282. put_le32(pb, bytespersec); /* bytes per second */
  283. put_le16(pb, blkalign); /* block align */
  284. put_le16(pb, bps); /* bits per sample */
  285. if (enc->codec_id == CODEC_ID_MP3) {
  286. put_le16(pb, 12); /* wav_extra_size */
  287. hdrsize += 12;
  288. put_le16(pb, 1); /* wID */
  289. put_le32(pb, 2); /* fdwFlags */
  290. put_le16(pb, 1152); /* nBlockSize */
  291. put_le16(pb, 1); /* nFramesPerBlock */
  292. put_le16(pb, 1393); /* nCodecDelay */
  293. } else if (enc->codec_id == CODEC_ID_MP2) {
  294. put_le16(pb, 22); /* wav_extra_size */
  295. hdrsize += 22;
  296. put_le16(pb, 2); /* fwHeadLayer */
  297. put_le32(pb, enc->bit_rate); /* dwHeadBitrate */
  298. put_le16(pb, enc->channels == 2 ? 1 : 8); /* fwHeadMode */
  299. put_le16(pb, 0); /* fwHeadModeExt */
  300. put_le16(pb, 1); /* wHeadEmphasis */
  301. put_le16(pb, 16); /* fwHeadFlags */
  302. put_le32(pb, 0); /* dwPTSLow */
  303. put_le32(pb, 0); /* dwPTSHigh */
  304. } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {
  305. put_le16(pb, 2); /* wav_extra_size */
  306. hdrsize += 2;
  307. put_le16(pb, ((enc->block_align - 4 * enc->channels) / (4 * enc->channels)) * 8 + 1); /* wSamplesPerBlock */
  308. } else if(enc->extradata_size){
  309. put_le16(pb, enc->extradata_size);
  310. put_buffer(pb, enc->extradata, enc->extradata_size);
  311. hdrsize += enc->extradata_size;
  312. if(hdrsize&1){
  313. hdrsize++;
  314. put_byte(pb, 0);
  315. }
  316. } else {
  317. hdrsize -= 2;
  318. }
  319. return hdrsize;
  320. }
  321. /* BITMAPINFOHEADER header */
  322. void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags, int for_asf)
  323. {
  324. put_le32(pb, 40 + enc->extradata_size); /* size */
  325. put_le32(pb, enc->width);
  326. put_le32(pb, enc->height);
  327. put_le16(pb, 1); /* planes */
  328. put_le16(pb, enc->bits_per_sample ? enc->bits_per_sample : 24); /* depth */
  329. /* compression type */
  330. put_le32(pb, for_asf ? (enc->codec_tag ? enc->codec_tag : codec_get_asf_tag(tags, enc->codec_id)) : enc->codec_tag); //
  331. put_le32(pb, enc->width * enc->height * 3);
  332. put_le32(pb, 0);
  333. put_le32(pb, 0);
  334. put_le32(pb, 0);
  335. put_le32(pb, 0);
  336. put_buffer(pb, enc->extradata, enc->extradata_size);
  337. if (enc->extradata_size & 1)
  338. put_byte(pb, 0);
  339. }
  340. #endif //CONFIG_MUXERS
  341. #ifdef CONFIG_DEMUXERS
  342. /* We could be given one of the three possible structures here:
  343. * WAVEFORMAT, PCMWAVEFORMAT or WAVEFORMATEX. Each structure
  344. * is an expansion of the previous one with the fields added
  345. * at the bottom. PCMWAVEFORMAT adds 'WORD wBitsPerSample' and
  346. * WAVEFORMATEX adds 'WORD cbSize' and basically makes itself
  347. * an openended structure.
  348. */
  349. void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size)
  350. {
  351. int id;
  352. id = get_le16(pb);
  353. codec->codec_type = CODEC_TYPE_AUDIO;
  354. codec->codec_tag = id;
  355. codec->channels = get_le16(pb);
  356. codec->sample_rate = get_le32(pb);
  357. codec->bit_rate = get_le32(pb) * 8;
  358. codec->block_align = get_le16(pb);
  359. if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */
  360. codec->bits_per_sample = 8;
  361. }else
  362. codec->bits_per_sample = get_le16(pb);
  363. codec->codec_id = wav_codec_get_id(id, codec->bits_per_sample);
  364. if (size > 16) { /* We're obviously dealing with WAVEFORMATEX */
  365. codec->extradata_size = get_le16(pb);
  366. if (codec->extradata_size > 0) {
  367. if (codec->extradata_size > size - 18)
  368. codec->extradata_size = size - 18;
  369. codec->extradata = av_mallocz(codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
  370. get_buffer(pb, codec->extradata, codec->extradata_size);
  371. } else
  372. codec->extradata_size = 0;
  373. /* It is possible for the chunk to contain garbage at the end */
  374. if (size - codec->extradata_size - 18 > 0)
  375. url_fskip(pb, size - codec->extradata_size - 18);
  376. }
  377. }
  378. int wav_codec_get_id(unsigned int tag, int bps)
  379. {
  380. int id;
  381. id = codec_get_id(codec_wav_tags, tag);
  382. if (id <= 0)
  383. return id;
  384. /* handle specific u8 codec */
  385. if (id == CODEC_ID_PCM_S16LE && bps == 8)
  386. id = CODEC_ID_PCM_U8;
  387. if (id == CODEC_ID_PCM_S16LE && bps == 24)
  388. id = CODEC_ID_PCM_S24LE;
  389. if (id == CODEC_ID_PCM_S16LE && bps == 32)
  390. id = CODEC_ID_PCM_S32LE;
  391. return id;
  392. }
  393. #endif // CONFIG_DEMUXERS
  394. void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale)
  395. {
  396. int gcd;
  397. *au_ssize= stream->block_align;
  398. if(stream->frame_size && stream->sample_rate){
  399. *au_scale=stream->frame_size;
  400. *au_rate= stream->sample_rate;
  401. }else if(stream->codec_type == CODEC_TYPE_VIDEO){
  402. *au_scale= stream->time_base.num;
  403. *au_rate = stream->time_base.den;
  404. }else{
  405. *au_scale= stream->block_align ? stream->block_align*8 : 8;
  406. *au_rate = stream->bit_rate;
  407. }
  408. gcd= ff_gcd(*au_scale, *au_rate);
  409. *au_scale /= gcd;
  410. *au_rate /= gcd;
  411. }