]> granicus.if.org Git - libvpx/commitdiff
Refactor denoiser frame buffer update
authorJingning Han <jingning@google.com>
Thu, 8 Jan 2015 02:30:50 +0000 (18:30 -0800)
committerJingning Han <jingning@google.com>
Thu, 8 Jan 2015 02:33:13 +0000 (18:33 -0800)
Use frame buffer pointer swap instead of memcpy when possible.
These two CLs make the denoiser when running on vidyo1 720p at
speed -6 over 10% faster.

Change-Id: I64fe8a2422cafca6787a50c7f4dfb961191c0a9d

vp9/encoder/vp9_denoiser.c

index 1444c3782ba80d69e6834bbb5d0eb5aec8dc0686..dec340d8aeb1e9e8b2c4c209a639397d2c985ffc 100644 (file)
@@ -365,6 +365,15 @@ static void copy_frame(YV12_BUFFER_CONFIG dest, const YV12_BUFFER_CONFIG src) {
   }
 }
 
+static void swap_frame_buffer(YV12_BUFFER_CONFIG dest,
+                              YV12_BUFFER_CONFIG src) {
+  uint8_t *tmp_buf = dest.y_buffer;
+  assert(dest.y_width == src.y_width);
+  assert(dest.y_height == src.y_height);
+  dest.y_buffer = src.y_buffer;
+  src.y_buffer = tmp_buf;
+}
+
 void vp9_denoiser_update_frame_info(VP9_DENOISER *denoiser,
                                     YV12_BUFFER_CONFIG src,
                                     FRAME_TYPE frame_type,
@@ -374,22 +383,23 @@ void vp9_denoiser_update_frame_info(VP9_DENOISER *denoiser,
   if (frame_type == KEY_FRAME) {
     int i;
     // Start at 1 so as not to overwrite the INTRA_FRAME
-    for (i = 1; i < MAX_REF_FRAMES; ++i) {
+    for (i = 1; i < MAX_REF_FRAMES; ++i)
       copy_frame(denoiser->running_avg_y[i], src);
-    }
-  } else {  /* For non key frames */
-    if (refresh_alt_ref_frame) {
-      copy_frame(denoiser->running_avg_y[ALTREF_FRAME],
-                 denoiser->running_avg_y[INTRA_FRAME]);
-    }
-    if (refresh_golden_frame) {
-      copy_frame(denoiser->running_avg_y[GOLDEN_FRAME],
-                 denoiser->running_avg_y[INTRA_FRAME]);
-    }
-    if (refresh_last_frame) {
-      copy_frame(denoiser->running_avg_y[LAST_FRAME],
-                 denoiser->running_avg_y[INTRA_FRAME]);
-    }
+    return;
+  }
+
+  /* For non key frames */
+  if (refresh_alt_ref_frame) {
+    swap_frame_buffer(denoiser->running_avg_y[ALTREF_FRAME],
+                      denoiser->running_avg_y[INTRA_FRAME]);
+  }
+  if (refresh_golden_frame) {
+    swap_frame_buffer(denoiser->running_avg_y[GOLDEN_FRAME],
+                      denoiser->running_avg_y[INTRA_FRAME]);
+  }
+  if (refresh_last_frame) {
+    swap_frame_buffer(denoiser->running_avg_y[LAST_FRAME],
+                      denoiser->running_avg_y[INTRA_FRAME]);
   }
 }