-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
srs_protocol_stack.hpp
1653 lines (1595 loc) · 49.4 KB
/
srs_protocol_stack.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
The MIT License (MIT)
Copyright (c) 2013-2014 winlin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef SRS_RTMP_PROTOCOL_STACK_HPP
#define SRS_RTMP_PROTOCOL_STACK_HPP
/*
#include <srs_protocol_stack.hpp>
*/
#include <srs_core.hpp>
#include <map>
#include <vector>
#include <string>
// for srs-librtmp, @see https://github.com/winlinvip/simple-rtmp-server/issues/213
#ifndef _WIN32
#include <sys/uio.h>
#endif
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_consts.hpp>
class ISrsProtocolReaderWriter;
class SrsBuffer;
class SrsPacket;
class SrsStream;
class SrsAmf0Object;
class SrsAmf0Any;
class SrsMessageHeader;
class SrsMessage;
class SrsChunkStream;
class SrsSharedPtrMessage;
class IMergeReadHandler;
/**
* 4.1. Message Header
*/
class SrsMessageHeader
{
public:
/**
* 3bytes.
* Three-byte field that contains a timestamp delta of the message.
* The 4 bytes are packed in the big-endian order.
* @remark, only used for decoding message from chunk stream.
*/
int32_t timestamp_delta;
/**
* 3bytes.
* Three-byte field that represents the size of the payload in bytes.
* It is set in big-endian format.
*/
int32_t payload_length;
/**
* 1byte.
* One byte field to represent the message type. A range of type IDs
* (1-7) are reserved for protocol control messages.
*/
int8_t message_type;
/**
* 4bytes.
* Four-byte field that identifies the stream of the message. These
* bytes are set in big-endian format.
*/
int32_t stream_id;
/**
* Four-byte field that contains a timestamp of the message.
* The 4 bytes are packed in the big-endian order.
* @remark, used as calc timestamp when decode and encode time.
* @remark, we use 64bits for large time for jitter detect and hls.
*/
int64_t timestamp;
public:
/**
* get the perfered cid(chunk stream id) which sendout over.
* set at decoding, and canbe used for directly send message,
* for example, dispatch to all connections.
*/
int perfer_cid;
public:
SrsMessageHeader();
virtual ~SrsMessageHeader();
public:
bool is_audio();
bool is_video();
bool is_amf0_command();
bool is_amf0_data();
bool is_amf3_command();
bool is_amf3_data();
bool is_window_ackledgement_size();
bool is_ackledgement();
bool is_set_chunk_size();
bool is_user_control_message();
bool is_set_peer_bandwidth();
bool is_aggregate();
public:
/**
* create a amf0 script header, set the size and stream_id.
*/
void initialize_amf0_script(int size, int stream);
/**
* create a audio header, set the size, timestamp and stream_id.
*/
void initialize_audio(int size, u_int32_t time, int stream);
/**
* create a video header, set the size, timestamp and stream_id.
*/
void initialize_video(int size, u_int32_t time, int stream);
};
/**
* message is raw data RTMP message, bytes oriented,
* protcol always recv RTMP message, and can send RTMP message or RTMP packet.
* the shared-ptr message is a special RTMP message, use ref-count for performance issue.
*
* @remark, never directly new SrsMessage, the constructor is protected,
* for in the SrsMessage, we never know whether we should free the message,
* for SrsCommonMessage, we should free the payload,
* while for SrsSharedPtrMessage, we should use ref-count to free it.
* so, use these two concrete message, SrsCommonMessage or SrsSharedPtrMessage instread.
*/
class SrsMessage
{
// 4.1. Message Header
public:
SrsMessageHeader header;
// 4.2. Message Payload
public:
/**
* current message parsed size,
* size <= header.payload_length
* for the payload maybe sent in multiple chunks.
*/
int size;
/**
* the payload of message, the SrsMessage never know about the detail of payload,
* user must use SrsProtocol.decode_message to get concrete packet.
* @remark, not all message payload can be decoded to packet. for example,
* video/audio packet use raw bytes, no video/audio packet.
*/
char* payload;
protected:
SrsMessage();
public:
virtual ~SrsMessage();
};
/**
* the protocol provides the rtmp-message-protocol services,
* to recv RTMP message from RTMP chunk stream,
* and to send out RTMP message over RTMP chunk stream.
*/
class SrsProtocol
{
private:
class AckWindowSize
{
public:
int ack_window_size;
int64_t acked_size;
AckWindowSize();
};
// peer in/out
private:
/**
* underlayer socket object, send/recv bytes.
*/
ISrsProtocolReaderWriter* skt;
/**
* requests sent out, used to build the response.
* key: transactionId
* value: the request command name
*/
std::map<double, std::string> requests;
// peer in
private:
/**
* chunk stream to decode RTMP messages.
*/
std::map<int, SrsChunkStream*> chunk_streams;
/**
* bytes buffer cache, recv from skt, provide services for stream.
*/
SrsBuffer* in_buffer;
/**
* input chunk size, default to 128, set by peer packet.
*/
int32_t in_chunk_size;
/**
* input ack size, when to send the acked packet.
*/
AckWindowSize in_ack_size;
/**
* whether auto response when recv messages.
* default to true for it's very easy to use the protocol stack.
* @see: https://github.com/winlinvip/simple-rtmp-server/issues/217
*/
bool auto_response_when_recv;
/**
* when not auto response message, manual flush the messages in queue.
*/
std::vector<SrsPacket*> manual_response_queue;
// peer out
private:
/**
* cache for multiple messages send,
* initialize to iovec[SRS_CONSTS_IOVS_MAX] and realloc when consumed,
* it's ok to realloc the iovs cache, for all ptr is ok.
*/
iovec* out_iovs;
int nb_out_iovs;
/**
* output header cache.
* used for type0, 11bytes(or 15bytes with extended timestamp) header.
* or for type3, 1bytes(or 5bytes with extended timestamp) header.
* the c0c3 caches must use unit SRS_CONSTS_RTMP_MAX_FMT0_HEADER_SIZE bytes.
*
* @remark, the c0c3 cache cannot be realloc.
*/
char out_c0c3_caches[SRS_CONSTS_C0C3_HEADERS_MAX];
// whether warned user to increase the c0c3 header cache.
bool warned_c0c3_cache_dry;
/**
* output chunk size, default to 128, set by config.
*/
int32_t out_chunk_size;
public:
/**
* use io to create the protocol stack,
* @param io, provides io interfaces, user must free it.
*/
SrsProtocol(ISrsProtocolReaderWriter* io);
virtual ~SrsProtocol();
public:
/**
* set the auto response message when recv for protocol stack.
* @param v, whether auto response message when recv message.
* @see: https://github.com/winlinvip/simple-rtmp-server/issues/217
*/
virtual void set_auto_response(bool v);
/**
* flush for manual response when the auto response is disabled
* by set_auto_response(false), we default use auto response, so donot
* need to call this api(the protocol sdk will auto send message).
* @see the auto_response_when_recv and manual_response_queue.
*/
virtual int manual_response_flush();
public:
/**
* to improve read performance, merge some packets then read,
* when it on and read small bytes, we sleep to wait more data.,
* that is, we merge some data to read together.
* @param v true to ename merged read.
* @param handler the handler when merge read is enabled.
* @see https://github.com/winlinvip/simple-rtmp-server/issues/241
*/
virtual void set_merge_read(bool v, IMergeReadHandler* handler);
public:
/**
* set/get the recv timeout in us.
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
*/
virtual void set_recv_timeout(int64_t timeout_us);
virtual int64_t get_recv_timeout();
/**
* set/get the send timeout in us.
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
*/
virtual void set_send_timeout(int64_t timeout_us);
virtual int64_t get_send_timeout();
/**
* get recv/send bytes.
*/
virtual int64_t get_recv_bytes();
virtual int64_t get_send_bytes();
public:
/**
* recv a RTMP message, which is bytes oriented.
* user can use decode_message to get the decoded RTMP packet.
* @param pmsg, set the received message,
* always NULL if error,
* NULL for unknown packet but return success.
* never NULL if decode success.
* @remark, drop message when msg is empty or payload length is empty.
*/
virtual int recv_message(SrsMessage** pmsg);
/**
* decode bytes oriented RTMP message to RTMP packet,
* @param ppacket, output decoded packet,
* always NULL if error, never NULL if success.
* @return error when unknown packet, error when decode failed.
*/
virtual int decode_message(SrsMessage* msg, SrsPacket** ppacket);
/**
* send the RTMP message and always free it.
* user must never free or use the msg after this method,
* for it will always free the msg.
* @param msg, the msg to send out, never be NULL.
* @param stream_id, the stream id of packet to send over, 0 for control message.
*/
virtual int send_and_free_message(SrsMessage* msg, int stream_id);
/**
* send the RTMP message and always free it.
* user must never free or use the msg after this method,
* for it will always free the msg.
* @param msgs, the msgs to send out, never be NULL.
* @param nb_msgs, the size of msgs to send out.
* @param stream_id, the stream id of packet to send over, 0 for control message.
*/
virtual int send_and_free_messages(SrsMessage** msgs, int nb_msgs, int stream_id);
/**
* send the RTMP packet and always free it.
* user must never free or use the packet after this method,
* for it will always free the packet.
* @param packet, the packet to send out, never be NULL.
* @param stream_id, the stream id of packet to send over, 0 for control message.
*/
virtual int send_and_free_packet(SrsPacket* packet, int stream_id);
public:
/**
* expect a specified message, drop others util got specified one.
* @pmsg, user must free it. NULL if not success.
* @ppacket, store in the pmsg, user must never free it. NULL if not success.
* @remark, only when success, user can use and must free the pmsg/ppacket.
* for example:
SrsCommonMessage* msg = NULL;
SrsConnectAppResPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsConnectAppResPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) {
return ret;
}
// use pkt
* user should never recv message and convert it, use this method instead.
* if need to set timeout, use set timeout of SrsProtocol.
*/
template<class T>
int expect_message(SrsMessage** pmsg, T** ppacket)
{
*pmsg = NULL;
*ppacket = NULL;
int ret = ERROR_SUCCESS;
while (true) {
SrsMessage* msg = NULL;
if ((ret = recv_message(&msg)) != ERROR_SUCCESS) {
if (ret != ERROR_SOCKET_TIMEOUT && !srs_is_client_gracefully_close(ret)) {
srs_error("recv message failed. ret=%d", ret);
}
return ret;
}
srs_verbose("recv message success.");
SrsPacket* packet = NULL;
if ((ret = decode_message(msg, &packet)) != ERROR_SUCCESS) {
srs_error("decode message failed. ret=%d", ret);
srs_freep(msg);
srs_freep(packet);
return ret;
}
T* pkt = dynamic_cast<T*>(packet);
if (!pkt) {
srs_info("drop message(type=%d, size=%d, time=%"PRId64", sid=%d).",
msg->header.message_type, msg->header.payload_length,
msg->header.timestamp, msg->header.stream_id);
srs_freep(msg);
srs_freep(packet);
continue;
}
*pmsg = msg;
*ppacket = pkt;
break;
}
return ret;
}
private:
/**
* send out the messages, donot free it,
* the caller must free the param msgs.
*/
virtual int do_send_messages(SrsMessage** msgs, int nb_msgs);
/**
* underlayer api for send and free packet.
*/
virtual int do_send_and_free_packet(SrsPacket* packet, int stream_id);
/**
* generate the chunk header for msg.
* @param mh, the header of msg to send.
* @param c0, whether the first chunk, the c0 chunk.
* @param pnbh, output the size of header.
* @param ph, output the header cache.
* user should never free it, it's cached header.
*/
virtual void generate_chunk_header(char* cache, SrsMessageHeader* mh, bool c0, int* pnbh, char** ph);
/**
* imp for decode_message
*/
virtual int do_decode_message(SrsMessageHeader& header, SrsStream* stream, SrsPacket** ppacket);
/**
* recv bytes oriented RTMP message from protocol stack.
* return error if error occur and nerver set the pmsg,
* return success and pmsg set to NULL if no entire message got,
* return success and pmsg set to entire message if got one.
*/
virtual int recv_interlaced_message(SrsMessage** pmsg);
/**
* read the chunk basic header(fmt, cid) from chunk stream.
* user can discovery a SrsChunkStream by cid.
* @bh_size return the chunk basic header size, to remove the used bytes when finished.
*/
virtual int read_basic_header(char& fmt, int& cid, int& bh_size);
/**
* read the chunk message header(timestamp, payload_length, message_type, stream_id)
* from chunk stream and save to SrsChunkStream.
* @mh_size return the chunk message header size, to remove the used bytes when finished.
*/
virtual int read_message_header(SrsChunkStream* chunk, char fmt, int bh_size, int& mh_size);
/**
* read the chunk payload, remove the used bytes in buffer,
* if got entire message, set the pmsg.
* @payload_size read size in this roundtrip, generally a chunk size or left message size.
*/
virtual int read_message_payload(SrsChunkStream* chunk, int bh_size, int mh_size, int& payload_size, SrsMessage** pmsg);
/**
* when recv message, update the context.
*/
virtual int on_recv_message(SrsMessage* msg);
/**
* when message sentout, update the context.
*/
virtual int on_send_packet(SrsMessage* msg, SrsPacket* packet);
private:
/**
* auto response the ack message.
*/
virtual int response_acknowledgement_message();
/**
* auto response the ping message.
*/
virtual int response_ping_message(int32_t timestamp);
};
/**
* incoming chunk stream maybe interlaced,
* use the chunk stream to cache the input RTMP chunk streams.
*/
class SrsChunkStream
{
public:
/**
* represents the basic header fmt,
* which used to identify the variant message header type.
*/
char fmt;
/**
* represents the basic header cid,
* which is the chunk stream id.
*/
int cid;
/**
* cached message header
*/
SrsMessageHeader header;
/**
* whether the chunk message header has extended timestamp.
*/
bool extended_timestamp;
/**
* partially read message.
*/
SrsMessage* msg;
/**
* decoded msg count, to identify whether the chunk stream is fresh.
*/
int64_t msg_count;
public:
SrsChunkStream(int _cid);
virtual ~SrsChunkStream();
};
/**
* the common message used free the payload in common way.
*/
class SrsCommonMessage : public SrsMessage
{
public:
SrsCommonMessage();
virtual ~SrsCommonMessage();
};
/**
* shared ptr message.
* for audio/video/data message that need less memory copy.
* and only for output.
*
* create first object by constructor and create(),
* use copy if need reference count message.
*
* Usage:
* SrsSharedPtrMessage msg;
*
*/
class SrsSharedPtrMessage : public SrsMessage
{
private:
class __SrsSharedPtr
{
public:
char* payload;
int size;
int shared_count;
__SrsSharedPtr();
virtual ~__SrsSharedPtr();
};
__SrsSharedPtr* ptr;
public:
SrsSharedPtrMessage();
virtual ~SrsSharedPtrMessage();
public:
/**
* create shared ptr message,
* copy header, manage the payload of msg,
* set the payload to NULL to prevent double free.
* @remark payload of msg set to NULL if success.
*/
virtual int create(SrsMessage* msg);
/**
* create shared ptr message,
* from the header and payload.
* @remark user should never free the payload.
*/
virtual int create(SrsMessageHeader* pheader, char* payload, int size);
/**
* get current reference count.
* when this object created, count set to 0.
* if copy() this object, count increase 1.
* if this or copy deleted, free payload when count is 0, or count--.
* @remark, assert object is created.
*/
virtual int count();
public:
/**
* copy current shared ptr message, use ref-count.
* @remark, assert object is created.
*/
virtual SrsSharedPtrMessage* copy();
};
/**
* the decoded message payload.
* @remark we seperate the packet from message,
* for the packet focus on logic and domain data,
* the message bind to the protocol and focus on protocol, such as header.
* we can merge the message and packet, using OOAD hierachy, packet extends from message,
* it's better for me to use components -- the message use the packet as payload.
*/
class SrsPacket
{
public:
SrsPacket();
virtual ~SrsPacket();
public:
/**
* the subpacket can override this encode,
* for example, video and audio will directly set the payload withou memory copy,
* other packet which need to serialize/encode to bytes by override the
* get_size and encode_packet.
*/
virtual int encode(int& size, char*& payload);
// decode functions for concrete packet to override.
public:
/**
* subpacket must override to decode packet from stream.
* @remark never invoke the super.decode, it always failed.
*/
virtual int decode(SrsStream* stream);
// encode functions for concrete packet to override.
public:
/**
* the cid(chunk id) specifies the chunk to send data over.
* generally, each message perfer some cid, for example,
* all protocol control messages perfer RTMP_CID_ProtocolControl,
* SrsSetWindowAckSizePacket is protocol control message.
*/
virtual int get_prefer_cid();
/**
* subpacket must override to provide the right message type.
* the message type set the RTMP message type in header.
*/
virtual int get_message_type();
protected:
/**
* subpacket can override to calc the packet size.
*/
virtual int get_size();
/**
* subpacket can override to encode the payload to stream.
* @remark never invoke the super.encode_packet, it always failed.
*/
virtual int encode_packet(SrsStream* stream);
};
/**
* 4.1.1. connect
* The client sends the connect command to the server to request
* connection to a server application instance.
*/
class SrsConnectAppPacket : public SrsPacket
{
public:
/**
* Name of the command. Set to “connect”.
*/
std::string command_name;
/**
* Always set to 1.
*/
double transaction_id;
/**
* Command information object which has the name-value pairs.
* @remark: alloc in packet constructor, user can directly use it,
* user should never alloc it again which will cause memory leak.
* @remark, never be NULL.
*/
SrsAmf0Object* command_object;
/**
* Any optional information
* @remark, optional, init to and maybe NULL.
*/
SrsAmf0Object* args;
public:
SrsConnectAppPacket();
virtual ~SrsConnectAppPacket();
// decode functions for concrete packet to override.
public:
virtual int decode(SrsStream* stream);
// encode functions for concrete packet to override.
public:
virtual int get_prefer_cid();
virtual int get_message_type();
protected:
virtual int get_size();
virtual int encode_packet(SrsStream* stream);
};
/**
* response for SrsConnectAppPacket.
*/
class SrsConnectAppResPacket : public SrsPacket
{
public:
/**
* _result or _error; indicates whether the response is result or error.
*/
std::string command_name;
/**
* Transaction ID is 1 for call connect responses
*/
double transaction_id;
/**
* Name-value pairs that describe the properties(fmsver etc.) of the connection.
* @remark, never be NULL.
*/
SrsAmf0Object* props;
/**
* Name-value pairs that describe the response from|the server. ‘code’,
* ‘level’, ‘description’ are names of few among such information.
* @remark, never be NULL.
*/
SrsAmf0Object* info;
public:
SrsConnectAppResPacket();
virtual ~SrsConnectAppResPacket();
// decode functions for concrete packet to override.
public:
virtual int decode(SrsStream* stream);
// encode functions for concrete packet to override.
public:
virtual int get_prefer_cid();
virtual int get_message_type();
protected:
virtual int get_size();
virtual int encode_packet(SrsStream* stream);
};
/**
* 4.1.2. Call
* The call method of the NetConnection object runs remote procedure
* calls (RPC) at the receiving end. The called RPC name is passed as a
* parameter to the call command.
*/
class SrsCallPacket : public SrsPacket
{
public:
/**
* Name of the remote procedure that is called.
*/
std::string command_name;
/**
* If a response is expected we give a transaction Id. Else we pass a value of 0
*/
double transaction_id;
/**
* If there exists any command info this
* is set, else this is set to null type.
* @remark, optional, init to and maybe NULL.
*/
SrsAmf0Any* command_object;
/**
* Any optional arguments to be provided
* @remark, optional, init to and maybe NULL.
*/
SrsAmf0Any* arguments;
public:
SrsCallPacket();
virtual ~SrsCallPacket();
// decode functions for concrete packet to override.
public:
virtual int decode(SrsStream* stream);
// encode functions for concrete packet to override.
public:
virtual int get_prefer_cid();
virtual int get_message_type();
protected:
virtual int get_size();
virtual int encode_packet(SrsStream* stream);
};
/**
* response for SrsCallPacket.
*/
class SrsCallResPacket : public SrsPacket
{
public:
/**
* Name of the command.
*/
std::string command_name;
/**
* ID of the command, to which the response belongs to
*/
double transaction_id;
/**
* If there exists any command info this is set, else this is set to null type.
* @remark, optional, init to and maybe NULL.
*/
SrsAmf0Any* command_object;
/**
* Response from the method that was called.
* @remark, optional, init to and maybe NULL.
*/
SrsAmf0Any* response;
public:
SrsCallResPacket(double _transaction_id);
virtual ~SrsCallResPacket();
// encode functions for concrete packet to override.
public:
virtual int get_prefer_cid();
virtual int get_message_type();
protected:
virtual int get_size();
virtual int encode_packet(SrsStream* stream);
};
/**
* 4.1.3. createStream
* The client sends this command to the server to create a logical
* channel for message communication The publishing of audio, video, and
* metadata is carried out over stream channel created using the
* createStream command.
*/
class SrsCreateStreamPacket : public SrsPacket
{
public:
/**
* Name of the command. Set to “createStream”.
*/
std::string command_name;
/**
* Transaction ID of the command.
*/
double transaction_id;
/**
* If there exists any command info this is set, else this is set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
SrsAmf0Any* command_object; // null
public:
SrsCreateStreamPacket();
virtual ~SrsCreateStreamPacket();
// decode functions for concrete packet to override.
public:
virtual int decode(SrsStream* stream);
// encode functions for concrete packet to override.
public:
virtual int get_prefer_cid();
virtual int get_message_type();
protected:
virtual int get_size();
virtual int encode_packet(SrsStream* stream);
};
/**
* response for SrsCreateStreamPacket.
*/
class SrsCreateStreamResPacket : public SrsPacket
{
public:
/**
* _result or _error; indicates whether the response is result or error.
*/
std::string command_name;
/**
* ID of the command that response belongs to.
*/
double transaction_id;
/**
* If there exists any command info this is set, else this is set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
SrsAmf0Any* command_object; // null
/**
* The return value is either a stream ID or an error information object.
*/
double stream_id;
public:
SrsCreateStreamResPacket(double _transaction_id, double _stream_id);
virtual ~SrsCreateStreamResPacket();
// decode functions for concrete packet to override.
public:
virtual int decode(SrsStream* stream);
// encode functions for concrete packet to override.
public:
virtual int get_prefer_cid();
virtual int get_message_type();
protected:
virtual int get_size();
virtual int encode_packet(SrsStream* stream);
};
/**
* client close stream packet.
*/
class SrsCloseStreamPacket : public SrsPacket
{
public:
/**
* Name of the command, set to “closeStream”.
*/
std::string command_name;
/**
* Transaction ID set to 0.
*/
double transaction_id;
/**
* Command information object does not exist. Set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
SrsAmf0Any* command_object; // null
public:
SrsCloseStreamPacket();
virtual ~SrsCloseStreamPacket();
// decode functions for concrete packet to override.
public:
virtual int decode(SrsStream* stream);
};
/**
* FMLE start publish: ReleaseStream/PublishStream
*/
class SrsFMLEStartPacket : public SrsPacket
{
public:
/**
* Name of the command
*/
std::string command_name;
/**
* the transaction ID to get the response.
*/
double transaction_id;
/**
* If there exists any command info this is set, else this is set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
SrsAmf0Any* command_object; // null
/**
* the stream name to start publish or release.
*/
std::string stream_name;
public:
SrsFMLEStartPacket();
virtual ~SrsFMLEStartPacket();
// decode functions for concrete packet to override.
public:
virtual int decode(SrsStream* stream);
// encode functions for concrete packet to override.
public:
virtual int get_prefer_cid();
virtual int get_message_type();
protected:
virtual int get_size();
virtual int encode_packet(SrsStream* stream);
// factory method to create specified FMLE packet.
public:
static SrsFMLEStartPacket* create_release_stream(std::string stream);
static SrsFMLEStartPacket* create_FC_publish(std::string stream);
};
/**
* response for SrsFMLEStartPacket.
*/
class SrsFMLEStartResPacket : public SrsPacket
{
public:
/**
* Name of the command
*/
std::string command_name;
/**
* the transaction ID to get the response.
*/
double transaction_id;
/**
* If there exists any command info this is set, else this is set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
SrsAmf0Any* command_object; // null
/**
* the optional args, set to undefined.
* @remark, never be NULL, an AMF0 undefined instance.
*/
SrsAmf0Any* args; // undefined
public:
SrsFMLEStartResPacket(double _transaction_id);
virtual ~SrsFMLEStartResPacket();
// decode functions for concrete packet to override.
public:
virtual int decode(SrsStream* stream);
// encode functions for concrete packet to override.
public:
virtual int get_prefer_cid();
virtual int get_message_type();
protected:
virtual int get_size();
virtual int encode_packet(SrsStream* stream);
};
/**
* FMLE/flash publish
* 4.2.6. Publish
* The client sends the publish command to publish a named stream to the
* server. Using this name, any client can play this stream and receive
* the published audio, video, and data messages.
*/
class SrsPublishPacket : public SrsPacket
{
public:
/**
* Name of the command, set to “publish”.
*/
std::string command_name;
/**
* Transaction ID set to 0.
*/
double transaction_id;
/**
* Command information object does not exist. Set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
SrsAmf0Any* command_object; // null
/**
* Name with which the stream is published.
*/
std::string stream_name;
/**