Blame view

trunk/src/app/srs_app_rtmp_conn.hpp 4.4 KB
winlin authored
1 2 3
/*
The MIT License (MIT)
4
Copyright (c) 2013-2015 SRS(simple-rtmp-server)
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_RTMP_CONN_HPP
#define SRS_APP_RTMP_CONN_HPP
winlin authored
26 27

/*
28
#include <srs_app_rtmp_conn.hpp>
winlin authored
29 30 31 32
*/

#include <srs_core.hpp>
33 34 35
#include <srs_app_st.hpp>
#include <srs_app_conn.hpp>
#include <srs_app_reload.hpp>
winlin authored
36
37
class SrsServer;
38
class SrsRtmpServer;
winlin authored
39 40 41 42 43
class SrsRequest;
class SrsResponse;
class SrsSource;
class SrsRefer;
class SrsConsumer;
44
class SrsCommonMessage;
45
class SrsStSocket;
46
#ifdef SRS_AUTO_HTTP_CALLBACK    
winlin authored
47 48
class SrsHttpHooks;
#endif
49
class SrsBandwidth;
50
class SrsKbps;
51
class SrsRtmpClient;
52
class SrsSharedPtrMessage;
53
class SrsQueueRecvThread;
54
class SrsPublishRecvThread;
55
class SrsSecurity;
winlin authored
56 57 58 59

/**
* the client provides the main logic control for RTMP clients.
*/
60
class SrsRtmpConn : public virtual SrsConnection, public virtual ISrsReloadHandler
winlin authored
61
{
62 63
    // for the thread to directly access any field of connection.
    friend class SrsPublishRecvThread;
winlin authored
64
private:
65
    SrsServer* server;
66 67
    SrsRequest* req;
    SrsResponse* res;
68
    SrsStSocket* skt;
69 70 71
    SrsRtmpServer* rtmp;
    SrsRefer* refer;
    SrsBandwidth* bandwidth;
72
    SrsSecurity* security;
73 74
    // elapse duration in ms
    // for live play duration, for instance, rtmpdump to record.
75
    // @see https://github.com/simple-rtmp-server/srs/issues/47
76
    int64_t duration;
77
    SrsKbps* kbps;
78 79
    // the MR(merged-write) sleep time in ms.
    int mw_sleep;
80 81
    // the MR(merged-write) only enabled for play.
    int mw_enabled;
82
    // for realtime
83
    // @see https://github.com/simple-rtmp-server/srs/issues/257
84
    bool realtime;
winlin authored
85
public:
86
    SrsRtmpConn(SrsServer* svr, st_netfd_t c);
87
    virtual ~SrsRtmpConn();
winlin authored
88
protected:
89
    virtual int do_cycle();
90 91
// interface ISrsReloadHandler
public:
92
    virtual int on_reload_vhost_removed(std::string vhost);
93
    virtual int on_reload_vhost_mw(std::string vhost);
94
    virtual int on_reload_vhost_realtime(std::string vhost);
95 96
// interface IKbpsDelta
public:
97
    virtual void resample();
98 99
    virtual int64_t get_send_bytes_delta();
    virtual int64_t get_recv_bytes_delta();
100
    virtual void cleanup();
winlin authored
101
private:
102 103 104 105 106 107
    // when valid and connected to vhost/app, service the client.
    virtual int service_cycle();
    // stream(play/publish) service cycle, identify client first.
    virtual int stream_service_cycle();
    virtual int check_vhost();
    virtual int playing(SrsSource* source);
108
    virtual int do_playing(SrsSource* source, SrsConsumer* consumer, SrsQueueRecvThread* trd);
109 110
    virtual int fmle_publishing(SrsSource* source);
    virtual int flash_publishing(SrsSource* source);
111
    virtual int do_publishing(SrsSource* source, SrsPublishRecvThread* trd);
112 113 114
    virtual int handle_publish_message(SrsSource* source, SrsCommonMessage* msg, bool is_fmle, bool vhost_is_edge);
    virtual int process_publish_message(SrsSource* source, SrsCommonMessage* msg, bool vhost_is_edge);
    virtual int process_play_control_msg(SrsConsumer* consumer, SrsCommonMessage* msg);
115
    virtual void change_mw_sleep(int sleep_ms);
116
    virtual void play_set_sock_options();
117
private:
118 119
    virtual int check_edge_token_traverse_auth();
    virtual int connect_server(int origin_index, st_netfd_t* pstsock);
120
    virtual int do_token_traverse_auth(SrsRtmpClient* client);
121
private:
122 123 124 125 126 127
    virtual int http_hooks_on_connect();
    virtual void http_hooks_on_close();
    virtual int http_hooks_on_publish();
    virtual void http_hooks_on_unpublish();
    virtual int http_hooks_on_play();
    virtual void http_hooks_on_stop();
winlin authored
128 129
};
130
#endif
131