2013-11-29 14:21:31 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
2014-01-01 02:37:12 +00:00
|
|
|
Copyright (c) 2013-2014 winlin
|
2013-11-29 14:21:31 +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-02 13:49:09 +00:00
|
|
|
#ifndef SRS_APP_FORWARD_HPP
|
|
|
|
#define SRS_APP_FORWARD_HPP
|
2013-11-29 14:21:31 +00:00
|
|
|
|
|
|
|
/*
|
2014-03-02 13:49:09 +00:00
|
|
|
#include <srs_app_forward.hpp>
|
2013-11-29 14:21:31 +00:00
|
|
|
*/
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2014-03-02 13:49:09 +00:00
|
|
|
#include <srs_app_st.hpp>
|
|
|
|
#include <srs_app_thread.hpp>
|
2013-11-29 14:21:31 +00:00
|
|
|
|
2014-03-01 04:43:04 +00:00
|
|
|
class ISrsProtocolReaderWriter;
|
2014-04-29 06:44:07 +00:00
|
|
|
class SrsSharedPtrMessage;
|
2013-11-29 14:21:31 +00:00
|
|
|
class SrsOnMetaDataPacket;
|
2013-12-15 10:25:55 +00:00
|
|
|
class SrsMessageQueue;
|
2013-12-15 11:24:29 +00:00
|
|
|
class SrsRtmpJitter;
|
2013-11-29 14:21:31 +00:00
|
|
|
class SrsRtmpClient;
|
2013-12-01 09:32:06 +00:00
|
|
|
class SrsRequest;
|
2013-12-15 09:09:25 +00:00
|
|
|
class SrsSource;
|
2014-05-12 09:27:50 +00:00
|
|
|
class SrsKbps;
|
2013-11-29 14:21:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* forward the stream to other servers.
|
|
|
|
*/
|
2014-07-26 12:17:03 +00:00
|
|
|
// TODO: FIXME: refine the error log, comments it.
|
2013-12-14 06:06:32 +00:00
|
|
|
class SrsForwarder : public ISrsThreadHandler
|
2013-11-29 14:21:31 +00:00
|
|
|
{
|
|
|
|
private:
|
2014-08-19 03:54:33 +00:00
|
|
|
// the ep to forward, server[:port].
|
|
|
|
std::string _ep_forward;
|
|
|
|
SrsRequest* _req;
|
2014-03-18 03:32:58 +00:00
|
|
|
int stream_id;
|
2013-11-29 14:21:31 +00:00
|
|
|
private:
|
2014-03-18 03:32:58 +00:00
|
|
|
st_netfd_t stfd;
|
|
|
|
SrsThread* pthread;
|
2013-11-29 14:21:31 +00:00
|
|
|
private:
|
2014-03-18 03:32:58 +00:00
|
|
|
SrsSource* source;
|
|
|
|
ISrsProtocolReaderWriter* io;
|
2014-05-12 09:27:50 +00:00
|
|
|
SrsKbps* kbps;
|
2014-03-18 03:32:58 +00:00
|
|
|
SrsRtmpClient* client;
|
|
|
|
SrsRtmpJitter* jitter;
|
|
|
|
SrsMessageQueue* queue;
|
2013-11-29 14:21:31 +00:00
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
SrsForwarder(SrsSource* _source);
|
|
|
|
virtual ~SrsForwarder();
|
2013-12-15 10:25:55 +00:00
|
|
|
public:
|
2014-08-19 03:54:33 +00:00
|
|
|
virtual int initialize(SrsRequest* req, std::string ep_forward);
|
2014-03-18 03:32:58 +00:00
|
|
|
virtual void set_queue_size(double queue_size);
|
2013-11-29 14:21:31 +00:00
|
|
|
public:
|
2014-08-19 03:54:33 +00:00
|
|
|
virtual int on_publish();
|
2014-03-18 03:32:58 +00:00
|
|
|
virtual void on_unpublish();
|
2014-04-29 06:44:07 +00:00
|
|
|
virtual int on_meta_data(SrsSharedPtrMessage* metadata);
|
|
|
|
virtual int on_audio(SrsSharedPtrMessage* msg);
|
|
|
|
virtual int on_video(SrsSharedPtrMessage* msg);
|
2013-12-14 06:06:32 +00:00
|
|
|
// interface ISrsThreadHandler.
|
|
|
|
public:
|
2014-03-18 03:32:58 +00:00
|
|
|
virtual int cycle();
|
2013-11-29 14:21:31 +00:00
|
|
|
private:
|
2014-03-18 03:32:58 +00:00
|
|
|
virtual void close_underlayer_socket();
|
2014-08-19 03:54:33 +00:00
|
|
|
virtual void discovery_ep(std::string& server, std::string& port, std::string& tc_url);
|
|
|
|
virtual int connect_server(std::string& ep_server, std::string& ep_port);
|
|
|
|
virtual int connect_app(std::string ep_server, std::string ep_port);
|
2014-03-18 03:32:58 +00:00
|
|
|
virtual int forward();
|
2013-11-29 14:21:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2014-08-02 14:18:39 +00:00
|
|
|
|