Fix #1405: Restore the stream when parsing failed. v5.0.59

pull/3282/head
winlin 2 years ago
parent ef04d411c0
commit 6988e60ad6

@ -7,6 +7,7 @@ The changelog for SRS.
## SRS 5.0 Changelog
* v5.0, 2022-09-01, Fix [#1405](https://github.com/ossrs/srs/issues/1405): Restore the stream when parsing failed. v5.0.59
* v5.0, 2022-09-01, Fix [#1405](https://github.com/ossrs/srs/issues/1405): Support guessing IBMF first. v5.0.58
* v5.0, 2022-09-01, ST: Define and use a new jmpbuf. v5.0.57
* v5.0, 2022-08-31, Fix URL parsing bug for `__defaultVhost__`. v5.0.56

@ -9,6 +9,6 @@
#define VERSION_MAJOR 5
#define VERSION_MINOR 0
#define VERSION_REVISION 58
#define VERSION_REVISION 59
#endif

@ -1136,54 +1136,25 @@ srs_error_t SrsFormat::video_nalu_demux(SrsBuffer* stream)
srs_warn("avc ignore type=%d for no sequence header", SrsVideoAvcFrameTraitNALU);
return err;
}
// guess for the first time.
if (vcodec->payload_format == SrsAvcPayloadFormatGuess) {
if (try_annexb_first) {
// One or more NALUs (Full frames are required)
// try "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
if ((err = avc_demux_annexb_format(stream)) != srs_success) {
srs_freep(err);
// try "ISO Base Media File Format" from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
if ((err = avc_demux_ibmf_format(stream)) != srs_success) {
return srs_error_wrap(err, "avc demux ibmf");
} else {
vcodec->payload_format = SrsAvcPayloadFormatIbmf;
}
} else {
vcodec->payload_format = SrsAvcPayloadFormatAnnexb;
}
} else {
// One or more NALUs (Full frames are required)
// try "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
if ((err = avc_demux_ibmf_format(stream)) == srs_success) {
vcodec->payload_format = SrsAvcPayloadFormatIbmf;
} else {
srs_freep(err);
if ((err = avc_demux_annexb_format(stream)) == srs_success) {
vcodec->payload_format = SrsAvcPayloadFormatAnnexb;
} else {
return srs_error_wrap(err, "avc demux annexb");
}
}
}
} else if (vcodec->payload_format == SrsAvcPayloadFormatIbmf) {
// try "ISO Base Media File Format" from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
// Parse the SPS/PPS in ANNEXB or IBMF format.
if (vcodec->payload_format == SrsAvcPayloadFormatIbmf) {
if ((err = avc_demux_ibmf_format(stream)) != srs_success) {
return srs_error_wrap(err, "avc demux ibmf");
}
} else {
// One or more NALUs (Full frames are required)
// try "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
} else if (vcodec->payload_format == SrsAvcPayloadFormatAnnexb) {
if ((err = avc_demux_annexb_format(stream)) != srs_success) {
return srs_error_wrap(err, "avc demux annexb");
}
} else {
if ((err = try_annexb_first ? avc_demux_annexb_format(stream) : avc_demux_ibmf_format(stream)) == srs_success) {
vcodec->payload_format = try_annexb_first ? SrsAvcPayloadFormatAnnexb : SrsAvcPayloadFormatIbmf;
} else {
srs_freep(err);
// try "ISO Base Media File Format" from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
if ((err = avc_demux_ibmf_format(stream)) != srs_success) {
return srs_error_wrap(err, "avc demux ibmf");
if ((err = try_annexb_first ? avc_demux_ibmf_format(stream) : avc_demux_annexb_format(stream)) == srs_success) {
vcodec->payload_format = try_annexb_first ? SrsAvcPayloadFormatIbmf : SrsAvcPayloadFormatAnnexb;
} else {
vcodec->payload_format = SrsAvcPayloadFormatIbmf;
return srs_error_wrap(err, "avc demux try_annexb_first=%d", try_annexb_first);
}
}
}
@ -1192,12 +1163,27 @@ srs_error_t SrsFormat::video_nalu_demux(SrsBuffer* stream)
}
srs_error_t SrsFormat::avc_demux_annexb_format(SrsBuffer* stream)
{
srs_error_t err = srs_success;
int pos = stream->pos();
err = do_avc_demux_annexb_format(stream);
// Restore the stream if error.
if (err != srs_success) {
stream->skip(pos - stream->pos());
}
return err;
}
srs_error_t SrsFormat::do_avc_demux_annexb_format(SrsBuffer* stream)
{
srs_error_t err = srs_success;
// not annexb, try others
if (!srs_avc_startswith_annexb(stream, NULL)) {
return srs_error_new(ERROR_HLS_AVC_TRY_OTHERS, "try others");
return srs_error_new(ERROR_HLS_DECODE_ERROR, "not annexb");
}
// AnnexB
@ -1244,6 +1230,21 @@ srs_error_t SrsFormat::avc_demux_annexb_format(SrsBuffer* stream)
}
srs_error_t SrsFormat::avc_demux_ibmf_format(SrsBuffer* stream)
{
srs_error_t err = srs_success;
int pos = stream->pos();
err = do_avc_demux_ibmf_format(stream);
// Restore the stream if error.
if (err != srs_success) {
stream->skip(pos - stream->pos());
}
return err;
}
srs_error_t SrsFormat::do_avc_demux_ibmf_format(SrsBuffer* stream)
{
srs_error_t err = srs_success;

@ -759,8 +759,10 @@ private:
virtual srs_error_t video_nalu_demux(SrsBuffer* stream);
// Demux the avc NALU in "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
virtual srs_error_t avc_demux_annexb_format(SrsBuffer* stream);
virtual srs_error_t do_avc_demux_annexb_format(SrsBuffer* stream);
// Demux the avc NALU in "ISO Base Media File Format" from ISO_IEC_14496-15-AVC-format-2012.pdf, page 20
virtual srs_error_t avc_demux_ibmf_format(SrsBuffer* stream);
virtual srs_error_t do_avc_demux_ibmf_format(SrsBuffer* stream);
private:
// Demux the audio packet in AAC codec.
// Demux the asc from sequence header.

Loading…
Cancel
Save