From 25556d1aaf883a51d36d5e42868ec0339ae1572a Mon Sep 17 00:00:00 2001 From: Vittorio Giovara Date: Mon, 12 Oct 2015 15:13:29 +0200 Subject: [PATCH] daalaenc: Remove the last parameter from daala_encode_packet_out() It is very rare that applications know when the last frame is being processed, and this information is exclusively used for OGG muxing. Move setting the necessary OGG parameter from library to example code, and simplify checking encoder state a bit. --- examples/encoder_example.c | 3 ++- include/daala/daalaenc.h | 6 +----- src/encode.c | 10 ++++------ 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/examples/encoder_example.c b/examples/encoder_example.c index 6978ffe7..39dbdd99 100644 --- a/examples/encoder_example.c +++ b/examples/encoder_example.c @@ -493,10 +493,11 @@ int fetch_and_process_video(av_input *avin, ogg_page *page, /*Pull the packets from the previous frame, now that we know whether or not we can read the current one. This is used to set the e_o_s bit on the final packet.*/ - while (daala_encode_packet_out(dd, last, &dp)) { + while (daala_encode_packet_out(dd, &dp)) { ogg_packet op; daala_to_ogg_packet(&op, &dp); + op.e_o_s = last; ogg_stream_packetin(vo, &op); } diff --git a/include/daala/daalaenc.h b/include/daala/daalaenc.h index 7e8e137d..b3187ba1 100644 --- a/include/daala/daalaenc.h +++ b/include/daala/daalaenc.h @@ -121,9 +121,6 @@ int daala_encode_img_in(daala_enc_ctx *enc, od_img *img, int duration); * manner. * However, this may be changed in the future. * \param enc A #daala_enc_ctx handle. - * \param last Set this flag to a non-zero value if no more uncompressed - * frames will be submitted. - * This ensures that a proper EOS flag is set on the last packet. * \param dp A daala_packet structure to fill. * All of the elements of this structure will be set, including a * pointer to the video data. @@ -133,8 +130,7 @@ int daala_encode_img_in(daala_enc_ctx *enc, od_img *img, int duration); * \retval 0 No packet was produced, and no more encoded video data * remains. * \retval OD_EFAULT \a enc or \a op was NULL.*/ -int daala_encode_packet_out(daala_enc_ctx *enc, - int last, daala_packet *dp); +int daala_encode_packet_out(daala_enc_ctx *enc, daala_packet *dp); /**Frees an allocated encoder instance. * \param enc A #daala_enc_ctx handle.*/ void daala_encode_free(daala_enc_ctx *enc); diff --git a/src/encode.c b/src/encode.c index 6e7384bf..4188800f 100644 --- a/src/encode.c +++ b/src/encode.c @@ -2657,7 +2657,6 @@ int daala_encode_img_in(daala_enc_ctx *enc, od_img *img, int duration) { od_mb_enc_ctx mbctx; od_img *ref_img; if (enc == NULL || img == NULL) return OD_EFAULT; - if (enc->packet_state == OD_PACKET_DONE) return OD_EINVAL; /*Check the input image dimensions to make sure they're compatible with the declared video size.*/ nplanes = enc->state.info.nplanes; @@ -2862,10 +2861,10 @@ static void daala_encoder_check(daala_enc_ctx *ctx, od_img *img, } #endif -int daala_encode_packet_out(daala_enc_ctx *enc, int last, daala_packet *op) { +int daala_encode_packet_out(daala_enc_ctx *enc, daala_packet *op) { uint32_t nbytes; if (enc == NULL || op == NULL) return OD_EFAULT; - else if (enc->packet_state <= 0 || enc->packet_state == OD_PACKET_DONE) { + else if (enc->packet_state <= 0) { return 0; } op->packet = od_ec_enc_done(&enc->ec, &nbytes); @@ -2873,11 +2872,10 @@ int daala_encode_packet_out(daala_enc_ctx *enc, int last, daala_packet *op) { OD_LOG((OD_LOG_ENCODER, OD_LOG_INFO, "Output Bytes: %ld (%ld Kbits)", op->bytes, op->bytes*8/1024)); op->b_o_s = 0; - op->e_o_s = last; + op->e_o_s = 0; op->packetno = 0; op->granulepos = enc->state.cur_time; - if (last) enc->packet_state = OD_PACKET_DONE; - else enc->packet_state = OD_PACKET_EMPTY; + enc->packet_state = OD_PACKET_EMPTY; #if defined(OD_ENCODER_CHECK) /*Compare reconstructed frame against decoded frame.*/