2020-07-02 22:23:43 +08:00
|
|
|
|
/*
|
|
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
|
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2020-07-02 22:23:43 +08:00
|
|
|
|
*
|
|
|
|
|
|
* Use of this source code is governed by MIT license that can be found in the
|
|
|
|
|
|
* LICENSE file in the root of the source tree. All contributing project authors
|
|
|
|
|
|
* may be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef ZLMEDIAKIT_RTPSERVER_H
|
|
|
|
|
|
#define ZLMEDIAKIT_RTPSERVER_H
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(ENABLE_RTPPROXY)
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
#include "Network/Socket.h"
|
|
|
|
|
|
#include "Network/TcpServer.h"
|
2021-06-08 14:03:25 +08:00
|
|
|
|
#include "Network/UdpServer.h"
|
2020-07-02 22:23:43 +08:00
|
|
|
|
#include "RtpSession.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace mediakit{
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* RTP服务器,支持UDP/TCP
|
|
|
|
|
|
*/
|
|
|
|
|
|
class RtpServer {
|
|
|
|
|
|
public:
|
2022-02-02 20:34:50 +08:00
|
|
|
|
using Ptr = std::shared_ptr<RtpServer>;
|
|
|
|
|
|
using onRecv = std::function<void(const toolkit::Buffer::Ptr &buf)>;
|
2020-07-02 22:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
RtpServer();
|
|
|
|
|
|
~RtpServer();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 开启服务器,可能抛异常
|
|
|
|
|
|
* @param local_port 本地端口,0时为随机端口
|
2020-07-07 10:01:12 +08:00
|
|
|
|
* @param stream_id 流id,置空则使用ssrc
|
2020-07-02 22:23:43 +08:00
|
|
|
|
* @param enable_tcp 是否启用tcp服务器
|
|
|
|
|
|
* @param local_ip 绑定的本地网卡ip
|
2022-04-09 10:26:15 +08:00
|
|
|
|
* @param re_use_port 是否设置socket为re_use属性
|
2020-07-02 22:23:43 +08:00
|
|
|
|
*/
|
2022-04-28 17:44:35 +08:00
|
|
|
|
void start(uint16_t local_port, const std::string &stream_id = "", bool enable_tcp = true,
|
|
|
|
|
|
const char *local_ip = "0.0.0.0", bool re_use_port = true, uint32_t ssrc = 0);
|
2020-07-02 22:23:43 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取绑定的本地端口
|
|
|
|
|
|
*/
|
|
|
|
|
|
uint16_t getPort();
|
|
|
|
|
|
|
2020-07-08 10:25:30 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 设置RtpProcess onDetach事件回调
|
|
|
|
|
|
*/
|
2022-02-02 20:34:50 +08:00
|
|
|
|
void setOnDetach(const std::function<void()> &cb);
|
2020-12-27 21:21:31 +08:00
|
|
|
|
|
2020-07-02 22:23:43 +08:00
|
|
|
|
protected:
|
2022-02-02 20:34:50 +08:00
|
|
|
|
toolkit::Socket::Ptr _rtp_socket;
|
|
|
|
|
|
toolkit::UdpServer::Ptr _udp_server;
|
|
|
|
|
|
toolkit::TcpServer::Ptr _tcp_server;
|
2020-07-08 10:25:30 +08:00
|
|
|
|
RtpProcess::Ptr _rtp_process;
|
2022-02-02 20:34:50 +08:00
|
|
|
|
std::function<void()> _on_clearup;
|
2020-07-02 22:23:43 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}//namespace mediakit
|
|
|
|
|
|
#endif//defined(ENABLE_RTPPROXY)
|
|
|
|
|
|
#endif //ZLMEDIAKIT_RTPSERVER_H
|