00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "libavcodec/avcodec.h"
00023 #include "avformat.h"
00024 #include "riff.h"
00025
00026
00027
00028 const AVCodecTag codec_bmp_tags[] = {
00029 { CODEC_ID_H264, MKTAG('H', '2', '6', '4') },
00030 { CODEC_ID_H264, MKTAG('h', '2', '6', '4') },
00031 { CODEC_ID_H264, MKTAG('X', '2', '6', '4') },
00032 { CODEC_ID_H264, MKTAG('x', '2', '6', '4') },
00033 { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') },
00034 { CODEC_ID_H264, MKTAG('V', 'S', 'S', 'H') },
00035 { CODEC_ID_H263, MKTAG('H', '2', '6', '3') },
00036 { CODEC_ID_H263, MKTAG('X', '2', '6', '3') },
00037 { CODEC_ID_H263, MKTAG('T', '2', '6', '3') },
00038 { CODEC_ID_H263, MKTAG('L', '2', '6', '3') },
00039 { CODEC_ID_H263, MKTAG('V', 'X', '1', 'K') },
00040 { CODEC_ID_H263P, MKTAG('H', '2', '6', '3') },
00041 { CODEC_ID_H263I, MKTAG('I', '2', '6', '3') },
00042 { CODEC_ID_H261, MKTAG('H', '2', '6', '1') },
00043 { CODEC_ID_H263P, MKTAG('U', '2', '6', '3') },
00044 { CODEC_ID_H263P, MKTAG('v', 'i', 'v', '1') },
00045 { CODEC_ID_MPEG4, MKTAG('F', 'M', 'P', '4') },
00046 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') },
00047 { CODEC_ID_MPEG4, MKTAG('D', 'X', '5', '0') },
00048 { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') },
00049 { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') },
00050 { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') },
00051 { CODEC_ID_MPEG4, MKTAG( 4 , 0 , 0 , 0 ) },
00052 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', '1') },
00053 { CODEC_ID_MPEG4, MKTAG('B', 'L', 'Z', '0') },
00054 { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
00055 { CODEC_ID_MPEG4, MKTAG('U', 'M', 'P', '4') },
00056 { CODEC_ID_MPEG4, MKTAG('W', 'V', '1', 'F') },
00057 { CODEC_ID_MPEG4, MKTAG('S', 'E', 'D', 'G') },
00058 { CODEC_ID_MPEG4, MKTAG('R', 'M', 'P', '4') },
00059 { CODEC_ID_MPEG4, MKTAG('3', 'I', 'V', '2') },
00060 { CODEC_ID_MPEG4, MKTAG('F', 'F', 'D', 'S') },
00061 { CODEC_ID_MPEG4, MKTAG('F', 'V', 'F', 'W') },
00062 { CODEC_ID_MPEG4, MKTAG('D', 'C', 'O', 'D') },
00063 { CODEC_ID_MPEG4, MKTAG('M', 'V', 'X', 'M') },
00064 { CODEC_ID_MPEG4, MKTAG('P', 'M', '4', 'V') },
00065 { CODEC_ID_MPEG4, MKTAG('S', 'M', 'P', '4') },
00066 { CODEC_ID_MPEG4, MKTAG('D', 'X', 'G', 'M') },
00067 { CODEC_ID_MPEG4, MKTAG('V', 'I', 'D', 'M') },
00068 { CODEC_ID_MPEG4, MKTAG('M', '4', 'T', '3') },
00069 { CODEC_ID_MPEG4, MKTAG('G', 'E', 'O', 'X') },
00070 { CODEC_ID_MPEG4, MKTAG('H', 'D', 'X', '4') },
00071 { CODEC_ID_MPEG4, MKTAG('D', 'M', 'K', '2') },
00072 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'G', 'I') },
00073 { CODEC_ID_MPEG4, MKTAG('I', 'N', 'M', 'C') },
00074 { CODEC_ID_MPEG4, MKTAG('E', 'P', 'H', 'V') },
00075 { CODEC_ID_MPEG4, MKTAG('E', 'M', '4', 'A') },
00076 { CODEC_ID_MPEG4, MKTAG('M', '4', 'C', 'C') },
00077 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3') },
00078 { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') },
00079 { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') },
00080 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '5') },
00081 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '6') },
00082 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '4') },
00083 { CODEC_ID_MSMPEG4V3, MKTAG('D', 'V', 'X', '3') },
00084 { CODEC_ID_MSMPEG4V3, MKTAG('A', 'P', '4', '1') },
00085 { CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '1') },
00086 { CODEC_ID_MSMPEG4V3, MKTAG('C', 'O', 'L', '0') },
00087 { CODEC_ID_MSMPEG4V2, MKTAG('M', 'P', '4', '2') },
00088 { CODEC_ID_MSMPEG4V2, MKTAG('D', 'I', 'V', '2') },
00089 { CODEC_ID_MSMPEG4V1, MKTAG('M', 'P', 'G', '4') },
00090 { CODEC_ID_MSMPEG4V1, MKTAG('M', 'P', '4', '1') },
00091 { CODEC_ID_WMV1, MKTAG('W', 'M', 'V', '1') },
00092 { CODEC_ID_WMV2, MKTAG('W', 'M', 'V', '2') },
00093 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'd') },
00094 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', 'd') },
00095 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 's', 'l') },
00096 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '2', '5') },
00097 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '5', '0') },
00098 { CODEC_ID_DVVIDEO, MKTAG('c', 'd', 'v', 'c') },
00099 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') },
00100 { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '1') },
00101 { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'g', '2') },
00102 { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', 'g', '2') },
00103 { CODEC_ID_MPEG2VIDEO, MKTAG('M', 'P', 'E', 'G') },
00104 { CODEC_ID_MPEG1VIDEO, MKTAG('P', 'I', 'M', '1') },
00105 { CODEC_ID_MPEG2VIDEO, MKTAG('P', 'I', 'M', '2') },
00106 { CODEC_ID_MPEG1VIDEO, MKTAG('V', 'C', 'R', '2') },
00107 { CODEC_ID_MPEG1VIDEO, MKTAG( 1 , 0 , 0 , 16) },
00108 { CODEC_ID_MPEG2VIDEO, MKTAG( 2 , 0 , 0 , 16) },
00109 { CODEC_ID_MPEG2VIDEO, MKTAG('D', 'V', 'R', ' ') },
00110 { CODEC_ID_MPEG2VIDEO, MKTAG('M', 'M', 'E', 'S') },
00111 { CODEC_ID_MPEG2VIDEO, MKTAG('L', 'M', 'P', '2') },
00112 { CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') },
00113 { CODEC_ID_MJPEG, MKTAG('L', 'J', 'P', 'G') },
00114 { CODEC_ID_MJPEG, MKTAG('d', 'm', 'b', '1') },
00115 { CODEC_ID_LJPEG, MKTAG('L', 'J', 'P', 'G') },
00116 { CODEC_ID_MJPEG, MKTAG('J', 'P', 'G', 'L') },
00117 { CODEC_ID_JPEGLS, MKTAG('M', 'J', 'L', 'S') },
00118 { CODEC_ID_MJPEG, MKTAG('M', 'J', 'L', 'S') },
00119 { CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') },
00120 { CODEC_ID_MJPEG, MKTAG('I', 'J', 'P', 'G') },
00121 { CODEC_ID_MJPEG, MKTAG('A', 'V', 'R', 'n') },
00122 { CODEC_ID_MJPEG, MKTAG('A', 'C', 'D', 'V') },
00123 { CODEC_ID_MJPEG, MKTAG('Q', 'I', 'V', 'G') },
00124 { CODEC_ID_MJPEG, MKTAG('S', 'L', 'M', 'J') },
00125 { CODEC_ID_MJPEG, MKTAG('C', 'J', 'P', 'G') },
00126 { CODEC_ID_HUFFYUV, MKTAG('H', 'F', 'Y', 'U') },
00127 { CODEC_ID_FFVHUFF, MKTAG('F', 'F', 'V', 'H') },
00128 { CODEC_ID_CYUV, MKTAG('C', 'Y', 'U', 'V') },
00129 { CODEC_ID_RAWVIDEO, MKTAG( 0 , 0 , 0 , 0 ) },
00130 { CODEC_ID_RAWVIDEO, MKTAG('I', '4', '2', '0') },
00131 { CODEC_ID_RAWVIDEO, MKTAG('Y', 'U', 'Y', '2') },
00132 { CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '2', '2') },
00133 { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '2') },
00134 { CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'V', 'Y') },
00135 { CODEC_ID_RAWVIDEO, MKTAG('I', 'Y', 'U', 'V') },
00136 { CODEC_ID_RAWVIDEO, MKTAG('Y', '8', '0', '0') },
00137 { CODEC_ID_RAWVIDEO, MKTAG('H', 'D', 'Y', 'C') },
00138 { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '1') },
00139 { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '2') },
00140 { CODEC_ID_INDEO4, MKTAG('I', 'V', '4', '1') },
00141 { CODEC_ID_INDEO5, MKTAG('I', 'V', '5', '0') },
00142 { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') },
00143 { CODEC_ID_VP3, MKTAG('V', 'P', '3', '0') },
00144 { CODEC_ID_VP5, MKTAG('V', 'P', '5', '0') },
00145 { CODEC_ID_VP6, MKTAG('V', 'P', '6', '0') },
00146 { CODEC_ID_VP6, MKTAG('V', 'P', '6', '1') },
00147 { CODEC_ID_VP6, MKTAG('V', 'P', '6', '2') },
00148 { CODEC_ID_ASV1, MKTAG('A', 'S', 'V', '1') },
00149 { CODEC_ID_ASV2, MKTAG('A', 'S', 'V', '2') },
00150 { CODEC_ID_VCR1, MKTAG('V', 'C', 'R', '1') },
00151 { CODEC_ID_FFV1, MKTAG('F', 'F', 'V', '1') },
00152 { CODEC_ID_XAN_WC4, MKTAG('X', 'x', 'a', 'n') },
00153 { CODEC_ID_MIMIC, MKTAG('L', 'M', '2', '0') },
00154 { CODEC_ID_MSRLE, MKTAG('m', 'r', 'l', 'e') },
00155 { CODEC_ID_MSRLE, MKTAG( 1 , 0 , 0 , 0 ) },
00156 { CODEC_ID_MSRLE, MKTAG( 2 , 0 , 0 , 0 ) },
00157 { CODEC_ID_MSVIDEO1, MKTAG('M', 'S', 'V', 'C') },
00158 { CODEC_ID_MSVIDEO1, MKTAG('m', 's', 'v', 'c') },
00159 { CODEC_ID_MSVIDEO1, MKTAG('C', 'R', 'A', 'M') },
00160 { CODEC_ID_MSVIDEO1, MKTAG('c', 'r', 'a', 'm') },
00161 { CODEC_ID_MSVIDEO1, MKTAG('W', 'H', 'A', 'M') },
00162 { CODEC_ID_MSVIDEO1, MKTAG('w', 'h', 'a', 'm') },
00163 { CODEC_ID_CINEPAK, MKTAG('c', 'v', 'i', 'd') },
00164 { CODEC_ID_TRUEMOTION1, MKTAG('D', 'U', 'C', 'K') },
00165 { CODEC_ID_TRUEMOTION1, MKTAG('P', 'V', 'E', 'Z') },
00166 { CODEC_ID_MSZH, MKTAG('M', 'S', 'Z', 'H') },
00167 { CODEC_ID_ZLIB, MKTAG('Z', 'L', 'I', 'B') },
00168 { CODEC_ID_SNOW, MKTAG('S', 'N', 'O', 'W') },
00169 { CODEC_ID_4XM, MKTAG('4', 'X', 'M', 'V') },
00170 { CODEC_ID_FLV1, MKTAG('F', 'L', 'V', '1') },
00171 { CODEC_ID_FLASHSV, MKTAG('F', 'S', 'V', '1') },
00172 { CODEC_ID_VP6F, MKTAG('V', 'P', '6', 'F') },
00173 { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') },
00174 { CODEC_ID_TSCC, MKTAG('t', 's', 'c', 'c') },
00175 { CODEC_ID_ULTI, MKTAG('U', 'L', 'T', 'I') },
00176 { CODEC_ID_VIXL, MKTAG('V', 'I', 'X', 'L') },
00177 { CODEC_ID_QPEG, MKTAG('Q', 'P', 'E', 'G') },
00178 { CODEC_ID_QPEG, MKTAG('Q', '1', '.', '0') },
00179 { CODEC_ID_QPEG, MKTAG('Q', '1', '.', '1') },
00180 { CODEC_ID_WMV3, MKTAG('W', 'M', 'V', '3') },
00181 { CODEC_ID_VC1, MKTAG('W', 'V', 'C', '1') },
00182 { CODEC_ID_VC1, MKTAG('W', 'M', 'V', 'A') },
00183 { CODEC_ID_LOCO, MKTAG('L', 'O', 'C', 'O') },
00184 { CODEC_ID_WNV1, MKTAG('W', 'N', 'V', '1') },
00185 { CODEC_ID_AASC, MKTAG('A', 'A', 'S', 'C') },
00186 { CODEC_ID_INDEO2, MKTAG('R', 'T', '2', '1') },
00187 { CODEC_ID_FRAPS, MKTAG('F', 'P', 'S', '1') },
00188 { CODEC_ID_THEORA, MKTAG('t', 'h', 'e', 'o') },
00189 { CODEC_ID_TRUEMOTION2, MKTAG('T', 'M', '2', '0') },
00190 { CODEC_ID_CSCD, MKTAG('C', 'S', 'C', 'D') },
00191 { CODEC_ID_ZMBV, MKTAG('Z', 'M', 'B', 'V') },
00192 { CODEC_ID_KMVC, MKTAG('K', 'M', 'V', 'C') },
00193 { CODEC_ID_CAVS, MKTAG('C', 'A', 'V', 'S') },
00194 { CODEC_ID_JPEG2000, MKTAG('M', 'J', '2', 'C') },
00195 { CODEC_ID_VMNC, MKTAG('V', 'M', 'n', 'c') },
00196 { CODEC_ID_TARGA, MKTAG('t', 'g', 'a', ' ') },
00197 { CODEC_ID_PNG, MKTAG('M', 'P', 'N', 'G') },
00198 { CODEC_ID_CLJR, MKTAG('c', 'l', 'j', 'r') },
00199 { CODEC_ID_DIRAC, MKTAG('d', 'r', 'a', 'c') },
00200 { CODEC_ID_RPZA, MKTAG('a', 'z', 'p', 'r') },
00201 { CODEC_ID_RPZA, MKTAG('R', 'P', 'Z', 'A') },
00202 { CODEC_ID_RPZA, MKTAG('r', 'p', 'z', 'a') },
00203 { CODEC_ID_SP5X, MKTAG('S', 'P', '5', '4') },
00204 { CODEC_ID_NONE, 0 }
00205 };
00206
00207 const AVCodecTag codec_wav_tags[] = {
00208 { CODEC_ID_PCM_S16LE, 0x0001 },
00209 { CODEC_ID_PCM_U8, 0x0001 },
00210 { CODEC_ID_PCM_S24LE, 0x0001 },
00211 { CODEC_ID_PCM_S32LE, 0x0001 },
00212 { CODEC_ID_ADPCM_MS, 0x0002 },
00213 { CODEC_ID_PCM_F32LE, 0x0003 },
00214 { CODEC_ID_PCM_F64LE, 0x0003 },
00215 { CODEC_ID_PCM_ALAW, 0x0006 },
00216 { CODEC_ID_PCM_MULAW, 0x0007 },
00217 { CODEC_ID_WMAVOICE, 0x000A },
00218 { CODEC_ID_ADPCM_IMA_WAV, 0x0011 },
00219 { CODEC_ID_PCM_ZORK, 0x0011 },
00220 { CODEC_ID_ADPCM_YAMAHA, 0x0020 },
00221 { CODEC_ID_TRUESPEECH, 0x0022 },
00222 { CODEC_ID_GSM_MS, 0x0031 },
00223 { CODEC_ID_ADPCM_G726, 0x0045 },
00224 { CODEC_ID_MP2, 0x0050 },
00225 { CODEC_ID_MP3, 0x0055 },
00226 { CODEC_ID_AMR_NB, 0x0057 },
00227 { CODEC_ID_AMR_WB, 0x0058 },
00228 { CODEC_ID_ADPCM_IMA_DK4, 0x0061 },
00229 { CODEC_ID_ADPCM_IMA_DK3, 0x0062 },
00230 { CODEC_ID_ADPCM_IMA_WAV, 0x0069 },
00231 { CODEC_ID_VOXWARE, 0x0075 },
00232 { CODEC_ID_AAC, 0x00ff },
00233 { CODEC_ID_SIPR, 0x0130 },
00234 { CODEC_ID_WMAV1, 0x0160 },
00235 { CODEC_ID_WMAV2, 0x0161 },
00236 { CODEC_ID_WMAPRO, 0x0162 },
00237 { CODEC_ID_WMALOSSLESS, 0x0163 },
00238 { CODEC_ID_ADPCM_CT, 0x0200 },
00239 { CODEC_ID_ATRAC3, 0x0270 },
00240 { CODEC_ID_IMC, 0x0401 },
00241 { CODEC_ID_AC3, 0x2000 },
00242 { CODEC_ID_DTS, 0x2001 },
00243 { CODEC_ID_SONIC, 0x2048 },
00244 { CODEC_ID_SONIC_LS, 0x2048 },
00245 { CODEC_ID_AAC, 0x706d },
00246 { CODEC_ID_AAC, 0x4143 },
00247 { CODEC_ID_FLAC, 0xF1AC },
00248 { CODEC_ID_ADPCM_SWF, ('S'<<8)+'F' },
00249 { CODEC_ID_VORBIS, ('V'<<8)+'o' },
00250
00251
00252
00253 { CODEC_ID_PCM_S16LE, MKTAG('R', 'A', 'W', 'A') },
00254 { CODEC_ID_MP3, MKTAG('L', 'A', 'M', 'E') },
00255 { CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') },
00256 { 0, 0 },
00257 };
00258
00259 #if CONFIG_MUXERS
00260 int64_t start_tag(ByteIOContext *pb, const char *tag)
00261 {
00262 put_tag(pb, tag);
00263 put_le32(pb, 0);
00264 return url_ftell(pb);
00265 }
00266
00267 void end_tag(ByteIOContext *pb, int64_t start)
00268 {
00269 int64_t pos;
00270
00271 pos = url_ftell(pb);
00272 url_fseek(pb, start - 4, SEEK_SET);
00273 put_le32(pb, (uint32_t)(pos - start));
00274 url_fseek(pb, pos, SEEK_SET);
00275 }
00276
00277
00278
00279 int put_wav_header(ByteIOContext *pb, AVCodecContext *enc)
00280 {
00281 int bps, blkalign, bytespersec;
00282 int hdrsize = 18;
00283
00284 if(!enc->codec_tag || enc->codec_tag > 0xffff)
00285 return -1;
00286
00287 put_le16(pb, enc->codec_tag);
00288 put_le16(pb, enc->channels);
00289 put_le32(pb, enc->sample_rate);
00290 if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) {
00291 bps = 0;
00292 } 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) {
00293 bps = 4;
00294 } else {
00295 if (!(bps = av_get_bits_per_sample(enc->codec_id)))
00296 bps = 16;
00297 }
00298 if(bps != enc->bits_per_coded_sample && enc->bits_per_coded_sample){
00299 av_log(enc, AV_LOG_WARNING, "requested bits_per_coded_sample (%d) and actually stored (%d) differ\n", enc->bits_per_coded_sample, bps);
00300 }
00301
00302 if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_AC3) {
00303 blkalign = enc->frame_size;
00304
00305 } else if (enc->codec_id == CODEC_ID_ADPCM_G726) {
00306 blkalign = 1;
00307 } else if (enc->block_align != 0) {
00308 blkalign = enc->block_align;
00309 } else
00310 blkalign = enc->channels*bps >> 3;
00311 if (enc->codec_id == CODEC_ID_PCM_U8 ||
00312 enc->codec_id == CODEC_ID_PCM_S24LE ||
00313 enc->codec_id == CODEC_ID_PCM_S32LE ||
00314 enc->codec_id == CODEC_ID_PCM_F32LE ||
00315 enc->codec_id == CODEC_ID_PCM_F64LE ||
00316 enc->codec_id == CODEC_ID_PCM_S16LE) {
00317 bytespersec = enc->sample_rate * blkalign;
00318 } else {
00319 bytespersec = enc->bit_rate / 8;
00320 }
00321 put_le32(pb, bytespersec);
00322 put_le16(pb, blkalign);
00323 put_le16(pb, bps);
00324 if (enc->codec_id == CODEC_ID_MP3) {
00325 put_le16(pb, 12);
00326 hdrsize += 12;
00327 put_le16(pb, 1);
00328 put_le32(pb, 2);
00329 put_le16(pb, 1152);
00330 put_le16(pb, 1);
00331 put_le16(pb, 1393);
00332 } else if (enc->codec_id == CODEC_ID_MP2) {
00333 put_le16(pb, 22);
00334 hdrsize += 22;
00335 put_le16(pb, 2);
00336 put_le32(pb, enc->bit_rate);
00337 put_le16(pb, enc->channels == 2 ? 1 : 8);
00338 put_le16(pb, 0);
00339 put_le16(pb, 1);
00340 put_le16(pb, 16);
00341 put_le32(pb, 0);
00342 put_le32(pb, 0);
00343 } else if (enc->codec_id == CODEC_ID_GSM_MS) {
00344 put_le16(pb, 2);
00345 hdrsize += 2;
00346 put_le16(pb, enc->frame_size);
00347 } else if (enc->codec_id == CODEC_ID_ADPCM_IMA_WAV) {
00348 put_le16(pb, 2);
00349 hdrsize += 2;
00350 put_le16(pb, enc->frame_size);
00351 } else if(enc->extradata_size){
00352 put_le16(pb, enc->extradata_size);
00353 put_buffer(pb, enc->extradata, enc->extradata_size);
00354 hdrsize += enc->extradata_size;
00355 if(hdrsize&1){
00356 hdrsize++;
00357 put_byte(pb, 0);
00358 }
00359 } else {
00360 hdrsize -= 2;
00361 }
00362
00363 return hdrsize;
00364 }
00365
00366
00367 void put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf)
00368 {
00369 put_le32(pb, 40 + enc->extradata_size);
00370 put_le32(pb, enc->width);
00371
00372 put_le32(pb, enc->codec_tag ? enc->height : -enc->height);
00373 put_le16(pb, 1);
00374
00375 put_le16(pb, enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24);
00376
00377 put_le32(pb, enc->codec_tag);
00378 put_le32(pb, enc->width * enc->height * 3);
00379 put_le32(pb, 0);
00380 put_le32(pb, 0);
00381 put_le32(pb, 0);
00382 put_le32(pb, 0);
00383
00384 put_buffer(pb, enc->extradata, enc->extradata_size);
00385
00386 if (enc->extradata_size & 1)
00387 put_byte(pb, 0);
00388 }
00389 #endif //CONFIG_MUXERS
00390
00391 #if CONFIG_DEMUXERS
00392
00393
00394
00395
00396
00397
00398
00399 void get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size)
00400 {
00401 int id;
00402
00403 id = get_le16(pb);
00404 codec->codec_type = CODEC_TYPE_AUDIO;
00405 codec->codec_tag = id;
00406 codec->channels = get_le16(pb);
00407 codec->sample_rate = get_le32(pb);
00408 codec->bit_rate = get_le32(pb) * 8;
00409 codec->block_align = get_le16(pb);
00410 if (size == 14) {
00411 codec->bits_per_coded_sample = 8;
00412 }else
00413 codec->bits_per_coded_sample = get_le16(pb);
00414 if (size >= 18) {
00415 int cbSize = get_le16(pb);
00416 size -= 18;
00417 cbSize = FFMIN(size, cbSize);
00418 if (cbSize >= 22 && id == 0xfffe) {
00419 codec->bits_per_coded_sample = get_le16(pb);
00420 codec->channel_layout = get_le32(pb);
00421 id = get_le32(pb);
00422 url_fskip(pb, 12);
00423 cbSize -= 22;
00424 size -= 22;
00425 }
00426 codec->extradata_size = cbSize;
00427 if (cbSize > 0) {
00428 codec->extradata = av_mallocz(codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE);
00429 get_buffer(pb, codec->extradata, codec->extradata_size);
00430 size -= cbSize;
00431 }
00432
00433
00434 if (size > 0)
00435 url_fskip(pb, size);
00436 }
00437 codec->codec_id = wav_codec_get_id(id, codec->bits_per_coded_sample);
00438 }
00439
00440
00441 enum CodecID wav_codec_get_id(unsigned int tag, int bps)
00442 {
00443 enum CodecID id;
00444 id = codec_get_id(codec_wav_tags, tag);
00445 if (id <= 0)
00446 return id;
00447
00448 if (id == CODEC_ID_PCM_S16LE && bps == 8)
00449 id = CODEC_ID_PCM_U8;
00450 if (id == CODEC_ID_PCM_S16LE && bps == 24)
00451 id = CODEC_ID_PCM_S24LE;
00452 if (id == CODEC_ID_PCM_S16LE && bps == 32)
00453 id = CODEC_ID_PCM_S32LE;
00454 if (id == CODEC_ID_PCM_F32LE && bps == 64)
00455 id = CODEC_ID_PCM_F64LE;
00456 if (id == CODEC_ID_ADPCM_IMA_WAV && bps == 8)
00457 id = CODEC_ID_PCM_ZORK;
00458 return id;
00459 }
00460 #endif // CONFIG_DEMUXERS
00461
00462 void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale)
00463 {
00464 int gcd;
00465
00466 *au_ssize= stream->block_align;
00467 if(stream->frame_size && stream->sample_rate){
00468 *au_scale=stream->frame_size;
00469 *au_rate= stream->sample_rate;
00470 }else if(stream->codec_type == CODEC_TYPE_VIDEO){
00471 *au_scale= stream->time_base.num;
00472 *au_rate = stream->time_base.den;
00473 }else{
00474 *au_scale= stream->block_align ? stream->block_align*8 : 8;
00475 *au_rate = stream->bit_rate ? stream->bit_rate : 8*stream->sample_rate;
00476 }
00477 gcd= av_gcd(*au_scale, *au_rate);
00478 *au_scale /= gcd;
00479 *au_rate /= gcd;
00480 }