History

Merge commit 'b5f19f7478492307e4b4763aeac3180faf50e17f'

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

James Almer committed 9 years ago

Commit b9d3def2 parents ff173ce b5f19f714 files · +141 −52Browse files

Unified · Split

14 files
  1. configure +6 −2
  2. doc/developer.texi +1 −1
  3. libavcodec/Makefile +7 −6
  4. libavcodec/aac_adtstoasc_bsf.c +7 −6
  5. libavcodec/aac_parser.c +6 −4
  6. libavcodec/aacdec.c +1 −1
  7. libavcodec/aacdec_fixed.c +1 −1
  8. libavcodec/aacdec_template.c +1 −1
  9. libavcodec/adts_header.c +4 −3
  10. libavcodec/adts_header.h +4 −8
  11. libavcodec/adts_parser.c +44 −0
  12. libavcodec/adts_parser.h +37 −0
  13. libavformat/spdifdec.c +14 −10
  14. libavformat/spdifenc.c +8 −9
configure+6−2
@@ -2135,6 +2135,7 @@ HAVE_LIST=" · 2134 unmodified lines
2135CONFIG_EXTRA="2135CONFIG_EXTRA="
2136 aandcttables2136 aandcttables
2137 ac3dsp2137 ac3dsp
2138 adts_header
2138 audio_frame_queue2139 audio_frame_queue
2139 audiodsp2140 audiodsp
2140 blockdsp2141 blockdsp
@@ -2421,7 +2422,7 @@ vc1dsp_select="h264chroma qpeldsp startcode" · 280 unmodified lines
2421rdft_select="fft"2422rdft_select="fft"
2422 2423
2423# decoders / encoders2424# decoders / encoders
2424aac_decoder_select="mdct15 mdct sinewin"2425aac_decoder_select="adts_header mdct15 mdct sinewin"
2425aac_fixed_decoder_select="mdct sinewin"2426aac_fixed_decoder_select="mdct sinewin"
2426aac_encoder_select="audio_frame_queue iirfilter lpc mdct sinewin"2427aac_encoder_select="audio_frame_queue iirfilter lpc mdct sinewin"
2427aac_latm_decoder_select="aac_decoder aac_latm_parser"2428aac_latm_decoder_select="aac_decoder aac_latm_parser"
@@ -2873,6 +2874,7 @@ vp9_v4l2m2m_decoder_deps="v4l2_m2m vp9_v4l2_m2m" · 445 unmodified lines
2873wmv3_crystalhd_decoder_select="crystalhd"2874wmv3_crystalhd_decoder_select="crystalhd"
2874 2875
2875# parsers2876# parsers
2877aac_parser_select="adts_header"
2876h264_parser_select="golomb h264dsp h264parse"2878h264_parser_select="golomb h264dsp h264parse"
2877hevc_parser_select="hevcparse"2879hevc_parser_select="hevcparse"
2878mpegaudio_parser_select="mpegaudioheader"2880mpegaudio_parser_select="mpegaudioheader"
@@ -2881,6 +2883,7 @@ mpeg4video_parser_select="h263dsp mpegvideo qpeldsp" · 2 unmodified lines
2881vc1_parser_select="vc1dsp"2883vc1_parser_select="vc1dsp"
2882 2884
2883# bitstream_filters2885# bitstream_filters
2886aac_adtstoasc_bsf_select="adts_header"
2884h264_metadata_bsf_select="cbs_h264"2887h264_metadata_bsf_select="cbs_h264"
2885h264_redundant_pps_bsf_select="cbs_h264"2888h264_redundant_pps_bsf_select="cbs_h264"
2886hevc_metadata_bsf_select="cbs_h265"2889hevc_metadata_bsf_select="cbs_h265"
@@ -3047,7 +3050,8 @@ sap_demuxer_select="sdp_demuxer" · 160 unmodified lines
3047sap_muxer_select="rtp_muxer rtp_protocol rtpenc_chain"3050sap_muxer_select="rtp_muxer rtp_protocol rtpenc_chain"
3048sdp_demuxer_select="rtpdec"3051sdp_demuxer_select="rtpdec"
3049smoothstreaming_muxer_select="ismv_muxer"3052smoothstreaming_muxer_select="ismv_muxer"
3050spdif_muxer_select="aac_parser"3053spdif_demuxer_select="adts_header"
3054spdif_muxer_select="adts_header"
3051spx_muxer_select="ogg_muxer"3055spx_muxer_select="ogg_muxer"
3052swf_demuxer_suggest="zlib"3056swf_demuxer_suggest="zlib"
3053tak_demuxer_select="tak_parser"3057tak_demuxer_select="tak_parser"
doc/developer.texi+1−1
@@ -184,7 +184,7 @@ e.g. @samp{ff_w64_demuxer}. · 183 unmodified lines
184@item184@item
185For variables and functions visible outside of file scope, used internally185For variables and functions visible outside of file scope, used internally
186across multiple libraries, use @code{avpriv_} as prefix, for example,186across multiple libraries, use @code{avpriv_} as prefix, for example,
187@samp{avpriv_aac_parse_header}.187@samp{avpriv_report_missing_feature}.
188 188
189@item189@item
190Each library has its own prefix for public symbols, in addition to the190Each library has its own prefix for public symbols, in addition to the
libavcodec/Makefile+7−6
@@ -2,6 +2,7 @@ NAME = avcodec · 1 unmodified line
2DESC = FFmpeg codec library2DESC = FFmpeg codec library
3 3
4HEADERS = ac3_parser.h \4HEADERS = ac3_parser.h \
5 adts_parser.h \
5 avcodec.h \6 avcodec.h \
6 avdct.h \7 avdct.h \
7 avfft.h \8 avfft.h \
@@ -20,6 +21,7 @@ HEADERS = ac3_parser.h \ · 12 unmodified lines
20 xvmc.h \21 xvmc.h \
21 22
22OBJS = ac3_parser.o \23OBJS = ac3_parser.o \
24 adts_parser.o \
23 allcodecs.o \25 allcodecs.o \
24 avdct.o \26 avdct.o \
25 avpacket.o \27 avpacket.o \
@@ -52,6 +54,7 @@ OBJS = ac3_parser.o \ · 26 unmodified lines
52# subsystems54# subsystems
53OBJS-$(CONFIG_AANDCTTABLES) += aandcttab.o55OBJS-$(CONFIG_AANDCTTABLES) += aandcttab.o
54OBJS-$(CONFIG_AC3DSP) += ac3dsp.o ac3.o ac3tab.o56OBJS-$(CONFIG_AC3DSP) += ac3dsp.o ac3.o ac3tab.o
57OBJS-$(CONFIG_ADTS_HEADER) += adts_header.o mpeg4audio.o
55OBJS-$(CONFIG_AUDIO_FRAME_QUEUE) += audio_frame_queue.o58OBJS-$(CONFIG_AUDIO_FRAME_QUEUE) += audio_frame_queue.o
56OBJS-$(CONFIG_AUDIODSP) += audiodsp.o59OBJS-$(CONFIG_AUDIODSP) += audiodsp.o
57OBJS-$(CONFIG_BLOCKDSP) += blockdsp.o60OBJS-$(CONFIG_BLOCKDSP) += blockdsp.o
@@ -148,10 +151,10 @@ OBJS-$(CONFIG_ZERO12V_DECODER) += 012v.o · 90 unmodified lines
148OBJS-$(CONFIG_A64MULTI_ENCODER) += a64multienc.o elbg.o151OBJS-$(CONFIG_A64MULTI_ENCODER) += a64multienc.o elbg.o
149OBJS-$(CONFIG_A64MULTI5_ENCODER) += a64multienc.o elbg.o152OBJS-$(CONFIG_A64MULTI5_ENCODER) += a64multienc.o elbg.o
150OBJS-$(CONFIG_AAC_DECODER) += aacdec.o aactab.o aacsbr.o aacps_float.o \153OBJS-$(CONFIG_AAC_DECODER) += aacdec.o aactab.o aacsbr.o aacps_float.o \
151 aacadtsdec.o mpeg4audio.o kbdwin.o \154 mpeg4audio.o kbdwin.o \
152 sbrdsp.o aacpsdsp_float.o cbrt_data.o155 sbrdsp.o aacpsdsp_float.o cbrt_data.o
153OBJS-$(CONFIG_AAC_FIXED_DECODER) += aacdec_fixed.o aactab.o aacsbr_fixed.o aacps_fixed.o \156OBJS-$(CONFIG_AAC_FIXED_DECODER) += aacdec_fixed.o aactab.o aacsbr_fixed.o aacps_fixed.o \
154 aacadtsdec.o mpeg4audio.o kbdwin.o \157 mpeg4audio.o kbdwin.o \
155 sbrdsp_fixed.o aacpsdsp_fixed.o cbrt_data_fixed.o158 sbrdsp_fixed.o aacpsdsp_fixed.o cbrt_data_fixed.o
156OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o aaccoder.o aacenctab.o \159OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o aaccoder.o aacenctab.o \
157 aacpsy.o aactab.o \160 aacpsy.o aactab.o \
@@ -880,7 +883,6 @@ OBJS-$(CONFIG_MXF_MUXER) += dnxhddata.o · 722 unmodified lines
880OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o883OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o
881OBJS-$(CONFIG_NUT_DEMUXER) += mpegaudiodata.o mpeg4audio.o884OBJS-$(CONFIG_NUT_DEMUXER) += mpegaudiodata.o mpeg4audio.o
882OBJS-$(CONFIG_RTP_MUXER) += mpeg4audio.o885OBJS-$(CONFIG_RTP_MUXER) += mpeg4audio.o
883OBJS-$(CONFIG_SPDIF_DEMUXER) += aacadtsdec.o mpeg4audio.o
884OBJS-$(CONFIG_SPDIF_MUXER) += dca.o886OBJS-$(CONFIG_SPDIF_MUXER) += dca.o
885OBJS-$(CONFIG_TAK_DEMUXER) += tak.o887OBJS-$(CONFIG_TAK_DEMUXER) += tak.o
886OBJS-$(CONFIG_WEBM_MUXER) += mpeg4audio.o888OBJS-$(CONFIG_WEBM_MUXER) += mpeg4audio.o
@@ -957,7 +959,7 @@ OBJS-$(CONFIG_LIBZVBI_TELETEXT_DECODER) += libzvbi-teletextdec.o ass.o · 70 unmodified lines
957# parsers959# parsers
958OBJS-$(CONFIG_AAC_LATM_PARSER) += latm_parser.o960OBJS-$(CONFIG_AAC_LATM_PARSER) += latm_parser.o
959OBJS-$(CONFIG_AAC_PARSER) += aac_parser.o aac_ac3_parser.o \961OBJS-$(CONFIG_AAC_PARSER) += aac_parser.o aac_ac3_parser.o \
960 aacadtsdec.o mpeg4audio.o962 mpeg4audio.o
961OBJS-$(CONFIG_AC3_PARSER) += ac3tab.o aac_ac3_parser.o963OBJS-$(CONFIG_AC3_PARSER) += ac3tab.o aac_ac3_parser.o
962OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o adx.o964OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o adx.o
963OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o965OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o
@@ -1003,8 +1005,7 @@ OBJS-$(CONFIG_VP9_PARSER) += vp9_parser.o · 39 unmodified lines
1003OBJS-$(CONFIG_XMA_PARSER) += xma_parser.o1005OBJS-$(CONFIG_XMA_PARSER) += xma_parser.o
1004 1006
1005# bitstream filters1007# bitstream filters
1006OBJS-$(CONFIG_AAC_ADTSTOASC_BSF) += aac_adtstoasc_bsf.o aacadtsdec.o \1008OBJS-$(CONFIG_AAC_ADTSTOASC_BSF) += aac_adtstoasc_bsf.o mpeg4audio.o
1007 mpeg4audio.o
1008OBJS-$(CONFIG_CHOMP_BSF) += chomp_bsf.o1009OBJS-$(CONFIG_CHOMP_BSF) += chomp_bsf.o
1009OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o1010OBJS-$(CONFIG_DUMP_EXTRADATA_BSF) += dump_extradata_bsf.o
1010OBJS-$(CONFIG_DCA_CORE_BSF) += dca_core_bsf.o1011OBJS-$(CONFIG_DCA_CORE_BSF) += dca_core_bsf.o
libavcodec/aac_adtstoasc_bsf.c+7−6
@@ -19,8 +19,9 @@ · 18 unmodified lines
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */20 */
21 21
22#include "adts_header.h"
23#include "adts_parser.h"
22#include "avcodec.h"24#include "avcodec.h"
23#include "aacadtsdec.h"
24#include "bsf.h"25#include "bsf.h"
25#include "put_bits.h"26#include "put_bits.h"
26#include "get_bits.h"27#include "get_bits.h"
@@ -52,12 +53,12 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out) · 25 unmodified lines
52 if (bsfc->par_in->extradata && in->size >= 2 && (AV_RB16(in->data) >> 4) != 0xfff)53 if (bsfc->par_in->extradata && in->size >= 2 && (AV_RB16(in->data) >> 4) != 0xfff)
53 goto finish;54 goto finish;
54 55
55 if (in->size < AAC_ADTS_HEADER_SIZE)56 if (in->size < AV_AAC_ADTS_HEADER_SIZE)
56 goto packet_too_small;57 goto packet_too_small;
57 58
58 init_get_bits(&gb, in->data, AAC_ADTS_HEADER_SIZE * 8);59 init_get_bits(&gb, in->data, AV_AAC_ADTS_HEADER_SIZE * 8);
59 60
60 if (avpriv_aac_parse_header(&gb, &hdr) < 0) {61 if (ff_adts_header_parse(&gb, &hdr) < 0) {
61 av_log(bsfc, AV_LOG_ERROR, "Error parsing ADTS frame header!\n");62 av_log(bsfc, AV_LOG_ERROR, "Error parsing ADTS frame header!\n");
62 ret = AVERROR_INVALIDDATA;63 ret = AVERROR_INVALIDDATA;
63 goto fail;64 goto fail;
@@ -70,10 +71,10 @@ static int aac_adtstoasc_filter(AVBSFContext *bsfc, AVPacket *out) · 6 unmodified lines
70 goto fail;71 goto fail;
71 }72 }
72 73
73 in->size -= AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;74 in->size -= AV_AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;
74 if (in->size <= 0)75 if (in->size <= 0)
75 goto packet_too_small;76 goto packet_too_small;
76 in->data += AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;77 in->data += AV_AAC_ADTS_HEADER_SIZE + 2 * !hdr.crc_absent;
77 78
78 if (!ctx->first_frame_done) {79 if (!ctx->first_frame_done) {
79 int pce_size = 0;80 int pce_size = 0;
libavcodec/aac_parser.c+6−4
@@ -22,7 +22,8 @@ · 21 unmodified lines
22 22
23#include "parser.h"23#include "parser.h"
24#include "aac_ac3_parser.h"24#include "aac_ac3_parser.h"
25#include "aacadtsdec.h"25#include "adts_header.h"
26#include "adts_parser.h"
26#include "get_bits.h"27#include "get_bits.h"
27#include "mpeg4audio.h"28#include "mpeg4audio.h"
28 29
@@ -38,9 +39,10 @@ static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info, · 9 unmodified lines
38 } tmp;39 } tmp;
39 40
40 tmp.u64 = av_be2ne64(state);41 tmp.u64 = av_be2ne64(state);
41 init_get_bits(&bits, tmp.u8+8-AAC_ADTS_HEADER_SIZE, AAC_ADTS_HEADER_SIZE * 8);42 init_get_bits(&bits, tmp.u8 + 8 - AV_AAC_ADTS_HEADER_SIZE,
43 AV_AAC_ADTS_HEADER_SIZE * 8);
42 44
43 if ((size = avpriv_aac_parse_header(&bits, &hdr)) < 0)45 if ((size = ff_adts_header_parse(&bits, &hdr)) < 0)
44 return 0;46 return 0;
45 *need_next_header = 0;47 *need_next_header = 0;
46 *new_frame_start = 1;48 *new_frame_start = 1;
@@ -54,7 +56,7 @@ static int aac_sync(uint64_t state, AACAC3ParseContext *hdr_info, · 7 unmodified lines
54static av_cold int aac_parse_init(AVCodecParserContext *s1)56static av_cold int aac_parse_init(AVCodecParserContext *s1)
55{57{
56 AACAC3ParseContext *s = s1->priv_data;58 AACAC3ParseContext *s = s1->priv_data;
57 s->header_size = AAC_ADTS_HEADER_SIZE;59 s->header_size = AV_AAC_ADTS_HEADER_SIZE;
58 s->sync = aac_sync;60 s->sync = aac_sync;
59 return 0;61 return 0;
60}62}
libavcodec/aacdec.c+1−1
@@ -50,11 +50,11 @@ · 49 unmodified lines
50#include "aac.h"50#include "aac.h"
51#include "aactab.h"51#include "aactab.h"
52#include "aacdectab.h"52#include "aacdectab.h"
53#include "adts_header.h"
53#include "cbrt_data.h"54#include "cbrt_data.h"
54#include "sbr.h"55#include "sbr.h"
55#include "aacsbr.h"56#include "aacsbr.h"
56#include "mpeg4audio.h"57#include "mpeg4audio.h"
57#include "aacadtsdec.h"
58#include "profiles.h"58#include "profiles.h"
59#include "libavutil/intfloat.h"59#include "libavutil/intfloat.h"
60 60
libavcodec/aacdec_fixed.c+1−1
@@ -75,11 +75,11 @@ · 74 unmodified lines
75#include "aac.h"75#include "aac.h"
76#include "aactab.h"76#include "aactab.h"
77#include "aacdectab.h"77#include "aacdectab.h"
78#include "adts_header.h"
78#include "cbrt_data.h"79#include "cbrt_data.h"
79#include "sbr.h"80#include "sbr.h"
80#include "aacsbr.h"81#include "aacsbr.h"
81#include "mpeg4audio.h"82#include "mpeg4audio.h"
82#include "aacadtsdec.h"
83#include "profiles.h"83#include "profiles.h"
84#include "libavutil/intfloat.h"84#include "libavutil/intfloat.h"
85 85
libavcodec/aacdec_template.c+1−1
@@ -2955,7 +2955,7 @@ static int parse_adts_frame_header(AACContext *ac, GetBitContext *gb) · 2954 unmodified lines
2955 uint8_t layout_map[MAX_ELEM_ID*4][3];2955 uint8_t layout_map[MAX_ELEM_ID*4][3];
2956 int layout_map_tags, ret;2956 int layout_map_tags, ret;
2957 2957
2958 size = avpriv_aac_parse_header(gb, &hdr_info);2958 size = ff_adts_header_parse(gb, &hdr_info);
2959 if (size > 0) {2959 if (size > 0) {
2960 if (!ac->warned_num_aac_frames && hdr_info.num_aac_frames != 1) {2960 if (!ac->warned_num_aac_frames && hdr_info.num_aac_frames != 1) {
2961 // This is 2 for "VLB " audio in NSV files.2961 // This is 2 for "VLB " audio in NSV files.
libavcodec/adts_header.crenamed from libavcodec/aacadtsdec.c+4−3
@@ -22,11 +22,12 @@ · 21 unmodified lines
22 */22 */
23 23
24#include "aac_ac3_parser.h"24#include "aac_ac3_parser.h"
25#include "aacadtsdec.h"25#include "adts_header.h"
26#include "adts_parser.h"
26#include "get_bits.h"27#include "get_bits.h"
27#include "mpeg4audio.h"28#include "mpeg4audio.h"
28 29
29int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr)30int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr)
30{31{
31 int size, rdb, ch, sr;32 int size, rdb, ch, sr;
32 int aot, crc_abs;33 int aot, crc_abs;
@@ -51,7 +52,7 @@ int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr) · 18 unmodified lines
51 skip_bits1(gbc); /* copyright_identification_bit */52 skip_bits1(gbc); /* copyright_identification_bit */
52 skip_bits1(gbc); /* copyright_identification_start */53 skip_bits1(gbc); /* copyright_identification_start */
53 size = get_bits(gbc, 13); /* aac_frame_length */54 size = get_bits(gbc, 13); /* aac_frame_length */
54 if (size < AAC_ADTS_HEADER_SIZE)55 if (size < AV_AAC_ADTS_HEADER_SIZE)
55 return AAC_AC3_PARSE_ERROR_FRAME_SIZE;56 return AAC_AC3_PARSE_ERROR_FRAME_SIZE;
56 57
57 skip_bits(gbc, 11); /* adts_buffer_fullness */58 skip_bits(gbc, 11); /* adts_buffer_fullness */
libavcodec/adts_header.hrenamed from libavcodec/aacadtsdec.h+4−8
@@ -20,14 +20,11 @@ · 19 unmodified lines
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */21 */
22 22
23#ifndef AVCODEC_AACADTSDEC_H23#ifndef AVCODEC_ADTS_HEADER_H
24#define AVCODEC_AACADTSDEC_H24#define AVCODEC_ADTS_HEADER_H
25 25
26#include <stdint.h>
27#include "get_bits.h"26#include "get_bits.h"
28 27
29#define AAC_ADTS_HEADER_SIZE 7
30
31typedef struct AACADTSHeaderInfo {28typedef struct AACADTSHeaderInfo {
32 uint32_t sample_rate;29 uint32_t sample_rate;
33 uint32_t samples;30 uint32_t samples;
@@ -40,7 +37,6 @@ typedef struct AACADTSHeaderInfo { · 6 unmodified lines
40} AACADTSHeaderInfo;37} AACADTSHeaderInfo;
41 38
42/**39/**
43 * Parse AAC frame header.
44 * Parse the ADTS frame header to the end of the variable header, which is40 * Parse the ADTS frame header to the end of the variable header, which is
45 * the first 54 bits.41 * the first 54 bits.
46 * @param[in] gbc BitContext containing the first 54 bits of the frame.42 * @param[in] gbc BitContext containing the first 54 bits of the frame.
@@ -49,6 +45,6 @@ typedef struct AACADTSHeaderInfo { · 2 unmodified lines
49 * -2 if the version element is invalid, -3 if the sample rate45 * -2 if the version element is invalid, -3 if the sample rate
50 * element is invalid, or -4 if the bit rate element is invalid.46 * element is invalid, or -4 if the bit rate element is invalid.
51 */47 */
52int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr);48int ff_adts_header_parse(GetBitContext *gbc, AACADTSHeaderInfo *hdr);
53 49
54#endif /* AVCODEC_AACADTSDEC_H */50#endif /* AVCODEC_ADTS_HEADER_H */
libavcodec/adts_parser.c+44−0
@@ -0,0 +1,44 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "config.h"
20
21#include <stddef.h>
22#include <stdint.h>
23
24#include "adts_header.h"
25#include "adts_parser.h"
26
27int av_adts_header_parse(const uint8_t *buf, uint32_t *samples, uint8_t *frames)
28{
29#if CONFIG_ADTS_HEADER
30 GetBitContext gb;
31 AACADTSHeaderInfo hdr;
32 int err = init_get_bits8(&gb, buf, AV_AAC_ADTS_HEADER_SIZE);
33 if (err < 0)
34 return err;
35 err = ff_adts_header_parse(&gb, &hdr);
36 if (err < 0)
37 return err;
38 *samples = hdr.samples;
39 *frames = hdr.num_aac_frames;
40 return 0;
41#else
42 return AVERROR(ENOSYS);
43#endif
44}
libavcodec/adts_parser.h+37−0
@@ -0,0 +1,37 @@
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#ifndef AVCODEC_ADTS_PARSER_H
20#define AVCODEC_ADTS_PARSER_H
21
22#include <stddef.h>
23#include <stdint.h>
24
25#define AV_AAC_ADTS_HEADER_SIZE 7
26
27/**
28 * Extract the number of samples and frames from AAC data.
29 * @param[in] buf pointer to AAC data buffer
30 * @param[out] samples Pointer to where number of samples is written
31 * @param[out] frames Pointer to where number of frames is written
32 * @return Returns 0 on success, error code on failure.
33 */
34int av_adts_header_parse(const uint8_t *buf, uint32_t *samples,
35 uint8_t *frames);
36
37#endif /* AVCODEC_ADTS_PARSER_H */
libavformat/spdifdec.c+14−10
@@ -25,18 +25,22 @@ · 24 unmodified lines
25 * @author Anssi Hannula25 * @author Anssi Hannula
26 */26 */
27 27
28#include "libavutil/bswap.h"
29
30#include "libavcodec/ac3.h"
31#include "libavcodec/adts_parser.h"
32
28#include "avformat.h"33#include "avformat.h"
29#include "spdif.h"34#include "spdif.h"
30#include "libavcodec/ac3.h"
31#include "libavcodec/aacadtsdec.h"
32 35
33static int spdif_get_offset_and_codec(AVFormatContext *s,36static int spdif_get_offset_and_codec(AVFormatContext *s,
34 enum IEC61937DataType data_type,37 enum IEC61937DataType data_type,
35 const char *buf, int *offset,38 const char *buf, int *offset,
36 enum AVCodecID *codec)39 enum AVCodecID *codec)
37{40{
38 AACADTSHeaderInfo aac_hdr;41 uint32_t samples;
39 GetBitContext gbc;42 uint8_t frames;
43 int ret;
40 44
41 switch (data_type & 0xff) {45 switch (data_type & 0xff) {
42 case IEC61937_AC3:46 case IEC61937_AC3:
@@ -56,13 +60,13 @@ static int spdif_get_offset_and_codec(AVFormatContext *s, · 13 unmodified lines
56 *codec = AV_CODEC_ID_MP3;60 *codec = AV_CODEC_ID_MP3;
57 break;61 break;
58 case IEC61937_MPEG2_AAC:62 case IEC61937_MPEG2_AAC:
59 init_get_bits(&gbc, buf, AAC_ADTS_HEADER_SIZE * 8);63 ret = av_adts_header_parse(buf, &samples, &frames);
60 if (avpriv_aac_parse_header(&gbc, &aac_hdr) < 0) {64 if (ret < 0) {
61 if (s) /* be silent during a probe */65 if (s) /* be silent during a probe */
62 av_log(s, AV_LOG_ERROR, "Invalid AAC packet in IEC 61937\n");66 av_log(s, AV_LOG_ERROR, "Invalid AAC packet in IEC 61937\n");
63 return AVERROR_INVALIDDATA;67 return ret;
64 }68 }
65 *offset = aac_hdr.samples << 2;69 *offset = samples << 2;
66 *codec = AV_CODEC_ID_AAC;70 *codec = AV_CODEC_ID_AAC;
67 break;71 break;
68 case IEC61937_MPEG2_LAYER1_LSF:72 case IEC61937_MPEG2_LAYER1_LSF:
@@ -100,7 +104,7 @@ static int spdif_get_offset_and_codec(AVFormatContext *s, · 31 unmodified lines
100}104}
101 105
102/* Largest offset between bursts we currently handle, i.e. AAC with106/* Largest offset between bursts we currently handle, i.e. AAC with
103 aac_hdr.samples = 4096 */107 samples = 4096 */
104#define SPDIF_MAX_OFFSET 16384108#define SPDIF_MAX_OFFSET 16384
105 109
106static int spdif_probe(AVProbeData *p)110static int spdif_probe(AVProbeData *p)
@@ -132,7 +136,7 @@ int ff_spdif_probe(const uint8_t *p_buf, int buf_size, enum AVCodecID *codec) · 25 unmodified lines
132 } else136 } else
133 consecutive_codes = 0;137 consecutive_codes = 0;
134 138
135 if (buf + 4 + AAC_ADTS_HEADER_SIZE > p_buf + buf_size)139 if (buf + 4 + AV_AAC_ADTS_HEADER_SIZE > p_buf + buf_size)
136 break;140 break;
137 141
138 /* continue probing to find more sync codes */142 /* continue probing to find more sync codes */
libavformat/spdifenc.c+8−9
@@ -50,9 +50,9 @@ · 49 unmodified lines
50#include "avio_internal.h"50#include "avio_internal.h"
51#include "spdif.h"51#include "spdif.h"
52#include "libavcodec/ac3.h"52#include "libavcodec/ac3.h"
53#include "libavcodec/adts_parser.h"
53#include "libavcodec/dca.h"54#include "libavcodec/dca.h"
54#include "libavcodec/dca_syncwords.h"55#include "libavcodec/dca_syncwords.h"
55#include "libavcodec/aacadtsdec.h"
56#include "libavutil/opt.h"56#include "libavutil/opt.h"
57 57
58typedef struct IEC61937Context {58typedef struct IEC61937Context {
@@ -349,19 +349,18 @@ static int spdif_header_mpeg(AVFormatContext *s, AVPacket *pkt) · 290 unmodified lines
349static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)349static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt)
350{350{
351 IEC61937Context *ctx = s->priv_data;351 IEC61937Context *ctx = s->priv_data;
352 AACADTSHeaderInfo hdr;352 uint32_t samples;
353 GetBitContext gbc;353 uint8_t frames;
354 int ret;354 int ret;
355 355
356 init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8);356 ret = av_adts_header_parse(pkt->data, &samples, &frames);
357 ret = avpriv_aac_parse_header(&gbc, &hdr);
358 if (ret < 0) {357 if (ret < 0) {
359 av_log(s, AV_LOG_ERROR, "Wrong AAC file format\n");358 av_log(s, AV_LOG_ERROR, "Wrong AAC file format\n");
360 return AVERROR_INVALIDDATA;359 return ret;
361 }360 }
362 361
363 ctx->pkt_offset = hdr.samples << 2;362 ctx->pkt_offset = samples << 2;
364 switch (hdr.num_aac_frames) {363 switch (frames) {
365 case 1:364 case 1:
366 ctx->data_type = IEC61937_MPEG2_AAC;365 ctx->data_type = IEC61937_MPEG2_AAC;
367 break;366 break;
@@ -373,7 +372,7 @@ static int spdif_header_aac(AVFormatContext *s, AVPacket *pkt) · 5 unmodified lines
373 break;372 break;
374 default:373 default:
375 av_log(s, AV_LOG_ERROR,374 av_log(s, AV_LOG_ERROR,
376 "%"PRIu32" samples in AAC frame not supported\n", hdr.samples);375 "%"PRIu32" samples in AAC frame not supported\n", samples);
377 return AVERROR(EINVAL);376 return AVERROR(EINVAL);
378 }377 }
379 //TODO Data type dependent info (LC profile/SBR)378 //TODO Data type dependent info (LC profile/SBR)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t