mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Fix #1405: Restore the stream when parsing failed. v5.0.59
This commit is contained in:
parent
ef04d411c0
commit
6988e60ad6
4 changed files with 47 additions and 43 deletions
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue