L4T Multimedia API Reference

28.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NvV4l2ElementPlane.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA CORPORATION nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
47 #ifndef __NV_V4L2_ELELMENT_PLANE_H__
48 #define __NV_V4L2_ELELMENT_PLANE_H__
49 
50 #include <pthread.h>
51 #include "NvElement.h"
52 #include "NvLogging.h"
53 #include "NvBuffer.h"
54 
59 #define PLANE_DEBUG_MSG(str) COMP_DEBUG_MSG(plane_name << ":" << str);
60 
64 #define PLANE_INFO_MSG(str) COMP_INFO_MSG(plane_name << ":" << str);
65 
69 #define PLANE_WARN_MSG(str) COMP_WARN_MSG(plane_name << ":" << str);
70 
74 #define PLANE_ERROR_MSG(str) COMP_ERROR_MSG(plane_name << ":" << str);
75 
79 #define PLANE_SYS_ERROR_MSG(str) COMP_SYS_ERROR_MSG(plane_name << ":" << str);
80 
105 {
106 
107 public:
116  int getFormat(struct v4l2_format & format);
125  int setFormat(struct v4l2_format & format);
126 
135  int getCrop(struct v4l2_crop & crop);
136 
147  int setSelection(uint32_t target, uint32_t flags, struct v4l2_rect & rect);
148 
159  int reqbufs(enum v4l2_memory mem_type, uint32_t num);
172  int queryBuffer(uint32_t buf_index);
184  int exportBuffer(uint32_t buf_index);
185 
194  int setStreamStatus(bool status);
195 
201  bool getStreamStatus();
202 
212  int setStreamParms(struct v4l2_streamparm & parm);
213 
232  int setupPlane(enum v4l2_memory mem_type, uint32_t num_buffers, bool map, bool allocate);
242  void deinitPlane();
243 
249  inline enum v4l2_buf_type getBufType()
250  {
251  return buf_type;
252  }
253 
259  NvBuffer *getNthBuffer(uint32_t n);
260 
281  int dqBuffer(struct v4l2_buffer &v4l2_buf, NvBuffer ** buffer,
282  NvBuffer ** shared_buffer, uint32_t num_retries);
294  int qBuffer(struct v4l2_buffer &v4l2_buf, NvBuffer * shared_buffer);
295 
301  inline uint32_t getNumBuffers()
302  {
303  return num_buffers;
304  }
305 
312  inline uint32_t getNumPlanes()
313  {
314  return n_planes;
315  }
316 
331  void setBufferPlaneFormat(int n_planes, NvBuffer::NvBufferPlaneFormat * planefmts);
332 
338  inline uint32_t getNumQueuedBuffers()
339  {
340  return num_queued_buffers;
341  }
342 
348  inline uint32_t getTotalDequeuedBuffers()
349  {
350  return total_dequeued_buffers;
351  }
352 
358  inline uint32_t getTotalQueuedBuffers()
359  {
360  return total_queued_buffers;
361  }
362 
372  int waitAllBuffersQueued(uint32_t max_wait_ms);
382  int waitAllBuffersDequeued(uint32_t max_wait_ms);
383 
402  typedef bool(*dqThreadCallback) (struct v4l2_buffer * v4l2_buf,
403  NvBuffer * buffer, NvBuffer * shared_buffer,
404  void *data);
405 
415  bool setDQThreadCallback(dqThreadCallback callback);
431  int startDQThread(void *data);
441  int stopDQThread();
452  int waitForDQThread(uint32_t max_wait_ms);
453 
454  pthread_mutex_t plane_lock;
455  pthread_cond_t plane_cond;
459 private:
460  int &fd;
462  const char *plane_name;
464  enum v4l2_buf_type buf_type;
466  bool blocking;
469  uint32_t num_buffers;
471  NvBuffer **buffers;
474  uint8_t n_planes;
480  enum v4l2_memory memory_type;
482  uint32_t num_queued_buffers;
484  uint32_t total_queued_buffers;
486  uint32_t total_dequeued_buffers;
489  bool streamon;
491  bool dqthread_running;
493  bool stop_dqthread;
495  pthread_t dq_thread;
497  dqThreadCallback callback;
499  void *dqThread_data;
513  static void *dqThread(void *v4l2_element_plane);
514 
515  NvElementProfiler &v4l2elem_profiler;
524  inline int isInError()
525  {
526  return is_in_error;
527  }
528 
539  NvV4l2ElementPlane(enum v4l2_buf_type buf_type, const char *device_name,
540  int &fd, bool blocking, NvElementProfiler &profiler);
541 
549  void operator=(NvV4l2ElementPlane const&);
550 
557 
558  int is_in_error;
560  const char *comp_name;
563  friend class NvV4l2Element;
564 };
566 #endif
int setupPlane(enum v4l2_memory mem_type, uint32_t num_buffers, bool map, bool allocate)
Helper method that encapsulates all the method calls required to set up the plane for streaming...
int waitAllBuffersDequeued(uint32_t max_wait_ms)
Waits until all buffers of the plane are dequeued.
bool setDQThreadCallback(dqThreadCallback callback)
Sets the DQ Thread callback method.
pthread_cond_t plane_cond
Plane condition that application can wait on to receive notifications from qBuffer/dqBuffer.
int stopDQThread()
Force stops the DQ Thread if it is running.
uint32_t getTotalDequeuedBuffers()
Gets the total number of buffers dequeued from the plane.
Defines a helper class for V4L2 based components.
Definition: NvV4l2Element.h:65
void setBufferPlaneFormat(int n_planes, NvBuffer::NvBufferPlaneFormat *planefmts)
Sets the format of the planes of the buffer that is used with this plane.
int qBuffer(struct v4l2_buffer &v4l2_buf, NvBuffer *shared_buffer)
Queues a buffer on the plane.
bool getStreamStatus()
Checks whether the plane is streaming.
int reqbufs(enum v4l2_memory mem_type, uint32_t num)
Requests for buffers on the plane.
int setSelection(uint32_t target, uint32_t flags, struct v4l2_rect &rect)
Sets the selection rectangle for the plane.
Defines a helper class for operations performed on a V4L2 Element plane.
NVIDIA Multimedia API: NvElement Base Class
Class representing a buffer.
Definition: NvBuffer.h:85
Holds the buffer plane format.
Definition: NvBuffer.h:91
bool(* dqThreadCallback)(struct v4l2_buffer *v4l2_buf, NvBuffer *buffer, NvBuffer *shared_buffer, void *data)
This is a callback function type method that is called by the DQ Thread when it successfully dequeues...
NVIDIA Multimedia API: Buffer API
int setFormat(struct v4l2_format &format)
Sets the plane format.
uint32_t getNumPlanes()
Gets the number of planes buffers on this plane for the currently set format.
#define MAX_PLANES
Specifies the maximum number of planes a buffer can contain.
Definition: NvBuffer.h:58
int dqBuffer(struct v4l2_buffer &v4l2_buf, NvBuffer **buffer, NvBuffer **shared_buffer, uint32_t num_retries)
Dequeues a buffer from the plane.
int startDQThread(void *data)
Starts DQ Thread.
NvBuffer * getNthBuffer(uint32_t n)
Gets the NvBuffer object at index n.
uint32_t getNumQueuedBuffers()
Gets the number of buffers currently queued on the plane.
int waitAllBuffersQueued(uint32_t max_wait_ms)
Waits until all buffers of the plane are queued.
int setStreamStatus(bool status)
Starts or stops streaming on the plane.
NVIDIA Multimedia API: Logging API
enum v4l2_buf_type getBufType()
Gets the streaming/buffer type of this plane.
uint32_t getTotalQueuedBuffers()
Gets the total number of buffers queued on the plane.
int getCrop(struct v4l2_crop &crop)
Gets the cropping rectangle for the plane.
int queryBuffer(uint32_t buf_index)
Queries the status of the buffer at the index.
int setStreamParms(struct v4l2_streamparm &parm)
Sets streaming parameters.
void deinitPlane()
Helper method that encapsulates all the method calls required to deinitialize the plane for streaming...
int exportBuffer(uint32_t buf_index)
Exports the buffer as DMABUF FD.
int waitForDQThread(uint32_t max_wait_ms)
Waits for the DQ Thread to stop.
pthread_mutex_t plane_lock
Mutex lock used along with plane_cond.
int getFormat(struct v4l2_format &format)
Gets the plane format.
uint32_t getNumBuffers()
Gets the number of buffers allocated/requested on the plane.