| 29 | } AIFFOutputContext; |
| 30 | |
| 31 | static int aiff_write_header(AVFormatContext *s) |
| 32 | { |
| 33 | AIFFOutputContext *aiff = s->priv_data; |
| 34 | ByteIOContext *pb = s->pb; |
| 35 | AVCodecContext *enc = s->streams[0]->codec; |
| 36 | AVExtFloat sample_rate; |
| 37 | int aifc = 0; |
| 38 | |
| 39 | /* First verify if format is ok */ |
| 40 | if (!enc->codec_tag) |
| 41 | return -1; |
| 42 | if (enc->codec_tag != MKTAG('N','O','N','E')) |
| 43 | aifc = 1; |
| 44 | |
| 45 | /* FORM AIFF header */ |
| 46 | put_tag(pb, "FORM"); |
| 47 | aiff->form = url_ftell(pb); |
| 48 | put_be32(pb, 0); /* file length */ |
| 49 | put_tag(pb, aifc ? "AIFC" : "AIFF"); |
| 50 | |
| 51 | if (aifc) { // compressed audio |
| 52 | enc->bits_per_coded_sample = 16; |
| 53 | if (!enc->block_align) { |
| 54 | av_log(s, AV_LOG_ERROR, "block align not set\n"); |
| 55 | return -1; |
| 56 | } |
| 57 | /* Version chunk */ |
| 58 | put_tag(pb, "FVER"); |
| 59 | put_be32(pb, 4); |
| 60 | put_be32(pb, 0xA2805140); |
| 61 | } |
| 62 | |
| 63 | /* Common chunk */ |
| 64 | put_tag(pb, "COMM"); |
| 65 | put_be32(pb, aifc ? 24 : 18); /* size */ |
| 66 | put_be16(pb, enc->channels); /* Number of channels */ |
| 67 | |
| 68 | aiff->frames = url_ftell(pb); |
| 69 | put_be32(pb, 0); /* Number of frames */ |
| 70 | |
| 71 | if (!enc->bits_per_coded_sample) |
| 72 | enc->bits_per_coded_sample = av_get_bits_per_sample(enc->codec_id); |
| 73 | if (!enc->bits_per_coded_sample) { |
| 74 | av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n"); |
| 75 | return -1; |
| 76 | } |
| 77 | if (!enc->block_align) |
| 78 | enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3; |
| 79 | |
| 80 | put_be16(pb, enc->bits_per_coded_sample); /* Sample size */ |
| 81 | |
| 82 | sample_rate = av_dbl2ext((double)enc->sample_rate); |
| 83 | put_buffer(pb, (uint8_t*)&sample_rate, sizeof(sample_rate)); |
| 84 | |
| 85 | if (aifc) { |
| 86 | put_le32(pb, enc->codec_tag); |
| 87 | put_be16(pb, 0); |
| 88 | } |
nothing calls this directly
no test coverage detected