From patchwork Wed Jan 2 18:53:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 11634 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 84CB444E01B for ; Wed, 2 Jan 2019 21:00:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 19FB568A062; Wed, 2 Jan 2019 21:00:05 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D0C14689E94 for ; Wed, 2 Jan 2019 20:59:58 +0200 (EET) Received: by mail-wr1-f68.google.com with SMTP id p4so31471628wrt.7 for ; Wed, 02 Jan 2019 11:00:07 -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=mUAiC+PoVSnRtwi9EHw3ino/AAtjtHlSxmYz8v4hpBg=; b=uqf83f9Arqu0AV7kN1f8g8DI0lYh0ALj0rRLXbDfLny7mWDTDfTwMh4MaMS7XZAiZs lhCNaS7EA0v9J0ZE/tnoaXXHC8v/yDOozgDjw4AxFCzNtU+Q6WpF7LVUMJViskFMk+G3 +JjnOGAlbMX9x6z+VItoH4bBc66bVA9sjF83S6rO7Wq/zIg5EIxHdFg6eYtzuxoTNQDn hUFEsNWAjIMVeDGOJ1esIzX/R5vbaADwK9qjS9WL7L38lRjSBM9qlaXi0NTK74J6Ob4/ bm+Dh7+fDnNL48zIsGnhMSTfvoPuB+IRHK50VL2sVy7Dr+/v+GU9vWKjsSKQiItJfyzz Nw8Q== 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=mUAiC+PoVSnRtwi9EHw3ino/AAtjtHlSxmYz8v4hpBg=; b=dSS6oG4GLopVQDWJVZ/FrG6dBuTYFk5Q3dNO+/woGTdBmIexI8vksVCDNBBrw7M3FM eOnTvzYxnz1tCLAQeICU7N50PpV4vTsdh+c+/e4H/jOybUI0wo7efO7nE6idxEVuuaMf D2loVLfPMqNrZhtge3XcJ/LyvtXuAUjmFdIv+zu/MwKDQ+d6B54PJrmmfZD4kcb++oJX 305ww/5pZ/TaL4YRwQoNuSpecXgPWrgju7bp4r0cHUPaAwRGNTdMBy2mKhtTxlnjBtwC rS/Z1wr9e6ojrlASOFszlwMUIkf7xSC0Wir+9XC830NoC3xvtVrZeuIgkiCPv0U0i/Uf jmBg== X-Gm-Message-State: AJcUukfECRiYrCcJY/CaRXMLYSbFPMjUzux/KrIrwviLuoe4PaUlyRDn 8d0NWYP/cSKMuiq7wUGp6MfT7mE6 X-Google-Smtp-Source: ALg8bN4OPT4K8Mp6kzTL1HT2PmMakjfURoo5Ekrdyf9gRkbGl01XRlXRINOKXbrvl+6+F3DuyXWWuA== X-Received: by 2002:adf:d243:: with SMTP id o3mr40638027wri.66.1546455228727; Wed, 02 Jan 2019 10:53:48 -0800 (PST) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id o16sm52276836wrn.11.2019.01.02.10.53.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Jan 2019 10:53:48 -0800 (PST) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Jan 2019 19:53:38 +0100 Message-Id: <20190102185338.4910-2-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190102185338.4910-1-onemda@gmail.com> References: <20190102185338.4910-1-onemda@gmail.com> Subject: [FFmpeg-devel] [PATCH 2/2] avformat: add HCOM 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/allformats.c | 1 + libavformat/hcom.c | 89 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 libavformat/hcom.c diff --git a/libavformat/Makefile b/libavformat/Makefile index c42ceb40c5..c010fc83f9 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -219,6 +219,7 @@ OBJS-$(CONFIG_H263_MUXER) += rawenc.o OBJS-$(CONFIG_H264_DEMUXER) += h264dec.o rawdec.o OBJS-$(CONFIG_H264_MUXER) += rawenc.o OBJS-$(CONFIG_HASH_MUXER) += hashenc.o +OBJS-$(CONFIG_HCOM_DEMUXER) += hcom.o OBJS-$(CONFIG_HDS_MUXER) += hdsenc.o OBJS-$(CONFIG_HEVC_DEMUXER) += hevcdec.o rawdec.o OBJS-$(CONFIG_HEVC_MUXER) += rawenc.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 399625fd78..06844986f3 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -176,6 +176,7 @@ extern AVOutputFormat ff_h263_muxer; extern AVInputFormat ff_h264_demuxer; extern AVOutputFormat ff_h264_muxer; extern AVOutputFormat ff_hash_muxer; +extern AVInputFormat ff_hcom_demuxer; extern AVOutputFormat ff_hds_muxer; extern AVInputFormat ff_hevc_demuxer; extern AVOutputFormat ff_hevc_muxer; diff --git a/libavformat/hcom.c b/libavformat/hcom.c new file mode 100644 index 0000000000..933ecce373 --- /dev/null +++ b/libavformat/hcom.c @@ -0,0 +1,89 @@ +/* + * HCOM 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/intreadwrite.h" +#include "libavcodec/internal.h" +#include "avformat.h" +#include "internal.h" +#include "pcm.h" + +static int hcom_probe(AVProbeData *p) +{ + if (!memcmp(p->buf+65, "FSSD", 4) && + !memcmp(p->buf+128, "HCOM", 4)) + return AVPROBE_SCORE_MAX; + return 0; +} + +static int hcom_read_header(AVFormatContext *s) +{ + AVStream *st; + unsigned data_size, rsrc_size, huffcount; + unsigned compresstype, divisor; + unsigned dict_entries; + int ret; + + avio_skip(s->pb, 83); + data_size = avio_rb32(s->pb); + rsrc_size = avio_rb32(s->pb); + avio_skip(s->pb, 128-91+4); + huffcount = avio_rb32(s->pb); + avio_skip(s->pb, 4); + compresstype = avio_rb32(s->pb); + if (compresstype > 1) + return AVERROR_INVALIDDATA; + divisor = avio_rb32(s->pb); + if (divisor == 0 || divisor > 4) + return AVERROR_INVALIDDATA; + dict_entries = avio_rb16(s->pb); + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + st->codecpar->channels = 1; + st->codecpar->sample_rate = 22050 / divisor; + st->codecpar->codec_id = AV_CODEC_ID_HCOM; + st->codecpar->bits_per_coded_sample = 8; + st->codecpar->block_align = 4; + + ret = ff_alloc_extradata(st->codecpar, dict_entries * 4 + 7); + if (ret < 0) + return ret; + AV_WB16(st->codecpar->extradata, dict_entries); + AV_WB32(st->codecpar->extradata + 2, compresstype); + avio_read(s->pb, st->codecpar->extradata + 6, dict_entries * 4); + avio_skip(s->pb, 1); + st->codecpar->extradata[dict_entries * 4 + 6] = avio_r8(s->pb); + + avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); + + return 0; +} + +AVInputFormat ff_hcom_demuxer = { + .name = "hcom", + .long_name = NULL_IF_CONFIG_SMALL("Macintosh HCOM"), + .read_probe = hcom_probe, + .read_header = hcom_read_header, + .read_packet = ff_pcm_read_packet, +};