[FFmpeg-devel] [PATCH] hls demuxer: add option to defer parsing of variants

Rainer Hochecker rainer.hochecker at googlemail.com
Sun Nov 26 11:22:28 EET 2017


>> +    /*
>> +     * If this is a live stream and this playlist looks like it is one segment
>> +     * behind, try to sync it up so that every substream starts at the same
>> +     * time position (so e.g. avformat_find_stream_info() will see packets from
>> +     * all active streams within the first few seconds). This is not very generic,
>> +     * though, as the sequence numbers are technically independent.
>> +     */
>> +    highest_cur_seq_no = 0;
>> +    for (i = 0; i < c->n_playlists; i++) {
>> +        struct playlist *pls = c->playlists[i];
>> +        if (!pls->parsed)
>> +            continue;
>> +        if (pls->cur_seq_no > highest_cur_seq_no)
>> +            highest_cur_seq_no = pls->cur_seq_no;
>> +    }
>> +    if (!pls->finished && pls->cur_seq_no == highest_cur_seq_no - 1 &&
>> +        highest_cur_seq_no < pls->start_seq_no + pls->n_segments) {
>> +        pls->cur_seq_no = highest_cur_seq_no;
>> +    }
>> +
>> +    pls->read_buffer = av_malloc(INITIAL_BUFFER_SIZE);
>> +    if (!pls->read_buffer){
>> +        ret = AVERROR(ENOMEM);
>> +        avformat_free_context(pls->ctx);
>> +        pls->ctx = NULL;
>> +        return ret;
>> +    }
>> +    ffio_init_context(&pls->pb, pls->read_buffer, INITIAL_BUFFER_SIZE, 0, pls,
>> +                      read_data, NULL, NULL);
>> +    pls->pb.seekable = 0;
>> +    ret = av_probe_input_buffer(&pls->pb, &in_fmt, pls->segments[0]->url,
>> +                                NULL, 0, 0);
>> +    if (ret < 0) {
>> +        /* Free the ctx - it isn't initialized properly at this point,
>> +         * so avformat_close_input shouldn't be called. If
>> +         * avformat_open_input fails below, it frees and zeros the
>> +         * context, so it doesn't need any special treatment like this. */
>> +        av_log(c->ctx, AV_LOG_ERROR, "Error when loading first segment '%s'\n", pls->segments[0]->url);
>> +        avformat_free_context(pls->ctx);
>> +        pls->ctx = NULL;
>> +        return ret;
> Is that pls->read_buffer will memleak?
>
>

yes, looks like this. this is already an issue in current code.
nevertheless, I will fix it here.


More information about the ffmpeg-devel mailing list