HVE
HVE Hardware Video Encoder library
Public interface

Data Structures

struct  hve_config
 Encoder configuration. More...
 
struct  hve_frame
 Data to be encoded (single frame). More...
 
struct  hve
 Internal library data passed around by the user. More...
 

Enumerations

enum  hve_retval_enum { HVE_ERROR =-1, HVE_OK =0 }
 Constants returned by most of library functions. More...
 

Functions

struct hvehve_init (const struct hve_config *config)
 initialize internal library data. More...
 
void hve_close (struct hve *h)
 free library resources More...
 
int hve_send_frame (struct hve *h, struct hve_frame *frame)
 Send frame to hardware for encoding. More...
 
AVPacket * hve_receive_packet (struct hve *h, int *error)
 Retrieve encoded frame data from hardware. More...
 

Detailed Description

Enumeration Type Documentation

Constants returned by most of library functions.

Enumerator
HVE_ERROR 

error occured with errno set

HVE_OK 

succesfull execution

Function Documentation

void hve_close ( struct hve h)

free library resources

Cleans and frees memory

Parameters
hpointer to internal library data
struct hve* hve_init ( const struct hve_config config)

initialize internal library data.

Parameters
configencoder configuration
Returns
  • pointer to internal library data
  • NULL on error, errors printed to stderr
See also
hve_config, hve_close
AVPacket* hve_receive_packet ( struct hve h,
int *  error 
)

Retrieve encoded frame data from hardware.

Keep calling this functions after hve_send_frame until NULL is returned. The ownership of returned AVPacket remains with the library:

  • consume it immidiately
  • or copy the data

While beginning encoding you may have to send a few frames before you will get packets. When flushing the encoder you may get multiple packets afterwards.

Parameters
hpointer to internal library data
errorpointer to error code
Returns
  • AVPacket * pointer to FFMpeg AVPacket, you are mainly interested in data and size members
  • NULL when no more data is pending, query error parameter to check result (HVE_OK on success)
See also
hve_send_frame

Example (in encoding loop):

1 if( hve_send_frame(hardware_encoder, &frame) != HVE_OK)
2  break; //break on error
3 
4 while( (packet=hve_receive_packet(hardware_encoder, &failed)) )
5 {
6  //do something with packet->data, packet->size
7 }
8 
9 //NULL packet and non-zero failed indicates failure during encoding
10 if(failed)
11  break; //break on error
int hve_send_frame ( struct hve h,
struct hve_frame frame 
)

Send frame to hardware for encoding.

Call this for each frame you want to encode. Follow with hve_receive_packet to get encoded data from hardware. Call with NULL frame argument to flush the encoder when you want to finish encoding. After flushing follow with hve_receive_packet to get last encoded frames. After flushing it is not possible to reuse the encoder.

The pixel format of the frame should match the one specified in hve_init.

Hardware accelerated scaling is performed before encoding if non-zero input_width and input_height different from width and height were specified in hve_init.

Perfomance hints:

  • don't copy data from your source, just pass the pointers to data planes
Parameters
hpointer to internal library data
framedata to encode
Returns
  • HVE_OK on success
  • HVE_ERROR indicates error
See also
hve_frame, hve_receive_packet

Example flushing:

1 hve_send_frame(hardware_encoder, NULL);
2 
3 while( (packet=hve_receive_packet(hardware_encoder, &failed)) )
4 {
5  //do something with packet->datag, packet->size
6 }
7 
8 //NULL packet and non-zero failed indicates failure during encoding
9 if(failed)
10  //your logic on failure