Browse code

Make FLAC parser return frames when it has the required amount (without buffering extra input). Patch by Michael Chinen [mchinen at gmail]

Originally committed as revision 25932 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Chinen authored on 2010/12/12 09:52:54
Showing 1 changed files
... ...
@@ -75,6 +75,7 @@ typedef struct FLACParseContext {
75 75
     FLACHeaderMarker *best_header; /**< highest scoring header within buffer  */
76 76
     int nb_headers_found;          /**< number of headers found in the last
77 77
                                         flac_parse() call                     */
78
+    int nb_headers_buffered;       /**< number of headers that are buffered   */
78 79
     int best_header_valid;         /**< flag set when the parser returns junk;
79 80
                                         if set return best_header next time   */
80 81
     AVFifoBuffer *fifo_buf;        /**< buffer to store all data until headers
... ...
@@ -504,6 +505,7 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
504 504
             temp = curr->next;
505 505
             av_freep(&curr->link_penalty);
506 506
             av_free(curr);
507
+            fpc->nb_headers_buffered--;
507 508
         }
508 509
         /* Release returned data from ring buffer. */
509 510
         av_fifo_drain(fpc->fifo_buf, best_child->offset);
... ...
@@ -512,8 +514,13 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
512 512
         for (curr = best_child->next; curr; curr = curr->next)
513 513
             curr->offset -= best_child->offset;
514 514
 
515
+        fpc->nb_headers_buffered--;
515 516
         best_child->offset = 0;
516 517
         fpc->headers       = best_child;
518
+        if (fpc->nb_headers_buffered >= FLAC_MIN_HEADERS) {
519
+            fpc->best_header = best_child;
520
+            return get_best_header(fpc, poutbuf, poutbuf_size);
521
+        }
517 522
         fpc->best_header   = NULL;
518 523
     } else if (fpc->best_header) {
519 524
         /* No end frame no need to delete the buffer; probably eof */
... ...
@@ -562,8 +569,15 @@ static int flac_parse(AVCodecParserContext *s, AVCodecContext *avctx,
562 562
         start_offset = FFMAX(0, start_offset);
563 563
         nb_headers   = find_new_headers(fpc, start_offset);
564 564
 
565
+        if (nb_headers < 0) {
566
+            av_log(avctx, AV_LOG_ERROR,
567
+                   "find_new_headers couldn't allocate FLAC header\n");
568
+            goto handle_error;
569
+        }
570
+
571
+        fpc->nb_headers_buffered = nb_headers;
565 572
         /* Wait till FLAC_MIN_HEADERS to output a valid frame. */
566
-        if (!fpc->end_padded && nb_headers < FLAC_MIN_HEADERS)
573
+        if (!fpc->end_padded && fpc->nb_headers_buffered < FLAC_MIN_HEADERS)
567 574
             goto handle_error;
568 575
 
569 576
         /* If headers found, update the scores since we have longer chains. */