From patchwork Wed Aug 9 11:19:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jorge Ramirez-Ortiz X-Patchwork-Id: 4667 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.46.211 with SMTP id u202csp822804vsu; Wed, 9 Aug 2017 04:20:10 -0700 (PDT) X-Received: by 10.28.214.13 with SMTP id n13mr4554195wmg.16.1502277610622; Wed, 09 Aug 2017 04:20:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502277610; cv=none; d=google.com; s=arc-20160816; b=ewJzie+ReZtQbbZ5K/FL4g26i+zvFLmqrH/ZOJwPhCi/Luap7w5jmjBFCJNSERqXa7 TophRDT2yyzCjk4/S+LIFo7wUBvE6tzJfqaG0I6qplvfaAXAxiGLKM1rjFhv0CpFo9Oi tbICpdKVChIS+nIgNh51OoZFzSByZ5RVI4/nJ4VWoNOjjXmJlVX6ij1AY4PHRmGF+WMU udz9cR4rC+EVjC/9qS77IHONPGiix1RcIrb/k07KpIXYhp/2gjQvn8ONxYbaaM4K95nv nPIP88CQtHpPWqlolonEgTQ1cCxTNYRwVpWIER3LMa0hGbm8EcZjEbDonQt1WTWRUMZw Ej4w== 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:cc: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=yuMAZrtbXmIQcGTqpkKlFWn+naAOa2TjB7cO5FnbL44=; b=w8n2zsZXI5djijNAiY+S1JQd9DHI7JMhP9QG7YYa21x7XkEgcccPDO4bIhUgBADSTg kTXQBy3v+NOhu5iVIt4KpTSiz2jACk1kgR+g1uKLb6wL9gkczdHc58o4W9NwXYPkWgQm BkaUyUDUjnZ6K9cfdHBhMEY+0T3AT2+vWBqT93f9jwIhXKIvXnNdnAE8Ow0d2GL0ptiz rWFzEihQvLJK+Lj3SVXukyazff4sitOZ1ayixIjQoL1T+jJdDYKNpJD+x3tk+DBovY9S 3M5fwdw3/e3nCDkd/yLY+PrrkFxQZTsJ7ET3Ptm0nFxMzDFmjtzlZg0ov338DESiLnAv SgNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=aoZ377lr; 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=linaro.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id c14si3105389wrb.102.2017.08.09.04.20.10; Wed, 09 Aug 2017 04:20:10 -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=@linaro.org header.s=google header.b=aoZ377lr; 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=linaro.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EBDB6689A62; Wed, 9 Aug 2017 14:20:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f52.google.com (mail-wm0-f52.google.com [74.125.82.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F210A689723 for ; Wed, 9 Aug 2017 14:19:55 +0300 (EEST) Received: by mail-wm0-f52.google.com with SMTP id m85so28414053wma.1 for ; Wed, 09 Aug 2017 04:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=IVK7NP51gbaawkVifUmhUmHR5ae6snxKa1yudxcMxbo=; b=aoZ377lrH78CP9nUxVv0dgP/QDltTEd6/jy7PGJbZxUqQienUfdrrFz72Z4ZnihkJ1 uhVL4BWXhwGbtNZ8y7DjW/eS9nc2ofy/Z5fuzba+M/sG9+JjtavY57yYZBvMbX+kNBQO WBoMNTcu2KA6lHpbkJ4FL/DCNrja6RT+b4MOs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=IVK7NP51gbaawkVifUmhUmHR5ae6snxKa1yudxcMxbo=; b=GLlgUFKaMn6kIcqfNYCj/mJdxtsMPu7upGc9niUd6v3i0vq1/5VrreunRh1ody+Nyv ScEe7VKDm84wlT3vDQsvexZEFwFHe/JNiD+kSSSH/rPaUP/GAnd8IB/myP5sbwkGdtQn apjpMQmfwwxJ1kRzE+KnR3RgGIkkrOLPCFx+w9a+e2LhhGy6aVBMdBKmAvpCEWsJAj73 g3JwoiW1wW2Syzs07+C6W3mqJCEuZvLuPzx5Qy1ZAUD44M+Na+PW5YItO3sAZrlcplqo 7n8WDpgRKnsMSR+rA4OP19JohBNvqG8WL3p3xsv6Joi4E5GCft7BXoQ098pf8REG5MZ7 o4JQ== X-Gm-Message-State: AHYfb5gDK1+GqxAldSpPXPNEGWUYYmY8Asv22e7LpPsQ1HBeNOGiGD7+ TzRjGOABVukO4A16 X-Received: by 10.28.60.11 with SMTP id j11mr5027528wma.47.1502277597713; Wed, 09 Aug 2017 04:19:57 -0700 (PDT) Received: from igloo.80.58.61.254 (39.red-81-40-130.staticip.rima-tde.net. [81.40.130.39]) by smtp.gmail.com with ESMTPSA id 134sm3136849wmw.24.2017.08.09.04.19.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Aug 2017 04:19:55 -0700 (PDT) From: Jorge Ramirez-Ortiz To: jorge.ramirez-ortiz@linaro.org, sw@jkqxz.net, ffmpeg-devel@ffmpeg.org, michael@niedermayer.cc Date: Wed, 9 Aug 2017 13:19:46 +0200 Message-Id: <1502277589-12397-2-git-send-email-jorge.ramirez-ortiz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502277589-12397-1-git-send-email-jorge.ramirez-ortiz@linaro.org> References: <1502277589-12397-1-git-send-email-jorge.ramirez-ortiz@linaro.org> Subject: [FFmpeg-devel] [PATCHv5 1/4] Move lavd/v4l2-common.* to lavc 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: nicolas.dechesne@linaro.org, stanimir.varbanov@linaro.org, aballier@gentoo.org MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Alexis Ballier In preparation to support the integation of the V4L2 API for encoding and decoding, move v4l2 related files to libavcodec. v4l2-common was renamed to v4l2_fmt for clarity (v4l2-common.h belongs to the V4L2 API) Signed-off-by: Alexis Ballier Reviewed-by: Jorge Ramirez-Ortiz --- configure | 6 ++- libavcodec/Makefile | 1 + libavcodec/v4l2_fmt.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++ libavcodec/v4l2_fmt.h | 57 +++++++++++++++++++++++++ libavdevice/Makefile | 6 +-- libavdevice/v4l2-common.c | 105 ---------------------------------------------- libavdevice/v4l2-common.h | 61 --------------------------- libavdevice/v4l2.c | 40 ++++++++++++------ libavdevice/v4l2enc.c | 12 +++++- 9 files changed, 206 insertions(+), 187 deletions(-) create mode 100644 libavcodec/v4l2_fmt.c create mode 100644 libavcodec/v4l2_fmt.h delete mode 100644 libavdevice/v4l2-common.c delete mode 100644 libavdevice/v4l2-common.h diff --git a/configure b/configure index 66c7b94..ed94de0 100755 --- a/configure +++ b/configure @@ -1671,6 +1671,7 @@ SUBSYSTEM_LIST=" pixelutils network rdft + v4l2 " # COMPONENT_LIST needs to come last to ensure correct dependency checking @@ -2268,6 +2269,7 @@ map 'eval ${v}_inline_deps=inline_asm' $ARCH_EXT_LIST_ARM loongson2_deps="mips" loongson3_deps="mips" +v4l2_deps_any="linux_videodev2_h sys_videoio_h" mipsfpu_deps="mips" mipsdsp_deps="mips" mipsdspr2_deps="mips" @@ -3041,8 +3043,8 @@ sdl2_outdev_deps="sdl2" sndio_indev_deps="sndio" sndio_outdev_deps="sndio" v4l_indev_deps="linux_videodev_h" -v4l2_indev_deps_any="linux_videodev2_h sys_videoio_h" -v4l2_outdev_deps_any="linux_videodev2_h sys_videoio_h" +v4l2_indev_select="v4l2" +v4l2_outdev_select="v4l2" vfwcap_indev_deps="vfw32 vfwcap_defines" xcbgrab_indev_deps="libxcb" xv_outdev_deps="X11_extensions_Xvlib_h XvGetPortAttribute" diff --git a/libavcodec/Makefile b/libavcodec/Makefile index b0c39ac..6be1b4b 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -101,6 +101,7 @@ OBJS-$(CONFIG_LZF) += lzf.o OBJS-$(CONFIG_MDCT) += mdct_fixed.o mdct_float.o mdct_fixed_32.o OBJS-$(CONFIG_ME_CMP) += me_cmp.o OBJS-$(CONFIG_MEDIACODEC) += mediacodecdec_common.o mediacodec_surface.o mediacodec_wrapper.o mediacodec_sw_buffer.o +OBJS-$(CONFIG_V4L2) += v4l2_fmt.o OBJS-$(CONFIG_MPEG_ER) += mpeg_er.o OBJS-$(CONFIG_MPEGAUDIO) += mpegaudio.o OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \ diff --git a/libavcodec/v4l2_fmt.c b/libavcodec/v4l2_fmt.c new file mode 100644 index 0000000..322f595 --- /dev/null +++ b/libavcodec/v4l2_fmt.c @@ -0,0 +1,105 @@ +/* + * 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 "v4l2_fmt.h" + +const struct v4l_fmt_map avpriv_v4l_fmt_conversion_table[] = { + //ff_fmt codec_id v4l2_fmt + { AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV420 }, + { AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YVU420 }, + { AV_PIX_FMT_YUV422P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV422P }, + { AV_PIX_FMT_YUYV422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUYV }, + { AV_PIX_FMT_UYVY422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_UYVY }, + { AV_PIX_FMT_YUV411P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV411P }, + { AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV410 }, + { AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YVU410 }, + { AV_PIX_FMT_RGB555LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555 }, + { AV_PIX_FMT_RGB555BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555X }, + { AV_PIX_FMT_RGB565LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565 }, + { AV_PIX_FMT_RGB565BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565X }, + { AV_PIX_FMT_BGR24, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR24 }, + { AV_PIX_FMT_RGB24, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB24 }, + { AV_PIX_FMT_BGR0, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR32 }, + { AV_PIX_FMT_0RGB, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB32 }, + { AV_PIX_FMT_GRAY8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_GREY }, +#ifdef V4L2_PIX_FMT_Y16 + { AV_PIX_FMT_GRAY16LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_Y16 }, +#endif + { AV_PIX_FMT_NV12, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV12 }, + { AV_PIX_FMT_NONE, AV_CODEC_ID_MJPEG, V4L2_PIX_FMT_MJPEG }, + { AV_PIX_FMT_NONE, AV_CODEC_ID_MJPEG, V4L2_PIX_FMT_JPEG }, +#ifdef V4L2_PIX_FMT_H264 + { AV_PIX_FMT_NONE, AV_CODEC_ID_H264, V4L2_PIX_FMT_H264 }, +#endif +#ifdef V4L2_PIX_FMT_MPEG4 + { AV_PIX_FMT_NONE, AV_CODEC_ID_MPEG4, V4L2_PIX_FMT_MPEG4 }, +#endif +#ifdef V4L2_PIX_FMT_CPIA1 + { AV_PIX_FMT_NONE, AV_CODEC_ID_CPIA, V4L2_PIX_FMT_CPIA1 }, +#endif +#ifdef V4L2_PIX_FMT_SRGGB8 + { AV_PIX_FMT_BAYER_BGGR8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_SBGGR8 }, + { AV_PIX_FMT_BAYER_GBRG8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_SGBRG8 }, + { AV_PIX_FMT_BAYER_GRBG8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_SGRBG8 }, + { AV_PIX_FMT_BAYER_RGGB8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_SRGGB8 }, +#endif + { AV_PIX_FMT_NONE, AV_CODEC_ID_NONE, 0 }, +}; + +uint32_t avpriv_v4l_fmt_ff2v4l(enum AVPixelFormat pix_fmt, enum AVCodecID codec_id) +{ + int i; + + for (i = 0; avpriv_v4l_fmt_conversion_table[i].codec_id != AV_CODEC_ID_NONE; i++) { + if ((codec_id == AV_CODEC_ID_NONE || + avpriv_v4l_fmt_conversion_table[i].codec_id == codec_id) && + (pix_fmt == AV_PIX_FMT_NONE || + avpriv_v4l_fmt_conversion_table[i].ff_fmt == pix_fmt)) { + return avpriv_v4l_fmt_conversion_table[i].v4l2_fmt; + } + } + + return 0; +} + +enum AVPixelFormat avpriv_v4l_fmt_v4l2ff(uint32_t v4l2_fmt, enum AVCodecID codec_id) +{ + int i; + + for (i = 0; avpriv_v4l_fmt_conversion_table[i].codec_id != AV_CODEC_ID_NONE; i++) { + if (avpriv_v4l_fmt_conversion_table[i].v4l2_fmt == v4l2_fmt && + avpriv_v4l_fmt_conversion_table[i].codec_id == codec_id) { + return avpriv_v4l_fmt_conversion_table[i].ff_fmt; + } + } + + return AV_PIX_FMT_NONE; +} + +enum AVCodecID avpriv_v4l_fmt_v4l2codec(uint32_t v4l2_fmt) +{ + int i; + + for (i = 0; avpriv_v4l_fmt_conversion_table[i].codec_id != AV_CODEC_ID_NONE; i++) { + if (avpriv_v4l_fmt_conversion_table[i].v4l2_fmt == v4l2_fmt) { + return avpriv_v4l_fmt_conversion_table[i].codec_id; + } + } + + return AV_CODEC_ID_NONE; +} diff --git a/libavcodec/v4l2_fmt.h b/libavcodec/v4l2_fmt.h new file mode 100644 index 0000000..91dc502 --- /dev/null +++ b/libavcodec/v4l2_fmt.h @@ -0,0 +1,57 @@ +/* + * 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 + */ + +#ifndef AVCODEC_V4L2_COMMON_H +#define AVCODEC_V4L2_COMMON_H + +#undef __STRICT_ANSI__ //workaround due to broken kernel headers +#include "config.h" +#if HAVE_SYS_VIDEOIO_H +#include +#else +#if HAVE_ASM_TYPES_H +#include +#endif +#include +#endif +#include "libavutil/avassert.h" +#include "libavutil/imgutils.h" +#include "libavutil/log.h" +#include "libavutil/opt.h" +#include "avdevice.h" +#include "timefilter.h" +#include "libavutil/parseutils.h" +#include "libavutil/pixdesc.h" +#include "libavutil/time.h" +#include "libavutil/avstring.h" +#include "libavutil/pixfmt.h" +#include "libavcodec/avcodec.h" + +struct v4l_fmt_map { + enum AVPixelFormat ff_fmt; + enum AVCodecID codec_id; + uint32_t v4l2_fmt; +}; + +extern const struct v4l_fmt_map avpriv_v4l_fmt_conversion_table[]; + +uint32_t avpriv_v4l_fmt_ff2v4l(enum AVPixelFormat pix_fmt, enum AVCodecID codec_id); +enum AVPixelFormat avpriv_v4l_fmt_v4l2ff(uint32_t v4l2_fmt, enum AVCodecID codec_id); +enum AVCodecID avpriv_v4l_fmt_v4l2codec(uint32_t v4l2_fmt); + +#endif /* AVCODEC_V4L2_COMMON_H */ diff --git a/libavdevice/Makefile b/libavdevice/Makefile index 1d4e9e6..a001e74 100644 --- a/libavdevice/Makefile +++ b/libavdevice/Makefile @@ -43,8 +43,8 @@ OBJS-$(CONFIG_QTKIT_INDEV) += qtkit.o OBJS-$(CONFIG_SDL2_OUTDEV) += sdl2.o OBJS-$(CONFIG_SNDIO_INDEV) += sndio_dec.o sndio.o OBJS-$(CONFIG_SNDIO_OUTDEV) += sndio_enc.o sndio.o -OBJS-$(CONFIG_V4L2_INDEV) += v4l2.o v4l2-common.o timefilter.o -OBJS-$(CONFIG_V4L2_OUTDEV) += v4l2enc.o v4l2-common.o +OBJS-$(CONFIG_V4L2_INDEV) += v4l2.o timefilter.o +OBJS-$(CONFIG_V4L2_OUTDEV) += v4l2enc.o OBJS-$(CONFIG_V4L_INDEV) += v4l.o OBJS-$(CONFIG_VFWCAP_INDEV) += vfwcap.o OBJS-$(CONFIG_XCBGRAB_INDEV) += xcbgrab.o @@ -64,8 +64,6 @@ SKIPHEADERS-$(CONFIG_DSHOW_INDEV) += dshow_capture.h SKIPHEADERS-$(CONFIG_FBDEV_INDEV) += fbdev_common.h SKIPHEADERS-$(CONFIG_FBDEV_OUTDEV) += fbdev_common.h SKIPHEADERS-$(CONFIG_LIBPULSE) += pulse_audio_common.h -SKIPHEADERS-$(CONFIG_V4L2_INDEV) += v4l2-common.h -SKIPHEADERS-$(CONFIG_V4L2_OUTDEV) += v4l2-common.h SKIPHEADERS-$(HAVE_ALSA) += alsa.h SKIPHEADERS-$(HAVE_SNDIO) += sndio.h diff --git a/libavdevice/v4l2-common.c b/libavdevice/v4l2-common.c deleted file mode 100644 index 196c09b..0000000 --- a/libavdevice/v4l2-common.c +++ /dev/null @@ -1,105 +0,0 @@ -/* - * 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 "v4l2-common.h" - -const struct fmt_map ff_fmt_conversion_table[] = { - //ff_fmt codec_id v4l2_fmt - { AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV420 }, - { AV_PIX_FMT_YUV420P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YVU420 }, - { AV_PIX_FMT_YUV422P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV422P }, - { AV_PIX_FMT_YUYV422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUYV }, - { AV_PIX_FMT_UYVY422, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_UYVY }, - { AV_PIX_FMT_YUV411P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV411P }, - { AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YUV410 }, - { AV_PIX_FMT_YUV410P, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_YVU410 }, - { AV_PIX_FMT_RGB555LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555 }, - { AV_PIX_FMT_RGB555BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB555X }, - { AV_PIX_FMT_RGB565LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565 }, - { AV_PIX_FMT_RGB565BE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB565X }, - { AV_PIX_FMT_BGR24, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR24 }, - { AV_PIX_FMT_RGB24, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB24 }, - { AV_PIX_FMT_BGR0, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_BGR32 }, - { AV_PIX_FMT_0RGB, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_RGB32 }, - { AV_PIX_FMT_GRAY8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_GREY }, -#ifdef V4L2_PIX_FMT_Y16 - { AV_PIX_FMT_GRAY16LE,AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_Y16 }, -#endif - { AV_PIX_FMT_NV12, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_NV12 }, - { AV_PIX_FMT_NONE, AV_CODEC_ID_MJPEG, V4L2_PIX_FMT_MJPEG }, - { AV_PIX_FMT_NONE, AV_CODEC_ID_MJPEG, V4L2_PIX_FMT_JPEG }, -#ifdef V4L2_PIX_FMT_H264 - { AV_PIX_FMT_NONE, AV_CODEC_ID_H264, V4L2_PIX_FMT_H264 }, -#endif -#ifdef V4L2_PIX_FMT_MPEG4 - { AV_PIX_FMT_NONE, AV_CODEC_ID_MPEG4, V4L2_PIX_FMT_MPEG4 }, -#endif -#ifdef V4L2_PIX_FMT_CPIA1 - { AV_PIX_FMT_NONE, AV_CODEC_ID_CPIA, V4L2_PIX_FMT_CPIA1 }, -#endif -#ifdef V4L2_PIX_FMT_SRGGB8 - { AV_PIX_FMT_BAYER_BGGR8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_SBGGR8 }, - { AV_PIX_FMT_BAYER_GBRG8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_SGBRG8 }, - { AV_PIX_FMT_BAYER_GRBG8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_SGRBG8 }, - { AV_PIX_FMT_BAYER_RGGB8, AV_CODEC_ID_RAWVIDEO, V4L2_PIX_FMT_SRGGB8 }, -#endif - { AV_PIX_FMT_NONE, AV_CODEC_ID_NONE, 0 }, -}; - -uint32_t ff_fmt_ff2v4l(enum AVPixelFormat pix_fmt, enum AVCodecID codec_id) -{ - int i; - - for (i = 0; ff_fmt_conversion_table[i].codec_id != AV_CODEC_ID_NONE; i++) { - if ((codec_id == AV_CODEC_ID_NONE || - ff_fmt_conversion_table[i].codec_id == codec_id) && - (pix_fmt == AV_PIX_FMT_NONE || - ff_fmt_conversion_table[i].ff_fmt == pix_fmt)) { - return ff_fmt_conversion_table[i].v4l2_fmt; - } - } - - return 0; -} - -enum AVPixelFormat ff_fmt_v4l2ff(uint32_t v4l2_fmt, enum AVCodecID codec_id) -{ - int i; - - for (i = 0; ff_fmt_conversion_table[i].codec_id != AV_CODEC_ID_NONE; i++) { - if (ff_fmt_conversion_table[i].v4l2_fmt == v4l2_fmt && - ff_fmt_conversion_table[i].codec_id == codec_id) { - return ff_fmt_conversion_table[i].ff_fmt; - } - } - - return AV_PIX_FMT_NONE; -} - -enum AVCodecID ff_fmt_v4l2codec(uint32_t v4l2_fmt) -{ - int i; - - for (i = 0; ff_fmt_conversion_table[i].codec_id != AV_CODEC_ID_NONE; i++) { - if (ff_fmt_conversion_table[i].v4l2_fmt == v4l2_fmt) { - return ff_fmt_conversion_table[i].codec_id; - } - } - - return AV_CODEC_ID_NONE; -} diff --git a/libavdevice/v4l2-common.h b/libavdevice/v4l2-common.h deleted file mode 100644 index 0cbaec8..0000000 --- a/libavdevice/v4l2-common.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 - */ - -#ifndef AVDEVICE_V4L2_COMMON_H -#define AVDEVICE_V4L2_COMMON_H - -#undef __STRICT_ANSI__ //workaround due to broken kernel headers -#include "config.h" -#include "libavformat/internal.h" -#include -#include -#include -#include -#include -#if HAVE_SYS_VIDEOIO_H -#include -#else -#if HAVE_ASM_TYPES_H -#include -#endif -#include -#endif -#include "libavutil/avassert.h" -#include "libavutil/imgutils.h" -#include "libavutil/log.h" -#include "libavutil/opt.h" -#include "avdevice.h" -#include "timefilter.h" -#include "libavutil/parseutils.h" -#include "libavutil/pixdesc.h" -#include "libavutil/time.h" -#include "libavutil/avstring.h" - -struct fmt_map { - enum AVPixelFormat ff_fmt; - enum AVCodecID codec_id; - uint32_t v4l2_fmt; -}; - -extern const struct fmt_map ff_fmt_conversion_table[]; - -uint32_t ff_fmt_ff2v4l(enum AVPixelFormat pix_fmt, enum AVCodecID codec_id); -enum AVPixelFormat ff_fmt_v4l2ff(uint32_t v4l2_fmt, enum AVCodecID codec_id); -enum AVCodecID ff_fmt_v4l2codec(uint32_t v4l2_fmt); - -#endif /* AVDEVICE_V4L2_COMMON_H */ diff --git a/libavdevice/v4l2.c b/libavdevice/v4l2.c index 17451cd..1585800 100644 --- a/libavdevice/v4l2.c +++ b/libavdevice/v4l2.c @@ -31,8 +31,23 @@ */ #include - -#include "v4l2-common.h" +#include +#include +#include +#include +#include +#include + +#include "libavutil/atomic.h" +#include "libavutil/avassert.h" +#include "libavutil/avstring.h" +#include "libavutil/imgutils.h" +#include "libavutil/parseutils.h" +#include "libavutil/time.h" +#include "libavcodec/v4l2_fmt.h" +#include "libavformat/internal.h" +#include "avdevice.h" +#include "timefilter.h" #include #if CONFIG_LIBV4L2 @@ -274,8 +289,8 @@ static void list_formats(AVFormatContext *ctx, int type) struct v4l2_fmtdesc vfd = { .type = V4L2_BUF_TYPE_VIDEO_CAPTURE }; while(!v4l2_ioctl(s->fd, VIDIOC_ENUM_FMT, &vfd)) { - enum AVCodecID codec_id = ff_fmt_v4l2codec(vfd.pixelformat); - enum AVPixelFormat pix_fmt = ff_fmt_v4l2ff(vfd.pixelformat, codec_id); + enum AVCodecID codec_id = avpriv_v4l_fmt_v4l2codec(vfd.pixelformat); + enum AVPixelFormat pix_fmt = avpriv_v4l_fmt_v4l2ff(vfd.pixelformat, codec_id); vfd.index++; @@ -766,7 +781,7 @@ static int device_try_init(AVFormatContext *ctx, { int ret, i; - *desired_format = ff_fmt_ff2v4l(pix_fmt, ctx->video_codec_id); + *desired_format = avpriv_v4l_fmt_ff2v4l(pix_fmt, ctx->video_codec_id); if (*desired_format) { ret = device_init(ctx, width, height, *desired_format); @@ -778,14 +793,14 @@ static int device_try_init(AVFormatContext *ctx, } if (!*desired_format) { - for (i = 0; ff_fmt_conversion_table[i].codec_id != AV_CODEC_ID_NONE; i++) { + for (i = 0; avpriv_v4l_fmt_conversion_table[i].codec_id != AV_CODEC_ID_NONE; i++) { if (ctx->video_codec_id == AV_CODEC_ID_NONE || - ff_fmt_conversion_table[i].codec_id == ctx->video_codec_id) { + avpriv_v4l_fmt_conversion_table[i].codec_id == ctx->video_codec_id) { av_log(ctx, AV_LOG_DEBUG, "Trying to set codec:%s pix_fmt:%s\n", - avcodec_get_name(ff_fmt_conversion_table[i].codec_id), - (char *)av_x_if_null(av_get_pix_fmt_name(ff_fmt_conversion_table[i].ff_fmt), "none")); + avcodec_get_name(avpriv_v4l_fmt_conversion_table[i].codec_id), + (char *)av_x_if_null(av_get_pix_fmt_name(avpriv_v4l_fmt_conversion_table[i].ff_fmt), "none")); - *desired_format = ff_fmt_conversion_table[i].v4l2_fmt; + *desired_format = avpriv_v4l_fmt_conversion_table[i].v4l2_fmt; ret = device_init(ctx, width, height, *desired_format); if (ret >= 0) break; @@ -804,7 +819,7 @@ static int device_try_init(AVFormatContext *ctx, } } - *codec_id = ff_fmt_v4l2codec(*desired_format); + *codec_id = avpriv_v4l_fmt_v4l2codec(*desired_format); av_assert0(*codec_id != AV_CODEC_ID_NONE); return ret; } @@ -937,11 +952,10 @@ static int v4l2_read_header(AVFormatContext *ctx) if ((res = v4l2_set_parameters(ctx)) < 0) goto fail; - st->codecpar->format = ff_fmt_v4l2ff(desired_format, codec_id); + st->codecpar->format = avpriv_v4l_fmt_v4l2ff(desired_format, codec_id); if (st->codecpar->format != AV_PIX_FMT_NONE) s->frame_size = av_image_get_buffer_size(st->codecpar->format, s->width, s->height, 1); - if ((res = mmap_init(ctx)) || (res = mmap_start(ctx)) < 0) goto fail; diff --git a/libavdevice/v4l2enc.c b/libavdevice/v4l2enc.c index faf6e07..24ca32b 100644 --- a/libavdevice/v4l2enc.c +++ b/libavdevice/v4l2enc.c @@ -18,7 +18,15 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "v4l2-common.h" +#include +#include +#include +#include +#include + +#include "libavutil/imgutils.h" +#include "libavutil/pixdesc.h" +#include "libavcodec/v4l2_fmt.h" #include "avdevice.h" typedef struct { @@ -56,7 +64,7 @@ static av_cold int write_header(AVFormatContext *s1) par = s1->streams[0]->codecpar; - v4l2_pixfmt = ff_fmt_ff2v4l(par->format, AV_CODEC_ID_RAWVIDEO); + v4l2_pixfmt = avpriv_v4l_fmt_ff2v4l(par->format, AV_CODEC_ID_RAWVIDEO); if (!v4l2_pixfmt) { // XXX: try to force them one by one? av_log(s1, AV_LOG_ERROR, "Unknown V4L2 pixel format equivalent for %s\n", av_get_pix_fmt_name(par->format));