MWCapture SDK Linux  3.3.1.LAST_SVN_COMMIT_NUM
Typedefs | Functions
Hardware Encoder Module Functions

Typedefs

typedef void(* MW_ENCODER_CALLBACK) (void *user_ptr, const uint8_t *p_frame, uint32_t frame_len, mw_venc_frame_info_t *p_frame_info)
 Callback functions. More...
 

Functions

mw_venc_status_t mw_venc_init ()
 Initializes mw_venc. More...
 
mw_venc_status_t mw_venc_deinit ()
 Destroys mw_venc. More...
 
int32_t mw_venc_get_gpu_num ()
 Obtains the number of GPUs for hardware video encoding and decoding. More...
 
mw_venc_status_t mw_venc_get_gpu_info_by_index (int32_t index, mw_venc_gpu_info_t *info)
 Obtains hardware information of GPU by index. More...
 
mw_venc_status_t mw_venc_get_default_param (mw_venc_param_t *p_param)
 Gets the default value of encoding parameters. More...
 
uint32_t mw_venc_get_support_platfrom ()
 Gets supported encoding hardware platform. More...
 
mw_venc_handle_t mw_venc_create (mw_venc_platform_t platform, mw_venc_param_t *p_param, MW_ENCODER_CALLBACK frame_callback, void *user_ptr)
 Creates an encoder. More...
 
mw_venc_handle_t mw_venc_create_by_index (int32_t index, mw_venc_param_t *p_param, MW_ENCODER_CALLBACK frame_callback, void *user_ptr)
 Ctreats an encoder. More...
 
mw_venc_status_t mw_venc_put_frame (mw_venc_handle_t handle, uint8_t *p_frame)
 Imports data to encoders. More...
 
mw_venc_status_t mw_venc_put_frame_ex (mw_venc_handle_t handle, uint8_t *p_frame, int64_t pts)
 Imports data to encoders. More...
 
mw_venc_status_t mw_venc_destory (mw_venc_handle_t handle)
 Destroys encoders. More...
 
mw_venc_status_t mw_venc_get_property (mw_venc_handle_t handle, mw_venc_property_t param, void *args)
 Gets encoder parameters. More...
 
mw_venc_status_t mw_venc_set_property (mw_venc_handle_t handle, mw_venc_property_t param, void *args)
 Sets encoder parameters. More...
 

Detailed Description

Typedef Documentation

typedef void(* MW_ENCODER_CALLBACK) (void *user_ptr, const uint8_t *p_frame, uint32_t frame_len, mw_venc_frame_info_t *p_frame_info)

Callback functions.

out code date.
Related function(s):
mw_venc_create
mw_venc_create_ex

Function Documentation

mw_venc_handle_t mw_venc_create ( mw_venc_platform_t  platform,
mw_venc_param_t p_param,
MW_ENCODER_CALLBACK  frame_callback,
void *  user_ptr 
)

Creates an encoder.

Parameters
[in]platformHardware encoding platform
[in]p_paramEncoder parameters
[in]frame_callbackEncoder callback function
[in]user_ptrCallback parameter
Returns
Returns the encoder handle if succeeded, otherwise returns NULL.

Usage:
The recommended way to call the function is as follows.

1  ....
2  // Callback function
3  void encode_callback(
4  void * user_ptr,
5  const uint8_t * p_frame,
6  uint32_t frame_len,
7  mw_venc_frame_info_t *p_frame_info)
8  {
9  // Processes data
10  }
11  ...
12  mw_venc_init();
13  ...
14  mw_venc_handle_t t_handle = NULL;
15  mw_venc_platform_t t_platfrom = MW_VENC_PLATFORM_UNKNOWN;
16  mw_venc_param_t t_venc_param;
17  mw_venc_status_t t_venc_stat = MW_VENC_STATUS_SUCCESS;
18  mw_venc_get_default_param(&t_venc_param);
19  uint32 t_u32_platfrom = mw_venc_get_support_platfrom();
20  if(t_u32_platfrom & MW_VENC_PLATFORM_AMD){
21  //For AMD
22  t_platfrom = MW_VENC_PLATFORM_AMD;
23  }
24  if(t_u32_platform & MW_VENC_PLATFORM_INTEL){
25  //For Intel
26  t_platfrom = MW_VENC_PLATFORM_INTEL;
27  }
28  if(t_u32_platform & MW_VENC_PLATFORM_NVIDIA){
29  //For Nvidia
30  t_platfrom = MW_VENC_PLATFORM_NVIDIA;
31  }
32  t_venc_param.code_type = MW_VENC_CODE_TYPE_H264;
33  t_venc_param.fourcc = MW_VENC_FOURCC_NV12;
34  t_venc_param.targetusage = MW_VENC_TARGETUSAGE_BALANCED;
35  t_venc_param.rate_control.mode = MW_VENC_RATECONTROL_CBR;
36  t_venc_param.rate_control.target_bitrate = 4096;
37  t_venc_param.width = 1920;
38  t_venc_param.height = 1080;
39  t_venc_param.profile = MW_VENC_PROFILE_H264_MAIN;
40  ...
41  // Creates an encoder
42  t_handle = mw_venc_create(t_platfrom,&t_venc_param,encode_callback,NULL);
43  ...
44  // Inputs data char* t_p_data;
45  t_venc_stat = mw_venc_put_frame(t_handle,t_p_data);
46  ...
47  // Gets parameters of encoder
48  mw_venc_property_t t_property = MW_VENC_PROPERTY_FPS;
49  mw_venc_fps_t t_fps;
50  t_venc_stat = mw_venc_get_property(t_handle,t_property,&t_fps);
51  ...
52  //Modifies parameters of encoder
53  t_fps.num = 30;
54  t_fps.den = 1;
55  t_venc_stat = mw_venc_set_property(t_handle,t_property,&t_fps);
56  ...
57  // Destroys the encoder
58  t_venc_stat = mw_venc_destory(t_handle);
59  t_handle = NULL;
60  ...
61 mw_venc_deinit();
62  ...
mw_venc_handle_t mw_venc_create_by_index ( int32_t  index,
mw_venc_param_t p_param,
MW_ENCODER_CALLBACK  frame_callback,
void *  user_ptr 
)

Ctreats an encoder.

Parameters
[in]indexindex of GPU used for hardware encoding
[in]p_paramparameters of the encoder
[in]frame_callbackcallback
[in]user_ptrcallback parameters
Returns
If succeeded, it returns the encoder handle; otherwise, it returns NULL.

Usage:
The recommended way to call the function is as follows.

1 ....
2 // callback
3 void encode_callback(
4  void * user_ptr,
5  const uint8_t * p_frame,
6  uint32_t frame_len,
7  mw_venc_frame_info_t *p_frame_info)
8 {
9  // Processes data
10 }
11 ...
12 mw_venc_init();
13 ...
14 mw_venc_handle_t t_handle = NULL;
15 mw_venc_platform_t t_platfrom = MW_VENC_PLATFORM_UNKNOWN;
16 mw_venc_param_t t_venc_param;
17 mw_venc_status_t t_venc_stat = MW_VENC_STATUS_SUCCESS;
18 mw_venc_get_default_param(&t_venc_param);
19 int t_n_num = mw_venc_get_gpu_num();
20 int t_n_index = -1;
21 if(t_n_num>0)
22  t_n_index = 0;
23 t_venc_param.code_type = MW_VENC_CODE_TYPE_H264;
24 t_venc_param.fourcc = MW_VENC_FOURCC_NV12;
25 t_venc_param.targetusage = MW_VENC_TARGETUSAGE_BALANCED;
26 t_venc_param.rate_control.mode = MW_VENC_RATECONTROL_CBR;
27 t_venc_param.rate_control.target_bitrate = 4096;
28 t_venc_param.width = 1920;
29 t_venc_param.height = 1080;
30 t_venc_param.profile = MW_VENC_PROFILE_H264_MAIN;
31 ...
32 // Creates an encoder
33 t_handle = mw_venc_create_by_index(t_n_index,&t_venc_param,encode_callback,NULL);
34 ...
35 // Inputs data char* t_p_data;
36 t_venc_stat = mw_venc_put_frame(t_handle,t_p_data);
37 ...
38 // Obtains encoder parameters
39 mw_venc_property_t t_property = MW_VENC_PROPERTY_FPS;
40 mw_venc_fps_t t_fps;
41 t_venc_stat = mw_venc_get_property(t_handle,t_property,&t_fps);
42 ...
43 // Modifys encoder parameters
44 t_fps.num = 30;
45 t_fps.den = 1;
46 t_venc_stat = mw_venc_set_property(t_handle,t_property,&t_fps);
47 ...
48 // Destroys the encoder
49 t_venc_stat = mw_venc_destory(t_handle);
50 t_handle = NULL;
51 ...
52 mw_venc_deinit();
53 ...
mw_venc_status_t mw_venc_deinit ( )

Destroys mw_venc.

Returns
Returns mw_venc_status_t, by default it is MW_VENC_STATUS_SUCCESS.

Usage: Refers to mw_venc_init

mw_venc_status_t mw_venc_destory ( mw_venc_handle_t  handle)

Destroys encoders.

Parameters
[in]handleEncoder handle
Returns
The possible return values of mw_venc_status_t are as follows.
MW_VENC_STATUS_SUCCESS Function call succeeded.
MW_VENC_STATUS_INVALID_PARAM Input invalid value(s).

Usage:
The usage refers to mw_venc_create mw_venc_create_by_index

mw_venc_status_t mw_venc_get_default_param ( mw_venc_param_t p_param)

Gets the default value of encoding parameters.

Parameters
[out]p_paramencoding parameters
Returns
The values of returned mw_venc_status_t are as follows.
MW_VENC_STATUS_SUCCESS Function call succeeded.
MW_VENC_STATUS_INVALID_PARAM Input invalid value(s).

Related type(s):
mw_venc_param_t
Sets the default value of the parameters.

1 p_param->code_type = MW_VENC_CODE_TYPE_UNKNOWN;
2 p_param->fourcc = MW_VENC_FOURCC_UNKNOWN;
3 p_param->targetusage = MW_VENC_TARGETUSAGE_BALANCED;
4 p_param->rate_control.mode = MW_VENC_RATECONTROL_UNKNOWN;
5 p_param->rate_control.target_bitrate = 0;
6 p_param->rate_control.max_bitrate = 0;
7 p_param->width = 0;
8 p_param->height = 0;
9 p_param->fps.num = 60;
10 p_param->fps.den = 1;
11 p_param->slice_num = 1;
12 p_param->gop_pic_size = 60;
13 p_param->gop_ref_size = 1;
14 p_param->profile = MW_VENC_PROFILE_UNKNOWN;
15 p_param->level = MW_VENC_LEVEL_5_1;
16 p_param->amd_mem_reserved = MW_VENC_AMD_MEM_DX11;
mw_venc_status_t mw_venc_get_gpu_info_by_index ( int32_t  index,
mw_venc_gpu_info_t info 
)

Obtains hardware information of GPU by index.

Returns
Returns mw_venc_status_t. The possible return values are as follows.
MW_VENC_STATUS_SUCCESS Function call succeeded.
MW_VENC_STATUS_INVALID_PARAM Input invalid value(s).

Related type(s):
mw_venc_gpu_info_t Usage:

1 mw_venc_status_t t_status = MW_VENC_STATUS_SUCCESS;
2 mw_venc_init();
3 ...
4 int t_n_num = mw_venc_get_gpu_num();
5 ...
6 uint32 t_u32_platforms = mw_venc_get_support_platfrom();
7 for(int i=0;i<t_u32_platforms;i++){
8  mw_venc_gpu_info_t t_gou_info;
9  t_status = mw_venc_get_gpu_info_by_index(i,&t_gpu_info);
10  if(t_status == MW_VENC_STATUS_SUCCESS){
11  // ...
12  }
13 }
14 ...
15 mw_venc_deinit();

Call the function after mw_venc_init

int32_t mw_venc_get_gpu_num ( )

Obtains the number of GPUs for hardware video encoding and decoding.

Returns
Returns the number of GPUs for hardware video encoding and decoding

Usage: Refers to mw_venc_init Note: Call the function after mw_venc_init

mw_venc_status_t mw_venc_get_property ( mw_venc_handle_t  handle,
mw_venc_property_t  param,
void *  args 
)

Gets encoder parameters.

Parameters
[in]handleEncoder handle
[in]paramParameter type
[out]argsParameter values
Returns
The possible return values of mw_venc_status_t are as follows.
MW_VENC_STATUS_SUCCESS Function call succeeded.
MW_VENC_STATUS_INVALID_PARAM Input invalid value(s).
MW_VENC_STATUS_FAIL Failed to get encoder parameters.
MW_VENC_STATUS_UNSUPPORT Unsupported parameter type.
MW_VENC_STATUS_UNKNOWN_ERROR Failed to get encoder parameters with unknown error.

Usage:
The usage refers to mw_venc_create mw_venc_create_by_index

uint32_t mw_venc_get_support_platfrom ( )

Gets supported encoding hardware platform.

Returns
Returns mask of supported hardware encoding platform. The detailed information refers to mw_venc_platform_t.

Usage:
The recommended way of calling function:

1 ...
2 mw_venc_init();
3 ...
4 uint32 t_u32_platfrom = mw_venc_get_support_platfrom();
5 if(t_u32_platfrom & MW_VENC_PLATFORM_AMD){
6  //For AMD hardware encoding
7 }
8 if(t_u32_platform & MW_VENC_PLATFORM_INTEL){
9  //For Intel hardware encoding
10 }
11 if(t_u32_platform & MW_VENC_PLATFORM_NVIDIA){
12  //For Nvidia hardware encoding
13 }
14 ...
15 mw_venc_deinit();
16 ...
mw_venc_status_t mw_venc_init ( )

Initializes mw_venc.

Returns
Returns mw_venc_status_t, by default it is MW_VENC_STATUS_SUCCESS.

Usage: The suggested API call:

1 // Call the function before other mw_venc modules. It initializes resources for the mw_venc.
2 mw_venc_init();
3 ...
4 int t_n_num = mw_venc_get_gpu_num();
5 ...
6 uint32 t_u32_platforms = mw_venc_get_support_platfrom()
7 ...
8 mw_venc_deinit();
mw_venc_status_t mw_venc_put_frame ( mw_venc_handle_t  handle,
uint8_t *  p_frame 
)

Imports data to encoders.

Parameters
[in]handleEncoder handle
[in]p_frameFrame data
Returns
The possible return values of mw_venc_status_t are as follows.
MW_VENC_STATUS_SUCCESS Function call succeeded.
MW_VENC_STATUS_INVALID_PARAM Input invalid value(s).
MW_VENC_STATUS_FAIL Function call failed.
MW_VENC_STATUS_UNKNOWN_ERROR Function call failed with unknown errors.

Usage:
The usage refers to mw_venc_create
mw_venc_create_by_index

mw_venc_status_t mw_venc_put_frame_ex ( mw_venc_handle_t  handle,
uint8_t *  p_frame,
int64_t  pts 
)

Imports data to encoders.

Parameters
[in]handleEncoder handle
[in]p_frameFrame data
[in]ptstimestamp
Returns
The possible return values of mw_venc_status_t are as follows.
MW_VENC_STATUS_SUCCESS Function call succeeded
MW_VENC_STATUS_INVALID_PARAM Input invalid value(s).
MW_VENC_STATUS_FAIL Function call failed.
MW_VENC_STATUS_UNKNOWN_ERROR Function call failed with unknown errors.

Usage:
The usage refers to mw_venc_put_frame

mw_venc_status_t mw_venc_set_property ( mw_venc_handle_t  handle,
mw_venc_property_t  param,
void *  args 
)

Sets encoder parameters.

Parameters
[in]handleEncoder handle [in] param Parameter type
[in]argsParameter values
Returns
The possible return values of mw_venc_status_t are as follows.
MW_VENC_STATUS_SUCCESS Function call succeeded.
MW_VENC_STATUS_INVALID_PARAM Input invalid value(s).
MW_VENC_STATUS_FAIL Function call failed.
MW_VENC_STATUS_UNSUPPORT Unsupported parameter type.

Usage:
The usage refers to mw_venc_create mw_venc_create_by_index