Allintra: Allocate obmc_buffer and comp_rd_buffer conditionally

The buffers 'obmc_buffer' and 'comp_rd_buffer' are used in inter
frames to store intermediate inter mode prediction results and
are not required for allintra encoding mode. Hence, these buffers
are not allocated for allintra encoding mode.

For AVIF image encode with speed = 6,

             HEAP Memory reduction(%)
Resolution   threads=1    threads=4
640x360        3.15         9.36
768x512        1.92         6.18
832x480        2.02         6.52
1280x720       0.98         3.49

HEAP memory reduction was measured using the following command.
$valgrind --tool=massif ./avifenc ...

Change-Id: I5ead979c1c703f58f0b87052146cb79dcfe41740
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 6886d75..a4fcba6 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -750,20 +750,20 @@
                     aom_memalign(16, sizeof(*x->palette_buffer)));
   }
 
-  if (x->comp_rd_buffer.pred0 == NULL) {
-    alloc_compound_type_rd_buffers(cm->error, &x->comp_rd_buffer);
-  }
-
   if (x->tmp_conv_dst == NULL) {
     CHECK_MEM_ERROR(
         cm, x->tmp_conv_dst,
         aom_memalign(32, MAX_SB_SIZE * MAX_SB_SIZE * sizeof(*x->tmp_conv_dst)));
     x->e_mbd.tmp_conv_dst = x->tmp_conv_dst;
   }
-  // The buffers 'tmp_pred_bufs[]' are used in inter frames to store temporary
-  // prediction results. Hence, the memory allocation is avoided for allintra
-  // encode.
+  // The buffers 'tmp_pred_bufs[]' and 'comp_rd_buffer' are used in inter frames
+  // to store intermediate inter mode prediction results and are not required
+  // for allintra encoding mode. Hence, the memory allocations for these buffers
+  // are avoided for allintra encoding mode.
   if (cpi->oxcf.kf_cfg.key_freq_max != 0) {
+    if (x->comp_rd_buffer.pred0 == NULL)
+      alloc_compound_type_rd_buffers(cm->error, &x->comp_rd_buffer);
+
     for (int i = 0; i < 2; ++i) {
       if (x->tmp_pred_bufs[i] == NULL) {
         CHECK_MEM_ERROR(cm, x->tmp_pred_bufs[i],
@@ -1352,7 +1352,11 @@
   }
 #endif
 
-  alloc_obmc_buffers(&cpi->td.mb.obmc_buffer, cm->error);
+  // The buffer "obmc_buffer" is used in inter frames for fast obmc search.
+  // Hence, the memory allocation for the same is avoided for allintra encoding
+  // mode.
+  if (cpi->oxcf.kf_cfg.key_freq_max != 0)
+    alloc_obmc_buffers(&cpi->td.mb.obmc_buffer, cm->error);
 
   for (int x = 0; x < 2; x++)
     for (int y = 0; y < 2; y++)
diff --git a/av1/encoder/ethread.c b/av1/encoder/ethread.c
index 98638bc..5f4d0b3 100644
--- a/av1/encoder/ethread.c
+++ b/av1/encoder/ethread.c
@@ -722,8 +722,6 @@
         // Set up sms_tree.
         av1_setup_sms_tree(ppi->cpi, thread_data->td);
 
-        alloc_obmc_buffers(&thread_data->td->obmc_buffer, &ppi->error);
-
         for (int x = 0; x < 2; x++)
           for (int y = 0; y < 2; y++)
             AOM_CHECK_MEM_ERROR(
@@ -741,13 +739,17 @@
             &ppi->error, thread_data->td->palette_buffer,
             aom_memalign(16, sizeof(*thread_data->td->palette_buffer)));
 
-        alloc_compound_type_rd_buffers(&ppi->error,
-                                       &thread_data->td->comp_rd_buffer);
-
-        // The buffers 'tmp_pred_bufs[]' are used in inter frames to store
-        // temporary prediction results. Hence, the memory allocation is avoided
-        // for allintra encode.
+        // The buffers 'tmp_pred_bufs[]', 'comp_rd_buffer' and 'obmc_buffer' are
+        // used in inter frames to store intermediate inter mode prediction
+        // results and are not required for allintra encoding mode. Hence, the
+        // memory allocations for these buffers are avoided for allintra
+        // encoding mode.
         if (ppi->cpi->oxcf.kf_cfg.key_freq_max != 0) {
+          alloc_obmc_buffers(&thread_data->td->obmc_buffer, &ppi->error);
+
+          alloc_compound_type_rd_buffers(&ppi->error,
+                                         &thread_data->td->comp_rd_buffer);
+
           for (int j = 0; j < 2; ++j) {
             AOM_CHECK_MEM_ERROR(
                 &ppi->error, thread_data->td->tmp_pred_bufs[j],