Fix potential infinite loop in encoder_encode()
Before this patch, an infinite loop may occur if av1_get_compressed_data()
returns with error.
Change-Id: Iee945dbb71d181f3d272b99c4adfa66816ac893c
diff --git a/av1/av1_cx_iface.c b/av1/av1_cx_iface.c
index 33f252f..a13a143 100644
--- a/av1/av1_cx_iface.c
+++ b/av1/av1_cx_iface.c
@@ -1836,10 +1836,15 @@
int has_fwd_keyframe = 0;
// invisible frames get packed with the next visible frame
while (cx_data_sz - index_size >= ctx->cx_data_sz / 2 &&
- !is_frame_visible &&
- -1 != av1_get_compressed_data(cpi, &lib_flags, &frame_size, cx_data,
- &dst_time_stamp, &dst_end_time_stamp,
- !img, timestamp_ratio)) {
+ !is_frame_visible) {
+ const int status = av1_get_compressed_data(
+ cpi, &lib_flags, &frame_size, cx_data, &dst_time_stamp,
+ &dst_end_time_stamp, !img, timestamp_ratio);
+ if (status == -1) break;
+ if (status != AOM_CODEC_OK) {
+ aom_internal_error(&cpi->common.error, AOM_CODEC_ERROR, NULL);
+ }
+
cpi->seq_params_locked = 1;
if (frame_size) {
if (ctx->pending_cx_data == 0) ctx->pending_cx_data = cx_data;
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 9e23c55..4f55317 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -5845,7 +5845,7 @@
aom_clear_system_state();
- return 0;
+ return AOM_CODEC_OK;
}
int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest) {