FFmpeg
Data Structures | Macros | Enumerations | Functions
hevc.c File Reference
#include "libavcodec/get_bits.h"
#include "libavcodec/golomb.h"
#include "libavcodec/hevc/hevc.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/mem.h"
#include "avc.h"
#include "avio.h"
#include "avio_internal.h"
#include "hevc.h"
#include "nal.h"

Go to the source code of this file.

Data Structures

struct  HVCCNALUnit
 
struct  HVCCNALUnitArray
 
struct  HEVCDecoderConfigurationRecord
 
struct  HVCCProfileTierLevel
 

Macros

#define MAX_SPATIAL_SEGMENTATION   4096
 
#define FLAG_ARRAY_COMPLETENESS   (1 << 0)
 
#define FLAG_IS_NALFF   (1 << 1)
 
#define FLAG_IS_LHVC   (1 << 2)
 

Enumerations

enum  {
  VPS_INDEX, SPS_INDEX, PPS_INDEX, SEI_PREFIX_INDEX,
  SEI_SUFFIX_INDEX, NB_ARRAYS
}
 

Functions

static void hvcc_update_ptl (HEVCDecoderConfigurationRecord *hvcc, HVCCProfileTierLevel *ptl)
 
static void hvcc_parse_ptl (GetBitContext *gb, HEVCDecoderConfigurationRecord *hvcc, unsigned int max_sub_layers_minus1)
 
static void skip_sub_layer_hrd_parameters (GetBitContext *gb, unsigned int cpb_cnt_minus1, uint8_t sub_pic_hrd_params_present_flag)
 
static int skip_hrd_parameters (GetBitContext *gb, uint8_t cprms_present_flag, unsigned int max_sub_layers_minus1)
 
static void skip_timing_info (GetBitContext *gb)
 
static void hvcc_parse_vui (GetBitContext *gb, HEVCDecoderConfigurationRecord *hvcc, unsigned int max_sub_layers_minus1)
 
static void skip_sub_layer_ordering_info (GetBitContext *gb)
 
static int hvcc_parse_vps (GetBitContext *gb, HVCCNALUnit *nal, HEVCDecoderConfigurationRecord *hvcc)
 
static void skip_scaling_list_data (GetBitContext *gb)
 
static int parse_rps (GetBitContext *gb, unsigned int rps_idx, unsigned int num_rps, unsigned int num_delta_pocs[HEVC_MAX_SHORT_TERM_REF_PIC_SETS])
 
static int hvcc_parse_sps (GetBitContext *gb, HVCCNALUnit *nal, HEVCDecoderConfigurationRecord *hvcc)
 
static int hvcc_parse_pps (GetBitContext *gb, HVCCNALUnit *nal, HEVCDecoderConfigurationRecord *hvcc)
 
static void nal_unit_parse_header (GetBitContext *gb, uint8_t *nal_type, uint8_t *nuh_layer_id)
 
static int hvcc_array_add_nal_unit (const uint8_t *nal_buf, uint32_t nal_size, HVCCNALUnitArray *array)
 
static int hvcc_add_nal_unit (const uint8_t *nal_buf, uint32_t nal_size, HEVCDecoderConfigurationRecord *hvcc, int flags, unsigned array_idx)
 
static void hvcc_init (HEVCDecoderConfigurationRecord *hvcc)
 
static void hvcc_close (HEVCDecoderConfigurationRecord *hvcc)
 
static int hvcc_write (AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc, int flags)
 
int ff_hevc_annexb2mp4 (AVIOContext *pb, const uint8_t *buf_in, int size, int filter_ps, int *ps_count)
 Writes Annex B formatted HEVC NAL units to the provided AVIOContext. More...
 
int ff_hevc_annexb2mp4_buf (const uint8_t *buf_in, uint8_t **buf_out, int *size, int filter_ps, int *ps_count)
 Writes Annex B formatted HEVC NAL units to a data buffer. More...
 
static int hvcc_parse_nal_unit (const uint8_t *buf, uint32_t len, int type, HEVCDecoderConfigurationRecord *hvcc, int flags)
 
static int write_configuration_record (AVIOContext *pb, const uint8_t *data, int size, int flags)
 
int ff_isom_write_hvcc (AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness)
 Writes HEVC extradata (parameter sets and declarative SEI NAL units with nuh_layer_id == 0, as a HEVCDecoderConfigurationRecord) to the provided AVIOContext. More...
 
int ff_isom_write_lhvc (AVIOContext *pb, const uint8_t *data, int size, int ps_array_completeness)
 Writes L-HEVC extradata (parameter sets with nuh_layer_id > 0, as a LHEVCDecoderConfigurationRecord) to the provided AVIOContext. More...
 

Macro Definition Documentation

◆ MAX_SPATIAL_SEGMENTATION

#define MAX_SPATIAL_SEGMENTATION   4096

Definition at line 32 of file hevc.c.

◆ FLAG_ARRAY_COMPLETENESS

#define FLAG_ARRAY_COMPLETENESS   (1 << 0)

Definition at line 44 of file hevc.c.

◆ FLAG_IS_NALFF

#define FLAG_IS_NALFF   (1 << 1)

Definition at line 45 of file hevc.c.

◆ FLAG_IS_LHVC

#define FLAG_IS_LHVC   (1 << 2)

Definition at line 46 of file hevc.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
VPS_INDEX 
SPS_INDEX 
PPS_INDEX 
SEI_PREFIX_INDEX 
SEI_SUFFIX_INDEX 
NB_ARRAYS 

Definition at line 34 of file hevc.c.

Function Documentation

◆ hvcc_update_ptl()

static void hvcc_update_ptl ( HEVCDecoderConfigurationRecord hvcc,
HVCCProfileTierLevel ptl 
)
static

Definition at line 96 of file hevc.c.

Referenced by hvcc_parse_ptl().

◆ hvcc_parse_ptl()

static void hvcc_parse_ptl ( GetBitContext gb,
HEVCDecoderConfigurationRecord hvcc,
unsigned int  max_sub_layers_minus1 
)
static

Definition at line 150 of file hevc.c.

Referenced by hvcc_parse_sps(), and hvcc_parse_vps().

◆ skip_sub_layer_hrd_parameters()

static void skip_sub_layer_hrd_parameters ( GetBitContext gb,
unsigned int  cpb_cnt_minus1,
uint8_t  sub_pic_hrd_params_present_flag 
)
static

Definition at line 199 of file hevc.c.

Referenced by skip_hrd_parameters().

◆ skip_hrd_parameters()

static int skip_hrd_parameters ( GetBitContext gb,
uint8_t  cprms_present_flag,
unsigned int  max_sub_layers_minus1 
)
static

Definition at line 218 of file hevc.c.

Referenced by hvcc_parse_vui().

◆ skip_timing_info()

static void skip_timing_info ( GetBitContext gb)
static

Definition at line 293 of file hevc.c.

Referenced by hvcc_parse_vui().

◆ hvcc_parse_vui()

static void hvcc_parse_vui ( GetBitContext gb,
HEVCDecoderConfigurationRecord hvcc,
unsigned int  max_sub_layers_minus1 
)
static

Definition at line 302 of file hevc.c.

Referenced by hvcc_parse_sps().

◆ skip_sub_layer_ordering_info()

static void skip_sub_layer_ordering_info ( GetBitContext gb)
static

Definition at line 380 of file hevc.c.

Referenced by hvcc_parse_sps().

◆ hvcc_parse_vps()

static int hvcc_parse_vps ( GetBitContext gb,
HVCCNALUnit nal,
HEVCDecoderConfigurationRecord hvcc 
)
static

Definition at line 387 of file hevc.c.

Referenced by hvcc_add_nal_unit().

◆ skip_scaling_list_data()

static void skip_scaling_list_data ( GetBitContext gb)
static

Definition at line 422 of file hevc.c.

Referenced by hvcc_parse_sps().

◆ parse_rps()

static int parse_rps ( GetBitContext gb,
unsigned int  rps_idx,
unsigned int  num_rps,
unsigned int  num_delta_pocs[HEVC_MAX_SHORT_TERM_REF_PIC_SETS] 
)
static

Definition at line 441 of file hevc.c.

Referenced by hvcc_parse_sps().

◆ hvcc_parse_sps()

static int hvcc_parse_sps ( GetBitContext gb,
HVCCNALUnit nal,
HEVCDecoderConfigurationRecord hvcc 
)
static

Definition at line 508 of file hevc.c.

Referenced by hvcc_add_nal_unit().

◆ hvcc_parse_pps()

static int hvcc_parse_pps ( GetBitContext gb,
HVCCNALUnit nal,
HEVCDecoderConfigurationRecord hvcc 
)
static

Definition at line 649 of file hevc.c.

Referenced by hvcc_add_nal_unit().

◆ nal_unit_parse_header()

static void nal_unit_parse_header ( GetBitContext gb,
uint8_t *  nal_type,
uint8_t *  nuh_layer_id 
)
static

Definition at line 706 of file hevc.c.

Referenced by hvcc_add_nal_unit().

◆ hvcc_array_add_nal_unit()

static int hvcc_array_add_nal_unit ( const uint8_t *  nal_buf,
uint32_t  nal_size,
HVCCNALUnitArray array 
)
static

Definition at line 720 of file hevc.c.

Referenced by hvcc_add_nal_unit().

◆ hvcc_add_nal_unit()

static int hvcc_add_nal_unit ( const uint8_t *  nal_buf,
uint32_t  nal_size,
HEVCDecoderConfigurationRecord hvcc,
int  flags,
unsigned  array_idx 
)
static

Definition at line 739 of file hevc.c.

Referenced by hvcc_parse_nal_unit().

◆ hvcc_init()

static void hvcc_init ( HEVCDecoderConfigurationRecord hvcc)
static

Definition at line 812 of file hevc.c.

Referenced by write_configuration_record().

◆ hvcc_close()

static void hvcc_close ( HEVCDecoderConfigurationRecord hvcc)
static

Definition at line 832 of file hevc.c.

Referenced by write_configuration_record().

◆ hvcc_write()

static int hvcc_write ( AVIOContext pb,
HEVCDecoderConfigurationRecord hvcc,
int  flags 
)
static

Definition at line 841 of file hevc.c.

Referenced by write_configuration_record().

◆ ff_hevc_annexb2mp4()

int ff_hevc_annexb2mp4 ( AVIOContext pb,
const uint8_t *  buf_in,
int  size,
int  filter_ps,
int *  ps_count 
)

Writes Annex B formatted HEVC NAL units to the provided AVIOContext.

The NAL units are converted to an MP4-compatible format (start code prefixes are replaced by 4-byte size fields, as per ISO/IEC 14496-15).

If filter_ps is non-zero, any HEVC parameter sets found in the input will be discarded, and *ps_count will be set to the number of discarded PS NAL units.

Parameters
pbaddress of the AVIOContext where the data shall be written
buf_inaddress of the buffer holding the input data
sizesize (in bytes) of the input buffer
filter_pswhether to write parameter set NAL units to the output (0) or to discard them (non-zero)
ps_countaddress of the variable where the number of discarded parameter set NAL units shall be written, may be NULL
Returns
the amount (in bytes) of data written in case of success, a negative value corresponding to an AVERROR code in case of failure

Definition at line 1076 of file hevc.c.

Referenced by ff_hevc_annexb2mp4_buf(), and ff_mov_write_packet().

◆ ff_hevc_annexb2mp4_buf()

int ff_hevc_annexb2mp4_buf ( const uint8_t *  buf_in,
uint8_t **  buf_out,
int *  size,
int  filter_ps,
int *  ps_count 
)

Writes Annex B formatted HEVC NAL units to a data buffer.

The NAL units are converted to an MP4-compatible format (start code prefixes are replaced by 4-byte size fields, as per ISO/IEC 14496-15).

If filter_ps is non-zero, any HEVC parameter sets found in the input will be discarded, and *ps_count will be set to the number of discarded PS NAL units.

On success, *size holds the size (in bytes) of the output data buffer.

Parameters
buf_inaddress of the buffer holding the input data
sizeaddress of the variable holding the size (in bytes) of the input buffer (on input) and of the output buffer (on success)
buf_outon success, address of the variable holding the address of the output buffer
filter_pswhether to write parameter set NAL units to the output (0) or to discard them (non-zero)
ps_countaddress of the variable where the number of discarded parameter set NAL units shall be written, may be NULL
Returns
0 in case of success, a negative value corresponding to an AVERROR code in case of failure
Note
*buf_out will be treated as uninitialized on input and won't be freed.

Definition at line 1124 of file hevc.c.

Referenced by ff_mov_write_packet(), and flv_write_packet().

◆ hvcc_parse_nal_unit()

static int hvcc_parse_nal_unit ( const uint8_t *  buf,
uint32_t  len,
int  type,
HEVCDecoderConfigurationRecord hvcc,
int  flags 
)
static

Definition at line 1145 of file hevc.c.

Referenced by write_configuration_record().

◆ write_configuration_record()

static int write_configuration_record ( AVIOContext pb,
const uint8_t *  data,
int  size,
int  flags 
)
static

Definition at line 1165 of file hevc.c.

Referenced by ff_isom_write_hvcc(), and ff_isom_write_lhvc().

◆ ff_isom_write_hvcc()

int ff_isom_write_hvcc ( AVIOContext pb,
const uint8_t *  data,
int  size,
int  ps_array_completeness 
)

Writes HEVC extradata (parameter sets and declarative SEI NAL units with nuh_layer_id == 0, as a HEVCDecoderConfigurationRecord) to the provided AVIOContext.

If the extradata is Annex B format, it gets converted to hvcC format before writing.

Parameters
pbaddress of the AVIOContext where the hvcC shall be written
dataaddress of the buffer holding the data needed to write the hvcC
sizesize (in bytes) of the data buffer
ps_array_completenesswhether all parameter sets are in the hvcC (1) or there may be additional parameter sets in the bitstream (0)
Returns
>=0 in case of success, a negative value corresponding to an AVERROR code in case of failure

Definition at line 1273 of file hevc.c.

Referenced by flv_write_codec_header(), mkv_assemble_native_codecprivate(), and mov_write_hvcc_tag().

◆ ff_isom_write_lhvc()

int ff_isom_write_lhvc ( AVIOContext pb,
const uint8_t *  data,
int  size,
int  ps_array_completeness 
)

Writes L-HEVC extradata (parameter sets with nuh_layer_id > 0, as a LHEVCDecoderConfigurationRecord) to the provided AVIOContext.

If the extradata is Annex B format, it gets converted to lhvC format before writing. Otherwise, hvcC formated extradata is expected, not lhvC.

Parameters
pbaddress of the AVIOContext where the lhvC shall be written
dataaddress of the buffer holding the data needed to write the lhvC
sizesize (in bytes) of the data buffer
ps_array_completenesswhether all parameter sets are in the lhvC (1) or there may be additional parameter sets in the bitstream (0)
Returns
>=0 in case of success, a negative value corresponding to an AVERROR code in case of failure

Definition at line 1280 of file hevc.c.

Referenced by mov_write_lhvc_tag().