HANDLE_AACENCODER encoder, uint32_t frame_length,
m4af_ctx_t *m4af)
{
- struct buffer_t {
- uint8_t *data;
- uint32_t len, size;
- };
int16_t *ibuf = 0, *ip;
- struct buffer_t obuf[2] = {{ 0 }}, *obp;
+ aacenc_result_t obuf[2] = {{ 0 }}, *obp;
unsigned flip = 0;
int nread = 1;
int rc = -1;
remaining = nread;
do {
obp = &obuf[flip];
- consumed = aac_encode_frame(encoder, fmt, ip, remaining,
- &obp->data, &obp->len, &obp->size);
+ consumed = aac_encode_frame(encoder, fmt, ip, remaining, obp);
if (consumed < 0) goto END;
if (consumed == 0 && obp->len == 0) goto DONE;
if (obp->len == 0) break;
m4af_set_priming_mode(m4af, params.gapless_mode + 1);
m4af_begin_write(m4af);
}
+ if (sbr_mode && (aacinfo.encoderDelay & 1)) {
+ /*
+ * Since odd delay cannot be exactly expressed in downsampled scale,
+ * we push one zero frame to the encoder here, to make delay even
+ */
+ int16_t zero[8] = { 0 };
+ aacenc_result_t obuf = { 0 };
+ aac_encode_frame(encoder, sample_format, zero, 1, &obuf);
+ free(obuf.data);
+ }
frame_count = encode(¶ms, reader, encoder, aacinfo.frameLength, m4af);
if (frame_count < 0)
goto END;