Avoid an unnecessary allocation

Force the encoder-side enable_global_motion flag to 0 in
realtime mode, as global motion is never used in this case.

This prevents an edge case where we could allocate a buffer
to store an 8-bit version of the source frame, but then not
actually use it. This could happen if using realtime mode
with 16-bit internal buffers, on a build with CONFIG_REALTIME_ONLY=0

Also change the memory accounting logic so that this buffer is
only accounted toward the maximum allocation limit if it is
actually allocated.

Finally, add an assertion to ensure that this buffer is never
allocated in decoder-only or realtime-only builds.

Change-Id: I83a25fcd3bc98091fabe1caf79928e565a5e51a6
diff --git a/aom_scale/generic/yv12config.c b/aom_scale/generic/yv12config.c
index de56263..c1081e7 100644
--- a/aom_scale/generic/yv12config.c
+++ b/aom_scale/generic/yv12config.c
@@ -59,11 +59,17 @@
 
     uint8_t *buf = NULL;
 
+#if CONFIG_REALTIME_ONLY || !CONFIG_AV1_ENCODER
+    // We should only need an 8-bit version of the source frame if we are
+    // encoding in non-realtime mode
+    assert(alloc_y_buffer_8bit == 0);
+#endif  // CONFIG_REALTIME_ONLY || !CONFIG_AV1_ENCODER
+
 #if defined AOM_MAX_ALLOCABLE_MEMORY
     // The size of ybf->buffer_alloc.
     uint64_t alloc_size = frame_size;
     // The size of ybf->y_buffer_8bit.
-    if (use_highbitdepth) alloc_size += yplane_size;
+    if (use_highbitdepth && alloc_y_buffer_8bit) alloc_size += yplane_size;
     // The decoder may allocate REF_FRAMES frame buffers in the frame buffer
     // pool. Bound the total amount of allocated memory as if these REF_FRAMES
     // frame buffers were allocated in a single allocation.
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index c5f9f1e..eb09f26 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -1156,7 +1156,8 @@
   tool_cfg->enable_interintra_comp = extra_cfg->enable_interintra_comp;
   tool_cfg->ref_frame_mvs_present =
       extra_cfg->enable_ref_frame_mvs & extra_cfg->enable_order_hint;
-  tool_cfg->enable_global_motion = extra_cfg->enable_global_motion;
+  tool_cfg->enable_global_motion =
+      extra_cfg->enable_global_motion && (cfg->g_usage != AOM_USAGE_REALTIME);
   tool_cfg->error_resilient_mode =
       cfg->g_error_resilient | extra_cfg->error_resilient_mode;
   tool_cfg->frame_parallel_decoding_mode =