From 35fe05d62c31326ef17041a3d620f8a14bf7155c Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 22 Apr 2019 09:19:05 +0800 Subject: [PATCH] Refine typo in kernel. --- trunk/src/core/srs_core.hpp | 2 +- trunk/src/kernel/srs_kernel_aac.hpp | 18 +- trunk/src/kernel/srs_kernel_consts.hpp | 138 ++- trunk/src/kernel/srs_kernel_error.hpp | 26 +- trunk/src/kernel/srs_kernel_flv.hpp | 581 ++++------ trunk/src/kernel/srs_kernel_log.hpp | 88 +- trunk/src/kernel/srs_kernel_mp4.hpp | 906 ++++++--------- trunk/src/kernel/srs_kernel_ts.hpp | 1406 +++++++++-------------- trunk/src/kernel/srs_kernel_utility.hpp | 132 +-- 9 files changed, 1321 insertions(+), 1976 deletions(-) diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index f2f638a9f..201263148 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -101,7 +101,7 @@ (void)0 // 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__) #error "only support i386/amd64/x86_64/arm cpu" #endif diff --git a/trunk/src/kernel/srs_kernel_aac.hpp b/trunk/src/kernel/srs_kernel_aac.hpp index 09ff0f7cc..187e50ad2 100644 --- a/trunk/src/kernel/srs_kernel_aac.hpp +++ b/trunk/src/kernel/srs_kernel_aac.hpp @@ -35,9 +35,7 @@ class SrsBuffer; class ISrsStreamWriter; -/** - * Transmux the RTMP packets to AAC stream. - */ +// Transmux the RTMP packets to AAC stream. class SrsAacTransmuxer { private: @@ -51,17 +49,13 @@ public: SrsAacTransmuxer(); virtual ~SrsAacTransmuxer(); public: - /** - * initialize the underlayer file stream. - * @remark user can initialize multiple times to encode multiple aac files. - * @remark, user must free the fs, aac encoder never close/free it. - */ + // Initialize the underlayer file stream. + // @remark User can initialize multiple times to encode multiple aac files. + // @remark User must free the fs, aac encoder never close/free it. virtual srs_error_t initialize(ISrsStreamWriter* fs); public: - /** - * write audio/video packet. - * @remark assert data is not NULL. - */ + // Write audio/video packet. + // @remark The assert data should not be NULL. virtual srs_error_t write_audio(int64_t timestamp, char* data, int size); }; diff --git a/trunk/src/kernel/srs_kernel_consts.hpp b/trunk/src/kernel/srs_kernel_consts.hpp index 692f89624..8f09912ff 100644 --- a/trunk/src/kernel/srs_kernel_consts.hpp +++ b/trunk/src/kernel/srs_kernel_consts.hpp @@ -36,82 +36,72 @@ /////////////////////////////////////////////////////////// // RTMP consts values /////////////////////////////////////////////////////////// -// default vhost of rtmp +// Default vhost of rtmp #define SRS_CONSTS_RTMP_DEFAULT_VHOST "__defaultVhost__" #define SRS_CONSTS_RTMP_DEFAULT_APP "__defaultApp__" -// default port of rtmp +// Default port of rtmp #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 // 6. Chunking, RTMP protocol default chunk size. #define SRS_CONSTS_RTMP_PROTOCOL_CHUNK_SIZE 128 -/** - * 6. Chunking - * The chunk size is configurable. It can be set using a control - * message(Set Chunk Size) as described in section 7.1. The maximum - * chunk size can be 65536 bytes and minimum 128 bytes. Larger values - * reduce CPU usage, but also commit to larger writes that can delay - * other content on lower bandwidth connections. Smaller chunks are not - * good for high-bit rate streaming. Chunk size is maintained - * independently for each direction. - */ +// 6. Chunking +// The chunk size is configurable. It can be set using a control +// message(Set Chunk Size) as described in section 7.1. The maximum +// chunk size can be 65536 bytes and minimum 128 bytes. Larger values +// reduce CPU usage, but also commit to larger writes that can delay +// other content on lower bandwidth connections. Smaller chunks are not +// good for high-bit rate streaming. Chunk size is maintained +// independently for each direction. #define SRS_CONSTS_RTMP_MIN_CHUNK_SIZE 128 #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. -// 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? #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, // generally, it's the pulse time for data seding. // @remark, recomment to 500ms. #define SRS_CONSTS_RTMP_PULSE (500 * SRS_UTIME_MILLISECONDS) -/** - * max rtmp header size: - * 1bytes basic header, - * 11bytes message header, - * 4bytes timestamp header, - * that is, 1+11+4=16bytes. - */ +// The max rtmp header size: +// 1bytes basic header, +// 11bytes message header, +// 4bytes timestamp header, +// that is, 1+11+4=16bytes. #define SRS_CONSTS_RTMP_MAX_FMT0_HEADER_SIZE 16 -/** - * max rtmp header size: - * 1bytes basic header, - * 4bytes timestamp header, - * that is, 1+4=5bytes. - */ +// The max rtmp header size: +// 1bytes basic header, +// 4bytes timestamp header, +// that is, 1+4=5bytes. // always use fmt0 as cache. #define SRS_CONSTS_RTMP_MAX_FMT3_HEADER_SIZE 5 -/** - * for performance issue, - * the iovs cache, @see https://github.com/ossrs/srs/issues/194 - * 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, - * so the iovs max should be (SRS_PERF_MW_MSGS * 2) - * - * @remark, SRS will realloc when the iovs not enough. - */ +// For performance issue, +// the iovs cache, @see https://github.com/ossrs/srs/issues/194 +// 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, +// so the iovs max should be (SRS_PERF_MW_MSGS * 2) +// +// @remark, SRS will realloc when the iovs not enough. #define SRS_CONSTS_IOVS_MAX (SRS_PERF_MW_MSGS * 2) -/** - * for performance issue, - * the c0c3 cache, @see https://github.com/ossrs/srs/issues/194 - * c0c3 cache for multiple messages for each connections. - * each c0 <= 16byes, suppose the chunk size is 64k, - * each message send in a chunk which needs only a c0 header, - * 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. - * so we use larger c0c3 cache, that is (SRS_PERF_MW_MSGS * 32) - */ +// For performance issue, +// the c0c3 cache, @see https://github.com/ossrs/srs/issues/194 +// c0c3 cache for multiple messages for each connections. +// each c0 <= 16byes, suppose the chunk size is 64k, +// each message send in a chunk which needs only a c0 header, +// 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. +// so we use larger c0c3 cache, that is (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_LOCALHOST "127.0.0.1" -// signal defines. -// reload the config file and apply new config. +// The signal defines. +// To reload the config file and apply new config. #define SRS_SIGNAL_RELOAD SIGHUP -// reopen the log file. +// Reopen the log file. #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 -// application level signals. -// persistence the config in memory to config file. +// The application level signals. +// Persistence the config in memory to config file. // @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. #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" -// 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" -// edge/origin forwarder. +// The edge/origin forwarder. #define SRS_CONSTS_LOG_FOWARDER "FWR" -// play stream on edge/origin. +// Play stream on edge/origin. #define SRS_CONSTS_LOG_PLAY "PLA" -// client publish to edge/origin +// Client publish to edge/origin #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" -// ingester for edge(play)/origin +// Ingester for edge(play)/origin #define SRS_CONSTS_LOG_INGESTER "IGS" -// hls log id. +// The hls log id. #define SRS_CONSTS_LOG_HLS "HLS" -// encoder log id. +// The encoder log id. #define SRS_CONSTS_LOG_ENCODER "ENC" -// http stream log id. +// The http stream log id. #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" -// stream caster log id. +// The stream caster log id. #define SRS_CONSTS_LOG_STREAM_CASTER "SCS" -// the nginx exec log id. +// The nginx exec log id. #define SRS_CONSTS_LOG_EXEC "EXE" /////////////////////////////////////////////////////////// @@ -213,14 +203,14 @@ /////////////////////////////////////////////////////////// // HTTP consts values /////////////////////////////////////////////////////////// -// the default http port. +// The default http port. #define SRS_CONSTS_HTTP_DEFAULT_PORT 80 -// linux path seprator +// The linux path seprator #define SRS_CONSTS_HTTP_PATH_SEP '/' -// query string seprator +// Query string seprator #define SRS_CONSTS_HTTP_QUERY_SEP '?' -// the default recv timeout. +// The default recv timeout. #define SRS_HTTP_RECV_TIMEOUT (60 * SRS_UTIME_SECONDS) // 6.1.1 Status Code and Reason Phrase @@ -405,7 +395,7 @@ /////////////////////////////////////////////////////////// #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) #endif diff --git a/trunk/src/kernel/srs_kernel_error.hpp b/trunk/src/kernel/srs_kernel_error.hpp index 62c776636..95ab4cd36 100644 --- a/trunk/src/kernel/srs_kernel_error.hpp +++ b/trunk/src/kernel/srs_kernel_error.hpp @@ -28,13 +28,13 @@ #include -// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213 +// For srs-librtmp, @see https://github.com/ossrs/srs/issues/213 #ifndef _WIN32 #define ERROR_SUCCESS 0 #endif /////////////////////////////////////////////////////// -// system error. +// The system error. /////////////////////////////////////////////////////// #define ERROR_SOCKET_CREATE 1000 #define ERROR_SOCKET_SETREUSE 1001 @@ -173,18 +173,18 @@ #define ERROR_RTMP_STREAM_NAME_EMPTY 2051 #define ERROR_HTTP_HIJACK 2052 // -// system control message, -// not an error, but special control logic. +// The system control message, +// 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 -// sys ctl: rtmp close stream, support replay. +// For sys ctl: rtmp close stream, support replay. #define ERROR_CONTROL_RTMP_CLOSE 2998 -// FMLE stop publish and republish. +// When FMLE stop publish and republish. #define ERROR_CONTROL_REPUBLISH 2999 /////////////////////////////////////////////////////// -// application level +// The application level errors. /////////////////////////////////////////////////////// #define ERROR_HLS_METADATA 3000 #define ERROR_HLS_DECODE_ERROR 3001 @@ -329,23 +329,23 @@ //#define ERROR_API_METHOD_NOT_ALLOWD /////////////////////////////////////////////////////// -// user-define error. +// For user-define error. /////////////////////////////////////////////////////// #define ERROR_USER_START 9000 //#define ERROR_USER_DISCONNECT 9001 #define ERROR_SOURCE_NOT_FOUND 9002 #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. 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_client_gracefully_close(int error_code); 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 { private: diff --git a/trunk/src/kernel/srs_kernel_flv.hpp b/trunk/src/kernel/srs_kernel_flv.hpp index 685bf7284..80cd62e9c 100644 --- a/trunk/src/kernel/srs_kernel_flv.hpp +++ b/trunk/src/kernel/srs_kernel_flv.hpp @@ -28,7 +28,7 @@ #include -// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213 +// For srs-librtmp, @see https://github.com/ossrs/srs/issues/213 #ifndef _WIN32 #include #endif @@ -40,19 +40,13 @@ class SrsFileReader; #define SRS_FLV_TAG_HEADER_SIZE 11 #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 - with IDs 3-6 are reserved for usage of RTMP. Protocol message with ID - 7 is used between edge server and origin server. - */ +// 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 +// 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_AbortMessage 0x02 #define RTMP_MSG_Acknowledgement 0x03 @@ -60,167 +54,121 @@ class SrsFileReader; #define RTMP_MSG_WindowAcknowledgementSize 0x05 #define RTMP_MSG_SetPeerBandwidth 0x06 #define RTMP_MSG_EdgeAndOriginServerCommand 0x07 -/** - 3. Types of messages - The server and the client send messages over the network to - communicate with each other. The messages can be of any type which - includes audio messages, video messages, command messages, shared - object messages, data messages, and user control messages. - 3.1. Command message - Command messages carry the AMF-encoded commands between the client - and the server. These messages have been assigned message type value - of 20 for AMF0 encoding and message type value of 17 for AMF3 - encoding. These messages are sent to perform some operations like - connect, createStream, publish, play, pause on the peer. Command - messages like onstatus, result etc. are used to inform the sender - about the status of the requested commands. A command message - consists of command name, transaction ID, and command object that - contains related parameters. A client or a server can request Remote - Procedure Calls (RPC) over streams that are communicated using the - command messages to the peer. - */ +// 3. Types of messages +// The server and the client send messages over the network to +// communicate with each other. The messages can be of any type which +// includes audio messages, video messages, command messages, shared +// object messages, data messages, and user control messages. +// 3.1. Command message +// Command messages carry the AMF-encoded commands between the client +// and the server. These messages have been assigned message type value +// of 20 for AMF0 encoding and message type value of 17 for AMF3 +// encoding. These messages are sent to perform some operations like +// connect, createStream, publish, play, pause on the peer. Command +// messages like onstatus, result etc. are used to inform the sender +// about the status of the requested commands. A command message +// consists of command name, transaction ID, and command object that +// contains related parameters. A client or a server can request Remote +// Procedure Calls (RPC) over streams that are communicated using the +// command messages to the peer. #define RTMP_MSG_AMF3CommandMessage 17 // 0x11 #define RTMP_MSG_AMF0CommandMessage 20 // 0x14 -/** - 3.2. Data message - The client or the server sends this message to send Metadata or any - user data to the peer. Metadata includes details about the - data(audio, video etc.) like creation time, duration, theme and so - on. These messages have been assigned message type value of 18 for - AMF0 and message type value of 15 for AMF3. - */ +// 3.2. Data message +// The client or the server sends this message to send Metadata or any +// user data to the peer. Metadata includes details about the +// data(audio, video etc.) like creation time, duration, theme and so +// on. These messages have been assigned message type value of 18 for +// AMF0 and message type value of 15 for AMF3. #define RTMP_MSG_AMF0DataMessage 18 // 0x12 #define RTMP_MSG_AMF3DataMessage 15 // 0x0F -/** - 3.3. Shared object message - A shared object is a Flash object (a collection of name value pairs) - that are in synchronization across multiple clients, instances, and - so on. The message types kMsgContainer=19 for AMF0 and - kMsgContainerEx=16 for AMF3 are reserved for shared object events. - Each message can contain multiple events. - */ +// 3.3. Shared object message +// A shared object is a Flash object (a collection of name value pairs) +// that are in synchronization across multiple clients, instances, and +// so on. The message types kMsgContainer=19 for AMF0 and +// kMsgContainerEx=16 for AMF3 are reserved for shared object events. +// Each message can contain multiple events. #define RTMP_MSG_AMF3SharedObject 16 // 0x10 #define RTMP_MSG_AMF0SharedObject 19 // 0x13 -/** - 3.4. Audio message - 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. - */ +// 3.4. Audio message +// 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. #define RTMP_MSG_AudioMessage 8 // 0x08 -/* * - 3.5. Video message - 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. - These messages are large and can delay the sending of other type of - messages. To avoid such a situation, the video message is assigned - the lowest priority. - */ +// 3.5. Video message +// 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. +// These messages are large and can delay the sending of other type of +// messages. To avoid such a situation, the video message is assigned +// The lowest priority. #define RTMP_MSG_VideoMessage 9 // 0x09 -/** - 3.6. Aggregate message - An aggregate message is a single message that contains a list of submessages. - The message type value of 22 is reserved for aggregate - messages. - */ +// 3.6. Aggregate message +// An aggregate message is a single message that contains a list of submessages. +// The message type value of 22 is reserved for aggregate +// messages. #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 -/** - * the AMF0/AMF3 command message, invoke method and return the result, over NetConnection. - * generally use 0x03. - */ +// The AMF0/AMF3 command message, invoke method and return the result, over NetConnection. +// generally use 0x03. #define RTMP_CID_OverConnection 0x03 -/** - * the AMF0/AMF3 command message, invoke method and return the result, over NetConnection, - * the midst state(we guess). - * rarely used, e.g. onStatus(NetStream.Play.Reset). - */ +// The AMF0/AMF3 command message, invoke method and return the result, over NetConnection, +// The midst state(we guess). +// rarely used, e.g. onStatus(NetStream.Play.Reset). #define RTMP_CID_OverConnection2 0x04 -/** - * the stream message(amf0/amf3), over NetStream. - * generally use 0x05. - */ +// The stream message(amf0/amf3), over NetStream. +// generally use 0x05. #define RTMP_CID_OverStream 0x05 -/** - * the stream message(amf0/amf3), over NetStream, the midst state(we guess). - * rarely used, e.g. play("mp4:mystram.f4v") - */ +// The stream message(amf0/amf3), over NetStream, the midst state(we guess). +// rarely used, e.g. play("mp4:mystram.f4v") #define RTMP_CID_OverStream2 0x08 -/** - * the stream message(video), over NetStream - * generally use 0x06. - */ +// The stream message(video), over NetStream +// generally use 0x06. #define RTMP_CID_Video 0x06 -/** - * the stream message(audio), over NetStream. - * generally use 0x07. - */ +// The stream message(audio), over NetStream. +// generally use 0x07. #define RTMP_CID_Audio 0x07 -/** - * 6.1. Chunk Format - * Extended timestamp: 0 or 4 bytes - * 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 - * anything else. So for values less than 0xffffff the normal - * timestamp field SHOULD be used in which case the extended timestamp - * 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 - * 0xffffff and the extended timestamp MUST be sent. - */ +// 6.1. Chunk Format +// Extended timestamp: 0 or 4 bytes +// 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 +// anything else. So for values less than 0xffffff the normal +// timestamp field SHOULD be used in which case the extended timestamp +// 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 +// 0xffffff and the extended timestamp MUST be sent. #define RTMP_EXTENDED_TIMESTAMP 0xFFFFFF -/** - * 4.1. Message Header - */ +// 4.1. Message Header class SrsMessageHeader { public: - /** - * 3bytes. - * Three-byte field that contains a timestamp delta of the message. - * @remark, only used for decoding message from chunk stream. - */ + // 3bytes. + // Three-byte field that contains a timestamp delta of the message. + // @remark, only used for decoding message from chunk stream. int32_t timestamp_delta; - /** - * 3bytes. - * Three-byte field that represents the size of the payload in bytes. - * It is set in big-endian format. - */ + // 3bytes. + // Three-byte field that represents the size of the payload in bytes. + // It is set in big-endian format. int32_t payload_length; - /** - * 1byte. - * One byte field to represent the message type. A range of type IDs - * (1-7) are reserved for protocol control messages. - */ + // 1byte. + // One byte field to represent the message type. A range of type IDs + // (1-7) are reserved for protocol control messages. int8_t message_type; - /** - * 4bytes. - * Four-byte field that identifies the stream of the message. These - * bytes are set in little-endian format. - */ + // 4bytes. + // Four-byte field that identifies the stream of the message. These + // bytes are set in little-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. - */ + // Four-byte field that contains a timestamp of the message. + // The 4 bytes are packed in the big-endian order. + // @remark, used as calc timestamp when decode and encode time. + // @remark, we use 64bits for large time for jitter detect and hls. int64_t timestamp; public: - /** - * get the perfered cid(chunk stream id) which sendout over. - * set at decoding, and canbe used for directly send message, - * for example, dispatch to all connections. - */ + // Get the perfered cid(chunk stream id) which sendout over. + // set at decoding, and canbe used for directly send message, + // For example, dispatch to all connections. int perfer_cid; public: SrsMessageHeader(); @@ -239,149 +187,114 @@ public: bool is_set_peer_bandwidth(); bool is_aggregate(); 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); - /** - * 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); - /** - * 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); }; -/** - * message is raw data RTMP message, bytes oriented, - * protcol always recv RTMP message, and can send RTMP message or RTMP packet. - * the common message is read from underlay protocol sdk. - * while the shared ptr message used to copy and send. - */ +// The message is raw data RTMP message, bytes oriented, +// protcol always recv RTMP message, and can send RTMP message or RTMP packet. +// The common message is read from underlay protocol sdk. +// while the shared ptr message used to copy and send. class SrsCommonMessage { - // 4.1. Message Header +// 4.1. Message Header public: SrsMessageHeader header; - // 4.2. Message Payload +// 4.2. Message Payload public: - /** - * current message parsed size, - * size <= header.payload_length - * for the payload maybe sent in multiple chunks. - */ + // The current message parsed size, + // size <= header.payload_length + // For the payload maybe sent in multiple chunks. int size; - /** - * the payload of message, the SrsCommonMessage 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. - */ + // The payload of message, the SrsCommonMessage never know about the detail of payload, + // user must use SrsProtocol.decode_message to get concrete packet. + // @remark, not all message payload can be decoded to packet. for example, + // video/audio packet use raw bytes, no video/audio packet. char* payload; public: SrsCommonMessage(); virtual ~SrsCommonMessage(); public: - /** - * alloc the payload to specified size of bytes. - */ + // Alloc the payload to specified size of bytes. virtual void create_payload(int size); public: - /** - * create common message, - * from the header and body. - * @remark user should never free the body. - * @param pheader, the header to copy to the message. NULL to ignore. - */ + // Create common message, + // from the header and body. + // @remark user should never free the body. + // @param pheader, the header to copy to the message. NULL to ignore. virtual srs_error_t create(SrsMessageHeader* pheader, char* body, int size); }; -/** - * the message header for shared ptr message. - * only the message for all msgs are same. - */ +// The message header for shared ptr message. +// only the message for all msgs are same. struct SrsSharedMessageHeader { - /** - * 3bytes. - * Three-byte field that represents the size of the payload in bytes. - * It is set in big-endian format. - */ + // 3bytes. + // Three-byte field that represents the size of the payload in bytes. + // It is set in big-endian format. int32_t payload_length; - /** - * 1byte. - * One byte field to represent the message type. A range of type IDs - * (1-7) are reserved for protocol control messages. - */ + // 1byte. + // One byte field to represent the message type. A range of type IDs + // (1-7) are reserved for protocol control messages. int8_t message_type; - /** - * 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. - */ + // 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; SrsSharedMessageHeader(); virtual ~SrsSharedMessageHeader(); }; -/** - * shared ptr message. - * for audio/video/data message that need less memory copy. - * and only for output. - * - * create first object by constructor and create(), - * use copy if need reference count message. - * - */ +// The shared ptr message. +// For audio/video/data message that need less memory copy. +// and only for output. +// +// Create first object by constructor and create(), +// use copy if need reference count message. class SrsSharedPtrMessage { - // 4.1. Message Header +// 4.1. Message Header 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 //SrsSharedMessageHeader header; - /** - * 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. - */ + // 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; - /** - * 4bytes. - * Four-byte field that identifies the stream of the message. These - * bytes are set in big-endian format. - */ + // 4bytes. + // Four-byte field that identifies the stream of the message. These + // bytes are set in big-endian format. int32_t stream_id; // 4.2. Message Payload public: - /** - * current message parsed size, - * size <= header.payload_length - * for the payload maybe sent in multiple chunks. - */ + // The current message parsed size, + // size <= header.payload_length + // For the payload maybe sent in multiple chunks. int size; - /** - * the payload of message, the SrsCommonMessage 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. - */ + // The payload of message, the SrsCommonMessage never know about the detail of payload, + // user must use SrsProtocol.decode_message to get concrete packet. + // @remark, not all message payload can be decoded to packet. for example, + // video/audio packet use raw bytes, no video/audio packet. char* payload; private: class SrsSharedPtrPayload { public: - // shared message header. + // The shared message header. // @see https://github.com/ossrs/srs/issues/251 SrsSharedMessageHeader header; - // actual shared payload. + // The actual shared payload. char* payload; - // size of payload. + // The size of payload. int size; - // the reference count + // The reference count int shared_count; public: SrsSharedPtrPayload(); @@ -392,54 +305,40 @@ public: SrsSharedPtrMessage(); virtual ~SrsSharedPtrMessage(); public: - /** - * create shared ptr message, - * copy header, manage the payload of msg, - * set the payload to NULL to prevent double free. - * @remark payload of msg set to NULL if success. - */ + // 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 srs_error_t create(SrsCommonMessage* msg); - /** - * create shared ptr message, - * from the header and payload. - * @remark user should never free the payload. - * @param pheader, the header to copy to the message. NULL to ignore. - */ + // Create shared ptr message, + // from the header and payload. + // @remark user should never free the payload. + // @param pheader, the header to copy to the message. NULL to ignore. virtual srs_error_t create(SrsMessageHeader* pheader, char* payload, int size); - /** - * get current reference count. - * when this object created, count set to 0. - * if copy() this object, count increase 1. - * if this or copy deleted, free payload when count is 0, or count--. - * @remark, assert object is created. - */ + // Get current reference count. + // when this object created, count set to 0. + // if copy() this object, count increase 1. + // if this or copy deleted, free payload when count is 0, or count--. + // @remark, assert object is created. virtual int count(); - /** - * check perfer cid and stream id. - * @return whether stream id already set. - */ + // check perfer cid and stream id. + // @return whether stream id already set. virtual bool check(int stream_id); public: virtual bool is_av(); virtual bool is_audio(); virtual bool is_video(); public: - /** - * generate the chunk header to cache. - * @return the size of header. - */ + // generate the chunk header to cache. + // @return the size of header. virtual int chunk_header(char* cache, int nb_cache, bool c0); public: - /** - * copy current shared ptr message, use ref-count. - * @remark, assert object is created. - */ + // copy current shared ptr message, use ref-count. + // @remark, assert object is created. virtual SrsSharedPtrMessage* copy(); }; -/** - * Transmux RTMP packets to FLV stream. - */ +// Transmux RTMP packets to FLV stream. class SrsFlvTransmuxer { private: @@ -450,60 +349,48 @@ public: SrsFlvTransmuxer(); virtual ~SrsFlvTransmuxer(); public: - /** - * initialize the underlayer file stream. - * @remark user can initialize multiple times to encode multiple flv files. - * @remark, user must free the @param fw, flv encoder never close/free it. - */ + // Initialize the underlayer file stream. + // @remark user can initialize multiple times to encode multiple flv files. + // @remark, user must free the @param fw, flv encoder never close/free it. virtual srs_error_t initialize(ISrsWriter* fw); public: - /** - * write flv header. - * write following: - * 1. E.2 The FLV header - * 2. PreviousTagSize0 UI32 Always 0 - * that is, 9+4=13bytes. - */ + // Write flv header. + // Write following: + // 1. E.2 The FLV header + // 2. PreviousTagSize0 UI32 Always 0 + // that is, 9+4=13bytes. virtual srs_error_t write_header(); virtual srs_error_t write_header(char flv_header[9]); - /** - * write flv metadata. - * @param type, the type of data, or other message type. - * @see SrsFrameType - * @param data, the amf0 metadata which serialize from: - * AMF0 string: onMetaData, - * AMF0 object: the metadata object. - * @remark assert data is not NULL. - */ + // Write flv metadata. + // @param type, the type of data, or other message type. + // @see SrsFrameType + // @param data, the amf0 metadata which serialize from: + // AMF0 string: onMetaData, + // AMF0 object: the metadata object. + // @remark assert data is not NULL. virtual srs_error_t write_metadata(char type, char* data, int size); - /** - * write audio/video packet. - * @remark assert data is not NULL. - */ + // Write audio/video packet. + // @remark assert data is not NULL. 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); public: - /** - * get the tag size, - * including the tag header, body, and 4bytes previous tag size. - * @remark assert data_size is not negative. - */ + // Get the tag size, + // including the tag header, body, and 4bytes previous tag size. + // @remark assert data_size is not negative. static int size_tag(int data_size); #ifdef SRS_PERF_FAST_FLV_ENCODER private: - // cache tag header. + // The cache tag header. int nb_tag_headers; char* tag_headers; - // cache pps(previous tag size) + // The cache pps(previous tag size) int nb_ppts; char* ppts; - // cache iovss. + // The cache iovss. int nb_iovss_cache; iovec* iovss_cache; public: - /** - * write the tags in a time. - */ + // Write the tags in a time. virtual srs_error_t write_tags(SrsSharedPtrMessage** msgs, int count); #endif private: @@ -514,9 +401,7 @@ private: virtual srs_error_t write_tag(char* header, int header_size, char* tag, int tag_size); }; -/** - * decode flv file. - */ +// Decode flv file. class SrsFlvDecoder { private: @@ -525,40 +410,28 @@ public: SrsFlvDecoder(); virtual ~SrsFlvDecoder(); public: - /** - * initialize the underlayer file stream - * @remark user can initialize multiple times to decode multiple flv files. - * @remark user must free the @param fr, flv decoder never close/free it - */ + // Initialize the underlayer file stream + // @remark user can initialize multiple times to decode multiple flv files. + // @remark user must free the @param fr, flv decoder never close/free it virtual srs_error_t initialize(ISrsReader* fr); public: - /** - * read the flv header, donot including the 4bytes previous tag size. - * @remark assert header not NULL. - */ + // Read the flv header, donot including the 4bytes previous tag size. + // @remark assert header not NULL. virtual srs_error_t read_header(char header[9]); - /** - * read the tag header infos. - * @remark assert ptype/pdata_size/ptime not NULL. - */ + // Read the tag header infos. + // @remark assert ptype/pdata_size/ptime not NULL. virtual srs_error_t read_tag_header(char* ptype, int32_t* pdata_size, uint32_t* ptime); - /** - * read the tag data. - * @remark assert data not NULL. - */ + // Read the tag data. + // @remark assert data not NULL. virtual srs_error_t read_tag_data(char* data, int32_t size); - /** - * read the 4bytes previous tag size. - * @remark assert previous_tag_size not NULL. - */ + // Read the 4bytes previous tag size. + // @remark assert previous_tag_size not NULL. virtual srs_error_t read_previous_tag_size(char previous_tag_size[4]); }; -/** - * decode flv fast by only decoding the header and tag. - * used for vod flv stream to read the header and sequence header, - * then seek to specified offset. - */ +// Decode flv fast by only decoding the header and tag. +// used for vod flv stream to read the header and sequence header, +// then seek to specified offset. class SrsFlvVodStreamDecoder { private: @@ -567,31 +440,23 @@ public: SrsFlvVodStreamDecoder(); virtual ~SrsFlvVodStreamDecoder(); public: - /** - * initialize the underlayer file stream - * @remark user can initialize multiple times to decode multiple flv files. - * @remark user must free the @param fr, flv decoder never close/free it. - */ + // Initialize the underlayer file stream + // @remark user can initialize multiple times to decode multiple flv files. + // @remark user must free the @param fr, flv decoder never close/free it. virtual srs_error_t initialize(ISrsReader* fr); public: - /** - * read the flv header and its size. - * @param header, fill it 13bytes(9bytes header, 4bytes previous tag size). - * @remark assert header not NULL. - */ + // Read the flv header and its size. + // @param header, fill it 13bytes(9bytes header, 4bytes previous tag size). + // @remark assert header not NULL. virtual srs_error_t read_header_ext(char header[13]); - /** - * read the sequence header tags offset and its size. - * @param pstart, the start offset of sequence header. - * @param psize, output the size, (tag header)+(tag body)+(4bytes previous tag size). - * @remark we think the first audio/video is sequence header. - * @remark assert pstart/psize not NULL. - */ + // Read the sequence header tags offset and its size. + // @param pstart, the start offset of sequence header. + // @param psize, output the size, (tag header)+(tag body)+(4bytes previous tag size). + // @remark we think the first audio/video is sequence header. + // @remark assert pstart/psize not NULL. virtual srs_error_t read_sequence_header_summary(int64_t* pstart, int* psize); 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); }; diff --git a/trunk/src/kernel/srs_kernel_log.hpp b/trunk/src/kernel/srs_kernel_log.hpp index f371455e4..23d4399c4 100644 --- a/trunk/src/kernel/srs_kernel_log.hpp +++ b/trunk/src/kernel/srs_kernel_log.hpp @@ -33,15 +33,13 @@ #include -/** - * the log level, for example: - * if specified Debug level, all level messages will be logged. - * if specified Warn level, only Warn/Error/Fatal level messages will be logged. - */ +// The log level, for example: +// if specified Debug level, all level messages will be logged. +// if specified Warn level, only Warn/Error/Fatal level messages will be logged. enum SrsLogLevel { SrsLogLevelForbidden = 0x00, - // only used for very verbose debug, generally, + // Only used for very verbose debug, generally, // we compile without this level for high performance. SrsLogLevelVerbose = 0x01, SrsLogLevelInfo = 0x02, @@ -51,85 +49,63 @@ enum SrsLogLevel SrsLogLevelDisabled = 0x20, }; -/** - * the log interface provides method to write log. - * 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. - */ +// The log interface provides method to write log. +// 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. class ISrsLog { public: ISrsLog(); virtual ~ISrsLog(); public: - /** - * initialize log utilities. - */ + // Initialize log utilities. virtual srs_error_t initialize(); - /** - * reopen the log file for log rotate. - */ + // Reopen the log file for log rotate. virtual void reopen(); public: - /** - * log for verbose, very verbose information. - */ + // The log for verbose, very verbose information. virtual void verbose(const char* tag, int context_id, const char* fmt, ...); - /** - * log for debug, detail information. - */ + // The log for debug, detail information. virtual void info(const char* tag, int context_id, const char* fmt, ...); - /** - * log for trace, important information. - */ + // The log for trace, important information. virtual void trace(const char* tag, int context_id, const char* fmt, ...); - /** - * log for warn, warn is something should take attention, but not a error. - */ + // The 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, ...); - /** - * log for error, something error occur, do something about the error, ie. close the connection, - * but we will donot abort the program. - */ + // The log for error, something error occur, do something about the error, ie. close the connection, + // but we will donot abort the program. virtual void error(const char* tag, int context_id, const char* fmt, ...); }; -/** - * the context id manager to identify context, for instance, the green-thread. - * usage: - * _srs_context->generate_id(); // when thread start. - * _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. - */ -// the context for multiple clients. +// The context id manager to identify context, for instance, the green-thread. +// Usage: +// _srs_context->generate_id(); // when thread start. +// _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. +// The context for multiple clients. class ISrsThreadContext { public: ISrsThreadContext(); virtual ~ISrsThreadContext(); public: - /** - * generate the id for current context. - */ + // Generate the id for current context. virtual int generate_id(); - /** - * get the generated id of current context. - */ + // Get the generated id of current context. virtual int get_id(); - /** - * set the id of current context. - * @return the previous id value; 0 if no context. - */ + // Set the id of current context. + // @return the previous id value; 0 if no context. virtual int set_id(int v); }; -// @global user must provides a log object +// @global User must provides a log object 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; -// donot print method +// Log style. +// Use __FUNCTION__ to print c method +// Use __PRETTY_FUNCTION__ to print c++ class:method #if 1 #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__) @@ -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_error(msg, ...) _srs_log->error(NULL, _srs_context->get_id(), msg, ##__VA_ARGS__) #endif -// use __FUNCTION__ to print c method #if 0 #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__) @@ -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_error(msg, ...) _srs_log->error(__FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) #endif -// use __PRETTY_FUNCTION__ to print c++ class:method #if 0 #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__) @@ -154,7 +128,7 @@ extern ISrsThreadContext* _srs_context; #define srs_error(msg, ...) _srs_log->error(__PRETTY_FUNCTION__, _srs_context->get_id(), msg, ##__VA_ARGS__) #endif -// TODO: FIXME: add more verbose and info logs. +// TODO: FIXME: Add more verbose and info logs. #ifndef SRS_AUTO_VERBOSE #undef srs_verbose #define srs_verbose(msg, ...) (void)0 diff --git a/trunk/src/kernel/srs_kernel_mp4.hpp b/trunk/src/kernel/srs_kernel_mp4.hpp index 6b3bed71b..593eb56b8 100644 --- a/trunk/src/kernel/srs_kernel_mp4.hpp +++ b/trunk/src/kernel/srs_kernel_mp4.hpp @@ -71,10 +71,8 @@ class SrsMp4TrackFragmentHeaderBox; class SrsMp4TrackFragmentDecodeTimeBox; class SrsMp4TrackFragmentRunBox; -/** - * 4.2 Object Structure - * ISO_IEC_14496-12-base-format-2012.pdf, page 16 - */ +// 4.2 Object Structure +// ISO_IEC_14496-12-base-format-2012.pdf, page 16 enum SrsMp4BoxType { SrsMp4BoxTypeForbidden = 0x00, @@ -127,10 +125,8 @@ enum SrsMp4BoxType SrsMp4BoxTypeTRUN = 0x7472756e, // 'trun' }; -/** - * 8.4.3.3 Semantics - * ISO_IEC_14496-12-base-format-2012.pdf, page 37 - */ +// 8.4.3.3 Semantics +// ISO_IEC_14496-12-base-format-2012.pdf, page 37 enum SrsMp4HandlerType { SrsMp4HandlerTypeForbidden = 0x00, @@ -139,10 +135,8 @@ enum SrsMp4HandlerType SrsMp4HandlerTypeSOUN = 0x736f756e, // 'soun' }; -/** - * File format brands - * ISO_IEC_14496-12-base-format-2012.pdf, page 166 - */ +// File format brands +// ISO_IEC_14496-12-base-format-2012.pdf, page 166 enum SrsMp4BoxBrand { SrsMp4BoxBrandForbidden = 0x00, @@ -156,9 +150,7 @@ enum SrsMp4BoxBrand SrsMp4BoxBrandMSDH = 0x6d736468, // 'msdh' }; -/** - * The context to dump. - */ +// The context to dump. struct SrsMp4DumpContext { int level; @@ -167,15 +159,13 @@ struct SrsMp4DumpContext SrsMp4DumpContext indent(); }; -/** - * 4.2 Object Structure - * ISO_IEC_14496-12-base-format-2012.pdf, page 16 - */ +// 4.2 Object Structure +// ISO_IEC_14496-12-base-format-2012.pdf, page 16 class SrsMp4Box : public ISrsCodec { private: // The size is the entire size of the box, including the size and type header, fields, - // and all contained boxes. This facilitates general parsing of the file. + // And all contained boxes. This facilitates general parsing of the file. // // if size is 1 then the actual size is in the field largesize; // if size is 0, then this box is the last one in the file, and its contents @@ -185,7 +175,7 @@ private: public: // identifies the box type; standard boxes use a compact type, which is normally four printable // characters, to permit ease of identification, and is shown so in the boxes below. User extensions use - // an extended type; in this case, the type field is set to ‘uuid’. + // An extended type; in this case, the type field is set to ‘uuid’. SrsMp4BoxType type; // For box 'uuid'. std::vector usertype; @@ -218,10 +208,8 @@ public: virtual int remove(SrsMp4BoxType bt); // Dumps the box and all contained boxes. virtual std::stringstream& dumps(std::stringstream& ss, SrsMp4DumpContext dc); - /** - * Discovery the box from buffer. - * @param ppbox Output the discoveried box, which user must free it. - */ + // Discovery the box from buffer. + // @param ppbox Output the discoveried box, which user must free it. static srs_error_t discovery(SrsBuffer* buf, SrsMp4Box** ppbox); // Interface ISrsCodec public: @@ -250,16 +238,14 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 4.2 Object Structure - * ISO_IEC_14496-12-base-format-2012.pdf, page 17 - */ +// 4.2 Object Structure +// ISO_IEC_14496-12-base-format-2012.pdf, page 17 class SrsMp4FullBox : public SrsMp4Box { public: - // an integer that specifies the version of this format of the box. + // An integer that specifies the version of this format of the box. uint8_t version; - // a map of flags + // A map of flags uint32_t flags; public: SrsMp4FullBox(); @@ -272,23 +258,21 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 4.3 File Type Box (ftyp) - * ISO_IEC_14496-12-base-format-2012.pdf, page 17 - * Files written to this version of this specification must contain a file-type box. For compatibility with an earlier - * version of this specification, files may be conformant to this specification and not contain a file-type box. Files - * with no file-type box should be read as if they contained an FTYP box with Major_brand='mp41', minor_version=0, and - * the single compatible brand 'mp41'. - */ +// 4.3 File Type Box (ftyp) +// ISO_IEC_14496-12-base-format-2012.pdf, page 17 +// Files written to this version of this specification must contain a file-type box. For compatibility with an earlier +// version of this specification, files may be conformant to this specification and not contain a file-type box. Files +// with no file-type box should be read as if they contained an FTYP box with Major_brand='mp41', minor_version=0, and +// The single compatible brand 'mp41'. class SrsMp4FileTypeBox : public SrsMp4Box { public: - // a brand identifier + // A brand identifier SrsMp4BoxBrand major_brand; - // an informative integer for the minor version of the major brand + // An informative integer for the minor version of the major brand uint32_t minor_version; private: - // a list, to the end of the box, of brands + // A list, to the end of the box, of brands std::vector compatible_brands; public: SrsMp4FileTypeBox(); @@ -304,13 +288,11 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.16.2 Segment Type Box (styp) - * ISO_IEC_14496-12-base-format-2012.pdf, page 105 - * If segments are stored in separate files (e.g. on a standard HTTP server) it is recommended that these - * 'segment files' contain a segment-type box, which must be first if present, to enable identification of those files, - * and declaration of the specifications with which they are compliant. - */ +// 8.16.2 Segment Type Box (styp) +// ISO_IEC_14496-12-base-format-2012.pdf, page 105 +// If segments are stored in separate files (e.g. on a standard HTTP server) it is recommended that these +// 'segment files' contain a segment-type box, which must be first if present, to enable identification of those files, +// And declaration of the specifications with which they are compliant. class SrsMp4SegmentTypeBox : public SrsMp4FileTypeBox { public: @@ -318,14 +300,12 @@ public: virtual ~SrsMp4SegmentTypeBox(); }; -/** - * 8.8.4 Movie Fragment Box (moof) - * ISO_IEC_14496-12-base-format-2012.pdf, page 66 - * The movie fragments extend the presentation in time. They provide the information that would previously have - * been in the Movie Box. The actual samples are in Media Data Boxes, as usual, if they are in the same file. - * The data reference index is in the sample description, so it is possible to build incremental presentations - * where the media data is in files other than the file containing the Movie Box. - */ +// 8.8.4 Movie Fragment Box (moof) +// ISO_IEC_14496-12-base-format-2012.pdf, page 66 +// The movie fragments extend the presentation in time. They provide the information that would previously have +// been in the Movie Box. The actual samples are in Media Data Boxes, as usual, if they are in the same file. +// The data reference index is in the sample description, so it is possible to build incremental presentations +// where the media data is in files other than the file containing the Movie Box. class SrsMp4MovieFragmentBox : public SrsMp4Box { public: @@ -340,18 +320,16 @@ public: virtual void set_traf(SrsMp4TrackFragmentBox* v); }; -/** - * 8.8.5 Movie Fragment Header Box (mfhd) - * ISO_IEC_14496-12-base-format-2012.pdf, page 67 - * The movie fragment header contains a sequence number, as a safety check. The sequence number usually - * starts at 1 and must increase for each movie fragment in the file, in the order in which they occur. This allows - * readers to verify integrity of the sequence; it is an error to construct a file where the fragments are out of - * sequence. - */ +// 8.8.5 Movie Fragment Header Box (mfhd) +// ISO_IEC_14496-12-base-format-2012.pdf, page 67 +// The movie fragment header contains a sequence number, as a safety check. The sequence number usually +// starts at 1 and must increase for each movie fragment in the file, in the order in which they occur. This allows +// readers to verify integrity of the sequence; it is an error to construct a file where the fragments are out of +// sequence. class SrsMp4MovieFragmentHeaderBox : public SrsMp4FullBox { public: - // the ordinal number of this fragment, in increasing order + // The ordinal number of this fragment, in increasing order uint32_t sequence_number; public: SrsMp4MovieFragmentHeaderBox(); @@ -364,13 +342,11 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.8.6 Track Fragment Box (traf) - * ISO_IEC_14496-12-base-format-2012.pdf, page 67 - * Within the movie fragment there is a set of track fragments, zero or more per track. The track fragments in - * turn contain zero or more track runs, each of which document a contiguous run of samples for that track. - * Within these structures, many fields are optional and can be defaulted. - */ +// 8.8.6 Track Fragment Box (traf) +// ISO_IEC_14496-12-base-format-2012.pdf, page 67 +// Within the movie fragment there is a set of track fragments, zero or more per track. The track fragments in +// turn contain zero or more track runs, each of which document a contiguous run of samples for that track. +// Within these structures, many fields are optional and can be defaulted. class SrsMp4TrackFragmentBox : public SrsMp4Box { public: @@ -388,59 +364,47 @@ public: virtual void set_trun(SrsMp4TrackFragmentRunBox* v); }; -/** - * The tf_flags of tfhd. - * ISO_IEC_14496-12-base-format-2012.pdf, page 68 - */ +// The tf_flags of tfhd. +// ISO_IEC_14496-12-base-format-2012.pdf, page 68 enum SrsMp4TfhdFlags { - /** - * indicates the presence of the base-data-offset field. This provides - * an explicit anchor for the data offsets in each track run (see below). If not provided, the base-data- - * offset for the first track in the movie fragment is the position of the first byte of the enclosing Movie - * Fragment Box, and for second and subsequent track fragments, the default is the end of the data - * defined by the preceding fragment. Fragments 'inheriting' their offset in this way must all use - * the same data-reference (i.e., the data for these tracks must be in the same file). - */ + // indicates the presence of the base-data-offset field. This provides + // An explicit anchor for the data offsets in each track run (see below). If not provided, the base-data- + // offset for the first track in the movie fragment is the position of the first byte of the enclosing Movie + // Fragment Box, and for second and subsequent track fragments, the default is the end of the data + // defined by the preceding fragment. Fragments 'inheriting' their offset in this way must all use + // The same data-reference (i.e., the data for these tracks must be in the same file). SrsMp4TfhdFlagsBaseDataOffset = 0x000001, - /** - * indicates the presence of this field, which over-rides, in this - * fragment, the default set up in the Track Extends Box. - */ + // indicates the presence of this field, which over-rides, in this + // fragment, the default set up in the Track Extends Box. SrsMp4TfhdFlagsSampleDescriptionIndex = 0x000002, SrsMp4TfhdFlagsDefaultSampleDuration = 0x000008, SrsMp4TfhdFlagsDefautlSampleSize = 0x000010, SrsMp4TfhdFlagsDefaultSampleFlags = 0x000020, - /** - * this indicates that the duration provided in either default-sample-duration, - * or by the default-duration in the Track Extends Box, is empty, i.e. that there are no samples for this - * time interval. It is an error to make a presentation that has both edit lists in the Movie Box, and empty- - * duration fragments. - */ + // this indicates that the duration provided in either default-sample-duration, + // or by the default-duration in the Track Extends Box, is empty, i.e. that there are no samples for this + // time interval. It is an error to make a presentation that has both edit lists in the Movie Box, and empty- + // duration fragments. SrsMp4TfhdFlagsDurationIsEmpty = 0x010000, - /** - * if base-data-offset-present is zero, this indicates that the base-data- - * offset for this track fragment is the position of the first byte of the enclosing Movie Fragment Box. - * Support for the default-base-is-moof flag is required under the ‘iso5’ brand, and it shall not be used in - * brands or compatible brands earlier than iso5. - */ + // if base-data-offset-present is zero, this indicates that the base-data- + // offset for this track fragment is the position of the first byte of the enclosing Movie Fragment Box. + // Support for the default-base-is-moof flag is required under the ‘iso5’ brand, and it shall not be used in + // brands or compatible brands earlier than iso5. SrsMp4TfhdFlagsDefaultBaseIsMoof = 0x020000, }; -/** - * 8.8.7 Track Fragment Header Box (tfhd) - * ISO_IEC_14496-12-base-format-2012.pdf, page 68 - * Each movie fragment can add zero or more fragments to each track; and a track fragment can add zero or - * more contiguous runs of samples. The track fragment header sets up information and defaults used for those - * runs of samples. - */ +// 8.8.7 Track Fragment Header Box (tfhd) +// ISO_IEC_14496-12-base-format-2012.pdf, page 68 +// Each movie fragment can add zero or more fragments to each track; and a track fragment can add zero or +// more contiguous runs of samples. The track fragment header sets up information and defaults used for those +// runs of samples. class SrsMp4TrackFragmentHeaderBox : public SrsMp4FullBox { public: uint32_t track_id; // all the following are optional fields public: - // the base offset to use when calculating data offsets + // The base offset to use when calculating data offsets uint64_t base_data_offset; uint32_t sample_description_index; uint32_t default_sample_duration; @@ -457,15 +421,13 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.8.12 Track fragment decode time (tfdt) - * ISO_IEC_14496-12-base-format-2012.pdf, page 72 - * The Track Fragment Base Media Decode Time Box provides the absolute decode time, measured on - * the media timeline, of the first sample in decode order in the track fragment. This can be useful, for example, - * when performing random access in a file; it is not necessary to sum the sample durations of all preceding - * samples in previous fragments to find this value (where the sample durations are the deltas in the Decoding - * Time to Sample Box and the sample_durations in the preceding track runs). - */ +// 8.8.12 Track fragment decode time (tfdt) +// ISO_IEC_14496-12-base-format-2012.pdf, page 72 +// The Track Fragment Base Media Decode Time Box provides the absolute decode time, measured on +// The media timeline, of the first sample in decode order in the track fragment. This can be useful, for example, +// when performing random access in a file; it is not necessary to sum the sample durations of all preceding +// samples in previous fragments to find this value (where the sample durations are the deltas in the Decoding +// Time to Sample Box and the sample_durations in the preceding track runs). class SrsMp4TrackFragmentDecodeTimeBox : public SrsMp4FullBox { public: @@ -482,10 +444,8 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * The tr_flags for trun - * ISO_IEC_14496-12-base-format-2012.pdf, page 69 - */ +// The tr_flags for trun +// ISO_IEC_14496-12-base-format-2012.pdf, page 69 enum SrsMp4TrunFlags { // data-offset-present. @@ -497,18 +457,16 @@ enum SrsMp4TrunFlags SrsMp4TrunFlagsFirstSample = 0x000004, // indicates that each sample has its own duration, otherwise the default is used. SrsMp4TrunFlagsSampleDuration = 0x000100, - // each sample has its own size, otherwise the default is used. + // Each sample has its own size, otherwise the default is used. SrsMp4TrunFlagsSampleSize = 0x000200, - // each sample has its own flags, otherwise the default is used. + // Each sample has its own flags, otherwise the default is used. SrsMp4TrunFlagsSampleFlag = 0x000400, - // each sample has a composition time offset (e.g. as used for I/P/B video in MPEG). + // Each sample has a composition time offset (e.g. as used for I/P/B video in MPEG). SrsMp4TrunFlagsSampleCtsOffset = 0x000800, }; -/** - * Entry for trun. - * ISO_IEC_14496-12-base-format-2012.pdf, page 69 - */ +// Entry for trun. +// ISO_IEC_14496-12-base-format-2012.pdf, page 69 struct SrsMp4TrunEntry { SrsMp4FullBox* owner; @@ -528,19 +486,17 @@ struct SrsMp4TrunEntry virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.8.8 Track Fragment Run Box (trun) - * ISO_IEC_14496-12-base-format-2012.pdf, page 69 - * Within the Track Fragment Box, there are zero or more Track Run Boxes. If the duration-is-empty flag is set in - * the tf_flags, there are no track runs. A track run documents a contiguous set of samples for a track. - */ +// 8.8.8 Track Fragment Run Box (trun) +// ISO_IEC_14496-12-base-format-2012.pdf, page 69 +// Within the Track Fragment Box, there are zero or more Track Run Boxes. If the duration-is-empty flag is set in +// The tf_flags, there are no track runs. A track run documents a contiguous set of samples for a track. class SrsMp4TrackFragmentRunBox : public SrsMp4FullBox { public: - // the number of samples being added in this run; also the number of rows in the following + // The number of samples being added in this run; also the number of rows in the following // table (the rows can be empty) uint32_t sample_count; -// the following are optional fields +// The following are optional fields public: // added to the implicit or explicit data_offset established in the track fragment header. int32_t data_offset; @@ -560,53 +516,51 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.1.1 Media Data Box (mdat) - * ISO_IEC_14496-12-base-format-2012.pdf, page 29 - * This box contains the media data. In video tracks, this box would contain video frames. - * A presentation may contain zero or more Media Data Boxes. The actual media data follows the type field; - * its structure is described by the metadata (see particularly the sample table, subclause 8.5, and the - * item location box, subclause 8.11.3). - * - * @remark The mdat box only decode and encode the header, - * so user must read and write the data by yourself. - * To encode mdat: - * SrsMp4MediaDataBox* mdat = new SrsMp4MediaDataBox(); - * mdat->nb_data = 1024000; - * - * char* buffer = new char[mdat->sz_header()]; - * SrsBuffer* buf = new SrsBuffer(buffer); - * mdat->encode(buf); - * - * file->write(buffer, mdat->sz_header()); // Write the mdat box header. - * file->write(data, size); // Write the mdat box data. - * - * To decode mdat: - * SrsMp4MediaDataBox* mdat = new SrsMp4MediaDataBox(); - * char* buffer = new char[mdat->sz_header()]; - * SrsBuffer* buf = ...; // Read mdat->sz_header() data from io. - * - * mdat->decode(buf); // The buf should be empty now. - * file->lseek(mdat->nb_data, SEEK_CUR); // Skip the mdat data in file. - * - * To discovery any box from file: - * SrsSimpleStream* stream = new SrsSimpleStream(); - * SrsBuffer* buf = new SrsBuffer(stream...); // Create read buffer from stream. - * - * // We don't know what's the next box, so try to read 4bytes and discovery it. - * append(file, stream, 4); // Append 4bytes from file to stream. - * - * SrsMp4Box* box = NULL; - * SrsMp4Box::discovery(buf, &box); - * - * required = (box->is_mdat()? box->sz_header():box->sz()); // Now we know how many bytes we needed. - * append(file, stream, required); - * box->decode(buf); - * - * if (box->is_mdat()) { - * file->lseek(mdat->nb_data, SEEK_CUR); // Skip the mdat data in file. - * } - */ +// 8.1.1 Media Data Box (mdat) +// ISO_IEC_14496-12-base-format-2012.pdf, page 29 +// This box contains the media data. In video tracks, this box would contain video frames. +// A presentation may contain zero or more Media Data Boxes. The actual media data follows the type field; +// its structure is described by the metadata (see particularly the sample table, subclause 8.5, and the +// item location box, subclause 8.11.3). +// +// @remark The mdat box only decode and encode the header, +// so user must read and write the data by yourself. +// To encode mdat: +// SrsMp4MediaDataBox* mdat = new SrsMp4MediaDataBox(); +// mdat->nb_data = 1024000; +// +// char* buffer = new char[mdat->sz_header()]; +// SrsBuffer* buf = new SrsBuffer(buffer); +// mdat->encode(buf); +// +// file->write(buffer, mdat->sz_header()); // Write the mdat box header. +// file->write(data, size); // Write the mdat box data. +// +// To decode mdat: +// SrsMp4MediaDataBox* mdat = new SrsMp4MediaDataBox(); +// char* buffer = new char[mdat->sz_header()]; +// SrsBuffer* buf = ...; // Read mdat->sz_header() data from io. +// +// mdat->decode(buf); // The buf should be empty now. +// file->lseek(mdat->nb_data, SEEK_CUR); // Skip the mdat data in file. +// +// To discovery any box from file: +// SrsSimpleStream* stream = new SrsSimpleStream(); +// SrsBuffer* buf = new SrsBuffer(stream...); // Create read buffer from stream. +// +// // We don't know what's the next box, so try to read 4bytes and discovery it. +// append(file, stream, 4); // Append 4bytes from file to stream. +// +// SrsMp4Box* box = NULL; +// SrsMp4Box::discovery(buf, &box); +// +// required = (box->is_mdat()? box->sz_header():box->sz()); // Now we know how many bytes we needed. +// append(file, stream, required); +// box->decode(buf); +// +// if (box->is_mdat()) { +// file->lseek(mdat->nb_data, SEEK_CUR); // Skip the mdat data in file. +// } class SrsMp4MediaDataBox : public SrsMp4Box { public: @@ -634,10 +588,8 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.1.2 Free Space Box (free or skip) - * ISO_IEC_14496-12-base-format-2012.pdf, page 29 - */ +// 8.1.2 Free Space Box (free or skip) +// ISO_IEC_14496-12-base-format-2012.pdf, page 29 class SrsMp4FreeSpaceBox : public SrsMp4Box { private: @@ -653,12 +605,10 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.2.1 Movie Box (moov) - * ISO_IEC_14496-12-base-format-2012.pdf, page 30 - * The metadata for a presentation is stored in the single Movie Box which occurs at the top-level of a file. - * Normally this box is close to the beginning or end of the file, though this is not required. - */ +// 8.2.1 Movie Box (moov) +// ISO_IEC_14496-12-base-format-2012.pdf, page 30 +// The metadata for a presentation is stored in the single Movie Box which occurs at the top-level of a file. +// Normally this box is close to the beginning or end of the file, though this is not required. class SrsMp4MovieBox : public SrsMp4Box { public: @@ -687,40 +637,38 @@ protected: virtual srs_error_t decode_header(SrsBuffer* buf); }; -/** - * 8.2.2 Movie Header Box (mvhd) - * ISO_IEC_14496-12-base-format-2012.pdf, page 31 - */ +// 8.2.2 Movie Header Box (mvhd) +// ISO_IEC_14496-12-base-format-2012.pdf, page 31 class SrsMp4MovieHeaderBox : public SrsMp4FullBox { public: - // an integer that declares the creation time of the presentation (in seconds since + // An integer that declares the creation time of the presentation (in seconds since // midnight, Jan. 1, 1904, in UTC time) uint64_t creation_time; - // an integer that declares the most recent time the presentation was modified (in + // An integer that declares the most recent time the presentation was modified (in // seconds since midnight, Jan. 1, 1904, in UTC time) uint64_t modification_time; public: - // an integer that specifies the time-scale for the entire presentation; this is the number of + // An integer that specifies the time-scale for the entire presentation; this is the number of // time units that pass in one second. For example, a time coordinate system that measures time in // sixtieths of a second has a time scale of 60. uint32_t timescale; - // an integer that declares length of the presentation (in the indicated timescale). This property + // An integer that declares length of the presentation (in the indicated timescale). This property // is derived from the presentation’s tracks: the value of this field corresponds to the duration of the // longest track in the presentation. If the duration cannot be determined then duration is set to all 1s. uint64_t duration_in_tbn; public: - // a fixed point 16.16 number that indicates the preferred rate to play the presentation; 1.0 + // A fixed point 16.16 number that indicates the preferred rate to play the presentation; 1.0 // (0x00010000) is normal forward playback uint32_t rate; - // a fixed point 8.8 number that indicates the preferred playback volume. 1.0 (0x0100) is full volume. + // A fixed point 8.8 number that indicates the preferred playback volume. 1.0 (0x0100) is full volume. uint16_t volume; uint16_t reserved0; uint64_t reserved1; - // a transformation matrix for the video; (u,v,w) are restricted here to (0,0,1), hex values (0,0,0x40000000). + // A transformation matrix for the video; (u,v,w) are restricted here to (0,0,1), hex values (0,0,0x40000000). int32_t matrix[9]; uint32_t pre_defined[6]; - // a non-zero integer that indicates a value to use for the track ID of the next track to be + // A non-zero integer that indicates a value to use for the track ID of the next track to be // added to this presentation. Zero is not a valid track ID value. The value of next_track_ID shall be // larger than the largest track-ID in use. If this value is equal to all 1s (32-bit maxint), and a new media // track is to be added, then a search must be made in the file for an unused track identifier. @@ -747,13 +695,11 @@ enum SrsMp4TrackType SrsMp4TrackTypeVideo = 0x02, }; -/** - * 8.8.1 Movie Extends Box (mvex) - * ISO_IEC_14496-12-base-format-2012.pdf, page 64 - * This box warns readers that there might be Movie Fragment Boxes in this file. To know of all samples in the - * tracks, these Movie Fragment Boxes must be found and scanned in order, and their information logically - * added to that found in the Movie Box. - */ +// 8.8.1 Movie Extends Box (mvex) +// ISO_IEC_14496-12-base-format-2012.pdf, page 64 +// This box warns readers that there might be Movie Fragment Boxes in this file. To know of all samples in the +// tracks, these Movie Fragment Boxes must be found and scanned in order, and their information logically +// added to that found in the Movie Box. class SrsMp4MovieExtendsBox : public SrsMp4Box { public: @@ -765,16 +711,14 @@ public: virtual void set_trex(SrsMp4TrackExtendsBox* v); }; -/** - * 8.8.3 Track Extends Box(trex) - * ISO_IEC_14496-12-base-format-2012.pdf, page 65 - */ +// 8.8.3 Track Extends Box(trex) +// ISO_IEC_14496-12-base-format-2012.pdf, page 65 class SrsMp4TrackExtendsBox : public SrsMp4FullBox { public: // identifies the track; this shall be the track ID of a track in the Movie Box uint32_t track_ID; - // these fields set up defaults used in the track fragments. + // These fields set up defaults used in the track fragments. uint32_t default_sample_description_index; uint32_t default_sample_duration; uint32_t default_sample_size; @@ -790,13 +734,11 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.3.1 Track Box (trak) - * ISO_IEC_14496-12-base-format-2012.pdf, page 32 - * This is a container box for a single track of a presentation. A presentation consists of one or more tracks. - * Each track is independent of the other tracks in the presentation and carries its own temporal and spatial - * information. Each track will contain its associated Media Box. - */ +// 8.3.1 Track Box (trak) +// ISO_IEC_14496-12-base-format-2012.pdf, page 32 +// This is a container box for a single track of a presentation. A presentation consists of one or more tracks. +// Each track is independent of the other tracks in the presentation and carries its own temporal and spatial +// information. Each track will contain its associated Media Box. class SrsMp4TrackBox : public SrsMp4Box { public: @@ -851,26 +793,24 @@ public: virtual SrsMp4AudioSampleEntry* mp4a(); }; -/** - * 8.3.2 Track Header Box (tkhd) - * ISO_IEC_14496-12-base-format-2012.pdf, page 32 - */ +// 8.3.2 Track Header Box (tkhd) +// ISO_IEC_14496-12-base-format-2012.pdf, page 32 class SrsMp4TrackHeaderBox : public SrsMp4FullBox { public: - // an integer that declares the creation time of the presentation (in seconds since + // An integer that declares the creation time of the presentation (in seconds since // midnight, Jan. 1, 1904, in UTC time) uint64_t creation_time; - // an integer that declares the most recent time the presentation was modified (in + // An integer that declares the most recent time the presentation was modified (in // seconds since midnight, Jan. 1, 1904, in UTC time) uint64_t modification_time; - // an integer that uniquely identifies this track over the entire life-time of this presentation. + // An integer that uniquely identifies this track over the entire life-time of this presentation. // Track IDs are never re-used and cannot be zero. uint32_t track_ID; uint32_t reserved0; - // an integer that indicates the duration of this track (in the timescale indicated in the Movie + // An integer that indicates the duration of this track (in the timescale indicated in the Movie // Header Box). The value of this field is equal to the sum of the durations of all of the track’s edits. If - // there is no edit list, then the duration is the sum of the sample durations, converted into the timescale + // There is no edit list, then the duration is the sum of the sample durations, converted into the timescale // in the Movie Header Box. If the duration of this track cannot be determined then duration is set to all // 1s. uint64_t duration; @@ -879,25 +819,25 @@ public: // specifies the front-to-back ordering of video tracks; tracks with lower numbers are closer to the // viewer. 0 is the normal value, and -1 would be in front of track 0, and so on. int16_t layer; - // an integer that specifies a group or collection of tracks. If this field is 0 there is no + // An integer that specifies a group or collection of tracks. If this field is 0 there is no // information on possible relations to other tracks. If this field is not 0, it should be the same for tracks // that contain alternate data for one another and different for tracks belonging to different such groups. // Only one track within an alternate group should be played or streamed at any one time, and must be // distinguishable from other tracks in the group via attributes such as bitrate, codec, language, packet // size etc. A group may have only one member. int16_t alternate_group; - // a fixed 8.8 value specifying the track's relative audio volume. Full volume is 1.0 (0x0100) and + // A fixed 8.8 value specifying the track's relative audio volume. Full volume is 1.0 (0x0100) and // is the normal value. Its value is irrelevant for a purely visual track. Tracks may be composed by // combining them according to their volume, and then using the overall Movie Header Box volume // setting; or more complex audio composition (e.g. MPEG-4 BIFS) may be used. int16_t volume; uint16_t reserved2; - // a transformation matrix for the video; (u,v,w) are restricted here to (0,0,1), hex (0,0,0x40000000). + // A transformation matrix for the video; (u,v,w) are restricted here to (0,0,1), hex (0,0,0x40000000). int32_t matrix[9]; - // the track's visual presentation size as fixed-point 16.16 values. These need + // The track's visual presentation size as fixed-point 16.16 values. These need // not be the same as the pixel dimensions of the images, which is documented in the sample // description(s); all images in the sequence are scaled to this size, before any overall transformation of - // the track represented by the matrix. The pixel dimensions of the images are the default values. + // The track represented by the matrix. The pixel dimensions of the images are the default values. int32_t width; int32_t height; public: @@ -911,12 +851,10 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.6.5 Edit Box (edts) - * ISO_IEC_14496-12-base-format-2012.pdf, page 54 - * An Edit Box maps the presentation time-line to the media time-line as it is stored in the file. - * The Edit Box is a container for the edit lists. - */ +// 8.6.5 Edit Box (edts) +// ISO_IEC_14496-12-base-format-2012.pdf, page 54 +// An Edit Box maps the presentation time-line to the media time-line as it is stored in the file. +// The Edit Box is a container for the edit lists. class SrsMp4EditBox : public SrsMp4Box { public: @@ -924,24 +862,22 @@ public: virtual ~SrsMp4EditBox(); }; -/** - * 8.6.6 Edit List Box - * ISO_IEC_14496-12-base-format-2012.pdf, page 55 - */ +// 8.6.6 Edit List Box +// ISO_IEC_14496-12-base-format-2012.pdf, page 55 struct SrsMp4ElstEntry { public: - // an integer that specifies the duration of this edit segment in units of the timescale + // An integer that specifies the duration of this edit segment in units of the timescale // in the Movie Header Box uint64_t segment_duration; - // an integer containing the starting time within the media of this edit segment (in media time + // An integer containing the starting time within the media of this edit segment (in media time // scale units, in composition time). If this field is set to –1, it is an empty edit. The last edit in a track // shall never be an empty edit. Any difference between the duration in the Movie Header Box, and the // track’s duration is expressed as an implicit empty edit at the end. int64_t media_time; public: // specifies the relative rate at which to play the media corresponding to this edit segment. If this value is 0, - // then the edit is specifying a ‘dwell’: the media at media-time is presented for the segment-duration. Otherwise + // Then the edit is specifying a ‘dwell’: the media at media-time is presented for the segment-duration. Otherwise // this field shall contain the value 1. int16_t media_rate_integer; int16_t media_rate_fraction; @@ -953,17 +889,15 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.6.6 Edit List Box (elst) - * ISO_IEC_14496-12-base-format-2012.pdf, page 54 - * This box contains an explicit timeline map. Each entry defines part of the track time-line: by mapping part of - * the media time-line, or by indicating ‘empty’ time, or by defining a ‘dwell’, where a single time-point in the - * media is held for a period. - */ +// 8.6.6 Edit List Box (elst) +// ISO_IEC_14496-12-base-format-2012.pdf, page 54 +// This box contains an explicit timeline map. Each entry defines part of the track time-line: by mapping part of +// The media time-line, or by indicating ‘empty’ time, or by defining a ‘dwell’, where a single time-point in the +// media is held for a period. class SrsMp4EditListBox : public SrsMp4FullBox { public: - // an integer that gives the number of entries in the following table + // An integer that gives the number of entries in the following table std::vector entries; public: SrsMp4EditListBox(); @@ -976,12 +910,10 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.4.1 Media Box (mdia) - * ISO_IEC_14496-12-base-format-2012.pdf, page 36 - * The media declaration container contains all the objects that declare information about the media data within a - * track. - */ +// 8.4.1 Media Box (mdia) +// ISO_IEC_14496-12-base-format-2012.pdf, page 36 +// The media declaration container contains all the objects that declare information about the media data within a +// track. class SrsMp4MediaBox : public SrsMp4Box { public: @@ -1003,31 +935,29 @@ public: virtual void set_minf(SrsMp4MediaInformationBox* v); }; -/** - * 8.4.2 Media Header Box (mdhd) - * ISO_IEC_14496-12-base-format-2012.pdf, page 36 - * The media declaration container contains all the objects that declare information about the media data within a - * track. - */ +// 8.4.2 Media Header Box (mdhd) +// ISO_IEC_14496-12-base-format-2012.pdf, page 36 +// The media declaration container contains all the objects that declare information about the media data within a +// track. class SrsMp4MediaHeaderBox : public SrsMp4FullBox { public: - // an integer that declares the creation time of the presentation (in seconds since + // An integer that declares the creation time of the presentation (in seconds since // midnight, Jan. 1, 1904, in UTC time) uint64_t creation_time; - // an integer that declares the most recent time the presentation was modified (in + // An integer that declares the most recent time the presentation was modified (in // seconds since midnight, Jan. 1, 1904, in UTC time) uint64_t modification_time; - // an integer that specifies the time-scale for the entire presentation; this is the number of + // An integer that specifies the time-scale for the entire presentation; this is the number of // time units that pass in one second. For example, a time coordinate system that measures time in // sixtieths of a second has a time scale of 60. uint32_t timescale; - // an integer that declares length of the presentation (in the indicated timescale). This property + // An integer that declares length of the presentation (in the indicated timescale). This property // is derived from the presentation’s tracks: the value of this field corresponds to the duration of the // longest track in the presentation. If the duration cannot be determined then duration is set to all 1s. uint64_t duration; private: - // the language code for this media. See ISO 639-2/T for the set of three character + // The language code for this media. See ISO 639-2/T for the set of three character // codes. Each character is packed as the difference between its ASCII value and 0x60. Since the code // is confined to being three lower-case letters, these values are strictly positive. uint16_t language; @@ -1036,7 +966,7 @@ public: SrsMp4MediaHeaderBox(); virtual ~SrsMp4MediaHeaderBox(); public: - // the language code for this media. See ISO 639-2/T for the set of three character + // The language code for this media. See ISO 639-2/T for the set of three character // codes. Each character is packed as the difference between its ASCII value and 0x60. Since the code // is confined to being three lower-case letters, these values are strictly positive. // @param v The ASCII, for example, 'u'. @@ -1056,22 +986,20 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.4.3 Handler Reference Box (hdlr) - * ISO_IEC_14496-12-base-format-2012.pdf, page 37 - * This box within a Media Box declares the process by which the media-data in the track is presented, and thus, - * the nature of the media in a track. For example, a video track would be handled by a video handler. - */ +// 8.4.3 Handler Reference Box (hdlr) +// ISO_IEC_14496-12-base-format-2012.pdf, page 37 +// This box within a Media Box declares the process by which the media-data in the track is presented, and thus, +// The nature of the media in a track. For example, a video track would be handled by a video handler. class SrsMp4HandlerReferenceBox : public SrsMp4FullBox { public: uint32_t pre_defined; - // an integer containing one of the following values, or a value from a derived specification: + // An integer containing one of the following values, or a value from a derived specification: // ‘vide’, Video track // ‘soun’, Audio track SrsMp4HandlerType handler_type; uint32_t reserved[3]; - // a null-terminated string in UTF-8 characters which gives a human-readable name for the track + // A null-terminated string in UTF-8 characters which gives a human-readable name for the track // type (for debugging and inspection purposes). std::string name; public: @@ -1088,11 +1016,9 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.4.4 Media Information Box (minf) - * ISO_IEC_14496-12-base-format-2012.pdf, page 38 - * This box contains all the objects that declare characteristic information of the media in the track. - */ +// 8.4.4 Media Information Box (minf) +// ISO_IEC_14496-12-base-format-2012.pdf, page 38 +// This box contains all the objects that declare characteristic information of the media in the track. class SrsMp4MediaInformationBox : public SrsMp4Box { public: @@ -1113,20 +1039,18 @@ public: virtual void set_stbl(SrsMp4SampleTableBox* v); }; -/** - * 8.4.5.2 Video Media Header Box (vmhd) - * ISO_IEC_14496-12-base-format-2012.pdf, page 38 - * The video media header contains general presentation information, independent of the coding, for video - * media. Note that the flags field has the value 1. - */ +// 8.4.5.2 Video Media Header Box (vmhd) +// ISO_IEC_14496-12-base-format-2012.pdf, page 38 +// The video media header contains general presentation information, independent of the coding, for video +// media. Note that the flags field has the value 1. class SrsMp4VideoMeidaHeaderBox : public SrsMp4FullBox { public: - // a composition mode for this video track, from the following enumerated set, + // A composition mode for this video track, from the following enumerated set, // which may be extended by derived specifications: // copy = 0 copy over the existing image uint16_t graphicsmode; - // a set of 3 colour values (red, green, blue) available for use by graphics modes + // A set of 3 colour values (red, green, blue) available for use by graphics modes uint16_t opcolor[3]; public: SrsMp4VideoMeidaHeaderBox(); @@ -1137,16 +1061,14 @@ protected: virtual srs_error_t decode_header(SrsBuffer* buf); }; -/** - * 8.4.5.3 Sound Media Header Box (smhd) - * ISO_IEC_14496-12-base-format-2012.pdf, page 39 - * The sound media header contains general presentation information, independent of the coding, for audio - * media. This header is used for all tracks containing audio. - */ +// 8.4.5.3 Sound Media Header Box (smhd) +// ISO_IEC_14496-12-base-format-2012.pdf, page 39 +// The sound media header contains general presentation information, independent of the coding, for audio +// media. This header is used for all tracks containing audio. class SrsMp4SoundMeidaHeaderBox : public SrsMp4FullBox { public: - // a fixed-point 8.8 number that places mono audio tracks in a stereo space; 0 is centre (the + // A fixed-point 8.8 number that places mono audio tracks in a stereo space; 0 is centre (the // normal value); full left is -1.0 and full right is 1.0. int16_t balance; uint16_t reserved; @@ -1159,11 +1081,9 @@ protected: virtual srs_error_t decode_header(SrsBuffer* buf); }; -/** - * 8.7.1 Data Information Box (dinf) - * ISO_IEC_14496-12-base-format-2012.pdf, page 56 - * The data information box contains objects that declare the location of the media information in a track. - */ +// 8.7.1 Data Information Box (dinf) +// ISO_IEC_14496-12-base-format-2012.pdf, page 56 +// The data information box contains objects that declare the location of the media information in a track. class SrsMp4DataInformationBox : public SrsMp4Box { public: @@ -1175,12 +1095,10 @@ public: virtual void set_dref(SrsMp4DataReferenceBox* v); }; -/** - * 8.7.2 Data Reference Box - * ISO_IEC_14496-12-base-format-2012.pdf, page 56 - * a 24-bit integer with flags; one flag is defined (x000001) which means that the media - * data is in the same file as the Movie Box containing this data reference. - */ +// 8.7.2 Data Reference Box +// ISO_IEC_14496-12-base-format-2012.pdf, page 56 +// A 24-bit integer with flags; one flag is defined (x000001) which means that the media +// data is in the same file as the Movie Box containing this data reference. class SrsMp4DataEntryBox : public SrsMp4FullBox { public: @@ -1190,10 +1108,8 @@ public: virtual ~SrsMp4DataEntryBox(); }; -/** - * 8.7.2 Data Reference Box (url ) - * ISO_IEC_14496-12-base-format-2012.pdf, page 56 - */ +// 8.7.2 Data Reference Box (url ) +// ISO_IEC_14496-12-base-format-2012.pdf, page 56 class SrsMp4DataEntryUrlBox : public SrsMp4DataEntryBox { public: @@ -1207,10 +1123,8 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.7.2 Data Reference Box (urn ) - * ISO_IEC_14496-12-base-format-2012.pdf, page 56 - */ +// 8.7.2 Data Reference Box (urn ) +// ISO_IEC_14496-12-base-format-2012.pdf, page 56 class SrsMp4DataEntryUrnBox : public SrsMp4DataEntryBox { public: @@ -1226,13 +1140,11 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.7.2 Data Reference Box (dref) - * ISO_IEC_14496-12-base-format-2012.pdf, page 56 - * The data reference object contains a table of data references (normally URLs) that declare the location(s) of - * the media data used within the presentation. The data reference index in the sample description ties entries - * in this table to the samples in the track. A track may be split over several sources in this way. - */ +// 8.7.2 Data Reference Box (dref) +// ISO_IEC_14496-12-base-format-2012.pdf, page 56 +// The data reference object contains a table of data references (normally URLs) that declare the location(s) of +// The media data used within the presentation. The data reference index in the sample description ties entries +// in this table to the samples in the track. A track may be split over several sources in this way. class SrsMp4DataReferenceBox : public SrsMp4FullBox { private: @@ -1252,13 +1164,11 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.5.1 Sample Table Box (stbl) - * ISO_IEC_14496-12-base-format-2012.pdf, page 40 - * The sample table contains all the time and data indexing of the media samples in a track. Using the tables - * here, it is possible to locate samples in time, determine their type (e.g. I-frame or not), and determine their - * size, container, and offset into that container. - */ +// 8.5.1 Sample Table Box (stbl) +// ISO_IEC_14496-12-base-format-2012.pdf, page 40 +// The sample table contains all the time and data indexing of the media samples in a track. Using the tables +// here, it is possible to locate samples in time, determine their type (e.g. I-frame or not), and determine their +// size, container, and offset into that container. class SrsMp4SampleTableBox : public SrsMp4Box { public: @@ -1292,15 +1202,13 @@ protected: virtual srs_error_t decode_header(SrsBuffer* buf); }; -/** - * 8.5.2 Sample Description Box - * ISO_IEC_14496-12-base-format-2012.pdf, page 43 - */ +// 8.5.2 Sample Description Box +// ISO_IEC_14496-12-base-format-2012.pdf, page 43 class SrsMp4SampleEntry : public SrsMp4Box { public: uint8_t reserved[6]; - // an integer that contains the index of the data reference to use to retrieve + // An integer that contains the index of the data reference to use to retrieve // data associated with samples that use this sample description. Data references are stored in Data // Reference Boxes. The index ranges from 1 to the number of data references. uint16_t data_reference_index; @@ -1315,17 +1223,15 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.5.2 Sample Description Box (avc1) - * ISO_IEC_14496-12-base-format-2012.pdf, page 44 - */ +// 8.5.2 Sample Description Box (avc1) +// ISO_IEC_14496-12-base-format-2012.pdf, page 44 class SrsMp4VisualSampleEntry : public SrsMp4SampleEntry { public: uint16_t pre_defined0; uint16_t reserved0; uint32_t pre_defined1[3]; - // the maximum visual width and height of the stream described by this sample + // The maximum visual width and height of the stream described by this sample // description, in pixels uint16_t width; uint16_t height; @@ -1335,9 +1241,9 @@ public: // how many frames of compressed video are stored in each sample. The default is // 1, for one frame per sample; it may be more than 1 for multiple frames per sample uint16_t frame_count; - // a name, for informative purposes. It is formatted in a fixed 32-byte field, with the first + // A name, for informative purposes. It is formatted in a fixed 32-byte field, with the first // byte set to the number of bytes to be displayed, followed by that number of bytes of displayable data, - // and then padding to complete 32 bytes total (including the size byte). The field may be set to 0. + // And then padding to complete 32 bytes total (including the size byte). The field may be set to 0. char compressorname[32]; // one of the following values // 0x0018 – images are in colour with no alpha @@ -1358,10 +1264,8 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 5.3.4 AVC Video Stream Definition (avcC) - * ISO_IEC_14496-15-AVC-format-2012.pdf, page 19 - */ +// 5.3.4 AVC Video Stream Definition (avcC) +// ISO_IEC_14496-15-AVC-format-2012.pdf, page 19 class SrsMp4AvccBox : public SrsMp4Box { public: @@ -1377,10 +1281,8 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.5.2 Sample Description Box (mp4a) - * ISO_IEC_14496-12-base-format-2012.pdf, page 45 - */ +// 8.5.2 Sample Description Box (mp4a) +// ISO_IEC_14496-12-base-format-2012.pdf, page 45 class SrsMp4AudioSampleEntry : public SrsMp4SampleEntry { public: @@ -1420,10 +1322,8 @@ enum SrsMp4ESTagEs { SrsMp4ESTagESExtSLConfigDescrTag = 0x064, }; -/** - * 7.2.2.2 BaseDescriptor - * ISO_IEC_14496-1-System-2010.pdf, page 32 - */ +// 7.2.2.2 BaseDescriptor +// ISO_IEC_14496-1-System-2010.pdf, page 32 class SrsMp4BaseDescriptor : public ISrsCodec { public: @@ -1472,10 +1372,8 @@ enum SrsMp4StreamType SrsMp4StreamTypeAudioStream = 0x05, }; -/** - * 7.2.6.7 DecoderSpecificInfo - * ISO_IEC_14496-1-System-2010.pdf, page 51 - */ +// 7.2.6.7 DecoderSpecificInfo +// ISO_IEC_14496-1-System-2010.pdf, page 51 class SrsMp4DecoderSpecificInfo : public SrsMp4BaseDescriptor { public: @@ -1493,14 +1391,12 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 7.2.6.6 DecoderConfigDescriptor - * ISO_IEC_14496-1-System-2010.pdf, page 48 - */ +// 7.2.6.6 DecoderConfigDescriptor +// ISO_IEC_14496-1-System-2010.pdf, page 48 class SrsMp4DecoderConfigDescriptor : public SrsMp4BaseDescriptor { public: - // an indication of the object or scene description type that needs to be supported + // An indication of the object or scene description type that needs to be supported // by the decoder for this elementary stream as per Table 5. SrsMp4ObjectType objectTypeIndication; // bit(8) SrsMp4StreamType streamType; // bit(6) @@ -1521,10 +1417,8 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 7.3.2.3 SL Packet Header Configuration - * ISO_IEC_14496-1-System-2010.pdf, page 92 - */ +// 7.3.2.3 SL Packet Header Configuration +// ISO_IEC_14496-1-System-2010.pdf, page 92 class SrsMp4SLConfigDescriptor : public SrsMp4BaseDescriptor { public: @@ -1538,10 +1432,8 @@ protected: virtual srs_error_t decode_payload(SrsBuffer* buf); }; -/** - * 7.2.6.5 ES_Descriptor - * ISO_IEC_14496-1-System-2010.pdf, page 47 - */ +// 7.2.6.5 ES_Descriptor +// ISO_IEC_14496-1-System-2010.pdf, page 47 class SrsMp4ES_Descriptor : public SrsMp4BaseDescriptor { public: @@ -1569,12 +1461,10 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 5.6 Sample Description Boxes - * Elementary Stream Descriptors (esds) - * ISO_IEC_14496-14-MP4-2003.pdf, page 15 - * @see http://www.mp4ra.org/codecs.html - */ +// 5.6 Sample Description Boxes +// Elementary Stream Descriptors (esds) +// ISO_IEC_14496-14-MP4-2003.pdf, page 15 +// @see http://www.mp4ra.org/codecs.html class SrsMp4EsdsBox : public SrsMp4FullBox { public: @@ -1593,12 +1483,10 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.5.2 Sample Description Box (stsd), for Audio/Video. - * ISO_IEC_14496-12-base-format-2012.pdf, page 40 - * The sample description table gives detailed information about the coding type used, and any initialization - * information needed for that coding. - */ +// 8.5.2 Sample Description Box (stsd), for Audio/Video. +// ISO_IEC_14496-12-base-format-2012.pdf, page 40 +// The sample description table gives detailed information about the coding type used, and any initialization +// information needed for that coding. class SrsMp4SampleDescriptionBox : public SrsMp4FullBox { private: @@ -1624,16 +1512,14 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.6.1.2 Decoding Time to Sample Box (stts), for Audio/Video. - * ISO_IEC_14496-12-base-format-2012.pdf, page 48 - */ +// 8.6.1.2 Decoding Time to Sample Box (stts), for Audio/Video. +// ISO_IEC_14496-12-base-format-2012.pdf, page 48 struct SrsMp4SttsEntry { - // an integer that counts the number of consecutive samples that have the given + // An integer that counts the number of consecutive samples that have the given // duration. uint32_t sample_count; - // an integer that gives the delta of these samples in the time-scale of the media. + // An integer that gives the delta of these samples in the time-scale of the media. uint32_t sample_delta; // Constructor SrsMp4SttsEntry(); @@ -1642,18 +1528,16 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.6.1.2 Decoding Time to Sample Box (stts), for Audio/Video. - * ISO_IEC_14496-12-base-format-2012.pdf, page 48 - * This box contains a compact version of a table that allows indexing from decoding time to sample number. - * Other tables give sample sizes and pointers, from the sample number. Each entry in the table gives the - * number of consecutive samples with the same time delta, and the delta of those samples. By adding the - * deltas a complete time-to-sample map may be built. - */ +// 8.6.1.2 Decoding Time to Sample Box (stts), for Audio/Video. +// ISO_IEC_14496-12-base-format-2012.pdf, page 48 +// This box contains a compact version of a table that allows indexing from decoding time to sample number. +// Other tables give sample sizes and pointers, from the sample number. Each entry in the table gives the +// number of consecutive samples with the same time delta, and the delta of those samples. By adding the +// deltas a complete time-to-sample map may be built. class SrsMp4DecodingTime2SampleBox : public SrsMp4FullBox { public: - // an integer that gives the number of entries in the following table. + // An integer that gives the number of entries in the following table. std::vector entries; private: // The index for counter to calc the dts for samples. @@ -1675,17 +1559,15 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.6.1.3 Composition Time to Sample Box (ctts), for Video. - * ISO_IEC_14496-12-base-format-2012.pdf, page 49 - */ +// 8.6.1.3 Composition Time to Sample Box (ctts), for Video. +// ISO_IEC_14496-12-base-format-2012.pdf, page 49 struct SrsMp4CttsEntry { - // an integer that counts the number of consecutive samples that have the given offset. + // An integer that counts the number of consecutive samples that have the given offset. uint32_t sample_count; // uint32_t for version=0 // int32_t for version=1 - // an integer that gives the offset between CT and DT, such that CT(n) = DT(n) + + // An integer that gives the offset between CT and DT, such that CT(n) = DT(n) + // CTTS(n). int64_t sample_offset; // Constructor @@ -1695,20 +1577,18 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.6.1.3 Composition Time to Sample Box (ctts), for Video. - * ISO_IEC_14496-12-base-format-2012.pdf, page 49 - * This box provides the offset between decoding time and composition time. In version 0 of this box the - * decoding time must be less than the composition time, and the offsets are expressed as unsigned numbers - * such that CT(n) = DT(n) + CTTS(n) where CTTS(n) is the (uncompressed) table entry for sample n. In version - * 1 of this box, the composition timeline and the decoding timeline are still derived from each other, but the - * offsets are signed. It is recommended that for the computed composition timestamps, there is exactly one with - * the value 0 (zero). - */ +// 8.6.1.3 Composition Time to Sample Box (ctts), for Video. +// ISO_IEC_14496-12-base-format-2012.pdf, page 49 +// This box provides the offset between decoding time and composition time. In version 0 of this box the +// decoding time must be less than the composition time, and the offsets are expressed as unsigned numbers +// such that CT(n) = DT(n) + CTTS(n) where CTTS(n) is the (uncompressed) table entry for sample n. In version +// 1 of this box, the composition timeline and the decoding timeline are still derived from each other, but the +// offsets are signed. It is recommended that for the computed composition timestamps, there is exactly one with +// The value 0 (zero). class SrsMp4CompositionTime2SampleBox : public SrsMp4FullBox { public: - // an integer that gives the number of entries in the following table. + // An integer that gives the number of entries in the following table. std::vector entries; private: // The index for counter to calc the dts for samples. @@ -1730,19 +1610,17 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.6.2 Sync Sample Box (stss), for Video. - * ISO_IEC_14496-12-base-format-2012.pdf, page 51 - * This box provides a compact marking of the sync samples within the stream. The table is arranged in strictly - * increasing order of sample number. - */ +// 8.6.2 Sync Sample Box (stss), for Video. +// ISO_IEC_14496-12-base-format-2012.pdf, page 51 +// This box provides a compact marking of the sync samples within the stream. The table is arranged in strictly +// increasing order of sample number. class SrsMp4SyncSampleBox : public SrsMp4FullBox { public: - // an integer that gives the number of entries in the following table. If entry_count is zero, - // there are no sync samples within the stream and the following table is empty. + // An integer that gives the number of entries in the following table. If entry_count is zero, + // There are no sync samples within the stream and the following table is empty. uint32_t entry_count; - // the numbers of the samples that are sync samples in the stream. + // The numbers of the samples that are sync samples in the stream. uint32_t* sample_numbers; public: SrsMp4SyncSampleBox(); @@ -1758,20 +1636,18 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.7.4 Sample To Chunk Box (stsc), for Audio/Video. - * ISO_IEC_14496-12-base-format-2012.pdf, page 58 - */ +// 8.7.4 Sample To Chunk Box (stsc), for Audio/Video. +// ISO_IEC_14496-12-base-format-2012.pdf, page 58 struct SrsMp4StscEntry { - // an integer that gives the index of the first chunk in this run of chunks that share the + // An integer that gives the index of the first chunk in this run of chunks that share the // same samples-per-chunk and sample-description-index; the index of the first chunk in a track has the // value 1 (the first_chunk field in the first record of this box has the value 1, identifying that the first // sample maps to the first chunk). uint32_t first_chunk; - // an integer that gives the number of samples in each of these chunks + // An integer that gives the number of samples in each of these chunks uint32_t samples_per_chunk; - // an integer that gives the index of the sample entry that describes the + // An integer that gives the index of the sample entry that describes the // samples in this chunk. The index ranges from 1 to the number of sample entries in the Sample // Description Box uint32_t sample_description_index; @@ -1781,19 +1657,17 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.7.4 Sample To Chunk Box (stsc), for Audio/Video. - * ISO_IEC_14496-12-base-format-2012.pdf, page 58 - * Samples within the media data are grouped into chunks. Chunks can be of different sizes, and the samples - * within a chunk can have different sizes. This table can be used to find the chunk that contains a sample, - * its position, and the associated sample description. - */ +// 8.7.4 Sample To Chunk Box (stsc), for Audio/Video. +// ISO_IEC_14496-12-base-format-2012.pdf, page 58 +// Samples within the media data are grouped into chunks. Chunks can be of different sizes, and the samples +// within a chunk can have different sizes. This table can be used to find the chunk that contains a sample, +// its position, and the associated sample description. class SrsMp4Sample2ChunkBox : public SrsMp4FullBox { public: - // an integer that gives the number of entries in the following table + // An integer that gives the number of entries in the following table uint32_t entry_count; - // the numbers of the samples that are sync samples in the stream. + // The numbers of the samples that are sync samples in the stream. SrsMp4StscEntry* entries; private: // The index for counter to calc the dts for samples. @@ -1814,19 +1688,17 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.7.5 Chunk Offset Box (stco), for Audio/Video. - * ISO_IEC_14496-12-base-format-2012.pdf, page 59 - * The chunk offset table gives the index of each chunk into the containing file. There are two variants, permitting - * the use of 32-bit or 64-bit offsets. The latter is useful when managing very large presentations. At most one of - * these variants will occur in any single instance of a sample table. - */ +// 8.7.5 Chunk Offset Box (stco), for Audio/Video. +// ISO_IEC_14496-12-base-format-2012.pdf, page 59 +// The chunk offset table gives the index of each chunk into the containing file. There are two variants, permitting +// The use of 32-bit or 64-bit offsets. The latter is useful when managing very large presentations. At most one of +// These variants will occur in any single instance of a sample table. class SrsMp4ChunkOffsetBox : public SrsMp4FullBox { public: - // an integer that gives the number of entries in the following table + // An integer that gives the number of entries in the following table uint32_t entry_count; - // a 32 bit integer that gives the offset of the start of a chunk into its containing + // A 32 bit integer that gives the offset of the start of a chunk into its containing // media file. uint32_t* entries; public: @@ -1840,19 +1712,17 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.7.5 Chunk Large Offset Box (co64), for Audio/Video. - * ISO_IEC_14496-12-base-format-2012.pdf, page 59 - * The chunk offset table gives the index of each chunk into the containing file. There are two variants, permitting - * the use of 32-bit or 64-bit offsets. The latter is useful when managing very large presentations. At most one of - * these variants will occur in any single instance of a sample table. - */ +// 8.7.5 Chunk Large Offset Box (co64), for Audio/Video. +// ISO_IEC_14496-12-base-format-2012.pdf, page 59 +// The chunk offset table gives the index of each chunk into the containing file. There are two variants, permitting +// The use of 32-bit or 64-bit offsets. The latter is useful when managing very large presentations. At most one of +// These variants will occur in any single instance of a sample table. class SrsMp4ChunkLargeOffsetBox : public SrsMp4FullBox { public: - // an integer that gives the number of entries in the following table + // An integer that gives the number of entries in the following table uint32_t entry_count; - // a 64 bit integer that gives the offset of the start of a chunk into its containing + // A 64 bit integer that gives the offset of the start of a chunk into its containing // media file. uint64_t* entries; public: @@ -1866,24 +1736,22 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.7.3.2 Sample Size Box (stsz), for Audio/Video. - * ISO_IEC_14496-12-base-format-2012.pdf, page 58 - * This box contains the sample count and a table giving the size in bytes of each sample. This allows the media data - * itself to be unframed. The total number of samples in the media is always indicated in the sample count. - */ +// 8.7.3.2 Sample Size Box (stsz), for Audio/Video. +// ISO_IEC_14496-12-base-format-2012.pdf, page 58 +// This box contains the sample count and a table giving the size in bytes of each sample. This allows the media data +// itself to be unframed. The total number of samples in the media is always indicated in the sample count. class SrsMp4SampleSizeBox : public SrsMp4FullBox { public: - // the default sample size. If all the samples are the same size, this field + // The default sample size. If all the samples are the same size, this field // contains that size value. If this field is set to 0, then the samples have different sizes, and those sizes // are stored in the sample size table. If this field is not 0, it specifies the constant sample size, and no // array follows. uint32_t sample_size; - // an integer that gives the number of samples in the track; if sample-size is 0, then it is + // An integer that gives the number of samples in the track; if sample-size is 0, then it is // also the number of entries in the following table. uint32_t sample_count; - // each entry_size is an integer specifying the size of a sample, indexed by its number. + // Each entry_size is an integer specifying the size of a sample, indexed by its number. uint32_t* entry_sizes; public: SrsMp4SampleSizeBox(); @@ -1899,12 +1767,10 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * 8.10.1 User Data Box (udta) - * ISO_IEC_14496-12-base-format-2012.pdf, page 78 - * This box contains objects that declare user information about the containing box and its data (presentation or - * track). - */ +// 8.10.1 User Data Box (udta) +// ISO_IEC_14496-12-base-format-2012.pdf, page 78 +// This box contains objects that declare user information about the containing box and its data (presentation or +// track). class SrsMp4UserDataBox : public SrsMp4Box { public: @@ -1920,9 +1786,7 @@ public: virtual std::stringstream& dumps_detail(std::stringstream& ss, SrsMp4DumpContext dc); }; -/** - * Generally, a MP4 sample contains a frame, for example, a video frame or audio frame. - */ +// Generally, a MP4 sample contains a frame, for example, a video frame or audio frame. class SrsMp4Sample { public: @@ -1956,17 +1820,15 @@ public: virtual uint32_t pts_ms(); }; -/** - * Build samples from moov, or write samples to moov. - * One or more sample are grouped to a chunk, each track contains one or more chunks. - * The offset of chunk is specified by stco. - * The chunk-sample series is speicified by stsc. - * The sample size is specified by stsz. - * The dts is specified by stts. - * For video: - * The cts/pts is specified by ctts. - * The keyframe is specified by stss. - */ +// Build samples from moov, or write samples to moov. +// One or more sample are grouped to a chunk, each track contains one or more chunks. +// The offset of chunk is specified by stco. +// The chunk-sample series is speicified by stsc. +// The sample size is specified by stsz. +// The dts is specified by stts. +// For video: +// The cts/pts is specified by ctts. +// The keyframe is specified by stss. class SrsMp4SampleManager { public: @@ -2002,10 +1864,8 @@ private: SrsMp4DecodingTime2SampleBox* stts, SrsMp4CompositionTime2SampleBox* ctts, SrsMp4SyncSampleBox* stss); }; -/** - * The MP4 box reader, to get the RAW boxes without decode. - * @remark For mdat box, we only decode the header, then skip the data. - */ +// The MP4 box reader, to get the RAW boxes without decode. +// @remark For mdat box, we only decode the header, then skip the data. class SrsMp4BoxReader { private: @@ -2024,9 +1884,7 @@ public: virtual srs_error_t skip(SrsMp4Box* box, SrsSimpleStream* stream); }; -/** - * The MP4 demuxer. - */ +// The MP4 demuxer. class SrsMp4Decoder { private: @@ -2075,24 +1933,20 @@ public: SrsMp4Decoder(); virtual ~SrsMp4Decoder(); public: - /** - * Initialize the decoder with a reader r. - * @param r The underlayer io reader, user must manage it. - */ + // Initialize the decoder with a reader r. + // @param r The underlayer io reader, user must manage it. virtual srs_error_t initialize(ISrsReadSeeker* rs); - /** - * Read a sample from mp4. - * @param pht The sample hanler type, audio/soun or video/vide. - * @param pft, The frame type. For video, it's SrsVideoAvcFrameType. For audio, ignored. - * @param pct, The codec type. For video, it's SrsVideoAvcFrameTrait. For audio, it's SrsAudioAacFrameTrait. - * @param pdts The output dts in milliseconds. - * @param ppts The output pts in milliseconds. - * @param pnb_sample The output size of payload. - * @param psample The output payload, user must free it. - * @remark The decoder will generate the first two audio/video sequence header. - */ + // Read a sample from mp4. + // @param pht The sample hanler type, audio/soun or video/vide. + // @param pft, The frame type. For video, it's SrsVideoAvcFrameType. For audio, ignored. + // @param pct, The codec type. For video, it's SrsVideoAvcFrameTrait. For audio, it's SrsAudioAacFrameTrait. + // @param pdts The output dts in milliseconds. + // @param ppts The output pts in milliseconds. + // @param pnb_sample The output size of payload. + // @param psample The output payload, user must free it. + // @remark The decoder will generate the first two audio/video sequence header. virtual srs_error_t read_sample(SrsMp4HandlerType* pht, uint16_t* pft, uint16_t* pct, - uint32_t* pdts, uint32_t* ppts, uint8_t** psample, uint32_t* pnb_sample); + uint32_t* pdts, uint32_t* ppts, uint8_t** psample, uint32_t* pnb_sample); private: virtual srs_error_t parse_ftyp(SrsMp4FileTypeBox* ftyp); virtual srs_error_t parse_moov(SrsMp4MovieBox* moov); @@ -2104,9 +1958,7 @@ private: virtual srs_error_t do_load_next_box(SrsMp4Box** ppbox, uint32_t required_box_type); }; -/** - * The MP4 muxer. - */ +// The MP4 muxer. class SrsMp4Encoder { private: @@ -2172,9 +2024,7 @@ private: virtual srs_error_t do_write_sample(SrsMp4Sample* ps, uint8_t* sample, uint32_t nb_sample); }; -/** - * A fMP4 encoder, to write the init.mp4 with sequence header. - */ +// A fMP4 encoder, to write the init.mp4 with sequence header. class SrsMp4M2tsInitEncoder { private: @@ -2189,10 +2039,8 @@ public: virtual srs_error_t write(SrsFormat* format, bool video, int tid); }; -/** - * A fMP4 encoder, to cache segments then flush to disk, because the fMP4 should write - * trun box before mdat. - */ +// A fMP4 encoder, to cache segments then flush to disk, because the fMP4 should write +// trun box before mdat. class SrsMp4M2tsSegmentEncoder { private: diff --git a/trunk/src/kernel/srs_kernel_ts.hpp b/trunk/src/kernel/srs_kernel_ts.hpp index c31dd4eb2..d076bfbe7 100644 --- a/trunk/src/kernel/srs_kernel_ts.hpp +++ b/trunk/src/kernel/srs_kernel_ts.hpp @@ -5,15 +5,15 @@ * * 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 + * 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, + * 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 + * 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 @@ -51,14 +51,12 @@ class SrsTsContext; // Transport Stream packets are 188 bytes in length. #define SRS_TS_PACKET_SIZE 188 -// the aggregate pure audio for hls, in ts tbn(ms * 90). +// The aggregate pure audio for hls, in ts tbn(ms * 90). #define SRS_CONSTS_HLS_PURE_AUDIO_AGGREGATE 720 * 90 -/** - * the pid of ts packet, - * Table 2-3 - PID table, hls-mpeg-ts-iso13818-1.pdf, page 37 - * NOTE - The transport packets with PID values 0x0000, 0x0001, and 0x0010-0x1FFE are allowed to carry a PCR. - */ +// The pid of ts packet, +// Table 2-3 - PID table, hls-mpeg-ts-iso13818-1.pdf, page 37 +// NOTE - The transport packets with PID values 0x0000, 0x0001, and 0x0010-0x1FFE are allowed to carry a PCR. enum SrsTsPid { // Program Association Table(see Table 2-25). @@ -73,14 +71,12 @@ enum SrsTsPid // May be assigned as network_PID, Program_map_PID, elementary_PID, or for other purposes SrsTsPidAppStart = 0x10, SrsTsPidAppEnd = 0x1ffe, - // null packets (see Table 2-3) + // For null packets (see Table 2-3) SrsTsPidNULL = 0x01FFF, }; -/** - * the transport_scrambling_control of ts packet, - * Table 2-4 - Scrambling control values, hls-mpeg-ts-iso13818-1.pdf, page 38 - */ +// The transport_scrambling_control of ts packet, +// Table 2-4 - Scrambling control values, hls-mpeg-ts-iso13818-1.pdf, page 38 enum SrsTsScrambled { // Not scrambled @@ -93,10 +89,8 @@ enum SrsTsScrambled SrsTsScrambledUserDefined3 = 0x03, }; -/** - * the adaption_field_control of ts packet, - * Table 2-5 - Adaptation field control values, hls-mpeg-ts-iso13818-1.pdf, page 38 - */ +// the adaption_field_control of ts packet, +// Table 2-5 - Adaptation field control values, hls-mpeg-ts-iso13818-1.pdf, page 38 enum SrsTsAdaptationFieldType { // Reserved for future use by ISO/IEC @@ -109,10 +103,8 @@ enum SrsTsAdaptationFieldType SrsTsAdaptationFieldTypeBoth = 0x03, }; -/** - * the actually parsed ts pid, - * @see SrsTsPid, some pid, for example, PMT/Video/Audio is specified by PAT or other tables. - */ +// the actually parsed ts pid, +// @see SrsTsPid, some pid, for example, PMT/Video/Audio is specified by PAT or other tables. enum SrsTsPidApply { SrsTsPidApplyReserved = 0, // TSPidTypeReserved, nothing parsed, used reserved. @@ -124,9 +116,7 @@ enum SrsTsPidApply SrsTsPidApplyAudio, // vor audio }; -/** - * Table 2-29 - Stream type assignments - */ +// Table 2-29 - Stream type assignments enum SrsTsStream { // ITU-T | ISO/IEC Reserved @@ -166,9 +156,7 @@ enum SrsTsStream }; std::string srs_ts_stream2string(SrsTsStream stream); -/** - * the ts channel. - */ +// The ts channel. struct SrsTsChannel { int pid; @@ -183,10 +171,8 @@ struct SrsTsChannel virtual ~SrsTsChannel(); }; -/** - * the stream_id of PES payload of ts packet. - * Table 2-18 - Stream_id assignments, hls-mpeg-ts-iso13818-1.pdf, page 52. - */ +// The stream_id of PES payload of ts packet. +// Table 2-18 - Stream_id assignments, hls-mpeg-ts-iso13818-1.pdf, page 52. enum SrsTsPESStreamId { // program_stream_map @@ -244,104 +230,82 @@ enum SrsTsPESStreamId SrsTsPESStreamIdProgramStreamDirectory = 0xff, // 0b11111111 }; -/** - * the media audio/video message parsed from PES packet. - */ +// The media audio/video message parsed from PES packet. class SrsTsMessage { public: - // decoder only, + // For decoder only, // the ts messgae does not use them, // for user to get the channel and packet. SrsTsChannel* channel; SrsTsPacket* packet; public: - // the audio cache buffer start pts, to flush audio if full. + // The audio cache buffer start pts, to flush audio if full. // @remark the pts is not the adjust one, it's the orignal pts. int64_t start_pts; - // whether this message with pcr info, + // Whether this message with pcr info, // generally, the video IDR(I frame, the keyframe of h.264) carray the pcr info. bool write_pcr; - // whether got discontinuity ts, for example, sequence header changed. + // Whether got discontinuity ts, for example, sequence header changed. bool is_discontinuity; public: - // the timestamp in 90khz + // The timestamp in 90khz int64_t dts; int64_t pts; - // the id of pes stream to indicates the payload codec. + // The id of pes stream to indicates the payload codec. // @remark use is_audio() and is_video() to check it, and stream_number() to finger it out. SrsTsPESStreamId sid; - // the size of payload, 0 indicates the length() of payload. + // The size of payload, 0 indicates the length() of payload. uint16_t PES_packet_length; - // the chunk id. + // The chunk id. uint8_t continuity_counter; - // the payload bytes. + // The payload bytes. SrsSimpleStream* payload; public: SrsTsMessage(SrsTsChannel* c = NULL, SrsTsPacket* p = NULL); virtual ~SrsTsMessage(); - // decoder +// For decoder public: - /** - * dumps all bytes in stream to ts message. - */ - virtual srs_error_t dump(SrsBuffer* stream, int* pnb_bytes); - /** - * whether ts message is completed to reap. - * @param payload_unit_start_indicator whether new ts message start. - * PES_packet_length is 0, the payload_unit_start_indicator=1 to reap ts message. - * PES_packet_length > 0, the payload.length() == PES_packet_length to reap ts message. - * @remark when PES_packet_length>0, the payload_unit_start_indicator should never be 1 when not completed. - * @remark when fresh, the payload_unit_start_indicator should be 1. - */ + // To dumps all bytes in stream to ts message. + virtual srs_error_t dump(SrsBuffer* stream, int* pnb_bytes); + // Whether ts message is completed to reap. + // @param payload_unit_start_indicator whether new ts message start. + // PES_packet_length is 0, the payload_unit_start_indicator=1 to reap ts message. + // PES_packet_length > 0, the payload.length() == PES_packet_length to reap ts message. + // @remark when PES_packet_length>0, the payload_unit_start_indicator should never be 1 when not completed. + // @remark when fresh, the payload_unit_start_indicator should be 1. virtual bool completed(int8_t payload_unit_start_indicator); - /** - * whether the message is fresh. - */ + // Whether the message is fresh. virtual bool fresh(); public: - /** - * whether the sid indicates the elementary stream audio. - */ + // Whether the sid indicates the elementary stream audio. virtual bool is_audio(); - /** - * whether the sid indicates the elementary stream video. - */ + // Whether the sid indicates the elementary stream video. virtual bool is_video(); - /** - * when audio or video, get the stream number which specifies the format of stream. - * @return the stream number for audio/video; otherwise, -1. - */ + // When audio or video, get the stream number which specifies the format of stream. + // @return the stream number for audio/video; otherwise, -1. virtual int stream_number(); public: - /** - * detach the ts message, - * for user maybe need to parse the message by queue. - * @remark we always use the payload of original message. - */ + // Detach the ts message, + // for user maybe need to parse the message by queue. + // @remark we always use the payload of original message. virtual SrsTsMessage* detach(); }; -/** - * the ts message handler. - */ +// The ts message handler. class ISrsTsHandler { public: ISrsTsHandler(); virtual ~ISrsTsHandler(); public: - /** - * when ts context got message, use handler to process it. - * @param msg the ts msg, user should never free it. - * @return an int error code. - */ + // When ts context got message, use handler to process it. + // @param msg the ts msg, user should never free it. + // @return an int error code. virtual srs_error_t on_ts_message(SrsTsMessage* msg) = 0; }; -/** - * the context of ts, to decode the ts stream. - */ +// The context of ts, to decode the ts stream. class SrsTsContext { private: @@ -363,151 +327,117 @@ public: SrsTsContext(); virtual ~SrsTsContext(); public: - /** - * whether the hls stream is pure audio stream. - */ - // TODO: FIXME: merge with muxer codec detect. + // Whether the hls stream is pure audio stream. + // TODO: FIXME: merge with muxer codec detect. virtual bool is_pure_audio(); - /** - * when PMT table parsed, we know some info about stream. - */ + // When PMT table parsed, we know some info about stream. virtual void on_pmt_parsed(); - /** - * reset the context for a new ts segment start. - */ + // Reset the context for a new ts segment start. virtual void reset(); // codec public: - /** - * get the pid apply, the parsed pid. - * @return the apply channel; NULL for invalid. - */ + // Get the pid apply, the parsed pid. + // @return the apply channel; NULL for invalid. virtual SrsTsChannel* get(int pid); - /** - * set the pid apply, the parsed pid. - */ + // Set the pid apply, the parsed pid. virtual void set(int pid, SrsTsPidApply apply_pid, SrsTsStream stream = SrsTsStreamReserved); // decode methods public: - /** - * the stream contains only one ts packet. - * @param handler the ts message handler to process the msg. - * @remark we will consume all bytes in stream. - */ + // The stream contains only one ts packet. + // @param handler the ts message handler to process the msg. + // @remark we will consume all bytes in stream. virtual srs_error_t decode(SrsBuffer* stream, ISrsTsHandler* handler); // encode methods public: - /** - * write the PES packet, the video/audio stream. - * @param msg the video/audio msg to write to ts. - * @param vc the video codec, write the PAT/PMT table when changed. - * @param ac the audio codec, write the PAT/PMT table when changed. - */ + // Write the PES packet, the video/audio stream. + // @param msg the video/audio msg to write to ts. + // @param vc the video codec, write the PAT/PMT table when changed. + // @param ac the audio codec, write the PAT/PMT table when changed. virtual srs_error_t encode(ISrsStreamWriter* writer, SrsTsMessage* msg, SrsVideoCodecId vc, SrsAudioCodecId ac); // drm methods public: - /** - * set sync byte of ts segment. - * replace the standard ts sync byte to bravo sync byte. - */ + // Set sync byte of ts segment. + // replace the standard ts sync byte to bravo sync byte. virtual void set_sync_byte(int8_t sb); private: virtual srs_error_t encode_pat_pmt(ISrsStreamWriter* writer, int16_t vpid, SrsTsStream vs, int16_t apid, SrsTsStream as); virtual srs_error_t encode_pes(ISrsStreamWriter* writer, SrsTsMessage* msg, int16_t pid, SrsTsStream sid, bool pure_audio); }; -/** - * the packet in ts stream, - * 2.4.3.2 Transport Stream packet layer, hls-mpeg-ts-iso13818-1.pdf, page 36 - * Transport Stream packets shall be 188 bytes long. - */ +// The packet in ts stream, +// 2.4.3.2 Transport Stream packet layer, hls-mpeg-ts-iso13818-1.pdf, page 36 +// Transport Stream packets shall be 188 bytes long. class SrsTsPacket { public: // 1B - /** - * The sync_byte is a fixed 8-bit field whose value is '0100 0111' (0x47). Sync_byte emulation in the choice of - * values for other regularly occurring fields, such as PID, should be avoided. - */ + // The sync_byte is a fixed 8-bit field whose value is '0100 0111' (0x47). Sync_byte emulation in the choice of + // values for other regularly occurring fields, such as PID, should be avoided. int8_t sync_byte; //8bits // 2B - /** - * The transport_error_indicator is a 1-bit flag. When set to '1' it indicates that at least - * 1 uncorrectable bit error exists in the associated Transport Stream packet. This bit may be set to '1' by entities external to - * the transport layer. When set to '1' this bit shall not be reset to '0' unless the bit value(s) in error have been corrected. - */ + // The transport_error_indicator is a 1-bit flag. When set to '1' it indicates that at least + // 1 uncorrectable bit error exists in the associated Transport Stream packet. This bit may be set to '1' by entities external to + // the transport layer. When set to '1' this bit shall not be reset to '0' unless the bit value(s) in error have been corrected. int8_t transport_error_indicator; //1bit - /** - * The payload_unit_start_indicator is a 1-bit flag which has normative meaning for - * Transport Stream packets that carry PES packets (refer to 2.4.3.6) or PSI data (refer to 2.4.4). - * - * When the payload of the Transport Stream packet contains PES packet data, the payload_unit_start_indicator has the - * following significance: a '1' indicates that the payload of this Transport Stream packet will commence(start) with the first byte - * of a PES packet and a '0' indicates no PES packet shall start in this Transport Stream packet. If the - * payload_unit_start_indicator is set to '1', then one and only one PES packet starts in this Transport Stream packet. This - * also applies to private streams of stream_type 6 (refer to Table 2-29). - * - * When the payload of the Transport Stream packet contains PSI data, the payload_unit_start_indicator has the following - * significance: if the Transport Stream packet carries the first byte of a PSI section, the payload_unit_start_indicator value - * shall be '1', indicating that the first byte of the payload of this Transport Stream packet carries the pointer_field. If the - * Transport Stream packet does not carry the first byte of a PSI section, the payload_unit_start_indicator value shall be '0', - * indicating that there is no pointer_field in the payload. Refer to 2.4.4.1 and 2.4.4.2. This also applies to private streams of - * stream_type 5 (refer to Table 2-29). - * - * For null packets the payload_unit_start_indicator shall be set to '0'. - * - * The meaning of this bit for Transport Stream packets carrying only private data is not defined in this Specification. - */ + // The payload_unit_start_indicator is a 1-bit flag which has normative meaning for + // Transport Stream packets that carry PES packets (refer to 2.4.3.6) or PSI data (refer to 2.4.4). + // + // When the payload of the Transport Stream packet contains PES packet data, the payload_unit_start_indicator has the + // following significance: a '1' indicates that the payload of this Transport Stream packet will commence(start) with the first byte + // of a PES packet and a '0' indicates no PES packet shall start in this Transport Stream packet. If the + // payload_unit_start_indicator is set to '1', then one and only one PES packet starts in this Transport Stream packet. This + // also applies to private streams of stream_type 6 (refer to Table 2-29). + // + // When the payload of the Transport Stream packet contains PSI data, the payload_unit_start_indicator has the following + // significance: if the Transport Stream packet carries the first byte of a PSI section, the payload_unit_start_indicator value + // shall be '1', indicating that the first byte of the payload of this Transport Stream packet carries the pointer_field. If the + // Transport Stream packet does not carry the first byte of a PSI section, the payload_unit_start_indicator value shall be '0', + // indicating that there is no pointer_field in the payload. Refer to 2.4.4.1 and 2.4.4.2. This also applies to private streams of + // stream_type 5 (refer to Table 2-29). + // + // For null packets the payload_unit_start_indicator shall be set to '0'. + // + // The meaning of this bit for Transport Stream packets carrying only private data is not defined in this Specification. int8_t payload_unit_start_indicator; //1bit - /** - * The transport_priority is a 1-bit indicator. When set to '1' it indicates that the associated packet is - * of greater priority than other packets having the same PID which do not have the bit set to '1'. The transport mechanism - * can use this to prioritize its data within an elementary stream. Depending on the application the transport_priority field - * may be coded regardless of the PID or within one PID only. This field may be changed by channel specific encoders or - * decoders. - */ + // The transport_priority is a 1-bit indicator. When set to '1' it indicates that the associated packet is + // of greater priority than other packets having the same PID which do not have the bit set to '1'. The transport mechanism + // can use this to prioritize its data within an elementary stream. Depending on the application the transport_priority field + // may be coded regardless of the PID or within one PID only. This field may be changed by channel specific encoders or + // decoders. int8_t transport_priority; //1bit - /** - * The PID is a 13-bit field, indicating the type of the data stored in the packet payload. PID value 0x0000 is - * reserved for the Program Association Table (see Table 2-25). PID value 0x0001 is reserved for the Conditional Access - * Table (see Table 2-27). PID values 0x0002 - 0x000F are reserved. PID value 0x1FFF is reserved for null packets (see - * Table 2-3). - */ + // The PID is a 13-bit field, indicating the type of the data stored in the packet payload. PID value 0x0000 is + // reserved for the Program Association Table (see Table 2-25). PID value 0x0001 is reserved for the Conditional Access + // Table (see Table 2-27). PID values 0x0002 - 0x000F are reserved. PID value 0x1FFF is reserved for null packets (see + // Table 2-3). SrsTsPid pid; //13bits // 1B - /** - * This 2-bit field indicates the scrambling mode of the Transport Stream packet payload. - * The Transport Stream packet header, and the adaptation field when present, shall not be scrambled. In the case of a null - * packet the value of the transport_scrambling_control field shall be set to '00' (see Table 2-4). - */ + // This 2-bit field indicates the scrambling mode of the Transport Stream packet payload. + // The Transport Stream packet header, and the adaptation field when present, shall not be scrambled. In the case of a null + // packet the value of the transport_scrambling_control field shall be set to '00' (see Table 2-4). SrsTsScrambled transport_scrambling_control; //2bits - /** - * This 2-bit field indicates whether this Transport Stream packet header is followed by an - * adaptation field and/or payload (see Table 2-5). - * - * ITU-T Rec. H.222.0 | ISO/IEC 13818-1 decoders shall discard Transport Stream packets with the - * adaptation_field_control field set to a value of '00'. In the case of a null packet the value of the adaptation_field_control - * shall be set to '01'. - */ + // This 2-bit field indicates whether this Transport Stream packet header is followed by an + // adaptation field and/or payload (see Table 2-5). + // + // ITU-T Rec. H.222.0 | ISO/IEC 13818-1 decoders shall discard Transport Stream packets with the + // adaptation_field_control field set to a value of '00'. In the case of a null packet the value of the adaptation_field_control + // shall be set to '01'. SrsTsAdaptationFieldType adaption_field_control; //2bits - /** - * The continuity_counter is a 4-bit field incrementing with each Transport Stream packet with the - * same PID. The continuity_counter wraps around to 0 after its maximum value. The continuity_counter shall not be - * incremented when the adaptation_field_control of the packet equals '00'(reseverd) or '10'(adaptation field only). - * - * In Transport Streams, duplicate packets may be sent as two, and only two, consecutive Transport Stream packets of the - * same PID. The duplicate packets shall have the same continuity_counter value as the original packet and the - * adaptation_field_control field shall be equal to '01'(payload only) or '11'(both). In duplicate packets each byte of the original packet shall be - * duplicated, with the exception that in the program clock reference fields, if present, a valid value shall be encoded. - * - * The continuity_counter in a particular Transport Stream packet is continuous when it differs by a positive value of one - * from the continuity_counter value in the previous Transport Stream packet of the same PID, or when either of the nonincrementing - * conditions (adaptation_field_control set to '00' or '10', or duplicate packets as described above) are met. - * The continuity counter may be discontinuous when the discontinuity_indicator is set to '1' (refer to 2.4.3.4). In the case of - * a null packet the value of the continuity_counter is undefined. - */ + // The continuity_counter is a 4-bit field incrementing with each Transport Stream packet with the + // same PID. The continuity_counter wraps around to 0 after its maximum value. The continuity_counter shall not be + // incremented when the adaptation_field_control of the packet equals '00'(reseverd) or '10'(adaptation field only). + // + // In Transport Streams, duplicate packets may be sent as two, and only two, consecutive Transport Stream packets of the + // same PID. The duplicate packets shall have the same continuity_counter value as the original packet and the + // adaptation_field_control field shall be equal to '01'(payload only) or '11'(both). In duplicate packets each byte of the original packet shall be + // duplicated, with the exception that in the program clock reference fields, if present, a valid value shall be encoded. + // + // The continuity_counter in a particular Transport Stream packet is continuous when it differs by a positive value of one + // from the continuity_counter value in the previous Transport Stream packet of the same PID, or when either of the nonincrementing + // conditions (adaptation_field_control set to '00' or '10', or duplicate packets as described above) are met. + // The continuity counter may be discontinuous when the discontinuity_indicator is set to '1' (refer to 2.4.3.4). In the case of + // a null packet the value of the continuity_counter is undefined. uint8_t continuity_counter; //4bits private: SrsTsAdaptationField* adaptation_field; @@ -526,289 +456,239 @@ public: public: static SrsTsPacket* create_pat(SrsTsContext* context, int16_t pmt_number, int16_t pmt_pid); static SrsTsPacket* create_pmt(SrsTsContext* context, int16_t pmt_number, int16_t pmt_pid, - int16_t vpid, SrsTsStream vs, int16_t apid, SrsTsStream as); + int16_t vpid, SrsTsStream vs, int16_t apid, SrsTsStream as); static SrsTsPacket* create_pes_first(SrsTsContext* context, int16_t pid, SrsTsPESStreamId sid, - uint8_t continuity_counter, bool discontinuity, int64_t pcr, int64_t dts, int64_t pts, int size); + uint8_t continuity_counter, bool discontinuity, int64_t pcr, int64_t dts, int64_t pts, int size); static SrsTsPacket* create_pes_continue(SrsTsContext* context, - int16_t pid, SrsTsPESStreamId sid, uint8_t continuity_counter); + int16_t pid, SrsTsPESStreamId sid, uint8_t continuity_counter); }; -/** - * the adaption field of ts packet. - * 2.4.3.5 Semantic definition of fields in adaptation field, hls-mpeg-ts-iso13818-1.pdf, page 39 - * Table 2-6 - Transport Stream adaptation field, hls-mpeg-ts-iso13818-1.pdf, page 40 - */ +// The adaption field of ts packet. +// 2.4.3.5 Semantic definition of fields in adaptation field, hls-mpeg-ts-iso13818-1.pdf, page 39 +// Table 2-6 - Transport Stream adaptation field, hls-mpeg-ts-iso13818-1.pdf, page 40 class SrsTsAdaptationField { public: // 1B - /** - * The adaptation_field_length is an 8-bit field specifying the number of bytes in the - * adaptation_field immediately following the adaptation_field_length. The value 0 is for inserting a single stuffing byte in - * a Transport Stream packet. When the adaptation_field_control value is '11', the value of the adaptation_field_length shall - * be in the range 0 to 182. When the adaptation_field_control value is '10', the value of the adaptation_field_length shall - * be 183. For Transport Stream packets carrying PES packets, stuffing is needed when there is insufficient PES packet data - * to completely fill the Transport Stream packet payload bytes. Stuffing is accomplished by defining an adaptation field - * longer than the sum of the lengths of the data elements in it, so that the payload bytes remaining after the adaptation field - * exactly accommodates the available PES packet data. The extra space in the adaptation field is filled with stuffing bytes. - * - * This is the only method of stuffing allowed for Transport Stream packets carrying PES packets. For Transport Stream - * packets carrying PSI, an alternative stuffing method is described in 2.4.4. - */ + // The adaptation_field_length is an 8-bit field specifying the number of bytes in the + // adaptation_field immediately following the adaptation_field_length. The value 0 is for inserting a single stuffing byte in + // a Transport Stream packet. When the adaptation_field_control value is '11', the value of the adaptation_field_length shall + // be in the range 0 to 182. When the adaptation_field_control value is '10', the value of the adaptation_field_length shall + // be 183. For Transport Stream packets carrying PES packets, stuffing is needed when there is insufficient PES packet data + // to completely fill the Transport Stream packet payload bytes. Stuffing is accomplished by defining an adaptation field + // longer than the sum of the lengths of the data elements in it, so that the payload bytes remaining after the adaptation field + // exactly accommodates the available PES packet data. The extra space in the adaptation field is filled with stuffing bytes. + // + // This is the only method of stuffing allowed for Transport Stream packets carrying PES packets. For Transport Stream + // packets carrying PSI, an alternative stuffing method is described in 2.4.4. uint8_t adaption_field_length; //8bits // 1B - /** - * This is a 1-bit field which when set to '1' indicates that the discontinuity state is true for the - * current Transport Stream packet. When the discontinuity_indicator is set to '0' or is not present, the discontinuity state is - * false. The discontinuity indicator is used to indicate two types of discontinuities, system time-base discontinuities and - * continuity_counter discontinuities. - * - * A system time-base discontinuity is indicated by the use of the discontinuity_indicator in Transport Stream packets of a - * PID designated as a PCR_PID (refer to 2.4.4.9). When the discontinuity state is true for a Transport Stream packet of a - * PID designated as a PCR_PID, the next PCR in a Transport Stream packet with that same PID represents a sample of a - * new system time clock for the associated program. The system time-base discontinuity point is defined to be the instant - * in time when the first byte of a packet containing a PCR of a new system time-base arrives at the input of the T-STD. - * The discontinuity_indicator shall be set to '1' in the packet in which the system time-base discontinuity occurs. The - * discontinuity_indicator bit may also be set to '1' in Transport Stream packets of the same PCR_PID prior to the packet - * which contains the new system time-base PCR. In this case, once the discontinuity_indicator has been set to '1', it shall - * continue to be set to '1' in all Transport Stream packets of the same PCR_PID up to and including the Transport Stream - * packet which contains the first PCR of the new system time-base. After the occurrence of a system time-base - * discontinuity, no fewer than two PCRs for the new system time-base shall be received before another system time-base - * discontinuity can occur. Further, except when trick mode status is true, data from no more than two system time-bases - * shall be present in the set of T-STD buffers for one program at any time. - * - * Prior to the occurrence of a system time-base discontinuity, the first byte of a Transport Stream packet which contains a - * PTS or DTS which refers to the new system time-base shall not arrive at the input of the T-STD. After the occurrence of - * a system time-base discontinuity, the first byte of a Transport Stream packet which contains a PTS or DTS which refers - * to the previous system time-base shall not arrive at the input of the T-STD. - * - * A continuity_counter discontinuity is indicated by the use of the discontinuity_indicator in any Transport Stream packet. - * When the discontinuity state is true in any Transport Stream packet of a PID not designated as a PCR_PID, the - * continuity_counter in that packet may be discontinuous with respect to the previous Transport Stream packet of the same - * PID. When the discontinuity state is true in a Transport Stream packet of a PID that is designated as a PCR_PID, the - * continuity_counter may only be discontinuous in the packet in which a system time-base discontinuity occurs. A - * continuity counter discontinuity point occurs when the discontinuity state is true in a Transport Stream packet and the - * continuity_counter in the same packet is discontinuous with respect to the previous Transport Stream packet of the same - * PID. A continuity counter discontinuity point shall occur at most one time from the initiation of the discontinuity state - * until the conclusion of the discontinuity state. Furthermore, for all PIDs that are not designated as PCR_PIDs, when the - * discontinuity_indicator is set to '1' in a packet of a specific PID, the discontinuity_indicator may be set to '1' in the next - * Transport Stream packet of that same PID, but shall not be set to '1' in three consecutive Transport Stream packet of that - * same PID. - * - * For the purpose of this clause, an elementary stream access point is defined as follows: - * Video - The first byte of a video sequence header. - * Audio - The first byte of an audio frame. - * - * After a continuity counter discontinuity in a Transport packet which is designated as containing elementary stream data, - * the first byte of elementary stream data in a Transport Stream packet of the same PID shall be the first byte of an - * elementary stream access point or in the case of video, the first byte of an elementary stream access point or a - * sequence_end_code followed by an access point. Each Transport Stream packet which contains elementary stream data - * with a PID not designated as a PCR_PID, and in which a continuity counter discontinuity point occurs, and in which a - * PTS or DTS occurs, shall arrive at the input of the T-STD after the system time-base discontinuity for the associated - * program occurs. In the case where the discontinuity state is true, if two consecutive Transport Stream packets of the same - * PID occur which have the same continuity_counter value and have adaptation_field_control values set to '01' or '11', the - * second packet may be discarded. A Transport Stream shall not be constructed in such a way that discarding such a packet - * will cause the loss of PES packet payload data or PSI data. - * - * After the occurrence of a discontinuity_indicator set to '1' in a Transport Stream packet which contains PSI information, - * a single discontinuity in the version_number of PSI sections may occur. At the occurrence of such a discontinuity, a - * version of the TS_program_map_sections of the appropriate program shall be sent with section_length = = 13 and the - * current_next_indicator = = 1, such that there are no program_descriptors and no elementary streams described. This shall - * then be followed by a version of the TS_program_map_section for each affected program with the version_number - * incremented by one and the current_next_indicator = = 1, containing a complete program definition. This indicates a - * version change in PSI data. - */ + // This is a 1-bit field which when set to '1' indicates that the discontinuity state is true for the + // current Transport Stream packet. When the discontinuity_indicator is set to '0' or is not present, the discontinuity state is + // false. The discontinuity indicator is used to indicate two types of discontinuities, system time-base discontinuities and + // continuity_counter discontinuities. + // + // A system time-base discontinuity is indicated by the use of the discontinuity_indicator in Transport Stream packets of a + // PID designated as a PCR_PID (refer to 2.4.4.9). When the discontinuity state is true for a Transport Stream packet of a + // PID designated as a PCR_PID, the next PCR in a Transport Stream packet with that same PID represents a sample of a + // new system time clock for the associated program. The system time-base discontinuity point is defined to be the instant + // in time when the first byte of a packet containing a PCR of a new system time-base arrives at the input of the T-STD. + // The discontinuity_indicator shall be set to '1' in the packet in which the system time-base discontinuity occurs. The + // discontinuity_indicator bit may also be set to '1' in Transport Stream packets of the same PCR_PID prior to the packet + // which contains the new system time-base PCR. In this case, once the discontinuity_indicator has been set to '1', it shall + // continue to be set to '1' in all Transport Stream packets of the same PCR_PID up to and including the Transport Stream + // packet which contains the first PCR of the new system time-base. After the occurrence of a system time-base + // discontinuity, no fewer than two PCRs for the new system time-base shall be received before another system time-base + // discontinuity can occur. Further, except when trick mode status is true, data from no more than two system time-bases + // shall be present in the set of T-STD buffers for one program at any time. + // + // Prior to the occurrence of a system time-base discontinuity, the first byte of a Transport Stream packet which contains a + // PTS or DTS which refers to the new system time-base shall not arrive at the input of the T-STD. After the occurrence of + // a system time-base discontinuity, the first byte of a Transport Stream packet which contains a PTS or DTS which refers + // to the previous system time-base shall not arrive at the input of the T-STD. + // + // A continuity_counter discontinuity is indicated by the use of the discontinuity_indicator in any Transport Stream packet. + // When the discontinuity state is true in any Transport Stream packet of a PID not designated as a PCR_PID, the + // continuity_counter in that packet may be discontinuous with respect to the previous Transport Stream packet of the same + // PID. When the discontinuity state is true in a Transport Stream packet of a PID that is designated as a PCR_PID, the + // continuity_counter may only be discontinuous in the packet in which a system time-base discontinuity occurs. A + // continuity counter discontinuity point occurs when the discontinuity state is true in a Transport Stream packet and the + // continuity_counter in the same packet is discontinuous with respect to the previous Transport Stream packet of the same + // PID. A continuity counter discontinuity point shall occur at most one time from the initiation of the discontinuity state + // until the conclusion of the discontinuity state. Furthermore, for all PIDs that are not designated as PCR_PIDs, when the + // discontinuity_indicator is set to '1' in a packet of a specific PID, the discontinuity_indicator may be set to '1' in the next + // Transport Stream packet of that same PID, but shall not be set to '1' in three consecutive Transport Stream packet of that + // same PID. + // + // For the purpose of this clause, an elementary stream access point is defined as follows: + // Video - The first byte of a video sequence header. + // Audio - The first byte of an audio frame. + // + // After a continuity counter discontinuity in a Transport packet which is designated as containing elementary stream data, + // the first byte of elementary stream data in a Transport Stream packet of the same PID shall be the first byte of an + // elementary stream access point or in the case of video, the first byte of an elementary stream access point or a + // sequence_end_code followed by an access point. Each Transport Stream packet which contains elementary stream data + // with a PID not designated as a PCR_PID, and in which a continuity counter discontinuity point occurs, and in which a + // PTS or DTS occurs, shall arrive at the input of the T-STD after the system time-base discontinuity for the associated + // program occurs. In the case where the discontinuity state is true, if two consecutive Transport Stream packets of the same + // PID occur which have the same continuity_counter value and have adaptation_field_control values set to '01' or '11', the + // second packet may be discarded. A Transport Stream shall not be constructed in such a way that discarding such a packet + // will cause the loss of PES packet payload data or PSI data. + // + // After the occurrence of a discontinuity_indicator set to '1' in a Transport Stream packet which contains PSI information, + // a single discontinuity in the version_number of PSI sections may occur. At the occurrence of such a discontinuity, a + // version of the TS_program_map_sections of the appropriate program shall be sent with section_length = = 13 and the + // current_next_indicator = = 1, such that there are no program_descriptors and no elementary streams described. This shall + // then be followed by a version of the TS_program_map_section for each affected program with the version_number + // incremented by one and the current_next_indicator = = 1, containing a complete program definition. This indicates a + // version change in PSI data. int8_t discontinuity_indicator; //1bit - /** - * The random_access_indicator is a 1-bit field that indicates that the current Transport - * Stream packet, and possibly subsequent Transport Stream packets with the same PID, contain some information to aid - * random access at this point. Specifically, when the bit is set to '1', the next PES packet to start in the payload of Transport - * Stream packets with the current PID shall contain the first byte of a video sequence header if the PES stream type (refer - * to Table 2-29) is 1 or 2, or shall contain the first byte of an audio frame if the PES stream type is 3 or 4. In addition, in - * the case of video, a presentation timestamp shall be present in the PES packet containing the first picture following the - * sequence header. In the case of audio, the presentation timestamp shall be present in the PES packet containing the first - * byte of the audio frame. In the PCR_PID the random_access_indicator may only be set to '1' in Transport Stream packet - * containing the PCR fields. - */ + // The random_access_indicator is a 1-bit field that indicates that the current Transport + // Stream packet, and possibly subsequent Transport Stream packets with the same PID, contain some information to aid + // random access at this point. Specifically, when the bit is set to '1', the next PES packet to start in the payload of Transport + // Stream packets with the current PID shall contain the first byte of a video sequence header if the PES stream type (refer + // to Table 2-29) is 1 or 2, or shall contain the first byte of an audio frame if the PES stream type is 3 or 4. In addition, in + // the case of video, a presentation timestamp shall be present in the PES packet containing the first picture following the + // sequence header. In the case of audio, the presentation timestamp shall be present in the PES packet containing the first + // byte of the audio frame. In the PCR_PID the random_access_indicator may only be set to '1' in Transport Stream packet + // containing the PCR fields. int8_t random_access_indicator; //1bit - /** - * The elementary_stream_priority_indicator is a 1-bit field. It indicates, among - * packets with the same PID, the priority of the elementary stream data carried within the payload of this Transport Stream - * packet. A '1' indicates that the payload has a higher priority than the payloads of other Transport Stream packets. In the - * case of video, this field may be set to '1' only if the payload contains one or more bytes from an intra-coded slice. A - * value of '0' indicates that the payload has the same priority as all other packets which do not have this bit set to '1'. - */ + // The elementary_stream_priority_indicator is a 1-bit field. It indicates, among + // packets with the same PID, the priority of the elementary stream data carried within the payload of this Transport Stream + // packet. A '1' indicates that the payload has a higher priority than the payloads of other Transport Stream packets. In the + // case of video, this field may be set to '1' only if the payload contains one or more bytes from an intra-coded slice. A + // value of '0' indicates that the payload has the same priority as all other packets which do not have this bit set to '1'. int8_t elementary_stream_priority_indicator; //1bit - /** - * The PCR_flag is a 1-bit flag. A value of '1' indicates that the adaptation_field contains a PCR field coded in - * two parts. A value of '0' indicates that the adaptation field does not contain any PCR field. - */ + // The PCR_flag is a 1-bit flag. A value of '1' indicates that the adaptation_field contains a PCR field coded in + // two parts. A value of '0' indicates that the adaptation field does not contain any PCR field. int8_t PCR_flag; //1bit - /** - * The OPCR_flag is a 1-bit flag. A value of '1' indicates that the adaptation_field contains an OPCR field - * coded in two parts. A value of '0' indicates that the adaptation field does not contain any OPCR field. - */ + // The OPCR_flag is a 1-bit flag. A value of '1' indicates that the adaptation_field contains an OPCR field + // coded in two parts. A value of '0' indicates that the adaptation field does not contain any OPCR field. int8_t OPCR_flag; //1bit - /** - * The splicing_point_flag is a 1-bit flag. When set to '1', it indicates that a splice_countdown field - * shall be present in the associated adaptation field, specifying the occurrence of a splicing point. A value of '0' indicates - * that a splice_countdown field is not present in the adaptation field. - */ + // The splicing_point_flag is a 1-bit flag. When set to '1', it indicates that a splice_countdown field + // shall be present in the associated adaptation field, specifying the occurrence of a splicing point. A value of '0' indicates + // that a splice_countdown field is not present in the adaptation field. int8_t splicing_point_flag; //1bit - /** - * The transport_private_data_flag is a 1-bit flag. A value of '1' indicates that the - * adaptation field contains one or more private_data bytes. A value of '0' indicates the adaptation field does not contain any - * private_data bytes. - */ + // The transport_private_data_flag is a 1-bit flag. A value of '1' indicates that the + // adaptation field contains one or more private_data bytes. A value of '0' indicates the adaptation field does not contain any + // private_data bytes. int8_t transport_private_data_flag; //1bit - /** - * The adaptation_field_extension_flag is a 1-bit field which when set to '1' indicates - * the presence of an adaptation field extension. A value of '0' indicates that an adaptation field extension is not present in - * the adaptation field. - */ + // The adaptation_field_extension_flag is a 1-bit field which when set to '1' indicates + // the presence of an adaptation field extension. A value of '0' indicates that an adaptation field extension is not present in + // the adaptation field. int8_t adaptation_field_extension_flag; //1bit - // if PCR_flag, 6B - /** - * The program_clock_reference (PCR) is a - * 42-bit field coded in two parts. The first part, program_clock_reference_base, is a 33-bit field whose value is given by - * PCR_base(i), as given in equation 2-2. The second part, program_clock_reference_extension, is a 9-bit field whose value - * is given by PCR_ext(i), as given in equation 2-3. The PCR indicates the intended time of arrival of the byte containing - * the last bit of the program_clock_reference_base at the input of the system target decoder. - */ + // If PCR_flag, 6B + // The program_clock_reference (PCR) is a + // 42-bit field coded in two parts. The first part, program_clock_reference_base, is a 33-bit field whose value is given by + // PCR_base(i), as given in equation 2-2. The second part, program_clock_reference_extension, is a 9-bit field whose value + // is given by PCR_ext(i), as given in equation 2-3. The PCR indicates the intended time of arrival of the byte containing + // the last bit of the program_clock_reference_base at the input of the system target decoder. int64_t program_clock_reference_base; //33bits - /** - * 6bits reserved, must be '1' - */ + // 6bits reserved, must be '1' int8_t const1_value0; // 6bits int16_t program_clock_reference_extension; //9bits - // if OPCR_flag, 6B - /** - * The optional original - * program reference (OPCR) is a 42-bit field coded in two parts. These two parts, the base and the extension, are coded - * identically to the two corresponding parts of the PCR field. The presence of the OPCR is indicated by the OPCR_flag. - * The OPCR field shall be coded only in Transport Stream packets in which the PCR field is present. OPCRs are permitted - * in both single program and multiple program Transport Streams. - * - * OPCR assists in the reconstruction of a single program Transport Stream from another Transport Stream. When - * reconstructing the original single program Transport Stream, the OPCR may be copied to the PCR field. The resulting - * PCR value is valid only if the original single program Transport Stream is reconstructed exactly in its entirety. This - * would include at least any PSI and private data packets which were present in the original Transport Stream and would - * possibly require other private arrangements. It also means that the OPCR must be an identical copy of its associated PCR - * in the original single program Transport Stream. - */ + // If OPCR_flag, 6B + // The optional original + // program reference (OPCR) is a 42-bit field coded in two parts. These two parts, the base and the extension, are coded + // identically to the two corresponding parts of the PCR field. The presence of the OPCR is indicated by the OPCR_flag. + // The OPCR field shall be coded only in Transport Stream packets in which the PCR field is present. OPCRs are permitted + // in both single program and multiple program Transport Streams. + // + // OPCR assists in the reconstruction of a single program Transport Stream from another Transport Stream. When + // reconstructing the original single program Transport Stream, the OPCR may be copied to the PCR field. The resulting + // PCR value is valid only if the original single program Transport Stream is reconstructed exactly in its entirety. This + // would include at least any PSI and private data packets which were present in the original Transport Stream and would + // possibly require other private arrangements. It also means that the OPCR must be an identical copy of its associated PCR + // in the original single program Transport Stream. int64_t original_program_clock_reference_base; //33bits - /** - * 6bits reserved, must be '1' - */ + // 6bits reserved, must be '1' int8_t const1_value2; // 6bits int16_t original_program_clock_reference_extension; //9bits - // if splicing_point_flag, 1B - /** - * The splice_countdown is an 8-bit field, representing a value which may be positive or negative. A - * positive value specifies the remaining number of Transport Stream packets, of the same PID, following the associated - * Transport Stream packet until a splicing point is reached. Duplicate Transport Stream packets and Transport Stream - * packets which only contain adaptation fields are excluded. The splicing point is located immediately after the last byte of - * the Transport Stream packet in which the associated splice_countdown field reaches zero. In the Transport Stream packet - * where the splice_countdown reaches zero, the last data byte of the Transport Stream packet payload shall be the last byte - * of a coded audio frame or a coded picture. In the case of video, the corresponding access unit may or may not be - * terminated by a sequence_end_code. Transport Stream packets with the same PID, which follow, may contain data from - * a different elementary stream of the same type. - * - * The payload of the next Transport Stream packet of the same PID (duplicate packets and packets without payload being - * excluded) shall commence with the first byte of a PES packet.In the case of audio, the PES packet payload shall - * commence with an access point. In the case of video, the PES packet payload shall commence with an access point, or - * with a sequence_end_code, followed by an access point. Thus, the previous coded audio frame or coded picture aligns - * with the packet boundary, or is padded to make this so. Subsequent to the splicing point, the countdown field may also - * be present. When the splice_countdown is a negative number whose value is minus n(-n), it indicates that the associated - * Transport Stream packet is the n-th packet following the splicing point (duplicate packets and packets without payload - * being excluded). - * - * For the purposes of this subclause, an access point is defined as follows: - * Video - The first byte of a video_sequence_header. - * Audio - The first byte of an audio frame. - */ + // If splicing_point_flag, 1B + // The splice_countdown is an 8-bit field, representing a value which may be positive or negative. A + // positive value specifies the remaining number of Transport Stream packets, of the same PID, following the associated + // Transport Stream packet until a splicing point is reached. Duplicate Transport Stream packets and Transport Stream + // packets which only contain adaptation fields are excluded. The splicing point is located immediately after the last byte of + // the Transport Stream packet in which the associated splice_countdown field reaches zero. In the Transport Stream packet + // where the splice_countdown reaches zero, the last data byte of the Transport Stream packet payload shall be the last byte + // of a coded audio frame or a coded picture. In the case of video, the corresponding access unit may or may not be + // terminated by a sequence_end_code. Transport Stream packets with the same PID, which follow, may contain data from + // a different elementary stream of the same type. + // + // The payload of the next Transport Stream packet of the same PID (duplicate packets and packets without payload being + // excluded) shall commence with the first byte of a PES packet.In the case of audio, the PES packet payload shall + // commence with an access point. In the case of video, the PES packet payload shall commence with an access point, or + // with a sequence_end_code, followed by an access point. Thus, the previous coded audio frame or coded picture aligns + // with the packet boundary, or is padded to make this so. Subsequent to the splicing point, the countdown field may also + // be present. When the splice_countdown is a negative number whose value is minus n(-n), it indicates that the associated + // Transport Stream packet is the n-th packet following the splicing point (duplicate packets and packets without payload + // being excluded). + // + // For the purposes of this subclause, an access point is defined as follows: + // Video - The first byte of a video_sequence_header. + // Audio - The first byte of an audio frame. int8_t splice_countdown; //8bits - // if transport_private_data_flag, 1+p[0] B + // If transport_private_data_flag, 1+p[0] B std::vector transport_private_data; //[transport_private_data_length]bytes - // if adaptation_field_extension_flag, 2+x B - /** - * The adaptation_field_extension_length is an 8-bit field. It indicates the number of - * bytes of the extended adaptation field data immediately following this field, including reserved bytes if present. - */ + // If adaptation_field_extension_flag, 2+x B + // The adaptation_field_extension_length is an 8-bit field. It indicates the number of + // bytes of the extended adaptation field data immediately following this field, including reserved bytes if present. uint8_t adaptation_field_extension_length; //8bits - /** - * This is a 1-bit field which when set to '1' indicates the presence of the ltw_offset - * field. - */ + // This is a 1-bit field which when set to '1' indicates the presence of the ltw_offset + // field. int8_t ltw_flag; //1bit - /** - * This is a 1-bit field which when set to '1' indicates the presence of the piecewise_rate field. - */ + // This is a 1-bit field which when set to '1' indicates the presence of the piecewise_rate field. int8_t piecewise_rate_flag; //1bit - /** - * This is a 1-bit flag which when set to '1' indicates that the splice_type and DTS_next_AU fields - * are present. A value of '0' indicates that neither splice_type nor DTS_next_AU fields are present. This field shall not be - * set to '1' in Transport Stream packets in which the splicing_point_flag is not set to '1'. Once it is set to '1' in a Transport - * Stream packet in which the splice_countdown is positive, it shall be set to '1' in all the subsequent Transport Stream - * packets of the same PID that have the splicing_point_flag set to '1', until the packet in which the splice_countdown - * reaches zero (including this packet). When this flag is set, if the elementary stream carried in this PID is an audio stream, - * the splice_type field shall be set to '0000'. If the elementary stream carried in this PID is a video stream, it shall fulfil the - * constraints indicated by the splice_type value. - */ + // This is a 1-bit flag which when set to '1' indicates that the splice_type and DTS_next_AU fields + // are present. A value of '0' indicates that neither splice_type nor DTS_next_AU fields are present. This field shall not be + // set to '1' in Transport Stream packets in which the splicing_point_flag is not set to '1'. Once it is set to '1' in a Transport + // Stream packet in which the splice_countdown is positive, it shall be set to '1' in all the subsequent Transport Stream + // packets of the same PID that have the splicing_point_flag set to '1', until the packet in which the splice_countdown + // reaches zero (including this packet). When this flag is set, if the elementary stream carried in this PID is an audio stream, + // the splice_type field shall be set to '0000'. If the elementary stream carried in this PID is a video stream, it shall fulfil the + // constraints indicated by the splice_type value. int8_t seamless_splice_flag; //1bit - /** - * reserved 5bits, must be '1' - */ + // reserved 5bits, must be '1' int8_t const1_value1; //5bits // if ltw_flag, 2B - /** - * (legal time window_valid_flag) - This is a 1-bit field which when set to '1' indicates that the value of the - * ltw_offset shall be valid. A value of '0' indicates that the value in the ltw_offset field is undefined. - */ + // (legal time window_valid_flag) - This is a 1-bit field which when set to '1' indicates that the value of the + // ltw_offset shall be valid. A value of '0' indicates that the value in the ltw_offset field is undefined. int8_t ltw_valid_flag; //1bit - /** - * (legal time window offset) - This is a 15-bit field, the value of which is defined only if the ltw_valid flag has - * a value of '1'. When defined, the legal time window offset is in units of (300/fs) seconds, where fs is the system clock - * frequency of the program that this PID belongs to, and fulfils: - * offset = t1(i) - t(i) - * ltw_offset = offset//1 - * where i is the index of the first byte of this Transport Stream packet, offset is the value encoded in this field, t(i) is the - * arrival time of byte i in the T-STD, and t1(i) is the upper bound in time of a time interval called the Legal Time Window - * which is associated with this Transport Stream packet. - */ + // (legal time window offset) - This is a 15-bit field, the value of which is defined only if the ltw_valid flag has + // a value of '1'. When defined, the legal time window offset is in units of (300/fs) seconds, where fs is the system clock + // frequency of the program that this PID belongs to, and fulfils: + // offset = t1(i) - t(i) + // ltw_offset = offset//1 + // where i is the index of the first byte of this Transport Stream packet, offset is the value encoded in this field, t(i) is the + // arrival time of byte i in the T-STD, and t1(i) is the upper bound in time of a time interval called the Legal Time Window + // which is associated with this Transport Stream packet. int16_t ltw_offset; //15bits // if piecewise_rate_flag, 3B //2bits reserved - /** - * The meaning of this 22-bit field is only defined when both the ltw_flag and the ltw_valid_flag are set - * to '1'. When defined, it is a positive integer specifying a hypothetical bitrate R which is used to define the end times of - * the Legal Time Windows of Transport Stream packets of the same PID that follow this packet but do not include the - * legal_time_window_offset field. - */ + // The meaning of this 22-bit field is only defined when both the ltw_flag and the ltw_valid_flag are set + // to '1'. When defined, it is a positive integer specifying a hypothetical bitrate R which is used to define the end times of + // the Legal Time Windows of Transport Stream packets of the same PID that follow this packet but do not include the + // legal_time_window_offset field. int32_t piecewise_rate; //22bits // if seamless_splice_flag, 5B - /** - * This is a 4-bit field. From the first occurrence of this field onwards, it shall have the same value in all the - * subsequent Transport Stream packets of the same PID in which it is present, until the packet in which the - * splice_countdown reaches zero (including this packet). If the elementary stream carried in that PID is an audio stream, - * this field shall have the value '0000'. If the elementary stream carried in that PID is a video stream, this field indicates the - * conditions that shall be respected by this elementary stream for splicing purposes. These conditions are defined as a - * function of profile, level and splice_type in Table 2-7 through Table 2-16. - */ + // This is a 4-bit field. From the first occurrence of this field onwards, it shall have the same value in all the + // subsequent Transport Stream packets of the same PID in which it is present, until the packet in which the + // splice_countdown reaches zero (including this packet). If the elementary stream carried in that PID is an audio stream, + // this field shall have the value '0000'. If the elementary stream carried in that PID is a video stream, this field indicates the + // conditions that shall be respected by this elementary stream for splicing purposes. These conditions are defined as a + // function of profile, level and splice_type in Table 2-7 through Table 2-16. int8_t splice_type; //4bits - /** - * (decoding time stamp next access unit) - This is a 33-bit field, coded in three parts. In the case of - * continuous and periodic decoding through this splicing point it indicates the decoding time of the first access unit - * following the splicing point. This decoding time is expressed in the time base which is valid in the Transport Stream - * packet in which the splice_countdown reaches zero. From the first occurrence of this field onwards, it shall have the - * same value in all the subsequent Transport Stream packets of the same PID in which it is present, until the packet in - * which the splice_countdown reaches zero (including this packet). - */ + // (decoding time stamp next access unit) - This is a 33-bit field, coded in three parts. In the case of + // continuous and periodic decoding through this splicing point it indicates the decoding time of the first access unit + // following the splicing point. This decoding time is expressed in the time base which is valid in the Transport Stream + // packet in which the splice_countdown reaches zero. From the first occurrence of this field onwards, it shall have the + // same value in all the subsequent Transport Stream packets of the same PID in which it is present, until the packet in + // which the splice_countdown reaches zero (including this packet). int8_t DTS_next_AU0; //3bits int8_t marker_bit0; //1bit int16_t DTS_next_AU1; //15bits @@ -816,17 +696,13 @@ public: int16_t DTS_next_AU2; //15bits int8_t marker_bit2; //1bit // left bytes. - /** - * This is a fixed 8-bit value equal to '1111 1111' that can be inserted by the encoder. It is discarded by the - * decoder. - */ + // This is a fixed 8-bit value equal to '1111 1111' that can be inserted by the encoder. It is discarded by the + // decoder. int nb_af_ext_reserved; // left bytes. - /** - * This is a fixed 8-bit value equal to '1111 1111' that can be inserted by the encoder. It is discarded by the - * decoder. - */ + // This is a fixed 8-bit value equal to '1111 1111' that can be inserted by the encoder. It is discarded by the + // decoder. int nb_af_reserved; private: SrsTsPacket* packet; @@ -840,10 +716,8 @@ public: virtual srs_error_t encode(SrsBuffer* stream); }; -/** - * 2.4.4.4 Table_id assignments, hls-mpeg-ts-iso13818-1.pdf, page 62 - * The table_id field identifies the contents of a Transport Stream PSI section as shown in Table 2-26. - */ +// 2.4.4.4 Table_id assignments, hls-mpeg-ts-iso13818-1.pdf, page 62 +// The table_id field identifies the contents of a Transport Stream PSI section as shown in Table 2-26. enum SrsTsPsiId { // program_association_section @@ -871,9 +745,7 @@ enum SrsTsPsiId SrsTsPsiIdForbidden = 0xFF, }; -/** - * the payload of ts packet, can be PES or PSI payload. - */ +// The payload of ts packet, can be PES or PSI payload. class SrsTsPayload { protected: @@ -888,131 +760,93 @@ public: virtual srs_error_t encode(SrsBuffer* stream) = 0; }; -/** - * the PES payload of ts packet. - * 2.4.3.6 PES packet, hls-mpeg-ts-iso13818-1.pdf, page 49 - */ +// The PES payload of ts packet. +// 2.4.3.6 PES packet, hls-mpeg-ts-iso13818-1.pdf, page 49 class SrsTsPayloadPES : public SrsTsPayload { public: // 3B - /** - * The packet_start_code_prefix is a 24-bit code. Together with the stream_id that follows it - * constitutes a packet start code that identifies the beginning of a packet. The packet_start_code_prefix is the bit string - * '0000 0000 0000 0000 0000 0001' (0x000001). - */ + // The packet_start_code_prefix is a 24-bit code. Together with the stream_id that follows it + // constitutes a packet start code that identifies the beginning of a packet. The packet_start_code_prefix is the bit string + // '0000 0000 0000 0000 0000 0001' (0x000001). int32_t packet_start_code_prefix; //24bits // 1B - /** - * In Program Streams, the stream_id specifies the type and number of the elementary stream as defined by the - * stream_id Table 2-18. In Transport Streams, the stream_id may be set to any valid value which correctly describes the - * elementary stream type as defined in Table 2-18. In Transport Streams, the elementary stream type is specified in the - * Program Specific Information as specified in 2.4.4. - */ + // In Program Streams, the stream_id specifies the type and number of the elementary stream as defined by the + // stream_id Table 2-18. In Transport Streams, the stream_id may be set to any valid value which correctly describes the + // elementary stream type as defined in Table 2-18. In Transport Streams, the elementary stream type is specified in the + // Program Specific Information as specified in 2.4.4. // @see SrsTsPESStreamId, value can be SrsTsPESStreamIdAudioCommon or SrsTsPESStreamIdVideoCommon. uint8_t stream_id; //8bits // 2B - /** - * A 16-bit field specifying the number of bytes in the PES packet following the last byte of the - * field. A value of 0 indicates that the PES packet length is neither specified nor bounded and is allowed only in - * PES packets whose payload consists of bytes from a video elementary stream contained in Transport Stream packets. - */ + // A 16-bit field specifying the number of bytes in the PES packet following the last byte of the + // field. A value of 0 indicates that the PES packet length is neither specified nor bounded and is allowed only in + // PES packets whose payload consists of bytes from a video elementary stream contained in Transport Stream packets. uint16_t PES_packet_length; //16bits // 1B - /** - * 2bits const '10' - */ + // 2bits const '10' int8_t const2bits; //2bits - /** - * The 2-bit PES_scrambling_control field indicates the scrambling mode of the PES packet - * payload. When scrambling is performed at the PES level, the PES packet header, including the optional fields when - * present, shall not be scrambled (see Table 2-19). - */ + // The 2-bit PES_scrambling_control field indicates the scrambling mode of the PES packet + // payload. When scrambling is performed at the PES level, the PES packet header, including the optional fields when + // present, shall not be scrambled (see Table 2-19). int8_t PES_scrambling_control; //2bits - /** - * This is a 1-bit field indicating the priority of the payload in this PES packet. A '1' indicates a higher - * priority of the payload of the PES packet payload than a PES packet payload with this field set to '0'. A multiplexor can - * use the PES_priority bit to prioritize its data within an elementary stream. This field shall not be changed by the transport - * mechanism. - */ + // This is a 1-bit field indicating the priority of the payload in this PES packet. A '1' indicates a higher + // priority of the payload of the PES packet payload than a PES packet payload with this field set to '0'. A multiplexor can + // use the PES_priority bit to prioritize its data within an elementary stream. This field shall not be changed by the transport + // mechanism. int8_t PES_priority; //1bit - /** - * This is a 1-bit flag. When set to a value of '1' it indicates that the PES packet header is - * immediately followed by the video start code or audio syncword indicated in the data_stream_alignment_descriptor - * in 2.6.10 if this descriptor is present. If set to a value of '1' and the descriptor is not present, alignment as indicated in - * alignment_type '01' in Table 2-47 and Table 2-48 is required. When set to a value of '0' it is not defined whether any such - * alignment occurs or not. - */ + // This is a 1-bit flag. When set to a value of '1' it indicates that the PES packet header is + // immediately followed by the video start code or audio syncword indicated in the data_stream_alignment_descriptor + // in 2.6.10 if this descriptor is present. If set to a value of '1' and the descriptor is not present, alignment as indicated in + // alignment_type '01' in Table 2-47 and Table 2-48 is required. When set to a value of '0' it is not defined whether any such + // alignment occurs or not. int8_t data_alignment_indicator; //1bit - /** - * This is a 1-bit field. When set to '1' it indicates that the material of the associated PES packet payload is - * protected by copyright. When set to '0' it is not defined whether the material is protected by copyright. A copyright - * descriptor described in 2.6.24 is associated with the elementary stream which contains this PES packet and the copyright - * flag is set to '1' if the descriptor applies to the material contained in this PES packet - */ + // This is a 1-bit field. When set to '1' it indicates that the material of the associated PES packet payload is + // protected by copyright. When set to '0' it is not defined whether the material is protected by copyright. A copyright + // descriptor described in 2.6.24 is associated with the elementary stream which contains this PES packet and the copyright + // flag is set to '1' if the descriptor applies to the material contained in this PES packet int8_t copyright; //1bit - /** - * This is a 1-bit field. When set to '1' the contents of the associated PES packet payload is an original. - * When set to '0' it indicates that the contents of the associated PES packet payload is a copy. - */ + // This is a 1-bit field. When set to '1' the contents of the associated PES packet payload is an original. + // When set to '0' it indicates that the contents of the associated PES packet payload is a copy. int8_t original_or_copy; //1bit // 1B - /** - * This is a 2-bit field. When the PTS_DTS_flags field is set to '10', the PTS fields shall be present in - * the PES packet header. When the PTS_DTS_flags field is set to '11', both the PTS fields and DTS fields shall be present - * in the PES packet header. When the PTS_DTS_flags field is set to '00' no PTS or DTS fields shall be present in the PES - * packet header. The value '01' is forbidden. - */ + // This is a 2-bit field. When the PTS_DTS_flags field is set to '10', the PTS fields shall be present in + // the PES packet header. When the PTS_DTS_flags field is set to '11', both the PTS fields and DTS fields shall be present + // in the PES packet header. When the PTS_DTS_flags field is set to '00' no PTS or DTS fields shall be present in the PES + // packet header. The value '01' is forbidden. int8_t PTS_DTS_flags; //2bits - /** - * A 1-bit flag, which when set to '1' indicates that ESCR base and extension fields are present in the PES - * packet header. When set to '0' it indicates that no ESCR fields are present. - */ + // A 1-bit flag, which when set to '1' indicates that ESCR base and extension fields are present in the PES + // packet header. When set to '0' it indicates that no ESCR fields are present. int8_t ESCR_flag; //1bit - /** - * A 1-bit flag, which when set to '1' indicates that the ES_rate field is present in the PES packet header. - * When set to '0' it indicates that no ES_rate field is present. - */ + // A 1-bit flag, which when set to '1' indicates that the ES_rate field is present in the PES packet header. + // When set to '0' it indicates that no ES_rate field is present. int8_t ES_rate_flag; //1bit - /** - * A 1-bit flag, which when set to '1' it indicates the presence of an 8-bit trick mode field. When - * set to '0' it indicates that this field is not present. - */ + // A 1-bit flag, which when set to '1' it indicates the presence of an 8-bit trick mode field. When + // set to '0' it indicates that this field is not present. int8_t DSM_trick_mode_flag; //1bit - /** - * A 1-bit flag, which when set to '1' indicates the presence of the additional_copy_info field. - * When set to '0' it indicates that this field is not present. - */ + // A 1-bit flag, which when set to '1' indicates the presence of the additional_copy_info field. + // When set to '0' it indicates that this field is not present. int8_t additional_copy_info_flag; //1bit - /** - * A 1-bit flag, which when set to '1' indicates that a CRC field is present in the PES packet. When set to - * '0' it indicates that this field is not present. - */ + // A 1-bit flag, which when set to '1' indicates that a CRC field is present in the PES packet. When set to + // '0' it indicates that this field is not present. int8_t PES_CRC_flag; //1bit - /** - * A 1-bit flag, which when set to '1' indicates that an extension field exists in this PES packet - * header. When set to '0' it indicates that this field is not present. - */ + // A 1-bit flag, which when set to '1' indicates that an extension field exists in this PES packet + // header. When set to '0' it indicates that this field is not present. int8_t PES_extension_flag; //1bit // 1B - /** - * An 8-bit field specifying the total number of bytes occupied by the optional fields and any - * stuffing bytes contained in this PES packet header. The presence of optional fields is indicated in the byte that precedes - * the PES_header_data_length field. - */ + // An 8-bit field specifying the total number of bytes occupied by the optional fields and any + // stuffing bytes contained in this PES packet header. The presence of optional fields is indicated in the byte that precedes + // the PES_header_data_length field. uint8_t PES_header_data_length; //8bits // 5B - /** - * Presentation times shall be related to decoding times as follows: The PTS is a 33-bit - * number coded in three separate fields. It indicates the time of presentation, tp n (k), in the system target decoder of a - * presentation unit k of elementary stream n. The value of PTS is specified in units of the period of the system clock - * frequency divided by 300 (yielding 90 kHz). The presentation time is derived from the PTS according to equation 2-11 - * below. Refer to 2.7.4 for constraints on the frequency of coding presentation timestamps. - */ + // Presentation times shall be related to decoding times as follows: The PTS is a 33-bit + // number coded in three separate fields. It indicates the time of presentation, tp n (k), in the system target decoder of a + // presentation unit k of elementary stream n. The value of PTS is specified in units of the period of the system clock + // frequency divided by 300 (yielding 90 kHz). The presentation time is derived from the PTS according to equation 2-11 + // below. Refer to 2.7.4 for constraints on the frequency of coding presentation timestamps. // ===========1B // 4bits const // 3bits PTS [32..30] @@ -1026,11 +860,9 @@ public: int64_t pts; // 33bits // 5B - /** - * The DTS is a 33-bit number coded in three separate fields. It indicates the decoding time, - * td n (j), in the system target decoder of an access unit j of elementary stream n. The value of DTS is specified in units of - * the period of the system clock frequency divided by 300 (yielding 90 kHz). - */ + // The DTS is a 33-bit number coded in three separate fields. It indicates the decoding time, + // td n (j), in the system target decoder of an access unit j of elementary stream n. The value of DTS is specified in units of + // the period of the system clock frequency divided by 300 (yielding 90 kHz). // ===========1B // 4bits const // 3bits DTS [32..30] @@ -1044,13 +876,11 @@ public: int64_t dts; // 33bits // 6B - /** - * The elementary stream clock reference is a 42-bit field coded in two parts. The first - * part, ESCR_base, is a 33-bit field whose value is given by ESCR_base(i), as given in equation 2-14. The second part, - * ESCR_ext, is a 9-bit field whose value is given by ESCR_ext(i), as given in equation 2-15. The ESCR field indicates the - * intended time of arrival of the byte containing the last bit of the ESCR_base at the input of the PES-STD for PES streams - * (refer to 2.5.2.4). - */ + // The elementary stream clock reference is a 42-bit field coded in two parts. The first + // part, ESCR_base, is a 33-bit field whose value is given by ESCR_base(i), as given in equation 2-14. The second part, + // ESCR_ext, is a 9-bit field whose value is given by ESCR_ext(i), as given in equation 2-15. The ESCR field indicates the + // intended time of arrival of the byte containing the last bit of the ESCR_base at the input of the PES-STD for PES streams + // (refer to 2.5.2.4). // 2bits reserved // 3bits ESCR_base[32..30] // 1bit const '1' @@ -1064,83 +894,61 @@ public: int16_t ESCR_extension; //9bits // 3B - /** - * The ES_rate field is a 22-bit unsigned integer specifying the rate at which the - * system target decoder receives bytes of the PES packet in the case of a PES stream. The ES_rate is valid in the PES - * packet in which it is included and in subsequent PES packets of the same PES stream until a new ES_rate field is - * encountered. The value of the ES_rate is measured in units of 50 bytes/second. The value 0 is forbidden. The value of the - * ES_rate is used to define the time of arrival of bytes at the input of a P-STD for PES streams defined in 2.5.2.4. The - * value encoded in the ES_rate field may vary from PES_packet to PES_packet. - */ + // The ES_rate field is a 22-bit unsigned integer specifying the rate at which the + // system target decoder receives bytes of the PES packet in the case of a PES stream. The ES_rate is valid in the PES + // packet in which it is included and in subsequent PES packets of the same PES stream until a new ES_rate field is + // encountered. The value of the ES_rate is measured in units of 50 bytes/second. The value 0 is forbidden. The value of the + // ES_rate is used to define the time of arrival of bytes at the input of a P-STD for PES streams defined in 2.5.2.4. The + // value encoded in the ES_rate field may vary from PES_packet to PES_packet. // 1bit const '1' // 22bits ES_rate // 1bit const '1' int32_t ES_rate; //22bits // 1B - /** - * A 3-bit field that indicates which trick mode is applied to the associated video stream. In cases of - * other types of elementary streams, the meanings of this field and those defined by the following five bits are undefined. - * For the definition of trick_mode status, refer to the trick mode section of 2.4.2.3. - */ + // A 3-bit field that indicates which trick mode is applied to the associated video stream. In cases of + // other types of elementary streams, the meanings of this field and those defined by the following five bits are undefined. + // For the definition of trick_mode status, refer to the trick mode section of 2.4.2.3. int8_t trick_mode_control; //3bits int8_t trick_mode_value; //5bits // 1B // 1bit const '1' - /** - * This 7-bit field contains private data relating to copyright information. - */ + // This 7-bit field contains private data relating to copyright information. int8_t additional_copy_info; //7bits // 2B - /** - * The previous_PES_packet_CRC is a 16-bit field that contains the CRC value that yields - * a zero output of the 16 registers in the decoder similar to the one defined in Annex A, - */ + // The previous_PES_packet_CRC is a 16-bit field that contains the CRC value that yields + // a zero output of the 16 registers in the decoder similar to the one defined in Annex A, int16_t previous_PES_packet_CRC; //16bits // 1B - /** - * A 1-bit flag which when set to '1' indicates that the PES packet header contains private data. - * When set to a value of '0' it indicates that private data is not present in the PES header. - */ + // A 1-bit flag which when set to '1' indicates that the PES packet header contains private data. + // When set to a value of '0' it indicates that private data is not present in the PES header. int8_t PES_private_data_flag; //1bit - /** - * A 1-bit flag which when set to '1' indicates that an ISO/IEC 11172-1 pack header or a - * Program Stream pack header is stored in this PES packet header. If this field is in a PES packet that is contained in a - * Program Stream, then this field shall be set to '0'. In a Transport Stream, when set to the value '0' it indicates that no pack - * header is present in the PES header. - */ + // A 1-bit flag which when set to '1' indicates that an ISO/IEC 11172-1 pack header or a + // Program Stream pack header is stored in this PES packet header. If this field is in a PES packet that is contained in a + // Program Stream, then this field shall be set to '0'. In a Transport Stream, when set to the value '0' it indicates that no pack + // header is present in the PES header. int8_t pack_header_field_flag; //1bit - /** - * A 1-bit flag which when set to '1' indicates that the - * program_packet_sequence_counter, MPEG1_MPEG2_identifier, and original_stuff_length fields are present in this - * PES packet. When set to a value of '0' it indicates that these fields are not present in the PES header. - */ + // A 1-bit flag which when set to '1' indicates that the + // program_packet_sequence_counter, MPEG1_MPEG2_identifier, and original_stuff_length fields are present in this + // PES packet. When set to a value of '0' it indicates that these fields are not present in the PES header. int8_t program_packet_sequence_counter_flag; //1bit - /** - * A 1-bit flag which when set to '1' indicates that the P-STD_buffer_scale and P-STD_buffer_size - * are present in the PES packet header. When set to a value of '0' it indicates that these fields are not present in the - * PES header. - */ + // A 1-bit flag which when set to '1' indicates that the P-STD_buffer_scale and P-STD_buffer_size + // are present in the PES packet header. When set to a value of '0' it indicates that these fields are not present in the + // PES header. int8_t P_STD_buffer_flag; //1bit - /** - * reverved value, must be '1' - */ + // reverved value, must be '1' int8_t const1_value0; //3bits - /** - * A 1-bit field which when set to '1' indicates the presence of the PES_extension_field_length - * field and associated fields. When set to a value of '0' this indicates that the PES_extension_field_length field and any - * associated fields are not present. - */ + // A 1-bit field which when set to '1' indicates the presence of the PES_extension_field_length + // field and associated fields. When set to a value of '0' this indicates that the PES_extension_field_length field and any + // associated fields are not present. int8_t PES_extension_flag_2; //1bit // 16B - /** - * This is a 16-byte field which contains private data. This data, combined with the fields before and - * after, shall not emulate the packet_start_code_prefix (0x000001). - */ + // This is a 16-byte field which contains private data. This data, combined with the fields before and + // after, shall not emulate the packet_start_code_prefix (0x000001). std::vector PES_private_data; //128bits // (1+x)B @@ -1148,44 +956,34 @@ public: // 2B // 1bit const '1' - /** - * The program_packet_sequence_counter field is a 7-bit field. It is an optional - * counter that increments with each successive PES packet from a Program Stream or from an ISO/IEC 11172-1 Stream or - * the PES packets associated with a single program definition in a Transport Stream, providing functionality similar to a - * continuity counter (refer to 2.4.3.2). This allows an application to retrieve the original PES packet sequence of a Program - * Stream or the original packet sequence of the original ISO/IEC 11172-1 stream. The counter will wrap around to 0 after - * its maximum value. Repetition of PES packets shall not occur. Consequently, no two consecutive PES packets in the - * program multiplex shall have identical program_packet_sequence_counter values. - */ + // The program_packet_sequence_counter field is a 7-bit field. It is an optional + // counter that increments with each successive PES packet from a Program Stream or from an ISO/IEC 11172-1 Stream or + // the PES packets associated with a single program definition in a Transport Stream, providing functionality similar to a + // continuity counter (refer to 2.4.3.2). This allows an application to retrieve the original PES packet sequence of a Program + // Stream or the original packet sequence of the original ISO/IEC 11172-1 stream. The counter will wrap around to 0 after + // its maximum value. Repetition of PES packets shall not occur. Consequently, no two consecutive PES packets in the + // program multiplex shall have identical program_packet_sequence_counter values. int8_t program_packet_sequence_counter; //7bits // 1bit const '1' - /** - * A 1-bit flag which when set to '1' indicates that this PES packet carries information from - * an ISO/IEC 11172-1 stream. When set to '0' it indicates that this PES packet carries information from a Program Stream. - */ + // A 1-bit flag which when set to '1' indicates that this PES packet carries information from + // an ISO/IEC 11172-1 stream. When set to '0' it indicates that this PES packet carries information from a Program Stream. int8_t MPEG1_MPEG2_identifier; //1bit - /** - * This 6-bit field specifies the number of stuffing bytes used in the original ITU-T - * Rec. H.222.0 | ISO/IEC 13818-1 PES packet header or in the original ISO/IEC 11172-1 packet header. - */ + // This 6-bit field specifies the number of stuffing bytes used in the original ITU-T + // Rec. H.222.0 | ISO/IEC 13818-1 PES packet header or in the original ISO/IEC 11172-1 packet header. int8_t original_stuff_length; //6bits // 2B // 2bits const '01' - /** - * The P-STD_buffer_scale is a 1-bit field, the meaning of which is only defined if this PES packet - * is contained in a Program Stream. It indicates the scaling factor used to interpret the subsequent P-STD_buffer_size field. - * If the preceding stream_id indicates an audio stream, P-STD_buffer_scale shall have the value '0'. If the preceding - * stream_id indicates a video stream, P-STD_buffer_scale shall have the value '1'. For all other stream types, the value - * may be either '1' or '0'. - */ + // The P-STD_buffer_scale is a 1-bit field, the meaning of which is only defined if this PES packet + // is contained in a Program Stream. It indicates the scaling factor used to interpret the subsequent P-STD_buffer_size field. + // If the preceding stream_id indicates an audio stream, P-STD_buffer_scale shall have the value '0'. If the preceding + // stream_id indicates a video stream, P-STD_buffer_scale shall have the value '1'. For all other stream types, the value + // may be either '1' or '0'. int8_t P_STD_buffer_scale; //1bit - /** - * The P-STD_buffer_size is a 13-bit unsigned integer, the meaning of which is only defined if this - * PES packet is contained in a Program Stream. It defines the size of the input buffer, BS n , in the P-STD. If - * P-STD_buffer_scale has the value '0', then the P-STD_buffer_size measures the buffer size in units of 128 bytes. If - * P-STD_buffer_scale has the value '1', then the P-STD_buffer_size measures the buffer size in units of 1024 bytes. - */ + // The P-STD_buffer_size is a 13-bit unsigned integer, the meaning of which is only defined if this + // PES packet is contained in a Program Stream. It defines the size of the input buffer, BS n , in the P-STD. If + // P-STD_buffer_scale has the value '0', then the P-STD_buffer_size measures the buffer size in units of 128 bytes. If + // P-STD_buffer_scale has the value '1', then the P-STD_buffer_size measures the buffer size in units of 1024 bytes. int16_t P_STD_buffer_size; //13bits // (1+x)B @@ -1193,32 +991,26 @@ public: std::vector PES_extension_field; //[PES_extension_field_length] bytes // NB - /** - * This is a fixed 8-bit value equal to '1111 1111' that can be inserted by the encoder, for example to meet - * the requirements of the channel. It is discarded by the decoder. No more than 32 stuffing bytes shall be present in one - * PES packet header. - */ + // This is a fixed 8-bit value equal to '1111 1111' that can be inserted by the encoder, for example to meet + // the requirements of the channel. It is discarded by the decoder. No more than 32 stuffing bytes shall be present in one + // PES packet header. int nb_stuffings; // NB - /** - * PES_packet_data_bytes shall be contiguous bytes of data from the elementary stream - * indicated by the packet's stream_id or PID. When the elementary stream data conforms to ITU-T - * Rec. H.262 | ISO/IEC 13818-2 or ISO/IEC 13818-3, the PES_packet_data_bytes shall be byte aligned to the bytes of this - * Recommendation | International Standard. The byte-order of the elementary stream shall be preserved. The number of - * PES_packet_data_bytes, N, is specified by the PES_packet_length field. N shall be equal to the value indicated in the - * PES_packet_length minus the number of bytes between the last byte of the PES_packet_length field and the first - * PES_packet_data_byte. - * - * In the case of a private_stream_1, private_stream_2, ECM_stream, or EMM_stream, the contents of the - * PES_packet_data_byte field are user definable and will not be specified by ITU-T | ISO/IEC in the future. - */ + // PES_packet_data_bytes shall be contiguous bytes of data from the elementary stream + // indicated by the packet's stream_id or PID. When the elementary stream data conforms to ITU-T + // Rec. H.262 | ISO/IEC 13818-2 or ISO/IEC 13818-3, the PES_packet_data_bytes shall be byte aligned to the bytes of this + // Recommendation | International Standard. The byte-order of the elementary stream shall be preserved. The number of + // PES_packet_data_bytes, N, is specified by the PES_packet_length field. N shall be equal to the value indicated in the + // PES_packet_length minus the number of bytes between the last byte of the PES_packet_length field and the first + // PES_packet_data_byte. + // + // In the case of a private_stream_1, private_stream_2, ECM_stream, or EMM_stream, the contents of the + // PES_packet_data_byte field are user definable and will not be specified by ITU-T | ISO/IEC in the future. int nb_bytes; // NB - /** - * This is a fixed 8-bit value equal to '1111 1111'. It is discarded by the decoder. - */ + // This is a fixed 8-bit value equal to '1111 1111'. It is discarded by the decoder. int nb_paddings; public: SrsTsPayloadPES(SrsTsPacket* p); @@ -1233,59 +1025,43 @@ private: virtual srs_error_t encode_33bits_dts_pts(SrsBuffer* stream, uint8_t fb, int64_t v); }; -/** - * the PSI payload of ts packet. - * 2.4.4 Program specific information, hls-mpeg-ts-iso13818-1.pdf, page 59 - */ +// The PSI payload of ts packet. +// 2.4.4 Program specific information, hls-mpeg-ts-iso13818-1.pdf, page 59 class SrsTsPayloadPSI : public SrsTsPayload { public: // 1B - /** - * This is an 8-bit field whose value shall be the number of bytes, immediately following the pointer_field - * until the first byte of the first section that is present in the payload of the Transport Stream packet (so a value of 0x00 in - * the pointer_field indicates that the section starts immediately after the pointer_field). When at least one section begins in - * a given Transport Stream packet, then the payload_unit_start_indicator (refer to 2.4.3.2) shall be set to 1 and the first - * byte of the payload of that Transport Stream packet shall contain the pointer. When no section begins in a given - * Transport Stream packet, then the payload_unit_start_indicator shall be set to 0 and no pointer shall be sent in the - * payload of that packet. - */ + // This is an 8-bit field whose value shall be the number of bytes, immediately following the pointer_field + // until the first byte of the first section that is present in the payload of the Transport Stream packet (so a value of 0x00 in + // The pointer_field indicates that the section starts immediately after the pointer_field). When at least one section begins in + // a given Transport Stream packet, then the payload_unit_start_indicator (refer to 2.4.3.2) shall be set to 1 and the first + // byte of the payload of that Transport Stream packet shall contain the pointer. When no section begins in a given + // Transport Stream packet, then the payload_unit_start_indicator shall be set to 0 and no pointer shall be sent in the + // payload of that packet. int8_t pointer_field; public: // 1B - /** - * This is an 8-bit field, which shall be set to 0x00 as shown in Table 2-26. - */ + // This is an 8-bit field, which shall be set to 0x00 as shown in Table 2-26. SrsTsPsiId table_id; //8bits // 2B - /** - * The section_syntax_indicator is a 1-bit field which shall be set to '1'. - */ + // The section_syntax_indicator is a 1-bit field which shall be set to '1'. int8_t section_syntax_indicator; //1bit - /** - * const value, must be '0' - */ + // const value, must be '0' int8_t const0_value; //1bit - /** - * reverved value, must be '1' - */ + // reverved value, must be '1' int8_t const1_value; //2bits - /** - * This is a 12-bit field, the first two bits of which shall be '00'. The remaining 10 bits specify the number - * of bytes of the section, starting immediately following the section_length field, and including the CRC. The value in this - * field shall not exceed 1021 (0x3FD). - */ + // This is a 12-bit field, the first two bits of which shall be '00'. The remaining 10 bits specify the number + // of bytes of the section, starting immediately following the section_length field, and including the CRC. The value in this + // field shall not exceed 1021 (0x3FD). uint16_t section_length; //12bits public: // the specified psi info, for example, PAT fields. public: // 4B - /** - * This is a 32-bit field that contains the CRC value that gives a zero output of the registers in the decoder - * defined in Annex A after processing the entire section. - * @remark crc32(bytes without pointer field, before crc32 field) - */ + // This is a 32-bit field that contains the CRC value that gives a zero output of the registers in the decoder + // defined in Annex A after processing the entire section. + // @remark crc32(bytes without pointer field, before crc32 field) int32_t CRC_32; //32bits public: SrsTsPayloadPSI(SrsTsPacket* p); @@ -1301,31 +1077,23 @@ protected: virtual srs_error_t psi_decode(SrsBuffer* stream) = 0; }; -/** - * the program of PAT of PSI ts packet. - */ +// The program of PAT of PSI ts packet. class SrsTsPayloadPATProgram { public: // 4B - /** - * Program_number is a 16-bit field. It specifies the program to which the program_map_PID is - * applicable. When set to 0x0000, then the following PID reference shall be the network PID. For all other cases the value - * of this field is user defined. This field shall not take any single value more than once within one version of the Program - * Association Table. - */ + // Program_number is a 16-bit field. It specifies the program to which the program_map_PID is + // applicable. When set to 0x0000, then the following PID reference shall be the network PID. For all other cases the value + // of this field is user defined. This field shall not take any single value more than once within one version of the Program + // Association Table. int16_t number; // 16bits - /** - * reverved value, must be '1' - */ + // reverved value, must be '1' int8_t const1_value; //3bits - /** - * program_map_PID/network_PID 13bits - * network_PID - The network_PID is a 13-bit field, which is used only in conjunction with the value of the - * program_number set to 0x0000, specifies the PID of the Transport Stream packets which shall contain the Network - * Information Table. The value of the network_PID field is defined by the user, but shall only take values as specified in - * Table 2-3. The presence of the network_PID is optional. - */ + // program_map_PID/network_PID 13bits + // network_PID - The network_PID is a 13-bit field, which is used only in conjunction with the value of the + // program_number set to 0x0000, specifies the PID of the Transport Stream packets which shall contain the Network + // Information Table. The value of the network_PID field is defined by the user, but shall only take values as specified in + // Table 2-3. The presence of the network_PID is optional. int16_t pid; //13bits public: SrsTsPayloadPATProgram(int16_t n = 0, int16_t p = 0); @@ -1337,56 +1105,42 @@ public: virtual srs_error_t encode(SrsBuffer* stream); }; -/** - * the PAT payload of PSI ts packet. - * 2.4.4.3 Program association Table, hls-mpeg-ts-iso13818-1.pdf, page 61 - * The Program Association Table provides the correspondence between a program_number and the PID value of the - * Transport Stream packets which carry the program definition. The program_number is the numeric label associated with - * a program. - */ +// The PAT payload of PSI ts packet. +// 2.4.4.3 Program association Table, hls-mpeg-ts-iso13818-1.pdf, page 61 +// The Program Association Table provides the correspondence between a program_number and the PID value of the +// Transport Stream packets which carry the program definition. The program_number is the numeric label associated with +// a program. class SrsTsPayloadPAT : public SrsTsPayloadPSI { public: // 2B - /** - * This is a 16-bit field which serves as a label to identify this Transport Stream from any other - * multiplex within a network. Its value is defined by the user. - */ + // This is a 16-bit field which serves as a label to identify this Transport Stream from any other + // multiplex within a network. Its value is defined by the user. uint16_t transport_stream_id; //16bits // 1B - /** - * reverved value, must be '1' - */ + // reverved value, must be '1' int8_t const3_value; //2bits - /** - * This 5-bit field is the version number of the whole Program Association Table. The version number - * shall be incremented by 1 modulo 32 whenever the definition of the Program Association Table changes. When the - * current_next_indicator is set to '1', then the version_number shall be that of the currently applicable Program Association - * Table. When the current_next_indicator is set to '0', then the version_number shall be that of the next applicable Program - * Association Table. - */ + // This 5-bit field is the version number of the whole Program Association Table. The version number + // shall be incremented by 1 modulo 32 whenever the definition of the Program Association Table changes. When the + // current_next_indicator is set to '1', then the version_number shall be that of the currently applicable Program Association + // Table. When the current_next_indicator is set to '0', then the version_number shall be that of the next applicable Program + // Association Table. int8_t version_number; //5bits - /** - * A 1-bit indicator, which when set to '1' indicates that the Program Association Table sent is - * currently applicable. When the bit is set to '0', it indicates that the table sent is not yet applicable and shall be the next - * table to become valid. - */ + // A 1-bit indicator, which when set to '1' indicates that the Program Association Table sent is + // currently applicable. When the bit is set to '0', it indicates that the table sent is not yet applicable and shall be the next + // table to become valid. int8_t current_next_indicator; //1bit // 1B - /** - * This 8-bit field gives the number of this section. The section_number of the first section in the - * Program Association Table shall be 0x00. It shall be incremented by 1 with each additional section in the Program - * Association Table. - */ + // This 8-bit field gives the number of this section. The section_number of the first section in the + // Program Association Table shall be 0x00. It shall be incremented by 1 with each additional section in the Program + // Association Table. uint8_t section_number; //8bits // 1B - /** - * This 8-bit field specifies the number of the last section (that is, the section with the highest - * section_number) of the complete Program Association Table. - */ + // This 8-bit field specifies the number of the last section (that is, the section with the highest + // section_number) of the complete Program Association Table. uint8_t last_section_number; //8bits // multiple 4B program data. @@ -1401,34 +1155,24 @@ protected: virtual srs_error_t psi_encode(SrsBuffer* stream); }; -/** - * the esinfo for PMT program. - */ +// The esinfo for PMT program. class SrsTsPayloadPMTESInfo { public: // 1B - /** - * This is an 8-bit field specifying the type of program element carried within the packets with the PID - * whose value is specified by the elementary_PID. The values of stream_type are specified in Table 2-29. - */ + // This is an 8-bit field specifying the type of program element carried within the packets with the PID + // whose value is specified by the elementary_PID. The values of stream_type are specified in Table 2-29. SrsTsStream stream_type; //8bits // 2B - /** - * reverved value, must be '1' - */ + // reverved value, must be '1' int8_t const1_value0; //3bits - /** - * This is a 13-bit field specifying the PID of the Transport Stream packets which carry the associated - * program element. - */ + // This is a 13-bit field specifying the PID of the Transport Stream packets which carry the associated + // program element. int16_t elementary_PID; //13bits // (2+x)B - /** - * reverved value, must be '1' - */ + // reverved value, must be '1' int8_t const1_value1; //4bits std::vector ES_info; //[ES_info_length] bytes. public: @@ -1441,82 +1185,62 @@ public: virtual srs_error_t encode(SrsBuffer* stream); }; -/** - * the PMT payload of PSI ts packet. - * 2.4.4.8 Program Map Table, hls-mpeg-ts-iso13818-1.pdf, page 64 - * The Program Map Table provides the mappings between program numbers and the program elements that comprise - * them. A single instance of such a mapping is referred to as a "program definition". The program map table is the - * complete collection of all program definitions for a Transport Stream. This table shall be transmitted in packets, the PID - * values of which are selected by the encoder. More than one PID value may be used, if desired. The table is contained in - * one or more sections with the following syntax. It may be segmented to occupy multiple sections. In each section, the - * section number field shall be set to zero. Sections are identified by the program_number field. - */ +// The PMT payload of PSI ts packet. +// 2.4.4.8 Program Map Table, hls-mpeg-ts-iso13818-1.pdf, page 64 +// The Program Map Table provides the mappings between program numbers and the program elements that comprise +// Them. A single instance of such a mapping is referred to as a "program definition". The program map table is the +// complete collection of all program definitions for a Transport Stream. This table shall be transmitted in packets, the PID +// values of which are selected by the encoder. More than one PID value may be used, if desired. The table is contained in +// one or more sections with the following syntax. It may be segmented to occupy multiple sections. In each section, the +// section number field shall be set to zero. Sections are identified by the program_number field. class SrsTsPayloadPMT : public SrsTsPayloadPSI { public: // 2B - /** - * program_number is a 16-bit field. It specifies the program to which the program_map_PID is - * applicable. One program definition shall be carried within only one TS_program_map_section. This implies that a - * program definition is never longer than 1016 (0x3F8). See Informative Annex C for ways to deal with the cases when - * that length is not sufficient. The program_number may be used as a designation for a broadcast channel, for example. By - * describing the different program elements belonging to a program, data from different sources (e.g. sequential events) - * can be concatenated together to form a continuous set of streams using a program_number. For examples of applications - * refer to Annex C. - */ + // program_number is a 16-bit field. It specifies the program to which the program_map_PID is + // applicable. One program definition shall be carried within only one TS_program_map_section. This implies that a + // program definition is never longer than 1016 (0x3F8). See Informative Annex C for ways to deal with the cases when + // that length is not sufficient. The program_number may be used as a designation for a broadcast channel, for example. By + // describing the different program elements belonging to a program, data from different sources (e.g. sequential events) + // can be concatenated together to form a continuous set of streams using a program_number. For examples of applications + // refer to Annex C. uint16_t program_number; //16bits // 1B - /** - * reverved value, must be '1' - */ + // reverved value, must be '1' int8_t const1_value0; //2bits - /** - * This 5-bit field is the version number of the TS_program_map_section. The version number shall be - * incremented by 1 modulo 32 when a change in the information carried within the section occurs. Version number refers - * to the definition of a single program, and therefore to a single section. When the current_next_indicator is set to '1', then - * the version_number shall be that of the currently applicable TS_program_map_section. When the current_next_indicator - * is set to '0', then the version_number shall be that of the next applicable TS_program_map_section. - */ + // This 5-bit field is the version number of the TS_program_map_section. The version number shall be + // incremented by 1 modulo 32 when a change in the information carried within the section occurs. Version number refers + // to the definition of a single program, and therefore to a single section. When the current_next_indicator is set to '1', then + // The version_number shall be that of the currently applicable TS_program_map_section. When the current_next_indicator + // is set to '0', then the version_number shall be that of the next applicable TS_program_map_section. int8_t version_number; //5bits - /** - * A 1-bit field, which when set to '1' indicates that the TS_program_map_section sent is - * currently applicable. When the bit is set to '0', it indicates that the TS_program_map_section sent is not yet applicable - * and shall be the next TS_program_map_section to become valid. - */ + // A 1-bit field, which when set to '1' indicates that the TS_program_map_section sent is + // currently applicable. When the bit is set to '0', it indicates that the TS_program_map_section sent is not yet applicable + // and shall be the next TS_program_map_section to become valid. int8_t current_next_indicator; //1bit // 1B - /** - * The value of this 8-bit field shall be 0x00. - */ + // The value of this 8-bit field shall be 0x00. uint8_t section_number; //8bits // 1B - /** - * The value of this 8-bit field shall be 0x00. - */ + // The value of this 8-bit field shall be 0x00. uint8_t last_section_number; //8bits // 2B - /** - * reverved value, must be '1' - */ + // reverved value, must be '1' int8_t const1_value1; //3bits - /** - * This is a 13-bit field indicating the PID of the Transport Stream packets which shall contain the PCR fields - * valid for the program specified by program_number. If no PCR is associated with a program definition for private - * streams, then this field shall take the value of 0x1FFF. Refer to the semantic definition of PCR in 2.4.3.5 and Table 2-3 - * for restrictions on the choice of PCR_PID value. - */ + // This is a 13-bit field indicating the PID of the Transport Stream packets which shall contain the PCR fields + // valid for the program specified by program_number. If no PCR is associated with a program definition for private + // streams, then this field shall take the value of 0x1FFF. Refer to the semantic definition of PCR in 2.4.3.5 and Table 2-3 + // for restrictions on the choice of PCR_PID value. int16_t PCR_PID; //13bits // 2B int8_t const1_value2; //4bits - /** - * This is a 12-bit field, the first two bits of which shall be '00'. The remaining 10 bits specify the - * number of bytes of the descriptors immediately following the program_info_length field. - */ + // This is a 12-bit field, the first two bits of which shall be '00'. The remaining 10 bits specify the + // number of bytes of the descriptors immediately following the program_info_length field. std::vector program_info_desc; //[program_info_length]bytes // array of TSPMTESInfo. @@ -1531,9 +1255,7 @@ protected: virtual srs_error_t psi_encode(SrsBuffer* stream); }; -/** - * Write the TS message to TS context. - */ +// Write the TS message to TS context. class SrsTsContextWriter { private: @@ -1549,24 +1271,16 @@ public: SrsTsContextWriter(ISrsStreamWriter* w, SrsTsContext* c, SrsAudioCodecId ac, SrsVideoCodecId vc); virtual ~SrsTsContextWriter(); public: - /** - * write an audio frame to ts, - */ + // Write an audio frame to ts, virtual srs_error_t write_audio(SrsTsMessage* audio); - /** - * write a video frame to ts, - */ + // Write a video frame to ts, virtual srs_error_t write_video(SrsTsMessage* video); public: - /** - * get the video codec of ts muxer. - */ + // get the video codec of ts muxer. virtual SrsVideoCodecId video_codec(); }; -/* - * Used for HLS Encryption - */ +// Used for HLS Encryption class SrsEncFileWriter: public SrsFileWriter { public: @@ -1585,27 +1299,21 @@ private: int nb_buf; }; -/** - * TS messages cache, to group frames to TS message, - * for example, we may write multiple AAC RAW frames to a TS message. - */ +// TS messages cache, to group frames to TS message, +// for example, we may write multiple AAC RAW frames to a TS message. class SrsTsMessageCache { public: - // current ts message. + // The current ts message. SrsTsMessage* audio; SrsTsMessage* video; public: SrsTsMessageCache(); virtual ~SrsTsMessageCache(); public: - /** - * write audio to cache - */ + // Write audio to cache virtual srs_error_t cache_audio(SrsAudioFrame* frame, int64_t dts); - /** - * write video to muxer. - */ + // Write video to muxer. virtual srs_error_t cache_video(SrsVideoFrame* frame, int64_t dts); private: virtual srs_error_t do_cache_mp3(SrsAudioFrame* frame); @@ -1613,9 +1321,7 @@ private: virtual srs_error_t do_cache_avc(SrsVideoFrame* frame); }; -/** - * Transmux the RTMP stream to HTTP-TS stream. - */ +// Transmux the RTMP stream to HTTP-TS stream. class SrsTsTransmuxer { private: @@ -1629,16 +1335,12 @@ public: SrsTsTransmuxer(); virtual ~SrsTsTransmuxer(); public: - /** - * initialize the underlayer file stream. - * @param fw the writer to use for ts encoder, user must free it. - */ + // Initialize the underlayer file stream. + // @param fw the writer to use for ts encoder, user must free it. virtual srs_error_t initialize(ISrsStreamWriter* fw); public: - /** - * write audio/video packet. - * @remark assert data is not NULL. - */ + // Write audio/video packet. + // @remark assert data is not NULL. 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); private: diff --git a/trunk/src/kernel/srs_kernel_utility.hpp b/trunk/src/kernel/srs_kernel_utility.hpp index 2d22391a2..56bb78771 100644 --- a/trunk/src/kernel/srs_kernel_utility.hpp +++ b/trunk/src/kernel/srs_kernel_utility.hpp @@ -33,160 +33,132 @@ class SrsBuffer; class SrsBitBuffer; -// compare +// Basic compare function. #define srs_min(a, b) (((a) < (b))? (a) : (b)) #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_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_startup_time(); -// the deamon st-thread will update it. +// A daemon st-thread updates it. extern srs_utime_t srs_update_system_time(); -// the any address for listener, -// it's "0.0.0.0" for ipv4, and "::" for ipv6. +// The "ANY" address to listen, it's "0.0.0.0" for ipv4, and "::" for ipv6. 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); -// split the host:port to host and port. +// Split the host:port to host and port. // @remark the hostport format in , where port is optional. extern void srs_parse_hostport(const std::string& hostport, std::string& host, int& port); -// parse the endpoint to ip and port. -// @remark hostport format in <[ip:]port>, where ip is default to "0.0.0.0". +// Parse the endpoint to ip and port. +// @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); -// parse the int64 value to string. +// Parse the int64 value to string. 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); -// 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); -// whether system is little endian +// Whether system 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); -// 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); -// 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); -// 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); -// remove first substring from str +// Remove first substring from str 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); -// 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 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, 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 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, 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 flag0, std::string flag1); 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 flags); -// split the string by flag to array. +// Split the string by flag to array. extern std::vector srs_string_split(std::string str, std::string flag); extern std::vector srs_string_split(std::string str, std::vector flags); -/** - * compare the memory in bytes. - * @return true if completely equal; otherwise, false. - */ +// Compare the memory in bytes. +// @return true if completely equal; otherwise, false. 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); -// whether path exists. +// Whether path exists. 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); -// 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); -// 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); -// 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); -/** - * whether stream starts with the avc NALU in "AnnexB" - * from ISO_IEC_14496-10-AVC-2003.pdf, page 211. - * 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. - */ +// Whether stream starts with the avc NALU in "AnnexB" from ISO_IEC_14496-10-AVC-2003.pdf, page 211. +// The 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); -/** - * whether stream starts with the aac ADTS - * 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 - */ +// Whether stream starts with the aac ADTS from ISO_IEC_14496-3-AAC-2001.pdf, page 75, 1.A.2.2 ADTS. +// The start code must be '1111 1111 1111'B, that is 0xFFF 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); -/** - * 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); -/** - * Decode a base64-encoded string. - */ +// Decode a base64-encoded string. 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) -/** - * convert hex string to data. - * for example, p=config='139056E5A0' - * output hex to data={0x13, 0x90, 0x56, 0xe5, 0xa0} - */ +// Convert hex string to data, for example, p=config='139056E5A0' +// The output data in hex {0x13, 0x90, 0x56, 0xe5, 0xa0} as such. 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); -/** - * generate the c0 chunk header for msg. - * @param cache, the cache to write header. - * @param nb_cache, the size of cache. - * @return the size of header. 0 if cache not enough. - */ +// Generate the c0 chunk header for msg. +// @param cache, the cache to write header. +// @param nb_cache, the size of cache. +// @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); -/** - * generate the c3 chunk header for msg. - * @param cache, the cache to write header. - * @param nb_cache, the size of cache. - * @return the size of header. 0 if cache not enough. - */ +// Generate the c3 chunk header for msg. +// @param cache, the cache to write header. +// @param nb_cache, the size of cache. +// @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); #endif