L4T Multimedia API Reference

27.1 Release

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NvJPEGEncoder Class Reference

Detailed Description

NvJpegEncoder uses the libjpeg APIs for decoding JPEG images.

It supports two methods for encoding:

  • Encode using a file descriptor (FD) of the MMAP buffer created by a V4L2 element (supports YUV420 and NV12 color formats).
  • Encode using data pointers in NvBuffer object, i.e., software allocated memory (malloc); supports YUV420 color format.
Note
Only the JCS_YCbCr (YUV420) color space is currently supported.

Definition at line 85 of file NvJpegEncoder.h.

Inheritance diagram for NvJPEGEncoder:
Collaboration diagram for NvJPEGEncoder:

Public Member Functions

 ~NvJPEGEncoder ()
 
int encodeFromFd (int fd, J_COLOR_SPACE color_space, unsigned char **out_buf, unsigned long &out_buf_size)
 Encodes a JPEG image from a file descriptor (FD) of hardware buffer memory. More...
 
int encodeFromBuffer (NvBuffer &buffer, J_COLOR_SPACE color_space, unsigned char **out_buf, unsigned long &out_buf_size)
 Encodes a JPEG image from software buffer memory. More...
 
void setCropRect (uint32_t left, uint32_t top, uint32_t width, uint32_t height)
 Sets the cropping rectangle used by the JPEG encoder. More...
 
virtual int isInError ()
 Indicates if the element encountered an error during its operation. More...
 
void getProfilingData (NvElementProfiler::NvElementProfilerData &data)
 Gets profiling data for the element. More...
 
void printProfilingStats (std::ostream &out_stream=std::cout)
 Prints profiling data for the element to an output stream. More...
 
virtual void enableProfiling ()
 Enables profiling for the element. More...
 
bool isProfilingEnabled ()
 Checks whether profiling is enabled for the element. More...
 

Static Public Member Functions

static NvJPEGEncodercreateJPEGEncoder (const char *comp_name)
 Create a new JPEG Encoder named comp_name. More...
 

Protected Attributes

int is_in_error
 Indicates if an error was encountered during the operation of the element. More...
 
const char * comp_name
 Specifies the name of the component, for debugging. More...
 
NvElementProfiler profiler
 Profiler for the element. More...
 

Constructor & Destructor Documentation

NvJPEGEncoder::~NvJPEGEncoder ( )

Member Function Documentation

static NvJPEGEncoder* NvJPEGEncoder::createJPEGEncoder ( const char *  comp_name)
static

Create a new JPEG Encoder named comp_name.

Returns
Reference to the newly created decoder object, or NULL in case of failure during initialization.
virtual void NvElement::enableProfiling ( )
virtualinherited

Enables profiling for the element.

Reimplemented in NvV4l2Element.

int NvJPEGEncoder::encodeFromBuffer ( NvBuffer buffer,
J_COLOR_SPACE  color_space,
unsigned char **  out_buf,
unsigned long &  out_buf_size 
)

Encodes a JPEG image from software buffer memory.

The application may allocate the memory for storing the JPEG image. If the allocation is less than what is required, libjpeg allocates more memory. The out_buf pointer and out_buf_size are updated accordingly.

The encodeFromBuffer method is slower than NvJPEGEncoder::encodeFromFd because encodeFromBuffer involves conversion from software buffer memory to hardware buffer memory.

Supports the YUV420 format only.

Attention
The application must free the out_buf memory.
Parameters
[out]bufferIndicates the NvBuffer object to contain the encoded image.
[out]color_spaceIndicates the color_space to use for encoding.
[in]out_bufSpecifies a pointer to the memory for the JPEG image.
[in]out_buf_sizeSpecifies the size of the output buffer in bytes.
Returns
0 for success, -1 otherwise.
int NvJPEGEncoder::encodeFromFd ( int  fd,
J_COLOR_SPACE  color_space,
unsigned char **  out_buf,
unsigned long &  out_buf_size 
)

Encodes a JPEG image from a file descriptor (FD) of hardware buffer memory.

The application may allocate the memory for storing the JPEG image. If the allocation is less than what is required, libjpeg allocates more memory. The out_buf pointer and out_buf_size are updated accordingly.

Supports YUV420 and NV12 formats.

Attention
The application must free the out_buf memory.
Parameters
[out]fdIndicates the file descriptor (FD) of the hardware buffer.
[out]color_spaceIndicates the color_space to use for encoding.
[in]out_bufSpecifies a pointer to the memory for the JPEG image.
[in]out_buf_sizeSpecifies the size of the output buffer in bytes.
Returns
0 for success, -1 otherwise.
void NvElement::getProfilingData ( NvElementProfiler::NvElementProfilerData &  data)
inherited

Gets profiling data for the element.

Returns
A constant reference to the element's profiling data.
virtual int NvElement::isInError ( )
inlinevirtualinherited

Indicates if the element encountered an error during its operation.

Returns
0 if no error was encountered, a non-zero value if an error was encountered.

Reimplemented in NvV4l2Element.

Definition at line 72 of file NvElement.h.

References NvElement::is_in_error.

bool NvElement::isProfilingEnabled ( )
inherited

Checks whether profiling is enabled for the element.

Returns
Boolean value indicating if profiling is enabled.
void NvElement::printProfilingStats ( std::ostream &  out_stream = std::cout)
inherited

Prints profiling data for the element to an output stream.

Parameters
[in]out_streamOutput stream of type std::ostream to print the data to. It takes the default value std::cout if not specified.
void NvJPEGEncoder::setCropRect ( uint32_t  left,
uint32_t  top,
uint32_t  width,
uint32_t  height 
)

Sets the cropping rectangle used by the JPEG encoder.

This method must be called before encodeFromFd or encodeFromBuffer for the cropping to take effect.

Attention
The JPEG encoder resets the crop paramaters after each call to jpeg_finish_compress. Therefore, this method must be called before every call to encodeFromFd or encodeFromBuffer.
Parameters
[in]leftHorizontal offset of the cropping rectangle, in pixels.
[in]topVertical offset of the cropping rectangle, in pixels.
[in]widthWidth of the cropping rectangle, in pixels.
[in]heightHeight of the cropping rectangle, in pixels.

Field Documentation

const char* NvElement::comp_name
protectedinherited

Specifies the name of the component, for debugging.

Definition at line 122 of file NvElement.h.

int NvElement::is_in_error
protectedinherited

Indicates if an error was encountered during the operation of the element.

Definition at line 120 of file NvElement.h.

Referenced by NvElement::isInError().

NvElementProfiler NvElement::profiler
protectedinherited

Profiler for the element.

Definition at line 124 of file NvElement.h.


The documentation for this class was generated from the following file: