From patchwork Fri Nov 10 21:09:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Jacobs X-Patchwork-Id: 5912 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp3857088jah; Fri, 10 Nov 2017 13:09:57 -0800 (PST) X-Google-Smtp-Source: AGs4zMZvaqryNehAF4Y+aqX30098TLKZwEHfYd+o8dQ9E3rAOVkBJSG/We/P11JmADb+H7GdsuSF X-Received: by 10.28.100.212 with SMTP id y203mr1270112wmb.64.1510348197322; Fri, 10 Nov 2017 13:09:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510348197; cv=none; d=google.com; s=arc-20160816; b=0RiWNJTUTc51AF09yIwHT+brw5j3PlD76Ktj8un/ypIeN+TIcumfi4aMqfleZuAPzT EOJ3I//Hs7MzrzJsnjhFs8HqCmZObUqVst15H3cOpJbleNpkObGMsi6heMwm39GeMWxo RSF6KqLBwES4Ot0QIONVDR0zYLcBNOJhHbx6EBiE3GN2C/0cjAGDLMv8vHrjosDG70d1 DTT1sBSvzgcYS3kEuuHfA3BhIVHBY0NpZsPi+GGBwCQEG5y1VFIQPIA3ah2Y15dNBL7L cSwKtvgiEE94FZrkPJs28WMVBssMbz8XLV4b3RyHT1lSr3aD4fGOVwgygUbjXTiCDIVT FXpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to:arc-authentication-results; bh=NAP7dei/sZtVa0V3AM3s1fqRJvQo0zgJmOjLpngZ4Pc=; b=HpO9hgdqpi0eIJEJglH6ExiltJ33Mco9omBTTvVdCBYTPUahidyOX6JULIKm3c60W2 ztxdBhEmodzLkiBKds0QyP9cCZ2PBBk37t30RmqSwg0835vPJ9yMzK7YzghzSkRQm1Wk mBfLEyAghT+oJSaVpNxU9adDKKbyD1XEmkrPll3Kk0o9YPcx9hDhuXu5FGgPXwmKhePY rdtj/ZfRy/Qm+1+OAOUYh8CLJKRZGH9iZPPYrtNM8ec5Sup0RrnFgNkkSf8605PIVDQJ ms0KhSfjMvFCnfPprSQ/biHZnUWOZqZfvmshEvHNkU+0fH/pkP5J15NeKzEBAJ3Xkbix Couw== ARC-Authentication-Results: i=1; mx.google.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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w8si9254252wra.407.2017.11.10.13.09.56; Fri, 10 Nov 2017 13:09:57 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9832D689EA7; Fri, 10 Nov 2017 23:09:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp6-g21.free.fr (smtp6-g21.free.fr [212.27.42.6]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E6647689E77 for ; Fri, 10 Nov 2017 23:09:35 +0200 (EET) Received: from marge.gnuage.org (unknown [IPv6:2a01:e35:2e26:9790::10]) by smtp6-g21.free.fr (Postfix) with ESMTPS id 6256A780395 for ; Fri, 10 Nov 2017 22:09:49 +0100 (CET) Received: from [2a01:e35:2e26:9790:bc8a:b994:5b68:84cc] (helo=xps) by marge.gnuage.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1eDGYe-0004O4-8q; Fri, 10 Nov 2017 22:09:48 +0100 Received: from aurel by xps with local (Exim 4.89) (envelope-from ) id 1eDGYd-0003eJ-Vp; Fri, 10 Nov 2017 22:09:47 +0100 From: Aurelien Jacobs To: FFmpeg development discussions and patches Date: Fri, 10 Nov 2017 22:09:24 +0100 Message-Id: <20171110210924.13976-2-aurel@gnuage.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171110210924.13976-1-aurel@gnuage.org> References: <20171110210924.13976-1-aurel@gnuage.org> X-SA-Exim-Connect-IP: 2a01:e35:2e26:9790:bc8a:b994:5b68:84cc X-SA-Exim-Mail-From: aurel@gnuage.org X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on marge.gnuage.org X-Spam-Level: X-Spam-Status: No, score=-0.2 required=3.0 tests=BAYES_00, FSL_HELO_NON_FQDN_1, RDNS_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.1 X-SA-Exim-Version: 4.2.1 (built Tue, 02 Aug 2016 21:08:31 +0000) X-SA-Exim-Scanned: Yes (on marge.gnuage.org) Subject: [FFmpeg-devel] [PATCH 2/2] aptx: add raw muxer and demuxer for aptX 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 Cc: Aurelien Jacobs MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- doc/general.texi | 1 + libavformat/Makefile | 2 ++ libavformat/allformats.c | 1 + libavformat/aptxdec.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++ libavformat/rawenc.c | 13 ++++++++ libavformat/utils.c | 1 + 6 files changed, 96 insertions(+) create mode 100644 libavformat/aptxdec.c diff --git a/doc/general.texi b/doc/general.texi index de4efee913..efd4a92495 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -441,6 +441,7 @@ library: @item raw AC-3 @tab X @tab X @item raw AMR-NB @tab @tab X @item raw AMR-WB @tab @tab X +@item raw aptX @tab X @tab X @item raw Chinese AVS video @tab X @tab X @item raw CRI ADX @tab X @tab X @item raw Dirac @tab X @tab X diff --git a/libavformat/Makefile b/libavformat/Makefile index 146a4656f2..b1e7b193f4 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -94,6 +94,8 @@ OBJS-$(CONFIG_APC_DEMUXER) += apc.o OBJS-$(CONFIG_APE_DEMUXER) += ape.o apetag.o img2.o OBJS-$(CONFIG_APNG_DEMUXER) += apngdec.o OBJS-$(CONFIG_APNG_MUXER) += apngenc.o +OBJS-$(CONFIG_APTX_DEMUXER) += aptxdec.o rawdec.o +OBJS-$(CONFIG_APTX_MUXER) += rawenc.o OBJS-$(CONFIG_AQTITLE_DEMUXER) += aqtitledec.o subtitles.o OBJS-$(CONFIG_ASF_DEMUXER) += asfdec_f.o asf.o asfcrypt.o \ avlanguage.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 1896d50e9e..9213af9301 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -69,6 +69,7 @@ static void register_all(void) REGISTER_DEMUXER (APC, apc); REGISTER_DEMUXER (APE, ape); REGISTER_MUXDEMUX(APNG, apng); + REGISTER_MUXDEMUX(APTX, aptx); REGISTER_DEMUXER (AQTITLE, aqtitle); REGISTER_MUXDEMUX(ASF, asf); REGISTER_DEMUXER (ASF_O, asf_o); diff --git a/libavformat/aptxdec.c b/libavformat/aptxdec.c new file mode 100644 index 0000000000..3b8fae1b55 --- /dev/null +++ b/libavformat/aptxdec.c @@ -0,0 +1,78 @@ +/* + * RAW aptX demuxer + * + * Copyright (C) 2017 Aurelien Jacobs + * + * 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 "rawdec.h" + +#define APTX_BLOCK_SIZE 4 +#define APTX_PACKET_SIZE (256*APTX_BLOCK_SIZE) + +typedef struct AptXDemuxerContext { + AVClass *class; + int sample_rate; +} AptXDemuxerContext; + +static int aptx_read_header(AVFormatContext *s) +{ + AptXDemuxerContext *s1 = s->priv_data; + AVStream *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_APTX; + st->codecpar->format = AV_SAMPLE_FMT_S32P; + st->codecpar->channels = 2; + st->codecpar->sample_rate = s1->sample_rate; + st->codecpar->bits_per_coded_sample = 4; + st->codecpar->block_align = APTX_BLOCK_SIZE; + st->codecpar->frame_size = APTX_PACKET_SIZE; + st->start_time = 0; + return 0; +} + +static int aptx_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + return av_get_packet(s->pb, pkt, APTX_PACKET_SIZE); +} + +static const AVOption aptx_options[] = { + { "sample_rate", "", offsetof(AptXDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, + { NULL }, +}; + +static const AVClass aptx_demuxer_class = { + .class_name = "aptx demuxer", + .item_name = av_default_item_name, + .option = aptx_options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVInputFormat ff_aptx_demuxer = { + .name = "aptx", + .long_name = NULL_IF_CONFIG_SMALL("raw aptX"), + .extensions = "aptx", + .priv_data_size = sizeof(AptXDemuxerContext), + .read_header = aptx_read_header, + .read_packet = aptx_read_packet, + .flags = AVFMT_GENERIC_INDEX, + .priv_class = &aptx_demuxer_class, +}; diff --git a/libavformat/rawenc.c b/libavformat/rawenc.c index f640121cb4..aa3ef76fbf 100644 --- a/libavformat/rawenc.c +++ b/libavformat/rawenc.c @@ -91,6 +91,19 @@ AVOutputFormat ff_adx_muxer = { }; #endif +#if CONFIG_APTX_MUXER +AVOutputFormat ff_aptx_muxer = { + .name = "aptx", + .long_name = NULL_IF_CONFIG_SMALL("raw aptX (Audio Processing Technology for Bluetooth)"), + .extensions = "aptx", + .audio_codec = AV_CODEC_ID_APTX, + .video_codec = AV_CODEC_ID_NONE, + .write_header = force_one_stream, + .write_packet = ff_raw_write_packet, + .flags = AVFMT_NOTIMESTAMPS, +}; +#endif + #if CONFIG_CAVSVIDEO_MUXER AVOutputFormat ff_cavsvideo_muxer = { .name = "cavsvideo", diff --git a/libavformat/utils.c b/libavformat/utils.c index 2b2411ffe7..d45a6b55a7 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -324,6 +324,7 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, } fmt_id_type[] = { { "aac", AV_CODEC_ID_AAC, AVMEDIA_TYPE_AUDIO }, { "ac3", AV_CODEC_ID_AC3, AVMEDIA_TYPE_AUDIO }, + { "aptx", AV_CODEC_ID_APTX, AVMEDIA_TYPE_AUDIO }, { "dts", AV_CODEC_ID_DTS, AVMEDIA_TYPE_AUDIO }, { "dvbsub", AV_CODEC_ID_DVB_SUBTITLE,AVMEDIA_TYPE_SUBTITLE }, { "dvbtxt", AV_CODEC_ID_DVB_TELETEXT,AVMEDIA_TYPE_SUBTITLE },