00001 /* 00002 * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions 00006 * are met: 00007 * * Redistributions of source code must retain the above copyright 00008 * notice, this list of conditions and the following disclaimer. 00009 * * Redistributions in binary form must reproduce the above copyright 00010 * notice, this list of conditions and the following disclaimer in the 00011 * documentation and/or other materials provided with the distribution. 00012 * * Neither the name of NVIDIA CORPORATION nor the names of its 00013 * contributors may be used to endorse or promote products derived 00014 * from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 00017 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00018 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00019 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 00020 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00021 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00022 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00023 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00024 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00026 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 */ 00028 00029 /** 00030 * @file NvVideoConverter.h 00031 * 00032 * @brief Helper class for V4L2 Video Converter. 00033 */ 00034 00035 #ifndef __NV_VIDEO_CONVERTER_H__ 00036 #define __NV_VIDEO_CONVERTER_H__ 00037 00038 #include "NvV4l2Element.h" 00039 00040 /** 00041 * @brief Helper class for V4L2 Video Converter. 00042 * 00043 * Video converter can be used for color space conversion, scaling and 00044 * conversion between hardware buffer memory (V4L2_MEMORY_MMAP/ 00045 * V4L2_MEMORY_DMABUF) and software buffer memory (V4L2_MEMORY_USERPTR). 00046 * 00047 * The video converter device node is \b "/dev/nvhost-vic". The category name 00048 * for encoder is \b "NVVIDCONV" 00049 * 00050 * Refer to @ref V4L2Conv for more information on the converter. 00051 */ 00052 00053 class NvVideoConverter:public NvV4l2Element 00054 { 00055 public: 00056 00057 /** 00058 * Create a new V4L2 Video Converter named \a name 00059 * 00060 * This function internally calls v4l2_open on the converter dev node 00061 * \b "/dev/nvhost-vic" and checks for \b V4L2_CAP_VIDEO_M2M_MPLANE 00062 * capability on the device. This method allows the caller to specify 00063 * additional flags with which the device should be opened. 00064 * 00065 * The device is opened in blocking mode which can be modified by passing 00066 * the @a O_NONBLOCK flag to this method. 00067 * 00068 * @returns Reference to the newly created converter object else \a NULL in 00069 * case of failure during initialization. 00070 */ 00071 static NvVideoConverter *createVideoConverter(const char *name, int flags = 0); 00072 00073 ~NvVideoConverter(); 00074 /** 00075 * Sets the format on the converter output plane. 00076 * 00077 * Calls VIDIOC_S_FMT ioctl internally on the capture plane. 00078 * 00079 * @param[in] pixfmt One of the raw V4L2 pixel formats 00080 * @param[in] width Width of the output buffers in pixels 00081 * @param[in] height Height of the output buffers in pixels 00082 * @param[in] layout Layout of the buffers in plane, one of 00083 * enum v4l2_nv_buffer_layout 00084 * @returns 0 for success, -1 for failure 00085 */ 00086 int setCapturePlaneFormat(uint32_t pixfmt, uint32_t width, uint32_t height, 00087 enum v4l2_nv_buffer_layout type); 00088 /** 00089 * Sets the format on the converter output plane. 00090 * 00091 * Calls VIDIOC_S_FMT ioctl internally on the output plane. 00092 * 00093 * @param[in] pixfmt One of the raw V4L2 pixel formats 00094 * @param[in] width Width of the output buffers in pixels 00095 * @param[in] height Height of the output buffers in pixels 00096 * @param[in] layout Layout of the buffers in plane, one of 00097 * enum v4l2_nv_buffer_layout 00098 * @returns 0 for success, -1 for failure 00099 */ 00100 int setOutputPlaneFormat(uint32_t pixfmt, uint32_t width, uint32_t height, 00101 enum v4l2_nv_buffer_layout type); 00102 00103 /** 00104 * Set the buffer layout of the output plane buffers 00105 * 00106 * Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control id 00107 * #V4L2_CID_VIDEO_CONVERT_OUTPUT_PLANE_LAYOUT. Must be called before 00108 * setFormat on any of the planes. 00109 * 00110 * @param[in] type Type of layout, one of enum v4l2_nv_buffer_layout 00111 * 00112 * @returns 0 for success, -1 for failure 00113 */ 00114 int setOutputPlaneBufferLayout(enum v4l2_nv_buffer_layout type); 00115 00116 /** 00117 * Set the buffer layout of the capture plane buffers 00118 * 00119 * Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control id 00120 * #V4L2_CID_VIDEO_CONVERT_CAPTURE_PLANE_LAYOUT. Must be called before 00121 * setFormat on any of the planes. 00122 * 00123 * @param[in] type Type of layout, one of enum v4l2_nv_buffer_layout 00124 * 00125 * @returns 0 for success, -1 for failure 00126 */ 00127 int setCapturePlaneBufferLayout(enum v4l2_nv_buffer_layout type); 00128 00129 /** 00130 * Set the interpolation(filter) method used for scaling 00131 * 00132 * Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control id 00133 * #V4L2_CID_VIDEO_CONVERT_INTERPOLATION_METHOD. Must be called before 00134 * setFormat on any of the planes. 00135 * 00136 * @param[in] method Type of interpolation method, one of enum 00137 * v4l2_interpolation_method 00138 * 00139 * @returns 0 for success, -1 for failure 00140 */ 00141 int setInterpolationMethod(enum v4l2_interpolation_method method); 00142 00143 /** 00144 * Set the flip method 00145 * 00146 * Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control id 00147 * #V4L2_CID_VIDEO_CONVERT_FLIP_METHOD. Must be called before 00148 * setFormat on any of the planes. 00149 * 00150 * @param[in] method Type of flip method, one of enum v4l2_flip_method 00151 * 00152 * @returns 0 for success, -1 for failure 00153 */ 00154 int setFlipMethod(enum v4l2_flip_method method); 00155 00156 /** 00157 * Set the TNR(Temporal Noise Reduction) algorithm to use 00158 * 00159 * Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control id 00160 * #V4L2_CID_VIDEO_CONVERT_TNR_ALGORITHM. Must be called before 00161 * setFormat on any of the planes. 00162 * 00163 * @param[in] algorithm Type of TNR algorithm to use, one of enum 00164 * v4l2_tnr_algorithm 00165 * 00166 * @returns 0 for success, -1 for failure 00167 */ 00168 int setTnrAlgorithm(enum v4l2_tnr_algorithm algorithm); 00169 00170 /** 00171 * Set the cropping rectangle for the converter 00172 * 00173 * Calls the VIDIOC_S_SELECTION internally on capture plane. Must be called 00174 * before setFormat on any of the planes. 00175 * 00176 * @param[in] left Horizontal offset of the rectangle, in pixels 00177 * @param[in] top Verticaal offset of the rectangle, in pixels 00178 * @param[in] width Width of the rectangle, in pixels 00179 * @param[in] height Height of the rectangle, in pixels 00180 * 00181 * @returns 0 for success, -1 for failure 00182 */ 00183 int setCropRect(uint32_t left, uint32_t top, uint32_t width, 00184 uint32_t height); 00185 00186 /** 00187 * Wait till all the buffers queued on the output plane are converted and 00188 * dequeued from the capture plane. This is a blocking call. 00189 * 00190 * @param[in] max_wait_ms Maximum time to wait in milliseconds 00191 * @returns 0 for success, -1 for timeout 00192 */ 00193 int waitForIdle(uint32_t max_wait_ms); 00194 00195 private: 00196 /** 00197 * Contructor used by #createVideoConverter 00198 */ 00199 NvVideoConverter(const char *name, int flags); 00200 00201 static const NvElementProfiler::ProfilerField valid_fields = 00202 NvElementProfiler::PROFILER_FIELD_TOTAL_UNITS | 00203 NvElementProfiler::PROFILER_FIELD_LATENCIES | 00204 NvElementProfiler::PROFILER_FIELD_FPS; 00205 }; 00206 00207 #endif