Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions app/oapv_app_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ static const args_opt_t dec_args_opts[] = {
},
{
'd', "output-depth", ARGS_VAL_TYPE_INTEGER, 0, NULL,
"output bit depth (8, 10, 12) "
"output bit depth (8, 10, 12)\n"
" Note: This is option does not support 444/4444-16C12 profile."
},
{
ARGS_NO_KEY, "hash", ARGS_VAL_TYPE_NONE, 0, NULL,
Expand All @@ -87,6 +88,11 @@ static const args_opt_t dec_args_opts[] = {
" - 0: coded CSP\n"
" - 1: convert to P210 in case of YCbCr422\n"
},
{
ARGS_NO_KEY, "disable-companding", ARGS_VAL_TYPE_NONE, 0, NULL,
"forcely disable companding process\n"
" Note: this option forces to output 12 bits picture in case of 444/4444-16C12 profile"
},
{ARGS_END_KEY, "", ARGS_VAL_TYPE_NONE, 0, NULL, ""} /* termination */
};

Expand All @@ -102,6 +108,7 @@ typedef struct args_var {
char threads[16];
int output_depth;
int output_csp;
int disable_companding;
} args_var_t;

static args_var_t *args_init_vars(args_parser_t *args)
Expand All @@ -118,6 +125,8 @@ static args_var_t *args_init_vars(args_parser_t *args)
args_set_variable_by_key_long(opts, "output", vars->fname_out);
args_set_variable_by_key_long(opts, "max-au", &vars->max_au);
args_set_variable_by_key_long(opts, "hash", &vars->hash);
args_set_variable_by_key_long(opts, "disable-companding", &vars->disable_companding);
vars->disable_companding = 0; /* default */
args_set_variable_by_key_long(opts, "verbose", &op_verbose);
op_verbose = VERBOSE_SIMPLE; /* default */
args_set_variable_by_key_long(opts, "threads", vars->threads);
Expand Down Expand Up @@ -216,14 +225,23 @@ static int set_extra_config(oapvd_t id, args_var_t *args_vars)
int ret, size, value;

if(args_vars->hash) { // enable frame hash calculation
value = 1;
value = 1; // true
size = 4;
ret = oapvd_config(id, OAPV_CFG_SET_USE_FRM_HASH, &value, &size);
if(OAPV_FAILED(ret)) {
logerr("failed to set config for using frame hash\n");
return -1;
}
}
if(args_vars->disable_companding) {
value = 1; // true
size = 4;
ret = oapvd_config(id, OAPV_CFG_SET_DISABLE_COMPANDING, &value, &size);
if(OAPV_FAILED(ret)) {
logerr("failed to set config for disabling companding process\n");
return -1;
}
}
return 0;
}

Expand Down Expand Up @@ -313,16 +331,17 @@ static void print_stat_frm(oapvd_stat_t *stat, oapv_frms_t *frms, oapvm_t mid, a
: finfo[i].pbu_type == OAPV_PBU_TYPE_PREVIEW_FRAME ? "PREVIEW"
: finfo[i].pbu_type == OAPV_PBU_TYPE_DEPTH_FRAME ? "DEPTH"
: finfo[i].pbu_type == OAPV_PBU_TYPE_ALPHA_FRAME ? "ALPHA"
: "UNKNOWN";

const char * str_csp = finfo[i].cs == OAPV_CS_YCBCR400_10LE ? "4:0:0-10"
: finfo[i].cs == OAPV_CS_YCBCR422_10LE ? "4:2:2-10"
: finfo[i].cs == OAPV_CS_YCBCR422_12LE ? "4:2:2-12"
: finfo[i].cs == OAPV_CS_YCBCR444_10LE ? "4:4:4-10"
: finfo[i].cs == OAPV_CS_YCBCR444_12LE ? "4:4:4-12"
: finfo[i].cs == OAPV_CS_YCBCR4444_10LE ? "4:4:4:4-10"
: finfo[i].cs == OAPV_CS_YCBCR4444_12LE ? "4:4:4:4-12"
: "unknown-cs";
: "Unknown";

const char * str_csp = finfo[i].cs == OAPV_CS_YCBCR400_10LE ? "400-10"
: finfo[i].cs == OAPV_CS_YCBCR422_10LE ? "422-10"
: finfo[i].cs == OAPV_CS_YCBCR422_12LE ? "422-12"
: finfo[i].cs == OAPV_CS_YCBCR444_10LE ? "444-10"
: finfo[i].cs == OAPV_CS_YCBCR444_12LE ? "444-12"
: finfo[i].cs == OAPV_CS_YCBCR4444_10LE ? "4444-10"
: finfo[i].cs == OAPV_CS_YCBCR4444_12LE ? "4444-12"
: finfo[i].cs == OAPV_CS_YCBCR4444_16LE ? "4444-16"
: "Unknown";

// clang-format on

Expand Down Expand Up @@ -524,6 +543,9 @@ int main(int argc, const char **argv)
}
}

if(args_var->disable_companding && finfo->use_companding == 1) {
args_var->output_depth = 12;
}
if(args_var->output_depth == 0) {
args_var->output_depth = OAPV_CS_GET_BIT_DEPTH(finfo->cs);
}
Expand Down Expand Up @@ -583,7 +605,7 @@ int main(int argc, const char **argv)
for(i = 0; i < ofrms.num_frms; i++) {
frm = &ofrms.frm[i];
if(ofrms.num_frms > 0) {
if(OAPV_CS_GET_BIT_DEPTH(frm->imgb->cs) != args_var->output_depth && args_var->output_csp != 1) {
if(OAPV_CS_GET_BIT_DEPTH(frm->imgb->cs) != args_var->output_depth && args_var->output_csp != OUTPUT_CSP_P210) {
if(imgb_w == NULL) {
imgb_w = imgb_create(frm->imgb->w[0], frm->imgb->h[0],
OAPV_CS_SET(OAPV_CS_GET_FORMAT(frm->imgb->cs), args_var->output_depth, 0));
Expand Down
20 changes: 11 additions & 9 deletions app/oapv_app_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static const args_opt_t enc_args_opts[] = {
'q', "qp", ARGS_VAL_TYPE_STRING, 0, NULL,
"QP value: 0 ~ (63 + (bitdepth - 10)*6) \n"
" - 10bit input: 0 ~ 63\n"
" - 12bit input: 0 ~ 75\n"
" - 12bit input and 12C16bit: 0 ~ 75\n"
" - 'auto' means that the value is internally determined"
},
{
Expand All @@ -99,7 +99,7 @@ static const args_opt_t enc_args_opts[] = {
},
{
'd', "input-depth", ARGS_VAL_TYPE_INTEGER, 0, NULL,
"input bit depth (8, 10-12)\n"
"input bit depth (8, 10-12, 16)\n"
" - Note: 8bit input will be converted to 10bit"
},
{
Expand Down Expand Up @@ -127,10 +127,11 @@ static const args_opt_t enc_args_opts[] = {
"profile string\n"
" - 422-10: YCbCr422 10bit (default)\n"
" - 422-12: YCbCr422 12bit\n"
" - 444-10: YCbCr444 10bit\n"
" - 444-12: YCbCr444 12bit\n"
" - 4444-10: YCbCr4444 10bit\n"
" - 4444-12: YCbCr4444 12bit\n"
" - 444-10: YCbCr(RGB)444 10bit\n"
" - 444-12: YCbCr(RGB)444 12bit\n"
" - 4444-10: YCbCrX(RGBA)4444 10bit\n"
" - 4444-12: YCbCrX(RGBA)4444 12bit\n"
" - 4444-16C12: YCbCrX(RGBA)4444 16bit companded to 12bit\n"
" - 400-10: YCbCr400 (monochrome) 10bit\n"
" Note: Color space and bit depth of input video will be converted\n"
" automatically to support the given profile, if needs\n"
Expand Down Expand Up @@ -1032,7 +1033,7 @@ int main(int argc, const char **argv)

if(strlen(args_var->fname_rec) > 0) {
ret = check_file_name_type(args_var->fname_rec);
if(ret > 0) {
if(ret > 0 && args_var->input_csp != 16) {
is_rec_y4m = 1;
}
else if(ret == 0) {
Expand Down Expand Up @@ -1100,7 +1101,8 @@ int main(int argc, const char **argv)
param->profile_idc == OAPV_PROFILE_4444_10) ? 10 : (
param->profile_idc == OAPV_PROFILE_422_12 ||
param->profile_idc == OAPV_PROFILE_444_12 ||
param->profile_idc == OAPV_PROFILE_4444_12) ? 12 : 0;
param->profile_idc == OAPV_PROFILE_4444_12) ? 12 : (
param->profile_idc == OAPV_PROFILE_4444_16C12) ? 16 : 0;

if (codec_depth == 0) {
logerr("ERR: invalid profile\n");
Expand Down Expand Up @@ -1281,7 +1283,7 @@ int main(int argc, const char **argv)
bitrate_tot, psnr_avg[FRM_IDX][0]);
}
else if(cfmt == OAPV_CF_YCBCR4444) { // 4-channel
logv3(" -----------------: bitrate(kbps)\tPSNR-Y\tPSNR-U\tPSNR-V\tPSNR-T\n");
logv3(" -----------------: bitrate(kbps)\tPSNR-Y\tPSNR-U\tPSNR-V\tPSNR-X\n");
logv3(" Summary : %-4.4f\t%-5.4f\t%-5.4f\t%-5.4f\t%-5.4f\n",
bitrate_tot, psnr_avg[FRM_IDX][0], psnr_avg[FRM_IDX][1], psnr_avg[FRM_IDX][2], psnr_avg[FRM_IDX][3]);
}
Expand Down
20 changes: 10 additions & 10 deletions app/oapv_app_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,16 +407,16 @@ static int imgb_read(FILE *fp, oapv_imgb_t *img, int width, int height, int is_y
}

/* reading YUV format */
int chroma_format = OAPV_CS_GET_FORMAT(img->cs);
int color_format = OAPV_CS_GET_FORMAT(img->cs);
int bit_depth = OAPV_CS_GET_BIT_DEPTH(img->cs);
int w_shift = (chroma_format == OAPV_CF_YCBCR420) || ((chroma_format == OAPV_CF_YCBCR422) || (chroma_format == OAPV_CF_PLANAR2)) ? 1 : 0;
int h_shift = chroma_format == OAPV_CF_YCBCR420 ? 1 : 0;
int w_shift = (color_format == OAPV_CF_YCBCR420) || ((color_format == OAPV_CF_YCBCR422) || (color_format == OAPV_CF_PLANAR2)) ? 1 : 0;
int h_shift = color_format == OAPV_CF_YCBCR420 ? 1 : 0;

if(bit_depth == 8) {
f_w = width;
f_h = height;
}
else if(bit_depth >= 10 && bit_depth <= 14) {
else if(bit_depth >= 10 && bit_depth <= 16) {
f_w = width * sizeof(short);
f_h = height;
}
Expand All @@ -433,7 +433,7 @@ static int imgb_read(FILE *fp, oapv_imgb_t *img, int width, int height, int is_y
p8 += img->s[0];
}

if(chroma_format == OAPV_CF_PLANAR2) {
if(color_format == OAPV_CF_PLANAR2) {
p8 = (unsigned char *)img->a[1];
for(int j = 0; j < f_h; j++) {
if(fread(p8, 1, f_w, fp) != (unsigned)f_w) {
Expand All @@ -442,7 +442,7 @@ static int imgb_read(FILE *fp, oapv_imgb_t *img, int width, int height, int is_y
p8 += img->s[1];
}
}
else if(chroma_format != OAPV_CF_YCBCR400) {
else if(color_format != OAPV_CF_YCBCR400) {
f_w = f_w >> w_shift;
f_h = f_h >> h_shift;

Expand All @@ -463,7 +463,7 @@ static int imgb_read(FILE *fp, oapv_imgb_t *img, int width, int height, int is_y
}
}

if(chroma_format == OAPV_CF_YCBCR4444) {
if(color_format == OAPV_CF_YCBCR4444) {
f_w = f_w >> w_shift;
f_h = f_h >> h_shift;

Expand Down Expand Up @@ -497,7 +497,7 @@ static int imgb_write(char *fname, oapv_imgb_t *imgb)
chroma_format == OAPV_CF_YCBCR444 || chroma_format == OAPV_CF_YCBCR4444)) {
bd = 1;
}
else if(bit_depth >= 10 && bit_depth <= 14 && (chroma_format == OAPV_CF_YCBCR400 || chroma_format == OAPV_CF_YCBCR420 || chroma_format == OAPV_CF_YCBCR422 || chroma_format == OAPV_CF_YCBCR444 || chroma_format == OAPV_CF_YCBCR4444)) {
else if(bit_depth >= 10 && bit_depth <= 16 && (chroma_format == OAPV_CF_YCBCR400 || chroma_format == OAPV_CF_YCBCR420 || chroma_format == OAPV_CF_YCBCR422 || chroma_format == OAPV_CF_YCBCR444 || chroma_format == OAPV_CF_YCBCR4444)) {
bd = 2;
}
else if(bit_depth >= 10 && chroma_format == OAPV_CF_PLANAR2) {
Expand Down Expand Up @@ -697,7 +697,7 @@ static void measure_psnr(oapv_imgb_t *org, oapv_imgb_t *rec, double psnr[4], int
r += rec->s[i];
}
mse[i] = sum[i] / (org->w[i] * org->h[i]);
psnr[i] = (mse[i] == 0.0) ? 100. : fabs(10 * log10(((255 * 255) / mse[i])));
psnr[i] = (mse[i] == 0.0) ? 100. : fabs(10 * log10(((255.f * 255.f) / mse[i])));
}
}
else {
Expand All @@ -723,7 +723,7 @@ static void measure_psnr(oapv_imgb_t *org, oapv_imgb_t *rec, double psnr[4], int
r = (unsigned short *)((unsigned char *)r + rec->s[i]);
}
mse[i] = sum[i] / (org->w[i] * org->h[i]);
psnr[i] = (mse[i] == 0.0) ? 100. : fabs(10 * log10(((255 * 255 * factor) / mse[i])));
psnr[i] = (mse[i] == 0.0) ? 100. : fabs(10 * log10(((255.f * 255.f * factor) / mse[i])));
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions inc/oapv.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ extern "C" {
#define OAPV_CS_YCBCR422_12LE OAPV_CS_SET(OAPV_CF_YCBCR422, 12, 0)
#define OAPV_CS_YCBCR444_12LE OAPV_CS_SET(OAPV_CF_YCBCR444, 12, 0)
#define OAPV_CS_YCBCR4444_12LE OAPV_CS_SET(OAPV_CF_YCBCR4444, 12, 0)
#define OAPV_CS_YCBCR4444_16LE OAPV_CS_SET(OAPV_CF_YCBCR4444, 16, 0)
#define OAPV_CS_P210 OAPV_CS_SET(OAPV_CF_PLANAR2, 10, 0)

/* max number of color channel: ex) YCbCr4444 -> 4 channels */
Expand All @@ -180,6 +181,7 @@ extern "C" {
#define OAPV_CFG_SET_QP_MAX (209)
#define OAPV_CFG_SET_USE_FRM_HASH (301)
#define OAPV_CFG_SET_AU_BS_FMT (302)
#define OAPV_CFG_SET_DISABLE_COMPANDING (400)
#define OAPV_CFG_GET_QP_MIN (600)
#define OAPV_CFG_GET_QP_MAX (601)
#define OAPV_CFG_GET_QP (602)
Expand Down Expand Up @@ -240,6 +242,9 @@ extern "C" {
#define OAPV_PROFILE_4444_10 (77)
#define OAPV_PROFILE_4444_12 (88)
#define OAPV_PROFILE_400_10 (99)
#define OAPV_PROFILE_444_16C12 (140)
#define OAPV_PROFILE_4444_16C12 (144)


/*****************************************************************************
* family
Expand Down Expand Up @@ -405,6 +410,8 @@ typedef struct oapv_frm_info oapv_frm_info_t;
struct oapv_frm_info {
int w;
int h;
// output frame's color space
// 16bit color space will be set if the profile is 444/4444-16C12
int cs;
int pbu_type;
int group_id;
Expand All @@ -414,6 +421,7 @@ struct oapv_frm_info {
int chroma_format_idc;
int bit_depth;
int capture_time_distance;
int use_companding;
// flag for custom quantization matrix
int use_q_matrix;
// q_matrix is meaningful if use_q_matrix is true
Expand Down Expand Up @@ -451,6 +459,7 @@ static const oapv_dict_str_int_t oapv_param_opts_profile[] = {
{"4444-10", OAPV_PROFILE_4444_10},
{"4444-12", OAPV_PROFILE_4444_12},
{"400-10", OAPV_PROFILE_400_10},
{"4444-16C12", OAPV_PROFILE_4444_16C12},
{"", 0} // termination
};

Expand Down
Loading
Loading