mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-10 01:07:31 +09:00
aom: update libaom to 0ec86ac7ae1e32a7e70410fa4972a655ec3670a4
This commit is contained in:
parent
bc3f20e378
commit
eb361970c5
438 changed files with 52661 additions and 21905 deletions
305
third_party/aom/examples/lightfield_decoder.c
vendored
305
third_party/aom/examples/lightfield_decoder.c
vendored
|
|
@ -14,10 +14,26 @@
|
|||
//
|
||||
// This is an example of a simple lightfield decoder. It builds upon the
|
||||
// simple_decoder.c example. It takes an input file containing the compressed
|
||||
// data (in ivf format), treating it as a lightfield instead of a video.
|
||||
// data (in ivf format), treating it as a lightfield instead of a video; and a
|
||||
// text file with a list of tiles to decode. There is an optional parameter
|
||||
// allowing to choose the output format, and the supported formats are
|
||||
// YUV1D(default), YUV, and NV12.
|
||||
// After running the lightfield encoder, run lightfield decoder to decode a
|
||||
// batch of tiles:
|
||||
// examples/lightfield_decoder vase10x10.ivf vase_reference.yuv 4
|
||||
// examples/lightfield_decoder vase10x10.ivf vase_reference.yuv 4 tile_list.txt
|
||||
// 0(optional)
|
||||
// The tile_list.txt is expected to be of the form:
|
||||
// Frame <frame_index0>
|
||||
// <image_index0> <anchor_index0> <tile_col0> <tile_row0>
|
||||
// <image_index1> <anchor_index1> <tile_col1> <tile_row1>
|
||||
// ...
|
||||
// Frame <frame_index1)
|
||||
// ...
|
||||
//
|
||||
// The "Frame" markers indicate a new render frame and thus a new tile list
|
||||
// will be started and the old one flushed. The image_indexN, anchor_indexN,
|
||||
// tile_colN, and tile_rowN identify an individual tile to be decoded and
|
||||
// to use anchor_indexN anchor image for MCP.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -33,43 +49,109 @@
|
|||
static const char *exec_name;
|
||||
|
||||
void usage_exit(void) {
|
||||
fprintf(stderr, "Usage: %s <infile> <outfile> <num_references>\n", exec_name);
|
||||
fprintf(stderr,
|
||||
"Usage: %s <infile> <outfile> <num_references> <tile_list> <output "
|
||||
"format(optional)>\n",
|
||||
exec_name);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Tile list entry provided by the application
|
||||
typedef struct {
|
||||
int image_idx;
|
||||
int reference_idx;
|
||||
int tile_col;
|
||||
int tile_row;
|
||||
} TILE_LIST_INFO;
|
||||
// Output frame size
|
||||
const int output_frame_width = 512;
|
||||
const int output_frame_height = 512;
|
||||
|
||||
// M references: 0 - M-1; N images(including references): 0 - N-1;
|
||||
// Note: order the image index incrementally, so that we only go through the
|
||||
// bitstream once to construct the tile list.
|
||||
const int num_tile_lists = 2;
|
||||
const uint16_t tile_count_minus_1 = 9 - 1;
|
||||
const TILE_LIST_INFO tile_list[2][9] = {
|
||||
{ { 16, 0, 4, 5 },
|
||||
{ 83, 3, 13, 2 },
|
||||
{ 57, 2, 2, 6 },
|
||||
{ 31, 1, 11, 5 },
|
||||
{ 2, 0, 7, 4 },
|
||||
{ 77, 3, 9, 9 },
|
||||
{ 49, 1, 0, 1 },
|
||||
{ 6, 0, 3, 10 },
|
||||
{ 63, 2, 5, 8 } },
|
||||
{ { 65, 2, 11, 1 },
|
||||
{ 42, 1, 3, 7 },
|
||||
{ 88, 3, 8, 4 },
|
||||
{ 76, 3, 1, 15 },
|
||||
{ 1, 0, 2, 2 },
|
||||
{ 19, 0, 5, 6 },
|
||||
{ 60, 2, 4, 0 },
|
||||
{ 25, 1, 11, 15 },
|
||||
{ 50, 2, 5, 4 } },
|
||||
};
|
||||
static void aom_img_copy_tile(const aom_image_t *src, const aom_image_t *dst,
|
||||
int dst_row_offset, int dst_col_offset) {
|
||||
const int shift = (src->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 1 : 0;
|
||||
int plane;
|
||||
|
||||
for (plane = 0; plane < 3; ++plane) {
|
||||
const unsigned char *src_buf = src->planes[plane];
|
||||
const int src_stride = src->stride[plane];
|
||||
unsigned char *dst_buf = dst->planes[plane];
|
||||
const int dst_stride = dst->stride[plane];
|
||||
const int roffset =
|
||||
(plane > 0) ? dst_row_offset >> dst->y_chroma_shift : dst_row_offset;
|
||||
const int coffset =
|
||||
(plane > 0) ? dst_col_offset >> dst->x_chroma_shift : dst_col_offset;
|
||||
|
||||
// col offset needs to be adjusted for HBD.
|
||||
dst_buf += roffset * dst_stride + (coffset << shift);
|
||||
|
||||
const int w = (aom_img_plane_width(src, plane) << shift);
|
||||
const int h = aom_img_plane_height(src, plane);
|
||||
int y;
|
||||
|
||||
for (y = 0; y < h; ++y) {
|
||||
memcpy(dst_buf, src_buf, w);
|
||||
src_buf += src_stride;
|
||||
dst_buf += dst_stride;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void decode_tile(aom_codec_ctx_t *codec, const unsigned char *frame,
|
||||
size_t frame_size, int tr, int tc, int ref_idx,
|
||||
aom_image_t *reference_images, aom_image_t *output,
|
||||
int *tile_idx, unsigned int *output_bit_depth,
|
||||
aom_image_t **img_ptr, int output_format) {
|
||||
aom_codec_control_(codec, AV1_SET_TILE_MODE, 1);
|
||||
aom_codec_control_(codec, AV1D_EXT_TILE_DEBUG, 1);
|
||||
aom_codec_control_(codec, AV1_SET_DECODE_TILE_ROW, tr);
|
||||
aom_codec_control_(codec, AV1_SET_DECODE_TILE_COL, tc);
|
||||
|
||||
av1_ref_frame_t ref;
|
||||
ref.idx = 0;
|
||||
ref.use_external_ref = 1;
|
||||
ref.img = reference_images[ref_idx];
|
||||
if (aom_codec_control(codec, AV1_SET_REFERENCE, &ref)) {
|
||||
die_codec(codec, "Failed to set reference frame.");
|
||||
}
|
||||
|
||||
aom_codec_err_t aom_status = aom_codec_decode(codec, frame, frame_size, NULL);
|
||||
if (aom_status) die_codec(codec, "Failed to decode tile.");
|
||||
|
||||
aom_codec_iter_t iter = NULL;
|
||||
aom_image_t *img = aom_codec_get_frame(codec, &iter);
|
||||
if (!img) die_codec(codec, "Failed to get frame.");
|
||||
*img_ptr = img;
|
||||
|
||||
// aom_img_alloc() sets bit_depth as follows:
|
||||
// output->bit_depth = (fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 16 : 8;
|
||||
// Use img->bit_depth(read from bitstream), so that aom_shift_img()
|
||||
// works as expected.
|
||||
output->bit_depth = img->bit_depth;
|
||||
*output_bit_depth = img->bit_depth;
|
||||
|
||||
if (output_format != YUV1D) {
|
||||
// read out the tile size.
|
||||
unsigned int tile_size = 0;
|
||||
if (aom_codec_control(codec, AV1D_GET_TILE_SIZE, &tile_size))
|
||||
die_codec(codec, "Failed to get the tile size");
|
||||
const unsigned int tile_width = tile_size >> 16;
|
||||
const unsigned int tile_height = tile_size & 65535;
|
||||
const uint8_t output_frame_width_in_tiles = output_frame_width / tile_width;
|
||||
|
||||
// Copy the tile to the output frame.
|
||||
const int row_offset =
|
||||
(*tile_idx / output_frame_width_in_tiles) * tile_height;
|
||||
const int col_offset =
|
||||
(*tile_idx % output_frame_width_in_tiles) * tile_width;
|
||||
|
||||
aom_img_copy_tile(img, output, row_offset, col_offset);
|
||||
(*tile_idx)++;
|
||||
}
|
||||
}
|
||||
|
||||
static void img_write_to_file(const aom_image_t *img, FILE *file,
|
||||
int output_format) {
|
||||
if (output_format == YUV)
|
||||
aom_img_write(img, file);
|
||||
else if (output_format == NV12)
|
||||
aom_img_write_nv12(img, file);
|
||||
else
|
||||
die("Invalid output format");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
FILE *outfile = NULL;
|
||||
|
|
@ -78,13 +160,18 @@ int main(int argc, char **argv) {
|
|||
const AvxInterface *decoder = NULL;
|
||||
const AvxVideoInfo *info = NULL;
|
||||
int num_references;
|
||||
aom_img_fmt_t ref_fmt = 0;
|
||||
aom_image_t reference_images[MAX_EXTERNAL_REFERENCES];
|
||||
aom_image_t output;
|
||||
aom_image_t *output_shifted = NULL;
|
||||
size_t frame_size = 0;
|
||||
const unsigned char *frame = NULL;
|
||||
int n, i, j;
|
||||
int i, j;
|
||||
const char *tile_list_file = NULL;
|
||||
int output_format = YUV1D;
|
||||
exec_name = argv[0];
|
||||
|
||||
if (argc != 4) die("Invalid number of arguments.");
|
||||
if (argc < 5) die("Invalid number of arguments.");
|
||||
|
||||
reader = aom_video_reader_open(argv[1]);
|
||||
if (!reader) die("Failed to open %s for reading.", argv[1]);
|
||||
|
|
@ -93,11 +180,18 @@ int main(int argc, char **argv) {
|
|||
die("Failed to open %s for writing.", argv[2]);
|
||||
|
||||
num_references = (int)strtol(argv[3], NULL, 0);
|
||||
tile_list_file = argv[4];
|
||||
|
||||
if (argc > 5) output_format = (int)strtol(argv[5], NULL, 0);
|
||||
if (output_format < YUV1D || output_format > NV12)
|
||||
die("Output format out of range [0, 2]");
|
||||
|
||||
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))
|
||||
|
|
@ -116,7 +210,6 @@ int main(int argc, char **argv) {
|
|||
die_codec(&codec, "Failed to decode frame.");
|
||||
|
||||
if (i == 0) {
|
||||
aom_img_fmt_t ref_fmt = 0;
|
||||
if (aom_codec_control(&codec, AV1D_GET_IMG_FORMAT, &ref_fmt))
|
||||
die_codec(&codec, "Failed to get the image format");
|
||||
|
||||
|
|
@ -127,7 +220,7 @@ int main(int argc, char **argv) {
|
|||
// Allocate memory to store decoded references. Allocate memory with the
|
||||
// border so that it can be used as a reference.
|
||||
for (j = 0; j < num_references; j++) {
|
||||
unsigned int border = AOM_BORDER_IN_PIXELS;
|
||||
unsigned int border = AOM_DEC_BORDER_IN_PIXELS;
|
||||
if (!aom_img_alloc_with_border(&reference_images[j], ref_fmt,
|
||||
frame_res[0], frame_res[1], 32, 8,
|
||||
border)) {
|
||||
|
|
@ -156,50 +249,110 @@ int main(int argc, char **argv) {
|
|||
// Record the offset of the first camera image.
|
||||
const FileOffset camera_frame_pos = ftello(infile);
|
||||
|
||||
// Process 1 tile.
|
||||
for (n = 0; n < num_tile_lists; n++) {
|
||||
for (i = 0; i <= tile_count_minus_1; i++) {
|
||||
int image_idx = tile_list[n][i].image_idx;
|
||||
int ref_idx = tile_list[n][i].reference_idx;
|
||||
int tc = tile_list[n][i].tile_col;
|
||||
int tr = tile_list[n][i].tile_row;
|
||||
int frame_cnt = -1;
|
||||
printf("Loading compressed frames into memory.\n");
|
||||
|
||||
// Seek to the first camera image.
|
||||
fseeko(infile, camera_frame_pos, SEEK_SET);
|
||||
// Count the frames in the lightfield.
|
||||
int num_frames = 0;
|
||||
while (aom_video_reader_read_frame(reader)) {
|
||||
++num_frames;
|
||||
}
|
||||
if (num_frames < 1) die("Input light field has no frames.");
|
||||
|
||||
// Read out the camera image
|
||||
while (frame_cnt != image_idx) {
|
||||
aom_video_reader_read_frame(reader);
|
||||
frame_cnt++;
|
||||
// Read all of the lightfield frames into memory.
|
||||
unsigned char **frames =
|
||||
(unsigned char **)malloc(num_frames * sizeof(unsigned char *));
|
||||
size_t *frame_sizes = (size_t *)malloc(num_frames * sizeof(size_t));
|
||||
// Seek to the first camera image.
|
||||
fseeko(infile, camera_frame_pos, SEEK_SET);
|
||||
for (int f = 0; f < num_frames; ++f) {
|
||||
aom_video_reader_read_frame(reader);
|
||||
frame = aom_video_reader_get_frame(reader, &frame_size);
|
||||
frames[f] = (unsigned char *)malloc(frame_size * sizeof(unsigned char));
|
||||
memcpy(frames[f], frame, frame_size);
|
||||
frame_sizes[f] = frame_size;
|
||||
}
|
||||
printf("Read %d frames.\n", num_frames);
|
||||
|
||||
if (output_format != YUV1D) {
|
||||
// Allocate the output frame.
|
||||
aom_img_fmt_t out_fmt = ref_fmt;
|
||||
if (!CONFIG_LOWBITDEPTH) out_fmt |= AOM_IMG_FMT_HIGHBITDEPTH;
|
||||
if (!aom_img_alloc(&output, out_fmt, output_frame_width,
|
||||
output_frame_height, 32))
|
||||
die("Failed to allocate output image.");
|
||||
}
|
||||
|
||||
printf("Decoding tile list from file.\n");
|
||||
char line[1024];
|
||||
FILE *tile_list_fptr = fopen(tile_list_file, "r");
|
||||
int tile_list_cnt = 0;
|
||||
int tile_list_writes = 0;
|
||||
int tile_idx = 0;
|
||||
aom_image_t *out = NULL;
|
||||
unsigned int output_bit_depth = 0;
|
||||
|
||||
while ((fgets(line, 1024, tile_list_fptr)) != NULL) {
|
||||
if (line[0] == 'F') {
|
||||
if (output_format != YUV1D) {
|
||||
// Write out the tile list.
|
||||
if (tile_list_cnt) {
|
||||
out = &output;
|
||||
if (output_bit_depth != 0)
|
||||
aom_shift_img(output_bit_depth, &out, &output_shifted);
|
||||
img_write_to_file(out, outfile, output_format);
|
||||
tile_list_writes++;
|
||||
}
|
||||
|
||||
tile_list_cnt++;
|
||||
tile_idx = 0;
|
||||
// Then memset the frame.
|
||||
memset(output.img_data, 0, output.sz);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
frame = aom_video_reader_get_frame(reader, &frame_size);
|
||||
int image_idx, ref_idx, tc, tr;
|
||||
sscanf(line, "%d %d %d %d", &image_idx, &ref_idx, &tc, &tr);
|
||||
if (image_idx >= num_frames) {
|
||||
die("Tile list image_idx out of bounds: %d >= %d.", image_idx,
|
||||
num_frames);
|
||||
}
|
||||
if (ref_idx >= num_references) {
|
||||
die("Tile list ref_idx out of bounds: %d >= %d.", ref_idx,
|
||||
num_references);
|
||||
}
|
||||
frame = frames[image_idx];
|
||||
frame_size = frame_sizes[image_idx];
|
||||
|
||||
aom_codec_control_(&codec, AV1_SET_TILE_MODE, 1);
|
||||
aom_codec_control_(&codec, AV1D_EXT_TILE_DEBUG, 1);
|
||||
aom_codec_control_(&codec, AV1_SET_DECODE_TILE_ROW, tr);
|
||||
aom_codec_control_(&codec, AV1_SET_DECODE_TILE_COL, tc);
|
||||
|
||||
av1_ref_frame_t ref;
|
||||
ref.idx = 0;
|
||||
ref.use_external_ref = 1;
|
||||
ref.img = reference_images[ref_idx];
|
||||
if (aom_codec_control(&codec, AV1_SET_REFERENCE, &ref)) {
|
||||
die_codec(&codec, "Failed to set reference frame.");
|
||||
}
|
||||
|
||||
aom_codec_err_t aom_status =
|
||||
aom_codec_decode(&codec, frame, frame_size, NULL);
|
||||
if (aom_status) die_codec(&codec, "Failed to decode tile.");
|
||||
|
||||
aom_codec_iter_t iter = NULL;
|
||||
aom_image_t *img = aom_codec_get_frame(&codec, &iter);
|
||||
aom_img_write(img, outfile);
|
||||
aom_image_t *img = NULL;
|
||||
decode_tile(&codec, frame, frame_size, tr, tc, ref_idx, reference_images,
|
||||
&output, &tile_idx, &output_bit_depth, &img, output_format);
|
||||
if (output_format == YUV1D) {
|
||||
out = img;
|
||||
if (output_bit_depth != 0)
|
||||
aom_shift_img(output_bit_depth, &out, &output_shifted);
|
||||
aom_img_write(out, outfile);
|
||||
}
|
||||
}
|
||||
|
||||
if (output_format != YUV1D) {
|
||||
// Write out the last tile list.
|
||||
if (tile_list_writes < tile_list_cnt) {
|
||||
out = &output;
|
||||
if (output_bit_depth != 0)
|
||||
aom_shift_img(output_bit_depth, &out, &output_shifted);
|
||||
img_write_to_file(out, outfile, output_format);
|
||||
}
|
||||
}
|
||||
|
||||
if (output_shifted) aom_img_free(output_shifted);
|
||||
if (output_format != YUV1D) aom_img_free(&output);
|
||||
for (i = 0; i < num_references; i++) aom_img_free(&reference_images[i]);
|
||||
for (int f = 0; f < num_frames; ++f) {
|
||||
free(frames[f]);
|
||||
}
|
||||
free(frame_sizes);
|
||||
free(frames);
|
||||
if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
|
||||
aom_video_reader_close(reader);
|
||||
fclose(outfile);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue