From patchwork Fri Jun 2 19:56:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 3803 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.2 with SMTP id 2csp351672vsk; Fri, 2 Jun 2017 13:03:17 -0700 (PDT) X-Received: by 10.223.154.10 with SMTP id z10mr6195198wrb.76.1496433797261; Fri, 02 Jun 2017 13:03:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496433797; cv=none; d=google.com; s=arc-20160816; b=x20CYJEf6NAcSRwxeKdREAQHXAUiKYg20Ve0QsjU6PV55S36NbWVD9fcgg38JZ8gCd Pf7tGNX/QT0Q3M7Cum03TSwenE8BP3TD9UhFRS18o/E8UFwt2M+J0AGCJ+mgmFj3XFsN 5dlAzruSD+RJlFSjEMAh3w8imFLE+YNGe423QEAyrtgSRtto0yV/68w9KgCjv35TPxgd HDykpb17PF+Refw+VUWr5m+jIZlVbNI36DRm3uOZWZXabVcrd7fJfZOJLjSLr+Kq1L7r qLefMvC1AUb9rCQLrwUfLdGggOVN11jL6XKBoq2Ct3mtSWQ49VVKPFF0uRgiDBK2qMoH Cv+Q== 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: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:dkim-signature:delivered-to:arc-authentication-results; bh=Bjbc1USka38a6UkqgzCJRkVrvBIl/ohwY61bylWHcwY=; b=O3WpygED8Wfe54MMx8W+9wn4YuKF7WOlpoGHsr7w/YunBo4ib9VXifhpWMFrKeoIz3 apJqYJhbx6oG5TuRBDZdWx6w1pwiFXNVyf+1euf8b+MoCfssgL8SxkzY7+l02Sfp7aZ0 P7d2GfEV5Yw8cbi55Z3xwJA3VJzvR5EKPDUy1tT4XC37vPQrQVK5WSoC8gu4T1qDlAck j7PWyct9hWQtyN+5HYEZwC/8hFJlEpat8rLWOrN353KIgyD6KJMTv/oJknCRRw/fRK77 MugCk+b0pE5ZgIYt1i/TSWQtY/G5r2h4N7dsak114SKyvthqeo464oieqb8QQKc6f2Si TWpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.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; 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 b187si2039977wmd.25.2017.06.02.13.03.15; Fri, 02 Jun 2017 13:03:17 -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; 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 E2040689C59; Fri, 2 Jun 2017 23:03:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 87E8B689BF3 for ; Fri, 2 Jun 2017 23:03:01 +0300 (EEST) Received: by mail-wm0-f65.google.com with SMTP id g15so20545668wmc.2 for ; Fri, 02 Jun 2017 13:03:07 -0700 (PDT) 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=XbZYx4rCGKiIztQSDCfQaznbAQmiPPzpJUW3eLO1QQE=; b=f2mX+SLEpsVcTJWKXuWRAqI+4F2UNNuH2tODnoyUe44XMVUqWJagWAwam9EML8r2b5 HLtKFAzgBhy1qVZN49vZhVHjQYZKbN0bpSz8yZq5ry9+Cub4vuMj9G3LNarEn2ToJlgL p7YYICnorB22kNMeGu7WikMHe0QwsApkG9n1JyTpC8KjLdTm5mj8Zc49jGYgDpEisopD f8KKJDsSj8XDFeTP6BEQlIDGZgzEYvR7bu+C9ylkcfTZOZubjxg5F8s6nO1guXOpAUFO GyezgVDIhU677ZTLR8/Der0pVWwtmvyqPEIhsce5pn5c0IZORdPLGnagZLXx1I/IOBV4 OOmg== 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=XbZYx4rCGKiIztQSDCfQaznbAQmiPPzpJUW3eLO1QQE=; b=A3jDbCBzWUytSfpwHFdsYBgzC3n49yNkFNQlLz8cD0O36rkhnUGdJJINQITVeIXwzY ZXKj+YrRlTM8J05vZVvuWRDUsYLHr28IyTcBuGrFVSCKueagzlig0kHWnKRYhUt1ni1/ u0Vox+3lBvze8KC9aI23BeprBpDQghjg81aqeaGSspZ4+vJYhUdE/d2jXjzhrvRFX9aZ GYmaNr7yanPj1le/ApsMHy2xWyaYeCjFkOd7uJliEADk2yHKroEp+mGGnN/ywK0cEOVJ DQfXtXs7brZb4UZWDsqAZTtmervJJjxQk5n0Rf/0F6SPMzt4UbayzbrGG8YGbKukhwaf uQJQ== X-Gm-Message-State: AODbwcAbmPaWHg5UKgphyW1zewMUkho2zIDSjGUURjZajk5+DgqgRRfX DLSKnxkSz5VI7NN3 X-Received: by 10.28.19.137 with SMTP id 131mr655588wmt.70.1496433399136; Fri, 02 Jun 2017 12:56:39 -0700 (PDT) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id t27sm4324515wra.35.2017.06.02.12.56.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 12:56:38 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Jun 2017 21:56:19 +0200 Message-Id: <20170602195619.4374-3-onemda@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170602195619.4374-1-onemda@gmail.com> References: <20170602195619.4374-1-onemda@gmail.com> Subject: [FFmpeg-devel] [PATCH 3/3] avformat: add Gremlin Digital Video 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/gdv.c | 161 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 libavformat/gdv.c diff --git a/libavformat/Makefile b/libavformat/Makefile index 00cba52..80aeed2 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -192,6 +192,7 @@ OBJS-$(CONFIG_G722_MUXER) += rawenc.o OBJS-$(CONFIG_G723_1_DEMUXER) += g723_1.o OBJS-$(CONFIG_G723_1_MUXER) += rawenc.o OBJS-$(CONFIG_G729_DEMUXER) += g729dec.o +OBJS-$(CONFIG_GDV_DEMUXER) += gdv.o OBJS-$(CONFIG_GENH_DEMUXER) += genh.o OBJS-$(CONFIG_H261_DEMUXER) += h261dec.o rawdec.o OBJS-$(CONFIG_H261_MUXER) += rawenc.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index ad516eb..a0e2fb8 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -134,6 +134,7 @@ static void register_all(void) REGISTER_MUXDEMUX(G722, g722); REGISTER_MUXDEMUX(G723_1, g723_1); REGISTER_DEMUXER (G729, g729); + REGISTER_DEMUXER (GDV, gdv); REGISTER_DEMUXER (GENH, genh); REGISTER_MUXDEMUX(GIF, gif); REGISTER_MUXDEMUX(GSM, gsm); diff --git a/libavformat/gdv.c b/libavformat/gdv.c new file mode 100644 index 0000000..87bba2f --- /dev/null +++ b/libavformat/gdv.c @@ -0,0 +1,161 @@ +/* + * Gremlin Digital Video demuxer + * Copyright (c) 2017 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 "avformat.h" +#include "avio.h" +#include "internal.h" + +typedef struct GDVContext { + int is_first_video; + int is_audio; + int audio_size; + int audio_stream_index; + int video_stream_index; + unsigned pal[256]; +} GDVContext; + +static int gdv_read_probe(AVProbeData *p) +{ + if (AV_RL32(p->buf) == 0x29111994) + return AVPROBE_SCORE_MAX; + + return 0; +} + +static int gdv_read_header(AVFormatContext *ctx) +{ + GDVContext *gdv = ctx->priv_data; + AVIOContext *pb = ctx->pb; + AVStream *vst, *ast; + unsigned fps, snd_flags, vid_depth; + + avio_skip(pb, 6); + + vst = avformat_new_stream(ctx, 0); + if (!vst) + return AVERROR(ENOMEM); + + vst->start_time = 0; + vst->duration = + vst->nb_frames = avio_rl16(pb); + + fps = avio_rl16(pb); + snd_flags = avio_rl16(pb); + if (snd_flags & 1) { + ast = avformat_new_stream(ctx, 0); + if (!ast) + return AVERROR(ENOMEM); + + ast->start_time = 0; + ast->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codecpar->codec_tag = 0; + ast->codecpar->sample_rate = avio_rl16(pb); + ast->codecpar->channels = 1 + !!(snd_flags & 2); + if (snd_flags & 8) { + ast->codecpar->codec_id = AV_CODEC_ID_GREMLIN_DPCM; + } else { + ast->codecpar->codec_id = (snd_flags & 4) ? AV_CODEC_ID_PCM_S16LE : AV_CODEC_ID_PCM_U8; + } + + avpriv_set_pts_info(ast, 64, 1, ast->codecpar->sample_rate); + gdv->audio_size = (ast->codecpar->sample_rate / fps) * + ast->codecpar->channels * (1 + !!(snd_flags & 4)) / (1 + !!(snd_flags & 8)); + gdv->is_audio = 1; + } + vid_depth = avio_rl16(pb); + avio_skip(pb, 4); + + vst->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codecpar->codec_id = AV_CODEC_ID_GDV; + vst->codecpar->codec_tag = 0; + vst->codecpar->width = avio_rl16(pb); + vst->codecpar->height = avio_rl16(pb); + + avpriv_set_pts_info(vst, 64, 1, fps); + + if (vid_depth & 1) { + int i; + + for (i = 0; i < 256; i++) { + unsigned r = avio_r8(pb); + unsigned g = avio_r8(pb); + unsigned b = avio_r8(pb); + gdv->pal[i] = 0xFF << 24 | r << 18 | g << 10 | b << 2; + } + } + + gdv->is_first_video = 1; + + return 0; +} + +static int gdv_read_packet(AVFormatContext *ctx, AVPacket *pkt) +{ + GDVContext *gdv = ctx->priv_data; + AVIOContext *pb = ctx->pb; + int ret; + + if (avio_feof(pb)) + return pb->error ? pb->error : AVERROR_EOF; + + if (gdv->audio_size && gdv->is_audio) { + ret = av_get_packet(pb, pkt, gdv->audio_size); + if (ret < 0) + return ret; + pkt->stream_index = 1; + gdv->is_audio = 0; + } else { + uint8_t *pal; + + if (avio_rl16(pb) != 0x1305) + return AVERROR_INVALIDDATA; + ret = av_get_packet(pb, pkt, 4 + avio_rl16(pb)); + if (ret < 0) + return ret; + pkt->stream_index = 0; + gdv->is_audio = 1; + + if (gdv->is_first_video) { + pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, + AVPALETTE_SIZE); + if (!pal) { + av_packet_unref(pkt); + return AVERROR(ENOMEM); + } + memcpy(pal, gdv->pal, AVPALETTE_SIZE); + pkt->flags |= AV_PKT_FLAG_KEY; + gdv->is_first_video = 0; + } + } + + return 0; +} + +AVInputFormat ff_gdv_demuxer = { + .name = "gdv", + .long_name = NULL_IF_CONFIG_SMALL("Gremlin Digital Video"), + .priv_data_size = sizeof(GDVContext), + .read_probe = gdv_read_probe, + .read_header = gdv_read_header, + .read_packet = gdv_read_packet, +};