From patchwork Mon Dec 10 11:32:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Tomas_H=C3=A4rdin?= X-Patchwork-Id: 11358 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 C46D344C48A for ; Mon, 10 Dec 2018 13:32:33 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1D5AC68AB52; Mon, 10 Dec 2018 13:32:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.acc.umu.se (mail.acc.umu.se [130.239.18.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5333868AB45 for ; Mon, 10 Dec 2018 13:32:17 +0200 (EET) Received: from localhost (localhost.localdomain [127.0.0.1]) by amavisd-new (Postfix) with ESMTP id B355544B8F for ; Mon, 10 Dec 2018 12:32:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=acc.umu.se; s=mail1; t=1544441547; bh=hiMzMYK0mKyXpvSF28C3UxmlG2wSkpMgxC7x2HkRJV8=; h=Subject:From:To:Date:In-Reply-To:References:From; b=kzFCRnLqrnWudu2rJm2ykEGO+VB3kfiObHBLswQ8WnI2s0epLXerZ/a9YDCp7vf3U MX6JNyKNZVsB0XISjDbEEkP0K+ICyetxw0KGq8DLgGcBCiTxIw+5aUQ0r/fo1NKkNZ 7kqDCznAxbdiAoaNO4+0mjEdp18xLTC+hwfFXDlKrIPUuPBg6zHSPQC2ffVguEo51s oeFWP9SYzXwtdXxmVoy4pXr3xwthrcxz0v/mnmdDP7+uqcm0kLo3FQQ57WA0QqnVIs 5NoLV5RqtmgsPzRZZspk6r4Yxhb6sh5QUrmuo0ViFAv5rV2gaGK5fL3Gfmx/b/ZdbS DmoQbcp5NORMQ== Received: from laptop.lan (h-39-105.A258.priv.bahnhof.se [79.136.39.105]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: tjoppen) by mail.acc.umu.se (Postfix) with ESMTPSA id 6FF1A44B8B for ; Mon, 10 Dec 2018 12:32:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=acc.umu.se; s=mail1; t=1544441546; bh=hiMzMYK0mKyXpvSF28C3UxmlG2wSkpMgxC7x2HkRJV8=; h=Subject:From:To:Date:In-Reply-To:References:From; b=KgkGcZM2PjruirMHUNDb/ydvhudzxgrV6FDFENIQdlhsKkG3vJB9oHgMKJGA1KAjG fnrZ3TJu+WRHlWc9ylN4ygwhdw4fZw5F2wkL6BFd5ZfPChltR7i4nWR4k5F8SRX8EB tC4tHE1PaMr5DHB9bqa1PlspipYaGZL6xqnC6LLyR2f19IyoFe8a33lCwUekVvAwbX eH+n71gZEIcYDN3Z+97+zfX2h7Dbk1wP+rPkP5S+ikj9Tjujdx/fmV5f8bQdSzDXJN IXNDnXb8OLkLydBdduQPB3/xT/feG6ahem1yEgT+w5T7dH+VgzJvam+4Er/FYvrq4L FVpkUltkChDCQ== Message-ID: <1544441545.21980.18.camel@acc.umu.se> From: Tomas =?ISO-8859-1?Q?H=E4rdin?= To: FFmpeg development discussions and patches Date: Mon, 10 Dec 2018 12:32:25 +0100 In-Reply-To: <1544441511.21980.17.camel@acc.umu.se> References: <1544441511.21980.17.camel@acc.umu.se> X-Mailer: Evolution 3.22.6-1+deb9u1 Mime-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] Add CRYO APC muxer 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" From f08c1554f30839c7d42a9c5e677619f2c8b11c11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= Date: Thu, 22 Nov 2018 22:28:30 +0100 Subject: [PATCH 2/3] Add CRYO APC muxer --- Changelog | 1 + doc/general.texi | 2 +- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/apcenc.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++ libavformat/version.h | 4 +- 6 files changed, 125 insertions(+), 3 deletions(-) create mode 100644 libavformat/apcenc.c diff --git a/Changelog b/Changelog index 1f53ff46da..f678feed65 100644 --- a/Changelog +++ b/Changelog @@ -10,6 +10,7 @@ version : - truehd_core bitstream filter - dhav demuxer - PCM-DVD encoder +- CRYO APC muxer version 4.1: diff --git a/doc/general.texi b/doc/general.texi index d8832407bb..72da4019cb 100644 --- a/doc/general.texi +++ b/doc/general.texi @@ -400,7 +400,7 @@ library: @item CRC testing format @tab X @tab @item Creative Voice @tab X @tab X @tab Created for the Sound Blaster Pro. -@item CRYO APC @tab @tab X +@item CRYO APC @tab X @tab X @tab Audio format used in some games by CRYO Interactive Entertainment. @item D-Cinema audio @tab X @tab X @item Deluxe Paint Animation @tab @tab X diff --git a/libavformat/Makefile b/libavformat/Makefile index d0d621de07..1ac8c20cca 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -91,6 +91,7 @@ OBJS-$(CONFIG_AMRNB_DEMUXER) += amr.o OBJS-$(CONFIG_AMRWB_DEMUXER) += amr.o OBJS-$(CONFIG_ANM_DEMUXER) += anm.o OBJS-$(CONFIG_APC_DEMUXER) += apc.o +OBJS-$(CONFIG_APC_MUXER) += apcenc.o OBJS-$(CONFIG_APE_DEMUXER) += ape.o apetag.o img2.o OBJS-$(CONFIG_APNG_DEMUXER) += apngdec.o OBJS-$(CONFIG_APNG_MUXER) += apngenc.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 5fb5bf17c6..3bc1be430a 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -52,6 +52,7 @@ extern AVInputFormat ff_amrnb_demuxer; extern AVInputFormat ff_amrwb_demuxer; extern AVInputFormat ff_anm_demuxer; extern AVInputFormat ff_apc_demuxer; +extern AVOutputFormat ff_apc_muxer; extern AVInputFormat ff_ape_demuxer; extern AVInputFormat ff_apng_demuxer; extern AVOutputFormat ff_apng_muxer; diff --git a/libavformat/apcenc.c b/libavformat/apcenc.c new file mode 100644 index 0000000000..dba1b3b90c --- /dev/null +++ b/libavformat/apcenc.c @@ -0,0 +1,119 @@ +/* + * CRYO APC audio format muxer + * Copyright (c) 2018 Tomas Härdin + * + * 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 "avio_internal.h" +#include "internal.h" + +#define APC_HEADER_SIZE (8*4) + +static int apc_write_header(AVFormatContext *s) +{ + AVIOContext *pb = s->pb; + AVCodecParameters *par; + AVStream *st; + + if (s->nb_streams != 1) { + av_log(s, AV_LOG_ERROR, "Must have exactly one stream\n"); + return AVERROR(EINVAL); + } + + st = s->streams[0]; + par = st->codecpar; + + if (par->channels <= 0 || par->channels > 2) { + av_log(s, AV_LOG_ERROR, "Must be mono or stereo\n"); + return AVERROR(EINVAL); + } + + if (par->extradata_size != 0 && par->extradata_size != 8) { + av_log(s, AV_LOG_ERROR, + "Must have exactly 0 or 8 bytes of extradata, got %i\n", + par->extradata_size); + return AVERROR(EINVAL); + } + + ffio_wfourcc(pb, "CRYO"); + ffio_wfourcc(pb, "_APC"); + ffio_wfourcc(pb, "1.20"); + avio_wl32(pb, 0); //number or samples + avio_wl32(pb, par->sample_rate); + + //write extradata if we have it (remuxing) + //else write dummy values and wait for AV_PKT_DATA_NEW_EXTRADATA (encoding) + if (par->extradata_size) { + avio_write(pb, par->extradata, par->extradata_size); + } else { + avio_wl64(pb, 0); + } + + avio_wl32(pb, par->channels-1); + avpriv_set_pts_info(st, 64, 1, par->sample_rate); + return 0; +} + +static int apc_write_packet(AVFormatContext *s, AVPacket *pkt) +{ + int extradata_size = 0; + uint8_t *extradata = av_packet_get_side_data( + pkt, AV_PKT_DATA_NEW_EXTRADATA, &extradata_size); + + if (extradata_size == 8) { + //we got predictors from encoder + //try to seek back end write them + int64_t pos = avio_tell(s->pb); + if (avio_seek(s->pb, 20, SEEK_SET) > 0) { + avio_write(s->pb, extradata, extradata_size); + avio_seek(s->pb, pos, SEEK_SET); + } + } + + avio_write(s->pb, pkt->data, pkt->size); + return 0; +} + +static int apc_write_trailer(AVFormatContext *s) +{ + int64_t file_size = avio_tell(s->pb); + + //write length, if we're able to seek back + if (avio_seek(s->pb, 12, SEEK_SET) > 0) { + if (file_size - APC_HEADER_SIZE > + UINT32_MAX * s->streams[0]->codecpar->channels / 2) { + av_log(s, AV_LOG_ERROR, "File too large\n"); + return AVERROR(EINVAL); + } + + avio_wl32(s->pb, (file_size - APC_HEADER_SIZE) * + 2 / s->streams[0]->codecpar->channels); + } + return 0; +} + +AVOutputFormat ff_apc_muxer = { + .name = "apc", + .long_name = NULL_IF_CONFIG_SMALL("CRYO APC"), + .extensions = "apc", + .audio_codec = AV_CODEC_ID_ADPCM_IMA_APC, + .write_header = apc_write_header, + .write_packet = apc_write_packet, + .write_trailer = apc_write_trailer, +}; + diff --git a/libavformat/version.h b/libavformat/version.h index 30f2a84ddb..391ebed462 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 58 -#define LIBAVFORMAT_VERSION_MINOR 23 -#define LIBAVFORMAT_VERSION_MICRO 102 +#define LIBAVFORMAT_VERSION_MINOR 24 +#define LIBAVFORMAT_VERSION_MICRO 100 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ -- 2.11.0