Modify encoder interface to facilitate FPMT
Interface of av1_get_compressed_data() and post_encode_updates() have
been modified to use AV1_COMP_DATA structure.
Change-Id: Ic4388baa78e2dede0113f218d9fc3c225c1818ec
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index 3fa9378..a1f0348 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -2506,8 +2506,11 @@
volatile aom_codec_err_t res = AOM_CODEC_OK;
AV1_PRIMARY *const ppi = ctx->ppi;
AV1_COMP *const cpi = ppi->cpi;
- const aom_rational64_t *const timestamp_ratio = &ctx->timestamp_ratio;
volatile aom_codec_pts_t ptsvol = pts;
+ AV1_COMP_DATA cpi_data = { 0 };
+
+ cpi_data.timestamp_ratio = &ctx->timestamp_ratio;
+ cpi_data.flush = !img;
// LAP context
AV1_COMP *cpi_lap = ppi->cpi_lap;
if (cpi == NULL) return AOM_CODEC_INVALID_PARAM;
@@ -2622,9 +2625,10 @@
ctx->pts_offset_initialized = 1;
}
ptsvol -= ctx->pts_offset;
- int64_t src_time_stamp = timebase_units_to_ticks(timestamp_ratio, ptsvol);
+ int64_t src_time_stamp =
+ timebase_units_to_ticks(cpi_data.timestamp_ratio, ptsvol);
int64_t src_end_time_stamp =
- timebase_units_to_ticks(timestamp_ratio, ptsvol + duration);
+ timebase_units_to_ticks(cpi_data.timestamp_ratio, ptsvol + duration);
YV12_BUFFER_CONFIG sd;
res = image2yuvconfig(img, &sd);
@@ -2676,29 +2680,26 @@
ctx->next_frame_flags = 0;
}
- unsigned char *cx_data = ctx->cx_data;
- size_t cx_data_sz = ctx->cx_data_sz;
+ cpi_data.cx_data = ctx->cx_data;
+ cpi_data.cx_data_sz = ctx->cx_data_sz;
/* Any pending invisible frames? */
if (ctx->pending_cx_data_sz) {
- cx_data += ctx->pending_cx_data_sz;
- cx_data_sz -= ctx->pending_cx_data_sz;
+ cpi_data.cx_data += ctx->pending_cx_data_sz;
+ cpi_data.cx_data_sz -= ctx->pending_cx_data_sz;
/* TODO: this is a minimal check, the underlying codec doesn't respect
* the buffer size anyway.
*/
- if (cx_data_sz < ctx->cx_data_sz / 2) {
+ if (cpi_data.cx_data_sz < ctx->cx_data_sz / 2) {
aom_internal_error(&ppi->error, AOM_CODEC_ERROR,
"Compressed data buffer too small");
}
}
- size_t frame_size = 0;
- unsigned int lib_flags = 0;
int is_frame_visible = 0;
int has_no_show_keyframe = 0;
int num_workers = 0;
- int pop_lookahead = 0;
if (cpi->oxcf.pass == AOM_RC_FIRST_PASS) {
#if !CONFIG_REALTIME_ONLY
@@ -2736,29 +2737,21 @@
// Call for LAP stage
if (cpi_lap != NULL) {
- int64_t dst_time_stamp_la;
- int64_t dst_end_time_stamp_la;
- const int status = av1_get_compressed_data(
- cpi_lap, &lib_flags, &frame_size, cx_data_sz, NULL,
- &dst_time_stamp_la, &dst_end_time_stamp_la, !img, timestamp_ratio,
- &pop_lookahead);
+ AV1_COMP_DATA cpi_lap_data = { 0 };
+ cpi_lap_data.flush = !img;
+ cpi_lap_data.timestamp_ratio = &ctx->timestamp_ratio;
+ const int status = av1_get_compressed_data(cpi_lap, &cpi_lap_data);
if (status != -1) {
if (status != AOM_CODEC_OK) {
aom_internal_error(&ppi->error, AOM_CODEC_ERROR, NULL);
}
}
- av1_post_encode_updates(cpi_lap, frame_size, dst_time_stamp_la,
- dst_end_time_stamp_la, pop_lookahead, !img);
- lib_flags = 0;
- frame_size = 0;
- pop_lookahead = 0;
+ av1_post_encode_updates(cpi_lap, &cpi_lap_data);
}
// Get the next visible frame. Invisible frames get packed with the next
// visible frame.
- int64_t dst_time_stamp;
- int64_t dst_end_time_stamp;
- while (cx_data_sz >= ctx->cx_data_sz / 2 && !is_frame_visible) {
+ while (cpi_data.cx_data_sz >= ctx->cx_data_sz / 2 && !is_frame_visible) {
#if CONFIG_FRAME_PARALLEL_ENCODE
cpi->do_frame_data_update = true;
if (ppi->num_fp_contexts > 1 && ppi->gf_group.size > 1) {
@@ -2768,15 +2761,12 @@
}
}
#endif
- const int status = av1_get_compressed_data(
- cpi, &lib_flags, &frame_size, cx_data_sz, cx_data, &dst_time_stamp,
- &dst_end_time_stamp, !img, timestamp_ratio, &pop_lookahead);
+ const int status = av1_get_compressed_data(cpi, &cpi_data);
if (status == -1) break;
if (status != AOM_CODEC_OK) {
aom_internal_error(&ppi->error, AOM_CODEC_ERROR, NULL);
}
- av1_post_encode_updates(cpi, frame_size, dst_time_stamp,
- dst_end_time_stamp, pop_lookahead, !img);
+ av1_post_encode_updates(cpi, &cpi_data);
#if CONFIG_ENTROPY_STATS
if (ppi->cpi->oxcf.pass != 1 && !cpi->common.show_existing_frame)
@@ -2794,8 +2784,8 @@
#endif // CONFIG_INTERNAL_STATS
cpi->ppi->seq_params_locked = 1;
- if (!frame_size) continue;
- assert(cx_data != NULL && cx_data_sz != 0);
+ if (!cpi_data.frame_size) continue;
+ assert(cpi_data.cx_data != NULL && cpi_data.cx_data_sz != 0);
const int write_temporal_delimiter =
!cpi->common.spatial_layer_id && !ctx->pending_cx_data_sz;
@@ -2806,7 +2796,7 @@
aom_uleb_size_in_bytes(obu_payload_size);
const size_t move_offset = obu_header_size + length_field_size;
- memmove(ctx->cx_data + move_offset, ctx->cx_data, frame_size);
+ memmove(ctx->cx_data + move_offset, ctx->cx_data, cpi_data.frame_size);
obu_header_size = av1_write_obu_header(
&cpi->ppi->level_params, &cpi->frame_header_count,
OBU_TEMPORAL_DELIMITER, 0, ctx->cx_data);
@@ -2817,31 +2807,34 @@
aom_internal_error(&ppi->error, AOM_CODEC_ERROR, NULL);
}
- frame_size += obu_header_size + obu_payload_size + length_field_size;
+ cpi_data.frame_size +=
+ obu_header_size + obu_payload_size + length_field_size;
}
if (ctx->oxcf.save_as_annexb) {
- size_t curr_frame_size = frame_size;
- if (av1_convert_sect5obus_to_annexb(cx_data, &curr_frame_size) !=
- AOM_CODEC_OK) {
+ size_t curr_frame_size = cpi_data.frame_size;
+ if (av1_convert_sect5obus_to_annexb(cpi_data.cx_data,
+ &curr_frame_size) != AOM_CODEC_OK) {
aom_internal_error(&ppi->error, AOM_CODEC_ERROR, NULL);
}
- frame_size = curr_frame_size;
+ cpi_data.frame_size = curr_frame_size;
// B_PRIME (add frame size)
- const size_t length_field_size = aom_uleb_size_in_bytes(frame_size);
- memmove(cx_data + length_field_size, cx_data, frame_size);
- if (av1_write_uleb_obu_size(0, (uint32_t)frame_size, cx_data) !=
- AOM_CODEC_OK) {
+ const size_t length_field_size =
+ aom_uleb_size_in_bytes(cpi_data.frame_size);
+ memmove(cpi_data.cx_data + length_field_size, cpi_data.cx_data,
+ cpi_data.frame_size);
+ if (av1_write_uleb_obu_size(0, (uint32_t)cpi_data.frame_size,
+ cpi_data.cx_data) != AOM_CODEC_OK) {
aom_internal_error(&ppi->error, AOM_CODEC_ERROR, NULL);
}
- frame_size += length_field_size;
+ cpi_data.frame_size += length_field_size;
}
- ctx->pending_cx_data_sz += frame_size;
+ ctx->pending_cx_data_sz += cpi_data.frame_size;
- cx_data += frame_size;
- cx_data_sz -= frame_size;
+ cpi_data.cx_data += cpi_data.frame_size;
+ cpi_data.cx_data_sz -= cpi_data.frame_size;
is_frame_visible = cpi->common.show_frame;
@@ -2872,19 +2865,20 @@
pkt.data.frame.buf = ctx->cx_data;
pkt.data.frame.sz = ctx->pending_cx_data_sz;
pkt.data.frame.partition_id = -1;
- pkt.data.frame.vis_frame_size = frame_size;
+ pkt.data.frame.vis_frame_size = cpi_data.frame_size;
- pkt.data.frame.pts =
- ticks_to_timebase_units(timestamp_ratio, dst_time_stamp) +
- ctx->pts_offset;
- pkt.data.frame.flags = get_frame_pkt_flags(cpi, lib_flags);
+ pkt.data.frame.pts = ticks_to_timebase_units(cpi_data.timestamp_ratio,
+ cpi_data.ts_frame_start) +
+ ctx->pts_offset;
+ pkt.data.frame.flags = get_frame_pkt_flags(cpi, cpi_data.lib_flags);
if (has_no_show_keyframe) {
// If one of the invisible frames in the packet is a keyframe, set
// the delayed random access point flag.
pkt.data.frame.flags |= AOM_FRAME_IS_DELAYED_RANDOM_ACCESS_POINT;
}
pkt.data.frame.duration = (uint32_t)ticks_to_timebase_units(
- timestamp_ratio, dst_end_time_stamp - dst_time_stamp);
+ cpi_data.timestamp_ratio,
+ cpi_data.ts_frame_end - cpi_data.ts_frame_start);
aom_codec_pkt_list_add(&ctx->pkt_list.head, &pkt);
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 20cc13e..7d92739 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -4213,9 +4213,8 @@
update_gf_group_index(cpi);
}
-void av1_post_encode_updates(AV1_COMP *const cpi, size_t size,
- int64_t time_stamp, int64_t time_end,
- int pop_lookahead, int flush) {
+void av1_post_encode_updates(AV1_COMP *const cpi,
+ const AV1_COMP_DATA *const cpi_data) {
AV1_PRIMARY *const ppi = cpi->ppi;
AV1_COMMON *const cm = &cpi->common;
@@ -4245,11 +4244,12 @@
}
#endif // CONFIG_FRAME_PARALLEL_ENCODE_2
#endif // CONFIG_FRAME_PARALLEL_ENCODE
- av1_rc_postencode_update(cpi, size);
+ av1_rc_postencode_update(cpi, cpi_data->frame_size);
}
- if (pop_lookahead == 1) {
- av1_lookahead_pop(cpi->ppi->lookahead, flush, cpi->compressor_stage);
+ if (cpi_data->pop_lookahead == 1) {
+ av1_lookahead_pop(cpi->ppi->lookahead, cpi_data->flush,
+ cpi->compressor_stage);
}
if (ppi->level_params.keep_level_stats && !is_stat_generation_stage(cpi)) {
@@ -4258,7 +4258,8 @@
ppi->gf_group.refbuf_state[cpi->gf_frame_index] == REFBUF_RESET) {
av1_init_level_info(cpi);
}
- av1_update_level_info(cpi, size, time_stamp, time_end);
+ av1_update_level_info(cpi, cpi_data->frame_size, cpi_data->ts_frame_start,
+ cpi_data->ts_frame_end);
}
if (!is_stat_generation_stage(cpi)) {
@@ -4272,7 +4273,7 @@
if (ppi->use_svc) av1_save_layer_context(cpi);
// Note *size = 0 indicates a dropped frame for which psnr is not calculated
- if (ppi->b_calculate_psnr && size > 0) {
+ if (ppi->b_calculate_psnr && cpi_data->frame_size > 0) {
if (cm->show_existing_frame ||
(!is_stat_generation_stage(cpi) && cm->show_frame)) {
generate_psnr_packet(cpi);
@@ -4281,16 +4282,12 @@
#if CONFIG_INTERNAL_STATS
if (!is_stat_generation_stage(cpi)) {
- compute_internal_stats(cpi, (int)size);
+ compute_internal_stats(cpi, (int)cpi_data->frame_size);
}
#endif // CONFIG_INTERNAL_STATS
}
-int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
- size_t *size, size_t avail_size, uint8_t *dest,
- int64_t *time_stamp, int64_t *time_end, int flush,
- const aom_rational64_t *timestamp_ratio,
- int *const pop_lookahead) {
+int av1_get_compressed_data(AV1_COMP *cpi, AV1_COMP_DATA *const cpi_data) {
const AV1EncoderConfig *const oxcf = &cpi->oxcf;
AV1_COMMON *const cm = &cpi->common;
@@ -4318,8 +4315,8 @@
cpi->is_dropped_frame = false;
cm->showable_frame = 0;
- *size = 0;
- cpi->available_bs_size = avail_size;
+ cpi_data->frame_size = 0;
+ cpi->available_bs_size = cpi_data->cx_data_sz;
#if CONFIG_INTERNAL_STATS
struct aom_usec_timer cmptimer;
aom_usec_timer_start(&cmptimer);
@@ -4341,9 +4338,10 @@
if (cpi->oxcf.pass == 2) start_timing(cpi, av1_encode_strategy_time);
#endif
- const int result =
- av1_encode_strategy(cpi, size, dest, frame_flags, time_stamp, time_end,
- timestamp_ratio, pop_lookahead, flush);
+ const int result = av1_encode_strategy(
+ cpi, &cpi_data->frame_size, cpi_data->cx_data, &cpi_data->lib_flags,
+ &cpi_data->ts_frame_start, &cpi_data->ts_frame_end,
+ cpi_data->timestamp_ratio, &cpi_data->pop_lookahead, cpi_data->flush);
#if CONFIG_COLLECT_COMPONENT_TIMING
if (cpi->oxcf.pass == 2) end_timing(cpi, av1_encode_strategy_time);
diff --git a/av1/encoder/encoder.h b/av1/encoder/encoder.h
index 1e1693b..939598a 100644
--- a/av1/encoder/encoder.h
+++ b/av1/encoder/encoder.h
@@ -3161,9 +3161,8 @@
void av1_init_seq_coding_tools(AV1_PRIMARY *const ppi,
const AV1EncoderConfig *oxcf, int use_svc);
-void av1_post_encode_updates(AV1_COMP *const cpi, size_t size,
- int64_t time_stamp, int64_t time_end,
- int pop_lookahead, int flush);
+void av1_post_encode_updates(AV1_COMP *const cpi,
+ const AV1_COMP_DATA *const cpi_data);
/*!\endcond */
@@ -3194,18 +3193,11 @@
* \callergraph
* This function encodes the raw frame data, and outputs the frame bit stream
* to the designated buffer. The caller should use the output parameters
- * *time_stamp and *time_end only when this function returns AOM_CODEC_OK.
+ * cpi_data->ts_frame_start and cpi_data->ts_frame_end only when this function
+ * returns AOM_CODEC_OK.
*
- * \param[in] cpi Top-level encoder structure
- * \param[in] frame_flags Flags to decide how to encoding the frame
- * \param[in] size Bitstream size
- * \param[in] avail_size Available bitstream buffer size
- * \param[in] dest Bitstream output
- * \param[out] time_stamp Time stamp of the frame
- * \param[out] time_end Time end
- * \param[in] flush Decide to encode one frame or the rest of frames
- * \param[in] timebase Time base used
- * \param[in] pop_lookahead Decide to pop the source frame from queue
+ * \param[in] cpi Top-level encoder structure
+ * \param[in,out] cpi_data Data corresponding to a frame encode
*
* \return Returns a value to indicate if the encoding is done successfully.
* \retval #AOM_CODEC_OK
@@ -3213,11 +3205,7 @@
* No frame encoded; more input is required.
* \retval #AOM_CODEC_ERROR
*/
-int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
- size_t *size, size_t avail_size, uint8_t *dest,
- int64_t *time_stamp, int64_t *time_end, int flush,
- const aom_rational64_t *timebase,
- int *const pop_lookahead);
+int av1_get_compressed_data(AV1_COMP *cpi, AV1_COMP_DATA *const cpi_data);
/*!\brief Run 1-pass/2-pass encoding
*