]> git.sesse.net Git - ffmpeg/commitdiff
ac3_parser: add a public function for parsing the data required by the demuxer
authorAnton Khirnov <anton@khirnov.net>
Thu, 30 Mar 2017 14:56:28 +0000 (16:56 +0200)
committerDiego Biurrun <diego@biurrun.de>
Wed, 12 Apr 2017 13:39:00 +0000 (15:39 +0200)
Make the current semi-public avpriv_ac3_parse_header() private to lavc.

Signed-off-by: Diego Biurrun <diego@biurrun.de>
libavcodec/Makefile
libavcodec/ac3_parser.c
libavcodec/ac3_parser.h
libavcodec/ac3_parser_internal.h [new file with mode: 0644]
libavcodec/ac3dec.c
libavcodec/eac3dec.c
libavformat/ac3dec.c

index ec62f514a77db582f7e95b6a47d44b33dcab8e2b..a82210d89fe51ffdb6a51c94372a74676855cbd7 100644 (file)
@@ -1,7 +1,8 @@
 NAME = avcodec
 DESC = Libav codec library
 
-HEADERS = avcodec.h                                                     \
+HEADERS = ac3_parser.h                                                  \
+          avcodec.h                                                     \
           avfft.h                                                       \
           d3d11va.h                                                     \
           dirac.h                                                       \
@@ -14,7 +15,8 @@ HEADERS = avcodec.h                                                     \
           version.h                                                     \
           vorbis_parser.h                                               \
 
-OBJS = allcodecs.o                                                      \
+OBJS = ac3_parser.o                                                     \
+       allcodecs.o                                                      \
        avpacket.o                                                       \
        avpicture.o                                                      \
        bitstream.o                                                      \
@@ -719,8 +721,7 @@ OBJS-$(CONFIG_LIBXVID_ENCODER)            += libxvid.o
 OBJS-$(CONFIG_AAC_LATM_PARSER)         += latm_parser.o
 OBJS-$(CONFIG_AAC_PARSER)              += aac_parser.o aac_ac3_parser.o \
                                           aacadtsdec.o mpeg4audio.o
-OBJS-$(CONFIG_AC3_PARSER)              += ac3_parser.o ac3tab.o \
-                                          aac_ac3_parser.o
+OBJS-$(CONFIG_AC3_PARSER)              += ac3tab.o aac_ac3_parser.o
 OBJS-$(CONFIG_ADX_PARSER)              += adx_parser.o adx.o
 OBJS-$(CONFIG_BMP_PARSER)              += bmp_parser.o
 OBJS-$(CONFIG_CAVSVIDEO_PARSER)        += cavs_parser.o
index 970484810b4cc03e6f37e20535a35124850386a1..53189e0d4ed793464ff01d0f6bd7d2c96542365b 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "config.h"
+
 #include "libavutil/channel_layout.h"
 #include "parser.h"
 #include "ac3_parser.h"
+#include "ac3_parser_internal.h"
 #include "aac_ac3_parser.h"
 #include "get_bits.h"
 
 
 #define AC3_HEADER_SIZE 7
 
+#if CONFIG_AC3_PARSER
 
 static const uint8_t eac3_blocks[4] = {
     1, 2, 3, 6
@@ -47,7 +51,7 @@ static const uint8_t center_levels[4] = { 4, 5, 6, 5 };
 static const uint8_t surround_levels[4] = { 4, 6, 7, 6 };
 
 
-int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
+int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
 {
     int frame_size_code;
 
@@ -144,6 +148,24 @@ int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
     return 0;
 }
 
+int av_ac3_parse_header(const uint8_t *buf, size_t size,
+                        uint8_t *bitstream_id, uint16_t *frame_size)
+{
+    GetBitContext gb;
+    AC3HeaderInfo hdr;
+    int err;
+
+    init_get_bits8(&gb, buf, size);
+    err = ff_ac3_parse_header(&gb, &hdr);
+    if (err < 0)
+        return AVERROR_INVALIDDATA;
+
+    *bitstream_id = hdr.bitstream_id;
+    *frame_size   = hdr.frame_size;
+
+    return 0;
+}
+
 static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info,
         int *need_next_header, int *new_frame_start)
 {
@@ -156,7 +178,7 @@ static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info,
     GetBitContext gbc;
 
     init_get_bits(&gbc, tmp.u8+8-AC3_HEADER_SIZE, 54);
-    err = avpriv_ac3_parse_header(&gbc, &hdr);
+    err = ff_ac3_parse_header(&gbc, &hdr);
 
     if(err < 0)
         return 0;
@@ -195,3 +217,12 @@ AVCodecParser ff_ac3_parser = {
     .parser_parse   = ff_aac_ac3_parse,
     .parser_close   = ff_parse_close,
 };
+
+#else
+
+int av_ac3_parse_header(const uint8_t *buf, size_t size,
+                        uint8_t *bitstream_id, uint16_t *frame_size)
+{
+    return AVERROR(ENOSYS);
+}
+#endif
index 9322550ea5f15f1bbeed6f44ad6ef02b4fb59067..f78c461041a50accadbee9b932be3acb71ff2954 100644 (file)
 #ifndef AVCODEC_AC3_PARSER_H
 #define AVCODEC_AC3_PARSER_H
 
-#include "ac3.h"
-#include "get_bits.h"
+#include <stddef.h>
+#include <stdint.h>
 
 /**
- * Parse AC-3 frame header.
- * Parse the header up to the lfeon element, which is the first 52 or 54 bits
- * depending on the audio coding mode.
- * @param[in]  gbc BitContext containing the first 54 bits of the frame.
- * @param[out] hdr Pointer to struct where header info is written.
- * @return Returns 0 on success, -1 if there is a sync word mismatch,
- * -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate)
- * element is invalid, or -4 if the frmsizecod (bit rate) element is invalid.
+ * Extract the bitstream ID and the frame size from AC-3 data.
  */
-int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr);
+int av_ac3_parse_header(const uint8_t *buf, size_t size,
+                        uint8_t *bitstream_id, uint16_t *frame_size);
+
 
 #endif /* AVCODEC_AC3_PARSER_H */
diff --git a/libavcodec/ac3_parser_internal.h b/libavcodec/ac3_parser_internal.h
new file mode 100644 (file)
index 0000000..5e305e8
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * AC-3 parser internal code
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_AC3_PARSER_INTERNAL_H
+#define AVCODEC_AC3_PARSER_INTERNAL_H
+
+#include "ac3.h"
+#include "get_bits.h"
+
+/**
+ * Parse AC-3 frame header.
+ * Parse the header up to the lfeon element, which is the first 52 or 54 bits
+ * depending on the audio coding mode.
+ * @param[in]  gbc BitContext containing the first 54 bits of the frame.
+ * @param[out] hdr Pointer to struct where header info is written.
+ * @return Returns 0 on success, -1 if there is a sync word mismatch,
+ * -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate)
+ * element is invalid, or -4 if the frmsizecod (bit rate) element is invalid.
+ */
+int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr);
+
+#endif /* AVCODEC_AC3_PARSER_INTERNAL_H */
index ad50552ec1b097c1fd6d305f57bd713fbb1bd492..4be0f1f4117b48cf69e9b7854cfc31dd8c6c220e 100644 (file)
@@ -36,7 +36,7 @@
 #include "bswapdsp.h"
 #include "internal.h"
 #include "aac_ac3_parser.h"
-#include "ac3_parser.h"
+#include "ac3_parser_internal.h"
 #include "ac3dec.h"
 #include "ac3dec_data.h"
 #include "kbdwin.h"
@@ -270,7 +270,7 @@ static int parse_frame_header(AC3DecodeContext *s)
     AC3HeaderInfo hdr;
     int err;
 
-    err = avpriv_ac3_parse_header(&s->gbc, &hdr);
+    err = ff_ac3_parse_header(&s->gbc, &hdr);
     if (err)
         return err;
 
index fe52d27123667926b5bf30224d499474aa77f8cb..89db7d38bca10d176eb598e38420552e14da59bf 100644 (file)
@@ -48,7 +48,6 @@
 #include "internal.h"
 #include "aac_ac3_parser.h"
 #include "ac3.h"
-#include "ac3_parser.h"
 #include "ac3dec.h"
 #include "ac3dec_data.h"
 #include "eac3_data.h"
index 4ceffa54ddbf8806a8cd1ec0a64d655e2a8f9550..7a868056c70b7e7ac22c696b3bffc5d13fac8922 100644 (file)
@@ -28,8 +28,6 @@ static int ac3_eac3_probe(AVProbeData *p, enum AVCodecID expected_codec_id)
 {
     int max_frames, first_frames = 0, frames;
     uint8_t *buf, *buf2, *end;
-    AC3HeaderInfo hdr;
-    GetBitContext gbc;
     enum AVCodecID codec_id = AV_CODEC_ID_AC3;
 
     max_frames = 0;
@@ -40,15 +38,20 @@ static int ac3_eac3_probe(AVProbeData *p, enum AVCodecID expected_codec_id)
         buf2 = buf;
 
         for(frames = 0; buf2 < end; frames++) {
-            init_get_bits(&gbc, buf2, 54);
-            if(avpriv_ac3_parse_header(&gbc, &hdr) < 0)
+            uint8_t bitstream_id;
+            uint16_t frame_size;
+            int ret;
+
+            ret = av_ac3_parse_header(buf2, end - buf2, &bitstream_id,
+                                      &frame_size);
+            if (ret < 0)
                 break;
-            if(buf2 + hdr.frame_size > end ||
-               av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2))
+            if (buf2 + frame_size > end ||
+                av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, frame_size - 2))
                 break;
-            if (hdr.bitstream_id > 10)
+            if (bitstream_id > 10)
                 codec_id = AV_CODEC_ID_EAC3;
-            buf2 += hdr.frame_size;
+            buf2 += frame_size;
         }
         max_frames = FFMAX(max_frames, frames);
         if(buf == p->buf)