L4T Multimedia API Reference

28.2 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 mapOutputBuffers(struct v4l2_buffer &v4l2_buf, int dmabuff_fd);
136 
145  int unmapOutputBuffers(int index, int dmabuff_fd);
146 
155  int getCrop(struct v4l2_crop & crop);
156 
167  int setSelection(uint32_t target, uint32_t flags, struct v4l2_rect & rect);
168 
179  int reqbufs(enum v4l2_memory mem_type, uint32_t num);
192  int queryBuffer(uint32_t buf_index);
204  int exportBuffer(uint32_t buf_index);
205 
214  int setStreamStatus(bool status);
215 
221  bool getStreamStatus();
222 
232  int setStreamParms(struct v4l2_streamparm & parm);
233 
252  int setupPlane(enum v4l2_memory mem_type, uint32_t num_buffers, bool map, bool allocate);
262  void deinitPlane();
263 
269  inline enum v4l2_buf_type getBufType()
270  {
271  return buf_type;
272  }
273 
279  NvBuffer *getNthBuffer(uint32_t n);
280 
301  int dqBuffer(struct v4l2_buffer &v4l2_buf, NvBuffer ** buffer,
302  NvBuffer ** shared_buffer, uint32_t num_retries);
314  int qBuffer(struct v4l2_buffer &v4l2_buf, NvBuffer * shared_buffer);
315 
321  inline uint32_t getNumBuffers()
322  {
323  return num_buffers;
324  }
325 
332  inline uint32_t getNumPlanes()
333  {
334  return n_planes;
335  }
336 
351  void setBufferPlaneFormat(int n_planes, NvBuffer::NvBufferPlaneFormat * planefmts);
352 
358  inline uint32_t getNumQueuedBuffers()
359  {
360  return num_queued_buffers;
361  }
362 
368  inline uint32_t getTotalDequeuedBuffers()
369  {
370  return total_dequeued_buffers;
371  }
372 
378  inline uint32_t getTotalQueuedBuffers()
379  {
380  return total_queued_buffers;
381  }
382 
392  int waitAllBuffersQueued(uint32_t max_wait_ms);
402  int waitAllBuffersDequeued(uint32_t max_wait_ms);
403 
422  typedef bool(*dqThreadCallback) (struct v4l2_buffer * v4l2_buf,
423  NvBuffer * buffer, NvBuffer * shared_buffer,
424  void *data);
425 
435  bool setDQThreadCallback(dqThreadCallback callback);
451  int startDQThread(void *data);
461  int stopDQThread();
472  int waitForDQThread(uint32_t max_wait_ms);
473 
474  pthread_mutex_t plane_lock;
475  pthread_cond_t plane_cond;
479 private:
480  int &fd;
482  const char *plane_name;
484  enum v4l2_buf_type buf_type;
486  bool blocking;
489  uint32_t num_buffers;
491  NvBuffer **buffers;
494  uint8_t n_planes;
500  enum v4l2_memory memory_type;
502  uint32_t num_queued_buffers;
504  uint32_t total_queued_buffers;
506  uint32_t total_dequeued_buffers;
509  bool streamon;
511  bool dqthread_running;
513  bool stop_dqthread;
515  pthread_t dq_thread;
517  dqThreadCallback callback;
519  void *dqThread_data;
533  static void *dqThread(void *v4l2_element_plane);
534 
535  NvElementProfiler &v4l2elem_profiler;
544  inline int isInError()
545  {
546  return is_in_error;
547  }
548 
559  NvV4l2ElementPlane(enum v4l2_buf_type buf_type, const char *device_name,
560  int &fd, bool blocking, NvElementProfiler &profiler);
561 
569  void operator=(NvV4l2ElementPlane const&);
570 
577 
578  int is_in_error;
580  const char *comp_name;
583  friend class NvV4l2Element;
584 };
586 #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
int mapOutputBuffers(struct v4l2_buffer &v4l2_buf, int dmabuff_fd)
Maps the NvMMBuffer to NvBuffer for V4L2_MEMORY_DMABUF.
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.
int unmapOutputBuffers(int index, int dmabuff_fd)
Unmaps the NvMMBuffer for V4L2_MEMORY_DMABUF.