- written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, data,
- frame, 0);
+ if ((ret = ff_alloc_packet(avpkt, 32))) {
+ av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
+ return ret;
+ }
+
+ if (frame) {
+ if (frame->nb_samples < avctx->frame_size) {
+ flush_buf = av_mallocz(avctx->frame_size * sizeof(*flush_buf));
+ if (!flush_buf)
+ return AVERROR(ENOMEM);
+ memcpy(flush_buf, samples, frame->nb_samples * sizeof(*flush_buf));
+ samples = flush_buf;
+ if (frame->nb_samples < avctx->frame_size - avctx->delay)
+ s->enc_last_frame = -1;
+ }
+ if ((ret = ff_af_queue_add(&s->afq, frame) < 0)) {
+ av_freep(&flush_buf);
+ return ret;
+ }
+ } else {
+ if (s->enc_last_frame < 0)
+ return 0;
+ flush_buf = av_mallocz(avctx->frame_size * sizeof(*flush_buf));
+ if (!flush_buf)
+ return AVERROR(ENOMEM);
+ samples = flush_buf;
+ s->enc_last_frame = -1;
+ }
+
+ written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, samples,
+ avpkt->data, 0);