From patchwork Fri Oct 12 10:41:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul B Mahol X-Patchwork-Id: 10652 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 7BE3E446865 for ; Fri, 12 Oct 2018 13:41:14 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A4E2E68A4AE; Fri, 12 Oct 2018 13:40:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2D847689734 for ; Fri, 12 Oct 2018 13:40:49 +0300 (EEST) Received: by mail-ed1-f68.google.com with SMTP id v18-v6so11033373edq.12 for ; Fri, 12 Oct 2018 03:41:12 -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=GmilEKtRqXtbWoBhJ6FlqpKfdLFYCXa5xLaaHkUl02s=; b=JiFcwPId4KqfktEmbBQ8UwEp0V32eIKbLorbRT0t6u5xsTy4iYimqfGCpf8FQTBVV6 IPF/GLcoQBGa6ZE00DJW5984t1tUFeDJ7+epcoQFdn/LNun0MClN/0F/Ulr3FMEu3t5q YVb6av6uvXxWBbju12bSuufsYmtCcQYjxnl3fBXdPpwq/lcSp1Gu+pgsaOu5cTCjh8vQ FQxnuwM8+ly9DIyiLUsNmWm+561Glut5gRcoXWWxxeKyOL0gTLgcJnB4L7gSiKtUDWC5 aPoD1tE7OkaDvHLTYe4manJTAmLRlN3zSW+ZtbZzqT86wru+aqnh92u67BtbZ8sU/BIp 5wWA== 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=GmilEKtRqXtbWoBhJ6FlqpKfdLFYCXa5xLaaHkUl02s=; b=gb3XPgf+5Yt/+OHQgLMC2ZJfzTZDa5ViGWeClQA7/L6fTCrE5eQSvZMIU5wTi1uT72 UVt/czcJfAkXbtYL8Z2IaDRFoujEgH/YAorJUIVQuqj/zENt8fZS65dtERiltgMr1fts R6FhuScthD2kR/V5r2CvARc+02VVKdKkO4bFJEPMjQTtXLs485cRXbVTpG5OfNpSpA5+ ywDc7nJmTJlH8xjHtVtZOKun+nC6kuttn1vXii805rx053NC1ny50rSNtFfoz20lXYoK 0yyWdtJDW9pQmx5BzgWSSby08CauczM5Iyp+9G8lpsIyBRfDKL+nAaGvGIBb/BB5T9iU m/2Q== X-Gm-Message-State: ABuFfogqMOn4H9khjnjXmOj7DMIkkgVrQIZaSHngot57eSJq6Hbpf+IU HoPDO0vCrSI7Z1wciOypY8Gcu7+MyI4= X-Google-Smtp-Source: ACcGV63tp7iAOgwozZuFII66biXpEIXH5vOADub20pNiUn40ZjUtCxMhv9QQ8dEmNFWAy9Lqv09A4w== X-Received: by 2002:a05:6402:168f:: with SMTP id a15mr8042517edv.135.1539340871834; Fri, 12 Oct 2018 03:41:11 -0700 (PDT) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id h15-v6sm571926edk.62.2018.10.12.03.41.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 03:41:11 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 12 Oct 2018 12:41:02 +0200 Message-Id: <20181012104102.21941-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181012102111.19204-1-onemda@gmail.com> References: <20181012102111.19204-1-onemda@gmail.com> Subject: [FFmpeg-devel] [PATCH] avformat: add SER 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" Fixes #6821. Signed-off-by: Paul B Mahol --- libavformat/Makefile | 1 + libavformat/allformats.c | 1 + libavformat/serdec.c | 138 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 libavformat/serdec.c diff --git a/libavformat/Makefile b/libavformat/Makefile index e0222535c1..e99e9150d5 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -467,6 +467,7 @@ OBJS-$(CONFIG_SDX_DEMUXER) += sdxdec.o OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o OBJS-$(CONFIG_SEGAFILM_MUXER) += segafilmenc.o OBJS-$(CONFIG_SEGMENT_MUXER) += segment.o +OBJS-$(CONFIG_SER_DEMUXER) += serdec.o OBJS-$(CONFIG_SHORTEN_DEMUXER) += shortendec.o rawdec.o OBJS-$(CONFIG_SIFF_DEMUXER) += siff.o OBJS-$(CONFIG_SINGLEJPEG_MUXER) += rawenc.o diff --git a/libavformat/allformats.c b/libavformat/allformats.c index 5c32ee6dff..9e41718685 100644 --- a/libavformat/allformats.c +++ b/libavformat/allformats.c @@ -367,6 +367,7 @@ extern AVInputFormat ff_segafilm_demuxer; extern AVOutputFormat ff_segafilm_muxer; extern AVOutputFormat ff_segment_muxer; extern AVOutputFormat ff_stream_segment_muxer; +extern AVInputFormat ff_ser_demuxer; extern AVInputFormat ff_shorten_demuxer; extern AVInputFormat ff_siff_demuxer; extern AVOutputFormat ff_singlejpeg_muxer; diff --git a/libavformat/serdec.c b/libavformat/serdec.c new file mode 100644 index 0000000000..b14bb42d28 --- /dev/null +++ b/libavformat/serdec.c @@ -0,0 +1,138 @@ +/* + * SER video demuxer + * Copyright (c) 2018 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/imgutils.h" +#include "libavutil/parseutils.h" +#include "libavutil/pixdesc.h" +#include "libavutil/opt.h" +#include "internal.h" +#include "avformat.h" + +#define SER_MAGIC "LUCAM-RECORDER" + +typedef struct SERDemuxerContext { + const AVClass *class; + int width, height; + AVRational framerate; +} SERDemuxerContext; + +static int ser_probe(AVProbeData *pd) +{ + if (memcmp(pd->buf, SER_MAGIC, 14) == 0) + return AVPROBE_SCORE_MAX; + else + return 0; +} + +static int ser_read_header(AVFormatContext *s) +{ + SERDemuxerContext *ser = s->priv_data; + enum AVPixelFormat pix_fmt; + int depth, color_id, endian; + int packet_size; + AVStream *st; + + st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + avio_skip(s->pb, 14); + avio_skip(s->pb, 4); + color_id = avio_rl32(s->pb); + endian = avio_rl32(s->pb); + ser->width = avio_rl32(s->pb); + ser->height = avio_rl32(s->pb); + depth = avio_rl32(s->pb); + st->nb_frames = st->duration = avio_rl32(s->pb); + avio_skip(s->pb, 120); + avio_skip(s->pb, 8); + avio_skip(s->pb, 8); + + switch (color_id) { + case 0: pix_fmt = depth <= 8 ? AV_PIX_FMT_GRAY8 : endian ? AV_PIX_FMT_GRAY16LE : AV_PIX_FMT_GRAY16BE; break; + case 8: pix_fmt = depth <= 8 ? AV_PIX_FMT_BAYER_RGGB8 : endian ? AV_PIX_FMT_BAYER_RGGB16LE : AV_PIX_FMT_BAYER_RGGB16BE; break; + case 9: pix_fmt = depth <= 8 ? AV_PIX_FMT_BAYER_GRBG8 : endian ? AV_PIX_FMT_BAYER_GRBG16LE : AV_PIX_FMT_BAYER_GRBG16BE; break; + case 10: pix_fmt = depth <= 8 ? AV_PIX_FMT_BAYER_GBRG8 : endian ? AV_PIX_FMT_BAYER_GBRG16LE : AV_PIX_FMT_BAYER_GBRG16BE; break; + case 11: pix_fmt = depth <= 8 ? AV_PIX_FMT_BAYER_BGGR8 : endian ? AV_PIX_FMT_BAYER_BGGR16LE : AV_PIX_FMT_BAYER_BGGR16BE; break; + case 100: pix_fmt = depth <= 8 ? AV_PIX_FMT_RGB24 : endian ? AV_PIX_FMT_RGB48LE : AV_PIX_FMT_RGB48BE; break; + case 101: pix_fmt = depth <= 8 ? AV_PIX_FMT_BGR24 : endian ? AV_PIX_FMT_BGR48LE : AV_PIX_FMT_BGR48BE; break; + default: + return AVERROR_PATCHWELCOME; + } + + st->codecpar->codec_type = AVMEDIA_TYPE_VIDEO; + st->codecpar->codec_id = s->iformat->raw_codec_id; + + avpriv_set_pts_info(st, 64, ser->framerate.den, ser->framerate.num); + + st->codecpar->width = ser->width; + st->codecpar->height = ser->height; + st->codecpar->format = pix_fmt; + packet_size = av_image_get_buffer_size(st->codecpar->format, ser->width, ser->height, 1); + if (packet_size < 0) + return packet_size; + s->packet_size = packet_size; + st->codecpar->bit_rate = av_rescale_q(s->packet_size, + (AVRational){8,1}, st->time_base); + + return 0; +} + + +static int ser_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + int ret; + + ret = av_get_packet(s->pb, pkt, s->packet_size); + pkt->pts = pkt->dts = (pkt->pos - s->internal->data_offset) / s->packet_size; + + pkt->stream_index = 0; + if (ret < 0) + return ret; + return 0; +} + +#define OFFSET(x) offsetof(SERDemuxerContext, x) +#define DEC AV_OPT_FLAG_DECODING_PARAM +static const AVOption ser_options[] = { + { "framerate", "set frame rate", OFFSET(framerate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, DEC }, + { NULL }, +}; + +static const AVClass ser_demuxer_class = { + .class_name = "ser demuxer", + .item_name = av_default_item_name, + .option = ser_options, + .version = LIBAVUTIL_VERSION_INT, +}; + +AVInputFormat ff_ser_demuxer = { + .name = "ser", + .long_name = NULL_IF_CONFIG_SMALL("SER (Simple uncompressed video format for astronomical capturing)"), + .priv_data_size = sizeof(SERDemuxerContext), + .read_probe = ser_probe, + .read_header = ser_read_header, + .read_packet = ser_read_packet, + .flags = AVFMT_GENERIC_INDEX, + .extensions = "ser", + .raw_codec_id = AV_CODEC_ID_RAWVIDEO, + .priv_class = &ser_demuxer_class, +};