From patchwork Fri Oct 12 10:21:11 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: 10651 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 5FA99446865 for ; Fri, 12 Oct 2018 13:29:20 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9789368A4CD; Fri, 12 Oct 2018 13:29:01 +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 A996C68829D for ; Fri, 12 Oct 2018 13:28:54 +0300 (EEST) Received: by mail-ed1-f68.google.com with SMTP id r1-v6so11031886edd.7 for ; Fri, 12 Oct 2018 03:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=mEWWIhCpee5no6A9rr6SX1U5uCfRwTnwn3dEIsKxBeU=; b=qe855pajHteuQAvOr8xckoTPC6LLqM+uwinKOedHJfEK8sMNqAKDSHgUNlBQd44zLK +kl27yndhQcI1E6fl9Px8sd6/R9Mm9/Nx9JgZl0rfA5NJi4+y9YhIfYGFSib/WV0X0Se vszBpl0/t1i2wmRc00joFU1kb4c8PezjMDlgwyJ8T6Bk00mcsFdV3orOIt5oIMuc6PLk q68TYLL6Iyxoj+YLt261p62ySEsgzSEr3FTCUbXst2VfReCOO7r46IImalgEhbaKoDMx 4DzWXd7qRLC27Z/DyN1AOhiOw8U9z2dzJersEAyFldAQNClRw04SXz+ib5Ggd026OSat +gMQ== 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; bh=mEWWIhCpee5no6A9rr6SX1U5uCfRwTnwn3dEIsKxBeU=; b=rwnJP8VcsVF6Ll+S2gWGM04/eJGRc82n/B+mSwxZF5n5Se+avpKDxI5bosWcMQ5/53 r5K94UrszflzwTJmP8c0JxqdAKFZtzrFio0Y4RfDw3Nt8/y7nEGPXmW65Ap3Q8NDTdKH 5UWy3IIg3F7VBAAyVMDoR0Ac+uu8Qbj7e4mwPxuslSD28oTn0OtaXxpx5GYu9FqE5NzM tg+Oj/o1NGV+KfuxYkuf7gEF46vAVADDignHcKoRkXKQx0V/U7bRBjFGPeGDDnQns9Bd 0dbe5bZCddrttgjCTo8pEmUWl3uZ6ZOLsp6lQ4Js0y9yS7dDsXVyJmui4O5Qf+jTLbnH IcRw== X-Gm-Message-State: ABuFfojm7nLbn1ej6tev18JXs3OUTB4LcEtwcvbfnL1FP2uwrESq73wW 8U81FwoZudgJZwDDitj1+d7fw7R1tMY= X-Google-Smtp-Source: ACcGV63m/u2EKT1y0v+XAJVuQifCRMPA+U6I9gGvobVXkdJKBz9hYPPWIU7KWiZmfJgGf4OgFggzWQ== X-Received: by 2002:aa7:c4cb:: with SMTP id p11-v6mr7832378edr.285.1539339691293; Fri, 12 Oct 2018 03:21:31 -0700 (PDT) Received: from localhost.localdomain ([94.250.174.60]) by smtp.gmail.com with ESMTPSA id c24-v6sm438130ede.73.2018.10.12.03.21.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Oct 2018 03:21:30 -0700 (PDT) From: Paul B Mahol To: ffmpeg-devel@ffmpeg.org Date: Fri, 12 Oct 2018 12:21:11 +0200 Message-Id: <20181012102111.19204-1-onemda@gmail.com> X-Mailer: git-send-email 2.17.1 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..1deda4935c --- /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 = AV_PIX_FMT_MONOBLACK; 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, +};