Revision feb2440c libavformat/utils.c

View differences:

libavformat/utils.c
1879 1879
/* only usable for MPEG-PS streams */
1880 1880
static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset)
1881 1881
{
1882
    unsigned int nb_streams = ic->nb_streams;
1882 1883
    AVPacket pkt1, *pkt = &pkt1;
1883 1884
    AVStream *st;
1884 1885
    int read_size, i, ret;
1885
    int64_t end_time, start_time[MAX_STREAMS];
1886
    int64_t end_time, *start_time;
1886 1887
    int64_t filesize, offset, duration;
1887 1888
    int retry=0;
1888 1889

  
1890
    if (nb_streams >= INT_MAX/sizeof(*start_time) ||
1891
        !(start_time = av_malloc(nb_streams * sizeof(*start_time))))
1892
        return;
1893

  
1889 1894
    ic->cur_st = NULL;
1890 1895

  
1891 1896
    /* flush packet queue */
1892 1897
    flush_packet_queue(ic);
1893 1898

  
1894
    for(i=0;i<ic->nb_streams;i++) {
1899
    for (i=0; i<nb_streams; i++) {
1895 1900
        st = ic->streams[i];
1896 1901
        if(st->start_time != AV_NOPTS_VALUE){
1897 1902
            start_time[i]= st->start_time;
......
1946 1951
    }while(   end_time==AV_NOPTS_VALUE
1947 1952
           && filesize > (DURATION_MAX_READ_SIZE<<retry)
1948 1953
           && ++retry <= DURATION_MAX_RETRY);
1954
    av_free(start_time);
1949 1955

  
1950 1956
    fill_all_stream_timings(ic);
1951 1957

  
1952 1958
    url_fseek(ic->pb, old_offset, SEEK_SET);
1953
    for(i=0; i<ic->nb_streams; i++){
1959
    for (i=0; i<nb_streams; i++) {
1954 1960
        st= ic->streams[i];
1955 1961
        st->cur_dts= st->first_dts;
1956 1962
        st->last_IP_pts = AV_NOPTS_VALUE;
......
2172 2178
    AVStream *st;
2173 2179
    AVPacket pkt1, *pkt;
2174 2180
    int64_t old_offset = url_ftell(ic->pb);
2181
    unsigned int nb_streams = ic->nb_streams;
2175 2182
    struct {
2176 2183
        int64_t last_dts;
2177 2184
        int64_t duration_gcd;
2178 2185
        int duration_count;
2179 2186
        double duration_error[MAX_STD_TIMEBASES];
2180 2187
        int64_t codec_info_duration;
2181
    } info[MAX_STREAMS] = {{0}};
2188
    } *info, *tmp_info;
2189

  
2190
    if (ic->nb_streams >= INT_MAX/sizeof(*info) ||
2191
        !(info = av_mallocz(ic->nb_streams * sizeof(*info))))
2192
        return AVERROR(ENOMEM);
2182 2193

  
2183 2194
    for(i=0;i<ic->nb_streams;i++) {
2184 2195
        AVCodec *codec;
......
2218 2229
        }
2219 2230
    }
2220 2231

  
2221
    for(i=0;i<MAX_STREAMS;i++){
2232
    for (i=0; i<ic->nb_streams; i++) {
2222 2233
        info[i].last_dts= AV_NOPTS_VALUE;
2223 2234
    }
2224 2235

  
......
2266 2277
        /* NOTE: a new stream can be added there if no header in file
2267 2278
           (AVFMTCTX_NOHEADER) */
2268 2279
        ret = av_read_frame_internal(ic, &pkt1);
2269
        if(ret == AVERROR(EAGAIN))
2270
            continue;
2271
        if (ret < 0) {
2280
        if (ret < 0 && ret != AVERROR(EAGAIN)) {
2272 2281
            /* EOF or error */
2273 2282
            ret = -1; /* we could not have all the codec parameters before EOF */
2274 2283
            for(i=0;i<ic->nb_streams;i++) {
......
2284 2293
            break;
2285 2294
        }
2286 2295

  
2296
        if (ic->nb_streams > nb_streams) {
2297
            if (ic->nb_streams >= INT_MAX/sizeof(*info) ||
2298
                !(tmp_info = av_realloc(info, ic->nb_streams*sizeof(*info)))) {
2299
                av_free(info);
2300
                return AVERROR(ENOMEM);
2301
            }
2302
            info = tmp_info;
2303
            memset(info + nb_streams, 0, (ic->nb_streams - nb_streams) * sizeof(*info));
2304
            nb_streams = ic->nb_streams;
2305
        }
2306

  
2307
        if (ret == AVERROR(EAGAIN))
2308
            continue;
2309

  
2287 2310
        pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1, &ic->packet_buffer_end);
2288 2311
        if(av_dup_packet(pkt) < 0) {
2312
            av_free(info);
2289 2313
            return AVERROR(ENOMEM);
2290 2314
        }
2291 2315

  
......
2434 2458
    }
2435 2459
#endif
2436 2460

  
2461
    av_free(info);
2437 2462
    return ret;
2438 2463
}
2439 2464

  

Also available in: Unified diff