From patchwork Sat Jan 14 14:57:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 2216 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp639988vsb; Sat, 14 Jan 2017 06:58:25 -0800 (PST) X-Received: by 10.223.160.43 with SMTP id k40mr1379430wrk.24.1484405905349; Sat, 14 Jan 2017 06:58:25 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b65si5992614wmd.35.2017.01.14.06.58.24; Sat, 14 Jan 2017 06:58:25 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F28068A493; Sat, 14 Jan 2017 16:58:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7557168A48E for ; Sat, 14 Jan 2017 16:58:05 +0200 (EET) Received: by mail-wm0-f66.google.com with SMTP id c85so18738698wmi.1 for ; Sat, 14 Jan 2017 06:58:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=Vu+iDIYohfvXnd8kiMNCS/r1aA2q52jlCpwB1Bg+d54=; b=VmltXMRZzdU6zhYC8RDKUqgUs2nmvEOKqPNEaPgkMUWvPe+wFhx+oK89xqZ4pCBpZf LMwTyJ8D/F7QqsZrlifu2q8buLEpJNIyxUKCaEFE3mIcZT8LCU1rcoF50JLuVAzrNVl5 Cha5ODkm4u0ScwzQ29v5rr0N/rhNgrY4f8d0fMAOVG7kjk8gFl2CiiqkjOU2aNfpCqMP gjyDFviDanCsICuDp9o7gsGmQH6BKtFxL1UIQ9P/8o0pIRrosN4r7OsO+FGBvLeazqSl Pr9iM4OVyZpbV1pNHuG7onAGTDfCRl5ClMgVFTZKTsw3MPJ27cXPuFEn+ZyShut9PQIH CvMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Vu+iDIYohfvXnd8kiMNCS/r1aA2q52jlCpwB1Bg+d54=; b=a0GXqFGQb+lWZQnr+AA2fOIILNJXA1b7/cLdf0ZYPpsxOSKe44fBghL8LHCmUD0FCP NiXyvXYHAxMhXgGGL7U2MmJ97gb8yLavwGEncVYyN7Acct8YT+EkoaL1i2rqiRRtV3yX DOyfKBwoManxXe9OV01CWcJztDkDCHMPoncXrTQEBk3qzdSJWwnC8FWQlYIJ9SKPBqmY LjkFbv7CxPS0ICvhsPbKdQ/6FVdVr3+bLR87weScVqSb1N7PDy0Vj5NDzlh6GDvOj21W w7l5MSlW1iv/QXak/J9lUeJzdMLSbjhYerPqmRTgEVfhdUr7XHNdcq0mXucKxsl47WVI l75Q== X-Gm-Message-State: AIkVDXLSA1ei2/J3SzwOZeHuszoT/Z6Yrm/9oBPMBUIRv7O9pjdBRQSp1M17zNKzH9MiNw== X-Received: by 10.223.176.93 with SMTP id g29mr15981011wra.12.1484405893399; Sat, 14 Jan 2017 06:58:13 -0800 (PST) Received: from localhost.localdomain ([77.237.105.120]) by smtp.gmail.com with ESMTPSA id o132sm13244752wmo.17.2017.01.14.06.58.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 14 Jan 2017 06:58:12 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Sat, 14 Jan 2017 15:57:51 +0100 Message-Id: <20170114145751.20114-1-onemda@gmail.com> X-Mailer: git-send-email 2.9.3 Subject: [FFmpeg-devel] [PATCH] avcodec: add SIPR parser X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Fixes #2056. Signed-off-by: Paul B Mahol --- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/sipr_parser.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ libavformat/aadec.c | 2 ++ libavformat/rmdec.c | 1 + 5 files changed, 79 insertions(+) create mode 100644 libavcodec/sipr_parser.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 4494f26..f5735d0 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -943,6 +943,7 @@ OBJS-$(CONFIG_PNG_PARSER) += png_parser.o OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o OBJS-$(CONFIG_RV30_PARSER) += rv34_parser.o OBJS-$(CONFIG_RV40_PARSER) += rv34_parser.o +OBJS-$(CONFIG_SIPR_PARSER) += sipr_parser.o OBJS-$(CONFIG_TAK_PARSER) += tak_parser.o tak.o OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o vc1.o vc1data.o \ simple_idct.o wmv2data.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 22a93f3..703c552 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -702,6 +702,7 @@ void avcodec_register_all(void) REGISTER_PARSER(PNM, pnm); REGISTER_PARSER(RV30, rv30); REGISTER_PARSER(RV40, rv40); + REGISTER_PARSER(SIPR, sipr); REGISTER_PARSER(TAK, tak); REGISTER_PARSER(VC1, vc1); REGISTER_PARSER(VORBIS, vorbis); diff --git a/libavcodec/sipr_parser.c b/libavcodec/sipr_parser.c new file mode 100644 index 0000000..fba25e1 --- /dev/null +++ b/libavcodec/sipr_parser.c @@ -0,0 +1,74 @@ +/* + * 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 + */ + +/** + * @file + * Sipr audio parser + */ + +#include "parser.h" + +typedef struct SiprParserContext{ + ParseContext pc; +} SiprParserContext; + +static int sipr_split(AVCodecContext *avctx, const uint8_t *buf, int buf_size) +{ + int next; + + switch (avctx->block_align) { + case 20: + case 19: + case 29: + case 37: next = avctx->block_align; break; + default: + if (avctx->bit_rate > 12200) next = 20; + else if (avctx->bit_rate > 7500 ) next = 19; + else if (avctx->bit_rate > 5750 ) next = 29; + else next = 37; + } + + return FFMIN(next, buf_size); +} + +static int sipr_parse(AVCodecParserContext *s1, AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) +{ + SiprParserContext *s = s1->priv_data; + ParseContext *pc = &s->pc; + int next; + + next = sipr_split(avctx, buf, buf_size); + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; + *poutbuf_size = 0; + return buf_size; + } + + *poutbuf = buf; + *poutbuf_size = buf_size; + return next; +} + +AVCodecParser ff_sipr_parser = { + .codec_ids = { AV_CODEC_ID_SIPR }, + .priv_data_size = sizeof(SiprParserContext), + .parser_parse = sipr_parse, + .parser_close = ff_parse_close, +}; diff --git a/libavformat/aadec.c b/libavformat/aadec.c index cf5f3d1..0f4ec20 100644 --- a/libavformat/aadec.c +++ b/libavformat/aadec.c @@ -184,11 +184,13 @@ static int aa_read_header(AVFormatContext *s) st->codecpar->block_align = 19; st->codecpar->channels = 1; st->codecpar->sample_rate = 8500; + st->need_parsing = AVSTREAM_PARSE_FULL_RAW; } else if (!strcmp(codec_name, "acelp16")) { st->codecpar->codec_id = AV_CODEC_ID_SIPR; st->codecpar->block_align = 20; st->codecpar->channels = 1; st->codecpar->sample_rate = 16000; + st->need_parsing = AVSTREAM_PARSE_FULL_RAW; } /* determine, and jump to audio start offset */ diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c index 4d56529..c803588 100644 --- a/libavformat/rmdec.c +++ b/libavformat/rmdec.c @@ -236,6 +236,7 @@ static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, return -1; } st->codecpar->block_align = ff_sipr_subpk_size[flavor]; + st->need_parsing = AVSTREAM_PARSE_FULL_RAW; } else { if(sub_packet_size <= 0){ av_log(s, AV_LOG_ERROR, "sub_packet_size is invalid\n");