2014-04-25 08:35:03 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
|
|
|
Copyright (c) 2013-2014 winlin
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SRS_APP_EDGE_HPP
|
|
|
|
#define SRS_APP_EDGE_HPP
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <srs_app_edge.hpp>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
2014-04-26 13:41:18 +00:00
|
|
|
#include <srs_app_st.hpp>
|
2014-04-26 10:08:21 +00:00
|
|
|
#include <srs_app_thread.hpp>
|
|
|
|
|
2014-04-26 13:41:18 +00:00
|
|
|
class SrsSource;
|
2014-04-26 09:16:18 +00:00
|
|
|
class SrsRequest;
|
2014-04-27 01:29:37 +00:00
|
|
|
class SrsPlayEdge;
|
|
|
|
class SrsPublishEdge;
|
2014-04-26 13:41:18 +00:00
|
|
|
class SrsRtmpClient;
|
|
|
|
class SrsCommonMessage;
|
|
|
|
class ISrsProtocolReaderWriter;
|
2014-04-26 09:16:18 +00:00
|
|
|
|
2014-04-26 06:47:38 +00:00
|
|
|
/**
|
2014-04-26 14:51:01 +00:00
|
|
|
* the state of edge, auto machine
|
2014-04-26 06:47:38 +00:00
|
|
|
*/
|
|
|
|
enum SrsEdgeState
|
|
|
|
{
|
|
|
|
SrsEdgeStateInit = 0,
|
2014-04-27 01:29:37 +00:00
|
|
|
|
|
|
|
// for play edge
|
2014-04-26 06:47:38 +00:00
|
|
|
SrsEdgeStatePlay = 100,
|
2014-04-26 13:41:18 +00:00
|
|
|
// play stream from origin, ingest stream
|
|
|
|
SrsEdgeStateIngestConnected,
|
2014-04-27 01:29:37 +00:00
|
|
|
|
|
|
|
// for publish edge
|
|
|
|
SrsEdgeStatePublish = 200,
|
2014-04-26 13:41:18 +00:00
|
|
|
// publish stream to edge, forward to origin
|
|
|
|
SrsEdgeStateForwardConnected,
|
2014-04-26 14:51:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the state of edge from user, manual machine
|
|
|
|
*/
|
|
|
|
enum SrsEdgeUserState
|
|
|
|
{
|
|
|
|
SrsEdgeUserStateInit = 0,
|
|
|
|
SrsEdgeUserStateReloading = 100,
|
2014-04-26 06:47:38 +00:00
|
|
|
};
|
|
|
|
|
2014-04-26 10:08:21 +00:00
|
|
|
/**
|
|
|
|
* edge used to ingest stream from origin.
|
|
|
|
*/
|
|
|
|
class SrsEdgeIngester : public ISrsThreadHandler
|
|
|
|
{
|
|
|
|
private:
|
2014-04-26 13:41:18 +00:00
|
|
|
int stream_id;
|
|
|
|
private:
|
|
|
|
SrsSource* _source;
|
2014-04-27 01:29:37 +00:00
|
|
|
SrsPlayEdge* _edge;
|
2014-04-26 10:08:21 +00:00
|
|
|
SrsRequest* _req;
|
|
|
|
SrsThread* pthread;
|
2014-04-26 13:41:18 +00:00
|
|
|
st_netfd_t stfd;
|
|
|
|
ISrsProtocolReaderWriter* io;
|
|
|
|
SrsRtmpClient* client;
|
|
|
|
int origin_index;
|
2014-04-26 10:08:21 +00:00
|
|
|
public:
|
|
|
|
SrsEdgeIngester();
|
|
|
|
virtual ~SrsEdgeIngester();
|
|
|
|
public:
|
2014-04-27 01:29:37 +00:00
|
|
|
virtual int initialize(SrsSource* source, SrsPlayEdge* edge, SrsRequest* req);
|
2014-04-26 10:08:21 +00:00
|
|
|
virtual int start();
|
2014-04-26 13:41:18 +00:00
|
|
|
virtual void stop();
|
2014-04-26 10:08:21 +00:00
|
|
|
// interface ISrsThreadHandler
|
|
|
|
public:
|
|
|
|
virtual int cycle();
|
2014-04-26 13:41:18 +00:00
|
|
|
private:
|
|
|
|
virtual int ingest();
|
|
|
|
virtual void close_underlayer_socket();
|
|
|
|
virtual int connect_server();
|
|
|
|
virtual int process_publish_message(SrsCommonMessage* msg);
|
2014-04-26 10:08:21 +00:00
|
|
|
};
|
|
|
|
|
2014-04-26 06:47:38 +00:00
|
|
|
/**
|
2014-04-27 01:29:37 +00:00
|
|
|
* edge used to forward stream to origin.
|
|
|
|
*/
|
|
|
|
class SrsEdgeForwarder : public ISrsThreadHandler
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
int stream_id;
|
|
|
|
private:
|
|
|
|
SrsSource* _source;
|
|
|
|
SrsPublishEdge* _edge;
|
|
|
|
SrsRequest* _req;
|
|
|
|
SrsThread* pthread;
|
|
|
|
st_netfd_t stfd;
|
|
|
|
ISrsProtocolReaderWriter* io;
|
|
|
|
SrsRtmpClient* client;
|
|
|
|
int origin_index;
|
|
|
|
public:
|
|
|
|
SrsEdgeForwarder();
|
|
|
|
virtual ~SrsEdgeForwarder();
|
|
|
|
public:
|
|
|
|
virtual int initialize(SrsSource* source, SrsPublishEdge* edge, SrsRequest* req);
|
|
|
|
virtual int start();
|
|
|
|
virtual void stop();
|
|
|
|
// interface ISrsThreadHandler
|
|
|
|
public:
|
|
|
|
virtual int cycle();
|
|
|
|
private:
|
|
|
|
virtual int forward();
|
|
|
|
virtual void close_underlayer_socket();
|
|
|
|
virtual int connect_server();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* play edge control service.
|
|
|
|
* downloading edge speed-up.
|
2014-04-26 06:47:38 +00:00
|
|
|
*/
|
2014-04-27 01:29:37 +00:00
|
|
|
class SrsPlayEdge
|
2014-04-26 06:47:38 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
SrsEdgeState state;
|
2014-04-26 14:51:01 +00:00
|
|
|
SrsEdgeUserState user_state;
|
2014-04-26 10:08:21 +00:00
|
|
|
SrsEdgeIngester* ingester;
|
2014-04-26 06:47:38 +00:00
|
|
|
public:
|
2014-04-27 01:29:37 +00:00
|
|
|
SrsPlayEdge();
|
|
|
|
virtual ~SrsPlayEdge();
|
2014-04-26 06:47:38 +00:00
|
|
|
public:
|
2014-04-26 13:41:18 +00:00
|
|
|
virtual int initialize(SrsSource* source, SrsRequest* req);
|
2014-04-26 06:47:38 +00:00
|
|
|
/**
|
|
|
|
* when client play stream on edge.
|
|
|
|
*/
|
|
|
|
virtual int on_client_play();
|
2014-04-26 13:41:18 +00:00
|
|
|
/**
|
|
|
|
* when all client stopped play, disconnect to origin.
|
|
|
|
*/
|
|
|
|
virtual void on_all_client_stop();
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* when ingester start to play stream.
|
|
|
|
*/
|
|
|
|
virtual int on_ingest_play();
|
2014-04-26 06:47:38 +00:00
|
|
|
};
|
|
|
|
|
2014-04-27 01:29:37 +00:00
|
|
|
/**
|
|
|
|
* publish edge control service.
|
|
|
|
* uploading edge speed-up.
|
|
|
|
*/
|
|
|
|
class SrsPublishEdge
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
SrsEdgeState state;
|
|
|
|
SrsEdgeUserState user_state;
|
|
|
|
SrsEdgeForwarder* forwarder;
|
|
|
|
public:
|
|
|
|
SrsPublishEdge();
|
|
|
|
virtual ~SrsPublishEdge();
|
|
|
|
public:
|
|
|
|
virtual int initialize(SrsSource* source, SrsRequest* req);
|
|
|
|
/**
|
|
|
|
* when client publish stream on edge.
|
|
|
|
*/
|
|
|
|
virtual int on_client_publish();
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* when forwarder start to publish stream.
|
|
|
|
*/
|
|
|
|
virtual int on_forward_publish();
|
|
|
|
};
|
|
|
|
|
2014-04-26 06:47:38 +00:00
|
|
|
#endif
|