winlin

finish utest of protocol stack. 0.9.156

@@ -132,7 +132,7 @@ SrsAvcAacCodec::~SrsAvcAacCodec() @@ -132,7 +132,7 @@ SrsAvcAacCodec::~SrsAvcAacCodec()
132 srs_freep(pictureParameterSetNALUnit); 132 srs_freep(pictureParameterSetNALUnit);
133 } 133 }
134 134
135 -int SrsAvcAacCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample) 135 +int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample)
136 { 136 {
137 int ret = ERROR_SUCCESS; 137 int ret = ERROR_SUCCESS;
138 138
@@ -274,7 +274,7 @@ int SrsAvcAacCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* samp @@ -274,7 +274,7 @@ int SrsAvcAacCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* samp
274 return ret; 274 return ret;
275 } 275 }
276 276
277 -int SrsAvcAacCodec::video_avc_demux(int8_t* data, int size, SrsCodecSample* sample) 277 +int SrsAvcAacCodec::video_avc_demux(char* data, int size, SrsCodecSample* sample)
278 { 278 {
279 int ret = ERROR_SUCCESS; 279 int ret = ERROR_SUCCESS;
280 280
@@ -197,8 +197,8 @@ public: @@ -197,8 +197,8 @@ public:
197 virtual ~SrsAvcAacCodec(); 197 virtual ~SrsAvcAacCodec();
198 // the following function used for hls to build the codec info. 198 // the following function used for hls to build the codec info.
199 public: 199 public:
200 - virtual int audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample);  
201 - virtual int video_avc_demux(int8_t* data, int size, SrsCodecSample* sample); 200 + virtual int audio_aac_demux(char* data, int size, SrsCodecSample* sample);
  201 + virtual int video_avc_demux(char* data, int size, SrsCodecSample* sample);
202 }; 202 };
203 203
204 #endif 204 #endif
@@ -240,9 +240,9 @@ int SrsDvrPlan::on_video(SrsSharedPtrMessage* video) @@ -240,9 +240,9 @@ int SrsDvrPlan::on_video(SrsSharedPtrMessage* video)
240 int size = (int)video->size; 240 int size = (int)video->size;
241 241
242 #ifdef SRS_AUTO_HTTP_CALLBACK 242 #ifdef SRS_AUTO_HTTP_CALLBACK
243 - bool is_key_frame = SrsFlvCodec::video_is_h264((int8_t*)payload, size)  
244 - && SrsFlvCodec::video_is_keyframe((int8_t*)payload, size)  
245 - && !SrsFlvCodec::video_is_sequence_header((int8_t*)payload, size); 243 + bool is_key_frame = SrsFlvCodec::video_is_h264(payload, size)
  244 + && SrsFlvCodec::video_is_keyframe(payload, size)
  245 + && !SrsFlvCodec::video_is_sequence_header(payload, size);
246 if (is_key_frame) { 246 if (is_key_frame) {
247 segment->has_keyframe = true; 247 segment->has_keyframe = true;
248 if ((ret = on_video_keyframe()) != ERROR_SUCCESS) { 248 if ((ret = on_video_keyframe()) != ERROR_SUCCESS) {
@@ -1294,8 +1294,8 @@ int SrsSource::on_aggregate(SrsMessage* msg) @@ -1294,8 +1294,8 @@ int SrsSource::on_aggregate(SrsMessage* msg)
1294 1294
1295 if (data_size > 0) { 1295 if (data_size > 0) {
1296 o.size = data_size; 1296 o.size = data_size;
1297 - o.payload = new int8_t[o.size];  
1298 - stream->read_bytes((char*)o.payload, o.size); 1297 + o.payload = new char[o.size];
  1298 + stream->read_bytes(o.payload, o.size);
1299 } 1299 }
1300 1300
1301 if (!stream->require(4)) { 1301 if (!stream->require(4)) {
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR "0" 32 #define VERSION_MAJOR "0"
33 #define VERSION_MINOR "9" 33 #define VERSION_MINOR "9"
34 -#define VERSION_REVISION "155" 34 +#define VERSION_REVISION "156"
35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION 35 #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"
@@ -39,7 +39,7 @@ SrsFlvCodec::~SrsFlvCodec() @@ -39,7 +39,7 @@ SrsFlvCodec::~SrsFlvCodec()
39 { 39 {
40 } 40 }
41 41
42 -bool SrsFlvCodec::video_is_keyframe(int8_t* data, int size) 42 +bool SrsFlvCodec::video_is_keyframe(char* data, int size)
43 { 43 {
44 // 2bytes required. 44 // 2bytes required.
45 if (size < 1) { 45 if (size < 1) {
@@ -52,7 +52,7 @@ bool SrsFlvCodec::video_is_keyframe(int8_t* data, int size) @@ -52,7 +52,7 @@ bool SrsFlvCodec::video_is_keyframe(int8_t* data, int size)
52 return frame_type == SrsCodecVideoAVCFrameKeyFrame; 52 return frame_type == SrsCodecVideoAVCFrameKeyFrame;
53 } 53 }
54 54
55 -bool SrsFlvCodec::video_is_sequence_header(int8_t* data, int size) 55 +bool SrsFlvCodec::video_is_sequence_header(char* data, int size)
56 { 56 {
57 // sequence header only for h264 57 // sequence header only for h264
58 if (!video_is_h264(data, size)) { 58 if (!video_is_h264(data, size)) {
@@ -73,7 +73,7 @@ bool SrsFlvCodec::video_is_sequence_header(int8_t* data, int size) @@ -73,7 +73,7 @@ bool SrsFlvCodec::video_is_sequence_header(int8_t* data, int size)
73 && avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader; 73 && avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader;
74 } 74 }
75 75
76 -bool SrsFlvCodec::audio_is_sequence_header(int8_t* data, int size) 76 +bool SrsFlvCodec::audio_is_sequence_header(char* data, int size)
77 { 77 {
78 // sequence header only for aac 78 // sequence header only for aac
79 if (!audio_is_aac(data, size)) { 79 if (!audio_is_aac(data, size)) {
@@ -90,7 +90,7 @@ bool SrsFlvCodec::audio_is_sequence_header(int8_t* data, int size) @@ -90,7 +90,7 @@ bool SrsFlvCodec::audio_is_sequence_header(int8_t* data, int size)
90 return aac_packet_type == SrsCodecAudioTypeSequenceHeader; 90 return aac_packet_type == SrsCodecAudioTypeSequenceHeader;
91 } 91 }
92 92
93 -bool SrsFlvCodec::video_is_h264(int8_t* data, int size) 93 +bool SrsFlvCodec::video_is_h264(char* data, int size)
94 { 94 {
95 // 1bytes required. 95 // 1bytes required.
96 if (size < 1) { 96 if (size < 1) {
@@ -103,7 +103,7 @@ bool SrsFlvCodec::video_is_h264(int8_t* data, int size) @@ -103,7 +103,7 @@ bool SrsFlvCodec::video_is_h264(int8_t* data, int size)
103 return codec_id == SrsCodecVideoAVC; 103 return codec_id == SrsCodecVideoAVC;
104 } 104 }
105 105
106 -bool SrsFlvCodec::audio_is_aac(int8_t* data, int size) 106 +bool SrsFlvCodec::audio_is_aac(char* data, int size)
107 { 107 {
108 // 1bytes required. 108 // 1bytes required.
109 if (size < 1) { 109 if (size < 1) {
@@ -158,23 +158,23 @@ public: @@ -158,23 +158,23 @@ public:
158 /** 158 /**
159 * only check the frame_type, not check the codec type. 159 * only check the frame_type, not check the codec type.
160 */ 160 */
161 - static bool video_is_keyframe(int8_t* data, int size); 161 + static bool video_is_keyframe(char* data, int size);
162 /** 162 /**
163 * check codec h264, keyframe, sequence header 163 * check codec h264, keyframe, sequence header
164 */ 164 */
165 - static bool video_is_sequence_header(int8_t* data, int size); 165 + static bool video_is_sequence_header(char* data, int size);
166 /** 166 /**
167 * check codec aac, sequence header 167 * check codec aac, sequence header
168 */ 168 */
169 - static bool audio_is_sequence_header(int8_t* data, int size); 169 + static bool audio_is_sequence_header(char* data, int size);
170 /** 170 /**
171 * check codec h264. 171 * check codec h264.
172 */ 172 */
173 - static bool video_is_h264(int8_t* data, int size); 173 + static bool video_is_h264(char* data, int size);
174 /** 174 /**
175 * check codec aac. 175 * check codec aac.
176 */ 176 */
177 - static bool audio_is_aac(int8_t* data, int size); 177 + static bool audio_is_aac(char* data, int size);
178 }; 178 };
179 179
180 #endif 180 #endif
@@ -635,12 +635,12 @@ flv_bool srs_flv_is_eof(int error_code) @@ -635,12 +635,12 @@ flv_bool srs_flv_is_eof(int error_code)
635 635
636 flv_bool srs_flv_is_sequence_header(char* data, int32_t size) 636 flv_bool srs_flv_is_sequence_header(char* data, int32_t size)
637 { 637 {
638 - return SrsFlvCodec::video_is_sequence_header((int8_t*)data, (int)size); 638 + return SrsFlvCodec::video_is_sequence_header(data, (int)size);
639 } 639 }
640 640
641 flv_bool srs_flv_is_keyframe(char* data, int32_t size) 641 flv_bool srs_flv_is_keyframe(char* data, int32_t size)
642 { 642 {
643 - return SrsFlvCodec::video_is_keyframe((int8_t*)data, (int)size); 643 + return SrsFlvCodec::video_is_keyframe(data, (int)size);
644 } 644 }
645 645
646 srs_amf0_t srs_amf0_parse(char* data, int size, int* nparsed) 646 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) @@ -764,8 +764,8 @@ int SrsProtocol::send_and_free_packet(SrsPacket* packet, int stream_id)
764 // to message 764 // to message
765 SrsMessage* msg = new SrsCommonMessage(); 765 SrsMessage* msg = new SrsCommonMessage();
766 766
767 - msg->payload = (int8_t*)payload;  
768 - msg->size = (int32_t)size; 767 + msg->payload = payload;
  768 + msg->size = size;
769 769
770 msg->header.payload_length = size; 770 msg->header.payload_length = size;
771 msg->header.message_type = packet->get_message_type(); 771 msg->header.message_type = packet->get_message_type();
@@ -1297,7 +1297,7 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, int bh_size, int mh @@ -1297,7 +1297,7 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, int bh_size, int mh
1297 1297
1298 // create msg payload if not initialized 1298 // create msg payload if not initialized
1299 if (!chunk->msg->payload) { 1299 if (!chunk->msg->payload) {
1300 - chunk->msg->payload = new int8_t[chunk->header.payload_length]; 1300 + chunk->msg->payload = new char[chunk->header.payload_length];
1301 memset(chunk->msg->payload, 0, chunk->header.payload_length); 1301 memset(chunk->msg->payload, 0, chunk->header.payload_length);
1302 srs_verbose("create empty payload for RTMP message. size=%d", chunk->header.payload_length); 1302 srs_verbose("create empty payload for RTMP message. size=%d", chunk->header.payload_length);
1303 } 1303 }
@@ -1708,7 +1708,7 @@ int SrsSharedPtrMessage::create(SrsMessageHeader* pheader, char* payload, int si @@ -1708,7 +1708,7 @@ int SrsSharedPtrMessage::create(SrsMessageHeader* pheader, char* payload, int si
1708 ptr->size = size; 1708 ptr->size = size;
1709 1709
1710 // message can access it. 1710 // message can access it.
1711 - SrsMessage::payload = (int8_t*)ptr->payload; 1711 + SrsMessage::payload = ptr->payload;
1712 SrsMessage::size = ptr->size; 1712 SrsMessage::size = ptr->size;
1713 1713
1714 return ret; 1714 return ret;
@@ -1731,7 +1731,7 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy() @@ -1731,7 +1731,7 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy()
1731 copy->ptr = ptr; 1731 copy->ptr = ptr;
1732 ptr->shared_count++; 1732 ptr->shared_count++;
1733 1733
1734 - copy->payload = (int8_t*)ptr->payload; 1734 + copy->payload = ptr->payload;
1735 copy->size = ptr->size; 1735 copy->size = ptr->size;
1736 1736
1737 return copy; 1737 return copy;
@@ -3708,7 +3708,7 @@ int SrsSetChunkSizePacket::encode_packet(SrsStream* stream) @@ -3708,7 +3708,7 @@ int SrsSetChunkSizePacket::encode_packet(SrsStream* stream)
3708 SrsSetPeerBandwidthPacket::SrsSetPeerBandwidthPacket() 3708 SrsSetPeerBandwidthPacket::SrsSetPeerBandwidthPacket()
3709 { 3709 {
3710 bandwidth = 0; 3710 bandwidth = 0;
3711 - type = 2; 3711 + type = SrsPeerBandwidthDynamic;
3712 } 3712 }
3713 3713
3714 SrsSetPeerBandwidthPacket::~SrsSetPeerBandwidthPacket() 3714 SrsSetPeerBandwidthPacket::~SrsSetPeerBandwidthPacket()
@@ -3824,7 +3824,7 @@ int SrsUserControlPacket::encode_packet(SrsStream* stream) @@ -3824,7 +3824,7 @@ int SrsUserControlPacket::encode_packet(SrsStream* stream)
3824 // when event type is set buffer length, 3824 // when event type is set buffer length,
3825 // write the extra buffer length. 3825 // write the extra buffer length.
3826 if (event_type == SrcPCUCSetBufferLength) { 3826 if (event_type == SrcPCUCSetBufferLength) {
3827 - stream->write_2bytes(extra_data); 3827 + stream->write_4bytes(extra_data);
3828 srs_verbose("user control message, buffer_length=%d", extra_data); 3828 srs_verbose("user control message, buffer_length=%d", extra_data);
3829 } 3829 }
3830 3830
@@ -388,14 +388,14 @@ public: @@ -388,14 +388,14 @@ public:
388 * size <= header.payload_length 388 * size <= header.payload_length
389 * for the payload maybe sent in multiple chunks. 389 * for the payload maybe sent in multiple chunks.
390 */ 390 */
391 - int32_t size; 391 + int size;
392 /** 392 /**
393 * the payload of message, the SrsMessage never know about the detail of payload, 393 * the payload of message, the SrsMessage never know about the detail of payload,
394 * user must use SrsProtocol.decode_message to get concrete packet. 394 * user must use SrsProtocol.decode_message to get concrete packet.
395 * @remark, not all message payload can be decoded to packet. for example, 395 * @remark, not all message payload can be decoded to packet. for example,
396 * video/audio packet use raw bytes, no video/audio packet. 396 * video/audio packet use raw bytes, no video/audio packet.
397 */ 397 */
398 - int8_t* payload; 398 + char* payload;
399 protected: 399 protected:
400 SrsMessage(); 400 SrsMessage();
401 public: 401 public:
@@ -1023,6 +1023,7 @@ protected: @@ -1023,6 +1023,7 @@ protected:
1023 virtual int get_size(); 1023 virtual int get_size();
1024 virtual int encode_packet(SrsStream* stream); 1024 virtual int encode_packet(SrsStream* stream);
1025 }; 1025 };
  1026 +
1026 /** 1027 /**
1027 * response for SrsPlayPacket. 1028 * response for SrsPlayPacket.
1028 * @remark, user must set the stream_id in header. 1029 * @remark, user must set the stream_id in header.
@@ -1352,6 +1353,16 @@ protected: @@ -1352,6 +1353,16 @@ protected:
1352 virtual int encode_packet(SrsStream* stream); 1353 virtual int encode_packet(SrsStream* stream);
1353 }; 1354 };
1354 1355
  1356 +// 5.6. Set Peer Bandwidth (6)
  1357 +enum SrsPeerBandwidthType
  1358 +{
  1359 + // The sender can mark this message hard (0), soft (1), or dynamic (2)
  1360 + // using the Limit type field.
  1361 + SrsPeerBandwidthHard = 0,
  1362 + SrsPeerBandwidthSoft = 1,
  1363 + SrsPeerBandwidthDynamic = 2,
  1364 +};
  1365 +
1355 /** 1366 /**
1356 * 5.6. Set Peer Bandwidth (6) 1367 * 5.6. Set Peer Bandwidth (6)
1357 * The client or the server sends this message to update the output 1368 * The client or the server sends this message to update the output
@@ -1361,6 +1372,7 @@ class SrsSetPeerBandwidthPacket : public SrsPacket @@ -1361,6 +1372,7 @@ class SrsSetPeerBandwidthPacket : public SrsPacket
1361 { 1372 {
1362 public: 1373 public:
1363 int32_t bandwidth; 1374 int32_t bandwidth;
  1375 + // @see: SrsPeerBandwidthType
1364 int8_t type; 1376 int8_t type;
1365 public: 1377 public:
1366 SrsSetPeerBandwidthPacket(); 1378 SrsSetPeerBandwidthPacket();
@@ -36,6 +36,15 @@ ISrsThreadContext* _srs_context = new ISrsThreadContext(); @@ -36,6 +36,15 @@ ISrsThreadContext* _srs_context = new ISrsThreadContext();
36 SrsConfig* _srs_config = NULL; 36 SrsConfig* _srs_config = NULL;
37 SrsServer* _srs_server = NULL; 37 SrsServer* _srs_server = NULL;
38 38
  39 +void __srs_bytes_print(char* pa, int size)
  40 +{
  41 + for(int i = 0; i < size; i++) {
  42 + char v = pa[i];
  43 + printf("%#x ", v);
  44 + }
  45 + printf("\n");
  46 +}
  47 +
39 // basic test and samples. 48 // basic test and samples.
40 VOID TEST(SampleTest, FastSampleInt64Test) 49 VOID TEST(SampleTest, FastSampleInt64Test)
41 { 50 {
@@ -49,4 +49,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -49,4 +49,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49 // * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual): Tests that two double values are almost equal. 49 // * {ASSERT|EXPECT}_DOUBLE_EQ(expected, actual): Tests that two double values are almost equal.
50 // * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error): Tests that v1 and v2 are within the given distance to each other. 50 // * {ASSERT|EXPECT}_NEAR(v1, v2, abs_error): Tests that v1 and v2 are within the given distance to each other.
51 51
  52 +// print the bytes.
  53 +void __srs_bytes_print(char* pa, int size);
  54 +
52 #endif 55 #endif
@@ -287,7 +287,7 @@ VOID TEST(KernelBufferTest, Grow) @@ -287,7 +287,7 @@ VOID TEST(KernelBufferTest, Grow)
287 */ 287 */
288 VOID TEST(KernelCodecTest, IsKeyFrame) 288 VOID TEST(KernelCodecTest, IsKeyFrame)
289 { 289 {
290 - int8_t data; 290 + char data;
291 291
292 data = 0x10; 292 data = 0x10;
293 EXPECT_TRUE(SrsFlvCodec::video_is_keyframe(&data, 1)); 293 EXPECT_TRUE(SrsFlvCodec::video_is_keyframe(&data, 1));
@@ -303,7 +303,7 @@ VOID TEST(KernelCodecTest, IsKeyFrame) @@ -303,7 +303,7 @@ VOID TEST(KernelCodecTest, IsKeyFrame)
303 */ 303 */
304 VOID TEST(KernelCodecTest, IsH264) 304 VOID TEST(KernelCodecTest, IsH264)
305 { 305 {
306 - int8_t data; 306 + char data;
307 307
308 EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 0)); 308 EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 0));
309 309
@@ -326,19 +326,19 @@ VOID TEST(KernelCodecTest, IsSequenceHeader) @@ -326,19 +326,19 @@ VOID TEST(KernelCodecTest, IsSequenceHeader)
326 int16_t data; 326 int16_t data;
327 char* pp = (char*)&data; 327 char* pp = (char*)&data;
328 328
329 - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 0));  
330 - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 1)); 329 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 0));
  330 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 1));
331 331
332 pp[0] = 0x17; 332 pp[0] = 0x17;
333 pp[1] = 0x00; 333 pp[1] = 0x00;
334 - EXPECT_TRUE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); 334 + EXPECT_TRUE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2));
335 pp[0] = 0x18; 335 pp[0] = 0x18;
336 - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); 336 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2));
337 pp[0] = 0x27; 337 pp[0] = 0x27;
338 - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); 338 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2));
339 pp[0] = 0x17; 339 pp[0] = 0x17;
340 pp[1] = 0x01; 340 pp[1] = 0x01;
341 - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); 341 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2));
342 } 342 }
343 343
344 /** 344 /**
@@ -347,7 +347,7 @@ VOID TEST(KernelCodecTest, IsSequenceHeader) @@ -347,7 +347,7 @@ VOID TEST(KernelCodecTest, IsSequenceHeader)
347 */ 347 */
348 VOID TEST(KernelCodecTest, IsAAC) 348 VOID TEST(KernelCodecTest, IsAAC)
349 { 349 {
350 - int8_t data; 350 + char data;
351 351
352 EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 0)); 352 EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 0));
353 353
@@ -370,17 +370,17 @@ VOID TEST(KernelCodecTest, IsAudioSequenceHeader) @@ -370,17 +370,17 @@ VOID TEST(KernelCodecTest, IsAudioSequenceHeader)
370 int16_t data; 370 int16_t data;
371 char* pp = (char*)&data; 371 char* pp = (char*)&data;
372 372
373 - EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 0));  
374 - EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 1)); 373 + EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((char*)pp, 0));
  374 + EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((char*)pp, 1));
375 375
376 pp[0] = 0xa0; 376 pp[0] = 0xa0;
377 pp[1] = 0x00; 377 pp[1] = 0x00;
378 - EXPECT_TRUE(SrsFlvCodec::audio_is_sequence_header((int8_t*)pp, 2)); 378 + EXPECT_TRUE(SrsFlvCodec::audio_is_sequence_header((char*)pp, 2));
379 pp[0] = 0x00; 379 pp[0] = 0x00;
380 - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); 380 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2));
381 pp[0] = 0xa0; 381 pp[0] = 0xa0;
382 pp[1] = 0x01; 382 pp[1] = 0x01;
383 - EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((int8_t*)pp, 2)); 383 + EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2));
384 } 384 }
385 385
386 /** 386 /**
@@ -31,6 +31,7 @@ using namespace std; @@ -31,6 +31,7 @@ using namespace std;
31 #include <srs_protocol_rtmp_stack.hpp> 31 #include <srs_protocol_rtmp_stack.hpp>
32 #include <srs_kernel_utility.hpp> 32 #include <srs_kernel_utility.hpp>
33 #include <srs_app_st.hpp> 33 #include <srs_app_st.hpp>
  34 +#include <srs_protocol_amf0.hpp>
34 35
35 MockEmptyIO::MockEmptyIO() 36 MockEmptyIO::MockEmptyIO()
36 { 37 {
@@ -4463,3 +4464,663 @@ VOID TEST(ProtocolStackTest, ProtocolRecvV0LenMessage) @@ -4463,3 +4464,663 @@ VOID TEST(ProtocolStackTest, ProtocolRecvV0LenMessage)
4463 EXPECT_EQ(4, msg->header.payload_length); 4464 EXPECT_EQ(4, msg->header.payload_length);
4464 } 4465 }
4465 4466
  4467 +/**
  4468 +* send a video message
  4469 +*/
  4470 +VOID TEST(ProtocolStackTest, ProtocolSendVMessage)
  4471 +{
  4472 + MockBufferIO bio;
  4473 + SrsProtocol proto(&bio);
  4474 +
  4475 + char data[] = {0x01, 0x02, 0x03, 0x04};
  4476 +
  4477 + SrsMessage* msg = new SrsCommonMessage();
  4478 + msg->size = sizeof(data);
  4479 + msg->payload = new char[msg->size];
  4480 + memcpy(msg->payload, data, msg->size);
  4481 +
  4482 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_message(msg, 0));
  4483 + EXPECT_EQ(16, bio.out_buffer.length());
  4484 +}
  4485 +
  4486 +/**
  4487 +* send a SrsConnectAppPacket packet
  4488 +*/
  4489 +VOID TEST(ProtocolStackTest, ProtocolSendSrsConnectAppPacket)
  4490 +{
  4491 + MockBufferIO bio;
  4492 + SrsProtocol proto(&bio);
  4493 +
  4494 + SrsConnectAppPacket* pkt = new SrsConnectAppPacket();
  4495 + pkt->command_object = SrsAmf0Any::object();
  4496 + pkt->args = SrsAmf0Any::object();
  4497 +
  4498 + pkt->command_object->set("version", SrsAmf0Any::str("1.0.0"));
  4499 + pkt->command_object->set("build", SrsAmf0Any::number(150));
  4500 + SrsAmf0Object* data = SrsAmf0Any::object();
  4501 + pkt->command_object->set("data", data);
  4502 +
  4503 + data->set("server", SrsAmf0Any::str("SRS"));
  4504 + data->set("signature", SrsAmf0Any::str("simple-rtmp-server"));
  4505 +
  4506 + pkt->args->set("info", SrsAmf0Any::str("NetStream.Status.Info"));
  4507 + pkt->args->set("desc", SrsAmf0Any::str("connected"));
  4508 + pkt->args->set("data", SrsAmf0Any::ecma_array());
  4509 +
  4510 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4511 + char buf[] = {
  4512 + (char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0xb2, (char)0x14,
  4513 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x07, (char)0x63,
  4514 + (char)0x6f, (char)0x6e, (char)0x6e, (char)0x65, (char)0x63, (char)0x74, (char)0x00, (char)0x3f,
  4515 + (char)0xf0, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x03,
  4516 + (char)0x00, (char)0x07, (char)0x76, (char)0x65, (char)0x72, (char)0x73, (char)0x69, (char)0x6f,
  4517 + (char)0x6e, (char)0x02, (char)0x00, (char)0x05, (char)0x31, (char)0x2e, (char)0x30, (char)0x2e,
  4518 + (char)0x30, (char)0x00, (char)0x05, (char)0x62, (char)0x75, (char)0x69, (char)0x6c, (char)0x64,
  4519 + (char)0x00, (char)0x40, (char)0x62, (char)0xc0, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4520 + (char)0x00, (char)0x00, (char)0x04, (char)0x64, (char)0x61, (char)0x74, (char)0x61, (char)0x03,
  4521 + (char)0x00, (char)0x06, (char)0x73, (char)0x65, (char)0x72, (char)0x76, (char)0x65, (char)0x72,
  4522 + (char)0x02, (char)0x00, (char)0x03, (char)0x53, (char)0x52, (char)0x53, (char)0x00, (char)0x09,
  4523 + (char)0x73, (char)0x69, (char)0x67, (char)0x6e, (char)0x61, (char)0x74, (char)0x75, (char)0x72,
  4524 + (char)0x65, (char)0x02, (char)0x00, (char)0x12, (char)0x73, (char)0x69, (char)0x6d, (char)0x70,
  4525 + (char)0x6c, (char)0x65, (char)0x2d, (char)0x72, (char)0x74, (char)0x6d, (char)0x70, (char)0x2d,
  4526 + (char)0x73, (char)0x65, (char)0x72, (char)0x76, (char)0x65, (char)0x72, (char)0x00, (char)0x00,
  4527 + (char)0x09, (char)0x00, (char)0x00, (char)0x09, (char)0x03, (char)0x00, (char)0x04, (char)0x69,
  4528 + (char)0x6e, (char)0x66, (char)0x6f, (char)0x02, (char)0x00, (char)0x15, (char)0x4e, (char)0x65,
  4529 + (char)0x74, (char)0x53, (char)0x74, (char)0x72, (char)0xc3, (char)0x65, (char)0x61, (char)0x6d,
  4530 + (char)0x2e, (char)0x53, (char)0x74, (char)0x61, (char)0x74, (char)0x75, (char)0x73, (char)0x2e,
  4531 + (char)0x49, (char)0x6e, (char)0x66, (char)0x6f, (char)0x00, (char)0x04, (char)0x64, (char)0x65,
  4532 + (char)0x73, (char)0x63, (char)0x02, (char)0x00, (char)0x09, (char)0x63, (char)0x6f, (char)0x6e,
  4533 + (char)0x6e, (char)0x65, (char)0x63, (char)0x74, (char)0x65, (char)0x64, (char)0x00, (char)0x04,
  4534 + (char)0x64, (char)0x61, (char)0x74, (char)0x61, (char)0x08, (char)0x00, (char)0x00, (char)0x00,
  4535 + (char)0x00, (char)0x00, (char)0x00, (char)0x09, (char)0x00, (char)0x00, (char)0x09
  4536 + };
  4537 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4538 +}
  4539 +
  4540 +/**
  4541 +* send a SrsConnectAppResPacket packet
  4542 +*/
  4543 +VOID TEST(ProtocolStackTest, ProtocolSendSrsConnectAppResPacket)
  4544 +{
  4545 + MockBufferIO bio;
  4546 + SrsProtocol proto(&bio);
  4547 +
  4548 + SrsConnectAppResPacket* pkt = new SrsConnectAppResPacket();
  4549 + pkt->props = SrsAmf0Any::object();
  4550 + pkt->info = SrsAmf0Any::object();
  4551 +
  4552 + pkt->props->set("version", SrsAmf0Any::str("1.0.0"));
  4553 + pkt->props->set("build", SrsAmf0Any::number(150));
  4554 + SrsAmf0Object* data = SrsAmf0Any::object();
  4555 + pkt->props->set("data", data);
  4556 +
  4557 + data->set("server", SrsAmf0Any::str("SRS"));
  4558 + data->set("signature", SrsAmf0Any::str("simple-rtmp-server"));
  4559 +
  4560 + pkt->info->set("info", SrsAmf0Any::str("NetStream.Status.Info"));
  4561 + pkt->info->set("desc", SrsAmf0Any::str("connected"));
  4562 + pkt->info->set("data", SrsAmf0Any::ecma_array());
  4563 +
  4564 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4565 + char buf[] = {
  4566 + (char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0xb2, (char)0x14,
  4567 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x07, (char)0x5f,
  4568 + (char)0x72, (char)0x65, (char)0x73, (char)0x75, (char)0x6c, (char)0x74, (char)0x00, (char)0x3f,
  4569 + (char)0xf0, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x03,
  4570 + (char)0x00, (char)0x07, (char)0x76, (char)0x65, (char)0x72, (char)0x73, (char)0x69, (char)0x6f,
  4571 + (char)0x6e, (char)0x02, (char)0x00, (char)0x05, (char)0x31, (char)0x2e, (char)0x30, (char)0x2e,
  4572 + (char)0x30, (char)0x00, (char)0x05, (char)0x62, (char)0x75, (char)0x69, (char)0x6c, (char)0x64,
  4573 + (char)0x00, (char)0x40, (char)0x62, (char)0xc0, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4574 + (char)0x00, (char)0x00, (char)0x04, (char)0x64, (char)0x61, (char)0x74, (char)0x61, (char)0x03,
  4575 + (char)0x00, (char)0x06, (char)0x73, (char)0x65, (char)0x72, (char)0x76, (char)0x65, (char)0x72,
  4576 + (char)0x02, (char)0x00, (char)0x03, (char)0x53, (char)0x52, (char)0x53, (char)0x00, (char)0x09,
  4577 + (char)0x73, (char)0x69, (char)0x67, (char)0x6e, (char)0x61, (char)0x74, (char)0x75, (char)0x72,
  4578 + (char)0x65, (char)0x02, (char)0x00, (char)0x12, (char)0x73, (char)0x69, (char)0x6d, (char)0x70,
  4579 + (char)0x6c, (char)0x65, (char)0x2d, (char)0x72, (char)0x74, (char)0x6d, (char)0x70, (char)0x2d,
  4580 + (char)0x73, (char)0x65, (char)0x72, (char)0x76, (char)0x65, (char)0x72, (char)0x00, (char)0x00,
  4581 + (char)0x09, (char)0x00, (char)0x00, (char)0x09, (char)0x03, (char)0x00, (char)0x04, (char)0x69,
  4582 + (char)0x6e, (char)0x66, (char)0x6f, (char)0x02, (char)0x00, (char)0x15, (char)0x4e, (char)0x65,
  4583 + (char)0x74, (char)0x53, (char)0x74, (char)0x72, (char)0xc3, (char)0x65, (char)0x61, (char)0x6d,
  4584 + (char)0x2e, (char)0x53, (char)0x74, (char)0x61, (char)0x74, (char)0x75, (char)0x73, (char)0x2e,
  4585 + (char)0x49, (char)0x6e, (char)0x66, (char)0x6f, (char)0x00, (char)0x04, (char)0x64, (char)0x65,
  4586 + (char)0x73, (char)0x63, (char)0x02, (char)0x00, (char)0x09, (char)0x63, (char)0x6f, (char)0x6e,
  4587 + (char)0x6e, (char)0x65, (char)0x63, (char)0x74, (char)0x65, (char)0x64, (char)0x00, (char)0x04,
  4588 + (char)0x64, (char)0x61, (char)0x74, (char)0x61, (char)0x08, (char)0x00, (char)0x00, (char)0x00,
  4589 + (char)0x00, (char)0x00, (char)0x00, (char)0x09, (char)0x00, (char)0x00, (char)0x09
  4590 + };
  4591 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4592 +}
  4593 +
  4594 +/**
  4595 +* send a SrsCallPacket packet
  4596 +*/
  4597 +VOID TEST(ProtocolStackTest, ProtocolSendSrsCallPacket)
  4598 +{
  4599 + MockBufferIO bio;
  4600 + SrsProtocol proto(&bio);
  4601 +
  4602 + SrsAmf0Object* args = SrsAmf0Any::object();
  4603 +
  4604 + SrsCallPacket* pkt = new SrsCallPacket();
  4605 + pkt->command_name = "my_call";
  4606 + pkt->command_object = SrsAmf0Any::null();
  4607 + pkt->arguments = args;
  4608 +
  4609 + args->set("video_id", SrsAmf0Any::number(100));
  4610 + args->set("url", SrsAmf0Any::str("http://ossrs.net/api/v1/videos/100"));
  4611 + args->set("date", SrsAmf0Any::str("2014-07-11 16:20:10.2984"));
  4612 +
  4613 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4614 + char buf[] = {
  4615 + (char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x76, (char)0x14,
  4616 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x07, (char)0x6d,
  4617 + (char)0x79, (char)0x5f, (char)0x63, (char)0x61, (char)0x6c, (char)0x6c, (char)0x00, (char)0x00,
  4618 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05,
  4619 + (char)0x03, (char)0x00, (char)0x08, (char)0x76, (char)0x69, (char)0x64, (char)0x65, (char)0x6f,
  4620 + (char)0x5f, (char)0x69, (char)0x64, (char)0x00, (char)0x40, (char)0x59, (char)0x00, (char)0x00,
  4621 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x03, (char)0x75, (char)0x72,
  4622 + (char)0x6c, (char)0x02, (char)0x00, (char)0x22, (char)0x68, (char)0x74, (char)0x74, (char)0x70,
  4623 + (char)0x3a, (char)0x2f, (char)0x2f, (char)0x6f, (char)0x73, (char)0x73, (char)0x72, (char)0x73,
  4624 + (char)0x2e, (char)0x6e, (char)0x65, (char)0x74, (char)0x2f, (char)0x61, (char)0x70, (char)0x69,
  4625 + (char)0x2f, (char)0x76, (char)0x31, (char)0x2f, (char)0x76, (char)0x69, (char)0x64, (char)0x65,
  4626 + (char)0x6f, (char)0x73, (char)0x2f, (char)0x31, (char)0x30, (char)0x30, (char)0x00, (char)0x04,
  4627 + (char)0x64, (char)0x61, (char)0x74, (char)0x65, (char)0x02, (char)0x00, (char)0x18, (char)0x32,
  4628 + (char)0x30, (char)0x31, (char)0x34, (char)0x2d, (char)0x30, (char)0x37, (char)0x2d, (char)0x31,
  4629 + (char)0x31, (char)0x20, (char)0x31, (char)0x36, (char)0x3a, (char)0x32, (char)0x30, (char)0x3a,
  4630 + (char)0x31, (char)0x30, (char)0x2e, (char)0x32, (char)0x39, (char)0x38, (char)0x34, (char)0x00,
  4631 + (char)0x00, (char)0x09
  4632 + };
  4633 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4634 +}
  4635 +
  4636 +/**
  4637 +* send a SrsCallResPacket packet
  4638 +*/
  4639 +VOID TEST(ProtocolStackTest, ProtocolSendSrsCallResPacket)
  4640 +{
  4641 + MockBufferIO bio;
  4642 + SrsProtocol proto(&bio);
  4643 +
  4644 + SrsAmf0Object* args = SrsAmf0Any::object();
  4645 +
  4646 + SrsCallResPacket* pkt = new SrsCallResPacket(0);
  4647 + pkt->command_name = "_result";
  4648 + pkt->command_object = SrsAmf0Any::null();
  4649 + pkt->response = args;
  4650 +
  4651 + args->set("video_id", SrsAmf0Any::number(100));
  4652 + args->set("url", SrsAmf0Any::str("http://ossrs.net/api/v1/videos/100"));
  4653 + args->set("date", SrsAmf0Any::str("2014-07-11 16:20:10.2984"));
  4654 +
  4655 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4656 + char buf[] = {
  4657 + (char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x76, (char)0x14,
  4658 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x07, (char)0x5f,
  4659 + (char)0x72, (char)0x65, (char)0x73, (char)0x75, (char)0x6c, (char)0x74, (char)0x00, (char)0x00,
  4660 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05,
  4661 + (char)0x03, (char)0x00, (char)0x08, (char)0x76, (char)0x69, (char)0x64, (char)0x65, (char)0x6f,
  4662 + (char)0x5f, (char)0x69, (char)0x64, (char)0x00, (char)0x40, (char)0x59, (char)0x00, (char)0x00,
  4663 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x03, (char)0x75, (char)0x72,
  4664 + (char)0x6c, (char)0x02, (char)0x00, (char)0x22, (char)0x68, (char)0x74, (char)0x74, (char)0x70,
  4665 + (char)0x3a, (char)0x2f, (char)0x2f, (char)0x6f, (char)0x73, (char)0x73, (char)0x72, (char)0x73,
  4666 + (char)0x2e, (char)0x6e, (char)0x65, (char)0x74, (char)0x2f, (char)0x61, (char)0x70, (char)0x69,
  4667 + (char)0x2f, (char)0x76, (char)0x31, (char)0x2f, (char)0x76, (char)0x69, (char)0x64, (char)0x65,
  4668 + (char)0x6f, (char)0x73, (char)0x2f, (char)0x31, (char)0x30, (char)0x30, (char)0x00, (char)0x04,
  4669 + (char)0x64, (char)0x61, (char)0x74, (char)0x65, (char)0x02, (char)0x00, (char)0x18, (char)0x32,
  4670 + (char)0x30, (char)0x31, (char)0x34, (char)0x2d, (char)0x30, (char)0x37, (char)0x2d, (char)0x31,
  4671 + (char)0x31, (char)0x20, (char)0x31, (char)0x36, (char)0x3a, (char)0x32, (char)0x30, (char)0x3a,
  4672 + (char)0x31, (char)0x30, (char)0x2e, (char)0x32, (char)0x39, (char)0x38, (char)0x34, (char)0x00,
  4673 + (char)0x00, (char)0x09
  4674 + };
  4675 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4676 +}
  4677 +
  4678 +/**
  4679 +* send a SrsCreateStreamPacket packet
  4680 +*/
  4681 +VOID TEST(ProtocolStackTest, ProtocolSendSrsCreateStreamPacket)
  4682 +{
  4683 + MockBufferIO bio;
  4684 + SrsProtocol proto(&bio);
  4685 +
  4686 + SrsCreateStreamPacket* pkt = new SrsCreateStreamPacket();
  4687 + pkt->command_object = SrsAmf0Any::null();
  4688 +
  4689 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4690 + char buf[] = {
  4691 + (char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x19, (char)0x14,
  4692 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x0c, (char)0x63,
  4693 + (char)0x72, (char)0x65, (char)0x61, (char)0x74, (char)0x65, (char)0x53, (char)0x74, (char)0x72,
  4694 + (char)0x65, (char)0x61, (char)0x6d, (char)0x00, (char)0x40, (char)0x00, (char)0x00, (char)0x00,
  4695 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05
  4696 + };
  4697 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4698 +}
  4699 +
  4700 +/**
  4701 +* send a SrsFMLEStartPacket packet
  4702 +*/
  4703 +VOID TEST(ProtocolStackTest, ProtocolSendSrsFMLEStartPacket)
  4704 +{
  4705 + MockBufferIO bio;
  4706 + SrsProtocol proto(&bio);
  4707 +
  4708 + SrsFMLEStartPacket* pkt = new SrsFMLEStartPacket();
  4709 + pkt->command_name = "FMLEStart";
  4710 + pkt->command_object = SrsAmf0Any::null();
  4711 + pkt->stream_name = "livestream";
  4712 +
  4713 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4714 + char buf[] = {
  4715 + (char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x23, (char)0x14,
  4716 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x09, (char)0x46,
  4717 + (char)0x4d, (char)0x4c, (char)0x45, (char)0x53, (char)0x74, (char)0x61, (char)0x72, (char)0x74,
  4718 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4719 + (char)0x00, (char)0x05, (char)0x02, (char)0x00, (char)0x0a, (char)0x6c, (char)0x69, (char)0x76,
  4720 + (char)0x65, (char)0x73, (char)0x74, (char)0x72, (char)0x65, (char)0x61, (char)0x6d
  4721 + };
  4722 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4723 +}
  4724 +
  4725 +/**
  4726 +* send a SrsFMLEStartResPacket packet
  4727 +*/
  4728 +VOID TEST(ProtocolStackTest, ProtocolSendSrsFMLEStartResPacket)
  4729 +{
  4730 + MockBufferIO bio;
  4731 + SrsProtocol proto(&bio);
  4732 +
  4733 + SrsAmf0Object* args = SrsAmf0Any::object();
  4734 +
  4735 + SrsFMLEStartResPacket* pkt = new SrsFMLEStartResPacket(1);
  4736 + pkt->command_name = "FMLEStart";
  4737 + pkt->command_object = SrsAmf0Any::null();
  4738 + pkt->args = args;
  4739 +
  4740 + args->set("stream" , SrsAmf0Any::str("livestream"));
  4741 + args->set("start" , SrsAmf0Any::number(0));
  4742 +
  4743 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4744 + char buf[] = {
  4745 + (char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x17, (char)0x14,
  4746 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x09, (char)0x46,
  4747 + (char)0x4d, (char)0x4c, (char)0x45, (char)0x53, (char)0x74, (char)0x61, (char)0x72, (char)0x74,
  4748 + (char)0x00, (char)0x3f, (char)0xf0, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4749 + (char)0x00, (char)0x05, (char)0x06
  4750 + };
  4751 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4752 +}
  4753 +
  4754 +/**
  4755 +* send a SrsPublishPacket packet
  4756 +*/
  4757 +VOID TEST(ProtocolStackTest, ProtocolSendSrsPublishPacket)
  4758 +{
  4759 + MockBufferIO bio;
  4760 + SrsProtocol proto(&bio);
  4761 +
  4762 + SrsPublishPacket* pkt = new SrsPublishPacket();
  4763 + pkt->command_name = "publish";
  4764 + pkt->command_object = SrsAmf0Any::null();
  4765 + pkt->stream_name = "livestream";
  4766 + pkt->type = "live";
  4767 +
  4768 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4769 + char buf[] = {
  4770 + (char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x28, (char)0x14,
  4771 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x07, (char)0x70,
  4772 + (char)0x75, (char)0x62, (char)0x6c, (char)0x69, (char)0x73, (char)0x68, (char)0x00, (char)0x00,
  4773 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05,
  4774 + (char)0x02, (char)0x00, (char)0x0a, (char)0x6c, (char)0x69, (char)0x76, (char)0x65, (char)0x73,
  4775 + (char)0x74, (char)0x72, (char)0x65, (char)0x61, (char)0x6d, (char)0x02, (char)0x00, (char)0x04,
  4776 + (char)0x6c, (char)0x69, (char)0x76, (char)0x65
  4777 + };
  4778 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4779 +}
  4780 +
  4781 +/**
  4782 +* send a SrsPlayPacket packet
  4783 +*/
  4784 +VOID TEST(ProtocolStackTest, ProtocolSendSrsPlayPacket)
  4785 +{
  4786 + MockBufferIO bio;
  4787 + SrsProtocol proto(&bio);
  4788 +
  4789 + SrsPlayPacket* pkt = new SrsPlayPacket();
  4790 + pkt->command_name = "play";
  4791 + pkt->command_object = SrsAmf0Any::null();
  4792 + pkt->stream_name = "livestream";
  4793 + pkt->start = 0;
  4794 + pkt->duration = 0;
  4795 + pkt->reset = true;
  4796 +
  4797 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4798 + char buf[] = {
  4799 + (char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x32, (char)0x14,
  4800 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x04, (char)0x70,
  4801 + (char)0x6c, (char)0x61, (char)0x79, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4802 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05, (char)0x02, (char)0x00, (char)0x0a,
  4803 + (char)0x6c, (char)0x69, (char)0x76, (char)0x65, (char)0x73, (char)0x74, (char)0x72, (char)0x65,
  4804 + (char)0x61, (char)0x6d, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4805 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4806 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x01, (char)0x01
  4807 + };
  4808 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4809 +}
  4810 +
  4811 +/**
  4812 +* send a SrsPlayResPacket packet
  4813 +*/
  4814 +VOID TEST(ProtocolStackTest, ProtocolSendSrsPlayResPacket)
  4815 +{
  4816 + MockBufferIO bio;
  4817 + SrsProtocol proto(&bio);
  4818 +
  4819 + SrsAmf0Object* args = SrsAmf0Any::object();
  4820 +
  4821 + SrsPlayResPacket* pkt = new SrsPlayResPacket();
  4822 + pkt->command_name = "_result";
  4823 + pkt->command_object = SrsAmf0Any::null();
  4824 + pkt->desc = args;
  4825 +
  4826 + args->set("stream" , SrsAmf0Any::str("livestream"));
  4827 + args->set("start" , SrsAmf0Any::number(0));
  4828 +
  4829 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4830 + char buf[] = {
  4831 + (char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x3d, (char)0x14,
  4832 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x07, (char)0x5f,
  4833 + (char)0x72, (char)0x65, (char)0x73, (char)0x75, (char)0x6c, (char)0x74, (char)0x00, (char)0x00,
  4834 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05,
  4835 + (char)0x03, (char)0x00, (char)0x06, (char)0x73, (char)0x74, (char)0x72, (char)0x65, (char)0x61,
  4836 + (char)0x6d, (char)0x02, (char)0x00, (char)0x0a, (char)0x6c, (char)0x69, (char)0x76, (char)0x65,
  4837 + (char)0x73, (char)0x74, (char)0x72, (char)0x65, (char)0x61, (char)0x6d, (char)0x00, (char)0x05,
  4838 + (char)0x73, (char)0x74, (char)0x61, (char)0x72, (char)0x74, (char)0x00, (char)0x00, (char)0x00,
  4839 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4840 + (char)0x09
  4841 + };
  4842 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4843 +}
  4844 +
  4845 +/**
  4846 +* send a SrsOnBWDonePacket packet
  4847 +*/
  4848 +VOID TEST(ProtocolStackTest, ProtocolSendSrsOnBWDonePacket)
  4849 +{
  4850 + MockBufferIO bio;
  4851 + SrsProtocol proto(&bio);
  4852 +
  4853 + SrsOnBWDonePacket* pkt = new SrsOnBWDonePacket();
  4854 + pkt->command_name = "onBWDone";
  4855 + pkt->args = SrsAmf0Any::null();
  4856 +
  4857 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4858 + char buf[] = {
  4859 + (char)0x03, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x15, (char)0x14,
  4860 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x08, (char)0x6f,
  4861 + (char)0x6e, (char)0x42, (char)0x57, (char)0x44, (char)0x6f, (char)0x6e, (char)0x65, (char)0x00,
  4862 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4863 + (char)0x05
  4864 + };
  4865 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4866 +}
  4867 +
  4868 +/**
  4869 +* send a SrsOnStatusCallPacket packet
  4870 +*/
  4871 +VOID TEST(ProtocolStackTest, ProtocolSendSrsOnStatusCallPacket)
  4872 +{
  4873 + MockBufferIO bio;
  4874 + SrsProtocol proto(&bio);
  4875 +
  4876 + SrsAmf0Object* args = SrsAmf0Any::object();
  4877 +
  4878 + args->set("stream" , SrsAmf0Any::str("livestream"));
  4879 + args->set("start" , SrsAmf0Any::number(0));
  4880 +
  4881 + SrsOnStatusCallPacket* pkt = new SrsOnStatusCallPacket();
  4882 + pkt->command_name = "onStatus";
  4883 + pkt->args = SrsAmf0Any::null();
  4884 + pkt->data = args;
  4885 +
  4886 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4887 + char buf[] = {
  4888 + (char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x3e, (char)0x14,
  4889 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x08, (char)0x6f,
  4890 + (char)0x6e, (char)0x53, (char)0x74, (char)0x61, (char)0x74, (char)0x75, (char)0x73, (char)0x00,
  4891 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4892 + (char)0x05, (char)0x03, (char)0x00, (char)0x06, (char)0x73, (char)0x74, (char)0x72, (char)0x65,
  4893 + (char)0x61, (char)0x6d, (char)0x02, (char)0x00, (char)0x0a, (char)0x6c, (char)0x69, (char)0x76,
  4894 + (char)0x65, (char)0x73, (char)0x74, (char)0x72, (char)0x65, (char)0x61, (char)0x6d, (char)0x00,
  4895 + (char)0x05, (char)0x73, (char)0x74, (char)0x61, (char)0x72, (char)0x74, (char)0x00, (char)0x00,
  4896 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4897 + (char)0x00, (char)0x09
  4898 + };
  4899 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4900 +}
  4901 +
  4902 +/**
  4903 +* send a SrsBandwidthPacket packet
  4904 +*/
  4905 +VOID TEST(ProtocolStackTest, ProtocolSendSrsBandwidthPacket)
  4906 +{
  4907 + MockBufferIO bio;
  4908 + SrsProtocol proto(&bio);
  4909 +
  4910 + SrsAmf0Object* args = SrsAmf0Any::object();
  4911 +
  4912 + args->set("stream" , SrsAmf0Any::str("livestream"));
  4913 + args->set("start" , SrsAmf0Any::number(0));
  4914 +
  4915 + SrsBandwidthPacket* pkt = new SrsBandwidthPacket();
  4916 + pkt->command_name = "startPublish";
  4917 + pkt->args = SrsAmf0Any::null();
  4918 + pkt->data = args;
  4919 +
  4920 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4921 + char buf[] = {
  4922 + (char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x42, (char)0x14,
  4923 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x0c, (char)0x73,
  4924 + (char)0x74, (char)0x61, (char)0x72, (char)0x74, (char)0x50, (char)0x75, (char)0x62, (char)0x6c,
  4925 + (char)0x69, (char)0x73, (char)0x68, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4926 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05, (char)0x03, (char)0x00, (char)0x06,
  4927 + (char)0x73, (char)0x74, (char)0x72, (char)0x65, (char)0x61, (char)0x6d, (char)0x02, (char)0x00,
  4928 + (char)0x0a, (char)0x6c, (char)0x69, (char)0x76, (char)0x65, (char)0x73, (char)0x74, (char)0x72,
  4929 + (char)0x65, (char)0x61, (char)0x6d, (char)0x00, (char)0x05, (char)0x73, (char)0x74, (char)0x61,
  4930 + (char)0x72, (char)0x74, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4931 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x09
  4932 + };
  4933 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4934 +}
  4935 +
  4936 +/**
  4937 +* send a SrsOnStatusDataPacket packet
  4938 +*/
  4939 +VOID TEST(ProtocolStackTest, ProtocolSendSrsOnStatusDataPacket)
  4940 +{
  4941 + MockBufferIO bio;
  4942 + SrsProtocol proto(&bio);
  4943 +
  4944 + SrsAmf0Object* args = SrsAmf0Any::object();
  4945 +
  4946 + args->set("stream" , SrsAmf0Any::str("livestream"));
  4947 + args->set("start" , SrsAmf0Any::number(0));
  4948 +
  4949 + SrsOnStatusDataPacket* pkt = new SrsOnStatusDataPacket();
  4950 + pkt->command_name = "onData";
  4951 + pkt->data = args;
  4952 +
  4953 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4954 + char buf[] = {
  4955 + (char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x32, (char)0x12,
  4956 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x06, (char)0x6f,
  4957 + (char)0x6e, (char)0x44, (char)0x61, (char)0x74, (char)0x61, (char)0x03, (char)0x00, (char)0x06,
  4958 + (char)0x73, (char)0x74, (char)0x72, (char)0x65, (char)0x61, (char)0x6d, (char)0x02, (char)0x00,
  4959 + (char)0x0a, (char)0x6c, (char)0x69, (char)0x76, (char)0x65, (char)0x73, (char)0x74, (char)0x72,
  4960 + (char)0x65, (char)0x61, (char)0x6d, (char)0x00, (char)0x05, (char)0x73, (char)0x74, (char)0x61,
  4961 + (char)0x72, (char)0x74, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  4962 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x09
  4963 + };
  4964 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4965 +}
  4966 +
  4967 +/**
  4968 +* send a SrsSampleAccessPacket packet
  4969 +*/
  4970 +VOID TEST(ProtocolStackTest, ProtocolSendSrsSampleAccessPacket)
  4971 +{
  4972 + MockBufferIO bio;
  4973 + SrsProtocol proto(&bio);
  4974 +
  4975 + SrsSampleAccessPacket* pkt = new SrsSampleAccessPacket();
  4976 + pkt->command_name = "|RtmpSampleAccess";
  4977 + pkt->video_sample_access = true;
  4978 + pkt->audio_sample_access = true;
  4979 +
  4980 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  4981 + char buf[] = {
  4982 + (char)0x05, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x18, (char)0x12,
  4983 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x11, (char)0x7c,
  4984 + (char)0x52, (char)0x74, (char)0x6d, (char)0x70, (char)0x53, (char)0x61, (char)0x6d, (char)0x70,
  4985 + (char)0x6c, (char)0x65, (char)0x41, (char)0x63, (char)0x63, (char)0x65, (char)0x73, (char)0x73,
  4986 + (char)0x01, (char)0x01, (char)0x01, (char)0x01
  4987 + };
  4988 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  4989 +}
  4990 +
  4991 +/**
  4992 +* send a SrsOnMetaDataPacket packet
  4993 +*/
  4994 +VOID TEST(ProtocolStackTest, ProtocolSendSrsOnMetaDataPacket)
  4995 +{
  4996 + MockBufferIO bio;
  4997 + SrsProtocol proto(&bio);
  4998 +
  4999 + SrsAmf0Object* args = SrsAmf0Any::object();
  5000 +
  5001 + args->set("width" , SrsAmf0Any::number(1024));
  5002 + args->set("height" , SrsAmf0Any::number(576));
  5003 +
  5004 + SrsOnMetaDataPacket* pkt = new SrsOnMetaDataPacket();
  5005 + pkt->name = "onMetaData";
  5006 + pkt->metadata = args;
  5007 +
  5008 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  5009 + char buf[] = {
  5010 + (char)0x04, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x32, (char)0x12,
  5011 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x02, (char)0x00, (char)0x0a, (char)0x6f,
  5012 + (char)0x6e, (char)0x4d, (char)0x65, (char)0x74, (char)0x61, (char)0x44, (char)0x61, (char)0x74,
  5013 + (char)0x61, (char)0x03, (char)0x00, (char)0x05, (char)0x77, (char)0x69, (char)0x64, (char)0x74,
  5014 + (char)0x68, (char)0x00, (char)0x40, (char)0x90, (char)0x00, (char)0x00, (char)0x00, (char)0x00,
  5015 + (char)0x00, (char)0x00, (char)0x00, (char)0x06, (char)0x68, (char)0x65, (char)0x69, (char)0x67,
  5016 + (char)0x68, (char)0x74, (char)0x00, (char)0x40, (char)0x82, (char)0x00, (char)0x00, (char)0x00,
  5017 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x09
  5018 + };
  5019 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  5020 +}
  5021 +
  5022 +/**
  5023 +* send a SrsSetWindowAckSizePacket packet
  5024 +*/
  5025 +VOID TEST(ProtocolStackTest, ProtocolSendSrsSetWindowAckSizePacket)
  5026 +{
  5027 + MockBufferIO bio;
  5028 + SrsProtocol proto(&bio);
  5029 +
  5030 + SrsSetWindowAckSizePacket* pkt = new SrsSetWindowAckSizePacket();
  5031 + pkt->ackowledgement_window_size = 102400;
  5032 +
  5033 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  5034 + char buf[] = {
  5035 + (char)0x02, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x04, (char)0x05,
  5036 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x01, (char)0x90, (char)0x00
  5037 + };
  5038 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  5039 +}
  5040 +
  5041 +/**
  5042 +* send a SrsAcknowledgementPacket packet
  5043 +*/
  5044 +VOID TEST(ProtocolStackTest, ProtocolSendSrsAcknowledgementPacket)
  5045 +{
  5046 + MockBufferIO bio;
  5047 + SrsProtocol proto(&bio);
  5048 +
  5049 + SrsAcknowledgementPacket* pkt = new SrsAcknowledgementPacket();
  5050 + pkt->sequence_number = 1024;
  5051 +
  5052 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  5053 + char buf[] = {
  5054 + (char)0x02, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x04, (char)0x03,
  5055 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x04, (char)0x00
  5056 + };
  5057 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  5058 +}
  5059 +
  5060 +/**
  5061 +* send a SrsSetChunkSizePacket packet
  5062 +*/
  5063 +VOID TEST(ProtocolStackTest, ProtocolSendSrsSetChunkSizePacket)
  5064 +{
  5065 + MockBufferIO bio;
  5066 + SrsProtocol proto(&bio);
  5067 +
  5068 + SrsSetChunkSizePacket* pkt = new SrsSetChunkSizePacket();
  5069 + pkt->chunk_size = 1024;
  5070 +
  5071 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  5072 + char buf[] = {
  5073 + (char)0x02, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x04, (char)0x01,
  5074 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x04, (char)0x00
  5075 + };
  5076 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  5077 +}
  5078 +
  5079 +/**
  5080 +* send a SrsSetPeerBandwidthPacket packet
  5081 +*/
  5082 +VOID TEST(ProtocolStackTest, ProtocolSendSrsSetPeerBandwidthPacket)
  5083 +{
  5084 + MockBufferIO bio;
  5085 + SrsProtocol proto(&bio);
  5086 +
  5087 + SrsSetPeerBandwidthPacket* pkt = new SrsSetPeerBandwidthPacket();
  5088 + pkt->type = SrsPeerBandwidthSoft;
  5089 + pkt->bandwidth = 1024;
  5090 +
  5091 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  5092 + char buf[] = {
  5093 + (char)0x02, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x05, (char)0x06,
  5094 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x04, (char)0x00,
  5095 + (char)0x01
  5096 + };
  5097 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  5098 +}
  5099 +
  5100 +/**
  5101 +* send a SrsUserControlPacket packet
  5102 +*/
  5103 +VOID TEST(ProtocolStackTest, ProtocolSendSrsUserControlPacket)
  5104 +{
  5105 + MockBufferIO bio;
  5106 + SrsProtocol proto(&bio);
  5107 +
  5108 + SrsUserControlPacket* pkt = new SrsUserControlPacket();
  5109 + pkt->event_type = SrcPCUCSetBufferLength;
  5110 + pkt->event_data = 0x01;
  5111 + pkt->extra_data = 0x10;
  5112 +
  5113 + EXPECT_TRUE(ERROR_SUCCESS == proto.send_and_free_packet(pkt, 0));
  5114 + char buf[] = {
  5115 + (char)0x02, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x0a, (char)0x04,
  5116 + (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x00, (char)0x03, (char)0x00, (char)0x00,
  5117 + (char)0x00, (char)0x01, (char)0x00, (char)0x00, (char)0x00, (char)0x10
  5118 + };
  5119 +
  5120 + __srs_bytes_print(bio.out_buffer.bytes(), bio.out_buffer.length());
  5121 + __srs_bytes_print(buf, sizeof(buf));
  5122 +
  5123 + EXPECT_TRUE(srs_bytes_equals(bio.out_buffer.bytes(), buf, sizeof(buf)));
  5124 + EXPECT_TRUE(true);
  5125 +}
  5126 +