int kvz_encoder_state_match_children_of_previous_frame(encoder_state_t * const state) { int i; for (i = 0; state->children[i].encoder_control; ++i) { //Child should also exist for previous encoder assert(state->previous_encoder_state->children[i].encoder_control); state->children[i].previous_encoder_state = &state->previous_encoder_state->children[i]; kvz_encoder_state_match_children_of_previous_frame(&state->children[i]); } return 1; }
static kvz_encoder * kvazaar_open(const kvz_config *cfg) { kvz_encoder *encoder = NULL; //Initialize strategies // TODO: Make strategies non-global if (!kvz_strategyselector_init(cfg->cpuid, KVZ_BIT_DEPTH)) { fprintf(stderr, "Failed to initialize strategies.\n"); goto kvazaar_open_failure; } kvz_init_exp_golomb(); encoder = calloc(1, sizeof(kvz_encoder)); if (!encoder) { goto kvazaar_open_failure; } encoder->control = kvz_encoder_control_init(cfg); if (!encoder->control) { goto kvazaar_open_failure; } encoder->num_encoder_states = encoder->control->owf + 1; encoder->cur_state_num = 0; encoder->out_state_num = 0; encoder->frames_started = 0; encoder->frames_done = 0; kvz_init_input_frame_buffer(&encoder->input_buffer); encoder->states = calloc(encoder->num_encoder_states, sizeof(encoder_state_t)); if (!encoder->states) { goto kvazaar_open_failure; } for (unsigned i = 0; i < encoder->num_encoder_states; ++i) { encoder->states[i].encoder_control = encoder->control; if (!kvz_encoder_state_init(&encoder->states[i], NULL)) { goto kvazaar_open_failure; } encoder->states[i].global->QP = (int8_t)cfg->qp; } for (int i = 0; i < encoder->num_encoder_states; ++i) { if (i == 0) { encoder->states[i].previous_encoder_state = &encoder->states[encoder->num_encoder_states - 1]; } else { encoder->states[i].previous_encoder_state = &encoder->states[(i - 1) % encoder->num_encoder_states]; } kvz_encoder_state_match_children_of_previous_frame(&encoder->states[i]); } encoder->states[encoder->cur_state_num].global->frame = -1; return encoder; kvazaar_open_failure: kvazaar_close(encoder); return NULL; }