2017-03-25 09:21:39 +00:00
|
|
|
/**
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2019-12-30 02:10:35 +00:00
|
|
|
* Copyright (c) 2013-2020 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.
|
|
|
|
*/
|
2015-05-03 02:56:20 +00:00
|
|
|
|
|
|
|
#ifndef SRS_APP_CASTER_FLV_HPP
|
|
|
|
#define SRS_APP_CASTER_FLV_HPP
|
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
2015-05-03 15:34:59 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2015-05-03 02:56:20 +00:00
|
|
|
class SrsConfDirective;
|
2015-05-03 15:34:59 +00:00
|
|
|
class SrsHttpServeMux;
|
2015-05-04 11:06:38 +00:00
|
|
|
class SrsRtmpClient;
|
|
|
|
class SrsStSocket;
|
|
|
|
class SrsRequest;
|
2015-05-04 13:55:19 +00:00
|
|
|
class SrsPithyPrint;
|
2015-05-10 02:35:35 +00:00
|
|
|
class ISrsHttpResponseReader;
|
|
|
|
class SrsFlvDecoder;
|
2015-10-13 09:59:51 +00:00
|
|
|
class SrsTcpClient;
|
2015-10-14 03:16:50 +00:00
|
|
|
class SrsSimpleRtmpClient;
|
2015-05-03 02:56:20 +00:00
|
|
|
|
2020-09-11 08:44:40 +00:00
|
|
|
#include <srs_app_st.hpp>
|
2015-05-03 02:56:20 +00:00
|
|
|
#include <srs_app_listener.hpp>
|
2015-05-03 15:34:59 +00:00
|
|
|
#include <srs_app_conn.hpp>
|
2015-05-04 10:11:52 +00:00
|
|
|
#include <srs_app_http_conn.hpp>
|
2015-05-04 10:28:41 +00:00
|
|
|
#include <srs_kernel_file.hpp>
|
2015-05-03 02:56:20 +00:00
|
|
|
|
2019-04-28 01:08:05 +00:00
|
|
|
// The stream caster for flv stream over HTTP POST.
|
2015-05-03 15:34:59 +00:00
|
|
|
class SrsAppCasterFlv : virtual public ISrsTcpHandler
|
2020-09-19 02:30:05 +00:00
|
|
|
, virtual public ISrsResourceManager, virtual public ISrsHttpHandler
|
2015-05-03 02:56:20 +00:00
|
|
|
{
|
2015-05-03 15:34:59 +00:00
|
|
|
private:
|
|
|
|
std::string output;
|
|
|
|
SrsHttpServeMux* http_mux;
|
2020-11-05 07:08:36 +00:00
|
|
|
std::vector<ISrsStartableConneciton*> conns;
|
2020-09-19 02:30:05 +00:00
|
|
|
SrsResourceManager* manager;
|
2015-05-03 02:56:20 +00:00
|
|
|
public:
|
|
|
|
SrsAppCasterFlv(SrsConfDirective* c);
|
|
|
|
virtual ~SrsAppCasterFlv();
|
2015-05-03 15:34:59 +00:00
|
|
|
public:
|
2017-07-29 04:45:17 +00:00
|
|
|
virtual srs_error_t initialize();
|
2019-04-30 00:30:13 +00:00
|
|
|
// Interface ISrsTcpHandler
|
2015-05-03 02:56:20 +00:00
|
|
|
public:
|
2017-07-29 04:45:17 +00:00
|
|
|
virtual srs_error_t on_tcp_client(srs_netfd_t stfd);
|
2020-09-19 02:30:05 +00:00
|
|
|
// Interface ISrsResourceManager
|
2015-05-03 15:34:59 +00:00
|
|
|
public:
|
2020-09-19 02:30:05 +00:00
|
|
|
virtual void remove(ISrsResource* c);
|
2019-04-30 00:30:13 +00:00
|
|
|
// Interface ISrsHttpHandler
|
2015-05-03 15:34:59 +00:00
|
|
|
public:
|
2017-07-29 13:39:57 +00:00
|
|
|
virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r);
|
2015-05-03 02:56:20 +00:00
|
|
|
};
|
|
|
|
|
2019-04-28 01:08:05 +00:00
|
|
|
// The dynamic http connection, never drop the body.
|
2020-11-05 07:18:13 +00:00
|
|
|
class SrsDynamicHttpConn : virtual public ISrsStartableConneciton, virtual public ISrsHttpConnOwner
|
2020-11-05 08:46:16 +00:00
|
|
|
, virtual public ISrsReloadHandler
|
2015-05-04 10:11:52 +00:00
|
|
|
{
|
2015-05-04 11:06:38 +00:00
|
|
|
private:
|
2020-11-05 07:08:36 +00:00
|
|
|
// The manager object to manage the connection.
|
|
|
|
ISrsResourceManager* manager;
|
2015-05-04 11:06:38 +00:00
|
|
|
std::string output;
|
2015-05-04 13:55:19 +00:00
|
|
|
SrsPithyPrint* pprint;
|
2015-10-14 03:16:50 +00:00
|
|
|
SrsSimpleRtmpClient* sdk;
|
2020-11-05 07:08:36 +00:00
|
|
|
SrsHttpConn* conn;
|
|
|
|
private:
|
|
|
|
// The ip and port of client.
|
|
|
|
std::string ip;
|
|
|
|
int port;
|
2015-05-04 10:11:52 +00:00
|
|
|
public:
|
2020-09-19 02:30:05 +00:00
|
|
|
SrsDynamicHttpConn(ISrsResourceManager* cm, srs_netfd_t fd, SrsHttpServeMux* m, std::string cip, int port);
|
2015-05-04 10:11:52 +00:00
|
|
|
virtual ~SrsDynamicHttpConn();
|
2015-05-04 11:06:38 +00:00
|
|
|
public:
|
2018-01-01 11:39:57 +00:00
|
|
|
virtual srs_error_t proxy(ISrsHttpResponseWriter* w, ISrsHttpMessage* r, std::string o);
|
2015-05-04 13:55:19 +00:00
|
|
|
private:
|
2018-01-01 11:39:57 +00:00
|
|
|
virtual srs_error_t do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec);
|
2020-11-05 07:08:36 +00:00
|
|
|
// Extract APIs from SrsTcpConnection.
|
2020-11-05 08:46:16 +00:00
|
|
|
// Interface ISrsReloadHandler
|
|
|
|
public:
|
|
|
|
virtual srs_error_t on_reload_http_stream_crossdomain();
|
2020-11-05 07:18:13 +00:00
|
|
|
// Interface ISrsHttpConnOwner.
|
2020-11-05 07:08:36 +00:00
|
|
|
public:
|
2020-11-05 09:16:59 +00:00
|
|
|
virtual srs_error_t on_start();
|
2020-11-05 10:08:13 +00:00
|
|
|
virtual srs_error_t on_http_message(ISrsHttpMessage* r, SrsHttpResponseWriter* w);
|
2020-11-05 07:08:36 +00:00
|
|
|
virtual void on_conn_done();
|
|
|
|
// Interface ISrsResource.
|
|
|
|
public:
|
|
|
|
virtual std::string desc();
|
|
|
|
// Interface ISrsConnection.
|
|
|
|
public:
|
|
|
|
virtual std::string remote_ip();
|
|
|
|
virtual const SrsContextId& get_id();
|
|
|
|
// Interface ISrsStartable
|
|
|
|
public:
|
|
|
|
virtual srs_error_t start();
|
|
|
|
// Interface ISrsKbpsDelta
|
|
|
|
public:
|
|
|
|
virtual void remark(int64_t* in, int64_t* out);
|
2015-05-04 10:11:52 +00:00
|
|
|
};
|
|
|
|
|
2019-04-28 01:08:05 +00:00
|
|
|
// The http wrapper for file reader, to read http post stream like a file.
|
2015-05-04 10:28:41 +00:00
|
|
|
class SrsHttpFileReader : public SrsFileReader
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
ISrsHttpResponseReader* http;
|
|
|
|
public:
|
|
|
|
SrsHttpFileReader(ISrsHttpResponseReader* h);
|
|
|
|
virtual ~SrsHttpFileReader();
|
|
|
|
public:
|
2019-04-28 01:08:05 +00:00
|
|
|
// Open file reader, can open then close then open...
|
2018-01-01 11:39:57 +00:00
|
|
|
virtual srs_error_t open(std::string file);
|
2015-05-04 10:28:41 +00:00
|
|
|
virtual void close();
|
|
|
|
public:
|
|
|
|
// TODO: FIXME: extract interface.
|
|
|
|
virtual bool is_open();
|
|
|
|
virtual int64_t tellg();
|
|
|
|
virtual void skip(int64_t size);
|
2017-02-03 14:49:19 +00:00
|
|
|
virtual int64_t seek2(int64_t offset);
|
2015-05-04 10:28:41 +00:00
|
|
|
virtual int64_t filesize();
|
|
|
|
public:
|
2018-01-01 11:39:57 +00:00
|
|
|
virtual srs_error_t read(void* buf, size_t count, ssize_t* pnread);
|
|
|
|
virtual srs_error_t lseek(off_t offset, int whence, off_t* seeked);
|
2015-05-04 10:28:41 +00:00
|
|
|
};
|
|
|
|
|
2015-05-03 02:56:20 +00:00
|
|
|
#endif
|
|
|
|
|