summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2017-03-30 16:56:28 +0200
committerDiego Biurrun <diego@biurrun.de>2017-04-12 15:39:00 +0200
commit50a1c66cf6ab7eb683daaa9e2da3869fa3a54609 (patch)
tree4c967343ff0b2f0e6d61eb22b8782138c937bf8f
parent193b09189004ede4a6998e69192d1a9f63602088 (diff)
downloadffmpeg-streaming-50a1c66cf6ab7eb683daaa9e2da3869fa3a54609.zip
ffmpeg-streaming-50a1c66cf6ab7eb683daaa9e2da3869fa3a54609.tar.gz
ac3_parser: add a public function for parsing the data required by the demuxer
Make the current semi-public avpriv_ac3_parse_header() private to lavc. Signed-off-by: Diego Biurrun <diego@biurrun.de>
-rw-r--r--libavcodec/Makefile9
-rw-r--r--libavcodec/ac3_parser.c35
-rw-r--r--libavcodec/ac3_parser.h17
-rw-r--r--libavcodec/ac3_parser_internal.h39
-rw-r--r--libavcodec/ac3dec.c4
-rw-r--r--libavcodec/eac3dec.c1
-rw-r--r--libavformat/ac3dec.c19
7 files changed, 96 insertions, 28 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index ec62f51..a82210d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -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
diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 9704848..53189e0 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -20,15 +20,19 @@
* 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
diff --git a/libavcodec/ac3_parser.h b/libavcodec/ac3_parser.h
index 9322550..f78c461 100644
--- a/libavcodec/ac3_parser.h
+++ b/libavcodec/ac3_parser.h
@@ -23,19 +23,14 @@
#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
index 0000000..5e305e8
--- /dev/null
+++ b/libavcodec/ac3_parser_internal.h
@@ -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 */
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index ad50552..4be0f1f 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -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;
diff --git a/libavcodec/eac3dec.c b/libavcodec/eac3dec.c
index fe52d27..89db7d3 100644
--- a/libavcodec/eac3dec.c
+++ b/libavcodec/eac3dec.c
@@ -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"
diff --git a/libavformat/ac3dec.c b/libavformat/ac3dec.c
index 4ceffa5..7a86805 100644
--- a/libavformat/ac3dec.c
+++ b/libavformat/ac3dec.c
@@ -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)
OpenPOWER on IntegriCloud