Skip to content

Commit

Permalink
Merge branch 'frame-info'
Browse files Browse the repository at this point in the history
  • Loading branch information
aryla committed Sep 28, 2015
2 parents 9051fbf + 8f404a3 commit fdc3110
Show file tree
Hide file tree
Showing 19 changed files with 266 additions and 173 deletions.
38 changes: 13 additions & 25 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
*/

#include "cli.h"
#include "encoderstate.h"

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -356,37 +355,26 @@ void print_help(void)
}


void print_frame_info(encoder_state_t *state, double frame_psnr[3])
void print_frame_info(const kvz_frame_info *const info,
const double frame_psnr[3],
const uint32_t bytes)
{
fprintf(stderr, "POC %4d QP %2d (%c-frame) %10d bits PSNR: %2.4f %2.4f %2.4f",
state->global->poc,
state->global->QP,
"BPI"[state->global->slicetype % 3], state->stats_bitstream_length << 3,
info->poc,
info->qp,
"BPI"[info->slice_type % 3],
bytes << 3,
frame_psnr[0], frame_psnr[1], frame_psnr[2]);

// Print reference picture lists
if (state->global->slicetype != SLICE_I) {
int j, ref_list[2] = { 0, 0 }, ref_list_poc[2][16];
// List all pocs of lists
for (j = 0; j < state->global->ref->used_size; j++) {
if (state->global->ref->pocs[j] < state->global->poc) {
ref_list_poc[0][ref_list[0]] = state->global->ref->pocs[j];
ref_list[0]++;
} else {
ref_list_poc[1][ref_list[1]] = state->global->ref->pocs[j];
ref_list[1]++;
}
}
kvz_encoder_ref_insertion_sort(ref_list_poc[0], ref_list[0]);
kvz_encoder_ref_insertion_sort(ref_list_poc[1], ref_list[1]);

if (info->slice_type != KVZ_SLICE_I) {
// Print reference picture lists
fprintf(stderr, " [L0 ");
for (j = ref_list[0] - 1; j >= 0; j--) {
fprintf(stderr, "%d ", ref_list_poc[0][j]);
for (int j = info->ref_list_len[0] - 1; j >= 0; j--) {
fprintf(stderr, "%d ", info->ref_list[0][j]);
}
fprintf(stderr, "] [L1 ");
for (j = 0; j < ref_list[1]; j++) {
fprintf(stderr, "%d ", ref_list_poc[1][j]);
for (int j = 0; j < info->ref_list_len[1]; j++) {
fprintf(stderr, "%d ", info->ref_list[1][j]);
}
fprintf(stderr, "]");
}
Expand Down
4 changes: 3 additions & 1 deletion src/cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ void cmdline_opts_free(const kvz_api *api, cmdline_opts_t *opts);

void print_version(void);
void print_help(void);
void print_frame_info(encoder_state_t *state, double frame_psnr[3]);
void print_frame_info(const kvz_frame_info *const info,
const double frame_psnr[3],
const uint32_t bytes);

#endif
24 changes: 13 additions & 11 deletions src/encmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@

#include "checkpoint.h"
#include "global.h"
#include "config.h"
#include "threadqueue.h"
#include "encoder.h"
#include "encoderstate.h"
#include "videoframe.h"
#include "cli.h"
#include "yuv_io.h"

Expand Down Expand Up @@ -211,8 +210,16 @@ int main(int argc, char *argv[])

kvz_data_chunk* chunks_out = NULL;
kvz_picture *img_rec = NULL;
kvz_picture *img_src = NULL;
uint32_t len_out = 0;
if (!api->encoder_encode(enc, img_in, &chunks_out, &len_out, &img_rec)) {
kvz_frame_info info_out;
if (!api->encoder_encode(enc,
img_in,
&chunks_out,
&len_out,
&img_rec,
&img_src,
&info_out)) {
fprintf(stderr, "Failed to encode image.\n");
api->picture_free(img_in);
goto exit_failure;
Expand Down Expand Up @@ -244,14 +251,8 @@ int main(int argc, char *argv[])

// Compute and print stats.

// Number of the state that was finished is one less than
// enc->out_state_num.
encoder_state_t *state = &enc->states[
(enc->out_state_num + enc->num_encoder_states - 1) %
enc->num_encoder_states
];
double frame_psnr[3] = { 0.0, 0.0, 0.0 };
kvz_encoder_compute_stats(state, frame_psnr);
kvz_videoframe_compute_psnr(img_src, img_rec, frame_psnr);

if (recout) {
// Since chunks_out was not NULL, img_rec should have been set.
Expand All @@ -269,12 +270,13 @@ int main(int argc, char *argv[])
psnr_sum[1] += frame_psnr[1];
psnr_sum[2] += frame_psnr[2];

print_frame_info(state, frame_psnr);
print_frame_info(&info_out, frame_psnr, len_out);
}

api->picture_free(img_in);
api->chunk_free(chunks_out);
api->picture_free(img_rec);
api->picture_free(img_src);
}

GET_TIME(&encoding_end_real_time);
Expand Down
34 changes: 17 additions & 17 deletions src/encoder_state-bitstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
static void encoder_state_write_bitstream_aud(encoder_state_t * const state)
{
bitstream_t * const stream = &state->stream;
kvz_nal_write(stream, AUD_NUT, 0, 1);
kvz_nal_write(stream, KVZ_NAL_AUD_NUT, 0, 1);

uint8_t pic_type = state->global->slicetype == SLICE_I ? 0
: state->global->slicetype == SLICE_P ? 1
uint8_t pic_type = state->global->slicetype == KVZ_SLICE_I ? 0
: state->global->slicetype == KVZ_SLICE_P ? 1
: 2;
WRITE_U(stream, pic_type, 3, "pic_type");

Expand Down Expand Up @@ -654,8 +654,8 @@ void kvz_encoder_state_write_bitstream_slice_header(encoder_state_t * const stat
#endif
WRITE_U(stream, (state->slice->start_in_rs == 0), 1, "first_slice_segment_in_pic_flag");

if (state->global->pictype >= NAL_BLA_W_LP
&& state->global->pictype <= NAL_RSV_IRAP_VCL23) {
if (state->global->pictype >= KVZ_NAL_BLA_W_LP
&& state->global->pictype <= KVZ_NAL_RSV_IRAP_VCL23) {
WRITE_U(stream, 1, 1, "no_output_of_prior_pics_flag");
}

Expand All @@ -674,8 +674,8 @@ void kvz_encoder_state_write_bitstream_slice_header(encoder_state_t * const stat
//WRITE_U(stream, 1, 1, "pic_output_flag");
//end if
//if( IdrPicFlag ) <- nal_unit_type == 5
if (state->global->pictype != NAL_IDR_W_RADL
&& state->global->pictype != NAL_IDR_N_LP) {
if (state->global->pictype != KVZ_NAL_IDR_W_RADL
&& state->global->pictype != KVZ_NAL_IDR_N_LP) {
int last_poc = 0;
int poc_shift = 0;

Expand Down Expand Up @@ -745,10 +745,10 @@ void kvz_encoder_state_write_bitstream_slice_header(encoder_state_t * const stat
WRITE_U(stream, 1, 1, "slice_sao_chroma_flag");
}

if (state->global->slicetype != SLICE_I) {
if (state->global->slicetype != KVZ_SLICE_I) {
WRITE_U(stream, 1, 1, "num_ref_idx_active_override_flag");
WRITE_UE(stream, ref_negative != 0 ? ref_negative - 1: 0, "num_ref_idx_l0_active_minus1");
if (state->global->slicetype == SLICE_B) {
if (state->global->slicetype == KVZ_SLICE_B) {
WRITE_UE(stream, ref_positive != 0 ? ref_positive - 1 : 0, "num_ref_idx_l1_active_minus1");
WRITE_U(stream, 0, 1, "mvd_l1_zero_flag");
}
Expand Down Expand Up @@ -790,7 +790,7 @@ static void add_checksum(encoder_state_t * const state)
uint32_t checksum_val;
unsigned int i;

kvz_nal_write(stream, NAL_SUFFIT_SEI_NUT, 0, 0);
kvz_nal_write(stream, KVZ_NAL_SUFFIX_SEI_NUT, 0, 0);

kvz_image_checksum(frame->rec, checksum, state->encoder_control->bitdepth);

Expand Down Expand Up @@ -845,21 +845,21 @@ static void encoder_state_write_bitstream_main(encoder_state_t * const state)
first_nal_in_au = false;

// Video Parameter Set (VPS)
kvz_nal_write(stream, NAL_VPS_NUT, 0, 1);
kvz_nal_write(stream, KVZ_NAL_VPS_NUT, 0, 1);
encoder_state_write_bitstream_vid_parameter_set(state);

// Sequence Parameter Set (SPS)
kvz_nal_write(stream, NAL_SPS_NUT, 0, 1);
kvz_nal_write(stream, KVZ_NAL_SPS_NUT, 0, 1);
encoder_state_write_bitstream_seq_parameter_set(state);

// Picture Parameter Set (PPS)
kvz_nal_write(stream, NAL_PPS_NUT, 0, 1);
kvz_nal_write(stream, KVZ_NAL_PPS_NUT, 0, 1);
encoder_state_write_bitstream_pic_parameter_set(state);
}

// Send Kvazaar version information only in the first frame.
if (state->global->frame == 0 && state->encoder_control->cfg->add_encoder_info) {
kvz_nal_write(stream, PREFIX_SEI_NUT, 0, first_nal_in_au);
kvz_nal_write(stream, KVZ_NAL_PREFIX_SEI_NUT, 0, first_nal_in_au);
encoder_state_write_bitstream_prefix_sei_version(state);

// spec:sei_rbsp() rbsp_trailing_bits
Expand All @@ -870,19 +870,19 @@ static void encoder_state_write_bitstream_main(encoder_state_t * const state)
if (state->encoder_control->vui.frame_field_info_present_flag){
// These should be optional, needed for earlier versions
// of HM decoder to accept bitstream
//kvz_nal_write(stream, PREFIX_SEI_NUT, 0, 0);
//kvz_nal_write(stream, KVZ_NAL_PREFIX_SEI_NUT, 0, 0);
//encoder_state_write_active_parameter_sets_sei_message(state);
//kvz_bitstream_rbsp_trailing_bits(stream);

kvz_nal_write(stream, PREFIX_SEI_NUT, 0, first_nal_in_au);
kvz_nal_write(stream, KVZ_NAL_PREFIX_SEI_NUT, 0, first_nal_in_au);
encoder_state_write_picture_timing_sei_message(state);

// spec:sei_rbsp() rbsp_trailing_bits
kvz_bitstream_add_rbsp_trailing_bits(stream);
}

{
uint8_t nal_type = (state->global->is_idr_frame ? NAL_IDR_W_RADL : NAL_TRAIL_R);
uint8_t nal_type = (state->global->is_idr_frame ? KVZ_NAL_IDR_W_RADL : KVZ_NAL_TRAIL_R);
kvz_nal_write(stream, nal_type, 0, first_nal_in_au);
}

Expand Down
Loading

0 comments on commit fdc3110

Please sign in to comment.