mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-30 07:26:53 +08:00
确保PSRtpSender对象的线程安全
This commit is contained in:
parent
040c132fb6
commit
9c96f8d31a
@ -30,12 +30,14 @@ PSRtpSender::~PSRtpSender() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PSRtpSender::onPS(uint32_t stamp, void *packet, size_t bytes) {
|
void PSRtpSender::onPS(uint32_t stamp, void *packet, size_t bytes) {
|
||||||
|
//此函数在其他线程执行
|
||||||
_rtp_encoder->inputFrame(std::make_shared<FrameFromPtr>((char *) packet, bytes, stamp));
|
_rtp_encoder->inputFrame(std::make_shared<FrameFromPtr>((char *) packet, bytes, stamp));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PSRtpSender::startSend(const string &dst_url, uint16_t dst_port, bool is_udp, const function<void(const SockException &ex)> &cb){
|
void PSRtpSender::startSend(const string &dst_url, uint16_t dst_port, bool is_udp, const function<void(const SockException &ex)> &cb){
|
||||||
_is_udp = is_udp;
|
_is_udp = is_udp;
|
||||||
_socket = std::make_shared<Socket>();
|
//确保Socket对象的线程安全
|
||||||
|
_socket = std::make_shared<Socket>(_poller, true);
|
||||||
_dst_url = dst_url;
|
_dst_url = dst_url;
|
||||||
_dst_port = dst_port;
|
_dst_port = dst_port;
|
||||||
weak_ptr<PSRtpSender> weak_self = shared_from_this();
|
weak_ptr<PSRtpSender> weak_self = shared_from_this();
|
||||||
@ -89,6 +91,7 @@ void PSRtpSender::onConnect(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PSRtpSender::onRtp(const RtpPacket::Ptr &rtp, bool) {
|
void PSRtpSender::onRtp(const RtpPacket::Ptr &rtp, bool) {
|
||||||
|
//此函数在其他线程执行
|
||||||
if(!_is_connect){
|
if(!_is_connect){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -98,6 +101,7 @@ void PSRtpSender::onRtp(const RtpPacket::Ptr &rtp, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PSRtpSender::onFlush(shared_ptr<List<RtpPacket::Ptr>> &rtp_list, bool key_pos) {
|
void PSRtpSender::onFlush(shared_ptr<List<RtpPacket::Ptr>> &rtp_list, bool key_pos) {
|
||||||
|
//此函数在其他线程执行
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int size = rtp_list->size();
|
int size = rtp_list->size();
|
||||||
rtp_list->for_each([&](const RtpPacket::Ptr &packet) {
|
rtp_list->for_each([&](const RtpPacket::Ptr &packet) {
|
||||||
|
Loading…
Reference in New Issue
Block a user