HVD
HVD Hardware Video Decoder library
Public interface

Data Structures

struct  hvd_config
 Decoder configuration. More...
 
struct  hvd_packet
 Encoded data packet. More...
 
struct  hvd
 Internal library data passed around by the user. More...
 

Enumerations

enum  hvd_retval_enum { HVD_AGAIN =AVERROR(EAGAIN), HVD_ERROR =-1, HVD_OK =0 }
 Constants returned by most of library functions. More...
 

Functions

struct hvdhvd_init (const struct hvd_config *config)
 Initialize internal library data. More...
 
void hvd_close (struct hvd *h)
 Free library resources. More...
 
int hvd_send_packet (struct hvd *h, struct hvd_packet *packet)
 Send packet to hardware for decoding. More...
 
AVFrame * hvd_receive_frame (struct hvd *h, int *error)
 Retrieve decoded frame data from hardware. More...
 

Detailed Description

Enumeration Type Documentation

Constants returned by most of library functions.

Enumerator
HVD_AGAIN 

hvd_send_packet was not accepted (e.g. buffers full), use hvd_receive_frame before next call

HVD_ERROR 

error occured

HVD_OK 

succesfull execution

Function Documentation

void hvd_close ( struct hvd h)

Free library resources.

Cleans and frees library memory.

Parameters
hpointer to internal library data
See also
hvd_init
struct hvd* hvd_init ( const struct hvd_config config)

Initialize internal library data.

Parameters
configdecoder configuration
Returns
  • pointer to internal library data
  • NULL on error, errors printed to stderr
See also
hvd_config, hvd_close
AVFrame* hvd_receive_frame ( struct hvd h,
int *  error 
)

Retrieve decoded frame data from hardware.

Keep calling this functions after hvd_send_packet until NULL is returned. The ownership of returned FFmpeg AVFrame remains with the library:

  • consume it immidiately
  • or copy the data
Parameters
hpointer to internal library data
errorpointer to error code
Returns
  • AVFrame* pointer to FFMpeg AVFrame, you are mainly interested in data and linesize arrays
  • NULL when no more data is pending, query error argument to check result (HVD_OK on success)
See also
hvd_send_packet

Example (in decoding loop):

1 //send data for hardware decoding
2 if(hvd_send_packet(h, packet) != HVD_OK)
3  break; //break on error
4 
5 //get the decoded data
6 while( (frame = hvd_receive_frame(av, &error) ) )
7 {
8  //do something with frame->data, frame->linesize
9 }
10 
11 //NULL frame and non-zero failed indicates failure during decoding
12 if(failed)
13  break; //break on error
int hvd_send_packet ( struct hvd h,
struct hvd_packet packet 
)

Send packet to hardware for decoding.

Pass data in hvd_packet for decoding. Follow with hvd_receive_frame to get decoded data from hardware.

If you have simple loop like:

  • send encoded data with hve_send_packet
  • receive decoded data with hve_receive_frame

HVD_AGAIN return value will never happen. If you are sending lots of data and not reading you may get HVD_AGAIN when buffers are full.

When you are done with decoding call with:

  • NULL packet argument
  • or packet with NULL data and 0 size to flush the decoder and follow with hvd_receive_frame as usual to get last frames from decoder.

After flushing and reading last frames you can follow with decoding new stream.

Perfomance hints:

  • don't copy data from your source, pass the pointer in packet->data
Parameters
hpointer to internal library data
packetdata to decode
Returns
  • HVD_OK on success
  • HVD_ERROR on error
  • HVD_AGAIN input was rejected, read data with hvd_receive_packet before next try
See also
hvd_packet, hvd_receive_frame

Example flushing:

1 //flush
2 hvd_send_packet(hardware_decoder, NULL);
3 
4 //retrieve last frames from decoder as usual
5 while( (frame=hvd_receive_frame(hardware_decoder, &failed)) )
6 {
7  //do something with frame->data, frame->linesize
8 }
9 
10 //NULL frame and non-zero failed indicates failure during decoding
11 if(failed)
12  //your logic on failure
13 
14 //terminate or continue decoding new stream