1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-01-08 13:22:53 +02:00

avformat/hevc: add a log context to ff_isom_write_{hvcc,lhvc}

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
James Almer 2024-12-08 19:06:56 -03:00
parent 550c662a1f
commit 68ee3faf48
6 changed files with 50 additions and 47 deletions

View File

@ -695,7 +695,7 @@ static void flv_write_codec_header(AVFormatContext* s, AVCodecParameters* par, i
}
if (par->codec_id == AV_CODEC_ID_HEVC)
ff_isom_write_hvcc(pb, par->extradata, par->extradata_size, 0);
ff_isom_write_hvcc(pb, par->extradata, par->extradata_size, 0, s);
else if (par->codec_id == AV_CODEC_ID_AV1)
ff_isom_write_av1c(pb, par->extradata, par->extradata_size, 1);
else if (par->codec_id == AV_CODEC_ID_VP9)

View File

@ -838,8 +838,8 @@ static void hvcc_close(HEVCDecoderConfigurationRecord *hvcc)
}
}
static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc,
int flags)
static int hvcc_write(void *logctx, AVIOContext *pb,
HEVCDecoderConfigurationRecord *hvcc, int flags)
{
uint16_t numNalus[NB_ARRAYS] = { 0 };
int is_lhvc = !!(flags & FLAG_IS_LHVC);
@ -891,46 +891,46 @@ static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc,
numOfArrays += (numNalus[i] > 0);
}
av_log(NULL, AV_LOG_TRACE, "%s\n", is_lhvc ? "lhvC" : "hvcC");
av_log(NULL, AV_LOG_TRACE, "configurationVersion: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "%s\n", is_lhvc ? "lhvC" : "hvcC");
av_log(logctx, AV_LOG_TRACE, "configurationVersion: %"PRIu8"\n",
hvcc->configurationVersion);
if (!is_lhvc) {
av_log(NULL, AV_LOG_TRACE, "general_profile_space: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "general_profile_space: %"PRIu8"\n",
hvcc->general_profile_space);
av_log(NULL, AV_LOG_TRACE, "general_tier_flag: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "general_tier_flag: %"PRIu8"\n",
hvcc->general_tier_flag);
av_log(NULL, AV_LOG_TRACE, "general_profile_idc: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "general_profile_idc: %"PRIu8"\n",
hvcc->general_profile_idc);
av_log(NULL, AV_LOG_TRACE, "general_profile_compatibility_flags: 0x%08"PRIx32"\n",
av_log(logctx, AV_LOG_TRACE, "general_profile_compatibility_flags: 0x%08"PRIx32"\n",
hvcc->general_profile_compatibility_flags);
av_log(NULL, AV_LOG_TRACE, "general_constraint_indicator_flags: 0x%012"PRIx64"\n",
av_log(logctx, AV_LOG_TRACE, "general_constraint_indicator_flags: 0x%012"PRIx64"\n",
hvcc->general_constraint_indicator_flags);
av_log(NULL, AV_LOG_TRACE, "general_level_idc: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "general_level_idc: %"PRIu8"\n",
hvcc->general_level_idc);
}
av_log(NULL, AV_LOG_TRACE, "min_spatial_segmentation_idc: %"PRIu16"\n",
av_log(logctx, AV_LOG_TRACE, "min_spatial_segmentation_idc: %"PRIu16"\n",
hvcc->min_spatial_segmentation_idc);
av_log(NULL, AV_LOG_TRACE, "parallelismType: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "parallelismType: %"PRIu8"\n",
hvcc->parallelismType);
if (!is_lhvc) {
av_log(NULL, AV_LOG_TRACE, "chromaFormat: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "chromaFormat: %"PRIu8"\n",
hvcc->chromaFormat);
av_log(NULL, AV_LOG_TRACE, "bitDepthLumaMinus8: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "bitDepthLumaMinus8: %"PRIu8"\n",
hvcc->bitDepthLumaMinus8);
av_log(NULL, AV_LOG_TRACE, "bitDepthChromaMinus8: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "bitDepthChromaMinus8: %"PRIu8"\n",
hvcc->bitDepthChromaMinus8);
av_log(NULL, AV_LOG_TRACE, "avgFrameRate: %"PRIu16"\n",
av_log(logctx, AV_LOG_TRACE, "avgFrameRate: %"PRIu16"\n",
hvcc->avgFrameRate);
av_log(NULL, AV_LOG_TRACE, "constantFrameRate: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "constantFrameRate: %"PRIu8"\n",
hvcc->constantFrameRate);
}
av_log(NULL, AV_LOG_TRACE, "numTemporalLayers: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "numTemporalLayers: %"PRIu8"\n",
hvcc->numTemporalLayers);
av_log(NULL, AV_LOG_TRACE, "temporalIdNested: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "temporalIdNested: %"PRIu8"\n",
hvcc->temporalIdNested);
av_log(NULL, AV_LOG_TRACE, "lengthSizeMinusOne: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "lengthSizeMinusOne: %"PRIu8"\n",
hvcc->lengthSizeMinusOne);
av_log(NULL, AV_LOG_TRACE, "numOfArrays: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "numOfArrays: %"PRIu8"\n",
numOfArrays);
for (unsigned i = 0, j = 0; i < FF_ARRAY_ELEMS(hvcc->arrays); i++) {
const HVCCNALUnitArray *const array = &hvcc->arrays[i];
@ -938,17 +938,17 @@ static int hvcc_write(AVIOContext *pb, HEVCDecoderConfigurationRecord *hvcc,
if (numNalus[i] == 0)
continue;
av_log(NULL, AV_LOG_TRACE, "array_completeness[%u]: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "array_completeness[%u]: %"PRIu8"\n",
j, array->array_completeness);
av_log(NULL, AV_LOG_TRACE, "NAL_unit_type[%u]: %"PRIu8"\n",
av_log(logctx, AV_LOG_TRACE, "NAL_unit_type[%u]: %"PRIu8"\n",
j, array->NAL_unit_type);
av_log(NULL, AV_LOG_TRACE, "numNalus[%u]: %"PRIu16"\n",
av_log(logctx, AV_LOG_TRACE, "numNalus[%u]: %"PRIu16"\n",
j, numNalus[i]);
for (unsigned k = 0; k < array->numNalus; k++) {
if (is_lhvc && array->nal[k].nuh_layer_id == 0)
continue;
av_log(NULL, AV_LOG_TRACE,
av_log(logctx, AV_LOG_TRACE,
"nalUnitLength[%u][%u]: %"PRIu16"\n",
j, k, array->nal[k].nalUnitLength);
}
@ -1164,7 +1164,7 @@ static int hvcc_parse_nal_unit(const uint8_t *buf, uint32_t len, int type,
return 0;
}
static int write_configuration_record(AVIOContext *pb, const uint8_t *data,
static int write_configuration_record(void *logctx, AVIOContext *pb, const uint8_t *data,
int size, int flags)
{
HEVCDecoderConfigurationRecord hvcc;
@ -1235,7 +1235,7 @@ static int write_configuration_record(AVIOContext *pb, const uint8_t *data,
}
}
ret = hvcc_write(pb, &hvcc, flags);
ret = hvcc_write(logctx, pb, &hvcc, flags);
goto end;
} else if (!(AV_RB24(data) == 1 || AV_RB32(data) == 1)) {
/* Not a valid Annex B start code prefix */
@ -1264,7 +1264,7 @@ static int write_configuration_record(AVIOContext *pb, const uint8_t *data,
buf += len;
}
ret = hvcc_write(pb, &hvcc, flags);
ret = hvcc_write(logctx, pb, &hvcc, flags);
end:
hvcc_close(&hvcc);
@ -1273,15 +1273,15 @@ end:
}
int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data,
int size, int ps_array_completeness)
int size, int ps_array_completeness, void *logctx)
{
return write_configuration_record(pb, data, size,
return write_configuration_record(logctx, pb, data, size,
!!ps_array_completeness * FLAG_ARRAY_COMPLETENESS);
}
int ff_isom_write_lhvc(AVIOContext *pb, const uint8_t *data,
int size, int ps_array_completeness)
int size, int ps_array_completeness, void *logctx)
{
return write_configuration_record(pb, data, size,
return write_configuration_record(logctx, pb, data, size,
(!!ps_array_completeness * FLAG_ARRAY_COMPLETENESS) | FLAG_IS_LHVC);
}

View File

@ -91,11 +91,12 @@ int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out,
* @param size size (in bytes) of the data buffer
* @param ps_array_completeness whether all parameter sets are in the hvcC (1)
* or there may be additional parameter sets in the bitstream (0)
* @param logctx opaque struct starting with an AVClass element, used for logging
* @return >=0 in case of success, a negative value corresponding to an AVERROR
* code in case of failure
*/
int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data,
int size, int ps_array_completeness);
int size, int ps_array_completeness, void *logctx);
/**
* Writes L-HEVC extradata (parameter sets with nuh_layer_id > 0, as a
@ -109,9 +110,10 @@ int ff_isom_write_hvcc(AVIOContext *pb, const uint8_t *data,
* @param size size (in bytes) of the data buffer
* @param ps_array_completeness whether all parameter sets are in the lhvC (1)
* or there may be additional parameter sets in the bitstream (0)
* @param logctx opaque struct starting with an AVClass element, used for logging
* @return >=0 in case of success, a negative value corresponding to an AVERROR
* code in case of failure
*/
int ff_isom_write_lhvc(AVIOContext *pb, const uint8_t *data,
int size, int ps_array_completeness);
int size, int ps_array_completeness, void *logctx);
#endif /* AVFORMAT_HEVC_H */

View File

@ -1140,7 +1140,7 @@ static int mkv_assemble_native_codecprivate(AVFormatContext *s, AVIOContext *dyn
extradata_size);
case AV_CODEC_ID_HEVC:
return ff_isom_write_hvcc(dyn_cp, extradata,
extradata_size, 0);
extradata_size, 0, s);
case AV_CODEC_ID_ALAC:
if (extradata_size < 36) {
av_log(s, AV_LOG_ERROR,

View File

@ -1550,20 +1550,20 @@ static int mov_write_vpcc_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *tra
return update_size(pb, pos);
}
static int mov_write_hvcc_tag(AVIOContext *pb, MOVTrack *track)
static int mov_write_hvcc_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track)
{
int64_t pos = avio_tell(pb);
avio_wb32(pb, 0);
ffio_wfourcc(pb, "hvcC");
if (track->tag == MKTAG('h','v','c','1'))
ff_isom_write_hvcc(pb, track->vos_data, track->vos_len, 1);
ff_isom_write_hvcc(pb, track->vos_data, track->vos_len, 1, s);
else
ff_isom_write_hvcc(pb, track->vos_data, track->vos_len, 0);
ff_isom_write_hvcc(pb, track->vos_data, track->vos_len, 0, s);
return update_size(pb, pos);
}
static int mov_write_lhvc_tag(AVIOContext *pb, MOVTrack *track)
static int mov_write_lhvc_tag(AVFormatContext *s, AVIOContext *pb, MOVTrack *track)
{
int64_t pos = avio_tell(pb);
int ret;
@ -1571,9 +1571,9 @@ static int mov_write_lhvc_tag(AVIOContext *pb, MOVTrack *track)
avio_wb32(pb, 0);
ffio_wfourcc(pb, "lhvC");
if (track->tag == MKTAG('h','v','c','1'))
ret = ff_isom_write_lhvc(pb, track->vos_data, track->vos_len, 1);
ret = ff_isom_write_lhvc(pb, track->vos_data, track->vos_len, 1, s);
else
ret = ff_isom_write_lhvc(pb, track->vos_data, track->vos_len, 0);
ret = ff_isom_write_lhvc(pb, track->vos_data, track->vos_len, 0, s);
if (ret < 0) {
avio_seek(pb, pos, SEEK_SET);
@ -2710,9 +2710,9 @@ static int mov_write_video_tag(AVFormatContext *s, AVIOContext *pb, MOVMuxContex
mov_write_avid_tag(pb, track);
avid = 1;
} else if (track->par->codec_id == AV_CODEC_ID_HEVC) {
mov_write_hvcc_tag(pb, track);
mov_write_hvcc_tag(mov->fc, pb, track);
if (track->st->disposition & AV_DISPOSITION_MULTILAYER) {
ret = mov_write_lhvc_tag(pb, track);
ret = mov_write_lhvc_tag(mov->fc, pb, track);
if (ret < 0)
av_log(mov->fc, AV_LOG_WARNING, "Not writing 'lhvC' atom for multilayer stream.\n");
}

View File

@ -236,7 +236,8 @@ fail_in_loop:
return 0;
}
static int extradata2psets_hevc(const AVCodecParameters *par, char **out)
static int extradata2psets_hevc(AVFormatContext *fmt, const AVCodecParameters *par,
char **out)
{
char *psets;
uint8_t *extradata = par->extradata;
@ -260,7 +261,7 @@ static int extradata2psets_hevc(const AVCodecParameters *par, char **out)
if (ret < 0)
return ret;
ret = ff_isom_write_hvcc(pb, par->extradata, par->extradata_size, 0);
ret = ff_isom_write_hvcc(pb, par->extradata, par->extradata_size, 0, fmt);
if (ret < 0) {
avio_close_dyn_buf(pb, &tmpbuf);
goto err;
@ -571,7 +572,7 @@ static int sdp_write_media_attributes(char *buff, int size, const AVStream *st,
break;
case AV_CODEC_ID_HEVC:
if (p->extradata_size) {
ret = extradata2psets_hevc(p, &config);
ret = extradata2psets_hevc(fmt, p, &config);
if (ret < 0)
return ret;
}