Check aom_copy_metadata_to_frame_buffer() failure

aom_copy_metadata_to_frame_buffer() fails (returns -1) if its second
parameter is null. So call aom_copy_metadata_to_frame_buffer() only when
the second parameter is not null.

Also, aom_copy_metadata_to_frame_buffer() does nothing and returns 0
(indicating success) if the source and destination metadata pointers are
the same, so the caller don't need to check if the source and
destination frame buffers are different.

Bug: aomedia:3309
Change-Id: Idcf655b998cf091233c5ef70ef3a1d7da79904c1
diff --git a/av1/encoder/encode_strategy.c b/av1/encoder/encode_strategy.c
index 6bce897..8f93942 100644
--- a/av1/encoder/encode_strategy.c
+++ b/av1/encoder/encode_strategy.c
@@ -826,9 +826,12 @@
     }
 
     // Copy source metadata to the temporal filtered frame
-    if (frame_input->source != source_buffer) {
-      aom_copy_metadata_to_frame_buffer(frame_input->source,
-                                        source_buffer->metadata);
+    if (source_buffer->metadata &&
+        aom_copy_metadata_to_frame_buffer(frame_input->source,
+                                          source_buffer->metadata)) {
+      aom_internal_error(
+          cm->error, AOM_CODEC_MEM_ERROR,
+          "Failed to copy source metadata to the temporal filtered frame");
     }
   }
 #if CONFIG_COLLECT_COMPONENT_TIMING
diff --git a/av1/encoder/lookahead.c b/av1/encoder/lookahead.c
index a9bccb1..10fbb77 100644
--- a/av1/encoder/lookahead.c
+++ b/av1/encoder/lookahead.c
@@ -155,7 +155,10 @@
   buf->flags = flags;
   ++ctx->push_frame_count;
   aom_remove_metadata_from_frame_buffer(&buf->img);
-  aom_copy_metadata_to_frame_buffer(&buf->img, src->metadata);
+  if (src->metadata &&
+      aom_copy_metadata_to_frame_buffer(&buf->img, src->metadata)) {
+    return 1;
+  }
   return 0;
 }