Originally committed as revision 4924 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -22,7 +22,7 @@ OBJS+=mpeg.o mpegts.o mpegtsenc.o ffm.o crc.o img.o img2.o raw.o rm.o \ |
| 22 | 22 |
yuv4mpeg.o 4xm.o flvdec.o psxstr.o idroq.o ipmovie.o \ |
| 23 | 23 |
nut.o wc3movie.o mp3.o westwood.o segafilm.o idcin.o flic.o \ |
| 24 | 24 |
sierravmd.o matroska.o sol.o electronicarts.o nsvdec.o asf.o \ |
| 25 |
- ogg2.o oggparsevorbis.o oggparsetheora.o oggparseflac.o daud.o |
|
| 25 |
+ ogg2.o oggparsevorbis.o oggparsetheora.o oggparseflac.o daud.o aiff.o |
|
| 26 | 26 |
|
| 27 | 27 |
# muxers |
| 28 | 28 |
ifeq ($(CONFIG_MUXERS),yes) |
| 29 | 29 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,482 @@ |
| 0 |
+/* |
|
| 1 |
+ * AIFF/AIFF-C encoder and decoder |
|
| 2 |
+ * Copyright (c) 2006 Patrick Guimond |
|
| 3 |
+ * |
|
| 4 |
+ * This library is free software; you can redistribute it and/or |
|
| 5 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 6 |
+ * License as published by the Free Software Foundation; either |
|
| 7 |
+ * version 2 of the License, or (at your option) any later version. |
|
| 8 |
+ * |
|
| 9 |
+ * This library is distributed in the hope that it will be useful, |
|
| 10 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 12 |
+ * Lesser General Public License for more details. |
|
| 13 |
+ * |
|
| 14 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 15 |
+ * License along with this library; if not, write to the Free Software |
|
| 16 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 17 |
+ */ |
|
| 18 |
+#include "avformat.h" |
|
| 19 |
+#include "avi.h" |
|
| 20 |
+#include "intfloat_readwrite.h" |
|
| 21 |
+ |
|
| 22 |
+const CodecTag codec_aiff_tags[] = {
|
|
| 23 |
+ { CODEC_ID_PCM_S16BE, MKTAG('N','O','N','E') },
|
|
| 24 |
+ { CODEC_ID_PCM_S8, MKTAG('N','O','N','E') },
|
|
| 25 |
+ { CODEC_ID_PCM_S24BE, MKTAG('N','O','N','E') },
|
|
| 26 |
+ { CODEC_ID_PCM_S32BE, MKTAG('N','O','N','E') },
|
|
| 27 |
+ { CODEC_ID_PCM_ALAW, MKTAG('a','l','a','w') },
|
|
| 28 |
+ { CODEC_ID_PCM_ALAW, MKTAG('A','L','A','W') },
|
|
| 29 |
+ { CODEC_ID_PCM_MULAW, MKTAG('u','l','a','w') },
|
|
| 30 |
+ { CODEC_ID_PCM_MULAW, MKTAG('U','L','A','W') },
|
|
| 31 |
+ { CODEC_ID_MACE3, MKTAG('M','A','C','3') },
|
|
| 32 |
+ { CODEC_ID_MACE6, MKTAG('M','A','C','6') },
|
|
| 33 |
+ { CODEC_ID_GSM, MKTAG('G','S','M',' ') },
|
|
| 34 |
+ { CODEC_ID_ADPCM_G726, MKTAG('G','7','2','6') },
|
|
| 35 |
+ { 0, 0 },
|
|
| 36 |
+}; |
|
| 37 |
+ |
|
| 38 |
+#define AIFF 0 |
|
| 39 |
+#define AIFF_C_VERSION1 0xA2805140 |
|
| 40 |
+ |
|
| 41 |
+static int aiff_codec_get_id (int bps) |
|
| 42 |
+{
|
|
| 43 |
+ if (bps <= 8) |
|
| 44 |
+ return CODEC_ID_PCM_S8; |
|
| 45 |
+ if (bps <= 16) |
|
| 46 |
+ return CODEC_ID_PCM_S16BE; |
|
| 47 |
+ if (bps <= 24) |
|
| 48 |
+ return CODEC_ID_PCM_S24BE; |
|
| 49 |
+ if (bps <= 32) |
|
| 50 |
+ return CODEC_ID_PCM_S32BE; |
|
| 51 |
+ |
|
| 52 |
+ /* bigger than 32 isn't allowed */ |
|
| 53 |
+ return 0; |
|
| 54 |
+} |
|
| 55 |
+ |
|
| 56 |
+/* returns the size of the found tag */ |
|
| 57 |
+static int get_tag(ByteIOContext *pb, uint32_t * tag) |
|
| 58 |
+{
|
|
| 59 |
+ int size; |
|
| 60 |
+ |
|
| 61 |
+ if (url_feof(pb)) |
|
| 62 |
+ return AVERROR_IO; |
|
| 63 |
+ |
|
| 64 |
+ *tag = get_le32(pb); |
|
| 65 |
+ size = get_be32(pb); |
|
| 66 |
+ |
|
| 67 |
+ if (size < 0) |
|
| 68 |
+ size = 0x7fffffff; |
|
| 69 |
+ |
|
| 70 |
+ return size; |
|
| 71 |
+} |
|
| 72 |
+ |
|
| 73 |
+/* Metadata string read */ |
|
| 74 |
+static void get_meta(ByteIOContext *pb, char * str, int strsize, int size) |
|
| 75 |
+{
|
|
| 76 |
+ int res; |
|
| 77 |
+ |
|
| 78 |
+ if (size > strsize-1) |
|
| 79 |
+ res = get_buffer(pb, (uint8_t*)str, strsize-1); |
|
| 80 |
+ else |
|
| 81 |
+ res = get_buffer(pb, (uint8_t*)str, size); |
|
| 82 |
+ |
|
| 83 |
+ if (res < 0) |
|
| 84 |
+ return; |
|
| 85 |
+ |
|
| 86 |
+ str[res] = 0; |
|
| 87 |
+ if (size & 1) |
|
| 88 |
+ size++; |
|
| 89 |
+ size -= res; |
|
| 90 |
+ if (size); |
|
| 91 |
+ url_fskip(pb, size); |
|
| 92 |
+} |
|
| 93 |
+ |
|
| 94 |
+/* Returns the number of bits per second */ |
|
| 95 |
+static int fix_bps(int codec_id) |
|
| 96 |
+{
|
|
| 97 |
+ switch (codec_id) {
|
|
| 98 |
+ case CODEC_ID_PCM_S8: |
|
| 99 |
+ return 8; |
|
| 100 |
+ case CODEC_ID_PCM_S16BE: |
|
| 101 |
+ return 16; |
|
| 102 |
+ case CODEC_ID_PCM_S24BE: |
|
| 103 |
+ return 24; |
|
| 104 |
+ case CODEC_ID_PCM_S32BE: |
|
| 105 |
+ return 32; |
|
| 106 |
+ } |
|
| 107 |
+ |
|
| 108 |
+ return -1; |
|
| 109 |
+} |
|
| 110 |
+ |
|
| 111 |
+/* Returns the number of sound data frames or negative on error */ |
|
| 112 |
+unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec, |
|
| 113 |
+ int size, unsigned version) |
|
| 114 |
+{
|
|
| 115 |
+ AVExtFloat ext; |
|
| 116 |
+ double sample_rate; |
|
| 117 |
+ unsigned int num_frames; |
|
| 118 |
+ |
|
| 119 |
+ |
|
| 120 |
+ if (size & 1) |
|
| 121 |
+ size++; |
|
| 122 |
+ |
|
| 123 |
+ codec->codec_type = CODEC_TYPE_AUDIO; |
|
| 124 |
+ codec->channels = get_be16(pb); |
|
| 125 |
+ num_frames = get_be32(pb); |
|
| 126 |
+ codec->bits_per_sample = get_be16(pb); |
|
| 127 |
+ |
|
| 128 |
+ get_buffer(pb, (uint8_t*)&ext, sizeof(ext));/* Sample rate is in */ |
|
| 129 |
+ sample_rate = av_ext2dbl(ext); /* 80 bits BE IEEE extended float */ |
|
| 130 |
+ codec->sample_rate = sample_rate; |
|
| 131 |
+ size -= 18; |
|
| 132 |
+ |
|
| 133 |
+ /* Got an AIFF-C? */ |
|
| 134 |
+ if (version == AIFF_C_VERSION1) {
|
|
| 135 |
+ codec->codec_tag = get_le32(pb); |
|
| 136 |
+ codec->codec_id = codec_get_id (codec_aiff_tags, codec->codec_tag); |
|
| 137 |
+ |
|
| 138 |
+ if (codec->codec_id == CODEC_ID_PCM_S16BE) {
|
|
| 139 |
+ codec->codec_id = aiff_codec_get_id (codec->bits_per_sample); |
|
| 140 |
+ codec->bits_per_sample = fix_bps(codec->codec_id); |
|
| 141 |
+ } |
|
| 142 |
+ |
|
| 143 |
+ size -= 4; |
|
| 144 |
+ } else {
|
|
| 145 |
+ /* Need the codec type */ |
|
| 146 |
+ codec->codec_id = aiff_codec_get_id (codec->bits_per_sample); |
|
| 147 |
+ codec->bits_per_sample = fix_bps(codec->codec_id); |
|
| 148 |
+ } |
|
| 149 |
+ |
|
| 150 |
+ if (!codec->codec_id) |
|
| 151 |
+ return AVERROR_INVALIDDATA; |
|
| 152 |
+ |
|
| 153 |
+ /* Block align needs to be computed in all cases, as the definition |
|
| 154 |
+ * is specific to applications -> here we use the WAVE format definition */ |
|
| 155 |
+ codec->block_align = (codec->bits_per_sample * codec->channels) >> 3; |
|
| 156 |
+ |
|
| 157 |
+ codec->bit_rate = codec->sample_rate * codec->block_align; |
|
| 158 |
+ |
|
| 159 |
+ /* Chunk is over */ |
|
| 160 |
+ if (size) |
|
| 161 |
+ url_fseek(pb, size, SEEK_CUR); |
|
| 162 |
+ |
|
| 163 |
+ return num_frames; |
|
| 164 |
+} |
|
| 165 |
+ |
|
| 166 |
+#ifdef CONFIG_MUXERS |
|
| 167 |
+typedef struct {
|
|
| 168 |
+ offset_t form; |
|
| 169 |
+ offset_t frames; |
|
| 170 |
+ offset_t ssnd; |
|
| 171 |
+} AIFFOutputContext; |
|
| 172 |
+ |
|
| 173 |
+static int aiff_write_header(AVFormatContext *s) |
|
| 174 |
+{
|
|
| 175 |
+ AIFFOutputContext *aiff = s->priv_data; |
|
| 176 |
+ ByteIOContext *pb = &s->pb; |
|
| 177 |
+ AVCodecContext *enc = s->streams[0]->codec; |
|
| 178 |
+ AVExtFloat sample_rate; |
|
| 179 |
+ int coder_len; |
|
| 180 |
+ |
|
| 181 |
+ /* First verify if format is ok */ |
|
| 182 |
+ enc->codec_tag = codec_get_tag(codec_aiff_tags, enc->codec_id); |
|
| 183 |
+ if (!enc->codec_tag) {
|
|
| 184 |
+ av_free(aiff); |
|
| 185 |
+ return -1; |
|
| 186 |
+ } |
|
| 187 |
+ |
|
| 188 |
+ coder_len = strlen(enc->codec->name); |
|
| 189 |
+ |
|
| 190 |
+ /* FORM AIFF header */ |
|
| 191 |
+ put_tag(pb, "FORM"); |
|
| 192 |
+ aiff->form = url_ftell(pb); |
|
| 193 |
+ put_be32(pb, 0); /* file length */ |
|
| 194 |
+ put_tag(pb, "AIFC"); |
|
| 195 |
+ |
|
| 196 |
+ /* Version chunk */ |
|
| 197 |
+ put_tag(pb, "FVER"); |
|
| 198 |
+ put_be32(pb, 4); |
|
| 199 |
+ put_be32(pb, 0xA2805140); |
|
| 200 |
+ |
|
| 201 |
+ /* Common chunk */ |
|
| 202 |
+ put_tag(pb, "COMM"); |
|
| 203 |
+ if (coder_len & 1) /* Common chunk is of var size */ |
|
| 204 |
+ put_be32(pb, 23+coder_len); |
|
| 205 |
+ else |
|
| 206 |
+ put_be32(pb, 24+coder_len); |
|
| 207 |
+ put_be16(pb, enc->channels); /* Number of channels */ |
|
| 208 |
+ |
|
| 209 |
+ aiff->frames = url_ftell(pb); |
|
| 210 |
+ put_be32(pb, 0); /* Number of frames */ |
|
| 211 |
+ |
|
| 212 |
+ if (!enc->bits_per_sample) |
|
| 213 |
+ enc->bits_per_sample = (enc->block_align<<3) / enc->channels; |
|
| 214 |
+ put_be16(pb, enc->bits_per_sample); /* Sample size */ |
|
| 215 |
+ |
|
| 216 |
+ sample_rate = av_dbl2ext((double)enc->sample_rate); |
|
| 217 |
+ put_buffer(pb, (uint8_t*)&sample_rate, sizeof(sample_rate)); |
|
| 218 |
+ |
|
| 219 |
+ put_le32(pb, enc->codec_tag); |
|
| 220 |
+ if (coder_len & 1) {
|
|
| 221 |
+ put_byte(pb, coder_len); |
|
| 222 |
+ put_buffer(pb, (uint8_t*)enc->codec->name, coder_len); |
|
| 223 |
+ } else {
|
|
| 224 |
+ put_byte(pb, coder_len+1); |
|
| 225 |
+ put_buffer(pb, (uint8_t*)enc->codec->name, coder_len); |
|
| 226 |
+ put_byte(pb, 0); |
|
| 227 |
+ } |
|
| 228 |
+ |
|
| 229 |
+ /* Sound data chunk */ |
|
| 230 |
+ put_tag(pb, "SSND"); |
|
| 231 |
+ aiff->ssnd = url_ftell(pb); /* Sound chunk size */ |
|
| 232 |
+ put_be32(pb, 0); /* Sound samples data size */ |
|
| 233 |
+ put_be32(pb, 0); /* Data offset */ |
|
| 234 |
+ put_be32(pb, 0); /* Block-size (block align) */ |
|
| 235 |
+ |
|
| 236 |
+ av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); |
|
| 237 |
+ |
|
| 238 |
+ /* Data is starting here */ |
|
| 239 |
+ put_flush_packet(pb); |
|
| 240 |
+ |
|
| 241 |
+ return 0; |
|
| 242 |
+} |
|
| 243 |
+ |
|
| 244 |
+static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt) |
|
| 245 |
+{
|
|
| 246 |
+ ByteIOContext *pb = &s->pb; |
|
| 247 |
+ put_buffer(pb, pkt->data, pkt->size); |
|
| 248 |
+ return 0; |
|
| 249 |
+} |
|
| 250 |
+ |
|
| 251 |
+static int aiff_write_trailer(AVFormatContext *s) |
|
| 252 |
+{
|
|
| 253 |
+ ByteIOContext *pb = &s->pb; |
|
| 254 |
+ AIFFOutputContext *aiff = s->priv_data; |
|
| 255 |
+ AVCodecContext *enc = s->streams[0]->codec; |
|
| 256 |
+ |
|
| 257 |
+ /* Chunks sizes must be even */ |
|
| 258 |
+ offset_t file_size, end_size; |
|
| 259 |
+ end_size = file_size = url_ftell(pb); |
|
| 260 |
+ if (file_size & 1) {
|
|
| 261 |
+ put_byte(pb, 0); |
|
| 262 |
+ end_size++; |
|
| 263 |
+ } |
|
| 264 |
+ |
|
| 265 |
+ if (!url_is_streamed(&s->pb)) {
|
|
| 266 |
+ /* File length */ |
|
| 267 |
+ url_fseek(pb, aiff->form, SEEK_SET); |
|
| 268 |
+ put_be32(pb, (uint32_t)(file_size - aiff->form - 4)); |
|
| 269 |
+ |
|
| 270 |
+ /* Number of sample frames */ |
|
| 271 |
+ url_fseek(pb, aiff->frames, SEEK_SET); |
|
| 272 |
+ put_be32(pb, ((uint32_t)(file_size-aiff->ssnd-12))/enc->block_align); |
|
| 273 |
+ |
|
| 274 |
+ /* Sound Data chunk size */ |
|
| 275 |
+ url_fseek(pb, aiff->ssnd, SEEK_SET); |
|
| 276 |
+ put_be32(pb, (uint32_t)(file_size - aiff->ssnd - 4)); |
|
| 277 |
+ |
|
| 278 |
+ /* return to the end */ |
|
| 279 |
+ url_fseek(pb, end_size, SEEK_SET); |
|
| 280 |
+ |
|
| 281 |
+ put_flush_packet(pb); |
|
| 282 |
+ } |
|
| 283 |
+ |
|
| 284 |
+ return 0; |
|
| 285 |
+} |
|
| 286 |
+#endif //CONFIG_MUXERS |
|
| 287 |
+ |
|
| 288 |
+static int aiff_probe(AVProbeData *p) |
|
| 289 |
+{
|
|
| 290 |
+ /* check file header */ |
|
| 291 |
+ if (p->buf_size < 16) |
|
| 292 |
+ return 0; |
|
| 293 |
+ if (p->buf[0] == 'F' && p->buf[1] == 'O' && |
|
| 294 |
+ p->buf[2] == 'R' && p->buf[3] == 'M' && |
|
| 295 |
+ p->buf[8] == 'A' && p->buf[9] == 'I' && |
|
| 296 |
+ p->buf[10] == 'F' && (p->buf[11] == 'F' || p->buf[11] == 'C')) |
|
| 297 |
+ return AVPROBE_SCORE_MAX; |
|
| 298 |
+ else |
|
| 299 |
+ return 0; |
|
| 300 |
+} |
|
| 301 |
+ |
|
| 302 |
+/* aiff input */ |
|
| 303 |
+static int aiff_read_header(AVFormatContext *s, |
|
| 304 |
+ AVFormatParameters *ap) |
|
| 305 |
+{
|
|
| 306 |
+ int size, filesize, offset; |
|
| 307 |
+ uint32_t tag; |
|
| 308 |
+ unsigned version = AIFF_C_VERSION1; |
|
| 309 |
+ ByteIOContext *pb = &s->pb; |
|
| 310 |
+ AVStream * st = s->streams[0]; |
|
| 311 |
+ |
|
| 312 |
+ /* check FORM header */ |
|
| 313 |
+ filesize = get_tag(pb, &tag); |
|
| 314 |
+ if (filesize < 0 || tag != MKTAG('F', 'O', 'R', 'M'))
|
|
| 315 |
+ return AVERROR_INVALIDDATA; |
|
| 316 |
+ |
|
| 317 |
+ /* AIFF data type */ |
|
| 318 |
+ tag = get_le32(pb); |
|
| 319 |
+ if (tag == MKTAG('A', 'I', 'F', 'F')) /* Got an AIFF file */
|
|
| 320 |
+ version = AIFF; |
|
| 321 |
+ else if (tag != MKTAG('A', 'I', 'F', 'C')) /* An AIFF-C file then */
|
|
| 322 |
+ return AVERROR_INVALIDDATA; |
|
| 323 |
+ |
|
| 324 |
+ filesize -= 4; |
|
| 325 |
+ |
|
| 326 |
+ st = av_new_stream(s, 0); |
|
| 327 |
+ if (!st) |
|
| 328 |
+ return AVERROR_NOMEM; |
|
| 329 |
+ |
|
| 330 |
+ while (filesize > 0) {
|
|
| 331 |
+ /* parse different chunks */ |
|
| 332 |
+ size = get_tag(pb, &tag); |
|
| 333 |
+ if (size < 0) |
|
| 334 |
+ return size; |
|
| 335 |
+ |
|
| 336 |
+ filesize -= size + 8; |
|
| 337 |
+ |
|
| 338 |
+ switch (tag) {
|
|
| 339 |
+ case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */
|
|
| 340 |
+ /* Then for the complete header info */ |
|
| 341 |
+ st->nb_frames = get_aiff_header (pb, st->codec, size, version); |
|
| 342 |
+ if (st->nb_frames < 0) |
|
| 343 |
+ return st->nb_frames; |
|
| 344 |
+ break; |
|
| 345 |
+ |
|
| 346 |
+ case MKTAG('F', 'V', 'E', 'R'): /* Version chunk */
|
|
| 347 |
+ version = get_be32(pb); |
|
| 348 |
+ break; |
|
| 349 |
+ |
|
| 350 |
+ case MKTAG('N', 'A', 'M', 'E'): /* Sample name chunk */
|
|
| 351 |
+ get_meta (pb, s->title, sizeof(s->title), size); |
|
| 352 |
+ break; |
|
| 353 |
+ |
|
| 354 |
+ case MKTAG('A', 'U', 'T', 'H'): /* Author chunk */
|
|
| 355 |
+ get_meta (pb, s->author, sizeof(s->author), size); |
|
| 356 |
+ break; |
|
| 357 |
+ |
|
| 358 |
+ case MKTAG('(', 'c', ')', ' '): /* Copyright chunk */
|
|
| 359 |
+ get_meta (pb, s->copyright, sizeof(s->copyright), size); |
|
| 360 |
+ break; |
|
| 361 |
+ |
|
| 362 |
+ case MKTAG('A', 'N', 'N', 'O'): /* Annotation chunk */
|
|
| 363 |
+ get_meta (pb, s->comment, sizeof(s->comment), size); |
|
| 364 |
+ break; |
|
| 365 |
+ |
|
| 366 |
+ case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */
|
|
| 367 |
+ get_be32(pb); /* Block align... don't care */ |
|
| 368 |
+ offset = get_be32(pb); /* Offset of sound data */ |
|
| 369 |
+ goto got_sound; |
|
| 370 |
+ |
|
| 371 |
+ default: /* Jump */ |
|
| 372 |
+ if (size & 1) /* Always even aligned */ |
|
| 373 |
+ size++; |
|
| 374 |
+ url_fskip (pb, size); |
|
| 375 |
+ } |
|
| 376 |
+ } |
|
| 377 |
+ |
|
| 378 |
+ /* End of loop and didn't get sound */ |
|
| 379 |
+ return AVERROR_INVALIDDATA; |
|
| 380 |
+ |
|
| 381 |
+got_sound: |
|
| 382 |
+ /* Now positioned, get the sound data start and end */ |
|
| 383 |
+ if (st->nb_frames) |
|
| 384 |
+ s->file_size = st->nb_frames * st->codec->block_align; |
|
| 385 |
+ |
|
| 386 |
+ av_set_pts_info(st, 64, 1, st->codec->sample_rate); |
|
| 387 |
+ st->start_time = 0; |
|
| 388 |
+ st->duration = st->nb_frames; |
|
| 389 |
+ |
|
| 390 |
+ /* Position the stream at the first block */ |
|
| 391 |
+ url_fskip(pb, offset); |
|
| 392 |
+ |
|
| 393 |
+ return 0; |
|
| 394 |
+} |
|
| 395 |
+ |
|
| 396 |
+#define MAX_SIZE 4096 |
|
| 397 |
+ |
|
| 398 |
+static int aiff_read_packet(AVFormatContext *s, |
|
| 399 |
+ AVPacket *pkt) |
|
| 400 |
+{
|
|
| 401 |
+ offset_t pos; |
|
| 402 |
+ int res, size; |
|
| 403 |
+ |
|
| 404 |
+ /* End of stream may be reached */ |
|
| 405 |
+ if (url_feof(&s->pb)) |
|
| 406 |
+ return AVERROR_IO; |
|
| 407 |
+ |
|
| 408 |
+ /* Need to know if reached the end sound data */ |
|
| 409 |
+ size = MAX_SIZE; |
|
| 410 |
+ if (s->file_size) {
|
|
| 411 |
+ pos = url_ftell (&s->pb) - s->file_size; |
|
| 412 |
+ if (pos >= s->file_size) |
|
| 413 |
+ size = 0; |
|
| 414 |
+ else if (pos + MAX_SIZE >= s->file_size) |
|
| 415 |
+ size = s->file_size - pos; |
|
| 416 |
+ } |
|
| 417 |
+ |
|
| 418 |
+ /* Now for that packet */ |
|
| 419 |
+ res = av_get_packet (&s->pb, pkt, MAX_SIZE); |
|
| 420 |
+ if (res < 0) |
|
| 421 |
+ return res; |
|
| 422 |
+ |
|
| 423 |
+ /* Only one stream in an AIFF file */ |
|
| 424 |
+ pkt->stream_index = 0; |
|
| 425 |
+ |
|
| 426 |
+ /* Finaly fix the read to a block */ |
|
| 427 |
+ if (size <= res) |
|
| 428 |
+ pkt->size = size - (size % s->streams[0]->codec->block_align); |
|
| 429 |
+ else |
|
| 430 |
+ pkt->size = res - (res % s->streams[0]->codec->block_align); |
|
| 431 |
+ |
|
| 432 |
+ return 0; |
|
| 433 |
+} |
|
| 434 |
+ |
|
| 435 |
+static int aiff_read_close(AVFormatContext *s) |
|
| 436 |
+{
|
|
| 437 |
+ return 0; |
|
| 438 |
+} |
|
| 439 |
+ |
|
| 440 |
+static int aiff_read_seek(AVFormatContext *s, |
|
| 441 |
+ int stream_index, int64_t timestamp, int flags) |
|
| 442 |
+{
|
|
| 443 |
+ return pcm_read_seek(s, stream_index, timestamp, flags); |
|
| 444 |
+} |
|
| 445 |
+ |
|
| 446 |
+ |
|
| 447 |
+static AVInputFormat aiff_iformat = {
|
|
| 448 |
+ "aiff", |
|
| 449 |
+ "Audio IFF", |
|
| 450 |
+ 0, |
|
| 451 |
+ aiff_probe, |
|
| 452 |
+ aiff_read_header, |
|
| 453 |
+ aiff_read_packet, |
|
| 454 |
+ aiff_read_close, |
|
| 455 |
+ aiff_read_seek, |
|
| 456 |
+}; |
|
| 457 |
+ |
|
| 458 |
+#ifdef CONFIG_MUXERS |
|
| 459 |
+static AVOutputFormat aiff_oformat = {
|
|
| 460 |
+ "aiff", |
|
| 461 |
+ "Audio IFF", |
|
| 462 |
+ "audio/aiff", |
|
| 463 |
+ "aif,aiff,afc,aifc", |
|
| 464 |
+ sizeof(AIFFOutputContext), |
|
| 465 |
+ CODEC_ID_PCM_S16BE, |
|
| 466 |
+ CODEC_ID_NONE, |
|
| 467 |
+ aiff_write_header, |
|
| 468 |
+ aiff_write_packet, |
|
| 469 |
+ aiff_write_trailer, |
|
| 470 |
+}; |
|
| 471 |
+#endif //CONFIG_MUXERS |
|
| 472 |
+ |
|
| 473 |
+int ff_aiff_init(void) |
|
| 474 |
+{
|
|
| 475 |
+ av_register_input_format(&aiff_iformat); |
|
| 476 |
+#ifdef CONFIG_MUXERS |
|
| 477 |
+ av_register_output_format(&aiff_oformat); |
|
| 478 |
+#endif //CONFIG_MUXERS |
|
| 479 |
+ return 0; |
|
| 480 |
+} |
|
| 481 |
+ |
| ... | ... |
@@ -38,6 +38,23 @@ float av_int2flt(int32_t v){
|
| 38 | 38 |
return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150); |
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 |
+double av_ext2dbl(const AVExtFloat ext){
|
|
| 42 |
+ uint64_t m = 0; |
|
| 43 |
+ int e, i; |
|
| 44 |
+ |
|
| 45 |
+ for (i = 0; i < 8; i++) |
|
| 46 |
+ m |= (uint64_t)ext.mantissa[i]<<(56-(i<<3)); |
|
| 47 |
+ e = (((int)ext.exponent[0]&0x7f)<<8) | ext.exponent[1]; |
|
| 48 |
+ if (e == 0x7fff && m) |
|
| 49 |
+ return 0.0/0.0; |
|
| 50 |
+ e -= 16383 + 63; /* In IEEE 80 bits, the whole (i.e. 1.xxxx) |
|
| 51 |
+ * mantissa bit is written as opposed to the |
|
| 52 |
+ * single and double precision formats */ |
|
| 53 |
+ if (ext.exponent[0]&0x80) |
|
| 54 |
+ return ldexp(-m, e); |
|
| 55 |
+ return ldexp(m, e); |
|
| 56 |
+} |
|
| 57 |
+ |
|
| 41 | 58 |
int64_t av_dbl2int(double d){
|
| 42 | 59 |
int e; |
| 43 | 60 |
if ( !d) return 0; |
| ... | ... |
@@ -53,3 +70,29 @@ int32_t av_flt2int(float d){
|
| 53 | 53 |
d= frexp(d, &e); |
| 54 | 54 |
return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24)); |
| 55 | 55 |
} |
| 56 |
+ |
|
| 57 |
+AVExtFloat av_dbl2ext(double d){
|
|
| 58 |
+ struct AVExtFloat ext; |
|
| 59 |
+ int e, i; double f; uint64_t m; |
|
| 60 |
+ |
|
| 61 |
+ f = fabs(frexp(d, &e)); |
|
| 62 |
+ if (f >= 0.5 && f < 1) {
|
|
| 63 |
+ e += 16382; |
|
| 64 |
+ ext.exponent[0] = e>>8; |
|
| 65 |
+ ext.exponent[1] = e; |
|
| 66 |
+ m = (uint64_t)ldexp(f, 64); |
|
| 67 |
+ for (i=0; i < 8; i++) |
|
| 68 |
+ ext.mantissa[i] = m>>(56-(i<<3)); |
|
| 69 |
+ } else if (f == 0.0) {
|
|
| 70 |
+ memset (&ext, 0, 10); |
|
| 71 |
+ } else {
|
|
| 72 |
+ ext.exponent[0] = 0x7f; ext.exponent[1] = 0xff; |
|
| 73 |
+ memset (&ext.mantissa, 0, 8); |
|
| 74 |
+ if (f != 1/0.0) |
|
| 75 |
+ ext.mantissa[0] = ~0; |
|
| 76 |
+ } |
|
| 77 |
+ if (d < 0) |
|
| 78 |
+ ext.exponent[0] |= 0x80; |
|
| 79 |
+ return ext; |
|
| 80 |
+} |
|
| 81 |
+ |
| ... | ... |
@@ -3,9 +3,17 @@ |
| 3 | 3 |
|
| 4 | 4 |
#include "common.h" |
| 5 | 5 |
|
| 6 |
+/* IEEE 80 bits extended float */ |
|
| 7 |
+typedef struct AVExtFloat {
|
|
| 8 |
+ uint8_t exponent[2]; |
|
| 9 |
+ uint8_t mantissa[8]; |
|
| 10 |
+} AVExtFloat; |
|
| 11 |
+ |
|
| 6 | 12 |
double av_int2dbl(int64_t v); |
| 7 | 13 |
float av_int2flt(int32_t v); |
| 14 |
+double av_ext2dbl(const AVExtFloat ext); |
|
| 8 | 15 |
int64_t av_dbl2int(double d); |
| 9 | 16 |
int32_t av_flt2int(float d); |
| 17 |
+AVExtFloat av_dbl2ext(double d); |
|
| 10 | 18 |
|
| 11 | 19 |
#endif /* INTFLOAT_READWRITE_H */ |
| ... | ... |
@@ -62,6 +62,9 @@ e2a6d6fae17394dfe87cb5bb8ae11837 *./data/b-libav.al |
| 62 | 62 |
20f9fa55b3c5bebe3520f5667ee4928b *./data/b-libav.mmf |
| 63 | 63 |
22609 ./data/b-libav.mmf |
| 64 | 64 |
./data/b-libav.mmf CRC=0x7e78cffe |
| 65 |
+a324baee6d76c53ab7c74616cfc31616 *./data/b-libav.aif |
|
| 66 |
+ 89168 ./data/b-libav.aif |
|
| 67 |
+./data/b-libav.aif CRC=0x2a09519c |
|
| 65 | 68 |
ce356ce2708cb6033ab5d762da93cfd4 *./data/b-libav-yuv420p.yuv |
| 66 | 69 |
304128 ./data/b-libav-yuv420p.yuv |
| 67 | 70 |
ce356ce2708cb6033ab5d762da93cfd4 *./data/b-libav-yuv422p.yuv |
| ... | ... |
@@ -696,6 +696,11 @@ file=${outfile}libav.mmf
|
| 696 | 696 |
do_ffmpeg $file -t 1 -y -qscale 10 -f s16le -i $pcm_src $file |
| 697 | 697 |
do_ffmpeg_crc $file -i $file |
| 698 | 698 |
|
| 699 |
+# aiff |
|
| 700 |
+file=${outfile}libav.aif
|
|
| 701 |
+do_ffmpeg $file -t 1 -y -qscale 10 -f s16le -i $pcm_src $file |
|
| 702 |
+do_ffmpeg_crc $file -i $file |
|
| 703 |
+ |
|
| 699 | 704 |
#################### |
| 700 | 705 |
# pix_fmt conversions |
| 701 | 706 |
conversions="yuv420p yuv422p yuv444p yuv422 yuv410p yuv411p yuvj420p \ |