1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

CI: Cover kernel mp4

This commit is contained in:
winlin 2019-02-05 20:15:32 +08:00
parent a0ba17b397
commit a8408de972
2 changed files with 183 additions and 9 deletions

View file

@ -36,6 +36,7 @@ using namespace std;
#include <srs_kernel_log.hpp>
#include <srs_kernel_mp3.hpp>
#include <srs_kernel_ts.hpp>
#include <srs_kernel_mp4.hpp>
#define MAX_MOCK_DATA_SIZE 1024 * 1024
@ -74,6 +75,11 @@ bool MockSrsFileWriter::is_open()
return offset >= 0;
}
void MockSrsFileWriter::seek2(int64_t offset)
{
this->offset = offset;
}
int64_t MockSrsFileWriter::tellg()
{
return offset;
@ -102,6 +108,19 @@ srs_error_t MockSrsFileWriter::write(void* buf, size_t count, ssize_t* pnwrite)
return srs_success;
}
srs_error_t MockSrsFileWriter::lseek(off_t offset, int whence, off_t* seeked)
{
if (seeked) {
*seeked = (off_t)this->offset;
}
if (whence == SEEK_SET) {
this->offset = (int)offset;
}
return srs_success;
}
void MockSrsFileWriter::mock_reset_offset()
{
offset = 0;
@ -176,9 +195,15 @@ srs_error_t MockSrsFileReader::read(void* buf, size_t count, ssize_t* pnread)
return srs_success;
}
srs_error_t MockSrsFileReader::lseek(off_t _offset, int /*whence*/, off_t* /*seeked*/)
srs_error_t MockSrsFileReader::lseek(off_t _offset, int whence, off_t* seeked)
{
offset = (int)_offset;
if (seeked) {
*seeked = (off_t)offset;
}
if (whence == SEEK_SET) {
offset = (int)_offset;
}
return srs_success;
}
@ -3492,13 +3517,6 @@ VOID TEST(KernelTSTest, CoverTransmuxer)
MockSrsFileWriter f;
EXPECT_TRUE(srs_success == m.initialize(&f));
if (true) {
uint8_t raw[] = {
0xaf, 0x00, 0x12, 0x10
};
EXPECT_TRUE(srs_success == m.write_audio(0, (char*)raw, sizeof(raw)));
}
if (true) {
uint8_t raw[] = {
0x17,
@ -3509,6 +3527,13 @@ VOID TEST(KernelTSTest, CoverTransmuxer)
EXPECT_TRUE(srs_success == m.write_video(0, (char*)raw, sizeof(raw)));
}
if (true) {
uint8_t raw[] = {
0xaf, 0x00, 0x12, 0x10
};
EXPECT_TRUE(srs_success == m.write_audio(0, (char*)raw, sizeof(raw)));
}
if (true) {
uint8_t raw[] = {
0xaf,
@ -3539,3 +3564,150 @@ VOID TEST(KernelTSTest, CoverTransmuxer)
}
}
VOID TEST(KernelMP4Test, CoverMP4Encoder)
{
SrsMp4Encoder enc;
MockSrsFileWriter f;
SrsFormat fmt;
EXPECT_TRUE(srs_success == enc.initialize(&f));
EXPECT_TRUE(srs_success == fmt.initialize());
if (true) {
uint8_t raw[] = {
0x17,
0x00, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x20, 0xff, 0xe1, 0x00, 0x19, 0x67, 0x64, 0x00, 0x20,
0xac, 0xd9, 0x40, 0xc0, 0x29, 0xb0, 0x11, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00,
0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c
};
EXPECT_TRUE(srs_success == fmt.on_video(0, (char*)raw, sizeof(raw)));
EXPECT_TRUE(srs_success == enc.write_sample(
SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw
));
}
if (true) {
uint8_t raw[] = {
0xaf, 0x00, 0x12, 0x10
};
EXPECT_TRUE(srs_success == fmt.on_audio(0, (char*)raw, sizeof(raw)));
EXPECT_TRUE(srs_success == enc.write_sample(
SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 0, 0, (uint8_t*)fmt.raw, fmt.nb_raw
));
}
if (true) {
uint8_t raw[] = {
0xaf,
0x01, 0x21, 0x11, 0x45, 0x00, 0x14, 0x50, 0x01, 0x46, 0xf3, 0xf1, 0x0a, 0x5a, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e
};
EXPECT_TRUE(srs_success == fmt.on_audio(0, (char*)raw, sizeof(raw)));
EXPECT_TRUE(srs_success == enc.write_sample(
SrsMp4HandlerTypeSOUN, 0x00, fmt.audio->aac_packet_type, 34, 34, (uint8_t*)fmt.raw, fmt.nb_raw
));
}
if (true) {
uint8_t raw[] = {
0x27,
0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x7b, 0x41, 0x9a, 0x21, 0x6c, 0x42, 0x1f, 0x00, 0x00,
0xf1, 0x68, 0x1a, 0x35, 0x84, 0xb3, 0xee, 0xe0, 0x61, 0xba, 0x4e, 0xa8, 0x52, 0x48, 0x50, 0x59,
0x75, 0x42, 0xd9, 0x96, 0x4a, 0x51, 0x38, 0x2c, 0x63, 0x5e, 0x41, 0xc9, 0x70, 0x60, 0x9d, 0x13,
0x53, 0xc2, 0xa8, 0xf5, 0x45, 0x86, 0xc5, 0x3e, 0x28, 0x1a, 0x69, 0x5f, 0x71, 0x1e, 0x51, 0x74,
0x0e, 0x31, 0x47, 0x3c, 0xd3, 0xd2, 0x10, 0x25, 0x45, 0xc5, 0xb7, 0x31, 0xec, 0x7f, 0xd8, 0x02,
0xae, 0xa4, 0x77, 0x6d, 0xcb, 0xc6, 0x1e, 0x2f, 0xa2, 0xd1, 0x12, 0x08, 0x34, 0x52, 0xea, 0xe8,
0x0b, 0x4f, 0x81, 0x21, 0x4f, 0x71, 0x3f, 0xf2, 0xad, 0x02, 0x58, 0xdf, 0x9e, 0x31, 0x86, 0x9b,
0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82,
0xb2, 0x72, 0x5a
};
EXPECT_TRUE(srs_success == fmt.on_video(0, (char*)raw, sizeof(raw)));
EXPECT_TRUE(srs_success == enc.write_sample(
SrsMp4HandlerTypeVIDE, fmt.video->frame_type, fmt.video->avc_packet_type, 40, 40, (uint8_t*)fmt.raw, fmt.nb_raw
));
}
EXPECT_TRUE(srs_success == enc.flush());
}
uint8_t* mock_copy_bytes(char* data, int size)
{
uint8_t* cp = new uint8_t[size];
memcpy(cp, data, size);
return cp;
}
VOID TEST(KernelMP4Test, CoverMP4M2tsSegmentEncoder)
{
SrsMp4M2tsSegmentEncoder enc;
MockSrsFileWriter f;
EXPECT_TRUE(srs_success == enc.initialize(&f, 0, 0, 100));
SrsFormat fmt;
EXPECT_TRUE(srs_success == fmt.initialize());
if (true) {
uint8_t raw[] = {
0x17,
0x00, 0x00, 0x00, 0x00, 0x01, 0x64, 0x00, 0x20, 0xff, 0xe1, 0x00, 0x19, 0x67, 0x64, 0x00, 0x20,
0xac, 0xd9, 0x40, 0xc0, 0x29, 0xb0, 0x11, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00,
0x32, 0x0f, 0x18, 0x31, 0x96, 0x01, 0x00, 0x05, 0x68, 0xeb, 0xec, 0xb2, 0x2c
};
EXPECT_TRUE(srs_success == fmt.on_video(0, (char*)raw, sizeof(raw)));
EXPECT_TRUE(srs_success == enc.write_sample(
SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 0, 0, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw
));
}
if (true) {
uint8_t raw[] = {
0xaf, 0x00, 0x12, 0x10
};
EXPECT_TRUE(srs_success == fmt.on_audio(0, (char*)raw, sizeof(raw)));
EXPECT_TRUE(srs_success == enc.write_sample(
SrsMp4HandlerTypeSOUN, 0x00, 0, 0, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw
));
}
if (true) {
uint8_t raw[] = {
0xaf,
0x01, 0x21, 0x11, 0x45, 0x00, 0x14, 0x50, 0x01, 0x46, 0xf3, 0xf1, 0x0a, 0x5a, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5e
};
EXPECT_TRUE(srs_success == fmt.on_audio(0, (char*)raw, sizeof(raw)));
EXPECT_TRUE(srs_success == enc.write_sample(
SrsMp4HandlerTypeSOUN, 0x00, 34, 34, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw
));
}
if (true) {
uint8_t raw[] = {
0x27,
0x01, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x7b, 0x41, 0x9a, 0x21, 0x6c, 0x42, 0x1f, 0x00, 0x00,
0xf1, 0x68, 0x1a, 0x35, 0x84, 0xb3, 0xee, 0xe0, 0x61, 0xba, 0x4e, 0xa8, 0x52, 0x48, 0x50, 0x59,
0x75, 0x42, 0xd9, 0x96, 0x4a, 0x51, 0x38, 0x2c, 0x63, 0x5e, 0x41, 0xc9, 0x70, 0x60, 0x9d, 0x13,
0x53, 0xc2, 0xa8, 0xf5, 0x45, 0x86, 0xc5, 0x3e, 0x28, 0x1a, 0x69, 0x5f, 0x71, 0x1e, 0x51, 0x74,
0x0e, 0x31, 0x47, 0x3c, 0xd3, 0xd2, 0x10, 0x25, 0x45, 0xc5, 0xb7, 0x31, 0xec, 0x7f, 0xd8, 0x02,
0xae, 0xa4, 0x77, 0x6d, 0xcb, 0xc6, 0x1e, 0x2f, 0xa2, 0xd1, 0x12, 0x08, 0x34, 0x52, 0xea, 0xe8,
0x0b, 0x4f, 0x81, 0x21, 0x4f, 0x71, 0x3f, 0xf2, 0xad, 0x02, 0x58, 0xdf, 0x9e, 0x31, 0x86, 0x9b,
0x1b, 0x41, 0xbf, 0x2a, 0x09, 0x00, 0x43, 0x5c, 0xa1, 0x7e, 0x76, 0x59, 0xef, 0xa6, 0xfc, 0x82,
0xb2, 0x72, 0x5a
};
EXPECT_TRUE(srs_success == fmt.on_video(0, (char*)raw, sizeof(raw)));
EXPECT_TRUE(srs_success == enc.write_sample(
SrsMp4HandlerTypeVIDE, fmt.video->frame_type, 40, 40, mock_copy_bytes(fmt.raw, fmt.nb_raw), fmt.nb_raw
));
}
uint64_t dts = 0;
EXPECT_TRUE(srs_success == enc.flush(dts));
}

View file

@ -61,9 +61,11 @@ public:
virtual void close();
public:
virtual bool is_open();
virtual void seek2(int64_t offset);
virtual int64_t tellg();
public:
virtual srs_error_t write(void* buf, size_t count, ssize_t* pnwrite);
virtual srs_error_t lseek(off_t offset, int whence, off_t* seeked);
// for mock
public:
void mock_reset_offset();