2017-03-25 09:21:39 +00:00
|
|
|
/**
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2018-01-07 02:58:53 +00:00
|
|
|
* Copyright (c) 2013-2018 Winlin
|
2017-03-25 09:21:39 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
2014-03-01 07:59:55 +00:00
|
|
|
|
2015-09-22 01:11:07 +00:00
|
|
|
#ifndef SRS_PROTOCOL_UTILITY_HPP
|
|
|
|
#define SRS_PROTOCOL_UTILITY_HPP
|
2014-03-01 07:59:55 +00:00
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
2015-11-11 02:37:50 +00:00
|
|
|
// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213
|
2015-05-24 17:02:06 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <sys/uio.h>
|
|
|
|
#endif
|
|
|
|
|
2014-06-08 05:03:03 +00:00
|
|
|
#include <string>
|
2015-10-22 05:43:38 +00:00
|
|
|
#include <vector>
|
2016-01-08 05:58:19 +00:00
|
|
|
#include <map>
|
2014-06-08 05:03:03 +00:00
|
|
|
|
2014-07-20 05:11:53 +00:00
|
|
|
#include <srs_kernel_consts.hpp>
|
2014-03-01 07:59:55 +00:00
|
|
|
|
2014-12-06 11:56:06 +00:00
|
|
|
class SrsMessageHeader;
|
2015-01-31 11:46:55 +00:00
|
|
|
class SrsSharedPtrMessage;
|
2016-01-08 05:58:19 +00:00
|
|
|
class SrsCommonMessage;
|
2015-05-24 17:02:06 +00:00
|
|
|
class ISrsProtocolReaderWriter;
|
2014-11-07 15:07:31 +00:00
|
|
|
|
2014-07-06 09:43:08 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* parse the tcUrl, output the schema, host, vhost, app and port.
|
|
|
|
* @param tcUrl, the input tcUrl, for example,
|
|
|
|
* rtmp://192.168.1.10:19350/live?vhost=vhost.ossrs.net
|
|
|
|
* @param schema, for example, rtmp
|
|
|
|
* @param host, for example, 192.168.1.10
|
|
|
|
* @param vhost, for example, vhost.ossrs.net.
|
|
|
|
* vhost default to host, when user not set vhost in query of app.
|
|
|
|
* @param app, for example, live
|
|
|
|
* @param port, for example, 19350
|
|
|
|
* default to 1935 if not specified.
|
|
|
|
* param param, for example, vhost=vhost.ossrs.net
|
2018-02-13 00:52:57 +00:00
|
|
|
* @remark The param stream is input and output param, that is:
|
|
|
|
* input: tcUrl+stream
|
|
|
|
* output: schema, host, vhost, app, stream, port, param
|
2017-03-25 09:21:39 +00:00
|
|
|
*/
|
2018-02-13 00:52:57 +00:00
|
|
|
extern void srs_discovery_tc_url(std::string tcUrl, std::string& schema, std::string& host, std::string& vhost, std::string& app,
|
|
|
|
std::string& stream, int& port, std::string& param);
|
2014-06-29 03:45:31 +00:00
|
|
|
|
2016-01-08 05:58:19 +00:00
|
|
|
// parse query string to map(k,v).
|
|
|
|
// must format as key=value&...&keyN=valueN
|
|
|
|
extern void srs_parse_query_string(std::string q, std::map<std::string, std::string>& query);
|
|
|
|
|
2014-07-06 09:43:08 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* generate ramdom data for handshake.
|
|
|
|
*/
|
2014-03-19 06:58:29 +00:00
|
|
|
extern void srs_random_generate(char* bytes, int size);
|
|
|
|
|
2014-07-06 09:43:08 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* generate the tcUrl.
|
|
|
|
* @param param, the app parameters in tcUrl. for example, ?key=xxx,vhost=xxx
|
|
|
|
* @return the tcUrl generated from ip/vhost/app/port.
|
|
|
|
* @remark when vhost equals to __defaultVhost__, use ip as vhost.
|
|
|
|
* @remark ignore port if port equals to default port 1935.
|
|
|
|
*/
|
|
|
|
extern std::string srs_generate_tc_url(std::string ip, std::string vhost, std::string app, int port, std::string param);
|
2014-06-29 02:03:29 +00:00
|
|
|
|
2016-01-08 05:58:19 +00:00
|
|
|
/**
|
|
|
|
* srs_detect_tools generate the normal tcUrl
|
|
|
|
*/
|
2017-03-25 09:21:39 +00:00
|
|
|
extern std::string srs_generate_normal_tc_url(std::string ip, std::string vhost, std::string app, int port, std::string param);
|
2016-01-08 05:58:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* srs_detect_tools generate the normal tcUrl
|
|
|
|
*/
|
2017-03-25 09:21:39 +00:00
|
|
|
extern std::string srs_generate_via_tc_url(std::string ip, std::string vhost, std::string app, int port, std::string param);
|
2016-01-08 05:58:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* srs_detect_tools generate the vis/vis2 tcUrl
|
|
|
|
*/
|
2017-03-25 09:21:39 +00:00
|
|
|
extern std::string srs_generate_vis_tc_url(std::string ip, std::string vhost, std::string app, int port, std::string param);
|
2014-07-05 03:10:42 +00:00
|
|
|
|
2015-01-31 11:46:55 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* create shared ptr message from bytes.
|
|
|
|
* @param data the packet bytes. user should never free it.
|
|
|
|
* @param ppmsg output the shared ptr message. user should free it.
|
|
|
|
*/
|
2018-01-01 01:38:22 +00:00
|
|
|
extern srs_error_t srs_rtmp_create_msg(char type, uint32_t timestamp, char* data, int size, int stream_id, SrsSharedPtrMessage** ppmsg);
|
|
|
|
extern srs_error_t srs_rtmp_create_msg(char type, uint32_t timestamp, char* data, int size, int stream_id, SrsCommonMessage** ppmsg);
|
2015-01-31 11:46:55 +00:00
|
|
|
|
2015-05-22 03:20:25 +00:00
|
|
|
// get the stream identify, vhost/app/stream.
|
2017-03-25 09:21:39 +00:00
|
|
|
extern std::string srs_generate_stream_url(std::string vhost, std::string app, std::string stream);
|
2015-10-13 08:06:37 +00:00
|
|
|
|
|
|
|
// parse the rtmp url to tcUrl/stream,
|
|
|
|
// for example, rtmp://v.ossrs.net/live/livestream to
|
|
|
|
// tcUrl: rtmp://v.ossrs.net/live
|
|
|
|
// stream: livestream
|
2017-03-25 09:21:39 +00:00
|
|
|
extern void srs_parse_rtmp_url(std::string url, std::string& tcUrl, std::string& stream);
|
2015-05-22 03:20:25 +00:00
|
|
|
|
2015-08-25 14:29:00 +00:00
|
|
|
// genereate the rtmp url, for instance, rtmp://server:port/app...vhost...vhost/stream
|
2017-03-25 09:21:39 +00:00
|
|
|
extern std::string srs_generate_rtmp_url(std::string server, int port, std::string vhost, std::string app, std::string stream);
|
2015-08-25 14:29:00 +00:00
|
|
|
|
2015-05-24 17:02:06 +00:00
|
|
|
// write large numbers of iovs.
|
2017-12-31 12:52:04 +00:00
|
|
|
extern srs_error_t srs_write_large_iovs(ISrsProtocolReaderWriter* skt, iovec* iovs, int size, ssize_t* pnwrite = NULL);
|
2015-05-24 17:02:06 +00:00
|
|
|
|
2015-10-22 05:43:38 +00:00
|
|
|
// join string in vector with indicated separator
|
|
|
|
extern std::string srs_join_vector_string(std::vector<std::string>& vs, std::string separator);
|
|
|
|
|
2014-03-01 07:59:55 +00:00
|
|
|
#endif
|
2014-08-02 14:18:39 +00:00
|
|
|
|