ZLMediaKit/src/Rtp/RtpServer.h

86 lines
2.5 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
*
* 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"
#include "Network/UdpServer.h"
#include "RtpSession.h"
2022-11-01 17:27:27 +08:00
namespace mediakit {
class RtcpHelper;
/**
* RTP服务器UDP/TCP
*/
class RtpServer : public std::enable_shared_from_this<RtpServer> {
public:
using Ptr = std::shared_ptr<RtpServer>;
using onRecv = std::function<void(const toolkit::Buffer::Ptr &buf)>;
enum TcpMode { NONE = 0, PASSIVE, ACTIVE };
2022-11-12 21:59:48 +08:00
RtpServer() = default;
~RtpServer();
/**
*
* @param local_port 0
* @param stream_id id使ssrc
* @param tcp_mode tcp服务模式
* @param local_ip ip
* @param re_use_port socket为re_use属性
* @param ssrc ssrc
*/
void start(uint16_t local_port, const std::string &stream_id = "", TcpMode tcp_mode = PASSIVE,
const char *local_ip = "::", bool re_use_port = true, uint32_t ssrc = 0, bool only_audio = false);
/**
* tcp服务(tcp主动模式)
* @param url
* @param port
* @param cb
*/
void connectToServer(const std::string &url, uint16_t port, const std::function<void(const toolkit::SockException &ex)> &cb);
/**
*
*/
uint16_t getPort();
/**
* RtpProcess onDetach事件回调
*/
2022-11-01 17:27:27 +08:00
void setOnDetach(std::function<void()> cb);
2020-12-27 21:21:31 +08:00
private:
// tcp主动模式连接服务器成功回调
void onConnect();
protected:
toolkit::Socket::Ptr _rtp_socket;
toolkit::UdpServer::Ptr _udp_server;
toolkit::TcpServer::Ptr _tcp_server;
2022-11-01 17:27:27 +08:00
std::shared_ptr<RtcpHelper> _rtcp_helper;
std::function<void()> _on_cleanup;
bool _only_audio = false;
//用于tcp主动模式
TcpMode _tcp_mode = NONE;
};
}//namespace mediakit
#endif//defined(ENABLE_RTPPROXY)
#endif //ZLMEDIAKIT_RTPSERVER_H