svc_encoder_rtc.c: Cleanup and minor improvements
Change the mismatch_seen output parameter of test_decode() to the return
value. The function returns void and has only one output parameter, so
the output parameter can become the return value.
Correct a comment about AV1_GET_NEW_FRAME_IMAGE in test_decode(). The
new frame is not necessarily a reference frame.
Call die_codec() instead of die() after aom_codec_enc_init() and
aom_codec_dec_init() failures. Those two functions set an error in the
codec context when they fail, so calling die_codec() will report the
error code (and the error detail, if available).
Change "codec" to "encoder" in error messages about the encoder
instance.
Bug: aomedia:3404
Change-Id: Ib76ee9f9836358736d263260f6a6ade7851a1359
diff --git a/examples/svc_encoder_rtc.c b/examples/svc_encoder_rtc.c
index 74bb56b..94a9db9 100644
--- a/examples/svc_encoder_rtc.c
+++ b/examples/svc_encoder_rtc.c
@@ -1136,13 +1136,14 @@
}
#if CONFIG_AV1_DECODER
-static void test_decode(aom_codec_ctx_t *encoder, aom_codec_ctx_t *decoder,
- const int frames_out, int *mismatch_seen) {
+// Returns whether there is a mismatch between the encoder's new frame and the
+// decoder's new frame.
+static int test_decode(aom_codec_ctx_t *encoder, aom_codec_ctx_t *decoder,
+ const int frames_out) {
aom_image_t enc_img, dec_img;
+ int mismatch = 0;
- if (*mismatch_seen) return;
-
- /* Get the internal reference frame */
+ /* Get the internal new frame */
AOM_CODEC_CONTROL_TYPECHECKED(encoder, AV1_GET_NEW_FRAME_IMAGE, &enc_img);
AOM_CODEC_CONTROL_TYPECHECKED(decoder, AV1_GET_NEW_FRAME_IMAGE, &dec_img);
@@ -1184,11 +1185,12 @@
" V[%d, %d] {%d/%d}\n",
frames_out, y[0], y[1], y[2], y[3], u[0], u[1], u[2], u[3], v[0],
v[1], v[2], v[3]);
- *mismatch_seen = frames_out;
+ mismatch = 1;
}
aom_img_free(&enc_img);
aom_img_free(&dec_img);
+ return mismatch;
}
#endif // CONFIG_AV1_DECODER
@@ -1371,12 +1373,12 @@
if (aom_codec_enc_init(
&codec, encoder, &cfg,
cfg.g_input_bit_depth == AOM_BITS_8 ? 0 : AOM_CODEC_USE_HIGHBITDEPTH))
- die("Failed to initialize encoder");
+ die_codec(&codec, "Failed to initialize encoder");
#if CONFIG_AV1_DECODER
if (app_input.decode) {
if (aom_codec_dec_init(&decoder, get_aom_decoder_by_index(0), NULL, 0))
- die("Failed to initialize decoder");
+ die_codec(&decoder, "Failed to initialize decoder");
}
#endif
@@ -1666,12 +1668,10 @@
if ((ss_number_layers > 1 || ts_number_layers > 1) &&
!(layer_id.temporal_layer_id > 0 &&
layer_id.temporal_layer_id == (int)ts_number_layers - 1)) {
- int mismatch_seen = 0;
- test_decode(&codec, &decoder, frame_cnt, &mismatch_seen);
- if (mismatch_seen) {
+ if (test_decode(&codec, &decoder, frame_cnt)) {
#if CONFIG_INTERNAL_STATS
fprintf(stats_file, "First mismatch occurred in frame %d\n",
- mismatch_seen);
+ frame_cnt);
fclose(stats_file);
#endif
die("Mismatch seen");
@@ -1703,7 +1703,7 @@
frame_cnt, 1000 * (float)cx_time / (double)(frame_cnt * 1000000),
1000000 * (double)frame_cnt / (double)cx_time);
- if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy codec");
+ if (aom_codec_destroy(&codec)) die_codec(&codec, "Failed to destroy encoder");
#if CONFIG_AV1_DECODER
if (app_input.decode) {