Skip to content

Commit d143e19

Browse files
committed
avformat/whip: add H264 constraints flag fully parse
refer to hlsenc write_codec_attr code Signed-off-by: Jack Lau <[email protected]>
1 parent 777cb42 commit d143e19

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

libavformat/whip.c

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ typedef struct WHIPContext {
205205
/* Parameters for the input audio and video codecs. */
206206
AVCodecParameters *audio_par;
207207
AVCodecParameters *video_par;
208+
uint8_t constraint_set_flags;
208209

209210
/**
210211
* The h264_mp4toannexb Bitstream Filter (BSF) bypasses the AnnexB packet;
@@ -440,45 +441,30 @@ static av_cold int initialize(AVFormatContext *s)
440441
static int parse_profile_level(AVFormatContext *s, AVCodecParameters *par)
441442
{
442443
int ret = 0;
443-
const uint8_t *r = par->extradata, *r1, *end = par->extradata + par->extradata_size;
444-
H264SPS seq, *const sps = &seq;
445-
uint32_t state;
444+
const uint8_t *r = par->extradata;
446445
WHIPContext *whip = s->priv_data;
447446

448447
if (par->codec_id != AV_CODEC_ID_H264)
449448
return ret;
450449

451-
if (par->profile != AV_PROFILE_UNKNOWN && par->level != AV_LEVEL_UNKNOWN)
452-
return ret;
453-
454450
if (!par->extradata || par->extradata_size <= 0) {
455451
av_log(whip, AV_LOG_ERROR, "WHIP: Unable to parse profile from empty extradata=%p, size=%d\n",
456452
par->extradata, par->extradata_size);
457453
return AVERROR(EINVAL);
458454
}
459455

460-
while (1) {
461-
r = avpriv_find_start_code(r, end, &state);
462-
if (r >= end)
463-
break;
464-
465-
r1 = ff_nal_find_startcode(r, end);
466-
if ((state & 0x1f) == H264_NAL_SPS) {
467-
ret = ff_avc_decode_sps(sps, r, r1 - r);
468-
if (ret < 0) {
469-
av_log(whip, AV_LOG_ERROR, "WHIP: Failed to decode SPS, state=%x, size=%d\n",
470-
state, (int)(r1 - r));
471-
return ret;
472-
}
473-
474-
av_log(whip, AV_LOG_VERBOSE, "WHIP: Parse profile=%d, level=%d from SPS\n",
475-
sps->profile_idc, sps->level_idc);
476-
par->profile = sps->profile_idc;
477-
par->level = sps->level_idc;
478-
}
456+
if (AV_RB32(r) == 0x00000001 && (r[4] & 0x1F) == 7)
457+
r = &r[5];
458+
else if (AV_RB24(r) == 0x000001 && (r[3] & 0x1F) == 7)
459+
r = &r[4];
460+
else if (r[0] == 0x01) // avcC
461+
r = &r[1];
462+
else
463+
return AVERROR(EINVAL);
479464

480-
r = r1;
481-
}
465+
if (par->profile == AV_PROFILE_UNKNOWN) par->profile = r[0];
466+
whip->constraint_set_flags = r[1];
467+
if (par->level == AV_LEVEL_UNKNOWN) par->level = r[2];
482468

483469
return ret;
484470
}
@@ -589,7 +575,7 @@ static int parse_codec(AVFormatContext *s)
589575
*/
590576
static int generate_sdp_offer(AVFormatContext *s)
591577
{
592-
int ret = 0, profile, level, profile_iop;
578+
int ret = 0, profile, level;
593579
const char *acodec_name = NULL, *vcodec_name = NULL;
594580
AVBPrint bp;
595581
WHIPContext *whip = s->priv_data;
@@ -657,11 +643,10 @@ static int generate_sdp_offer(AVFormatContext *s)
657643
}
658644

659645
if (whip->video_par) {
660-
profile_iop = profile = whip->video_par->profile;
646+
profile = whip->video_par->profile;
661647
level = whip->video_par->level;
662648
if (whip->video_par->codec_id == AV_CODEC_ID_H264) {
663649
vcodec_name = "H264";
664-
profile_iop = (whip->video_par->profile & AV_PROFILE_H264_CONSTRAINED) ? (1<<6) : 0;
665650
profile &= (~AV_PROFILE_H264_CONSTRAINED);
666651
}
667652

@@ -689,7 +674,7 @@ static int generate_sdp_offer(AVFormatContext *s)
689674
vcodec_name,
690675
whip->video_payload_type,
691676
profile,
692-
profile_iop,
677+
whip->constraint_set_flags,
693678
level,
694679
whip->video_ssrc,
695680
whip->video_ssrc);

0 commit comments

Comments
 (0)