changeset 6527:32b984487899 libavcodec

Pass AACAC3ParseContext to sync() instead of individual arguments. Patch by Bartlomiej Wolowiec (bartek wolowiec gmail com)
author jbr
date Sun, 23 Mar 2008 15:43:29 +0000
parents 737b74bec1e5
children 28d0e7dac45d
files aac_ac3_parser.c aac_ac3_parser.h aac_parser.c ac3_parser.c
diffstat 4 files changed, 25 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/aac_ac3_parser.c	Sat Mar 22 17:34:29 2008 +0000
+++ b/aac_ac3_parser.c	Sun Mar 23 15:43:29 2008 +0000
@@ -30,7 +30,7 @@
 {
     AACAC3ParseContext *s = s1->priv_data;
     const uint8_t *buf_ptr;
-    int len, sample_rate, bit_rate, channels, samples;
+    int len;
 
     *poutbuf = NULL;
     *poutbuf_size = 0;
@@ -50,8 +50,7 @@
 
         if (s->frame_size == 0) {
             if ((s->inbuf_ptr - s->inbuf) == s->header_size) {
-                len = s->sync(s->inbuf, &channels, &sample_rate, &bit_rate,
-                              &samples);
+                len = s->sync(s);
                 if (len == 0) {
                     /* no sync found : move by one byte (inefficient, but simple!) */
                     memmove(s->inbuf, s->inbuf + 1, s->header_size - 1);
@@ -59,19 +58,19 @@
                 } else {
                     s->frame_size = len;
                     /* update codec info */
-                    avctx->sample_rate = sample_rate;
+                    avctx->sample_rate = s->sample_rate;
                     /* allow downmixing to stereo (or mono for AC3) */
                     if(avctx->request_channels > 0 &&
-                            avctx->request_channels < channels &&
+                            avctx->request_channels < s->channels &&
                             (avctx->request_channels <= 2 ||
                             (avctx->request_channels == 1 &&
                             avctx->codec_id == CODEC_ID_AC3))) {
                         avctx->channels = avctx->request_channels;
                     } else {
-                        avctx->channels = channels;
+                        avctx->channels = s->channels;
                     }
-                    avctx->bit_rate = bit_rate;
-                    avctx->frame_size = samples;
+                    avctx->bit_rate = s->bit_rate;
+                    avctx->frame_size = s->samples;
                 }
             }
         } else {
--- a/aac_ac3_parser.h	Sat Mar 22 17:34:29 2008 +0000
+++ b/aac_ac3_parser.h	Sun Mar 23 15:43:29 2008 +0000
@@ -30,9 +30,13 @@
     uint8_t *inbuf_ptr;
     int frame_size;
     int header_size;
-    int (*sync)(const uint8_t *buf, int *channels, int *sample_rate,
-                int *bit_rate, int *samples);
+    int (*sync)(struct AACAC3ParseContext *hdr_info);
     uint8_t inbuf[8192]; /* input buffer */
+
+    int channels;
+    int sample_rate;
+    int bit_rate;
+    int samples;
 } AACAC3ParseContext;
 
 int ff_aac_ac3_parse(AVCodecParserContext *s1,
--- a/aac_parser.c	Sat Mar 22 17:34:29 2008 +0000
+++ b/aac_parser.c	Sun Mar 23 15:43:29 2008 +0000
@@ -38,13 +38,12 @@
 };
 
 
-static int aac_sync(const uint8_t *buf, int *channels, int *sample_rate,
-                    int *bit_rate, int *samples)
+static int aac_sync(AACAC3ParseContext *hdr_info)
 {
     GetBitContext bits;
     int size, rdb, ch, sr;
 
-    init_get_bits(&bits, buf, AAC_HEADER_SIZE * 8);
+    init_get_bits(&bits, hdr_info->inbuf, AAC_HEADER_SIZE * 8);
 
     if(get_bits(&bits, 12) != 0xfff)
         return 0;
@@ -73,10 +72,10 @@
     skip_bits(&bits, 11);       /* adts_buffer_fullness */
     rdb = get_bits(&bits, 2);   /* number_of_raw_data_blocks_in_frame */
 
-    *channels = aac_channels[ch];
-    *sample_rate = aac_sample_rates[sr];
-    *samples = (rdb + 1) * 1024;
-    *bit_rate = size * 8 * *sample_rate / *samples;
+    hdr_info->channels = aac_channels[ch];
+    hdr_info->sample_rate = aac_sample_rates[sr];
+    hdr_info->samples = (rdb + 1) * 1024;
+    hdr_info->bit_rate = size * 8 * hdr_info->sample_rate / hdr_info->samples;
 
     return size;
 }
--- a/ac3_parser.c	Sat Mar 22 17:34:29 2008 +0000
+++ b/ac3_parser.c	Sun Mar 23 15:43:29 2008 +0000
@@ -119,21 +119,20 @@
     return 0;
 }
 
-static int ac3_sync(const uint8_t *buf, int *channels, int *sample_rate,
-                    int *bit_rate, int *samples)
+static int ac3_sync(AACAC3ParseContext *hdr_info)
 {
     int err;
     AC3HeaderInfo hdr;
 
-    err = ff_ac3_parse_header(buf, &hdr);
+    err = ff_ac3_parse_header(hdr_info->inbuf, &hdr);
 
     if(err < 0)
         return 0;
 
-    *sample_rate = hdr.sample_rate;
-    *bit_rate = hdr.bit_rate;
-    *channels = hdr.channels;
-    *samples = AC3_FRAME_SIZE;
+    hdr_info->sample_rate = hdr.sample_rate;
+    hdr_info->bit_rate = hdr.bit_rate;
+    hdr_info->channels = hdr.channels;
+    hdr_info->samples = AC3_FRAME_SIZE;
     return hdr.frame_size;
 }