Blame view

trunk/src/app/srs_app_forward.hpp 3.0 KB
winlin authored
1 2 3
/*
The MIT License (MIT)
4
Copyright (c) 2013-2014 winlin
winlin authored
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

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.
*/
24 25
#ifndef SRS_APP_FORWARD_HPP
#define SRS_APP_FORWARD_HPP
winlin authored
26 27

/*
28
#include <srs_app_forward.hpp>
winlin authored
29 30 31 32 33
*/
#include <srs_core.hpp>

#include <string>
34 35
#include <srs_app_st.hpp>
#include <srs_app_thread.hpp>
winlin authored
36
37
class ISrsProtocolReaderWriter;
38
class SrsSharedPtrMessage;
winlin authored
39
class SrsOnMetaDataPacket;
winlin authored
40
class SrsMessageQueue;
41
class SrsRtmpJitter;
winlin authored
42
class SrsRtmpClient;
43
class SrsRequest;
44
class SrsSource;
45
class SrsKbps;
winlin authored
46 47 48 49

/**
* forward the stream to other servers.
*/
winlin authored
50
// TODO: FIXME: refine the error log, comments it.
51
class SrsForwarder : public ISrsThreadHandler
winlin authored
52 53
{
private:
54 55 56
    // the ep to forward, server[:port].
    std::string _ep_forward;
    SrsRequest* _req;
57
    int stream_id;
winlin authored
58
private:
59 60
    st_netfd_t stfd;
    SrsThread* pthread;
winlin authored
61
private:
62 63
    SrsSource* source;
    ISrsProtocolReaderWriter* io;
64
    SrsKbps* kbps;
65 66 67
    SrsRtmpClient* client;
    SrsRtmpJitter* jitter;
    SrsMessageQueue* queue;
68 69 70 71 72 73
    /**
    * cache the sequence header for retry when slave is failed.
    * @see https://github.com/winlinvip/simple-rtmp-server/issues/150
    */
    SrsSharedPtrMessage* sh_audio;
    SrsSharedPtrMessage* sh_video;
winlin authored
74
public:
75 76
    SrsForwarder(SrsSource* _source);
    virtual ~SrsForwarder();
winlin authored
77
public:
78
    virtual int initialize(SrsRequest* req, std::string ep_forward);
79
    virtual void set_queue_size(double queue_size);
winlin authored
80
public:
81
    virtual int on_publish();
82
    virtual void on_unpublish();
83 84 85
    virtual int on_meta_data(SrsSharedPtrMessage* metadata);
    virtual int on_audio(SrsSharedPtrMessage* msg);
    virtual int on_video(SrsSharedPtrMessage* msg);
86 87
// interface ISrsThreadHandler.
public:
88
    virtual int cycle();
winlin authored
89
private:
90
    virtual void close_underlayer_socket();
91 92 93
    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);
94
    virtual int forward();
winlin authored
95 96 97
};

#endif
98