On 2014-03-31 20:46:29 +0200, wm4 wrote:
> The only interesting parts are initialization in ff_MPV_common_init and
> uninitialization in ff_MPV_common_end.
> 
> ff_mpeg_unref_picture and ff_thread_release_buffer have additional NULL
> checks for Picture.f, because these functions can be called on
> uninitialized or partially initialized Pictures.
> 
> diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
> index 0fc77e8..3363ea0 100644
> --- a/libavcodec/mpegvideo.c
> +++ b/libavcodec/mpegvideo.c
> @@ -1252,14 +1252,26 @@ av_cold int ff_MPV_common_init(MpegEncContext *s)
>      FF_ALLOCZ_OR_GOTO(s->avctx, s->picture,
>                        MAX_PICTURE_COUNT * sizeof(Picture), fail);
>      for (i = 0; i < MAX_PICTURE_COUNT; i++) {
> -        av_frame_unref(&s->picture[i].f);
> +        s->picture[i].f = av_frame_alloc();
> +        if (!s->picture[i].f)
> +            goto fail;
>      }
>      memset(&s->next_picture, 0, sizeof(s->next_picture));
>      memset(&s->last_picture, 0, sizeof(s->last_picture));
>      memset(&s->current_picture, 0, sizeof(s->current_picture));
> -    av_frame_unref(&s->next_picture.f);
> -    av_frame_unref(&s->last_picture.f);
> -    av_frame_unref(&s->current_picture.f);
> +    memset(&s->new_picture, 0, sizeof(s->new_picture));
> +    s->next_picture.f = av_frame_alloc();
> +    if (!s->next_picture.f)
> +        goto fail;
> +    s->last_picture.f = av_frame_alloc();
> +    if (!s->last_picture.f)
> +        goto fail;
> +    s->current_picture.f = av_frame_alloc();
> +    if (!s->current_picture.f)
> +        goto fail;
> +    s->new_picture.f = av_frame_alloc();
> +    if (!s->new_picture.f)
> +        goto fail;

new_picture is a encoding only field and should be handled in
MPV_encode_init/close

>      if (s->width && s->height) {
>          if (init_context_frame(s))
> @@ -1453,15 +1465,22 @@ void ff_MPV_common_end(MpegEncContext *s)
>          for (i = 0; i < MAX_PICTURE_COUNT; i++) {
>              ff_free_picture_tables(&s->picture[i]);
>              ff_mpeg_unref_picture(s, &s->picture[i]);
> +            av_frame_free(&s->picture[i].f);
>          }
>      }
>      av_freep(&s->picture);
>      ff_free_picture_tables(&s->last_picture);
>      ff_mpeg_unref_picture(s, &s->last_picture);
> +    av_frame_free(&s->last_picture.f);
>      ff_free_picture_tables(&s->current_picture);
>      ff_mpeg_unref_picture(s, &s->current_picture);
> +    av_frame_free(&s->current_picture.f);
>      ff_free_picture_tables(&s->next_picture);
>      ff_mpeg_unref_picture(s, &s->next_picture);
> +    av_frame_free(&s->next_picture.f);
> +    ff_free_picture_tables(&s->new_picture);
> +    ff_mpeg_unref_picture(s, &s->new_picture);
> +    av_frame_free(&s->new_picture.f);

see above

There are several places with broken vertical alignment and I fear that
not all AVFrame dereferences are guaranteed to operate on valid pointers
but I don't see good way to handle it other than fixing problems as they
are discovered.

otherwise ok with the other patches squashed

Janne
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to