This is last part of patch written earlier:

> Here is my idea of changing ac3 parser, so that it will send in one package 
> to decoder all frames concerning one part of time.
> It works like that: it buffers all frames until next independent frame.
> The problem is that the last frame never leaves the buffer. Any ideas how to
> solve it?


-- 
Bartlomiej Wolowiec
Index: libavcodec/aac_ac3_parser.c
===================================================================
--- libavcodec/aac_ac3_parser.c	(wersja 12599)
+++ libavcodec/aac_ac3_parser.c	(kopia robocza)
@@ -23,6 +23,7 @@
 #include "parser.h"
 #include "aac_ac3_parser.h"
 
+// TODO check s->inbuf_tab size
 int ff_aac_ac3_parse(AVCodecParserContext *s1,
                      AVCodecContext *avctx,
                      const uint8_t **poutbuf, int *poutbuf_size,
@@ -36,6 +37,13 @@
     *poutbuf_size = 0;
 
     buf_ptr = buf;
+
+    if(s->inbuf_ptr < s->inbuf) {
+        //after sending package of data in the end there was one new header
+        memcpy(s->inbuf_tab, s->inbuf, s->header_size);
+        s->inbuf = s->inbuf_tab;
+        s->inbuf_ptr = s->inbuf_tab + s->header_size;
+    }
     while (buf_size > 0) {
         int size_needed= s->frame_size ? s->frame_size : s->header_size;
         len = s->inbuf_ptr - s->inbuf;
@@ -56,7 +64,14 @@
                     memmove(s->inbuf, s->inbuf + 1, s->header_size - 1);
                     s->inbuf_ptr--;
                 } else {
-                    s->frame_size = len;
+                    if(!s->stream_type) {
+                        if(s->inbuf != s->inbuf_tab) {
+                            *poutbuf = s->inbuf_tab;
+                            *poutbuf_size = s->inbuf - s->inbuf_tab;
+                            s->inbuf_ptr = s->inbuf_tab;
+                            s->frame_size = 0;
+                            break;
+                        }
                     /* update codec info */
                     avctx->sample_rate = s->sample_rate;
                     /* allow downmixing to stereo (or mono for AC3) */
@@ -71,15 +86,18 @@
                     }
                     avctx->bit_rate = s->bit_rate;
                     avctx->frame_size = s->samples;
+                    } else {
+                        //TODO update bit_rate
+                        avctx->frame_size += s->samples;
+                    }
+                    s->frame_size = len;
                 }
             }
         } else {
             if(s->inbuf_ptr - s->inbuf == s->frame_size){
-                *poutbuf = s->inbuf;
-                *poutbuf_size = s->frame_size;
+                s->inbuf += s->frame_size;
                 s->inbuf_ptr = s->inbuf;
                 s->frame_size = 0;
-                break;
             }
         }
     }
Index: libavcodec/aac_ac3_parser.h
===================================================================
--- libavcodec/aac_ac3_parser.h	(wersja 12599)
+++ libavcodec/aac_ac3_parser.h	(kopia robocza)
@@ -28,10 +28,11 @@
 
 typedef struct AACAC3ParseContext {
     uint8_t *inbuf_ptr;
+    uint8_t *inbuf;
     int frame_size;
     int header_size;
     int (*sync)(struct AACAC3ParseContext *hdr_info);
-    uint8_t inbuf[8192]; /* input buffer */
+    uint8_t inbuf_tab[8192]; /* input buffer */
 
     int channels;
     int sample_rate;
Index: libavcodec/aac_parser.c
===================================================================
--- libavcodec/aac_parser.c	(wersja 12599)
+++ libavcodec/aac_parser.c	(kopia robocza)
@@ -85,6 +85,7 @@
 {
     AACAC3ParseContext *s = s1->priv_data;
     s->stream_type = EAC3_STREAM_TYPE_INDEPENDENT;
+    s->inbuf = s->inbuf_tab;
     s->inbuf_ptr = s->inbuf;
     s->header_size = AAC_HEADER_SIZE;
     s->sync = aac_sync;
Index: libavcodec/ac3_parser.c
===================================================================
--- libavcodec/ac3_parser.c	(wersja 12599)
+++ libavcodec/ac3_parser.c	(kopia robocza)
@@ -137,12 +137,14 @@
     hdr_info->bit_rate = hdr.bit_rate;
     hdr_info->channels = hdr.channels;
     hdr_info->samples = AC3_FRAME_SIZE;
+    hdr_info->stream_type = hdr.stream_type;
     return hdr.frame_size;
 }
 
 static av_cold int ac3_parse_init(AVCodecParserContext *s1)
 {
     AACAC3ParseContext *s = s1->priv_data;
+    s->inbuf = s->inbuf_tab;
     s->inbuf_ptr = s->inbuf;
     s->header_size = AC3_HEADER_SIZE;
     s->sync = ac3_sync;
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc

Reply via email to