mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-08 13:22:53 +02:00
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>
This commit is contained in:
parent
193b091890
commit
50a1c66cf6
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
39
libavcodec/ac3_parser_internal.h
Normal file
39
libavcodec/ac3_parser_internal.h
Normal file
@ -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 */
|
@ -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;
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user