├── libva ├── AUTHORS ├── autogen.sh ├── COPYING ├── Makefile.am ├── .gitignore ├── README.md ├── COPYING.MIT ├── src │ ├── Makefile.am │ ├── tiled_yuv.h │ ├── picture.h │ ├── mpeg2.h │ ├── mpeg4.h │ ├── sunxi_cedrus_drv_video.h │ ├── context.h │ ├── image.h │ ├── buffer.h │ ├── subpicture.h │ ├── object_heap.h │ ├── surface.h │ ├── subpicture.c │ ├── va_config.h │ ├── tiled_yuv.S │ ├── image.c │ ├── mpeg2.c │ ├── context.c │ ├── buffer.c │ ├── mpeg4.c │ └── object_heap.c └── configure.ac ├── driver ├── .gitignore ├── Makefile ├── sunxi_cedrus_dec.h ├── sunxi-cedrus.txt ├── sunxi_cedrus_hw.h ├── sunxi_cedrus_common.h ├── sunxi_cedrus_hw.c ├── sunxi_cedrus_mpeg4.c ├── sunxi_cedrus_regs.h └── sunxi_cedrus_mpeg2.c ├── patches ├── 4.9 │ ├── 0017-v4l-Add-sunxi-Video-Engine-pixel-format.patch │ ├── 0002-videodev2.h-add-request-to-v4l2_ext_controls.patch │ ├── 0016-v4l-Add-private-compound-control-type.patch │ ├── 0021-ARM-dts-sun5i-Use-video-engine-node.patch │ ├── 0004-vb2-add-allow_requests-flag.patch │ ├── 0022-ARM-dts-sun8i-add-video-engine-support-for-A33.patch │ ├── 0001-videodev2.h-add-max_reqs-to-struct-v4l2_query_ext_ct.patch │ ├── 0012-v4l2-device-add-v4l2_device_req_queue.patch │ ├── 0007-v4l2-ctrls-implement-delete-request-s.patch │ ├── 0010-vb2-add-helper-function-to-queue-request-specific-bu.patch │ ├── 0009-v4l2-add-initial-V4L2_REQ_CMD_QUEUE-support.patch │ ├── 0013-vivid-add-request-support-for-video-capture.patch │ ├── 0011-v4l2-device-keep-track-of-registered-video_devices.patch │ ├── 0003-videodev2.h-add-request-field-to-v4l2_buffer.patch │ ├── 0018-v4l-Add-MPEG2-low-level-decoder-API-control.patch │ └── 0019-v4l-Add-MPEG4-low-level-decoder-API-control.patch └── 4.14 │ ├── 0016-v4l-Add-sunxi-Video-Engine-pixel-format.patch │ ├── 0002-videodev2.h-add-request-to-v4l2_ext_controls.patch │ ├── 0019-ARM-dts-sun5i-Use-video-engine-node.patch │ ├── 0004-vb2-add-allow_requests-flag.patch │ ├── 0020-ARM-dts-sun8i-add-video-engine-support-for-A33.patch │ ├── 0010-vb2-add-helper-function-to-queue-request-specific-bu.patch │ ├── 0001-videodev2.h-add-max_reqs-to-struct-v4l2_query_ext_ct.patch │ ├── 0022-ARM-dts-sun7i-Add-video-engine-support-for-the-A20.patch │ ├── 0012-v4l2-device-add-v4l2_device_req_queue.patch │ ├── 0007-v4l2-ctrls-implement-delete-request-s.patch │ ├── 0009-v4l2-add-initial-V4L2_REQ_CMD_QUEUE-support.patch │ ├── 0011-v4l2-device-keep-track-of-registered-video_devices.patch │ ├── 0013-vivid-add-request-support-for-video-capture.patch │ ├── 0003-videodev2.h-add-request-field-to-v4l2_buffer.patch │ ├── 0017-v4l-Add-MPEG2-low-level-decoder-API-control.patch │ └── 0018-v4l-Add-MPEG4-low-level-decoder-API-control.patch └── .travis.yml /libva/AUTHORS: -------------------------------------------------------------------------------- 1 | Florent Revest 2 | -------------------------------------------------------------------------------- /driver/.gitignore: -------------------------------------------------------------------------------- 1 | *.ko.cmd 2 | *.mod.c 3 | *.o 4 | *.o.cmd 5 | .tmp_versions 6 | modules.order 7 | Module.symvers 8 | -------------------------------------------------------------------------------- /libva/autogen.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | autoreconf -v --install 4 | 5 | if test -z "$NOCONFIGURE"; then 6 | ./configure "$@" 7 | fi 8 | -------------------------------------------------------------------------------- /libva/COPYING: -------------------------------------------------------------------------------- 1 | This code has two licenses: MIT and LGPL the details of each license is included 2 | in the beginning of each file and the full text of those two licenses are 3 | distributed in COPYING.MIT and COPYING.LGPL 4 | -------------------------------------------------------------------------------- /libva/Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = foreign 2 | 3 | SUBDIRS = src 4 | 5 | # Extra clean files so that maintainer-clean removes *everything* 6 | MAINTAINERCLEANFILES = \ 7 | aclocal.m4 compile config.guess config.sub \ 8 | configure depcomp install-sh ltmain.sh \ 9 | Makefile.in missing 10 | -------------------------------------------------------------------------------- /driver/Makefile: -------------------------------------------------------------------------------- 1 | ifneq ($(KERNELRELEASE),) 2 | 3 | obj-m := sunxi-cedrus.o 4 | 5 | sunxi-cedrus-y := sunxi_cedrus.o sunxi_cedrus_hw.o sunxi_cedrus_dec.o \ 6 | sunxi_cedrus_mpeg2.o sunxi_cedrus_mpeg4.o 7 | 8 | else 9 | KDIR ?= /lib/modules/$(uname -r)/build 10 | 11 | default: 12 | $(MAKE) -C $(KDIR) M=$$PWD 13 | endif 14 | -------------------------------------------------------------------------------- /libva/.gitignore: -------------------------------------------------------------------------------- 1 | # Object files 2 | *.o 3 | *.ko 4 | 5 | # Libraries 6 | *.lib 7 | *.a 8 | *.lo 9 | *.la 10 | 11 | # Shared objects (inc. Windows DLLs) 12 | *.dll 13 | *.so 14 | *.so.* 15 | *.dylib 16 | 17 | # Misc 18 | *~ 19 | *.orig 20 | *.rej 21 | *.loT 22 | *.bin 23 | *.pc 24 | *.g[4-7]s 25 | .deps 26 | .libs 27 | install-sh 28 | libtool 29 | ltmain.sh 30 | compile 31 | missing 32 | Makefile 33 | Makefile.in 34 | config.h 35 | config.h.in 36 | stamp-h1 37 | aclocal.m4 38 | autom4te.cache 39 | config.guess 40 | config.log 41 | config.status 42 | config.sub 43 | configure 44 | depcomp 45 | TAGS 46 | -------------------------------------------------------------------------------- /libva/README.md: -------------------------------------------------------------------------------- 1 | Sunxi Cedrus VA backend 2 | ======================= 3 | 4 | This libVA video driver is designed to work with the v4l2 "sunxi-cedrus" kernel 5 | driver. However, the only sunxi-cedrus specific part is the format conversion 6 | from tiled to planar, otherwise it would be generic enough to be used with other 7 | v4l2 drivers using the "Frame API". 8 | 9 | You can try this driver with VLC but don't forget to tell libVA to use this 10 | backend: 11 | 12 | export LIBVA_DRIVER_NAME=sunxi_cedrus 13 | vlc big_buck_bunny_480p_MPEG2_MP2_25fps_1800K.MPG 14 | 15 | Sample media files can be found here: 16 | 17 | http://samplemedia.linaro.org/MPEG2/ 18 | http://samplemedia.linaro.org/MPEG4/SVT/ 19 | -------------------------------------------------------------------------------- /libva/COPYING.MIT: -------------------------------------------------------------------------------- 1 | Permission is hereby granted, free of charge, to any person obtaining a 2 | copy of this software and associated documentation files (the 3 | "Software"), to deal in the Software without restriction, including 4 | without limitation the rights to use, copy, modify, merge, publish, 5 | distribute, sub license, and/or sell copies of the Software, and to 6 | permit persons to whom the Software is furnished to do so, subject to 7 | the following conditions: 8 | 9 | The above copyright notice and this permission notice (including the 10 | next paragraph) shall be included in all copies or substantial portions 11 | of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 14 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 15 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 16 | IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 17 | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 18 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 19 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /driver/sunxi_cedrus_dec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sunxi Cedrus codec driver 3 | * 4 | * Copyright (C) 2016 Florent Revest 5 | * Florent Revest 6 | * 7 | * Based on vim2m 8 | * 9 | * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd. 10 | * Pawel Osciak, 11 | * Marek Szyprowski, 12 | * 13 | * This software is licensed under the terms of the GNU General Public 14 | * License version 2, as published by the Free Software Foundation, and 15 | * may be copied, distributed, and modified under those terms. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | */ 22 | 23 | #ifndef SUNXI_CEDRUS_DEC_H_ 24 | #define SUNXI_CEDRUS_DEC_H_ 25 | 26 | int queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq); 27 | 28 | void job_abort(void *priv); 29 | void device_run(void *priv); 30 | 31 | extern const struct v4l2_ioctl_ops sunxi_cedrus_ioctl_ops; 32 | 33 | #endif /* SUNXI_CEDRUS_DEC_H_ */ 34 | -------------------------------------------------------------------------------- /libva/src/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = \ 2 | -DPTHREADS \ 3 | $(X11_DEPS_CFLAGS)\ 4 | $(DRM_CFLAGS) \ 5 | $(LIBVA_DEPS_CFLAGS) 6 | 7 | driver_cflags = \ 8 | -Wall \ 9 | -fvisibility=hidden 10 | 11 | driver_ldflags = \ 12 | -module -avoid-version \ 13 | -no-undefined \ 14 | -Wl,--no-undefined 15 | 16 | driver_libs = \ 17 | -lpthread -ldl \ 18 | $(DRM_LIBS) \ 19 | $(X11_DEPS_LIBS) \ 20 | $(LIBVA_DEPS_LIBS) 21 | 22 | source_c = sunxi_cedrus_drv_video.c object_heap.c buffer.c va_config.c \ 23 | context.c image.c mpeg2.c mpeg4.c picture.c subpicture.c surface.c 24 | 25 | source_s = \ 26 | tiled_yuv.S 27 | 28 | source_h = sunxi_cedrus_drv_video.h object_heap.h buffer.h va_config.h \ 29 | context.h image.h mpeg2.h mpeg4.h picture.h subpicture.h surface.h \ 30 | tiled_yuv.h 31 | 32 | sunxi_cedrus_drv_video_la_LTLIBRARIES = sunxi_cedrus_drv_video.la 33 | sunxi_cedrus_drv_video_ladir = $(LIBVA_DRIVERS_PATH) 34 | sunxi_cedrus_drv_video_la_CFLAGS = $(driver_cflags) 35 | sunxi_cedrus_drv_video_la_LDFLAGS = $(driver_ldflags) 36 | sunxi_cedrus_drv_video_la_LIBADD = $(driver_libs) 37 | sunxi_cedrus_drv_video_la_SOURCES = $(source_c) $(source_s) 38 | noinst_HEADERS = $(source_h) 39 | 40 | MAINTAINERCLEANFILES = Makefile.in config.h.in 41 | -------------------------------------------------------------------------------- /driver/sunxi-cedrus.txt: -------------------------------------------------------------------------------- 1 | Device-Tree bindings for SUNXI video engine found in sunXi SoC family 2 | 3 | Required properties: 4 | - compatible : "allwinner,sun5i-a13-video-engine"; 5 | - memory-region : DMA pool for buffers allocation; 6 | - clocks : list of clock specifiers, corresponding to 7 | entries in clock-names property; 8 | - clock-names : should contain "ahb", "mod" and "ram" entries; 9 | - resets : phandle for reset; 10 | - interrupts : should contain VE interrupt number; 11 | - reg : should contain register base and length of VE. 12 | 13 | Example: 14 | 15 | reserved-memory { 16 | #address-cells = <1>; 17 | #size-cells = <1>; 18 | ranges; 19 | 20 | ve_reserved: cma { 21 | compatible = "shared-dma-pool"; 22 | reg = <0x43d00000 0x9000000>; 23 | no-map; 24 | linux,cma-default; 25 | }; 26 | }; 27 | 28 | video-engine { 29 | compatible = "allwinner,sun5i-a13-video-engine"; 30 | memory-region = <&ve_reserved>; 31 | 32 | clocks = <&ahb_gates 32>, <&ccu CLK_VE>, 33 | <&dram_gates 0>; 34 | clock-names = "ahb", "mod", "ram"; 35 | 36 | assigned-clocks = <&ccu CLK_VE>; 37 | assigned-clock-rates = <320000000>; 38 | 39 | resets = <&ccu RST_VE>; 40 | 41 | interrupts = <53>; 42 | 43 | reg = <0x01c0e000 4096>; 44 | }; 45 | -------------------------------------------------------------------------------- /libva/src/tiled_yuv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Jens Kuske 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | #ifndef __TILED_YUV_H__ 21 | #define __TILED_YUV_H__ 22 | 23 | void tiled_to_planar(void *src, void *dst, unsigned int dst_pitch, 24 | unsigned int width, unsigned int height); 25 | 26 | void tiled_deinterleave_to_planar(void *src, void *dst1, void *dst2, 27 | unsigned int dst_pitch, 28 | unsigned int width, unsigned int height); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /driver/sunxi_cedrus_hw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sunxi Cedrus codec driver 3 | * 4 | * Copyright (C) 2016 Florent Revest 5 | * Florent Revest 6 | * 7 | * Based on vim2m 8 | * 9 | * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd. 10 | * Pawel Osciak, 11 | * Marek Szyprowski, 12 | * 13 | * This software is licensed under the terms of the GNU General Public 14 | * License version 2, as published by the Free Software Foundation, and 15 | * may be copied, distributed, and modified under those terms. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | */ 22 | 23 | #ifndef SUNXI_CEDRUS_HW_H_ 24 | #define SUNXI_CEDRUS_HW_H_ 25 | 26 | struct sunxi_cedrus_dev; 27 | struct sunxi_cedrus_ctx; 28 | 29 | int sunxi_cedrus_hw_probe(struct sunxi_cedrus_dev *vpu); 30 | void sunxi_cedrus_hw_remove(struct sunxi_cedrus_dev *vpu); 31 | 32 | void process_mpeg2(struct sunxi_cedrus_ctx *ctx, dma_addr_t in_buf, 33 | dma_addr_t out_luma, dma_addr_t out_chroma, 34 | struct v4l2_ctrl_mpeg2_frame_hdr *frame_hdr); 35 | void process_mpeg4(struct sunxi_cedrus_ctx *ctx, dma_addr_t in_buf, 36 | dma_addr_t out_luma, dma_addr_t out_chroma, 37 | struct v4l2_ctrl_mpeg4_frame_hdr *frame_hdr); 38 | 39 | #endif /* SUNXI_CEDRUS_HW_H_ */ 40 | -------------------------------------------------------------------------------- /patches/4.9/0017-v4l-Add-sunxi-Video-Engine-pixel-format.patch: -------------------------------------------------------------------------------- 1 | From d1e30c8873996a15b3e62c071aeb15a2cd372f5a Mon Sep 17 00:00:00 2001 2 | From: Florent Revest 3 | Date: Wed, 24 Aug 2016 13:25:33 +0200 4 | Subject: [PATCH] v4l: Add sunxi Video Engine pixel format 5 | 6 | Add support for the allwinner's proprietary pixel format described in 7 | details here: http://linux-sunxi.org/File:Ve_tile_format_v1.pdf 8 | 9 | This format is similar to V4L2_PIX_FMT_NV12M but the planes are divided 10 | in tiles of 32x32px. 11 | 12 | Signed-off-by: Florent Revest 13 | --- 14 | include/uapi/linux/videodev2.h | 1 + 15 | 1 file changed, 1 insertion(+) 16 | 17 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 18 | index 01c8bfc2fd21..82979987bff0 100644 19 | --- a/include/uapi/linux/videodev2.h 20 | +++ b/include/uapi/linux/videodev2.h 21 | @@ -634,6 +634,7 @@ struct v4l2_pix_format { 22 | #define V4L2_PIX_FMT_Y8I v4l2_fourcc('Y', '8', 'I', ' ') /* Greyscale 8-bit L/R interleaved */ 23 | #define V4L2_PIX_FMT_Y12I v4l2_fourcc('Y', '1', '2', 'I') /* Greyscale 12-bit L/R interleaved */ 24 | #define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ') /* Depth data 16-bit */ 25 | +#define V4L2_PIX_FMT_SUNXI v4l2_fourcc('S', 'X', 'I', 'Y') /* Sunxi VE's 32x32 tiled NV12 */ 26 | 27 | /* SDR formats - used only for Software Defined Radio devices */ 28 | #define V4L2_SDR_FMT_CU8 v4l2_fourcc('C', 'U', '0', '8') /* IQ u8 */ 29 | -- 30 | 2.14.3 31 | 32 | -------------------------------------------------------------------------------- /patches/4.14/0016-v4l-Add-sunxi-Video-Engine-pixel-format.patch: -------------------------------------------------------------------------------- 1 | From a71ee62c3f808dd4def55784bcae6ae078d5afa5 Mon Sep 17 00:00:00 2001 2 | From: Florent Revest 3 | Date: Wed, 24 Aug 2016 13:25:33 +0200 4 | Subject: [PATCH 16/22] v4l: Add sunxi Video Engine pixel format 5 | 6 | Add support for the allwinner's proprietary pixel format described in 7 | details here: http://linux-sunxi.org/File:Ve_tile_format_v1.pdf 8 | 9 | This format is similar to V4L2_PIX_FMT_NV12M but the planes are divided 10 | in tiles of 32x32px. 11 | 12 | Signed-off-by: Florent Revest 13 | --- 14 | include/uapi/linux/videodev2.h | 1 + 15 | 1 file changed, 1 insertion(+) 16 | 17 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 18 | index 3cac84dd7f11..91b82f6531ed 100644 19 | --- a/include/uapi/linux/videodev2.h 20 | +++ b/include/uapi/linux/videodev2.h 21 | @@ -668,6 +668,7 @@ struct v4l2_pix_format { 22 | #define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ') /* Depth data 16-bit */ 23 | #define V4L2_PIX_FMT_MT21C v4l2_fourcc('M', 'T', '2', '1') /* Mediatek compressed block mode */ 24 | #define V4L2_PIX_FMT_INZI v4l2_fourcc('I', 'N', 'Z', 'I') /* Intel Planar Greyscale 10-bit and Depth 16-bit */ 25 | +#define V4L2_PIX_FMT_SUNXI v4l2_fourcc('S', 'X', 'I', 'Y') /* Sunxi VE's 32x32 tiled NV12 */ 26 | 27 | /* SDR formats - used only for Software Defined Radio devices */ 28 | #define V4L2_SDR_FMT_CU8 v4l2_fourcc('C', 'U', '0', '8') /* IQ u8 */ 29 | -- 30 | 2.14.3 31 | 32 | -------------------------------------------------------------------------------- /patches/4.9/0002-videodev2.h-add-request-to-v4l2_ext_controls.patch: -------------------------------------------------------------------------------- 1 | From 3af9e8989ee9e3e7dca868bf0ea8ddab70d2a100 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Mon, 16 Dec 2013 16:45:24 +0100 4 | Subject: [PATCH] videodev2.h: add request to v4l2_ext_controls 5 | 6 | The ctrl_class is fairly pointless when used with drivers that use the control 7 | framework: you can just fill in 0 and it will just work fine. There are still 8 | some old unconverted drivers that do not support 0 and instead want the control 9 | class there. The idea being that all controls in the list all belong to that 10 | class. This was done to simplify drivers in the absence of the control framework. 11 | 12 | When using the control framework the framework itself is smart enough to allow 13 | controls of any class to be included in the control list. 14 | 15 | Since request IDs are in the range 1..65535 (or so, in any case a relatively 16 | small non-zero positive integer) it makes sense to effectively rename ctrl_class 17 | to request. Set it to 0 and you get the normal behavior (you change the current 18 | control value), set it to a request ID and you get/set the control for 19 | that request. 20 | 21 | Signed-off-by: Hans Verkuil 22 | --- 23 | include/uapi/linux/videodev2.h | 1 + 24 | 1 file changed, 1 insertion(+) 25 | 26 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 27 | index fc6b22939e04..80d22869b380 100644 28 | --- a/include/uapi/linux/videodev2.h 29 | +++ b/include/uapi/linux/videodev2.h 30 | @@ -1507,6 +1507,7 @@ struct v4l2_ext_controls { 31 | __u32 ctrl_class; 32 | #endif 33 | __u32 which; 34 | + __u32 request; 35 | }; 36 | __u32 count; 37 | __u32 error_idx; 38 | -- 39 | 2.14.3 40 | 41 | -------------------------------------------------------------------------------- /patches/4.14/0002-videodev2.h-add-request-to-v4l2_ext_controls.patch: -------------------------------------------------------------------------------- 1 | From 83db93be38f81685e5b65acb0eb855867d65b4aa Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Mon, 16 Dec 2013 16:45:24 +0100 4 | Subject: [PATCH 02/22] videodev2.h: add request to v4l2_ext_controls 5 | 6 | The ctrl_class is fairly pointless when used with drivers that use the control 7 | framework: you can just fill in 0 and it will just work fine. There are still 8 | some old unconverted drivers that do not support 0 and instead want the control 9 | class there. The idea being that all controls in the list all belong to that 10 | class. This was done to simplify drivers in the absence of the control framework. 11 | 12 | When using the control framework the framework itself is smart enough to allow 13 | controls of any class to be included in the control list. 14 | 15 | Since request IDs are in the range 1..65535 (or so, in any case a relatively 16 | small non-zero positive integer) it makes sense to effectively rename ctrl_class 17 | to request. Set it to 0 and you get the normal behavior (you change the current 18 | control value), set it to a request ID and you get/set the control for 19 | that request. 20 | 21 | Signed-off-by: Hans Verkuil 22 | --- 23 | include/uapi/linux/videodev2.h | 1 + 24 | 1 file changed, 1 insertion(+) 25 | 26 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 27 | index d091ffad9761..4a32d88dc437 100644 28 | --- a/include/uapi/linux/videodev2.h 29 | +++ b/include/uapi/linux/videodev2.h 30 | @@ -1581,6 +1581,7 @@ struct v4l2_ext_controls { 31 | __u32 ctrl_class; 32 | #endif 33 | __u32 which; 34 | + __u32 request; 35 | }; 36 | __u32 count; 37 | __u32 error_idx; 38 | -- 39 | 2.14.3 40 | 41 | -------------------------------------------------------------------------------- /patches/4.9/0016-v4l-Add-private-compound-control-type.patch: -------------------------------------------------------------------------------- 1 | From 47d31f4113429f8c99935f4d5c5115d7462bf8c0 Mon Sep 17 00:00:00 2001 2 | From: Pawel Osciak 3 | Date: Tue, 1 Mar 2016 10:23:23 +0800 4 | Subject: [PATCH] v4l: Add private compound control type. 5 | 6 | V4L2_CTRL_TYPE_PRIVATE is to be used for private driver compound 7 | controls that use the "ptr" member of struct v4l2_ext_control. 8 | 9 | Signed-off-by: Pawel Osciak 10 | Signed-off-by: Jung Zhao 11 | Signed-off-by: Florent Revest 12 | --- 13 | drivers/media/v4l2-core/v4l2-ctrls.c | 4 ++++ 14 | include/uapi/linux/videodev2.h | 2 ++ 15 | 2 files changed, 6 insertions(+) 16 | 17 | diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c 18 | index b518438e7b75..dbb900eed37f 100644 19 | --- a/drivers/media/v4l2-core/v4l2-ctrls.c 20 | +++ b/drivers/media/v4l2-core/v4l2-ctrls.c 21 | @@ -1544,6 +1544,10 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx, 22 | return -ERANGE; 23 | return 0; 24 | 25 | + /* FIXME:just return 0 for now */ 26 | + case V4L2_CTRL_TYPE_PRIVATE: 27 | + return 0; 28 | + 29 | default: 30 | return -EINVAL; 31 | } 32 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 33 | index 31f832793ef1..01c8bfc2fd21 100644 34 | --- a/include/uapi/linux/videodev2.h 35 | +++ b/include/uapi/linux/videodev2.h 36 | @@ -1543,6 +1543,8 @@ enum v4l2_ctrl_type { 37 | V4L2_CTRL_TYPE_U8 = 0x0100, 38 | V4L2_CTRL_TYPE_U16 = 0x0101, 39 | V4L2_CTRL_TYPE_U32 = 0x0102, 40 | + 41 | + V4L2_CTRL_TYPE_PRIVATE = 0xffff, 42 | }; 43 | 44 | /* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */ 45 | -- 46 | 2.14.3 47 | 48 | -------------------------------------------------------------------------------- /libva/src/picture.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _PICTURE_H_ 27 | #define _PICTURE_H_ 28 | 29 | #include 30 | 31 | #include "object_heap.h" 32 | 33 | VAStatus sunxi_cedrus_BeginPicture(VADriverContextP ctx, VAContextID context, 34 | VASurfaceID render_target); 35 | 36 | VAStatus sunxi_cedrus_RenderPicture(VADriverContextP ctx, VAContextID context, 37 | VABufferID *buffers, int num_buffers); 38 | 39 | VAStatus sunxi_cedrus_EndPicture(VADriverContextP ctx, VAContextID context); 40 | 41 | #endif /* _PICTURE_H_ */ 42 | -------------------------------------------------------------------------------- /libva/src/mpeg2.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _MPEG2_H_ 27 | #define _MPEG2_H_ 28 | 29 | #include 30 | 31 | #include "context.h" 32 | #include "buffer.h" 33 | 34 | #include "surface.h" 35 | 36 | VAStatus sunxi_cedrus_render_mpeg2_slice_data(VADriverContextP ctx, 37 | object_context_p obj_context, object_surface_p obj_surface, 38 | object_buffer_p obj_buffer); 39 | 40 | VAStatus sunxi_cedrus_render_mpeg2_picture_parameter(VADriverContextP ctx, 41 | object_context_p obj_context, object_surface_p obj_surface, 42 | object_buffer_p obj_buffer); 43 | 44 | #endif /* _MPEG2_H_ */ 45 | -------------------------------------------------------------------------------- /libva/src/mpeg4.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _MPEG4_H_ 27 | #define _MPEG4_H_ 28 | 29 | #include 30 | 31 | #include "context.h" 32 | #include "buffer.h" 33 | 34 | #include "surface.h" 35 | 36 | VAStatus sunxi_cedrus_render_mpeg4_slice_data(VADriverContextP ctx, 37 | object_context_p obj_context, object_surface_p obj_surface, 38 | object_buffer_p obj_buffer); 39 | 40 | VAStatus sunxi_cedrus_render_mpeg4_picture_parameter(VADriverContextP ctx, 41 | object_context_p obj_context, object_surface_p obj_surface, 42 | object_buffer_p obj_buffer); 43 | 44 | VAStatus sunxi_cedrus_render_mpeg4_slice_parameter(VADriverContextP ctx, 45 | object_context_p obj_context, object_surface_p obj_surface, 46 | object_buffer_p obj_buffer); 47 | 48 | #endif /* _MPEG4_H_ */ 49 | -------------------------------------------------------------------------------- /patches/4.14/0019-ARM-dts-sun5i-Use-video-engine-node.patch: -------------------------------------------------------------------------------- 1 | From b01de4a8fc67dea8930ecded6a99bf17aa64240e Mon Sep 17 00:00:00 2001 2 | From: Florent Revest 3 | Date: Wed, 24 Aug 2016 14:15:26 +0200 4 | Subject: [PATCH 19/22] ARM: dts: sun5i: Use video-engine node 5 | 6 | Now that we have a driver matching "allwinner,sun5i-a13-video-engine" we 7 | can load it. 8 | 9 | The "video-engine" node depends on the new sunxi-ng's CCU clock and 10 | reset bindings. This patch also includes a ve_reserved DMA pool for 11 | videobuf2 buffer allocations in sunxi-cedrus. 12 | 13 | Signed-off-by: Florent Revest 14 | [Icenowy: beautify the node name] 15 | Signed-off-by: Icenowy Zheng 16 | --- 17 | arch/arm/boot/dts/sun5i-a13.dtsi | 30 ++++++++++++++++++++++++++++++ 18 | 1 file changed, 30 insertions(+) 19 | 20 | diff --git a/arch/arm/boot/dts/sun5i-a13.dtsi b/arch/arm/boot/dts/sun5i-a13.dtsi 21 | index 6436bad94404..99226109d5ed 100644 22 | --- a/arch/arm/boot/dts/sun5i-a13.dtsi 23 | +++ b/arch/arm/boot/dts/sun5i-a13.dtsi 24 | @@ -51,6 +51,19 @@ 25 | / { 26 | interrupt-parent = <&intc>; 27 | 28 | + reserved-memory { 29 | + #address-cells = <1>; 30 | + #size-cells = <1>; 31 | + ranges; 32 | + 33 | + ve_reserved: cma { 34 | + compatible = "shared-dma-pool"; 35 | + reg = <0x43d00000 0x9000000>; 36 | + no-map; 37 | + linux,cma-default; 38 | + }; 39 | + }; 40 | + 41 | thermal-zones { 42 | cpu_thermal { 43 | /* milliseconds */ 44 | @@ -97,6 +110,23 @@ 45 | status = "disabled"; 46 | }; 47 | 48 | + ve: video-engine@01c0e000 { 49 | + compatible = "allwinner,sun5i-a13-video-engine"; 50 | + memory-region = <&ve_reserved>; 51 | + 52 | + clocks = <&ccu CLK_AHB_VE>, <&ccu CLK_VE>, 53 | + <&ccu CLK_DRAM_VE>; 54 | + clock-names = "ahb", "mod", "ram"; 55 | + 56 | + assigned-clocks = <&ccu CLK_VE>; 57 | + assigned-clock-rates = <320000000>; 58 | + 59 | + resets = <&ccu RST_VE>; 60 | + 61 | + interrupts = <53>; 62 | + 63 | + reg = <0x01c0e000 0x1000>; 64 | + }; 65 | }; 66 | }; 67 | 68 | -- 69 | 2.14.3 70 | 71 | -------------------------------------------------------------------------------- /patches/4.9/0021-ARM-dts-sun5i-Use-video-engine-node.patch: -------------------------------------------------------------------------------- 1 | From 8e2967baeae684ef83fa5acb3c31b32481229bc2 Mon Sep 17 00:00:00 2001 2 | From: Florent Revest 3 | Date: Wed, 24 Aug 2016 14:15:26 +0200 4 | Subject: [PATCH] ARM: dts: sun5i: Use video-engine node 5 | 6 | Now that we have a driver matching "allwinner,sun5i-a13-video-engine" we 7 | can load it. 8 | 9 | The "video-engine" node depends on the new sunxi-ng's CCU clock and 10 | reset bindings. This patch also includes a ve_reserved DMA pool for 11 | videobuf2 buffer allocations in sunxi-cedrus. 12 | 13 | Signed-off-by: Florent Revest 14 | [Icenowy: beautify the node name] 15 | Signed-off-by: Icenowy Zheng 16 | --- 17 | arch/arm/boot/dts/sun5i-a13.dtsi | 31 +++++++++++++++++++++++++++++++ 18 | 1 file changed, 31 insertions(+) 19 | 20 | diff --git a/arch/arm/boot/dts/sun5i-a13.dtsi b/arch/arm/boot/dts/sun5i-a13.dtsi 21 | index a72e1895940c..9286bbc74724 100644 22 | --- a/arch/arm/boot/dts/sun5i-a13.dtsi 23 | +++ b/arch/arm/boot/dts/sun5i-a13.dtsi 24 | @@ -69,6 +69,19 @@ 25 | }; 26 | }; 27 | 28 | + reserved-memory { 29 | + #address-cells = <1>; 30 | + #size-cells = <1>; 31 | + ranges; 32 | + 33 | + ve_reserved: cma { 34 | + compatible = "shared-dma-pool"; 35 | + reg = <0x43d00000 0x9000000>; 36 | + no-map; 37 | + linux,cma-default; 38 | + }; 39 | + }; 40 | + 41 | thermal-zones { 42 | cpu_thermal { 43 | /* milliseconds */ 44 | @@ -330,6 +343,24 @@ 45 | }; 46 | }; 47 | 48 | + ve: video-engine@01c0e000 { 49 | + compatible = "allwinner,sun5i-a13-video-engine"; 50 | + memory-region = <&ve_reserved>; 51 | + 52 | + clocks = <&ahb_gates 32>, <&ccu CLK_VE>, 53 | + <&dram_gates 0>; 54 | + clock-names = "ahb", "mod", "ram"; 55 | + 56 | + assigned-clocks = <&ccu CLK_VE>; 57 | + assigned-clock-rates = <320000000>; 58 | + 59 | + resets = <&ccu RST_VE>; 60 | + 61 | + interrupts = <53>; 62 | + 63 | + reg = <0x01c0e000 0x1000>; 64 | + }; 65 | + 66 | ccu: clock@01c20000 { 67 | compatible = "allwinner,sun5i-a13-ccu"; 68 | reg = <0x01c20000 0x400>; 69 | -- 70 | 2.14.3 71 | 72 | -------------------------------------------------------------------------------- /patches/4.9/0004-vb2-add-allow_requests-flag.patch: -------------------------------------------------------------------------------- 1 | From fe2039286795e8138bfb110fc8b37142f25392a0 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Tue, 21 Apr 2015 12:16:58 +0200 4 | Subject: [PATCH] vb2: add allow_requests flag 5 | 6 | The driver has to set allow_requests explicitly in order to allow 7 | queuing or preparing buffers for a specific request ID. 8 | 9 | Signed-off-by: Hans Verkuil 10 | --- 11 | drivers/media/v4l2-core/videobuf2-v4l2.c | 5 +++++ 12 | include/media/videobuf2-core.h | 3 +++ 13 | 2 files changed, 8 insertions(+) 14 | 15 | diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c 16 | index 2c3051cfbafd..e788f527b7f0 100644 17 | --- a/drivers/media/v4l2-core/videobuf2-v4l2.c 18 | +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c 19 | @@ -179,6 +179,11 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b, 20 | return -EINVAL; 21 | } 22 | 23 | + if (!q->v4l2_allow_requests && b->request) { 24 | + dprintk(1, "%s: unsupported request ID\n", opname); 25 | + return -EINVAL; 26 | + } 27 | + 28 | return __verify_planes_array(q->bufs[b->index], b); 29 | } 30 | 31 | diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h 32 | index ac5898a55fd9..66a2dc5a135b 100644 33 | --- a/include/media/videobuf2-core.h 34 | +++ b/include/media/videobuf2-core.h 35 | @@ -487,6 +487,8 @@ struct vb2_buf_ops { 36 | * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the 37 | * last decoded buffer was already dequeued. Set for capture queues 38 | * when a buffer with the V4L2_BUF_FLAG_LAST is dequeued. 39 | + * @v4l2_allow_requests: allow request != 0 to be passed to the driver, V4L2 40 | + * specific. 41 | * @fileio: file io emulator internal data, used only if emulator is active 42 | * @threadio: thread io internal data, used only if thread is active 43 | */ 44 | @@ -537,6 +539,7 @@ struct vb2_queue { 45 | unsigned int is_output:1; 46 | unsigned int copy_timestamp:1; 47 | unsigned int last_buffer_dequeued:1; 48 | + unsigned int v4l2_allow_requests:1; 49 | 50 | struct vb2_fileio_data *fileio; 51 | struct vb2_threadio_data *threadio; 52 | -- 53 | 2.14.3 54 | 55 | -------------------------------------------------------------------------------- /patches/4.14/0004-vb2-add-allow_requests-flag.patch: -------------------------------------------------------------------------------- 1 | From e982a4958780f73f127b9154a608378e9261030d Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Tue, 21 Apr 2015 12:16:58 +0200 4 | Subject: [PATCH 04/22] vb2: add allow_requests flag 5 | 6 | The driver has to set allow_requests explicitly in order to allow 7 | queuing or preparing buffers for a specific request ID. 8 | 9 | Signed-off-by: Hans Verkuil 10 | --- 11 | drivers/media/v4l2-core/videobuf2-v4l2.c | 5 +++++ 12 | include/media/videobuf2-core.h | 3 +++ 13 | 2 files changed, 8 insertions(+) 14 | 15 | diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c 16 | index a0211921a492..40eaef9b4336 100644 17 | --- a/drivers/media/v4l2-core/videobuf2-v4l2.c 18 | +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c 19 | @@ -178,6 +178,11 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b, 20 | return -EINVAL; 21 | } 22 | 23 | + if (!q->v4l2_allow_requests && b->request) { 24 | + dprintk(1, "%s: unsupported request ID\n", opname); 25 | + return -EINVAL; 26 | + } 27 | + 28 | return __verify_planes_array(q->bufs[b->index], b); 29 | } 30 | 31 | diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h 32 | index ef9b64398c8c..555cfdf774a8 100644 33 | --- a/include/media/videobuf2-core.h 34 | +++ b/include/media/videobuf2-core.h 35 | @@ -498,6 +498,8 @@ struct vb2_buf_ops { 36 | * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the 37 | * last decoded buffer was already dequeued. Set for capture queues 38 | * when a buffer with the V4L2_BUF_FLAG_LAST is dequeued. 39 | + * @v4l2_allow_requests: allow request != 0 to be passed to the driver, V4L2 40 | + * specific. 41 | * @fileio: file io emulator internal data, used only if emulator is active 42 | * @threadio: thread io internal data, used only if thread is active 43 | */ 44 | @@ -550,6 +552,7 @@ struct vb2_queue { 45 | unsigned int is_output:1; 46 | unsigned int copy_timestamp:1; 47 | unsigned int last_buffer_dequeued:1; 48 | + unsigned int v4l2_allow_requests:1; 49 | 50 | struct vb2_fileio_data *fileio; 51 | struct vb2_threadio_data *threadio; 52 | -- 53 | 2.14.3 54 | 55 | -------------------------------------------------------------------------------- /patches/4.9/0022-ARM-dts-sun8i-add-video-engine-support-for-A33.patch: -------------------------------------------------------------------------------- 1 | From 3dbcfc0adac72570d2b527cfac5cf72d8bf068e1 Mon Sep 17 00:00:00 2001 2 | From: Icenowy Zheng 3 | Date: Sat, 7 Jan 2017 00:19:54 +0800 4 | Subject: [PATCH] ARM: dts: sun8i: add video engine support for A33 5 | 6 | A33 has a video engine just like the one in A13. 7 | 8 | Add the support for it in the device tree. 9 | 10 | Signed-off-by: Icenowy Zheng 11 | --- 12 | arch/arm/boot/dts/sun8i-a33.dtsi | 39 +++++++++++++++++++++++++++++++++++++++ 13 | 1 file changed, 39 insertions(+) 14 | 15 | diff --git a/arch/arm/boot/dts/sun8i-a33.dtsi b/arch/arm/boot/dts/sun8i-a33.dtsi 16 | index fd1e1cddd4a8..72b8046270b8 100644 17 | --- a/arch/arm/boot/dts/sun8i-a33.dtsi 18 | +++ b/arch/arm/boot/dts/sun8i-a33.dtsi 19 | @@ -69,7 +69,27 @@ 20 | reg = <0x40000000 0x80000000>; 21 | }; 22 | 23 | + reserved-memory { 24 | + #address-cells = <1>; 25 | + #size-cells = <1>; 26 | + ranges; 27 | + 28 | + ve_reserved: cma { 29 | + compatible = "shared-dma-pool"; 30 | + no-map; 31 | + size = <0x4000000>; 32 | + alignment = <0x2000>; 33 | + alloc-ranges = <0x40000000 0x10000000>; 34 | + linux,cma-default; 35 | + }; 36 | + }; 37 | + 38 | soc@01c00000 { 39 | + syscon: system-controller@01c00000 { 40 | + compatible = "allwinner,sun8i-a33-syscon", "syscon"; 41 | + reg = <0x01c00000 0x1000>; 42 | + }; 43 | + 44 | tcon0: lcd-controller@01c0c000 { 45 | compatible = "allwinner,sun8i-a33-tcon"; 46 | reg = <0x01c0c000 0x1000>; 47 | @@ -106,6 +126,25 @@ 48 | }; 49 | }; 50 | 51 | + ve: video-engine@01c0e000 { 52 | + compatible = "allwinner,sun5i-a13-video-engine"; 53 | + memory-region = <&ve_reserved>; 54 | + syscon = <&syscon>; 55 | + 56 | + clocks = <&ccu CLK_BUS_VE>, <&ccu CLK_VE>, 57 | + <&ccu CLK_DRAM_VE>; 58 | + clock-names = "ahb", "mod", "ram"; 59 | + 60 | + assigned-clocks = <&ccu CLK_VE>; 61 | + assigned-clock-rates = <320000000>; 62 | + 63 | + resets = <&ccu RST_BUS_VE>; 64 | + 65 | + interrupts = ; 66 | + 67 | + reg = <0x01c0e000 0x1000>; 68 | + }; 69 | + 70 | crypto: crypto-engine@01c15000 { 71 | compatible = "allwinner,sun4i-a10-crypto"; 72 | reg = <0x01c15000 0x1000>; 73 | -- 74 | 2.14.3 75 | 76 | -------------------------------------------------------------------------------- /patches/4.9/0001-videodev2.h-add-max_reqs-to-struct-v4l2_query_ext_ct.patch: -------------------------------------------------------------------------------- 1 | From 7859b9ca706456798f3a1f04fddf716f56384ae2 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Tue, 7 Apr 2015 15:48:43 +0200 4 | Subject: [PATCH] videodev2.h: add max_reqs to struct v4l2_query_ext_ctrl 5 | 6 | struct v4l2_query_ext_ctrl is extended with a new 'max_reqs' field to store 7 | the maximum number of outstanding requests that contain this control. 8 | 9 | Signed-off-by: Hans Verkuil 10 | --- 11 | drivers/media/v4l2-core/v4l2-ioctl.c | 5 +++-- 12 | include/uapi/linux/videodev2.h | 4 +++- 13 | 2 files changed, 6 insertions(+), 3 deletions(-) 14 | 15 | diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c 16 | index c52d94c018bb..f49255ae7193 100644 17 | --- a/drivers/media/v4l2-core/v4l2-ioctl.c 18 | +++ b/drivers/media/v4l2-core/v4l2-ioctl.c 19 | @@ -539,12 +539,13 @@ static void v4l_print_query_ext_ctrl(const void *arg, bool write_only) 20 | 21 | pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%lld/%lld, " 22 | "step=%lld, default=%lld, flags=0x%08x, elem_size=%u, elems=%u, " 23 | - "nr_of_dims=%u, dims=%u,%u,%u,%u\n", 24 | + "nr_of_dims=%u, dims=%u,%u,%u,%u, max_reqs=%u, request=%u\n", 25 | p->id, p->type, (int)sizeof(p->name), p->name, 26 | p->minimum, p->maximum, 27 | p->step, p->default_value, p->flags, 28 | p->elem_size, p->elems, p->nr_of_dims, 29 | - p->dims[0], p->dims[1], p->dims[2], p->dims[3]); 30 | + p->dims[0], p->dims[1], p->dims[2], p->dims[3], 31 | + p->max_reqs, p->request); 32 | } 33 | 34 | static void v4l_print_querymenu(const void *arg, bool write_only) 35 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 36 | index 94f123f3e04e..fc6b22939e04 100644 37 | --- a/include/uapi/linux/videodev2.h 38 | +++ b/include/uapi/linux/videodev2.h 39 | @@ -1569,7 +1569,9 @@ struct v4l2_query_ext_ctrl { 40 | __u32 elems; 41 | __u32 nr_of_dims; 42 | __u32 dims[V4L2_CTRL_MAX_DIMS]; 43 | - __u32 reserved[32]; 44 | + __u32 max_reqs; 45 | + __u32 request; 46 | + __u32 reserved[30]; 47 | }; 48 | 49 | /* Used in the VIDIOC_QUERYMENU ioctl for querying menu items */ 50 | -- 51 | 2.14.3 52 | 53 | -------------------------------------------------------------------------------- /patches/4.14/0020-ARM-dts-sun8i-add-video-engine-support-for-A33.patch: -------------------------------------------------------------------------------- 1 | From ad63c355213cfc8847cfe9f19bf42261ab94530c Mon Sep 17 00:00:00 2001 2 | From: Icenowy Zheng 3 | Date: Sat, 7 Jan 2017 00:19:54 +0800 4 | Subject: [PATCH 20/22] ARM: dts: sun8i: add video engine support for A33 5 | 6 | A33 has a video engine just like the one in A13. 7 | 8 | Add the support for it in the device tree. 9 | 10 | Signed-off-by: Icenowy Zheng 11 | --- 12 | arch/arm/boot/dts/sun8i-a33.dtsi | 39 +++++++++++++++++++++++++++++++++++++++ 13 | 1 file changed, 39 insertions(+) 14 | 15 | diff --git a/arch/arm/boot/dts/sun8i-a33.dtsi b/arch/arm/boot/dts/sun8i-a33.dtsi 16 | index 22660919bd08..b7d2fac0d305 100644 17 | --- a/arch/arm/boot/dts/sun8i-a33.dtsi 18 | +++ b/arch/arm/boot/dts/sun8i-a33.dtsi 19 | @@ -181,6 +181,21 @@ 20 | reg = <0x40000000 0x80000000>; 21 | }; 22 | 23 | + reserved-memory { 24 | + #address-cells = <1>; 25 | + #size-cells = <1>; 26 | + ranges; 27 | + 28 | + ve_reserved: cma { 29 | + compatible = "shared-dma-pool"; 30 | + no-map; 31 | + size = <0x4000000>; 32 | + alignment = <0x2000>; 33 | + alloc-ranges = <0x40000000 0x10000000>; 34 | + linux,cma-default; 35 | + }; 36 | + }; 37 | + 38 | sound: sound { 39 | compatible = "simple-audio-card"; 40 | simple-audio-card,name = "sun8i-a33-audio"; 41 | @@ -204,6 +219,11 @@ 42 | }; 43 | 44 | soc@01c00000 { 45 | + syscon: system-controller@01c00000 { 46 | + compatible = "allwinner,sun8i-a33-syscon", "syscon"; 47 | + reg = <0x01c00000 0x1000>; 48 | + }; 49 | + 50 | tcon0: lcd-controller@01c0c000 { 51 | compatible = "allwinner,sun8i-a33-tcon"; 52 | reg = <0x01c0c000 0x1000>; 53 | @@ -240,6 +260,25 @@ 54 | }; 55 | }; 56 | 57 | + ve: video-engine@01c0e000 { 58 | + compatible = "allwinner,sun5i-a13-video-engine"; 59 | + memory-region = <&ve_reserved>; 60 | + syscon = <&syscon>; 61 | + 62 | + clocks = <&ccu CLK_BUS_VE>, <&ccu CLK_VE>, 63 | + <&ccu CLK_DRAM_VE>; 64 | + clock-names = "ahb", "mod", "ram"; 65 | + 66 | + assigned-clocks = <&ccu CLK_VE>; 67 | + assigned-clock-rates = <320000000>; 68 | + 69 | + resets = <&ccu RST_BUS_VE>; 70 | + 71 | + interrupts = ; 72 | + 73 | + reg = <0x01c0e000 0x1000>; 74 | + }; 75 | + 76 | crypto: crypto-engine@01c15000 { 77 | compatible = "allwinner,sun4i-a10-crypto"; 78 | reg = <0x01c15000 0x1000>; 79 | -- 80 | 2.14.3 81 | 82 | -------------------------------------------------------------------------------- /patches/4.14/0010-vb2-add-helper-function-to-queue-request-specific-bu.patch: -------------------------------------------------------------------------------- 1 | From 5e8e3f3e84163721877b02d1d11d2a71257364a4 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Mon, 13 Apr 2015 15:53:34 +0200 4 | Subject: [PATCH 10/22] vb2: add helper function to queue request-specific 5 | buffer. 6 | 7 | The vb2_qbuf_request() function will queue any buffers for the given request 8 | that are in state PREPARED. 9 | 10 | Useful when drivers have to implement the req_queue callback. 11 | 12 | Signed-off-by: Hans Verkuil 13 | --- 14 | drivers/media/v4l2-core/videobuf2-v4l2.c | 21 +++++++++++++++++++++ 15 | include/media/videobuf2-v4l2.h | 2 ++ 16 | 2 files changed, 23 insertions(+) 17 | 18 | diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c 19 | index 40eaef9b4336..9798fd449c41 100644 20 | --- a/drivers/media/v4l2-core/videobuf2-v4l2.c 21 | +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c 22 | @@ -579,6 +579,27 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) 23 | } 24 | EXPORT_SYMBOL_GPL(vb2_qbuf); 25 | 26 | +int vb2_qbuf_request(struct vb2_queue *q, u16 request, struct vb2_buffer **p_buf) 27 | +{ 28 | + struct v4l2_buffer v4l2_buf; 29 | + int buffer; 30 | + 31 | + for (buffer = 0; buffer < q->num_buffers; buffer++) { 32 | + struct vb2_buffer *vb = q->bufs[buffer]; 33 | + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 34 | + 35 | + if (vbuf->request == request && 36 | + vb->state == VB2_BUF_STATE_PREPARED) { 37 | + if (p_buf) 38 | + *p_buf = vb; 39 | + __fill_v4l2_buffer(vb, &v4l2_buf); 40 | + return vb2_qbuf(q, &v4l2_buf); 41 | + } 42 | + } 43 | + return -ENOENT; 44 | +} 45 | +EXPORT_SYMBOL_GPL(vb2_qbuf_request); 46 | + 47 | int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking) 48 | { 49 | int ret; 50 | diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h 51 | index 3029b763ab58..9d4b5422ae06 100644 52 | --- a/include/media/videobuf2-v4l2.h 53 | +++ b/include/media/videobuf2-v4l2.h 54 | @@ -125,6 +125,8 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b); 55 | */ 56 | int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb); 57 | 58 | +int vb2_qbuf_request(struct vb2_queue *q, u16 request, struct vb2_buffer **p_buf); 59 | + 60 | /** 61 | * vb2_dqbuf() - Dequeue a buffer to the userspace 62 | * @q: videobuf2 queue 63 | -- 64 | 2.14.3 65 | 66 | -------------------------------------------------------------------------------- /patches/4.14/0001-videodev2.h-add-max_reqs-to-struct-v4l2_query_ext_ct.patch: -------------------------------------------------------------------------------- 1 | From e1058a70283cfd5d529b6248fe8598bd2f02c382 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Tue, 7 Apr 2015 15:48:43 +0200 4 | Subject: [PATCH 01/22] videodev2.h: add max_reqs to struct v4l2_query_ext_ctrl 5 | 6 | struct v4l2_query_ext_ctrl is extended with a new 'max_reqs' field to store 7 | the maximum number of outstanding requests that contain this control. 8 | 9 | Signed-off-by: Hans Verkuil 10 | --- 11 | drivers/media/v4l2-core/v4l2-ioctl.c | 5 +++-- 12 | include/uapi/linux/videodev2.h | 4 +++- 13 | 2 files changed, 6 insertions(+), 3 deletions(-) 14 | 15 | diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c 16 | index b60a6b0841d1..52e8e1076d76 100644 17 | --- a/drivers/media/v4l2-core/v4l2-ioctl.c 18 | +++ b/drivers/media/v4l2-core/v4l2-ioctl.c 19 | @@ -526,12 +526,13 @@ static void v4l_print_query_ext_ctrl(const void *arg, bool write_only) 20 | { 21 | const struct v4l2_query_ext_ctrl *p = arg; 22 | 23 | - pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%lld/%lld, step=%lld, default=%lld, flags=0x%08x, elem_size=%u, elems=%u, nr_of_dims=%u, dims=%u,%u,%u,%u\n", 24 | + pr_cont("id=0x%x, type=%d, name=%.*s, min/max=%lld/%lld, step=%lld, default=%lld, flags=0x%08x, elem_size=%u, elems=%u, nr_of_dims=%u, dims=%u,%u,%u,%u, max_reqs=%u, request=%u\n", 25 | p->id, p->type, (int)sizeof(p->name), p->name, 26 | p->minimum, p->maximum, 27 | p->step, p->default_value, p->flags, 28 | p->elem_size, p->elems, p->nr_of_dims, 29 | - p->dims[0], p->dims[1], p->dims[2], p->dims[3]); 30 | + p->dims[0], p->dims[1], p->dims[2], p->dims[3], 31 | + p->max_reqs, p->request); 32 | } 33 | 34 | static void v4l_print_querymenu(const void *arg, bool write_only) 35 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 36 | index 1c095b5a99c5..d091ffad9761 100644 37 | --- a/include/uapi/linux/videodev2.h 38 | +++ b/include/uapi/linux/videodev2.h 39 | @@ -1643,7 +1643,9 @@ struct v4l2_query_ext_ctrl { 40 | __u32 elems; 41 | __u32 nr_of_dims; 42 | __u32 dims[V4L2_CTRL_MAX_DIMS]; 43 | - __u32 reserved[32]; 44 | + __u32 max_reqs; 45 | + __u32 request; 46 | + __u32 reserved[30]; 47 | }; 48 | 49 | /* Used in the VIDIOC_QUERYMENU ioctl for querying menu items */ 50 | -- 51 | 2.14.3 52 | 53 | -------------------------------------------------------------------------------- /libva/src/sunxi_cedrus_drv_video.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _SUNXI_CEDRUS_DRV_VIDEO_H_ 27 | #define _SUNXI_CEDRUS_DRV_VIDEO_H_ 28 | 29 | #include 30 | #include "object_heap.h" 31 | 32 | #include 33 | 34 | #define INIT_DRIVER_DATA struct sunxi_cedrus_driver_data * const driver_data = (struct sunxi_cedrus_driver_data *) ctx->pDriverData; 35 | 36 | #define SUNXI_CEDRUS_STR_VENDOR "Sunxi Cedrus Driver 1.0" 37 | 38 | #define SUNXI_CEDRUS_MAX_PROFILES 11 39 | #define SUNXI_CEDRUS_MAX_ENTRYPOINTS 5 40 | #define SUNXI_CEDRUS_MAX_CONFIG_ATTRIBUTES 10 41 | #define SUNXI_CEDRUS_MAX_IMAGE_FORMATS 10 42 | #define SUNXI_CEDRUS_MAX_SUBPIC_FORMATS 4 43 | #define SUNXI_CEDRUS_MAX_DISPLAY_ATTRIBUTES 4 44 | 45 | void sunxi_cedrus_msg(const char *msg, ...); 46 | 47 | struct sunxi_cedrus_driver_data { 48 | struct object_heap config_heap; 49 | struct object_heap context_heap; 50 | struct object_heap surface_heap; 51 | struct object_heap buffer_heap; 52 | struct object_heap image_heap; 53 | char *luma_bufs[VIDEO_MAX_FRAME]; 54 | char *chroma_bufs[VIDEO_MAX_FRAME]; 55 | unsigned int num_dst_bufs; 56 | int mem2mem_fd; 57 | }; 58 | 59 | #endif /* _SUNXI_CEDRUS_DRV_VIDEO_H_ */ 60 | -------------------------------------------------------------------------------- /patches/4.14/0022-ARM-dts-sun7i-Add-video-engine-support-for-the-A20.patch: -------------------------------------------------------------------------------- 1 | From 6a52f896f0169960561738897a861225c0f0e2d9 Mon Sep 17 00:00:00 2001 2 | From: Thomas van Kleef 3 | Date: Thu, 23 Nov 2017 12:10:38 +0100 4 | Subject: [PATCH 22/22] ARM: dts: sun7i: Add video engine support for the A20 5 | 6 | The A20 has a video engine similare to the one in the A13. 7 | 8 | Add the device node in the A20. 9 | 10 | Signed-off-by: Thomas van Kleef 11 | Signed-off-by: Maxime Ripard 12 | --- 13 | arch/arm/boot/dts/sun7i-a20.dtsi | 47 ++++++++++++++++++++++++++++++++++++++++ 14 | 1 file changed, 47 insertions(+) 15 | 16 | diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi 17 | index 39d0727bd9c3..a29abf95c6f9 100644 18 | --- a/arch/arm/boot/dts/sun7i-a20.dtsi 19 | +++ b/arch/arm/boot/dts/sun7i-a20.dtsi 20 | @@ -53,6 +53,35 @@ 21 | / { 22 | interrupt-parent = <&gic>; 23 | 24 | + reserved-memory { 25 | + #address-cells = <1>; 26 | + #size-cells = <1>; 27 | + ranges; 28 | + 29 | + /* 30 | + * MUST TO BE IN THE LOWER 256MB of RAM for the VE! 31 | + * Src: http://linux-sunxi.org/Sunxi-cedrus "A 32 | + * limitation of the Allwinner's VPU is the need for 33 | + * buffers in the lower 256M of RAM. In order to 34 | + * allocate large sets of data in this area, 35 | + * "sunxi-cedrus" reserves a DMA pool that is then 36 | + * used by videobuf's dma-contig backend() to allocate 37 | + * input and output buffers easily and integrate that 38 | + * with the v4l QBUF/DQBUF APIs." 39 | + * 40 | + * The lower limit is 0x41000000 but the kernel has to 41 | + * be moved somewhere else in order to use this 42 | + * region. 43 | + */ 44 | + 45 | + ve_reserved: cma { 46 | + compatible = "shared-dma-pool"; 47 | + reg = <0x41000000 0x9000000>; 48 | + no-map; 49 | + linux,cma-default; 50 | + }; 51 | + }; 52 | + 53 | aliases { 54 | ethernet0 = &gmac; 55 | }; 56 | @@ -346,6 +375,24 @@ 57 | #size-cells = <0>; 58 | }; 59 | 60 | + ve: video-engine@01c0e000 { 61 | + compatible = "allwinner,sun5i-a13-video-engine"; 62 | + memory-region = <&ve_reserved>; 63 | + 64 | + clocks = <&ccu CLK_AHB_VE>, <&ccu CLK_VE>, 65 | + <&ccu CLK_DRAM_VE>; 66 | + clock-names = "ahb", "mod", "ram"; 67 | + 68 | + assigned-clocks = <&ccu CLK_VE>; 69 | + assigned-clock-rates = <320000000>; 70 | + 71 | + resets = <&ccu RST_VE>; 72 | + 73 | + interrupts = ; 74 | + 75 | + reg = <0x01c0e000 0x1000>; 76 | + }; 77 | + 78 | mmc0: mmc@01c0f000 { 79 | compatible = "allwinner,sun7i-a20-mmc"; 80 | reg = <0x01c0f000 0x1000>; 81 | -- 82 | 2.14.3 83 | 84 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | addons: 4 | apt: 5 | packages: 6 | - build-essential 7 | - quilt 8 | - wget 9 | 10 | env: 11 | global: 12 | - ARCH=arm 13 | - BRDIR=/tmp/buildroot 14 | - CROSS_COMPILE=arm-buildroot-linux-gnueabihf- 15 | - KDIR=/tmp/kernel 16 | - KERNEL_DEFCONFIG=multi_v7_defconfig 17 | - TOOLCHAIN_DIR=/tmp/toolchain 18 | - PATH=${TOOLCHAIN_DIR}/bin:$PATH 19 | 20 | install: 21 | - wget -O toolchain.tar.xz https://free-electrons.com/~maxime/pub/cedrus-toolchain.tar.xz 22 | - mkdir ${TOOLCHAIN_DIR} 23 | - tar -C ${TOOLCHAIN_DIR} --strip=1 -xf toolchain.tar.xz 24 | - pushd ${TOOLCHAIN_DIR} 25 | - ./relocate-sdk.sh 26 | - popd 27 | - if [[ "${CEDRUS_BUILD}" != "libva" ]]; then 28 | wget -O kernel.tar.xz https://www.kernel.org/pub/linux/kernel/v4.x/linux-${KERNEL_VERSION}.tar.xz; 29 | mkdir ${KDIR}; 30 | tar -C ${KDIR} --strip=1 -xf kernel.tar.xz; 31 | fi 32 | - if [[ "${CEDRUS_BUILD}" == "libva" ]]; then 33 | wget -O buildroot.tar.gz https://buildroot.org/downloads/buildroot-2017.11.tar.gz; 34 | mkdir ${BRDIR}; 35 | tar -C ${BRDIR} --strip=1 -xf buildroot.tar.gz; 36 | fi 37 | 38 | before_script: 39 | - if [[ "${CEDRUS_BUILD}" != "libva" ]]; then 40 | PATCH_DIR=$(pwd)/patches/${KERNEL_VERSION}; 41 | pushd ${KDIR}; 42 | quilt import ${PATCH_DIR}/*.patch; 43 | quilt push -a; 44 | make -j $(nproc) ${KERNEL_DEFCONFIG}; 45 | popd; 46 | fi 47 | - if [[ "${CEDRUS_BUILD}" == "driver" ]]; then 48 | make -C ${KDIR} -j $(nproc) modules_prepare; 49 | fi 50 | - if [[ "${CEDRUS_BUILD}" == "libva" ]]; then 51 | make -C ${BRDIR} BR2_EXTERNAL=$(pwd)/buildroot libva_defconfig; 52 | fi 53 | 54 | script: 55 | - if [[ "${CEDRUS_BUILD}" == "driver" ]]; then 56 | make -C driver -j $(nproc); 57 | fi 58 | - if [[ "${CEDRUS_BUILD}" == "dtbs" ]]; then 59 | make -C ${KDIR} -j $(nproc) dtbs; 60 | fi 61 | - if [[ "${CEDRUS_BUILD}" == "kernel" ]]; then 62 | make -C ${KDIR} -j $(nproc) zImage modules; 63 | fi 64 | - if [[ "${CEDRUS_BUILD}" == "libva" ]]; then 65 | make -C ${BRDIR} libva-cedrus-driver; 66 | fi 67 | 68 | matrix: 69 | include: 70 | - env: 71 | - CEDRUS_BUILD: driver 72 | KERNEL_VERSION: 4.9 73 | - env: 74 | - CEDRUS_BUILD: driver 75 | KERNEL_VERSION: 4.14 76 | - env: 77 | - CEDRUS_BUILD: dtbs 78 | KERNEL_VERSION: 4.9 79 | - env: 80 | - CEDRUS_BUILD: dtbs 81 | KERNEL_VERSION: 4.14 82 | - env: 83 | - CEDRUS_BUILD: kernel 84 | KERNEL_VERSION: 4.9 85 | - env: 86 | - CEDRUS_BUILD: kernel 87 | KERNEL_VERSION: 4.14 88 | - env: 89 | - CEDRUS_BUILD: libva 90 | -------------------------------------------------------------------------------- /libva/src/context.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _CONTEXT_H_ 27 | #define _CONTEXT_H_ 28 | 29 | #include 30 | 31 | #include "object_heap.h" 32 | 33 | /* We can't dynamically call VIDIOC_REQBUFS for every MPEG slice we create. 34 | * Indeed, the queue might be busy processing a previous buffer, so we need to 35 | * pre-allocate a set of buffers with a max size */ 36 | #define INPUT_BUFFER_MAX_SIZE 131072 37 | #define INPUT_BUFFERS_NB 4 38 | 39 | #define CONTEXT(id) ((object_context_p) object_heap_lookup(&driver_data->context_heap, id)) 40 | #define CONTEXT_ID_OFFSET 0x02000000 41 | 42 | struct object_context { 43 | struct object_base base; 44 | VAContextID context_id; 45 | VAConfigID config_id; 46 | VASurfaceID current_render_target; 47 | int picture_width; 48 | int picture_height; 49 | int num_render_targets; 50 | int flags; 51 | VASurfaceID *render_targets; 52 | uint32_t num_rendered_surfaces; 53 | 54 | struct v4l2_ctrl_mpeg2_frame_hdr mpeg2_frame_hdr; 55 | struct v4l2_ctrl_mpeg4_frame_hdr mpeg4_frame_hdr; 56 | }; 57 | 58 | typedef struct object_context *object_context_p; 59 | 60 | VAStatus sunxi_cedrus_CreateContext(VADriverContextP ctx, VAConfigID config_id, 61 | int picture_width, int picture_height, int flag, 62 | VASurfaceID *render_targets, int num_render_targets, 63 | VAContextID *context); 64 | 65 | VAStatus sunxi_cedrus_DestroyContext(VADriverContextP ctx, VAContextID context); 66 | 67 | #endif /* _CONTEXT_H_ */ 68 | -------------------------------------------------------------------------------- /libva/src/image.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _IMAGE_H_ 27 | #define _IMAGE_H_ 28 | 29 | #include 30 | 31 | #include "object_heap.h" 32 | 33 | #define IMAGE(id) ((object_image_p) object_heap_lookup(&driver_data->image_heap, id)) 34 | #define IMAGE_ID_OFFSET 0x10000000 35 | 36 | struct object_image { 37 | struct object_base base; 38 | VABufferID buf; 39 | }; 40 | 41 | typedef struct object_image *object_image_p; 42 | 43 | VAStatus sunxi_cedrus_QueryImageFormats(VADriverContextP ctx, 44 | VAImageFormat *format_list, int *num_formats); 45 | 46 | VAStatus sunxi_cedrus_CreateImage(VADriverContextP ctx, VAImageFormat *format, 47 | int width, int height, VAImage *image); 48 | 49 | VAStatus sunxi_cedrus_DeriveImage(VADriverContextP ctx, VASurfaceID surface, 50 | VAImage *image); 51 | 52 | VAStatus sunxi_cedrus_DestroyImage(VADriverContextP ctx, VAImageID image); 53 | 54 | VAStatus sunxi_cedrus_SetImagePalette(VADriverContextP ctx, VAImageID image, 55 | unsigned char *palette); 56 | 57 | VAStatus sunxi_cedrus_GetImage(VADriverContextP ctx, VASurfaceID surface, 58 | int x, int y, unsigned int width, unsigned int height, 59 | VAImageID image); 60 | 61 | VAStatus sunxi_cedrus_PutImage(VADriverContextP ctx, VASurfaceID surface, 62 | VAImageID image, int src_x, int src_y, unsigned int src_width, 63 | unsigned int src_height, int dest_x, int dest_y, 64 | unsigned int dest_width, unsigned int dest_height); 65 | 66 | #endif /* _IMAGE_H_ */ 67 | -------------------------------------------------------------------------------- /patches/4.9/0012-v4l2-device-add-v4l2_device_req_queue.patch: -------------------------------------------------------------------------------- 1 | From 6b5d509a772f6ba6e7cd2c4066c2414e667b43c7 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Tue, 21 Apr 2015 11:31:38 +0200 4 | Subject: [PATCH] v4l2-device: add v4l2_device_req_queue 5 | 6 | The v4l2_device_req_queue() function is a helper that can be used 7 | as the req_queue callback in simple cases: it will walk over all 8 | registered video_devices and call vb2_qbuf_request() for each video 9 | device. 10 | 11 | Signed-off-by: Hans Verkuil 12 | --- 13 | drivers/media/v4l2-core/v4l2-device.c | 25 +++++++++++++++++++++++++ 14 | include/media/v4l2-device.h | 3 +++ 15 | 2 files changed, 28 insertions(+) 16 | 17 | diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c 18 | index b3b342afd635..a3896959be5a 100644 19 | --- a/drivers/media/v4l2-core/v4l2-device.c 20 | +++ b/drivers/media/v4l2-core/v4l2-device.c 21 | @@ -29,6 +29,7 @@ 22 | #include 23 | #include 24 | #include 25 | +#include 26 | 27 | int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) 28 | { 29 | @@ -318,3 +319,27 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd) 30 | module_put(sd->owner); 31 | } 32 | EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev); 33 | + 34 | +int v4l2_device_req_queue(struct v4l2_device *v4l2_dev, u16 request) 35 | +{ 36 | + struct video_device *vdev; 37 | + struct video_device *tmp; 38 | + int err; 39 | + 40 | + if (request == 0) 41 | + return -EINVAL; 42 | + 43 | + list_for_each_entry_safe(vdev, tmp, &v4l2_dev->vdevs, list) { 44 | + if (vdev->queue == NULL || !vdev->queue->v4l2_allow_requests) 45 | + continue; 46 | + if (vdev->lock && mutex_lock_interruptible(vdev->lock)) 47 | + return -ERESTARTSYS; 48 | + err = vb2_qbuf_request(vdev->queue, request, NULL); 49 | + if (vdev->lock) 50 | + mutex_unlock(vdev->lock); 51 | + if (err) 52 | + return err; 53 | + } 54 | + return 0; 55 | +} 56 | +EXPORT_SYMBOL_GPL(v4l2_device_req_queue); 57 | diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h 58 | index 64176f773fa7..619d5b6a1662 100644 59 | --- a/include/media/v4l2-device.h 60 | +++ b/include/media/v4l2-device.h 61 | @@ -218,6 +218,9 @@ static inline void v4l2_subdev_notify(struct v4l2_subdev *sd, 62 | sd->v4l2_dev->notify(sd, notification, arg); 63 | } 64 | 65 | +/* For each registered video_device struct call vb2_qbuf_request(). */ 66 | +int v4l2_device_req_queue(struct v4l2_device *v4l2_dev, u16 request); 67 | + 68 | /* Iterate over all subdevs. */ 69 | #define v4l2_device_for_each_subdev(sd, v4l2_dev) \ 70 | list_for_each_entry(sd, &(v4l2_dev)->subdevs, list) 71 | -- 72 | 2.14.3 73 | 74 | -------------------------------------------------------------------------------- /patches/4.14/0012-v4l2-device-add-v4l2_device_req_queue.patch: -------------------------------------------------------------------------------- 1 | From 54cdfcc755db3950ecf3f1717088c53a9f491eae Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Tue, 21 Apr 2015 11:31:38 +0200 4 | Subject: [PATCH 12/22] v4l2-device: add v4l2_device_req_queue 5 | 6 | The v4l2_device_req_queue() function is a helper that can be used 7 | as the req_queue callback in simple cases: it will walk over all 8 | registered video_devices and call vb2_qbuf_request() for each video 9 | device. 10 | 11 | Signed-off-by: Hans Verkuil 12 | --- 13 | drivers/media/v4l2-core/v4l2-device.c | 25 +++++++++++++++++++++++++ 14 | include/media/v4l2-device.h | 3 +++ 15 | 2 files changed, 28 insertions(+) 16 | 17 | diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c 18 | index 7a6ac03d58f9..5f53c9a7d092 100644 19 | --- a/drivers/media/v4l2-core/v4l2-device.c 20 | +++ b/drivers/media/v4l2-core/v4l2-device.c 21 | @@ -29,6 +29,7 @@ 22 | #include 23 | #include 24 | #include 25 | +#include 26 | 27 | int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) 28 | { 29 | @@ -321,3 +322,27 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd) 30 | module_put(sd->owner); 31 | } 32 | EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev); 33 | + 34 | +int v4l2_device_req_queue(struct v4l2_device *v4l2_dev, u16 request) 35 | +{ 36 | + struct video_device *vdev; 37 | + struct video_device *tmp; 38 | + int err; 39 | + 40 | + if (request == 0) 41 | + return -EINVAL; 42 | + 43 | + list_for_each_entry_safe(vdev, tmp, &v4l2_dev->vdevs, list) { 44 | + if (vdev->queue == NULL || !vdev->queue->v4l2_allow_requests) 45 | + continue; 46 | + if (vdev->lock && mutex_lock_interruptible(vdev->lock)) 47 | + return -ERESTARTSYS; 48 | + err = vb2_qbuf_request(vdev->queue, request, NULL); 49 | + if (vdev->lock) 50 | + mutex_unlock(vdev->lock); 51 | + if (err) 52 | + return err; 53 | + } 54 | + return 0; 55 | +} 56 | +EXPORT_SYMBOL_GPL(v4l2_device_req_queue); 57 | diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h 58 | index d28843270e6a..10810d5a7025 100644 59 | --- a/include/media/v4l2-device.h 60 | +++ b/include/media/v4l2-device.h 61 | @@ -220,6 +220,9 @@ static inline void v4l2_subdev_notify(struct v4l2_subdev *sd, 62 | sd->v4l2_dev->notify(sd, notification, arg); 63 | } 64 | 65 | +/* For each registered video_device struct call vb2_qbuf_request(). */ 66 | +int v4l2_device_req_queue(struct v4l2_device *v4l2_dev, u16 request); 67 | + 68 | /* Iterate over all subdevs. */ 69 | #define v4l2_device_for_each_subdev(sd, v4l2_dev) \ 70 | list_for_each_entry(sd, &(v4l2_dev)->subdevs, list) 71 | -- 72 | 2.14.3 73 | 74 | -------------------------------------------------------------------------------- /patches/4.9/0007-v4l2-ctrls-implement-delete-request-s.patch: -------------------------------------------------------------------------------- 1 | From 547269717b162b7ba6fd1430ff89bdeea0743b72 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Thu, 9 Apr 2015 14:11:42 +0200 4 | Subject: [PATCH] v4l2-ctrls: implement delete request(s) 5 | 6 | Signed-off-by: Hans Verkuil 7 | --- 8 | drivers/media/v4l2-core/v4l2-ctrls.c | 42 ++++++++++++++++++++++++++++++++++++ 9 | include/media/v4l2-ctrls.h | 1 + 10 | 2 files changed, 43 insertions(+) 11 | 12 | diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c 13 | index 0a35ce1abc3b..2260ae2c7e2a 100644 14 | --- a/drivers/media/v4l2-core/v4l2-ctrls.c 15 | +++ b/drivers/media/v4l2-core/v4l2-ctrls.c 16 | @@ -3534,6 +3534,48 @@ int v4l2_ctrl_apply_request(struct v4l2_ctrl_handler *hdl, unsigned request) 17 | } 18 | EXPORT_SYMBOL(v4l2_ctrl_apply_request); 19 | 20 | +int v4l2_ctrl_delete_request(struct v4l2_ctrl_handler *hdl, unsigned request) 21 | +{ 22 | + struct v4l2_ctrl_ref *ref; 23 | + unsigned i; 24 | + 25 | + if (hdl == NULL || request == 0) 26 | + return -EINVAL; 27 | + 28 | + mutex_lock(hdl->lock); 29 | + 30 | + list_for_each_entry(ref, &hdl->ctrl_refs, node) { 31 | + struct v4l2_ctrl *master; 32 | + 33 | + if (ref->ctrl->max_reqs == 0) 34 | + continue; 35 | + master = ref->ctrl->cluster[0]; 36 | + if (ref->ctrl != master) 37 | + continue; 38 | + if (master->handler != hdl) 39 | + v4l2_ctrl_lock(master); 40 | + for (i = 0; i < master->ncontrols; i++) { 41 | + struct v4l2_ctrl *ctrl = master->cluster[i]; 42 | + struct v4l2_ctrl_req *req; 43 | + 44 | + if (ctrl == NULL || ctrl->request_lists == NULL) 45 | + continue; 46 | + 47 | + if (request == 0) { 48 | + free_requests(ctrl); 49 | + continue; 50 | + } 51 | + req = get_request(ctrl, request); 52 | + if (req) 53 | + del_request(ctrl, req); 54 | + } 55 | + if (master->handler != hdl) 56 | + v4l2_ctrl_unlock(master); 57 | + } 58 | + return 0; 59 | +} 60 | +EXPORT_SYMBOL(v4l2_ctrl_delete_request); 61 | + 62 | void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv) 63 | { 64 | if (ctrl == NULL) 65 | diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h 66 | index a831da6ca08e..c4998e6ea1c8 100644 67 | --- a/include/media/v4l2-ctrls.h 68 | +++ b/include/media/v4l2-ctrls.h 69 | @@ -989,6 +989,7 @@ static inline void v4l2_ctrl_s_max_reqs(struct v4l2_ctrl *ctrl, u16 max_reqs) 70 | } 71 | 72 | int v4l2_ctrl_apply_request(struct v4l2_ctrl_handler *hdl, unsigned request); 73 | +int v4l2_ctrl_delete_request(struct v4l2_ctrl_handler *hdl, unsigned request); 74 | 75 | /* Internal helper functions that deal with control events. */ 76 | extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops; 77 | -- 78 | 2.14.3 79 | 80 | -------------------------------------------------------------------------------- /patches/4.14/0007-v4l2-ctrls-implement-delete-request-s.patch: -------------------------------------------------------------------------------- 1 | From b3c1164222bf794175720afb21a012c54316a436 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Thu, 9 Apr 2015 14:11:42 +0200 4 | Subject: [PATCH 07/22] v4l2-ctrls: implement delete request(s) 5 | 6 | Signed-off-by: Hans Verkuil 7 | --- 8 | drivers/media/v4l2-core/v4l2-ctrls.c | 42 ++++++++++++++++++++++++++++++++++++ 9 | include/media/v4l2-ctrls.h | 1 + 10 | 2 files changed, 43 insertions(+) 11 | 12 | diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c 13 | index b55f402ba61c..fed1dfb2f7eb 100644 14 | --- a/drivers/media/v4l2-core/v4l2-ctrls.c 15 | +++ b/drivers/media/v4l2-core/v4l2-ctrls.c 16 | @@ -3561,6 +3561,48 @@ int v4l2_ctrl_apply_request(struct v4l2_ctrl_handler *hdl, unsigned request) 17 | } 18 | EXPORT_SYMBOL(v4l2_ctrl_apply_request); 19 | 20 | +int v4l2_ctrl_delete_request(struct v4l2_ctrl_handler *hdl, unsigned request) 21 | +{ 22 | + struct v4l2_ctrl_ref *ref; 23 | + unsigned i; 24 | + 25 | + if (hdl == NULL || request == 0) 26 | + return -EINVAL; 27 | + 28 | + mutex_lock(hdl->lock); 29 | + 30 | + list_for_each_entry(ref, &hdl->ctrl_refs, node) { 31 | + struct v4l2_ctrl *master; 32 | + 33 | + if (ref->ctrl->max_reqs == 0) 34 | + continue; 35 | + master = ref->ctrl->cluster[0]; 36 | + if (ref->ctrl != master) 37 | + continue; 38 | + if (master->handler != hdl) 39 | + v4l2_ctrl_lock(master); 40 | + for (i = 0; i < master->ncontrols; i++) { 41 | + struct v4l2_ctrl *ctrl = master->cluster[i]; 42 | + struct v4l2_ctrl_req *req; 43 | + 44 | + if (ctrl == NULL || ctrl->request_lists == NULL) 45 | + continue; 46 | + 47 | + if (request == 0) { 48 | + free_requests(ctrl); 49 | + continue; 50 | + } 51 | + req = get_request(ctrl, request); 52 | + if (req) 53 | + del_request(ctrl, req); 54 | + } 55 | + if (master->handler != hdl) 56 | + v4l2_ctrl_unlock(master); 57 | + } 58 | + return 0; 59 | +} 60 | +EXPORT_SYMBOL(v4l2_ctrl_delete_request); 61 | + 62 | void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, v4l2_ctrl_notify_fnc notify, void *priv) 63 | { 64 | if (ctrl == NULL) 65 | diff --git a/include/media/v4l2-ctrls.h b/include/media/v4l2-ctrls.h 66 | index 6ad0df048f53..da5a18fe2e32 100644 67 | --- a/include/media/v4l2-ctrls.h 68 | +++ b/include/media/v4l2-ctrls.h 69 | @@ -1002,6 +1002,7 @@ static inline void v4l2_ctrl_s_max_reqs(struct v4l2_ctrl *ctrl, u16 max_reqs) 70 | } 71 | 72 | int v4l2_ctrl_apply_request(struct v4l2_ctrl_handler *hdl, unsigned request); 73 | +int v4l2_ctrl_delete_request(struct v4l2_ctrl_handler *hdl, unsigned request); 74 | 75 | /* Internal helper functions that deal with control events. */ 76 | extern const struct v4l2_subscribed_event_ops v4l2_ctrl_sub_ev_ops; 77 | -- 78 | 2.14.3 79 | 80 | -------------------------------------------------------------------------------- /libva/src/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _BUFFER_H_ 27 | #define _BUFFER_H_ 28 | 29 | #include 30 | 31 | #include "object_heap.h" 32 | #include "sunxi_cedrus_drv_video.h" 33 | 34 | #define BUFFER(id) ((object_buffer_p) object_heap_lookup(&driver_data->buffer_heap, id)) 35 | #define BUFFER_ID_OFFSET 0x08000000 36 | 37 | struct object_buffer { 38 | struct object_base base; 39 | void *buffer_data; 40 | int max_num_elements; 41 | int num_elements; 42 | VABufferType type; 43 | unsigned int size; 44 | }; 45 | 46 | typedef struct object_buffer *object_buffer_p; 47 | 48 | VAStatus sunxi_cedrus_CreateBuffer(VADriverContextP ctx, VAContextID context, 49 | VABufferType type, unsigned int size, unsigned int num_elements, 50 | void *data, VABufferID *buf_id); 51 | 52 | VAStatus sunxi_cedrus_BufferSetNumElements(VADriverContextP ctx, 53 | VABufferID buf_id, unsigned int num_elements); 54 | 55 | VAStatus sunxi_cedrus_MapBuffer(VADriverContextP ctx, VABufferID buf_id, 56 | void **pbuf); 57 | 58 | VAStatus sunxi_cedrus_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id); 59 | 60 | void sunxi_cedrus_destroy_buffer(struct sunxi_cedrus_driver_data *driver_data, 61 | object_buffer_p obj_buffer); 62 | 63 | VAStatus sunxi_cedrus_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id); 64 | 65 | VAStatus sunxi_cedrus_BufferInfo(VADriverContextP ctx, VABufferID buf_id, 66 | VABufferType *type, unsigned int *size, 67 | unsigned int *num_elements); 68 | 69 | #endif /* _BUFFER_H_ */ 70 | -------------------------------------------------------------------------------- /driver/sunxi_cedrus_common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sunxi Cedrus codec driver 3 | * 4 | * Copyright (C) 2016 Florent Revest 5 | * Florent Revest 6 | * 7 | * Based on vim2m 8 | * 9 | * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd. 10 | * Pawel Osciak, 11 | * Marek Szyprowski, 12 | * 13 | * This software is licensed under the terms of the GNU General Public 14 | * License version 2, as published by the Free Software Foundation, and 15 | * may be copied, distributed, and modified under those terms. 16 | * 17 | * This program is distributed in the hope that it will be useful, 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | * GNU General Public License for more details. 21 | */ 22 | 23 | #ifndef SUNXI_CEDRUS_COMMON_H_ 24 | #define SUNXI_CEDRUS_COMMON_H_ 25 | 26 | #include "sunxi_cedrus_regs.h" 27 | 28 | #include 29 | #include 30 | 31 | #define SUNXI_CEDRUS_NAME "sunxi-cedrus" 32 | 33 | struct sunxi_cedrus_dev { 34 | struct v4l2_device v4l2_dev; 35 | struct video_device vfd; 36 | struct platform_device *pdev; 37 | struct device *dev; 38 | struct v4l2_m2m_dev *m2m_dev; 39 | 40 | /* Mutex for device file */ 41 | struct mutex dev_mutex; 42 | /* Spinlock for interrupt */ 43 | spinlock_t irqlock; 44 | 45 | struct clk *mod_clk; 46 | struct clk *ahb_clk; 47 | struct clk *ram_clk; 48 | 49 | struct reset_control *rstc; 50 | 51 | char *base; 52 | 53 | unsigned int mbh_buf; 54 | unsigned int dcac_buf; 55 | unsigned int ncf_buf; 56 | 57 | void *mbh_buf_virt; 58 | void *dcac_buf_virt; 59 | void *ncf_buf_virt; 60 | 61 | unsigned int mbh_buf_size; 62 | unsigned int dcac_buf_size; 63 | unsigned int ncf_buf_size; 64 | }; 65 | 66 | struct sunxi_cedrus_fmt { 67 | u32 fourcc; 68 | int depth; 69 | u32 types; 70 | unsigned int num_planes; 71 | }; 72 | 73 | struct sunxi_cedrus_ctx { 74 | struct v4l2_fh fh; 75 | struct sunxi_cedrus_dev *dev; 76 | 77 | struct sunxi_cedrus_fmt *vpu_src_fmt; 78 | struct v4l2_pix_format_mplane src_fmt; 79 | struct sunxi_cedrus_fmt *vpu_dst_fmt; 80 | struct v4l2_pix_format_mplane dst_fmt; 81 | 82 | struct v4l2_ctrl_handler hdl; 83 | 84 | struct vb2_buffer *dst_bufs[VIDEO_MAX_FRAME]; 85 | 86 | struct v4l2_ctrl *mpeg2_frame_hdr_ctrl; 87 | struct v4l2_ctrl *mpeg4_frame_hdr_ctrl; 88 | }; 89 | 90 | static inline void sunxi_cedrus_write(struct sunxi_cedrus_dev *vpu, 91 | u32 val, u32 reg) 92 | { 93 | writel(val, vpu->base + reg); 94 | } 95 | 96 | static inline u32 sunxi_cedrus_read(struct sunxi_cedrus_dev *vpu, u32 reg) 97 | { 98 | return readl(vpu->base + reg); 99 | } 100 | 101 | #endif /* SUNXI_CEDRUS_COMMON_H_ */ 102 | -------------------------------------------------------------------------------- /libva/src/subpicture.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _SUBPICTURE_H_ 27 | #define _SUBPICTURE_H_ 28 | 29 | #include 30 | 31 | VAStatus sunxi_cedrus_QuerySubpictureFormats(VADriverContextP ctx, 32 | VAImageFormat *format_list, unsigned int *flags, 33 | unsigned int *num_formats); 34 | 35 | VAStatus sunxi_cedrus_CreateSubpicture(VADriverContextP ctx, VAImageID image, 36 | VASubpictureID *subpicture); 37 | 38 | VAStatus sunxi_cedrus_DestroySubpicture(VADriverContextP ctx, 39 | VASubpictureID subpicture); 40 | 41 | VAStatus sunxi_cedrus_SetSubpictureImage(VADriverContextP ctx, 42 | VASubpictureID subpicture, VAImageID image); 43 | 44 | VAStatus sunxi_cedrus_SetSubpicturePalette(VADriverContextP ctx, 45 | VASubpictureID subpicture, unsigned char *palette); 46 | 47 | VAStatus sunxi_cedrus_SetSubpictureChromakey(VADriverContextP ctx, 48 | VASubpictureID subpicture, unsigned int chromakey_min, 49 | unsigned int chromakey_max, unsigned int chromakey_mask); 50 | 51 | VAStatus sunxi_cedrus_SetSubpictureGlobalAlpha(VADriverContextP ctx, 52 | VASubpictureID subpicture, float global_alpha); 53 | 54 | VAStatus sunxi_cedrus_AssociateSubpicture(VADriverContextP ctx, 55 | VASubpictureID subpicture, VASurfaceID *target_surfaces, 56 | int num_surfaces, short src_x, short src_y, 57 | unsigned short src_width, unsigned short src_height, 58 | short dest_x, short dest_y, unsigned short dest_width, 59 | unsigned short dest_height, unsigned int flags); 60 | 61 | VAStatus sunxi_cedrus_DeassociateSubpicture(VADriverContextP ctx, 62 | VASubpictureID subpicture, VASurfaceID *target_surfaces, 63 | int num_surfaces); 64 | 65 | #endif /* _SUBPICTURE_H_ */ 66 | -------------------------------------------------------------------------------- /libva/src/object_heap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Intel Corporation. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sub license, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice (including the 13 | * next paragraph) shall be included in all copies or substantial portions 14 | * of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 19 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 20 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #ifndef OBJECT_HEAP_H 26 | #define OBJECT_HEAP_H 27 | 28 | #include 29 | 30 | #define OBJECT_HEAP_OFFSET_MASK 0x7F000000 31 | #define OBJECT_HEAP_ID_MASK 0x00FFFFFF 32 | 33 | typedef struct object_base *object_base_p; 34 | typedef struct object_heap *object_heap_p; 35 | 36 | struct object_base { 37 | int id; 38 | int next_free; 39 | }; 40 | 41 | struct object_heap { 42 | pthread_mutex_t mutex; 43 | int object_size; 44 | int id_offset; 45 | int next_free; 46 | int heap_size; 47 | int heap_increment; 48 | void **bucket; 49 | int num_buckets; 50 | }; 51 | 52 | typedef int object_heap_iterator; 53 | 54 | /* 55 | * Return 0 on success, -1 on error 56 | */ 57 | int object_heap_init(object_heap_p heap, int object_size, int id_offset); 58 | 59 | /* 60 | * Allocates an object 61 | * Returns the object ID on success, returns -1 on error 62 | */ 63 | int object_heap_allocate(object_heap_p heap); 64 | 65 | /* 66 | * Lookup an allocated object by object ID 67 | * Returns a pointer to the object on success, returns NULL on error 68 | */ 69 | object_base_p object_heap_lookup(object_heap_p heap, int id); 70 | 71 | /* 72 | * Iterate over all objects in the heap. 73 | * Returns a pointer to the first object on the heap, returns NULL if heap is empty. 74 | */ 75 | object_base_p object_heap_first(object_heap_p heap, object_heap_iterator *iter); 76 | 77 | /* 78 | * Iterate over all objects in the heap. 79 | * Returns a pointer to the next object on the heap, returns NULL if heap is empty. 80 | */ 81 | object_base_p object_heap_next(object_heap_p heap, object_heap_iterator *iter); 82 | 83 | /* 84 | * Frees an object 85 | */ 86 | void object_heap_free(object_heap_p heap, object_base_p obj); 87 | 88 | /* 89 | * Destroys a heap, the heap must be empty. 90 | */ 91 | void object_heap_destroy(object_heap_p heap); 92 | 93 | #endif /* OBJECT_HEAP_H */ 94 | -------------------------------------------------------------------------------- /libva/src/surface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _SURFACES_H_ 27 | #define _SURFACES_H_ 28 | 29 | #include 30 | 31 | #include "object_heap.h" 32 | 33 | #define SURFACE(id) ((object_surface_p) object_heap_lookup(&driver_data->surface_heap, id)) 34 | #define SURFACE_ID_OFFSET 0x04000000 35 | 36 | struct object_surface { 37 | struct object_base base; 38 | VASurfaceID surface_id; 39 | uint32_t request; 40 | uint32_t input_buf_index; 41 | uint32_t output_buf_index; 42 | int width; 43 | int height; 44 | VAStatus status; 45 | }; 46 | 47 | typedef struct object_surface *object_surface_p; 48 | 49 | VAStatus sunxi_cedrus_CreateSurfaces(VADriverContextP ctx, int width, 50 | int height, int format, int num_surfaces, VASurfaceID *surfaces); 51 | 52 | VAStatus sunxi_cedrus_DestroySurfaces(VADriverContextP ctx, 53 | VASurfaceID *surface_list, int num_surfaces); 54 | 55 | VAStatus sunxi_cedrus_SyncSurface(VADriverContextP ctx, 56 | VASurfaceID render_target); 57 | 58 | VAStatus sunxi_cedrus_QuerySurfaceStatus(VADriverContextP ctx, 59 | VASurfaceID render_target, VASurfaceStatus *status); 60 | 61 | VAStatus sunxi_cedrus_PutSurface(VADriverContextP ctx, VASurfaceID surface, 62 | void *draw, short srcx, short srcy, unsigned short srcw, 63 | unsigned short srch, short destx, short desty, 64 | unsigned short destw, unsigned short desth, 65 | VARectangle *cliprects, unsigned int number_cliprects, 66 | unsigned int flags); 67 | 68 | VAStatus sunxi_cedrus_LockSurface(VADriverContextP ctx, VASurfaceID surface, 69 | unsigned int *fourcc, unsigned int *luma_stride, 70 | unsigned int *chroma_u_stride, unsigned int *chroma_v_stride, 71 | unsigned int *luma_offset, unsigned int *chroma_u_offset, 72 | unsigned int *chroma_v_offset, unsigned int *buffer_name, 73 | void **buffer); 74 | 75 | VAStatus sunxi_cedrus_UnlockSurface(VADriverContextP ctx, VASurfaceID surface); 76 | 77 | #endif /* _SURFACES_H_ */ 78 | -------------------------------------------------------------------------------- /libva/src/subpicture.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "sunxi_cedrus_drv_video.h" 27 | #include "subpicture.h" 28 | 29 | /* 30 | * Subpictures aren't supported yet 31 | */ 32 | 33 | VAStatus sunxi_cedrus_QuerySubpictureFormats(VADriverContextP ctx, 34 | VAImageFormat *format_list, unsigned int *flags, 35 | unsigned int *num_formats) 36 | { return VA_STATUS_SUCCESS; } 37 | 38 | VAStatus sunxi_cedrus_CreateSubpicture(VADriverContextP ctx, VAImageID image, 39 | VASubpictureID *subpicture) 40 | { return VA_STATUS_SUCCESS; } 41 | 42 | VAStatus sunxi_cedrus_DestroySubpicture(VADriverContextP ctx, 43 | VASubpictureID subpicture) 44 | { return VA_STATUS_SUCCESS; } 45 | 46 | VAStatus sunxi_cedrus_SetSubpictureImage(VADriverContextP ctx, 47 | VASubpictureID subpicture, VAImageID image) 48 | { return VA_STATUS_SUCCESS; } 49 | 50 | VAStatus sunxi_cedrus_SetSubpicturePalette(VADriverContextP ctx, 51 | VASubpictureID subpicture, unsigned char *palette) 52 | { return VA_STATUS_SUCCESS; } 53 | 54 | VAStatus sunxi_cedrus_SetSubpictureChromakey(VADriverContextP ctx, 55 | VASubpictureID subpicture, unsigned int chromakey_min, 56 | unsigned int chromakey_max, unsigned int chromakey_mask) 57 | { return VA_STATUS_SUCCESS; } 58 | 59 | VAStatus sunxi_cedrus_SetSubpictureGlobalAlpha(VADriverContextP ctx, 60 | VASubpictureID subpicture, float global_alpha) 61 | { return VA_STATUS_SUCCESS; } 62 | 63 | VAStatus sunxi_cedrus_AssociateSubpicture(VADriverContextP ctx, 64 | VASubpictureID subpicture, VASurfaceID *target_surfaces, 65 | int num_surfaces, short src_x, short src_y, 66 | unsigned short src_width, unsigned short src_height, 67 | short dest_x, short dest_y, unsigned short dest_width, 68 | unsigned short dest_height, unsigned int flags) 69 | { return VA_STATUS_SUCCESS; } 70 | 71 | VAStatus sunxi_cedrus_DeassociateSubpicture(VADriverContextP ctx, 72 | VASubpictureID subpicture, VASurfaceID *target_surfaces, 73 | int num_surfaces) 74 | { return VA_STATUS_SUCCESS; } 75 | 76 | -------------------------------------------------------------------------------- /libva/src/va_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _CONFIG_H_ 27 | #define _CONFIG_H_ 28 | 29 | #include 30 | 31 | #include "object_heap.h" 32 | 33 | #define CONFIG(id) ((object_config_p) object_heap_lookup(&driver_data->config_heap, id)) 34 | #define CONFIG_ID_OFFSET 0x01000000 35 | 36 | struct object_config { 37 | struct object_base base; 38 | VAProfile profile; 39 | VAEntrypoint entrypoint; 40 | VAConfigAttrib attrib_list[SUNXI_CEDRUS_MAX_CONFIG_ATTRIBUTES]; 41 | int attrib_count; 42 | }; 43 | 44 | typedef struct object_config *object_config_p; 45 | 46 | VAStatus sunxi_cedrus_QueryConfigProfiles(VADriverContextP ctx, 47 | VAProfile *profile_list, int *num_profiles); 48 | 49 | VAStatus sunxi_cedrus_QueryConfigEntrypoints(VADriverContextP ctx, 50 | VAProfile profile, VAEntrypoint *entrypoint_list, 51 | int *num_entrypoints); 52 | 53 | VAStatus sunxi_cedrus_GetConfigAttributes(VADriverContextP ctx, 54 | VAProfile profile, VAEntrypoint entrypoint, 55 | VAConfigAttrib *attrib_list, int num_attribs); 56 | 57 | VAStatus sunxi_cedrus_update_attribute(object_config_p obj_config, 58 | VAConfigAttrib *attrib); 59 | 60 | VAStatus sunxi_cedrus_CreateConfig(VADriverContextP ctx, VAProfile profile, 61 | VAEntrypoint entrypoint, VAConfigAttrib *attrib_list, 62 | int num_attribs, VAConfigID *config_id); 63 | 64 | VAStatus sunxi_cedrus_DestroyConfig(VADriverContextP ctx, VAConfigID config_id); 65 | 66 | VAStatus sunxi_cedrus_QueryConfigAttributes(VADriverContextP ctx, 67 | VAConfigID config_id, VAProfile *profile, 68 | VAEntrypoint *entrypoint, VAConfigAttrib *attrib_list, 69 | int *num_attribs); 70 | 71 | VAStatus sunxi_cedrus_QueryDisplayAttributes (VADriverContextP ctx, 72 | VADisplayAttribute *attr_list, int *num_attributes); 73 | 74 | VAStatus sunxi_cedrus_GetDisplayAttributes (VADriverContextP ctx, 75 | VADisplayAttribute *attr_list, int num_attributes); 76 | 77 | VAStatus sunxi_cedrus_SetDisplayAttributes (VADriverContextP ctx, 78 | VADisplayAttribute *attr_list, int num_attributes); 79 | 80 | #endif /* _CONFIG_H_ */ 81 | -------------------------------------------------------------------------------- /patches/4.9/0010-vb2-add-helper-function-to-queue-request-specific-bu.patch: -------------------------------------------------------------------------------- 1 | From 188cf64c8bc6f7fe33d39fd1ce849fe9f34fee45 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Mon, 13 Apr 2015 15:53:34 +0200 4 | Subject: [PATCH] vb2: add helper function to queue request-specific buffer. 5 | 6 | The vb2_qbuf_request() function will queue any buffers for the given request 7 | that are in state PREPARED. 8 | 9 | Useful when drivers have to implement the req_queue callback. 10 | 11 | Signed-off-by: Hans Verkuil 12 | --- 13 | drivers/media/v4l2-core/videobuf2-v4l2.c | 42 ++++++++++++++++++++++++++++++++ 14 | include/media/videobuf2-v4l2.h | 1 + 15 | 2 files changed, 43 insertions(+) 16 | 17 | diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c 18 | index e788f527b7f0..94b18b65f9d8 100644 19 | --- a/drivers/media/v4l2-core/videobuf2-v4l2.c 20 | +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c 21 | @@ -579,6 +579,48 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) 22 | } 23 | EXPORT_SYMBOL_GPL(vb2_qbuf); 24 | 25 | +int vb2_qbuf_request(struct vb2_queue *q, u16 request, struct vb2_buffer **p_buf) 26 | +{ 27 | + struct v4l2_buffer v4l2_buf; 28 | + int buffer; 29 | + 30 | + for (buffer = 0; buffer < q->num_buffers; buffer++) { 31 | + struct vb2_buffer *vb = q->bufs[buffer]; 32 | + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); 33 | + 34 | + if (vbuf->request == request && 35 | + vb->state == VB2_BUF_STATE_PREPARED) { 36 | + if (p_buf) 37 | + *p_buf = vb; 38 | + __fill_v4l2_buffer(vb, &v4l2_buf); 39 | + return vb2_qbuf(q, &v4l2_buf); 40 | + } 41 | + } 42 | + return -ENOENT; 43 | +} 44 | +EXPORT_SYMBOL_GPL(vb2_qbuf_request); 45 | + 46 | +/** 47 | + * vb2_dqbuf() - Dequeue a buffer to the userspace 48 | + * @q: videobuf2 queue 49 | + * @b: buffer structure passed from userspace to vidioc_dqbuf handler 50 | + * in driver 51 | + * @nonblocking: if true, this call will not sleep waiting for a buffer if no 52 | + * buffers ready for dequeuing are present. Normally the driver 53 | + * would be passing (file->f_flags & O_NONBLOCK) here 54 | + * 55 | + * Should be called from vidioc_dqbuf ioctl handler of a driver. 56 | + * This function: 57 | + * 1) verifies the passed buffer, 58 | + * 2) calls buf_finish callback in the driver (if provided), in which 59 | + * driver can perform any additional operations that may be required before 60 | + * returning the buffer to userspace, such as cache sync, 61 | + * 3) the buffer struct members are filled with relevant information for 62 | + * the userspace. 63 | + * 64 | + * The return values from this function are intended to be directly returned 65 | + * from vidioc_dqbuf handler in driver. 66 | + */ 67 | int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking) 68 | { 69 | int ret; 70 | diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h 71 | index 3029b763ab58..47d38971b9d5 100644 72 | --- a/include/media/videobuf2-v4l2.h 73 | +++ b/include/media/videobuf2-v4l2.h 74 | @@ -113,6 +113,7 @@ int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b); 75 | * from VIDIOC_QBUF() handler in driver. 76 | */ 77 | int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b); 78 | +int vb2_qbuf_request(struct vb2_queue *q, u16 request, struct vb2_buffer **p_buf); 79 | 80 | /** 81 | * vb2_expbuf() - Export a buffer as a file descriptor 82 | -- 83 | 2.14.3 84 | 85 | -------------------------------------------------------------------------------- /patches/4.9/0009-v4l2-add-initial-V4L2_REQ_CMD_QUEUE-support.patch: -------------------------------------------------------------------------------- 1 | From bf692a640d4997c9c80659572079b604682770b7 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Tue, 21 Apr 2015 12:28:44 +0200 4 | Subject: [PATCH] v4l2: add initial V4L2_REQ_CMD_QUEUE support 5 | 6 | Add the V4L2_REQ_CMD_QUEUE command and the req_queue callback to struct 7 | v4l2_device. Call it if set from v4l2-ioctl.c and v4l2-subdev.c. Make sure 8 | in v4l2-ioctl.c to unlock any current lock first (and relock afterwards). 9 | That way req_queue is called with the assurance that there are no video_device 10 | locks taken. Since req_queue operates device-wide that would make that code 11 | much more complex. 12 | 13 | Signed-off-by: Hans Verkuil 14 | --- 15 | drivers/media/v4l2-core/v4l2-ioctl.c | 11 +++++++++++ 16 | drivers/media/v4l2-core/v4l2-subdev.c | 6 ++++++ 17 | include/media/v4l2-device.h | 2 ++ 18 | include/uapi/linux/videodev2.h | 1 + 19 | 4 files changed, 20 insertions(+) 20 | 21 | diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c 22 | index 2403d9455114..c6cbb3eb845f 100644 23 | --- a/drivers/media/v4l2-core/v4l2-ioctl.c 24 | +++ b/drivers/media/v4l2-core/v4l2-ioctl.c 25 | @@ -2303,6 +2303,17 @@ static int v4l_request_cmd(const struct v4l2_ioctl_ops *ops, 26 | return v4l2_ctrl_delete_request(vfh->ctrl_handler, p->request); 27 | case V4L2_REQ_CMD_APPLY: 28 | return v4l2_ctrl_apply_request(vfh->ctrl_handler, p->request); 29 | + case V4L2_REQ_CMD_QUEUE: 30 | + if (vfd->v4l2_dev->req_queue == NULL) 31 | + return -ENOSYS; 32 | + if (p->request == 0) 33 | + return -EINVAL; 34 | + if (vfd->lock) 35 | + mutex_unlock(vfd->lock); 36 | + ret = vfd->v4l2_dev->req_queue(vfd->v4l2_dev, p->request); 37 | + if (vfd->lock) 38 | + mutex_lock(vfd->lock); 39 | + return ret; 40 | default: 41 | return -EINVAL; 42 | } 43 | diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c 44 | index 27a908498eaf..1f598ba687ba 100644 45 | --- a/drivers/media/v4l2-core/v4l2-subdev.c 46 | +++ b/drivers/media/v4l2-core/v4l2-subdev.c 47 | @@ -268,6 +268,12 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) 48 | case V4L2_REQ_CMD_APPLY: 49 | return v4l2_ctrl_apply_request(vfh->ctrl_handler, 50 | p->request); 51 | + case V4L2_REQ_CMD_QUEUE: 52 | + if (sd->v4l2_dev->req_queue == NULL) 53 | + return -ENOSYS; 54 | + if (p->request == 0) 55 | + return -EINVAL; 56 | + return sd->v4l2_dev->req_queue(sd->v4l2_dev, p->request); 57 | default: 58 | return -EINVAL; 59 | } 60 | diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h 61 | index 8ffa94009d1a..f11f079b2fa4 100644 62 | --- a/include/media/v4l2-device.h 63 | +++ b/include/media/v4l2-device.h 64 | @@ -71,6 +71,8 @@ struct v4l2_device { 65 | struct v4l2_prio_state prio; 66 | struct kref ref; 67 | void (*release)(struct v4l2_device *v4l2_dev); 68 | + /* Queue a request */ 69 | + int (*req_queue)(struct v4l2_device *v4l2_dev, u16 request); 70 | }; 71 | 72 | /** 73 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 74 | index af094ec8b4a3..30ade0ce6dfc 100644 75 | --- a/include/uapi/linux/videodev2.h 76 | +++ b/include/uapi/linux/videodev2.h 77 | @@ -2218,6 +2218,7 @@ struct v4l2_create_buffers { 78 | #define V4L2_REQ_CMD_END (1) 79 | #define V4L2_REQ_CMD_DELETE (2) 80 | #define V4L2_REQ_CMD_APPLY (3) 81 | +#define V4L2_REQ_CMD_QUEUE (4) 82 | 83 | struct v4l2_request_cmd { 84 | __u32 cmd; 85 | -- 86 | 2.14.3 87 | 88 | -------------------------------------------------------------------------------- /patches/4.14/0009-v4l2-add-initial-V4L2_REQ_CMD_QUEUE-support.patch: -------------------------------------------------------------------------------- 1 | From dd0f8dbdfcdf27fc21a820ad4e7cf28b692750a5 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Tue, 21 Apr 2015 12:28:44 +0200 4 | Subject: [PATCH 09/22] v4l2: add initial V4L2_REQ_CMD_QUEUE support 5 | 6 | Add the V4L2_REQ_CMD_QUEUE command and the req_queue callback to struct 7 | v4l2_device. Call it if set from v4l2-ioctl.c and v4l2-subdev.c. Make sure 8 | in v4l2-ioctl.c to unlock any current lock first (and relock afterwards). 9 | That way req_queue is called with the assurance that there are no video_device 10 | locks taken. Since req_queue operates device-wide that would make that code 11 | much more complex. 12 | 13 | Signed-off-by: Hans Verkuil 14 | --- 15 | drivers/media/v4l2-core/v4l2-ioctl.c | 11 +++++++++++ 16 | drivers/media/v4l2-core/v4l2-subdev.c | 6 ++++++ 17 | include/media/v4l2-device.h | 2 ++ 18 | include/uapi/linux/videodev2.h | 1 + 19 | 4 files changed, 20 insertions(+) 20 | 21 | diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c 22 | index 2f82bd75879e..9eec9b9dee79 100644 23 | --- a/drivers/media/v4l2-core/v4l2-ioctl.c 24 | +++ b/drivers/media/v4l2-core/v4l2-ioctl.c 25 | @@ -2360,6 +2360,17 @@ static int v4l_request_cmd(const struct v4l2_ioctl_ops *ops, 26 | return v4l2_ctrl_delete_request(vfh->ctrl_handler, p->request); 27 | case V4L2_REQ_CMD_APPLY: 28 | return v4l2_ctrl_apply_request(vfh->ctrl_handler, p->request); 29 | + case V4L2_REQ_CMD_QUEUE: 30 | + if (vfd->v4l2_dev->req_queue == NULL) 31 | + return -ENOSYS; 32 | + if (p->request == 0) 33 | + return -EINVAL; 34 | + if (vfd->lock) 35 | + mutex_unlock(vfd->lock); 36 | + ret = vfd->v4l2_dev->req_queue(vfd->v4l2_dev, p->request); 37 | + if (vfd->lock) 38 | + mutex_lock(vfd->lock); 39 | + return ret; 40 | default: 41 | return -EINVAL; 42 | } 43 | diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c 44 | index 0b5997ebadce..c1da78c7ff6c 100644 45 | --- a/drivers/media/v4l2-core/v4l2-subdev.c 46 | +++ b/drivers/media/v4l2-core/v4l2-subdev.c 47 | @@ -265,6 +265,12 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) 48 | case V4L2_REQ_CMD_APPLY: 49 | return v4l2_ctrl_apply_request(vfh->ctrl_handler, 50 | p->request); 51 | + case V4L2_REQ_CMD_QUEUE: 52 | + if (sd->v4l2_dev->req_queue == NULL) 53 | + return -ENOSYS; 54 | + if (p->request == 0) 55 | + return -EINVAL; 56 | + return sd->v4l2_dev->req_queue(sd->v4l2_dev, p->request); 57 | default: 58 | return -EINVAL; 59 | } 60 | diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h 61 | index 8ffa94009d1a..f11f079b2fa4 100644 62 | --- a/include/media/v4l2-device.h 63 | +++ b/include/media/v4l2-device.h 64 | @@ -71,6 +71,8 @@ struct v4l2_device { 65 | struct v4l2_prio_state prio; 66 | struct kref ref; 67 | void (*release)(struct v4l2_device *v4l2_dev); 68 | + /* Queue a request */ 69 | + int (*req_queue)(struct v4l2_device *v4l2_dev, u16 request); 70 | }; 71 | 72 | /** 73 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 74 | index f39565ae69d3..5030fba95006 100644 75 | --- a/include/uapi/linux/videodev2.h 76 | +++ b/include/uapi/linux/videodev2.h 77 | @@ -2307,6 +2307,7 @@ struct v4l2_create_buffers { 78 | #define V4L2_REQ_CMD_END (1) 79 | #define V4L2_REQ_CMD_DELETE (2) 80 | #define V4L2_REQ_CMD_APPLY (3) 81 | +#define V4L2_REQ_CMD_QUEUE (4) 82 | 83 | struct v4l2_request_cmd { 84 | __u32 cmd; 85 | -- 86 | 2.14.3 87 | 88 | -------------------------------------------------------------------------------- /patches/4.14/0011-v4l2-device-keep-track-of-registered-video_devices.patch: -------------------------------------------------------------------------------- 1 | From c3a295174eafc165f4a54ddde362622fc7d2eb24 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Tue, 21 Apr 2015 09:58:34 +0200 4 | Subject: [PATCH 11/22] v4l2-device: keep track of registered video_devices 5 | 6 | In order to efficiently handle V4L2_REQ_CMD_QUEUE we need to know which 7 | video_device structs are registered for the given v4l2_device struct. 8 | 9 | So create a list of vdevs in v4l2_device and add/remove each video_device 10 | there as it is registered/unregistered. 11 | 12 | Signed-off-by: Hans Verkuil 13 | --- 14 | drivers/media/v4l2-core/v4l2-dev.c | 8 ++++++++ 15 | drivers/media/v4l2-core/v4l2-device.c | 1 + 16 | include/media/v4l2-dev.h | 3 +++ 17 | include/media/v4l2-device.h | 4 ++++ 18 | 4 files changed, 16 insertions(+) 19 | 20 | diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c 21 | index 623ed06d874e..b9a41292229d 100644 22 | --- a/drivers/media/v4l2-core/v4l2-dev.c 23 | +++ b/drivers/media/v4l2-core/v4l2-dev.c 24 | @@ -842,6 +842,8 @@ int __video_register_device(struct video_device *vdev, int type, int nr, 25 | if (WARN_ON(!vdev->v4l2_dev)) 26 | return -EINVAL; 27 | 28 | + INIT_LIST_HEAD(&vdev->list); 29 | + 30 | /* v4l2_fh support */ 31 | spin_lock_init(&vdev->fh_lock); 32 | INIT_LIST_HEAD(&vdev->fh_list); 33 | @@ -991,6 +993,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr, 34 | 35 | /* Part 6: Activate this minor. The char device can now be used. */ 36 | set_bit(V4L2_FL_REGISTERED, &vdev->flags); 37 | + spin_lock(&vdev->v4l2_dev->lock); 38 | + list_add_tail(&vdev->list, &vdev->v4l2_dev->vdevs); 39 | + spin_unlock(&vdev->v4l2_dev->lock); 40 | 41 | return 0; 42 | 43 | @@ -1026,6 +1031,9 @@ void video_unregister_device(struct video_device *vdev) 44 | */ 45 | clear_bit(V4L2_FL_REGISTERED, &vdev->flags); 46 | mutex_unlock(&videodev_lock); 47 | + spin_lock(&vdev->v4l2_dev->lock); 48 | + list_del(&vdev->list); 49 | + spin_unlock(&vdev->v4l2_dev->lock); 50 | device_unregister(&vdev->dev); 51 | } 52 | EXPORT_SYMBOL(video_unregister_device); 53 | diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c 54 | index 937c6de85606..7a6ac03d58f9 100644 55 | --- a/drivers/media/v4l2-core/v4l2-device.c 56 | +++ b/drivers/media/v4l2-core/v4l2-device.c 57 | @@ -36,6 +36,7 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) 58 | return -EINVAL; 59 | 60 | INIT_LIST_HEAD(&v4l2_dev->subdevs); 61 | + INIT_LIST_HEAD(&v4l2_dev->vdevs); 62 | spin_lock_init(&v4l2_dev->lock); 63 | v4l2_prio_init(&v4l2_dev->prio); 64 | kref_init(&v4l2_dev->ref); 65 | diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h 66 | index 28a686eb7d09..ad714d5124cb 100644 67 | --- a/include/media/v4l2-dev.h 68 | +++ b/include/media/v4l2-dev.h 69 | @@ -213,6 +213,9 @@ struct v4l2_file_operations { 70 | 71 | struct video_device 72 | { 73 | + /* links into v4l2_device vdevs list */ 74 | + struct list_head list; 75 | + 76 | #if defined(CONFIG_MEDIA_CONTROLLER) 77 | struct media_entity entity; 78 | struct media_intf_devnode *intf_devnode; 79 | diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h 80 | index f11f079b2fa4..d28843270e6a 100644 81 | --- a/include/media/v4l2-device.h 82 | +++ b/include/media/v4l2-device.h 83 | @@ -63,6 +63,10 @@ struct v4l2_device { 84 | struct media_device *mdev; 85 | #endif 86 | struct list_head subdevs; 87 | + /* used to keep track of the registered video_devices */ 88 | + struct list_head vdevs; 89 | + /* lock this struct; can be used by the driver as well if this 90 | + struct is embedded into a larger struct. */ 91 | spinlock_t lock; 92 | char name[V4L2_DEVICE_NAME_SIZE]; 93 | void (*notify)(struct v4l2_subdev *sd, 94 | -- 95 | 2.14.3 96 | 97 | -------------------------------------------------------------------------------- /patches/4.14/0013-vivid-add-request-support-for-video-capture.patch: -------------------------------------------------------------------------------- 1 | From e8901580cae6c5f0d3855cd7dea87402d69eaf29 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Mon, 13 Apr 2015 15:54:13 +0200 4 | Subject: [PATCH 13/22] vivid: add request support for video capture. 5 | 6 | In order to test the request API in applications we add request support to 7 | vivid. The brightness, contrast, saturation and hue controls now can be used 8 | in requests. Those were chosen because the test pattern generator supports 9 | those controls and will adjust the TPG colors accordingly, so this gives a 10 | good visual feedback. 11 | 12 | Just before a buffer with a specific request is ready to be filled, any 13 | controls set for that request are applied and the TPG will use the new 14 | values for filling in the buffer, so this matches what a well-written driver 15 | will do in actual hardware. 16 | 17 | Finally, support for req_queue is added using the new v4l2_device_req_queue 18 | helper function. 19 | 20 | Signed-off-by: Hans Verkuil 21 | --- 22 | drivers/media/platform/vivid/vivid-core.c | 2 ++ 23 | drivers/media/platform/vivid/vivid-ctrls.c | 4 ++++ 24 | drivers/media/platform/vivid/vivid-kthread-cap.c | 2 ++ 25 | 3 files changed, 8 insertions(+) 26 | 27 | diff --git a/drivers/media/platform/vivid/vivid-core.c b/drivers/media/platform/vivid/vivid-core.c 28 | index 5f316a5e38db..d484df2bb2b8 100644 29 | --- a/drivers/media/platform/vivid/vivid-core.c 30 | +++ b/drivers/media/platform/vivid/vivid-core.c 31 | @@ -678,6 +678,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst) 32 | return ret; 33 | } 34 | dev->v4l2_dev.release = vivid_dev_release; 35 | + dev->v4l2_dev.req_queue = v4l2_device_req_queue; 36 | 37 | /* start detecting feature set */ 38 | 39 | @@ -1071,6 +1072,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst) 40 | q->min_buffers_needed = 2; 41 | q->lock = &dev->mutex; 42 | q->dev = dev->v4l2_dev.dev; 43 | + q->v4l2_allow_requests = 1; 44 | 45 | ret = vb2_queue_init(q); 46 | if (ret) 47 | diff --git a/drivers/media/platform/vivid/vivid-ctrls.c b/drivers/media/platform/vivid/vivid-ctrls.c 48 | index 34731f71cc00..1eac99fedacf 100644 49 | --- a/drivers/media/platform/vivid/vivid-ctrls.c 50 | +++ b/drivers/media/platform/vivid/vivid-ctrls.c 51 | @@ -1411,12 +1411,16 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap, 52 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); 53 | for (i = 0; i < MAX_INPUTS; i++) 54 | dev->input_brightness[i] = 128; 55 | + v4l2_ctrl_s_max_reqs(dev->brightness, VIDEO_MAX_FRAME); 56 | dev->contrast = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops, 57 | V4L2_CID_CONTRAST, 0, 255, 1, 128); 58 | + v4l2_ctrl_s_max_reqs(dev->contrast, VIDEO_MAX_FRAME); 59 | dev->saturation = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops, 60 | V4L2_CID_SATURATION, 0, 255, 1, 128); 61 | + v4l2_ctrl_s_max_reqs(dev->saturation, VIDEO_MAX_FRAME); 62 | dev->hue = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops, 63 | V4L2_CID_HUE, -128, 128, 1, 0); 64 | + v4l2_ctrl_s_max_reqs(dev->hue, VIDEO_MAX_FRAME); 65 | v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops, 66 | V4L2_CID_HFLIP, 0, 1, 1, 0); 67 | v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops, 68 | diff --git a/drivers/media/platform/vivid/vivid-kthread-cap.c b/drivers/media/platform/vivid/vivid-kthread-cap.c 69 | index 6ca71aabb576..326eb37ef047 100644 70 | --- a/drivers/media/platform/vivid/vivid-kthread-cap.c 71 | +++ b/drivers/media/platform/vivid/vivid-kthread-cap.c 72 | @@ -700,6 +700,8 @@ static void vivid_thread_vid_cap_tick(struct vivid_dev *dev, int dropped_bufs) 73 | if (!list_empty(&dev->vid_cap_active)) { 74 | vid_cap_buf = list_entry(dev->vid_cap_active.next, struct vivid_buffer, list); 75 | list_del(&vid_cap_buf->list); 76 | + v4l2_ctrl_apply_request(dev->vid_cap_dev.ctrl_handler, 77 | + vid_cap_buf->vb.request); 78 | } 79 | if (!list_empty(&dev->vbi_cap_active)) { 80 | if (dev->field_cap != V4L2_FIELD_ALTERNATE || 81 | -- 82 | 2.14.3 83 | 84 | -------------------------------------------------------------------------------- /patches/4.9/0013-vivid-add-request-support-for-video-capture.patch: -------------------------------------------------------------------------------- 1 | From 82feaa6d1f42c13ec81333d0586cdbc5fa585ba8 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Mon, 13 Apr 2015 15:54:13 +0200 4 | Subject: [PATCH] vivid: add request support for video capture. 5 | 6 | In order to test the request API in applications we add request support to 7 | vivid. The brightness, contrast, saturation and hue controls now can be used 8 | in requests. Those were chosen because the test pattern generator supports 9 | those controls and will adjust the TPG colors accordingly, so this gives a 10 | good visual feedback. 11 | 12 | Just before a buffer with a specific request is ready to be filled, any 13 | controls set for that request are applied and the TPG will use the new 14 | values for filling in the buffer, so this matches what a well-written driver 15 | will do in actual hardware. 16 | 17 | Finally, support for req_queue is added using the new v4l2_device_req_queue 18 | helper function. 19 | 20 | Signed-off-by: Hans Verkuil 21 | --- 22 | drivers/media/platform/vivid/vivid-core.c | 2 ++ 23 | drivers/media/platform/vivid/vivid-ctrls.c | 4 ++++ 24 | drivers/media/platform/vivid/vivid-kthread-cap.c | 2 ++ 25 | 3 files changed, 8 insertions(+) 26 | 27 | diff --git a/drivers/media/platform/vivid/vivid-core.c b/drivers/media/platform/vivid/vivid-core.c 28 | index 5464fefbaab9..bbae1f11d40b 100644 29 | --- a/drivers/media/platform/vivid/vivid-core.c 30 | +++ b/drivers/media/platform/vivid/vivid-core.c 31 | @@ -666,6 +666,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst) 32 | return ret; 33 | } 34 | dev->v4l2_dev.release = vivid_dev_release; 35 | + dev->v4l2_dev.req_queue = v4l2_device_req_queue; 36 | 37 | /* start detecting feature set */ 38 | 39 | @@ -1053,6 +1054,7 @@ static int vivid_create_instance(struct platform_device *pdev, int inst) 40 | q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 41 | q->min_buffers_needed = 2; 42 | q->lock = &dev->mutex; 43 | + q->v4l2_allow_requests = 1; 44 | 45 | ret = vb2_queue_init(q); 46 | if (ret) 47 | diff --git a/drivers/media/platform/vivid/vivid-ctrls.c b/drivers/media/platform/vivid/vivid-ctrls.c 48 | index aceb38d9f7e7..3b1949610f5d 100644 49 | --- a/drivers/media/platform/vivid/vivid-ctrls.c 50 | +++ b/drivers/media/platform/vivid/vivid-ctrls.c 51 | @@ -1387,12 +1387,16 @@ int vivid_create_controls(struct vivid_dev *dev, bool show_ccs_cap, 52 | V4L2_CID_BRIGHTNESS, 0, 255, 1, 128); 53 | for (i = 0; i < MAX_INPUTS; i++) 54 | dev->input_brightness[i] = 128; 55 | + v4l2_ctrl_s_max_reqs(dev->brightness, VIDEO_MAX_FRAME); 56 | dev->contrast = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops, 57 | V4L2_CID_CONTRAST, 0, 255, 1, 128); 58 | + v4l2_ctrl_s_max_reqs(dev->contrast, VIDEO_MAX_FRAME); 59 | dev->saturation = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops, 60 | V4L2_CID_SATURATION, 0, 255, 1, 128); 61 | + v4l2_ctrl_s_max_reqs(dev->saturation, VIDEO_MAX_FRAME); 62 | dev->hue = v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops, 63 | V4L2_CID_HUE, -128, 128, 1, 0); 64 | + v4l2_ctrl_s_max_reqs(dev->hue, VIDEO_MAX_FRAME); 65 | v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops, 66 | V4L2_CID_HFLIP, 0, 1, 1, 0); 67 | v4l2_ctrl_new_std(hdl_user_vid, &vivid_user_vid_ctrl_ops, 68 | diff --git a/drivers/media/platform/vivid/vivid-kthread-cap.c b/drivers/media/platform/vivid/vivid-kthread-cap.c 69 | index 6ca71aabb576..326eb37ef047 100644 70 | --- a/drivers/media/platform/vivid/vivid-kthread-cap.c 71 | +++ b/drivers/media/platform/vivid/vivid-kthread-cap.c 72 | @@ -700,6 +700,8 @@ static void vivid_thread_vid_cap_tick(struct vivid_dev *dev, int dropped_bufs) 73 | if (!list_empty(&dev->vid_cap_active)) { 74 | vid_cap_buf = list_entry(dev->vid_cap_active.next, struct vivid_buffer, list); 75 | list_del(&vid_cap_buf->list); 76 | + v4l2_ctrl_apply_request(dev->vid_cap_dev.ctrl_handler, 77 | + vid_cap_buf->vb.request); 78 | } 79 | if (!list_empty(&dev->vbi_cap_active)) { 80 | if (dev->field_cap != V4L2_FIELD_ALTERNATE || 81 | -- 82 | 2.14.3 83 | 84 | -------------------------------------------------------------------------------- /libva/configure.ac: -------------------------------------------------------------------------------- 1 | # intel-driver package version number 2 | m4_define([sunxi_cedrus_major_version], [1]) 3 | m4_define([sunxi_cedrus_minor_version], [0]) 4 | m4_define([sunxi_cedrus_micro_version], [0]) 5 | m4_define([sunxi_cedrus_pre_version], [0]) 6 | m4_define([sunxi_cedrus_version], 7 | [sunxi_cedrus_major_version.sunxi_cedrus_minor_version.sunxi_cedrus_micro_version]) 8 | m4_if(sunxi_cedrus_pre_version, [0], [], [ 9 | m4_append([sunxi_cedrus_version], sunxi_cedrus_pre_version, [.pre]) 10 | ]) 11 | 12 | # libva minimum version requirement 13 | m4_define([libva_package_version], [1.2.2]) 14 | m4_define([va_api_version], [0.34.0]) 15 | 16 | # libdrm minimum version requirement 17 | m4_define([libdrm_version], [2.4.45]) 18 | 19 | AC_PREREQ([2.60]) 20 | AC_INIT([liva_wrapper], [sunxi_cedrus_version], 21 | [florent.revest@free-electrons.com], [sunxi_cedrus]) 22 | AC_CONFIG_SRCDIR([Makefile.am]) 23 | AM_INIT_AUTOMAKE([1.9 tar-ustar]) 24 | 25 | AC_CONFIG_HEADERS([src/config.h]) 26 | 27 | SUNXI_CEDRUS_MAJOR_VERSION=sunxi_cedrus_major_version 28 | SUNXI_CEDRUS_MINOR_VERSION=sunxi_cedrus_minor_version 29 | SUNXI_CEDRUS_MICRO_VERSION=sunxi_cedrus_micro_version 30 | AC_DEFINE([SUNXI_CEDRUS_MAJOR_VERSION], [sunxi_cedrus_major_version], [Major version of the driver]) 31 | AC_DEFINE([SUNXI_CEDRUS_MINOR_VERSION], [sunxi_cedrus_minor_version], [Minor version of the driver]) 32 | AC_DEFINE([SUNXI_CEDRUS_MICRO_VERSION], [sunxi_cedrus_micro_version], [Micro version of the driver]) 33 | AC_DEFINE([SUNXI_CEDRUS_PRE_VERSION], [sunxi_cedrus_pre_version], [Preversion of the driver]) 34 | 35 | SUNXI_CEDRUS_LT_LDFLAGS="-avoid-version" 36 | AC_SUBST(SUNXI_CEDRUS_LT_LDFLAGS) 37 | 38 | dnl Use pretty build output with automake >= 1.11 39 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])], [ 40 | AM_DEFAULT_VERBOSITY=1 41 | AC_SUBST(AM_DEFAULT_VERBOSITY) 42 | ]) 43 | 44 | AC_DISABLE_STATIC 45 | AC_PROG_LIBTOOL 46 | AC_PROG_CC 47 | AM_PROG_CC_C_O 48 | AM_PROG_AS 49 | 50 | AC_C_BIGENDIAN 51 | AC_HEADER_STDC 52 | AC_SYS_LARGEFILE 53 | AC_CHECK_LIB([m], [sin]) 54 | 55 | LIBVA_PACKAGE_VERSION=libva_package_version 56 | AC_SUBST(LIBVA_PACKAGE_VERSION) 57 | 58 | dnl Check for recent enough DRM 59 | LIBDRM_VERSION=libdrm_version 60 | PKG_CHECK_MODULES([DRM], [libdrm >= $LIBDRM_VERSION]) 61 | AC_SUBST(LIBDRM_VERSION) 62 | 63 | dnl Check for VA-API 64 | PKG_CHECK_MODULES(LIBVA_DEPS, [libva >= va_api_version]) 65 | PKG_CHECK_MODULES(X11_DEPS, [x11]) 66 | 67 | dnl Check for VA/DRM API 68 | PKG_CHECK_MODULES(LIBVA_DRM_DEPS, [libva-drm], 69 | [AC_DEFINE([HAVE_VA_DRM], [1], [Defined to 1 if VA/DRM API is enabled])], 70 | [USE_DRM="no"]) 71 | 72 | # Check for 73 | if test "$USE_DRM" = "yes"; then 74 | saved_CPPFLAGS="$CPPFLAGS" 75 | CPPFLAGS="$CPPFLAGS $DRM_CFLAGS" 76 | AC_CHECK_HEADERS([drm_fourcc.h], [:], [USE_DRM="no"]) 77 | CPPFLAGS="$saved_CPPFLAGS" 78 | fi 79 | 80 | VA_VERSION=`$PKG_CONFIG --modversion libva` 81 | VA_MAJOR_VERSION=`echo "$VA_VERSION" | cut -d'.' -f1` 82 | VA_MINOR_VERSION=`echo "$VA_VERSION" | cut -d'.' -f2` 83 | VA_MICRO_VERSION=`echo "$VA_VERSION" | cut -d'.' -f3` 84 | VA_VERSION_STR="$VA_VERSION" 85 | 86 | va_full_version_int=`expr ${VA_MAJOR_VERSION:-0} "*" 1000000 + \ 87 | ${VA_MINOR_VERSION:-0} "*" 10000 + \ 88 | ${VA_MICRO_VERSION:-0} "*" 100 + \ 89 | 0` 90 | VA_DRIVER_INIT_FUNC="__vaDriverInit_${VA_MAJOR_VERSION}_${VA_MINOR_VERSION}" 91 | AC_DEFINE_UNQUOTED([VA_DRIVER_INIT_FUNC], [$VA_DRIVER_INIT_FUNC], 92 | [Define driver entry-point]) 93 | 94 | dnl Check for VA-API drivers path 95 | AC_MSG_CHECKING([for VA drivers path]) 96 | LIBVA_DRIVERS_PATH=`$PKG_CONFIG libva --variable driverdir` 97 | if test -z "$LIBVA_DRIVERS_PATH"; then 98 | LIBVA_DRIVERS_PATH="/usr/lib/dri/" 99 | fi 100 | AC_MSG_RESULT([$LIBVA_DRIVERS_PATH]) 101 | AC_SUBST(LIBVA_DRIVERS_PATH) 102 | 103 | AC_OUTPUT([ 104 | Makefile 105 | src/Makefile 106 | ]) 107 | 108 | echo 109 | echo $PACKAGE configuration summary: 110 | echo 111 | echo VA-API version ................... : $VA_VERSION_STR 112 | echo VA-API drivers path .............. : $LIBVA_DRIVERS_PATH 113 | echo 114 | -------------------------------------------------------------------------------- /patches/4.9/0011-v4l2-device-keep-track-of-registered-video_devices.patch: -------------------------------------------------------------------------------- 1 | From 680df2229c533a318d6ecb721af6eccee0dfc9e2 Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Tue, 21 Apr 2015 09:58:34 +0200 4 | Subject: [PATCH] v4l2-device: keep track of registered video_devices 5 | 6 | In order to efficiently handle V4L2_REQ_CMD_QUEUE we need to know which 7 | video_device structs are registered for the given v4l2_device struct. 8 | 9 | So create a list of vdevs in v4l2_device and add/remove each video_device 10 | there as it is registered/unregistered. 11 | 12 | Signed-off-by: Hans Verkuil 13 | --- 14 | drivers/media/v4l2-core/v4l2-dev.c | 8 ++++++++ 15 | drivers/media/v4l2-core/v4l2-device.c | 1 + 16 | include/media/v4l2-dev.h | 3 +++ 17 | include/media/v4l2-device.h | 2 ++ 18 | 4 files changed, 14 insertions(+) 19 | 20 | diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c 21 | index eb774864caca..8f3cf80bc3e3 100644 22 | --- a/drivers/media/v4l2-core/v4l2-dev.c 23 | +++ b/drivers/media/v4l2-core/v4l2-dev.c 24 | @@ -838,6 +838,8 @@ int __video_register_device(struct video_device *vdev, int type, int nr, 25 | if (WARN_ON(!vdev->v4l2_dev)) 26 | return -EINVAL; 27 | 28 | + INIT_LIST_HEAD(&vdev->list); 29 | + 30 | /* v4l2_fh support */ 31 | spin_lock_init(&vdev->fh_lock); 32 | INIT_LIST_HEAD(&vdev->fh_list); 33 | @@ -987,6 +989,9 @@ int __video_register_device(struct video_device *vdev, int type, int nr, 34 | 35 | /* Part 6: Activate this minor. The char device can now be used. */ 36 | set_bit(V4L2_FL_REGISTERED, &vdev->flags); 37 | + spin_lock(&vdev->v4l2_dev->lock); 38 | + list_add_tail(&vdev->list, &vdev->v4l2_dev->vdevs); 39 | + spin_unlock(&vdev->v4l2_dev->lock); 40 | 41 | return 0; 42 | 43 | @@ -1022,6 +1027,9 @@ void video_unregister_device(struct video_device *vdev) 44 | */ 45 | clear_bit(V4L2_FL_REGISTERED, &vdev->flags); 46 | mutex_unlock(&videodev_lock); 47 | + spin_lock(&vdev->v4l2_dev->lock); 48 | + list_del(&vdev->list); 49 | + spin_unlock(&vdev->v4l2_dev->lock); 50 | device_unregister(&vdev->dev); 51 | } 52 | EXPORT_SYMBOL(video_unregister_device); 53 | diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c 54 | index 62bbed76dbbc..b3b342afd635 100644 55 | --- a/drivers/media/v4l2-core/v4l2-device.c 56 | +++ b/drivers/media/v4l2-core/v4l2-device.c 57 | @@ -36,6 +36,7 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) 58 | return -EINVAL; 59 | 60 | INIT_LIST_HEAD(&v4l2_dev->subdevs); 61 | + INIT_LIST_HEAD(&v4l2_dev->vdevs); 62 | spin_lock_init(&v4l2_dev->lock); 63 | v4l2_prio_init(&v4l2_dev->prio); 64 | kref_init(&v4l2_dev->ref); 65 | diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h 66 | index e657614521e3..29d0c5ede518 100644 67 | --- a/include/media/v4l2-dev.h 68 | +++ b/include/media/v4l2-dev.h 69 | @@ -212,6 +212,9 @@ struct v4l2_file_operations { 70 | 71 | struct video_device 72 | { 73 | + /* links into v4l2_device vdevs list */ 74 | + struct list_head list; 75 | + 76 | #if defined(CONFIG_MEDIA_CONTROLLER) 77 | struct media_entity entity; 78 | struct media_intf_devnode *intf_devnode; 79 | diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h 80 | index f11f079b2fa4..64176f773fa7 100644 81 | --- a/include/media/v4l2-device.h 82 | +++ b/include/media/v4l2-device.h 83 | @@ -35,6 +35,7 @@ struct v4l2_ctrl_handler; 84 | * @dev: pointer to struct device. 85 | * @mdev: pointer to struct media_device 86 | * @subdevs: used to keep track of the registered subdevs 87 | + * @vdevs: used to keep track of the registered video_devices 88 | * @lock: lock this struct; can be used by the driver as well 89 | * if this struct is embedded into a larger struct. 90 | * @name: unique device name, by default the driver name + bus ID 91 | @@ -63,6 +64,7 @@ struct v4l2_device { 92 | struct media_device *mdev; 93 | #endif 94 | struct list_head subdevs; 95 | + struct list_head vdevs; 96 | spinlock_t lock; 97 | char name[V4L2_DEVICE_NAME_SIZE]; 98 | void (*notify)(struct v4l2_subdev *sd, 99 | -- 100 | 2.14.3 101 | 102 | -------------------------------------------------------------------------------- /libva/src/tiled_yuv.S: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Jens Kuske 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | * 18 | */ 19 | 20 | /* 21 | * The Sunxi Video Engine outputs buffers in a specific format similar to NV12 22 | * but with "tiles" of size 32x32. This code converts the data from this tiled 23 | * format to two NV12 planes. 24 | */ 25 | 26 | #if defined(__linux__) && defined(__ELF__) 27 | .section .note.GNU-stack,"",%progbits /* mark stack as non-executable */ 28 | #endif 29 | 30 | #ifndef __aarch64__ 31 | 32 | .text 33 | .syntax unified 34 | .arch armv7-a 35 | .fpu neon 36 | .thumb 37 | 38 | .macro thumb_function fname 39 | .global \fname 40 | #ifdef __ELF__ 41 | .hidden \fname 42 | .type \fname, %function 43 | #endif 44 | .thumb_func 45 | \fname: 46 | .endm 47 | 48 | .macro end_function fname 49 | #ifdef __ELF__ 50 | .size \fname, .-\fname 51 | #endif 52 | .endm 53 | 54 | SRC .req r0 55 | DST .req r1 56 | PITCH .req r2 57 | CNT .req r3 58 | TLINE .req r4 59 | HEIGHT .req r5 60 | REST .req r6 61 | NTILES .req r7 62 | TMPSRC .req r8 63 | DST2 .req r9 64 | TSIZE .req r12 65 | NEXTLIN .req lr 66 | 67 | thumb_function tiled_to_planar 68 | push {r4, r5, r6, r7, r8, lr} 69 | ldr HEIGHT, [sp, #24] 70 | add NEXTLIN, r3, #31 71 | lsrs NTILES, r3, #5 72 | bic NEXTLIN, NEXTLIN, #31 73 | and REST, r3, #31 74 | lsl NEXTLIN, NEXTLIN, #5 75 | subs PITCH, r2, r3 76 | movs TLINE, #32 77 | rsb NEXTLIN, NEXTLIN, #32 78 | mov TSIZE, #1024 79 | 80 | /* y loop */ 81 | 1: cbz NTILES, 3f 82 | mov CNT, NTILES 83 | 84 | /* x loop complete tiles */ 85 | 2: pld [SRC, TSIZE] 86 | vld1.8 {d0 - d3}, [SRC :256], TSIZE 87 | subs CNT, #1 88 | vst1.8 {d0 - d3}, [DST]! 89 | bne 2b 90 | 91 | 3: cbnz REST, 4f 92 | 93 | /* fix up dest pointer if pitch != width */ 94 | 7: add DST, PITCH 95 | 96 | /* fix up src pointer at end of line */ 97 | subs TLINE, #1 98 | itee ne 99 | addne SRC, NEXTLIN 100 | subeq SRC, #992 101 | moveq TLINE, #32 102 | 103 | subs HEIGHT, #1 104 | bne 1b 105 | pop {r4, r5, r6, r7, r8, pc} 106 | 107 | /* partly copy last tile of line */ 108 | 4: mov TMPSRC, SRC 109 | tst REST, #16 110 | beq 5f 111 | vld1.8 {d0 - d1}, [TMPSRC :128]! 112 | vst1.8 {d0 - d1}, [DST]! 113 | 5: add SRC, TSIZE 114 | ands CNT, REST, #15 115 | beq 7b 116 | 6: vld1.8 {d0[0]}, [TMPSRC]! 117 | subs CNT, #1 118 | vst1.8 {d0[0]}, [DST]! 119 | bne 6b 120 | b 7b 121 | end_function tiled_to_planar 122 | 123 | thumb_function tiled_deinterleave_to_planar 124 | push {r4, r5, r6, r7, r8, r9, lr} 125 | mov DST2, r2 126 | ldr HEIGHT, [sp, #32] 127 | ldr r4, [sp, #28] 128 | add NEXTLIN, r4, #31 129 | lsrs NTILES, r4, #5 130 | bic NEXTLIN, NEXTLIN, #31 131 | ubfx REST, r4, #1, #4 132 | lsl NEXTLIN, NEXTLIN, #5 133 | sub PITCH, r3, r4, lsr #1 134 | movs TLINE, #32 135 | rsb NEXTLIN, NEXTLIN, #32 136 | mov TSIZE, #1024 137 | 138 | /* y loop */ 139 | 1: cbz NTILES, 3f 140 | mov CNT, NTILES 141 | 142 | /* x loop complete tiles */ 143 | 2: pld [SRC, TSIZE] 144 | vld2.8 {d0 - d3}, [SRC :256], TSIZE 145 | subs CNT, #1 146 | vst1.8 {d0 - d1}, [DST]! 147 | vst1.8 {d2 - d3}, [DST2]! 148 | bne 2b 149 | 150 | 3: cbnz REST, 4f 151 | 152 | /* fix up dest pointer if pitch != width */ 153 | 7: add DST, PITCH 154 | add DST2, PITCH 155 | 156 | /* fix up src pointer at end of line */ 157 | subs TLINE, #1 158 | itee ne 159 | addne SRC, NEXTLIN 160 | subeq SRC, #992 161 | moveq TLINE, #32 162 | 163 | subs HEIGHT, #1 164 | bne 1b 165 | pop {r4, r5, r6, r7, r8, r9, pc} 166 | 167 | /* partly copy last tile of line */ 168 | 4: mov TMPSRC, SRC 169 | tst REST, #8 170 | beq 5f 171 | vld2.8 {d0 - d1}, [TMPSRC :128]! 172 | vst1.8 {d0}, [DST]! 173 | vst1.8 {d1}, [DST2]! 174 | 5: add SRC, TSIZE 175 | ands CNT, REST, #7 176 | beq 7b 177 | 6: vld2.8 {d0[0], d1[0]}, [TMPSRC]! 178 | subs CNT, #1 179 | vst1.8 {d0[0]}, [DST]! 180 | vst1.8 {d1[0]}, [DST2]! 181 | bne 6b 182 | b 7b 183 | end_function tiled_deinterleave_to_planar 184 | 185 | #endif 186 | -------------------------------------------------------------------------------- /libva/src/image.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "sunxi_cedrus_drv_video.h" 27 | #include "image.h" 28 | #include "surface.h" 29 | #include "buffer.h" 30 | 31 | #include 32 | 33 | #include "tiled_yuv.h" 34 | 35 | /* 36 | * An Image is a standard data structure containing rendered frames in a usable 37 | * pixel format. Here we only use NV12 buffers which are converted from sunxi's 38 | * proprietary tiled pixel format with tiled_yuv when deriving an Image from a 39 | * Surface. 40 | */ 41 | 42 | VAStatus sunxi_cedrus_QueryImageFormats(VADriverContextP ctx, 43 | VAImageFormat *format_list, int *num_formats) 44 | { 45 | format_list[0].fourcc = VA_FOURCC_NV12; 46 | *num_formats = 1; 47 | return VA_STATUS_SUCCESS; 48 | } 49 | 50 | VAStatus sunxi_cedrus_CreateImage(VADriverContextP ctx, VAImageFormat *format, 51 | int width, int height, VAImage *image) 52 | { 53 | INIT_DRIVER_DATA 54 | int sizeY, sizeUV; 55 | object_image_p obj_img; 56 | 57 | image->format = *format; 58 | image->buf = VA_INVALID_ID; 59 | image->width = width; 60 | image->height = height; 61 | 62 | sizeY = image->width * image->height; 63 | sizeUV = ((image->width+1) * (image->height+1)/2); 64 | 65 | image->num_planes = 2; 66 | image->pitches[0] = (image->width+31)&~31; 67 | image->pitches[1] = (image->width+31)&~31; 68 | image->offsets[0] = 0; 69 | image->offsets[1] = sizeY; 70 | image->data_size = sizeY + sizeUV; 71 | 72 | image->image_id = object_heap_allocate(&driver_data->image_heap); 73 | if (image->image_id == VA_INVALID_ID) 74 | return VA_STATUS_ERROR_ALLOCATION_FAILED; 75 | obj_img = IMAGE(image->image_id); 76 | 77 | if (sunxi_cedrus_CreateBuffer(ctx, 0, VAImageBufferType, image->data_size, 78 | 1, NULL, &image->buf) != VA_STATUS_SUCCESS) 79 | return VA_STATUS_ERROR_ALLOCATION_FAILED; 80 | obj_img->buf = image->buf; 81 | 82 | return VA_STATUS_SUCCESS; 83 | } 84 | 85 | VAStatus sunxi_cedrus_DeriveImage(VADriverContextP ctx, VASurfaceID surface, 86 | VAImage *image) 87 | { 88 | INIT_DRIVER_DATA 89 | object_surface_p obj_surface; 90 | VAImageFormat fmt; 91 | object_buffer_p obj_buffer; 92 | VAStatus ret; 93 | 94 | obj_surface = SURFACE(surface); 95 | fmt.fourcc = VA_FOURCC_NV12; 96 | 97 | ret = sunxi_cedrus_CreateImage(ctx, &fmt, obj_surface->width, 98 | obj_surface->height, image); 99 | if(ret != VA_STATUS_SUCCESS) 100 | return ret; 101 | 102 | obj_buffer = BUFFER(image->buf); 103 | if (NULL == obj_buffer) 104 | return VA_STATUS_ERROR_ALLOCATION_FAILED; 105 | 106 | /* TODO: Use an appropriate DRM plane instead */ 107 | tiled_to_planar(driver_data->luma_bufs[obj_surface->output_buf_index], obj_buffer->buffer_data, image->pitches[0], image->width, image->height); 108 | tiled_to_planar(driver_data->chroma_bufs[obj_surface->output_buf_index], obj_buffer->buffer_data + image->width*image->height, image->pitches[1], image->width, image->height/2); 109 | 110 | return VA_STATUS_SUCCESS; 111 | } 112 | 113 | VAStatus sunxi_cedrus_DestroyImage(VADriverContextP ctx, VAImageID image) 114 | { 115 | INIT_DRIVER_DATA 116 | object_image_p obj_img; 117 | 118 | obj_img = IMAGE(image); 119 | assert(obj_img); 120 | 121 | sunxi_cedrus_DestroyBuffer(ctx, obj_img->buf); 122 | return VA_STATUS_SUCCESS; 123 | } 124 | 125 | VAStatus sunxi_cedrus_SetImagePalette(VADriverContextP ctx, VAImageID image, 126 | unsigned char *palette) 127 | { return VA_STATUS_SUCCESS; } 128 | 129 | VAStatus sunxi_cedrus_GetImage(VADriverContextP ctx, VASurfaceID surface, 130 | int x, int y, unsigned int width, unsigned int height, 131 | VAImageID image) 132 | { return VA_STATUS_SUCCESS; } 133 | 134 | VAStatus sunxi_cedrus_PutImage(VADriverContextP ctx, VASurfaceID surface, 135 | VAImageID image, int src_x, int src_y, unsigned int src_width, 136 | unsigned int src_height, int dest_x, int dest_y, 137 | unsigned int dest_width, unsigned int dest_height) 138 | { return VA_STATUS_SUCCESS; } 139 | -------------------------------------------------------------------------------- /driver/sunxi_cedrus_hw.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Sunxi Cedrus codec driver 3 | * 4 | * Copyright (C) 2016 Florent Revest 5 | * Florent Revest 6 | * 7 | * Based on vim2m 8 | * 9 | * Copyright (c) 2009-2010 Samsung Electronics Co., Ltd. 10 | * Pawel Osciak, 11 | * Marek Szyprowski, 12 | * 13 | * And reverse engineering efforts of the 'Cedrus' project 14 | * Copyright (c) 2013-2014 Jens Kuske 15 | * 16 | * This software is licensed under the terms of the GNU General Public 17 | * License version 2, as published by the Free Software Foundation, and 18 | * may be copied, distributed, and modified under those terms. 19 | * 20 | * This program is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | * GNU General Public License for more details. 24 | */ 25 | 26 | #include "sunxi_cedrus_common.h" 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | /* 39 | * Interrupt handlers. 40 | */ 41 | 42 | static irqreturn_t sunxi_cedrus_ve_irq(int irq, void *dev_id) 43 | { 44 | struct sunxi_cedrus_dev *vpu = dev_id; 45 | struct sunxi_cedrus_ctx *curr_ctx; 46 | struct vb2_v4l2_buffer *src_vb, *dst_vb; 47 | int val; 48 | unsigned long flags; 49 | 50 | /* Disable MPEG interrupts and stop the MPEG engine */ 51 | val = sunxi_cedrus_read(vpu, VE_MPEG_CTRL); 52 | sunxi_cedrus_write(vpu, val & (~0xf), VE_MPEG_CTRL); 53 | val = sunxi_cedrus_read(vpu, VE_MPEG_STATUS); 54 | sunxi_cedrus_write(vpu, 0x0000c00f, VE_MPEG_STATUS); 55 | sunxi_cedrus_write(vpu, VE_CTRL_REINIT, VE_CTRL); 56 | 57 | curr_ctx = v4l2_m2m_get_curr_priv(vpu->m2m_dev); 58 | 59 | if (!curr_ctx) { 60 | pr_err("Instance released before the end of transaction\n"); 61 | return IRQ_HANDLED; 62 | } 63 | 64 | src_vb = v4l2_m2m_src_buf_remove(curr_ctx->fh.m2m_ctx); 65 | dst_vb = v4l2_m2m_dst_buf_remove(curr_ctx->fh.m2m_ctx); 66 | 67 | /* First bit of MPEG_STATUS means success */ 68 | spin_lock_irqsave(&vpu->irqlock, flags); 69 | if (val & 0x1) { 70 | v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_DONE); 71 | v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_DONE); 72 | } else { 73 | v4l2_m2m_buf_done(src_vb, VB2_BUF_STATE_ERROR); 74 | v4l2_m2m_buf_done(dst_vb, VB2_BUF_STATE_ERROR); 75 | } 76 | spin_unlock_irqrestore(&vpu->irqlock, flags); 77 | 78 | v4l2_m2m_job_finish(vpu->m2m_dev, curr_ctx->fh.m2m_ctx); 79 | 80 | return IRQ_HANDLED; 81 | } 82 | 83 | /* 84 | * Initialization/clean-up. 85 | */ 86 | 87 | int sunxi_cedrus_hw_probe(struct sunxi_cedrus_dev *vpu) 88 | { 89 | struct resource *res; 90 | int irq_dec; 91 | int ret; 92 | 93 | irq_dec = platform_get_irq(vpu->pdev, 0); 94 | if (irq_dec <= 0) { 95 | dev_err(vpu->dev, "could not get ve IRQ\n"); 96 | return -ENXIO; 97 | } 98 | ret = devm_request_irq(vpu->dev, irq_dec, sunxi_cedrus_ve_irq, 0, 99 | dev_name(vpu->dev), vpu); 100 | if (ret) { 101 | dev_err(vpu->dev, "could not request ve IRQ\n"); 102 | return -ENXIO; 103 | } 104 | 105 | ret = of_reserved_mem_device_init(vpu->dev); 106 | if (ret) { 107 | dev_err(vpu->dev, "could not reserve memory\n"); 108 | return -ENODEV; 109 | } 110 | 111 | vpu->ahb_clk = devm_clk_get(vpu->dev, "ahb"); 112 | if (IS_ERR(vpu->ahb_clk)) { 113 | dev_err(vpu->dev, "failed to get ahb clock\n"); 114 | return PTR_ERR(vpu->ahb_clk); 115 | } 116 | vpu->mod_clk = devm_clk_get(vpu->dev, "mod"); 117 | if (IS_ERR(vpu->mod_clk)) { 118 | dev_err(vpu->dev, "failed to get mod clock\n"); 119 | return PTR_ERR(vpu->mod_clk); 120 | } 121 | vpu->ram_clk = devm_clk_get(vpu->dev, "ram"); 122 | if (IS_ERR(vpu->ram_clk)) { 123 | dev_err(vpu->dev, "failed to get ram clock\n"); 124 | return PTR_ERR(vpu->ram_clk); 125 | } 126 | 127 | vpu->rstc = devm_reset_control_get(vpu->dev, NULL); 128 | 129 | res = platform_get_resource(vpu->pdev, IORESOURCE_MEM, 0); 130 | vpu->base = devm_ioremap_resource(vpu->dev, res); 131 | if (!vpu->base) 132 | dev_err(vpu->dev, "could not maps MACC registers\n"); 133 | 134 | ret = clk_prepare_enable(vpu->ahb_clk); 135 | if (ret) { 136 | dev_err(vpu->dev, "could not enable ahb clock\n"); 137 | return -EFAULT; 138 | } 139 | ret = clk_prepare_enable(vpu->mod_clk); 140 | if (ret) { 141 | clk_disable_unprepare(vpu->ahb_clk); 142 | dev_err(vpu->dev, "could not enable mod clock\n"); 143 | return -EFAULT; 144 | } 145 | ret = clk_prepare_enable(vpu->ram_clk); 146 | if (ret) { 147 | clk_disable_unprepare(vpu->mod_clk); 148 | clk_disable_unprepare(vpu->ahb_clk); 149 | dev_err(vpu->dev, "could not enable ram clock\n"); 150 | return -EFAULT; 151 | } 152 | 153 | reset_control_assert(vpu->rstc); 154 | reset_control_deassert(vpu->rstc); 155 | 156 | return 0; 157 | } 158 | 159 | void sunxi_cedrus_hw_remove(struct sunxi_cedrus_dev *vpu) 160 | { 161 | clk_disable_unprepare(vpu->ram_clk); 162 | clk_disable_unprepare(vpu->mod_clk); 163 | clk_disable_unprepare(vpu->ahb_clk); 164 | 165 | of_reserved_mem_device_release(vpu->dev); 166 | } 167 | -------------------------------------------------------------------------------- /libva/src/mpeg2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "sunxi_cedrus_drv_video.h" 27 | #include "mpeg2.h" 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | /* 38 | * This file takes care of filling v4l2's frame API MPEG2 headers extended 39 | * controls from VA's data structures. 40 | */ 41 | 42 | VAStatus sunxi_cedrus_render_mpeg2_slice_data(VADriverContextP ctx, 43 | object_context_p obj_context, object_surface_p obj_surface, 44 | object_buffer_p obj_buffer) 45 | { 46 | INIT_DRIVER_DATA 47 | VAStatus vaStatus = VA_STATUS_SUCCESS; 48 | struct v4l2_buffer buf; 49 | struct v4l2_plane plane[1]; 50 | 51 | memset(plane, 0, sizeof(struct v4l2_plane)); 52 | 53 | /* Query */ 54 | memset(&(buf), 0, sizeof(buf)); 55 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 56 | buf.memory = V4L2_MEMORY_MMAP; 57 | buf.index = obj_surface->input_buf_index; 58 | buf.length = 1; 59 | buf.m.planes = plane; 60 | 61 | assert(ioctl(driver_data->mem2mem_fd, VIDIOC_QUERYBUF, &buf)==0); 62 | 63 | /* Populate frame */ 64 | char *src_buf = mmap(NULL, obj_buffer->size, 65 | PROT_READ | PROT_WRITE, MAP_SHARED, 66 | driver_data->mem2mem_fd, buf.m.planes[0].m.mem_offset); 67 | assert(src_buf != MAP_FAILED); 68 | memcpy(src_buf, obj_buffer->buffer_data, obj_buffer->size); 69 | 70 | obj_context->mpeg2_frame_hdr.slice_pos = 0; 71 | obj_context->mpeg2_frame_hdr.slice_len = obj_buffer->size*8; 72 | 73 | return vaStatus; 74 | } 75 | 76 | VAStatus sunxi_cedrus_render_mpeg2_picture_parameter(VADriverContextP ctx, 77 | object_context_p obj_context, object_surface_p obj_surface, 78 | object_buffer_p obj_buffer) 79 | { 80 | INIT_DRIVER_DATA 81 | VAStatus vaStatus = VA_STATUS_SUCCESS; 82 | 83 | VAPictureParameterBufferMPEG2 *pic_param = (VAPictureParameterBufferMPEG2 *)obj_buffer->buffer_data; 84 | obj_context->mpeg2_frame_hdr.type = MPEG2; 85 | 86 | obj_context->mpeg2_frame_hdr.width = pic_param->horizontal_size; 87 | obj_context->mpeg2_frame_hdr.height = pic_param->vertical_size; 88 | 89 | obj_context->mpeg2_frame_hdr.picture_coding_type = pic_param->picture_coding_type; 90 | obj_context->mpeg2_frame_hdr.f_code[0][0] = (pic_param->f_code >> 12) & 0xf; 91 | obj_context->mpeg2_frame_hdr.f_code[0][1] = (pic_param->f_code >> 8) & 0xf; 92 | obj_context->mpeg2_frame_hdr.f_code[1][0] = (pic_param->f_code >> 4) & 0xf; 93 | obj_context->mpeg2_frame_hdr.f_code[1][1] = pic_param->f_code & 0xf; 94 | 95 | obj_context->mpeg2_frame_hdr.intra_dc_precision = pic_param->picture_coding_extension.bits.intra_dc_precision; 96 | obj_context->mpeg2_frame_hdr.picture_structure = pic_param->picture_coding_extension.bits.picture_structure; 97 | obj_context->mpeg2_frame_hdr.top_field_first = pic_param->picture_coding_extension.bits.top_field_first; 98 | obj_context->mpeg2_frame_hdr.frame_pred_frame_dct = pic_param->picture_coding_extension.bits.frame_pred_frame_dct; 99 | obj_context->mpeg2_frame_hdr.concealment_motion_vectors = pic_param->picture_coding_extension.bits.concealment_motion_vectors; 100 | obj_context->mpeg2_frame_hdr.q_scale_type = pic_param->picture_coding_extension.bits.q_scale_type; 101 | obj_context->mpeg2_frame_hdr.intra_vlc_format = pic_param->picture_coding_extension.bits.intra_vlc_format; 102 | obj_context->mpeg2_frame_hdr.alternate_scan = pic_param->picture_coding_extension.bits.alternate_scan; 103 | 104 | object_surface_p fwd_surface = SURFACE(pic_param->forward_reference_picture); 105 | if(fwd_surface) 106 | obj_context->mpeg2_frame_hdr.forward_index = fwd_surface->output_buf_index; 107 | else 108 | obj_context->mpeg2_frame_hdr.forward_index = obj_surface->output_buf_index; 109 | object_surface_p bwd_surface = SURFACE(pic_param->backward_reference_picture); 110 | if(bwd_surface) 111 | obj_context->mpeg2_frame_hdr.backward_index = bwd_surface->output_buf_index; 112 | else 113 | obj_context->mpeg2_frame_hdr.backward_index = obj_surface->output_buf_index; 114 | 115 | return vaStatus; 116 | } 117 | 118 | 119 | -------------------------------------------------------------------------------- /driver/sunxi_cedrus_mpeg4.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Sunxi Cedrus codec driver 3 | * 4 | * Copyright (C) 2016 Florent Revest 5 | * Florent Revest 6 | * 7 | * Based on reverse engineering efforts of the 'Cedrus' project 8 | * Copyright (c) 2013-2014 Jens Kuske 9 | * 10 | * This software is licensed under the terms of the GNU General Public 11 | * License version 2, as published by the Free Software Foundation, and 12 | * may be copied, distributed, and modified under those terms. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | */ 19 | 20 | #include "sunxi_cedrus_common.h" 21 | 22 | #include 23 | 24 | #define VOP_I 0 25 | #define VOP_P 1 26 | #define VOP_B 2 27 | #define VOP_S 3 28 | 29 | void process_mpeg4(struct sunxi_cedrus_ctx *ctx, dma_addr_t in_buf, 30 | dma_addr_t out_luma, dma_addr_t out_chroma, 31 | struct v4l2_ctrl_mpeg4_frame_hdr *frame_hdr) 32 | { 33 | struct sunxi_cedrus_dev *dev = ctx->dev; 34 | 35 | u16 width = DIV_ROUND_UP(frame_hdr->width, 16); 36 | u16 height = DIV_ROUND_UP(frame_hdr->height, 16); 37 | 38 | u32 vop_header = 0; 39 | u32 vld_len = frame_hdr->slice_len - frame_hdr->slice_pos; 40 | 41 | struct vb2_buffer *fwd_vb2_buf, *bwd_vb2_buf; 42 | dma_addr_t fwd_luma = 0, fwd_chroma = 0, bwd_luma = 0, bwd_chroma = 0; 43 | 44 | /* 45 | * The VPU is only able to handle bus addresses so we have to subtract 46 | * the RAM offset to the physcal addresses 47 | */ 48 | fwd_vb2_buf = ctx->dst_bufs[frame_hdr->forward_index]; 49 | if (fwd_vb2_buf) { 50 | fwd_luma = vb2_dma_contig_plane_dma_addr(fwd_vb2_buf, 0); 51 | fwd_chroma = vb2_dma_contig_plane_dma_addr(fwd_vb2_buf, 1); 52 | fwd_luma -= PHYS_OFFSET; 53 | fwd_chroma -= PHYS_OFFSET; 54 | } 55 | 56 | bwd_vb2_buf = ctx->dst_bufs[frame_hdr->backward_index]; 57 | if (bwd_vb2_buf) { 58 | bwd_luma = vb2_dma_contig_plane_dma_addr(bwd_vb2_buf, 0); 59 | bwd_chroma = vb2_dma_contig_plane_dma_addr(bwd_vb2_buf, 1); 60 | bwd_chroma -= PHYS_OFFSET; 61 | bwd_luma -= PHYS_OFFSET; 62 | } 63 | 64 | /* Activates MPEG engine */ 65 | sunxi_cedrus_write(dev, VE_CTRL_MPEG, VE_CTRL); 66 | 67 | /* Quantization parameter */ 68 | sunxi_cedrus_write(dev, frame_hdr->quant_scale, VE_MPEG_QP_INPUT); 69 | 70 | /* Intermediate buffers needed by the VPU */ 71 | sunxi_cedrus_write(dev, dev->mbh_buf - PHYS_OFFSET, VE_MPEG_MBH_ADDR); 72 | sunxi_cedrus_write(dev, dev->dcac_buf - PHYS_OFFSET, VE_MPEG_DCAC_ADDR); 73 | sunxi_cedrus_write(dev, dev->ncf_buf - PHYS_OFFSET, VE_MPEG_NCF_ADDR); 74 | 75 | /* Image's dimensions */ 76 | sunxi_cedrus_write(dev, width << 8 | height, VE_MPEG_SIZE); 77 | sunxi_cedrus_write(dev, width << 20 | height << 4, VE_MPEG_FRAME_SIZE); 78 | 79 | /* MPEG VOP's header */ 80 | vop_header |= (frame_hdr->vop_fields.vop_coding_type == VOP_B) << 28; 81 | vop_header |= frame_hdr->vol_fields.quant_type << 24; 82 | vop_header |= frame_hdr->vol_fields.quarter_sample << 23; 83 | vop_header |= frame_hdr->vol_fields.resync_marker_disable << 22; 84 | vop_header |= frame_hdr->vop_fields.vop_coding_type << 18; 85 | vop_header |= frame_hdr->vop_fields.vop_rounding_type << 17; 86 | vop_header |= frame_hdr->vop_fields.intra_dc_vlc_thr << 8; 87 | vop_header |= frame_hdr->vop_fields.top_field_first << 7; 88 | vop_header |= frame_hdr->vop_fields.alternate_vertical_scan_flag << 6; 89 | if (frame_hdr->vop_fields.vop_coding_type != VOP_I) 90 | vop_header |= frame_hdr->vop_fcode_forward << 3; 91 | if (frame_hdr->vop_fields.vop_coding_type == VOP_B) 92 | vop_header |= frame_hdr->vop_fcode_backward << 0; 93 | sunxi_cedrus_write(dev, vop_header, VE_MPEG_VOP_HDR); 94 | 95 | /* Enable interrupt and an unknown control flag */ 96 | if (frame_hdr->vop_fields.vop_coding_type == VOP_P) 97 | sunxi_cedrus_write(dev, VE_MPEG_CTRL_MPEG4_P, VE_MPEG_CTRL); 98 | else 99 | sunxi_cedrus_write(dev, VE_MPEG_CTRL_MPEG4, VE_MPEG_CTRL); 100 | 101 | /* Temporal distances of B frames */ 102 | if (frame_hdr->vop_fields.vop_coding_type == VOP_B) { 103 | u32 trbtrd = (frame_hdr->trb << 16) | frame_hdr->trd; 104 | 105 | sunxi_cedrus_write(dev, trbtrd, VE_MPEG_TRBTRD_FRAME); 106 | sunxi_cedrus_write(dev, 0, VE_MPEG_TRBTRD_FIELD); 107 | } 108 | 109 | /* Don't rotate or scale buffer */ 110 | sunxi_cedrus_write(dev, VE_NO_SDROT_CTRL, VE_MPEG_SDROT_CTRL); 111 | 112 | /* Macroblock number */ 113 | sunxi_cedrus_write(dev, 0, VE_MPEG_MBA); 114 | 115 | /* Clear previous status */ 116 | sunxi_cedrus_write(dev, 0xffffffff, VE_MPEG_STATUS); 117 | 118 | /* Forward and backward prediction buffers (cached in dst_bufs) */ 119 | sunxi_cedrus_write(dev, fwd_luma, VE_MPEG_FWD_LUMA); 120 | sunxi_cedrus_write(dev, fwd_chroma, VE_MPEG_FWD_CHROMA); 121 | sunxi_cedrus_write(dev, bwd_luma, VE_MPEG_BACK_LUMA); 122 | sunxi_cedrus_write(dev, bwd_chroma, VE_MPEG_BACK_CHROMA); 123 | 124 | /* Output luma and chroma buffers */ 125 | sunxi_cedrus_write(dev, out_luma, VE_MPEG_REC_LUMA); 126 | sunxi_cedrus_write(dev, out_chroma, VE_MPEG_REC_CHROMA); 127 | sunxi_cedrus_write(dev, out_luma, VE_MPEG_ROT_LUMA); 128 | sunxi_cedrus_write(dev, out_chroma, VE_MPEG_ROT_CHROMA); 129 | 130 | /* Input offset and length in bits */ 131 | sunxi_cedrus_write(dev, frame_hdr->slice_pos, VE_MPEG_VLD_OFFSET); 132 | sunxi_cedrus_write(dev, vld_len, VE_MPEG_VLD_LEN); 133 | 134 | /* Input beginning and end addresses */ 135 | sunxi_cedrus_write(dev, VE_MPEG_VLD_ADDR_VAL(in_buf), VE_MPEG_VLD_ADDR); 136 | sunxi_cedrus_write(dev, in_buf + VBV_SIZE - 1, VE_MPEG_VLD_END); 137 | 138 | /* Starts the MPEG engine */ 139 | sunxi_cedrus_write(dev, VE_TRIG_MPEG4(width, height), VE_MPEG_TRIGGER); 140 | } 141 | -------------------------------------------------------------------------------- /patches/4.9/0003-videodev2.h-add-request-field-to-v4l2_buffer.patch: -------------------------------------------------------------------------------- 1 | From c3835ca22e864ff37c5009e945a7f7beeb55ab5b Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Thu, 9 Apr 2015 13:30:35 +0200 4 | Subject: [PATCH] videodev2.h: add request field to v4l2_buffer. 5 | 6 | When queuing buffers allow for passing the request ID that 7 | should be associated with this buffer. Split the u32 reserved2 field 8 | into two u16 fields, one for request, one with the old reserved2 name. 9 | 10 | Signed-off-by: Hans Verkuil 11 | Signed-off-by: Florent Revest 12 | --- 13 | drivers/media/usb/cpia2/cpia2_v4l.c | 1 + 14 | drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 +++- 15 | drivers/media/v4l2-core/v4l2-ioctl.c | 4 ++-- 16 | drivers/media/v4l2-core/videobuf2-v4l2.c | 3 +++ 17 | include/media/videobuf2-v4l2.h | 2 ++ 18 | include/uapi/linux/videodev2.h | 4 +++- 19 | 6 files changed, 14 insertions(+), 4 deletions(-) 20 | 21 | diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c b/drivers/media/usb/cpia2/cpia2_v4l.c 22 | index 9caea8344547..01c596a4a760 100644 23 | --- a/drivers/media/usb/cpia2/cpia2_v4l.c 24 | +++ b/drivers/media/usb/cpia2/cpia2_v4l.c 25 | @@ -952,6 +952,7 @@ static int cpia2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) 26 | buf->sequence = cam->buffers[buf->index].seq; 27 | buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer; 28 | buf->length = cam->frame_size; 29 | + buf->request = 0; 30 | buf->reserved2 = 0; 31 | buf->reserved = 0; 32 | memset(&buf->timecode, 0, sizeof(buf->timecode)); 33 | diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 34 | index bacecbd68a6d..20d9580e6333 100644 35 | --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 36 | +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 37 | @@ -348,7 +348,8 @@ struct v4l2_buffer32 { 38 | __s32 fd; 39 | } m; 40 | __u32 length; 41 | - __u32 reserved2; 42 | + __u16 request; 43 | + __u16 reserved2; 44 | __u32 reserved; 45 | }; 46 | 47 | @@ -509,6 +510,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user 48 | put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) || 49 | copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) || 50 | put_user(kp->sequence, &up->sequence) || 51 | + put_user(kp->request, &up->request) || 52 | put_user(kp->reserved2, &up->reserved2) || 53 | put_user(kp->reserved, &up->reserved) || 54 | put_user(kp->length, &up->length)) 55 | diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c 56 | index f49255ae7193..97028c1e6c25 100644 57 | --- a/drivers/media/v4l2-core/v4l2-ioctl.c 58 | +++ b/drivers/media/v4l2-core/v4l2-ioctl.c 59 | @@ -442,14 +442,14 @@ static void v4l_print_buffer(const void *arg, bool write_only) 60 | const struct v4l2_plane *plane; 61 | int i; 62 | 63 | - pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, " 64 | + pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, request=%u, " 65 | "flags=0x%08x, field=%s, sequence=%d, memory=%s", 66 | p->timestamp.tv_sec / 3600, 67 | (int)(p->timestamp.tv_sec / 60) % 60, 68 | (int)(p->timestamp.tv_sec % 60), 69 | (long)p->timestamp.tv_usec, 70 | p->index, 71 | - prt_names(p->type, v4l2_type_names), 72 | + prt_names(p->type, v4l2_type_names), p->request, 73 | p->flags, prt_names(p->field, v4l2_field_names), 74 | p->sequence, prt_names(p->memory, v4l2_memory_names)); 75 | 76 | diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c 77 | index 52ef8833f6b6..2c3051cfbafd 100644 78 | --- a/drivers/media/v4l2-core/videobuf2-v4l2.c 79 | +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c 80 | @@ -204,6 +204,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb) 81 | b->timestamp = ns_to_timeval(vb->timestamp); 82 | b->timecode = vbuf->timecode; 83 | b->sequence = vbuf->sequence; 84 | + b->request = vbuf->request; 85 | b->reserved2 = 0; 86 | b->reserved = 0; 87 | 88 | @@ -438,6 +439,8 @@ static int __fill_vb2_buffer(struct vb2_buffer *vb, 89 | vbuf->flags &= ~V4L2_BUFFER_OUT_FLAGS; 90 | } 91 | 92 | + vbuf->request = b->request; 93 | + 94 | return 0; 95 | } 96 | 97 | diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h 98 | index 036127c54bbf..3029b763ab58 100644 99 | --- a/include/media/videobuf2-v4l2.h 100 | +++ b/include/media/videobuf2-v4l2.h 101 | @@ -30,6 +30,7 @@ 102 | * @flags: buffer informational flags 103 | * @field: enum v4l2_field; field order of the image in the buffer 104 | * @timecode: frame timecode 105 | + * @request: this buffer should use this request 106 | * @sequence: sequence count of this frame 107 | * 108 | * Should contain enough information to be able to cover all the fields 109 | @@ -41,6 +42,7 @@ struct vb2_v4l2_buffer { 110 | __u32 flags; 111 | __u32 field; 112 | struct v4l2_timecode timecode; 113 | + __u16 request; 114 | __u32 sequence; 115 | }; 116 | 117 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 118 | index 80d22869b380..46d8a2915e4e 100644 119 | --- a/include/uapi/linux/videodev2.h 120 | +++ b/include/uapi/linux/videodev2.h 121 | @@ -861,6 +861,7 @@ struct v4l2_plane { 122 | * @length: size in bytes of the buffer (NOT its payload) for single-plane 123 | * buffers (when type != *_MPLANE); number of elements in the 124 | * planes array for multi-plane buffers 125 | + * @request: this buffer should use this request 126 | * 127 | * Contains data exchanged by application and driver using one of the Streaming 128 | * I/O methods. 129 | @@ -884,7 +885,8 @@ struct v4l2_buffer { 130 | __s32 fd; 131 | } m; 132 | __u32 length; 133 | - __u32 reserved2; 134 | + __u16 request; 135 | + __u16 reserved2; 136 | __u32 reserved; 137 | }; 138 | 139 | -- 140 | 2.14.3 141 | 142 | -------------------------------------------------------------------------------- /patches/4.14/0003-videodev2.h-add-request-field-to-v4l2_buffer.patch: -------------------------------------------------------------------------------- 1 | From e456edae31528bc2995f65bf063e3b719c54698f Mon Sep 17 00:00:00 2001 2 | From: Hans Verkuil 3 | Date: Thu, 9 Apr 2015 13:30:35 +0200 4 | Subject: [PATCH 03/22] videodev2.h: add request field to v4l2_buffer. 5 | 6 | When queuing buffers allow for passing the request ID that 7 | should be associated with this buffer. Split the u32 reserved2 field 8 | into two u16 fields, one for request, one with the old reserved2 name. 9 | 10 | Signed-off-by: Hans Verkuil 11 | --- 12 | drivers/media/usb/cpia2/cpia2_v4l.c | 1 + 13 | drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 +++- 14 | drivers/media/v4l2-core/v4l2-ioctl.c | 4 ++-- 15 | drivers/media/v4l2-core/videobuf2-v4l2.c | 2 ++ 16 | include/media/videobuf2-v4l2.h | 2 ++ 17 | include/uapi/linux/videodev2.h | 4 +++- 18 | 6 files changed, 13 insertions(+), 4 deletions(-) 19 | 20 | diff --git a/drivers/media/usb/cpia2/cpia2_v4l.c b/drivers/media/usb/cpia2/cpia2_v4l.c 21 | index 3dedd83f0b19..919c1024cd44 100644 22 | --- a/drivers/media/usb/cpia2/cpia2_v4l.c 23 | +++ b/drivers/media/usb/cpia2/cpia2_v4l.c 24 | @@ -948,6 +948,7 @@ static int cpia2_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf) 25 | buf->sequence = cam->buffers[buf->index].seq; 26 | buf->m.offset = cam->buffers[buf->index].data - cam->frame_buffer; 27 | buf->length = cam->frame_size; 28 | + buf->request = 0; 29 | buf->reserved2 = 0; 30 | buf->reserved = 0; 31 | memset(&buf->timecode, 0, sizeof(buf->timecode)); 32 | diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 33 | index 821f2aa299ae..26d74430349d 100644 34 | --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 35 | +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c 36 | @@ -370,7 +370,8 @@ struct v4l2_buffer32 { 37 | __s32 fd; 38 | } m; 39 | __u32 length; 40 | - __u32 reserved2; 41 | + __u16 request; 42 | + __u16 reserved2; 43 | __u32 reserved; 44 | }; 45 | 46 | @@ -533,6 +534,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user 47 | put_user(kp->timestamp.tv_usec, &up->timestamp.tv_usec) || 48 | copy_to_user(&up->timecode, &kp->timecode, sizeof(struct v4l2_timecode)) || 49 | put_user(kp->sequence, &up->sequence) || 50 | + put_user(kp->request, &up->request) || 51 | put_user(kp->reserved2, &up->reserved2) || 52 | put_user(kp->reserved, &up->reserved) || 53 | put_user(kp->length, &up->length)) 54 | diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c 55 | index 52e8e1076d76..674d51bf93e0 100644 56 | --- a/drivers/media/v4l2-core/v4l2-ioctl.c 57 | +++ b/drivers/media/v4l2-core/v4l2-ioctl.c 58 | @@ -437,13 +437,13 @@ static void v4l_print_buffer(const void *arg, bool write_only) 59 | const struct v4l2_plane *plane; 60 | int i; 61 | 62 | - pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, flags=0x%08x, field=%s, sequence=%d, memory=%s", 63 | + pr_cont("%02ld:%02d:%02d.%08ld index=%d, type=%s, request=%u, flags=0x%08x, field=%s, sequence=%d, memory=%s", 64 | p->timestamp.tv_sec / 3600, 65 | (int)(p->timestamp.tv_sec / 60) % 60, 66 | (int)(p->timestamp.tv_sec % 60), 67 | (long)p->timestamp.tv_usec, 68 | p->index, 69 | - prt_names(p->type, v4l2_type_names), 70 | + prt_names(p->type, v4l2_type_names), p->request, 71 | p->flags, prt_names(p->field, v4l2_field_names), 72 | p->sequence, prt_names(p->memory, v4l2_memory_names)); 73 | 74 | diff --git a/drivers/media/v4l2-core/videobuf2-v4l2.c b/drivers/media/v4l2-core/videobuf2-v4l2.c 75 | index 0c0669976bdc..a0211921a492 100644 76 | --- a/drivers/media/v4l2-core/videobuf2-v4l2.c 77 | +++ b/drivers/media/v4l2-core/videobuf2-v4l2.c 78 | @@ -203,6 +203,7 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, void *pb) 79 | b->timestamp = ns_to_timeval(vb->timestamp); 80 | b->timecode = vbuf->timecode; 81 | b->sequence = vbuf->sequence; 82 | + b->request = vbuf->request; 83 | b->reserved2 = 0; 84 | b->reserved = 0; 85 | 86 | @@ -319,6 +320,7 @@ static int __fill_vb2_buffer(struct vb2_buffer *vb, 87 | return -EINVAL; 88 | } 89 | vb->timestamp = 0; 90 | + vbuf->request = b->request; 91 | vbuf->sequence = 0; 92 | 93 | if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) { 94 | diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h 95 | index 036127c54bbf..3029b763ab58 100644 96 | --- a/include/media/videobuf2-v4l2.h 97 | +++ b/include/media/videobuf2-v4l2.h 98 | @@ -30,6 +30,7 @@ 99 | * @flags: buffer informational flags 100 | * @field: enum v4l2_field; field order of the image in the buffer 101 | * @timecode: frame timecode 102 | + * @request: this buffer should use this request 103 | * @sequence: sequence count of this frame 104 | * 105 | * Should contain enough information to be able to cover all the fields 106 | @@ -41,6 +42,7 @@ struct vb2_v4l2_buffer { 107 | __u32 flags; 108 | __u32 field; 109 | struct v4l2_timecode timecode; 110 | + __u16 request; 111 | __u32 sequence; 112 | }; 113 | 114 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 115 | index 4a32d88dc437..df9098c02c56 100644 116 | --- a/include/uapi/linux/videodev2.h 117 | +++ b/include/uapi/linux/videodev2.h 118 | @@ -902,6 +902,7 @@ struct v4l2_plane { 119 | * @length: size in bytes of the buffer (NOT its payload) for single-plane 120 | * buffers (when type != *_MPLANE); number of elements in the 121 | * planes array for multi-plane buffers 122 | + * @request: this buffer should use this request 123 | * 124 | * Contains data exchanged by application and driver using one of the Streaming 125 | * I/O methods. 126 | @@ -925,7 +926,8 @@ struct v4l2_buffer { 127 | __s32 fd; 128 | } m; 129 | __u32 length; 130 | - __u32 reserved2; 131 | + __u16 request; 132 | + __u16 reserved2; 133 | __u32 reserved; 134 | }; 135 | 136 | -- 137 | 2.14.3 138 | 139 | -------------------------------------------------------------------------------- /driver/sunxi_cedrus_regs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Sunxi Cedrus codec driver 3 | * 4 | * Copyright (C) 2016 Florent Revest 5 | * Florent Revest 6 | * 7 | * Based on Cedrus 8 | * 9 | * Copyright (c) 2013 Jens Kuske 10 | * 11 | * This software is licensed under the terms of the GNU General Public 12 | * License version 2, as published by the Free Software Foundation, and 13 | * may be copied, distributed, and modified under those terms. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | */ 20 | 21 | #ifndef SUNXI_CEDRUS_REGS_H 22 | #define SUNXI_CEDRUS_REGS_H 23 | 24 | /* 25 | * For more information consult http://linux-sunxi.org/VE_Register_guide 26 | */ 27 | 28 | /* Special registers values */ 29 | 30 | /* VE_CTRL: 31 | * The first 3 bits indicate the engine (0 for MPEG, 1 for H264, b for AVC...) 32 | * The 16th and 17th bits indicate the memory type (3 for DDR3 32 bits) 33 | * The 20th bit is unknown but needed 34 | */ 35 | #define VE_CTRL_MPEG 0x130000 36 | #define VE_CTRL_H264 0x130001 37 | #define VE_CTRL_AVC 0x13000b 38 | #define VE_CTRL_REINIT 0x130007 39 | 40 | /* VE_MPEG_CTRL: 41 | * The bit 3 (0x8) is used to enable IRQs 42 | * The other bits are unknown but needed 43 | */ 44 | #define VE_MPEG_CTRL_MPEG2 0x800001b8 45 | #define VE_MPEG_CTRL_MPEG4 (0x80084118 | BIT(7)) 46 | #define VE_MPEG_CTRL_MPEG4_P (VE_MPEG_CTRL_MPEG4 | BIT(12)) 47 | 48 | /* VE_MPEG_VLD_ADDR: 49 | * The bits 27 to 4 are used for the address 50 | * The bits 31 to 28 (0x7) are used to select the MPEG or JPEG engine 51 | */ 52 | #define VE_MPEG_VLD_ADDR_VAL(x) ((x & 0x0ffffff0) | (x >> 28) | (0x7 << 28)) 53 | 54 | /* VE_MPEG_TRIGGER: 55 | * The first three bits are used to trigger the engine 56 | * The bits 24 to 26 are used to select the input format (1 for MPEG1, 2 for 57 | * MPEG2, 4 for MPEG4) 58 | * The bit 21 (0x8) is used to disable bitstream error handling 59 | * 60 | * In MPEG4 the w*h value is somehow used for an offset, unknown but needed 61 | */ 62 | #define VE_TRIG_MPEG1 0x8100000f 63 | #define VE_TRIG_MPEG2 0x8200000f 64 | #define VE_TRIG_MPEG4(w, h) (0x8400000d | ((w * h) << 8)) 65 | 66 | /* VE_MPEG_SDROT_CTRL: 67 | * The bit 8 at zero is used to disable x downscaling 68 | * The bit 10 at 0 is used to disable y downscaling 69 | * The other bits are unknown but needed 70 | */ 71 | #define VE_NO_SDROT_CTRL 0x40620000 72 | 73 | /* Decent size fo video buffering verifier */ 74 | #define VBV_SIZE (1024 * 1024) 75 | 76 | /* Registers addresses */ 77 | #define VE_CTRL 0x000 78 | #define VE_VERSION 0x0f0 79 | 80 | #define VE_MPEG_PIC_HDR 0x100 81 | #define VE_MPEG_VOP_HDR 0x104 82 | #define VE_MPEG_SIZE 0x108 83 | #define VE_MPEG_FRAME_SIZE 0x10c 84 | #define VE_MPEG_MBA 0x110 85 | #define VE_MPEG_CTRL 0x114 86 | #define VE_MPEG_TRIGGER 0x118 87 | #define VE_MPEG_STATUS 0x11c 88 | #define VE_MPEG_TRBTRD_FIELD 0x120 89 | #define VE_MPEG_TRBTRD_FRAME 0x124 90 | #define VE_MPEG_VLD_ADDR 0x128 91 | #define VE_MPEG_VLD_OFFSET 0x12c 92 | #define VE_MPEG_VLD_LEN 0x130 93 | #define VE_MPEG_VLD_END 0x134 94 | #define VE_MPEG_MBH_ADDR 0x138 95 | #define VE_MPEG_DCAC_ADDR 0x13c 96 | #define VE_MPEG_NCF_ADDR 0x144 97 | #define VE_MPEG_REC_LUMA 0x148 98 | #define VE_MPEG_REC_CHROMA 0x14c 99 | #define VE_MPEG_FWD_LUMA 0x150 100 | #define VE_MPEG_FWD_CHROMA 0x154 101 | #define VE_MPEG_BACK_LUMA 0x158 102 | #define VE_MPEG_BACK_CHROMA 0x15c 103 | #define VE_MPEG_IQ_MIN_INPUT 0x180 104 | #define VE_MPEG_QP_INPUT 0x184 105 | #define VE_MPEG_JPEG_SIZE 0x1b8 106 | #define VE_MPEG_JPEG_RES_INT 0x1c0 107 | #define VE_MPEG_ERROR 0x1c4 108 | #define VE_MPEG_CTR_MB 0x1c8 109 | #define VE_MPEG_ROT_LUMA 0x1cc 110 | #define VE_MPEG_ROT_CHROMA 0x1d0 111 | #define VE_MPEG_SDROT_CTRL 0x1d4 112 | #define VE_MPEG_RAM_WRITE_PTR 0x1e0 113 | #define VE_MPEG_RAM_WRITE_DATA 0x1e4 114 | 115 | #define VE_H264_FRAME_SIZE 0x200 116 | #define VE_H264_PIC_HDR 0x204 117 | #define VE_H264_SLICE_HDR 0x208 118 | #define VE_H264_SLICE_HDR2 0x20c 119 | #define VE_H264_PRED_WEIGHT 0x210 120 | #define VE_H264_QP_PARAM 0x21c 121 | #define VE_H264_CTRL 0x220 122 | #define VE_H264_TRIGGER 0x224 123 | #define VE_H264_STATUS 0x228 124 | #define VE_H264_CUR_MB_NUM 0x22c 125 | #define VE_H264_VLD_ADDR 0x230 126 | #define VE_H264_VLD_OFFSET 0x234 127 | #define VE_H264_VLD_LEN 0x238 128 | #define VE_H264_VLD_END 0x23c 129 | #define VE_H264_SDROT_CTRL 0x240 130 | #define VE_H264_OUTPUT_FRAME_IDX 0x24c 131 | #define VE_H264_EXTRA_BUFFER1 0x250 132 | #define VE_H264_EXTRA_BUFFER2 0x254 133 | #define VE_H264_BASIC_BITS 0x2dc 134 | #define VE_H264_RAM_WRITE_PTR 0x2e0 135 | #define VE_H264_RAM_WRITE_DATA 0x2e4 136 | 137 | #define VE_SRAM_H264_PRED_WEIGHT_TABLE 0x000 138 | #define VE_SRAM_H264_FRAMEBUFFER_LIST 0x400 139 | #define VE_SRAM_H264_REF_LIST0 0x640 140 | #define VE_SRAM_H264_REF_LIST1 0x664 141 | #define VE_SRAM_H264_SCALING_LISTS 0x800 142 | 143 | #define VE_ISP_INPUT_SIZE 0xa00 144 | #define VE_ISP_INPUT_STRIDE 0xa04 145 | #define VE_ISP_CTRL 0xa08 146 | #define VE_ISP_INPUT_LUMA 0xa78 147 | #define VE_ISP_INPUT_CHROMA 0xa7c 148 | 149 | #define VE_AVC_PARAM 0xb04 150 | #define VE_AVC_QP 0xb08 151 | #define VE_AVC_MOTION_EST 0xb10 152 | #define VE_AVC_CTRL 0xb14 153 | #define VE_AVC_TRIGGER 0xb18 154 | #define VE_AVC_STATUS 0xb1c 155 | #define VE_AVC_BASIC_BITS 0xb20 156 | #define VE_AVC_UNK_BUF 0xb60 157 | #define VE_AVC_VLE_ADDR 0xb80 158 | #define VE_AVC_VLE_END 0xb84 159 | #define VE_AVC_VLE_OFFSET 0xb88 160 | #define VE_AVC_VLE_MAX 0xb8c 161 | #define VE_AVC_VLE_LENGTH 0xb90 162 | #define VE_AVC_REF_LUMA 0xba0 163 | #define VE_AVC_REF_CHROMA 0xba4 164 | #define VE_AVC_REC_LUMA 0xbb0 165 | #define VE_AVC_REC_CHROMA 0xbb4 166 | #define VE_AVC_REF_SLUMA 0xbb8 167 | #define VE_AVC_REC_SLUMA 0xbbc 168 | #define VE_AVC_MB_INFO 0xbc0 169 | 170 | #endif /* SUNXI_CEDRUS_REGS_H */ 171 | -------------------------------------------------------------------------------- /driver/sunxi_cedrus_mpeg2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Sunxi Cedrus codec driver 3 | * 4 | * Copyright (C) 2016 Florent Revest 5 | * Florent Revest 6 | * 7 | * Based on reverse engineering efforts of the 'Cedrus' project 8 | * Copyright (c) 2013-2014 Jens Kuske 9 | * 10 | * This software is licensed under the terms of the GNU General Public 11 | * License version 2, as published by the Free Software Foundation, and 12 | * may be copied, distributed, and modified under those terms. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | */ 19 | 20 | #include "sunxi_cedrus_common.h" 21 | 22 | #include 23 | 24 | static const u8 mpeg_default_intra_quant[64] = { 25 | 8, 16, 16, 19, 16, 19, 22, 22, 26 | 22, 22, 22, 22, 26, 24, 26, 27, 27 | 27, 27, 26, 26, 26, 26, 27, 27, 28 | 27, 29, 29, 29, 34, 34, 34, 29, 29 | 29, 29, 27, 27, 29, 29, 32, 32, 30 | 34, 34, 37, 38, 37, 35, 35, 34, 31 | 35, 38, 38, 40, 40, 40, 48, 48, 32 | 46, 46, 56, 56, 58, 69, 69, 83 33 | }; 34 | 35 | #define m_iq(i) (((64 + i) << 8) | mpeg_default_intra_quant[i]) 36 | 37 | static const u8 mpeg_default_non_intra_quant[64] = { 38 | 16, 16, 16, 16, 16, 16, 16, 16, 39 | 16, 16, 16, 16, 16, 16, 16, 16, 40 | 16, 16, 16, 16, 16, 16, 16, 16, 41 | 16, 16, 16, 16, 16, 16, 16, 16, 42 | 16, 16, 16, 16, 16, 16, 16, 16, 43 | 16, 16, 16, 16, 16, 16, 16, 16, 44 | 16, 16, 16, 16, 16, 16, 16, 16, 45 | 16, 16, 16, 16, 16, 16, 16, 16 46 | }; 47 | 48 | #define m_niq(i) ((i << 8) | mpeg_default_non_intra_quant[i]) 49 | 50 | void process_mpeg2(struct sunxi_cedrus_ctx *ctx, dma_addr_t in_buf, 51 | dma_addr_t out_luma, dma_addr_t out_chroma, 52 | struct v4l2_ctrl_mpeg2_frame_hdr *frame_hdr) 53 | { 54 | struct sunxi_cedrus_dev *dev = ctx->dev; 55 | 56 | u16 width = DIV_ROUND_UP(frame_hdr->width, 16); 57 | u16 height = DIV_ROUND_UP(frame_hdr->height, 16); 58 | 59 | u32 pic_header = 0; 60 | u32 vld_len = frame_hdr->slice_len - frame_hdr->slice_pos; 61 | int i; 62 | 63 | struct vb2_buffer *fwd_vb2_buf, *bwd_vb2_buf; 64 | dma_addr_t fwd_luma = 0, fwd_chroma = 0, bwd_luma = 0, bwd_chroma = 0; 65 | 66 | /* 67 | * The VPU is only able to handle bus addresses so we have to subtract 68 | * the RAM offset to the physcal addresses 69 | */ 70 | fwd_vb2_buf = ctx->dst_bufs[frame_hdr->forward_index]; 71 | if (fwd_vb2_buf) { 72 | fwd_luma = vb2_dma_contig_plane_dma_addr(fwd_vb2_buf, 0); 73 | fwd_chroma = vb2_dma_contig_plane_dma_addr(fwd_vb2_buf, 1); 74 | fwd_luma -= PHYS_OFFSET; 75 | fwd_chroma -= PHYS_OFFSET; 76 | } 77 | 78 | bwd_vb2_buf = ctx->dst_bufs[frame_hdr->backward_index]; 79 | if (bwd_vb2_buf) { 80 | bwd_luma = vb2_dma_contig_plane_dma_addr(bwd_vb2_buf, 0); 81 | bwd_chroma = vb2_dma_contig_plane_dma_addr(bwd_vb2_buf, 1); 82 | bwd_chroma -= PHYS_OFFSET; 83 | bwd_luma -= PHYS_OFFSET; 84 | } 85 | 86 | /* Activates MPEG engine */ 87 | sunxi_cedrus_write(dev, VE_CTRL_MPEG, VE_CTRL); 88 | 89 | /* Upload quantization matrices */ 90 | for (i = 0; i < 64; i++) { 91 | sunxi_cedrus_write(dev, m_iq(i), VE_MPEG_IQ_MIN_INPUT); 92 | sunxi_cedrus_write(dev, m_niq(i), VE_MPEG_IQ_MIN_INPUT); 93 | } 94 | 95 | /* Image's dimensions */ 96 | sunxi_cedrus_write(dev, width << 8 | height, VE_MPEG_SIZE); 97 | sunxi_cedrus_write(dev, width << 20 | height << 4, VE_MPEG_FRAME_SIZE); 98 | 99 | /* MPEG picture's header */ 100 | pic_header |= (frame_hdr->picture_coding_type & 0xf) << 28; 101 | pic_header |= (frame_hdr->f_code[0][0] & 0xf) << 24; 102 | pic_header |= (frame_hdr->f_code[0][1] & 0xf) << 20; 103 | pic_header |= (frame_hdr->f_code[1][0] & 0xf) << 16; 104 | pic_header |= (frame_hdr->f_code[1][1] & 0xf) << 12; 105 | pic_header |= (frame_hdr->intra_dc_precision & 0x3) << 10; 106 | pic_header |= (frame_hdr->picture_structure & 0x3) << 8; 107 | pic_header |= (frame_hdr->top_field_first & 0x1) << 7; 108 | pic_header |= (frame_hdr->frame_pred_frame_dct & 0x1) << 6; 109 | pic_header |= (frame_hdr->concealment_motion_vectors & 0x1) << 5; 110 | pic_header |= (frame_hdr->q_scale_type & 0x1) << 4; 111 | pic_header |= (frame_hdr->intra_vlc_format & 0x1) << 3; 112 | pic_header |= (frame_hdr->alternate_scan & 0x1) << 2; 113 | sunxi_cedrus_write(dev, pic_header, VE_MPEG_PIC_HDR); 114 | 115 | /* Enable interrupt and an unknown control flag */ 116 | sunxi_cedrus_write(dev, VE_MPEG_CTRL_MPEG2, VE_MPEG_CTRL); 117 | 118 | /* Macroblock address */ 119 | sunxi_cedrus_write(dev, 0, VE_MPEG_MBA); 120 | 121 | /* Clear previous errors */ 122 | sunxi_cedrus_write(dev, 0, VE_MPEG_ERROR); 123 | 124 | /* Unknown register */ 125 | sunxi_cedrus_write(dev, 0, VE_MPEG_CTR_MB); 126 | 127 | /* Forward and backward prediction buffers (cached in dst_bufs) */ 128 | sunxi_cedrus_write(dev, fwd_luma, VE_MPEG_FWD_LUMA); 129 | sunxi_cedrus_write(dev, fwd_chroma, VE_MPEG_FWD_CHROMA); 130 | sunxi_cedrus_write(dev, bwd_luma, VE_MPEG_BACK_LUMA); 131 | sunxi_cedrus_write(dev, bwd_chroma, VE_MPEG_BACK_CHROMA); 132 | 133 | /* Output luma and chroma buffers */ 134 | sunxi_cedrus_write(dev, out_luma, VE_MPEG_REC_LUMA); 135 | sunxi_cedrus_write(dev, out_chroma, VE_MPEG_REC_CHROMA); 136 | sunxi_cedrus_write(dev, out_luma, VE_MPEG_ROT_LUMA); 137 | sunxi_cedrus_write(dev, out_chroma, VE_MPEG_ROT_CHROMA); 138 | 139 | /* Input offset and length in bits */ 140 | sunxi_cedrus_write(dev, frame_hdr->slice_pos, VE_MPEG_VLD_OFFSET); 141 | sunxi_cedrus_write(dev, vld_len, VE_MPEG_VLD_LEN); 142 | 143 | /* Input beginning and end addresses */ 144 | sunxi_cedrus_write(dev, VE_MPEG_VLD_ADDR_VAL(in_buf), VE_MPEG_VLD_ADDR); 145 | sunxi_cedrus_write(dev, in_buf + VBV_SIZE - 1, VE_MPEG_VLD_END); 146 | 147 | /* Starts the MPEG engine */ 148 | if (frame_hdr->type == MPEG2) 149 | sunxi_cedrus_write(dev, VE_TRIG_MPEG2, VE_MPEG_TRIGGER); 150 | else 151 | sunxi_cedrus_write(dev, VE_TRIG_MPEG1, VE_MPEG_TRIGGER); 152 | } 153 | -------------------------------------------------------------------------------- /patches/4.9/0018-v4l-Add-MPEG2-low-level-decoder-API-control.patch: -------------------------------------------------------------------------------- 1 | From cfbbfcb28bb6ed834324602434556a355c8f8093 Mon Sep 17 00:00:00 2001 2 | From: Florent Revest 3 | Date: Wed, 24 Aug 2016 13:39:02 +0200 4 | Subject: [PATCH] v4l: Add MPEG2 low-level decoder API control 5 | 6 | This control is to be used with the new low-level decoder API for 7 | MPEG2 to provide additional parameters for the hardware that cannot parse 8 | the input stream. 9 | 10 | Signed-off-by: Florent Revest 11 | --- 12 | drivers/media/v4l2-core/v4l2-ctrls.c | 11 +++++++++++ 13 | drivers/media/v4l2-core/v4l2-ioctl.c | 1 + 14 | include/uapi/linux/v4l2-controls.h | 26 ++++++++++++++++++++++++++ 15 | include/uapi/linux/videodev2.h | 3 +++ 16 | 4 files changed, 41 insertions(+) 17 | 18 | diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c 19 | index dbb900eed37f..355c7d8549a9 100644 20 | --- a/drivers/media/v4l2-core/v4l2-ctrls.c 21 | +++ b/drivers/media/v4l2-core/v4l2-ctrls.c 22 | @@ -761,6 +761,8 @@ const char *v4l2_ctrl_get_name(u32 id) 23 | case V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER: return "Repeat Sequence Header"; 24 | case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: return "Force Key Frame"; 25 | 26 | + case V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR: return "MPEG2 Frame Header"; 27 | + 28 | /* VPX controls */ 29 | case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS: return "VPX Number of Partitions"; 30 | case V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4: return "VPX Intra Mode Decision Disable"; 31 | @@ -1144,6 +1146,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, 32 | case V4L2_CID_RDS_TX_ALT_FREQS: 33 | *type = V4L2_CTRL_TYPE_U32; 34 | break; 35 | + case V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR: 36 | + *type = V4L2_CTRL_TYPE_MPEG2_FRAME_HDR; 37 | + break; 38 | default: 39 | *type = V4L2_CTRL_TYPE_INTEGER; 40 | break; 41 | @@ -1544,6 +1549,9 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx, 42 | return -ERANGE; 43 | return 0; 44 | 45 | + case V4L2_CTRL_TYPE_MPEG2_FRAME_HDR: 46 | + return 0; 47 | + 48 | /* FIXME:just return 0 for now */ 49 | case V4L2_CTRL_TYPE_PRIVATE: 50 | return 0; 51 | @@ -2097,6 +2105,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, 52 | case V4L2_CTRL_TYPE_U32: 53 | elem_size = sizeof(u32); 54 | break; 55 | + case V4L2_CTRL_TYPE_MPEG2_FRAME_HDR: 56 | + elem_size = sizeof(struct v4l2_ctrl_mpeg2_frame_hdr); 57 | + break; 58 | default: 59 | if (type < V4L2_CTRL_COMPOUND_TYPES) 60 | elem_size = sizeof(s32); 61 | diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c 62 | index 3fd13fbf2898..6c0f13b47522 100644 63 | --- a/drivers/media/v4l2-core/v4l2-ioctl.c 64 | +++ b/drivers/media/v4l2-core/v4l2-ioctl.c 65 | @@ -1278,6 +1278,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) 66 | case V4L2_PIX_FMT_VC1_ANNEX_G: descr = "VC-1 (SMPTE 412M Annex G)"; break; 67 | case V4L2_PIX_FMT_VC1_ANNEX_L: descr = "VC-1 (SMPTE 412M Annex L)"; break; 68 | case V4L2_PIX_FMT_VP8: descr = "VP8"; break; 69 | + case V4L2_PIX_FMT_MPEG2_FRAME: descr = "MPEG2 FRAME"; break; 70 | case V4L2_PIX_FMT_CPIA1: descr = "GSPCA CPiA YUV"; break; 71 | case V4L2_PIX_FMT_WNVA: descr = "WNVA"; break; 72 | case V4L2_PIX_FMT_SN9C10X: descr = "GSPCA SN9C10X"; break; 73 | diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h 74 | index b6a357a5f053..cdf94971b230 100644 75 | --- a/include/uapi/linux/v4l2-controls.h 76 | +++ b/include/uapi/linux/v4l2-controls.h 77 | @@ -547,6 +547,8 @@ enum v4l2_mpeg_video_mpeg4_profile { 78 | }; 79 | #define V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (V4L2_CID_MPEG_BASE+407) 80 | 81 | +#define V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR (V4L2_CID_MPEG_BASE+450) 82 | + 83 | /* Control IDs for VP8 streams 84 | * Although VP8 is not part of MPEG we add these controls to the MPEG class 85 | * as that class is already handling other video compression standards 86 | @@ -974,4 +976,28 @@ enum v4l2_detect_md_mode { 87 | #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) 88 | #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) 89 | 90 | +struct v4l2_ctrl_mpeg2_frame_hdr { 91 | + __u32 slice_len; 92 | + __u32 slice_pos; 93 | + enum { MPEG1, MPEG2 } type; 94 | + 95 | + __u16 width; 96 | + __u16 height; 97 | + 98 | + enum { PCT_I = 1, PCT_P, PCT_B, PCT_D } picture_coding_type; 99 | + __u8 f_code[2][2]; 100 | + 101 | + __u8 intra_dc_precision; 102 | + __u8 picture_structure; 103 | + __u8 top_field_first; 104 | + __u8 frame_pred_frame_dct; 105 | + __u8 concealment_motion_vectors; 106 | + __u8 q_scale_type; 107 | + __u8 intra_vlc_format; 108 | + __u8 alternate_scan; 109 | + 110 | + __u8 backward_index; 111 | + __u8 forward_index; 112 | +}; 113 | + 114 | #endif 115 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 116 | index 82979987bff0..a7fba0170b28 100644 117 | --- a/include/uapi/linux/videodev2.h 118 | +++ b/include/uapi/linux/videodev2.h 119 | @@ -603,6 +603,7 @@ struct v4l2_pix_format { 120 | #define V4L2_PIX_FMT_VC1_ANNEX_G v4l2_fourcc('V', 'C', '1', 'G') /* SMPTE 421M Annex G compliant stream */ 121 | #define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */ 122 | #define V4L2_PIX_FMT_VP8 v4l2_fourcc('V', 'P', '8', '0') /* VP8 */ 123 | +#define V4L2_PIX_FMT_MPEG2_FRAME v4l2_fourcc('M', 'G', '2', 'F') /* MPEG2 frame */ 124 | 125 | /* Vendor-specific formats */ 126 | #define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */ 127 | @@ -1500,6 +1501,7 @@ struct v4l2_ext_control { 128 | __u8 __user *p_u8; 129 | __u16 __user *p_u16; 130 | __u32 __user *p_u32; 131 | + struct v4l2_ctrl_mpeg2_frame_hdr __user *p_mpeg2_frame_hdr; 132 | void __user *ptr; 133 | }; 134 | } __attribute__ ((packed)); 135 | @@ -1544,6 +1546,7 @@ enum v4l2_ctrl_type { 136 | V4L2_CTRL_TYPE_U8 = 0x0100, 137 | V4L2_CTRL_TYPE_U16 = 0x0101, 138 | V4L2_CTRL_TYPE_U32 = 0x0102, 139 | + V4L2_CTRL_TYPE_MPEG2_FRAME_HDR = 0x0109, 140 | 141 | V4L2_CTRL_TYPE_PRIVATE = 0xffff, 142 | }; 143 | -- 144 | 2.14.3 145 | 146 | -------------------------------------------------------------------------------- /patches/4.14/0017-v4l-Add-MPEG2-low-level-decoder-API-control.patch: -------------------------------------------------------------------------------- 1 | From c591c74a6547160bbe02a31292510c632832c10a Mon Sep 17 00:00:00 2001 2 | From: Florent Revest 3 | Date: Wed, 24 Aug 2016 13:39:02 +0200 4 | Subject: [PATCH 17/22] v4l: Add MPEG2 low-level decoder API control 5 | 6 | This control is to be used with the new low-level decoder API for 7 | MPEG2 to provide additional parameters for the hardware that cannot parse 8 | the input stream. 9 | 10 | Signed-off-by: Florent Revest 11 | --- 12 | drivers/media/v4l2-core/v4l2-ctrls.c | 15 +++++++++++++++ 13 | drivers/media/v4l2-core/v4l2-ioctl.c | 1 + 14 | include/uapi/linux/v4l2-controls.h | 26 ++++++++++++++++++++++++++ 15 | include/uapi/linux/videodev2.h | 5 +++++ 16 | 4 files changed, 47 insertions(+) 17 | 18 | diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c 19 | index 78d2a8b06be4..7f6488aa5434 100644 20 | --- a/drivers/media/v4l2-core/v4l2-ctrls.c 21 | +++ b/drivers/media/v4l2-core/v4l2-ctrls.c 22 | @@ -762,6 +762,8 @@ const char *v4l2_ctrl_get_name(u32 id) 23 | case V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER: return "Repeat Sequence Header"; 24 | case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: return "Force Key Frame"; 25 | 26 | + case V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR: return "MPEG2 Frame Header"; 27 | + 28 | /* VPX controls */ 29 | case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS: return "VPX Number of Partitions"; 30 | case V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4: return "VPX Intra Mode Decision Disable"; 31 | @@ -1152,6 +1154,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, 32 | case V4L2_CID_RDS_TX_ALT_FREQS: 33 | *type = V4L2_CTRL_TYPE_U32; 34 | break; 35 | + case V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR: 36 | + *type = V4L2_CTRL_TYPE_MPEG2_FRAME_HDR; 37 | + break; 38 | default: 39 | *type = V4L2_CTRL_TYPE_INTEGER; 40 | break; 41 | @@ -1552,6 +1557,13 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx, 42 | return -ERANGE; 43 | return 0; 44 | 45 | + case V4L2_CTRL_TYPE_MPEG2_FRAME_HDR: 46 | + return 0; 47 | + 48 | + /* FIXME:just return 0 for now */ 49 | + case V4L2_CTRL_TYPE_PRIVATE: 50 | + return 0; 51 | + 52 | default: 53 | return -EINVAL; 54 | } 55 | @@ -2103,6 +2115,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, 56 | case V4L2_CTRL_TYPE_U32: 57 | elem_size = sizeof(u32); 58 | break; 59 | + case V4L2_CTRL_TYPE_MPEG2_FRAME_HDR: 60 | + elem_size = sizeof(struct v4l2_ctrl_mpeg2_frame_hdr); 61 | + break; 62 | default: 63 | if (type < V4L2_CTRL_COMPOUND_TYPES) 64 | elem_size = sizeof(s32); 65 | diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c 66 | index 98c871855072..9f7bd65e5573 100644 67 | --- a/drivers/media/v4l2-core/v4l2-ioctl.c 68 | +++ b/drivers/media/v4l2-core/v4l2-ioctl.c 69 | @@ -1274,6 +1274,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) 70 | case V4L2_PIX_FMT_VC1_ANNEX_L: descr = "VC-1 (SMPTE 412M Annex L)"; break; 71 | case V4L2_PIX_FMT_VP8: descr = "VP8"; break; 72 | case V4L2_PIX_FMT_VP9: descr = "VP9"; break; 73 | + case V4L2_PIX_FMT_MPEG2_FRAME: descr = "MPEG2 FRAME"; break; 74 | case V4L2_PIX_FMT_CPIA1: descr = "GSPCA CPiA YUV"; break; 75 | case V4L2_PIX_FMT_WNVA: descr = "WNVA"; break; 76 | case V4L2_PIX_FMT_SN9C10X: descr = "GSPCA SN9C10X"; break; 77 | diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h 78 | index a692623e0236..441a7f90867e 100644 79 | --- a/include/uapi/linux/v4l2-controls.h 80 | +++ b/include/uapi/linux/v4l2-controls.h 81 | @@ -557,6 +557,8 @@ enum v4l2_mpeg_video_mpeg4_profile { 82 | }; 83 | #define V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (V4L2_CID_MPEG_BASE+407) 84 | 85 | +#define V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR (V4L2_CID_MPEG_BASE+450) 86 | + 87 | /* Control IDs for VP8 streams 88 | * Although VP8 is not part of MPEG we add these controls to the MPEG class 89 | * as that class is already handling other video compression standards 90 | @@ -985,4 +987,28 @@ enum v4l2_detect_md_mode { 91 | #define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3) 92 | #define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4) 93 | 94 | +struct v4l2_ctrl_mpeg2_frame_hdr { 95 | + __u32 slice_len; 96 | + __u32 slice_pos; 97 | + enum { MPEG1, MPEG2 } type; 98 | + 99 | + __u16 width; 100 | + __u16 height; 101 | + 102 | + enum { PCT_I = 1, PCT_P, PCT_B, PCT_D } picture_coding_type; 103 | + __u8 f_code[2][2]; 104 | + 105 | + __u8 intra_dc_precision; 106 | + __u8 picture_structure; 107 | + __u8 top_field_first; 108 | + __u8 frame_pred_frame_dct; 109 | + __u8 concealment_motion_vectors; 110 | + __u8 q_scale_type; 111 | + __u8 intra_vlc_format; 112 | + __u8 alternate_scan; 113 | + 114 | + __u8 backward_index; 115 | + __u8 forward_index; 116 | +}; 117 | + 118 | #endif 119 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 120 | index 91b82f6531ed..715c0d88805c 100644 121 | --- a/include/uapi/linux/videodev2.h 122 | +++ b/include/uapi/linux/videodev2.h 123 | @@ -635,6 +635,7 @@ struct v4l2_pix_format { 124 | #define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */ 125 | #define V4L2_PIX_FMT_VP8 v4l2_fourcc('V', 'P', '8', '0') /* VP8 */ 126 | #define V4L2_PIX_FMT_VP9 v4l2_fourcc('V', 'P', '9', '0') /* VP9 */ 127 | +#define V4L2_PIX_FMT_MPEG2_FRAME v4l2_fourcc('M', 'G', '2', 'F') /* MPEG2 frame */ 128 | 129 | /* Vendor-specific formats */ 130 | #define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */ 131 | @@ -1574,6 +1575,7 @@ struct v4l2_ext_control { 132 | __u8 __user *p_u8; 133 | __u16 __user *p_u16; 134 | __u32 __user *p_u32; 135 | + struct v4l2_ctrl_mpeg2_frame_hdr __user *p_mpeg2_frame_hdr; 136 | void __user *ptr; 137 | }; 138 | } __attribute__ ((packed)); 139 | @@ -1618,6 +1620,9 @@ enum v4l2_ctrl_type { 140 | V4L2_CTRL_TYPE_U8 = 0x0100, 141 | V4L2_CTRL_TYPE_U16 = 0x0101, 142 | V4L2_CTRL_TYPE_U32 = 0x0102, 143 | + V4L2_CTRL_TYPE_MPEG2_FRAME_HDR = 0x0109, 144 | + 145 | + V4L2_CTRL_TYPE_PRIVATE = 0xffff, 146 | }; 147 | 148 | /* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */ 149 | -- 150 | 2.14.3 151 | 152 | -------------------------------------------------------------------------------- /libva/src/context.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "sunxi_cedrus_drv_video.h" 27 | #include "context.h" 28 | #include "va_config.h" 29 | #include "surface.h" 30 | 31 | #include 32 | #include 33 | 34 | #include 35 | 36 | #include 37 | 38 | #include 39 | 40 | /* 41 | * A Context is a global data structure used for rendering a video of a certain 42 | * format. When a context is created, input buffers are created and v4l's output 43 | * (which is the compressed data input queue, since capture is the real output) 44 | * format is set. 45 | */ 46 | 47 | VAStatus sunxi_cedrus_CreateContext(VADriverContextP ctx, VAConfigID config_id, 48 | int picture_width, int picture_height, int flag, 49 | VASurfaceID *render_targets, int num_render_targets, 50 | VAContextID *context) 51 | { 52 | INIT_DRIVER_DATA 53 | VAStatus vaStatus = VA_STATUS_SUCCESS; 54 | object_config_p obj_config; 55 | int i; 56 | struct v4l2_create_buffers create_bufs; 57 | struct v4l2_format fmt; 58 | enum v4l2_buf_type type; 59 | 60 | obj_config = CONFIG(config_id); 61 | if (NULL == obj_config) 62 | { 63 | vaStatus = VA_STATUS_ERROR_INVALID_CONFIG; 64 | return vaStatus; 65 | } 66 | 67 | int contextID = object_heap_allocate(&driver_data->context_heap); 68 | object_context_p obj_context = CONTEXT(contextID); 69 | if (NULL == obj_context) 70 | { 71 | vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; 72 | return vaStatus; 73 | } 74 | 75 | obj_context->context_id = contextID; 76 | *context = contextID; 77 | obj_context->current_render_target = -1; 78 | obj_context->config_id = config_id; 79 | obj_context->picture_width = picture_width; 80 | obj_context->picture_height = picture_height; 81 | obj_context->num_render_targets = num_render_targets; 82 | obj_context->render_targets = (VASurfaceID *) malloc(num_render_targets * sizeof(VASurfaceID)); 83 | obj_context->num_rendered_surfaces = 0; 84 | 85 | if (obj_context->render_targets == NULL) 86 | { 87 | vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; 88 | return vaStatus; 89 | } 90 | 91 | for(i = 0; i < num_render_targets; i++) 92 | { 93 | if (NULL == SURFACE(render_targets[i])) 94 | { 95 | vaStatus = VA_STATUS_ERROR_INVALID_SURFACE; 96 | break; 97 | } 98 | obj_context->render_targets[i] = render_targets[i]; 99 | } 100 | obj_context->flags = flag; 101 | 102 | /* Error recovery */ 103 | if (VA_STATUS_SUCCESS != vaStatus) 104 | { 105 | obj_context->context_id = -1; 106 | obj_context->config_id = -1; 107 | free(obj_context->render_targets); 108 | obj_context->render_targets = NULL; 109 | obj_context->num_render_targets = 0; 110 | obj_context->flags = 0; 111 | object_heap_free(&driver_data->context_heap, (object_base_p) obj_context); 112 | } 113 | 114 | memset(&(fmt), 0, sizeof(fmt)); 115 | fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 116 | fmt.fmt.pix_mp.width = picture_width; 117 | fmt.fmt.pix_mp.height = picture_height; 118 | fmt.fmt.pix_mp.plane_fmt[0].sizeimage = INPUT_BUFFER_MAX_SIZE; 119 | switch(obj_config->profile) { 120 | case VAProfileMPEG2Simple: 121 | case VAProfileMPEG2Main: 122 | fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_MPEG2_FRAME; 123 | break; 124 | case VAProfileMPEG4Simple: 125 | case VAProfileMPEG4AdvancedSimple: 126 | case VAProfileMPEG4Main: 127 | fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_MPEG4_FRAME; 128 | break; 129 | default: 130 | vaStatus = VA_STATUS_ERROR_UNSUPPORTED_PROFILE; 131 | return vaStatus; 132 | break; 133 | } 134 | fmt.fmt.pix_mp.field = V4L2_FIELD_ANY; 135 | fmt.fmt.pix_mp.num_planes = 1; 136 | assert(ioctl(driver_data->mem2mem_fd, VIDIOC_S_FMT, &fmt)==0); 137 | 138 | memset (&create_bufs, 0, sizeof (struct v4l2_create_buffers)); 139 | create_bufs.count = INPUT_BUFFERS_NB; 140 | create_bufs.memory = V4L2_MEMORY_MMAP; 141 | create_bufs.format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 142 | assert(ioctl(driver_data->mem2mem_fd, VIDIOC_G_FMT, &create_bufs.format)==0); 143 | assert(ioctl(driver_data->mem2mem_fd, VIDIOC_CREATE_BUFS, &create_bufs)==0); 144 | 145 | type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 146 | assert(ioctl(driver_data->mem2mem_fd, VIDIOC_STREAMON, &type)==0); 147 | 148 | type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 149 | assert(ioctl(driver_data->mem2mem_fd, VIDIOC_STREAMON, &type)==0); 150 | 151 | return vaStatus; 152 | } 153 | 154 | VAStatus sunxi_cedrus_DestroyContext(VADriverContextP ctx, VAContextID context) 155 | { 156 | INIT_DRIVER_DATA 157 | object_context_p obj_context = CONTEXT(context); 158 | assert(obj_context); 159 | 160 | obj_context->context_id = -1; 161 | obj_context->config_id = -1; 162 | obj_context->picture_width = 0; 163 | obj_context->picture_height = 0; 164 | if (obj_context->render_targets) 165 | free(obj_context->render_targets); 166 | obj_context->render_targets = NULL; 167 | obj_context->num_render_targets = 0; 168 | obj_context->flags = 0; 169 | 170 | obj_context->current_render_target = -1; 171 | 172 | object_heap_free(&driver_data->context_heap, (object_base_p) obj_context); 173 | 174 | return VA_STATUS_SUCCESS; 175 | } 176 | 177 | -------------------------------------------------------------------------------- /libva/src/buffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "sunxi_cedrus_drv_video.h" 27 | #include "buffer.h" 28 | #include "context.h" 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | 37 | #include 38 | 39 | /* 40 | * A Buffer is a memory zone used to handle all kind of data, for example an IQ 41 | * matrix or image buffer (which are allocated using realloc) or slice data 42 | * (which are mmapped from v4l's kernel space) 43 | */ 44 | 45 | VAStatus sunxi_cedrus_CreateBuffer(VADriverContextP ctx, VAContextID context, 46 | VABufferType type, unsigned int size, unsigned int num_elements, 47 | void *data, VABufferID *buf_id) 48 | { 49 | INIT_DRIVER_DATA 50 | VAStatus vaStatus = VA_STATUS_SUCCESS; 51 | int bufferID; 52 | struct v4l2_plane plane[1]; 53 | object_buffer_p obj_buffer; 54 | 55 | memset(plane, 0, sizeof(struct v4l2_plane)); 56 | 57 | /* Validate type */ 58 | switch (type) 59 | { 60 | case VAPictureParameterBufferType: 61 | case VAIQMatrixBufferType: /* Ignored */ 62 | case VASliceParameterBufferType: 63 | case VASliceDataBufferType: 64 | case VAImageBufferType: 65 | /* Ok */ 66 | break; 67 | default: 68 | vaStatus = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE; 69 | return vaStatus; 70 | } 71 | 72 | bufferID = object_heap_allocate(&driver_data->buffer_heap); 73 | obj_buffer = BUFFER(bufferID); 74 | if (NULL == obj_buffer) 75 | { 76 | vaStatus = VA_STATUS_ERROR_ALLOCATION_FAILED; 77 | return vaStatus; 78 | } 79 | 80 | obj_buffer->buffer_data = NULL; 81 | obj_buffer->type = type; 82 | 83 | if(obj_buffer->type == VASliceDataBufferType) { 84 | object_context_p obj_context; 85 | 86 | obj_context = CONTEXT(context); 87 | assert(obj_context); 88 | 89 | struct v4l2_buffer buf; 90 | memset(&(buf), 0, sizeof(buf)); 91 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 92 | buf.memory = V4L2_MEMORY_MMAP; 93 | buf.index = obj_context->num_rendered_surfaces%INPUT_BUFFERS_NB; 94 | buf.length = 1; 95 | buf.m.planes = plane; 96 | 97 | assert(ioctl(driver_data->mem2mem_fd, VIDIOC_QUERYBUF, &buf)==0); 98 | 99 | obj_buffer->buffer_data = mmap(NULL, size * num_elements, 100 | PROT_READ | PROT_WRITE, MAP_SHARED, 101 | driver_data->mem2mem_fd, buf.m.planes[0].m.mem_offset); 102 | } else 103 | obj_buffer->buffer_data = realloc(obj_buffer->buffer_data, size * num_elements); 104 | 105 | if (obj_buffer->buffer_data == NULL) 106 | return VA_STATUS_ERROR_ALLOCATION_FAILED; 107 | 108 | if (VA_STATUS_SUCCESS == vaStatus) 109 | { 110 | obj_buffer->max_num_elements = num_elements; 111 | obj_buffer->num_elements = num_elements; 112 | obj_buffer->size = size; 113 | 114 | if (data) 115 | memcpy(obj_buffer->buffer_data, data, 116 | size * num_elements); 117 | } 118 | 119 | if (VA_STATUS_SUCCESS == vaStatus) 120 | *buf_id = bufferID; 121 | 122 | return vaStatus; 123 | } 124 | 125 | VAStatus sunxi_cedrus_BufferSetNumElements(VADriverContextP ctx, 126 | VABufferID buf_id, unsigned int num_elements) 127 | { 128 | INIT_DRIVER_DATA 129 | VAStatus vaStatus = VA_STATUS_SUCCESS; 130 | object_buffer_p obj_buffer = BUFFER(buf_id); 131 | assert(obj_buffer); 132 | 133 | if ((num_elements < 0) || (num_elements > obj_buffer->max_num_elements)) 134 | vaStatus = VA_STATUS_ERROR_UNKNOWN; 135 | if (VA_STATUS_SUCCESS == vaStatus) 136 | obj_buffer->num_elements = num_elements; 137 | 138 | return vaStatus; 139 | } 140 | 141 | VAStatus sunxi_cedrus_MapBuffer(VADriverContextP ctx, VABufferID buf_id, 142 | void **pbuf) 143 | { 144 | INIT_DRIVER_DATA 145 | VAStatus vaStatus = VA_STATUS_ERROR_UNKNOWN; 146 | object_buffer_p obj_buffer = BUFFER(buf_id); 147 | assert(obj_buffer); 148 | if (NULL == obj_buffer) 149 | { 150 | vaStatus = VA_STATUS_ERROR_INVALID_BUFFER; 151 | return vaStatus; 152 | } 153 | 154 | if (NULL != obj_buffer->buffer_data) 155 | { 156 | *pbuf = obj_buffer->buffer_data; 157 | vaStatus = VA_STATUS_SUCCESS; 158 | } 159 | return vaStatus; 160 | } 161 | 162 | VAStatus sunxi_cedrus_UnmapBuffer(VADriverContextP ctx, VABufferID buf_id) 163 | { 164 | /* Do nothing */ 165 | return VA_STATUS_SUCCESS; 166 | } 167 | 168 | void sunxi_cedrus_destroy_buffer(struct sunxi_cedrus_driver_data *driver_data, 169 | object_buffer_p obj_buffer) 170 | { 171 | if (NULL != obj_buffer->buffer_data) 172 | { 173 | if(obj_buffer->type == VASliceDataBufferType) 174 | munmap(obj_buffer->buffer_data, obj_buffer->size); 175 | else 176 | free(obj_buffer->buffer_data); 177 | 178 | obj_buffer->buffer_data = NULL; 179 | } 180 | 181 | object_heap_free(&driver_data->buffer_heap, (object_base_p) obj_buffer); 182 | } 183 | 184 | VAStatus sunxi_cedrus_DestroyBuffer(VADriverContextP ctx, VABufferID buffer_id) 185 | { 186 | INIT_DRIVER_DATA 187 | object_buffer_p obj_buffer = BUFFER(buffer_id); 188 | assert(obj_buffer); 189 | 190 | sunxi_cedrus_destroy_buffer(driver_data, obj_buffer); 191 | return VA_STATUS_SUCCESS; 192 | } 193 | 194 | /* sunxi-cedrus doesn't support buffer info */ 195 | VAStatus sunxi_cedrus_BufferInfo(VADriverContextP ctx, VABufferID buf_id, 196 | VABufferType *type, unsigned int *size, 197 | unsigned int *num_elements) 198 | { return VA_STATUS_ERROR_UNIMPLEMENTED; } 199 | -------------------------------------------------------------------------------- /libva/src/mpeg4.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Florent Revest, 3 | * 2007 Intel Corporation. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a 6 | * copy of this software and associated documentation files (the 7 | * "Software"), to deal in the Software without restriction, including 8 | * without limitation the rights to use, copy, modify, merge, publish, 9 | * distribute, sub license, and/or sell copies of the Software, and to 10 | * permit persons to whom the Software is furnished to do so, subject to 11 | * the following conditions: 12 | * 13 | * The above copyright notice and this permission notice (including the 14 | * next paragraph) shall be included in all copies or substantial portions 15 | * of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 20 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "sunxi_cedrus_drv_video.h" 27 | #include "mpeg4.h" 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | 37 | /* 38 | * This file takes care of filling v4l2's frame API MPEG4 headers extended 39 | * controls from VA's data structures. 40 | */ 41 | 42 | VAStatus sunxi_cedrus_render_mpeg4_slice_data(VADriverContextP ctx, 43 | object_context_p obj_context, object_surface_p obj_surface, 44 | object_buffer_p obj_buffer) 45 | { 46 | INIT_DRIVER_DATA 47 | VAStatus vaStatus = VA_STATUS_SUCCESS; 48 | struct v4l2_buffer buf; 49 | struct v4l2_plane plane[1]; 50 | 51 | memset(plane, 0, sizeof(struct v4l2_plane)); 52 | 53 | /* Query */ 54 | memset(&(buf), 0, sizeof(buf)); 55 | buf.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; 56 | buf.memory = V4L2_MEMORY_MMAP; 57 | buf.index = obj_surface->input_buf_index; 58 | buf.length = 1; 59 | buf.m.planes = plane; 60 | 61 | assert(ioctl(driver_data->mem2mem_fd, VIDIOC_QUERYBUF, &buf)==0); 62 | 63 | /* Populate frame */ 64 | char *src_buf = mmap(NULL, obj_buffer->size, 65 | PROT_READ | PROT_WRITE, MAP_SHARED, 66 | driver_data->mem2mem_fd, buf.m.planes[0].m.mem_offset); 67 | assert(src_buf != MAP_FAILED); 68 | memcpy(src_buf, obj_buffer->buffer_data, obj_buffer->size); 69 | 70 | return vaStatus; 71 | } 72 | 73 | VAStatus sunxi_cedrus_render_mpeg4_picture_parameter(VADriverContextP ctx, 74 | object_context_p obj_context, object_surface_p obj_surface, 75 | object_buffer_p obj_buffer) 76 | { 77 | INIT_DRIVER_DATA 78 | VAStatus vaStatus = VA_STATUS_SUCCESS; 79 | 80 | VAPictureParameterBufferMPEG4 *pic_param = (VAPictureParameterBufferMPEG4 *)obj_buffer->buffer_data; 81 | 82 | obj_context->mpeg4_frame_hdr.width = pic_param->vop_width; 83 | obj_context->mpeg4_frame_hdr.height = pic_param->vop_height; 84 | 85 | obj_context->mpeg4_frame_hdr.vol_fields.short_video_header = pic_param->vol_fields.bits.short_video_header; 86 | obj_context->mpeg4_frame_hdr.vol_fields.chroma_format = pic_param->vol_fields.bits.chroma_format; 87 | obj_context->mpeg4_frame_hdr.vol_fields.interlaced = pic_param->vol_fields.bits.interlaced; 88 | obj_context->mpeg4_frame_hdr.vol_fields.obmc_disable = pic_param->vol_fields.bits.obmc_disable; 89 | obj_context->mpeg4_frame_hdr.vol_fields.sprite_enable = pic_param->vol_fields.bits.sprite_enable; 90 | obj_context->mpeg4_frame_hdr.vol_fields.sprite_warping_accuracy = pic_param->vol_fields.bits.sprite_warping_accuracy; 91 | obj_context->mpeg4_frame_hdr.vol_fields.quant_type = pic_param->vol_fields.bits.quant_type; 92 | obj_context->mpeg4_frame_hdr.vol_fields.quarter_sample = pic_param->vol_fields.bits.quarter_sample; 93 | obj_context->mpeg4_frame_hdr.vol_fields.data_partitioned = pic_param->vol_fields.bits.data_partitioned; 94 | obj_context->mpeg4_frame_hdr.vol_fields.reversible_vlc = pic_param->vol_fields.bits.reversible_vlc; 95 | obj_context->mpeg4_frame_hdr.vol_fields.resync_marker_disable = pic_param->vol_fields.bits.resync_marker_disable; 96 | 97 | obj_context->mpeg4_frame_hdr.vop_fields.vop_coding_type = pic_param->vop_fields.bits.vop_coding_type; 98 | obj_context->mpeg4_frame_hdr.vop_fields.backward_reference_vop_coding_type = pic_param->vop_fields.bits.backward_reference_vop_coding_type; 99 | obj_context->mpeg4_frame_hdr.vop_fields.vop_rounding_type = pic_param->vop_fields.bits.vop_rounding_type; 100 | obj_context->mpeg4_frame_hdr.vop_fields.intra_dc_vlc_thr = pic_param->vop_fields.bits.intra_dc_vlc_thr; 101 | obj_context->mpeg4_frame_hdr.vop_fields.top_field_first = pic_param->vop_fields.bits.top_field_first; 102 | obj_context->mpeg4_frame_hdr.vop_fields.alternate_vertical_scan_flag = pic_param->vop_fields.bits.alternate_vertical_scan_flag; 103 | 104 | obj_context->mpeg4_frame_hdr.vop_fcode_forward = pic_param->vop_fcode_forward; 105 | obj_context->mpeg4_frame_hdr.vop_fcode_backward = pic_param->vop_fcode_backward; 106 | 107 | obj_context->mpeg4_frame_hdr.trb = pic_param->TRB; 108 | obj_context->mpeg4_frame_hdr.trd = pic_param->TRD; 109 | 110 | object_surface_p fwd_surface = SURFACE(pic_param->forward_reference_picture); 111 | if(fwd_surface) 112 | obj_context->mpeg4_frame_hdr.forward_index = fwd_surface->output_buf_index; 113 | else 114 | obj_context->mpeg4_frame_hdr.forward_index = obj_surface->output_buf_index; 115 | object_surface_p bwd_surface = SURFACE(pic_param->backward_reference_picture); 116 | if(bwd_surface) 117 | obj_context->mpeg4_frame_hdr.backward_index = bwd_surface->output_buf_index; 118 | else 119 | obj_context->mpeg4_frame_hdr.backward_index = obj_surface->output_buf_index; 120 | 121 | return vaStatus; 122 | } 123 | 124 | VAStatus sunxi_cedrus_render_mpeg4_slice_parameter(VADriverContextP ctx, 125 | object_context_p obj_context, object_surface_p obj_surface, 126 | object_buffer_p obj_buffer) 127 | { 128 | VASliceParameterBufferMPEG4 *slice_param = (VASliceParameterBufferMPEG4 *)obj_buffer->buffer_data; 129 | 130 | obj_context->mpeg4_frame_hdr.slice_pos = slice_param->slice_data_offset*8+slice_param->macroblock_offset; 131 | obj_context->mpeg4_frame_hdr.slice_len = slice_param->slice_data_size*8; 132 | obj_context->mpeg4_frame_hdr.quant_scale = slice_param->quant_scale; 133 | 134 | return VA_STATUS_SUCCESS; 135 | } 136 | 137 | -------------------------------------------------------------------------------- /patches/4.14/0018-v4l-Add-MPEG4-low-level-decoder-API-control.patch: -------------------------------------------------------------------------------- 1 | From 544f4452d461f29da03dff06736268624889a3d5 Mon Sep 17 00:00:00 2001 2 | From: Florent Revest 3 | Date: Wed, 24 Aug 2016 13:45:18 +0200 4 | Subject: [PATCH 18/22] v4l: Add MPEG4 low-level decoder API control 5 | 6 | This control is to be used with the new low-level decoder API for MPEG4 7 | to provide additional parameters for the hardware that cannot parse the 8 | input stream. 9 | 10 | Some fields are still missing for this structure to be complete. 11 | 12 | Signed-off-by: Florent Revest 13 | --- 14 | drivers/media/v4l2-core/v4l2-ctrls.c | 8 +++++++ 15 | drivers/media/v4l2-core/v4l2-ioctl.c | 1 + 16 | include/uapi/linux/v4l2-controls.h | 42 ++++++++++++++++++++++++++++++++++++ 17 | include/uapi/linux/videodev2.h | 3 +++ 18 | 4 files changed, 54 insertions(+) 19 | 20 | diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c 21 | index 7f6488aa5434..7107e46b761b 100644 22 | --- a/drivers/media/v4l2-core/v4l2-ctrls.c 23 | +++ b/drivers/media/v4l2-core/v4l2-ctrls.c 24 | @@ -763,6 +763,7 @@ const char *v4l2_ctrl_get_name(u32 id) 25 | case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: return "Force Key Frame"; 26 | 27 | case V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR: return "MPEG2 Frame Header"; 28 | + case V4L2_CID_MPEG_VIDEO_MPEG4_FRAME_HDR: return "MPEG4 Frame Header"; 29 | 30 | /* VPX controls */ 31 | case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS: return "VPX Number of Partitions"; 32 | @@ -1157,6 +1158,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, 33 | case V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR: 34 | *type = V4L2_CTRL_TYPE_MPEG2_FRAME_HDR; 35 | break; 36 | + case V4L2_CID_MPEG_VIDEO_MPEG4_FRAME_HDR: 37 | + *type = V4L2_CTRL_TYPE_MPEG4_FRAME_HDR; 38 | + break; 39 | default: 40 | *type = V4L2_CTRL_TYPE_INTEGER; 41 | break; 42 | @@ -1558,6 +1562,7 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx, 43 | return 0; 44 | 45 | case V4L2_CTRL_TYPE_MPEG2_FRAME_HDR: 46 | + case V4L2_CTRL_TYPE_MPEG4_FRAME_HDR: 47 | return 0; 48 | 49 | /* FIXME:just return 0 for now */ 50 | @@ -2118,6 +2123,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, 51 | case V4L2_CTRL_TYPE_MPEG2_FRAME_HDR: 52 | elem_size = sizeof(struct v4l2_ctrl_mpeg2_frame_hdr); 53 | break; 54 | + case V4L2_CTRL_TYPE_MPEG4_FRAME_HDR: 55 | + elem_size = sizeof(struct v4l2_ctrl_mpeg4_frame_hdr); 56 | + break; 57 | default: 58 | if (type < V4L2_CTRL_COMPOUND_TYPES) 59 | elem_size = sizeof(s32); 60 | diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c 61 | index 9f7bd65e5573..b85c15111d06 100644 62 | --- a/drivers/media/v4l2-core/v4l2-ioctl.c 63 | +++ b/drivers/media/v4l2-core/v4l2-ioctl.c 64 | @@ -1275,6 +1275,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) 65 | case V4L2_PIX_FMT_VP8: descr = "VP8"; break; 66 | case V4L2_PIX_FMT_VP9: descr = "VP9"; break; 67 | case V4L2_PIX_FMT_MPEG2_FRAME: descr = "MPEG2 FRAME"; break; 68 | + case V4L2_PIX_FMT_MPEG4_FRAME: descr = "MPEG4 FRAME"; break; 69 | case V4L2_PIX_FMT_CPIA1: descr = "GSPCA CPiA YUV"; break; 70 | case V4L2_PIX_FMT_WNVA: descr = "WNVA"; break; 71 | case V4L2_PIX_FMT_SN9C10X: descr = "GSPCA SN9C10X"; break; 72 | diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h 73 | index 441a7f90867e..abafa5d3cea1 100644 74 | --- a/include/uapi/linux/v4l2-controls.h 75 | +++ b/include/uapi/linux/v4l2-controls.h 76 | @@ -558,6 +558,7 @@ enum v4l2_mpeg_video_mpeg4_profile { 77 | #define V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (V4L2_CID_MPEG_BASE+407) 78 | 79 | #define V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR (V4L2_CID_MPEG_BASE+450) 80 | +#define V4L2_CID_MPEG_VIDEO_MPEG4_FRAME_HDR (V4L2_CID_MPEG_BASE+451) 81 | 82 | /* Control IDs for VP8 streams 83 | * Although VP8 is not part of MPEG we add these controls to the MPEG class 84 | @@ -1011,4 +1012,45 @@ struct v4l2_ctrl_mpeg2_frame_hdr { 85 | __u8 forward_index; 86 | }; 87 | 88 | +struct v4l2_ctrl_mpeg4_frame_hdr { 89 | + __u32 slice_len; 90 | + __u32 slice_pos; 91 | + unsigned char quant_scale; 92 | + 93 | + __u16 width; 94 | + __u16 height; 95 | + 96 | + struct { 97 | + unsigned int short_video_header : 1; 98 | + unsigned int chroma_format : 2; 99 | + unsigned int interlaced : 1; 100 | + unsigned int obmc_disable : 1; 101 | + unsigned int sprite_enable : 2; 102 | + unsigned int sprite_warping_accuracy : 2; 103 | + unsigned int quant_type : 1; 104 | + unsigned int quarter_sample : 1; 105 | + unsigned int data_partitioned : 1; 106 | + unsigned int reversible_vlc : 1; 107 | + unsigned int resync_marker_disable : 1; 108 | + } vol_fields; 109 | + 110 | + struct { 111 | + unsigned int vop_coding_type : 2; 112 | + unsigned int backward_reference_vop_coding_type : 2; 113 | + unsigned int vop_rounding_type : 1; 114 | + unsigned int intra_dc_vlc_thr : 3; 115 | + unsigned int top_field_first : 1; 116 | + unsigned int alternate_vertical_scan_flag : 1; 117 | + } vop_fields; 118 | + 119 | + unsigned char vop_fcode_forward; 120 | + unsigned char vop_fcode_backward; 121 | + 122 | + short trb; 123 | + short trd; 124 | + 125 | + __u8 backward_index; 126 | + __u8 forward_index; 127 | +}; 128 | + 129 | #endif 130 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 131 | index 715c0d88805c..f9e15a9e79f4 100644 132 | --- a/include/uapi/linux/videodev2.h 133 | +++ b/include/uapi/linux/videodev2.h 134 | @@ -636,6 +636,7 @@ struct v4l2_pix_format { 135 | #define V4L2_PIX_FMT_VP8 v4l2_fourcc('V', 'P', '8', '0') /* VP8 */ 136 | #define V4L2_PIX_FMT_VP9 v4l2_fourcc('V', 'P', '9', '0') /* VP9 */ 137 | #define V4L2_PIX_FMT_MPEG2_FRAME v4l2_fourcc('M', 'G', '2', 'F') /* MPEG2 frame */ 138 | +#define V4L2_PIX_FMT_MPEG4_FRAME v4l2_fourcc('M', 'G', '4', 'F') /* MPEG4 frame */ 139 | 140 | /* Vendor-specific formats */ 141 | #define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */ 142 | @@ -1576,6 +1577,7 @@ struct v4l2_ext_control { 143 | __u16 __user *p_u16; 144 | __u32 __user *p_u32; 145 | struct v4l2_ctrl_mpeg2_frame_hdr __user *p_mpeg2_frame_hdr; 146 | + struct v4l2_ctrl_mpeg4_frame_hdr __user *p_mpeg4_frame_hdr; 147 | void __user *ptr; 148 | }; 149 | } __attribute__ ((packed)); 150 | @@ -1621,6 +1623,7 @@ enum v4l2_ctrl_type { 151 | V4L2_CTRL_TYPE_U16 = 0x0101, 152 | V4L2_CTRL_TYPE_U32 = 0x0102, 153 | V4L2_CTRL_TYPE_MPEG2_FRAME_HDR = 0x0109, 154 | + V4L2_CTRL_TYPE_MPEG4_FRAME_HDR = 0x010A, 155 | 156 | V4L2_CTRL_TYPE_PRIVATE = 0xffff, 157 | }; 158 | -- 159 | 2.14.3 160 | 161 | -------------------------------------------------------------------------------- /patches/4.9/0019-v4l-Add-MPEG4-low-level-decoder-API-control.patch: -------------------------------------------------------------------------------- 1 | From b13317919b787ceb49403d7da42f798df348acf1 Mon Sep 17 00:00:00 2001 2 | From: Florent Revest 3 | Date: Wed, 24 Aug 2016 13:45:18 +0200 4 | Subject: [PATCH] v4l: Add MPEG4 low-level decoder API control 5 | 6 | This control is to be used with the new low-level decoder API for MPEG4 7 | to provide additional parameters for the hardware that cannot parse the 8 | input stream. 9 | 10 | Some fields are still missing for this structure to be complete. 11 | 12 | Signed-off-by: Florent Revest 13 | --- 14 | drivers/media/v4l2-core/v4l2-ctrls.c | 8 +++++++ 15 | drivers/media/v4l2-core/v4l2-ioctl.c | 1 + 16 | include/uapi/linux/v4l2-controls.h | 42 ++++++++++++++++++++++++++++++++++++ 17 | include/uapi/linux/videodev2.h | 3 +++ 18 | 4 files changed, 54 insertions(+) 19 | 20 | diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c 21 | index 355c7d8549a9..b6d55939b39c 100644 22 | --- a/drivers/media/v4l2-core/v4l2-ctrls.c 23 | +++ b/drivers/media/v4l2-core/v4l2-ctrls.c 24 | @@ -762,6 +762,7 @@ const char *v4l2_ctrl_get_name(u32 id) 25 | case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: return "Force Key Frame"; 26 | 27 | case V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR: return "MPEG2 Frame Header"; 28 | + case V4L2_CID_MPEG_VIDEO_MPEG4_FRAME_HDR: return "MPEG4 Frame Header"; 29 | 30 | /* VPX controls */ 31 | case V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS: return "VPX Number of Partitions"; 32 | @@ -1149,6 +1150,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type, 33 | case V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR: 34 | *type = V4L2_CTRL_TYPE_MPEG2_FRAME_HDR; 35 | break; 36 | + case V4L2_CID_MPEG_VIDEO_MPEG4_FRAME_HDR: 37 | + *type = V4L2_CTRL_TYPE_MPEG4_FRAME_HDR; 38 | + break; 39 | default: 40 | *type = V4L2_CTRL_TYPE_INTEGER; 41 | break; 42 | @@ -1550,6 +1554,7 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx, 43 | return 0; 44 | 45 | case V4L2_CTRL_TYPE_MPEG2_FRAME_HDR: 46 | + case V4L2_CTRL_TYPE_MPEG4_FRAME_HDR: 47 | return 0; 48 | 49 | /* FIXME:just return 0 for now */ 50 | @@ -2108,6 +2113,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl, 51 | case V4L2_CTRL_TYPE_MPEG2_FRAME_HDR: 52 | elem_size = sizeof(struct v4l2_ctrl_mpeg2_frame_hdr); 53 | break; 54 | + case V4L2_CTRL_TYPE_MPEG4_FRAME_HDR: 55 | + elem_size = sizeof(struct v4l2_ctrl_mpeg4_frame_hdr); 56 | + break; 57 | default: 58 | if (type < V4L2_CTRL_COMPOUND_TYPES) 59 | elem_size = sizeof(s32); 60 | diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c 61 | index 6c0f13b47522..a2255bd10ae0 100644 62 | --- a/drivers/media/v4l2-core/v4l2-ioctl.c 63 | +++ b/drivers/media/v4l2-core/v4l2-ioctl.c 64 | @@ -1279,6 +1279,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) 65 | case V4L2_PIX_FMT_VC1_ANNEX_L: descr = "VC-1 (SMPTE 412M Annex L)"; break; 66 | case V4L2_PIX_FMT_VP8: descr = "VP8"; break; 67 | case V4L2_PIX_FMT_MPEG2_FRAME: descr = "MPEG2 FRAME"; break; 68 | + case V4L2_PIX_FMT_MPEG4_FRAME: descr = "MPEG4 FRAME"; break; 69 | case V4L2_PIX_FMT_CPIA1: descr = "GSPCA CPiA YUV"; break; 70 | case V4L2_PIX_FMT_WNVA: descr = "WNVA"; break; 71 | case V4L2_PIX_FMT_SN9C10X: descr = "GSPCA SN9C10X"; break; 72 | diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h 73 | index cdf94971b230..af466ca4b507 100644 74 | --- a/include/uapi/linux/v4l2-controls.h 75 | +++ b/include/uapi/linux/v4l2-controls.h 76 | @@ -548,6 +548,7 @@ enum v4l2_mpeg_video_mpeg4_profile { 77 | #define V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (V4L2_CID_MPEG_BASE+407) 78 | 79 | #define V4L2_CID_MPEG_VIDEO_MPEG2_FRAME_HDR (V4L2_CID_MPEG_BASE+450) 80 | +#define V4L2_CID_MPEG_VIDEO_MPEG4_FRAME_HDR (V4L2_CID_MPEG_BASE+451) 81 | 82 | /* Control IDs for VP8 streams 83 | * Although VP8 is not part of MPEG we add these controls to the MPEG class 84 | @@ -1000,4 +1001,45 @@ struct v4l2_ctrl_mpeg2_frame_hdr { 85 | __u8 forward_index; 86 | }; 87 | 88 | +struct v4l2_ctrl_mpeg4_frame_hdr { 89 | + __u32 slice_len; 90 | + __u32 slice_pos; 91 | + unsigned char quant_scale; 92 | + 93 | + __u16 width; 94 | + __u16 height; 95 | + 96 | + struct { 97 | + unsigned int short_video_header : 1; 98 | + unsigned int chroma_format : 2; 99 | + unsigned int interlaced : 1; 100 | + unsigned int obmc_disable : 1; 101 | + unsigned int sprite_enable : 2; 102 | + unsigned int sprite_warping_accuracy : 2; 103 | + unsigned int quant_type : 1; 104 | + unsigned int quarter_sample : 1; 105 | + unsigned int data_partitioned : 1; 106 | + unsigned int reversible_vlc : 1; 107 | + unsigned int resync_marker_disable : 1; 108 | + } vol_fields; 109 | + 110 | + struct { 111 | + unsigned int vop_coding_type : 2; 112 | + unsigned int backward_reference_vop_coding_type : 2; 113 | + unsigned int vop_rounding_type : 1; 114 | + unsigned int intra_dc_vlc_thr : 3; 115 | + unsigned int top_field_first : 1; 116 | + unsigned int alternate_vertical_scan_flag : 1; 117 | + } vop_fields; 118 | + 119 | + unsigned char vop_fcode_forward; 120 | + unsigned char vop_fcode_backward; 121 | + 122 | + short trb; 123 | + short trd; 124 | + 125 | + __u8 backward_index; 126 | + __u8 forward_index; 127 | +}; 128 | + 129 | #endif 130 | diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h 131 | index a7fba0170b28..af6c4465eb0c 100644 132 | --- a/include/uapi/linux/videodev2.h 133 | +++ b/include/uapi/linux/videodev2.h 134 | @@ -604,6 +604,7 @@ struct v4l2_pix_format { 135 | #define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */ 136 | #define V4L2_PIX_FMT_VP8 v4l2_fourcc('V', 'P', '8', '0') /* VP8 */ 137 | #define V4L2_PIX_FMT_MPEG2_FRAME v4l2_fourcc('M', 'G', '2', 'F') /* MPEG2 frame */ 138 | +#define V4L2_PIX_FMT_MPEG4_FRAME v4l2_fourcc('M', 'G', '4', 'F') /* MPEG4 frame */ 139 | 140 | /* Vendor-specific formats */ 141 | #define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */ 142 | @@ -1502,6 +1503,7 @@ struct v4l2_ext_control { 143 | __u16 __user *p_u16; 144 | __u32 __user *p_u32; 145 | struct v4l2_ctrl_mpeg2_frame_hdr __user *p_mpeg2_frame_hdr; 146 | + struct v4l2_ctrl_mpeg4_frame_hdr __user *p_mpeg4_frame_hdr; 147 | void __user *ptr; 148 | }; 149 | } __attribute__ ((packed)); 150 | @@ -1547,6 +1549,7 @@ enum v4l2_ctrl_type { 151 | V4L2_CTRL_TYPE_U16 = 0x0101, 152 | V4L2_CTRL_TYPE_U32 = 0x0102, 153 | V4L2_CTRL_TYPE_MPEG2_FRAME_HDR = 0x0109, 154 | + V4L2_CTRL_TYPE_MPEG4_FRAME_HDR = 0x010A, 155 | 156 | V4L2_CTRL_TYPE_PRIVATE = 0xffff, 157 | }; 158 | -- 159 | 2.14.3 160 | 161 | -------------------------------------------------------------------------------- /libva/src/object_heap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Intel Corporation. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the 6 | * "Software"), to deal in the Software without restriction, including 7 | * without limitation the rights to use, copy, modify, merge, publish, 8 | * distribute, sub license, and/or sell copies of the Software, and to 9 | * permit persons to whom the Software is furnished to do so, subject to 10 | * the following conditions: 11 | * 12 | * The above copyright notice and this permission notice (including the 13 | * next paragraph) shall be included in all copies or substantial portions 14 | * of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 17 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 19 | * IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR 20 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | */ 24 | 25 | #include 26 | #include 27 | #include "object_heap.h" 28 | 29 | #define ASSERT assert 30 | 31 | #define LAST_FREE -1 32 | #define ALLOCATED -2 33 | 34 | /* 35 | * Expands the heap 36 | * Return 0 on success, -1 on error 37 | */ 38 | static int object_heap_expand(object_heap_p heap) 39 | { 40 | int i; 41 | void *new_heap_index; 42 | int next_free; 43 | int new_heap_size = heap->heap_size + heap->heap_increment; 44 | int bucket_index = new_heap_size / heap->heap_increment - 1; 45 | 46 | if (bucket_index >= heap->num_buckets) { 47 | int new_num_buckets = heap->num_buckets + 8; 48 | void **new_bucket; 49 | 50 | new_bucket = realloc(heap->bucket, new_num_buckets * sizeof(void *)); 51 | if (NULL == new_bucket) { 52 | return -1; 53 | } 54 | 55 | heap->num_buckets = new_num_buckets; 56 | heap->bucket = new_bucket; 57 | } 58 | 59 | new_heap_index = (void *) malloc(heap->heap_increment * heap->object_size); 60 | if (NULL == new_heap_index) { 61 | return -1; /* Out of memory */ 62 | } 63 | 64 | heap->bucket[bucket_index] = new_heap_index; 65 | next_free = heap->next_free; 66 | for (i = new_heap_size; i-- > heap->heap_size;) { 67 | object_base_p obj = (object_base_p)(new_heap_index + (i - heap->heap_size) * heap->object_size); 68 | obj->id = i + heap->id_offset; 69 | obj->next_free = next_free; 70 | next_free = i; 71 | } 72 | heap->next_free = next_free; 73 | heap->heap_size = new_heap_size; 74 | return 0; /* Success */ 75 | } 76 | 77 | /* 78 | * Return 0 on success, -1 on error 79 | */ 80 | int object_heap_init(object_heap_p heap, int object_size, int id_offset) 81 | { 82 | pthread_mutex_init(&heap->mutex, NULL); 83 | heap->object_size = object_size; 84 | heap->id_offset = id_offset & OBJECT_HEAP_OFFSET_MASK; 85 | heap->heap_size = 0; 86 | heap->heap_increment = 16; 87 | heap->next_free = LAST_FREE; 88 | heap->num_buckets = 0; 89 | heap->bucket = NULL; 90 | return object_heap_expand(heap); 91 | } 92 | 93 | /* 94 | * Allocates an object 95 | * Returns the object ID on success, returns -1 on error 96 | */ 97 | static int object_heap_allocate_unlocked(object_heap_p heap) 98 | { 99 | object_base_p obj; 100 | int bucket_index, obj_index; 101 | 102 | if (LAST_FREE == heap->next_free) { 103 | if (-1 == object_heap_expand(heap)) { 104 | return -1; /* Out of memory */ 105 | } 106 | } 107 | ASSERT(heap->next_free >= 0); 108 | 109 | bucket_index = heap->next_free / heap->heap_increment; 110 | obj_index = heap->next_free % heap->heap_increment; 111 | 112 | obj = (object_base_p)(heap->bucket[bucket_index] + obj_index * heap->object_size); 113 | heap->next_free = obj->next_free; 114 | obj->next_free = ALLOCATED; 115 | return obj->id; 116 | } 117 | 118 | int object_heap_allocate(object_heap_p heap) 119 | { 120 | int ret; 121 | 122 | pthread_mutex_lock(&heap->mutex); 123 | ret = object_heap_allocate_unlocked(heap); 124 | pthread_mutex_unlock(&heap->mutex); 125 | return ret; 126 | } 127 | 128 | /* 129 | * Lookup an object by object ID 130 | * Returns a pointer to the object on success, returns NULL on error 131 | */ 132 | static object_base_p object_heap_lookup_unlocked(object_heap_p heap, int id) 133 | { 134 | object_base_p obj; 135 | int bucket_index, obj_index; 136 | 137 | if ((id < heap->id_offset) || (id > (heap->heap_size + heap->id_offset))) { 138 | return NULL; 139 | } 140 | id &= OBJECT_HEAP_ID_MASK; 141 | bucket_index = id / heap->heap_increment; 142 | obj_index = id % heap->heap_increment; 143 | obj = (object_base_p)(heap->bucket[bucket_index] + obj_index * heap->object_size); 144 | 145 | /* Check if the object has in fact been allocated */ 146 | if (obj->next_free != ALLOCATED) { 147 | return NULL; 148 | } 149 | return obj; 150 | } 151 | 152 | object_base_p object_heap_lookup(object_heap_p heap, int id) 153 | { 154 | object_base_p obj; 155 | 156 | pthread_mutex_lock(&heap->mutex); 157 | obj = object_heap_lookup_unlocked(heap, id); 158 | pthread_mutex_unlock(&heap->mutex); 159 | return obj; 160 | } 161 | 162 | /* 163 | * Iterate over all objects in the heap. 164 | * Returns a pointer to the first object on the heap, returns NULL if heap is empty. 165 | */ 166 | object_base_p object_heap_first(object_heap_p heap, object_heap_iterator *iter) 167 | { 168 | *iter = -1; 169 | return object_heap_next(heap, iter); 170 | } 171 | 172 | /* 173 | * Iterate over all objects in the heap. 174 | * Returns a pointer to the next object on the heap, returns NULL if heap is empty. 175 | */ 176 | static object_base_p object_heap_next_unlocked(object_heap_p heap, object_heap_iterator *iter) 177 | { 178 | object_base_p obj; 179 | int bucket_index, obj_index; 180 | int i = *iter + 1; 181 | 182 | while (i < heap->heap_size) { 183 | bucket_index = i / heap->heap_increment; 184 | obj_index = i % heap->heap_increment; 185 | 186 | obj = (object_base_p)(heap->bucket[bucket_index] + obj_index * heap->object_size); 187 | if (obj->next_free == ALLOCATED) { 188 | *iter = i; 189 | return obj; 190 | } 191 | i++; 192 | } 193 | *iter = i; 194 | return NULL; 195 | } 196 | 197 | object_base_p object_heap_next(object_heap_p heap, object_heap_iterator *iter) 198 | { 199 | object_base_p obj; 200 | 201 | pthread_mutex_lock(&heap->mutex); 202 | obj = object_heap_next_unlocked(heap, iter); 203 | pthread_mutex_unlock(&heap->mutex); 204 | return obj; 205 | } 206 | 207 | /* 208 | * Frees an object 209 | */ 210 | static void object_heap_free_unlocked(object_heap_p heap, object_base_p obj) 211 | { 212 | /* Check if the object has in fact been allocated */ 213 | ASSERT(obj->next_free == ALLOCATED); 214 | 215 | obj->next_free = heap->next_free; 216 | heap->next_free = obj->id & OBJECT_HEAP_ID_MASK; 217 | } 218 | 219 | void object_heap_free(object_heap_p heap, object_base_p obj) 220 | { 221 | if (!obj) 222 | return; 223 | pthread_mutex_lock(&heap->mutex); 224 | object_heap_free_unlocked(heap, obj); 225 | pthread_mutex_unlock(&heap->mutex); 226 | } 227 | 228 | /* 229 | * Destroys a heap, the heap must be empty. 230 | */ 231 | void object_heap_destroy(object_heap_p heap) 232 | { 233 | object_base_p obj; 234 | int bucket_index, obj_index, i; 235 | 236 | /* Check if heap is empty */ 237 | for (i = 0; i < heap->heap_size; i++) { 238 | /* Check if object is not still allocated */ 239 | bucket_index = i / heap->heap_increment; 240 | obj_index = i % heap->heap_increment; 241 | obj = (object_base_p)(heap->bucket[bucket_index] + obj_index * heap->object_size); 242 | ASSERT(obj->next_free != ALLOCATED); 243 | } 244 | 245 | for (i = 0; i < heap->heap_size / heap->heap_increment; i++) { 246 | free(heap->bucket[i]); 247 | } 248 | 249 | pthread_mutex_destroy(&heap->mutex); 250 | 251 | free(heap->bucket); 252 | heap->bucket = NULL; 253 | heap->heap_size = 0; 254 | heap->next_free = LAST_FREE; 255 | } 256 | --------------------------------------------------------------------------------