Merge commit 'b5f19f7478492307e4b4763aeac3180faf50e17f'

* commit 'b5f19f7478492307e4b4763aeac3180faf50e17f':
  aac: Split function to parse ADTS header data into public and private part

Merged-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer 2017-10-30 18:56:45 -03:00
commit b9d3def9b2
14 changed files with 141 additions and 52 deletions

8
configure vendored
View File

@ -2135,6 +2135,7 @@ HAVE_LIST="
CONFIG_EXTRA="
aandcttables
ac3dsp
adts_header
audio_frame_queue
audiodsp
blockdsp
@ -2421,7 +2422,7 @@ vc1dsp_select="h264chroma qpeldsp startcode"
rdft_select="fft"
# decoders / encoders
aac_decoder_select="mdct15 mdct sinewin"
aac_decoder_select="adts_header mdct15 mdct sinewin"
aac_fixed_decoder_select="mdct sinewin"
aac_encoder_select="audio_frame_queue iirfilter lpc mdct sinewin"
aac_latm_decoder_select="aac_decoder aac_latm_parser"
@ -2873,6 +2874,7 @@ vp9_v4l2m2m_decoder_deps="v4l2_m2m vp9_v4l2_m2m"
wmv3_crystalhd_decoder_select="crystalhd"
# parsers
aac_parser_select="adts_header"
h264_parser_select="golomb h264dsp h264parse"
hevc_parser_select="hevcparse"
mpegaudio_parser_select="mpegaudioheader"
@ -2881,6 +2883,7 @@ mpeg4video_parser_select="h263dsp mpegvideo qpeldsp"
vc1_parser_select="vc1dsp"
# bitstream_filters
aac_adtstoasc_bsf_select="adts_header"
h264_metadata_bsf_select="cbs_h264"
h264_redundant_pps_bsf_select="cbs_h264"
hevc_metadata_bsf_select="cbs_h265"
@ -3047,7 +3050,8 @@ sap_demuxer_select="sdp_demuxer"
sap_muxer_select="rtp_muxer rtp_protocol rtpenc_chain"
sdp_demuxer_select="rtpdec"
smoothstreaming_muxer_select="ismv_muxer"
spdif_muxer_select="aac_parser"
spdif_demuxer_select="adts_header"
spdif_muxer_select="adts_header"
spx_muxer_select="ogg_muxer"
swf_demuxer_suggest="zlib"
tak_demuxer_select="tak_parser"

View File

@ -184,7 +184,7 @@ e.g. @samp{ff_w64_demuxer}.
@item
For variables and functions visible outside of file scope, used internally
across multiple libraries, use @code{avpriv_} as prefix, for example,
@samp{avpriv_aac_parse_header}.
@samp{avpriv_report_missing_feature}.
@item
Each library has its own prefix for public symbols, in addition to the

View File

@ -2,6 +2,7 @@ NAME = avcodec
DESC = FFmpeg codec library
HEADERS = ac3_parser.h \
adts_parser.h \
avcodec.h \
avdct.h \
avfft.h \
@ -20,6 +21,7 @@ HEADERS = ac3_parser.h \
xvmc.h \
OBJS = ac3_parser.o \
adts_parser.o \
allcodecs.o \
avdct.o \
avpacket.o \
@ -52,6 +54,7 @@ OBJS = ac3_parser.o \
# subsystems
OBJS-$(CONFIG_AANDCTTABLES) += aandcttab.o
OBJS-$(CONFIG_AC3DSP) += ac3dsp.o ac3.o ac3tab.o
OBJS-$(CONFIG_ADTS_HEADER) += adts_header.o mpeg4audio.o
OBJS-$(CONFIG_AUDIO_FRAME_QUEUE) += audio_frame_queue.o
OBJS-$(CONFIG_AUDIODSP) += audiodsp.o
OBJS-$(CONFIG_BLOCKDSP) += blockdsp.o
@ -148,10 +151,10 @@ OBJS-$(CONFIG_ZERO12V_DECODER) += 012v.o
OBJS-$(CONFIG_A64MULTI_ENCODER) += a64multienc.o elbg.o
OBJS-$(CONFIG_A64MULTI5_ENCODER) += a64multienc.o elbg.o
OBJS-$(CONFIG_AAC_DECODER) += aacdec.o aactab.o aacsbr.o aacps_float.o \
aacadtsdec.o mpeg4audio.o kbdwin.o \
mpeg4audio.o kbdwin.o \
sbrdsp.o aacpsdsp_float.o cbrt_data.o
OBJS-$(CONFIG_AAC_FIXED_DECODER) += aacdec_fixed.o aactab.o aacsbr_fixed.o aacps_fixed.o \
aacadtsdec.o mpeg4audio.o kbdwin.o \
mpeg4audio.o kbdwin.o \
sbrdsp_fixed.o aacpsdsp_fixed.o cbrt_data_fixed.o
OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o aaccoder.o aacenctab.o \
aacpsy.o aactab.o \
@ -880,7 +883,6 @@ OBJS-$(CONFIG_MXF_MUXER) += dnxhddata.o
OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o
OBJS-$(CONFIG_NUT_DEMUXER) += mpegaudiodata.o mpeg4audio.o
OBJS-$(CONFIG_RTP_MUXER) += mpeg4audio.o
OBJS-$(CONFIG_SPDIF_DEMUXER) += aacadtsdec.o mpeg4audio.o
OBJS-$(CONFIG_SPDIF_MUXER) += dca.o
OBJS-$(CONFIG_TAK_DEMUXER) += tak.o
OBJS-$(CONFIG_WEBM_MUXER) += mpeg4audio.o
@ -957,7 +959,7 @@ OBJS-$(CONFIG_LIBZVBI_TELETEXT_DECODER) += libzvbi-teletextdec.o ass.o
# parsers
OBJS-$(CONFIG_AAC_LATM_PARSER) += latm_parser.o
OBJS-$(CONFIG_AAC_PARSER) += aac_parser.o aac_ac3_parser.o \
aacadtsdec.o mpeg4audio.o
mpeg4audio.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
@ -1003,8 +1005,7 @@ OBJS-$(CONFIG_VP9_PARSER) += vp9_parser.o
OBJS-$(CONFIG_XMA_PARSER) += xma_parser.o
# bitstream filters
OBJS-$(CONFIG_AAC_ADTSTOASC_BSF) += aac_adtstoasc_bsf.o aacadtsdec.o \
mpeg4audio.o
OBJS-$(CONFIG_AAC_ADTSTOASC_BSF) += aac_adtstoasc_bsf.o mpeg4audio.o
OBJS-$(CONFIG_CHOMP_BSF) += chomp_bsf.o
OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o
OBJS-$(CONFIG_DCA_CORE_BSF) += dca_core_bsf.o

View File

@ -19,8 +19,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "adts_header.h"
#include "adts_parser.h"
#include "avcodec.h"
#include "aacadtsdec.h"
#include "bsf.h"
#include "put_bits.h"
#include "get_bits.h"
@ -52,12 +53,12 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out)
if (bsfc->par_in->extradata && in->size >= 2 && (AV_RB16(in->data) >> 4) != 0xfff)
goto finish;
if (in->size < AAC_ADTS_HEADER_SIZE)
if (in->size < AV_AAC_ADTS_HEADER_SIZE)
goto packet_too_small;
init_get_bits(&gb, in->data, AAC_ADTS_HEADER_SIZE * 8);
init_get_bits(&gb, in->data, AV_AAC_ADTS_HEADER_SIZE * 8);
if (avpriv_aac_parse_header(&gb, &hdr) < 0) {
if (ff_adts_header_parse(&gb, &hdr) < 0) {
av_log(bsfc, AV_LOG_ERROR, "Error parsing ADTS frame header!\n");
ret = AVERROR_INVALIDDATA;
goto fail;
@ -70,10 +71,10 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out)
goto fail;
}
in->size -= AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;
in->size -= AV_AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;
if (in->size <= 0)
goto packet_too_small;
in->data += AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;
in->data += AV_AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;
if (!ctx->first_frame_done) {
int pce_size = 0;

View File

@ -22,7 +22,8 @@
#include "parser.h"
#include "aac_ac3_parser.h"
#include "aacadtsdec.h"
#include "adts_header.h"
#include "adts_parser.h"
#include "get_bits.h"
#include "mpeg4audio.h"
@ -38,9 +39,10 @@ static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info,
} tmp;
tmp.u64 = av_be2ne64(state);
init_get_bits(&bits, tmp.u8+8-AAC_ADTS_HEADER_SIZE, AAC_ADTS_HEADER_SIZE * 8);
init_get_bits(&bits, tmp.u8 + 8 - AV_AAC_ADTS_HEADER_SIZE,
AV_AAC_ADTS_HEADER_SIZE * 8);
if ((size = avpriv_aac_parse_header(&bits, &hdr)) < 0)
if ((size = ff_adts_header_parse(&bits, &hdr)) < 0)
return 0;
*need_next_header = 0;
*new_frame_start = 1;
@ -54,7 +56,7 @@ static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info,
static av_cold int aac_parse_init(AVCodecParserContext *s1)
{
AACAC3ParseContext *s = s1->priv_data;
s->header_size = AAC_ADTS_HEADER_SIZE;
s->header_size = AV_AAC_ADTS_HEADER_SIZE;
s->sync = aac_sync;
return 0;
}

View File

@ -50,11 +50,11 @@
#include "aac.h"
#include "aactab.h"
#include "aacdectab.h"
#include "adts_header.h"
#include "cbrt_data.h"
#include "sbr.h"
#include "aacsbr.h"
#include "mpeg4audio.h"
#include "aacadtsdec.h"
#include "profiles.h"
#include "libavutil/intfloat.h"

View File

@ -75,11 +75,11 @@
#include "aac.h"
#include "aactab.h"
#include "aacdectab.h"
#include "adts_header.h"
#include "cbrt_data.h"
#include "sbr.h"
#include "aacsbr.h"
#include "mpeg4audio.h"
#include "aacadtsdec.h"
#include "profiles.h"
#include "libavutil/intfloat.h"

View File

@ -2955,7 +2955,7 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb)
uint8_t layout_map[MAX_ELEM_ID*4][3];
int layout_map_tags, ret;
size = avpriv_aac_parse_header(gb, &hdr_info);
size = ff_adts_header_parse(gb, &hdr_info);
if (size > 0) {
if (!ac->warned_num_aac_frames && hdr_info.num_aac_frames != 1) {
// This is 2 for "VLB " audio in NSV files.

View File

@ -22,11 +22,12 @@
*/
#include "aac_ac3_parser.h"
#include "aacadtsdec.h"
#include "adts_header.h"
#include "adts_parser.h"
#include "get_bits.h"
#include "mpeg4audio.h"
int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
{
int size, rdb, ch, sr;
int aot, crc_abs;
@ -51,7 +52,7 @@ int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
skip_bits1(gbc); /* copyright_identification_bit */
skip_bits1(gbc); /* copyright_identification_start */
size = get_bits(gbc, 13); /* aac_frame_length */
if (size < AAC_ADTS_HEADER_SIZE)
if (size < AV_AAC_ADTS_HEADER_SIZE)
return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
skip_bits(gbc, 11); /* adts_buffer_fullness */

View File

@ -20,14 +20,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_AACADTSDEC_H
#define AVCODEC_AACADTSDEC_H
#ifndef AVCODEC_ADTS_HEADER_H
#define AVCODEC_ADTS_HEADER_H
#include <stdint.h>
#include "get_bits.h"
#define AAC_ADTS_HEADER_SIZE 7
typedef struct AACADTSHeaderInfo {
uint32_t sample_rate;
uint32_t samples;
@ -40,7 +37,6 @@ typedef struct AACADTSHeaderInfo {
} AACADTSHeaderInfo;
/**
* Parse AAC frame header.
* Parse the ADTS frame header to the end of the variable header, which is
* the first 54 bits.
* @param[in] gbc BitContext containing the first 54 bits of the frame.
@ -49,6 +45,6 @@ typedef struct AACADTSHeaderInfo {
* -2 if the version element is invalid, -3 if the sample rate
* element is invalid, or -4 if the bit rate element is invalid.
*/
int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr);
int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr);
#endif /* AVCODEC_AACADTSDEC_H */
#endif /* AVCODEC_ADTS_HEADER_H */

44
libavcodec/adts_parser.c Normal file
View File

@ -0,0 +1,44 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "config.h"
#include <stddef.h>
#include <stdint.h>
#include "adts_header.h"
#include "adts_parser.h"
int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames)
{
#if CONFIG_ADTS_HEADER
GetBitContext gb;
AACADTSHeaderInfo hdr;
int err = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE);
if (err < 0)
return err;
err = ff_adts_header_parse(&gb, &hdr);
if (err < 0)
return err;
*samples = hdr.samples;
*frames = hdr.num_aac_frames;
return 0;
#else
return AVERROR(ENOSYS);
#endif
}

37
libavcodec/adts_parser.h Normal file
View File

@ -0,0 +1,37 @@
/*
* This file is part of FFmpeg.
*
* FFmpeg 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.
*
* FFmpeg 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 FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_ADTS_PARSER_H
#define AVCODEC_ADTS_PARSER_H
#include <stddef.h>
#include <stdint.h>
#define AV_AAC_ADTS_HEADER_SIZE 7
/**
* Extract the number of samples and frames from AAC data.
* @param[in] buf pointer to AAC data buffer
* @param[out] samples Pointer to where number of samples is written
* @param[out] frames Pointer to where number of frames is written
* @return Returns 0 on success, error code on failure.
*/
int av_adts_header_parse(const uint8_t *buf, uint32_t *samples,
uint8_t *frames);
#endif /* AVCODEC_ADTS_PARSER_H */

View File

@ -25,18 +25,22 @@
* @author Anssi Hannula
*/
#include "libavutil/bswap.h"
#include "libavcodec/ac3.h"
#include "libavcodec/adts_parser.h"
#include "avformat.h"
#include "spdif.h"
#include "libavcodec/ac3.h"
#include "libavcodec/aacadtsdec.h"
static int spdif_get_offset_and_codec(AVFormatContext *s,
enum IEC61937DataType data_type,
const char *buf, int *offset,
enum AVCodecID *codec)
{
AACADTSHeaderInfo aac_hdr;
GetBitContext gbc;
uint32_t samples;
uint8_t frames;
int ret;
switch (data_type & 0xff) {
case IEC61937_AC3:
@ -56,13 +60,13 @@ static int spdif_get_offset_and_codec(AVFormatContext *s,
*codec = AV_CODEC_ID_MP3;
break;
case IEC61937_MPEG2_AAC:
init_get_bits(&gbc, buf, AAC_ADTS_HEADER_SIZE * 8);
if (avpriv_aac_parse_header(&gbc, &aac_hdr) < 0) {
ret = av_adts_header_parse(buf, &samples, &frames);
if (ret < 0) {
if (s) /* be silent during a probe */
av_log(s, AV_LOG_ERROR, "Invalid AAC packet in IEC 61937\n");
return AVERROR_INVALIDDATA;
return ret;
}
*offset = aac_hdr.samples << 2;
*offset = samples << 2;
*codec = AV_CODEC_ID_AAC;
break;
case IEC61937_MPEG2_LAYER1_LSF:
@ -100,7 +104,7 @@ static int spdif_get_offset_and_codec(AVFormatContext *s,
}
/* Largest offset between bursts we currently handle, i.e. AAC with
aac_hdr.samples = 4096 */
samples = 4096 */
#define SPDIF_MAX_OFFSET 16384
static int spdif_probe(AVProbeData *p)
@ -132,7 +136,7 @@ int ff_spdif_probe(const uint8_t *p_buf, int buf_size, enum AVCodecID *codec)
} else
consecutive_codes = 0;
if (buf + 4 + AAC_ADTS_HEADER_SIZE > p_buf + buf_size)
if (buf + 4 + AV_AAC_ADTS_HEADER_SIZE > p_buf + buf_size)
break;
/* continue probing to find more sync codes */

View File

@ -50,9 +50,9 @@
#include "avio_internal.h"
#include "spdif.h"
#include "libavcodec/ac3.h"
#include "libavcodec/adts_parser.h"
#include "libavcodec/dca.h"
#include "libavcodec/dca_syncwords.h"
#include "libavcodec/aacadtsdec.h"
#include "libavutil/opt.h"
typedef struct IEC61937Context {
@ -349,19 +349,18 @@ static int spdif_header_mpeg(AVFormatContext *s, AVPacket *pkt)
static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
{
IEC61937Context *ctx = s->priv_data;
AACADTSHeaderInfo hdr;
GetBitContext gbc;
uint32_t samples;
uint8_t frames;
int ret;
init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8);
ret = avpriv_aac_parse_header(&gbc, &hdr);
ret = av_adts_header_parse(pkt->data, &samples, &frames);
if (ret < 0) {
av_log(s, AV_LOG_ERROR, "Wrong AAC file format\n");
return AVERROR_INVALIDDATA;
return ret;
}
ctx->pkt_offset = hdr.samples << 2;
switch (hdr.num_aac_frames) {
ctx->pkt_offset = samples << 2;
switch (frames) {
case 1:
ctx->data_type = IEC61937_MPEG2_AAC;
break;
@ -373,7 +372,7 @@ static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
break;
default:
av_log(s, AV_LOG_ERROR,
"%"PRIu32" samples in AAC frame not supported\n", hdr.samples);
"%"PRIu32" samples in AAC frame not supported\n", samples);
return AVERROR(EINVAL);
}
//TODO Data type dependent info (LC profile/SBR)