]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/vividas.c
avformat/av1: Fix nits in the documentation of ff_av1_filter_obus_buf()
[ffmpeg] / libavformat / vividas.c
index a55f5c0eaddaa1907f105ae445e21f5066e647db..4f54a4302e1356632ede417351231a21045d0ddd 100644 (file)
@@ -52,6 +52,7 @@ typedef struct VIV_AudioSubpacket {
 typedef struct VividasDemuxContext {
     int n_sb_blocks;
     VIV_SB_block *sb_blocks;
+    int num_audio;
 
     uint32_t sb_key;
     int64_t sb_offset;
@@ -277,15 +278,13 @@ static uint8_t *read_sb_block(AVIOContext *src, unsigned *size,
 
 static int track_header(VividasDemuxContext *viv, AVFormatContext *s,  uint8_t *buf, int size)
 {
-    int i,j;
+    int i, j, ret;
     int64_t off;
     int val_1;
-    int num_video, num_audio;
-    AVIOContext *pb;
+    int num_video;
+    AVIOContext pb0, *pb = &pb0;
 
-    pb = avio_alloc_context(buf, size, 0, NULL, NULL, NULL, NULL);
-    if (!pb)
-        return AVERROR(ENOMEM);
+    ffio_init_context(pb, buf, size, 0, NULL, NULL, NULL, NULL);
 
     ffio_read_varlen(pb); // track_header_len
     avio_r8(pb); // '1'
@@ -311,11 +310,15 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s,  uint8_t *
     num_video = avio_r8(pb);
 
     avio_seek(pb, off, SEEK_SET);
-    if (num_video != 1)
-        av_log(s, AV_LOG_WARNING, "number of video tracks %d is not 1\n", num_video);
+    if (num_video != 1) {
+        av_log(s, AV_LOG_ERROR, "number of video tracks %d is not 1\n", num_video);
+        return AVERROR_PATCHWELCOME;
+    }
 
     for (i = 0; i < num_video; i++) {
         AVStream *st = avformat_new_stream(s, NULL);
+        if (!st)
+            return AVERROR(ENOMEM);
 
         st->id = i;
 
@@ -340,15 +343,17 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s,  uint8_t *
     off = avio_tell(pb);
     off += ffio_read_varlen(pb); // val_10
     avio_r8(pb); // '4'
-    num_audio = avio_r8(pb);
+    viv->num_audio = avio_r8(pb);
     avio_seek(pb, off, SEEK_SET);
 
-    if (num_audio != 1)
-        av_log(s, AV_LOG_WARNING, "number of audio tracks %d is not 1\n", num_audio);
+    if (viv->num_audio != 1)
+        av_log(s, AV_LOG_WARNING, "number of audio tracks %d is not 1\n", viv->num_audio);
 
-    for(i=0;i<num_audio;i++) {
+    for(i=0;i<viv->num_audio;i++) {
         int q;
         AVStream *st = avformat_new_stream(s, NULL);
+        if (!st)
+            return AVERROR(ENOMEM);
 
         st->id = num_video + i;
 
@@ -380,18 +385,15 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s,  uint8_t *
             for (j = 0; j < num_data; j++) {
                 uint64_t len = ffio_read_varlen(pb);
                 if (len > INT_MAX/2 - xd_size) {
-                    av_free(pb);
                     return AVERROR_INVALIDDATA;
                 }
                 data_len[j] = len;
                 xd_size += len;
             }
 
-            st->codecpar->extradata_size = 64 + xd_size + xd_size / 255;
-            if (ff_alloc_extradata(st->codecpar, st->codecpar->extradata_size)) {
-                av_free(pb);
-                return AVERROR(ENOMEM);
-            }
+            ret = ff_alloc_extradata(st->codecpar, 64 + xd_size + xd_size / 255);
+            if (ret < 0)
+                return ret;
 
             p = st->codecpar->extradata;
             p[0] = 2;
@@ -399,7 +401,6 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s,  uint8_t *
             for (j = 0; j < num_data - 1; j++) {
                 unsigned delta = av_xiphlacing(&p[offset], data_len[j]);
                 if (delta > data_len[j]) {
-                    av_free(pb);
                     return AVERROR_INVALIDDATA;
                 }
                 offset += delta;
@@ -420,7 +421,6 @@ static int track_header(VividasDemuxContext *viv, AVFormatContext *s,  uint8_t *
         }
     }
 
-    av_free(pb);
     return 0;
 }
 
@@ -429,13 +429,11 @@ static int track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *bu
     int64_t off;
     int64_t poff;
     int maxnp=0;
-    AVIOContext *pb;
+    AVIOContext pb0, *pb = &pb0;
     int i;
     int64_t filesize = avio_size(s->pb);
 
-    pb = avio_alloc_context(buf, size, 0, NULL, NULL, NULL, NULL);
-    if (!pb)
-        return AVERROR(ENOMEM);
+    ffio_init_context(pb, buf, size, 0, NULL, NULL, NULL, NULL);
 
     ffio_read_varlen(pb); // track_index_len
     avio_r8(pb); // 'c'
@@ -445,7 +443,6 @@ static int track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *bu
     viv->sb_blocks = av_calloc(viv->n_sb_blocks, sizeof(VIV_SB_block));
     if (!viv->sb_blocks) {
         viv->n_sb_blocks = 0;
-        av_free(pb);
         return AVERROR(ENOMEM);
     }
 
@@ -476,11 +473,9 @@ static int track_index(VividasDemuxContext *viv, AVFormatContext *s, uint8_t *bu
         goto error;
 
     viv->sb_entries = av_calloc(maxnp, sizeof(VIV_SB_entry));
-    av_free(pb);
 
     return 0;
 error:
-    av_free(pb);
     viv->n_sb_blocks = 0;
     av_freep(&viv->sb_blocks);
     return AVERROR_INVALIDDATA;
@@ -676,6 +671,9 @@ static int viv_read_packet(AVFormatContext *s,
     if (viv->sb_entries[viv->current_sb_entry].flag == 0) {
         uint64_t v_size = ffio_read_varlen(pb);
 
+        if (!viv->num_audio)
+            return AVERROR_INVALIDDATA;
+
         ffio_read_varlen(pb);
         if (v_size > INT_MAX)
             return AVERROR_INVALIDDATA;