Handle unsupported bitstream while large-scale-tile=1

This patch follows the previous one to handle large-scale-tile=1
bitstream in decoder by assigning a different fourcc. Also,
modified lightfield example accordingly.

Details:
aomenc/lightfield_encoder: for large scale tile(LST) encoding,
write LST_FOURCC to output bitstream.

aomdec: if input bitstream's fourcc isn't equal to AV1_FOURCC,
decoder fails with unsupported fourcc error message.

lightfield_bitstream_parsing: convert LST bitstream to AV1
bitstream. Set fourcc to AV1_FOURCC and write it to output
bitstream.

BUG=aomedia:2274

Change-Id: Iadc88b0e9804badb8e5d014be0f0796fb2d6ce25
diff --git a/apps/aomdec.c b/apps/aomdec.c
index 58ac172..c054425 100644
--- a/apps/aomdec.c
+++ b/apps/aomdec.c
@@ -484,6 +484,7 @@
   input.webm_ctx = &webm_ctx;
 #endif
   struct ObuDecInputContext obu_ctx = { NULL, NULL, 0, 0, 0 };
+  int is_ivf = 0;
 
   obu_ctx.avx_ctx = &aom_input_ctx;
   input.obu_ctx = &obu_ctx;
@@ -610,8 +611,10 @@
 #endif
   input.aom_input_ctx->filename = fn;
   input.aom_input_ctx->file = infile;
-  if (file_is_ivf(input.aom_input_ctx))
+  if (file_is_ivf(input.aom_input_ctx)) {
     input.aom_input_ctx->file_type = FILE_TYPE_IVF;
+    is_ivf = 1;
+  }
 #if CONFIG_WEBM_IO
   else if (file_is_webm(input.webm_ctx, input.aom_input_ctx))
     input.aom_input_ctx->file_type = FILE_TYPE_WEBM;
@@ -661,6 +664,10 @@
   }
 
   fourcc_interface = get_aom_decoder_by_fourcc(aom_input_ctx.fourcc);
+
+  if (is_ivf && !fourcc_interface)
+    fatal("Unsupported fourcc: %x\n", aom_input_ctx.fourcc);
+
   if (interface && fourcc_interface && interface != fourcc_interface)
     warn("Header indicates codec: %s\n", fourcc_interface->name);
   else
diff --git a/apps/aomenc.c b/apps/aomenc.c
index ef6c388..83c1353 100644
--- a/apps/aomenc.c
+++ b/apps/aomenc.c
@@ -1357,6 +1357,7 @@
       config->cfg.g_lag_in_frames = arg_parse_uint(&arg);
     } else if (arg_match(&arg, &large_scale_tile, argi)) {
       config->cfg.large_scale_tile = arg_parse_uint(&arg);
+      if (config->cfg.large_scale_tile) global->codec = get_aom_lst_encoder();
     } else if (arg_match(&arg, &monochrome, argi)) {
       config->cfg.monochrome = 1;
     } else if (arg_match(&arg, &full_still_picture_hdr, argi)) {
diff --git a/common/tools_common.c b/common/tools_common.c
index 2e32f61..51c1c52 100644
--- a/common/tools_common.c
+++ b/common/tools_common.c
@@ -149,6 +149,11 @@
 
   return NULL;
 }
+
+// large scale tile encoding
+static const AvxInterface aom_lst_encoder = { "av1", LST_FOURCC,
+                                              &aom_codec_av1_cx };
+const AvxInterface *get_aom_lst_encoder(void) { return &aom_lst_encoder; }
 #endif  // CONFIG_AV1_ENCODER
 
 #if CONFIG_AV1_DECODER
diff --git a/common/tools_common.h b/common/tools_common.h
index 81f4061..d9a68f0 100644
--- a/common/tools_common.h
+++ b/common/tools_common.h
@@ -85,6 +85,9 @@
   NV12,   // Tile output in NV12 format.
 } UENUM1BYTE(OUTPUT_FORMAT);
 
+// The fourcc for large_scale_tile encoding is "LSTC".
+#define LST_FOURCC 0x4354534c
+
 struct FileTypeDetectionBuffer {
   char buf[4];
   size_t buf_read;
@@ -150,6 +153,7 @@
 int get_aom_encoder_count(void);
 const AvxInterface *get_aom_encoder_by_index(int i);
 const AvxInterface *get_aom_encoder_by_name(const char *name);
+const AvxInterface *get_aom_lst_encoder(void);
 
 int get_aom_decoder_count(void);
 const AvxInterface *get_aom_decoder_by_index(int i);
diff --git a/common/video_reader.c b/common/video_reader.c
index 47ad6e1..7b021bc 100644
--- a/common/video_reader.c
+++ b/common/video_reader.c
@@ -121,3 +121,7 @@
 const AvxVideoInfo *aom_video_reader_get_info(AvxVideoReader *reader) {
   return &reader->info;
 }
+
+void aom_video_reader_set_fourcc(AvxVideoReader *reader, uint32_t fourcc) {
+  reader->info.codec_fourcc = fourcc;
+}
diff --git a/common/video_reader.h b/common/video_reader.h
index 903deae..9ab439e 100644
--- a/common/video_reader.h
+++ b/common/video_reader.h
@@ -50,6 +50,9 @@
 // Fills AvxVideoInfo with information from opened video file.
 const AvxVideoInfo *aom_video_reader_get_info(AvxVideoReader *reader);
 
+// Set fourcc.
+void aom_video_reader_set_fourcc(AvxVideoReader *reader, uint32_t fourcc);
+
 #ifdef __cplusplus
 }  // extern "C"
 #endif
diff --git a/common/video_writer.c b/common/video_writer.c
index a7ec309..2b42e36 100644
--- a/common/video_writer.c
+++ b/common/video_writer.c
@@ -75,3 +75,7 @@
 
   return 1;
 }
+
+void aom_video_writer_set_fourcc(AvxVideoWriter *writer, uint32_t fourcc) {
+  writer->info.codec_fourcc = fourcc;
+}
diff --git a/common/video_writer.h b/common/video_writer.h
index 14bdc1b..8712d47 100644
--- a/common/video_writer.h
+++ b/common/video_writer.h
@@ -37,6 +37,8 @@
 // Writes frame bytes to the file.
 int aom_video_writer_write_frame(AvxVideoWriter *writer, const uint8_t *buffer,
                                  size_t size, int64_t pts);
+// Set fourcc.
+void aom_video_writer_set_fourcc(AvxVideoWriter *writer, uint32_t fourcc);
 
 #ifdef __cplusplus
 }  // extern "C"
diff --git a/examples/lightfield_bitstream_parsing.c b/examples/lightfield_bitstream_parsing.c
index 9c90671..afacf44 100644
--- a/examples/lightfield_bitstream_parsing.c
+++ b/examples/lightfield_bitstream_parsing.c
@@ -211,6 +211,8 @@
   num_references = (int)strtol(argv[3], NULL, 0);
   info = aom_video_reader_get_info(reader);
 
+  aom_video_reader_set_fourcc(reader, AV1_FOURCC);
+
   // The writer to write out ivf file in tile list OBU, which can be decoded by
   // AV1 decoder.
   writer = aom_video_writer_open(argv[2], kContainerIVF, info);
diff --git a/examples/lightfield_decoder.c b/examples/lightfield_decoder.c
index cb57dfe..7a445f0 100644
--- a/examples/lightfield_decoder.c
+++ b/examples/lightfield_decoder.c
@@ -188,8 +188,10 @@
 
   info = aom_video_reader_get_info(reader);
 
-  decoder = get_aom_decoder_by_fourcc(info->codec_fourcc);
-  if (!decoder) die("Unknown input codec.");
+  if (info->codec_fourcc == LST_FOURCC)
+    decoder = get_aom_decoder_by_fourcc(AV1_FOURCC);
+  else
+    die("Unknown input codec.");
   printf("Using %s\n", aom_codec_iface_name(decoder->codec_interface()));
 
   if (aom_codec_dec_init(&codec, decoder->codec_interface(), NULL, 0))
diff --git a/examples/lightfield_encoder.c b/examples/lightfield_encoder.c
index 301bc90..4dd71ca 100644
--- a/examples/lightfield_encoder.c
+++ b/examples/lightfield_encoder.c
@@ -397,6 +397,10 @@
   for (i = 0; i < reference_image_num; i++) aom_img_free(&reference_images[i]);
 
   if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec.");
+
+  // Modify large_scale_file fourcc.
+  if (cfg->large_scale_tile == 1)
+    aom_video_writer_set_fourcc(writer, LST_FOURCC);
   aom_video_writer_close(writer);
 
   printf("\nSecond pass complete. Processed %d frames.\n", frame_count);