]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/apetag.c
avfilter: Constify all AVFilters
[ffmpeg] / libavformat / apetag.c
index 8cb3f4a23af41db978b402560592f61e65b67b9a..6f82fbe20262a8b24912018fcbbf63e7f10698bd 100644 (file)
@@ -79,25 +79,15 @@ static int ape_tag_read_field(AVFormatContext *s)
         av_dict_set(&st->metadata, key, filename, 0);
 
         if ((id = ff_guess_image2_codec(filename)) != AV_CODEC_ID_NONE) {
-            AVPacket pkt;
-            int ret;
-
-            ret = av_get_packet(s->pb, &pkt, size);
+            int ret = ff_add_attached_pic(s, st, s->pb, NULL, size);
             if (ret < 0) {
                 av_log(s, AV_LOG_ERROR, "Error reading cover art.\n");
                 return ret;
             }
-
-            st->disposition      |= AV_DISPOSITION_ATTACHED_PIC;
-            st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO;
             st->codecpar->codec_id   = id;
-
-            st->attached_pic              = pkt;
-            st->attached_pic.stream_index = st->index;
-            st->attached_pic.flags       |= AV_PKT_FLAG_KEY;
         } else {
-            if (ff_get_extradata(s, st->codecpar, s->pb, size) < 0)
-                return AVERROR(ENOMEM);
+            if ((ret = ff_get_extradata(s, st->codecpar, s->pb, size)) < 0)
+                return ret;
             st->codecpar->codec_type = AVMEDIA_TYPE_ATTACHMENT;
         }
     } else {
@@ -186,11 +176,11 @@ int ff_ape_write_tag(AVFormatContext *s)
 {
     AVDictionaryEntry *e = NULL;
     int size, ret, count = 0;
-    AVIOContext *dyn_bc = NULL;
-    uint8_t *dyn_buf = NULL;
+    AVIOContext *dyn_bc;
+    uint8_t *dyn_buf;
 
     if ((ret = avio_open_dyn_buf(&dyn_bc)) < 0)
-        goto end;
+        return ret;
 
     ff_standardize_creation_time(s);
     while ((e = av_dict_get(s->metadata, "", e, AV_DICT_IGNORE_SUFFIX))) {
@@ -211,7 +201,7 @@ int ff_ape_write_tag(AVFormatContext *s)
     if (!count)
         goto end;
 
-    size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
+    size = avio_get_dyn_buf(dyn_bc, &dyn_buf);
     if (size <= 0)
         goto end;
     size += APE_TAG_FOOTER_BYTES;
@@ -239,9 +229,7 @@ int ff_ape_write_tag(AVFormatContext *s)
     ffio_fill(s->pb, 0, 8);             // reserved
 
 end:
-    if (dyn_bc && !dyn_buf)
-        avio_close_dyn_buf(dyn_bc, &dyn_buf);
-    av_freep(&dyn_buf);
+    ffio_free_dyn_buf(&dyn_bc);
 
     return ret;
 }