avformat/mlvdec: read_string() received unsigned size, make the argument unsigned
[ffmpeg.git] / libavformat / ttaenc.c
index b05705b..d8e1136 100644 (file)
@@ -35,16 +35,17 @@ typedef struct TTAMuxContext {
     int last_frame;
 } TTAMuxContext;
 
-static int tta_write_header(AVFormatContext *s)
+static int tta_init(AVFormatContext *s)
 {
     TTAMuxContext *tta = s->priv_data;
-    AVCodecParameters *par = s->streams[0]->codecpar;
-    int ret;
+    AVCodecParameters *par;
 
     if (s->nb_streams != 1) {
         av_log(s, AV_LOG_ERROR, "Only one stream is supported\n");
         return AVERROR(EINVAL);
     }
+    par = s->streams[0]->codecpar;
+
     if (par->codec_id != AV_CODEC_ID_TTA) {
         av_log(s, AV_LOG_ERROR, "Unsupported codec\n");
         return AVERROR(EINVAL);
@@ -54,6 +55,23 @@ static int tta_write_header(AVFormatContext *s)
         return AVERROR_INVALIDDATA;
     }
 
+    /* Prevent overflow */
+    if (par->sample_rate > 0x7FFFFFu) {
+        av_log(s, AV_LOG_ERROR, "Sample rate too large\n");
+        return AVERROR(EINVAL);
+    }
+    tta->frame_size = par->sample_rate * 256 / 245;
+    avpriv_set_pts_info(s->streams[0], 64, 1, par->sample_rate);
+
+    return 0;
+}
+
+static int tta_write_header(AVFormatContext *s)
+{
+    TTAMuxContext *tta = s->priv_data;
+    AVCodecParameters *par = s->streams[0]->codecpar;
+    int ret;
+
     if ((ret = avio_open_dyn_buf(&tta->seek_table)) < 0)
         return ret;
 
@@ -66,13 +84,6 @@ static int tta_write_header(AVFormatContext *s)
     avio_wl16(s->pb, par->channels);
     avio_wl16(s->pb, par->bits_per_raw_sample);
     avio_wl32(s->pb, par->sample_rate);
-    /* Prevent overflow */
-    if (par->sample_rate > 0x7FFFFFu) {
-        av_log(s, AV_LOG_ERROR, "Sample rate too large\n");
-        return AVERROR(EINVAL);
-    }
-    tta->frame_size = par->sample_rate * 256 / 245;
-    avpriv_set_pts_info(s->streams[0], 64, 1, par->sample_rate);
 
     return 0;
 }
@@ -80,22 +91,13 @@ static int tta_write_header(AVFormatContext *s)
 static int tta_write_packet(AVFormatContext *s, AVPacket *pkt)
 {
     TTAMuxContext *tta = s->priv_data;
-    AVPacketList *pktl = av_mallocz(sizeof(*pktl));
     int ret;
 
-    if (!pktl)
-        return AVERROR(ENOMEM);
-
-    ret = av_packet_ref(&pktl->pkt, pkt);
+    ret = ff_packet_list_put(&tta->queue, &tta->queue_end, pkt,
+                             FF_PACKETLIST_FLAG_REF_PACKET);
     if (ret < 0) {
-        av_free(pktl);
         return ret;
     }
-    if (tta->queue_end)
-        tta->queue_end->next = pktl;
-    else
-        tta->queue = pktl;
-    tta->queue_end = pktl;
 
     avio_wl32(tta->seek_table, pkt->size);
     tta->nb_samples += pkt->duration;
@@ -120,16 +122,13 @@ static int tta_write_packet(AVFormatContext *s, AVPacket *pkt)
 static void tta_queue_flush(AVFormatContext *s)
 {
     TTAMuxContext *tta = s->priv_data;
-    AVPacketList *pktl;
-
-    while (pktl = tta->queue) {
-        AVPacket *pkt = &pktl->pkt;
-        avio_write(s->pb, pkt->data, pkt->size);
-        av_packet_unref(pkt);
-        tta->queue = pktl->next;
-        av_free(pktl);
+    AVPacket pkt;
+
+    while (tta->queue) {
+        ff_packet_list_get(&tta->queue, &tta->queue_end, &pkt);
+        avio_write(s->pb, pkt.data, pkt.size);
+        av_packet_unref(&pkt);
     }
-    tta->queue_end = NULL;
 }
 
 static int tta_write_trailer(AVFormatContext *s)
@@ -167,6 +166,7 @@ AVOutputFormat ff_tta_muxer = {
     .priv_data_size    = sizeof(TTAMuxContext),
     .audio_codec       = AV_CODEC_ID_TTA,
     .video_codec       = AV_CODEC_ID_NONE,
+    .init              = tta_init,
     .write_header      = tta_write_header,
     .write_packet      = tta_write_packet,
     .write_trailer     = tta_write_trailer,