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.

453 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_RAWVIDEO, 0 },
  141. { CODEC_ID_NONE, 0 },
  142. };
  143. const CodecTag codec_wav_tags[] = {
  144. { CODEC_ID_MP2, 0x50 },
  145. { CODEC_ID_MP3, 0x55 },
  146. { CODEC_ID_AC3, 0x2000 },
  147. { CODEC_ID_DTS, 0x2001 },
  148. { CODEC_ID_PCM_S16LE, 0x01 },
  149. { CODEC_ID_PCM_U8, 0x01 }, /* must come after s16le in this list */
  150. { CODEC_ID_PCM_S24LE, 0x01 },
  151. { CODEC_ID_PCM_S32LE, 0x01 },
  152. { CODEC_ID_PCM_ALAW, 0x06 },
  153. { CODEC_ID_PCM_MULAW, 0x07 },
  154. { CODEC_ID_ADPCM_MS, 0x02 },
  155. { CODEC_ID_ADPCM_IMA_WAV, 0x11 },
  156. { CODEC_ID_ADPCM_YAMAHA, 0x20 },
  157. { CODEC_ID_ADPCM_G726, 0x45 },
  158. { CODEC_ID_ADPCM_IMA_DK4, 0x61 }, /* rogue format number */
  159. { CODEC_ID_ADPCM_IMA_DK3, 0x62 }, /* rogue format number */
  160. { CODEC_ID_WMAV1, 0x160 },
  161. { CODEC_ID_WMAV2, 0x161 },
  162. { CODEC_ID_AAC, 0x706d },
  163. { CODEC_ID_VORBIS, ('V'<<8)+'o' }, //HACK/FIXME, does vorbis in WAV/AVI have an (in)official id?
  164. { CODEC_ID_SONIC, 0x2048 },
  165. { CODEC_ID_SONIC_LS, 0x2048 },
  166. { CODEC_ID_ADPCM_CT, 0x200 },
  167. { CODEC_ID_ADPCM_SWF, ('S'<<8)+'F' },
  168. { CODEC_ID_TRUESPEECH, 0x22 },
  169. // for NuppelVideo (nuv.c)
  170. { CODEC_ID_PCM_S16LE, MKTAG('R', 'A', 'W', 'A') },
  171. { CODEC_ID_MP3, MKTAG('L', 'A', 'M', 'E') },
  172. { 0, 0 },
  173. };
  174. unsigned int codec_get_tag(const CodecTag *tags, int id)
  175. {
  176. while (tags->id != CODEC_ID_NONE) {
  177. if (tags->id == id)
  178. return tags->tag;
  179. tags++;
  180. }
  181. return 0;
  182. }
  183. unsigned int codec_get_asf_tag(const CodecTag *tags, unsigned int id)
  184. {
  185. while (tags->id != CODEC_ID_NONE) {
  186. if (!tags->invalid_asf && tags->id == id)
  187. return tags->tag;
  188. tags++;
  189. }
  190. return 0;
  191. }
  192. enum CodecID codec_get_id(const CodecTag *tags, unsigned int tag)
  193. {
  194. while (tags->id != CODEC_ID_NONE) {
  195. if( toupper((tag >> 0)&0xFF) == toupper((tags->tag >> 0)&0xFF)
  196. && toupper((tag >> 8)&0xFF) == toupper((tags->tag >> 8)&0xFF)
  197. && toupper((tag >>16)&0xFF) == toupper((tags->tag >>16)&0xFF)
  198. && toupper((tag >>24)&0xFF) == toupper((tags->tag >>24)&0xFF))
  199. return tags->id;
  200. tags++;
  201. }
  202. return CODEC_ID_NONE;
  203. }
  204. unsigned int codec_get_bmp_tag(int id)
  205. {
  206. return codec_get_tag(codec_bmp_tags, id);
  207. }
  208. unsigned int codec_get_wav_tag(int id)
  209. {
  210. return codec_get_tag(codec_wav_tags, id);
  211. }
  212. enum CodecID codec_get_bmp_id(unsigned int tag)
  213. {
  214. return codec_get_id(codec_bmp_tags, tag);
  215. }
  216. enum CodecID codec_get_wav_id(unsigned int tag)
  217. {
  218. return codec_get_id(codec_wav_tags, tag);
  219. }
  220. #ifdef CONFIG_MUXERS
  221. offset_t start_tag(ByteIOContext *pb, const char *tag)
  222. {
  223. put_tag(pb, tag);
  224. put_le32(pb, 0);
  225. return url_ftell(pb);
  226. }
  227. void end_tag(ByteIOContext *pb, offset_t start)
  228. {
  229. offset_t pos;
  230. pos = url_ftell(pb);
  231. url_fseek(pb, start - 4, SEEK_SET);
  232. put_le32(pb, (uint32_t)(pos - start));
  233. url_fseek(pb, pos, SEEK_SET);
  234. }
  235. /* WAVEFORMATEX header */
  236. /* returns the size or -1 on error */
  237. int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
  238. {
  239. int bps, blkalign, bytespersec;
  240. int hdrsize = 18;
  241. if(!enc->codec_tag || enc->codec_tag > 0xffff)
  242. enc->codec_tag = codec_get_tag(codec_wav_tags, enc->codec_id);
  243. if(!enc->codec_tag)
  244. return -1;
  245. put_le16(pb, enc->codec_tag);
  246. put_le16(pb, enc->channels);
  247. put_le32(pb, enc->sample_rate);
  248. if (enc->codec_id == CODEC_ID_PCM_U8 ||
  249. enc->codec_id == CODEC_ID_PCM_ALAW ||
  250. enc->codec_id == CODEC_ID_PCM_MULAW) {
  251. bps = 8;
  252. } else if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {
  253. bps = 0;
  254. } 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) { //
  255. bps = 4;
  256. } else if (enc->codec_id == CODEC_ID_PCM_S24LE) {
  257. bps = 24;
  258. } else if (enc->codec_id == CODEC_ID_PCM_S32LE) {
  259. bps = 32;
  260. } else {
  261. bps = 16;
  262. }
  263. if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3) {
  264. blkalign = enc->frame_size; //this is wrong, but seems many demuxers dont work if this is set correctly
  265. //blkalign = 144 * enc->bit_rate/enc->sample_rate;
  266. } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { //
  267. blkalign = 1;
  268. } else if (enc->block_align != 0) { /* specified by the codec */
  269. blkalign = enc->block_align;
  270. } else
  271. blkalign = enc->channels*bps >> 3;
  272. if (enc->codec_id == CODEC_ID_PCM_U8 ||
  273. enc->codec_id == CODEC_ID_PCM_S24LE ||
  274. enc->codec_id == CODEC_ID_PCM_S32LE ||
  275. enc->codec_id == CODEC_ID_PCM_S16LE) {
  276. bytespersec = enc->sample_rate * blkalign;
  277. } else {
  278. bytespersec = enc->bit_rate / 8;
  279. }
  280. put_le32(pb, bytespersec); /* bytes per second */
  281. put_le16(pb, blkalign); /* block align */
  282. put_le16(pb, bps); /* bits per sample */
  283. if (enc->codec_id == CODEC_ID_MP3) {
  284. put_le16(pb, 12); /* wav_extra_size */
  285. hdrsize += 12;
  286. put_le16(pb, 1); /* wID */
  287. put_le32(pb, 2); /* fdwFlags */
  288. put_le16(pb, 1152); /* nBlockSize */
  289. put_le16(pb, 1); /* nFramesPerBlock */
  290. put_le16(pb, 1393); /* nCodecDelay */
  291. } else if (enc->codec_id == CODEC_ID_MP2) {
  292. put_le16(pb, 22); /* wav_extra_size */
  293. hdrsize += 22;
  294. put_le16(pb, 2); /* fwHeadLayer */
  295. put_le32(pb, enc->bit_rate); /* dwHeadBitrate */
  296. put_le16(pb, enc->channels == 2 ? 1 : 8); /* fwHeadMode */
  297. put_le16(pb, 0); /* fwHeadModeExt */
  298. put_le16(pb, 1); /* wHeadEmphasis */
  299. put_le16(pb, 16); /* fwHeadFlags */
  300. put_le32(pb, 0); /* dwPTSLow */
  301. put_le32(pb, 0); /* dwPTSHigh */
  302. } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {
  303. put_le16(pb, 2); /* wav_extra_size */
  304. hdrsize += 2;
  305. put_le16(pb, ((enc->block_align - 4 * enc->channels) / (4 * enc->channels)) * 8 + 1); /* wSamplesPerBlock */
  306. } else if(enc->extradata_size){
  307. put_le16(pb, enc->extradata_size);
  308. put_buffer(pb, enc->extradata, enc->extradata_size);
  309. hdrsize += enc->extradata_size;
  310. if(hdrsize&1){
  311. hdrsize++;
  312. put_byte(pb, 0);
  313. }
  314. } else {
  315. hdrsize -= 2;
  316. }
  317. return hdrsize;
  318. }
  319. /* BITMAPINFOHEADER header */
  320. void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const CodecTag *tags, int for_asf)
  321. {
  322. put_le32(pb, 40 + enc->extradata_size); /* size */
  323. put_le32(pb, enc->width);
  324. put_le32(pb, enc->height);
  325. put_le16(pb, 1); /* planes */
  326. put_le16(pb, enc->bits_per_sample ? enc->bits_per_sample : 24); /* depth */
  327. /* compression type */
  328. put_le32(pb, for_asf ? (enc->codec_tag ? enc->codec_tag : codec_get_asf_tag(tags, enc->codec_id)) : enc->codec_tag); //
  329. put_le32(pb, enc->width * enc->height * 3);
  330. put_le32(pb, 0);
  331. put_le32(pb, 0);
  332. put_le32(pb, 0);
  333. put_le32(pb, 0);
  334. put_buffer(pb, enc->extradata, enc->extradata_size);
  335. if (enc->extradata_size & 1)
  336. put_byte(pb, 0);
  337. }
  338. #endif //CONFIG_MUXERS
  339. #ifdef CONFIG_DEMUXERS
  340. /* We could be given one of the three possible structures here:
  341. * WAVEFORMAT, PCMWAVEFORMAT or WAVEFORMATEX. Each structure
  342. * is an expansion of the previous one with the fields added
  343. * at the bottom. PCMWAVEFORMAT adds 'WORD wBitsPerSample' and
  344. * WAVEFORMATEX adds 'WORD cbSize' and basically makes itself
  345. * an openended structure.
  346. */
  347. void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size)
  348. {
  349. int id;
  350. id = get_le16(pb);
  351. codec->codec_type = CODEC_TYPE_AUDIO;
  352. codec->codec_tag = id;
  353. codec->channels = get_le16(pb);
  354. codec->sample_rate = get_le32(pb);
  355. codec->bit_rate = get_le32(pb) * 8;
  356. codec->block_align = get_le16(pb);
  357. if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */
  358. codec->bits_per_sample = 8;
  359. }else
  360. codec->bits_per_sample = get_le16(pb);
  361. codec->codec_id = wav_codec_get_id(id, codec->bits_per_sample);
  362. if (size > 16) { /* We're obviously dealing with WAVEFORMATEX */
  363. codec->extradata_size = get_le16(pb);
  364. if (codec->extradata_size > 0) {
  365. if (codec->extradata_size > size - 18)
  366. codec->extradata_size = size - 18;
  367. codec->extradata = av_mallocz(codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
  368. get_buffer(pb, codec->extradata, codec->extradata_size);
  369. } else
  370. codec->extradata_size = 0;
  371. /* It is possible for the chunk to contain garbage at the end */
  372. if (size - codec->extradata_size - 18 > 0)
  373. url_fskip(pb, size - codec->extradata_size - 18);
  374. }
  375. }
  376. int wav_codec_get_id(unsigned int tag, int bps)
  377. {
  378. int id;
  379. id = codec_get_id(codec_wav_tags, tag);
  380. if (id <= 0)
  381. return id;
  382. /* handle specific u8 codec */
  383. if (id == CODEC_ID_PCM_S16LE && bps == 8)
  384. id = CODEC_ID_PCM_U8;
  385. if (id == CODEC_ID_PCM_S16LE && bps == 24)
  386. id = CODEC_ID_PCM_S24LE;
  387. if (id == CODEC_ID_PCM_S16LE && bps == 32)
  388. id = CODEC_ID_PCM_S32LE;
  389. return id;
  390. }
  391. #endif // CONFIG_DEMUXERS
  392. void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale)
  393. {
  394. int gcd;
  395. *au_ssize= stream->block_align;
  396. if(stream->frame_size && stream->sample_rate){
  397. *au_scale=stream->frame_size;
  398. *au_rate= stream->sample_rate;
  399. }else if(stream->codec_type == CODEC_TYPE_VIDEO){
  400. *au_scale= stream->time_base.num;
  401. *au_rate = stream->time_base.den;
  402. }else{
  403. *au_scale= stream->block_align ? stream->block_align*8 : 8;
  404. *au_rate = stream->bit_rate;
  405. }
  406. gcd= ff_gcd(*au_scale, *au_rate);
  407. *au_scale /= gcd;
  408. *au_rate /= gcd;
  409. }