Browse code

aacenc: quit when the audio queue reaches 0 rather than keeping track of empty frames

The libopus encoder does the same thing and its better than
keeping track of when the empty flush frames appear.

Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>

Rostislav Pehlivanov authored on 2016/11/07 11:11:50
Showing 2 changed files
... ...
@@ -520,13 +520,13 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
520 520
     int chan_el_counter[4];
521 521
     FFPsyWindowInfo windows[AAC_MAX_CHANNELS];
522 522
 
523
-    if (s->last_frame == 2)
524
-        return 0;
525
-
526 523
     /* add current frame to queue */
527 524
     if (frame) {
528 525
         if ((ret = ff_af_queue_add(&s->afq, frame)) < 0)
529 526
             return ret;
527
+    } else {
528
+        if (!s->afq.remaining_samples || (!s->afq.frame_alloc && !s->afq.frame_count))
529
+            return 0;
530 530
     }
531 531
 
532 532
     copy_input_samples(s, frame);
... ...
@@ -841,9 +841,6 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
841 841
     s->lambda_sum += s->lambda;
842 842
     s->lambda_count++;
843 843
 
844
-    if (!frame)
845
-        s->last_frame++;
846
-
847 844
     ff_af_queue_remove(&s->afq, avctx->frame_size, &avpkt->pts,
848 845
                        &avpkt->duration);
849 846
 
... ...
@@ -112,7 +112,6 @@ typedef struct AACEncContext {
112 112
     struct FFPsyPreprocessContext* psypp;
113 113
     AACCoefficientsEncoder *coder;
114 114
     int cur_channel;                             ///< current channel for coder context
115
-    int last_frame;
116 115
     int random_state;
117 116
     float lambda;
118 117
     int last_frame_pb_count;                     ///< number of bits for the previous frame