+ VO_PBYTE samples;
+ int ret;
+
+ /* handle end-of-stream small frame and flushing */
+ if (!frame) {
+ if (s->last_frame <= 0)
+ return 0;
+ if (s->last_samples > 0 && s->last_samples < ENC_DELAY - FRAME_SIZE) {
+ s->last_samples = 0;
+ s->last_frame--;
+ }
+ s->last_frame--;
+ memset(s->end_buffer, 0, 2 * avctx->channels * avctx->frame_size);
+ samples = s->end_buffer;
+ } else {
+ if (frame->nb_samples < avctx->frame_size) {
+ s->last_samples = frame->nb_samples;
+ memcpy(s->end_buffer, frame->data[0], 2 * avctx->channels * frame->nb_samples);
+ samples = s->end_buffer;
+ } else {
+ samples = (VO_PBYTE)frame->data[0];
+ }
+ /* add current frame to the queue */
+ if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)
+ return ret;
+ }
+
+ if ((ret = ff_alloc_packet(avpkt, FFMAX(8192, 768 * avctx->channels)))) {
+ av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n");
+ return ret;
+ }