2014-04-01 10:40:24 +00:00
|
|
|
/*
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
2014-12-31 12:32:09 +00:00
|
|
|
Copyright (c) 2013-2015 winlin
|
2014-04-01 10:40:24 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SRS_APP_HTTP_HOOKS_HPP
|
|
|
|
#define SRS_APP_HTTP_HOOKS_HPP
|
|
|
|
|
|
|
|
/*
|
|
|
|
#include <srs_app_http_hooks.hpp>
|
|
|
|
*/
|
|
|
|
#include <srs_core.hpp>
|
|
|
|
|
2014-06-08 05:03:03 +00:00
|
|
|
#include <string>
|
|
|
|
|
2014-04-15 06:01:57 +00:00
|
|
|
#ifdef SRS_AUTO_HTTP_CALLBACK
|
2014-04-01 10:40:24 +00:00
|
|
|
|
|
|
|
#include <http_parser.h>
|
|
|
|
|
|
|
|
class SrsHttpUri;
|
2014-07-26 12:08:37 +00:00
|
|
|
class SrsStSocket;
|
2014-04-01 10:40:24 +00:00
|
|
|
class SrsRequest;
|
2014-04-02 04:03:49 +00:00
|
|
|
class SrsHttpParser;
|
2014-04-23 09:53:14 +00:00
|
|
|
class SrsFlvSegment;
|
2014-04-01 10:40:24 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* the http hooks, http callback api,
|
|
|
|
* for some event, such as on_connect, call
|
|
|
|
* a http api(hooks).
|
|
|
|
*/
|
|
|
|
class SrsHttpHooks
|
|
|
|
{
|
2014-04-22 09:32:45 +00:00
|
|
|
private:
|
2014-04-01 10:40:24 +00:00
|
|
|
SrsHttpHooks();
|
2014-04-22 09:32:45 +00:00
|
|
|
public:
|
2014-04-01 10:40:24 +00:00
|
|
|
virtual ~SrsHttpHooks();
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* on_connect hook, when client connect to srs.
|
|
|
|
* @param url the api server url, to valid the client.
|
|
|
|
* ignore if empty.
|
|
|
|
*/
|
2015-03-31 09:52:49 +00:00
|
|
|
static int on_connect(std::string url, SrsRequest* req);
|
2014-04-01 10:40:24 +00:00
|
|
|
/**
|
|
|
|
* on_close hook, when client disconnect to srs, where client is valid by on_connect.
|
|
|
|
* @param url the api server url, to process the event.
|
|
|
|
* ignore if empty.
|
|
|
|
*/
|
2015-03-31 09:52:49 +00:00
|
|
|
static void on_close(std::string url, SrsRequest* req, int64_t send_bytes, int64_t recv_bytes);
|
2014-04-01 10:40:24 +00:00
|
|
|
/**
|
|
|
|
* on_publish hook, when client(encoder) start to publish stream
|
|
|
|
* @param url the api server url, to valid the client.
|
|
|
|
* ignore if empty.
|
|
|
|
*/
|
2015-03-31 09:52:49 +00:00
|
|
|
static int on_publish(std::string url, SrsRequest* req);
|
2014-04-01 10:40:24 +00:00
|
|
|
/**
|
|
|
|
* on_unpublish hook, when client(encoder) stop publish stream.
|
|
|
|
* @param url the api server url, to process the event.
|
|
|
|
* ignore if empty.
|
|
|
|
*/
|
2015-03-31 09:52:49 +00:00
|
|
|
static void on_unpublish(std::string url, SrsRequest* req);
|
2014-04-01 10:40:24 +00:00
|
|
|
/**
|
|
|
|
* on_play hook, when client start to play stream.
|
|
|
|
* @param url the api server url, to valid the client.
|
|
|
|
* ignore if empty.
|
|
|
|
*/
|
2015-03-31 09:52:49 +00:00
|
|
|
static int on_play(std::string url, SrsRequest* req);
|
2014-04-01 10:40:24 +00:00
|
|
|
/**
|
|
|
|
* on_stop hook, when client stop to play the stream.
|
|
|
|
* @param url the api server url, to process the event.
|
|
|
|
* ignore if empty.
|
|
|
|
*/
|
2015-03-31 09:52:49 +00:00
|
|
|
static void on_stop(std::string url, SrsRequest* req);
|
2015-01-03 07:33:23 +00:00
|
|
|
/**
|
|
|
|
* on_dvr hook, when reap a dvr file.
|
|
|
|
* @param url the api server url, to process the event.
|
|
|
|
* ignore if empty.
|
|
|
|
* @param file the file path, can be relative or absolute path.
|
|
|
|
*/
|
2015-03-31 09:52:49 +00:00
|
|
|
static int on_dvr(std::string url, SrsRequest* req, std::string file);
|
2015-02-22 02:45:13 +00:00
|
|
|
/**
|
2015-03-31 09:42:12 +00:00
|
|
|
* when hls reap segment, callback.
|
2015-02-22 02:45:13 +00:00
|
|
|
* @param url the api server url, to process the event.
|
|
|
|
* ignore if empty.
|
2015-03-31 09:42:12 +00:00
|
|
|
* @param file the ts file path, can be relative or absolute path.
|
|
|
|
* @param sn the seq_no, the sequence number of ts in hls/m3u8.
|
2015-04-03 05:46:44 +00:00
|
|
|
* @param duration the segment duration in seconds.
|
2015-02-22 02:45:13 +00:00
|
|
|
*/
|
2015-04-03 05:46:44 +00:00
|
|
|
static int on_hls(std::string url, SrsRequest* req, std::string file, int sn, double duration);
|
2015-03-06 03:51:20 +00:00
|
|
|
private:
|
|
|
|
static int do_post(std::string url, std::string req, int& code, std::string& res);
|
2014-04-01 10:40:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2014-06-08 05:03:03 +00:00
|
|
|
#endif
|
2014-08-02 14:18:39 +00:00
|
|
|
|