Commit 0a075cb3 authored by Yunqing Wang's avatar Yunqing Wang

Make set_reference control API work in VP9

Moved the API patch from NextGenv2. An example was included.
To try it, for example, run the following command:
$ examples/vpx_cx_set_ref vp9 352 288 in.yuv out.ivf 4 30

Change-Id: I4cf8f23b86d7ebd85ffd2630dcfbd799c0b88101
parent f5a15f27
......@@ -215,6 +215,17 @@ vp8cx_set_ref.SRCS += vpx_ports/msvc.h
vp8cx_set_ref.GUID = C5E31F7F-96F6-48BD-BD3E-10EBF6E8057A
vp8cx_set_ref.DESCRIPTION = VP8 set encoder reference frame
ifeq ($(CONFIG_VP9_ENCODER),yes)
ifeq ($(CONFIG_DECODERS),yes)
EXAMPLES-yes += vpx_cx_set_ref.c
vpx_cx_set_ref.SRCS += ivfenc.h ivfenc.c
vpx_cx_set_ref.SRCS += tools_common.h tools_common.c
vpx_cx_set_ref.SRCS += video_common.h
vpx_cx_set_ref.SRCS += video_writer.h video_writer.c
vpx_cx_set_ref.GUID = 65D7F14A-2EE6-4293-B958-AB5107A03B55
vpx_cx_set_ref.DESCRIPTION = VP9 set encoder reference frame
endif
endif
ifeq ($(CONFIG_MULTI_RES_ENCODING),yes)
ifeq ($(CONFIG_LIBYUV),yes)
......
This diff is collapsed.
#!/bin/sh
##
## Copyright (c) 2014 The WebM project authors. All Rights Reserved.
## Copyright (c) 2016 The WebM project authors. All Rights Reserved.
##
## Use of this source code is governed by a BSD-style license
## that can be found in the LICENSE file in the root of the source
......@@ -8,30 +8,27 @@
## in the file PATENTS. All contributing project authors may
## be found in the AUTHORS file in the root of the source tree.
##
## This file tests the libvpx vp8cx_set_ref example. To add new tests to this
## This file tests the libvpx 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 vp8cx_set_ref_tests (on a new line).
## 2. Add the function to cx_set_ref_tests (on a new line).
##
. $(dirname $0)/tools_common.sh
# Environment check: $YUV_RAW_INPUT is required.
vp8cx_set_ref_verify_environment() {
cx_set_ref_verify_environment() {
if [ ! -e "${YUV_RAW_INPUT}" ]; then
echo "Libvpx test data must exist in LIBVPX_TEST_DATA_PATH."
return 1
fi
}
# Runs vp8cx_set_ref and updates the reference frame before encoding frame 90.
# $1 is the codec name, which vp8cx_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
# VP9.
# Runs cx_set_ref and updates the reference frame before encoding frame 90.
# $1 is the codec name.
vpx_set_ref() {
local encoder="${LIBVPX_BIN_PATH}/vp8cx_set_ref${VPX_TEST_EXE_SUFFIX}"
local codec="$1"
local output_file="${VPX_TEST_OUTPUT_DIR}/vp8cx_set_ref_${codec}.ivf"
local encoder="${LIBVPX_BIN_PATH}/${codec}cx_set_ref${VPX_TEST_EXE_SUFFIX}"
local output_file="${VPX_TEST_OUTPUT_DIR}/${codec}cx_set_ref_${codec}.ivf"
local ref_frame_num=90
if [ ! -x "${encoder}" ]; then
......@@ -46,12 +43,18 @@ vpx_set_ref() {
[ -e "${output_file}" ] || return 1
}
vp8cx_set_ref_vp8() {
cx_set_ref_vp8() {
if [ "$(vp8_encode_available)" = "yes" ]; then
vpx_set_ref vp8 || return 1
fi
}
vp8cx_set_ref_tests="vp8cx_set_ref_vp8"
cx_set_ref_vp9() {
if [ "$(vp9_encode_available)" = "yes" ]; then
vpx_set_ref vp9 || return 1
fi
}
cx_set_ref_tests="cx_set_ref_vp8 cx_set_ref_vp9"
run_tests vp8cx_set_ref_verify_environment "${vp8cx_set_ref_tests}"
run_tests cx_set_ref_verify_environment "${cx_set_ref_tests}"
......@@ -187,47 +187,45 @@ vpx_codec_err_t vp9_copy_reference_dec(VP9Decoder *pbi,
vpx_codec_err_t vp9_set_reference_dec(VP9_COMMON *cm,
VP9_REFFRAME ref_frame_flag,
YV12_BUFFER_CONFIG *sd) {
RefBuffer *ref_buf = NULL;
RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs;
int idx;
YV12_BUFFER_CONFIG *ref_buf = NULL;
// 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
// vpxenc --test-decode functionality working, and will be replaced in a
// later commit that adds VP9-specific controls for this functionality.
// (Yunqing) The set_reference control depends on the following setting in
// encoder.
// cpi->lst_fb_idx = 0;
// cpi->gld_fb_idx = 1;
// cpi->alt_fb_idx = 2;
if (ref_frame_flag == VP9_LAST_FLAG) {
ref_buf = &cm->frame_refs[0];
idx = cm->ref_frame_map[0];
} else if (ref_frame_flag == VP9_GOLD_FLAG) {
ref_buf = &cm->frame_refs[1];
idx = cm->ref_frame_map[1];
} else if (ref_frame_flag == VP9_ALT_FLAG) {
ref_buf = &cm->frame_refs[2];
idx = cm->ref_frame_map[2];
} else {
vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
"Invalid reference frame");
return cm->error.error_code;
}
if (!equal_dimensions(ref_buf->buf, sd)) {
if (idx < 0 || idx >= FRAME_BUFFERS) {
vpx_internal_error(&cm->error, VPX_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) {
vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
"Unable to find free frame buffer");
return cm->error.error_code;
}
"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;
vp8_yv12_copy_frame(sd, ref_buf->buf);
if (!equal_dimensions(ref_buf, sd)) {
vpx_internal_error(&cm->error, VPX_CODEC_ERROR,
"Incorrect buffer dimensions");
} else {
// Overwrite the reference frame buffer.
vp8_yv12_copy_frame(sd, ref_buf);
}
return cm->error.error_code;
......
......@@ -105,19 +105,6 @@ struct vpx_codec_alg_priv {
BufferPool *buffer_pool;
};
static VP9_REFFRAME ref_frame_to_vp9_reframe(vpx_ref_frame_type_t frame) {
switch (frame) {
case VP8_LAST_FRAME:
return VP9_LAST_FLAG;
case VP8_GOLD_FRAME:
return VP9_GOLD_FLAG;
case VP8_ALTR_FRAME:
return VP9_ALT_FLAG;
}
assert(0 && "Invalid Reference Frame");
return VP9_LAST_FLAG;
}
static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx,
const struct vpx_internal_error_info *error) {
const vpx_codec_err_t res = error->error_code;
......
......@@ -785,7 +785,8 @@ static vpx_codec_err_t ctrl_set_reference(vpx_codec_alg_priv_t *ctx,
FrameWorkerData *const frame_worker_data = (FrameWorkerData *)worker->data1;
image2yuvconfig(&frame->img, &sd);
return vp9_set_reference_dec(&frame_worker_data->pbi->common,
(VP9_REFFRAME)frame->frame_type, &sd);
ref_frame_to_vp9_reframe(frame->frame_type),
&sd);
} else {
return VPX_CODEC_INVALID_PARAM;
}
......
......@@ -133,4 +133,16 @@ static vpx_codec_err_t image2yuvconfig(const vpx_image_t *img,
return VPX_CODEC_OK;
}
static VP9_REFFRAME ref_frame_to_vp9_reframe(vpx_ref_frame_type_t frame) {
switch (frame) {
case VP8_LAST_FRAME:
return VP9_LAST_FLAG;
case VP8_GOLD_FRAME:
return VP9_GOLD_FLAG;
case VP8_ALTR_FRAME:
return VP9_ALT_FLAG;
}
assert(0 && "Invalid Reference Frame");
return VP9_LAST_FLAG;
}
#endif // VP9_VP9_IFACE_COMMON_H_
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