mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
finish utest of protocol stack. 0.9.156
This commit is contained in:
parent
8e27df4cf7
commit
9556790a5e
14 changed files with 730 additions and 45 deletions
|
@ -132,7 +132,7 @@ SrsAvcAacCodec::~SrsAvcAacCodec()
|
||||||
srs_freep(pictureParameterSetNALUnit);
|
srs_freep(pictureParameterSetNALUnit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsAvcAacCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample)
|
int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ int SrsAvcAacCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* samp
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsAvcAacCodec::video_avc_demux(int8_t* data, int size, SrsCodecSample* sample)
|
int SrsAvcAacCodec::video_avc_demux(char* data, int size, SrsCodecSample* sample)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
|
|
@ -197,8 +197,8 @@ public:
|
||||||
virtual ~SrsAvcAacCodec();
|
virtual ~SrsAvcAacCodec();
|
||||||
// the following function used for hls to build the codec info.
|
// the following function used for hls to build the codec info.
|
||||||
public:
|
public:
|
||||||
virtual int audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample);
|
virtual int audio_aac_demux(char* data, int size, SrsCodecSample* sample);
|
||||||
virtual int video_avc_demux(int8_t* data, int size, SrsCodecSample* sample);
|
virtual int video_avc_demux(char* data, int size, SrsCodecSample* sample);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -240,9 +240,9 @@ int SrsDvrPlan::on_video(SrsSharedPtrMessage* video)
|
||||||
int size = (int)video->size;
|
int size = (int)video->size;
|
||||||
|
|
||||||
#ifdef SRS_AUTO_HTTP_CALLBACK
|
#ifdef SRS_AUTO_HTTP_CALLBACK
|
||||||
bool is_key_frame = SrsFlvCodec::video_is_h264((int8_t*)payload, size)
|
bool is_key_frame = SrsFlvCodec::video_is_h264(payload, size)
|
||||||
&& SrsFlvCodec::video_is_keyframe((int8_t*)payload, size)
|
&& SrsFlvCodec::video_is_keyframe(payload, size)
|
||||||
&& !SrsFlvCodec::video_is_sequence_header((int8_t*)payload, size);
|
&& !SrsFlvCodec::video_is_sequence_header(payload, size);
|
||||||
if (is_key_frame) {
|
if (is_key_frame) {
|
||||||
segment->has_keyframe = true;
|
segment->has_keyframe = true;
|
||||||
if ((ret = on_video_keyframe()) != ERROR_SUCCESS) {
|
if ((ret = on_video_keyframe()) != ERROR_SUCCESS) {
|
||||||
|
|
|
@ -1294,8 +1294,8 @@ int SrsSource::on_aggregate(SrsMessage* msg)
|
||||||
|
|
||||||
if (data_size > 0) {
|
if (data_size > 0) {
|
||||||
o.size = data_size;
|
o.size = data_size;
|
||||||
o.payload = new int8_t[o.size];
|
o.payload = new char[o.size];
|
||||||
stream->read_bytes((char*)o.payload, o.size);
|
stream->read_bytes(o.payload, o.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!stream->require(4)) {
|
if (!stream->require(4)) {
|
||||||
|
|
|
@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// current release version
|
// current release version
|
||||||
#define VERSION_MAJOR "0"
|
#define VERSION_MAJOR "0"
|
||||||
#define VERSION_MINOR "9"
|
#define VERSION_MINOR "9"
|
||||||
#define VERSION_REVISION "155"
|
#define VERSION_REVISION "156"
|
||||||
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
|
#define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
|
||||||
// server info.
|
// server info.
|
||||||
#define RTMP_SIG_SRS_KEY "SRS"
|
#define RTMP_SIG_SRS_KEY "SRS"
|
||||||
|
|
|
@ -39,7 +39,7 @@ SrsFlvCodec::~SrsFlvCodec()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsFlvCodec::video_is_keyframe(int8_t* data, int size)
|
bool SrsFlvCodec::video_is_keyframe(char* data, int size)
|
||||||
{
|
{
|
||||||
// 2bytes required.
|
// 2bytes required.
|
||||||
if (size < 1) {
|
if (size < 1) {
|
||||||
|
@ -52,7 +52,7 @@ bool SrsFlvCodec::video_is_keyframe(int8_t* data, int size)
|
||||||
return frame_type == SrsCodecVideoAVCFrameKeyFrame;
|
return frame_type == SrsCodecVideoAVCFrameKeyFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsFlvCodec::video_is_sequence_header(int8_t* data, int size)
|
bool SrsFlvCodec::video_is_sequence_header(char* data, int size)
|
||||||
{
|
{
|
||||||
// sequence header only for h264
|
// sequence header only for h264
|
||||||
if (!video_is_h264(data, size)) {
|
if (!video_is_h264(data, size)) {
|
||||||
|
@ -73,7 +73,7 @@ bool SrsFlvCodec::video_is_sequence_header(int8_t* data, int size)
|
||||||
&& avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader;
|
&& avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsFlvCodec::audio_is_sequence_header(int8_t* data, int size)
|
bool SrsFlvCodec::audio_is_sequence_header(char* data, int size)
|
||||||
{
|
{
|
||||||
// sequence header only for aac
|
// sequence header only for aac
|
||||||
if (!audio_is_aac(data, size)) {
|
if (!audio_is_aac(data, size)) {
|
||||||
|
@ -90,7 +90,7 @@ bool SrsFlvCodec::audio_is_sequence_header(int8_t* data, int size)
|
||||||
return aac_packet_type == SrsCodecAudioTypeSequenceHeader;
|
return aac_packet_type == SrsCodecAudioTypeSequenceHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsFlvCodec::video_is_h264(int8_t* data, int size)
|
bool SrsFlvCodec::video_is_h264(char* data, int size)
|
||||||
{
|
{
|
||||||
// 1bytes required.
|
// 1bytes required.
|
||||||
if (size < 1) {
|
if (size < 1) {
|
||||||
|
@ -103,7 +103,7 @@ bool SrsFlvCodec::video_is_h264(int8_t* data, int size)
|
||||||
return codec_id == SrsCodecVideoAVC;
|
return codec_id == SrsCodecVideoAVC;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsFlvCodec::audio_is_aac(int8_t* data, int size)
|
bool SrsFlvCodec::audio_is_aac(char* data, int size)
|
||||||
{
|
{
|
||||||
// 1bytes required.
|
// 1bytes required.
|
||||||
if (size < 1) {
|
if (size < 1) {
|
||||||
|
|
|
@ -158,23 +158,23 @@ public:
|
||||||
/**
|
/**
|
||||||
* only check the frame_type, not check the codec type.
|
* only check the frame_type, not check the codec type.
|
||||||
*/
|
*/
|
||||||
static bool video_is_keyframe(int8_t* data, int size);
|
static bool video_is_keyframe(char* data, int size);
|
||||||
/**
|
/**
|
||||||
* check codec h264, keyframe, sequence header
|
* check codec h264, keyframe, sequence header
|
||||||
*/
|
*/
|
||||||
static bool video_is_sequence_header(int8_t* data, int size);
|
static bool video_is_sequence_header(char* data, int size);
|
||||||
/**
|
/**
|
||||||
* check codec aac, sequence header
|
* check codec aac, sequence header
|
||||||
*/
|
*/
|
||||||
static bool audio_is_sequence_header(int8_t* data, int size);
|
static bool audio_is_sequence_header(char* data, int size);
|
||||||
/**
|
/**
|
||||||
* check codec h264.
|
* check codec h264.
|
||||||
*/
|
*/
|
||||||
static bool video_is_h264(int8_t* data, int size);
|
static bool video_is_h264(char* data, int size);
|
||||||
/**
|
/**
|
||||||
* check codec aac.
|
* check codec aac.
|
||||||
*/
|
*/
|
||||||
static bool audio_is_aac(int8_t* data, int size);
|
static bool audio_is_aac(char* data, int size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -635,12 +635,12 @@ flv_bool srs_flv_is_eof(int error_code)
|
||||||
|
|
||||||
flv_bool srs_flv_is_sequence_header(char* data, int32_t size)
|
flv_bool srs_flv_is_sequence_header(char* data, int32_t size)
|
||||||
{
|
{
|
||||||
return SrsFlvCodec::video_is_sequence_header((int8_t*)data, (int)size);
|
return SrsFlvCodec::video_is_sequence_header(data, (int)size);
|
||||||
}
|
}
|
||||||
|
|
||||||
flv_bool srs_flv_is_keyframe(char* data, int32_t size)
|
flv_bool srs_flv_is_keyframe(char* data, int32_t size)
|
||||||
{
|
{
|
||||||
return SrsFlvCodec::video_is_keyframe((int8_t*)data, (int)size);
|
return SrsFlvCodec::video_is_keyframe(data, (int)size);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_amf0_t srs_amf0_parse(char* data, int size, int* nparsed)
|
srs_amf0_t srs_amf0_parse(char* data, int size, int* nparsed)
|
||||||
|
|
|
@ -764,8 +764,8 @@ int SrsProtocol::send_and_free_packet(SrsPacket* packet, int stream_id)
|
||||||
// to message
|
// to message
|
||||||
SrsMessage* msg = new SrsCommonMessage();
|
SrsMessage* msg = new SrsCommonMessage();
|
||||||
|
|
||||||
msg->payload = (int8_t*)payload;
|
msg->payload = payload;
|
||||||
msg->size = (int32_t)size;
|
msg->size = size;
|
||||||
|
|
||||||
msg->header.payload_length = size;
|
msg->header.payload_length = size;
|
||||||
msg->header.message_type = packet->get_message_type();
|
msg->header.message_type = packet->get_message_type();
|
||||||
|
@ -1297,7 +1297,7 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, int bh_size, int mh
|
||||||
|
|
||||||
// create msg payload if not initialized
|
// create msg payload if not initialized
|
||||||
if (!chunk->msg->payload) {
|
if (!chunk->msg->payload) {
|
||||||
chunk->msg->payload = new int8_t[chunk->header.payload_length];
|
chunk->msg->payload = new char[chunk->header.payload_length];
|
||||||
memset(chunk->msg->payload, 0, chunk->header.payload_length);
|
memset(chunk->msg->payload, 0, chunk->header.payload_length);
|
||||||
srs_verbose("create empty payload for RTMP message. size=%d", chunk->header.payload_length);
|
srs_verbose("create empty payload for RTMP message. size=%d", chunk->header.payload_length);
|
||||||
}
|
}
|
||||||
|
@ -1708,7 +1708,7 @@ int SrsSharedPtrMessage::create(SrsMessageHeader* pheader, char* payload, int si
|
||||||
ptr->size = size;
|
ptr->size = size;
|
||||||
|
|
||||||
// message can access it.
|
// message can access it.
|
||||||
SrsMessage::payload = (int8_t*)ptr->payload;
|
SrsMessage::payload = ptr->payload;
|
||||||
SrsMessage::size = ptr->size;
|
SrsMessage::size = ptr->size;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1731,7 +1731,7 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy()
|
||||||
copy->ptr = ptr;
|
copy->ptr = ptr;
|
||||||
ptr->shared_count++;
|
ptr->shared_count++;
|
||||||
|
|
||||||
copy->payload = (int8_t*)ptr->payload;
|
copy->payload = ptr->payload;
|
||||||
copy->size = ptr->size;
|
copy->size = ptr->size;
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
|
@ -3708,7 +3708,7 @@ int SrsSetChunkSizePacket::encode_packet(SrsStream* stream)
|
||||||
SrsSetPeerBandwidthPacket::SrsSetPeerBandwidthPacket()
|
SrsSetPeerBandwidthPacket::SrsSetPeerBandwidthPacket()
|
||||||
{
|
{
|
||||||
bandwidth = 0;
|
bandwidth = 0;
|
||||||
type = 2;
|
type = SrsPeerBandwidthDynamic;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSetPeerBandwidthPacket::~SrsSetPeerBandwidthPacket()
|
SrsSetPeerBandwidthPacket::~SrsSetPeerBandwidthPacket()
|
||||||
|
@ -3824,7 +3824,7 @@ int SrsUserControlPacket::encode_packet(SrsStream* stream)
|
||||||
// when event type is set buffer length,
|
// when event type is set buffer length,
|
||||||
// write the extra buffer length.
|
// write the extra buffer length.
|
||||||
if (event_type == SrcPCUCSetBufferLength) {
|
if (event_type == SrcPCUCSetBufferLength) {
|
||||||
stream->write_2bytes(extra_data);
|
stream->write_4bytes(extra_data);
|
||||||
srs_verbose("user control message, buffer_length=%d", extra_data);
|
srs_verbose("user control message, buffer_length=%d", extra_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -388,14 +388,14 @@ public:
|
||||||
* size <= header.payload_length
|
* size <= header.payload_length
|
||||||
* for the payload maybe sent in multiple chunks.
|
* for the payload maybe sent in multiple chunks.
|
||||||
*/
|
*/
|
||||||
int32_t size;
|
int size;
|
||||||
/**
|
/**
|
||||||
* the payload of message, the SrsMessage never know about the detail of payload,
|
* the payload of message, the SrsMessage never know about the detail of payload,
|
||||||
* user must use SrsProtocol.decode_message to get concrete packet.
|
* user must use SrsProtocol.decode_message to get concrete packet.
|
||||||
* @remark, not all message payload can be decoded to packet. for example,
|
* @remark, not all message payload can be decoded to packet. for example,
|
||||||
* video/audio packet use raw bytes, no video/audio packet.
|
* video/audio packet use raw bytes, no video/audio packet.
|
||||||
*/
|
*/
|
||||||
int8_t* payload;
|
char* payload;
|
||||||
protected:
|
protected:
|
||||||
SrsMessage();
|
SrsMessage();
|
||||||
public:
|
public:
|
||||||
|
@ -1023,6 +1023,7 @@ protected:
|
||||||
virtual int get_size();
|
virtual int get_size();
|
||||||
virtual int encode_packet(SrsStream* stream);
|
virtual int encode_packet(SrsStream* stream);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* response for SrsPlayPacket.
|
* response for SrsPlayPacket.
|
||||||
* @remark, user must set the stream_id in header.
|
* @remark, user must set the stream_id in header.
|
||||||
|
@ -1352,6 +1353,16 @@ protected:
|
||||||
virtual int encode_packet(SrsStream* stream);
|
virtual int encode_packet(SrsStream* stream);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 5.6. Set Peer Bandwidth (6)
|
||||||
|
enum SrsPeerBandwidthType
|
||||||
|
{
|
||||||
|
// The sender can mark this message hard (0), soft (1), or dynamic (2)
|
||||||
|
// using the Limit type field.
|
||||||
|
SrsPeerBandwidthHard = 0,
|
||||||
|
SrsPeerBandwidthSoft = 1,
|
||||||
|
SrsPeerBandwidthDynamic = 2,
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 5.6. Set Peer Bandwidth (6)
|
* 5.6. Set Peer Bandwidth (6)
|
||||||
* The client or the server sends this message to update the output
|
* The client or the server sends this message to update the output
|
||||||
|
@ -1361,6 +1372,7 @@ class SrsSetPeerBandwidthPacket : public SrsPacket
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int32_t bandwidth;
|
int32_t bandwidth;
|
||||||
|
// @see: SrsPeerBandwidthType
|
||||||
int8_t type;
|
int8_t type;
|
||||||
public:
|
public:
|
||||||
SrsSetPeerBandwidthPacket();
|
SrsSetPeerBandwidthPacket();
|
||||||
|
|
|
@ -36,6 +36,15 @@ ISrsThreadContext* _srs_context = new ISrsThreadContext();
|
||||||
SrsConfig* _srs_config = NULL;
|
SrsConfig* _srs_config = NULL;
|
||||||
SrsServer* _srs_server = NULL;
|
SrsServer* _srs_server = NULL;
|
||||||
|
|
||||||
|
void __srs_bytes_print(char* pa, int size)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < size; i++) {
|
||||||
|
char v = pa[i];
|
||||||
|
printf("%#x ", v);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
// basic test and samples.
|
// basic test and samples.
|
||||||
VOID TEST(SampleTest, FastSampleInt64Test)
|
VOID TEST(SampleTest, FastSampleInt64Test)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,4 +49,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual): Tests that two double values are almost equal.
|
// * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual): Tests that two double values are almost equal.
|
||||||
// * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error): Tests that v1 and v2 are within the given distance to each other.
|
// * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error): Tests that v1 and v2 are within the given distance to each other.
|
||||||
|
|
||||||
|
// print the bytes.
|
||||||
|
void __srs_bytes_print(char* pa, int size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -287,7 +287,7 @@ VOID TEST(KernelBufferTest, Grow)
|
||||||
*/
|
*/
|
||||||
VOID TEST(KernelCodecTest, IsKeyFrame)
|
VOID TEST(KernelCodecTest, IsKeyFrame)
|
||||||
{
|
{
|
||||||
int8_t data;
|
char data;
|
||||||
|
|
||||||
data = 0x10;
|
data = 0x10;
|
||||||
EXPECT_TRUE(SrsFlvCodec::video_is_keyframe(&data, 1));
|
EXPECT_TRUE(SrsFlvCodec::video_is_keyframe(&data, 1));
|
||||||
|
@ -303,7 +303,7 @@ VOID TEST(KernelCodecTest, IsKeyFrame)
|
||||||
*/
|
*/
|
||||||
VOID TEST(KernelCodecTest, IsH264)
|
VOID TEST(KernelCodecTest, IsH264)
|
||||||
{
|
{
|
||||||
int8_t data;
|
char data;
|
||||||
|
|
||||||
EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 0));
|
EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 0));
|
||||||
|
|
||||||
|
@ -326,19 +326,19 @@ VOID TEST(KernelCodecTest, IsSequenceHeader)
|
||||||
int16_t data;
|
int16_t data;
|
||||||
char* pp = (char*)&data;
|
char* pp = (char*)&data;
|
||||||
|
|
||||||
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 0));
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 0));
|
||||||
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 1));
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 1));
|
||||||
|
|
||||||
pp[0] = 0x17;
|
pp[0] = 0x17;
|
||||||
pp[1] = 0x00;
|
pp[1] = 0x00;
|
||||||
EXPECT_TRUE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
|
EXPECT_TRUE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2));
|
||||||
pp[0] = 0x18;
|
pp[0] = 0x18;
|
||||||
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2));
|
||||||
pp[0] = 0x27;
|
pp[0] = 0x27;
|
||||||
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2));
|
||||||
pp[0] = 0x17;
|
pp[0] = 0x17;
|
||||||
pp[1] = 0x01;
|
pp[1] = 0x01;
|
||||||
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -347,7 +347,7 @@ VOID TEST(KernelCodecTest, IsSequenceHeader)
|
||||||
*/
|
*/
|
||||||
VOID TEST(KernelCodecTest, IsAAC)
|
VOID TEST(KernelCodecTest, IsAAC)
|
||||||
{
|
{
|
||||||
int8_t data;
|
char data;
|
||||||
|
|
||||||
EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 0));
|
EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 0));
|
||||||
|
|
||||||
|
@ -370,17 +370,17 @@ VOID TEST(KernelCodecTest, IsAudioSequenceHeader)
|
||||||
int16_t data;
|
int16_t data;
|
||||||
char* pp = (char*)&data;
|
char* pp = (char*)&data;
|
||||||
|
|
||||||
EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 0));
|
EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((char*)pp, 0));
|
||||||
EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 1));
|
EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((char*)pp, 1));
|
||||||
|
|
||||||
pp[0] = 0xa0;
|
pp[0] = 0xa0;
|
||||||
pp[1] = 0x00;
|
pp[1] = 0x00;
|
||||||
EXPECT_TRUE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 2));
|
EXPECT_TRUE(SrsFlvCodec::audio_is_sequence_header((char*)pp, 2));
|
||||||
pp[0] = 0x00;
|
pp[0] = 0x00;
|
||||||
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2));
|
||||||
pp[0] = 0xa0;
|
pp[0] = 0xa0;
|
||||||
pp[1] = 0x01;
|
pp[1] = 0x01;
|
||||||
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2));
|
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,6 +31,7 @@ using namespace std;
|
||||||
#include <srs_protocol_rtmp_stack.hpp>
|
#include <srs_protocol_rtmp_stack.hpp>
|
||||||
#include <srs_kernel_utility.hpp>
|
#include <srs_kernel_utility.hpp>
|
||||||
#include <srs_app_st.hpp>
|
#include <srs_app_st.hpp>
|
||||||
|
#include <srs_protocol_amf0.hpp>
|
||||||
|
|
||||||
MockEmptyIO::MockEmptyIO()
|
MockEmptyIO::MockEmptyIO()
|
||||||
{
|
{
|
||||||
|
@ -4463,3 +4464,663 @@ VOID TEST(ProtocolStackTest, ProtocolRecvV0LenMessage)
|
||||||
EXPECT_EQ(4, msg->header.payload_length);
|
EXPECT_EQ(4, msg->header.payload_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a video message
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendVMessage)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
char data[] = {0x01, 0x02, 0x03, 0x04};
|
||||||
|
|
||||||
|
SrsMessage* msg = new SrsCommonMessage();
|
||||||
|
msg->size = sizeof(data);
|
||||||
|
msg->payload = new char[msg->size];
|
||||||
|
memcpy(msg->payload, data, msg->size);
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_message(msg, 0));
|
||||||
|
EXPECT_EQ(16, bio.out_buffer.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsConnectAppPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsConnectAppPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsConnectAppPacket* pkt = new SrsConnectAppPacket();
|
||||||
|
pkt->command_object = SrsAmf0Any::object();
|
||||||
|
pkt->args = SrsAmf0Any::object();
|
||||||
|
|
||||||
|
pkt->command_object->set("version", SrsAmf0Any::str("1.0.0"));
|
||||||
|
pkt->command_object->set("build", SrsAmf0Any::number(150));
|
||||||
|
SrsAmf0Object* data = SrsAmf0Any::object();
|
||||||
|
pkt->command_object->set("data", data);
|
||||||
|
|
||||||
|
data->set("server", SrsAmf0Any::str("SRS"));
|
||||||
|
data->set("signature", SrsAmf0Any::str("simple-rtmp-server"));
|
||||||
|
|
||||||
|
pkt->args->set("info", SrsAmf0Any::str("NetStream.Status.Info"));
|
||||||
|
pkt->args->set("desc", SrsAmf0Any::str("connected"));
|
||||||
|
pkt->args->set("data", SrsAmf0Any::ecma_array());
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0xb2, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x07, (char)0x63,
|
||||||
|
(char)0x6f, (char)0x6e, (char)0x6e, (char)0x65, (char)0x63, (char)0x74, (char)0x00, (char)0x3f,
|
||||||
|
(char)0xf0, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x03,
|
||||||
|
(char)0x00, (char)0x07, (char)0x76, (char)0x65, (char)0x72, (char)0x73, (char)0x69, (char)0x6f,
|
||||||
|
(char)0x6e, (char)0x02, (char)0x00, (char)0x05, (char)0x31, (char)0x2e, (char)0x30, (char)0x2e,
|
||||||
|
(char)0x30, (char)0x00, (char)0x05, (char)0x62, (char)0x75, (char)0x69, (char)0x6c, (char)0x64,
|
||||||
|
(char)0x00, (char)0x40, (char)0x62, (char)0xc0, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x04, (char)0x64, (char)0x61, (char)0x74, (char)0x61, (char)0x03,
|
||||||
|
(char)0x00, (char)0x06, (char)0x73, (char)0x65, (char)0x72, (char)0x76, (char)0x65, (char)0x72,
|
||||||
|
(char)0x02, (char)0x00, (char)0x03, (char)0x53, (char)0x52, (char)0x53, (char)0x00, (char)0x09,
|
||||||
|
(char)0x73, (char)0x69, (char)0x67, (char)0x6e, (char)0x61, (char)0x74, (char)0x75, (char)0x72,
|
||||||
|
(char)0x65, (char)0x02, (char)0x00, (char)0x12, (char)0x73, (char)0x69, (char)0x6d, (char)0x70,
|
||||||
|
(char)0x6c, (char)0x65, (char)0x2d, (char)0x72, (char)0x74, (char)0x6d, (char)0x70, (char)0x2d,
|
||||||
|
(char)0x73, (char)0x65, (char)0x72, (char)0x76, (char)0x65, (char)0x72, (char)0x00, (char)0x00,
|
||||||
|
(char)0x09, (char)0x00, (char)0x00, (char)0x09, (char)0x03, (char)0x00, (char)0x04, (char)0x69,
|
||||||
|
(char)0x6e, (char)0x66, (char)0x6f, (char)0x02, (char)0x00, (char)0x15, (char)0x4e, (char)0x65,
|
||||||
|
(char)0x74, (char)0x53, (char)0x74, (char)0x72, (char)0xc3, (char)0x65, (char)0x61, (char)0x6d,
|
||||||
|
(char)0x2e, (char)0x53, (char)0x74, (char)0x61, (char)0x74, (char)0x75, (char)0x73, (char)0x2e,
|
||||||
|
(char)0x49, (char)0x6e, (char)0x66, (char)0x6f, (char)0x00, (char)0x04, (char)0x64, (char)0x65,
|
||||||
|
(char)0x73, (char)0x63, (char)0x02, (char)0x00, (char)0x09, (char)0x63, (char)0x6f, (char)0x6e,
|
||||||
|
(char)0x6e, (char)0x65, (char)0x63, (char)0x74, (char)0x65, (char)0x64, (char)0x00, (char)0x04,
|
||||||
|
(char)0x64, (char)0x61, (char)0x74, (char)0x61, (char)0x08, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x09, (char)0x00, (char)0x00, (char)0x09
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsConnectAppResPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsConnectAppResPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsConnectAppResPacket* pkt = new SrsConnectAppResPacket();
|
||||||
|
pkt->props = SrsAmf0Any::object();
|
||||||
|
pkt->info = SrsAmf0Any::object();
|
||||||
|
|
||||||
|
pkt->props->set("version", SrsAmf0Any::str("1.0.0"));
|
||||||
|
pkt->props->set("build", SrsAmf0Any::number(150));
|
||||||
|
SrsAmf0Object* data = SrsAmf0Any::object();
|
||||||
|
pkt->props->set("data", data);
|
||||||
|
|
||||||
|
data->set("server", SrsAmf0Any::str("SRS"));
|
||||||
|
data->set("signature", SrsAmf0Any::str("simple-rtmp-server"));
|
||||||
|
|
||||||
|
pkt->info->set("info", SrsAmf0Any::str("NetStream.Status.Info"));
|
||||||
|
pkt->info->set("desc", SrsAmf0Any::str("connected"));
|
||||||
|
pkt->info->set("data", SrsAmf0Any::ecma_array());
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0xb2, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x07, (char)0x5f,
|
||||||
|
(char)0x72, (char)0x65, (char)0x73, (char)0x75, (char)0x6c, (char)0x74, (char)0x00, (char)0x3f,
|
||||||
|
(char)0xf0, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x03,
|
||||||
|
(char)0x00, (char)0x07, (char)0x76, (char)0x65, (char)0x72, (char)0x73, (char)0x69, (char)0x6f,
|
||||||
|
(char)0x6e, (char)0x02, (char)0x00, (char)0x05, (char)0x31, (char)0x2e, (char)0x30, (char)0x2e,
|
||||||
|
(char)0x30, (char)0x00, (char)0x05, (char)0x62, (char)0x75, (char)0x69, (char)0x6c, (char)0x64,
|
||||||
|
(char)0x00, (char)0x40, (char)0x62, (char)0xc0, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x04, (char)0x64, (char)0x61, (char)0x74, (char)0x61, (char)0x03,
|
||||||
|
(char)0x00, (char)0x06, (char)0x73, (char)0x65, (char)0x72, (char)0x76, (char)0x65, (char)0x72,
|
||||||
|
(char)0x02, (char)0x00, (char)0x03, (char)0x53, (char)0x52, (char)0x53, (char)0x00, (char)0x09,
|
||||||
|
(char)0x73, (char)0x69, (char)0x67, (char)0x6e, (char)0x61, (char)0x74, (char)0x75, (char)0x72,
|
||||||
|
(char)0x65, (char)0x02, (char)0x00, (char)0x12, (char)0x73, (char)0x69, (char)0x6d, (char)0x70,
|
||||||
|
(char)0x6c, (char)0x65, (char)0x2d, (char)0x72, (char)0x74, (char)0x6d, (char)0x70, (char)0x2d,
|
||||||
|
(char)0x73, (char)0x65, (char)0x72, (char)0x76, (char)0x65, (char)0x72, (char)0x00, (char)0x00,
|
||||||
|
(char)0x09, (char)0x00, (char)0x00, (char)0x09, (char)0x03, (char)0x00, (char)0x04, (char)0x69,
|
||||||
|
(char)0x6e, (char)0x66, (char)0x6f, (char)0x02, (char)0x00, (char)0x15, (char)0x4e, (char)0x65,
|
||||||
|
(char)0x74, (char)0x53, (char)0x74, (char)0x72, (char)0xc3, (char)0x65, (char)0x61, (char)0x6d,
|
||||||
|
(char)0x2e, (char)0x53, (char)0x74, (char)0x61, (char)0x74, (char)0x75, (char)0x73, (char)0x2e,
|
||||||
|
(char)0x49, (char)0x6e, (char)0x66, (char)0x6f, (char)0x00, (char)0x04, (char)0x64, (char)0x65,
|
||||||
|
(char)0x73, (char)0x63, (char)0x02, (char)0x00, (char)0x09, (char)0x63, (char)0x6f, (char)0x6e,
|
||||||
|
(char)0x6e, (char)0x65, (char)0x63, (char)0x74, (char)0x65, (char)0x64, (char)0x00, (char)0x04,
|
||||||
|
(char)0x64, (char)0x61, (char)0x74, (char)0x61, (char)0x08, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x09, (char)0x00, (char)0x00, (char)0x09
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsCallPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsCallPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsAmf0Object* args = SrsAmf0Any::object();
|
||||||
|
|
||||||
|
SrsCallPacket* pkt = new SrsCallPacket();
|
||||||
|
pkt->command_name = "my_call";
|
||||||
|
pkt->command_object = SrsAmf0Any::null();
|
||||||
|
pkt->arguments = args;
|
||||||
|
|
||||||
|
args->set("video_id", SrsAmf0Any::number(100));
|
||||||
|
args->set("url", SrsAmf0Any::str("http://ossrs.net/api/v1/videos/100"));
|
||||||
|
args->set("date", SrsAmf0Any::str("2014-07-11 16:20:10.2984"));
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x76, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x07, (char)0x6d,
|
||||||
|
(char)0x79, (char)0x5f, (char)0x63, (char)0x61, (char)0x6c, (char)0x6c, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05,
|
||||||
|
(char)0x03, (char)0x00, (char)0x08, (char)0x76, (char)0x69, (char)0x64, (char)0x65, (char)0x6f,
|
||||||
|
(char)0x5f, (char)0x69, (char)0x64, (char)0x00, (char)0x40, (char)0x59, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x03, (char)0x75, (char)0x72,
|
||||||
|
(char)0x6c, (char)0x02, (char)0x00, (char)0x22, (char)0x68, (char)0x74, (char)0x74, (char)0x70,
|
||||||
|
(char)0x3a, (char)0x2f, (char)0x2f, (char)0x6f, (char)0x73, (char)0x73, (char)0x72, (char)0x73,
|
||||||
|
(char)0x2e, (char)0x6e, (char)0x65, (char)0x74, (char)0x2f, (char)0x61, (char)0x70, (char)0x69,
|
||||||
|
(char)0x2f, (char)0x76, (char)0x31, (char)0x2f, (char)0x76, (char)0x69, (char)0x64, (char)0x65,
|
||||||
|
(char)0x6f, (char)0x73, (char)0x2f, (char)0x31, (char)0x30, (char)0x30, (char)0x00, (char)0x04,
|
||||||
|
(char)0x64, (char)0x61, (char)0x74, (char)0x65, (char)0x02, (char)0x00, (char)0x18, (char)0x32,
|
||||||
|
(char)0x30, (char)0x31, (char)0x34, (char)0x2d, (char)0x30, (char)0x37, (char)0x2d, (char)0x31,
|
||||||
|
(char)0x31, (char)0x20, (char)0x31, (char)0x36, (char)0x3a, (char)0x32, (char)0x30, (char)0x3a,
|
||||||
|
(char)0x31, (char)0x30, (char)0x2e, (char)0x32, (char)0x39, (char)0x38, (char)0x34, (char)0x00,
|
||||||
|
(char)0x00, (char)0x09
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsCallResPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsCallResPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsAmf0Object* args = SrsAmf0Any::object();
|
||||||
|
|
||||||
|
SrsCallResPacket* pkt = new SrsCallResPacket(0);
|
||||||
|
pkt->command_name = "_result";
|
||||||
|
pkt->command_object = SrsAmf0Any::null();
|
||||||
|
pkt->response = args;
|
||||||
|
|
||||||
|
args->set("video_id", SrsAmf0Any::number(100));
|
||||||
|
args->set("url", SrsAmf0Any::str("http://ossrs.net/api/v1/videos/100"));
|
||||||
|
args->set("date", SrsAmf0Any::str("2014-07-11 16:20:10.2984"));
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x76, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x07, (char)0x5f,
|
||||||
|
(char)0x72, (char)0x65, (char)0x73, (char)0x75, (char)0x6c, (char)0x74, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05,
|
||||||
|
(char)0x03, (char)0x00, (char)0x08, (char)0x76, (char)0x69, (char)0x64, (char)0x65, (char)0x6f,
|
||||||
|
(char)0x5f, (char)0x69, (char)0x64, (char)0x00, (char)0x40, (char)0x59, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x03, (char)0x75, (char)0x72,
|
||||||
|
(char)0x6c, (char)0x02, (char)0x00, (char)0x22, (char)0x68, (char)0x74, (char)0x74, (char)0x70,
|
||||||
|
(char)0x3a, (char)0x2f, (char)0x2f, (char)0x6f, (char)0x73, (char)0x73, (char)0x72, (char)0x73,
|
||||||
|
(char)0x2e, (char)0x6e, (char)0x65, (char)0x74, (char)0x2f, (char)0x61, (char)0x70, (char)0x69,
|
||||||
|
(char)0x2f, (char)0x76, (char)0x31, (char)0x2f, (char)0x76, (char)0x69, (char)0x64, (char)0x65,
|
||||||
|
(char)0x6f, (char)0x73, (char)0x2f, (char)0x31, (char)0x30, (char)0x30, (char)0x00, (char)0x04,
|
||||||
|
(char)0x64, (char)0x61, (char)0x74, (char)0x65, (char)0x02, (char)0x00, (char)0x18, (char)0x32,
|
||||||
|
(char)0x30, (char)0x31, (char)0x34, (char)0x2d, (char)0x30, (char)0x37, (char)0x2d, (char)0x31,
|
||||||
|
(char)0x31, (char)0x20, (char)0x31, (char)0x36, (char)0x3a, (char)0x32, (char)0x30, (char)0x3a,
|
||||||
|
(char)0x31, (char)0x30, (char)0x2e, (char)0x32, (char)0x39, (char)0x38, (char)0x34, (char)0x00,
|
||||||
|
(char)0x00, (char)0x09
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsCreateStreamPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsCreateStreamPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsCreateStreamPacket* pkt = new SrsCreateStreamPacket();
|
||||||
|
pkt->command_object = SrsAmf0Any::null();
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x19, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x0c, (char)0x63,
|
||||||
|
(char)0x72, (char)0x65, (char)0x61, (char)0x74, (char)0x65, (char)0x53, (char)0x74, (char)0x72,
|
||||||
|
(char)0x65, (char)0x61, (char)0x6d, (char)0x00, (char)0x40, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsFMLEStartPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsFMLEStartPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsFMLEStartPacket* pkt = new SrsFMLEStartPacket();
|
||||||
|
pkt->command_name = "FMLEStart";
|
||||||
|
pkt->command_object = SrsAmf0Any::null();
|
||||||
|
pkt->stream_name = "livestream";
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x23, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x09, (char)0x46,
|
||||||
|
(char)0x4d, (char)0x4c, (char)0x45, (char)0x53, (char)0x74, (char)0x61, (char)0x72, (char)0x74,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x05, (char)0x02, (char)0x00, (char)0x0a, (char)0x6c, (char)0x69, (char)0x76,
|
||||||
|
(char)0x65, (char)0x73, (char)0x74, (char)0x72, (char)0x65, (char)0x61, (char)0x6d
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsFMLEStartResPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsFMLEStartResPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsAmf0Object* args = SrsAmf0Any::object();
|
||||||
|
|
||||||
|
SrsFMLEStartResPacket* pkt = new SrsFMLEStartResPacket(1);
|
||||||
|
pkt->command_name = "FMLEStart";
|
||||||
|
pkt->command_object = SrsAmf0Any::null();
|
||||||
|
pkt->args = args;
|
||||||
|
|
||||||
|
args->set("stream" , SrsAmf0Any::str("livestream"));
|
||||||
|
args->set("start" , SrsAmf0Any::number(0));
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x17, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x09, (char)0x46,
|
||||||
|
(char)0x4d, (char)0x4c, (char)0x45, (char)0x53, (char)0x74, (char)0x61, (char)0x72, (char)0x74,
|
||||||
|
(char)0x00, (char)0x3f, (char)0xf0, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x05, (char)0x06
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsPublishPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsPublishPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsPublishPacket* pkt = new SrsPublishPacket();
|
||||||
|
pkt->command_name = "publish";
|
||||||
|
pkt->command_object = SrsAmf0Any::null();
|
||||||
|
pkt->stream_name = "livestream";
|
||||||
|
pkt->type = "live";
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x28, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x07, (char)0x70,
|
||||||
|
(char)0x75, (char)0x62, (char)0x6c, (char)0x69, (char)0x73, (char)0x68, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05,
|
||||||
|
(char)0x02, (char)0x00, (char)0x0a, (char)0x6c, (char)0x69, (char)0x76, (char)0x65, (char)0x73,
|
||||||
|
(char)0x74, (char)0x72, (char)0x65, (char)0x61, (char)0x6d, (char)0x02, (char)0x00, (char)0x04,
|
||||||
|
(char)0x6c, (char)0x69, (char)0x76, (char)0x65
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsPlayPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsPlayPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsPlayPacket* pkt = new SrsPlayPacket();
|
||||||
|
pkt->command_name = "play";
|
||||||
|
pkt->command_object = SrsAmf0Any::null();
|
||||||
|
pkt->stream_name = "livestream";
|
||||||
|
pkt->start = 0;
|
||||||
|
pkt->duration = 0;
|
||||||
|
pkt->reset = true;
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x32, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x04, (char)0x70,
|
||||||
|
(char)0x6c, (char)0x61, (char)0x79, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05, (char)0x02, (char)0x00, (char)0x0a,
|
||||||
|
(char)0x6c, (char)0x69, (char)0x76, (char)0x65, (char)0x73, (char)0x74, (char)0x72, (char)0x65,
|
||||||
|
(char)0x61, (char)0x6d, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x01, (char)0x01
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsPlayResPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsPlayResPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsAmf0Object* args = SrsAmf0Any::object();
|
||||||
|
|
||||||
|
SrsPlayResPacket* pkt = new SrsPlayResPacket();
|
||||||
|
pkt->command_name = "_result";
|
||||||
|
pkt->command_object = SrsAmf0Any::null();
|
||||||
|
pkt->desc = args;
|
||||||
|
|
||||||
|
args->set("stream" , SrsAmf0Any::str("livestream"));
|
||||||
|
args->set("start" , SrsAmf0Any::number(0));
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x3d, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x07, (char)0x5f,
|
||||||
|
(char)0x72, (char)0x65, (char)0x73, (char)0x75, (char)0x6c, (char)0x74, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05,
|
||||||
|
(char)0x03, (char)0x00, (char)0x06, (char)0x73, (char)0x74, (char)0x72, (char)0x65, (char)0x61,
|
||||||
|
(char)0x6d, (char)0x02, (char)0x00, (char)0x0a, (char)0x6c, (char)0x69, (char)0x76, (char)0x65,
|
||||||
|
(char)0x73, (char)0x74, (char)0x72, (char)0x65, (char)0x61, (char)0x6d, (char)0x00, (char)0x05,
|
||||||
|
(char)0x73, (char)0x74, (char)0x61, (char)0x72, (char)0x74, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x09
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsOnBWDonePacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsOnBWDonePacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsOnBWDonePacket* pkt = new SrsOnBWDonePacket();
|
||||||
|
pkt->command_name = "onBWDone";
|
||||||
|
pkt->args = SrsAmf0Any::null();
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x15, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x08, (char)0x6f,
|
||||||
|
(char)0x6e, (char)0x42, (char)0x57, (char)0x44, (char)0x6f, (char)0x6e, (char)0x65, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x05
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsOnStatusCallPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsOnStatusCallPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsAmf0Object* args = SrsAmf0Any::object();
|
||||||
|
|
||||||
|
args->set("stream" , SrsAmf0Any::str("livestream"));
|
||||||
|
args->set("start" , SrsAmf0Any::number(0));
|
||||||
|
|
||||||
|
SrsOnStatusCallPacket* pkt = new SrsOnStatusCallPacket();
|
||||||
|
pkt->command_name = "onStatus";
|
||||||
|
pkt->args = SrsAmf0Any::null();
|
||||||
|
pkt->data = args;
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x3e, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x08, (char)0x6f,
|
||||||
|
(char)0x6e, (char)0x53, (char)0x74, (char)0x61, (char)0x74, (char)0x75, (char)0x73, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x05, (char)0x03, (char)0x00, (char)0x06, (char)0x73, (char)0x74, (char)0x72, (char)0x65,
|
||||||
|
(char)0x61, (char)0x6d, (char)0x02, (char)0x00, (char)0x0a, (char)0x6c, (char)0x69, (char)0x76,
|
||||||
|
(char)0x65, (char)0x73, (char)0x74, (char)0x72, (char)0x65, (char)0x61, (char)0x6d, (char)0x00,
|
||||||
|
(char)0x05, (char)0x73, (char)0x74, (char)0x61, (char)0x72, (char)0x74, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x09
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsBandwidthPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsBandwidthPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsAmf0Object* args = SrsAmf0Any::object();
|
||||||
|
|
||||||
|
args->set("stream" , SrsAmf0Any::str("livestream"));
|
||||||
|
args->set("start" , SrsAmf0Any::number(0));
|
||||||
|
|
||||||
|
SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
|
||||||
|
pkt->command_name = "startPublish";
|
||||||
|
pkt->args = SrsAmf0Any::null();
|
||||||
|
pkt->data = args;
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x42, (char)0x14,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x0c, (char)0x73,
|
||||||
|
(char)0x74, (char)0x61, (char)0x72, (char)0x74, (char)0x50, (char)0x75, (char)0x62, (char)0x6c,
|
||||||
|
(char)0x69, (char)0x73, (char)0x68, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05, (char)0x03, (char)0x00, (char)0x06,
|
||||||
|
(char)0x73, (char)0x74, (char)0x72, (char)0x65, (char)0x61, (char)0x6d, (char)0x02, (char)0x00,
|
||||||
|
(char)0x0a, (char)0x6c, (char)0x69, (char)0x76, (char)0x65, (char)0x73, (char)0x74, (char)0x72,
|
||||||
|
(char)0x65, (char)0x61, (char)0x6d, (char)0x00, (char)0x05, (char)0x73, (char)0x74, (char)0x61,
|
||||||
|
(char)0x72, (char)0x74, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x09
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsOnStatusDataPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsOnStatusDataPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsAmf0Object* args = SrsAmf0Any::object();
|
||||||
|
|
||||||
|
args->set("stream" , SrsAmf0Any::str("livestream"));
|
||||||
|
args->set("start" , SrsAmf0Any::number(0));
|
||||||
|
|
||||||
|
SrsOnStatusDataPacket* pkt = new SrsOnStatusDataPacket();
|
||||||
|
pkt->command_name = "onData";
|
||||||
|
pkt->data = args;
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x32, (char)0x12,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x06, (char)0x6f,
|
||||||
|
(char)0x6e, (char)0x44, (char)0x61, (char)0x74, (char)0x61, (char)0x03, (char)0x00, (char)0x06,
|
||||||
|
(char)0x73, (char)0x74, (char)0x72, (char)0x65, (char)0x61, (char)0x6d, (char)0x02, (char)0x00,
|
||||||
|
(char)0x0a, (char)0x6c, (char)0x69, (char)0x76, (char)0x65, (char)0x73, (char)0x74, (char)0x72,
|
||||||
|
(char)0x65, (char)0x61, (char)0x6d, (char)0x00, (char)0x05, (char)0x73, (char)0x74, (char)0x61,
|
||||||
|
(char)0x72, (char)0x74, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x09
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsSampleAccessPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsSampleAccessPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsSampleAccessPacket* pkt = new SrsSampleAccessPacket();
|
||||||
|
pkt->command_name = "|RtmpSampleAccess";
|
||||||
|
pkt->video_sample_access = true;
|
||||||
|
pkt->audio_sample_access = true;
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x18, (char)0x12,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x11, (char)0x7c,
|
||||||
|
(char)0x52, (char)0x74, (char)0x6d, (char)0x70, (char)0x53, (char)0x61, (char)0x6d, (char)0x70,
|
||||||
|
(char)0x6c, (char)0x65, (char)0x41, (char)0x63, (char)0x63, (char)0x65, (char)0x73, (char)0x73,
|
||||||
|
(char)0x01, (char)0x01, (char)0x01, (char)0x01
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsOnMetaDataPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsOnMetaDataPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsAmf0Object* args = SrsAmf0Any::object();
|
||||||
|
|
||||||
|
args->set("width" , SrsAmf0Any::number(1024));
|
||||||
|
args->set("height" , SrsAmf0Any::number(576));
|
||||||
|
|
||||||
|
SrsOnMetaDataPacket* pkt = new SrsOnMetaDataPacket();
|
||||||
|
pkt->name = "onMetaData";
|
||||||
|
pkt->metadata = args;
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x04, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x32, (char)0x12,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x0a, (char)0x6f,
|
||||||
|
(char)0x6e, (char)0x4d, (char)0x65, (char)0x74, (char)0x61, (char)0x44, (char)0x61, (char)0x74,
|
||||||
|
(char)0x61, (char)0x03, (char)0x00, (char)0x05, (char)0x77, (char)0x69, (char)0x64, (char)0x74,
|
||||||
|
(char)0x68, (char)0x00, (char)0x40, (char)0x90, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x06, (char)0x68, (char)0x65, (char)0x69, (char)0x67,
|
||||||
|
(char)0x68, (char)0x74, (char)0x00, (char)0x40, (char)0x82, (char)0x00, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x09
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsSetWindowAckSizePacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsSetWindowAckSizePacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsSetWindowAckSizePacket* pkt = new SrsSetWindowAckSizePacket();
|
||||||
|
pkt->ackowledgement_window_size = 102400;
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x02, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x04, (char)0x05,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x01, (char)0x90, (char)0x00
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsAcknowledgementPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsAcknowledgementPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsAcknowledgementPacket* pkt = new SrsAcknowledgementPacket();
|
||||||
|
pkt->sequence_number = 1024;
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x02, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x04, (char)0x03,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x04, (char)0x00
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsSetChunkSizePacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsSetChunkSizePacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsSetChunkSizePacket* pkt = new SrsSetChunkSizePacket();
|
||||||
|
pkt->chunk_size = 1024;
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x02, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x04, (char)0x01,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x04, (char)0x00
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsSetPeerBandwidthPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsSetPeerBandwidthPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsSetPeerBandwidthPacket* pkt = new SrsSetPeerBandwidthPacket();
|
||||||
|
pkt->type = SrsPeerBandwidthSoft;
|
||||||
|
pkt->bandwidth = 1024;
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x02, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05, (char)0x06,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x04, (char)0x00,
|
||||||
|
(char)0x01
|
||||||
|
};
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a SrsUserControlPacket packet
|
||||||
|
*/
|
||||||
|
VOID TEST(ProtocolStackTest, ProtocolSendSrsUserControlPacket)
|
||||||
|
{
|
||||||
|
MockBufferIO bio;
|
||||||
|
SrsProtocol proto(&bio);
|
||||||
|
|
||||||
|
SrsUserControlPacket* pkt = new SrsUserControlPacket();
|
||||||
|
pkt->event_type = SrcPCUCSetBufferLength;
|
||||||
|
pkt->event_data = 0x01;
|
||||||
|
pkt->extra_data = 0x10;
|
||||||
|
|
||||||
|
EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
|
||||||
|
char buf[] = {
|
||||||
|
(char)0x02, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x0a, (char)0x04,
|
||||||
|
(char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x03, (char)0x00, (char)0x00,
|
||||||
|
(char)0x00, (char)0x01, (char)0x00, (char)0x00, (char)0x00, (char)0x10
|
||||||
|
};
|
||||||
|
|
||||||
|
__srs_bytes_print(bio.out_buffer.bytes(), bio.out_buffer.length());
|
||||||
|
__srs_bytes_print(buf, sizeof(buf));
|
||||||
|
|
||||||
|
EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
|
||||||
|
EXPECT_TRUE(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue