From patchwork Fri Aug 25 11:22:45 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: 4833 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.15.201 with SMTP id 70csp327080jao; Fri, 25 Aug 2017 04:29:19 -0700 (PDT) X-Received: by 10.28.47.142 with SMTP id v136mr1021952wmv.59.1503660559544; Fri, 25 Aug 2017 04:29:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503660559; cv=none; d=google.com; s=arc-20160816; b=sc4AD/+LsZ9wBhP9Cr2sLsQGIRwfQk6vWvU7ca4tKtNbYbhduj6ZxGSyLR6MPSJwNs 3WLTYuaqdNK/hs7MC+57U3YtyNyOkelbWg9esHPRVJIg/xmdFQrdFeFIcL9ekXWUzwVt 43vvoR2qsZPo0IMOzxq7Syx/gxjVA3vs+ROiGfoaq2kN7kFSi4QD6s1Qq+FugOtP8TNn DoncUN/vzGhQAYTL1vkCTAgGs/QEobfFMtBnACuc6VoFMLIT23/qOdQRlVrV/UuaO3tY hJjyoMzWMZZuYD2m0Ei8n0yFaZ9IVKVpQ+IXRzmqa+fOhnm1NqTyAzP42HAGxpYU2+xI v2Jw== 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=xsjMDzZHu7drGg4HVPIt0p7uB/h/8kks3SZmkPkRrZI=; b=X7SEVX8nLyNLd3rTorpuj5VTTxolOGR0cACNoaqS8ucRmaPHB67wr2LbxEYr0gApqK kA46cl1jH6UDKBUt3RYXszh6cV+Nsire+TqvbpWdagbUB/2P5zCdSez+eCt6Mbqy3/4h O6I4UBl+ueu4VGwOQPb0GDnQpaGA+91ngblM0Gt05itt1b9ChJzfh9ahhCQGUuqwwkVV x7VkKXyut1M0vGhBtfB38VbRcbzjl/pRA4EUq0hBEJESbF19pVyIN1jXRb07xEAQxYQl D1CSWYavB5mA6MlHTMhENOM9rTdLrlxB8Zla4QAkAUILqvwSmiskXFUsJogpxExqR9rR SnNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=VL5a903i; 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 j37si5133707wrj.331.2017.08.25.04.29.18; Fri, 25 Aug 2017 04:29:19 -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=VL5a903i; 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 70C94689AC3; Fri, 25 Aug 2017 14:29:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ACB21689A9D for ; Fri, 25 Aug 2017 14:29:00 +0300 (EEST) Received: by mail-wm0-f51.google.com with SMTP id y71so649964wmd.0 for ; Fri, 25 Aug 2017 04:29:09 -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=1mwweH/yeuNt0Cpi/vH7ocmeAN2siLfM3N0L3kdl6kE=; b=VL5a903iBSSUlIUh+bvsGBLh2ARawWhi3//Ox2I+fkG/m9EeMzMPu41r1lUaaK7pzc Y4ROJuPvkl4LnlIogQXjRp11dFbiO0TTmWyhU7dzBl9B0nJ2+Uac152i2V7VgHyYMgjN eTjcz661g23N8hwRsBzl8y7l1u8k11JMZFeTc= 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=1mwweH/yeuNt0Cpi/vH7ocmeAN2siLfM3N0L3kdl6kE=; b=eYikPBGxNDyEbfAbZSftvE5h6UVnenYG0fP9pP/SUEje4MNhr96u1JJX2+jhyk+D6+ TKgyvQ62A+O7AKgMET8k/jFA5TFVdeE5xjucnxcdcMyQrPTHYXwkMjFQDhU/J0AuwnOj 2qLGfddtEu0GQqoYf9gYgvbzRnHocMIMIaudNzpgPJHGLsSZHsJQXEq25UgtEwYbF1NT Q6kPrrTizbvUG49kF9RYGbjwSfbO0Gow3OSkF/h3mPFffQ0bmcVOli4y6OCZa+IUC6IE Ds+j2NWIEg2CX+ljT4y6jD4CzMKjaYLMeE9BLXOXqxBPfrKaWpzffiWI9i53qZ79UQLr 0+iA== X-Gm-Message-State: AHYfb5iRQ+DAcISRubFeQSh+wUa6hoHDF5Th2h8hxuOKd32LA0jlj6CH ITFMhPbmUbFfn5hF X-Received: by 10.28.180.138 with SMTP id d132mr1318220wmf.33.1503660175901; Fri, 25 Aug 2017 04:22:55 -0700 (PDT) Received: from igloo.80.58.61.254 (1.red-88-10-92.dynamicip.rima-tde.net. [88.10.92.1]) by smtp.gmail.com with ESMTPSA id 134sm1107567wmw.24.2017.08.25.04.22.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 Aug 2017 04:22:55 -0700 (PDT) From: Jorge Ramirez-Ortiz To: jorge.ramirez-ortiz@linaro.org, sw@jkqxz.net, ffmpeg-devel@ffmpeg.org, michael@niedermayer.cc Date: Fri, 25 Aug 2017 13:22:45 +0200 Message-Id: <1503660168-24757-2-git-send-email-jorge.ramirez-ortiz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1503660168-24757-1-git-send-email-jorge.ramirez-ortiz@linaro.org> References: <1503660168-24757-1-git-send-email-jorge.ramirez-ortiz@linaro.org> Subject: [FFmpeg-devel] [PATCHv6 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 7201941..e048b02 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 @@ -2269,6 +2270,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" @@ -3042,8 +3044,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 982d7f5..153247f 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));