Skip to content

Commit

Permalink
daalaenc: Remove the last parameter from daala_encode_packet_out()
Browse files Browse the repository at this point in the history
It is very rare that applications know when the last frame is being
processed, and this information is exclusively used for OGG muxing.

Move the necessary OGG parameter outside the library to the example code,
and simplify checking encoder state a bit.
  • Loading branch information
kodawah committed Oct 12, 2015
1 parent 5773936 commit 00c9323
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
3 changes: 2 additions & 1 deletion examples/encoder_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 1 addition & 5 deletions include/daala/daalaenc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tt>daala_packet</tt> structure to fill.
* All of the elements of this structure will be set, including a
* pointer to the video data.
Expand All @@ -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 <tt>NULL</tt>.*/
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);
Expand Down
10 changes: 4 additions & 6 deletions src/encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -2862,22 +2861,21 @@ 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);
op->bytes = nbytes;
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.*/
Expand Down

0 comments on commit 00c9323

Please sign in to comment.