[FFmpeg-devel] [PATCH] Playlist API

Michael Niedermayer michaelni
Thu Sep 3 14:43:31 CEST 2009


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


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Into a blind darkness they enter who follow after the Ignorance,
they as if into a greater darkness enter who devote themselves
to the Knowledge alone. -- Isha Upanishad
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090903/cbcd1d98/attachment.pgp>



More information about the ffmpeg-devel mailing list