Cover more kernel codec.

pull/1398/head
winlin 6 years ago
parent 77cc148608
commit f7994b85eb

@ -553,10 +553,8 @@ srs_error_t SrsFormat::on_audio(int64_t timestamp, char* data, int size)
SrsBuffer* buffer = new SrsBuffer(data, size);
SrsAutoFree(SrsBuffer, buffer);
// audio decode
if (!buffer->require(1)) {
return srs_error_new(ERROR_HLS_DECODE_ERROR, "aac decode sound_format");
}
// We already checked the size is positive and data is not NULL.
srs_assert(buffer->require(1));
// @see: E.4.2 Audio Tags, video_file_format_spec_v10_1.pdf, page 76
uint8_t v = buffer->read_1bytes();
@ -599,10 +597,8 @@ srs_error_t SrsFormat::on_video(int64_t timestamp, char* data, int size)
SrsBuffer* buffer = new SrsBuffer(data, size);
SrsAutoFree(SrsBuffer, buffer);
// video decode
if (!buffer->require(1)) {
return srs_error_new(ERROR_HLS_DECODE_ERROR, "decode frame_type");
}
// We already checked the size is positive and data is not NULL.
srs_assert(buffer->require(1));
// @see: E.4.3 Video Tags, video_file_format_spec_v10_1.pdf, page 78
int8_t frame_type = buffer->read_1bytes();

@ -2690,6 +2690,39 @@ VOID TEST(KernelCodecTest, AVFrame)
}
}
VOID TEST(KernelCodecTest, IsSequenceHeaderSpecial)
{
if (true) {
SrsFormat f;
EXPECT_FALSE(f.is_avc_sequence_header());
f.vcodec = new SrsVideoCodecConfig();
f.video = new SrsVideoFrame();
EXPECT_FALSE(f.is_avc_sequence_header());
f.vcodec->id = SrsVideoCodecIdAVC;
EXPECT_FALSE(f.is_avc_sequence_header());
f.video->avc_packet_type = SrsVideoAvcFrameTraitSequenceHeader;
EXPECT_TRUE(f.is_avc_sequence_header());
}
if (true) {
SrsFormat f;
EXPECT_FALSE(f.is_avc_sequence_header());
f.vcodec = new SrsVideoCodecConfig();
f.video = new SrsVideoFrame();
EXPECT_FALSE(f.is_avc_sequence_header());
f.vcodec->id = SrsVideoCodecIdHEVC;
EXPECT_FALSE(f.is_avc_sequence_header());
f.video->avc_packet_type = SrsVideoAvcFrameTraitSequenceHeader;
EXPECT_TRUE(f.is_avc_sequence_header());
}
}
VOID TEST(KernelCodecTest, AudioFormat)
{
if (true) {
@ -2805,6 +2838,137 @@ VOID TEST(KernelCodecTest, AudioFormat)
}
}
VOID TEST(KernelCodecTest, VideoFormatSepcial)
{
srs_error_t err;
if (true) {
SrsFormat f;
EXPECT_TRUE(srs_success == f.initialize());
HELPER_EXPECT_FAILED(f.on_video(0, (char*)"\x17", 1));
HELPER_EXPECT_FAILED(f.on_video(0, (char*)"\x27", 1));
}
if (true) {
SrsFormat f;
EXPECT_TRUE(srs_success == f.initialize());
uint8_t buf[] = {
0x17, // 1, Keyframe; 7, AVC.
0x00, // 0, Sequence header.
0x00, 0x00, 0x00, // Timestamp.
};
HELPER_EXPECT_FAILED(f.on_video(0, (char*)buf, sizeof(buf)));
}
if (true) {
SrsFormat f;
EXPECT_TRUE(srs_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,
0x02, // lengthSizeMinusOne
0x00,
};
HELPER_EXPECT_FAILED(f.on_video(0, (char*)buf, sizeof(buf)));
}
if (true) {
SrsFormat f;
EXPECT_TRUE(srs_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
0x00, // SPS
};
HELPER_EXPECT_FAILED(f.on_video(0, (char*)buf, sizeof(buf)));
}
if (true) {
SrsFormat f;
EXPECT_TRUE(srs_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
0x01, // SPS
};
HELPER_EXPECT_FAILED(f.on_video(0, (char*)buf, sizeof(buf)));
}
if (true) {
SrsFormat f;
EXPECT_TRUE(srs_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
0x01, 0x00, 0x00, // SPS, empty
};
HELPER_EXPECT_FAILED(f.on_video(0, (char*)buf, sizeof(buf)));
}
if (true) {
SrsFormat f;
EXPECT_TRUE(srs_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
0x01, 0x00, 0x00, // SPS, empty
0x00, // PPS
};
HELPER_EXPECT_FAILED(f.on_video(0, (char*)buf, sizeof(buf)));
}
if (true) {
SrsFormat f;
EXPECT_TRUE(srs_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
0x01, 0x00, 0x00, // SPS
0x01, // PPS
};
HELPER_EXPECT_FAILED(f.on_video(0, (char*)buf, sizeof(buf)));
}
if (true) {
SrsFormat f;
EXPECT_TRUE(srs_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
0x01, 0x00, 0x00, // SPS, empty
0x01, 0x00, 0x00, // PPS, empty
};
HELPER_EXPECT_SUCCESS(f.on_video(0, (char*)buf, sizeof(buf)));
}
}
VOID TEST(KernelCodecTest, VideoFormat)
{
if (true) {

Loading…
Cancel
Save