From patchwork Sun Oct 1 16:23:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Carl Eugen Hoyos X-Patchwork-Id: 5359 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.61.8 with SMTP id n8csp628572jan; Sun, 1 Oct 2017 09:24:21 -0700 (PDT) X-Received: by 10.223.136.218 with SMTP id g26mr108530wrg.86.1506875060952; Sun, 01 Oct 2017 09:24:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506875060; cv=none; d=google.com; s=arc-20160816; b=RLd4d6w0s20DCLqOqZn2R+5KqIUoAQ95Vbw8z4Wk3PKSJV5VxtaFUSh8wuO8BWDZjd pIsQr7aqeAJRN2IBdvO7Jsd4iwXEWNBi/S47kwHr1kME6UyGDe3BoldM5HzdQ8rV9HFL ITNky4FGOTcHeWL9bIZdtG5b2M0FFVBzyplD0EhJ4V9XAa1NPbssnUg94HfocHJrO+gX Vo4yNL6sd/OCOcAP/fbFGhsdn6AI2wDCin02pZKPYM7bAzd0BsTXJ7tMZFTGk/eMulXM +OvQJBFN0YrBGj4qMP+dJfy5tkpW9+5kw54iPVo6UBLbzR6e+4k5+Xgspa5oXDBFy3dy RMuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:delivered-to:arc-authentication-results; bh=k2JR8qg2BhfYT54p+YdAH9gJm9mfFBiFaGAHuICshj8=; b=xaFwUazwhWpiqy3pYoSf5nuKEEAt3RU6Sie8mL9xYh9OfyV+7Cvk1NlPiKoWT/Px3K HGuahE/mXy4LUmdly1YBXYbIAdv7ZZM+soCrleVcItkiZgSQzkhvRgTLDG7Dcbw57stN ckLrx5QAL0aM8221vrs05WL7nI2DZJLjMvooI5+k5BMa2Y6QMIyWQ8VVAuKIm61v/P3M qIg92Zih/gGaY6uR5DHafrmJKgswBjhfQgjfRv79CPEhpfxpMYRitkM4VaUZOuxpTE5C GBr7m6JyaX1P/yCnsMi3mzzVrj58O72qChD2s/EbgHft1uDVEOLMnZSAVoQV6Wc8TK28 HlIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=FptNVk29; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 8si6106376wmq.79.2017.10.01.09.24.20; Sun, 01 Oct 2017 09:24:20 -0700 (PDT) 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 header.s=20161025 header.b=FptNVk29; 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 950D0689B49; Sun, 1 Oct 2017 19:24:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io0-f171.google.com (mail-io0-f171.google.com [209.85.223.171]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9BC32689A34 for ; Sun, 1 Oct 2017 19:23:58 +0300 (EEST) Received: by mail-io0-f171.google.com with SMTP id n69so3118214ioi.5 for ; Sun, 01 Oct 2017 09:24:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=556JwCkhlJOa806j9LVl0OiZ1DeVRpn156ObCPpOieE=; b=FptNVk295TJK0oM+cbzawcpACgvJ65Ji4dqm7hiJZIqX5w615wXgAdNFK17NDQnEzy DRmjbDJVil+d/o4fx99bh3kTxKnhiS7HmkExPIwtUyn0bPSQJIGa+eQ0czIteVSv8v/b UqnThhfJCbnxFCqo9aIIT5GR+sFeighOchO40XOMeeE+2KDy8ucaIgSmfvadm/H9dChV Y4IvECY0lUGjkpH8zBvm/Y2jRel7I3khKJLbqfqkhI2K+OnWJZsGmxqAjYZPv23PXI8o j6WrWMp5gJOp5RFLGI6bSkKHJCPSyTQHlToOyLxUuf+dDUpSaeSfPMnP1N9b+xW4J0uM Ep1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=556JwCkhlJOa806j9LVl0OiZ1DeVRpn156ObCPpOieE=; b=eUV1hdaHoU4YMwnreSWOm7B15SiKaIrRZecW3WFIk6il7kwYB0S/OzTuzjLV/DoDlo MqWXUCHYbIx5CwgjiTEU9ACTEaQKcrBePp7kqbQ3zymVRCVfIHr0rRq9uMpcgGzUR3n9 yoNw9AeakaW2pwXzAP5+wwFMqaWR5+Vp+cejqqb8qB+6lIHO7qw/TGxesvkJKZmk3Ykx kCwU7sia9G1aVclfLVaUhayvoMJUea5hvbQkwNgZViKi6ot0YeWiu/054FoWA+DS+KeE P/TNiQDCCAvGkgnbGTLq3e0kaM6VVdoL2yJ3gyJDh+xQD0NsHAYUpB/e7fzM9p8jnlKn MYSA== X-Gm-Message-State: AMCzsaW+VLraDaGg6c4YcsWM261isjdZtkJN/RaSH8sxBJ2C+E3RvC5o HA+MeETgEwSN5okXU+jhYcHxenJE1p23mGI8Y8I= X-Google-Smtp-Source: AOwi7QAzoRgljQTyQHUWCNmrBQU+uRncM5Iswl0ax9Q4+AjSASkqiiFMhi/Be6SL0NzReOlhO5nydsOqUFwHyHf/UXQ= X-Received: by 10.107.10.9 with SMTP id u9mr22873440ioi.107.1506875051213; Sun, 01 Oct 2017 09:24:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.2.81.137 with HTTP; Sun, 1 Oct 2017 09:23:50 -0700 (PDT) In-Reply-To: References: From: Carl Eugen Hoyos Date: Sun, 1 Oct 2017 18:23:50 +0200 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH]lavf/amr: Add amrnb and amrwb demuxers 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 2017-09-27 18:08 GMT+02:00 Carl Eugen Hoyos : > The existing amr demuxer does not allow reading streams, > it requires the 3GPP-conforming file header. > Attached patch allows reading amrnb and amrwb from (live) > streams, fixes ticket #6678. New patch with auto-detection attached, passes probecheck. Please comment, Carl Eugen From 5539b3a9f6195fed91cbf10d4ecb2b7e6c75ac99 Mon Sep 17 00:00:00 2001 From: Carl Eugen Hoyos Date: Sun, 1 Oct 2017 18:13:14 +0200 Subject: [PATCH] lavf/amr: Add amrnb and amrwb demuxers. Fixes ticket #6678. --- libavformat/Makefile | 2 ++ libavformat/allformats.c | 2 ++ libavformat/amr.c | 10 ++----- libavformat/amr.h | 34 +++++++++++++++++++++ libavformat/amrnb.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ libavformat/amrwb.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ libavformat/version.h | 4 +-- 7 files changed, 189 insertions(+), 9 deletions(-) create mode 100644 libavformat/amr.h create mode 100644 libavformat/amrnb.c create mode 100644 libavformat/amrwb.c diff --git a/libavformat/Makefile b/libavformat/Makefile index df709c29..bf8fb86 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -87,6 +87,8 @@ OBJS-$(CONFIG_AIFF_MUXER) += aiffenc.o id3v2enc.o OBJS-$(CONFIG_AIX_DEMUXER) += aixdec.o OBJS-$(CONFIG_AMR_DEMUXER) += amr.o OBJS-$(CONFIG_AMR_MUXER) += amr.o +OBJS-$(CONFIG_AMRNB_DEMUXER) += amrnb.o +OBJS-$(CONFIG_AMRWB_DEMUXER) += amrwb.o OBJS-$(CONFIG_ANM_DEMUXER) += anm.o OBJS-$(CONFIG_APC_DEMUXER) += apc.o OBJS-$(CONFIG_APE_DEMUXER) += ape.o apetag.o img2.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 405ddb5..dc8984e 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -63,6 +63,8 @@ static void register_all(void) REGISTER_MUXDEMUX(AIFF, aiff); REGISTER_DEMUXER (AIX, aix); REGISTER_MUXDEMUX(AMR, amr); + REGISTER_DEMUXER (AMRNB, amrnb); + REGISTER_DEMUXER (AMRWB, amrwb); REGISTER_DEMUXER (ANM, anm); REGISTER_DEMUXER (APC, apc); REGISTER_DEMUXER (APE, ape); diff --git a/libavformat/amr.c b/libavformat/amr.c index b5194a2..40653ce 100644 --- a/libavformat/amr.c +++ b/libavformat/amr.c @@ -29,11 +29,7 @@ Only mono files are supported. #include "libavutil/channel_layout.h" #include "avformat.h" #include "internal.h" - -typedef struct { - uint64_t cumulated_size; - uint64_t block_count; -} AMRContext; +#include "amr.h" static const char AMR_header[] = "#!AMR\n"; static const char AMRWB_header[] = "#!AMR-WB\n"; @@ -110,7 +106,7 @@ static int amr_read_header(AVFormatContext *s) return 0; } -static int amr_read_packet(AVFormatContext *s, AVPacket *pkt) +int ff_amr_read_packet(AVFormatContext *s, AVPacket *pkt) { AVCodecParameters *par = s->streams[0]->codecpar; int read, size = 0, toc, mode; @@ -171,7 +167,7 @@ AVInputFormat ff_amr_demuxer = { .priv_data_size = sizeof(AMRContext), .read_probe = amr_probe, .read_header = amr_read_header, - .read_packet = amr_read_packet, + .read_packet = ff_amr_read_packet, .flags = AVFMT_GENERIC_INDEX, }; #endif diff --git a/libavformat/amr.h b/libavformat/amr.h new file mode 100644 index 0000000..5c3760e --- /dev/null +++ b/libavformat/amr.h @@ -0,0 +1,34 @@ +/* + * amr file format + * Copyright (c) 2001 FFmpeg project + * + * 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 AVFORMAT_AMR_H +#define AVFORMAT_AMR_H + +#include "avformat.h" + +typedef struct { + uint64_t cumulated_size; + uint64_t block_count; +} AMRContext; + +int ff_amr_read_packet(AVFormatContext *s, AVPacket *pkt); + +#endif diff --git a/libavformat/amrnb.c b/libavformat/amrnb.c new file mode 100644 index 0000000..cdfe976 --- /dev/null +++ b/libavformat/amrnb.c @@ -0,0 +1,73 @@ +/* + * amr-nb file format + * Copyright (c) 2017 Carl Eugen Hoyos + * + * 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 "avformat.h" +#include "amr.h" +#include "internal.h" +#include "libavutil/internal.h" +#include "libavcodec/amrnbdata.h" + +static int amrnb_read_header(AVFormatContext *s) +{ + AVStream *st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codecpar->codec_tag = MKTAG('s', 'a', 'm', 'r'); + st->codecpar->codec_id = AV_CODEC_ID_AMR_NB; + st->codecpar->sample_rate = 8000; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + avpriv_set_pts_info(st, 64, 1, 8000); + + return 0; +} + +static int amrnb_probe(AVProbeData *p) +{ + int i, valid = 0; + const uint8_t *b = p->buf; + enum Mode mode; + + while (i < p->buf_size) { + mode = b[i] >> 3 & 0x0F; + if (mode < N_MODES && (b[i] & 0x4) == 0x4) { + i += frame_sizes_nb[mode] + 1; + valid++; + } else { + valid = 0; + i++; + } + } + if (valid > 100) + return AVPROBE_SCORE_EXTENSION / 2 + 1; + return 0; +} + +AVInputFormat ff_amrnb_demuxer = { + .name = "amrnb", + .long_name = NULL_IF_CONFIG_SMALL("raw AMR-NB"), + .priv_data_size = sizeof(AMRContext), + .read_probe = amrnb_probe, + .read_header = amrnb_read_header, + .read_packet = ff_amr_read_packet, + .flags = AVFMT_GENERIC_INDEX, +}; diff --git a/libavformat/amrwb.c b/libavformat/amrwb.c new file mode 100644 index 0000000..2aa631b --- /dev/null +++ b/libavformat/amrwb.c @@ -0,0 +1,73 @@ +/* + * amr-wb file format + * Copyright (c) 2017 Carl Eugen Hoyos + * + * 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 "avformat.h" +#include "amr.h" +#include "internal.h" +#include "libavutil/internal.h" +#include "libavcodec/amrwbdata.h" + +static int amrwb_probe(AVProbeData *p) +{ + int i, valid = 0; + const uint8_t *b = p->buf; + enum Mode mode; + + while (i < p->buf_size) { + mode = b[i] >> 3 & 0x0F; + if (mode <= MODE_SID && (b[i] & 0x4) == 0x4) { + i += ((cf_sizes_wb[mode] + 7) >> 3) + 1; + valid++; + } else { + valid = 0; + i++; + } + } + if (valid > 100) + return AVPROBE_SCORE_EXTENSION / 2 + 1; + return 0; +} + +static int amrwb_read_header(AVFormatContext *s) +{ + AVStream *st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codecpar->codec_tag = MKTAG('s', 'a', 'w', 'b'); + st->codecpar->codec_id = AV_CODEC_ID_AMR_WB; + st->codecpar->sample_rate = 16000; + st->codecpar->channels = 1; + st->codecpar->channel_layout = AV_CH_LAYOUT_MONO; + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + avpriv_set_pts_info(st, 64, 1, 16000); + + return 0; +} + +AVInputFormat ff_amrwb_demuxer = { + .name = "amrwb", + .long_name = NULL_IF_CONFIG_SMALL("raw AMR-WB"), + .priv_data_size = sizeof(AMRContext), + .read_probe = amrwb_probe, + .read_header = amrwb_read_header, + .read_packet = ff_amr_read_packet, + .flags = AVFMT_GENERIC_INDEX, +}; diff --git a/libavformat/version.h b/libavformat/version.h index ac6edf7..878917d 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -32,8 +32,8 @@ // Major bumping may affect Ticket5467, 5421, 5451(compatibility with Chromium) // Also please add any ticket numbers that you believe might be affected here #define LIBAVFORMAT_VERSION_MAJOR 57 -#define LIBAVFORMAT_VERSION_MINOR 82 -#define LIBAVFORMAT_VERSION_MICRO 102 +#define LIBAVFORMAT_VERSION_MINOR 83 +#define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ -- 1.7.10.4