[FFmpeg-devel] [PATCH] Playlist API

Geza Kovacs gkovacs
Thu Sep 3 22:17:01 CEST 2009


On 09/03/2009 05:43 AM, Michael Niedermayer wrote:
> On Sat, Aug 29, 2009 at 04:29:50PM -0700, Geza Kovacs wrote:
> 
> [...]
>> +int av_playlist_insert_item(AVPlaylistContext *ctx, const char *itempath, int pos)
>> +{
>> +    int i, itempath_len;
>> +    int64_t *durations_tmp;
>> +    unsigned int *nb_streams_list_tmp;
>> +    AVFormatContext **formatcontext_list_tmp;
>> +    char **flist_tmp;
>> +    AVFormatContext *ic;
>> +    ++ctx->pelist_size;
>> +    flist_tmp = av_realloc(ctx->flist, sizeof(*(ctx->flist)) * ctx->pelist_size);
>> +    if (!flist_tmp) {
>> +        av_log(NULL, AV_LOG_ERROR,
>> +               "av_realloc error for flist in av_playlist_insert_item\n");
>> +        return AVERROR_NOMEM;
>> +    } else
>> +        ctx->flist = flist_tmp;
>> +    durations_tmp = av_realloc(ctx->durations,
>> +                               sizeof(*(ctx->durations)) * ctx->pelist_size);
>> +    if (!durations_tmp) {
>> +        av_log(NULL, AV_LOG_ERROR,
>> +               "av_realloc error for durations in av_playlist_insert_item\n");
>> +        return AVERROR_NOMEM;
>> +    } else
>> +        ctx->durations = durations_tmp;
>> +    nb_streams_list_tmp = av_realloc(ctx->nb_streams_list,
>> +                                     sizeof(*(ctx->nb_streams_list)) * ctx->pelist_size);
>> +    if (!nb_streams_list_tmp) {
>> +        av_log(NULL, AV_LOG_ERROR,
>> +               "av_realloc error for nb_streams_list in av_playlist_insert_item\n");
>> +        return AVERROR_NOMEM;
>> +    } else
>> +        ctx->nb_streams_list = nb_streams_list_tmp;
>> +    formatcontext_list_tmp = av_realloc(ctx->formatcontext_list,
>> +                                        sizeof(*(ctx->formatcontext_list)) * ctx->pelist_size);
>> +    if (!formatcontext_list_tmp) {
>> +        av_log(NULL, AV_LOG_ERROR,
>> +               "av_realloc error for formatcontext_list in av_playlist_insert_item\n");
>> +        return AVERROR_NOMEM;
>> +    } else
>> +        ctx->formatcontext_list = formatcontext_list_tmp;
> 
>> +    ctx->formatcontext_list[pos] = NULL;
> 
> this looks more like replace than insert
> 
> 
> [...]
>> +int av_playlist_insert_playlist(AVPlaylistContext *ctx, AVPlaylistContext *insert_ctx, int pos)
>> +{
>> +    int i, err;
>> +    for (i = 0; i < insert_ctx->pelist_size; ++i) {
>> +        err = av_playlist_insert_item(ctx, insert_ctx->flist[i], pos + i);
>> +        if (err) {
> 
>> +            av_log(NULL, AV_LOG_ERROR,
> 
> av_log should have a non null context
> 
> 
>> +                   "failed to insert item %d to new position %d in av_playlist_insert_playlist\n",
>> +                   i, pos + i);
>> +            return err;
>> +        }
>> +    }
>> +    return 0;
>> +}
>> +
> 
>> +int av_playlist_remove_item(AVPlaylistContext *ctx, int pos)
>> +{
>> +    int i, cur_offset;
>> +    int64_t *durations_tmp;
>> +    unsigned int *nb_streams_list_tmp;
>> +    AVFormatContext **formatcontext_list_tmp;
>> +    char **flist_tmp;
>> +    if (pos >= ctx->pelist_size || !ctx->flist || !ctx->durations || !ctx->nb_streams_list) {
>> +        av_log(NULL, AV_LOG_ERROR,
>> +               "failed to remove item %d which is not present in playlist\n",
>> +               pos);
>> +        return AVERROR_INVALIDDATA;
>> +    }
>> +    --ctx->pelist_size;
>> +    av_free(ctx->flist[pos]);
>> +    for (i = pos; i < ctx->pelist_size; ++i)
>> +        ctx->flist[i] = ctx->flist[i + 1];
>> +    flist_tmp = av_realloc(ctx->flist, sizeof(*(ctx->flist)) * ctx->pelist_size);
>> +    if (!flist_tmp) {
>> +        av_log(NULL, AV_LOG_ERROR,
>> +               "av_realloc error for flist in av_playlist_remove_item\n");
>> +        return AVERROR_NOMEM;
> 
> this faiure seems to leave the list in an inconsistent state
> 

I believe this updated patch should fix these issues. I've only made
changes in avplaylist.c so only that part needs to be re-reviewed. My
classes will be starting soon hence I will probably be unable to work
any further on this until winter break.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ffmpeg-concat.diff
Type: text/x-diff
Size: 68330 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090903/dedec893/attachment.diff>



More information about the ffmpeg-devel mailing list