On Tue,  4 Mar 2014 19:24:33 +0100, Vittorio Giovara 
<[email protected]> wrote:
> A new function is introduced to keep compatibility across the code.
> ---
>  libavcodec/error_resilience.c | 208 
> +++++++++++++++++++++---------------------
>  libavcodec/error_resilience.h |  21 ++++-
>  libavcodec/h264.c             |   6 +-
>  libavcodec/mpegvideo.c        |  28 +++++-
>  libavcodec/mpegvideo.h        |   2 +
>  5 files changed, 151 insertions(+), 114 deletions(-)
> 
> diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c
> index 51ebc04..2ebb941 100644
> diff --git a/libavcodec/error_resilience.h b/libavcodec/error_resilience.h
> index f979656..1cb1099 100644
> --- a/libavcodec/error_resilience.h
> +++ b/libavcodec/error_resilience.h
> @@ -24,6 +24,7 @@
>  
>  #include "avcodec.h"
>  #include "dsputil.h"
> +#include "thread.h"
>  
>  ///< current MB is the first after a resync marker
>  #define VP_START               1
> @@ -37,6 +38,20 @@
>  #define ER_MB_ERROR (ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR)
>  #define ER_MB_END   (ER_AC_END|ER_DC_END|ER_MV_END)
>  
> +typedef struct ERPicture {
> +    AVFrame *f;
> +    ThreadFrame tf;

ThreadFrame contains refcounted buffers, so I'd rather not have copies of it.
Make this a pointer too.

> +
> +    AVBufferRef *motion_val_buf[2];
> +    int16_t (*motion_val[2])[2];
> +
> +    AVBufferRef *ref_index_buf[2];
> +    int8_t *ref_index[2];
> +
> +    uint32_t *mb_type;
> +    int field_picture;
> +} ERPicture;
> +
>  typedef struct ERContext {
>      AVCodecContext *avctx;
>      DSPContext *dsp;
> @@ -55,9 +70,9 @@ typedef struct ERContext {
>      uint8_t *mbintra_table;
>      int mv[2][4][2];
>  
> -    struct Picture *cur_pic;
> -    struct Picture *last_pic;
> -    struct Picture *next_pic;
> +    ERPicture cur_pic;
> +    ERPicture last_pic;
> +    ERPicture next_pic;
>  
>      uint16_t pp_time;
>      uint16_t pb_time;
> diff --git a/libavcodec/h264.c b/libavcodec/h264.c
> index 76cdb0c..ff36613 100644
> --- a/libavcodec/h264.c
> +++ b/libavcodec/h264.c
> @@ -2974,9 +2974,9 @@ static int field_end(H264Context *h, int in_setup)
>       * causes problems for the first MB line, too.
>       */
>      if (CONFIG_ERROR_RESILIENCE && !FIELD_PICTURE(h)) {
> -        h->er.cur_pic  = h->cur_pic_ptr;
> -        h->er.last_pic = h->ref_count[0] ? &h->ref_list[0][0] : NULL;
> -        h->er.next_pic = h->ref_count[1] ? &h->ref_list[1][0] : NULL;
> +        ff_copy_to_er(&h->er.cur_pic, h->cur_pic_ptr);
> +        ff_copy_to_er(&h->er.last_pic, h->ref_count[0] ? &h->ref_list[0][0] 
> : NULL);
> +        ff_copy_to_er(&h->er.next_pic, h->ref_count[1] ? &h->ref_list[1][0] 
> : NULL);
>          ff_er_frame_end(&h->er);
>      }
>      emms_c();
> diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
> index 59c64b8..a23ab43 100644
> --- a/libavcodec/mpegvideo.c
> +++ b/libavcodec/mpegvideo.c
> @@ -2482,13 +2482,35 @@ void ff_MPV_report_decode_progress(MpegEncContext *s)
>  }
>  
>  #if CONFIG_ERROR_RESILIENCE
> +void ff_copy_to_er(ERPicture *dst, Picture *src)
> +{
> +    int i;
> +
> +    if (!src)
> +        return;
> +
> +    dst->f = &src->f;
> +    dst->tf = src->tf;
> +
> +    for (i = 0; i < 2; i++) {
> +        dst->motion_val_buf[i] = src->motion_val_buf[i];

You don't need to (and should not) copy the buffer refs.
If you look at the code, the only way those fields are used is to _allocate_
dummy values when the real ones are missing.

OTOH when those dummy fields are create in ER, it's probably necessary to
propagate them back to the caller after ER does its thing.

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

Reply via email to