2013-11-23 03:36:07 +00:00
|
|
|
|
/*
|
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
|
2014-01-01 02:37:12 +00:00
|
|
|
|
Copyright (c) 2013-2014 winlin
|
2013-11-23 03:36:07 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2014-03-01 06:09:22 +00:00
|
|
|
|
#ifndef SRS_RTMP_PROTOCOL_RTMP_STACK_HPP
|
|
|
|
|
#define SRS_RTMP_PROTOCOL_RTMP_STACK_HPP
|
2013-11-23 03:36:07 +00:00
|
|
|
|
|
|
|
|
|
/*
|
2014-03-01 05:39:27 +00:00
|
|
|
|
#include <srs_protocol_rtmp_stack.hpp>
|
2013-11-23 03:36:07 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2014-03-01 02:42:55 +00:00
|
|
|
|
#include <srs_kernel_log.hpp>
|
2014-03-01 02:30:16 +00:00
|
|
|
|
#include <srs_kernel_error.hpp>
|
2014-04-07 01:07:12 +00:00
|
|
|
|
|
|
|
|
|
class ISrsProtocolReaderWriter;
|
|
|
|
|
class SrsBuffer;
|
|
|
|
|
class SrsPacket;
|
|
|
|
|
class SrsStream;
|
|
|
|
|
class SrsAmf0Object;
|
|
|
|
|
class SrsAmf0Any;
|
2014-04-29 05:39:16 +00:00
|
|
|
|
class SrsMessageHeader;
|
2014-04-29 06:44:07 +00:00
|
|
|
|
class SrsMessage;
|
|
|
|
|
class SrsChunkStream;
|
2014-03-19 08:30:43 +00:00
|
|
|
|
|
2014-01-01 11:58:33 +00:00
|
|
|
|
// the following is the timeout for rtmp protocol,
|
|
|
|
|
// to avoid death connection.
|
|
|
|
|
|
|
|
|
|
// the timeout to wait client data,
|
|
|
|
|
// if timeout, close the connection.
|
2014-02-11 05:54:05 +00:00
|
|
|
|
#define SRS_SEND_TIMEOUT_US (int64_t)(30*1000*1000LL)
|
2014-01-01 11:58:33 +00:00
|
|
|
|
|
|
|
|
|
// the timeout to send data to client,
|
|
|
|
|
// if timeout, close the connection.
|
2014-02-11 05:54:05 +00:00
|
|
|
|
#define SRS_RECV_TIMEOUT_US (int64_t)(30*1000*1000LL)
|
2014-01-01 11:58:33 +00:00
|
|
|
|
|
2014-04-07 01:07:12 +00:00
|
|
|
|
// the timeout to wait for client control message,
|
|
|
|
|
// if timeout, we generally ignore and send the data to client,
|
|
|
|
|
// generally, it's the pulse time for data seding.
|
|
|
|
|
#define SRS_PULSE_TIMEOUT_US (int64_t)(200*1000LL)
|
2013-11-23 03:36:07 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* max rtmp header size:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
* 1bytes basic header,
|
|
|
|
|
* 11bytes message header,
|
|
|
|
|
* 4bytes timestamp header,
|
2013-11-23 03:36:07 +00:00
|
|
|
|
* that is, 1+11+4=16bytes.
|
|
|
|
|
*/
|
|
|
|
|
#define RTMP_MAX_FMT0_HEADER_SIZE 16
|
|
|
|
|
/**
|
|
|
|
|
* max rtmp header size:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
* 1bytes basic header,
|
|
|
|
|
* 4bytes timestamp header,
|
2013-11-23 03:36:07 +00:00
|
|
|
|
* that is, 1+4=5bytes.
|
|
|
|
|
*/
|
2014-03-31 02:04:44 +00:00
|
|
|
|
// always use fmt0 as cache.
|
|
|
|
|
//#define RTMP_MAX_FMT3_HEADER_SIZE 5
|
2013-11-23 03:36:07 +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.
|
|
|
|
|
*/
|
|
|
|
|
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:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
int ack_window_size;
|
|
|
|
|
int64_t acked_size;
|
|
|
|
|
|
|
|
|
|
AckWindowSize();
|
|
|
|
|
};
|
2013-11-23 03:36:07 +00:00
|
|
|
|
// peer in/out
|
|
|
|
|
private:
|
2014-07-06 12:59:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* underlayer socket object, send/recv bytes.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
ISrsProtocolReaderWriter* skt;
|
|
|
|
|
/**
|
|
|
|
|
* requests sent out, used to build the response.
|
|
|
|
|
* key: transactionId
|
|
|
|
|
* value: the request command name
|
|
|
|
|
*/
|
|
|
|
|
std::map<double, std::string> requests;
|
2013-11-23 03:36:07 +00:00
|
|
|
|
// peer in
|
|
|
|
|
private:
|
2014-07-06 12:59:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* chunk stream to decode RTMP messages.
|
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
std::map<int, SrsChunkStream*> chunk_streams;
|
2014-07-06 12:59:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* bytes buffer cache, recv from skt, provide services for stream.
|
|
|
|
|
*/
|
|
|
|
|
SrsBuffer* in_buffer;
|
|
|
|
|
/**
|
|
|
|
|
* input chunk size, default to 128, set by peer packet.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
int32_t in_chunk_size;
|
2014-07-06 12:59:23 +00:00
|
|
|
|
/**
|
|
|
|
|
* input ack size, when to send the acked packet.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
AckWindowSize in_ack_size;
|
2013-11-23 03:36:07 +00:00
|
|
|
|
// peer out
|
|
|
|
|
private:
|
2014-07-06 12:59:23 +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.
|
|
|
|
|
*/
|
2014-03-31 02:04:44 +00:00
|
|
|
|
char out_header_cache[RTMP_MAX_FMT0_HEADER_SIZE];
|
2014-07-06 12:59:23 +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:
|
|
|
|
|
/**
|
|
|
|
|
* use io to create the protocol stack,
|
|
|
|
|
* @param io, provides io interfaces, user must free it.
|
|
|
|
|
*/
|
|
|
|
|
SrsProtocol(ISrsProtocolReaderWriter* io);
|
|
|
|
|
virtual ~SrsProtocol();
|
|
|
|
|
public:
|
|
|
|
|
/**
|
2014-07-06 12:43:05 +00:00
|
|
|
|
* set/get the recv timeout in us.
|
2014-03-18 03:32:58 +00:00
|
|
|
|
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
|
|
|
|
|
*/
|
|
|
|
|
virtual void set_recv_timeout(int64_t timeout_us);
|
|
|
|
|
virtual int64_t get_recv_timeout();
|
2014-07-06 12:43:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* set/get the send timeout in us.
|
|
|
|
|
* if timeout, recv/send message return ERROR_SOCKET_TIMEOUT.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual void set_send_timeout(int64_t timeout_us);
|
|
|
|
|
virtual int64_t get_send_timeout();
|
2014-07-06 12:43:05 +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();
|
2014-04-29 05:39:16 +00:00
|
|
|
|
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.
|
2014-07-11 06:57:20 +00:00
|
|
|
|
* @remark, drop message when msg is empty or payload length is empty.
|
2014-04-29 05:39:16 +00:00
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
virtual int recv_message(SrsMessage** pmsg);
|
2014-04-29 05:39:16 +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.
|
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
virtual int decode_message(SrsMessage* msg, SrsPacket** ppacket);
|
2014-04-29 05:39:16 +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.
|
2014-05-17 09:53:27 +00:00
|
|
|
|
* @param stream_id, the stream id of packet to send over, 0 for control message.
|
2014-04-29 05:39:16 +00:00
|
|
|
|
*/
|
2014-05-17 09:53:27 +00:00
|
|
|
|
virtual int send_and_free_message(SrsMessage* msg, int stream_id);
|
2014-04-29 05:39:16 +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.
|
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
virtual int send_and_free_packet(SrsPacket* packet, int stream_id);
|
2014-04-29 05:39:16 +00:00
|
|
|
|
private:
|
|
|
|
|
/**
|
2014-06-22 12:01:25 +00:00
|
|
|
|
* send out the message, donot free it, the caller must free the param msg.
|
2014-04-29 05:39:16 +00:00
|
|
|
|
* @param packet the packet of message, NULL for raw message.
|
|
|
|
|
*/
|
2014-06-22 12:01:25 +00:00
|
|
|
|
virtual int do_send_message(SrsMessage* msg, SrsPacket* packet);
|
2014-04-29 05:39:16 +00:00
|
|
|
|
/**
|
2014-04-29 06:44:07 +00:00
|
|
|
|
* imp for decode_message
|
2014-04-29 05:39:16 +00:00
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
virtual int do_decode_message(SrsMessageHeader& header, SrsStream* stream, SrsPacket** ppacket);
|
2014-04-29 05:39:16 +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.
|
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
virtual int recv_interlaced_message(SrsMessage** pmsg);
|
2014-04-29 05:39:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
virtual int read_basic_header(char& fmt, int& cid, int& bh_size);
|
2014-04-29 05:39:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
virtual int read_message_header(SrsChunkStream* chunk, char fmt, int bh_size, int& mh_size);
|
2014-04-29 05:39:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
virtual int read_message_payload(SrsChunkStream* chunk, int bh_size, int mh_size, int& payload_size, SrsMessage** pmsg);
|
2014-04-29 05:39:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* when recv message, update the context.
|
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
virtual int on_recv_message(SrsMessage* msg);
|
2014-04-29 05:39:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* when message sentout, update the context.
|
|
|
|
|
*/
|
2014-07-11 06:57:20 +00:00
|
|
|
|
virtual int on_send_packet(SrsMessage* msg, SrsPacket* packet);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
private:
|
2014-07-06 12:43:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* auto response the ack message.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int response_acknowledgement_message();
|
2014-07-06 12:43:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* auto response the ping message.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int response_ping_message(int32_t timestamp);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 4.1. Message Header
|
|
|
|
|
*/
|
2014-05-17 06:59:33 +00:00
|
|
|
|
class SrsMessageHeader
|
2013-11-23 03:36:07 +00:00
|
|
|
|
{
|
2014-05-17 06:59:33 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
/**
|
2014-07-10 06:46:58 +00:00
|
|
|
|
* 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.
|
2014-03-18 03:32:58 +00:00
|
|
|
|
*/
|
2014-07-10 06:46:58 +00:00
|
|
|
|
int32_t timestamp_delta;
|
2014-03-18 03:32:58 +00:00
|
|
|
|
/**
|
2014-07-10 06:46:58 +00:00
|
|
|
|
* 3bytes.
|
2014-03-18 03:32:58 +00:00
|
|
|
|
* Three-byte field that represents the size of the payload in bytes.
|
|
|
|
|
* It is set in big-endian format.
|
|
|
|
|
*/
|
|
|
|
|
int32_t payload_length;
|
|
|
|
|
/**
|
2014-07-10 06:46:58 +00:00
|
|
|
|
* 1byte.
|
|
|
|
|
* One byte field to represent the message type. A range of type IDs
|
|
|
|
|
* (1-7) are reserved for protocol control messages.
|
2014-03-18 03:32:58 +00:00
|
|
|
|
*/
|
2014-07-10 06:46:58 +00:00
|
|
|
|
int8_t message_type;
|
2014-03-18 03:32:58 +00:00
|
|
|
|
/**
|
2014-07-10 06:46:58 +00:00
|
|
|
|
* 4bytes.
|
|
|
|
|
* Four-byte field that identifies the stream of the message. These
|
2014-03-18 03:32:58 +00:00
|
|
|
|
* 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;
|
2014-04-29 05:39:16 +00:00
|
|
|
|
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:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsMessageHeader();
|
|
|
|
|
virtual ~SrsMessageHeader();
|
2014-07-06 12:43:05 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
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();
|
2014-04-27 04:28:45 +00:00
|
|
|
|
bool is_ackledgement();
|
2014-03-18 03:32:58 +00:00
|
|
|
|
bool is_set_chunk_size();
|
|
|
|
|
bool is_user_control_message();
|
2014-05-29 06:16:34 +00:00
|
|
|
|
bool is_set_peer_bandwidth();
|
2014-05-08 06:33:25 +00:00
|
|
|
|
bool is_aggregate();
|
2014-07-06 12:43:05 +00:00
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* create a amf0 script header, set the size and stream_id.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
void initialize_amf0_script(int size, int stream);
|
2014-07-06 12:43:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* create a audio header, set the size, timestamp and stream_id.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
void initialize_audio(int size, u_int32_t time, int stream);
|
2014-07-06 12:43:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* create a video header, set the size, timestamp and stream_id.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
void initialize_video(int size, u_int32_t time, int stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-04-29 05:39:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* incoming chunk stream maybe interlaced,
|
|
|
|
|
* use the chunk stream to cache the input RTMP chunk streams.
|
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
class SrsChunkStream
|
2014-04-29 05:39:16 +00:00
|
|
|
|
{
|
|
|
|
|
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.
|
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
SrsMessage* msg;
|
2014-04-29 05:39:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* decoded msg count, to identify whether the chunk stream is fresh.
|
|
|
|
|
*/
|
|
|
|
|
int64_t msg_count;
|
|
|
|
|
public:
|
2014-04-29 06:44:07 +00:00
|
|
|
|
SrsChunkStream(int _cid);
|
|
|
|
|
virtual ~SrsChunkStream();
|
2014-04-29 05:39:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
2014-05-02 04:29:56 +00:00
|
|
|
|
*
|
|
|
|
|
* @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.
|
2014-04-29 05:39:16 +00:00
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
class SrsMessage
|
2014-04-29 05:39:16 +00:00
|
|
|
|
{
|
|
|
|
|
// 4.1. Message Header
|
|
|
|
|
public:
|
|
|
|
|
SrsMessageHeader header;
|
|
|
|
|
// 4.2. Message Payload
|
|
|
|
|
public:
|
|
|
|
|
/**
|
2014-07-10 06:46:58 +00:00
|
|
|
|
* current message parsed size,
|
|
|
|
|
* size <= header.payload_length
|
|
|
|
|
* for the payload maybe sent in multiple chunks.
|
2014-04-29 05:39:16 +00:00
|
|
|
|
*/
|
|
|
|
|
int32_t size;
|
2014-07-10 06:46:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2014-04-29 05:39:16 +00:00
|
|
|
|
int8_t* payload;
|
2014-05-02 04:29:56 +00:00
|
|
|
|
protected:
|
2014-04-29 06:44:07 +00:00
|
|
|
|
SrsMessage();
|
2014-05-02 04:29:56 +00:00
|
|
|
|
public:
|
2014-04-29 06:44:07 +00:00
|
|
|
|
virtual ~SrsMessage();
|
2014-04-29 05:39:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-05-02 04:29:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* the common message used free the payload in common way.
|
|
|
|
|
*/
|
|
|
|
|
class SrsCommonMessage : public SrsMessage
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SrsCommonMessage();
|
|
|
|
|
virtual ~SrsCommonMessage();
|
|
|
|
|
};
|
|
|
|
|
|
2014-04-29 05:39:16 +00:00
|
|
|
|
/**
|
|
|
|
|
* shared ptr message.
|
|
|
|
|
* for audio/video/data message that need less memory copy.
|
|
|
|
|
* and only for output.
|
2014-07-06 10:23:14 +00:00
|
|
|
|
*
|
|
|
|
|
* create first object by constructor and create(),
|
|
|
|
|
* use copy if need reference count message.
|
|
|
|
|
*
|
|
|
|
|
* Usage:
|
|
|
|
|
* SrsSharedPtrMessage msg;
|
|
|
|
|
*
|
2014-04-29 05:39:16 +00:00
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
class SrsSharedPtrMessage : public SrsMessage
|
2014-04-29 05:39:16 +00:00
|
|
|
|
{
|
|
|
|
|
private:
|
2014-05-17 06:59:33 +00:00
|
|
|
|
class __SrsSharedPtr
|
2014-04-29 05:39:16 +00:00
|
|
|
|
{
|
2014-05-17 06:59:33 +00:00
|
|
|
|
public:
|
2014-04-29 05:39:16 +00:00
|
|
|
|
char* payload;
|
|
|
|
|
int size;
|
|
|
|
|
int shared_count;
|
|
|
|
|
|
|
|
|
|
__SrsSharedPtr();
|
|
|
|
|
virtual ~__SrsSharedPtr();
|
|
|
|
|
};
|
|
|
|
|
__SrsSharedPtr* ptr;
|
|
|
|
|
public:
|
2014-04-29 06:44:07 +00:00
|
|
|
|
SrsSharedPtrMessage();
|
|
|
|
|
virtual ~SrsSharedPtrMessage();
|
2014-04-29 05:39:16 +00:00
|
|
|
|
public:
|
|
|
|
|
/**
|
2014-07-06 10:23:14 +00:00
|
|
|
|
* 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.
|
2014-04-29 05:39:16 +00:00
|
|
|
|
*/
|
2014-07-06 10:23:14 +00:00
|
|
|
|
virtual int create(SrsMessageHeader* pheader, char* payload, int size);
|
2014-04-29 05:39:16 +00:00
|
|
|
|
/**
|
2014-07-06 10:23:14 +00:00
|
|
|
|
* 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.
|
2014-04-29 05:39:16 +00:00
|
|
|
|
*/
|
2014-07-06 10:23:14 +00:00
|
|
|
|
virtual int count();
|
2014-04-29 05:39:16 +00:00
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* copy current shared ptr message, use ref-count.
|
2014-07-06 10:23:14 +00:00
|
|
|
|
* @remark, assert object is created.
|
2014-04-29 05:39:16 +00:00
|
|
|
|
*/
|
2014-04-29 06:44:07 +00:00
|
|
|
|
virtual SrsSharedPtrMessage* copy();
|
2014-04-29 05:39:16 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-11-23 03:36:07 +00:00
|
|
|
|
/**
|
|
|
|
|
* the decoded message payload.
|
|
|
|
|
* @remark we seperate the packet from message,
|
2014-03-18 03:32:58 +00:00
|
|
|
|
* 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.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
*/
|
|
|
|
|
class SrsPacket
|
|
|
|
|
{
|
2014-03-18 03:32:58 +00:00
|
|
|
|
public:
|
|
|
|
|
SrsPacket();
|
|
|
|
|
virtual ~SrsPacket();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
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.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* subpacket must override to decode packet from stream.
|
|
|
|
|
* @remark never invoke the super.decode, it always failed.
|
|
|
|
|
*/
|
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-07-06 11:06:25 +00:00
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
/**
|
|
|
|
|
* subpacket must override to provide the right message type.
|
2014-07-06 11:06:25 +00:00
|
|
|
|
* the message type set the RTMP message type in header.
|
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
|
|
|
|
/**
|
|
|
|
|
* 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);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* Always set to 1.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
double transaction_id;
|
2014-05-02 04:44:38 +00:00
|
|
|
|
/**
|
2014-07-06 12:17:02 +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.
|
2014-05-02 04:44:38 +00:00
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAmf0Object* command_object;
|
2014-06-21 03:41:00 +00:00
|
|
|
|
/**
|
|
|
|
|
* Any optional information
|
|
|
|
|
*/
|
|
|
|
|
SrsAmf0Object* args;
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsConnectAppPacket();
|
|
|
|
|
virtual ~SrsConnectAppPacket();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-29 07:07:05 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* response for SrsConnectAppPacket.
|
|
|
|
|
*/
|
|
|
|
|
class SrsConnectAppResPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
/**
|
|
|
|
|
* Name-value pairs that describe the properties(fmsver etc.) of the connection.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAmf0Object* props;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Name-value pairs that describe the response from|the server. ‘code’,
|
|
|
|
|
* ‘level’, ‘description’ are names of few among such information.
|
|
|
|
|
*/
|
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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-11-29 07:07:05 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
2014-06-28 08:43:57 +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
|
|
|
|
/**
|
|
|
|
|
* Name of the remote procedure that is called.
|
|
|
|
|
*/
|
2014-06-28 08:43:57 +00:00
|
|
|
|
std::string command_name;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* If a response is expected we give a transaction Id. Else we pass a value of 0
|
|
|
|
|
*/
|
2014-06-28 08:43:57 +00:00
|
|
|
|
double transaction_id;
|
|
|
|
|
/**
|
|
|
|
|
* If there exists any command info this
|
|
|
|
|
* is set, else this is set to null type.
|
|
|
|
|
*/
|
|
|
|
|
SrsAmf0Any* command_object;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Any optional arguments to be provided
|
|
|
|
|
*/
|
2014-06-28 08:43:57 +00:00
|
|
|
|
SrsAmf0Any* arguments;
|
|
|
|
|
public:
|
|
|
|
|
SrsCallPacket();
|
|
|
|
|
virtual ~SrsCallPacket();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2014-06-28 08:43:57 +00:00
|
|
|
|
public:
|
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2014-06-28 08:43:57 +00:00
|
|
|
|
public:
|
|
|
|
|
virtual int get_perfer_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:
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Name of the command.
|
|
|
|
|
*/
|
2014-06-28 08:43:57 +00:00
|
|
|
|
std::string command_name;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* ID of the command, to which the response belongs to
|
|
|
|
|
*/
|
2014-06-28 08:43:57 +00:00
|
|
|
|
double transaction_id;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* If there exists any command info this is set, else this is set to null type.
|
|
|
|
|
*/
|
2014-06-28 08:43:57 +00:00
|
|
|
|
SrsAmf0Any* command_object;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Response from the method that was called.
|
|
|
|
|
*/
|
2014-06-28 08:43:57 +00:00
|
|
|
|
SrsAmf0Any* response;
|
|
|
|
|
public:
|
|
|
|
|
SrsCallResPacket(double _transaction_id);
|
|
|
|
|
virtual ~SrsCallResPacket();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2014-06-28 08:43:57 +00:00
|
|
|
|
public:
|
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
virtual int get_message_type();
|
|
|
|
|
protected:
|
|
|
|
|
virtual int get_size();
|
|
|
|
|
virtual int encode_packet(SrsStream* stream);
|
|
|
|
|
};
|
|
|
|
|
|
2013-11-23 03:36:07 +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.
|
|
|
|
|
*/
|
|
|
|
|
class SrsCreateStreamPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* Transaction ID of the command.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
double transaction_id;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* If there exists any command info this is set, else this is set to null type.
|
|
|
|
|
*/
|
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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-29 08:52:24 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* response for SrsCreateStreamPacket.
|
|
|
|
|
*/
|
|
|
|
|
class SrsCreateStreamResPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
/**
|
|
|
|
|
* If there exists any command info this is set, else this is set to null type.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAmf0Any* command_object; // null
|
2014-07-06 12:17:02 +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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-11-29 08:52:24 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
2014-06-28 08:43:57 +00:00
|
|
|
|
|
2014-01-11 11:55:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* client close stream packet.
|
|
|
|
|
*/
|
|
|
|
|
class SrsCloseStreamPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Name of the command, set to “closeStream”.
|
|
|
|
|
*/
|
2014-01-11 11:55:55 +00:00
|
|
|
|
std::string command_name;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Transaction ID set to 0.
|
|
|
|
|
*/
|
2014-01-11 11:55:55 +00:00
|
|
|
|
double transaction_id;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Command information object does not exist. Set to null type.
|
|
|
|
|
*/
|
2014-03-08 06:38:19 +00:00
|
|
|
|
SrsAmf0Any* command_object; // null
|
2014-01-11 11:55:55 +00:00
|
|
|
|
public:
|
|
|
|
|
SrsCloseStreamPacket();
|
|
|
|
|
virtual ~SrsCloseStreamPacket();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2014-01-11 11:55:55 +00:00
|
|
|
|
public:
|
|
|
|
|
virtual int decode(SrsStream* stream);
|
|
|
|
|
};
|
2013-11-23 03:36:07 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* FMLE start publish: ReleaseStream/PublishStream
|
|
|
|
|
*/
|
|
|
|
|
class SrsFMLEStartPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
/**
|
|
|
|
|
* If there exists any command info this is set, else this is set to null type.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAmf0Any* command_object; // null
|
2014-07-06 12:17:02 +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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2014-03-02 06:51:19 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
virtual int get_message_type();
|
2014-03-02 06:51:19 +00:00
|
|
|
|
protected:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_size();
|
|
|
|
|
virtual int encode_packet(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// factory method to create specified FMLE packet.
|
2014-03-02 06:51:19 +00:00
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* response for SrsFMLEStartPacket.
|
|
|
|
|
*/
|
|
|
|
|
class SrsFMLEStartResPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
/**
|
|
|
|
|
* If there exists any command info this is set, else this is set to null type.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAmf0Any* command_object; // null
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* the optional args, set to undefined.
|
|
|
|
|
*/
|
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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2014-03-02 06:51:19 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +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.
|
|
|
|
|
*/
|
|
|
|
|
class SrsPublishPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* Transaction ID set to 0.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
double transaction_id;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Command information object does not exist. Set to null type.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAmf0Any* command_object; // null
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* 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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-29 08:52:24 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 4.2.8. pause
|
|
|
|
|
* The client sends the pause command to tell the server to pause or
|
|
|
|
|
* start playing.
|
|
|
|
|
*/
|
|
|
|
|
class SrsPausePacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
/**
|
|
|
|
|
* Command information object does not exist. Set to null type.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAmf0Any* command_object; // null
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* 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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 4.2.1. play
|
|
|
|
|
* The client sends this command to the server to play a stream.
|
|
|
|
|
*/
|
|
|
|
|
class SrsPlayPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* Transaction ID set to 0.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
double transaction_id;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Command information does not exist. Set to null type.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAmf0Any* command_object; // null
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
/**
|
|
|
|
|
* 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
|
|
|
|
/**
|
|
|
|
|
* 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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-29 08:52:24 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
/**
|
|
|
|
|
* response for SrsPlayPacket.
|
|
|
|
|
* @remark, user must set the stream_id in header.
|
|
|
|
|
*/
|
|
|
|
|
class SrsPlayResPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* Transaction ID set to 0.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
double transaction_id;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Command information does not exist. Set to null type.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAmf0Any* command_object; // null
|
2014-07-06 12:17:02 +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.
|
|
|
|
|
*/
|
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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* when bandwidth test done, notice client.
|
|
|
|
|
*/
|
|
|
|
|
class SrsOnBWDonePacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* Transaction ID set to 0.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
double transaction_id;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Command information does not exist. Set to null type.
|
|
|
|
|
*/
|
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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* onStatus command, AMF0 Call
|
|
|
|
|
* @remark, user must set the stream_id by SrsMessage.set_packet().
|
|
|
|
|
*/
|
|
|
|
|
class SrsOnStatusCallPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* Transaction ID set to 0.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
double transaction_id;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Command information does not exist. Set to null type.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAmf0Any* args; // null
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Name-value pairs that describe the response from the server.
|
|
|
|
|
* ‘code’,‘level’, ‘description’ are names of few among such information.
|
|
|
|
|
*/
|
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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-12-22 09:28:29 +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
|
|
|
|
|
{
|
|
|
|
|
private:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
disable_default_copy(SrsBandwidthPacket);
|
2013-12-22 09:28:29 +00:00
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* Transaction ID set to 0.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
double transaction_id;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Command information does not exist. Set to null type.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAmf0Any* args; // null
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
|
|
|
|
* Name-value pairs that describe the response from the server.
|
|
|
|
|
* ‘code’,‘level’, ‘description’ are names of few among such information.
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAmf0Object* data;
|
2013-12-22 09:28:29 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsBandwidthPacket();
|
|
|
|
|
virtual ~SrsBandwidthPacket();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-12-22 09:28:29 +00:00
|
|
|
|
public:
|
2014-07-06 11:06:25 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
|
|
|
|
// encode functions for concrete packet to override.
|
2013-12-22 09:28:29 +00:00
|
|
|
|
public:
|
2014-07-06 11:06:25 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_message_type();
|
2013-12-22 09:28:29 +00:00
|
|
|
|
protected:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_size();
|
|
|
|
|
virtual int encode_packet(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// help function for bandwidth packet.
|
2013-12-22 09:28:29 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual bool is_starting_play();
|
|
|
|
|
virtual bool is_stopped_play();
|
|
|
|
|
virtual bool is_starting_publish();
|
|
|
|
|
virtual bool is_stopped_publish();
|
|
|
|
|
virtual bool is_flash_final();
|
|
|
|
|
static SrsBandwidthPacket* create_finish();
|
|
|
|
|
static SrsBandwidthPacket* create_start_play();
|
|
|
|
|
static SrsBandwidthPacket* create_playing();
|
|
|
|
|
static SrsBandwidthPacket* create_stop_play();
|
|
|
|
|
static SrsBandwidthPacket* create_start_publish();
|
|
|
|
|
static SrsBandwidthPacket* create_stop_publish();
|
2013-12-22 09:28:29 +00:00
|
|
|
|
private:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual SrsBandwidthPacket* set_command(std::string command);
|
2013-12-22 09:28:29 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-11-23 03:36:07 +00:00
|
|
|
|
/**
|
|
|
|
|
* onStatus data, AMF0 Data
|
|
|
|
|
* @remark, user must set the stream_id by SrsMessage.set_packet().
|
|
|
|
|
*/
|
|
|
|
|
class SrsOnStatusDataPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +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
|
|
|
|
/**
|
|
|
|
|
* Name-value pairs that describe the response from the server.
|
|
|
|
|
* ‘code’, are names of few among such information.
|
|
|
|
|
*/
|
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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* AMF0Data RtmpSampleAccess
|
|
|
|
|
* @remark, user must set the stream_id by SrsMessage.set_packet().
|
|
|
|
|
*/
|
|
|
|
|
class SrsSampleAccessPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
2014-07-06 12:26:05 +00:00
|
|
|
|
* Name of command. Set to "|RtmpSampleAccess".
|
2014-07-06 12:17:02 +00:00
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
std::string command_name;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
2014-07-06 12:26:05 +00:00
|
|
|
|
* whether allow access the sample of video.
|
|
|
|
|
* @see: https://github.com/winlinvip/simple-rtmp-server/issues/49
|
|
|
|
|
* @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#videoSampleAccess
|
2014-07-06 12:17:02 +00:00
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
bool video_sample_access;
|
2014-07-06 12:17:02 +00:00
|
|
|
|
/**
|
2014-07-06 12:26:05 +00:00
|
|
|
|
* whether allow access the sample of audio.
|
|
|
|
|
* @see: https://github.com/winlinvip/simple-rtmp-server/issues/49
|
|
|
|
|
* @see: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/NetStream.html#audioSampleAccess
|
2014-07-06 12:17:02 +00:00
|
|
|
|
*/
|
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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* the stream metadata.
|
|
|
|
|
* FMLE: @setDataFrame
|
|
|
|
|
* others: onMetaData
|
|
|
|
|
*/
|
|
|
|
|
class SrsOnMetaDataPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:26:05 +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
|
|
|
|
/**
|
|
|
|
|
* Metadata of stream.
|
|
|
|
|
*/
|
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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +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.
|
|
|
|
|
*/
|
|
|
|
|
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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +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.
|
|
|
|
|
*/
|
|
|
|
|
class SrsAcknowledgementPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
int32_t sequence_number;
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsAcknowledgementPacket();
|
|
|
|
|
virtual ~SrsAcknowledgementPacket();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +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.
|
|
|
|
|
*/
|
|
|
|
|
class SrsSetChunkSizePacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:26:05 +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();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 5.6. Set Peer Bandwidth (6)
|
|
|
|
|
* The client or the server sends this message to update the output
|
|
|
|
|
* bandwidth of the peer.
|
|
|
|
|
*/
|
|
|
|
|
class SrsSetPeerBandwidthPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
int32_t bandwidth;
|
|
|
|
|
int8_t type;
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsSetPeerBandwidthPacket();
|
|
|
|
|
virtual ~SrsSetPeerBandwidthPacket();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 3.7. User Control message
|
|
|
|
|
enum SrcPCUCEventType
|
|
|
|
|
{
|
2014-07-06 12:34:11 +00:00
|
|
|
|
// generally, 4bytes event-data
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
SrcPCUCStreamBegin = 0x00,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
SrcPCUCStreamEOF = 0x01,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
SrcPCUCStreamDry = 0x02,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
SrcPCUCSetBufferLength = 0x03, // 8bytes event-data
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
SrcPCUCStreamIsRecorded = 0x04,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
SrcPCUCPingRequest = 0x06,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
SrcPCUCPingResponse = 0x07,
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
2014-07-06 12:26:05 +00:00
|
|
|
|
* 5.4. User Control Message (4)
|
|
|
|
|
*
|
2013-11-23 03:36:07 +00:00
|
|
|
|
* for the EventData is 4bytes.
|
2014-07-06 12:26:05 +00:00
|
|
|
|
* 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.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
*
|
|
|
|
|
* 3.7. User Control message
|
|
|
|
|
* +------------------------------+-------------------------
|
|
|
|
|
* | Event Type ( 2- bytes ) | Event Data
|
|
|
|
|
* +------------------------------+-------------------------
|
|
|
|
|
* Figure 5 Pay load for the ‘User Control Message’.
|
|
|
|
|
*/
|
|
|
|
|
class SrsUserControlPacket : public SrsPacket
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-07-06 12:26:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* Event type is followed by Event data.
|
|
|
|
|
* @see: SrcPCUCEventType
|
|
|
|
|
*/
|
2014-03-18 03:32:58 +00:00
|
|
|
|
int16_t event_type;
|
|
|
|
|
int32_t event_data;
|
|
|
|
|
/**
|
|
|
|
|
* 4bytes if event_type is SetBufferLength; otherwise 0.
|
|
|
|
|
*/
|
|
|
|
|
int32_t extra_data;
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsUserControlPacket();
|
|
|
|
|
virtual ~SrsUserControlPacket();
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// decode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int decode(SrsStream* stream);
|
2014-07-06 11:06:25 +00:00
|
|
|
|
// encode functions for concrete packet to override.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
virtual int get_perfer_cid();
|
|
|
|
|
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 int encode_packet(SrsStream* stream);
|
2013-11-23 03:36:07 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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.
|
2014-03-01 04:43:04 +00:00
|
|
|
|
* for example:
|
2014-03-18 03:32:58 +00:00
|
|
|
|
SrsCommonMessage* msg = NULL;
|
|
|
|
|
SrsConnectAppResPacket* pkt = NULL;
|
|
|
|
|
if ((ret = srs_rtmp_expect_message<SrsConnectAppResPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
// use pkt
|
2014-03-01 04:43:04 +00:00
|
|
|
|
* user should never recv message and convert it, use this method instead.
|
|
|
|
|
* if need to set timeout, use set timeout of SrsProtocol.
|
2013-11-23 03:36:07 +00:00
|
|
|
|
*/
|
|
|
|
|
template<class T>
|
2014-05-02 04:45:42 +00:00
|
|
|
|
int srs_rtmp_expect_message(SrsProtocol* protocol, SrsMessage** pmsg, T** ppacket)
|
2014-04-29 05:39:16 +00:00
|
|
|
|
{
|
|
|
|
|
*pmsg = NULL;
|
|
|
|
|
*ppacket = NULL;
|
|
|
|
|
|
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
while (true) {
|
2014-04-29 06:44:07 +00:00
|
|
|
|
SrsMessage* msg = NULL;
|
|
|
|
|
if ((ret = protocol->recv_message(&msg)) != ERROR_SUCCESS) {
|
2014-04-29 05:39:16 +00:00
|
|
|
|
srs_error("recv message failed. ret=%d", ret);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
srs_verbose("recv message success.");
|
|
|
|
|
|
|
|
|
|
SrsPacket* packet = NULL;
|
2014-04-29 06:44:07 +00:00
|
|
|
|
if ((ret = protocol->decode_message(msg, &packet)) != ERROR_SUCCESS) {
|
2014-04-29 05:39:16 +00:00
|
|
|
|
srs_error("decode message failed. ret=%d", ret);
|
|
|
|
|
srs_freep(msg);
|
2014-05-02 04:49:11 +00:00
|
|
|
|
srs_freep(packet);
|
2014-04-29 05:39:16 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
T* pkt = dynamic_cast<T*>(packet);
|
|
|
|
|
if (!pkt) {
|
2014-05-04 03:11:51 +00:00
|
|
|
|
srs_info("drop message(type=%d, size=%d, time=%"PRId64", sid=%d).",
|
2014-04-29 05:39:16 +00:00
|
|
|
|
msg->header.message_type, msg->header.payload_length,
|
|
|
|
|
msg->header.timestamp, msg->header.stream_id);
|
|
|
|
|
srs_freep(msg);
|
2014-05-02 04:49:11 +00:00
|
|
|
|
srs_freep(packet);
|
2014-04-29 05:39:16 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*pmsg = msg;
|
|
|
|
|
*ppacket = pkt;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2013-11-23 03:36:07 +00:00
|
|
|
|
|
2014-01-11 11:55:55 +00:00
|
|
|
|
#endif
|