![]() |
libxcoder
5.2.0
|
Audio/video related utility definitions. More...
#include <arpa/inet.h>
#include <limits.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "ni_util.h"
#include "ni_nvme.h"
#include "ni_bitstream.h"
#include "ni_av_codec.h"
#include "ni_device_api_priv.h"
Go to the source code of this file.
Macros | |
#define | BR_SHIFT 6 |
#define | CPB_SHIFT 4 |
#define | SAMPLE_SPS_MAX_SUB_LAYERS_MINUS1 0 |
#define | MAX_VPS_MAX_SUB_LAYERS 16 |
#define | MAX_CPB_COUNT 16 |
#define | MAX_DURATION 0.5 |
Enumerations | |
enum | slice_type_t { SLICE_TYPE_B = 0, SLICE_TYPE_P = 1, SLICE_TYPE_I = 2, SLICE_TYPE_MP = 3 } |
enum | gop_preset_t { GOP_PRESET_CUSTOM = 0, GOP_PRESET_I_1 = 1, GOP_PRESET_P_1 = 2, GOP_PRESET_B_1 = 3, GOP_PRESET_BP_2 = 4, GOP_PRESET_BBBP_3 = 5, GOP_PRESET_LP_4 = 6, GOP_PRESET_LD_4 = 7, GOP_PRESET_RA_8 = 8, GOP_PRESET_SP_1 = 9, GOP_PRESET_BSP_2 = 10, GOP_PRESET_BBBSP_3 = 11, GOP_PRESET_LSP_4 = 12, GOP_PRESET_BBP_3 = 13, GOP_PRESET_BBSP_3 = 14, GOP_PRESET_BBBBBBBP_8 = 15, GOP_PRESET_BBBBBBBSP_8 = 16, NUM_GOP_PRESET_NUM = 17 } |
Functions | |
int | ni_should_send_sei_with_frame (ni_session_context_t *p_enc_ctx, ni_pic_type_t pic_type, ni_xcoder_params_t *p_param) |
Whether SEI (HDR) should be sent together with this frame to encoder. More... | |
void | ni_dec_retrieve_aux_data (ni_frame_t *frame) |
Retrieve auxiliary data (close caption, various SEI) associated with this frame that is returned by decoder, convert them to appropriate format and save them in the frame's auxiliary data storage for future use by encoding. Usually they would be sent together with this frame to encoder at encoding. More... | |
void | ni_enc_prep_aux_data (ni_session_context_t *p_enc_ctx, ni_frame_t *p_enc_frame, ni_frame_t *p_dec_frame, ni_codec_format_t codec_format, int should_send_sei_with_frame, uint8_t *mdcv_data, uint8_t *cll_data, uint8_t *cc_data, uint8_t *udu_data, uint8_t *hdrp_data) |
Prepare auxiliary data that should be sent together with this frame to encoder based on the auxiliary data of the decoded frame. More... | |
void | ni_enc_copy_aux_data (ni_session_context_t *p_enc_ctx, ni_frame_t *p_enc_frame, ni_frame_t *p_dec_frame, ni_codec_format_t codec_format, const uint8_t *mdcv_data, const uint8_t *cll_data, const uint8_t *cc_data, const uint8_t *udu_data, const uint8_t *hdrp_data, int is_hwframe, int is_semiplanar) |
Copy auxiliary data that should be sent together with this frame to encoder. More... | |
LIB_API int | ni_enc_insert_timecode (ni_session_context_t *p_enc_ctx, ni_frame_t *p_enc_frame, ni_timecode_t *p_timecode) |
Insert timecode data into picture timing SEI (H264) or time code SEI (H265) More... | |
int | ni_enc_write_from_yuv_buffer (ni_session_context_t *p_ctx, ni_frame_t *p_enc_frame, uint8_t *p_yuv_buffer) |
Send an input data frame to the encoder with YUV data given in the inputs. More... | |
const uint8_t * | ni_find_start_code (const uint8_t *p, const uint8_t *end, uint32_t *state) |
Find the next start code. More... | |
int | ni_extract_custom_sei (uint8_t *pkt_data, int pkt_size, long index, ni_packet_t *p_packet, uint8_t sei_type, int vcl_found) |
Extract custom sei payload data from pkt_data, and save it to ni_packet_t. More... | |
int | ni_dec_packet_parse (ni_session_context_t *p_session_ctx, ni_xcoder_params_t *p_param, uint8_t *data, int size, ni_packet_t *p_packet, int low_delay, int codec_format, int pkt_nal_bitmap, int custom_sei_type, int *svct_skip_next_packet, int *is_lone_sei_pkt) |
Decode parse packet. More... | |
int | ni_expand_frame (ni_frame_t *dst, ni_frame_t *src, int dst_stride[], int raw_width, int raw_height, int ni_fmt, int nb_planes) |
Expand frame form src frame. More... | |
int | ni_reconfig_ppu_output (ni_session_context_t *p_session_ctx, ni_xcoder_params_t *p_param, ni_ppu_config_t *ppu_config) |
Reset decoder ppu resolution. More... | |
#define BR_SHIFT 6 |
Definition at line 169 of file ni_av_codec.c.
#define CPB_SHIFT 4 |
Definition at line 170 of file ni_av_codec.c.
#define MAX_CPB_COUNT 16 |
Definition at line 174 of file ni_av_codec.c.
#define MAX_DURATION 0.5 |
Definition at line 175 of file ni_av_codec.c.
#define MAX_VPS_MAX_SUB_LAYERS 16 |
Definition at line 173 of file ni_av_codec.c.
#define SAMPLE_SPS_MAX_SUB_LAYERS_MINUS1 0 |
Definition at line 172 of file ni_av_codec.c.
enum gop_preset_t |
Definition at line 51 of file ni_av_codec.c.
enum slice_type_t |
Enumerator | |
---|---|
SLICE_TYPE_B | |
SLICE_TYPE_P | |
SLICE_TYPE_I | |
SLICE_TYPE_MP |
Definition at line 43 of file ni_av_codec.c.
int ni_dec_packet_parse | ( | ni_session_context_t * | p_session_ctx, |
ni_xcoder_params_t * | p_param, | ||
uint8_t * | data, | ||
int | size, | ||
ni_packet_t * | p_packet, | ||
int | low_delay, | ||
int | codec_format, | ||
int | pkt_nal_bitmap, | ||
int | custom_sei_type, | ||
int * | svct_skip_next_packet, | ||
int * | is_lone_sei_pkt | ||
) |
Decode parse packet.
[in] | p_session_ctx | Pointer to a caller allocated ni_session_context_t struct |
[in] | p_param | Pointer to a caller allocated ni_xcoder_params_t struct |
[in] | *data | FFmpeg AVPacket data |
[in] | size | packet size |
[in] | p_packet | Pointer to a caller allocated ni_packet_t struct |
[in] | low_delay | FFmpeg lowdelay |
[in] | codec_format | enum ni_codec_format_t |
[in] | pkt_nal_bitmap | pkt_nal_bitmap |
[in] | custom_sei_type | custom_sei_type |
[in] | <em>svct_skip_next_packet | svct_skip_next_packet int |
[in] | <em>is_lone_sei_pkt | is_lone_sei_pkt int |
Definition at line 3065 of file ni_av_codec.c.
void ni_dec_retrieve_aux_data | ( | ni_frame_t * | frame | ) |
Retrieve auxiliary data (close caption, various SEI) associated with this frame that is returned by decoder, convert them to appropriate format and save them in the frame's auxiliary data storage for future use by encoding. Usually they would be sent together with this frame to encoder at encoding.
[in/out] | frame that is returned by decoder |
Definition at line 237 of file ni_av_codec.c.
void ni_enc_copy_aux_data | ( | ni_session_context_t * | p_enc_ctx, |
ni_frame_t * | p_enc_frame, | ||
ni_frame_t * | p_dec_frame, | ||
ni_codec_format_t | codec_format, | ||
const uint8_t * | mdcv_data, | ||
const uint8_t * | cll_data, | ||
const uint8_t * | cc_data, | ||
const uint8_t * | udu_data, | ||
const uint8_t * | hdrp_data, | ||
int | is_hwframe, | ||
int | is_semiplanar | ||
) |
Copy auxiliary data that should be sent together with this frame to encoder.
[in] | p_enc_ctx | encoder session context |
[out] | p_enc_frame | frame to be sent to encoder |
[in] | p_dec_frame | frame returned by decoder |
[in] | mdcv_data | SEI for HDR mastering display color volume info |
[in] | cll_data | SEI for HDR content light level info |
[in] | cc_data | SEI for close caption |
[in] | udu_data | SEI for User data unregistered |
[in] | hdrp_data | SEI for HDR10+ |
[in] | is_hwframe,must | be 0 (sw frame) or 1 (hw frame) |
[in] | is_semiplanar,must | be 1 (semiplanar frame) or 0 (not) |
Definition at line 2267 of file ni_av_codec.c.
LIB_API int ni_enc_insert_timecode | ( | ni_session_context_t * | p_enc_ctx, |
ni_frame_t * | p_enc_frame, | ||
ni_timecode_t * | p_timecode | ||
) |
Insert timecode data into picture timing SEI (H264) or time code SEI (H265)
[in] | p_enc_ctx | encoder session context |
[out] | p_enc_frame | frame to be sent to encoder |
[in] | p_timecode | the timecode data to be written along with the frame |
Definition at line 2453 of file ni_av_codec.c.
void ni_enc_prep_aux_data | ( | ni_session_context_t * | p_enc_ctx, |
ni_frame_t * | p_enc_frame, | ||
ni_frame_t * | p_dec_frame, | ||
ni_codec_format_t | codec_format, | ||
int | should_send_sei_with_frame, | ||
uint8_t * | mdcv_data, | ||
uint8_t * | cll_data, | ||
uint8_t * | cc_data, | ||
uint8_t * | udu_data, | ||
uint8_t * | hdrp_data | ||
) |
Prepare auxiliary data that should be sent together with this frame to encoder based on the auxiliary data of the decoded frame.
Note: Some of the SEI (e.g. HDR) will be updated and stored in encoder context whenever received through decoded frame; they will be sent out with the encoded frame to encoder only when appropriate, i.e. should_send_sei_with_frame is true. When a type of aux data is to be sent, its associated length will be set in the encoder frame.
[in/out] | p_enc_ctx encoder session contextwhose various SEI type header can be updated as the result of this function | |
[out] | p_enc_frame | frame to be sent to encoder |
[in] | p_dec_frame | frame that is returned by decoder |
[in] | codec_format | H.264 or H.265 |
[in] | should_send_sei_with_frame | if need to send a certain type of SEI with this frame |
[out] | mdcv_data | SEI for HDR mastering display color volume info |
[out] | cll_data | SEI for HDR content light level info |
[out] | cc_data | SEI for close caption |
[out] | udu_data | SEI for User data unregistered |
[out] | hdrp_data | SEI for HDR10+ |
Definition at line 858 of file ni_av_codec.c.
int ni_enc_write_from_yuv_buffer | ( | ni_session_context_t * | p_ctx, |
ni_frame_t * | p_enc_frame, | ||
uint8_t * | p_yuv_buffer | ||
) |
Send an input data frame to the encoder with YUV data given in the inputs.
For ideal performance memory should be 4k aligned. If it is not 4K aligned then a temporary 4k aligned memory will be used to copy data to and from when writing and reading. This will negatively impact performance.
Any metadata to be sent with the frame should be attached to p_enc_frame as aux data (e.g. using ni_frame_new_aux_data()).
[in] | p_ctx | Encoder session context |
[in] | p_enc_frame | Struct holding information about the frame to be sent to the encoder |
[in] | p_yuv_buffer | Caller allocated buffer holding YUV data for the frame |
Definition at line 2625 of file ni_av_codec.c.
int ni_expand_frame | ( | ni_frame_t * | dst, |
ni_frame_t * | src, | ||
int | dst_stride[], | ||
int | raw_width, | ||
int | raw_height, | ||
int | ni_fmt, | ||
int | nb_planes | ||
) |
Expand frame form src frame.
[in] | dst | Pointer to a caller allocated ni_frame_t struct |
[in] | src | Pointer to a caller allocated ni_frame_t struct |
[in] | dst_stride | int dst_stride[] |
[in] | raw_width | frame width |
[in] | raw_height | frame height |
[in] | ni_fmt | ni_pix_fmt_t type for ni pix_fmt |
[in] | nb_planes | int nb_planes |
Definition at line 3289 of file ni_av_codec.c.
int ni_extract_custom_sei | ( | uint8_t * | pkt_data, |
int | pkt_size, | ||
long | index, | ||
ni_packet_t * | p_packet, | ||
uint8_t | sei_type, | ||
int | vcl_found | ||
) |
Extract custom sei payload data from pkt_data, and save it to ni_packet_t.
uint8_t | *pkt_data - FFmpeg AVPacket data |
int | pkt_size - packet size |
long | index - pkt data index of custom sei first byte after SEI type |
ni_packet_t | *p_packet - libxcoder internal packet |
uint8_t | sei_type - type of SEI |
int | vcl_found - whether got vcl in the pkt data, 1 means got |
extract SEI payload size. the first byte after SEI type is the SEI payload size. if the first byte is 255(0xFF), it means the SEI payload size is more than 255. in this case, to get the SEI payload size is to do a summation. the end of SEI size is the first non-0xFF value. for example, 0xFF 0xFF 0x08, the SEI payload size equals to (0xFF+0xFF+0x08).
Definition at line 2944 of file ni_av_codec.c.
const uint8_t* ni_find_start_code | ( | const uint8_t * | p, |
const uint8_t * | end, | ||
uint32_t * | state | ||
) |
Find the next start code.
[in] | p | pointer to buffer start address. |
[in] | end | pointer to buffer end address. |
[state] | state pointer to nalu type address |
Definition at line 2897 of file ni_av_codec.c.
int ni_reconfig_ppu_output | ( | ni_session_context_t * | p_session_ctx, |
ni_xcoder_params_t * | p_param, | ||
ni_ppu_config_t * | ppu_config | ||
) |
Reset decoder ppu resolution.
[in] | p_session_ctx | Pointer to a caller allocated ni_session_context_t struct |
[in] | p_param | Pointer to a caller allocated ni_xcoder_params_t struct |
[in] | ppu_config | Pointer to a caller allocated ni_ppu_config_t struct |
Definition at line 3485 of file ni_av_codec.c.
int ni_should_send_sei_with_frame | ( | ni_session_context_t * | p_enc_ctx, |
ni_pic_type_t | pic_type, | ||
ni_xcoder_params_t * | p_param | ||
) |
Whether SEI (HDR) should be sent together with this frame to encoder.
Whether SEI should be sent together with this frame to encoder.
[in] | p_enc_ctx | encoder session context |
[in] | pic_type | frame type |
[in] | p_param | encoder parameters |
Definition at line 186 of file ni_av_codec.c.