ZLMediaKit/src/Rtp/RtpSender.h

87 lines
2.5 KiB
C++
Raw Normal View History

2020-09-06 18:09:31 +08:00
/*
2020-09-06 17:56:05 +08:00
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
*
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
2020-09-06 17:56:05 +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.
*/
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"
namespace mediakit{
2020-10-24 23:33:13 +08:00
//rtp发送客户端支持发送GB28181协议
class RtpSender : public MediaSinkInterface, public std::enable_shared_from_this<RtpSender>{
2020-09-06 17:56:05 +08:00
public:
2020-10-24 23:33:13 +08:00
typedef std::shared_ptr<RtpSender> Ptr;
2020-09-06 17:56:05 +08:00
2020-10-24 23:33:13 +08:00
~RtpSender() override;
2020-09-06 17:56:05 +08:00
/**
2020-10-24 23:33:13 +08:00
* GB28181 RTP发送客户端
2020-09-06 17:56:05 +08:00
* @param ssrc rtp的ssrc
* @param payload_type ps-rtp的pt一般为96
*/
2020-10-24 23:33:13 +08:00
RtpSender(uint32_t ssrc, uint8_t payload_type = 96);
2020-09-06 17:56:05 +08:00
/**
* ps-rtp包
* @param dst_url ip或域名
* @param dst_port
* @param is_udp udp方式发送rtp
* @param cb
*/
void startSend(const std::string &dst_url, uint16_t dst_port, bool is_udp, uint16_t src_port, const std::function<void(uint16_t local_port, const toolkit::SockException &ex)> &cb);
2020-09-06 17:56:05 +08:00
/**
*
*/
bool inputFrame(const Frame::Ptr &frame) override;
2020-10-24 23:33:13 +08:00
/**
* trackTrack的clone方法
* sps pps这些信息 Delegate相关关系
* @param track
*/
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
private:
2020-10-24 23:33:13 +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事件
void onErr(const toolkit::SockException &ex, bool is_connect = false);
2020-09-06 17:56:05 +08:00
private:
bool _is_udp;
bool _is_connect = false;
std::string _dst_url;
2020-09-06 17:56:05 +08:00
uint16_t _dst_port;
uint16_t _src_port;
toolkit::Socket::Ptr _socket;
toolkit::EventPoller::Ptr _poller;
toolkit::Timer::Ptr _connect_timer;
2020-10-24 23:33:13 +08:00
MediaSinkInterface::Ptr _interface;
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