Refactor av1_lookahead_init

Removed unnecessary value clipping in av1_lookahead_init.

Change-Id: Ibc662d018e8224f6aab4df48e3054e5c55565f13
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index 457aa06..4b85cf0 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -752,7 +752,7 @@
     case AOM_RC_LAST_PASS: oxcf->pass = 2; break;
   }
 
-  oxcf->lag_in_frames = cfg->g_lag_in_frames;
+  oxcf->lag_in_frames = clamp(cfg->g_lag_in_frames, 0, MAX_LAG_BUFFERS);
   oxcf->rc_mode = cfg->rc_end_usage;
 
   // Convert target bandwidth from Kbit/s to Bit/s
@@ -1927,7 +1927,8 @@
         res = create_context_and_bufferpool(
             &priv->cpi_lap, &priv->buffer_pool_lap, &priv->oxcf, NULL,
             priv->frame_stats_buffer, LAP_STAGE, *num_lap_buffers,
-            lap_lag_in_frames, &priv->stats_buf_context);
+            clamp(lap_lag_in_frames, 0, MAX_LAG_BUFFERS),
+            &priv->stats_buf_context);
       }
     }
   }
diff --git a/av1/encoder/lookahead.c b/av1/encoder/lookahead.c
index ee90bc0..0f7c819 100644
--- a/av1/encoder/lookahead.c
+++ b/av1/encoder/lookahead.c
@@ -47,13 +47,7 @@
     unsigned int subsampling_y, int use_highbitdepth, unsigned int depth,
     const int border_in_pixels, int byte_alignment, int num_lap_buffers) {
   struct lookahead_ctx *ctx = NULL;
-  int lag_in_frames = clamp(depth, 1, MAX_LAG_BUFFERS);
-
-  // Clamp the lookahead queue depth
-  depth = clamp(depth, 0, MAX_LAG_BUFFERS);
-
-  // Clamp the LAP lag
-  num_lap_buffers = clamp(num_lap_buffers, 0, MAX_LAP_BUFFERS);
+  int lag_in_frames = AOMMAX(1, depth);
 
   // Add the lags to depth and clamp
   depth += num_lap_buffers;