libxcoder  3.5.1
ni_av_codec_logan.c File Reference

NETINT audio/video related utility functions. More...

#include <limits.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include "ni_defs_logan.h"
#include "ni_util_logan.h"
#include "ni_nvme_logan.h"
#include "ni_bitstream_logan.h"
#include "ni_av_codec_logan.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_logan_should_send_sei_with_frame (ni_logan_session_context_t *p_enc_ctx, ni_logan_pic_type_t pic_type, ni_logan_encoder_params_t *p_param)
 Whether SEI (HDR) should be sent together with this frame to encoder. More...
 
void ni_logan_set_vui (ni_logan_encoder_params_t *p_param, ni_logan_session_context_t *p_ctx, ni_color_primaries_t color_primaries, ni_color_transfer_characteristic_t color_trc, ni_color_space_t color_space, int video_full_range_flag, int sar_num, int sar_den, ni_logan_codec_format_t codec_format)
 Set SPS VUI part of encoded stream header. More...
 
void ni_logan_reset_vui (ni_logan_encoder_params_t *p_param, ni_aux_data_t *aux_data, ni_logan_codec_format_t codec_format)
 Reset vui info from decoder. More...
 
uint32_t ni_logan_enc_buffering_period_sei (ni_logan_encoder_params_t *p_param, ni_logan_session_context_t *p_ctx, uint32_t frame_idx, int buf_len, uint8_t *p_buf)
 Buffered period sei. More...
 
uint32_t ni_logan_enc_buffering_custom_sei (void *p_data, ni_logan_session_context_t *p_ctx, uint32_t index)
 Buffered customer sei. More...
 
uint32_t ni_logan_enc_pic_timing_sei2 (ni_logan_encoder_params_t *p_param, ni_logan_session_context_t *p_ctx, int is_i_or_idr, int is_idr, uint32_t frame_idx, int buf_len, uint8_t *p_buf)
 Generate pic timing sei2. More...
 
void ni_logan_dec_retrieve_aux_data (ni_logan_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_logan_enc_init_aux_params (ni_logan_session_data_io_t *p_api_fme)
 Initialize auxiliary data that should be sent together with this frame to encoder based on the auxiliary data of the decoded frame. More...
 
void ni_logan_enc_prep_aux_data (ni_logan_session_context_t *p_enc_ctx, ni_logan_frame_t *p_enc_frame, ni_logan_frame_t *p_dec_frame, ni_logan_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_logan_enc_copy_aux_data (ni_logan_session_context_t *p_enc_ctx, ni_logan_frame_t *p_enc_frame, ni_logan_frame_t *p_dec_frame, ni_logan_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)
 Copy auxiliary data that should be sent together with this frame to encoder. More...
 
int ni_logan_enc_fill_reconfig_params (ni_logan_encoder_params_t *p_param, ni_logan_session_context_t *p_ctx, ni_logan_frame_t *p_api_fme, int reconfigCount)
 Fill reconfig params. More...
 
int ni_logan_enc_fill_reconfig_vui (ni_logan_encoder_params_t *p_param, ni_logan_session_context_t *p_ctx, ni_logan_frame_t *p_api_fme, int reconfigCount, ni_aux_data_t *aux_data)
 Fill reconfig vui. More...
 
const uint8_t * ni_logan_find_start_code (const uint8_t *p, const uint8_t *end, uint32_t *state)
 Find the next start code. More...
 
int ni_logan_detect_custom_sei (const uint8_t *data, int size, ni_logan_session_context_t *p_api_ctx, ni_logan_decoder_params_t *p_api_param, ni_logan_packet_t *p_packet)
 detect custom SEI payload data in Packet data, custom SEI has two meanings: a. the SEI type is not in the standard protocol, which is added by customes, for example SEI type 100, note that custom SEI is not user data unregistered SEI. b. the SEI NAL location does not conform to protocol. It's after VCL NALs. So there are cases to handle here: case a: enable custom_sei, detext custom SEIs before VCL. case b: enable custom_sei and enable_check_packet, detect custom SEIs before VCL, and all SEIs after VCL. all of these SEIs are passthroughed in the same places after encoding. More...
 
void ni_logan_enc_reconfig_vfr (ni_logan_session_context_t *p_session_ctx, ni_logan_encoder_params_t *p_encoder_params, ni_logan_frame_t *ni_frame, int64_t pts, uint32_t timebase)
 Fill reconfig vfr. More...
 

Detailed Description

NETINT audio/video related utility functions.


Copyright (C) 2018 NETINT Technologies.

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.


Definition in file ni_av_codec_logan.c.

Macro Definition Documentation

◆ BR_SHIFT

#define BR_SHIFT   6

Definition at line 392 of file ni_av_codec_logan.c.

◆ CPB_SHIFT

#define CPB_SHIFT   4

Definition at line 393 of file ni_av_codec_logan.c.

◆ MAX_CPB_COUNT

#define MAX_CPB_COUNT   16

Definition at line 397 of file ni_av_codec_logan.c.

◆ MAX_DURATION

#define MAX_DURATION   0.5

Definition at line 398 of file ni_av_codec_logan.c.

◆ MAX_VPS_MAX_SUB_LAYERS

#define MAX_VPS_MAX_SUB_LAYERS   16

Definition at line 396 of file ni_av_codec_logan.c.

◆ SAMPLE_SPS_MAX_SUB_LAYERS_MINUS1

#define SAMPLE_SPS_MAX_SUB_LAYERS_MINUS1   0

Definition at line 395 of file ni_av_codec_logan.c.

Enumeration Type Documentation

◆ gop_preset_t

Enumerator
GOP_PRESET_CUSTOM 
GOP_PRESET_I_1 
GOP_PRESET_P_1 
GOP_PRESET_B_1 
GOP_PRESET_BP_2 
GOP_PRESET_BBBP_3 
GOP_PRESET_LP_4 
GOP_PRESET_LD_4 
GOP_PRESET_RA_8 
GOP_PRESET_SP_1 
GOP_PRESET_BSP_2 
GOP_PRESET_BBBSP_3 
GOP_PRESET_LSP_4 
GOP_PRESET_BBP_3 
GOP_PRESET_BBSP_3 
GOP_PRESET_BBBBBBBP_8 
GOP_PRESET_BBBBBBBSP_8 
NUM_GOP_PRESET_NUM 

Definition at line 41 of file ni_av_codec_logan.c.

◆ slice_type_t

Enumerator
SLICE_TYPE_B 
SLICE_TYPE_P 
SLICE_TYPE_I 
SLICE_TYPE_MP 

Definition at line 33 of file ni_av_codec_logan.c.

Function Documentation

◆ ni_logan_dec_retrieve_aux_data()

void ni_logan_dec_retrieve_aux_data ( ni_logan_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.


Parameters
[in/out]frame that is returned by decoder
Returns
NONE

Definition at line 1405 of file ni_av_codec_logan.c.

◆ ni_logan_detect_custom_sei()

int ni_logan_detect_custom_sei ( const uint8_t *  data,
int  size,
ni_logan_session_context_t p_api_ctx,
ni_logan_decoder_params_t p_api_param,
ni_logan_packet_t p_packet 
)

detect custom SEI payload data in Packet data, custom SEI has two meanings: a. the SEI type is not in the standard protocol, which is added by customes, for example SEI type 100, note that custom SEI is not user data unregistered SEI. b. the SEI NAL location does not conform to protocol. It's after VCL NALs. So there are cases to handle here: case a: enable custom_sei, detext custom SEIs before VCL. case b: enable custom_sei and enable_check_packet, detect custom SEIs before VCL, and all SEIs after VCL. all of these SEIs are passthroughed in the same places after encoding.


Parameters
uint8_t*data - packet data
intsize - pkt data size
ni_logan_session_context_t*p_api_ctx - Netint session context
ni_logan_decoder_params_t*api_param - Netint xcoder params
ni_logan_packet_t*p_packet - netint internal packet
Returns
- 0 on success or not detect correct custom sei, non-0 on failure

Definition at line 3511 of file ni_av_codec_logan.c.

◆ ni_logan_enc_buffering_custom_sei()

uint32_t ni_logan_enc_buffering_custom_sei ( void *  p_data,
ni_logan_session_context_t p_ctx,
uint32_t  index 
)

Buffered customer sei.


Parameters
[in]p_datainput side data of customer sei
[out]p_ctxsession context, update its pkt_custom_sei.
[in]indexfifo index
Returns
success return NI_LOGAN_RETCODE_SUCCESS failure return < 0

Definition at line 1170 of file ni_av_codec_logan.c.

◆ ni_logan_enc_buffering_period_sei()

uint32_t ni_logan_enc_buffering_period_sei ( ni_logan_encoder_params_t p_param,
ni_logan_session_context_t p_ctx,
uint32_t  frame_idx,
int  buf_len,
uint8_t *  p_buf 
)

Buffered period sei.


Parameters
[in/out]p_param encoder parameters, its GOP information will be updated.
[in]p_ctxsession context, use its HRD parameters (hrd_params).
[in]frame_idxframe index
[in]buf_lenoutput buffer length
[out]p_bufoutput sei buffer.
Returns
put_bit_byte_size

Definition at line 1052 of file ni_av_codec_logan.c.

◆ ni_logan_enc_copy_aux_data()

void ni_logan_enc_copy_aux_data ( ni_logan_session_context_t p_enc_ctx,
ni_logan_frame_t p_enc_frame,
ni_logan_frame_t p_dec_frame,
ni_logan_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 
)

Copy auxiliary data that should be sent together with this frame to encoder.


Parameters
[in]p_enc_ctxencoder session context
[out]p_enc_frameframe to be sent to encoder
[in]p_dec_frameframe returned by decoder
[in]mdcv_dataSEI for HDR mastering display color volume info
[in]cll_dataSEI for HDR content light level info
[in]cc_dataSEI for close caption
[in]udu_dataSEI for User data unregistered
[in]hdrp_dataSEI for HDR10+
Returns
NONE

Definition at line 2948 of file ni_av_codec_logan.c.

◆ ni_logan_enc_fill_reconfig_params()

int ni_logan_enc_fill_reconfig_params ( ni_logan_encoder_params_t p_param,
ni_logan_session_context_t p_ctx,
ni_logan_frame_t p_api_fme,
int  reconfigCount 
)

Fill reconfig params.


Parameters
[in]p_paramencoder parameters.
[in/out]p_ctx session context, its enc_change_params may be updated.
[in/out]p_api_fme extra_data_len and reconf_len may be updated
[in]reconfigCountreconfig count, may be updated.
Returns
reconfigCount on success < 0 on failure, NI_LOGAN_RETCODE_INVALID_PARAM NI_LOGAN_RETCODE_ERROR_MEM_ALOC

Definition at line 3084 of file ni_av_codec_logan.c.

◆ ni_logan_enc_fill_reconfig_vui()

int ni_logan_enc_fill_reconfig_vui ( ni_logan_encoder_params_t p_param,
ni_logan_session_context_t p_ctx,
ni_logan_frame_t p_api_fme,
int  reconfigCount,
ni_aux_data_t aux_data 
)

Fill reconfig vui.


Parameters
[in]p_paramencoder parameters.
[in/out]p_ctx session context, its enc_change_params may be updated.
[in/out]p_api_fme extra_data_len and reconf_len may be updated
[in]reconfigCountreconfig count, may be updated.
[in]aux_dataaux_data may be updated
Returns
reconfigCount on success < 0 on failure, NI_LOGAN_RETCODE_INVALID_PARAM NI_LOGAN_RETCODE_ERROR_MEM_ALOC

Definition at line 3290 of file ni_av_codec_logan.c.

◆ ni_logan_enc_init_aux_params()

void ni_logan_enc_init_aux_params ( ni_logan_session_data_io_t p_api_fme)

Initialize auxiliary data that should be sent together with this frame to encoder based on the auxiliary data of the decoded frame.


Parameters
[in/out]ni_logan_session_data_io_t session data
Returns
NONE

Definition at line 2084 of file ni_av_codec_logan.c.

◆ ni_logan_enc_pic_timing_sei2()

uint32_t ni_logan_enc_pic_timing_sei2 ( ni_logan_encoder_params_t p_param,
ni_logan_session_context_t p_ctx,
int  is_i_or_idr,
int  is_idr,
uint32_t  frame_idx,
int  buf_len,
uint8_t *  p_buf 
)

Generate pic timing sei2.


Parameters
[in/out]p_param encoder parameters, its GOP information will be updated.
[in/out]p_ctx session context, its HRD parameters (hrd_params) may be updated.
[in]is_i_or_idrTrue if it is i or idr packet.
[in]is_idrTrue if it is idr packet.
[in]frame_idxframe index
[in]buf_lenoutput buffer length
[out]p_bufoutput sei buffer.
Returns
length of pci timing sei2

Definition at line 1297 of file ni_av_codec_logan.c.

◆ ni_logan_enc_prep_aux_data()

void ni_logan_enc_prep_aux_data ( ni_logan_session_context_t p_enc_ctx,
ni_logan_frame_t p_enc_frame,
ni_logan_frame_t p_dec_frame,
ni_logan_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.

Parameters
[in/out]p_enc_ctx encoder session contextwhose various SEI type header can be updated as the result of this function
[out]p_enc_frameframe to be sent to encoder
[in]p_dec_frameframe that is returned by decoder
[in]codec_formatH.264 or H.265
[in]should_send_sei_with_frameif need to send a certain type of SEI with this frame
[out]mdcv_dataSEI for HDR mastering display color volume info
[out]cll_dataSEI for HDR content light level info
[out]cc_dataSEI for close caption
[out]udu_dataSEI for User data unregistered
[out]hdrp_dataSEI for HDR10+
Returns
NONE

Definition at line 2132 of file ni_av_codec_logan.c.

◆ ni_logan_enc_reconfig_vfr()

void ni_logan_enc_reconfig_vfr ( ni_logan_session_context_t p_session_ctx,
ni_logan_encoder_params_t p_encoder_params,
ni_logan_frame_t ni_frame,
int64_t  pts,
uint32_t  timebase 
)

Fill reconfig vfr.


Parameters
[in/out]p_session_ctx session context, some parameters may be updated.
[in]p_paramencoder parameters.
[in/out]ni_frame aux_data may be updated
[in]ptsframe pts
[in]timebasetimebase
Returns

Definition at line 3716 of file ni_av_codec_logan.c.

◆ ni_logan_find_start_code()

const uint8_t* ni_logan_find_start_code ( const uint8_t *  p,
const uint8_t *  end,
uint32_t *  state 
)

Find the next start code.


Parameters
[in]ppointer to buffer start address.
[in]endpointer to buffer end address.
[state]state pointer to nalu type address
Returns
search end address

Definition at line 3341 of file ni_av_codec_logan.c.

◆ ni_logan_reset_vui()

void ni_logan_reset_vui ( ni_logan_encoder_params_t p_param,
ni_aux_data_t aux_data,
ni_logan_codec_format_t  codec_format 
)

Reset vui info from decoder.


Parameters
[in]p_paramencoder parameters.
[in]aux_dataaux_data may be updated
[in]codec_formatencoder format
Returns

Definition at line 793 of file ni_av_codec_logan.c.

◆ ni_logan_set_vui()

void ni_logan_set_vui ( ni_logan_encoder_params_t p_param,
ni_logan_session_context_t p_ctx,
ni_color_primaries_t  color_primaries,
ni_color_transfer_characteristic_t  color_trc,
ni_color_space_t  color_space,
int  video_full_range_flag,
int  sar_num,
int  sar_den,
ni_logan_codec_format_t  codec_format 
)

Set SPS VUI part of encoded stream header.


Parameters
[in/out]p_param encoder parameters, its VUI data member will be updated.
[out]p_ctxsession context, its HRD parameters (hrd_params) may be updated.
[in]color_primariescolor primaries
[in]color_trccolor transfer characteristic
[in]color_spaceYUV colorspace type
[in]video_full_range_flag
[in]sar_num/sar_densample aspect ration in numerator/denominator
[in]codec_formatH.264 or H.265
Returns
NONE

Definition at line 464 of file ni_av_codec_logan.c.

◆ ni_logan_should_send_sei_with_frame()

int ni_logan_should_send_sei_with_frame ( ni_logan_session_context_t p_enc_ctx,
ni_logan_pic_type_t  pic_type,
ni_logan_encoder_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.


Parameters
[in]p_enc_ctxencoder session context
[in]pic_typeframe type
[in]p_paramencoder parameters
Returns
1 if yes, 0 otherwise

Definition at line 409 of file ni_av_codec_logan.c.