diff options
author | James Almer <jamrial@gmail.com> | 2017-10-27 13:52:19 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2017-10-27 18:15:37 -0300 |
commit | e0250cf3651e6417e0117486a7816b45fb2d34cd (patch) | |
tree | fd04f7310c17247d93843ea177ef6f9d644296c4 /libavcodec | |
parent | 5834cba05efbfd24dadedd187753f244ad7e0cab (diff) | |
parent | 50a1c66cf6ab7eb683daaa9e2da3869fa3a54609 (diff) |
Merge commit '50a1c66cf6ab7eb683daaa9e2da3869fa3a54609'
* commit '50a1c66cf6ab7eb683daaa9e2da3869fa3a54609':
ac3_parser: add a public function for parsing the data required by the demuxer
avpriv_ac3_parse_header() is left in place but without the
GetBitContext parameter, as the mov muxer requires a lot more fields
than just bitstream_id and frame_size from the AC3HeaderInfo struct.
Merged-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/Makefile | 9 | ||||
-rw-r--r-- | libavcodec/ac3_parser.c | 72 | ||||
-rw-r--r-- | libavcodec/ac3_parser.h | 18 | ||||
-rw-r--r-- | libavcodec/ac3_parser_internal.h | 42 | ||||
-rw-r--r-- | libavcodec/ac3dec.c | 6 | ||||
-rw-r--r-- | libavcodec/audiotoolboxdec.c | 4 | ||||
-rw-r--r-- | libavcodec/eac3dec.c | 1 |
7 files changed, 120 insertions, 32 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index bc4d7dab27..8c878c3699 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1,7 +1,8 @@ NAME = avcodec DESC = FFmpeg codec library -HEADERS = avcodec.h \ +HEADERS = ac3_parser.h \ + avcodec.h \ avdct.h \ avfft.h \ d3d11va.h \ @@ -18,7 +19,8 @@ HEADERS = avcodec.h \ vorbis_parser.h \ xvmc.h \ -OBJS = allcodecs.o \ +OBJS = ac3_parser.o \ + allcodecs.o \ avdct.o \ avpacket.o \ avpicture.o \ @@ -955,8 +957,7 @@ OBJS-$(CONFIG_LIBZVBI_TELETEXT_DECODER) += libzvbi-teletextdec.o ass.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 83dd90ff67..1015245a90 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,16 +51,9 @@ 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 **phdr) +int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr) { int frame_size_code; - AC3HeaderInfo *hdr; - - if (!*phdr) - *phdr = av_mallocz(sizeof(AC3HeaderInfo)); - if (!*phdr) - return AVERROR(ENOMEM); - hdr = *phdr; memset(hdr, 0, sizeof(*hdr)); @@ -151,6 +148,46 @@ int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo **phdr) return 0; } +// TODO: Better way to pass AC3HeaderInfo fields to mov muxer. +int avpriv_ac3_parse_header(AC3HeaderInfo **phdr, const uint8_t *buf, + size_t size) +{ + GetBitContext gb; + AC3HeaderInfo *hdr; + int err; + + if (!*phdr) + *phdr = av_mallocz(sizeof(AC3HeaderInfo)); + if (!*phdr) + return AVERROR(ENOMEM); + hdr = *phdr; + + init_get_bits8(&gb, buf, size); + err = ff_ac3_parse_header(&gb, hdr); + if (err < 0) + return AVERROR_INVALIDDATA; + + return get_bits_count(&gb); +} + +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) { @@ -159,11 +196,11 @@ static int ac3_sync(uint64_t state, AACAC3ParseContext *hdr_info, uint64_t u64; uint8_t u8[8 + AV_INPUT_BUFFER_PADDING_SIZE]; } tmp = { av_be2ne64(state) }; - AC3HeaderInfo hdr, *phdr = &hdr; + AC3HeaderInfo hdr; GetBitContext gbc; init_get_bits(&gbc, tmp.u8+8-AC3_HEADER_SIZE, 54); - err = avpriv_ac3_parse_header(&gbc, &phdr); + err = ff_ac3_parse_header(&gbc, &hdr); if(err < 0) return 0; @@ -202,3 +239,18 @@ AVCodecParser ff_ac3_parser = { .parser_parse = ff_aac_ac3_parse, .parser_close = ff_parse_close, }; + +#else + +int avpriv_ac3_parse_header(AC3HeaderInfo **phdr, const uint8_t *buf, + size_t size) +{ + return AVERROR(ENOSYS); +} + +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 dc5d035e11..ff8cc4cf09 100644 --- a/libavcodec/ac3_parser.h +++ b/libavcodec/ac3_parser.h @@ -23,20 +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 Pointer to struct where header info is written. - * will be allocated if NULL - * @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 0000000000..3648802a73 --- /dev/null +++ b/libavcodec/ac3_parser_internal.h @@ -0,0 +1,42 @@ +/* + * AC-3 parser internal code + * + * 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_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); + +int avpriv_ac3_parse_header(AC3HeaderInfo **hdr, const uint8_t *buf, + size_t size); + +#endif /* AVCODEC_AC3_PARSER_INTERNAL_H */ diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c index c393076aec..244a18323f 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" @@ -297,10 +297,10 @@ static int ac3_parse_header(AC3DecodeContext *s) */ static int parse_frame_header(AC3DecodeContext *s) { - AC3HeaderInfo hdr, *phdr=&hdr; + AC3HeaderInfo hdr; int err; - err = avpriv_ac3_parse_header(&s->gbc, &phdr); + err = ff_ac3_parse_header(&s->gbc, &hdr); if (err) return err; diff --git a/libavcodec/audiotoolboxdec.c b/libavcodec/audiotoolboxdec.c index 607d3ba4d4..a149949aba 100644 --- a/libavcodec/audiotoolboxdec.c +++ b/libavcodec/audiotoolboxdec.c @@ -350,10 +350,10 @@ static av_cold int ffat_create_decoder(AVCodecContext *avctx, AVPacket *pkt) } else if (pkt && pkt->size >= 7 && (avctx->codec_id == AV_CODEC_ID_AC3 || avctx->codec_id == AV_CODEC_ID_EAC3)) { - AC3HeaderInfo hdr, *phdr = &hdr; + AC3HeaderInfo hdr; GetBitContext gbc; init_get_bits(&gbc, pkt->data, pkt->size); - if (avpriv_ac3_parse_header(&gbc, &phdr) < 0) + if (ff_ac3_parse_header(&gbc, &hdr) < 0) return AVERROR_INVALIDDATA; in_format.mSampleRate = hdr.sample_rate; in_format.mChannelsPerFrame = hdr.channels; diff --git a/libavcodec/eac3dec.c b/libavcodec/eac3dec.c index c971879b2d..6f6309f179 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" |