diff mbox series

[FFmpeg-devel,09/18] vp3: eliminate copy_fields

Message ID 20200313102850.23913-9-anton@khirnov.net
State Accepted
Headers show
Series [FFmpeg-devel,01/18] mpeg4videodec: do not copy a range of fields at once
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork warning Failed to apply patch

Commit Message

Anton Khirnov March 13, 2020, 10:28 a.m. UTC
It is very fragile against fields being moved and hides what is actually
being copied. Copy all the fields explicitly instead.
---
 libavcodec/vp3.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Comments

Peter Ross March 14, 2020, 11:50 p.m. UTC | #1
On Fri, Mar 13, 2020 at 11:28:41AM +0100, Anton Khirnov wrote:
> It is very fragile against fields being moved and hides what is actually
> being copied. Copy all the fields explicitly instead.
> ---
>  libavcodec/vp3.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
> index 0a8c8ad286..81d0b9b7bb 100644
> --- a/libavcodec/vp3.c
> +++ b/libavcodec/vp3.c
> @@ -2590,10 +2590,6 @@ static int vp3_update_thread_context(AVCodecContext *dst, const AVCodecContext *
>      Vp3DecodeContext *s = dst->priv_data, *s1 = src->priv_data;
>      int qps_changed = 0, i, err;
>  
> -#define copy_fields(to, from, start_field, end_field)                         \
> -    memcpy(&to->start_field, &from->start_field,                              \
> -           (char *) &to->end_field - (char *) &to->start_field)
> -
>      if (!s1->current_frame.f->data[0] ||
>          s->width != s1->width || s->height != s1->height) {
>          if (s != s1)
> @@ -2620,9 +2616,11 @@ static int vp3_update_thread_context(AVCodecContext *dst, const AVCodecContext *
>              memcpy(&s->bounding_values_array, &s1->bounding_values_array,
>                     sizeof(s->bounding_values_array));
>  
> -        if (qps_changed)
> -            copy_fields(s, s1, qps, superblock_count);
> -#undef copy_fields
> +        if (qps_changed) {
> +            memcpy(s->qps,      s1->qps,      sizeof(s->qps));
> +            memcpy(s->last_qps, s1->last_qps, sizeof(s->last_qps));
> +            s->nqps = s1->nqps;
> +        }
>      }
>  
>      return update_frames(dst);

Looks good.

-- Peter
(A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B)
diff mbox series

Patch

diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index 0a8c8ad286..81d0b9b7bb 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -2590,10 +2590,6 @@  static int vp3_update_thread_context(AVCodecContext *dst, const AVCodecContext *
     Vp3DecodeContext *s = dst->priv_data, *s1 = src->priv_data;
     int qps_changed = 0, i, err;
 
-#define copy_fields(to, from, start_field, end_field)                         \
-    memcpy(&to->start_field, &from->start_field,                              \
-           (char *) &to->end_field - (char *) &to->start_field)
-
     if (!s1->current_frame.f->data[0] ||
         s->width != s1->width || s->height != s1->height) {
         if (s != s1)
@@ -2620,9 +2616,11 @@  static int vp3_update_thread_context(AVCodecContext *dst, const AVCodecContext *
             memcpy(&s->bounding_values_array, &s1->bounding_values_array,
                    sizeof(s->bounding_values_array));
 
-        if (qps_changed)
-            copy_fields(s, s1, qps, superblock_count);
-#undef copy_fields
+        if (qps_changed) {
+            memcpy(s->qps,      s1->qps,      sizeof(s->qps));
+            memcpy(s->last_qps, s1->last_qps, sizeof(s->last_qps));
+            s->nqps = s1->nqps;
+        }
     }
 
     return update_frames(dst);