]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/avidec.c
avcodec: remove pointless lowres deprecation wrappers
[ffmpeg] / libavformat / avidec.c
index 33e50e98782f4fc6b6c6defef8f1a9bd0436327e..547eb63b1b92084a375d8096daa1ccba8d1214ce 100644 (file)
@@ -110,6 +110,15 @@ static const char avi_headers[][8] = {
 
 static const AVMetadataConv avi_metadata_conv[] = {
     { "strn", "title" },
+    { "isbj", "subject" },
+    { "inam", "title" },
+    { "iart", "artist" },
+    { "icop", "copyright" },
+    { "icmt", "comment" },
+    { "ignr", "genre" },
+    { "iprd", "product" },
+    { "isft", "software" },
+
     { 0 },
 };
 
@@ -126,7 +135,7 @@ static inline int get_duration(AVIStream *ast, int len)
     if (ast->sample_size)
         return len;
     else if (ast->dshow_block_align)
-        return (len + ast->dshow_block_align - 1) / ast->dshow_block_align;
+        return (len + (int64_t)ast->dshow_block_align - 1) / ast->dshow_block_align;
     else
         return 1;
 }
@@ -272,7 +281,7 @@ static void clean_index(AVFormatContext *s)
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st   = s->streams[i];
         AVIStream *ast = st->priv_data;
-        int n          = st->nb_index_entries;
+        int n          = st->internal->nb_index_entries;
         int max        = ast->sample_size;
         int64_t pos, size, ts;
 
@@ -282,9 +291,9 @@ static void clean_index(AVFormatContext *s)
         while (max < 1024)
             max += max;
 
-        pos  = st->index_entries[0].pos;
-        size = st->index_entries[0].size;
-        ts   = st->index_entries[0].timestamp;
+        pos  = st->internal->index_entries[0].pos;
+        size = st->internal->index_entries[0].size;
+        ts   = st->internal->index_entries[0].timestamp;
 
         for (j = 0; j < size; j += max)
             av_add_index_entry(st, pos + j, ts + j, FFMIN(max, size - j), 0,
@@ -432,12 +441,12 @@ static int calculate_bitrate(AVFormatContext *s)
         int64_t len = 0;
         AVStream *st = s->streams[i];
 
-        if (!st->nb_index_entries)
+        if (!st->internal->nb_index_entries)
             continue;
 
-        for (j = 0; j < st->nb_index_entries; j++)
-            len += st->index_entries[j].size;
-        maxpos = FFMAX(maxpos, st->index_entries[j-1].pos);
+        for (j = 0; j < st->internal->nb_index_entries; j++)
+            len += st->internal->index_entries[j].size;
+        maxpos = FFMAX(maxpos, st->internal->index_entries[j-1].pos);
         lensum += len;
     }
     if (maxpos < av_rescale(avi->io_fsize, 9, 10)) // index does not cover the whole file
@@ -451,12 +460,12 @@ static int calculate_bitrate(AVFormatContext *s)
         int64_t duration;
         int64_t bitrate;
 
-        for (j = 0; j < st->nb_index_entries; j++)
-            len += st->index_entries[j].size;
+        for (j = 0; j < st->internal->nb_index_entries; j++)
+            len += st->internal->index_entries[j].size;
 
-        if (st->nb_index_entries < 2 || st->codecpar->bit_rate > 0)
+        if (st->internal->nb_index_entries < 2 || st->codecpar->bit_rate > 0)
             continue;
-        duration = st->index_entries[j-1].timestamp - st->index_entries[0].timestamp;
+        duration = st->internal->index_entries[j-1].timestamp - st->internal->index_entries[0].timestamp;
         bitrate = av_rescale(8*len, st->time_base.den, duration * st->time_base.num);
         if (bitrate > 0) {
             st->codecpar->bit_rate = bitrate;
@@ -901,7 +910,7 @@ static int avi_read_header(AVFormatContext *s)
                     break;
                 case AVMEDIA_TYPE_SUBTITLE:
                     st->codecpar->codec_type = AVMEDIA_TYPE_SUBTITLE;
-                    st->request_probe= 1;
+                    st->internal->request_probe= 1;
                     avio_skip(pb, size);
                     break;
                 default:
@@ -979,6 +988,14 @@ static int avi_read_header(AVFormatContext *s)
             avio_skip(pb, size);
             break;
         case MKTAG('s', 't', 'r', 'n'):
+        case MKTAG('i', 's', 'b', 'j'):
+        case MKTAG('i', 'n', 'a', 'm'):
+        case MKTAG('i', 'a', 'r', 't'):
+        case MKTAG('i', 'c', 'o', 'p'):
+        case MKTAG('i', 'c', 'm', 't'):
+        case MKTAG('i', 'g', 'n', 'r'):
+        case MKTAG('i', 'p', 'o', 'd'):
+        case MKTAG('i', 's', 'o', 'f'):
             if (s->nb_streams) {
                 ret = avi_read_tag(s, s->streams[s->nb_streams - 1], tag, size);
                 if (ret < 0)
@@ -1034,7 +1051,7 @@ end_of_header:
 
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
-        if (st->nb_index_entries)
+        if (st->internal->nb_index_entries)
             break;
     }
     // DV-in-AVI cannot be non-interleaved, if set this must be
@@ -1320,8 +1337,8 @@ start_sync:
 
                 if (size) {
                     uint64_t pos = avio_tell(pb) - 8;
-                    if (!st->index_entries || !st->nb_index_entries ||
-                        st->index_entries[st->nb_index_entries - 1].pos < pos) {
+                    if (!st->internal->index_entries || !st->internal->nb_index_entries ||
+                        st->internal->index_entries[st->internal->nb_index_entries - 1].pos < pos) {
                         av_add_index_entry(st, pos, ast->frame_offset, size,
                                            0, AVINDEX_KEYFRAME);
                     }
@@ -1351,10 +1368,10 @@ static int ni_prepare_read(AVFormatContext *s)
         int64_t ts     = ast->frame_offset;
         int64_t last_ts;
 
-        if (!st->nb_index_entries)
+        if (!st->internal->nb_index_entries)
             continue;
 
-        last_ts = st->index_entries[st->nb_index_entries - 1].timestamp;
+        last_ts = st->internal->index_entries[st->internal->nb_index_entries - 1].timestamp;
         if (!ast->remaining && ts > last_ts)
             continue;
 
@@ -1383,11 +1400,11 @@ static int ni_prepare_read(AVFormatContext *s)
     } else {
         i = av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY);
         if (i >= 0)
-            best_ast->frame_offset = best_st->index_entries[i].timestamp;
+            best_ast->frame_offset = best_st->internal->index_entries[i].timestamp;
     }
 
     if (i >= 0) {
-        int64_t pos = best_st->index_entries[i].pos;
+        int64_t pos = best_st->internal->index_entries[i].pos;
         pos += best_ast->packet_size - best_ast->remaining;
         if (avio_seek(s->pb, pos + 8, SEEK_SET) < 0)
           return AVERROR_EOF;
@@ -1397,7 +1414,7 @@ static int ni_prepare_read(AVFormatContext *s)
         avi->stream_index = best_stream_index;
         if (!best_ast->remaining)
             best_ast->packet_size =
-            best_ast->remaining   = best_st->index_entries[i].size;
+            best_ast->remaining   = best_st->internal->index_entries[i].size;
     }
     else
         return AVERROR_EOF;
@@ -1429,6 +1446,7 @@ resync:
     if (avi->stream_index >= 0) {
         AVStream *st   = s->streams[avi->stream_index];
         AVIStream *ast = st->priv_data;
+        int dv_demux = CONFIG_DV_DEMUXER && avi->dv_demux;
         int size, err;
 
         if (get_subtitle_pkt(s, st, pkt))
@@ -1451,7 +1469,7 @@ resync:
             return err;
         size = err;
 
-        if (ast->has_pal && pkt->size < (unsigned)INT_MAX / 2) {
+        if (ast->has_pal && pkt->size < (unsigned)INT_MAX / 2 && !dv_demux) {
             uint8_t *pal;
             pal = av_packet_new_side_data(pkt,
                                           AV_PKT_DATA_PALETTE,
@@ -1465,7 +1483,7 @@ resync:
             }
         }
 
-        if (CONFIG_DV_DEMUXER && avi->dv_demux) {
+        if (CONFIG_DV_DEMUXER && dv_demux) {
             AVBufferRef *avbuf = pkt->buf;
             size = avpriv_dv_produce_packet(avi->dv_demux, pkt,
                                             pkt->data, pkt->size, pkt->pos);
@@ -1487,15 +1505,15 @@ resync:
                 pkt->dts /= ast->sample_size;
             pkt->stream_index = avi->stream_index;
 
-            if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->index_entries) {
+            if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO && st->internal->index_entries) {
                 AVIndexEntry *e;
                 int index;
 
                 index = av_index_search_timestamp(st, ast->frame_offset, AVSEEK_FLAG_ANY);
-                e     = &st->index_entries[index];
+                e     = &st->internal->index_entries[index];
 
                 if (index >= 0 && e->timestamp == ast->frame_offset) {
-                    if (index == st->nb_index_entries-1) {
+                    if (index == st->internal->nb_index_entries-1) {
                         int key=1;
                         uint32_t state=-1;
                         if (st->codecpar->codec_id == AV_CODEC_ID_MPEG4) {
@@ -1531,7 +1549,7 @@ resync:
         }
         ast->seek_pos= 0;
 
-        if (!avi->non_interleaved && st->nb_index_entries>1 && avi->index_loaded>1) {
+        if (!avi->non_interleaved && st->internal->nb_index_entries>1 && avi->index_loaded>1) {
             int64_t dts= av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q);
 
             if (avi->dts_max < dts) {
@@ -1631,8 +1649,8 @@ static int avi_read_idx1(AVFormatContext *s, int size)
     if (!anykey) {
         for (index = 0; index < s->nb_streams; index++) {
             st = s->streams[index];
-            if (st->nb_index_entries)
-                st->index_entries[0].flags |= AVINDEX_KEYFRAME;
+            if (st->internal->nb_index_entries)
+                st->internal->index_entries[0].flags |= AVINDEX_KEYFRAME;
         }
     }
     return 0;
@@ -1657,16 +1675,16 @@ static int check_stream_max_drift(AVFormatContext *s)
         for (i = 0; i < s->nb_streams; i++) {
             AVStream *st = s->streams[i];
             AVIStream *ast = st->priv_data;
-            int n = st->nb_index_entries;
-            while (idx[i] < n && st->index_entries[idx[i]].pos < pos)
+            int n = st->internal->nb_index_entries;
+            while (idx[i] < n && st->internal->index_entries[idx[i]].pos < pos)
                 idx[i]++;
             if (idx[i] < n) {
                 int64_t dts;
-                dts = av_rescale_q(st->index_entries[idx[i]].timestamp /
+                dts = av_rescale_q(st->internal->index_entries[idx[i]].timestamp /
                                    FFMAX(ast->sample_size, 1),
                                    st->time_base, AV_TIME_BASE_Q);
                 min_dts = FFMIN(min_dts, dts);
-                min_pos = FFMIN(min_pos, st->index_entries[idx[i]].pos);
+                min_pos = FFMIN(min_pos, st->internal->index_entries[idx[i]].pos);
             }
         }
         for (i = 0; i < s->nb_streams; i++) {
@@ -1674,18 +1692,19 @@ static int check_stream_max_drift(AVFormatContext *s)
             AVIStream *ast = st->priv_data;
 
             if (idx[i] && min_dts != INT64_MAX / 2) {
-                int64_t dts;
-                dts = av_rescale_q(st->index_entries[idx[i] - 1].timestamp /
+                int64_t dts, delta_dts;
+                dts = av_rescale_q(st->internal->index_entries[idx[i] - 1].timestamp /
                                    FFMAX(ast->sample_size, 1),
                                    st->time_base, AV_TIME_BASE_Q);
+                delta_dts = av_sat_sub64(dts, min_dts);
                 max_dts = FFMAX(max_dts, dts);
                 max_buffer = FFMAX(max_buffer,
-                                   av_rescale(dts - min_dts,
+                                   av_rescale(delta_dts,
                                               st->codecpar->bit_rate,
                                               AV_TIME_BASE));
             }
         }
-        if (max_dts - min_dts > 2 * AV_TIME_BASE ||
+        if (av_sat_sub64(max_dts, min_dts) > 2 * AV_TIME_BASE ||
             max_buffer > 1024 * 1024 * 8 * 8) {
             av_free(idx);
             return 1;
@@ -1704,30 +1723,30 @@ static int guess_ni_flag(AVFormatContext *s)
 
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st = s->streams[i];
-        int n        = st->nb_index_entries;
+        int n        = st->internal->nb_index_entries;
         unsigned int size;
 
         if (n <= 0)
             continue;
 
         if (n >= 2) {
-            int64_t pos = st->index_entries[0].pos;
+            int64_t pos = st->internal->index_entries[0].pos;
             unsigned tag[2];
             avio_seek(s->pb, pos, SEEK_SET);
             tag[0] = avio_r8(s->pb);
             tag[1] = avio_r8(s->pb);
             avio_rl16(s->pb);
             size = avio_rl32(s->pb);
-            if (get_stream_idx(tag) == i && pos + size > st->index_entries[1].pos)
+            if (get_stream_idx(tag) == i && pos + size > st->internal->index_entries[1].pos)
                 last_start = INT64_MAX;
-            if (get_stream_idx(tag) == i && size == st->index_entries[0].size + 8)
+            if (get_stream_idx(tag) == i && size == st->internal->index_entries[0].size + 8)
                 last_start = INT64_MAX;
         }
 
-        if (st->index_entries[0].pos > last_start)
-            last_start = st->index_entries[0].pos;
-        if (st->index_entries[n - 1].pos < first_end)
-            first_end = st->index_entries[n - 1].pos;
+        if (st->internal->index_entries[0].pos > last_start)
+            last_start = st->internal->index_entries[0].pos;
+        if (st->internal->index_entries[n - 1].pos < first_end)
+            first_end = st->internal->index_entries[n - 1].pos;
     }
     avio_seek(s->pb, oldpos, SEEK_SET);
 
@@ -1815,20 +1834,20 @@ static int avi_read_seek(AVFormatContext *s, int stream_index,
                                       timestamp * FFMAX(ast->sample_size, 1),
                                       flags);
     if (index < 0) {
-        if (st->nb_index_entries > 0)
+        if (st->internal->nb_index_entries > 0)
             av_log(s, AV_LOG_DEBUG, "Failed to find timestamp %"PRId64 " in index %"PRId64 " .. %"PRId64 "\n",
                    timestamp * FFMAX(ast->sample_size, 1),
-                   st->index_entries[0].timestamp,
-                   st->index_entries[st->nb_index_entries - 1].timestamp);
+                   st->internal->index_entries[0].timestamp,
+                   st->internal->index_entries[st->internal->nb_index_entries - 1].timestamp);
         return AVERROR_INVALIDDATA;
     }
 
     /* find the position */
-    pos       = st->index_entries[index].pos;
-    timestamp = st->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);
+    pos       = st->internal->index_entries[index].pos;
+    timestamp = st->internal->index_entries[index].timestamp / FFMAX(ast->sample_size, 1);
 
     av_log(s, AV_LOG_TRACE, "XX %"PRId64" %d %"PRId64"\n",
-            timestamp, index, st->index_entries[index].timestamp);
+            timestamp, index, st->internal->index_entries[index].timestamp);
 
     if (CONFIG_DV_DEMUXER && avi->dv_demux) {
         /* One and only one real stream for DV in AVI, and it has video  */
@@ -1859,7 +1878,7 @@ static int avi_read_seek(AVFormatContext *s, int stream_index,
             continue;
         }
 
-        if (st2->nb_index_entries <= 0)
+        if (st2->internal->nb_index_entries <= 0)
             continue;
 
 //        av_assert1(st2->codecpar->block_align);
@@ -1873,14 +1892,14 @@ static int avi_read_seek(AVFormatContext *s, int stream_index,
                                           (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
         if (index < 0)
             index = 0;
-        ast2->seek_pos = st2->index_entries[index].pos;
+        ast2->seek_pos = st2->internal->index_entries[index].pos;
         pos_min = FFMIN(pos_min,ast2->seek_pos);
     }
     for (i = 0; i < s->nb_streams; i++) {
         AVStream *st2 = s->streams[i];
         AVIStream *ast2 = st2->priv_data;
 
-        if (ast2->sub_ctx || st2->nb_index_entries <= 0)
+        if (ast2->sub_ctx || st2->internal->nb_index_entries <= 0)
             continue;
 
         index = av_index_search_timestamp(
@@ -1889,9 +1908,9 @@ static int avi_read_seek(AVFormatContext *s, int stream_index,
                 flags | AVSEEK_FLAG_BACKWARD | (st2->codecpar->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0));
         if (index < 0)
             index = 0;
-        while (!avi->non_interleaved && index>0 && st2->index_entries[index-1].pos >= pos_min)
+        while (!avi->non_interleaved && index>0 && st2->internal->index_entries[index-1].pos >= pos_min)
             index--;
-        ast2->frame_offset = st2->index_entries[index].timestamp;
+        ast2->frame_offset = st2->internal->index_entries[index].timestamp;
     }
 
     /* do the seek */