1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00
srs/trunk/src/app/srs_app_http_hooks.hpp

88 lines
3.8 KiB
C++
Raw Normal View History

//
// Copyright (c) 2013-2021 The SRS Authors
//
// SPDX-License-Identifier: MIT
//
2014-04-01 10:40:24 +00:00
#ifndef SRS_APP_HTTP_HOOKS_HPP
#define SRS_APP_HTTP_HOOKS_HPP
#include <srs_core.hpp>
#include <string>
2014-04-01 10:40:24 +00:00
class SrsHttpUri;
class SrsStSocket;
2014-04-01 10:40:24 +00:00
class SrsRequest;
class SrsHttpParser;
2015-09-17 03:37:35 +00:00
class SrsHttpClient;
2014-04-01 10:40:24 +00:00
2019-04-30 00:24:52 +00:00
// the http hooks, http callback api,
// for some event, such as on_connect, call
// a http api(hooks).
// TODO: Refine to global variable.
2014-04-01 10:40:24 +00:00
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:
2019-04-30 00:24:52 +00:00
// The on_connect hook, when client connect to srs.
// @param url the api server url, to valid the client.
// ignore if empty.
static srs_error_t on_connect(std::string url, SrsRequest* req);
2019-04-30 00:24:52 +00:00
// The 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.
static void on_close(std::string url, SrsRequest* req, int64_t send_bytes, int64_t recv_bytes);
2019-04-30 00:24:52 +00:00
// The on_publish hook, when client(encoder) start to publish stream
// @param url the api server url, to valid the client.
// ignore if empty.
static srs_error_t on_publish(std::string url, SrsRequest* req);
2019-04-30 00:24:52 +00:00
// The on_unpublish hook, when client(encoder) stop publish stream.
// @param url the api server url, to process the event.
// ignore if empty.
static void on_unpublish(std::string url, SrsRequest* req);
2019-04-30 00:24:52 +00:00
// The on_play hook, when client start to play stream.
// @param url the api server url, to valid the client.
// ignore if empty.
static srs_error_t on_play(std::string url, SrsRequest* req);
2019-04-30 00:24:52 +00:00
// The on_stop hook, when client stop to play the stream.
// @param url the api server url, to process the event.
// ignore if empty.
static void on_stop(std::string url, SrsRequest* req);
2019-04-30 00:24:52 +00:00
// The 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.
// @param cid the source connection cid, for the on_dvr is async call.
static srs_error_t on_dvr(SrsContextId cid, std::string url, SrsRequest* req, std::string file);
2019-04-30 00:24:52 +00:00
// When hls reap segment, callback.
// @param url the api server url, to process the event.
// ignore if empty.
// @param file the ts file path, can be relative or absolute path.
// @param ts_url the ts url, which used for m3u8.
// @param m3u8 the m3u8 file path, can be relative or absolute path.
// @param m3u8_url the m3u8 url, which is used for the http mount path.
// @param sn the seq_no, the sequence number of ts in hls/m3u8.
// @param duration the segment duration in srs_utime_t.
// @param cid the source connection cid, for the on_dvr is async call.
static srs_error_t on_hls(SrsContextId cid, std::string url, SrsRequest* req, std::string file, std::string ts_url,
2019-04-14 23:53:29 +00:00
std::string m3u8, std::string m3u8_url, int sn, srs_utime_t duration);
2019-04-30 00:24:52 +00:00
// When hls reap segment, callback.
// @param url the api server url, to process the event.
// ignore if empty.
// @param ts_url the ts uri, used to replace the variable [ts_url] in url.
// @param nb_notify the max bytes to read from notify server.
// @param cid the source connection cid, for the on_dvr is async call.
static srs_error_t on_hls_notify(SrsContextId cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify);
2019-04-30 00:24:52 +00:00
// Discover co-workers for origin cluster.
2018-02-16 08:39:07 +00:00
static srs_error_t discover_co_workers(std::string url, std::string& host, int& port);
2015-03-06 03:51:20 +00:00
private:
static srs_error_t do_post(SrsHttpClient* hc, std::string url, std::string req, int& code, std::string& res);
2014-04-01 10:40:24 +00:00
};
#endif