mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
Refine typo in kernel.
This commit is contained in:
parent
735176cab4
commit
35fe05d62c
9 changed files with 1321 additions and 1976 deletions
|
@ -101,7 +101,7 @@
|
||||||
(void)0
|
(void)0
|
||||||
|
|
||||||
// Checking for st(state-threads), only support the following cpus: i386/amd64/x86_64/arm
|
// Checking for st(state-threads), only support the following cpus: i386/amd64/x86_64/arm
|
||||||
// @reamrk to patch ST for arm, read https://github.com/ossrs/state-threads/issues/1
|
// @reamrk To patch ST for arm, read https://github.com/ossrs/state-threads/issues/1
|
||||||
#if !defined(__amd64__) && !defined(__x86_64__) && !defined(__i386__) && !defined(__arm__)
|
#if !defined(__amd64__) && !defined(__x86_64__) && !defined(__i386__) && !defined(__arm__)
|
||||||
#error "only support i386/amd64/x86_64/arm cpu"
|
#error "only support i386/amd64/x86_64/arm cpu"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,9 +35,7 @@
|
||||||
class SrsBuffer;
|
class SrsBuffer;
|
||||||
class ISrsStreamWriter;
|
class ISrsStreamWriter;
|
||||||
|
|
||||||
/**
|
// Transmux the RTMP packets to AAC stream.
|
||||||
* Transmux the RTMP packets to AAC stream.
|
|
||||||
*/
|
|
||||||
class SrsAacTransmuxer
|
class SrsAacTransmuxer
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -51,17 +49,13 @@ public:
|
||||||
SrsAacTransmuxer();
|
SrsAacTransmuxer();
|
||||||
virtual ~SrsAacTransmuxer();
|
virtual ~SrsAacTransmuxer();
|
||||||
public:
|
public:
|
||||||
/**
|
// Initialize the underlayer file stream.
|
||||||
* initialize the underlayer file stream.
|
// @remark User can initialize multiple times to encode multiple aac files.
|
||||||
* @remark user can initialize multiple times to encode multiple aac files.
|
// @remark User must free the fs, aac encoder never close/free it.
|
||||||
* @remark, user must free the fs, aac encoder never close/free it.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t initialize(ISrsStreamWriter* fs);
|
virtual srs_error_t initialize(ISrsStreamWriter* fs);
|
||||||
public:
|
public:
|
||||||
/**
|
// Write audio/video packet.
|
||||||
* write audio/video packet.
|
// @remark The assert data should not be NULL.
|
||||||
* @remark assert data is not NULL.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t write_audio(int64_t timestamp, char* data, int size);
|
virtual srs_error_t write_audio(int64_t timestamp, char* data, int size);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -36,82 +36,72 @@
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// RTMP consts values
|
// RTMP consts values
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// default vhost of rtmp
|
// Default vhost of rtmp
|
||||||
#define SRS_CONSTS_RTMP_DEFAULT_VHOST "__defaultVhost__"
|
#define SRS_CONSTS_RTMP_DEFAULT_VHOST "__defaultVhost__"
|
||||||
#define SRS_CONSTS_RTMP_DEFAULT_APP "__defaultApp__"
|
#define SRS_CONSTS_RTMP_DEFAULT_APP "__defaultApp__"
|
||||||
// default port of rtmp
|
// Default port of rtmp
|
||||||
#define SRS_CONSTS_RTMP_DEFAULT_PORT 1935
|
#define SRS_CONSTS_RTMP_DEFAULT_PORT 1935
|
||||||
|
|
||||||
// the default chunk size for system.
|
// The default chunk size for system.
|
||||||
#define SRS_CONSTS_RTMP_SRS_CHUNK_SIZE 60000
|
#define SRS_CONSTS_RTMP_SRS_CHUNK_SIZE 60000
|
||||||
// 6. Chunking, RTMP protocol default chunk size.
|
// 6. Chunking, RTMP protocol default chunk size.
|
||||||
#define SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE 128
|
#define SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE 128
|
||||||
|
|
||||||
/**
|
// 6. Chunking
|
||||||
* 6. Chunking
|
// The chunk size is configurable. It can be set using a control
|
||||||
* The chunk size is configurable. It can be set using a control
|
// message(Set Chunk Size) as described in section 7.1. The maximum
|
||||||
* message(Set Chunk Size) as described in section 7.1. The maximum
|
// chunk size can be 65536 bytes and minimum 128 bytes. Larger values
|
||||||
* chunk size can be 65536 bytes and minimum 128 bytes. Larger values
|
// reduce CPU usage, but also commit to larger writes that can delay
|
||||||
* reduce CPU usage, but also commit to larger writes that can delay
|
// other content on lower bandwidth connections. Smaller chunks are not
|
||||||
* other content on lower bandwidth connections. Smaller chunks are not
|
// good for high-bit rate streaming. Chunk size is maintained
|
||||||
* good for high-bit rate streaming. Chunk size is maintained
|
// independently for each direction.
|
||||||
* independently for each direction.
|
|
||||||
*/
|
|
||||||
#define SRS_CONSTS_RTMP_MIN_CHUNK_SIZE 128
|
#define SRS_CONSTS_RTMP_MIN_CHUNK_SIZE 128
|
||||||
#define SRS_CONSTS_RTMP_MAX_CHUNK_SIZE 65536
|
#define SRS_CONSTS_RTMP_MAX_CHUNK_SIZE 65536
|
||||||
|
|
||||||
|
|
||||||
// the following is the timeout for rtmp protocol,
|
// The following is the timeout for rtmp protocol,
|
||||||
// to avoid death connection.
|
// to avoid death connection.
|
||||||
|
|
||||||
// the common io timeout, for connect, recv or send.
|
// The common io timeout, for connect, recv or send.
|
||||||
// TODO: FIXME: Maybe change to smaller value, such as 3s?
|
// TODO: FIXME: Maybe change to smaller value, such as 3s?
|
||||||
#define SRS_CONSTS_RTMP_TIMEOUT (30 * SRS_UTIME_SECONDS)
|
#define SRS_CONSTS_RTMP_TIMEOUT (30 * SRS_UTIME_SECONDS)
|
||||||
|
|
||||||
// the timeout to wait for client control message,
|
// The timeout to wait for client control message,
|
||||||
// if timeout, we generally ignore and send the data to client,
|
// if timeout, we generally ignore and send the data to client,
|
||||||
// generally, it's the pulse time for data seding.
|
// generally, it's the pulse time for data seding.
|
||||||
// @remark, recomment to 500ms.
|
// @remark, recomment to 500ms.
|
||||||
#define SRS_CONSTS_RTMP_PULSE (500 * SRS_UTIME_MILLISECONDS)
|
#define SRS_CONSTS_RTMP_PULSE (500 * SRS_UTIME_MILLISECONDS)
|
||||||
|
|
||||||
/**
|
// The max rtmp header size:
|
||||||
* max rtmp header size:
|
// 1bytes basic header,
|
||||||
* 1bytes basic header,
|
// 11bytes message header,
|
||||||
* 11bytes message header,
|
// 4bytes timestamp header,
|
||||||
* 4bytes timestamp header,
|
// that is, 1+11+4=16bytes.
|
||||||
* that is, 1+11+4=16bytes.
|
|
||||||
*/
|
|
||||||
#define SRS_CONSTS_RTMP_MAX_FMT0_HEADER_SIZE 16
|
#define SRS_CONSTS_RTMP_MAX_FMT0_HEADER_SIZE 16
|
||||||
/**
|
// The max rtmp header size:
|
||||||
* max rtmp header size:
|
// 1bytes basic header,
|
||||||
* 1bytes basic header,
|
// 4bytes timestamp header,
|
||||||
* 4bytes timestamp header,
|
// that is, 1+4=5bytes.
|
||||||
* that is, 1+4=5bytes.
|
|
||||||
*/
|
|
||||||
// always use fmt0 as cache.
|
// always use fmt0 as cache.
|
||||||
#define SRS_CONSTS_RTMP_MAX_FMT3_HEADER_SIZE 5
|
#define SRS_CONSTS_RTMP_MAX_FMT3_HEADER_SIZE 5
|
||||||
|
|
||||||
/**
|
// For performance issue,
|
||||||
* for performance issue,
|
// the iovs cache, @see https://github.com/ossrs/srs/issues/194
|
||||||
* the iovs cache, @see https://github.com/ossrs/srs/issues/194
|
// iovs cache for multiple messages for each connections.
|
||||||
* iovs cache for multiple messages for each connections.
|
// suppose the chunk size is 64k, each message send in a chunk which needs only 2 iovec,
|
||||||
* suppose the chunk size is 64k, each message send in a chunk which needs only 2 iovec,
|
// so the iovs max should be (SRS_PERF_MW_MSGS * 2)
|
||||||
* so the iovs max should be (SRS_PERF_MW_MSGS * 2)
|
//
|
||||||
*
|
// @remark, SRS will realloc when the iovs not enough.
|
||||||
* @remark, SRS will realloc when the iovs not enough.
|
|
||||||
*/
|
|
||||||
#define SRS_CONSTS_IOVS_MAX (SRS_PERF_MW_MSGS * 2)
|
#define SRS_CONSTS_IOVS_MAX (SRS_PERF_MW_MSGS * 2)
|
||||||
/**
|
// For performance issue,
|
||||||
* for performance issue,
|
// the c0c3 cache, @see https://github.com/ossrs/srs/issues/194
|
||||||
* the c0c3 cache, @see https://github.com/ossrs/srs/issues/194
|
// c0c3 cache for multiple messages for each connections.
|
||||||
* c0c3 cache for multiple messages for each connections.
|
// each c0 <= 16byes, suppose the chunk size is 64k,
|
||||||
* each c0 <= 16byes, suppose the chunk size is 64k,
|
// each message send in a chunk which needs only a c0 header,
|
||||||
* each message send in a chunk which needs only a c0 header,
|
// so the c0c3 cache should be (SRS_PERF_MW_MSGS * 16)
|
||||||
* so the c0c3 cache should be (SRS_PERF_MW_MSGS * 16)
|
//
|
||||||
*
|
// @remark, SRS will try another loop when c0c3 cache dry, for we cannot realloc it.
|
||||||
* @remark, SRS will try another loop when c0c3 cache dry, for we cannot realloc it.
|
// so we use larger c0c3 cache, that is (SRS_PERF_MW_MSGS * 32)
|
||||||
* so we use larger c0c3 cache, that is (SRS_PERF_MW_MSGS * 32)
|
|
||||||
*/
|
|
||||||
#define SRS_CONSTS_C0C3_HEADERS_MAX (SRS_PERF_MW_MSGS * 32)
|
#define SRS_CONSTS_C0C3_HEADERS_MAX (SRS_PERF_MW_MSGS * 32)
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
|
@ -127,16 +117,16 @@
|
||||||
#define SRS_CONSTS_NULL_FILE "/dev/null"
|
#define SRS_CONSTS_NULL_FILE "/dev/null"
|
||||||
#define SRS_CONSTS_LOCALHOST "127.0.0.1"
|
#define SRS_CONSTS_LOCALHOST "127.0.0.1"
|
||||||
|
|
||||||
// signal defines.
|
// The signal defines.
|
||||||
// reload the config file and apply new config.
|
// To reload the config file and apply new config.
|
||||||
#define SRS_SIGNAL_RELOAD SIGHUP
|
#define SRS_SIGNAL_RELOAD SIGHUP
|
||||||
// reopen the log file.
|
// Reopen the log file.
|
||||||
#define SRS_SIGNAL_REOPEN_LOG SIGUSR1
|
#define SRS_SIGNAL_REOPEN_LOG SIGUSR1
|
||||||
// srs should gracefully quit, do dispose then exit.
|
// The signal for srs to gracefully quit, do dispose then exit.
|
||||||
#define SRS_SIGNAL_GRACEFULLY_QUIT SIGTERM
|
#define SRS_SIGNAL_GRACEFULLY_QUIT SIGTERM
|
||||||
|
|
||||||
// application level signals.
|
// The application level signals.
|
||||||
// persistence the config in memory to config file.
|
// Persistence the config in memory to config file.
|
||||||
// @see https://github.com/ossrs/srs/issues/319#issuecomment-134993922
|
// @see https://github.com/ossrs/srs/issues/319#issuecomment-134993922
|
||||||
// @remark we actually don't handle the signal for it's not a valid os signal.
|
// @remark we actually don't handle the signal for it's not a valid os signal.
|
||||||
#define SRS_SIGNAL_PERSISTENCE_CONFIG 1000
|
#define SRS_SIGNAL_PERSISTENCE_CONFIG 1000
|
||||||
|
@ -149,33 +139,33 @@
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// log consts values
|
// The log consts values
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// downloading speed-up, play to edge, ingest from origin
|
// Downloading speed-up, play to edge, ingest from origin
|
||||||
#define SRS_CONSTS_LOG_EDGE_PLAY "EIG"
|
#define SRS_CONSTS_LOG_EDGE_PLAY "EIG"
|
||||||
// uploading speed-up, publish to edge, foward to origin
|
// Uploading speed-up, publish to edge, foward to origin
|
||||||
#define SRS_CONSTS_LOG_EDGE_PUBLISH "EFW"
|
#define SRS_CONSTS_LOG_EDGE_PUBLISH "EFW"
|
||||||
// edge/origin forwarder.
|
// The edge/origin forwarder.
|
||||||
#define SRS_CONSTS_LOG_FOWARDER "FWR"
|
#define SRS_CONSTS_LOG_FOWARDER "FWR"
|
||||||
// play stream on edge/origin.
|
// Play stream on edge/origin.
|
||||||
#define SRS_CONSTS_LOG_PLAY "PLA"
|
#define SRS_CONSTS_LOG_PLAY "PLA"
|
||||||
// client publish to edge/origin
|
// Client publish to edge/origin
|
||||||
#define SRS_CONSTS_LOG_CLIENT_PUBLISH "CPB"
|
#define SRS_CONSTS_LOG_CLIENT_PUBLISH "CPB"
|
||||||
// web/flash publish to edge/origin
|
// The web/flash publish to edge/origin
|
||||||
#define SRS_CONSTS_LOG_WEB_PUBLISH "WPB"
|
#define SRS_CONSTS_LOG_WEB_PUBLISH "WPB"
|
||||||
// ingester for edge(play)/origin
|
// Ingester for edge(play)/origin
|
||||||
#define SRS_CONSTS_LOG_INGESTER "IGS"
|
#define SRS_CONSTS_LOG_INGESTER "IGS"
|
||||||
// hls log id.
|
// The hls log id.
|
||||||
#define SRS_CONSTS_LOG_HLS "HLS"
|
#define SRS_CONSTS_LOG_HLS "HLS"
|
||||||
// encoder log id.
|
// The encoder log id.
|
||||||
#define SRS_CONSTS_LOG_ENCODER "ENC"
|
#define SRS_CONSTS_LOG_ENCODER "ENC"
|
||||||
// http stream log id.
|
// The http stream log id.
|
||||||
#define SRS_CONSTS_LOG_HTTP_STREAM "HTS"
|
#define SRS_CONSTS_LOG_HTTP_STREAM "HTS"
|
||||||
// http stream cache log id.
|
// The http stream cache log id.
|
||||||
#define SRS_CONSTS_LOG_HTTP_STREAM_CACHE "HTC"
|
#define SRS_CONSTS_LOG_HTTP_STREAM_CACHE "HTC"
|
||||||
// stream caster log id.
|
// The stream caster log id.
|
||||||
#define SRS_CONSTS_LOG_STREAM_CASTER "SCS"
|
#define SRS_CONSTS_LOG_STREAM_CASTER "SCS"
|
||||||
// the nginx exec log id.
|
// The nginx exec log id.
|
||||||
#define SRS_CONSTS_LOG_EXEC "EXE"
|
#define SRS_CONSTS_LOG_EXEC "EXE"
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
|
@ -213,14 +203,14 @@
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// HTTP consts values
|
// HTTP consts values
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
// the default http port.
|
// The default http port.
|
||||||
#define SRS_CONSTS_HTTP_DEFAULT_PORT 80
|
#define SRS_CONSTS_HTTP_DEFAULT_PORT 80
|
||||||
// linux path seprator
|
// The linux path seprator
|
||||||
#define SRS_CONSTS_HTTP_PATH_SEP '/'
|
#define SRS_CONSTS_HTTP_PATH_SEP '/'
|
||||||
// query string seprator
|
// Query string seprator
|
||||||
#define SRS_CONSTS_HTTP_QUERY_SEP '?'
|
#define SRS_CONSTS_HTTP_QUERY_SEP '?'
|
||||||
|
|
||||||
// the default recv timeout.
|
// The default recv timeout.
|
||||||
#define SRS_HTTP_RECV_TIMEOUT (60 * SRS_UTIME_SECONDS)
|
#define SRS_HTTP_RECV_TIMEOUT (60 * SRS_UTIME_SECONDS)
|
||||||
|
|
||||||
// 6.1.1 Status Code and Reason Phrase
|
// 6.1.1 Status Code and Reason Phrase
|
||||||
|
@ -405,7 +395,7 @@
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
#define SRS_CONSTS_KAFKA_DEFAULT_PORT 9092
|
#define SRS_CONSTS_KAFKA_DEFAULT_PORT 9092
|
||||||
|
|
||||||
// the common io timeout, for both recv and send.
|
// The common io timeout, for both recv and send.
|
||||||
#define SRS_CONSTS_KAFKA_TIMEOUT (30 * SRS_UTIME_MILLISECONDS)
|
#define SRS_CONSTS_KAFKA_TIMEOUT (30 * SRS_UTIME_MILLISECONDS)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,13 +28,13 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213
|
// For srs-librtmp, @see https://github.com/ossrs/srs/issues/213
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#define ERROR_SUCCESS 0
|
#define ERROR_SUCCESS 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
// system error.
|
// The system error.
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
#define ERROR_SOCKET_CREATE 1000
|
#define ERROR_SOCKET_CREATE 1000
|
||||||
#define ERROR_SOCKET_SETREUSE 1001
|
#define ERROR_SOCKET_SETREUSE 1001
|
||||||
|
@ -173,18 +173,18 @@
|
||||||
#define ERROR_RTMP_STREAM_NAME_EMPTY 2051
|
#define ERROR_RTMP_STREAM_NAME_EMPTY 2051
|
||||||
#define ERROR_HTTP_HIJACK 2052
|
#define ERROR_HTTP_HIJACK 2052
|
||||||
//
|
//
|
||||||
// system control message,
|
// The system control message,
|
||||||
// not an error, but special control logic.
|
// It's not an error, but special control logic.
|
||||||
//
|
//
|
||||||
// connection is redirect to another server.
|
// When connection is redirect to another server.
|
||||||
#define ERROR_CONTROL_REDIRECT 2997
|
#define ERROR_CONTROL_REDIRECT 2997
|
||||||
// sys ctl: rtmp close stream, support replay.
|
// For sys ctl: rtmp close stream, support replay.
|
||||||
#define ERROR_CONTROL_RTMP_CLOSE 2998
|
#define ERROR_CONTROL_RTMP_CLOSE 2998
|
||||||
// FMLE stop publish and republish.
|
// When FMLE stop publish and republish.
|
||||||
#define ERROR_CONTROL_REPUBLISH 2999
|
#define ERROR_CONTROL_REPUBLISH 2999
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
// application level
|
// The application level errors.
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
#define ERROR_HLS_METADATA 3000
|
#define ERROR_HLS_METADATA 3000
|
||||||
#define ERROR_HLS_DECODE_ERROR 3001
|
#define ERROR_HLS_DECODE_ERROR 3001
|
||||||
|
@ -329,23 +329,23 @@
|
||||||
//#define ERROR_API_METHOD_NOT_ALLOWD
|
//#define ERROR_API_METHOD_NOT_ALLOWD
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
// user-define error.
|
// For user-define error.
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
#define ERROR_USER_START 9000
|
#define ERROR_USER_START 9000
|
||||||
//#define ERROR_USER_DISCONNECT 9001
|
//#define ERROR_USER_DISCONNECT 9001
|
||||||
#define ERROR_SOURCE_NOT_FOUND 9002
|
#define ERROR_SOURCE_NOT_FOUND 9002
|
||||||
#define ERROR_USER_END 9999
|
#define ERROR_USER_END 9999
|
||||||
|
|
||||||
/**
|
// Whether the error code is an system control error.
|
||||||
* whether the error code is an system control error.
|
|
||||||
*/
|
|
||||||
// TODO: FIXME: Remove it from underlayer for confused with error and logger.
|
// TODO: FIXME: Remove it from underlayer for confused with error and logger.
|
||||||
extern bool srs_is_system_control_error(int error_code);
|
extern bool srs_is_system_control_error(int error_code);
|
||||||
extern bool srs_is_system_control_error(srs_error_t err);
|
extern bool srs_is_system_control_error(srs_error_t err);
|
||||||
extern bool srs_is_client_gracefully_close(int error_code);
|
extern bool srs_is_client_gracefully_close(int error_code);
|
||||||
extern bool srs_is_client_gracefully_close(srs_error_t err);
|
extern bool srs_is_client_gracefully_close(srs_error_t err);
|
||||||
|
|
||||||
// Use complex errors, @read https://github.com/ossrs/srs/issues/913
|
// The complex error carries code, message, callstack and instant variables,
|
||||||
|
// which is more strong and easy to locate problem by log,
|
||||||
|
// please @read https://github.com/ossrs/srs/issues/913
|
||||||
class SrsCplxError
|
class SrsCplxError
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213
|
// For srs-librtmp, @see https://github.com/ossrs/srs/issues/213
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -40,19 +40,13 @@ class SrsFileReader;
|
||||||
|
|
||||||
#define SRS_FLV_TAG_HEADER_SIZE 11
|
#define SRS_FLV_TAG_HEADER_SIZE 11
|
||||||
#define SRS_FLV_PREVIOUS_TAG_SIZE 4
|
#define SRS_FLV_PREVIOUS_TAG_SIZE 4
|
||||||
|
// 5. Protocol Control Messages
|
||||||
/****************************************************************************
|
// RTMP reserves message type IDs 1-7 for protocol control messages.
|
||||||
*****************************************************************************
|
// These messages contain information needed by the RTM Chunk Stream
|
||||||
****************************************************************************/
|
// protocol or RTMP itself. Protocol messages with IDs 1 & 2 are
|
||||||
/**
|
// reserved for usage with RTM Chunk Stream protocol. Protocol messages
|
||||||
5. Protocol Control Messages
|
// with IDs 3-6 are reserved for usage of RTMP. Protocol message with ID
|
||||||
RTMP reserves message type IDs 1-7 for protocol control messages.
|
// 7 is used between edge server and origin server.
|
||||||
These messages contain information needed by the RTM Chunk Stream
|
|
||||||
protocol or RTMP itself. Protocol messages with IDs 1 & 2 are
|
|
||||||
reserved for usage with RTM Chunk Stream protocol. Protocol messages
|
|
||||||
with IDs 3-6 are reserved for usage of RTMP. Protocol message with ID
|
|
||||||
7 is used between edge server and origin server.
|
|
||||||
*/
|
|
||||||
#define RTMP_MSG_SetChunkSize 0x01
|
#define RTMP_MSG_SetChunkSize 0x01
|
||||||
#define RTMP_MSG_AbortMessage 0x02
|
#define RTMP_MSG_AbortMessage 0x02
|
||||||
#define RTMP_MSG_Acknowledgement 0x03
|
#define RTMP_MSG_Acknowledgement 0x03
|
||||||
|
@ -60,167 +54,121 @@ class SrsFileReader;
|
||||||
#define RTMP_MSG_WindowAcknowledgementSize 0x05
|
#define RTMP_MSG_WindowAcknowledgementSize 0x05
|
||||||
#define RTMP_MSG_SetPeerBandwidth 0x06
|
#define RTMP_MSG_SetPeerBandwidth 0x06
|
||||||
#define RTMP_MSG_EdgeAndOriginServerCommand 0x07
|
#define RTMP_MSG_EdgeAndOriginServerCommand 0x07
|
||||||
/**
|
// 3. Types of messages
|
||||||
3. Types of messages
|
// The server and the client send messages over the network to
|
||||||
The server and the client send messages over the network to
|
// communicate with each other. The messages can be of any type which
|
||||||
communicate with each other. The messages can be of any type which
|
// includes audio messages, video messages, command messages, shared
|
||||||
includes audio messages, video messages, command messages, shared
|
// object messages, data messages, and user control messages.
|
||||||
object messages, data messages, and user control messages.
|
// 3.1. Command message
|
||||||
3.1. Command message
|
// Command messages carry the AMF-encoded commands between the client
|
||||||
Command messages carry the AMF-encoded commands between the client
|
// and the server. These messages have been assigned message type value
|
||||||
and the server. These messages have been assigned message type value
|
// of 20 for AMF0 encoding and message type value of 17 for AMF3
|
||||||
of 20 for AMF0 encoding and message type value of 17 for AMF3
|
// encoding. These messages are sent to perform some operations like
|
||||||
encoding. These messages are sent to perform some operations like
|
// connect, createStream, publish, play, pause on the peer. Command
|
||||||
connect, createStream, publish, play, pause on the peer. Command
|
// messages like onstatus, result etc. are used to inform the sender
|
||||||
messages like onstatus, result etc. are used to inform the sender
|
// about the status of the requested commands. A command message
|
||||||
about the status of the requested commands. A command message
|
// consists of command name, transaction ID, and command object that
|
||||||
consists of command name, transaction ID, and command object that
|
// contains related parameters. A client or a server can request Remote
|
||||||
contains related parameters. A client or a server can request Remote
|
// Procedure Calls (RPC) over streams that are communicated using the
|
||||||
Procedure Calls (RPC) over streams that are communicated using the
|
// command messages to the peer.
|
||||||
command messages to the peer.
|
|
||||||
*/
|
|
||||||
#define RTMP_MSG_AMF3CommandMessage 17 // 0x11
|
#define RTMP_MSG_AMF3CommandMessage 17 // 0x11
|
||||||
#define RTMP_MSG_AMF0CommandMessage 20 // 0x14
|
#define RTMP_MSG_AMF0CommandMessage 20 // 0x14
|
||||||
/**
|
// 3.2. Data message
|
||||||
3.2. Data message
|
// The client or the server sends this message to send Metadata or any
|
||||||
The client or the server sends this message to send Metadata or any
|
// user data to the peer. Metadata includes details about the
|
||||||
user data to the peer. Metadata includes details about the
|
// data(audio, video etc.) like creation time, duration, theme and so
|
||||||
data(audio, video etc.) like creation time, duration, theme and so
|
// on. These messages have been assigned message type value of 18 for
|
||||||
on. These messages have been assigned message type value of 18 for
|
// AMF0 and message type value of 15 for AMF3.
|
||||||
AMF0 and message type value of 15 for AMF3.
|
|
||||||
*/
|
|
||||||
#define RTMP_MSG_AMF0DataMessage 18 // 0x12
|
#define RTMP_MSG_AMF0DataMessage 18 // 0x12
|
||||||
#define RTMP_MSG_AMF3DataMessage 15 // 0x0F
|
#define RTMP_MSG_AMF3DataMessage 15 // 0x0F
|
||||||
/**
|
// 3.3. Shared object message
|
||||||
3.3. Shared object message
|
// A shared object is a Flash object (a collection of name value pairs)
|
||||||
A shared object is a Flash object (a collection of name value pairs)
|
// that are in synchronization across multiple clients, instances, and
|
||||||
that are in synchronization across multiple clients, instances, and
|
// so on. The message types kMsgContainer=19 for AMF0 and
|
||||||
so on. The message types kMsgContainer=19 for AMF0 and
|
// kMsgContainerEx=16 for AMF3 are reserved for shared object events.
|
||||||
kMsgContainerEx=16 for AMF3 are reserved for shared object events.
|
// Each message can contain multiple events.
|
||||||
Each message can contain multiple events.
|
|
||||||
*/
|
|
||||||
#define RTMP_MSG_AMF3SharedObject 16 // 0x10
|
#define RTMP_MSG_AMF3SharedObject 16 // 0x10
|
||||||
#define RTMP_MSG_AMF0SharedObject 19 // 0x13
|
#define RTMP_MSG_AMF0SharedObject 19 // 0x13
|
||||||
/**
|
// 3.4. Audio message
|
||||||
3.4. Audio message
|
// The client or the server sends this message to send audio data to the
|
||||||
The client or the server sends this message to send audio data to the
|
// peer. The message type value of 8 is reserved for audio messages.
|
||||||
peer. The message type value of 8 is reserved for audio messages.
|
|
||||||
*/
|
|
||||||
#define RTMP_MSG_AudioMessage 8 // 0x08
|
#define RTMP_MSG_AudioMessage 8 // 0x08
|
||||||
/* *
|
// 3.5. Video message
|
||||||
3.5. Video message
|
// The client or the server sends this message to send video data to the
|
||||||
The client or the server sends this message to send video data to the
|
// peer. The message type value of 9 is reserved for video messages.
|
||||||
peer. The message type value of 9 is reserved for video messages.
|
// These messages are large and can delay the sending of other type of
|
||||||
These messages are large and can delay the sending of other type of
|
// messages. To avoid such a situation, the video message is assigned
|
||||||
messages. To avoid such a situation, the video message is assigned
|
// The lowest priority.
|
||||||
the lowest priority.
|
|
||||||
*/
|
|
||||||
#define RTMP_MSG_VideoMessage 9 // 0x09
|
#define RTMP_MSG_VideoMessage 9 // 0x09
|
||||||
/**
|
// 3.6. Aggregate message
|
||||||
3.6. Aggregate message
|
// An aggregate message is a single message that contains a list of submessages.
|
||||||
An aggregate message is a single message that contains a list of submessages.
|
// The message type value of 22 is reserved for aggregate
|
||||||
The message type value of 22 is reserved for aggregate
|
// messages.
|
||||||
messages.
|
|
||||||
*/
|
|
||||||
#define RTMP_MSG_AggregateMessage 22 // 0x16
|
#define RTMP_MSG_AggregateMessage 22 // 0x16
|
||||||
|
// The chunk stream id used for some under-layer message,
|
||||||
/****************************************************************************
|
// For example, the PC(protocol control) message.
|
||||||
*****************************************************************************
|
|
||||||
****************************************************************************/
|
|
||||||
/**
|
|
||||||
* the chunk stream id used for some under-layer message,
|
|
||||||
* for example, the PC(protocol control) message.
|
|
||||||
*/
|
|
||||||
#define RTMP_CID_ProtocolControl 0x02
|
#define RTMP_CID_ProtocolControl 0x02
|
||||||
/**
|
// The AMF0/AMF3 command message, invoke method and return the result, over NetConnection.
|
||||||
* the AMF0/AMF3 command message, invoke method and return the result, over NetConnection.
|
// generally use 0x03.
|
||||||
* generally use 0x03.
|
|
||||||
*/
|
|
||||||
#define RTMP_CID_OverConnection 0x03
|
#define RTMP_CID_OverConnection 0x03
|
||||||
/**
|
// The AMF0/AMF3 command message, invoke method and return the result, over NetConnection,
|
||||||
* the AMF0/AMF3 command message, invoke method and return the result, over NetConnection,
|
// The midst state(we guess).
|
||||||
* the midst state(we guess).
|
// rarely used, e.g. onStatus(NetStream.Play.Reset).
|
||||||
* rarely used, e.g. onStatus(NetStream.Play.Reset).
|
|
||||||
*/
|
|
||||||
#define RTMP_CID_OverConnection2 0x04
|
#define RTMP_CID_OverConnection2 0x04
|
||||||
/**
|
// The stream message(amf0/amf3), over NetStream.
|
||||||
* the stream message(amf0/amf3), over NetStream.
|
// generally use 0x05.
|
||||||
* generally use 0x05.
|
|
||||||
*/
|
|
||||||
#define RTMP_CID_OverStream 0x05
|
#define RTMP_CID_OverStream 0x05
|
||||||
/**
|
// The stream message(amf0/amf3), over NetStream, the midst state(we guess).
|
||||||
* the stream message(amf0/amf3), over NetStream, the midst state(we guess).
|
// rarely used, e.g. play("mp4:mystram.f4v")
|
||||||
* rarely used, e.g. play("mp4:mystram.f4v")
|
|
||||||
*/
|
|
||||||
#define RTMP_CID_OverStream2 0x08
|
#define RTMP_CID_OverStream2 0x08
|
||||||
/**
|
// The stream message(video), over NetStream
|
||||||
* the stream message(video), over NetStream
|
// generally use 0x06.
|
||||||
* generally use 0x06.
|
|
||||||
*/
|
|
||||||
#define RTMP_CID_Video 0x06
|
#define RTMP_CID_Video 0x06
|
||||||
/**
|
// The stream message(audio), over NetStream.
|
||||||
* the stream message(audio), over NetStream.
|
// generally use 0x07.
|
||||||
* generally use 0x07.
|
|
||||||
*/
|
|
||||||
#define RTMP_CID_Audio 0x07
|
#define RTMP_CID_Audio 0x07
|
||||||
|
|
||||||
/**
|
// 6.1. Chunk Format
|
||||||
* 6.1. Chunk Format
|
// Extended timestamp: 0 or 4 bytes
|
||||||
* Extended timestamp: 0 or 4 bytes
|
// This field MUST be sent when the normal timsestamp is set to
|
||||||
* This field MUST be sent when the normal timsestamp is set to
|
// 0xffffff, it MUST NOT be sent if the normal timestamp is set to
|
||||||
* 0xffffff, it MUST NOT be sent if the normal timestamp is set to
|
// anything else. So for values less than 0xffffff the normal
|
||||||
* anything else. So for values less than 0xffffff the normal
|
// timestamp field SHOULD be used in which case the extended timestamp
|
||||||
* timestamp field SHOULD be used in which case the extended timestamp
|
// MUST NOT be present. For values greater than or equal to 0xffffff
|
||||||
* MUST NOT be present. For values greater than or equal to 0xffffff
|
// The normal timestamp field MUST NOT be used and MUST be set to
|
||||||
* the normal timestamp field MUST NOT be used and MUST be set to
|
// 0xffffff and the extended timestamp MUST be sent.
|
||||||
* 0xffffff and the extended timestamp MUST be sent.
|
|
||||||
*/
|
|
||||||
#define RTMP_EXTENDED_TIMESTAMP 0xFFFFFF
|
#define RTMP_EXTENDED_TIMESTAMP 0xFFFFFF
|
||||||
|
|
||||||
/**
|
// 4.1. Message Header
|
||||||
* 4.1. Message Header
|
|
||||||
*/
|
|
||||||
class SrsMessageHeader
|
class SrsMessageHeader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/**
|
// 3bytes.
|
||||||
* 3bytes.
|
// Three-byte field that contains a timestamp delta of the message.
|
||||||
* Three-byte field that contains a timestamp delta of the message.
|
// @remark, only used for decoding message from chunk stream.
|
||||||
* @remark, only used for decoding message from chunk stream.
|
|
||||||
*/
|
|
||||||
int32_t timestamp_delta;
|
int32_t timestamp_delta;
|
||||||
/**
|
// 3bytes.
|
||||||
* 3bytes.
|
// Three-byte field that represents the size of the payload in bytes.
|
||||||
* Three-byte field that represents the size of the payload in bytes.
|
// It is set in big-endian format.
|
||||||
* It is set in big-endian format.
|
|
||||||
*/
|
|
||||||
int32_t payload_length;
|
int32_t payload_length;
|
||||||
/**
|
// 1byte.
|
||||||
* 1byte.
|
// One byte field to represent the message type. A range of type IDs
|
||||||
* One byte field to represent the message type. A range of type IDs
|
// (1-7) are reserved for protocol control messages.
|
||||||
* (1-7) are reserved for protocol control messages.
|
|
||||||
*/
|
|
||||||
int8_t message_type;
|
int8_t message_type;
|
||||||
/**
|
// 4bytes.
|
||||||
* 4bytes.
|
// Four-byte field that identifies the stream of the message. These
|
||||||
* Four-byte field that identifies the stream of the message. These
|
// bytes are set in little-endian format.
|
||||||
* bytes are set in little-endian format.
|
|
||||||
*/
|
|
||||||
int32_t stream_id;
|
int32_t stream_id;
|
||||||
|
|
||||||
/**
|
// Four-byte field that contains a timestamp of the message.
|
||||||
* Four-byte field that contains a timestamp of the message.
|
// The 4 bytes are packed in the big-endian order.
|
||||||
* The 4 bytes are packed in the big-endian order.
|
// @remark, used as calc timestamp when decode and encode time.
|
||||||
* @remark, used as calc timestamp when decode and encode time.
|
// @remark, we use 64bits for large time for jitter detect and hls.
|
||||||
* @remark, we use 64bits for large time for jitter detect and hls.
|
|
||||||
*/
|
|
||||||
int64_t timestamp;
|
int64_t timestamp;
|
||||||
public:
|
public:
|
||||||
/**
|
// Get the perfered cid(chunk stream id) which sendout over.
|
||||||
* get the perfered cid(chunk stream id) which sendout over.
|
// set at decoding, and canbe used for directly send message,
|
||||||
* set at decoding, and canbe used for directly send message,
|
// For example, dispatch to all connections.
|
||||||
* for example, dispatch to all connections.
|
|
||||||
*/
|
|
||||||
int perfer_cid;
|
int perfer_cid;
|
||||||
public:
|
public:
|
||||||
SrsMessageHeader();
|
SrsMessageHeader();
|
||||||
|
@ -239,149 +187,114 @@ public:
|
||||||
bool is_set_peer_bandwidth();
|
bool is_set_peer_bandwidth();
|
||||||
bool is_aggregate();
|
bool is_aggregate();
|
||||||
public:
|
public:
|
||||||
/**
|
// Create a amf0 script header, set the size and stream_id.
|
||||||
* create a amf0 script header, set the size and stream_id.
|
|
||||||
*/
|
|
||||||
void initialize_amf0_script(int size, int stream);
|
void initialize_amf0_script(int size, int stream);
|
||||||
/**
|
// Create a audio header, set the size, timestamp and stream_id.
|
||||||
* create a audio header, set the size, timestamp and stream_id.
|
|
||||||
*/
|
|
||||||
void initialize_audio(int size, uint32_t time, int stream);
|
void initialize_audio(int size, uint32_t time, int stream);
|
||||||
/**
|
// Create a video header, set the size, timestamp and stream_id.
|
||||||
* create a video header, set the size, timestamp and stream_id.
|
|
||||||
*/
|
|
||||||
void initialize_video(int size, uint32_t time, int stream);
|
void initialize_video(int size, uint32_t time, int stream);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// The message is raw data RTMP message, bytes oriented,
|
||||||
* message is raw data RTMP message, bytes oriented,
|
// protcol always recv RTMP message, and can send RTMP message or RTMP packet.
|
||||||
* protcol always recv RTMP message, and can send RTMP message or RTMP packet.
|
// The common message is read from underlay protocol sdk.
|
||||||
* the common message is read from underlay protocol sdk.
|
// while the shared ptr message used to copy and send.
|
||||||
* while the shared ptr message used to copy and send.
|
|
||||||
*/
|
|
||||||
class SrsCommonMessage
|
class SrsCommonMessage
|
||||||
{
|
{
|
||||||
// 4.1. Message Header
|
// 4.1. Message Header
|
||||||
public:
|
public:
|
||||||
SrsMessageHeader header;
|
SrsMessageHeader header;
|
||||||
// 4.2. Message Payload
|
// 4.2. Message Payload
|
||||||
public:
|
public:
|
||||||
/**
|
// The current message parsed size,
|
||||||
* current message parsed size,
|
// size <= header.payload_length
|
||||||
* size <= header.payload_length
|
// For the payload maybe sent in multiple chunks.
|
||||||
* for the payload maybe sent in multiple chunks.
|
|
||||||
*/
|
|
||||||
int size;
|
int size;
|
||||||
/**
|
// The payload of message, the SrsCommonMessage never know about the detail of payload,
|
||||||
* the payload of message, the SrsCommonMessage never know about the detail of payload,
|
// user must use SrsProtocol.decode_message to get concrete packet.
|
||||||
* user must use SrsProtocol.decode_message to get concrete packet.
|
// @remark, not all message payload can be decoded to packet. for example,
|
||||||
* @remark, not all message payload can be decoded to packet. for example,
|
// video/audio packet use raw bytes, no video/audio packet.
|
||||||
* video/audio packet use raw bytes, no video/audio packet.
|
|
||||||
*/
|
|
||||||
char* payload;
|
char* payload;
|
||||||
public:
|
public:
|
||||||
SrsCommonMessage();
|
SrsCommonMessage();
|
||||||
virtual ~SrsCommonMessage();
|
virtual ~SrsCommonMessage();
|
||||||
public:
|
public:
|
||||||
/**
|
// Alloc the payload to specified size of bytes.
|
||||||
* alloc the payload to specified size of bytes.
|
|
||||||
*/
|
|
||||||
virtual void create_payload(int size);
|
virtual void create_payload(int size);
|
||||||
public:
|
public:
|
||||||
/**
|
// Create common message,
|
||||||
* create common message,
|
// from the header and body.
|
||||||
* from the header and body.
|
// @remark user should never free the body.
|
||||||
* @remark user should never free the body.
|
// @param pheader, the header to copy to the message. NULL to ignore.
|
||||||
* @param pheader, the header to copy to the message. NULL to ignore.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t create(SrsMessageHeader* pheader, char* body, int size);
|
virtual srs_error_t create(SrsMessageHeader* pheader, char* body, int size);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// The message header for shared ptr message.
|
||||||
* the message header for shared ptr message.
|
// only the message for all msgs are same.
|
||||||
* only the message for all msgs are same.
|
|
||||||
*/
|
|
||||||
struct SrsSharedMessageHeader
|
struct SrsSharedMessageHeader
|
||||||
{
|
{
|
||||||
/**
|
// 3bytes.
|
||||||
* 3bytes.
|
// Three-byte field that represents the size of the payload in bytes.
|
||||||
* Three-byte field that represents the size of the payload in bytes.
|
// It is set in big-endian format.
|
||||||
* It is set in big-endian format.
|
|
||||||
*/
|
|
||||||
int32_t payload_length;
|
int32_t payload_length;
|
||||||
/**
|
// 1byte.
|
||||||
* 1byte.
|
// One byte field to represent the message type. A range of type IDs
|
||||||
* One byte field to represent the message type. A range of type IDs
|
// (1-7) are reserved for protocol control messages.
|
||||||
* (1-7) are reserved for protocol control messages.
|
|
||||||
*/
|
|
||||||
int8_t message_type;
|
int8_t message_type;
|
||||||
/**
|
// Get the perfered cid(chunk stream id) which sendout over.
|
||||||
* get the perfered cid(chunk stream id) which sendout over.
|
// set at decoding, and canbe used for directly send message,
|
||||||
* set at decoding, and canbe used for directly send message,
|
// For example, dispatch to all connections.
|
||||||
* for example, dispatch to all connections.
|
|
||||||
*/
|
|
||||||
int perfer_cid;
|
int perfer_cid;
|
||||||
|
|
||||||
SrsSharedMessageHeader();
|
SrsSharedMessageHeader();
|
||||||
virtual ~SrsSharedMessageHeader();
|
virtual ~SrsSharedMessageHeader();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// The shared ptr message.
|
||||||
* shared ptr message.
|
// For audio/video/data message that need less memory copy.
|
||||||
* for audio/video/data message that need less memory copy.
|
// and only for output.
|
||||||
* and only for output.
|
//
|
||||||
*
|
// Create first object by constructor and create(),
|
||||||
* create first object by constructor and create(),
|
// use copy if need reference count message.
|
||||||
* use copy if need reference count message.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class SrsSharedPtrMessage
|
class SrsSharedPtrMessage
|
||||||
{
|
{
|
||||||
// 4.1. Message Header
|
// 4.1. Message Header
|
||||||
public:
|
public:
|
||||||
// the header can shared, only set the timestamp and stream id.
|
// The header can shared, only set the timestamp and stream id.
|
||||||
// @see https://github.com/ossrs/srs/issues/251
|
// @see https://github.com/ossrs/srs/issues/251
|
||||||
//SrsSharedMessageHeader header;
|
//SrsSharedMessageHeader header;
|
||||||
/**
|
// Four-byte field that contains a timestamp of the message.
|
||||||
* Four-byte field that contains a timestamp of the message.
|
// The 4 bytes are packed in the big-endian order.
|
||||||
* The 4 bytes are packed in the big-endian order.
|
// @remark, used as calc timestamp when decode and encode time.
|
||||||
* @remark, used as calc timestamp when decode and encode time.
|
// @remark, we use 64bits for large time for jitter detect and hls.
|
||||||
* @remark, we use 64bits for large time for jitter detect and hls.
|
|
||||||
*/
|
|
||||||
int64_t timestamp;
|
int64_t timestamp;
|
||||||
/**
|
// 4bytes.
|
||||||
* 4bytes.
|
// Four-byte field that identifies the stream of the message. These
|
||||||
* Four-byte field that identifies the stream of the message. These
|
// bytes are set in big-endian format.
|
||||||
* bytes are set in big-endian format.
|
|
||||||
*/
|
|
||||||
int32_t stream_id;
|
int32_t stream_id;
|
||||||
// 4.2. Message Payload
|
// 4.2. Message Payload
|
||||||
public:
|
public:
|
||||||
/**
|
// The current message parsed size,
|
||||||
* current message parsed size,
|
// size <= header.payload_length
|
||||||
* size <= header.payload_length
|
// For the payload maybe sent in multiple chunks.
|
||||||
* for the payload maybe sent in multiple chunks.
|
|
||||||
*/
|
|
||||||
int size;
|
int size;
|
||||||
/**
|
// The payload of message, the SrsCommonMessage never know about the detail of payload,
|
||||||
* the payload of message, the SrsCommonMessage never know about the detail of payload,
|
// user must use SrsProtocol.decode_message to get concrete packet.
|
||||||
* user must use SrsProtocol.decode_message to get concrete packet.
|
// @remark, not all message payload can be decoded to packet. for example,
|
||||||
* @remark, not all message payload can be decoded to packet. for example,
|
// video/audio packet use raw bytes, no video/audio packet.
|
||||||
* video/audio packet use raw bytes, no video/audio packet.
|
|
||||||
*/
|
|
||||||
char* payload;
|
char* payload;
|
||||||
private:
|
private:
|
||||||
class SrsSharedPtrPayload
|
class SrsSharedPtrPayload
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// shared message header.
|
// The shared message header.
|
||||||
// @see https://github.com/ossrs/srs/issues/251
|
// @see https://github.com/ossrs/srs/issues/251
|
||||||
SrsSharedMessageHeader header;
|
SrsSharedMessageHeader header;
|
||||||
// actual shared payload.
|
// The actual shared payload.
|
||||||
char* payload;
|
char* payload;
|
||||||
// size of payload.
|
// The size of payload.
|
||||||
int size;
|
int size;
|
||||||
// the reference count
|
// The reference count
|
||||||
int shared_count;
|
int shared_count;
|
||||||
public:
|
public:
|
||||||
SrsSharedPtrPayload();
|
SrsSharedPtrPayload();
|
||||||
|
@ -392,54 +305,40 @@ public:
|
||||||
SrsSharedPtrMessage();
|
SrsSharedPtrMessage();
|
||||||
virtual ~SrsSharedPtrMessage();
|
virtual ~SrsSharedPtrMessage();
|
||||||
public:
|
public:
|
||||||
/**
|
// Create shared ptr message,
|
||||||
* create shared ptr message,
|
// copy header, manage the payload of msg,
|
||||||
* copy header, manage the payload of msg,
|
// set the payload to NULL to prevent double free.
|
||||||
* set the payload to NULL to prevent double free.
|
// @remark payload of msg set to NULL if success.
|
||||||
* @remark payload of msg set to NULL if success.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t create(SrsCommonMessage* msg);
|
virtual srs_error_t create(SrsCommonMessage* msg);
|
||||||
/**
|
// Create shared ptr message,
|
||||||
* create shared ptr message,
|
// from the header and payload.
|
||||||
* from the header and payload.
|
// @remark user should never free the payload.
|
||||||
* @remark user should never free the payload.
|
// @param pheader, the header to copy to the message. NULL to ignore.
|
||||||
* @param pheader, the header to copy to the message. NULL to ignore.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t create(SrsMessageHeader* pheader, char* payload, int size);
|
virtual srs_error_t create(SrsMessageHeader* pheader, char* payload, int size);
|
||||||
/**
|
// Get current reference count.
|
||||||
* get current reference count.
|
// when this object created, count set to 0.
|
||||||
* when this object created, count set to 0.
|
// if copy() this object, count increase 1.
|
||||||
* if copy() this object, count increase 1.
|
// if this or copy deleted, free payload when count is 0, or count--.
|
||||||
* if this or copy deleted, free payload when count is 0, or count--.
|
// @remark, assert object is created.
|
||||||
* @remark, assert object is created.
|
|
||||||
*/
|
|
||||||
virtual int count();
|
virtual int count();
|
||||||
/**
|
// check perfer cid and stream id.
|
||||||
* check perfer cid and stream id.
|
// @return whether stream id already set.
|
||||||
* @return whether stream id already set.
|
|
||||||
*/
|
|
||||||
virtual bool check(int stream_id);
|
virtual bool check(int stream_id);
|
||||||
public:
|
public:
|
||||||
virtual bool is_av();
|
virtual bool is_av();
|
||||||
virtual bool is_audio();
|
virtual bool is_audio();
|
||||||
virtual bool is_video();
|
virtual bool is_video();
|
||||||
public:
|
public:
|
||||||
/**
|
// generate the chunk header to cache.
|
||||||
* generate the chunk header to cache.
|
// @return the size of header.
|
||||||
* @return the size of header.
|
|
||||||
*/
|
|
||||||
virtual int chunk_header(char* cache, int nb_cache, bool c0);
|
virtual int chunk_header(char* cache, int nb_cache, bool c0);
|
||||||
public:
|
public:
|
||||||
/**
|
// copy current shared ptr message, use ref-count.
|
||||||
* copy current shared ptr message, use ref-count.
|
// @remark, assert object is created.
|
||||||
* @remark, assert object is created.
|
|
||||||
*/
|
|
||||||
virtual SrsSharedPtrMessage* copy();
|
virtual SrsSharedPtrMessage* copy();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// Transmux RTMP packets to FLV stream.
|
||||||
* Transmux RTMP packets to FLV stream.
|
|
||||||
*/
|
|
||||||
class SrsFlvTransmuxer
|
class SrsFlvTransmuxer
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -450,60 +349,48 @@ public:
|
||||||
SrsFlvTransmuxer();
|
SrsFlvTransmuxer();
|
||||||
virtual ~SrsFlvTransmuxer();
|
virtual ~SrsFlvTransmuxer();
|
||||||
public:
|
public:
|
||||||
/**
|
// Initialize the underlayer file stream.
|
||||||
* initialize the underlayer file stream.
|
// @remark user can initialize multiple times to encode multiple flv files.
|
||||||
* @remark user can initialize multiple times to encode multiple flv files.
|
// @remark, user must free the @param fw, flv encoder never close/free it.
|
||||||
* @remark, user must free the @param fw, flv encoder never close/free it.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t initialize(ISrsWriter* fw);
|
virtual srs_error_t initialize(ISrsWriter* fw);
|
||||||
public:
|
public:
|
||||||
/**
|
// Write flv header.
|
||||||
* write flv header.
|
// Write following:
|
||||||
* write following:
|
// 1. E.2 The FLV header
|
||||||
* 1. E.2 The FLV header
|
// 2. PreviousTagSize0 UI32 Always 0
|
||||||
* 2. PreviousTagSize0 UI32 Always 0
|
// that is, 9+4=13bytes.
|
||||||
* that is, 9+4=13bytes.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t write_header();
|
virtual srs_error_t write_header();
|
||||||
virtual srs_error_t write_header(char flv_header[9]);
|
virtual srs_error_t write_header(char flv_header[9]);
|
||||||
/**
|
// Write flv metadata.
|
||||||
* write flv metadata.
|
// @param type, the type of data, or other message type.
|
||||||
* @param type, the type of data, or other message type.
|
// @see SrsFrameType
|
||||||
* @see SrsFrameType
|
// @param data, the amf0 metadata which serialize from:
|
||||||
* @param data, the amf0 metadata which serialize from:
|
// AMF0 string: onMetaData,
|
||||||
* AMF0 string: onMetaData,
|
// AMF0 object: the metadata object.
|
||||||
* AMF0 object: the metadata object.
|
// @remark assert data is not NULL.
|
||||||
* @remark assert data is not NULL.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t write_metadata(char type, char* data, int size);
|
virtual srs_error_t write_metadata(char type, char* data, int size);
|
||||||
/**
|
// Write audio/video packet.
|
||||||
* write audio/video packet.
|
// @remark assert data is not NULL.
|
||||||
* @remark assert data is not NULL.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t write_audio(int64_t timestamp, char* data, int size);
|
virtual srs_error_t write_audio(int64_t timestamp, char* data, int size);
|
||||||
virtual srs_error_t write_video(int64_t timestamp, char* data, int size);
|
virtual srs_error_t write_video(int64_t timestamp, char* data, int size);
|
||||||
public:
|
public:
|
||||||
/**
|
// Get the tag size,
|
||||||
* get the tag size,
|
// including the tag header, body, and 4bytes previous tag size.
|
||||||
* including the tag header, body, and 4bytes previous tag size.
|
// @remark assert data_size is not negative.
|
||||||
* @remark assert data_size is not negative.
|
|
||||||
*/
|
|
||||||
static int size_tag(int data_size);
|
static int size_tag(int data_size);
|
||||||
#ifdef SRS_PERF_FAST_FLV_ENCODER
|
#ifdef SRS_PERF_FAST_FLV_ENCODER
|
||||||
private:
|
private:
|
||||||
// cache tag header.
|
// The cache tag header.
|
||||||
int nb_tag_headers;
|
int nb_tag_headers;
|
||||||
char* tag_headers;
|
char* tag_headers;
|
||||||
// cache pps(previous tag size)
|
// The cache pps(previous tag size)
|
||||||
int nb_ppts;
|
int nb_ppts;
|
||||||
char* ppts;
|
char* ppts;
|
||||||
// cache iovss.
|
// The cache iovss.
|
||||||
int nb_iovss_cache;
|
int nb_iovss_cache;
|
||||||
iovec* iovss_cache;
|
iovec* iovss_cache;
|
||||||
public:
|
public:
|
||||||
/**
|
// Write the tags in a time.
|
||||||
* write the tags in a time.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t write_tags(SrsSharedPtrMessage** msgs, int count);
|
virtual srs_error_t write_tags(SrsSharedPtrMessage** msgs, int count);
|
||||||
#endif
|
#endif
|
||||||
private:
|
private:
|
||||||
|
@ -514,9 +401,7 @@ private:
|
||||||
virtual srs_error_t write_tag(char* header, int header_size, char* tag, int tag_size);
|
virtual srs_error_t write_tag(char* header, int header_size, char* tag, int tag_size);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// Decode flv file.
|
||||||
* decode flv file.
|
|
||||||
*/
|
|
||||||
class SrsFlvDecoder
|
class SrsFlvDecoder
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -525,40 +410,28 @@ public:
|
||||||
SrsFlvDecoder();
|
SrsFlvDecoder();
|
||||||
virtual ~SrsFlvDecoder();
|
virtual ~SrsFlvDecoder();
|
||||||
public:
|
public:
|
||||||
/**
|
// Initialize the underlayer file stream
|
||||||
* initialize the underlayer file stream
|
// @remark user can initialize multiple times to decode multiple flv files.
|
||||||
* @remark user can initialize multiple times to decode multiple flv files.
|
// @remark user must free the @param fr, flv decoder never close/free it
|
||||||
* @remark user must free the @param fr, flv decoder never close/free it
|
|
||||||
*/
|
|
||||||
virtual srs_error_t initialize(ISrsReader* fr);
|
virtual srs_error_t initialize(ISrsReader* fr);
|
||||||
public:
|
public:
|
||||||
/**
|
// Read the flv header, donot including the 4bytes previous tag size.
|
||||||
* read the flv header, donot including the 4bytes previous tag size.
|
// @remark assert header not NULL.
|
||||||
* @remark assert header not NULL.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t read_header(char header[9]);
|
virtual srs_error_t read_header(char header[9]);
|
||||||
/**
|
// Read the tag header infos.
|
||||||
* read the tag header infos.
|
// @remark assert ptype/pdata_size/ptime not NULL.
|
||||||
* @remark assert ptype/pdata_size/ptime not NULL.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t read_tag_header(char* ptype, int32_t* pdata_size, uint32_t* ptime);
|
virtual srs_error_t read_tag_header(char* ptype, int32_t* pdata_size, uint32_t* ptime);
|
||||||
/**
|
// Read the tag data.
|
||||||
* read the tag data.
|
// @remark assert data not NULL.
|
||||||
* @remark assert data not NULL.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t read_tag_data(char* data, int32_t size);
|
virtual srs_error_t read_tag_data(char* data, int32_t size);
|
||||||
/**
|
// Read the 4bytes previous tag size.
|
||||||
* read the 4bytes previous tag size.
|
// @remark assert previous_tag_size not NULL.
|
||||||
* @remark assert previous_tag_size not NULL.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t read_previous_tag_size(char previous_tag_size[4]);
|
virtual srs_error_t read_previous_tag_size(char previous_tag_size[4]);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// Decode flv fast by only decoding the header and tag.
|
||||||
* decode flv fast by only decoding the header and tag.
|
// used for vod flv stream to read the header and sequence header,
|
||||||
* used for vod flv stream to read the header and sequence header,
|
// then seek to specified offset.
|
||||||
* then seek to specified offset.
|
|
||||||
*/
|
|
||||||
class SrsFlvVodStreamDecoder
|
class SrsFlvVodStreamDecoder
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -567,31 +440,23 @@ public:
|
||||||
SrsFlvVodStreamDecoder();
|
SrsFlvVodStreamDecoder();
|
||||||
virtual ~SrsFlvVodStreamDecoder();
|
virtual ~SrsFlvVodStreamDecoder();
|
||||||
public:
|
public:
|
||||||
/**
|
// Initialize the underlayer file stream
|
||||||
* initialize the underlayer file stream
|
// @remark user can initialize multiple times to decode multiple flv files.
|
||||||
* @remark user can initialize multiple times to decode multiple flv files.
|
// @remark user must free the @param fr, flv decoder never close/free it.
|
||||||
* @remark user must free the @param fr, flv decoder never close/free it.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t initialize(ISrsReader* fr);
|
virtual srs_error_t initialize(ISrsReader* fr);
|
||||||
public:
|
public:
|
||||||
/**
|
// Read the flv header and its size.
|
||||||
* read the flv header and its size.
|
// @param header, fill it 13bytes(9bytes header, 4bytes previous tag size).
|
||||||
* @param header, fill it 13bytes(9bytes header, 4bytes previous tag size).
|
// @remark assert header not NULL.
|
||||||
* @remark assert header not NULL.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t read_header_ext(char header[13]);
|
virtual srs_error_t read_header_ext(char header[13]);
|
||||||
/**
|
// Read the sequence header tags offset and its size.
|
||||||
* read the sequence header tags offset and its size.
|
// @param pstart, the start offset of sequence header.
|
||||||
* @param pstart, the start offset of sequence header.
|
// @param psize, output the size, (tag header)+(tag body)+(4bytes previous tag size).
|
||||||
* @param psize, output the size, (tag header)+(tag body)+(4bytes previous tag size).
|
// @remark we think the first audio/video is sequence header.
|
||||||
* @remark we think the first audio/video is sequence header.
|
// @remark assert pstart/psize not NULL.
|
||||||
* @remark assert pstart/psize not NULL.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t read_sequence_header_summary(int64_t* pstart, int* psize);
|
virtual srs_error_t read_sequence_header_summary(int64_t* pstart, int* psize);
|
||||||
public:
|
public:
|
||||||
/**
|
// For start offset, seed to this position and response flv stream.
|
||||||
* for start offset, seed to this position and response flv stream.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t seek2(int64_t offset);
|
virtual srs_error_t seek2(int64_t offset);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -33,15 +33,13 @@
|
||||||
|
|
||||||
#include <srs_kernel_consts.hpp>
|
#include <srs_kernel_consts.hpp>
|
||||||
|
|
||||||
/**
|
// The log level, for example:
|
||||||
* the log level, for example:
|
// if specified Debug level, all level messages will be logged.
|
||||||
* if specified Debug level, all level messages will be logged.
|
// if specified Warn level, only Warn/Error/Fatal level messages will be logged.
|
||||||
* if specified Warn level, only Warn/Error/Fatal level messages will be logged.
|
|
||||||
*/
|
|
||||||
enum SrsLogLevel
|
enum SrsLogLevel
|
||||||
{
|
{
|
||||||
SrsLogLevelForbidden = 0x00,
|
SrsLogLevelForbidden = 0x00,
|
||||||
// only used for very verbose debug, generally,
|
// Only used for very verbose debug, generally,
|
||||||
// we compile without this level for high performance.
|
// we compile without this level for high performance.
|
||||||
SrsLogLevelVerbose = 0x01,
|
SrsLogLevelVerbose = 0x01,
|
||||||
SrsLogLevelInfo = 0x02,
|
SrsLogLevelInfo = 0x02,
|
||||||
|
@ -51,85 +49,63 @@ enum SrsLogLevel
|
||||||
SrsLogLevelDisabled = 0x20,
|
SrsLogLevelDisabled = 0x20,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// The log interface provides method to write log.
|
||||||
* the log interface provides method to write log.
|
// but we provides some macro, which enable us to disable the log when compile.
|
||||||
* but we provides some macro, which enable us to disable the log when compile.
|
// @see also SmtDebug/SmtTrace/SmtWarn/SmtError which is corresponding to Debug/Trace/Warn/Fatal.
|
||||||
* @see also SmtDebug/SmtTrace/SmtWarn/SmtError which is corresponding to Debug/Trace/Warn/Fatal.
|
|
||||||
*/
|
|
||||||
class ISrsLog
|
class ISrsLog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ISrsLog();
|
ISrsLog();
|
||||||
virtual ~ISrsLog();
|
virtual ~ISrsLog();
|
||||||
public:
|
public:
|
||||||
/**
|
// Initialize log utilities.
|
||||||
* initialize log utilities.
|
|
||||||
*/
|
|
||||||
virtual srs_error_t initialize();
|
virtual srs_error_t initialize();
|
||||||
/**
|
// Reopen the log file for log rotate.
|
||||||
* reopen the log file for log rotate.
|
|
||||||
*/
|
|
||||||
virtual void reopen();
|
virtual void reopen();
|
||||||
public:
|
public:
|
||||||
/**
|
// The log for verbose, very verbose information.
|
||||||
* log for verbose, very verbose information.
|
|
||||||
*/
|
|
||||||
virtual void verbose(const char* tag, int context_id, const char* fmt, ...);
|
virtual void verbose(const char* tag, int context_id, const char* fmt, ...);
|
||||||
/**
|
// The log for debug, detail information.
|
||||||
* log for debug, detail information.
|
|
||||||
*/
|
|
||||||
virtual void info(const char* tag, int context_id, const char* fmt, ...);
|
virtual void info(const char* tag, int context_id, const char* fmt, ...);
|
||||||
/**
|
// The log for trace, important information.
|
||||||
* log for trace, important information.
|
|
||||||
*/
|
|
||||||
virtual void trace(const char* tag, int context_id, const char* fmt, ...);
|
virtual void trace(const char* tag, int context_id, const char* fmt, ...);
|
||||||
/**
|
// The log for warn, warn is something should take attention, but not a error.
|
||||||
* log for warn, warn is something should take attention, but not a error.
|
|
||||||
*/
|
|
||||||
virtual void warn(const char* tag, int context_id, const char* fmt, ...);
|
virtual void warn(const char* tag, int context_id, const char* fmt, ...);
|
||||||
/**
|
// The log for error, something error occur, do something about the error, ie. close the connection,
|
||||||
* log for error, something error occur, do something about the error, ie. close the connection,
|
// but we will donot abort the program.
|
||||||
* but we will donot abort the program.
|
|
||||||
*/
|
|
||||||
virtual void error(const char* tag, int context_id, const char* fmt, ...);
|
virtual void error(const char* tag, int context_id, const char* fmt, ...);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// The context id manager to identify context, for instance, the green-thread.
|
||||||
* the context id manager to identify context, for instance, the green-thread.
|
// Usage:
|
||||||
* usage:
|
// _srs_context->generate_id(); // when thread start.
|
||||||
* _srs_context->generate_id(); // when thread start.
|
// _srs_context->get_id(); // get current generated id.
|
||||||
* _srs_context->get_id(); // get current generated id.
|
// int old_id = _srs_context->set_id(1000); // set context id if need to merge thread context.
|
||||||
* int old_id = _srs_context->set_id(1000); // set context id if need to merge thread context.
|
// The context for multiple clients.
|
||||||
*/
|
|
||||||
// the context for multiple clients.
|
|
||||||
class ISrsThreadContext
|
class ISrsThreadContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ISrsThreadContext();
|
ISrsThreadContext();
|
||||||
virtual ~ISrsThreadContext();
|
virtual ~ISrsThreadContext();
|
||||||
public:
|
public:
|
||||||
/**
|
// Generate the id for current context.
|
||||||
* generate the id for current context.
|
|
||||||
*/
|
|
||||||
virtual int generate_id();
|
virtual int generate_id();
|
||||||
/**
|
// Get the generated id of current context.
|
||||||
* get the generated id of current context.
|
|
||||||
*/
|
|
||||||
virtual int get_id();
|
virtual int get_id();
|
||||||
/**
|
// Set the id of current context.
|
||||||
* set the id of current context.
|
// @return the previous id value; 0 if no context.
|
||||||
* @return the previous id value; 0 if no context.
|
|
||||||
*/
|
|
||||||
virtual int set_id(int v);
|
virtual int set_id(int v);
|
||||||
};
|
};
|
||||||
|
|
||||||
// @global user must provides a log object
|
// @global User must provides a log object
|
||||||
extern ISrsLog* _srs_log;
|
extern ISrsLog* _srs_log;
|
||||||
|
|
||||||
// @global user must implements the LogContext and define a global instance.
|
// @global User must implements the LogContext and define a global instance.
|
||||||
extern ISrsThreadContext* _srs_context;
|
extern ISrsThreadContext* _srs_context;
|
||||||
|
|
||||||
// donot print method
|
// Log style.
|
||||||
|
// Use __FUNCTION__ to print c method
|
||||||
|
// Use __PRETTY_FUNCTION__ to print c++ class:method
|
||||||
#if 1
|
#if 1
|
||||||
#define srs_verbose(msg, ...) _srs_log->verbose(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
#define srs_verbose(msg, ...) _srs_log->verbose(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||||
#define srs_info(msg, ...) _srs_log->info(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
#define srs_info(msg, ...) _srs_log->info(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||||
|
@ -137,7 +113,6 @@ extern ISrsThreadContext* _srs_context;
|
||||||
#define srs_warn(msg, ...) _srs_log->warn(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
#define srs_warn(msg, ...) _srs_log->warn(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||||
#define srs_error(msg, ...) _srs_log->error(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
#define srs_error(msg, ...) _srs_log->error(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
// use __FUNCTION__ to print c method
|
|
||||||
#if 0
|
#if 0
|
||||||
#define srs_verbose(msg, ...) _srs_log->verbose(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
#define srs_verbose(msg, ...) _srs_log->verbose(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||||
#define srs_info(msg, ...) _srs_log->info(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
#define srs_info(msg, ...) _srs_log->info(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||||
|
@ -145,7 +120,6 @@ extern ISrsThreadContext* _srs_context;
|
||||||
#define srs_warn(msg, ...) _srs_log->warn(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
#define srs_warn(msg, ...) _srs_log->warn(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||||
#define srs_error(msg, ...) _srs_log->error(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
#define srs_error(msg, ...) _srs_log->error(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
// use __PRETTY_FUNCTION__ to print c++ class:method
|
|
||||||
#if 0
|
#if 0
|
||||||
#define srs_verbose(msg, ...) _srs_log->verbose(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
#define srs_verbose(msg, ...) _srs_log->verbose(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||||
#define srs_info(msg, ...) _srs_log->info(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
#define srs_info(msg, ...) _srs_log->info(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||||
|
@ -154,7 +128,7 @@ extern ISrsThreadContext* _srs_context;
|
||||||
#define srs_error(msg, ...) _srs_log->error(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
#define srs_error(msg, ...) _srs_log->error(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO: FIXME: add more verbose and info logs.
|
// TODO: FIXME: Add more verbose and info logs.
|
||||||
#ifndef SRS_AUTO_VERBOSE
|
#ifndef SRS_AUTO_VERBOSE
|
||||||
#undef srs_verbose
|
#undef srs_verbose
|
||||||
#define srs_verbose(msg, ...) (void)0
|
#define srs_verbose(msg, ...) (void)0
|
||||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -33,160 +33,132 @@
|
||||||
class SrsBuffer;
|
class SrsBuffer;
|
||||||
class SrsBitBuffer;
|
class SrsBitBuffer;
|
||||||
|
|
||||||
// compare
|
// Basic compare function.
|
||||||
#define srs_min(a, b) (((a) < (b))? (a) : (b))
|
#define srs_min(a, b) (((a) < (b))? (a) : (b))
|
||||||
#define srs_max(a, b) (((a) < (b))? (b) : (a))
|
#define srs_max(a, b) (((a) < (b))? (b) : (a))
|
||||||
|
|
||||||
// read nalu uev.
|
// To read H.264 NALU uev.
|
||||||
extern srs_error_t srs_avc_nalu_read_uev(SrsBitBuffer* stream, int32_t& v);
|
extern srs_error_t srs_avc_nalu_read_uev(SrsBitBuffer* stream, int32_t& v);
|
||||||
extern srs_error_t srs_avc_nalu_read_bit(SrsBitBuffer* stream, int8_t& v);
|
extern srs_error_t srs_avc_nalu_read_bit(SrsBitBuffer* stream, int8_t& v);
|
||||||
|
|
||||||
// get current system time in srs_utime_t, use cache to avoid performance problem
|
// Get current system time in srs_utime_t, use cache to avoid performance problem
|
||||||
extern srs_utime_t srs_get_system_time();
|
extern srs_utime_t srs_get_system_time();
|
||||||
extern srs_utime_t srs_get_system_startup_time();
|
extern srs_utime_t srs_get_system_startup_time();
|
||||||
// the deamon st-thread will update it.
|
// A daemon st-thread updates it.
|
||||||
extern srs_utime_t srs_update_system_time();
|
extern srs_utime_t srs_update_system_time();
|
||||||
|
|
||||||
// the any address for listener,
|
// The "ANY" address to listen, it's "0.0.0.0" for ipv4, and "::" for ipv6.
|
||||||
// it's "0.0.0.0" for ipv4, and "::" for ipv6.
|
|
||||||
extern std::string srs_any_address4listener();
|
extern std::string srs_any_address4listener();
|
||||||
|
|
||||||
// dns resolve utility, return the resolved ip address.
|
// The dns resolve utility, return the resolved ip address.
|
||||||
extern std::string srs_dns_resolve(std::string host, int& family);
|
extern std::string srs_dns_resolve(std::string host, int& family);
|
||||||
|
|
||||||
// split the host:port to host and port.
|
// Split the host:port to host and port.
|
||||||
// @remark the hostport format in <host[:port]>, where port is optional.
|
// @remark the hostport format in <host[:port]>, where port is optional.
|
||||||
extern void srs_parse_hostport(const std::string& hostport, std::string& host, int& port);
|
extern void srs_parse_hostport(const std::string& hostport, std::string& host, int& port);
|
||||||
|
|
||||||
// parse the endpoint to ip and port.
|
// Parse the endpoint to ip and port.
|
||||||
// @remark hostport format in <[ip:]port>, where ip is default to "0.0.0.0".
|
// @remark The hostport format in <[ip:]port>, where ip is default to "0.0.0.0".
|
||||||
extern void srs_parse_endpoint(std::string hostport, std::string& ip, int& port);
|
extern void srs_parse_endpoint(std::string hostport, std::string& ip, int& port);
|
||||||
|
|
||||||
// parse the int64 value to string.
|
// Parse the int64 value to string.
|
||||||
extern std::string srs_int2str(int64_t value);
|
extern std::string srs_int2str(int64_t value);
|
||||||
// parse the float value to string, precise is 2.
|
// Parse the float value to string, precise is 2.
|
||||||
extern std::string srs_float2str(double value);
|
extern std::string srs_float2str(double value);
|
||||||
// convert bool to switch value, true to "on", false to "off".
|
// Convert bool to switch value, true to "on", false to "off".
|
||||||
extern std::string srs_bool2switch(bool v);
|
extern std::string srs_bool2switch(bool v);
|
||||||
|
|
||||||
// whether system is little endian
|
// Whether system is little endian
|
||||||
extern bool srs_is_little_endian();
|
extern bool srs_is_little_endian();
|
||||||
|
|
||||||
// replace old_str to new_str of str
|
// Replace old_str to new_str of str
|
||||||
extern std::string srs_string_replace(std::string str, std::string old_str, std::string new_str);
|
extern std::string srs_string_replace(std::string str, std::string old_str, std::string new_str);
|
||||||
// trim char in trim_chars of str
|
// Trim char in trim_chars of str
|
||||||
extern std::string srs_string_trim_end(std::string str, std::string trim_chars);
|
extern std::string srs_string_trim_end(std::string str, std::string trim_chars);
|
||||||
// trim char in trim_chars of str
|
// Trim char in trim_chars of str
|
||||||
extern std::string srs_string_trim_start(std::string str, std::string trim_chars);
|
extern std::string srs_string_trim_start(std::string str, std::string trim_chars);
|
||||||
// remove char in remove_chars of str
|
// Remove char in remove_chars of str
|
||||||
extern std::string srs_string_remove(std::string str, std::string remove_chars);
|
extern std::string srs_string_remove(std::string str, std::string remove_chars);
|
||||||
// remove first substring from str
|
// Remove first substring from str
|
||||||
extern std::string srs_erase_first_substr(std::string str, std::string erase_string);
|
extern std::string srs_erase_first_substr(std::string str, std::string erase_string);
|
||||||
// remove last substring from str
|
// Remove last substring from str
|
||||||
extern std::string srs_erase_last_substr(std::string str, std::string erase_string);
|
extern std::string srs_erase_last_substr(std::string str, std::string erase_string);
|
||||||
// whether string end with
|
// Whether string end with
|
||||||
extern bool srs_string_ends_with(std::string str, std::string flag);
|
extern bool srs_string_ends_with(std::string str, std::string flag);
|
||||||
extern bool srs_string_ends_with(std::string str, std::string flag0, std::string flag1);
|
extern bool srs_string_ends_with(std::string str, std::string flag0, std::string flag1);
|
||||||
extern bool srs_string_ends_with(std::string str, std::string flag0, std::string flag1, std::string flag2);
|
extern bool srs_string_ends_with(std::string str, std::string flag0, std::string flag1, std::string flag2);
|
||||||
extern bool srs_string_ends_with(std::string str, std::string flag0, std::string flag1, std::string flag2, std::string flag3);
|
extern bool srs_string_ends_with(std::string str, std::string flag0, std::string flag1, std::string flag2, std::string flag3);
|
||||||
// whether string starts with
|
// Whether string starts with
|
||||||
extern bool srs_string_starts_with(std::string str, std::string flag);
|
extern bool srs_string_starts_with(std::string str, std::string flag);
|
||||||
extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1);
|
extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1);
|
||||||
extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1, std::string flag2);
|
extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1, std::string flag2);
|
||||||
extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1, std::string flag2, std::string flag3);
|
extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1, std::string flag2, std::string flag3);
|
||||||
// whether string contains with
|
// Whether string contains with
|
||||||
extern bool srs_string_contains(std::string str, std::string flag);
|
extern bool srs_string_contains(std::string str, std::string flag);
|
||||||
extern bool srs_string_contains(std::string str, std::string flag0, std::string flag1);
|
extern bool srs_string_contains(std::string str, std::string flag0, std::string flag1);
|
||||||
extern bool srs_string_contains(std::string str, std::string flag0, std::string flag1, std::string flag2);
|
extern bool srs_string_contains(std::string str, std::string flag0, std::string flag1, std::string flag2);
|
||||||
// find the min match in str for flags.
|
// Find the min match in str for flags.
|
||||||
extern std::string srs_string_min_match(std::string str, std::vector<std::string> flags);
|
extern std::string srs_string_min_match(std::string str, std::vector<std::string> flags);
|
||||||
// split the string by flag to array.
|
// Split the string by flag to array.
|
||||||
extern std::vector<std::string> srs_string_split(std::string str, std::string flag);
|
extern std::vector<std::string> srs_string_split(std::string str, std::string flag);
|
||||||
extern std::vector<std::string> srs_string_split(std::string str, std::vector<std::string> flags);
|
extern std::vector<std::string> srs_string_split(std::string str, std::vector<std::string> flags);
|
||||||
|
|
||||||
/**
|
// Compare the memory in bytes.
|
||||||
* compare the memory in bytes.
|
// @return true if completely equal; otherwise, false.
|
||||||
* @return true if completely equal; otherwise, false.
|
|
||||||
*/
|
|
||||||
extern bool srs_bytes_equals(void* pa, void* pb, int size);
|
extern bool srs_bytes_equals(void* pa, void* pb, int size);
|
||||||
|
|
||||||
// create dir recursively
|
// Create dir recursively
|
||||||
extern srs_error_t srs_create_dir_recursively(std::string dir);
|
extern srs_error_t srs_create_dir_recursively(std::string dir);
|
||||||
|
|
||||||
// whether path exists.
|
// Whether path exists.
|
||||||
extern bool srs_path_exists(std::string path);
|
extern bool srs_path_exists(std::string path);
|
||||||
// get the dirname of path, for instance, dirname("/live/livestream")="/live"
|
// Get the dirname of path, for instance, dirname("/live/livestream")="/live"
|
||||||
extern std::string srs_path_dirname(std::string path);
|
extern std::string srs_path_dirname(std::string path);
|
||||||
// get the basename of path, for instance, basename("/live/livestream")="livestream"
|
// Get the basename of path, for instance, basename("/live/livestream")="livestream"
|
||||||
extern std::string srs_path_basename(std::string path);
|
extern std::string srs_path_basename(std::string path);
|
||||||
// get the filename of path, for instance, filename("livestream.flv")="livestream"
|
// Get the filename of path, for instance, filename("livestream.flv")="livestream"
|
||||||
extern std::string srs_path_filename(std::string path);
|
extern std::string srs_path_filename(std::string path);
|
||||||
// get the file extension of path, for instance, filext("live.flv")=".flv"
|
// Get the file extension of path, for instance, filext("live.flv")=".flv"
|
||||||
extern std::string srs_path_filext(std::string path);
|
extern std::string srs_path_filext(std::string path);
|
||||||
|
|
||||||
/**
|
// Whether stream starts with the avc NALU in "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
|
||||||
* whether stream starts with the avc NALU in "AnnexB"
|
// The start code must be "N[00] 00 00 01" where N>=0
|
||||||
* from ISO_IEC_14496-10-AVC-2003.pdf, page 211.
|
// @param pnb_start_code output the size of start code, must >=3. NULL to ignore.
|
||||||
* start code must be "N[00] 00 00 01" where N>=0
|
|
||||||
* @param pnb_start_code output the size of start code, must >=3.
|
|
||||||
* NULL to ignore.
|
|
||||||
*/
|
|
||||||
extern bool srs_avc_startswith_annexb(SrsBuffer* stream, int* pnb_start_code = NULL);
|
extern bool srs_avc_startswith_annexb(SrsBuffer* stream, int* pnb_start_code = NULL);
|
||||||
|
|
||||||
/**
|
// Whether stream starts with the aac ADTS from ISO_IEC_14496-3-AAC-2001.pdf, page 75, 1.A.2.2 ADTS.
|
||||||
* whether stream starts with the aac ADTS
|
// The start code must be '1111 1111 1111'B, that is 0xFFF
|
||||||
* from ISO_IEC_14496-3-AAC-2001.pdf, page 75, 1.A.2.2 ADTS.
|
|
||||||
* start code must be '1111 1111 1111'B, that is 0xFFF
|
|
||||||
*/
|
|
||||||
extern bool srs_aac_startswith_adts(SrsBuffer* stream);
|
extern bool srs_aac_startswith_adts(SrsBuffer* stream);
|
||||||
|
|
||||||
/**
|
// Cacl the crc32 of bytes in buf, for ffmpeg.
|
||||||
* cacl the crc32 of bytes in buf, for ffmpeg.
|
|
||||||
*/
|
|
||||||
extern uint32_t srs_crc32_mpegts(const void* buf, int size);
|
extern uint32_t srs_crc32_mpegts(const void* buf, int size);
|
||||||
|
|
||||||
/**
|
// Calc the crc32 of bytes in buf by IEEE, for zip.
|
||||||
* calc the crc32 of bytes in buf by IEEE, for zip.
|
|
||||||
*/
|
|
||||||
extern uint32_t srs_crc32_ieee(const void* buf, int size, uint32_t previous = 0);
|
extern uint32_t srs_crc32_ieee(const void* buf, int size, uint32_t previous = 0);
|
||||||
|
|
||||||
/**
|
// Decode a base64-encoded string.
|
||||||
* Decode a base64-encoded string.
|
|
||||||
*/
|
|
||||||
extern srs_error_t srs_av_base64_decode(std::string cipher, std::string& plaintext);
|
extern srs_error_t srs_av_base64_decode(std::string cipher, std::string& plaintext);
|
||||||
|
|
||||||
/**
|
// Calculate the output size needed to base64-encode x bytes to a null-terminated string.
|
||||||
* Calculate the output size needed to base64-encode x bytes to a
|
|
||||||
* null-terminated string.
|
|
||||||
*/
|
|
||||||
#define SRS_AV_BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1)
|
#define SRS_AV_BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1)
|
||||||
|
|
||||||
/**
|
// Convert hex string to data, for example, p=config='139056E5A0'
|
||||||
* convert hex string to data.
|
// The output data in hex {0x13, 0x90, 0x56, 0xe5, 0xa0} as such.
|
||||||
* for example, p=config='139056E5A0'
|
|
||||||
* output hex to data={0x13, 0x90, 0x56, 0xe5, 0xa0}
|
|
||||||
*/
|
|
||||||
extern int srs_hex_to_data(uint8_t* data, const char* p, int size);
|
extern int srs_hex_to_data(uint8_t* data, const char* p, int size);
|
||||||
|
|
||||||
/**
|
// Convert data string to hex.
|
||||||
* convert data string to hex.
|
|
||||||
*/
|
|
||||||
extern char *srs_data_to_hex(char *des, const uint8_t *src, int len);
|
extern char *srs_data_to_hex(char *des, const uint8_t *src, int len);
|
||||||
|
|
||||||
/**
|
// Generate the c0 chunk header for msg.
|
||||||
* generate the c0 chunk header for msg.
|
// @param cache, the cache to write header.
|
||||||
* @param cache, the cache to write header.
|
// @param nb_cache, the size of cache.
|
||||||
* @param nb_cache, the size of cache.
|
// @return The size of header. 0 if cache not enough.
|
||||||
* @return the size of header. 0 if cache not enough.
|
|
||||||
*/
|
|
||||||
extern int srs_chunk_header_c0(int perfer_cid, uint32_t timestamp, int32_t payload_length, int8_t message_type, int32_t stream_id, char* cache, int nb_cache);
|
extern int srs_chunk_header_c0(int perfer_cid, uint32_t timestamp, int32_t payload_length, int8_t message_type, int32_t stream_id, char* cache, int nb_cache);
|
||||||
|
|
||||||
/**
|
// Generate the c3 chunk header for msg.
|
||||||
* generate the c3 chunk header for msg.
|
// @param cache, the cache to write header.
|
||||||
* @param cache, the cache to write header.
|
// @param nb_cache, the size of cache.
|
||||||
* @param nb_cache, the size of cache.
|
// @return the size of header. 0 if cache not enough.
|
||||||
* @return the size of header. 0 if cache not enough.
|
|
||||||
*/
|
|
||||||
extern int srs_chunk_header_c3(int perfer_cid, uint32_t timestamp, char* cache, int nb_cache);
|
extern int srs_chunk_header_c3(int perfer_cid, uint32_t timestamp, char* cache, int nb_cache);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue