Output frame info from encoder_encode.

Adds a new output parameter info_out to encoder_encode. It returns
a struct containing information about the encoded frame, including POC,
QP and slice type.
This commit is contained in:
Arttu Ylä-Outinen 2015-09-08 13:59:55 +03:00
parent 173b70b53f
commit c856a6b598
5 changed files with 48 additions and 13 deletions

View file

@ -212,7 +212,7 @@ int main(int argc, char *argv[])
kvz_data_chunk* chunks_out = NULL;
kvz_picture *img_rec = NULL;
uint32_t len_out = 0;
if (!api->encoder_encode(enc, img_in, &chunks_out, &len_out, &img_rec)) {
if (!api->encoder_encode(enc, img_in, &chunks_out, &len_out, &img_rec, NULL)) {
fprintf(stderr, "Failed to encode image.\n");
api->picture_free(img_in);
goto exit_failure;

View file

@ -216,10 +216,5 @@ typedef int16_t coeff_t;
//Constants
typedef enum { COLOR_Y = 0, COLOR_U, COLOR_V, NUM_COLORS } color_t;
enum kvz_slice_type {
KVZ_SLICE_B = 0,
KVZ_SLICE_P = 1,
KVZ_SLICE_I = 2,
};
#endif

View file

@ -113,11 +113,20 @@ kvazaar_open_failure:
}
static void set_frame_info(kvz_frame_info *const info, const encoder_state_t *const state)
{
info->poc = state->global->poc,
info->qp = state->global->QP;
info->slice_type = state->global->slicetype;
}
static int kvazaar_encode(kvz_encoder *enc,
kvz_picture *pic_in,
kvz_data_chunk **data_out,
uint32_t *len_out,
kvz_picture **pic_out)
kvz_picture **pic_out,
kvz_frame_info *info_out)
{
if (data_out) *data_out = NULL;
if (len_out) *len_out = 0;
@ -164,6 +173,7 @@ static int kvazaar_encode(kvz_encoder *enc,
if (len_out) *len_out = kvz_bitstream_tell(&output_state->stream) / 8;
if (data_out) *data_out = kvz_bitstream_take_chunks(&output_state->stream);
if (pic_out) *pic_out = kvz_image_copy_ref(output_state->tile->frame->rec);
if (info_out) set_frame_info(info_out, output_state);
output_state->frame_done = 1;
output_state->prepared = 0;

View file

@ -191,6 +191,34 @@ typedef struct kvz_picture {
int64_t dts; //!< \brief Decompression timestamp.
} kvz_picture;
enum kvz_slice_type {
KVZ_SLICE_B = 0,
KVZ_SLICE_P = 1,
KVZ_SLICE_I = 2,
};
/**
* \brief Other information about an encoded frame
*/
typedef struct kvz_frame_info {
/**
* \brief Picture order count
*/
int32_t poc;
/**
* \brief Quantization parameter
*/
int8_t qp;
/**
* \brief Type of the slice
*/
enum kvz_slice_type slice_type;
} kvz_frame_info;
/**
* \brief A linked list of chunks of data.
*
@ -303,9 +331,9 @@ typedef struct kvz_api {
* \brief Encode one frame.
*
* Add pic_in to the encoding pipeline. If an encoded frame is ready, return
* the bitstream, length of the bitstream and the reconstructed frame in
* data_out, len_out and pic_out, respectively. Otherwise, set the output
* parameters to NULL.
* the bitstream, length of the bitstream, the reconstructed frame and frame
* info in data_out, len_out, pic_out and info_out, respectively. Otherwise,
* set the output parameters to NULL.
*
* After passing all of the input frames, the caller should keep calling this
* function with pic_in set to NULL, until no more data is returned in the
@ -317,20 +345,22 @@ typedef struct kvz_api {
* responsible for calling picture_free and chunk_free on them.
*
* A null pointer may be passed in place of any of the parameters data_out,
* len_out or pic_out to skip returning the corresponding value.
* len_out, pic_out or info_out to skip returning the corresponding value.
*
* \param encoder encoder
* \param pic_in input frame or NULL
* \param data_out Returns the encoded data.
* \param len_out Returns number of bytes in the encoded data.
* \param pic_out Returns the reconstructed picture.
* \param info_out Returns information about the encoded picture.
* \return 1 on success, 0 on error.
*/
int (*encoder_encode)(kvz_encoder *encoder,
kvz_picture *pic_in,
kvz_data_chunk **data_out,
uint32_t *len_out,
kvz_picture **pic_out);
kvz_picture **pic_out,
kvz_frame_info *info_out);
} kvz_api;
// Append API version to the getters name to prevent linking against incompatible versions.

View file

@ -21,6 +21,6 @@
****************************************************************************/
// KVZ_API_VERSION is incremented every time the public api changes.
#define KVZ_API_VERSION 4
#define KVZ_API_VERSION 5
#endif // KVAZAAR_VERSION_H_