2020-09-06 18:09:31 +08:00
|
|
|
|
/*
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
|
2020-09-06 17:56:05 +08:00
|
|
|
|
*
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
|
2020-09-06 17:56:05 +08:00
|
|
|
|
*
|
2023-12-09 16:23:51 +08:00
|
|
|
|
* Use of this source code is governed by MIT-like license that can be found in the
|
2020-09-06 17:56:05 +08:00
|
|
|
|
* 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.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2020-10-24 23:33:13 +08:00
|
|
|
|
#ifndef ZLMEDIAKIT_RTPSENDER_H
|
|
|
|
|
|
#define ZLMEDIAKIT_RTPSENDER_H
|
2020-09-06 17:56:05 +08:00
|
|
|
|
#if defined(ENABLE_RTPPROXY)
|
|
|
|
|
|
#include "PSEncoder.h"
|
|
|
|
|
|
#include "Extension/CommonRtp.h"
|
2022-08-20 12:48:27 +08:00
|
|
|
|
#include "Rtcp/RtcpContext.h"
|
2022-11-29 11:07:13 +08:00
|
|
|
|
#include "Common/MediaSource.h"
|
|
|
|
|
|
#include "Common/MediaSink.h"
|
2020-09-06 17:56:05 +08:00
|
|
|
|
|
|
|
|
|
|
namespace mediakit{
|
|
|
|
|
|
|
2023-01-07 22:36:30 +08:00
|
|
|
|
class RtpSession;
|
|
|
|
|
|
|
2020-10-24 23:33:13 +08:00
|
|
|
|
//rtp发送客户端,支持发送GB28181协议
|
2022-10-16 19:49:56 +08:00
|
|
|
|
class RtpSender final : public MediaSinkInterface, public std::enable_shared_from_this<RtpSender>{
|
2020-09-06 17:56:05 +08:00
|
|
|
|
public:
|
2022-12-02 14:43:06 +08:00
|
|
|
|
using Ptr = std::shared_ptr<RtpSender>;
|
2020-09-06 17:56:05 +08:00
|
|
|
|
|
2022-08-27 10:17:06 +08:00
|
|
|
|
RtpSender(toolkit::EventPoller::Ptr poller = nullptr);
|
2022-10-16 19:49:56 +08:00
|
|
|
|
~RtpSender() override;
|
2020-09-06 17:56:05 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 开始发送ps-rtp包
|
2022-04-03 18:25:36 +08:00
|
|
|
|
* @param args 发送参数
|
2020-09-06 17:56:05 +08:00
|
|
|
|
* @param cb 连接目标端口是否成功的回调
|
|
|
|
|
|
*/
|
2022-04-03 18:25:36 +08:00
|
|
|
|
void startSend(const MediaSourceEvent::SendRtpArgs &args, const std::function<void(uint16_t local_port, const toolkit::SockException &ex)> &cb);
|
2020-09-06 17:56:05 +08:00
|
|
|
|
|
2020-09-12 18:53:51 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 输入帧数据
|
|
|
|
|
|
*/
|
2021-09-27 13:12:53 +08:00
|
|
|
|
bool inputFrame(const Frame::Ptr &frame) override;
|
2020-09-12 18:53:51 +08:00
|
|
|
|
|
2022-10-16 19:49:56 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 刷新输出frame缓存
|
|
|
|
|
|
*/
|
|
|
|
|
|
void flush() override;
|
|
|
|
|
|
|
2020-10-24 23:33:13 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 添加track,内部会调用Track的clone方法
|
|
|
|
|
|
* 只会克隆sps pps这些信息 ,而不会克隆Delegate相关关系
|
|
|
|
|
|
* @param track
|
|
|
|
|
|
*/
|
2021-09-27 13:12:53 +08:00
|
|
|
|
virtual bool addTrack(const Track::Ptr & track) override;
|
2020-10-24 23:33:13 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 添加所有Track完毕
|
|
|
|
|
|
*/
|
|
|
|
|
|
virtual void addTrackCompleted() override;
|
2020-09-06 17:56:05 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2020-10-24 23:33:13 +08:00
|
|
|
|
* 重置track
|
2020-09-06 17:56:05 +08:00
|
|
|
|
*/
|
2020-10-24 23:33:13 +08:00
|
|
|
|
virtual void resetTracks() override;
|
2020-09-06 17:56:05 +08:00
|
|
|
|
|
2022-08-27 10:53:47 +08:00
|
|
|
|
void setOnClose(std::function<void(const toolkit::SockException &ex)> on_close);
|
2022-08-20 12:48:27 +08:00
|
|
|
|
|
2020-09-06 17:56:05 +08:00
|
|
|
|
private:
|
2020-10-24 23:33:13 +08:00
|
|
|
|
//合并写输出
|
2022-02-02 20:34:50 +08:00
|
|
|
|
void onFlushRtpList(std::shared_ptr<toolkit::List<toolkit::Buffer::Ptr> > rtp_list);
|
2020-09-06 17:56:05 +08:00
|
|
|
|
//udp/tcp连接成功回调
|
|
|
|
|
|
void onConnect();
|
|
|
|
|
|
//异常断开socket事件
|
2022-08-27 10:59:15 +08:00
|
|
|
|
void onErr(const toolkit::SockException &ex);
|
2022-08-20 12:48:27 +08:00
|
|
|
|
void createRtcpSocket();
|
|
|
|
|
|
void onRecvRtcp(RtcpHeader *rtcp);
|
|
|
|
|
|
void onSendRtpUdp(const toolkit::Buffer::Ptr &buf, bool check);
|
2022-08-27 10:53:47 +08:00
|
|
|
|
void onClose(const toolkit::SockException &ex);
|
2020-09-06 17:56:05 +08:00
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
bool _is_connect = false;
|
2022-04-03 18:25:36 +08:00
|
|
|
|
MediaSourceEvent::SendRtpArgs _args;
|
2022-08-20 12:48:27 +08:00
|
|
|
|
toolkit::Socket::Ptr _socket_rtp;
|
|
|
|
|
|
toolkit::Socket::Ptr _socket_rtcp;
|
2022-02-02 20:34:50 +08:00
|
|
|
|
toolkit::EventPoller::Ptr _poller;
|
2020-10-24 23:33:13 +08:00
|
|
|
|
MediaSinkInterface::Ptr _interface;
|
2022-08-20 12:48:27 +08:00
|
|
|
|
std::shared_ptr<RtcpContext> _rtcp_context;
|
|
|
|
|
|
toolkit::Ticker _rtcp_send_ticker;
|
|
|
|
|
|
toolkit::Ticker _rtcp_recv_ticker;
|
2023-01-07 22:36:30 +08:00
|
|
|
|
std::shared_ptr<RtpSession> _rtp_session;
|
2022-08-27 10:53:47 +08:00
|
|
|
|
std::function<void(const toolkit::SockException &ex)> _on_close;
|
2020-09-06 17:56:05 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}//namespace mediakit
|
|
|
|
|
|
#endif// defined(ENABLE_RTPPROXY)
|
2020-10-24 23:33:13 +08:00
|
|
|
|
#endif //ZLMEDIAKIT_RTPSENDER_H
|