[FFmpeg-devel] [PATCH 2/6] mpeg: add experimental support for PSMF audio.
Michael Niedermayer
michael at niedermayer.cc
Tue Dec 26 02:42:31 EET 2017
On Mon, Dec 25, 2017 at 10:28:30AM +0800, misty at brew.sh wrote:
> From: Maxim Poliakovski <maximumspatium at googlemail.com>
>
> ---
> libavcodec/Makefile | 1 +
> libavcodec/allcodecs.c | 1 +
> libavcodec/atrac3plus_parser.c | 153 +++++++++++++++++++++++++++++++++++++++++
> libavformat/mpeg.c | 27 +++++++-
> 4 files changed, 181 insertions(+), 1 deletion(-)
> create mode 100644 libavcodec/atrac3plus_parser.c
>
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index ca72138c02..e0e3f1ebac 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -977,6 +977,7 @@ OBJS-$(CONFIG_AAC_PARSER) += aac_parser.o aac_ac3_parser.o \
> mpeg4audio.o
> OBJS-$(CONFIG_AC3_PARSER) += ac3tab.o aac_ac3_parser.o
> OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o adx.o
> +OBJS-$(CONFIG_ATRAC3P_PARSER) += atrac3plus_parser.o
> OBJS-$(CONFIG_BMP_PARSER) += bmp_parser.o
> OBJS-$(CONFIG_CAVSVIDEO_PARSER) += cavs_parser.o
> OBJS-$(CONFIG_COOK_PARSER) += cook_parser.o
> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
> index ed1e7ab06e..81d5d2814a 100644
> --- a/libavcodec/allcodecs.c
> +++ b/libavcodec/allcodecs.c
> @@ -623,6 +623,7 @@ static void register_all(void)
> REGISTER_PARSER(AAC_LATM, aac_latm);
> REGISTER_PARSER(AC3, ac3);
> REGISTER_PARSER(ADX, adx);
> + REGISTER_PARSER(ATRAC3P, atrac3p);
> REGISTER_PARSER(BMP, bmp);
> REGISTER_PARSER(CAVSVIDEO, cavsvideo);
> REGISTER_PARSER(COOK, cook);
> diff --git a/libavcodec/atrac3plus_parser.c b/libavcodec/atrac3plus_parser.c
> new file mode 100644
> index 0000000000..01fcad4c45
> --- /dev/null
> +++ b/libavcodec/atrac3plus_parser.c
> @@ -0,0 +1,153 @@
> +/*
> + * Copyright (C) 2014 Maxim Poliakovski
> + *
> + * 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 "parser.h"
> +#include "get_bits.h"
> +#include "libavformat/oma.h"
> +
> +typedef struct Atrac3PlusParseContext {
> + ParseContext pc;
> + uint8_t hdr[8];
> + int hdr_bytes_needed, got_bytes;
> + int sample_rate, channel_id, frame_size;
> +} Atrac3PlusParseContext;
> +
> +static int parse_sound_frame_header(Atrac3PlusParseContext *c,
> + const uint8_t *buf)
> +{
> + uint16_t atrac_config;
> +
> + if (AV_RB16(buf) != 0x0FD0)
> + return AVERROR_INVALIDDATA;
> +
> + atrac_config = AV_RB16(&buf[2]);
> + c->sample_rate = ff_oma_srate_tab[(atrac_config >> 13) & 7] * 100;
> + c->channel_id = (atrac_config >> 10) & 7;
> + c->frame_size = ((atrac_config & 0x3FF) * 8) + 8;
> +
> + if (!c->channel_id || !c->sample_rate || !c->frame_size)
> + return AVERROR_INVALIDDATA;
> +
> + return 0;
> +}
> +
> +static int ff_atrac3p_parse(AVCodecParserContext *s,
> + AVCodecContext *avctx,
> + const uint8_t **poutbuf, int *poutbuf_size,
> + const uint8_t *buf, int buf_size)
> +{
> + Atrac3PlusParseContext *ctx = s->priv_data;
> + const uint8_t *hdr_buf = buf;
> + size_t bytes_remain;
> + int frame_size, hdr_bytes = 8;
> + int next = 0;
> +
> + if (s->flags & PARSER_FLAG_COMPLETE_FRAMES || !buf_size) {
> + next = buf_size;
> + } else {
> + if (buf_size >= 2) {
> + bytes_remain = AV_RB16(buf);
> +
> + if (bytes_remain != 0xFD0) {
> + next += 2;
> + buf += 2;
> + buf_size -= 2;
> + hdr_buf = buf;
> +
> + if (bytes_remain && !ctx->pc.index && !ctx->hdr_bytes_needed) {
> + av_log(avctx, AV_LOG_ERROR,
> + "2nd frame portion found but the 1st one is missing!\n");
> + return AVERROR_INVALIDDATA;
> + }
returning errors from the parse function will cause assertion failure at:
Assertion index > -0x20000000 failed at libavcodec/parser.c:185
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
When you are offended at any man's fault, turn to yourself and study your
own failings. Then you will forget your anger. -- Epictetus
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20171226/5d5ec9ce/attachment.sig>
More information about the ffmpeg-devel
mailing list