2017-03-25 09:21:39 +00:00
|
|
|
/**
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
2017-03-25 13:29:29 +00:00
|
|
|
* Copyright (c) 2013-2017 OSSRS(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.
|
|
|
|
*/
|
2013-11-29 14:21:31 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
#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;
|
2017-01-19 04:38:55 +00:00
|
|
|
class SrsOriginHub;
|
2014-05-12 09:27:50 +00:00
|
|
|
class SrsKbps;
|
2015-10-14 07:34:18 +00:00
|
|
|
class SrsSimpleRtmpClient;
|
2013-11-29 14:21:31 +00:00
|
|
|
|
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* forward the stream to other servers.
|
|
|
|
*/
|
2014-07-26 12:17:03 +00:00
|
|
|
// TODO: FIXME: refine the error log, comments it.
|
2015-05-23 01:49:15 +00:00
|
|
|
class SrsForwarder : public ISrsReusableThread2Handler
|
2013-11-29 14:21:31 +00:00
|
|
|
{
|
|
|
|
private:
|
2014-08-19 03:54:33 +00:00
|
|
|
// the ep to forward, server[:port].
|
2015-10-14 07:34:18 +00:00
|
|
|
std::string ep_forward;
|
|
|
|
SrsRequest* req;
|
2013-11-29 14:21:31 +00:00
|
|
|
private:
|
2015-05-23 01:49:15 +00:00
|
|
|
SrsReusableThread2* pthread;
|
2013-11-29 14:21:31 +00:00
|
|
|
private:
|
2017-01-19 04:38:55 +00:00
|
|
|
SrsOriginHub* hub;
|
2015-10-14 07:34:18 +00:00
|
|
|
SrsSimpleRtmpClient* sdk;
|
2014-03-18 03:32:58 +00:00
|
|
|
SrsRtmpJitter* jitter;
|
|
|
|
SrsMessageQueue* queue;
|
2014-08-24 14:34:38 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* cache the sequence header for retry when slave is failed.
|
|
|
|
* @see https://github.com/ossrs/srs/issues/150
|
|
|
|
*/
|
2014-08-24 14:34:38 +00:00
|
|
|
SrsSharedPtrMessage* sh_audio;
|
|
|
|
SrsSharedPtrMessage* sh_video;
|
2013-11-29 14:21:31 +00:00
|
|
|
public:
|
2017-01-19 04:38:55 +00:00
|
|
|
SrsForwarder(SrsOriginHub* h);
|
2014-03-18 03:32:58 +00:00
|
|
|
virtual ~SrsForwarder();
|
2013-12-15 10:25:55 +00:00
|
|
|
public:
|
2015-10-14 07:34:18 +00:00
|
|
|
virtual int initialize(SrsRequest* r, std::string ep);
|
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-12-05 15:49:53 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* forward the audio packet.
|
|
|
|
* @param shared_metadata, directly ptr, copy it if need to save it.
|
|
|
|
*/
|
2015-03-21 03:55:28 +00:00
|
|
|
virtual int on_meta_data(SrsSharedPtrMessage* shared_metadata);
|
2014-12-05 15:49:53 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* forward the audio packet.
|
|
|
|
* @param shared_audio, directly ptr, copy it if need to save it.
|
|
|
|
*/
|
2015-03-21 03:55:28 +00:00
|
|
|
virtual int on_audio(SrsSharedPtrMessage* shared_audio);
|
2014-12-05 15:49:53 +00:00
|
|
|
/**
|
2017-03-25 09:21:39 +00:00
|
|
|
* forward the video packet.
|
|
|
|
* @param shared_video, directly ptr, copy it if need to save it.
|
|
|
|
*/
|
2015-03-21 03:55:28 +00:00
|
|
|
virtual int on_video(SrsSharedPtrMessage* shared_video);
|
2015-05-23 01:49:15 +00:00
|
|
|
// interface ISrsReusableThread2Handler.
|
2013-12-14 06:06:32 +00:00
|
|
|
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 int forward();
|
2013-11-29 14:21:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
2014-08-02 14:18:39 +00:00
|
|
|
|