Add rate_ctrl_log_path
Change-Id: I4dc25c9ce4103cf3de44cff4d63e8ff8c82f35c0
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -4615,12 +4616,12 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest,
|
||||
}
|
||||
}
|
||||
#endif // CONFIG_RATE_CTRL
|
||||
const GF_GROUP *gf_group = &cpi->twopass.gf_group;
|
||||
if (cpi->ext_ratectrl.ready && !ext_rc_recode &&
|
||||
!cpi->tpl_with_external_rc &&
|
||||
(cpi->ext_ratectrl.funcs.rc_type & VPX_RC_QP) != 0 &&
|
||||
cpi->ext_ratectrl.funcs.get_encodeframe_decision != NULL) {
|
||||
vpx_codec_err_t codec_status;
|
||||
const GF_GROUP *gf_group = &cpi->twopass.gf_group;
|
||||
vpx_rc_encodeframe_decision_t encode_frame_decision;
|
||||
codec_status = vp9_extrc_get_encodeframe_decision(
|
||||
&cpi->ext_ratectrl, gf_group->index, &encode_frame_decision);
|
||||
@@ -4635,6 +4636,12 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest,
|
||||
}
|
||||
}
|
||||
|
||||
if (cpi->ext_ratectrl.ready && cpi->ext_ratectrl.log_file) {
|
||||
fprintf(cpi->ext_ratectrl.log_file,
|
||||
"ENCODE_FRAME_INFO gop_index %d update_type %d q %d\n",
|
||||
gf_group->index, gf_group->update_type[gf_group->index], q);
|
||||
}
|
||||
|
||||
vp9_set_quantizer(cpi, q);
|
||||
|
||||
if (loop_count == 0) setup_frame(cpi);
|
||||
@@ -5401,6 +5408,22 @@ static void set_mb_wiener_variance(VP9_COMP *cpi) {
|
||||
}
|
||||
|
||||
#if !CONFIG_REALTIME_ONLY
|
||||
static PSNR_STATS compute_psnr_stats(const YV12_BUFFER_CONFIG *source_frame,
|
||||
const YV12_BUFFER_CONFIG *coded_frame,
|
||||
uint32_t bit_depth,
|
||||
uint32_t input_bit_depth) {
|
||||
PSNR_STATS psnr;
|
||||
#if CONFIG_VP9_HIGHBITDEPTH
|
||||
vpx_calc_highbd_psnr(source_frame, coded_frame, &psnr, bit_depth,
|
||||
input_bit_depth);
|
||||
#else // CONFIG_VP9_HIGHBITDEPTH
|
||||
(void)bit_depth;
|
||||
(void)input_bit_depth;
|
||||
vpx_calc_psnr(source_frame, coded_frame, &psnr);
|
||||
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||
return psnr;
|
||||
}
|
||||
|
||||
static void update_encode_frame_result_basic(
|
||||
FRAME_UPDATE_TYPE update_type, int show_idx, int quantize_index,
|
||||
ENCODE_FRAME_RESULT *encode_frame_result) {
|
||||
@@ -5437,6 +5460,7 @@ static void yv12_buffer_to_image_buffer(const YV12_BUFFER_CONFIG *yv12_buffer,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function will update extra information specific for simple_encode APIs
|
||||
static void update_encode_frame_result_simple_encode(
|
||||
int ref_frame_flags, FRAME_UPDATE_TYPE update_type,
|
||||
@@ -5450,14 +5474,8 @@ static void update_encode_frame_result_simple_encode(
|
||||
PSNR_STATS psnr;
|
||||
update_encode_frame_result_basic(update_type, coded_frame_buf->frame_index,
|
||||
quantize_index, encode_frame_result);
|
||||
#if CONFIG_VP9_HIGHBITDEPTH
|
||||
vpx_calc_highbd_psnr(source_frame, &coded_frame_buf->buf, &psnr, bit_depth,
|
||||
input_bit_depth);
|
||||
#else // CONFIG_VP9_HIGHBITDEPTH
|
||||
(void)bit_depth;
|
||||
(void)input_bit_depth;
|
||||
vpx_calc_psnr(source_frame, &coded_frame_buf->buf, &psnr);
|
||||
#endif // CONFIG_VP9_HIGHBITDEPTH
|
||||
compute_psnr_stats(source_frame, &coded_frame_buf->buf, bit_depth,
|
||||
input_bit_depth);
|
||||
encode_frame_result->frame_coding_index = coded_frame_buf->frame_coding_index;
|
||||
|
||||
vp9_get_ref_frame_info(update_type, ref_frame_flags, ref_frame_bufs,
|
||||
@@ -5722,6 +5740,15 @@ static void encode_frame_to_data_rate(
|
||||
|
||||
update_encode_frame_result_basic(update_type, coded_frame_buf->frame_index,
|
||||
quantize_index, encode_frame_result);
|
||||
if (cpi->ext_ratectrl.ready && cpi->ext_ratectrl.log_file) {
|
||||
PSNR_STATS psnr =
|
||||
compute_psnr_stats(cpi->Source, &coded_frame_buf->buf, cm->bit_depth,
|
||||
cpi->oxcf.input_bit_depth);
|
||||
fprintf(cpi->ext_ratectrl.log_file,
|
||||
"ENCODE_FRAME_RESULT psnr %f bits %ld \n", psnr.psnr[0],
|
||||
(*size) << 3);
|
||||
}
|
||||
|
||||
#if CONFIG_RATE_CTRL
|
||||
if (cpi->oxcf.use_simple_encode_api) {
|
||||
const int ref_frame_flags = get_ref_frame_flags(cpi);
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "vp9/encoder/vp9_ext_ratectrl.h"
|
||||
#include "vp9/encoder/vp9_encoder.h"
|
||||
@@ -51,6 +52,14 @@ vpx_codec_err_t vp9_extrc_create(vpx_rc_funcs_t funcs,
|
||||
if (rc_firstpass_stats->frame_stats == NULL) {
|
||||
return VPX_CODEC_MEM_ERROR;
|
||||
}
|
||||
if (funcs.rate_ctrl_log_path != NULL) {
|
||||
ext_ratectrl->log_file = fopen(funcs.rate_ctrl_log_path, "w");
|
||||
if (!ext_ratectrl->log_file) {
|
||||
return VPX_CODEC_ERROR;
|
||||
}
|
||||
} else {
|
||||
ext_ratectrl->log_file = NULL;
|
||||
}
|
||||
ext_ratectrl->ready = 1;
|
||||
return VPX_CODEC_OK;
|
||||
}
|
||||
@@ -60,6 +69,9 @@ vpx_codec_err_t vp9_extrc_delete(EXT_RATECTRL *ext_ratectrl) {
|
||||
return VPX_CODEC_INVALID_PARAM;
|
||||
}
|
||||
if (ext_ratectrl->ready) {
|
||||
if (ext_ratectrl->log_file) {
|
||||
fclose(ext_ratectrl->log_file);
|
||||
}
|
||||
vpx_rc_status_t rc_status =
|
||||
ext_ratectrl->funcs.delete_model(ext_ratectrl->model);
|
||||
if (rc_status == VPX_RC_ERROR) {
|
||||
|
||||
@@ -22,6 +22,7 @@ typedef struct EXT_RATECTRL {
|
||||
vpx_rc_funcs_t funcs;
|
||||
vpx_rc_config_t ratectrl_config;
|
||||
vpx_rc_firstpass_stats_t rc_firstpass_stats;
|
||||
FILE *log_file;
|
||||
} EXT_RATECTRL;
|
||||
|
||||
vpx_codec_err_t vp9_extrc_init(EXT_RATECTRL *ext_ratectrl);
|
||||
|
||||
@@ -3641,7 +3641,6 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
|
||||
}
|
||||
rc->baseline_gf_interval =
|
||||
gop_decision.gop_coding_frames - rc->source_alt_ref_pending;
|
||||
rc->frames_till_gf_update_due = rc->baseline_gf_interval;
|
||||
ext_rc_define_gf_group_structure(cpi, &gop_decision);
|
||||
}
|
||||
} else {
|
||||
@@ -3657,16 +3656,14 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
|
||||
if (rc->frames_till_gf_update_due == 0) {
|
||||
define_gf_group(cpi, show_idx);
|
||||
|
||||
rc->frames_till_gf_update_due = rc->baseline_gf_interval;
|
||||
|
||||
#if ARF_STATS_OUTPUT
|
||||
{
|
||||
FILE *fpfile;
|
||||
fpfile = fopen("arf.stt", "a");
|
||||
++arf_count;
|
||||
fprintf(fpfile, "%10d %10ld %10d %10d %10ld %10ld\n",
|
||||
cm->current_video_frame, rc->frames_till_gf_update_due,
|
||||
rc->kf_boost, arf_count, rc->gfu_boost, cm->frame_type);
|
||||
cm->current_video_frame, rc->baseline_gf_interval, rc->kf_boost,
|
||||
arf_count, rc->gfu_boost, cm->frame_type);
|
||||
|
||||
fclose(fpfile);
|
||||
}
|
||||
@@ -3674,6 +3671,14 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
|
||||
}
|
||||
}
|
||||
|
||||
if (rc->frames_till_gf_update_due == 0) {
|
||||
if (cpi->ext_ratectrl.ready && cpi->ext_ratectrl.log_file) {
|
||||
fprintf(cpi->ext_ratectrl.log_file, "GOP_INFO gop_size %d\n",
|
||||
rc->baseline_gf_interval);
|
||||
}
|
||||
rc->frames_till_gf_update_due = rc->baseline_gf_interval;
|
||||
}
|
||||
|
||||
vp9_configure_buffer_updates(cpi, gf_group->index);
|
||||
|
||||
rc->base_frame_target = gf_group->bit_allocation[gf_group->index];
|
||||
|
||||
@@ -514,6 +514,11 @@ typedef struct vpx_rc_funcs {
|
||||
* Delete the external rate control model.
|
||||
*/
|
||||
vpx_rc_delete_model_cb_fn_t delete_model;
|
||||
|
||||
/*!
|
||||
* Rate control log path.
|
||||
*/
|
||||
char *rate_ctrl_log_path;
|
||||
/*!
|
||||
* Private data for the external rate control model.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user