Downloading with LibXCoder
Input Preparation, Purpose
The HW download is somewhat unique in its implementation in comparison to the other jobs like decoding, uploading, and encoding. The inputs to the hwdownload must be HW frames from a previous session such as an output from the list below:
- Decoder in hwframe mode (excluding tiled4x4 format)
- Scaler
- Uploader
The purpose of the download is to convert HW frame formats into SW frame formats which are still compatible with with Quadra encoding. A typical scenario would be one such as downloading a HW frame from Quadra device A and sending it to Quadra device B since B does not have access to device A’s memory for processing video data.
Downloading Sequence
The downloading sequence is very short and is comprised of these main steps
- Prepare output buffer to contain raw frame info
- Download the data using the HW frame as input
- Freeing buffers where necessary
- Example below shows immediate HW frame buffer recycle but that is sequence specific. If there are parallel processes using the HWFrame, the aformentioned frame tracking mechanism is recommeneded and unreferencing the frame is the correct behaviour
- The hwdownload output buffer may be reused each time as long as the downstream user is no longer reading from it.
Example:
ni_session_data_io_t hwdl_session_data = {0};
ni_session_data_io_t *p_session_data = &hwdl_session_data;
niFrameSurface1_t *src_surf = (niFrameSurface1_t *)(p_src_frame->p_data[3]);
int ret = 0;
int pixel_format = NI_PIX_FMT_YUV420P; //could be others
ret = ni_frame_buffer_alloc_dl(&(p_session_data->data.frame), src_surf->ui16width, src_surf->ui16height, pixel_format);
if (ret != NI_RETCODE_SUCCESS)
{
return NI_RETCODE_ERROR_MEM_ALOC;
{
p_ctx->is_auto_dl = false; //for encoder internal download if true
ret = ni_device_session_hwdl(p_ctx, p_session_data, src_surf);
//Unref the hwframe if hwframe tracking used.
//Below is if no other entity is using the hwframe
ni_hwframe_buffer_recycle2(src_surf);
if (ret <= 0)
{
ni_frame_buffer_free(&p_session_data->data.frame);
return ret
}
//Do whatever is required with the output frame in p_session_data
//Note, the frame buffer for hwdownload may be reused
ni_frame_buffer_free(&(hwdl_session_data.data.frame));