1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00
srs/trunk/src/protocol/srs_rtmp_stack.hpp

2030 lines
66 KiB
C++
Raw Normal View History

2017-03-25 09:21:39 +00:00
/**
* The MIT License (MIT)
*
2019-01-01 13:37:28 +00:00
* Copyright (c) 2013-2019 Winlin
2017-03-25 09:21:39 +00:00
*
* 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.
*/
2013-11-23 03:36:07 +00:00
2015-09-22 01:15:51 +00:00
#ifndef SRS_PROTOCOL_RTMP_HPP
#define SRS_PROTOCOL_RTMP_HPP
2013-11-23 03:36:07 +00:00
#include <srs_core.hpp>
#include <map>
#include <vector>
2013-11-23 03:36:07 +00:00
#include <string>
2015-11-11 02:37:50 +00:00
// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213
#ifndef _WIN32
#include <sys/uio.h>
#endif
2013-11-23 03:36:07 +00:00
#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
2014-07-20 05:23:45 +00:00
#include <srs_kernel_consts.hpp>
#include <srs_core_performance.hpp>
#include <srs_kernel_flv.hpp>
2014-04-07 01:07:12 +00:00
2015-09-22 01:01:47 +00:00
class SrsFastStream;
2015-09-22 00:57:31 +00:00
class SrsBuffer;
2014-04-07 01:07:12 +00:00
class SrsAmf0Any;
class SrsMessageHeader;
class SrsChunkStream;
class SrsSharedPtrMessage;
2013-11-23 03:36:07 +00:00
2015-06-13 08:04:59 +00:00
class SrsProtocol;
class ISrsProtocolReadWriter;
2015-06-13 08:04:59 +00:00
class SrsCreateStreamPacket;
class SrsFMLEStartPacket;
class SrsPublishPacket;
class SrsOnMetaDataPacket;
class SrsPlayPacket;
class SrsCommonMessage;
class SrsPacket;
class SrsAmf0Object;
class IMergeReadHandler;
class SrsCallPacket;
2015-06-13 08:04:59 +00:00
/****************************************************************************
*****************************************************************************
****************************************************************************/
/**
* amf0 command message, command name macros
*/
#define RTMP_AMF0_COMMAND_CONNECT "connect"
#define RTMP_AMF0_COMMAND_CREATE_STREAM "createStream"
#define RTMP_AMF0_COMMAND_CLOSE_STREAM "closeStream"
#define RTMP_AMF0_COMMAND_PLAY "play"
#define RTMP_AMF0_COMMAND_PAUSE "pause"
#define RTMP_AMF0_COMMAND_ON_BW_DONE "onBWDone"
#define RTMP_AMF0_COMMAND_ON_STATUS "onStatus"
#define RTMP_AMF0_COMMAND_RESULT "_result"
#define RTMP_AMF0_COMMAND_ERROR "_error"
#define RTMP_AMF0_COMMAND_RELEASE_STREAM "releaseStream"
#define RTMP_AMF0_COMMAND_FC_PUBLISH "FCPublish"
#define RTMP_AMF0_COMMAND_UNPUBLISH "FCUnpublish"
#define RTMP_AMF0_COMMAND_PUBLISH "publish"
#define RTMP_AMF0_DATA_SAMPLE_ACCESS "|RtmpSampleAccess"
2015-06-13 08:04:59 +00:00
/**
* the signature for packets to client.
*/
#define RTMP_SIG_FMS_VER "3,5,3,888"
#define RTMP_SIG_AMF0_VER 0
#define RTMP_SIG_CLIENT_ID "ASAICiss"
/**
* onStatus consts.
*/
#define StatusLevel "level"
#define StatusCode "code"
#define StatusDescription "description"
#define StatusDetails "details"
#define StatusClientId "clientid"
// status value
#define StatusLevelStatus "status"
// status error
#define StatusLevelError "error"
// code value
#define StatusCodeConnectSuccess "NetConnection.Connect.Success"
#define StatusCodeConnectRejected "NetConnection.Connect.Rejected"
#define StatusCodeStreamReset "NetStream.Play.Reset"
#define StatusCodeStreamStart "NetStream.Play.Start"
#define StatusCodeStreamPause "NetStream.Pause.Notify"
#define StatusCodeStreamUnpause "NetStream.Unpause.Notify"
#define StatusCodePublishStart "NetStream.Publish.Start"
#define StatusCodeDataStart "NetStream.Data.Start"
#define StatusCodeUnpublishSuccess "NetStream.Unpublish.Success"
2014-12-06 11:56:06 +00:00
/****************************************************************************
2017-03-25 09:21:39 +00:00
*****************************************************************************
****************************************************************************/
2015-03-13 04:53:01 +00:00
/**
* 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 srs_error_t encode(int& size, char*& payload);
// decode functions for concrete packet to override.
2015-03-13 04:53:01 +00:00
public:
/**
* subpacket must override to decode packet from stream.
* @remark never invoke the super.decode, it always failed.
*/
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2015-03-13 04:53:01 +00:00
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 srs_error_t encode_packet(SrsBuffer* stream);
2015-03-13 04:53:01 +00:00
};
2013-11-23 03:36:07 +00:00
/**
2017-03-25 09:21:39 +00:00
* 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.
*/
2013-11-23 03:36:07 +00:00
class SrsProtocol
{
private:
2014-05-17 06:59:33 +00:00
class AckWindowSize
2014-03-18 03:32:58 +00:00
{
2014-05-17 06:59:33 +00:00
public:
uint32_t window;
// number of received bytes.
int64_t nb_recv_bytes;
// previous responsed sequence number.
uint32_t sequence_number;
2014-03-18 03:32:58 +00:00
AckWindowSize();
};
2017-03-25 09:21:39 +00:00
// peer in/out
2013-11-23 03:36:07 +00:00
private:
/**
2017-03-25 09:21:39 +00:00
* underlayer socket object, send/recv bytes.
*/
ISrsProtocolReadWriter* skt;
2014-03-18 03:32:58 +00:00
/**
2017-03-25 09:21:39 +00:00
* requests sent out, used to build the response.
* key: transactionId
* value: the request command name
*/
2014-03-18 03:32:58 +00:00
std::map<double, std::string> requests;
// peer in
2013-11-23 03:36:07 +00:00
private:
/**
2017-03-25 09:21:39 +00:00
* chunk stream to decode RTMP messages.
*/
std::map<int, SrsChunkStream*> chunk_streams;
/**
2017-03-25 09:21:39 +00:00
* cache some frequently used chunk header.
* cs_cache, the chunk stream cache.
* @see https://github.com/ossrs/srs/issues/249
*/
SrsChunkStream** cs_cache;
/**
2017-03-25 09:21:39 +00:00
* bytes buffer cache, recv from skt, provide services for stream.
*/
2015-09-22 01:01:47 +00:00
SrsFastStream* in_buffer;
/**
2017-03-25 09:21:39 +00:00
* input chunk size, default to 128, set by peer packet.
*/
2014-03-18 03:32:58 +00:00
int32_t in_chunk_size;
// The input ack window, to response acknowledge to peer,
// for example, to respose the encoder, for server got lots of packets.
2014-03-18 03:32:58 +00:00
AckWindowSize in_ack_size;
// The output ack window, to require peer to response the ack.
AckWindowSize out_ack_size;
// The buffer length set by peer.
int32_t in_buffer_length;
// Whether print the protocol level debug info.
// Generally we print the debug info when got or send first A/V packet.
bool show_debug_info;
/**
2017-03-25 09:21:39 +00:00
* whether auto response when recv messages.
* default to true for it's very easy to use the protocol stack.
* @see: https://github.com/ossrs/srs/issues/217
*/
bool auto_response_when_recv;
/**
2017-03-25 09:21:39 +00:00
* when not auto response message, manual flush the messages in queue.
*/
std::vector<SrsPacket*> manual_response_queue;
// peer out
2013-11-23 03:36:07 +00:00
private:
/**
2017-03-25 09:21:39 +00:00
* 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;
/**
2017-03-25 09:21:39 +00:00
* 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.
2014-11-13 09:04:13 +00:00
bool warned_c0c3_cache_dry;
/**
2017-03-25 09:21:39 +00:00
* output chunk size, default to 128, set by config.
*/
2014-03-18 03:32:58 +00:00
int32_t out_chunk_size;
public:
SrsProtocol(ISrsProtocolReadWriter* io);
2014-03-18 03:32:58 +00:00
virtual ~SrsProtocol();
public:
/**
2017-03-25 09:21:39 +00:00
* set the auto response message when recv for protocol stack.
* @param v, whether auto response message when recv message.
* @see: https://github.com/ossrs/srs/issues/217
*/
virtual void set_auto_response(bool v);
/**
2017-03-25 09:21:39 +00:00
* 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 srs_error_t manual_response_flush();
public:
#ifdef SRS_PERF_MERGED_READ
/**
2017-03-25 09:21:39 +00:00
* 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/ossrs/srs/issues/241
*/
virtual void set_merge_read(bool v, IMergeReadHandler* handler);
/**
2017-03-25 09:21:39 +00:00
* create buffer with specifeid size.
* @param buffer the size of buffer.
* @remark when MR(SRS_PERF_MERGED_READ) disabled, always set to 8K.
* @remark when buffer changed, the previous ptr maybe invalid.
* @see https://github.com/ossrs/srs/issues/241
*/
virtual void set_recv_buffer(int buffer_size);
#endif
2014-03-18 03:32:58 +00:00
public:
/**
2019-04-17 00:31:53 +00:00
* set/get the recv timeout in srs_utime_t.
2017-03-25 09:21:39 +00:00
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
*/
2019-04-17 00:31:53 +00:00
virtual void set_recv_timeout(srs_utime_t tm);
virtual srs_utime_t get_recv_timeout();
2014-07-06 12:43:05 +00:00
/**
2019-04-17 00:18:37 +00:00
* set/get the send timeout in srs_utime_t.
2017-03-25 09:21:39 +00:00
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
*/
2019-04-17 00:18:37 +00:00
virtual void set_send_timeout(srs_utime_t tm);
2019-04-17 00:23:15 +00:00
virtual srs_utime_t get_send_timeout();
2014-07-06 12:43:05 +00:00
/**
2017-03-25 09:21:39 +00:00
* get recv/send bytes.
*/
2014-03-18 03:32:58 +00:00
virtual int64_t get_recv_bytes();
virtual int64_t get_send_bytes();
public:
// Set the input default ack size. This is generally set by the message from peer,
// but for some encoder, it never send the ack message while it default to a none zone size.
// This will cause the encoder to block after publishing some messages to server,
// because it wait for server to send acknowledge, but server default to 0 which means no need
// to ack encoder. We can change the default input ack size. We will always response the
// ack size whatever the encoder set or not.
virtual srs_error_t set_in_window_ack_size(int ack_size);
public:
/**
2017-03-25 09:21:39 +00:00
* 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 srs_error_t recv_message(SrsCommonMessage** pmsg);
/**
2017-03-25 09:21:39 +00:00
* 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 srs_error_t decode_message(SrsCommonMessage* msg, SrsPacket** ppacket);
/**
2017-03-25 09:21:39 +00:00
* 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 srs_error_t send_and_free_message(SrsSharedPtrMessage* msg, int stream_id);
/**
2017-03-25 09:21:39 +00:00
* 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 srs_error_t send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, int stream_id);
/**
2017-03-25 09:21:39 +00:00
* 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 srs_error_t send_and_free_packet(SrsPacket* packet, int stream_id);
public:
/**
2015-06-13 08:04:59 +00:00
* expect a specified message, drop others util got specified one.
* @pmsg, user must free it. NULL if not success.
* @ppacket, user must free it, which decode from payload of message. NULL if not success.
* @remark, only when success, user can use and must free the pmsg and ppacket.
* for example:
* SrsCommonMessage* msg = NULL;
* SrsConnectAppResPacket* pkt = NULL;
* if ((ret = protocol->expect_message<SrsConnectAppResPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) {
* return ret;
* }
* // use then free msg and pkt
* srs_freep(msg);
* srs_freep(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>
srs_error_t expect_message(SrsCommonMessage** pmsg, T** ppacket)
{
*pmsg = NULL;
*ppacket = NULL;
srs_error_t err = srs_success;
while (true) {
SrsCommonMessage* msg = NULL;
if ((err = recv_message(&msg)) != srs_success) {
return srs_error_wrap(err, "recv message");
}
SrsPacket* packet = NULL;
if ((err = decode_message(msg, &packet)) != srs_success) {
srs_freep(msg);
srs_freep(packet);
return srs_error_wrap(err, "decode message");
}
T* pkt = dynamic_cast<T*>(packet);
if (!pkt) {
srs_freep(msg);
srs_freep(packet);
continue;
}
*pmsg = msg;
*ppacket = pkt;
break;
}
return err;
}
private:
/**
2017-03-25 09:21:39 +00:00
* send out the messages, donot free it,
* the caller must free the param msgs.
*/
virtual srs_error_t do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs);
/**
2017-03-25 09:21:39 +00:00
* send iovs. send multiple times if exceed limits.
*/
virtual srs_error_t do_iovs_send(iovec* iovs, int size);
/**
2017-03-25 09:21:39 +00:00
* underlayer api for send and free packet.
*/
virtual srs_error_t do_send_and_free_packet(SrsPacket* packet, int stream_id);
/**
2017-03-25 09:21:39 +00:00
* use simple algorithm to send the header and bytes.
* @remark, for do_send_and_free_packet to send.
*/
virtual srs_error_t do_simple_send(SrsMessageHeader* mh, char* payload, int size);
/**
2017-03-25 09:21:39 +00:00
* imp for decode_message
*/
virtual srs_error_t do_decode_message(SrsMessageHeader& header, SrsBuffer* stream, SrsPacket** ppacket);
/**
2017-03-25 09:21:39 +00:00
* 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 srs_error_t recv_interlaced_message(SrsCommonMessage** pmsg);
/**
2017-03-25 09:21:39 +00:00
* read the chunk basic header(fmt, cid) from chunk stream.
* user can discovery a SrsChunkStream by cid.
*/
virtual srs_error_t read_basic_header(char& fmt, int& cid);
/**
2017-03-25 09:21:39 +00:00
* read the chunk message header(timestamp, payload_length, message_type, stream_id)
* from chunk stream and save to SrsChunkStream.
*/
virtual srs_error_t read_message_header(SrsChunkStream* chunk, char fmt);
/**
2017-03-25 09:21:39 +00:00
* read the chunk payload, remove the used bytes in buffer,
* if got entire message, set the pmsg.
*/
virtual srs_error_t read_message_payload(SrsChunkStream* chunk, SrsCommonMessage** pmsg);
/**
2017-03-25 09:21:39 +00:00
* when recv message, update the context.
*/
virtual srs_error_t on_recv_message(SrsCommonMessage* msg);
/**
2017-03-25 09:21:39 +00:00
* when message sentout, update the context.
*/
virtual srs_error_t on_send_packet(SrsMessageHeader* mh, SrsPacket* packet);
2013-11-23 03:36:07 +00:00
private:
2014-07-06 12:43:05 +00:00
/**
2017-03-25 09:21:39 +00:00
* auto response the ack message.
*/
virtual srs_error_t response_acknowledgement_message();
2014-07-06 12:43:05 +00:00
/**
2017-03-25 09:21:39 +00:00
* auto response the ping message.
*/
virtual srs_error_t response_ping_message(int32_t timestamp);
private:
virtual void print_debug_info();
2013-11-23 03:36:07 +00:00
};
/**
2015-06-13 08:04:59 +00:00
* incoming chunk stream maybe interlaced,
* use the chunk stream to cache the input RTMP chunk streams.
*/
class SrsChunkStream
{
public:
/**
2015-06-13 08:04:59 +00:00
* represents the basic header fmt,
* which used to identify the variant message header type.
*/
char fmt;
/**
2015-06-13 08:04:59 +00:00
* represents the basic header cid,
* which is the chunk stream id.
*/
int cid;
/**
2015-06-13 08:04:59 +00:00
* cached message header
*/
SrsMessageHeader header;
/**
2015-06-13 08:04:59 +00:00
* whether the chunk message header has extended timestamp.
*/
bool extended_timestamp;
/**
2015-06-13 08:04:59 +00:00
* partially read message.
*/
SrsCommonMessage* msg;
/**
2015-06-13 08:04:59 +00:00
* decoded msg count, to identify whether the chunk stream is fresh.
*/
int64_t msg_count;
public:
SrsChunkStream(int _cid);
virtual ~SrsChunkStream();
};
2015-06-13 08:04:59 +00:00
/**
* the original request from client.
*/
class SrsRequest
{
public:
// client ip.
std::string ip;
public:
/**
* tcUrl: rtmp://request_vhost:port/app/stream
* support pass vhost in query string, such as:
* rtmp://ip:port/app?vhost=request_vhost/stream
* rtmp://ip:port/app...vhost...request_vhost/stream
*/
std::string tcUrl;
std::string pageUrl;
std::string swfUrl;
double objectEncoding;
// data discovery from request.
public:
// discovery from tcUrl and play/publish.
std::string schema;
// the vhost in tcUrl.
std::string vhost;
// the host in tcUrl.
std::string host;
// the port in tcUrl.
2015-09-24 10:33:07 +00:00
int port;
2015-06-13 08:04:59 +00:00
// the app in tcUrl, without param.
std::string app;
// the param in tcUrl(app).
std::string param;
// the stream in play/publish
std::string stream;
// for play live stream,
// used to specified the stop when exceed the duration.
2015-11-11 02:37:50 +00:00
// @see https://github.com/ossrs/srs/issues/45
2015-06-13 08:04:59 +00:00
// in ms.
double duration;
// the token in the connect request,
// used for edge traverse to origin authentication,
2015-11-11 02:37:50 +00:00
// @see https://github.com/ossrs/srs/issues/104
2015-06-13 08:04:59 +00:00
SrsAmf0Object* args;
public:
SrsRequest();
virtual ~SrsRequest();
public:
/**
* deep copy the request, for source to use it to support reload,
* for when initialize the source, the request is valid,
* when reload it, the request maybe invalid, so need to copy it.
*/
virtual SrsRequest* copy();
/**
* update the auth info of request,
* to keep the current request ptr is ok,
* for many components use the ptr of request.
*/
virtual void update_auth(SrsRequest* req);
/**
* get the stream identify, vhost/app/stream.
*/
virtual std::string get_stream_url();
/**
* strip url, user must strip when update the url.
*/
virtual void strip();
public:
// Transform it as HTTP request.
virtual SrsRequest* as_http();
2015-06-13 08:04:59 +00:00
};
/**
* the response to client.
*/
class SrsResponse
{
public:
/**
* the stream id to response client createStream.
*/
int stream_id;
public:
SrsResponse();
virtual ~SrsResponse();
};
/**
* the rtmp client type.
*/
enum SrsRtmpConnType
{
SrsRtmpConnUnknown,
SrsRtmpConnPlay,
SrsRtmpConnFMLEPublish,
SrsRtmpConnFlashPublish,
SrsRtmpConnHaivisionPublish,
2015-06-13 08:04:59 +00:00
};
std::string srs_client_type_string(SrsRtmpConnType type);
bool srs_client_type_is_publish(SrsRtmpConnType type);
2015-06-13 08:04:59 +00:00
/**
* store the handshake bytes,
* for smart switch between complex and simple handshake.
*/
class SrsHandshakeBytes
{
public:
// [1+1536]
char* c0c1;
// [1+1536+1536]
char* s0s1s2;
// [1536]
char* c2;
public:
SrsHandshakeBytes();
virtual ~SrsHandshakeBytes();
public:
virtual srs_error_t read_c0c1(ISrsProtocolReadWriter* io);
virtual srs_error_t read_s0s1s2(ISrsProtocolReadWriter* io);
virtual srs_error_t read_c2(ISrsProtocolReadWriter* io);
virtual srs_error_t create_c0c1();
virtual srs_error_t create_s0s1s2(const char* c1 = NULL);
virtual srs_error_t create_c2();
2015-06-13 08:04:59 +00:00
};
2017-02-28 11:46:09 +00:00
/**
* The information return from RTMP server.
*/
struct SrsServerInfo
{
std::string ip;
std::string sig;
int pid;
int cid;
int major;
int minor;
int revision;
int build;
SrsServerInfo();
};
2015-06-13 08:04:59 +00:00
/**
* implements the client role protocol.
*/
class SrsRtmpClient
{
private:
SrsHandshakeBytes* hs_bytes;
protected:
SrsProtocol* protocol;
ISrsProtocolReadWriter* io;
2015-06-13 08:04:59 +00:00
public:
SrsRtmpClient(ISrsProtocolReadWriter* skt);
2015-06-13 08:04:59 +00:00
virtual ~SrsRtmpClient();
// protocol methods proxy
2015-06-13 08:04:59 +00:00
public:
2019-04-17 00:31:53 +00:00
virtual void set_recv_timeout(srs_utime_t tm);
2019-04-17 00:18:37 +00:00
virtual void set_send_timeout(srs_utime_t tm);
2015-06-13 08:04:59 +00:00
virtual int64_t get_recv_bytes();
virtual int64_t get_send_bytes();
virtual srs_error_t recv_message(SrsCommonMessage** pmsg);
virtual srs_error_t decode_message(SrsCommonMessage* msg, SrsPacket** ppacket);
virtual srs_error_t send_and_free_message(SrsSharedPtrMessage* msg, int stream_id);
virtual srs_error_t send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, int stream_id);
virtual srs_error_t send_and_free_packet(SrsPacket* packet, int stream_id);
2015-06-13 08:04:59 +00:00
public:
/**
* handshake with server, try complex, then simple handshake.
*/
virtual srs_error_t handshake();
2015-06-13 08:04:59 +00:00
/**
* only use simple handshake
*/
virtual srs_error_t simple_handshake();
2015-06-13 08:04:59 +00:00
/**
* only use complex handshake
*/
virtual srs_error_t complex_handshake();
2015-06-13 08:04:59 +00:00
/**
2017-02-28 11:46:09 +00:00
* Connect to RTMP tcUrl and app, get the server info.
2015-06-13 08:04:59 +00:00
*
2017-02-28 11:46:09 +00:00
* @param app, The app to connect at, for example, live.
* @param tcUrl, The tcUrl to connect at, for example, rtmp://ossrs.net/live.
2015-06-13 08:04:59 +00:00
* @param req, the optional req object, use the swfUrl/pageUrl if specified. NULL to ignore.
2017-05-13 13:47:20 +00:00
* @param dsu, Whether debug SRS upnode. For edge, set to true to send its info to upnode.
* @param si, The server information, retrieve from response of connect app request. NULL to ignore.
2015-06-13 08:04:59 +00:00
*/
virtual srs_error_t connect_app(std::string app, std::string tcUrl, SrsRequest* r, bool dsu, SrsServerInfo* si);
2015-06-13 08:04:59 +00:00
/**
* create a stream, then play/publish data over this stream.
*/
virtual srs_error_t create_stream(int& stream_id);
2015-06-13 08:04:59 +00:00
/**
* start play stream.
*/
virtual srs_error_t play(std::string stream, int stream_id, int chunk_size);
2015-06-13 08:04:59 +00:00
/**
* start publish stream. use flash publish workflow:
* connect-app => create-stream => flash-publish
*/
virtual srs_error_t publish(std::string stream, int stream_id, int chunk_size);
2015-06-13 08:04:59 +00:00
/**
* start publish stream. use FMLE publish workflow:
* connect-app => FMLE publish
*/
virtual srs_error_t fmle_publish(std::string stream, int& stream_id);
2015-06-13 08:04:59 +00:00
public:
/**
* expect a specified message, drop others util got specified one.
* @pmsg, user must free it. NULL if not success.
* @ppacket, user must free it, which decode from payload of message. NULL if not success.
* @remark, only when success, user can use and must free the pmsg and ppacket.
* for example:
* SrsCommonMessage* msg = NULL;
* SrsConnectAppResPacket* pkt = NULL;
* if ((ret = client->expect_message<SrsConnectAppResPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) {
* return ret;
* }
* // use then free msg and pkt
* srs_freep(msg);
* srs_freep(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>
srs_error_t expect_message(SrsCommonMessage** pmsg, T** ppacket)
2015-06-13 08:04:59 +00:00
{
return protocol->expect_message<T>(pmsg, ppacket);
}
};
/**
* the rtmp provices rtmp-command-protocol services,
* a high level protocol, media stream oriented services,
* such as connect to vhost/app, play stream, get audio/video data.
*/
class SrsRtmpServer
{
private:
SrsHandshakeBytes* hs_bytes;
SrsProtocol* protocol;
ISrsProtocolReadWriter* io;
2015-06-13 08:04:59 +00:00
public:
SrsRtmpServer(ISrsProtocolReadWriter* skt);
2015-06-13 08:04:59 +00:00
virtual ~SrsRtmpServer();
// protocol methods proxy
2015-06-13 08:04:59 +00:00
public:
/**
* set the auto response message when recv for protocol stack.
* @param v, whether auto response message when recv message.
2015-11-11 02:37:50 +00:00
* @see: https://github.com/ossrs/srs/issues/217
2015-06-13 08:04:59 +00:00
*/
virtual void set_auto_response(bool v);
#ifdef SRS_PERF_MERGED_READ
/**
* 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.
2015-11-11 02:37:50 +00:00
* @see https://github.com/ossrs/srs/issues/241
2015-06-13 08:04:59 +00:00
*/
virtual void set_merge_read(bool v, IMergeReadHandler* handler);
/**
* create buffer with specifeid size.
* @param buffer the size of buffer.
* @remark when MR(SRS_PERF_MERGED_READ) disabled, always set to 8K.
* @remark when buffer changed, the previous ptr maybe invalid.
2015-11-11 02:37:50 +00:00
* @see https://github.com/ossrs/srs/issues/241
2015-06-13 08:04:59 +00:00
*/
virtual void set_recv_buffer(int buffer_size);
#endif
/**
2019-04-17 00:31:53 +00:00
* set/get the recv timeout in srs_utime_t.
2015-06-13 08:04:59 +00:00
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
*/
2019-04-17 00:31:53 +00:00
virtual void set_recv_timeout(srs_utime_t tm);
virtual srs_utime_t get_recv_timeout();
2015-06-13 08:04:59 +00:00
/**
2019-04-17 00:18:37 +00:00
* set/get the send timeout in srs_utime_t.
2015-06-13 08:04:59 +00:00
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
*/
2019-04-17 00:18:37 +00:00
virtual void set_send_timeout(srs_utime_t tm);
2019-04-17 00:23:15 +00:00
virtual srs_utime_t get_send_timeout();
2015-06-13 08:04:59 +00:00
/**
* get recv/send bytes.
*/
virtual int64_t get_recv_bytes();
virtual int64_t get_send_bytes();
/**
* 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 srs_error_t recv_message(SrsCommonMessage** pmsg);
2015-06-13 08:04:59 +00:00
/**
* 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 srs_error_t decode_message(SrsCommonMessage* msg, SrsPacket** ppacket);
2015-06-13 08:04:59 +00:00
/**
* 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 srs_error_t send_and_free_message(SrsSharedPtrMessage* msg, int stream_id);
2015-06-13 08:04:59 +00:00
/**
* 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.
*
* @remark performance issue, to support 6k+ 250kbps client,
2015-11-11 02:37:50 +00:00
* @see https://github.com/ossrs/srs/issues/194
2015-06-13 08:04:59 +00:00
*/
virtual srs_error_t send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, int stream_id);
2015-06-13 08:04:59 +00:00
/**
* 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 srs_error_t send_and_free_packet(SrsPacket* packet, int stream_id);
2015-06-13 08:04:59 +00:00
public:
/**
* handshake with client, try complex then simple.
*/
virtual srs_error_t handshake();
2015-06-13 08:04:59 +00:00
/**
* do connect app with client, to discovery tcUrl.
*/
virtual srs_error_t connect_app(SrsRequest* req);
2015-06-13 08:04:59 +00:00
/**
* set output ack size to client, client will send ack-size for each ack window
2015-06-13 08:04:59 +00:00
*/
virtual srs_error_t set_window_ack_size(int ack_size);
// Set the default input ack size value.
virtual srs_error_t set_in_window_ack_size(int ack_size);
2015-06-13 08:04:59 +00:00
/**
* @type: The sender can mark this message hard (0), soft (1), or dynamic (2)
* using the Limit type field.
*/
virtual srs_error_t set_peer_bandwidth(int bandwidth, int type);
2015-06-13 08:04:59 +00:00
/**
* @param server_ip the ip of server.
*/
virtual srs_error_t response_connect_app(SrsRequest* req, const char* server_ip = NULL);
/**
* redirect the connection to another rtmp server.
* @param the hostname or ip of target.
* @param whether the client accept the redirect.
*/
virtual srs_error_t redirect(SrsRequest* r, std::string host, int port, bool& accepted);
2015-06-13 08:04:59 +00:00
/**
* reject the connect app request.
*/
virtual void response_connect_reject(SrsRequest* req, const char* desc);
/**
* response client the onBWDone message.
*/
virtual srs_error_t on_bw_done();
2015-06-13 08:04:59 +00:00
/**
* recv some message to identify the client.
* @stream_id, client will createStream to play or publish by flash,
* the stream_id used to response the createStream request.
* @type, output the client type.
* @stream_name, output the client publish/play stream name. @see: SrsRequest.stream
* @duration, output the play client duration. @see: SrsRequest.duration
*/
virtual srs_error_t identify_client(int stream_id, SrsRtmpConnType& type, std::string& stream_name, double& duration);
2015-06-13 08:04:59 +00:00
/**
* set the chunk size when client type identified.
*/
virtual srs_error_t set_chunk_size(int chunk_size);
2015-06-13 08:04:59 +00:00
/**
* when client type is play, response with packets:
* StreamBegin,
* onStatus(NetStream.Play.Reset), onStatus(NetStream.Play.Start).,
* |RtmpSampleAccess(false, false),
* onStatus(NetStream.Data.Start).
*/
virtual srs_error_t start_play(int stream_id);
2015-06-13 08:04:59 +00:00
/**
* when client(type is play) send pause message,
* if is_pause, response the following packets:
* onStatus(NetStream.Pause.Notify)
* StreamEOF
* if not is_pause, response the following packets:
* onStatus(NetStream.Unpause.Notify)
* StreamBegin
*/
virtual srs_error_t on_play_client_pause(int stream_id, bool is_pause);
2015-06-13 08:04:59 +00:00
/**
* when client type is publish, response with packets:
* releaseStream response
* FCPublish
* FCPublish response
* createStream response
* onFCPublish(NetStream.Publish.Start)
* onStatus(NetStream.Publish.Start)
*/
virtual srs_error_t start_fmle_publish(int stream_id);
/**
* For encoder of Haivision, response the startup request.
* @see https://github.com/ossrs/srs/issues/844
*/
virtual srs_error_t start_haivision_publish(int stream_id);
2015-06-13 08:04:59 +00:00
/**
* process the FMLE unpublish event.
* @unpublish_tid the unpublish request transaction id.
*/
virtual srs_error_t fmle_unpublish(int stream_id, double unpublish_tid);
2015-06-13 08:04:59 +00:00
/**
* when client type is publish, response with packets:
* onStatus(NetStream.Publish.Start)
*/
virtual srs_error_t start_flash_publish(int stream_id);
2015-06-13 08:04:59 +00:00
public:
/**
* expect a specified message, drop others util got specified one.
* @pmsg, user must free it. NULL if not success.
* @ppacket, user must free it, which decode from payload of message. NULL if not success.
* @remark, only when success, user can use and must free the pmsg and ppacket.
* for example:
* SrsCommonMessage* msg = NULL;
* SrsConnectAppResPacket* pkt = NULL;
* if ((ret = server->expect_message<SrsConnectAppResPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
2015-06-13 08:04:59 +00:00
* return ret;
* }
* // use then free msg and pkt
* srs_freep(msg);
* srs_freep(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>
srs_error_t expect_message(SrsCommonMessage** pmsg, T** ppacket)
2015-06-13 08:04:59 +00:00
{
return protocol->expect_message<T>(pmsg, ppacket);
}
private:
virtual srs_error_t identify_create_stream_client(SrsCreateStreamPacket* req, int stream_id, SrsRtmpConnType& type, std::string& stream_name, double& duration);
virtual srs_error_t identify_fmle_publish_client(SrsFMLEStartPacket* req, SrsRtmpConnType& type, std::string& stream_name);
virtual srs_error_t identify_haivision_publish_client(SrsFMLEStartPacket* req, SrsRtmpConnType& type, std::string& stream_name);
virtual srs_error_t identify_flash_publish_client(SrsPublishPacket* req, SrsRtmpConnType& type, std::string& stream_name);
2015-06-13 08:04:59 +00:00
private:
virtual srs_error_t identify_play_client(SrsPlayPacket* req, SrsRtmpConnType& type, std::string& stream_name, double& duration);
2015-06-13 08:04:59 +00:00
};
2013-11-23 03:36:07 +00:00
/**
2017-03-25 09:21:39 +00:00
* 4.1.1. connect
* The client sends the connect command to the server to request
* connection to a server application instance.
*/
2013-11-23 03:36:07 +00:00
class SrsConnectAppPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of the command. Set to "connect".
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Always set to 1.
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
/**
2017-03-25 09:21:39 +00:00
* 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.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Object* command_object;
/**
2017-03-25 09:21:39 +00:00
* Any optional information
* @remark, optional, init to and maybe NULL.
*/
SrsAmf0Object* args;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsConnectAppPacket();
virtual ~SrsConnectAppPacket();
// decode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2013-11-29 07:07:05 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-29 07:07:05 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* response for SrsConnectAppPacket.
*/
2013-11-23 03:36:07 +00:00
class SrsConnectAppResPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* _result or _error; indicates whether the response is result or error.
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Transaction ID is 1 for call connect responses
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name-value pairs that describe the properties(fmsver etc.) of the connection.
* @remark, never be NULL.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Object* props;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name-value pairs that describe the response from|the server. 'code',
* 'level', 'description' are names of few among such information.
* @remark, never be NULL.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Object* info;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsConnectAppResPacket();
virtual ~SrsConnectAppResPacket();
// decode functions for concrete packet to override.
2013-11-29 07:07:05 +00:00
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* 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:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of the remote procedure that is called.
*/
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* If a response is expected we give a transaction Id. Else we pass a value of 0
*/
double transaction_id;
/**
2017-03-25 09:21:39 +00:00
* 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;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* 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 srs_error_t decode(SrsBuffer* 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 srs_error_t encode_packet(SrsBuffer* stream);
};
/**
2017-03-25 09:21:39 +00:00
* response for SrsCallPacket.
*/
class SrsCallResPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of the command.
*/
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* ID of the command, to which the response belongs to
*/
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* 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;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* 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 srs_error_t encode_packet(SrsBuffer* stream);
};
2013-11-23 03:36:07 +00:00
/**
2017-03-25 09:21:39 +00:00
* 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.
*/
2013-11-23 03:36:07 +00:00
class SrsCreateStreamPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of the command. Set to "createStream".
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Transaction ID of the command.
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* If there exists any command info this is set, else this is set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Any* command_object; // null
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsCreateStreamPacket();
virtual ~SrsCreateStreamPacket();
// decode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2013-11-29 08:52:24 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-29 08:52:24 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* response for SrsCreateStreamPacket.
*/
2013-11-23 03:36:07 +00:00
class SrsCreateStreamResPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* _result or _error; indicates whether the response is result or error.
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* ID of the command that response belongs to.
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* If there exists any command info this is set, else this is set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Any* command_object; // null
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* The return value is either a stream ID or an error information object.
*/
2014-03-18 03:32:58 +00:00
double stream_id;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsCreateStreamResPacket(double _transaction_id, double _stream_id);
virtual ~SrsCreateStreamResPacket();
// decode functions for concrete packet to override.
2013-11-29 08:52:24 +00:00
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* client close stream packet.
*/
class SrsCloseStreamPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of the command, set to "closeStream".
*/
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Transaction ID set to 0.
*/
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* 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 srs_error_t decode(SrsBuffer* stream);
};
2013-11-23 03:36:07 +00:00
/**
2017-04-15 12:46:00 +00:00
* FMLE start publish: ReleaseStream/PublishStream/FCPublish/FCUnpublish
2017-03-25 09:21:39 +00:00
*/
2013-11-23 03:36:07 +00:00
class SrsFMLEStartPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of the command
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* the transaction ID to get the response.
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* If there exists any command info this is set, else this is set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Any* command_object; // null
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* the stream name to start publish or release.
*/
2014-03-18 03:32:58 +00:00
std::string stream_name;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsFMLEStartPacket();
virtual ~SrsFMLEStartPacket();
// decode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
// factory method to create specified FMLE packet.
public:
2014-03-18 03:32:58 +00:00
static SrsFMLEStartPacket* create_release_stream(std::string stream);
static SrsFMLEStartPacket* create_FC_publish(std::string stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* response for SrsFMLEStartPacket.
*/
2013-11-23 03:36:07 +00:00
class SrsFMLEStartResPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of the command
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* the transaction ID to get the response.
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* If there exists any command info this is set, else this is set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Any* command_object; // null
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* the optional args, set to undefined.
* @remark, never be NULL, an AMF0 undefined instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Any* args; // undefined
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsFMLEStartResPacket(double _transaction_id);
virtual ~SrsFMLEStartResPacket();
// decode functions for concrete packet to override.
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* 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.
*/
2013-11-23 03:36:07 +00:00
class SrsPublishPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of the command, set to "publish".
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Transaction ID set to 0.
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Command information object does not exist. Set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Any* command_object; // null
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name with which the stream is published.
*/
2014-03-18 03:32:58 +00:00
std::string stream_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Type of publishing. Set to "live", "record", or "append".
* record: The stream is published and the data is recorded to a new file.The file
* is stored on the server in a subdirectory within the directory that
* contains the server application. If the file already exists, it is
* overwritten.
* append: The stream is published and the data is appended to a file. If no file
* is found, it is created.
* live: Live data is published without recording it in a file.
* @remark, SRS only support live.
* @remark, optional, default to live.
*/
2014-03-18 03:32:58 +00:00
std::string type;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsPublishPacket();
virtual ~SrsPublishPacket();
// decode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2013-11-29 08:52:24 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-29 08:52:24 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* 4.2.8. pause
* The client sends the pause command to tell the server to pause or
* start playing.
*/
2013-11-23 03:36:07 +00:00
class SrsPausePacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of the command, set to "pause".
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* There is no transaction ID for this command. Set to 0.
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Command information object does not exist. Set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Any* command_object; // null
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* true or false, to indicate pausing or resuming play
*/
2014-03-18 03:32:58 +00:00
bool is_pause;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Number of milliseconds at which the the stream is paused or play resumed.
* This is the current stream time at the Client when stream was paused. When the
* playback is resumed, the server will only send messages with timestamps
* greater than this value.
*/
2014-03-18 03:32:58 +00:00
double time_ms;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsPausePacket();
virtual ~SrsPausePacket();
// decode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual srs_error_t decode(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* 4.2.1. play
* The client sends this command to the server to play a stream.
*/
2013-11-23 03:36:07 +00:00
class SrsPlayPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of the command. Set to "play".
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Transaction ID set to 0.
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Command information does not exist. Set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Any* command_object; // null
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of the stream to play.
* To play video (FLV) files, specify the name of the stream without a file
* extension (for example, "sample").
* To play back MP3 or ID3 tags, you must precede the stream name with mp3:
* (for example, "mp3:sample".)
* To play H.264/AAC files, you must precede the stream name with mp4: and specify the
* file extension. For example, to play the file sample.m4v, specify
* "mp4:sample.m4v"
*/
2014-03-18 03:32:58 +00:00
std::string stream_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* An optional parameter that specifies the start time in seconds.
* The default value is -2, which means the subscriber first tries to play the live
* stream specified in the Stream Name field. If a live stream of that name is
* not found, it plays the recorded stream specified in the Stream Name field.
* If you pass -1 in the Start field, only the live stream specified in the Stream
* Name field is played.
* If you pass 0 or a positive number in the Start field, a recorded stream specified
* in the Stream Name field is played beginning from the time specified in the
* Start field.
* If no recorded stream is found, the next item in the playlist is played.
*/
2014-03-18 03:32:58 +00:00
double start;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* An optional parameter that specifies the duration of playback in seconds.
* The default value is -1. The -1 value means a live stream is played until it is no
* longer available or a recorded stream is played until it ends.
* If u pass 0, it plays the single frame since the time specified in the Start field
* from the beginning of a recorded stream. It is assumed that the value specified
* in the Start field is equal to or greater than 0.
* If you pass a positive number, it plays a live stream for the time period specified
* in the Duration field. After that it becomes available or plays a recorded
* stream for the time specified in the Duration field. (If a stream ends before the
* time specified in the Duration field, playback ends when the stream ends.)
* If you pass a negative number other than -1 in the Duration field, it interprets the
* value as if it were -1.
*/
2014-03-18 03:32:58 +00:00
double duration;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* An optional Boolean value or number that specifies whether to flush any
* previous playlist.
*/
2014-03-18 03:32:58 +00:00
bool reset;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsPlayPacket();
virtual ~SrsPlayPacket();
// decode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2013-11-29 08:52:24 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-29 08:52:24 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
2013-11-23 03:36:07 +00:00
/**
2017-03-25 09:21:39 +00:00
* response for SrsPlayPacket.
* @remark, user must set the stream_id in header.
*/
2013-11-23 03:36:07 +00:00
class SrsPlayResPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of the command. If the play command is successful, the command
* name is set to onStatus.
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Transaction ID set to 0.
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Command information does not exist. Set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Any* command_object; // null
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* If the play command is successful, the client receives OnStatus message from
* server which is NetStream.Play.Start. If the specified stream is not found,
* NetStream.Play.StreamNotFound is received.
* @remark, never be NULL, an AMF0 object instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Object* desc;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsPlayResPacket();
virtual ~SrsPlayResPacket();
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* when bandwidth test done, notice client.
*/
2013-11-23 03:36:07 +00:00
class SrsOnBWDonePacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of command. Set to "onBWDone"
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Transaction ID set to 0.
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Command information does not exist. Set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Any* args; // null
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsOnBWDonePacket();
virtual ~SrsOnBWDonePacket();
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* onStatus command, AMF0 Call
* @remark, user must set the stream_id by SrsCommonMessage.set_packet().
*/
2013-11-23 03:36:07 +00:00
class SrsOnStatusCallPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of command. Set to "onStatus"
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Transaction ID set to 0.
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Command information does not exist. Set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Any* args; // null
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name-value pairs that describe the response from the server.
* 'code','level', 'description' are names of few among such information.
* @remark, never be NULL, an AMF0 object instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Object* data;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsOnStatusCallPacket();
virtual ~SrsOnStatusCallPacket();
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* the special packet for the bandwidth test.
* actually, it's a SrsOnStatusCallPacket, but
* 1. encode with data field, to send data to client.
* 2. decode ignore the data field, donot care.
*/
class SrsBandwidthPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of command.
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Transaction ID set to 0.
*/
2014-03-18 03:32:58 +00:00
double transaction_id;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Command information does not exist. Set to null type.
* @remark, never be NULL, an AMF0 null instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Any* args; // null
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name-value pairs that describe the response from the server.
* 'code','level', 'description' are names of few among such information.
* @remark, never be NULL, an AMF0 object instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Object* data;
public:
2014-03-18 03:32:58 +00:00
SrsBandwidthPacket();
virtual ~SrsBandwidthPacket();
// decode functions for concrete packet to override.
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
// help function for bandwidth packet.
public:
virtual bool is_start_play();
2014-03-18 03:32:58 +00:00
virtual bool is_starting_play();
virtual bool is_stop_play();
2014-03-18 03:32:58 +00:00
virtual bool is_stopped_play();
virtual bool is_start_publish();
2014-03-18 03:32:58 +00:00
virtual bool is_starting_publish();
virtual bool is_stop_publish();
2014-03-18 03:32:58 +00:00
virtual bool is_stopped_publish();
virtual bool is_finish();
virtual bool is_final();
2014-03-18 03:32:58 +00:00
static SrsBandwidthPacket* create_start_play();
static SrsBandwidthPacket* create_starting_play();
2014-03-18 03:32:58 +00:00
static SrsBandwidthPacket* create_playing();
static SrsBandwidthPacket* create_stop_play();
static SrsBandwidthPacket* create_stopped_play();
2014-03-18 03:32:58 +00:00
static SrsBandwidthPacket* create_start_publish();
static SrsBandwidthPacket* create_starting_publish();
static SrsBandwidthPacket* create_publishing();
2014-03-18 03:32:58 +00:00
static SrsBandwidthPacket* create_stop_publish();
static SrsBandwidthPacket* create_stopped_publish();
static SrsBandwidthPacket* create_finish();
static SrsBandwidthPacket* create_final();
private:
2014-03-18 03:32:58 +00:00
virtual SrsBandwidthPacket* set_command(std::string command);
};
2013-11-23 03:36:07 +00:00
/**
2017-03-25 09:21:39 +00:00
* onStatus data, AMF0 Data
* @remark, user must set the stream_id by SrsCommonMessage.set_packet().
*/
2013-11-23 03:36:07 +00:00
class SrsOnStatusDataPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of command. Set to "onStatus"
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name-value pairs that describe the response from the server.
* 'code', are names of few among such information.
* @remark, never be NULL, an AMF0 object instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Object* data;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsOnStatusDataPacket();
virtual ~SrsOnStatusDataPacket();
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* AMF0Data RtmpSampleAccess
* @remark, user must set the stream_id by SrsCommonMessage.set_packet().
*/
2013-11-23 03:36:07 +00:00
class SrsSampleAccessPacket : public SrsPacket
{
public:
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of command. Set to "|RtmpSampleAccess".
*/
2014-03-18 03:32:58 +00:00
std::string command_name;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* whether allow access the sample of video.
* @see: https://github.com/ossrs/srs/issues/49
* @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#videoSampleAccess
*/
2014-03-18 03:32:58 +00:00
bool video_sample_access;
2014-07-06 12:17:02 +00:00
/**
2017-03-25 09:21:39 +00:00
* whether allow access the sample of audio.
* @see: https://github.com/ossrs/srs/issues/49
* @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#audioSampleAccess
*/
2014-03-18 03:32:58 +00:00
bool audio_sample_access;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsSampleAccessPacket();
virtual ~SrsSampleAccessPacket();
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* the stream metadata.
* FMLE: @setDataFrame
* others: onMetaData
*/
2013-11-23 03:36:07 +00:00
class SrsOnMetaDataPacket : public SrsPacket
{
public:
2014-07-06 12:26:05 +00:00
/**
2017-03-25 09:21:39 +00:00
* Name of metadata. Set to "onMetaData"
*/
2014-03-18 03:32:58 +00:00
std::string name;
2014-07-06 12:26:05 +00:00
/**
2017-03-25 09:21:39 +00:00
* Metadata of stream.
* @remark, never be NULL, an AMF0 object instance.
*/
2014-03-18 03:32:58 +00:00
SrsAmf0Object* metadata;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsOnMetaDataPacket();
virtual ~SrsOnMetaDataPacket();
// decode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* 5.5. Window Acknowledgement Size (5)
* The client or the server sends this message to inform the peer which
* window size to use when sending acknowledgment.
*/
2013-11-23 03:36:07 +00:00
class SrsSetWindowAckSizePacket : public SrsPacket
{
public:
2014-03-18 03:32:58 +00:00
int32_t ackowledgement_window_size;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsSetWindowAckSizePacket();
virtual ~SrsSetWindowAckSizePacket();
// decode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* 5.3. Acknowledgement (3)
* The client or the server sends the acknowledgment to the peer after
* receiving bytes equal to the window size.
*/
2013-11-23 03:36:07 +00:00
class SrsAcknowledgementPacket : public SrsPacket
{
public:
uint32_t sequence_number;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsAcknowledgementPacket();
virtual ~SrsAcknowledgementPacket();
// decode functions for concrete packet to override.
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* 7.1. Set Chunk Size
* Protocol control message 1, Set Chunk Size, is used to notify the
* peer about the new maximum chunk size.
*/
2013-11-23 03:36:07 +00:00
class SrsSetChunkSizePacket : public SrsPacket
{
public:
2014-07-06 12:26:05 +00:00
/**
2017-03-25 09:21:39 +00:00
* The maximum chunk size can be 65536 bytes. The chunk size is
* maintained independently for each direction.
*/
2014-03-18 03:32:58 +00:00
int32_t chunk_size;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsSetChunkSizePacket();
virtual ~SrsSetChunkSizePacket();
// decode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
// 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,
};
2013-11-23 03:36:07 +00:00
/**
2017-03-25 09:21:39 +00:00
* 5.6. Set Peer Bandwidth (6)
* The client or the server sends this message to update the output
* bandwidth of the peer.
*/
2013-11-23 03:36:07 +00:00
class SrsSetPeerBandwidthPacket : public SrsPacket
{
public:
2014-03-18 03:32:58 +00:00
int32_t bandwidth;
// @see: SrsPeerBandwidthType
2014-03-18 03:32:58 +00:00
int8_t type;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsSetPeerBandwidthPacket();
virtual ~SrsSetPeerBandwidthPacket();
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
// 3.7. User Control message
enum SrcPCUCEventType
{
// generally, 4bytes event-data
/**
2017-03-25 09:21:39 +00:00
* The server sends this event to notify the client
* that a stream has become functional and can be
* used for communication. By default, this event
* is sent on ID 0 after the application connect
* command is successfully received from the
* client. The event data is 4-byte and represents
* the stream ID of the stream that became
* functional.
*/
2017-01-16 07:47:26 +00:00
SrcPCUCStreamBegin = 0x00,
2017-03-25 09:21:39 +00:00
/**
2017-03-25 09:21:39 +00:00
* The server sends this event to notify the client
* that the playback of data is over as requested
* on this stream. No more data is sent without
* issuing additional commands. The client discards
* the messages received for the stream. The
* 4 bytes of event data represent the ID of the
* stream on which playback has ended.
*/
2017-01-16 07:47:26 +00:00
SrcPCUCStreamEOF = 0x01,
2017-03-25 09:21:39 +00:00
/**
2017-03-25 09:21:39 +00:00
* The server sends this event to notify the client
* that there is no more data on the stream. If the
* server does not detect any message for a time
* period, it can notify the subscribed clients
* that the stream is dry. The 4 bytes of event
* data represent the stream ID of the dry stream.
*/
2017-01-16 07:47:26 +00:00
SrcPCUCStreamDry = 0x02,
2017-03-25 09:21:39 +00:00
/**
2017-03-25 09:21:39 +00:00
* The client sends this event to inform the server
* of the buffer size (in milliseconds) that is
* used to buffer any data coming over a stream.
* This event is sent before the server starts
* processing the stream. The first 4 bytes of the
* event data represent the stream ID and the next
* 4 bytes represent the buffer length, in
* milliseconds.
*/
2017-01-16 07:47:26 +00:00
SrcPCUCSetBufferLength = 0x03, // 8bytes event-data
2017-03-25 09:21:39 +00:00
/**
2017-03-25 09:21:39 +00:00
* The server sends this event to notify the client
* that the stream is a recorded stream. The
* 4 bytes event data represent the stream ID of
* the recorded stream.
*/
2017-01-16 07:47:26 +00:00
SrcPCUCStreamIsRecorded = 0x04,
2017-03-25 09:21:39 +00:00
/**
2017-03-25 09:21:39 +00:00
* The server sends this event to test whether the
* client is reachable. Event data is a 4-byte
* timestamp, representing the local server time
* when the server dispatched the command. The
* client responds with kMsgPingResponse on
* receiving kMsgPingRequest.
*/
2017-01-16 07:47:26 +00:00
SrcPCUCPingRequest = 0x06,
2017-03-25 09:21:39 +00:00
/**
2017-03-25 09:21:39 +00:00
* The client sends this event to the server in
* response to the ping request. The event data is
* a 4-byte timestamp, which was received with the
* kMsgPingRequest request.
*/
2017-01-16 07:47:26 +00:00
SrcPCUCPingResponse = 0x07,
/**
2017-03-04 06:29:17 +00:00
* For PCUC size=3, for example the payload is "00 1A 01",
* it's a FMS control event, where the event type is 0x001a and event data is 0x01,
* please notice that the event data is only 1 byte for this event.
*/
2017-01-16 07:47:26 +00:00
SrsPCUCFmsEvent0 = 0x1a,
2013-11-23 03:36:07 +00:00
};
/**
2017-03-25 09:21:39 +00:00
* 5.4. User Control Message (4)
*
* for the EventData is 4bytes.
* Stream Begin(=0) 4-bytes stream ID
* Stream EOF(=1) 4-bytes stream ID
* StreamDry(=2) 4-bytes stream ID
* SetBufferLength(=3) 8-bytes 4bytes stream ID, 4bytes buffer length.
* StreamIsRecorded(=4) 4-bytes stream ID
* PingRequest(=6) 4-bytes timestamp local server time
* PingResponse(=7) 4-bytes timestamp received ping request.
*
* 3.7. User Control message
* +------------------------------+-------------------------
* | Event Type ( 2- bytes ) | Event Data
* +------------------------------+-------------------------
* Figure 5 Pay load for the 'User Control Message'.
*/
2013-11-23 03:36:07 +00:00
class SrsUserControlPacket : public SrsPacket
{
public:
2014-07-06 12:26:05 +00:00
/**
2017-03-25 09:21:39 +00:00
* Event type is followed by Event data.
* @see: SrcPCUCEventType
*/
2014-03-18 03:32:58 +00:00
int16_t event_type;
/**
* the event data generally in 4bytes.
* @remark for event type is 0x001a, only 1bytes.
* @see SrsPCUCFmsEvent0
*/
2014-03-18 03:32:58 +00:00
int32_t event_data;
/**
2017-03-25 09:21:39 +00:00
* 4bytes if event_type is SetBufferLength; otherwise 0.
*/
2014-03-18 03:32:58 +00:00
int32_t extra_data;
2013-11-23 03:36:07 +00:00
public:
2014-03-18 03:32:58 +00:00
SrsUserControlPacket();
virtual ~SrsUserControlPacket();
// decode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual srs_error_t decode(SrsBuffer* stream);
// encode functions for concrete packet to override.
2013-11-23 03:36:07 +00:00
public:
virtual int get_prefer_cid();
2014-03-18 03:32:58 +00:00
virtual int get_message_type();
2013-11-23 03:36:07 +00:00
protected:
2014-03-18 03:32:58 +00:00
virtual int get_size();
virtual srs_error_t encode_packet(SrsBuffer* stream);
2013-11-23 03:36:07 +00:00
};
#endif
2014-08-02 14:18:39 +00:00