#include <NvV4l2ElementPlane.h>
Public Types | |
typedef bool(* | dqThreadCallback )(struct v4l2_buffer *v4l2_buf, NvBuffer *buffer, NvBuffer *shared_buffer, void *data) |
This is a callback function type which is called by the DQ Thread when it successfully dequeues a buffer from the plane. | |
Public Member Functions | |
int | getFormat (struct v4l2_format &format) |
Get the plane format. | |
int | setFormat (struct v4l2_format &format) |
Set the plane format. | |
int | getCrop (struct v4l2_crop &crop) |
Get the cropping rectangle for the plane. | |
int | setSelection (uint32_t target, uint32_t flags, struct v4l2_rect &rect) |
Set the selection rectangle for the plane. | |
int | reqbufs (enum v4l2_memory mem_type, uint32_t num) |
Request for buffers on the plane. | |
int | queryBuffer (uint32_t buf_index) |
Query the status of buffer at index. | |
int | exportBuffer (uint32_t buf_index) |
Export the buffer as DMABUF FD. | |
int | setStreamStatus (bool status) |
Start or stop streaming on the plane. | |
bool | getStreamStatus () |
Check if the plane is streaming. | |
int | setStreamParms (struct v4l2_streamparm &parm) |
Set streaming parameters. | |
int | setupPlane (enum v4l2_memory mem_type, uint32_t num_buffers, bool map, bool allocate) |
Helper function which encapsulates all the function calls required to setup the plane for streaming. | |
void | deinitPlane () |
Helper function which encapsulates all the function calls required to deinitialize the plane for streaming. | |
enum v4l2_buf_type | getBufType () |
Get the streaming/buffer type of this plane. | |
NvBuffer * | getNthBuffer (uint32_t n) |
Get the NvBuffer object at index n. | |
int | dqBuffer (struct v4l2_buffer &v4l2_buf, NvBuffer **buffer, NvBuffer **shared_buffer, uint32_t num_retries) |
Dequeue a buffer from the plane. | |
int | qBuffer (struct v4l2_buffer &v4l2_buf, NvBuffer *shared_buffer) |
Queue a buffer on the plane. | |
uint32_t | getNumBuffers () |
Get the number of buffers allocated/requested on the plane. | |
uint32_t | getNumPlanes () |
Get the number of planes buffers on this plane contain for the currently set format. | |
void | setBufferPlaneFormat (int n_planes, NvBuffer::NvBufferPlaneFormat *planefmts) |
Set the format of the planes of the buffer which will be used with this plane. | |
uint32_t | getNumQueuedBuffers () |
Get the number of buffers currently queued on the plane. | |
uint32_t | getTotalDequeuedBuffers () |
Get the total number of buffers dequeued from the plane. | |
uint32_t | getTotalQueuedBuffers () |
Get the total number of buffers queued on the plane. | |
int | waitAllBuffersQueued (uint32_t max_wait_ms) |
Wait till all the buffers of the plane get queued. | |
int | waitAllBuffersDequeued (uint32_t max_wait_ms) |
Wait till all the buffers of the plane get dequeued. | |
bool | setDQThreadCallback (dqThreadCallback callback) |
Set the DQ Thread callback function. | |
int | startDQThread (void *data) |
Start DQ Thread. | |
int | stopDQThread () |
Force stop the DQ Thread if it is running. | |
int | waitForDQThread (uint32_t max_wait_ms) |
Wait for the DQ Thread to stop. | |
Public Attributes | |
pthread_mutex_t | plane_lock |
Mutex lock used along with plane_cond. | |
pthread_cond_t | plane_cond |
Plane condition which application can wait on to receive notifications from qBuffer/dqBuffer. | |
Private Member Functions | |
int | isInError () |
Indicates if the plane encountered an error during its operation. | |
NvV4l2ElementPlane (enum v4l2_buf_type buf_type, const char *device_name, int &fd, bool blocking, NvElementProfiler &profiler) | |
Creates a new V4l2Element plane. | |
NvV4l2ElementPlane (const NvV4l2ElementPlane &that) | |
Disallow copy constructor. | |
void | operator= (NvV4l2ElementPlane const &) |
Disallow assignment. | |
~NvV4l2ElementPlane () | |
NvV4l2ElementPlane destructor. | |
Static Private Member Functions | |
static void * | dqThread (void *v4l2_element_plane) |
The DQ thread function. | |
Private Attributes | |
int & | fd |
FD of the V4l2 Element the plane is associated with. | |
const char * | plane_name |
Name of the plane. | |
enum v4l2_buf_type | buf_type |
Type of the stream. | |
bool | blocking |
Whether the V4l2 element has been opened with blocking mode. | |
uint32_t | num_buffers |
Number of buffers returned by VIDIOC_REQBUFS ioctl. | |
NvBuffer ** | buffers |
Array of NvBuffer object pointers. | |
uint8_t | n_planes |
Number of planes in the buffers. | |
NvBuffer::NvBufferPlaneFormat | planefmts [MAX_PLANES] |
Format of the buffer planes. | |
enum v4l2_memory | memory_type |
V4l2 memory type of the buffers. | |
uint32_t | num_queued_buffers |
Number of buffers currently queued on the plane. | |
uint32_t | total_queued_buffers |
Total number of buffers queued on the plane. | |
uint32_t | total_dequeued_buffers |
Total number of buffers dequeued from the plane. | |
bool | streamon |
Boolean indicating if the plane is streaming. | |
bool | dqthread_running |
Boolean indicating if the DQ Thread is running. | |
bool | stop_dqthread |
Boolean value used to signal the DQ Thread to stop. | |
pthread_t | dq_thread |
pthread ID of the DQ Thread | |
dqThreadCallback | callback |
Callback function used by the DQ Thread. | |
void * | dqThread_data |
Application supplied pointer provided as an argument in dqThreadCallback. | |
NvElementProfiler & | v4l2elem_profiler |
A reference to the profiler belonging to the plane's parent element. | |
int | is_in_error |
Indicates if an error was encountered during the operation of the element. | |
const char * | comp_name |
Specifies the name of the component, for debugging. | |
Friends | |
class | NvV4l2Element |
This class is modelled on the planes of a V4L2 Element. It provides convenient wrapper functions around V4L2 ioctls associated with plane operations such as VIDIOC_G_FMT/VIDIOC_S_FMT, VIDIOC_REQBUFS,\ VIDIOC_STREAMON/VIDIOC_STREAMOFF, etc.
The plane buffer type can be either V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE (for the output plane) or V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE (for the capture plane).
The plane has an array of NvBuffer object pointers which is allocated and initialized during reqbufs call. These NvBuffer objects are similar to the v4l2_buffer structures which are queued/dequeued.
This class provides another feature useful for multi-threading. On calling startDQThread, it internally spawns a thread which runs infinitely till signalled to stop. This thread keeps on trying to dequeue a buffer from the plane and calls a dqThreadCallback function specified by the user on successful dequeue.
Definition at line 92 of file NvV4l2ElementPlane.h.
typedef bool(* NvV4l2ElementPlane::dqThreadCallback)(struct v4l2_buffer *v4l2_buf, NvBuffer *buffer, NvBuffer *shared_buffer, void *data) |
This is a callback function type which is called by the DQ Thread when it successfully dequeues a buffer from the plane.
Applications must implement this and set the callback using setDQThreadCallback.
Setting the stream to off will automatically stop this thread.
v4l2_buf | v4l2_buffer structure which was used for dequeueing | |
buffer | NvBuffer object at the index contained in v4l2_buf | |
shared_buffer | If the plane shares buffer with another elements pointer to the NvBuffer object else NULL | |
data | Pointer to application specific data which was set with startDQThread |
NvV4l2ElementPlane::NvV4l2ElementPlane | ( | enum v4l2_buf_type | buf_type, | |
const char * | device_name, | |||
int & | fd, | |||
bool | blocking, | |||
NvElementProfiler & | profiler | |||
) | [private] |
Creates a new V4l2Element plane.
[in] | buf_type | Type of the stream |
[in] | device_name | Name of the element the plane belongs to |
[in] | fd | FD of the device opened using v4l2_open |
[in] | blocking | Whether the device has been opened with blocking mode |
Definition at line 49 of file NvV4l2ElementPlane.cpp.
NvV4l2ElementPlane::NvV4l2ElementPlane | ( | const NvV4l2ElementPlane & | that | ) | [private] |
Disallow copy constructor.
NvV4l2ElementPlane::~NvV4l2ElementPlane | ( | ) | [private] |
NvV4l2ElementPlane destructor.
Calls deinitPlane internally.
Definition at line 97 of file NvV4l2ElementPlane.cpp.
void NvV4l2ElementPlane::deinitPlane | ( | ) |
Helper function which encapsulates all the function calls required to deinitialize the plane for streaming.
For each of the buffers unmaps/deallocates memory depending on the memory type. Then, calls reqbufs with count zero.
Definition at line 351 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::dqBuffer | ( | struct v4l2_buffer & | v4l2_buf, | |
NvBuffer ** | buffer, | |||
NvBuffer ** | shared_buffer, | |||
uint32_t | num_retries | |||
) |
Dequeue a buffer from the plane.
This is a blocking call. This call returns when a buffer is successfully dequeued or timeout is reached. If buffer is not NULL returns the NvBuffer object at the index returned by the VIDIOC_DQBUF ioctl. If this plane shares a buffer with other element and shared_buffer is not NULL returns the shared NvBuffer object in shared_buffer.
[in] | v4l2_buf | v4l2_buffer structure to be used for dequeueing |
[out] | buffer | Returns the NvBuffer object associated with the dequeued buffer. Can be NULL |
[out] | shared_buffer | Returns the shared NvBuffer object, if the queued buffer is being shared with other elements. Can be NULL. |
[in] | num_retries | Number of times to try dequeuing a buffer before a failure is returned. In case of non-blocking mode, this is equivalent to the number of milliseconds to try to dequeue a buffer. |
Definition at line 116 of file NvV4l2ElementPlane.cpp.
void * NvV4l2ElementPlane::dqThread | ( | void * | v4l2_element_plane | ) | [static, private] |
The DQ thread function.
This function keeps on running infinitely till it is signalled to stop by stopDQThread or the dqThreadCallback function returns false. It keeps on trying to dequeue a buffer from the plane and calls the dqThreadCallback function on successful dequeue
[in] | v4l2_element_plane | Pointer to the NvV4l2ElementPlane object for which the thread has been started |
Definition at line 710 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::exportBuffer | ( | uint32_t | buf_index | ) |
Export the buffer as DMABUF FD.
[in] | buf_index | Index of the buffer to export |
Definition at line 556 of file NvV4l2ElementPlane.cpp.
enum v4l2_buf_type NvV4l2ElementPlane::getBufType | ( | ) | [inline] |
Get the streaming/buffer type of this plane.
Definition at line 237 of file NvV4l2ElementPlane.h.
int NvV4l2ElementPlane::getCrop | ( | struct v4l2_crop & | crop | ) |
Get the cropping rectangle for the plane.
Calls VIDIOC_G_CROP ioctl internally.
[in] | crop | Reference to v4l2_crop structure to be filled |
Definition at line 303 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::getFormat | ( | struct v4l2_format & | format | ) |
Get the plane format.
Calls VIDIOC_G_FMT ioctl internally.
[in,out] | format | Reference to v4l2_format structure to be filled |
Definition at line 268 of file NvV4l2ElementPlane.cpp.
NvBuffer * NvV4l2ElementPlane::getNthBuffer | ( | uint32_t | n | ) |
Get the NvBuffer object at index n.
Definition at line 104 of file NvV4l2ElementPlane.cpp.
uint32_t NvV4l2ElementPlane::getNumBuffers | ( | ) | [inline] |
Get the number of buffers allocated/requested on the plane.
Definition at line 289 of file NvV4l2ElementPlane.h.
uint32_t NvV4l2ElementPlane::getNumPlanes | ( | ) | [inline] |
Get the number of planes buffers on this plane contain for the currently set format.
Definition at line 300 of file NvV4l2ElementPlane.h.
uint32_t NvV4l2ElementPlane::getNumQueuedBuffers | ( | ) | [inline] |
Get the number of buffers currently queued on the plane.
Definition at line 326 of file NvV4l2ElementPlane.h.
bool NvV4l2ElementPlane::getStreamStatus | ( | ) |
Check if the plane is streaming.
Definition at line 494 of file NvV4l2ElementPlane.cpp.
uint32_t NvV4l2ElementPlane::getTotalDequeuedBuffers | ( | ) | [inline] |
Get the total number of buffers dequeued from the plane.
Definition at line 336 of file NvV4l2ElementPlane.h.
uint32_t NvV4l2ElementPlane::getTotalQueuedBuffers | ( | ) | [inline] |
Get the total number of buffers queued on the plane.
Definition at line 346 of file NvV4l2ElementPlane.h.
int NvV4l2ElementPlane::isInError | ( | ) | [inline, private] |
Indicates if the plane encountered an error during its operation.
Definition at line 513 of file NvV4l2ElementPlane.h.
void NvV4l2ElementPlane::operator= | ( | NvV4l2ElementPlane const & | ) | [private] |
Disallow assignment.
int NvV4l2ElementPlane::qBuffer | ( | struct v4l2_buffer & | v4l2_buf, | |
NvBuffer * | shared_buffer | |||
) |
Queue a buffer on the plane.
This function calls VIDIOC_QBUF internally. If this plane is sharing buffer with other elements, the application can pass the pointer to the shared NvBuffer object in shared_buffer.
[in] | v4l2_buf | v4l2_buffer structure to be used for queueing |
[in] | shared_buffer | Pointer to the shared NvBuffer object |
Definition at line 187 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::queryBuffer | ( | uint32_t | buf_index | ) |
Query the status of buffer at index.
[in] | buf_index | Index of the buffer to query |
Definition at line 519 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::reqbufs | ( | enum v4l2_memory | mem_type, | |
uint32_t | num | |||
) |
Request for buffers on the plane.
Calls VIDIOC_REQBUFS ioctl internally. Creates an array of NvBuffer of length equal to the count returned by the ioctl.
[in] | mem_type | Type of V4L2 Memory to be requested |
[in] | num | Number of buffers to request on the plane |
Definition at line 376 of file NvV4l2ElementPlane.cpp.
void NvV4l2ElementPlane::setBufferPlaneFormat | ( | int | n_planes, | |
NvBuffer::NvBufferPlaneFormat * | planefmts | |||
) |
Set the format of the planes of the buffer which will be used with this plane.
The buffer plane format needs to be set before calling reqbufs, since these are needed by the NvBuffer constructor.
[in] | n_planes | Number of planes in the buffer |
[in] | planefmts | Array of NvBufferPlaneFormat which describes the format of each of the plane. The array length should be at least n_planes. |
Definition at line 338 of file NvV4l2ElementPlane.cpp.
bool NvV4l2ElementPlane::setDQThreadCallback | ( | dqThreadCallback | callback | ) |
Set the DQ Thread callback function.
The callback function is called from the DQ Thread once a buffer is successfully dequeued.
[in] | callback | Function to be called on succesful dequeue |
Definition at line 701 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::setFormat | ( | struct v4l2_format & | format | ) |
Set the plane format.
Calls VIDIOC_S_FMT ioctl internally.
[in] | format | Reference to v4l2_format structure to be set on the plane |
Definition at line 276 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::setSelection | ( | uint32_t | target, | |
uint32_t | flags, | |||
struct v4l2_rect & | rect | |||
) |
Set the selection rectangle for the plane.
Calls VIDIOC_S_SELECTION ioctl internally.
[in] | target | Rectangle selection type |
[in] | flags | Flags to control selection adjustments |
[in] | rect | Selection rectangle |
Definition at line 312 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::setStreamParms | ( | struct v4l2_streamparm & | parm | ) |
Set streaming parameters.
Calls VIDIOC_S_PARM ioctl internally.
[in] | parm | Reference to v4l2_streamparm structure to be set on the plane |
Definition at line 500 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::setStreamStatus | ( | bool | status | ) |
Start or stop streaming on the plane.
Calls VIDIOC_STREAMON/VIDIOC_STREAMOFF ioctls internally.
[in] | status | Should be true to start stream, false to stop stream |
Definition at line 440 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::setupPlane | ( | enum v4l2_memory | mem_type, | |
uint32_t | num_buffers, | |||
bool | map, | |||
bool | allocate | |||
) |
Helper function which encapsulates all the function calls required to setup the plane for streaming.
Calls reqbufs internally. Then, for each of the buffers calls queryBuffer, exportBuffer and maps the buffer/allocates the buffer memory depending on the memory type.
[in] | mem_type | V4L2 Memory to use on the buffer |
[in] | num_buffers | Number of buffer to request on the plane |
[in] | map | boolean value indicating if the buffers should be mapped to memory (Only for V4L2_MEMORY_MMAP) |
[in] | allocate | boolean valued indicating if the buffers should be allocated memory (Only for V4L2_MEMORY_USERPTR) |
Definition at line 588 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::startDQThread | ( | void * | data | ) |
Start DQ Thread.
This function starts a thread internally. On successful dequeue of a buffer from the plane, dqThreadCallback function set using setDQThreadCallback gets called.
Setting the stream to off will automatically stop the thread.
[in] | data | Application data pointer. This is provided as an argument in the dqThreadCallback function |
Definition at line 768 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::stopDQThread | ( | ) |
Force stop the DQ Thread if it is running.
Does not work when the device has been opened in blocking mode.
Definition at line 786 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::waitAllBuffersDequeued | ( | uint32_t | max_wait_ms | ) |
Wait till all the buffers of the plane get dequeued.
This is a blocking call which returns when all the buffers get dequeued or timeout is reached.
[in] | max_wait_ms | Maximum time to wait in milliseconds |
Definition at line 672 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::waitAllBuffersQueued | ( | uint32_t | max_wait_ms | ) |
Wait till all the buffers of the plane get queued.
This is a blocking call which returns when all the buffers get queued or timeout is reached.
[in] | max_wait_ms | Maximum time to wait in milliseconds |
Definition at line 642 of file NvV4l2ElementPlane.cpp.
int NvV4l2ElementPlane::waitForDQThread | ( | uint32_t | max_wait_ms | ) |
Wait for the DQ Thread to stop.
This function waits till the DQ Thread stops or timeout is reached
[in] | max_wait_ms |
Definition at line 801 of file NvV4l2ElementPlane.cpp.
friend class NvV4l2Element [friend] |
Definition at line 551 of file NvV4l2ElementPlane.h.
bool NvV4l2ElementPlane::blocking [private] |
Whether the V4l2 element has been opened with blocking mode.
Definition at line 455 of file NvV4l2ElementPlane.h.
enum v4l2_buf_type NvV4l2ElementPlane::buf_type [private] |
NvBuffer** NvV4l2ElementPlane::buffers [private] |
Array of NvBuffer object pointers.
This array is allocated and initialized in reqbufs.
Definition at line 460 of file NvV4l2ElementPlane.h.
dqThreadCallback NvV4l2ElementPlane::callback [private] |
const char* NvV4l2ElementPlane::comp_name [private] |
Specifies the name of the component, for debugging.
Definition at line 548 of file NvV4l2ElementPlane.h.
pthread_t NvV4l2ElementPlane::dq_thread [private] |
void* NvV4l2ElementPlane::dqThread_data [private] |
Application supplied pointer provided as an argument in dqThreadCallback.
Definition at line 488 of file NvV4l2ElementPlane.h.
bool NvV4l2ElementPlane::dqthread_running [private] |
Boolean indicating if the DQ Thread is running.
Its value is toggled by the DQ Thread
Definition at line 480 of file NvV4l2ElementPlane.h.
int& NvV4l2ElementPlane::fd [private] |
FD of the V4l2 Element the plane is associated with.
Definition at line 448 of file NvV4l2ElementPlane.h.
int NvV4l2ElementPlane::is_in_error [private] |
Indicates if an error was encountered during the operation of the element.
Definition at line 546 of file NvV4l2ElementPlane.h.
enum v4l2_memory NvV4l2ElementPlane::memory_type [private] |
uint8_t NvV4l2ElementPlane::n_planes [private] |
uint32_t NvV4l2ElementPlane::num_buffers [private] |
Number of buffers returned by VIDIOC_REQBUFS ioctl.
Definition at line 458 of file NvV4l2ElementPlane.h.
uint32_t NvV4l2ElementPlane::num_queued_buffers [private] |
Number of buffers currently queued on the plane.
Definition at line 471 of file NvV4l2ElementPlane.h.
pthread_cond_t NvV4l2ElementPlane::plane_cond |
Plane condition which application can wait on to receive notifications from qBuffer/dqBuffer.
Definition at line 443 of file NvV4l2ElementPlane.h.
pthread_mutex_t NvV4l2ElementPlane::plane_lock |
const char* NvV4l2ElementPlane::plane_name [private] |
Name of the plane.
Could be "Output Plane" or "Capture Plane". Used only for debug logs
Definition at line 450 of file NvV4l2ElementPlane.h.
NvBuffer::NvBufferPlaneFormat NvV4l2ElementPlane::planefmts[MAX_PLANES] [private] |
Format of the buffer planes.
This should be initialized before calling reqbufs since this is required by the NvBuffer constructor
Definition at line 465 of file NvV4l2ElementPlane.h.
bool NvV4l2ElementPlane::stop_dqthread [private] |
Boolean value used to signal the DQ Thread to stop.
Definition at line 482 of file NvV4l2ElementPlane.h.
bool NvV4l2ElementPlane::streamon [private] |
uint32_t NvV4l2ElementPlane::total_dequeued_buffers [private] |
Total number of buffers dequeued from the plane.
Definition at line 475 of file NvV4l2ElementPlane.h.
uint32_t NvV4l2ElementPlane::total_queued_buffers [private] |
A reference to the profiler belonging to the plane's parent element.
Definition at line 504 of file NvV4l2ElementPlane.h.