mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Support for multiple SPS/PPS, then pick the first one. (#2544)
This commit is contained in:
parent
38b0b1dab2
commit
826f5121c5
2 changed files with 54 additions and 24 deletions
|
@ -806,9 +806,11 @@ srs_error_t SrsFormat::avc_demux_sps_pps(SrsBuffer* stream)
|
||||||
}
|
}
|
||||||
int8_t numOfSequenceParameterSets = stream->read_1bytes();
|
int8_t numOfSequenceParameterSets = stream->read_1bytes();
|
||||||
numOfSequenceParameterSets &= 0x1f;
|
numOfSequenceParameterSets &= 0x1f;
|
||||||
if (numOfSequenceParameterSets != 1) {
|
if (numOfSequenceParameterSets < 1) {
|
||||||
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode SPS");
|
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode SPS");
|
||||||
}
|
}
|
||||||
|
// Support for multiple SPS, then pick the first non-empty one.
|
||||||
|
for (int i = 0; i < numOfSequenceParameterSets; ++i) {
|
||||||
if (!stream->require(2)) {
|
if (!stream->require(2)) {
|
||||||
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode SPS size");
|
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode SPS size");
|
||||||
}
|
}
|
||||||
|
@ -816,19 +818,27 @@ srs_error_t SrsFormat::avc_demux_sps_pps(SrsBuffer* stream)
|
||||||
if (!stream->require(sequenceParameterSetLength)) {
|
if (!stream->require(sequenceParameterSetLength)) {
|
||||||
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode SPS data");
|
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode SPS data");
|
||||||
}
|
}
|
||||||
|
if (vcodec->sequenceParameterSetNALUnit.size() > 0) {
|
||||||
|
stream->skip(sequenceParameterSetLength);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (sequenceParameterSetLength > 0) {
|
if (sequenceParameterSetLength > 0) {
|
||||||
vcodec->sequenceParameterSetNALUnit.resize(sequenceParameterSetLength);
|
vcodec->sequenceParameterSetNALUnit.resize(sequenceParameterSetLength);
|
||||||
stream->read_bytes(&vcodec->sequenceParameterSetNALUnit[0], sequenceParameterSetLength);
|
stream->read_bytes(&vcodec->sequenceParameterSetNALUnit[0], sequenceParameterSetLength);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 1 pps
|
// 1 pps
|
||||||
if (!stream->require(1)) {
|
if (!stream->require(1)) {
|
||||||
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode PPS");
|
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode PPS");
|
||||||
}
|
}
|
||||||
int8_t numOfPictureParameterSets = stream->read_1bytes();
|
int8_t numOfPictureParameterSets = stream->read_1bytes();
|
||||||
numOfPictureParameterSets &= 0x1f;
|
numOfPictureParameterSets &= 0x1f;
|
||||||
if (numOfPictureParameterSets != 1) {
|
if (numOfPictureParameterSets < 1) {
|
||||||
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode PPS");
|
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode SPS");
|
||||||
}
|
}
|
||||||
|
// Support for multiple PPS, then pick the first non-empty one.
|
||||||
|
for (int i = 0; i < numOfPictureParameterSets; ++i) {
|
||||||
if (!stream->require(2)) {
|
if (!stream->require(2)) {
|
||||||
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode PPS size");
|
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode PPS size");
|
||||||
}
|
}
|
||||||
|
@ -836,11 +846,15 @@ srs_error_t SrsFormat::avc_demux_sps_pps(SrsBuffer* stream)
|
||||||
if (!stream->require(pictureParameterSetLength)) {
|
if (!stream->require(pictureParameterSetLength)) {
|
||||||
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode PPS data");
|
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode PPS data");
|
||||||
}
|
}
|
||||||
|
if (vcodec->pictureParameterSetNALUnit.size() > 0) {
|
||||||
|
stream->skip(pictureParameterSetLength);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (pictureParameterSetLength > 0) {
|
if (pictureParameterSetLength > 0) {
|
||||||
vcodec->pictureParameterSetNALUnit.resize(pictureParameterSetLength);
|
vcodec->pictureParameterSetNALUnit.resize(pictureParameterSetLength);
|
||||||
stream->read_bytes(&vcodec->pictureParameterSetNALUnit[0], pictureParameterSetLength);
|
stream->read_bytes(&vcodec->pictureParameterSetNALUnit[0], pictureParameterSetLength);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return avc_demux_sps();
|
return avc_demux_sps();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3723,6 +3723,22 @@ VOID TEST(KernelCodecTest, VideoFormatSepcial)
|
||||||
};
|
};
|
||||||
HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)buf, sizeof(buf)));
|
HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)buf, sizeof(buf)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
SrsFormat f;
|
||||||
|
HELPER_EXPECT_SUCCESS(f.initialize());
|
||||||
|
uint8_t buf[] = {
|
||||||
|
0x17, // 1, Keyframe; 7, AVC.
|
||||||
|
0x00, // 0, Sequence header.
|
||||||
|
0x00, 0x00, 0x00, // Timestamp.
|
||||||
|
// AVC extra data, SPS/PPS.
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, // lengthSizeMinusOne
|
||||||
|
0x02, 0x00, 0x00, 0x00, 0x00, // 2 SPS,
|
||||||
|
0x02, 0x00, 0x00, 0x00, 0x00 // 2 PPS,
|
||||||
|
};
|
||||||
|
HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)buf, sizeof(buf)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID TEST(KernelCodecTest, VideoFormat)
|
VOID TEST(KernelCodecTest, VideoFormat)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue