From patchwork Wed Mar 4 22:26:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 18027 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2D8AF44ACEA for ; Thu, 5 Mar 2020 00:33:00 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0C80E68B51C; Thu, 5 Mar 2020 00:33:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 31F4A689D14 for ; Thu, 5 Mar 2020 00:32:54 +0200 (EET) Received: by mail-wm1-f65.google.com with SMTP id p9so4053188wmc.2 for ; Wed, 04 Mar 2020 14:32:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=9xCnPd51kP4vkES8nX/0xDBexfl5W220C7Tme+loMR4=; b=DyD+AJFCJ53NAjIaa9SefpMFw1CjO7BXc2XQ2GeBO4h5m2sBNPziz8Qp2UGBfOwG8d MEF5imRy+/ZdtTzv9IPoSTJhqgrHyNp8/NQcoh8gIv1HKQQSuvCNaNE6DNLdB53Wr2CN R0mEk40RTQmyaHh5nfyCwNkk5b5CBgVauZXSDDY7lFMWQtZoUdinzc7s1n9TvdowIPlM 8XZfRfBePN+xdhV4xOo4/uJi5IyDycYjwfh/NtQFD2xnhOLAHwb0jI7UMBiZPj67cDPs JeIYxJZnmj8h+RcASUrRaW18py7R3tTKhzrCgtX6olwklepByBc1mZFt4Lfo81VXhrsE 79Ng== 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:in-reply-to :references; bh=9xCnPd51kP4vkES8nX/0xDBexfl5W220C7Tme+loMR4=; b=sVppcvgXl+KsIP50aLIR4YjTTTlnDhZQlX1p7SnwR4FpieG3EdywGXtqrFeVGs7ExV 8qtjVV844i1X9Qmi267kvshygzRGd3tI5Ff8RH0uisje6Emzc8g4ZPzicn0bjky1NTV8 Oxpb8ckr5Ce4GM3Dz96pDgLeMPsNKqd+ZFCgTFPRGMiipIKXHv7J4lddkAJjH/fO7I/u ELXlBMC/1Engsn63Tn+7tu2e7tVNUN7Ai9K6oHZRYESC4XJN2eemq1/sa2yBhNJNwy5D v2VwgalmybLnhLbKFEzYEQNgFZx89B/tNo9bbxLUdreFylQX+RmB8qj9tPcXVnSLInCm OyCQ== X-Gm-Message-State: ANhLgQ2nlR/hUksdINtko0YcrOqD2WXiahijA0oCRwfH1JfAfIqj7tfp ceYJSWwnzXVdX9RZn/mX0VOjJOEr X-Google-Smtp-Source: ADFU+vt5dDtYFGZZAMNvTc+/KcIc0auPepYWSs0cjvL3k9YXwj/SIX+YkOzQqhVxF+GFWI2CIfSSfA== X-Received: by 2002:a7b:c148:: with SMTP id z8mr1148397wmi.174.1583360809359; Wed, 04 Mar 2020 14:26:49 -0800 (PST) Received: from localhost.localdomain ([109.227.41.139]) by smtp.gmail.com with ESMTPSA id 133sm6618096wmd.5.2020.03.04.14.26.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2020 14:26:48 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Wed, 4 Mar 2020 23:26:32 +0100 Message-Id: <20200304222633.12177-2-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200304222633.12177-1-onemda@gmail.com> References: <20200304222633.12177-1-onemda@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/3] avformat: add raw AC-4 demuxer 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" Signed-off-by: Paul B Mahol --- libavformat/Makefile | 1 + libavformat/ac4dec.c | 104 +++++++++++++++++++++++++++++++++++++++ libavformat/allformats.c | 1 + 3 files changed, 106 insertions(+) create mode 100644 libavformat/ac4dec.c diff --git a/libavformat/Makefile b/libavformat/Makefile index e0681058a2..b4e8d20e65 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -70,6 +70,7 @@ OBJS-$(CONFIG_AA_DEMUXER) += aadec.o OBJS-$(CONFIG_AAC_DEMUXER) += aacdec.o apetag.o img2.o rawdec.o OBJS-$(CONFIG_AC3_DEMUXER) += ac3dec.o rawdec.o OBJS-$(CONFIG_AC3_MUXER) += rawenc.o +OBJS-$(CONFIG_AC4_DEMUXER) += ac4dec.o OBJS-$(CONFIG_ACM_DEMUXER) += acm.o rawdec.o OBJS-$(CONFIG_ACT_DEMUXER) += act.o OBJS-$(CONFIG_ADF_DEMUXER) += bintext.o sauce.o diff --git a/libavformat/ac4dec.c b/libavformat/ac4dec.c new file mode 100644 index 0000000000..8c6e539409 --- /dev/null +++ b/libavformat/ac4dec.c @@ -0,0 +1,104 @@ +/* + * RAW AC-4 demuxer + * Copyright (c) 2019 Paul B Mahol + * + * 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 "libavutil/avassert.h" +#include "libavutil/crc.h" +#include "avformat.h" +#include "rawdec.h" + +static int ac4_probe(const AVProbeData *p) +{ + const uint8_t *buf = p->buf; + int left = p->buf_size; + int max_frames = 0; + + while (left > 7) { + int size; + + if (buf[0] == 0xAC && + (buf[1] == 0x40 || + buf[1] == 0x41)) { + size = (buf[2] << 8) | buf[3]; + if (size == 0xFFFF) + size = 3 + (buf[4] << 16) | (buf[5] << 8) | buf[6]; + size += 4; + if (buf[1] == 0x41) + size += 2; + max_frames++; + left -= size; + buf += size; + } else { + break; + } + } + + return FFMIN(AVPROBE_SCORE_MAX, max_frames * 7); +} + +static int ac4_read_header(AVFormatContext *s) +{ + AVStream *st; + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->codec_id = AV_CODEC_ID_AC4; + + return 0; +} + +static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + AVIOContext *pb = s->pb; + int64_t pos; + uint16_t sync; + int ret, size; + + if (avio_feof(s->pb)) + return AVERROR_EOF; + + pos = avio_tell(s->pb); + sync = avio_rb16(pb); + size = avio_rb16(pb); + if (size == 0xffff) + size = avio_rb24(pb); + + ret = av_get_packet(pb, pkt, size); + pkt->pos = pos; + pkt->stream_index = 0; + + if (sync == 0xAC41) + avio_skip(pb, 2); + + return ret; +} + +AVInputFormat ff_ac4_demuxer = { + .name = "ac4", + .long_name = NULL_IF_CONFIG_SMALL("raw AC-4"), + .read_probe = ac4_probe, + .read_header = ac4_read_header, + .read_packet = ac4_read_packet, + .flags = AVFMT_GENERIC_INDEX, + .extensions = "ac4", +}; diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 0209bf0e30..d2afcb2bdd 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -33,6 +33,7 @@ extern AVInputFormat ff_aa_demuxer; extern AVInputFormat ff_aac_demuxer; extern AVInputFormat ff_ac3_demuxer; extern AVOutputFormat ff_ac3_muxer; +extern AVInputFormat ff_ac4_demuxer; extern AVInputFormat ff_acm_demuxer; extern AVInputFormat ff_act_demuxer; extern AVInputFormat ff_adf_demuxer;