From patchwork Thu Feb 16 17:43:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Riegel X-Patchwork-Id: 2579 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp2590850vsb; Thu, 16 Feb 2017 09:44:16 -0800 (PST) X-Received: by 10.223.174.183 with SMTP id y52mr3618528wrc.112.1487267056130; Thu, 16 Feb 2017 09:44:16 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v204si1369581wmg.18.2017.02.16.09.44.15; Thu, 16 Feb 2017 09:44:16 -0800 (PST) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BEF3E689AA1; Thu, 16 Feb 2017 19:43:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail.savoirfairelinux.com (mail.savoirfairelinux.com [208.88.110.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3BBB4680A1A for ; Thu, 16 Feb 2017 19:43:53 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 4C1B09C1A88 for ; Thu, 16 Feb 2017 12:43:58 -0500 (EST) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 7nuG-yg1XbAA; Thu, 16 Feb 2017 12:43:57 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 9F81A9C1A80; Thu, 16 Feb 2017 12:43:57 -0500 (EST) X-Virus-Scanned: amavisd-new at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id CmDD8LUoRjjB; Thu, 16 Feb 2017 12:43:57 -0500 (EST) Received: from workotop.mtl.sfl (unknown [192.168.49.100]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 726419C1A88; Thu, 16 Feb 2017 12:43:57 -0500 (EST) From: Damien Riegel To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Feb 2017 12:43:36 -0500 Message-Id: <20170216174337.19488-2-damien.riegel@savoirfairelinux.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170216174337.19488-1-damien.riegel@savoirfairelinux.com> References: <20170216174337.19488-1-damien.riegel@savoirfairelinux.com> Subject: [FFmpeg-devel] [PATCH v1 1/2] codec: vrawdepay: add decoder for RFC4175 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 Cc: Damien Riegel MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Add a codec capable of decoding some formats of the RFC4175. For now it's only capable of handling YCbCr-4:2:2 with 8-bit or 10-bit depth. For 8-bit it's a simple pass-through, for 10-bit it depacks the stream in the AV_PIX_FMT_YUV422P10 pixel format. Change-Id: Id2184a6cee7031edbcb65a39a369623114c1783c Signed-off-by: Damien Riegel --- libavcodec/Makefile | 1 + libavcodec/allcodecs.c | 1 + libavcodec/avcodec.h | 1 + libavcodec/codec_desc.c | 7 +++ libavcodec/vrawdepay.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 libavcodec/vrawdepay.c diff --git a/libavcodec/Makefile b/libavcodec/Makefile index a1ce264f25..e09dcc3c1b 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -614,6 +614,7 @@ OBJS-$(CONFIG_VP9_CUVID_DECODER) += cuvid.o OBJS-$(CONFIG_VP9_MEDIACODEC_DECODER) += mediacodecdec.o OBJS-$(CONFIG_VPLAYER_DECODER) += textdec.o ass.o OBJS-$(CONFIG_VQA_DECODER) += vqavideo.o +OBJS-$(CONFIG_VRAWDEPAY_DECODER) += vrawdepay.o OBJS-$(CONFIG_WAVPACK_DECODER) += wavpack.o OBJS-$(CONFIG_WAVPACK_ENCODER) += wavpackenc.o OBJS-$(CONFIG_WEBP_DECODER) += webp.o diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index f12a54df50..dcce291ba2 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -365,6 +365,7 @@ void avcodec_register_all(void) REGISTER_DECODER(VP8, vp8); REGISTER_DECODER(VP9, vp9); REGISTER_DECODER(VQA, vqa); + REGISTER_DECODER(VRAWDEPAY, vrawdepay); REGISTER_DECODER(WEBP, webp); REGISTER_ENCODER(WRAPPED_AVFRAME, wrapped_avframe); REGISTER_ENCDEC (WMV1, wmv1); diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 5616fb01d6..aca4fe61e6 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -415,6 +415,7 @@ enum AVCodecID { AV_CODEC_ID_PIXLET, AV_CODEC_ID_SPEEDHQ, AV_CODEC_ID_FMVC, + AV_CODEC_ID_VRAWDEPAY, /* various PCM "codecs" */ AV_CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c index 35846c054e..8a3492adcf 100644 --- a/libavcodec/codec_desc.c +++ b/libavcodec/codec_desc.c @@ -1360,6 +1360,13 @@ static const AVCodecDescriptor codec_descriptors[] = { .long_name = NULL_IF_CONFIG_SMALL("FM Screen Capture Codec"), .props = AV_CODEC_PROP_LOSSLESS, }, + { + .id = AV_CODEC_ID_VRAWDEPAY, + .type = AVMEDIA_TYPE_VIDEO, + .name = "rfc4175", + .long_name = NULL_IF_CONFIG_SMALL("RFC4175 video depayloader"), + .props = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS, + }, /* image codecs */ { diff --git a/libavcodec/vrawdepay.c b/libavcodec/vrawdepay.c new file mode 100644 index 0000000000..53a5c38bb3 --- /dev/null +++ b/libavcodec/vrawdepay.c @@ -0,0 +1,113 @@ +/* + * Raw Video Depayloader (RFC4175) + * Copyright (c) 2017 Savoir-faire Linux, Inc + * + * 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 + */ + +/* Development sponsored by CBC/Radio-Canada */ + +/** + * @file + * Raw Video Depayloader (RFC4175) + */ + +#include +#include "avcodec.h" +#include "internal.h" +#include "get_bits.h" + +static av_cold int vrawdepay_init_decoder(AVCodecContext *avctx) +{ + if (!avctx->codec_tag || !avctx->width || !avctx->height) + return -1; + + if (avctx->codec_tag == MKTAG('U', 'Y', 'V', 'Y')) { + if (avctx->bits_per_coded_sample == 16) + avctx->pix_fmt = AV_PIX_FMT_UYVY422; + else if (avctx->bits_per_coded_sample == 20) + avctx->pix_fmt = AV_PIX_FMT_YUV422P10; + else + return -1; + } else { + return -1; + } + + return 0; +} + +static av_cold int vrawdepay_close_decoder(AVCodecContext *avctx) +{ + return 0; +} + +static int vrawdepay_decode(AVCodecContext *avctx, void *data, int *got_frame, + AVPacket *avpkt) +{ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + AVFrame *frame = data; + int res; + + frame->pict_type = AV_PICTURE_TYPE_I; + frame->key_frame = 1; + + if (avctx->bits_per_coded_sample == 16) { + /* there is no need to copy as the data already match + * a known pixel format */ + frame->buf[0] = av_buffer_ref(avpkt->buf); + + if ((res = av_image_fill_arrays(frame->data, frame->linesize, buf, + avctx->pix_fmt, avctx->width, avctx->height, 1)) < 0) { + av_buffer_unref(&frame->buf[0]); + return res; + } + } else { + GetBitContext bc; + uint16_t *y, *u, *v; + int i; + + res = ff_get_buffer(avctx, frame, 0); + if (res < 0) + return res; + y = (uint16_t*)frame->data[0]; + u = (uint16_t*)frame->data[1]; + v = (uint16_t*)frame->data[2]; + + res = init_get_bits(&bc, buf, avctx->width * avctx->height * 20); + for (i = 0; i < (avctx->width * avctx->height) / 2; i++) { + *u++ = get_bits(&bc, 10); + *y++ = get_bits(&bc, 10); + *v++ = get_bits(&bc, 10); + *y++ = get_bits(&bc, 10); + } + } + + *got_frame = 1; + return buf_size; + +} + +AVCodec ff_vrawdepay_decoder = { + .name = "vrawdepay", + .long_name = NULL_IF_CONFIG_SMALL("RFC4175 codec"), + .type = AVMEDIA_TYPE_VIDEO, + .id = AV_CODEC_ID_VRAWDEPAY, + .init = vrawdepay_init_decoder, + .close = vrawdepay_close_decoder, + .decode = vrawdepay_decode, +};