blob: 4ba34f42d11283907bc60e8cd584f4ba23b4a4cf [file] [log] [blame]
Yunqing Wang40bde4d2018-06-01 16:48:03 -07001/*
Krishna Rapaka7319db52021-09-28 20:35:29 -07002 * Copyright (c) 2021, Alliance for Open Media. All rights reserved
Yunqing Wang40bde4d2018-06-01 16:48:03 -07003 *
Vibhoothi41c6dd72021-10-12 18:48:26 +00004 * This source code is subject to the terms of the BSD 3-Clause Clear License
5 * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
6 * License was not distributed with this source code in the LICENSE file, you
7 * can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the
8 * Alliance for Open Media Patent License 1.0 was not distributed with this
9 * source code in the PATENTS file, you can obtain it at
10 * aomedia.org/license/patent-license/.
Yunqing Wang40bde4d2018-06-01 16:48:03 -070011 */
12
13// Lightfield Bitstream Parsing
14// ============================
15//
Yunqing Wangce285452018-06-25 14:51:51 -070016// This is a lightfield bitstream parsing example. It takes an input file
Ryan Overbeck18521392018-09-21 09:43:24 -070017// containing the whole compressed lightfield bitstream(ivf file) and a text
18// file containing a stream of tiles to decode and then constructs and outputs
19// a new bitstream that can be decoded by an AV1 decoder. The output bitstream
20// contains reference frames(i.e. anchor frames), camera frame header, and
21// tile list OBUs. num_references is the number of anchor frames coded at the
22// beginning of the light field file. After running the lightfield encoder,
23// run lightfield bitstream parsing:
Yunqing Wangce285452018-06-25 14:51:51 -070024// examples/lightfield_bitstream_parsing vase10x10.ivf vase_tile_list.ivf 4
Ryan Overbeck18521392018-09-21 09:43:24 -070025// tile_list.txt
26//
27// The tile_list.txt is expected to be of the form:
28// Frame <frame_index0>
29// <image_index0> <anchor_index0> <tile_col0> <tile_row0>
30// <image_index1> <anchor_index1> <tile_col1> <tile_row1>
31// ...
32// Frame <frame_index1)
33// ...
34//
35// The "Frame" markers indicate a new render frame and thus a new tile list
36// will be started and the old one flushed. The image_indexN, anchor_indexN,
37// tile_colN, and tile_rowN identify an individual tile to be decoded and
38// to use anchor_indexN anchor image for MCP.
Yunqing Wang40bde4d2018-06-01 16:48:03 -070039
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
Yunqing Wang40bde4d2018-06-01 16:48:03 -070043
44#include "aom/aom_decoder.h"
45#include "aom/aom_encoder.h"
Yunqing Wang946ec2b2018-06-06 12:34:23 -070046#include "aom/aom_integer.h"
Yunqing Wang40bde4d2018-06-01 16:48:03 -070047#include "aom/aomdx.h"
Yunqing Wang946ec2b2018-06-06 12:34:23 -070048#include "aom_dsp/bitwriter_buffer.h"
Yunqing Wang40bde4d2018-06-01 16:48:03 -070049#include "common/tools_common.h"
50#include "common/video_reader.h"
51#include "common/video_writer.h"
52
Yunqing Wangd74f5682018-07-12 14:34:56 -070053#define MAX_TILES 512
54
Yunqing Wang40bde4d2018-06-01 16:48:03 -070055static const char *exec_name;
56
57void usage_exit(void) {
Ryan Overbeck18521392018-09-21 09:43:24 -070058 fprintf(stderr, "Usage: %s <infile> <outfile> <num_references> <tile_list>\n",
Ryan Overbeck49a82172018-06-21 15:24:36 -070059 exec_name);
Yunqing Wang40bde4d2018-06-01 16:48:03 -070060 exit(EXIT_FAILURE);
61}
62
63#define ALIGN_POWER_OF_TWO(value, n) \
64 (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1))
65
Yunqing Wang6ff48092018-11-13 14:10:48 -080066const int output_frame_width = 512;
67const int output_frame_height = 512;
Yunqing Wang40bde4d2018-06-01 16:48:03 -070068
69// Spec:
70// typedef struct {
71// uint8_t anchor_frame_idx;
72// uint8_t tile_row;
73// uint8_t tile_col;
74// uint16_t coded_tile_data_size_minus_1;
75// uint8_t *coded_tile_data;
76// } TILE_LIST_ENTRY;
77
78// Tile list entry provided by the application
79typedef struct {
80 int image_idx;
81 int reference_idx;
82 int tile_col;
83 int tile_row;
84} TILE_LIST_INFO;
85
Yunqing Wangd74f5682018-07-12 14:34:56 -070086static int get_image_bps(aom_img_fmt_t fmt) {
87 switch (fmt) {
88 case AOM_IMG_FMT_I420: return 12;
89 case AOM_IMG_FMT_I422: return 16;
90 case AOM_IMG_FMT_I444: return 24;
91 case AOM_IMG_FMT_I42016: return 24;
92 case AOM_IMG_FMT_I42216: return 32;
93 case AOM_IMG_FMT_I44416: return 48;
94 default: die("Invalid image format");
95 }
Yaowu Xu0415f2e2018-07-23 11:48:53 -070096 return 0;
Yunqing Wangd74f5682018-07-12 14:34:56 -070097}
98
Ryan Overbeck18521392018-09-21 09:43:24 -070099void process_tile_list(const TILE_LIST_INFO *tiles, int num_tiles,
100 aom_codec_pts_t tl_pts, unsigned char **frames,
101 const size_t *frame_sizes, aom_codec_ctx_t *codec,
Yunqing Wang6ff48092018-11-13 14:10:48 -0800102 unsigned char *tl_buf, AvxVideoWriter *writer,
103 uint8_t output_frame_width_in_tiles_minus_1,
104 uint8_t output_frame_height_in_tiles_minus_1) {
Ryan Overbeck18521392018-09-21 09:43:24 -0700105 unsigned char *tl = tl_buf;
106 struct aom_write_bit_buffer wb = { tl, 0 };
107 unsigned char *saved_obu_size_loc = NULL;
108 uint32_t tile_list_obu_header_size = 0;
109 uint32_t tile_list_obu_size = 0;
110 int num_tiles_minus_1 = num_tiles - 1;
111 int i;
112
113 // Write the tile list OBU header that is 1 byte long.
114 aom_wb_write_literal(&wb, 0, 1); // forbidden bit.
115 aom_wb_write_literal(&wb, 8, 4); // tile list OBU: "1000"
116 aom_wb_write_literal(&wb, 0, 1); // obu_extension = 0
117 aom_wb_write_literal(&wb, 1, 1); // obu_has_size_field
118 aom_wb_write_literal(&wb, 0, 1); // reserved
119 tl++;
120 tile_list_obu_header_size++;
121
122 // Write the OBU size using a fixed length_field_size of 4 bytes.
123 saved_obu_size_loc = tl;
124 // aom_wb_write_unsigned_literal(&wb, data, bits) requires that bits <= 32.
125 aom_wb_write_unsigned_literal(&wb, 0, 32);
126 tl += 4;
127 tile_list_obu_header_size += 4;
128
129 // write_tile_list_obu()
130 aom_wb_write_literal(&wb, output_frame_width_in_tiles_minus_1, 8);
131 aom_wb_write_literal(&wb, output_frame_height_in_tiles_minus_1, 8);
132 aom_wb_write_literal(&wb, num_tiles_minus_1, 16);
133 tl += 4;
134 tile_list_obu_size += 4;
135
136 // Write each tile's data
137 for (i = 0; i <= num_tiles_minus_1; i++) {
138 aom_tile_data tile_data = { 0, NULL, 0 };
139
140 int image_idx = tiles[i].image_idx;
141 int ref_idx = tiles[i].reference_idx;
142 int tc = tiles[i].tile_col;
143 int tr = tiles[i].tile_row;
144
145 // Reset bit writer to the right location.
146 wb.bit_buffer = tl;
147 wb.bit_offset = 0;
148
149 size_t frame_size = frame_sizes[image_idx];
150 const unsigned char *frame = frames[image_idx];
151
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700152 AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1_SET_DECODE_TILE_ROW, tr);
153 AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1_SET_DECODE_TILE_COL, tc);
Ryan Overbeck18521392018-09-21 09:43:24 -0700154
155 aom_codec_err_t aom_status =
156 aom_codec_decode(codec, frame, frame_size, NULL);
157 if (aom_status) die_codec(codec, "Failed to decode tile.");
158
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700159 AOM_CODEC_CONTROL_TYPECHECKED(codec, AV1D_GET_TILE_DATA, &tile_data);
Ryan Overbeck18521392018-09-21 09:43:24 -0700160
161 // Copy over tile info.
162 // uint8_t anchor_frame_idx;
163 // uint8_t tile_row;
164 // uint8_t tile_col;
165 // uint16_t coded_tile_data_size_minus_1;
166 // uint8_t *coded_tile_data;
167 uint32_t tile_info_bytes = 5;
168 aom_wb_write_literal(&wb, ref_idx, 8);
169 aom_wb_write_literal(&wb, tr, 8);
170 aom_wb_write_literal(&wb, tc, 8);
171 aom_wb_write_literal(&wb, (int)tile_data.coded_tile_data_size - 1, 16);
172 tl += tile_info_bytes;
173
174 memcpy(tl, (uint8_t *)tile_data.coded_tile_data,
175 tile_data.coded_tile_data_size);
176 tl += tile_data.coded_tile_data_size;
177
178 tile_list_obu_size +=
179 tile_info_bytes + (uint32_t)tile_data.coded_tile_data_size;
180 }
181
182 // Write tile list OBU size.
183 size_t bytes_written = 0;
184 if (aom_uleb_encode_fixed_size(tile_list_obu_size, 4, 4, saved_obu_size_loc,
185 &bytes_written))
186 die_codec(codec, "Failed to encode the tile list obu size.");
187
188 // Copy the tile list.
189 if (!aom_video_writer_write_frame(
190 writer, tl_buf, tile_list_obu_header_size + tile_list_obu_size,
191 tl_pts))
192 die_codec(codec, "Failed to copy compressed tile list.");
193}
194
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700195int main(int argc, char **argv) {
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700196 AvxVideoReader *reader = NULL;
197 AvxVideoWriter *writer = NULL;
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700198 const AvxVideoInfo *info = NULL;
Ryan Overbeck49a82172018-06-21 15:24:36 -0700199 int num_references;
Ryan Overbeck18521392018-09-21 09:43:24 -0700200 int i;
Yunqing Wang946ec2b2018-06-06 12:34:23 -0700201 aom_codec_pts_t pts;
Ryan Overbeck18521392018-09-21 09:43:24 -0700202 const char *tile_list_file = NULL;
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700203
204 exec_name = argv[0];
Ryan Overbeck18521392018-09-21 09:43:24 -0700205 if (argc != 5) die("Invalid number of arguments.");
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700206
207 reader = aom_video_reader_open(argv[1]);
208 if (!reader) die("Failed to open %s for reading.", argv[1]);
209
Ryan Overbeck49a82172018-06-21 15:24:36 -0700210 num_references = (int)strtol(argv[3], NULL, 0);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700211 info = aom_video_reader_get_info(reader);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700212
Yunqing Wang3ae70c92019-01-25 17:34:07 -0800213 aom_video_reader_set_fourcc(reader, AV1_FOURCC);
214
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700215 // The writer to write out ivf file in tile list OBU, which can be decoded by
216 // AV1 decoder.
217 writer = aom_video_writer_open(argv[2], kContainerIVF, info);
218 if (!writer) die("Failed to open %s for writing", argv[2]);
219
Ryan Overbeck18521392018-09-21 09:43:24 -0700220 tile_list_file = argv[4];
221
Elliott Karpilovskycbe219b2020-04-22 16:21:06 -0700222 aom_codec_iface_t *decoder = get_aom_decoder_by_fourcc(info->codec_fourcc);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700223 if (!decoder) die("Unknown input codec.");
Elliott Karpilovskycbe219b2020-04-22 16:21:06 -0700224 printf("Using %s\n", aom_codec_iface_name(decoder));
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700225
Elliott Karpilovskycbe219b2020-04-22 16:21:06 -0700226 aom_codec_ctx_t codec;
227 if (aom_codec_dec_init(&codec, decoder, NULL, 0))
James Zerndad374f2020-05-06 19:13:19 -0700228 die("Failed to initialize decoder.");
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700229
230 // Decode anchor frames.
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700231 AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_TILE_MODE, 0);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700232
Ryan Overbeck18521392018-09-21 09:43:24 -0700233 printf("Reading %d reference images.\n", num_references);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700234 for (i = 0; i < num_references; ++i) {
235 aom_video_reader_read_frame(reader);
236
237 size_t frame_size = 0;
238 const unsigned char *frame =
239 aom_video_reader_get_frame(reader, &frame_size);
Yunqing Wang946ec2b2018-06-06 12:34:23 -0700240 pts = (aom_codec_pts_t)aom_video_reader_get_frame_pts(reader);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700241
242 // Copy references bitstream directly.
243 if (!aom_video_writer_write_frame(writer, frame, frame_size, pts))
244 die_codec(&codec, "Failed to copy compressed anchor frame.");
245
246 if (aom_codec_decode(&codec, frame, frame_size, NULL))
247 die_codec(&codec, "Failed to decode frame.");
248 }
249
250 // Decode camera frames.
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700251 AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_TILE_MODE, 1);
252 AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_EXT_TILE_DEBUG, 1);
Yunqing Wang946ec2b2018-06-06 12:34:23 -0700253
254 FILE *infile = aom_video_reader_get_file(reader);
255 // Record the offset of the first camera image.
256 const FileOffset camera_frame_pos = ftello(infile);
257
Ryan Overbeck18521392018-09-21 09:43:24 -0700258 printf("Loading compressed frames into memory.\n");
259
260 // Count the frames in the lightfield.
261 int num_frames = 0;
262 while (aom_video_reader_read_frame(reader)) {
263 ++num_frames;
264 }
265 if (num_frames < 1) die("Input light field has no frames.");
266
267 // Read all of the lightfield frames into memory.
268 unsigned char **frames =
269 (unsigned char **)malloc(num_frames * sizeof(unsigned char *));
270 size_t *frame_sizes = (size_t *)malloc(num_frames * sizeof(size_t));
271 // Seek to the first camera image.
272 fseeko(infile, camera_frame_pos, SEEK_SET);
273 for (int f = 0; f < num_frames; ++f) {
274 aom_video_reader_read_frame(reader);
275 size_t frame_size = 0;
276 const unsigned char *frame =
277 aom_video_reader_get_frame(reader, &frame_size);
278 frames[f] = (unsigned char *)malloc(frame_size * sizeof(unsigned char));
279 memcpy(frames[f], frame, frame_size);
280 frame_sizes[f] = frame_size;
281 }
282 printf("Read %d frames.\n", num_frames);
Yunqing Wang946ec2b2018-06-06 12:34:23 -0700283
284 // Copy first camera frame for getting camera frame header. This is done
285 // only once.
286 {
Ryan Overbeck18521392018-09-21 09:43:24 -0700287 size_t frame_size = frame_sizes[0];
288 const unsigned char *frame = frames[0];
289 pts = num_references;
Yunqing Wang3f9c1e22018-06-16 16:48:15 -0700290 aom_tile_data frame_header_info = { 0, NULL, 0 };
Yunqing Wang946ec2b2018-06-06 12:34:23 -0700291
Yunqing Wang3f9c1e22018-06-16 16:48:15 -0700292 // Need to decode frame header to get camera frame header info. So, here
293 // decoding 1 tile is enough.
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700294 AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_DECODE_TILE_ROW, 0);
295 AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1_SET_DECODE_TILE_COL, 0);
Yunqing Wang3f9c1e22018-06-16 16:48:15 -0700296
297 aom_codec_err_t aom_status =
298 aom_codec_decode(&codec, frame, frame_size, NULL);
299 if (aom_status) die_codec(&codec, "Failed to decode tile.");
300
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700301 AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_FRAME_HEADER_INFO,
302 &frame_header_info);
Yunqing Wang3f9c1e22018-06-16 16:48:15 -0700303
304 size_t obu_size_offset =
305 (uint8_t *)frame_header_info.coded_tile_data - frame;
306 size_t length_field_size = frame_header_info.coded_tile_data_size;
Yaowu Xu6fbfae32018-06-18 10:58:11 -0700307 // Remove ext-tile tile info.
308 uint32_t frame_header_size = (uint32_t)frame_header_info.extra_size - 1;
Yunqing Wang3f9c1e22018-06-16 16:48:15 -0700309 size_t bytes_to_copy =
310 obu_size_offset + length_field_size + frame_header_size;
311
312 unsigned char *frame_hdr_buf = (unsigned char *)malloc(bytes_to_copy);
313 if (frame_hdr_buf == NULL)
314 die_codec(&codec, "Failed to allocate frame header buffer.");
315
316 memcpy(frame_hdr_buf, frame, bytes_to_copy);
317
318 // Update frame header OBU size.
319 size_t bytes_written = 0;
320 if (aom_uleb_encode_fixed_size(
321 frame_header_size, length_field_size, length_field_size,
322 frame_hdr_buf + obu_size_offset, &bytes_written))
323 die_codec(&codec, "Failed to encode the tile list obu size.");
324
325 // Copy camera frame header bitstream.
326 if (!aom_video_writer_write_frame(writer, frame_hdr_buf, bytes_to_copy,
327 pts))
328 die_codec(&codec, "Failed to copy compressed camera frame header.");
Yunqing Wangaecdda82018-07-26 12:41:56 -0700329 free(frame_hdr_buf);
Yunqing Wang946ec2b2018-06-06 12:34:23 -0700330 }
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700331
Yunqing Wangd74f5682018-07-12 14:34:56 -0700332 // Read out the image format.
333 aom_img_fmt_t ref_fmt = 0;
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700334 if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_IMG_FORMAT, &ref_fmt))
Yunqing Wangd74f5682018-07-12 14:34:56 -0700335 die_codec(&codec, "Failed to get the image format");
336 const int bps = get_image_bps(ref_fmt);
Yunqing Wangaecdda82018-07-26 12:41:56 -0700337 if (!bps) die_codec(&codec, "Invalid image format.");
Yunqing Wangd74f5682018-07-12 14:34:56 -0700338 // read out the tile size.
339 unsigned int tile_size = 0;
Elliott Karpilovsky60dd0f92020-04-30 19:19:27 -0700340 if (AOM_CODEC_CONTROL_TYPECHECKED(&codec, AV1D_GET_TILE_SIZE, &tile_size))
Yunqing Wangd74f5682018-07-12 14:34:56 -0700341 die_codec(&codec, "Failed to get the tile size");
342 const unsigned int tile_width = tile_size >> 16;
343 const unsigned int tile_height = tile_size & 65535;
344 // Allocate a buffer to store tile list bitstream.
345 const size_t data_sz = MAX_TILES * ALIGN_POWER_OF_TWO(tile_width, 5) *
346 ALIGN_POWER_OF_TWO(tile_height, 5) * bps / 8;
Ryan Overbeck18521392018-09-21 09:43:24 -0700347
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700348 unsigned char *tl_buf = (unsigned char *)malloc(data_sz);
349 if (tl_buf == NULL) die_codec(&codec, "Failed to allocate tile list buffer.");
350
Ryan Overbeck18521392018-09-21 09:43:24 -0700351 aom_codec_pts_t tl_pts = num_references;
Yunqing Wang6ff48092018-11-13 14:10:48 -0800352 const uint8_t output_frame_width_in_tiles_minus_1 =
353 output_frame_width / tile_width - 1;
354 const uint8_t output_frame_height_in_tiles_minus_1 =
355 output_frame_height / tile_height - 1;
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700356
Ryan Overbeck18521392018-09-21 09:43:24 -0700357 printf("Reading tile list from file.\n");
358 char line[1024];
359 FILE *tile_list_fptr = fopen(tile_list_file, "r");
David Turner69c98e42018-11-09 14:17:20 +0000360 if (!tile_list_fptr) die_codec(&codec, "Failed to open tile list file.");
Ryan Overbeck18521392018-09-21 09:43:24 -0700361 int num_tiles = 0;
362 TILE_LIST_INFO tiles[MAX_TILES];
363 while ((fgets(line, 1024, tile_list_fptr)) != NULL) {
364 if (line[0] == 'F' || num_tiles >= MAX_TILES) {
365 // Flush existing tile list and start another, either because we hit a
366 // new render frame or because we've hit our max number of tiles per list.
367 if (num_tiles > 0) {
368 process_tile_list(tiles, num_tiles, tl_pts, frames, frame_sizes, &codec,
Yunqing Wang6ff48092018-11-13 14:10:48 -0800369 tl_buf, writer, output_frame_width_in_tiles_minus_1,
370 output_frame_height_in_tiles_minus_1);
Ryan Overbeck18521392018-09-21 09:43:24 -0700371 ++tl_pts;
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700372 }
Ryan Overbeck18521392018-09-21 09:43:24 -0700373 num_tiles = 0;
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700374 }
Ryan Overbeck18521392018-09-21 09:43:24 -0700375 if (line[0] == 'F') {
376 continue;
377 }
378 if (sscanf(line, "%d %d %d %d", &tiles[num_tiles].image_idx,
379 &tiles[num_tiles].reference_idx, &tiles[num_tiles].tile_col,
380 &tiles[num_tiles].tile_row) == 4) {
381 if (tiles[num_tiles].image_idx >= num_frames) {
382 die("Tile list image_idx out of bounds: %d >= %d.",
383 tiles[num_tiles].image_idx, num_frames);
384 }
385 if (tiles[num_tiles].reference_idx >= num_references) {
386 die("Tile list reference_idx out of bounds: %d >= %d.",
387 tiles[num_tiles].reference_idx, num_references);
388 }
389 ++num_tiles;
390 }
391 }
392 if (num_tiles > 0) {
393 // Flush out the last tile list.
394 process_tile_list(tiles, num_tiles, tl_pts, frames, frame_sizes, &codec,
Yunqing Wang6ff48092018-11-13 14:10:48 -0800395 tl_buf, writer, output_frame_width_in_tiles_minus_1,
396 output_frame_height_in_tiles_minus_1);
Ryan Overbeck18521392018-09-21 09:43:24 -0700397 ++tl_pts;
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700398 }
399
Zoe Liu81738a22018-09-27 11:40:08 -0700400 const int num_tile_lists = (int)(tl_pts - pts);
Ryan Overbeck18521392018-09-21 09:43:24 -0700401 printf("Finished processing tile lists. Num tile lists: %d.\n",
402 num_tile_lists);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700403 free(tl_buf);
Ryan Overbeck18521392018-09-21 09:43:24 -0700404 for (int f = 0; f < num_frames; ++f) {
405 free(frames[f]);
406 }
407 free(frame_sizes);
408 free(frames);
Yunqing Wang40bde4d2018-06-01 16:48:03 -0700409 if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
410 aom_video_writer_close(writer);
411 aom_video_reader_close(reader);
412
413 return EXIT_SUCCESS;
414}