summaryrefslogtreecommitdiffstats
path: root/third_party/aom/examples/aom_cx_set_ref.c
diff options
context:
space:
mode:
authortrav90 <travawine@palemoon.org>2018-10-19 21:52:15 -0500
committertrav90 <travawine@palemoon.org>2018-10-19 21:52:20 -0500
commitbbcc64772580c8a979288791afa02d30bc476d2e (patch)
tree437ce94c3fdd7497508e5b55de06c6d011678597 /third_party/aom/examples/aom_cx_set_ref.c
parent14805f6ddbfb173c327768fff9f81f40ce5e81b0 (diff)
downloadUXP-bbcc64772580c8a979288791afa02d30bc476d2e.tar
UXP-bbcc64772580c8a979288791afa02d30bc476d2e.tar.gz
UXP-bbcc64772580c8a979288791afa02d30bc476d2e.tar.lz
UXP-bbcc64772580c8a979288791afa02d30bc476d2e.tar.xz
UXP-bbcc64772580c8a979288791afa02d30bc476d2e.zip
Update aom to v1.0.0
Update aom to commit id d14c5bb4f336ef1842046089849dee4a301fbbf0.
Diffstat (limited to 'third_party/aom/examples/aom_cx_set_ref.c')
-rw-r--r--third_party/aom/examples/aom_cx_set_ref.c119
1 files changed, 91 insertions, 28 deletions
diff --git a/third_party/aom/examples/aom_cx_set_ref.c b/third_party/aom/examples/aom_cx_set_ref.c
index 456e81300..e02e94c07 100644
--- a/third_party/aom/examples/aom_cx_set_ref.c
+++ b/third_party/aom/examples/aom_cx_set_ref.c
@@ -51,12 +51,14 @@
#include <stdlib.h>
#include <string.h>
-#include "aom/aomcx.h"
#include "aom/aom_decoder.h"
#include "aom/aom_encoder.h"
+#include "aom/aomcx.h"
+#include "common/tools_common.h"
+#include "common/video_writer.h"
#include "examples/encoder_util.h"
-#include "./tools_common.h"
-#include "./video_writer.h"
+
+#define AOM_BORDER_IN_PIXELS 288
static const char *exec_name;
@@ -71,25 +73,41 @@ void usage_exit() {
static void testing_decode(aom_codec_ctx_t *encoder, aom_codec_ctx_t *decoder,
unsigned int frame_out, int *mismatch_seen) {
aom_image_t enc_img, dec_img;
- struct av1_ref_frame ref_enc, ref_dec;
if (*mismatch_seen) return;
- ref_enc.idx = 0;
- ref_dec.idx = 0;
- if (aom_codec_control(encoder, AV1_GET_REFERENCE, &ref_enc))
+ /* Get the internal reference frame */
+ if (aom_codec_control(encoder, AV1_GET_NEW_FRAME_IMAGE, &enc_img))
die_codec(encoder, "Failed to get encoder reference frame");
- enc_img = ref_enc.img;
- if (aom_codec_control(decoder, AV1_GET_REFERENCE, &ref_dec))
+ if (aom_codec_control(decoder, AV1_GET_NEW_FRAME_IMAGE, &dec_img))
die_codec(decoder, "Failed to get decoder reference frame");
- dec_img = ref_dec.img;
+
+ if ((enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) !=
+ (dec_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH)) {
+ if (enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
+ aom_image_t enc_hbd_img;
+ aom_img_alloc(&enc_hbd_img, enc_img.fmt - AOM_IMG_FMT_HIGHBITDEPTH,
+ enc_img.d_w, enc_img.d_h, 16);
+ aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
+ enc_img = enc_hbd_img;
+ }
+ if (dec_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
+ aom_image_t dec_hbd_img;
+ aom_img_alloc(&dec_hbd_img, dec_img.fmt - AOM_IMG_FMT_HIGHBITDEPTH,
+ dec_img.d_w, dec_img.d_h, 16);
+ aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
+ dec_img = dec_hbd_img;
+ }
+ }
if (!aom_compare_img(&enc_img, &dec_img)) {
int y[4], u[4], v[4];
+ if (enc_img.fmt & AOM_IMG_FMT_HIGHBITDEPTH) {
+ aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
+ } else {
+ aom_find_mismatch(&enc_img, &dec_img, y, u, v);
+ }
- *mismatch_seen = 1;
-
- aom_find_mismatch(&enc_img, &dec_img, y, u, v);
printf(
"Encode/decode mismatch on frame %d at"
" Y[%d, %d] {%d/%d},"
@@ -97,6 +115,7 @@ static void testing_decode(aom_codec_ctx_t *encoder, aom_codec_ctx_t *decoder,
" V[%d, %d] {%d/%d}",
frame_out, y[0], y[1], y[2], y[3], u[0], u[1], u[2], u[3], v[0], v[1],
v[2], v[3]);
+ *mismatch_seen = 1;
}
aom_img_free(&enc_img);
@@ -106,13 +125,13 @@ static void testing_decode(aom_codec_ctx_t *encoder, aom_codec_ctx_t *decoder,
static int encode_frame(aom_codec_ctx_t *ecodec, aom_image_t *img,
unsigned int frame_in, AvxVideoWriter *writer,
int test_decode, aom_codec_ctx_t *dcodec,
- unsigned int *frame_out, int *mismatch_seen) {
+ unsigned int *frame_out, int *mismatch_seen,
+ aom_image_t *ext_ref) {
int got_pkts = 0;
aom_codec_iter_t iter = NULL;
const aom_codec_cx_pkt_t *pkt = NULL;
int got_data;
- const aom_codec_err_t res =
- aom_codec_encode(ecodec, img, frame_in, 1, 0, AOM_DL_GOOD_QUALITY);
+ const aom_codec_err_t res = aom_codec_encode(ecodec, img, frame_in, 1, 0);
if (res != AOM_CODEC_OK) die_codec(ecodec, "Failed to encode frame");
got_data = 0;
@@ -139,8 +158,13 @@ static int encode_frame(aom_codec_ctx_t *ecodec, aom_image_t *img,
// Decode 1 frame.
if (test_decode) {
if (aom_codec_decode(dcodec, pkt->data.frame.buf,
- (unsigned int)pkt->data.frame.sz, NULL, 0))
+ (unsigned int)pkt->data.frame.sz, NULL))
die_codec(dcodec, "Failed to decode frame.");
+
+ // Copy out first decoded frame, and use it as reference later.
+ if (*frame_out == 1 && ext_ref != NULL)
+ if (aom_codec_control(dcodec, AV1_GET_NEW_FRAME_IMAGE, ext_ref))
+ die_codec(dcodec, "Failed to get decoder new frame");
}
}
}
@@ -160,10 +184,16 @@ int main(int argc, char **argv) {
aom_codec_enc_cfg_t cfg;
unsigned int frame_in = 0;
aom_image_t raw;
+ aom_image_t raw_shift;
+ aom_image_t ext_ref;
aom_codec_err_t res;
AvxVideoInfo info;
AvxVideoWriter *writer = NULL;
const AvxInterface *encoder = NULL;
+ int flags = 0;
+ int allocated_raw_shift = 0;
+ aom_img_fmt_t raw_fmt = AOM_IMG_FMT_I420;
+ aom_img_fmt_t ref_fmt = AOM_IMG_FMT_I420;
// Test encoder/decoder mismatch.
int test_decode = 1;
@@ -225,13 +255,21 @@ int main(int argc, char **argv) {
info.time_base.numerator = 1;
info.time_base.denominator = fps;
- if (info.frame_width <= 0 || info.frame_height <= 0 ||
- (info.frame_width % 2) != 0 || (info.frame_height % 2) != 0) {
+ if (info.frame_width <= 0 || info.frame_height <= 0) {
die("Invalid frame size: %dx%d", info.frame_width, info.frame_height);
}
- if (!aom_img_alloc(&raw, AOM_IMG_FMT_I420, info.frame_width,
- info.frame_height, 1)) {
+ // In this test, the bit depth of input video is 8-bit, and the input format
+ // is AOM_IMG_FMT_I420.
+ if (!aom_img_alloc(&raw, raw_fmt, info.frame_width, info.frame_height, 32)) {
+ die("Failed to allocate image.");
+ }
+
+ if (!CONFIG_LOWBITDEPTH) ref_fmt |= AOM_IMG_FMT_HIGHBITDEPTH;
+ // Allocate memory with the border so that it can be used as a reference.
+ if (!aom_img_alloc_with_border(&ext_ref, ref_fmt, info.frame_width,
+ info.frame_height, 32, 8,
+ AOM_BORDER_IN_PIXELS)) {
die("Failed to allocate image.");
}
@@ -246,6 +284,11 @@ int main(int argc, char **argv) {
cfg.g_timebase.den = info.time_base.denominator;
cfg.rc_target_bitrate = bitrate;
cfg.g_lag_in_frames = 3;
+ cfg.g_bit_depth = AOM_BITS_8;
+
+ flags |= (cfg.g_bit_depth > AOM_BITS_8 || !CONFIG_LOWBITDEPTH)
+ ? AOM_CODEC_USE_HIGHBITDEPTH
+ : 0;
writer = aom_video_writer_open(outfile_arg, kContainerIVF, &info);
if (!writer) die("Failed to open %s for writing.", outfile_arg);
@@ -253,7 +296,7 @@ int main(int argc, char **argv) {
if (!(infile = fopen(infile_arg, "rb")))
die("Failed to open %s for reading.", infile_arg);
- if (aom_codec_enc_init(&ecodec, encoder->codec_interface(), &cfg, 0))
+ if (aom_codec_enc_init(&ecodec, encoder->codec_interface(), &cfg, flags))
die_codec(&ecodec, "Failed to initialize encoder");
// Disable alt_ref.
@@ -269,25 +312,43 @@ int main(int argc, char **argv) {
// Encode frames.
while (aom_img_read(&raw, infile)) {
if (limit && frame_in >= limit) break;
+ aom_image_t *frame_to_encode;
+
+ if (!CONFIG_LOWBITDEPTH) {
+ // Need to allocate larger buffer to use hbd internal.
+ int input_shift = 0;
+ if (!allocated_raw_shift) {
+ aom_img_alloc(&raw_shift, raw_fmt | AOM_IMG_FMT_HIGHBITDEPTH,
+ info.frame_width, info.frame_height, 32);
+ allocated_raw_shift = 1;
+ }
+ aom_img_upshift(&raw_shift, &raw, input_shift);
+ frame_to_encode = &raw_shift;
+ } else {
+ frame_to_encode = &raw;
+ }
+
if (update_frame_num > 1 && frame_out + 1 == update_frame_num) {
av1_ref_frame_t ref;
ref.idx = 0;
- ref.img = raw;
+ ref.use_external_ref = 0;
+ ref.img = ext_ref;
// Set reference frame in encoder.
if (aom_codec_control(&ecodec, AV1_SET_REFERENCE, &ref))
- die_codec(&ecodec, "Failed to set reference frame");
+ die_codec(&ecodec, "Failed to set encoder reference frame");
printf(" <SET_REF>");
// If set_reference in decoder is commented out, the enc/dec mismatch
// would be seen.
if (test_decode) {
+ ref.use_external_ref = 1;
if (aom_codec_control(&dcodec, AV1_SET_REFERENCE, &ref))
- die_codec(&dcodec, "Failed to set reference frame");
+ die_codec(&dcodec, "Failed to set decoder reference frame");
}
}
- encode_frame(&ecodec, &raw, frame_in, writer, test_decode, &dcodec,
- &frame_out, &mismatch_seen);
+ encode_frame(&ecodec, frame_to_encode, frame_in, writer, test_decode,
+ &dcodec, &frame_out, &mismatch_seen, &ext_ref);
frame_in++;
if (mismatch_seen) break;
}
@@ -295,7 +356,7 @@ int main(int argc, char **argv) {
// Flush encoder.
if (!mismatch_seen)
while (encode_frame(&ecodec, NULL, frame_in, writer, test_decode, &dcodec,
- &frame_out, &mismatch_seen)) {
+ &frame_out, &mismatch_seen, NULL)) {
}
printf("\n");
@@ -313,6 +374,8 @@ int main(int argc, char **argv) {
if (aom_codec_destroy(&dcodec))
die_codec(&dcodec, "Failed to destroy decoder");
+ if (allocated_raw_shift) aom_img_free(&raw_shift);
+ aom_img_free(&ext_ref);
aom_img_free(&raw);
if (aom_codec_destroy(&ecodec))
die_codec(&ecodec, "Failed to destroy encoder.");