mirror of
https://github.com/ultravideo/uvg266.git
synced 2024-11-30 12:44:07 +00:00
Merge branch 'fixes'
This commit is contained in:
commit
0ee6321a6b
32
src/cfg.c
32
src/cfg.c
|
@ -986,27 +986,53 @@ int kvz_config_parse(kvz_config *cfg, const char *name, const char *value)
|
|||
// First number is width, second number is height,
|
||||
// then follows width * height number of dqp values.
|
||||
FILE* f = fopen(value, "rb");
|
||||
if (!f) {
|
||||
fprintf(stderr, "Could not open ROI file.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
if (!fscanf(f, "%d", &width) || !fscanf(f, "%d", &height)) {
|
||||
fprintf(stderr, "Failed to read ROI size.\n");
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (width <= 0 || height <= 0) {
|
||||
fprintf(stderr, "Invalid ROI size: %dx%d.\n", width, height);
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const long long unsigned size = (long long unsigned) width *
|
||||
(long long unsigned) height;
|
||||
if (size > SIZE_MAX) {
|
||||
fprintf(stderr, "Too large ROI size: %llu (maximum %zu).\n", size, SIZE_MAX);
|
||||
return 0;
|
||||
}
|
||||
|
||||
cfg->roi.width = width;
|
||||
cfg->roi.height = height;
|
||||
cfg->roi.dqps = malloc(width * height * sizeof(*cfg->roi.dqps));
|
||||
// FIXME: this array is never freed
|
||||
cfg->roi.dqps = calloc((size_t)size, sizeof(*cfg->roi.dqps));
|
||||
if (!cfg->roi.dqps) {
|
||||
fprintf(stderr, "Failed to allocate memory for ROI table.\n");
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
for (int i = 0; i < width * height; ++i) {
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
int number; // Need a pointer to int for fscanf
|
||||
if (!fscanf(f, "%d", &number)) {
|
||||
if (fscanf(f, "%d", &number) != 1) {
|
||||
fprintf(stderr, "Reading ROI file failed.\n");
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
cfg->roi.dqps[i] = (uint8_t)number;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
|
|
|
@ -90,7 +90,7 @@ static int select_owf_auto(const kvz_config *const cfg)
|
|||
threads_per_frame -= 2;
|
||||
}
|
||||
|
||||
if (cfg->gop_lowdelay && cfg->gop_lp_definition.t > 1) {
|
||||
if (cfg->gop_len && cfg->gop_lowdelay && cfg->gop_lp_definition.t > 1) {
|
||||
// Temporal skipping makes every other frame very fast to encode so
|
||||
// more parallel frames should be used.
|
||||
frames *= 2;
|
||||
|
|
|
@ -987,7 +987,9 @@ static void encoder_state_init_new_frame(encoder_state_t * const state, kvz_pict
|
|||
state->frame->slicetype = cfg->intra_period==1 ? KVZ_SLICE_I : (state->encoder_control->cfg->gop_len?KVZ_SLICE_B:KVZ_SLICE_P);
|
||||
|
||||
// Use P-slice for lowdelay.
|
||||
if (state->frame->slicetype == KVZ_SLICE_B && cfg->gop_lowdelay) {
|
||||
if (state->frame->slicetype == KVZ_SLICE_B &&
|
||||
cfg->gop_len > 0 &&
|
||||
cfg->gop_lowdelay) {
|
||||
state->frame->slicetype = KVZ_SLICE_P;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,8 @@ kvz_picture* kvz_encoder_feed_frame(input_frame_buffer_t *buf,
|
|||
|
||||
img_in->dts = img_in->pts;
|
||||
state->frame->gop_offset = 0;
|
||||
if (cfg->gop_lowdelay) {
|
||||
if (cfg->gop_len > 0) {
|
||||
// Using a low delay GOP structure.
|
||||
state->frame->gop_offset = (state->frame->num - 1) % cfg->gop_len;
|
||||
if (state->frame->gop_offset < 0) {
|
||||
// Set gop_offset of IDR as the highest quality picture.
|
||||
|
|
|
@ -733,7 +733,7 @@ static double search_cu(encoder_state_t * const state, int x, int y, int depth,
|
|||
|
||||
cur_cu->intra = cu_d1->intra;
|
||||
cur_cu->type = CU_INTRA;
|
||||
cur_cu->part_size = depth > MAX_DEPTH ? SIZE_NxN : SIZE_2Nx2N;
|
||||
cur_cu->part_size = SIZE_2Nx2N;
|
||||
|
||||
kvz_lcu_set_trdepth(&work_tree[depth], x, y, depth, cur_cu->tr_depth);
|
||||
lcu_set_intra_mode(&work_tree[depth], x, y, depth,
|
||||
|
|
|
@ -1229,20 +1229,16 @@ static void search_pu_inter_ref(encoder_state_t * const state,
|
|||
double *inter_cost,
|
||||
uint32_t *inter_bitcost)
|
||||
{
|
||||
const int x_cu = x >> 3;
|
||||
const int y_cu = y >> 3;
|
||||
const videoframe_t * const frame = state->tile->frame;
|
||||
kvz_picture *ref_image = state->frame->ref->images[ref_idx];
|
||||
const vector2d_t orig = { x, y };
|
||||
uint32_t temp_bitcost = 0;
|
||||
uint32_t temp_cost = 0;
|
||||
vector2d_t orig;
|
||||
int32_t merged = 0;
|
||||
uint8_t cu_mv_cand = 0;
|
||||
int8_t merge_idx = 0;
|
||||
int8_t ref_list = state->frame->refmap[ref_idx].list-1;
|
||||
int8_t temp_ref_idx = cur_cu->inter.mv_ref[ref_list];
|
||||
orig.x = x_cu * CU_MIN_SIZE_PIXELS;
|
||||
orig.y = y_cu * CU_MIN_SIZE_PIXELS;
|
||||
// Get MV candidates
|
||||
cur_cu->inter.mv_ref[ref_list] = ref_idx;
|
||||
kvz_inter_get_mv_cand(state, x, y, width, height, mv_cand, cur_cu, lcu, ref_list);
|
||||
|
|
Loading…
Reference in a new issue