From patchwork Tue Aug 8 16:07:05 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: 4657 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.46.211 with SMTP id u202csp4448583vsu; Tue, 8 Aug 2017 09:07:39 -0700 (PDT) X-Received: by 10.28.178.75 with SMTP id b72mr3009994wmf.55.1502208458970; Tue, 08 Aug 2017 09:07:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502208458; cv=none; d=google.com; s=arc-20160816; b=C5oQl7VdqJaaMYYgxsyWH2b7oguVbeWouFa1n79kB+jkn8iMBhoQ02vOtz+K1B7QEh b7aBBnCVgI2+dGN1v1wllFL6e2ClfzgXNw42mhwveRk5y88ZhpOnGxkKxOChdvWo9DLF GO+Hmc1CsXHe1aKp7meZ+ST6jENm9jtBMYJ47y8vC3v7gPznKKSHEbQqT52YfcZivID3 h5OT4LjKNR42yr8Gp9OeF1U9h75hmcvQSdIh72JlhGd665I+Ud9OsTJbUtKIr3VrxbuM hE9AhQAlz8q4Kq2jw/lN3tl6H1/pkpyAQ7pmZLJoYc4eh/W0nSSqo7W/JIYS0NGuNW5E 3Ckg== 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=UwXzqNNsofilTo3DjXGMw4bw31KQZ+ND0edGr5ZhSguesWWU37klbcd4Avbag0+Ql4 i6DT0sPZIcyiNvXnOSZ5r8xHzOGKzGxlgaf/QPOUJY3U6mrnw6+ktHkNteCxaN7ofHwD 2nlI2D8IuKIehNtC3urURFDa2YuAFG5LdTbJQ7NeoPWyteeGfJyDo8Y7gYo/txDz/w9S e0EVeTU3a1XgW/XTmG2FF5eOpYW/gdMc5AcdHXgqS2aeM490RZAa9Ov801jKnFxAeYqB neoh5IjUa0jqiGw+8Nq5hShBgJkwtEFIGVpuU5wRr0o9JJQvxDXao0KzwDxQ1Zt5qYuc sfOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jkHiSsov; 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 15si1425136wrl.295.2017.08.08.09.07.38; Tue, 08 Aug 2017 09:07:38 -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=jkHiSsov; 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 B07206883BA; Tue, 8 Aug 2017 19:07:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f54.google.com (mail-wm0-f54.google.com [74.125.82.54]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F13368799F for ; Tue, 8 Aug 2017 19:07:16 +0300 (EEST) Received: by mail-wm0-f54.google.com with SMTP id m85so11219344wma.0 for ; Tue, 08 Aug 2017 09:07:18 -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=jkHiSsov+MbEB6L2vNeFF5Dm8ZJq4STbKRJadTdceCqW4RVO8fRmD8N/C/tOTH4sqQ iX23Ec8f2z1utteX+g8oP+QeiFduIXbzPus/CQSWQ9YLpP/13RZhIHVgXfC5IoIEoQ3F j1/DZxepQJFG5tMXmKAJD2GLi7gpwldtab0Tc= 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=o741PY8GK1iBD2NwftdQ3/2l80ga8RepOhE2wG/khz1Ef2giYwx/gD6MWEfyWQeZSN XsEIWzPUjIU/5+DySlE16TSrGzti7So1QQ7huwth9Kk7askrGYc6E0Tm15VOWqAgv2vi /knkGZuKUpya32SuVITTAW/S4rXxgPunzTso1KAIO1ekobI55AfwqtrEaYSas1SllnnO borGb6HnB7VGSKjmum+FVsaNw9vj/PY0qjOZqn4Sr64jXcTyTnAGJrC9g4SqhIesmz4x ZX560zJ+S37zrF+a51yCIW60HV3QKRE1L9YhZNU6Nr64KwBMbvSOk1v4hjEkiX4dol/1 dv+w== X-Gm-Message-State: AHYfb5i/2WGlgNe02lh4Q+9WaPM+BdwROabajYGg35cUHr9KLmEwx4a+ E/DHxWUEuSizNh/4 X-Received: by 10.28.191.14 with SMTP id p14mr3986392wmf.64.1502208437468; Tue, 08 Aug 2017 09:07:17 -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 u30sm1477395wru.88.2017.08.08.09.07.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Aug 2017 09:07:16 -0700 (PDT) From: Jorge Ramirez-Ortiz To: jorge.ramirez-ortiz@linaro.org, ffmpeg-devel@ffmpeg.org, sw@jkqxz.net Date: Tue, 8 Aug 2017 18:07:05 +0200 Message-Id: <1502208428-17267-2-git-send-email-jorge.ramirez-ortiz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502208428-17267-1-git-send-email-jorge.ramirez-ortiz@linaro.org> References: <1502208428-17267-1-git-send-email-jorge.ramirez-ortiz@linaro.org> Subject: [FFmpeg-devel] [PATCHv4 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 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));