Commit 16944e59 authored by Jim Bankoski's avatar Jim Bankoski

aom_cx_set_ref: Example showing setting a reference frame.

This code was pulled over from libvpx (89a8174f and 9aaa3c93
Make set_reference control API work in VP9 and VP10). The testing
script was added to insure it's working properly.

Change-Id: Ica311c169a1e51718503e23756c4c394818217dd
parent 5da83395
......@@ -182,42 +182,41 @@ aom_codec_err_t av1_copy_reference_dec(AV1Decoder *pbi,
aom_codec_err_t av1_set_reference_dec(AV1_COMMON *cm,
AOM_REFFRAME ref_frame_flag,
YV12_BUFFER_CONFIG *sd) {
RefBuffer *ref_buf = NULL;
RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
// TODO(jkoleszar): The decoder doesn't have any real knowledge of what the
// encoder is using the frame buffers for. This is just a stub to keep the
// aomenc --test-decode functionality working, and will be replaced in a
// later commit that adds AV1-specific controls for this functionality.
int idx;
YV12_BUFFER_CONFIG *ref_buf = NULL;
// The set_reference control depends on the following setting in the
// encoder.
// cpi->lst_fb_idx = 0;
// cpi->gld_fb_idx = 1;
// cpi->alt_fb_idx = 2;
if (ref_frame_flag == AOM_LAST_FLAG) {
ref_buf = &cm->frame_refs[0];
idx = cm->ref_frame_map[0];
} else if (ref_frame_flag == AOM_GOLD_FLAG) {
ref_buf = &cm->frame_refs[1];
idx = cm->ref_frame_map[1];
} else if (ref_frame_flag == AOM_ALT_FLAG) {
ref_buf = &cm->frame_refs[2];
idx = cm->ref_frame_map[2];
} else {
aom_internal_error(&cm->error, AOM_CODEC_ERROR, "Invalid reference frame");
aom_internal_error(&cm->error, AOM_CODEC_ERROR,
"Invalid reference frame");
return cm->error.error_code;
}
if (!equal_dimensions(ref_buf->buf, sd)) {
if (idx < 0 || idx >= FRAME_BUFFERS) {
aom_internal_error(&cm->error, AOM_CODEC_ERROR,
"Incorrect buffer dimensions");
} else {
int *ref_fb_ptr = &ref_buf->idx;
// Find an empty frame buffer.
const int free_fb = get_free_fb(cm);
if (cm->new_fb_idx == INVALID_IDX) return AOM_CODEC_MEM_ERROR;
"Invalid reference frame map");
return cm->error.error_code;
}
// Decrease ref_count since it will be increased again in
// ref_cnt_fb() below.
--frame_bufs[free_fb].ref_count;
// Get the destination reference buffer.
ref_buf = &cm->buffer_pool->frame_bufs[idx].buf;
// Manage the reference counters and copy image.
ref_cnt_fb(frame_bufs, ref_fb_ptr, free_fb);
ref_buf->buf = &frame_bufs[*ref_fb_ptr].buf;
aom_yv12_copy_frame(sd, ref_buf->buf);
if (!equal_dimensions(ref_buf, sd)) {
aom_internal_error(&cm->error, AOM_CODEC_ERROR,
"Incorrect buffer dimensions");
} else {
// Overwrite the reference frame buffer.
aom_yv12_copy_frame(sd, ref_buf);
}
return cm->error.error_code;
......
......@@ -163,7 +163,18 @@ set_maps.SRCS += video_writer.h video_writer.c
set_maps.SRCS += aom_ports/msvc.h
set_maps.GUID = ECB2D24D-98B8-4015-A465-A4AF3DCC145F
set_maps.DESCRIPTION = Set active and ROI maps
ifeq ($(CONFIG_ENCODERS),yes)
ifeq ($(CONFIG_DECODERS),yes)
EXAMPLES-$(CONFIG_ENCODERS) += aom_cx_set_ref.c
aom_cx_set_ref.SRCS += ivfenc.h ivfenc.c
aom_cx_set_ref.SRCS += tools_common.h tools_common.c
aom_cx_set_ref.SRCS += video_common.h
aom_cx_set_ref.SRCS += video_writer.h video_writer.c
aom_cx_set_ref.SRCS += aom_ports/msvc.h
aom_cx_set_ref.GUID = C5E31F7F-96F6-48BD-BD3E-10EBF6E8057A
aom_cx_set_ref.DESCRIPTION = VP8 set encoder reference frame
endif
endif
# Handle extra library flags depending on codec configuration
......
This diff is collapsed.
......@@ -8,51 +8,51 @@
## Media Patent License 1.0 was not distributed with this source code in the
## PATENTS file, you can obtain it at www.aomedia.org/license/patent.
##
## This file tests the libaom aomcx_set_ref example. To add new tests to this
## This file tests the libaom aom_cx_set_ref example. To add new tests to this
## file, do the following:
## 1. Write a shell function (this is your test).
## 2. Add the function to aomcx_set_ref_tests (on a new line).
## 2. Add the function to aom_cx_set_ref_tests (on a new line).
##
. $(dirname $0)/tools_common.sh
# Environment check: $YUV_RAW_INPUT is required.
aomcx_set_ref_verify_environment() {
aom_cx_set_ref_verify_environment() {
if [ ! -e "${YUV_RAW_INPUT}" ]; then
echo "Libaom test data must exist in LIBAOM_TEST_DATA_PATH."
return 1
fi
}
# Runs aomcx_set_ref and updates the reference frame before encoding frame 90.
# $1 is the codec name, which aomcx_set_ref does not support at present: It's
# Runs aom_cx_set_ref and updates the reference frame before encoding frame 90.
# $1 is the codec name, which aom_cx_set_ref does not support at present: It's
# currently used only to name the output file.
# TODO(tomfinegan): Pass the codec param once the example is updated to support
# AV1.
aom_set_ref() {
local encoder="${LIBAOM_BIN_PATH}/aomcx_set_ref${AOM_TEST_EXE_SUFFIX}"
local encoder="${LIBAOM_BIN_PATH}/aom_cx_set_ref${AOM_TEST_EXE_SUFFIX}"
local codec="$1"
local output_file="${AOM_TEST_OUTPUT_DIR}/aomcx_set_ref_${codec}.ivf"
local ref_frame_num=90
local output_file="${AOM_TEST_OUTPUT_DIR}/aom_cx_set_ref_${codec}.ivf"
local ref_frame_num=4
local limit=20
if [ ! -x "${encoder}" ]; then
elog "${encoder} does not exist or is not executable."
return 1
fi
eval "${AOM_TEST_PREFIX}" "${encoder}" "${YUV_RAW_INPUT_WIDTH}" \
eval "${AOM_TEST_PREFIX}" "${encoder}" "${codec}" "${YUV_RAW_INPUT_WIDTH}" \
"${YUV_RAW_INPUT_HEIGHT}" "${YUV_RAW_INPUT}" "${output_file}" \
"${ref_frame_num}" ${devnull}
"${ref_frame_num}" "${limit}" ${devnull}
[ -e "${output_file}" ] || return 1
}
aomcx_set_ref_aom() {
if [ "$(aom_encode_available)" = "yes" ]; then
aom_set_ref aom || return 1
aom_cx_set_ref_av1() {
if [ "$(av1_encode_available)" = "yes" ]; then
aom_set_ref av1 || return 1
fi
}
aomcx_set_ref_tests="aomcx_set_ref_aom"
aom_cx_set_ref_tests="aom_cx_set_ref_av1"
run_tests aomcx_set_ref_verify_environment "${aomcx_set_ref_tests}"
run_tests aom_cx_set_ref_verify_environment "${aom_cx_set_ref_tests}"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment