#include "libavutil/intfloat.h"
#include "libavutil/opt.h"
+#include "libavcodec/packet_internal.h"
#include "avformat.h"
#include "internal.h"
#include "aiff.h"
int64_t frames;
int64_t ssnd;
int audio_stream_idx;
- AVPacketList *pict_list;
+ PacketList *pict_list, *pict_list_end;
int write_id3v2;
int id3v2_version;
} AIFFOutputContext;
uint64_t pos, end, size;
ID3v2EncContext id3v2 = { 0 };
AVIOContext *pb = s->pb;
- AVPacketList *pict_list = aiff->pict_list;
+ PacketList *pict_list = aiff->pict_list;
- if (!pb->seekable & AVIO_SEEKABLE_NORMAL)
- return 0;
-
- if (!s->metadata && !aiff->pict_list)
+ if (!s->metadata && !s->nb_chapters && !aiff->pict_list)
return 0;
avio_wl32(pb, MKTAG('I', 'D', '3', ' '));
/* First verify if format is ok */
if (!par->codec_tag)
- return -1;
+ return AVERROR(EINVAL);
if (par->codec_tag != MKTAG('N','O','N','E'))
aifc = 1;
if (aifc) { // compressed audio
if (!par->block_align) {
av_log(s, AV_LOG_ERROR, "block align not set\n");
- return -1;
+ return AVERROR(EINVAL);
}
/* Version chunk */
ffio_wfourcc(pb, "FVER");
par->bits_per_coded_sample = av_get_bits_per_sample(par->codec_id);
if (!par->bits_per_coded_sample) {
av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n");
- return -1;
+ return AVERROR(EINVAL);
}
if (!par->block_align)
par->block_align = (par->bits_per_coded_sample * par->channels) >> 3;
avpriv_set_pts_info(s->streams[aiff->audio_stream_idx], 64, 1,
s->streams[aiff->audio_stream_idx]->codecpar->sample_rate);
- /* Data is starting here */
- avio_flush(pb);
-
return 0;
}
if (pkt->stream_index == aiff->audio_stream_idx)
avio_write(pb, pkt->data, pkt->size);
else {
- int ret;
- AVPacketList *pict_list, *last;
-
- if (s->streams[pkt->stream_index]->codecpar->codec_type != AVMEDIA_TYPE_VIDEO)
- return 0;
-
/* warn only once for each stream */
if (s->streams[pkt->stream_index]->nb_frames == 1) {
av_log(s, AV_LOG_WARNING, "Got more than one picture in stream %d,"
if (s->streams[pkt->stream_index]->nb_frames >= 1)
return 0;
- pict_list = av_mallocz(sizeof(AVPacketList));
- if (!pict_list)
- return AVERROR(ENOMEM);
-
- ret = av_packet_ref(&pict_list->pkt, pkt);
- if (ret < 0) {
- av_freep(&pict_list);
- return ret;
- }
-
- if (!aiff->pict_list)
- aiff->pict_list = pict_list;
- else {
- last = aiff->pict_list;
- while (last->next)
- last = last->next;
- last->next = pict_list;
- }
+ return avpriv_packet_list_put(&aiff->pict_list, &aiff->pict_list_end,
+ pkt, av_packet_ref, 0);
}
return 0;
static int aiff_write_trailer(AVFormatContext *s)
{
- int ret;
+ int ret = 0;
AVIOContext *pb = s->pb;
AIFFOutputContext *aiff = s->priv_data;
- AVPacketList *pict_list = aiff->pict_list;
AVCodecParameters *par = s->streams[aiff->audio_stream_idx]->codecpar;
/* Chunks sizes must be even */
- int64_t file_size, end_size;
- end_size = file_size = avio_tell(pb);
- if (file_size & 1) {
+ int64_t file_size, data_size;
+ data_size = avio_tell(pb);
+ if (data_size & 1)
avio_w8(pb, 0);
- end_size++;
- }
if (s->pb->seekable & AVIO_SEEKABLE_NORMAL) {
- /* Number of sample frames */
- avio_seek(pb, aiff->frames, SEEK_SET);
- avio_wb32(pb, (file_size - aiff->ssnd - 12) / par->block_align);
-
- /* Sound Data chunk size */
- avio_seek(pb, aiff->ssnd, SEEK_SET);
- avio_wb32(pb, file_size - aiff->ssnd - 4);
-
- /* return to the end */
- avio_seek(pb, end_size, SEEK_SET);
-
/* Write ID3 tags */
if (aiff->write_id3v2)
if ((ret = put_id3v2_tags(s, aiff)) < 0)
avio_seek(pb, aiff->form, SEEK_SET);
avio_wb32(pb, file_size - aiff->form - 4);
- avio_flush(pb);
- }
+ /* Number of sample frames */
+ avio_seek(pb, aiff->frames, SEEK_SET);
+ avio_wb32(pb, (data_size - aiff->ssnd - 12) / par->block_align);
- while (pict_list) {
- AVPacketList *next = pict_list->next;
- av_packet_unref(&pict_list->pkt);
- av_freep(&pict_list);
- pict_list = next;
+ /* Sound Data chunk size */
+ avio_seek(pb, aiff->ssnd, SEEK_SET);
+ avio_wb32(pb, data_size - aiff->ssnd - 4);
}
- return 0;
+ return ret;
+}
+
+static void aiff_deinit(AVFormatContext *s)
+{
+ AIFFOutputContext *aiff = s->priv_data;
+
+ avpriv_packet_list_free(&aiff->pict_list, &aiff->pict_list_end);
}
#define OFFSET(x) offsetof(AIFFOutputContext, x)
.version = LIBAVUTIL_VERSION_INT,
};
-AVOutputFormat ff_aiff_muxer = {
+const AVOutputFormat ff_aiff_muxer = {
.name = "aiff",
.long_name = NULL_IF_CONFIG_SMALL("Audio IFF"),
.mime_type = "audio/aiff",
.write_header = aiff_write_header,
.write_packet = aiff_write_packet,
.write_trailer = aiff_write_trailer,
- .codec_tag = (const AVCodecTag* const []){ ff_codec_aiff_tags, 0 },
+ .deinit = aiff_deinit,
+ .codec_tag = ff_aiff_codec_tags_list,
.priv_class = &aiff_muxer_class,
};