- Main Page
- Modules
- Namespaces
- Classes
- Files

- Search for |

- File List
- File Members

# include/NvV4l2Element.h

Go to the documentation of this file.

    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 NvV4l2Element.h
    00031  *
    00032  * @brief Helper class for V4L2 based components.
    00033  */
    00034 #ifndef __NV_V4L2_ELEMENT_H__
    00035 #define __NV_V4L2_ELEMENT_H__
    00036
    00037 #include "NvElement.h"
    00038 #include "NvV4l2ElementPlane.h"
    00039
    00040 #include "v4l2_nv_extensions.h"
    00041
    00042 /**
    00043  * @brief Helper class for V4L2 based components.
    00044  *
    00045  * This class provides common functionality for V4L2 components. V4L2 based
    00046  * components like encoder/decoder extend from this class.
    00047  *
    00048  * This class has been modelled on v4l2 M2M devices. It includes FD of the device
    00049  * opened using \v4l2_open, two planes (NvV4l2ElementPlane) viz. Output plane,
    00050  * Capture plane and other helper functions such as setting/getting controls,
    00051  * subscribing/dequeueing events, etc.
    00052  */
    00053 class NvV4l2Element:public NvElement
    00054 {
    00055 public:
    00056     virtual ~NvV4l2Element();
    00057
    00058     /**
    00059      * Subscibe to an V4L2 Event.
    00060      *
    00061      * Calls VIDIOC_SUBSCRIBE_EVENT ioctl internally
    00062      *
    00063      * @param[in] type Type of the event
    00064      * @param[in] id ID of the event source
    00065      * @param[in] flags Event flags
    00066      * @returns 0 for success, -1 for failure
    00067      */
    00068     int subscribeEvent(uint32_t type, uint32_t id, uint32_t flags);
    00069     /**
    00070      * Dequeue a event from the element
    00071      *
    00072      * Calls VIDIOC_DQEVENT ioctl internally. User can specify the maximum time
    00073      * to wait for dequeuing the event. The call blocks till an event is
    00074      * dequeued successfully or timeout is reached.
    00075      *
    00076      * @param[in,out] event Reference to v4l2_event structure to be filled
    00077      * @param[in] max_wait_ms Max time to wait for dequeuing an event in
    00078      *                        in milliseconds
    00079      * @returns 0 for success, -1 for failure
    00080      */
    00081     int dqEvent(struct v4l2_event &event, uint32_t max_wait_ms);
    00082
    00083     /**
    00084      * Set the value of a control
    00085      *
    00086      * Calls VIDIOC_S_CTRL ioctl internally
    00087      *
    00088      * @param[in] id ID of the control to be set
    00089      * @param[in] value Value to be set on the control
    00090      * @returns 0 for success, -1 for failure
    00091      */
    00092     int setControl(uint32_t id, int32_t value);
    00093     /**
    00094      * Get the value of a control
    00095      *
    00096      * Calls VIDIOC_G_CTRL ioctl internally
    00097      *
    00098      * @param[in] id ID of the control to get
    00099      * @param[out] value Reference to the variable into which the control value
    00100                          will be read
    00101      * @returns 0 for success, -1 for failure
    00102      */
    00103     int getControl(uint32_t id, int32_t &value);
    00104
    00105     /**
    00106      * Set the value of several controls
    00107      *
    00108      * Calls VIDIOC_S_EXT_CTRLS ioctl internally
    00109      *
    00110      * @param[in] ctl Contains controls to be set
    00111      * @returns 0 for success, -1 for failure
    00112      */
    00113     int setExtControls(struct v4l2_ext_controls &ctl);
    00114     /**
    00115      * Get the value of several controls
    00116      *
    00117      * Calls VIDIOC_G_EXT_CTRLS ioctl internally
    00118      *
    00119      * @param[in,out] ctl Contains controls to get
    00120      * @returns 0 for success, -1 for failure
    00121      */
    00122     int getExtControls(struct v4l2_ext_controls &ctl);
    00123
    00124     virtual int isInError();
    00125
    00126     NvV4l2ElementPlane output_plane;  /**< Output plane of the element */
    00127     NvV4l2ElementPlane capture_plane; /**< Capture plane of the element */
    00128
    00129     /**
    00130      *
    00131      * Abort processing of queued buffers immediately. All the buffers are
    00132      * returned to the application.
    00133      *
    00134      * Calls VIDIOC_STREAMOFF ioctl on the both the planes internally.
    00135      *
    00136      * @returns 0 for success, -1 for failure
    00137      */
    00138     int abort();
    00139
    00140     /**
    00141      * Wait till the element has processed all the output plane buffers
    00142      *
    00143      * Classes extending V4l2Element should implement this since the idle
    00144      * condition will be component specific.
    00145      *
    00146      * @param[in] max_wait_ms Max time to wait in milliseconds
    00147      * @returns 0 for success, -1 for failure
    00148      */
    00149     virtual int waitForIdle(uint32_t max_wait_ms);
    00150
    00151     void *app_data; /**< Pointer to application specific data */
    00152
    00153     /**
    00154      * Enable profiling for the V4l2Element.
    00155      *
    00156      * Should be called before setting either plane formats.
    00157      */
    00158     void enableProfiling();
    00159
    00160 protected:
    00161     int fd;     /**< FD of the device opened using \v4l2_open */
    00162
    00163     uint32_t output_plane_pixfmt;  /**< Pixel format of output plane buffers */
    00164     uint32_t capture_plane_pixfmt; /**< Pixel format of capture plane buffers */
    00165
    00166     /**
    00167      * Creates a new V4l2Element named \a name.
    00168      *
    00169      * This constructor calls v4l2_open on the \a dev_node. Sets an error if
    00170      * v4l2_open fails.
    00171      *
    00172      * This function also checks if the device supports V4L2_CAP_VIDEO_M2M_MPLANE
    00173      * capability.
    00174      *
    00175      * @param[in] comp_name Unique name to identity the element instance
    00176      * @param[in] dev_node /dev/ * node of the device
    00177      * @param[in] flags Flags to open the device with
    00178      * @param[in] fields Profiler fields which are valid for the element.
    00179      */
    00180     NvV4l2Element(const char *comp_name, const char *dev_node, int flags, NvElementProfiler::ProfilerField fields);
    00181 };
    00182
    00183 #endif