mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-14 03:55:58 +08:00
MP4录制添加H265支持
This commit is contained in:
@@ -76,8 +76,14 @@ Track::Ptr Factory::getTrackBySdp(const SdpTrack::Ptr &track) {
|
||||
|
||||
if (strcasecmp(track->_codec.data(), "h265") == 0) {
|
||||
//a=fmtp:96 sprop-sps=QgEBAWAAAAMAsAAAAwAAAwBdoAKAgC0WNrkky/AIAAADAAgAAAMBlQg=; sprop-pps=RAHA8vA8kAA=
|
||||
int pt;
|
||||
int pt, id;
|
||||
char sprop_vps[128] = {0},sprop_sps[128] = {0},sprop_pps[128] = {0};
|
||||
if (5 == sscanf(track->_fmtp.data(), "%d profile-id=%d; sprop-sps=%127[^;]; sprop-pps=%127[^;]; sprop-vps=%127[^;]", &pt, &id, sprop_sps,sprop_pps, sprop_vps)) {
|
||||
auto vps = decodeBase64(sprop_vps);
|
||||
auto sps = decodeBase64(sprop_sps);
|
||||
auto pps = decodeBase64(sprop_pps);
|
||||
return std::make_shared<H265Track>(vps,sps,pps,0,0,0);
|
||||
}
|
||||
if (4 == sscanf(track->_fmtp.data(), "%d sprop-vps=%127[^;]; sprop-sps=%127[^;]; sprop-pps=%127[^;]", &pt, sprop_vps,sprop_sps, sprop_pps)) {
|
||||
auto vps = decodeBase64(sprop_vps);
|
||||
auto sps = decodeBase64(sprop_sps);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,15 @@
|
||||
|
||||
#define QP_MAX_NUM (51 + 6*6) // The maximum supported qp
|
||||
|
||||
#define HEVC_MAX_SHORT_TERM_RPS_COUNT 64
|
||||
|
||||
#define T_PROFILE_HEVC_MAIN 1
|
||||
#define T_PROFILE_HEVC_MAIN_10 2
|
||||
#define T_PROFILE_HEVC_MAIN_STILL_PICTURE 3
|
||||
#define T_PROFILE_HEVC_REXT 4
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Chromaticity coordinates of the source primaries.
|
||||
*/
|
||||
@@ -67,6 +76,62 @@ enum T_AVColorSpace {
|
||||
};
|
||||
|
||||
|
||||
enum {
|
||||
// 7.4.3.1: vps_max_layers_minus1 is in [0, 62].
|
||||
HEVC_MAX_LAYERS = 63,
|
||||
// 7.4.3.1: vps_max_sub_layers_minus1 is in [0, 6].
|
||||
HEVC_MAX_SUB_LAYERS = 7,
|
||||
// 7.4.3.1: vps_num_layer_sets_minus1 is in [0, 1023].
|
||||
HEVC_MAX_LAYER_SETS = 1024,
|
||||
|
||||
// 7.4.2.1: vps_video_parameter_set_id is u(4).
|
||||
HEVC_MAX_VPS_COUNT = 16,
|
||||
// 7.4.3.2.1: sps_seq_parameter_set_id is in [0, 15].
|
||||
HEVC_MAX_SPS_COUNT = 16,
|
||||
// 7.4.3.3.1: pps_pic_parameter_set_id is in [0, 63].
|
||||
HEVC_MAX_PPS_COUNT = 64,
|
||||
|
||||
// A.4.2: MaxDpbSize is bounded above by 16.
|
||||
HEVC_MAX_DPB_SIZE = 16,
|
||||
// 7.4.3.1: vps_max_dec_pic_buffering_minus1[i] is in [0, MaxDpbSize - 1].
|
||||
HEVC_MAX_REFS = HEVC_MAX_DPB_SIZE,
|
||||
|
||||
// 7.4.3.2.1: num_short_term_ref_pic_sets is in [0, 64].
|
||||
HEVC_MAX_SHORT_TERM_REF_PIC_SETS = 64,
|
||||
// 7.4.3.2.1: num_long_term_ref_pics_sps is in [0, 32].
|
||||
HEVC_MAX_LONG_TERM_REF_PICS = 32,
|
||||
|
||||
// A.3: all profiles require that CtbLog2SizeY is in [4, 6].
|
||||
HEVC_MIN_LOG2_CTB_SIZE = 4,
|
||||
HEVC_MAX_LOG2_CTB_SIZE = 6,
|
||||
|
||||
// E.3.2: cpb_cnt_minus1[i] is in [0, 31].
|
||||
HEVC_MAX_CPB_CNT = 32,
|
||||
|
||||
// A.4.1: in table A.6 the highest level allows a MaxLumaPs of 35 651 584.
|
||||
HEVC_MAX_LUMA_PS = 35651584,
|
||||
// A.4.1: pic_width_in_luma_samples and pic_height_in_luma_samples are
|
||||
// constrained to be not greater than sqrt(MaxLumaPs * 8). Hence height/
|
||||
// width are bounded above by sqrt(8 * 35651584) = 16888.2 samples.
|
||||
HEVC_MAX_WIDTH = 16888,
|
||||
HEVC_MAX_HEIGHT = 16888,
|
||||
|
||||
// A.4.1: table A.6 allows at most 22 tile rows for any level.
|
||||
HEVC_MAX_TILE_ROWS = 22,
|
||||
// A.4.1: table A.6 allows at most 20 tile columns for any level.
|
||||
HEVC_MAX_TILE_COLUMNS = 20,
|
||||
|
||||
// 7.4.7.1: in the worst case (tiles_enabled_flag and
|
||||
// entropy_coding_sync_enabled_flag are both set), entry points can be
|
||||
// placed at the beginning of every Ctb row in every tile, giving an
|
||||
// upper bound of (num_tile_columns_minus1 + 1) * PicHeightInCtbsY - 1.
|
||||
// Only a stream with very high resolution and perverse parameters could
|
||||
// get near that, though, so set a lower limit here with the maximum
|
||||
// possible value for 4K video (at most 135 16x16 Ctb rows).
|
||||
HEVC_MAX_ENTRY_POINT_OFFSETS = HEVC_MAX_TILE_COLUMNS * 135,
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* rational number numerator/denominator
|
||||
*/
|
||||
@@ -170,6 +235,189 @@ typedef struct T_PPS {
|
||||
int iChromaQpDiff;
|
||||
} T_PPS;
|
||||
|
||||
|
||||
typedef struct T_HEVCWindow {
|
||||
unsigned int left_offset;
|
||||
unsigned int right_offset;
|
||||
unsigned int top_offset;
|
||||
unsigned int bottom_offset;
|
||||
} T_HEVCWindow;
|
||||
|
||||
|
||||
typedef struct T_VUI {
|
||||
T_AVRational sar;
|
||||
|
||||
int overscan_info_present_flag;
|
||||
int overscan_appropriate_flag;
|
||||
|
||||
int video_signal_type_present_flag;
|
||||
int video_format;
|
||||
int video_full_range_flag;
|
||||
int colour_description_present_flag;
|
||||
uint8_t colour_primaries;
|
||||
uint8_t transfer_characteristic;
|
||||
uint8_t matrix_coeffs;
|
||||
|
||||
int chroma_loc_info_present_flag;
|
||||
int chroma_sample_loc_type_top_field;
|
||||
int chroma_sample_loc_type_bottom_field;
|
||||
int neutra_chroma_indication_flag;
|
||||
|
||||
int field_seq_flag;
|
||||
int frame_field_info_present_flag;
|
||||
|
||||
int default_display_window_flag;
|
||||
T_HEVCWindow def_disp_win;
|
||||
|
||||
int vui_timing_info_present_flag;
|
||||
uint32_t vui_num_units_in_tick;
|
||||
uint32_t vui_time_scale;
|
||||
int vui_poc_proportional_to_timing_flag;
|
||||
int vui_num_ticks_poc_diff_one_minus1;
|
||||
int vui_hrd_parameters_present_flag;
|
||||
|
||||
int bitstream_restriction_flag;
|
||||
int tiles_fixed_structure_flag;
|
||||
int motion_vectors_over_pic_boundaries_flag;
|
||||
int restricted_ref_pic_lists_flag;
|
||||
int min_spatial_segmentation_idc;
|
||||
int max_bytes_per_pic_denom;
|
||||
int max_bits_per_min_cu_denom;
|
||||
int log2_max_mv_length_horizontal;
|
||||
int log2_max_mv_length_vertical;
|
||||
} T_VUI;
|
||||
|
||||
typedef struct T_PTLCommon {
|
||||
uint8_t profile_space;
|
||||
uint8_t tier_flag;
|
||||
uint8_t profile_idc;
|
||||
uint8_t profile_compatibility_flag[32];
|
||||
uint8_t level_idc;
|
||||
uint8_t progressive_source_flag;
|
||||
uint8_t interlaced_source_flag;
|
||||
uint8_t non_packed_constraint_flag;
|
||||
uint8_t frame_only_constraint_flag;
|
||||
} T_PTLCommon;
|
||||
|
||||
typedef struct T_PTL {
|
||||
T_PTLCommon general_ptl;
|
||||
T_PTLCommon sub_layer_ptl[HEVC_MAX_SUB_LAYERS];
|
||||
|
||||
uint8_t sub_layer_profile_present_flag[HEVC_MAX_SUB_LAYERS];
|
||||
uint8_t sub_layer_level_present_flag[HEVC_MAX_SUB_LAYERS];
|
||||
} T_PTL;
|
||||
|
||||
typedef struct T_ScalingList {
|
||||
/* This is a little wasteful, since sizeID 0 only needs 8 coeffs,
|
||||
* and size ID 3 only has 2 arrays, not 6. */
|
||||
uint8_t sl[4][6][64];
|
||||
uint8_t sl_dc[2][6];
|
||||
} T_ScalingList;
|
||||
|
||||
typedef struct T_ShortTermRPS {
|
||||
unsigned int num_negative_pics;
|
||||
int num_delta_pocs;
|
||||
int rps_idx_num_delta_pocs;
|
||||
int32_t delta_poc[32];
|
||||
uint8_t used[32];
|
||||
} T_ShortTermRPS;
|
||||
|
||||
|
||||
typedef struct T_HEVCSPS {
|
||||
unsigned vps_id;
|
||||
int chroma_format_idc;
|
||||
uint8_t separate_colour_plane_flag;
|
||||
|
||||
///< output (i.e. cropped) values
|
||||
int output_width, output_height;
|
||||
T_HEVCWindow output_window;
|
||||
|
||||
T_HEVCWindow pic_conf_win;
|
||||
|
||||
int bit_depth;
|
||||
int bit_depth_chroma;
|
||||
int pixel_shift;
|
||||
// enum AVPixelFormat pix_fmt;
|
||||
|
||||
unsigned int log2_max_poc_lsb;
|
||||
int pcm_enabled_flag;
|
||||
|
||||
int max_sub_layers;
|
||||
struct {
|
||||
int max_dec_pic_buffering;
|
||||
int num_reorder_pics;
|
||||
int max_latency_increase;
|
||||
} temporal_layer[HEVC_MAX_SUB_LAYERS];
|
||||
uint8_t temporal_id_nesting_flag;
|
||||
|
||||
T_VUI vui;
|
||||
T_PTL ptl;
|
||||
|
||||
uint8_t scaling_list_enable_flag;
|
||||
T_ScalingList scaling_list;
|
||||
|
||||
unsigned int nb_st_rps;
|
||||
T_ShortTermRPS st_rps[HEVC_MAX_SHORT_TERM_RPS_COUNT];
|
||||
|
||||
uint8_t amp_enabled_flag;
|
||||
uint8_t sao_enabled;
|
||||
|
||||
uint8_t long_term_ref_pics_present_flag;
|
||||
uint16_t lt_ref_pic_poc_lsb_sps[32];
|
||||
uint8_t used_by_curr_pic_lt_sps_flag[32];
|
||||
uint8_t num_long_term_ref_pics_sps;
|
||||
|
||||
struct {
|
||||
uint8_t bit_depth;
|
||||
uint8_t bit_depth_chroma;
|
||||
unsigned int log2_min_pcm_cb_size;
|
||||
unsigned int log2_max_pcm_cb_size;
|
||||
uint8_t loop_filter_disable_flag;
|
||||
} pcm;
|
||||
uint8_t sps_temporal_mvp_enabled_flag;
|
||||
uint8_t sps_strong_intra_smoothing_enable_flag;
|
||||
|
||||
unsigned int log2_min_cb_size;
|
||||
unsigned int log2_diff_max_min_coding_block_size;
|
||||
unsigned int log2_min_tb_size;
|
||||
unsigned int log2_max_trafo_size;
|
||||
unsigned int log2_ctb_size;
|
||||
unsigned int log2_min_pu_size;
|
||||
|
||||
int max_transform_hierarchy_depth_inter;
|
||||
int max_transform_hierarchy_depth_intra;
|
||||
|
||||
int transform_skip_rotation_enabled_flag;
|
||||
int transform_skip_context_enabled_flag;
|
||||
int implicit_rdpcm_enabled_flag;
|
||||
int explicit_rdpcm_enabled_flag;
|
||||
int intra_smoothing_disabled_flag;
|
||||
int persistent_rice_adaptation_enabled_flag;
|
||||
|
||||
///< coded frame dimension in various units
|
||||
int width;
|
||||
int height;
|
||||
int ctb_width;
|
||||
int ctb_height;
|
||||
int ctb_size;
|
||||
int min_cb_width;
|
||||
int min_cb_height;
|
||||
int min_tb_width;
|
||||
int min_tb_height;
|
||||
int min_pu_width;
|
||||
int min_pu_height;
|
||||
int tb_mask;
|
||||
|
||||
int hshift[3];
|
||||
int vshift[3];
|
||||
|
||||
int qp_bd_offset;
|
||||
|
||||
uint8_t data[4096];
|
||||
int data_size;
|
||||
}T_HEVCSPS;
|
||||
|
||||
|
||||
typedef struct T_GetBitContext{
|
||||
uint8_t *pu8Buf; /*Ö¸ÏòSPS start*/
|
||||
int iBufSize; /*SPS ³¤¶È*/
|
||||
@@ -180,8 +428,13 @@ typedef struct T_GetBitContext{
|
||||
|
||||
|
||||
int h264DecSeqParameterSet(void *pvBuf, T_SPS *ptSps);
|
||||
int h265DecSeqParameterSet( void *pvBufSrc, T_HEVCSPS *p_sps );
|
||||
|
||||
void h264GetWidthHeight(T_SPS *ptSps, int *piWidth, int *piHeight);
|
||||
void h265GetWidthHeight(T_HEVCSPS *ptSps, int *piWidth, int *piHeight);
|
||||
|
||||
void h264GeFramerate(T_SPS *ptSps, float *pfFramerate);
|
||||
void h265GeFramerate(T_HEVCSPS *ptSps, float *pfFramerate);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user