正在显示
4 个修改的文件
包含
144 行增加
和
4 行删除
@@ -367,8 +367,8 @@ int srs_amf0_read_utf8(SrsStream* stream, std::string& value) | @@ -367,8 +367,8 @@ int srs_amf0_read_utf8(SrsStream* stream, std::string& value) | ||
367 | char ch = *(str.data() + i); | 367 | char ch = *(str.data() + i); |
368 | if ((ch & 0x80) != 0) { | 368 | if ((ch & 0x80) != 0) { |
369 | ret = ERROR_RTMP_AMF0_DECODE; | 369 | ret = ERROR_RTMP_AMF0_DECODE; |
370 | - srs_error("only support utf8-1, 0x00-0x7F, actual is %#x. ret=%d", (int)ch, ret); | ||
371 | - return ret; | 370 | + srs_error("ignored. only support utf8-1, 0x00-0x7F, actual is %#x. ret=%d", (int)ch, ret); |
371 | + ret = ERROR_SUCCESS; | ||
372 | } | 372 | } |
373 | } | 373 | } |
374 | 374 |
@@ -163,6 +163,22 @@ int SrsClient::streaming_publish() | @@ -163,6 +163,22 @@ int SrsClient::streaming_publish() | ||
163 | 163 | ||
164 | SrsAutoFree(SrsMessage, msg, false); | 164 | SrsAutoFree(SrsMessage, msg, false); |
165 | 165 | ||
166 | + // process onMetaData | ||
167 | + if (msg->header.is_amf0_data() || msg->header.is_amf3_data()) { | ||
168 | + if ((ret = msg->decode_packet()) != ERROR_SUCCESS) { | ||
169 | + srs_error("decode onMetaData message failed. ret=%d", ret); | ||
170 | + return ret; | ||
171 | + } | ||
172 | + | ||
173 | + SrsPacket* pkt = msg->get_packet(); | ||
174 | + if (dynamic_cast<SrsOnMetaDataPacket*>(pkt)) { | ||
175 | + SrsOnMetaDataPacket* metadata = dynamic_cast<SrsOnMetaDataPacket*>(pkt); | ||
176 | + } | ||
177 | + | ||
178 | + srs_trace("ignore AMF0/AMF3 data message."); | ||
179 | + continue; | ||
180 | + } | ||
181 | + | ||
166 | // process UnPublish event. | 182 | // process UnPublish event. |
167 | if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) { | 183 | if (msg->header.is_amf0_command() || msg->header.is_amf3_command()) { |
168 | if ((ret = msg->decode_packet()) != ERROR_SUCCESS) { | 184 | if ((ret = msg->decode_packet()) != ERROR_SUCCESS) { |
@@ -177,6 +193,7 @@ int SrsClient::streaming_publish() | @@ -177,6 +193,7 @@ int SrsClient::streaming_publish() | ||
177 | } | 193 | } |
178 | 194 | ||
179 | srs_trace("ignore AMF0/AMF3 command message."); | 195 | srs_trace("ignore AMF0/AMF3 command message."); |
196 | + continue; | ||
180 | } | 197 | } |
181 | } | 198 | } |
182 | 199 |
@@ -202,6 +202,8 @@ messages. | @@ -202,6 +202,8 @@ messages. | ||
202 | #define RTMP_AMF0_COMMAND_UNPUBLISH "FCUnpublish" | 202 | #define RTMP_AMF0_COMMAND_UNPUBLISH "FCUnpublish" |
203 | #define RTMP_AMF0_COMMAND_PUBLISH "publish" | 203 | #define RTMP_AMF0_COMMAND_PUBLISH "publish" |
204 | #define RTMP_AMF0_DATA_SAMPLE_ACCESS "|RtmpSampleAccess" | 204 | #define RTMP_AMF0_DATA_SAMPLE_ACCESS "|RtmpSampleAccess" |
205 | +#define RTMP_AMF0_DATA_SET_DATAFRAME "@setDataFrame" | ||
206 | +#define RTMP_AMF0_DATA_ON_METADATA "onMetaData" | ||
205 | 207 | ||
206 | /**************************************************************************** | 208 | /**************************************************************************** |
207 | ***************************************************************************** | 209 | ***************************************************************************** |
@@ -861,11 +863,21 @@ bool SrsMessageHeader::is_amf0_command() | @@ -861,11 +863,21 @@ bool SrsMessageHeader::is_amf0_command() | ||
861 | return message_type == RTMP_MSG_AMF0CommandMessage; | 863 | return message_type == RTMP_MSG_AMF0CommandMessage; |
862 | } | 864 | } |
863 | 865 | ||
866 | +bool SrsMessageHeader::is_amf0_data() | ||
867 | +{ | ||
868 | + return message_type == RTMP_MSG_AMF0DataMessage; | ||
869 | +} | ||
870 | + | ||
864 | bool SrsMessageHeader::is_amf3_command() | 871 | bool SrsMessageHeader::is_amf3_command() |
865 | { | 872 | { |
866 | return message_type == RTMP_MSG_AMF3CommandMessage; | 873 | return message_type == RTMP_MSG_AMF3CommandMessage; |
867 | } | 874 | } |
868 | 875 | ||
876 | +bool SrsMessageHeader::is_amf3_data() | ||
877 | +{ | ||
878 | + return message_type == RTMP_MSG_AMF3DataMessage; | ||
879 | +} | ||
880 | + | ||
869 | bool SrsMessageHeader::is_window_ackledgement_size() | 881 | bool SrsMessageHeader::is_window_ackledgement_size() |
870 | { | 882 | { |
871 | return message_type == RTMP_MSG_WindowAcknowledgementSize; | 883 | return message_type == RTMP_MSG_WindowAcknowledgementSize; |
@@ -931,7 +943,7 @@ int SrsMessage::decode_packet() | @@ -931,7 +943,7 @@ int SrsMessage::decode_packet() | ||
931 | srs_verbose("decode stream initialized success"); | 943 | srs_verbose("decode stream initialized success"); |
932 | 944 | ||
933 | // decode specified packet type | 945 | // decode specified packet type |
934 | - if (header.is_amf0_command() || header.is_amf3_command()) { | 946 | + if (header.is_amf0_command() || header.is_amf3_command() || header.is_amf0_data() || header.is_amf3_data()) { |
935 | srs_verbose("start to decode AMF0/AMF3 command message."); | 947 | srs_verbose("start to decode AMF0/AMF3 command message."); |
936 | 948 | ||
937 | // skip 1bytes to decode the amf3 command. | 949 | // skip 1bytes to decode the amf3 command. |
@@ -984,6 +996,10 @@ int SrsMessage::decode_packet() | @@ -984,6 +996,10 @@ int SrsMessage::decode_packet() | ||
984 | srs_info("decode the AMF0/AMF3 command(unpublish message)."); | 996 | srs_info("decode the AMF0/AMF3 command(unpublish message)."); |
985 | packet = new SrsFMLEStartPacket(); | 997 | packet = new SrsFMLEStartPacket(); |
986 | return packet->decode(stream); | 998 | return packet->decode(stream); |
999 | + } else if(command == RTMP_AMF0_DATA_SET_DATAFRAME || command == RTMP_AMF0_DATA_ON_METADATA) { | ||
1000 | + srs_info("decode the AMF0/AMF3 data(onMetaData message)."); | ||
1001 | + packet = new SrsOnMetaDataPacket(); | ||
1002 | + return packet->decode(stream); | ||
987 | } | 1003 | } |
988 | 1004 | ||
989 | // default packet to drop message. | 1005 | // default packet to drop message. |
@@ -1255,7 +1271,6 @@ int SrsConnectAppResPacket::encode_packet(SrsStream* stream) | @@ -1255,7 +1271,6 @@ int SrsConnectAppResPacket::encode_packet(SrsStream* stream) | ||
1255 | } | 1271 | } |
1256 | srs_verbose("encode info success."); | 1272 | srs_verbose("encode info success."); |
1257 | 1273 | ||
1258 | - | ||
1259 | srs_info("encode connect app response packet success."); | 1274 | srs_info("encode connect app response packet success."); |
1260 | 1275 | ||
1261 | return ret; | 1276 | return ret; |
@@ -1881,6 +1896,81 @@ int SrsSampleAccessPacket::encode_packet(SrsStream* stream) | @@ -1881,6 +1896,81 @@ int SrsSampleAccessPacket::encode_packet(SrsStream* stream) | ||
1881 | return ret; | 1896 | return ret; |
1882 | } | 1897 | } |
1883 | 1898 | ||
1899 | +SrsOnMetaDataPacket::SrsOnMetaDataPacket() | ||
1900 | +{ | ||
1901 | + name = RTMP_AMF0_DATA_ON_METADATA; | ||
1902 | + metadata = new SrsAmf0Object(); | ||
1903 | +} | ||
1904 | + | ||
1905 | +SrsOnMetaDataPacket::~SrsOnMetaDataPacket() | ||
1906 | +{ | ||
1907 | + srs_freep(metadata); | ||
1908 | +} | ||
1909 | + | ||
1910 | +int SrsOnMetaDataPacket::decode(SrsStream* stream) | ||
1911 | +{ | ||
1912 | + int ret = ERROR_SUCCESS; | ||
1913 | + | ||
1914 | + if ((ret = srs_amf0_read_string(stream, name)) != ERROR_SUCCESS) { | ||
1915 | + srs_error("decode metadata name failed. ret=%d", ret); | ||
1916 | + return ret; | ||
1917 | + } | ||
1918 | + | ||
1919 | + // ignore the @setDataFrame | ||
1920 | + if (name == RTMP_AMF0_DATA_SET_DATAFRAME) { | ||
1921 | + if ((ret = srs_amf0_read_string(stream, name)) != ERROR_SUCCESS) { | ||
1922 | + srs_error("decode metadata name failed. ret=%d", ret); | ||
1923 | + return ret; | ||
1924 | + } | ||
1925 | + } | ||
1926 | + | ||
1927 | + srs_verbose("decode metadata name success. name=%s", name.c_str()); | ||
1928 | + | ||
1929 | + if ((ret = srs_amf0_read_object(stream, metadata)) != ERROR_SUCCESS) { | ||
1930 | + srs_error("decode metadata metadata failed. ret=%d", ret); | ||
1931 | + return ret; | ||
1932 | + } | ||
1933 | + | ||
1934 | + srs_info("decode metadata success"); | ||
1935 | + | ||
1936 | + return ret; | ||
1937 | +} | ||
1938 | + | ||
1939 | +int SrsOnMetaDataPacket::get_perfer_cid() | ||
1940 | +{ | ||
1941 | + return RTMP_CID_OverConnection2; | ||
1942 | +} | ||
1943 | + | ||
1944 | +int SrsOnMetaDataPacket::get_message_type() | ||
1945 | +{ | ||
1946 | + return RTMP_MSG_AMF0DataMessage; | ||
1947 | +} | ||
1948 | + | ||
1949 | +int SrsOnMetaDataPacket::get_size() | ||
1950 | +{ | ||
1951 | + return srs_amf0_get_string_size(name) + srs_amf0_get_object_size(metadata); | ||
1952 | +} | ||
1953 | + | ||
1954 | +int SrsOnMetaDataPacket::encode_packet(SrsStream* stream) | ||
1955 | +{ | ||
1956 | + int ret = ERROR_SUCCESS; | ||
1957 | + | ||
1958 | + if ((ret = srs_amf0_write_string(stream, name)) != ERROR_SUCCESS) { | ||
1959 | + srs_error("encode name failed. ret=%d", ret); | ||
1960 | + return ret; | ||
1961 | + } | ||
1962 | + srs_verbose("encode name success."); | ||
1963 | + | ||
1964 | + if ((ret = srs_amf0_write_object(stream, metadata)) != ERROR_SUCCESS) { | ||
1965 | + srs_error("encode metadata failed. ret=%d", ret); | ||
1966 | + return ret; | ||
1967 | + } | ||
1968 | + srs_verbose("encode metadata success."); | ||
1969 | + | ||
1970 | + srs_info("encode onMetaData packet success."); | ||
1971 | + return ret; | ||
1972 | +} | ||
1973 | + | ||
1884 | SrsSetWindowAckSizePacket::SrsSetWindowAckSizePacket() | 1974 | SrsSetWindowAckSizePacket::SrsSetWindowAckSizePacket() |
1885 | { | 1975 | { |
1886 | ackowledgement_window_size = 0; | 1976 | ackowledgement_window_size = 0; |
@@ -180,7 +180,9 @@ struct SrsMessageHeader | @@ -180,7 +180,9 @@ struct SrsMessageHeader | ||
180 | virtual ~SrsMessageHeader(); | 180 | virtual ~SrsMessageHeader(); |
181 | 181 | ||
182 | bool is_amf0_command(); | 182 | bool is_amf0_command(); |
183 | + bool is_amf0_data(); | ||
183 | bool is_amf3_command(); | 184 | bool is_amf3_command(); |
185 | + bool is_amf3_data(); | ||
184 | bool is_window_ackledgement_size(); | 186 | bool is_window_ackledgement_size(); |
185 | bool is_set_chunk_size(); | 187 | bool is_set_chunk_size(); |
186 | }; | 188 | }; |
@@ -693,6 +695,37 @@ protected: | @@ -693,6 +695,37 @@ protected: | ||
693 | }; | 695 | }; |
694 | 696 | ||
695 | /** | 697 | /** |
698 | +* the stream metadata. | ||
699 | +* FMLE: @setDataFrame | ||
700 | +* others: onMetaData | ||
701 | +*/ | ||
702 | +class SrsOnMetaDataPacket : public SrsPacket | ||
703 | +{ | ||
704 | +private: | ||
705 | + typedef SrsPacket super; | ||
706 | +protected: | ||
707 | + virtual const char* get_class_name() | ||
708 | + { | ||
709 | + return CLASS_NAME_STRING(SrsOnMetaDataPacket); | ||
710 | + } | ||
711 | +public: | ||
712 | + std::string name; | ||
713 | + SrsAmf0Object* metadata; | ||
714 | +public: | ||
715 | + SrsOnMetaDataPacket(); | ||
716 | + virtual ~SrsOnMetaDataPacket(); | ||
717 | +public: | ||
718 | + virtual int decode(SrsStream* stream); | ||
719 | +public: | ||
720 | + virtual int get_perfer_cid(); | ||
721 | +public: | ||
722 | + virtual int get_message_type(); | ||
723 | +protected: | ||
724 | + virtual int get_size(); | ||
725 | + virtual int encode_packet(SrsStream* stream); | ||
726 | +}; | ||
727 | + | ||
728 | +/** | ||
696 | * 5.5. Window Acknowledgement Size (5) | 729 | * 5.5. Window Acknowledgement Size (5) |
697 | * The client or the server sends this message to inform the peer which | 730 | * The client or the server sends this message to inform the peer which |
698 | * window size to use when sending acknowledgment. | 731 | * window size to use when sending acknowledgment. |
-
请 注册 或 登录 后发表评论