Jetson Linux API 参考文档

32.7.4 版本
NvV4l2ElementPlane.h
跳转至此文件的文档。
1 /*
2  * 版权所有 (c) 2016, NVIDIA CORPORATION。保留所有权利。
3  *
4  * 只要满足以下条件,就允许以源代码和二进制形式重新发布和使用,无论是否经过
5  * 修改:
6  *
7  * * 源代码的重新发布必须保留上述版权声明、
8  * 条件列表和以下免责声明。
9  *
10  * * 二进制形式的重新发布必须在
11  * 文档和/或随发行版提供的其他材料中复制上述版权声明、条件列表和以下免责声明。
12  *
13  * * 未经事先书面许可,不得使用 NVIDIA CORPORATION 的名称或其
14  * 贡献者的姓名来认可或推广源自本软件的产品。
15  *
16  * 本软件由版权所有者“按原样”提供,并且不作任何明示或暗示的担保,包括但不限于
17  * 适销性和针对特定用途的适用性的暗示担保。在任何情况下,版权所有者或
18  * 贡献者均不对任何直接、间接、附带、特殊、
19  * 惩戒性或后果性损害(包括但不限于
20  * 替代商品或服务的采购;使用、数据或
21  * 利润损失;或业务中断)承担任何责任,无论其原因和任何责任理论,
22  * 无论是合同、严格责任还是侵权行为
23  * (包括疏忽或其他原因)以任何方式因使用本软件而引起,即使已被告知可能发生此类损害。
24  *
25  * 除非适用法律要求或书面同意,否则本软件按“原样”分发,
26  * 不提供任何形式的担保或条件,无论是明示的还是暗示的。
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
NvElementProfiler
Definition: NvElementProfiler.h:72
NvV4l2Element
Defines a helper class for V4L2 based components.
Definition: NvV4l2Element.h:65
NvV4l2ElementPlane::getNumQueuedBuffers
uint32_t getNumQueuedBuffers()
Gets the number of buffers currently queued on the plane.
Definition: NvV4l2ElementPlane.h:358
NvV4l2ElementPlane::qBuffer
int qBuffer(struct v4l2_buffer &v4l2_buf, NvBuffer *shared_buffer)
Queues a buffer on the plane.
NvV4l2ElementPlane::setSelection
int setSelection(uint32_t target, uint32_t flags, struct v4l2_rect &rect)
Sets the selection rectangle for the plane.
NvV4l2ElementPlane::setBufferPlaneFormat
void setBufferPlaneFormat(int n_planes, NvBuffer::NvBufferPlaneFormat *planefmts)
Sets the format of the planes of the buffer that is used with this plane.
NvV4l2ElementPlane::getNthBuffer
NvBuffer * getNthBuffer(uint32_t n)
Gets the NvBuffer object at index n.
NvV4l2ElementPlane::waitForDQThread
int waitForDQThread(uint32_t max_wait_ms)
Waits for the DQ Thread to stop.
NvV4l2ElementPlane::dqBuffer
int dqBuffer(struct v4l2_buffer &v4l2_buf, NvBuffer **buffer, NvBuffer **shared_buffer, uint32_t num_retries)
Dequeues a buffer from the plane.
NvV4l2ElementPlane::stopDQThread
int stopDQThread()
Force stops the DQ Thread if it is running.
NvV4l2ElementPlane::setupPlane
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.
NvV4l2ElementPlane::setStreamParms
int setStreamParms(struct v4l2_streamparm &parm)
Sets streaming parameters.
NvV4l2ElementPlane::getNumPlanes
uint32_t getNumPlanes()
Gets the number of planes buffers on this plane for the currently set format.
Definition: NvV4l2ElementPlane.h:332
NvV4l2ElementPlane::plane_cond
pthread_cond_t plane_cond
Plane condition that application can wait on to receive notifications from qBuffer/dqBuffer.
Definition: NvV4l2ElementPlane.h:475
NvV4l2ElementPlane::mapOutputBuffers
int mapOutputBuffers(struct v4l2_buffer &v4l2_buf, int dmabuff_fd)
Maps the NvMMBuffer to NvBuffer for V4L2_MEMORY_DMABUF.
NvV4l2ElementPlane::setDQThreadCallback
bool setDQThreadCallback(dqThreadCallback callback)
Sets the DQ Thread callback method.
NvV4l2ElementPlane::waitAllBuffersQueued
int waitAllBuffersQueued(uint32_t max_wait_ms)
Waits until all buffers of the plane are queued.
NvV4l2ElementPlane::getFormat
int getFormat(struct v4l2_format &format)
Gets the plane format.
NvV4l2ElementPlane::startDQThread
int startDQThread(void *data)
Starts DQ Thread.
NvV4l2ElementPlane::getBufType
enum v4l2_buf_type getBufType()
Gets the streaming/buffer type of this plane.
Definition: NvV4l2ElementPlane.h:269
MAX_PLANES
#define MAX_PLANES
Specifies the maximum number of planes a buffer can contain.
Definition: NvBuffer.h:58
NvV4l2ElementPlane::exportBuffer
int exportBuffer(uint32_t buf_index)
Exports the buffer as DMABUF FD.
NvV4l2ElementPlane::getTotalQueuedBuffers
uint32_t getTotalQueuedBuffers()
Gets the total number of buffers queued on the plane.
Definition: NvV4l2ElementPlane.h:378
NvV4l2ElementPlane::getCrop
int getCrop(struct v4l2_crop &crop)
Gets the cropping rectangle for the plane.
NvLogging.h
Description: This file defines macros for logging messages.
NvV4l2ElementPlane::waitAllBuffersDequeued
int waitAllBuffersDequeued(uint32_t max_wait_ms)
Waits until all buffers of the plane are dequeued.
NvV4l2ElementPlane::reqbufs
int reqbufs(enum v4l2_memory mem_type, uint32_t num)
Requests for buffers on the plane.
NvV4l2ElementPlane::getStreamStatus
bool getStreamStatus()
Checks whether the plane is streaming.
NvV4l2ElementPlane
Defines a helper class for operations performed on a V4L2 Element plane.
Definition: NvV4l2ElementPlane.h:104
NvV4l2ElementPlane::setFormat
int setFormat(struct v4l2_format &format)
Sets the plane format.
NvV4l2ElementPlane::queryBuffer
int queryBuffer(uint32_t buf_index)
Queries the status of the buffer at the index.
NvV4l2ElementPlane::deinitPlane
void deinitPlane()
Helper method that encapsulates all the method calls required to deinitialize the plane for streaming...
NvV4l2ElementPlane::setStreamStatus
int setStreamStatus(bool status)
Starts or stops streaming on the plane.
NvV4l2ElementPlane::getNumBuffers
uint32_t getNumBuffers()
Gets the number of buffers allocated/requested on the plane.
Definition: NvV4l2ElementPlane.h:321
NvV4l2ElementPlane::getTotalDequeuedBuffers
uint32_t getTotalDequeuedBuffers()
Gets the total number of buffers dequeued from the plane.
Definition: NvV4l2ElementPlane.h:368
NvBuffer.h
NvV4l2ElementPlane::unmapOutputBuffers
int unmapOutputBuffers(int index, int dmabuff_fd)
Unmaps the NvMMBuffer for V4L2_MEMORY_DMABUF.
NvElement.h
NvBuffer::NvBufferPlaneFormat
Holds the buffer plane format.
Definition: NvBuffer.h:91
NvBuffer
Class representing a buffer.
Definition: NvBuffer.h:85
NvV4l2ElementPlane::plane_lock
pthread_mutex_t plane_lock
Mutex lock used along with plane_cond.
Definition: NvV4l2ElementPlane.h:474
NvV4l2ElementPlane::dqThreadCallback
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...
Definition: NvV4l2ElementPlane.h:422
. All rights reserved.