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 NvVideoDecoder.h 00031 * 00032 * @brief Helper class for V4L2 Video Decoder. 00033 */ 00034 00035 #ifndef __NV_VIDEO_DECODER_H__ 00036 #define __NV_VIDEO_DECODER_H__ 00037 00038 #include "NvV4l2Element.h" 00039 00040 /** 00041 * @brief Helper class for V4L2 Video Decoder. 00042 * 00043 * The video decoder device node is \b "/dev/nvhost-nvdec". The category name 00044 * for encoder is \b "NVDEC". 00045 * 00046 * Refer to @ref V4L2Dec for more information on the converter. 00047 */ 00048 class NvVideoDecoder:public NvV4l2Element 00049 { 00050 public: 00051 /** 00052 * Create a new V4L2 Video Decoder named \a name. 00053 * 00054 * This function internally calls v4l2_open on the decoder dev node 00055 * \b "/dev/nvhost-nvdec" and checks for \b V4L2_CAP_VIDEO_M2M_MPLANE 00056 * capability on the device. This method allows the caller to specify 00057 * additional flags with which the device should be opened. 00058 * 00059 * The device is opened in blocking mode which can be modified by passing 00060 * the @a O_NONBLOCK flag to this method. 00061 * 00062 * @returns Reference to the newly created decoder object else \a NULL in 00063 * case of failure during initialization. 00064 */ 00065 static NvVideoDecoder *createVideoDecoder(const char *name, int flags = 0); 00066 00067 ~NvVideoDecoder(); 00068 /** 00069 * Sets the format on the decoder output plane. 00070 * 00071 * Calls VIDIOC_S_FMT ioctl internally on the capture plane. 00072 * 00073 * @param[in] pixfmt One of the raw V4L2 pixel formats 00074 * @param[in] width Width of the output buffers in pixels 00075 * @param[in] height Height of the output buffers in pixels 00076 * @returns 0 for success, -1 for failure. 00077 */ 00078 int setCapturePlaneFormat(uint32_t pixfmt, uint32_t width, uint32_t height); 00079 /** 00080 * Sets the format on the decoder output plane. 00081 * 00082 * Calls VIDIOC_S_FMT ioctl internally on the output plane. 00083 * 00084 * @param[in] pixfmt One of the coded V4L2 pixel formats 00085 * @param[in] sizeimage Maximum size of the buffers on the output plane 00086 containing encoded data in bytes 00087 * @returns 0 for success, -1 for failure. 00088 */ 00089 int setOutputPlaneFormat(uint32_t pixfmt, uint32_t sizeimage); 00090 00091 /** 00092 * Inform decoder input buffers may not contain complete frames 00093 * 00094 * Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control id 00095 * #V4L2_CID_MPEG_VIDEO_DISABLE_COMPLETE_FRAME_INPUT. Must be called before 00096 * setFormat on any of the planes. 00097 * 00098 * @returns 0 for success, -1 for failure 00099 */ 00100 int disableCompleteFrameInputBuffer(); 00101 00102 /** 00103 * Disable display picture buffer 00104 * 00105 * Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control id 00106 * #V4L2_CID_MPEG_VIDEO_DISABLE_DPB. Must be called after setFormat on both 00107 * the planes and before #requestBuffers on any of the planes. 00108 * 00109 * @returns 0 for success, -1 for failure 00110 */ 00111 int disableDPB(); 00112 00113 /** 00114 * Get the minimum number of buffers to be requested on decoder capture plane 00115 * 00116 * Calls the VIDIOC_G_CTRL ioctl internally with Control id 00117 * V4L2_CID_MIN_BUFFERS_FOR_CAPTURE. Is valid after the first 00118 * #V4L2_RESOLUTION_CHANGE_EVENT and may change after each subsequent 00119 * event. 00120 * 00121 * @param[out] num Pointer to integer to return the number of buffers 00122 * 00123 * @returns 0 for success, -1 for failure 00124 */ 00125 int getMinimumCapturePlaneBuffers(int & num); 00126 00127 /** 00128 * Set skip-frames parameter of the decoder 00129 * 00130 * Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control id 00131 * #V4L2_CID_MPEG_VIDEO_SKIP_FRAMES. Must be called after setFormat on both 00132 * the planes and before #requestBuffers on any of the planes. 00133 * 00134 * @param[in] skip_frames Type of frames to skip decoding, one of 00135 * enum v4l2_skip_frames_type 00136 * 00137 * @returns 0 for success, -1 for failure 00138 */ 00139 int setSkipFrames(enum v4l2_skip_frames_type skip_frames); 00140 00141 /** 00142 * Enable video decoder output metadata reporting 00143 * 00144 * Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control id 00145 * #V4L2_CID_MPEG_VIDEO_ERROR_REPORTING. Must be called after setFormat on 00146 * both the planes and before #requestBuffers on any of the planes. 00147 * 00148 * @returns 0 for success, -1 for failure 00149 */ 00150 int enableMetadataReporting(); 00151 00152 /** 00153 * Get metadata for decoded capture plane buffer 00154 * 00155 * Calls the VIDIOC_S_EXT_CTRLS ioctl internally with Control id 00156 * #V4L2_CID_MPEG_VIDEODEC_METADATA. Must be called for a buffer which has 00157 * been dequeued from the capture plane. The returned metadata corresponds 00158 * to the last dequeued buffer with index @a buffer_index. 00159 * 00160 * @param[in] buffer_index Index of the capture plane buffer whose metadata 00161 * is required 00162 * @param[in,out] Reference to the metadata structure 00163 * v4l2_ctrl_videodec_outputbuf_metadata to be filled 00164 * 00165 * @returns 0 for success, -1 for failure 00166 */ 00167 int getMetadata(uint32_t buffer_index, 00168 v4l2_ctrl_videodec_outputbuf_metadata &metadata); 00169 00170 private: 00171 /** 00172 * Contructor used by #createVideoDecoder. 00173 */ 00174 NvVideoDecoder(const char *name, int flags); 00175 00176 static const NvElementProfiler::ProfilerField valid_fields = 00177 NvElementProfiler::PROFILER_FIELD_TOTAL_UNITS | 00178 NvElementProfiler::PROFILER_FIELD_FPS; 00179 }; 00180 00181 #endif