正在显示
7 个修改的文件
包含
376 行增加
和
39 行删除
| @@ -108,7 +108,7 @@ void SrsForwarder::on_unpublish() | @@ -108,7 +108,7 @@ void SrsForwarder::on_unpublish() | ||
| 108 | srs_freep(client); | 108 | srs_freep(client); |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | -int SrsForwarder::on_meta_data(SrsOnMetaDataPacket* metadata) | 111 | +int SrsForwarder::on_meta_data(SrsSharedPtrMessage* metadata) |
| 112 | { | 112 | { |
| 113 | int ret = ERROR_SUCCESS; | 113 | int ret = ERROR_SUCCESS; |
| 114 | return ret; | 114 | return ret; |
| @@ -222,8 +222,13 @@ int SrsForwarder::forward_cycle_imp() | @@ -222,8 +222,13 @@ int SrsForwarder::forward_cycle_imp() | ||
| 222 | srs_error("connect with server failed, tcUrl=%s. ret=%d", tc_url.c_str(), ret); | 222 | srs_error("connect with server failed, tcUrl=%s. ret=%d", tc_url.c_str(), ret); |
| 223 | return ret; | 223 | return ret; |
| 224 | } | 224 | } |
| 225 | - if ((ret = client->play_stream(stream_name, stream_id)) != ERROR_SUCCESS) { | ||
| 226 | - srs_error("connect with server failed, stream_name=%s. ret=%d", stream_name.c_str(), ret); | 225 | + if ((ret = client->create_stream(stream_id)) != ERROR_SUCCESS) { |
| 226 | + srs_error("connect with server failed, stream_id=%d. ret=%d", stream_id, ret); | ||
| 227 | + return ret; | ||
| 228 | + } | ||
| 229 | + if ((ret = client->publish(stream_name, stream_id)) != ERROR_SUCCESS) { | ||
| 230 | + srs_error("connect with server failed, stream_name=%s, stream_id=%d. ret=%d", | ||
| 231 | + stream_name.c_str(), stream_id, ret); | ||
| 227 | return ret; | 232 | return ret; |
| 228 | } | 233 | } |
| 229 | 234 |
| @@ -61,7 +61,7 @@ public: | @@ -61,7 +61,7 @@ public: | ||
| 61 | public: | 61 | public: |
| 62 | virtual int on_publish(std::string vhost, std::string app, std::string stream, std::string forward_server); | 62 | virtual int on_publish(std::string vhost, std::string app, std::string stream, std::string forward_server); |
| 63 | virtual void on_unpublish(); | 63 | virtual void on_unpublish(); |
| 64 | - virtual int on_meta_data(SrsOnMetaDataPacket* metadata); | 64 | + virtual int on_meta_data(SrsSharedPtrMessage* metadata); |
| 65 | virtual int on_audio(SrsSharedPtrMessage* msg); | 65 | virtual int on_audio(SrsSharedPtrMessage* msg); |
| 66 | virtual int on_video(SrsSharedPtrMessage* msg); | 66 | virtual int on_video(SrsSharedPtrMessage* msg); |
| 67 | private: | 67 | private: |
| @@ -641,6 +641,15 @@ int SrsProtocol::on_send_message(ISrsMessage* msg) | @@ -641,6 +641,15 @@ int SrsProtocol::on_send_message(ISrsMessage* msg) | ||
| 641 | pkt = dynamic_cast<SrsConnectAppPacket*>(common_msg->get_packet()); | 641 | pkt = dynamic_cast<SrsConnectAppPacket*>(common_msg->get_packet()); |
| 642 | if (pkt) { | 642 | if (pkt) { |
| 643 | requests[pkt->transaction_id] = RTMP_AMF0_COMMAND_CONNECT; | 643 | requests[pkt->transaction_id] = RTMP_AMF0_COMMAND_CONNECT; |
| 644 | + break; | ||
| 645 | + } | ||
| 646 | + } | ||
| 647 | + if (true) { | ||
| 648 | + SrsCreateStreamPacket* pkt = NULL; | ||
| 649 | + pkt = dynamic_cast<SrsCreateStreamPacket*>(common_msg->get_packet()); | ||
| 650 | + if (pkt) { | ||
| 651 | + requests[pkt->transaction_id] = RTMP_AMF0_COMMAND_CREATE_STREAM; | ||
| 652 | + break; | ||
| 644 | } | 653 | } |
| 645 | } | 654 | } |
| 646 | break; | 655 | break; |
| @@ -1246,6 +1255,10 @@ int SrsCommonMessage::decode_packet(SrsProtocol* protocol) | @@ -1246,6 +1255,10 @@ int SrsCommonMessage::decode_packet(SrsProtocol* protocol) | ||
| 1246 | srs_info("decode the AMF0/AMF3 response command(connect vhost/app message)."); | 1255 | srs_info("decode the AMF0/AMF3 response command(connect vhost/app message)."); |
| 1247 | packet = new SrsConnectAppResPacket(); | 1256 | packet = new SrsConnectAppResPacket(); |
| 1248 | return packet->decode(stream); | 1257 | return packet->decode(stream); |
| 1258 | + } else if (request_name == RTMP_AMF0_COMMAND_CREATE_STREAM) { | ||
| 1259 | + srs_info("decode the AMF0/AMF3 response command(createStream message)."); | ||
| 1260 | + packet = new SrsCreateStreamResPacket(0, 0); | ||
| 1261 | + return packet->decode(stream); | ||
| 1249 | } else { | 1262 | } else { |
| 1250 | ret = ERROR_RTMP_NO_REQUEST; | 1263 | ret = ERROR_RTMP_NO_REQUEST; |
| 1251 | srs_error("decode AMF0/AMF3 request failed. " | 1264 | srs_error("decode AMF0/AMF3 request failed. " |
| @@ -1841,6 +1854,49 @@ int SrsCreateStreamPacket::decode(SrsStream* stream) | @@ -1841,6 +1854,49 @@ int SrsCreateStreamPacket::decode(SrsStream* stream) | ||
| 1841 | return ret; | 1854 | return ret; |
| 1842 | } | 1855 | } |
| 1843 | 1856 | ||
| 1857 | +int SrsCreateStreamPacket::get_perfer_cid() | ||
| 1858 | +{ | ||
| 1859 | + return RTMP_CID_OverConnection; | ||
| 1860 | +} | ||
| 1861 | + | ||
| 1862 | +int SrsCreateStreamPacket::get_message_type() | ||
| 1863 | +{ | ||
| 1864 | + return RTMP_MSG_AMF0CommandMessage; | ||
| 1865 | +} | ||
| 1866 | + | ||
| 1867 | +int SrsCreateStreamPacket::get_size() | ||
| 1868 | +{ | ||
| 1869 | + return srs_amf0_get_string_size(command_name) + srs_amf0_get_number_size() | ||
| 1870 | + + srs_amf0_get_null_size(); | ||
| 1871 | +} | ||
| 1872 | + | ||
| 1873 | +int SrsCreateStreamPacket::encode_packet(SrsStream* stream) | ||
| 1874 | +{ | ||
| 1875 | + int ret = ERROR_SUCCESS; | ||
| 1876 | + | ||
| 1877 | + if ((ret = srs_amf0_write_string(stream, command_name)) != ERROR_SUCCESS) { | ||
| 1878 | + srs_error("encode command_name failed. ret=%d", ret); | ||
| 1879 | + return ret; | ||
| 1880 | + } | ||
| 1881 | + srs_verbose("encode command_name success."); | ||
| 1882 | + | ||
| 1883 | + if ((ret = srs_amf0_write_number(stream, transaction_id)) != ERROR_SUCCESS) { | ||
| 1884 | + srs_error("encode transaction_id failed. ret=%d", ret); | ||
| 1885 | + return ret; | ||
| 1886 | + } | ||
| 1887 | + srs_verbose("encode transaction_id success."); | ||
| 1888 | + | ||
| 1889 | + if ((ret = srs_amf0_write_null(stream)) != ERROR_SUCCESS) { | ||
| 1890 | + srs_error("encode command_object failed. ret=%d", ret); | ||
| 1891 | + return ret; | ||
| 1892 | + } | ||
| 1893 | + srs_verbose("encode command_object success."); | ||
| 1894 | + | ||
| 1895 | + srs_info("encode create stream request packet success."); | ||
| 1896 | + | ||
| 1897 | + return ret; | ||
| 1898 | +} | ||
| 1899 | + | ||
| 1844 | SrsCreateStreamResPacket::SrsCreateStreamResPacket(double _transaction_id, double _stream_id) | 1900 | SrsCreateStreamResPacket::SrsCreateStreamResPacket(double _transaction_id, double _stream_id) |
| 1845 | { | 1901 | { |
| 1846 | command_name = RTMP_AMF0_COMMAND_RESULT; | 1902 | command_name = RTMP_AMF0_COMMAND_RESULT; |
| @@ -1854,6 +1910,41 @@ SrsCreateStreamResPacket::~SrsCreateStreamResPacket() | @@ -1854,6 +1910,41 @@ SrsCreateStreamResPacket::~SrsCreateStreamResPacket() | ||
| 1854 | srs_freep(command_object); | 1910 | srs_freep(command_object); |
| 1855 | } | 1911 | } |
| 1856 | 1912 | ||
| 1913 | +int SrsCreateStreamResPacket::decode(SrsStream* stream) | ||
| 1914 | +{ | ||
| 1915 | + int ret = ERROR_SUCCESS; | ||
| 1916 | + | ||
| 1917 | + if ((ret = srs_amf0_read_string(stream, command_name)) != ERROR_SUCCESS) { | ||
| 1918 | + srs_error("amf0 decode createStream command_name failed. ret=%d", ret); | ||
| 1919 | + return ret; | ||
| 1920 | + } | ||
| 1921 | + if (command_name.empty() || command_name != RTMP_AMF0_COMMAND_RESULT) { | ||
| 1922 | + ret = ERROR_RTMP_AMF0_DECODE; | ||
| 1923 | + srs_error("amf0 decode createStream command_name failed. " | ||
| 1924 | + "command_name=%s, ret=%d", command_name.c_str(), ret); | ||
| 1925 | + return ret; | ||
| 1926 | + } | ||
| 1927 | + | ||
| 1928 | + if ((ret = srs_amf0_read_number(stream, transaction_id)) != ERROR_SUCCESS) { | ||
| 1929 | + srs_error("amf0 decode createStream transaction_id failed. ret=%d", ret); | ||
| 1930 | + return ret; | ||
| 1931 | + } | ||
| 1932 | + | ||
| 1933 | + if ((ret = srs_amf0_read_null(stream)) != ERROR_SUCCESS) { | ||
| 1934 | + srs_error("amf0 decode createStream command_object failed. ret=%d", ret); | ||
| 1935 | + return ret; | ||
| 1936 | + } | ||
| 1937 | + | ||
| 1938 | + if ((ret = srs_amf0_read_number(stream, stream_id)) != ERROR_SUCCESS) { | ||
| 1939 | + srs_error("amf0 decode createStream stream_id failed. ret=%d", ret); | ||
| 1940 | + return ret; | ||
| 1941 | + } | ||
| 1942 | + | ||
| 1943 | + srs_info("amf0 decode createStream response packet success"); | ||
| 1944 | + | ||
| 1945 | + return ret; | ||
| 1946 | +} | ||
| 1947 | + | ||
| 1857 | int SrsCreateStreamResPacket::get_perfer_cid() | 1948 | int SrsCreateStreamResPacket::get_perfer_cid() |
| 1858 | { | 1949 | { |
| 1859 | return RTMP_CID_OverConnection; | 1950 | return RTMP_CID_OverConnection; |
| @@ -2072,6 +2163,62 @@ int SrsPublishPacket::decode(SrsStream* stream) | @@ -2072,6 +2163,62 @@ int SrsPublishPacket::decode(SrsStream* stream) | ||
| 2072 | return ret; | 2163 | return ret; |
| 2073 | } | 2164 | } |
| 2074 | 2165 | ||
| 2166 | +int SrsPublishPacket::get_perfer_cid() | ||
| 2167 | +{ | ||
| 2168 | + return RTMP_CID_OverStream; | ||
| 2169 | +} | ||
| 2170 | + | ||
| 2171 | +int SrsPublishPacket::get_message_type() | ||
| 2172 | +{ | ||
| 2173 | + return RTMP_MSG_AMF0CommandMessage; | ||
| 2174 | +} | ||
| 2175 | + | ||
| 2176 | +int SrsPublishPacket::get_size() | ||
| 2177 | +{ | ||
| 2178 | + return srs_amf0_get_string_size(command_name) + srs_amf0_get_number_size() | ||
| 2179 | + + srs_amf0_get_null_size() + srs_amf0_get_string_size(stream_name) | ||
| 2180 | + + srs_amf0_get_string_size(type); | ||
| 2181 | +} | ||
| 2182 | + | ||
| 2183 | +int SrsPublishPacket::encode_packet(SrsStream* stream) | ||
| 2184 | +{ | ||
| 2185 | + int ret = ERROR_SUCCESS; | ||
| 2186 | + | ||
| 2187 | + if ((ret = srs_amf0_write_string(stream, command_name)) != ERROR_SUCCESS) { | ||
| 2188 | + srs_error("encode command_name failed. ret=%d", ret); | ||
| 2189 | + return ret; | ||
| 2190 | + } | ||
| 2191 | + srs_verbose("encode command_name success."); | ||
| 2192 | + | ||
| 2193 | + if ((ret = srs_amf0_write_number(stream, transaction_id)) != ERROR_SUCCESS) { | ||
| 2194 | + srs_error("encode transaction_id failed. ret=%d", ret); | ||
| 2195 | + return ret; | ||
| 2196 | + } | ||
| 2197 | + srs_verbose("encode transaction_id success."); | ||
| 2198 | + | ||
| 2199 | + if ((ret = srs_amf0_write_null(stream)) != ERROR_SUCCESS) { | ||
| 2200 | + srs_error("encode command_object failed. ret=%d", ret); | ||
| 2201 | + return ret; | ||
| 2202 | + } | ||
| 2203 | + srs_verbose("encode command_object success."); | ||
| 2204 | + | ||
| 2205 | + if ((ret = srs_amf0_write_string(stream, stream_name)) != ERROR_SUCCESS) { | ||
| 2206 | + srs_error("encode stream_name failed. ret=%d", ret); | ||
| 2207 | + return ret; | ||
| 2208 | + } | ||
| 2209 | + srs_verbose("encode stream_name success."); | ||
| 2210 | + | ||
| 2211 | + if ((ret = srs_amf0_write_string(stream, type)) != ERROR_SUCCESS) { | ||
| 2212 | + srs_error("encode type failed. ret=%d", ret); | ||
| 2213 | + return ret; | ||
| 2214 | + } | ||
| 2215 | + srs_verbose("encode type success."); | ||
| 2216 | + | ||
| 2217 | + srs_info("encode play request packet success."); | ||
| 2218 | + | ||
| 2219 | + return ret; | ||
| 2220 | +} | ||
| 2221 | + | ||
| 2075 | SrsPausePacket::SrsPausePacket() | 2222 | SrsPausePacket::SrsPausePacket() |
| 2076 | { | 2223 | { |
| 2077 | command_name = RTMP_AMF0_COMMAND_PAUSE; | 2224 | command_name = RTMP_AMF0_COMMAND_PAUSE; |
| @@ -2191,6 +2338,75 @@ int SrsPlayPacket::decode(SrsStream* stream) | @@ -2191,6 +2338,75 @@ int SrsPlayPacket::decode(SrsStream* stream) | ||
| 2191 | return ret; | 2338 | return ret; |
| 2192 | } | 2339 | } |
| 2193 | 2340 | ||
| 2341 | +int SrsPlayPacket::get_perfer_cid() | ||
| 2342 | +{ | ||
| 2343 | + return RTMP_CID_OverStream; | ||
| 2344 | +} | ||
| 2345 | + | ||
| 2346 | +int SrsPlayPacket::get_message_type() | ||
| 2347 | +{ | ||
| 2348 | + return RTMP_MSG_AMF0CommandMessage; | ||
| 2349 | +} | ||
| 2350 | + | ||
| 2351 | +int SrsPlayPacket::get_size() | ||
| 2352 | +{ | ||
| 2353 | + return srs_amf0_get_string_size(command_name) + srs_amf0_get_number_size() | ||
| 2354 | + + srs_amf0_get_null_size() + srs_amf0_get_string_size(stream_name) | ||
| 2355 | + + srs_amf0_get_number_size() + srs_amf0_get_number_size() | ||
| 2356 | + + srs_amf0_get_boolean_size(); | ||
| 2357 | +} | ||
| 2358 | + | ||
| 2359 | +int SrsPlayPacket::encode_packet(SrsStream* stream) | ||
| 2360 | +{ | ||
| 2361 | + int ret = ERROR_SUCCESS; | ||
| 2362 | + | ||
| 2363 | + if ((ret = srs_amf0_write_string(stream, command_name)) != ERROR_SUCCESS) { | ||
| 2364 | + srs_error("encode command_name failed. ret=%d", ret); | ||
| 2365 | + return ret; | ||
| 2366 | + } | ||
| 2367 | + srs_verbose("encode command_name success."); | ||
| 2368 | + | ||
| 2369 | + if ((ret = srs_amf0_write_number(stream, transaction_id)) != ERROR_SUCCESS) { | ||
| 2370 | + srs_error("encode transaction_id failed. ret=%d", ret); | ||
| 2371 | + return ret; | ||
| 2372 | + } | ||
| 2373 | + srs_verbose("encode transaction_id success."); | ||
| 2374 | + | ||
| 2375 | + if ((ret = srs_amf0_write_null(stream)) != ERROR_SUCCESS) { | ||
| 2376 | + srs_error("encode command_object failed. ret=%d", ret); | ||
| 2377 | + return ret; | ||
| 2378 | + } | ||
| 2379 | + srs_verbose("encode command_object success."); | ||
| 2380 | + | ||
| 2381 | + if ((ret = srs_amf0_write_string(stream, stream_name)) != ERROR_SUCCESS) { | ||
| 2382 | + srs_error("encode stream_name failed. ret=%d", ret); | ||
| 2383 | + return ret; | ||
| 2384 | + } | ||
| 2385 | + srs_verbose("encode stream_name success."); | ||
| 2386 | + | ||
| 2387 | + if ((ret = srs_amf0_write_number(stream, start)) != ERROR_SUCCESS) { | ||
| 2388 | + srs_error("encode start failed. ret=%d", ret); | ||
| 2389 | + return ret; | ||
| 2390 | + } | ||
| 2391 | + srs_verbose("encode start success."); | ||
| 2392 | + | ||
| 2393 | + if ((ret = srs_amf0_write_number(stream, duration)) != ERROR_SUCCESS) { | ||
| 2394 | + srs_error("encode duration failed. ret=%d", ret); | ||
| 2395 | + return ret; | ||
| 2396 | + } | ||
| 2397 | + srs_verbose("encode duration success."); | ||
| 2398 | + | ||
| 2399 | + if ((ret = srs_amf0_write_boolean(stream, reset)) != ERROR_SUCCESS) { | ||
| 2400 | + srs_error("encode reset failed. ret=%d", ret); | ||
| 2401 | + return ret; | ||
| 2402 | + } | ||
| 2403 | + srs_verbose("encode reset success."); | ||
| 2404 | + | ||
| 2405 | + srs_info("encode play request packet success."); | ||
| 2406 | + | ||
| 2407 | + return ret; | ||
| 2408 | +} | ||
| 2409 | + | ||
| 2194 | SrsPlayResPacket::SrsPlayResPacket() | 2410 | SrsPlayResPacket::SrsPlayResPacket() |
| 2195 | { | 2411 | { |
| 2196 | command_name = RTMP_AMF0_COMMAND_RESULT; | 2412 | command_name = RTMP_AMF0_COMMAND_RESULT; |
| @@ -552,6 +552,13 @@ public: | @@ -552,6 +552,13 @@ public: | ||
| 552 | virtual ~SrsCreateStreamPacket(); | 552 | virtual ~SrsCreateStreamPacket(); |
| 553 | public: | 553 | public: |
| 554 | virtual int decode(SrsStream* stream); | 554 | virtual int decode(SrsStream* stream); |
| 555 | +public: | ||
| 556 | + virtual int get_perfer_cid(); | ||
| 557 | +public: | ||
| 558 | + virtual int get_message_type(); | ||
| 559 | +protected: | ||
| 560 | + virtual int get_size(); | ||
| 561 | + virtual int encode_packet(SrsStream* stream); | ||
| 555 | }; | 562 | }; |
| 556 | /** | 563 | /** |
| 557 | * response for SrsCreateStreamPacket. | 564 | * response for SrsCreateStreamPacket. |
| @@ -574,6 +581,8 @@ public: | @@ -574,6 +581,8 @@ public: | ||
| 574 | SrsCreateStreamResPacket(double _transaction_id, double _stream_id); | 581 | SrsCreateStreamResPacket(double _transaction_id, double _stream_id); |
| 575 | virtual ~SrsCreateStreamResPacket(); | 582 | virtual ~SrsCreateStreamResPacket(); |
| 576 | public: | 583 | public: |
| 584 | + virtual int decode(SrsStream* stream); | ||
| 585 | +public: | ||
| 577 | virtual int get_perfer_cid(); | 586 | virtual int get_perfer_cid(); |
| 578 | public: | 587 | public: |
| 579 | virtual int get_message_type(); | 588 | virtual int get_message_type(); |
| @@ -662,6 +671,13 @@ public: | @@ -662,6 +671,13 @@ public: | ||
| 662 | virtual ~SrsPublishPacket(); | 671 | virtual ~SrsPublishPacket(); |
| 663 | public: | 672 | public: |
| 664 | virtual int decode(SrsStream* stream); | 673 | virtual int decode(SrsStream* stream); |
| 674 | +public: | ||
| 675 | + virtual int get_perfer_cid(); | ||
| 676 | +public: | ||
| 677 | + virtual int get_message_type(); | ||
| 678 | +protected: | ||
| 679 | + virtual int get_size(); | ||
| 680 | + virtual int encode_packet(SrsStream* stream); | ||
| 665 | }; | 681 | }; |
| 666 | 682 | ||
| 667 | /** | 683 | /** |
| @@ -717,6 +733,13 @@ public: | @@ -717,6 +733,13 @@ public: | ||
| 717 | virtual ~SrsPlayPacket(); | 733 | virtual ~SrsPlayPacket(); |
| 718 | public: | 734 | public: |
| 719 | virtual int decode(SrsStream* stream); | 735 | virtual int decode(SrsStream* stream); |
| 736 | +public: | ||
| 737 | + virtual int get_perfer_cid(); | ||
| 738 | +public: | ||
| 739 | + virtual int get_message_type(); | ||
| 740 | +protected: | ||
| 741 | + virtual int get_size(); | ||
| 742 | + virtual int encode_packet(SrsStream* stream); | ||
| 720 | }; | 743 | }; |
| 721 | /** | 744 | /** |
| 722 | * response for SrsPlayPacket. | 745 | * response for SrsPlayPacket. |
| @@ -1050,6 +1073,7 @@ protected: | @@ -1050,6 +1073,7 @@ protected: | ||
| 1050 | return CLASS_NAME_STRING(SrsUserControlPacket); | 1073 | return CLASS_NAME_STRING(SrsUserControlPacket); |
| 1051 | } | 1074 | } |
| 1052 | public: | 1075 | public: |
| 1076 | + // @see: SrcPCUCEventType | ||
| 1053 | int16_t event_type; | 1077 | int16_t event_type; |
| 1054 | int32_t event_data; | 1078 | int32_t event_data; |
| 1055 | /** | 1079 | /** |
| @@ -252,12 +252,99 @@ int SrsRtmpClient::connect_app(std::string app, std::string tc_url) | @@ -252,12 +252,99 @@ int SrsRtmpClient::connect_app(std::string app, std::string tc_url) | ||
| 252 | return ret; | 252 | return ret; |
| 253 | } | 253 | } |
| 254 | 254 | ||
| 255 | -int SrsRtmpClient::play_stream(std::string stream, int& stream_id) | 255 | +int SrsRtmpClient::create_stream(int& stream_id) |
| 256 | { | 256 | { |
| 257 | int ret = ERROR_SUCCESS; | 257 | int ret = ERROR_SUCCESS; |
| 258 | 258 | ||
| 259 | // CreateStream | 259 | // CreateStream |
| 260 | if (true) { | 260 | if (true) { |
| 261 | + SrsCommonMessage* msg = new SrsCommonMessage(); | ||
| 262 | + SrsCreateStreamPacket* pkt = new SrsCreateStreamPacket(); | ||
| 263 | + | ||
| 264 | + msg->set_packet(pkt, 0); | ||
| 265 | + | ||
| 266 | + if ((ret = protocol->send_message(msg)) != ERROR_SUCCESS) { | ||
| 267 | + return ret; | ||
| 268 | + } | ||
| 269 | + } | ||
| 270 | + | ||
| 271 | + // CreateStream _result. | ||
| 272 | + if (true) { | ||
| 273 | + SrsCommonMessage* msg = NULL; | ||
| 274 | + SrsCreateStreamResPacket* pkt = NULL; | ||
| 275 | + if ((ret = srs_rtmp_expect_message<SrsCreateStreamResPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { | ||
| 276 | + srs_error("expect create stream response message failed. ret=%d", ret); | ||
| 277 | + return ret; | ||
| 278 | + } | ||
| 279 | + SrsAutoFree(SrsCommonMessage, msg, false); | ||
| 280 | + srs_info("get create stream response message"); | ||
| 281 | + | ||
| 282 | + stream_id = (int)pkt->stream_id; | ||
| 283 | + } | ||
| 284 | + | ||
| 285 | + return ret; | ||
| 286 | +} | ||
| 287 | + | ||
| 288 | +int SrsRtmpClient::play(std::string stream, int stream_id) | ||
| 289 | +{ | ||
| 290 | + int ret = ERROR_SUCCESS; | ||
| 291 | + | ||
| 292 | + // Play(stream) | ||
| 293 | + if (true) { | ||
| 294 | + SrsCommonMessage* msg = new SrsCommonMessage(); | ||
| 295 | + SrsPlayPacket* pkt = new SrsPlayPacket(); | ||
| 296 | + | ||
| 297 | + pkt->stream_name = stream; | ||
| 298 | + msg->set_packet(pkt, stream_id); | ||
| 299 | + | ||
| 300 | + if ((ret = protocol->send_message(msg)) != ERROR_SUCCESS) { | ||
| 301 | + srs_error("send play stream failed. " | ||
| 302 | + "stream=%s, stream_id=%d, ret=%d", | ||
| 303 | + stream.c_str(), stream_id, ret); | ||
| 304 | + return ret; | ||
| 305 | + } | ||
| 306 | + } | ||
| 307 | + | ||
| 308 | + // SetBufferLength(1000ms) | ||
| 309 | + int buffer_length_ms = 1000; | ||
| 310 | + if (true) { | ||
| 311 | + SrsCommonMessage* msg = new SrsCommonMessage(); | ||
| 312 | + SrsUserControlPacket* pkt = new SrsUserControlPacket(); | ||
| 313 | + | ||
| 314 | + pkt->event_type = SrcPCUCSetBufferLength; | ||
| 315 | + pkt->event_data = stream_id; | ||
| 316 | + pkt->extra_data = buffer_length_ms; | ||
| 317 | + msg->set_packet(pkt, 0); | ||
| 318 | + | ||
| 319 | + if ((ret = protocol->send_message(msg)) != ERROR_SUCCESS) { | ||
| 320 | + srs_error("send set buffer length failed. " | ||
| 321 | + "stream=%s, stream_id=%d, bufferLength=%d, ret=%d", | ||
| 322 | + stream.c_str(), stream_id, buffer_length_ms, ret); | ||
| 323 | + return ret; | ||
| 324 | + } | ||
| 325 | + } | ||
| 326 | + | ||
| 327 | + return ret; | ||
| 328 | +} | ||
| 329 | + | ||
| 330 | +int SrsRtmpClient::publish(std::string stream, int stream_id) | ||
| 331 | +{ | ||
| 332 | + int ret = ERROR_SUCCESS; | ||
| 333 | + | ||
| 334 | + // publish(stream) | ||
| 335 | + if (true) { | ||
| 336 | + SrsCommonMessage* msg = new SrsCommonMessage(); | ||
| 337 | + SrsPublishPacket* pkt = new SrsPublishPacket(); | ||
| 338 | + | ||
| 339 | + pkt->stream_name = stream; | ||
| 340 | + msg->set_packet(pkt, stream_id); | ||
| 341 | + | ||
| 342 | + if ((ret = protocol->send_message(msg)) != ERROR_SUCCESS) { | ||
| 343 | + srs_error("send publish message failed. " | ||
| 344 | + "stream=%s, stream_id=%d, ret=%d", | ||
| 345 | + stream.c_str(), stream_id, ret); | ||
| 346 | + return ret; | ||
| 347 | + } | ||
| 261 | } | 348 | } |
| 262 | 349 | ||
| 263 | return ret; | 350 | return ret; |
| @@ -111,7 +111,9 @@ public: | @@ -111,7 +111,9 @@ public: | ||
| 111 | public: | 111 | public: |
| 112 | virtual int handshake(); | 112 | virtual int handshake(); |
| 113 | virtual int connect_app(std::string app, std::string tc_url); | 113 | virtual int connect_app(std::string app, std::string tc_url); |
| 114 | - virtual int play_stream(std::string stream, int& stream_id); | 114 | + virtual int create_stream(int& stream_id); |
| 115 | + virtual int play(std::string stream, int stream_id); | ||
| 116 | + virtual int publish(std::string stream, int stream_id); | ||
| 115 | }; | 117 | }; |
| 116 | 118 | ||
| 117 | /** | 119 | /** |
| @@ -409,17 +409,6 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata | @@ -409,17 +409,6 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata | ||
| 409 | return ret; | 409 | return ret; |
| 410 | } | 410 | } |
| 411 | #endif | 411 | #endif |
| 412 | - | ||
| 413 | - if (true) { | ||
| 414 | - std::vector<SrsForwarder*>::iterator it; | ||
| 415 | - for (it = forwarders.begin(); it != forwarders.end(); ++it) { | ||
| 416 | - SrsForwarder* forwarder = *it; | ||
| 417 | - if ((ret = forwarder->on_meta_data(metadata)) != ERROR_SUCCESS) { | ||
| 418 | - srs_error("forwarder process onMetaData message failed. ret=%d", ret); | ||
| 419 | - return ret; | ||
| 420 | - } | ||
| 421 | - } | ||
| 422 | - } | ||
| 423 | 412 | ||
| 424 | metadata->metadata->set("server", new SrsAmf0String( | 413 | metadata->metadata->set("server", new SrsAmf0String( |
| 425 | RTMP_SIG_SRS_KEY" "RTMP_SIG_SRS_VERSION" ("RTMP_SIG_SRS_URL_SHORT")")); | 414 | RTMP_SIG_SRS_KEY" "RTMP_SIG_SRS_VERSION" ("RTMP_SIG_SRS_URL_SHORT")")); |
| @@ -477,6 +466,18 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata | @@ -477,6 +466,18 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata | ||
| 477 | srs_trace("dispatch metadata success."); | 466 | srs_trace("dispatch metadata success."); |
| 478 | } | 467 | } |
| 479 | 468 | ||
| 469 | + // copy to all forwarders | ||
| 470 | + if (true) { | ||
| 471 | + std::vector<SrsForwarder*>::iterator it; | ||
| 472 | + for (it = forwarders.begin(); it != forwarders.end(); ++it) { | ||
| 473 | + SrsForwarder* forwarder = *it; | ||
| 474 | + if ((ret = forwarder->on_meta_data(cache_metadata->copy())) != ERROR_SUCCESS) { | ||
| 475 | + srs_error("forwarder process onMetaData message failed. ret=%d", ret); | ||
| 476 | + return ret; | ||
| 477 | + } | ||
| 478 | + } | ||
| 479 | + } | ||
| 480 | + | ||
| 480 | return ret; | 481 | return ret; |
| 481 | } | 482 | } |
| 482 | 483 | ||
| @@ -498,17 +499,6 @@ int SrsSource::on_audio(SrsCommonMessage* audio) | @@ -498,17 +499,6 @@ int SrsSource::on_audio(SrsCommonMessage* audio) | ||
| 498 | return ret; | 499 | return ret; |
| 499 | } | 500 | } |
| 500 | #endif | 501 | #endif |
| 501 | - | ||
| 502 | - if (true) { | ||
| 503 | - std::vector<SrsForwarder*>::iterator it; | ||
| 504 | - for (it = forwarders.begin(); it != forwarders.end(); ++it) { | ||
| 505 | - SrsForwarder* forwarder = *it; | ||
| 506 | - if ((ret = forwarder->on_audio(msg->copy())) != ERROR_SUCCESS) { | ||
| 507 | - srs_error("forwarder process audio message failed. ret=%d", ret); | ||
| 508 | - return ret; | ||
| 509 | - } | ||
| 510 | - } | ||
| 511 | - } | ||
| 512 | 502 | ||
| 513 | // copy to all consumer | 503 | // copy to all consumer |
| 514 | if (true) { | 504 | if (true) { |
| @@ -523,6 +513,18 @@ int SrsSource::on_audio(SrsCommonMessage* audio) | @@ -523,6 +513,18 @@ int SrsSource::on_audio(SrsCommonMessage* audio) | ||
| 523 | srs_info("dispatch audio success."); | 513 | srs_info("dispatch audio success."); |
| 524 | } | 514 | } |
| 525 | 515 | ||
| 516 | + // copy to all forwarders. | ||
| 517 | + if (true) { | ||
| 518 | + std::vector<SrsForwarder*>::iterator it; | ||
| 519 | + for (it = forwarders.begin(); it != forwarders.end(); ++it) { | ||
| 520 | + SrsForwarder* forwarder = *it; | ||
| 521 | + if ((ret = forwarder->on_audio(msg->copy())) != ERROR_SUCCESS) { | ||
| 522 | + srs_error("forwarder process audio message failed. ret=%d", ret); | ||
| 523 | + return ret; | ||
| 524 | + } | ||
| 525 | + } | ||
| 526 | + } | ||
| 527 | + | ||
| 526 | // cache the sequence header if h264 | 528 | // cache the sequence header if h264 |
| 527 | if (SrsCodec::audio_is_sequence_header(msg->payload, msg->size)) { | 529 | if (SrsCodec::audio_is_sequence_header(msg->payload, msg->size)) { |
| 528 | srs_freep(cache_sh_audio); | 530 | srs_freep(cache_sh_audio); |
| @@ -559,17 +561,6 @@ int SrsSource::on_video(SrsCommonMessage* video) | @@ -559,17 +561,6 @@ int SrsSource::on_video(SrsCommonMessage* video) | ||
| 559 | return ret; | 561 | return ret; |
| 560 | } | 562 | } |
| 561 | #endif | 563 | #endif |
| 562 | - | ||
| 563 | - if (true) { | ||
| 564 | - std::vector<SrsForwarder*>::iterator it; | ||
| 565 | - for (it = forwarders.begin(); it != forwarders.end(); ++it) { | ||
| 566 | - SrsForwarder* forwarder = *it; | ||
| 567 | - if ((ret = forwarder->on_video(msg->copy())) != ERROR_SUCCESS) { | ||
| 568 | - srs_error("forwarder process video message failed. ret=%d", ret); | ||
| 569 | - return ret; | ||
| 570 | - } | ||
| 571 | - } | ||
| 572 | - } | ||
| 573 | 564 | ||
| 574 | // copy to all consumer | 565 | // copy to all consumer |
| 575 | if (true) { | 566 | if (true) { |
| @@ -584,6 +575,18 @@ int SrsSource::on_video(SrsCommonMessage* video) | @@ -584,6 +575,18 @@ int SrsSource::on_video(SrsCommonMessage* video) | ||
| 584 | srs_info("dispatch video success."); | 575 | srs_info("dispatch video success."); |
| 585 | } | 576 | } |
| 586 | 577 | ||
| 578 | + // copy to all forwarders. | ||
| 579 | + if (true) { | ||
| 580 | + std::vector<SrsForwarder*>::iterator it; | ||
| 581 | + for (it = forwarders.begin(); it != forwarders.end(); ++it) { | ||
| 582 | + SrsForwarder* forwarder = *it; | ||
| 583 | + if ((ret = forwarder->on_video(msg->copy())) != ERROR_SUCCESS) { | ||
| 584 | + srs_error("forwarder process video message failed. ret=%d", ret); | ||
| 585 | + return ret; | ||
| 586 | + } | ||
| 587 | + } | ||
| 588 | + } | ||
| 589 | + | ||
| 587 | // cache the sequence header if h264 | 590 | // cache the sequence header if h264 |
| 588 | if (SrsCodec::video_is_sequence_header(msg->payload, msg->size)) { | 591 | if (SrsCodec::video_is_sequence_header(msg->payload, msg->size)) { |
| 589 | srs_freep(cache_sh_video); | 592 | srs_freep(cache_sh_video); |
-
请 注册 或 登录 后发表评论