Skip to content

avformat/whip: fix H264 profile_iop bit map for SDP #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: workflows
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 16 additions & 31 deletions libavformat/whip.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ typedef struct WHIPContext {
/* Parameters for the input audio and video codecs. */
AVCodecParameters *audio_par;
AVCodecParameters *video_par;
uint8_t constraint_set_flags;

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

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

if (par->profile != AV_PROFILE_UNKNOWN && par->level != AV_LEVEL_UNKNOWN)
return ret;

if (!par->extradata || par->extradata_size <= 0) {
av_log(whip, AV_LOG_ERROR, "WHIP: Unable to parse profile from empty extradata=%p, size=%d\n",
par->extradata, par->extradata_size);
return AVERROR(EINVAL);
}

while (1) {
r = avpriv_find_start_code(r, end, &state);
if (r >= end)
break;

r1 = ff_nal_find_startcode(r, end);
if ((state & 0x1f) == H264_NAL_SPS) {
ret = ff_avc_decode_sps(sps, r, r1 - r);
if (ret < 0) {
av_log(whip, AV_LOG_ERROR, "WHIP: Failed to decode SPS, state=%x, size=%d\n",
state, (int)(r1 - r));
return ret;
}

av_log(whip, AV_LOG_VERBOSE, "WHIP: Parse profile=%d, level=%d from SPS\n",
sps->profile_idc, sps->level_idc);
par->profile = sps->profile_idc;
par->level = sps->level_idc;
}
if (AV_RB32(r) == 0x00000001 && (r[4] & 0x1F) == 7)
r = &r[5];
else if (AV_RB24(r) == 0x000001 && (r[3] & 0x1F) == 7)
r = &r[4];
else if (r[0] == 0x01) // avcC
r = &r[1];
else
return AVERROR(EINVAL);

r = r1;
}
if (par->profile == AV_PROFILE_UNKNOWN) par->profile = r[0];
whip->constraint_set_flags = r[1];
if (par->level == AV_LEVEL_UNKNOWN) par->level = r[2];

return ret;
}
Expand Down Expand Up @@ -589,7 +575,7 @@ static int parse_codec(AVFormatContext *s)
*/
static int generate_sdp_offer(AVFormatContext *s)
{
int ret = 0, profile, level, profile_iop;
int ret = 0, profile, level;
const char *acodec_name = NULL, *vcodec_name = NULL;
AVBPrint bp;
WHIPContext *whip = s->priv_data;
Expand Down Expand Up @@ -657,11 +643,10 @@ static int generate_sdp_offer(AVFormatContext *s)
}

if (whip->video_par) {
profile_iop = profile = whip->video_par->profile;
profile = whip->video_par->profile;
level = whip->video_par->level;
if (whip->video_par->codec_id == AV_CODEC_ID_H264) {
vcodec_name = "H264";
profile_iop &= AV_PROFILE_H264_CONSTRAINED;
profile &= (~AV_PROFILE_H264_CONSTRAINED);
}

Expand Down Expand Up @@ -689,7 +674,7 @@ static int generate_sdp_offer(AVFormatContext *s)
vcodec_name,
whip->video_payload_type,
profile,
profile_iop,
whip->constraint_set_flags,
level,
whip->video_ssrc,
whip->video_ssrc);
Expand Down