~ubuntu-branches/ubuntu/vivid/libav/vivid

« back to all changes in this revision

Viewing changes to libavformat/avidec.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2014-05-08 21:40:28 UTC
  • mfrom: (1.3.41 sid)
  • Revision ID: package-import@ubuntu.com-20140508214028-xuainxb1ibzt9lbg
Tags: 6:9.13-1ubuntu1
* Merge from unstable, remaining changes:
  - build-depend on libtiff5-dev rather than libtiff4-dev,
    avoids FTBFS caused by imlib
* New release fixes security issues LP: #1277173

Show diffs side-by-side

added added

removed removed

Lines of Context:
732
732
    if(!avi->index_loaded && pb->seekable)
733
733
        avi_load_index(s);
734
734
    avi->index_loaded = 1;
735
 
    avi->non_interleaved |= guess_ni_flag(s);
 
735
 
 
736
    if ((ret = guess_ni_flag(s)) < 0)
 
737
        return ret;
 
738
 
 
739
    avi->non_interleaved |= ret;
736
740
    for(i=0; i<s->nb_streams; i++){
737
741
        AVStream *st = s->streams[i];
738
742
        if(st->nb_index_entries)
1204
1208
    return 0;
1205
1209
}
1206
1210
 
 
1211
/* Scan the index and consider any file with streams more than
 
1212
 * 2 seconds or 64MB apart non-interleaved. */
 
1213
static int check_stream_max_drift(AVFormatContext *s)
 
1214
{
 
1215
    int64_t min_pos, pos;
 
1216
    int i;
 
1217
    int *idx = av_mallocz_array(s->nb_streams, sizeof(*idx));
 
1218
    if (!idx)
 
1219
        return AVERROR(ENOMEM);
 
1220
 
 
1221
    for (min_pos = pos = 0; min_pos != INT64_MAX; pos = min_pos + 1LU) {
 
1222
        int64_t max_dts = INT64_MIN / 2;
 
1223
        int64_t min_dts = INT64_MAX / 2;
 
1224
        int64_t max_buffer = 0;
 
1225
 
 
1226
        min_pos = INT64_MAX;
 
1227
 
 
1228
        for (i = 0; i < s->nb_streams; i++) {
 
1229
            AVStream *st = s->streams[i];
 
1230
            AVIStream *ast = st->priv_data;
 
1231
            int n = st->nb_index_entries;
 
1232
            while (idx[i] < n && st->index_entries[idx[i]].pos < pos)
 
1233
                idx[i]++;
 
1234
            if (idx[i] < n) {
 
1235
                int64_t dts;
 
1236
                dts = av_rescale_q(st->index_entries[idx[i]].timestamp /
 
1237
                                   FFMAX(ast->sample_size, 1),
 
1238
                                   st->time_base, AV_TIME_BASE_Q);
 
1239
                min_dts = FFMIN(min_dts, dts);
 
1240
                min_pos = FFMIN(min_pos, st->index_entries[idx[i]].pos);
 
1241
            }
 
1242
        }
 
1243
        for (i = 0; i < s->nb_streams; i++) {
 
1244
            AVStream *st = s->streams[i];
 
1245
            AVIStream *ast = st->priv_data;
 
1246
 
 
1247
            if (idx[i] && min_dts != INT64_MAX / 2) {
 
1248
                int64_t dts;
 
1249
                dts = av_rescale_q(st->index_entries[idx[i] - 1].timestamp /
 
1250
                                   FFMAX(ast->sample_size, 1),
 
1251
                                   st->time_base, AV_TIME_BASE_Q);
 
1252
                max_dts = FFMAX(max_dts, dts);
 
1253
                max_buffer = FFMAX(max_buffer,
 
1254
                                   av_rescale(dts - min_dts,
 
1255
                                              st->codec->bit_rate,
 
1256
                                              AV_TIME_BASE));
 
1257
            }
 
1258
        }
 
1259
        if (max_dts - min_dts > 2 * AV_TIME_BASE ||
 
1260
            max_buffer > 1024 * 1024 * 8 * 8) {
 
1261
            av_free(idx);
 
1262
            return 1;
 
1263
        }
 
1264
    }
 
1265
    av_free(idx);
 
1266
    return 0;
 
1267
}
 
1268
 
1207
1269
static int guess_ni_flag(AVFormatContext *s){
1208
1270
    int i;
1209
1271
    int64_t last_start=0;
1232
1294
            first_end= st->index_entries[n-1].pos;
1233
1295
    }
1234
1296
    avio_seek(s->pb, oldpos, SEEK_SET);
1235
 
    return last_start > first_end;
 
1297
 
 
1298
    if (last_start > first_end)
 
1299
        return 1;
 
1300
 
 
1301
    return check_stream_max_drift(s);
1236
1302
}
1237
1303
 
1238
1304
static int avi_load_index(AVFormatContext *s)