From 7bfbe4ec04f6b78ca16164cd13f046644e4a7aad Mon Sep 17 00:00:00 2001 From: Meonardo Date: Thu, 15 Dec 2022 21:17:37 +0800 Subject: [PATCH] Update. --- src/janus_connection.cpp | 20 ++++++++++---------- src/janus_connection.h | 2 +- src/rtc_client.cpp | 10 +++++----- src/rtc_client.h | 5 ++--- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/janus_connection.cpp b/src/janus_connection.cpp index 8a37991..db75b4f 100644 --- a/src/janus_connection.cpp +++ b/src/janus_connection.cpp @@ -50,7 +50,7 @@ void VideoFeederImpl::FeedVideoPacket(OBSVideoPacket *pkt, int width, JanusConnection::JanusConnection(bool send_encoded_data) : ws_client_(nullptr), rtc_client_(nullptr), - video_framer_(nullptr), + video_feeder_(nullptr), room_(0), session_id_(0), handle_id_(0), @@ -187,8 +187,9 @@ void JanusConnection::Unpublish() // destory RTCClient DestoryRTCClient(); // release the `VideoFrameFeeder` - if (video_framer_) { - video_framer_ = nullptr; + if (video_feeder_) { + delete video_feeder_; + video_feeder_ = nullptr; } } @@ -227,13 +228,13 @@ rtc::RTCClient *JanusConnection::GetRTCClient() const void JanusConnection::SendVideoFrame(OBSVideoFrame *frame, int width, int height) { - video_framer_->FeedVideoFrame(frame, width, height); + video_feeder_->FeedVideoFrame(frame, width, height); } void JanusConnection::SendVideoPacket(OBSVideoPacket *pkt, int width, int height) { - video_framer_->FeedVideoPacket(pkt, width, height); + video_feeder_->FeedVideoPacket(pkt, width, height); } void JanusConnection::DestoryRTCClient() @@ -267,8 +268,8 @@ void JanusConnection::CreateHandle() void JanusConnection::CreateOffer() { // create video framer if necessary - if (video_framer_ == nullptr) { - video_framer_ = new VideoFeederImpl(); + if (video_feeder_ == nullptr) { + video_feeder_ = new VideoFeederImpl(); } if (rtc_client_ == nullptr) @@ -276,10 +277,9 @@ void JanusConnection::CreateOffer() // create media sender if (use_encoded_data_) { - rtc_client_->CreateMediaSender(video_framer_); + rtc_client_->CreateMediaSender(video_feeder_, true); } else { - rtc_client_->CreateMediaSender( - std::unique_ptr(video_framer_)); + rtc_client_->CreateMediaSender(video_feeder_); } // create offer diff --git a/src/janus_connection.h b/src/janus_connection.h index 1deed16..d089004 100644 --- a/src/janus_connection.h +++ b/src/janus_connection.h @@ -85,7 +85,7 @@ class JanusConnection : public signaling::WebsocketClientInterface, signaling::WebsocketClient *ws_client_; rtc::RTCClient *rtc_client_; - VideoFeederImpl *video_framer_; + VideoFeederImpl *video_feeder_; // websocket events void Connect(const char *url); diff --git a/src/rtc_client.cpp b/src/rtc_client.cpp index ddfd7c5..e2a39ef 100644 --- a/src/rtc_client.cpp +++ b/src/rtc_client.cpp @@ -246,11 +246,10 @@ bool RTCClient::ToggleMute(bool mute) return audio_track_->set_enabled(!mute); } -void RTCClient::CreateMediaSender( - std::unique_ptr video) +void RTCClient::CreateMediaSender(owt::base::VideoFrameGeneratorInterface* video) { string video_label("obsrtc_video"); - local_video_track_ = pcf_->CreateVideoTrack(std::move(video), video_label); + local_video_track_ = pcf_->CreateVideoTrack(video, video_label); scoped_refptr stream = pcf_->CreateStream("obs-rtc-raw"); if (local_video_track_) @@ -258,7 +257,8 @@ void RTCClient::CreateMediaSender( pc_->AddStream(stream); } -void RTCClient::CreateMediaSender(owt::base::VideoEncoderInterface *encoder) +void RTCClient::CreateMediaSender(owt::base::VideoEncoderInterface *encoder, + bool encoded) { string video_label("obsrtc_video"); local_video_track_ = pcf_->CreateVideoTrack(encoder, video_label); @@ -420,7 +420,7 @@ RTCClient *CreateClient( { if (g_pcf_ == nullptr) { // Default log level is none - UpdateRTCLogLevel(kError); + UpdateRTCLogLevel(kNone); // SetVideoHardwareAccelerationEnabled(true); SetCustomizedVideoEncoderEnabled(true); diff --git a/src/rtc_client.h b/src/rtc_client.h index 6e40f72..7607935 100644 --- a/src/rtc_client.h +++ b/src/rtc_client.h @@ -112,10 +112,9 @@ class RTCClient : public libwebrtc::RTCPeerConnectionObserver { // Media bool ToggleMute(bool mute); // customized raw frame sender - void CreateMediaSender( - std::unique_ptr video); + void CreateMediaSender(owt::base::VideoFrameGeneratorInterface* video); // customized encoded packet sender - void CreateMediaSender(owt::base::VideoEncoderInterface *encoder); + void CreateMediaSender(owt::base::VideoEncoderInterface *encoder, bool encoded); // PC Observer & callback void AddPeerconnectionEventsObserver(RTCClientConnectionObserver *cb);