diff --git a/src/media/video/video_rtp_session.cpp b/src/media/video/video_rtp_session.cpp index 6e7564e55b999889dff7dab4779945674090146f..f0aa2ddcd596c4b65131b93e15eaa2f2b043e865 100644 --- a/src/media/video/video_rtp_session.cpp +++ b/src/media/video/video_rtp_session.cpp @@ -214,8 +214,8 @@ VideoRtpSession::startReceiver() receiveThread_->addIOContext(*socketPair_); receiveThread_->setSuccessfulSetupCb(onSuccessfulSetup_); receiveThread_->startLoop(); - if (receiveThread_) - receiveThread_->setRequestKeyFrameCallback([this]() { cbKeyFrameRequest_(); }); + receiveThread_->setRequestKeyFrameCallback([this]() { cbKeyFrameRequest_(); }); + receiveThread_->setRotation(rotation_.load()); } else { JAMI_DBG("Video receiving disabled"); if (receiveThread_) @@ -319,6 +319,7 @@ VideoRtpSession::forceKeyFrame() void VideoRtpSession::setRotation(int rotation) { + rotation_.store(rotation); if (receiveThread_) receiveThread_->setRotation(rotation); } diff --git a/src/media/video/video_rtp_session.h b/src/media/video/video_rtp_session.h index f8da52fc77dd7cc8b21beaa624824221a78ec3f5..0c83d7e8d8ec83da46efaff7bbf16e5ef6f25f20 100644 --- a/src/media/video/video_rtp_session.h +++ b/src/media/video/video_rtp_session.h @@ -177,6 +177,8 @@ private: std::unique_ptr<CongestionControl> cc; std::function<void(void)> cbKeyFrameRequest_; + + std::atomic<int> rotation_ {0}; }; } // namespace video diff --git a/src/sip/sipcall.cpp b/src/sip/sipcall.cpp index 4621da5bbb6e6715090b5f4e73b4904197d4c7b1..fff0fc510fee8123bbbc1d8282c8c42b0c42cab5 100644 --- a/src/sip/sipcall.cpp +++ b/src/sip/sipcall.cpp @@ -176,6 +176,7 @@ SIPCall::createRtpSession(RtpStream& stream) #ifdef ENABLE_VIDEO else if (stream.mediaAttribute_->type_ == MediaType::MEDIA_VIDEO) { stream.rtpSession_ = std::make_shared<video::VideoRtpSession>(id_, getVideoSettings()); + std::static_pointer_cast<video::VideoRtpSession>(stream.rtpSession_)->setRotation(rotation_); } #endif else { @@ -2805,10 +2806,22 @@ SIPCall::getReceiveVideoFrameActiveWriter() return {}; } +#ifdef ENABLE_VIDEO +std::shared_ptr<video::VideoRtpSession> +SIPCall::getVideoRtp() const +{ + for (auto const& stream : rtpStreams_) { + auto rtp = stream.rtpSession_; + if (rtp->getMediaType() == MediaType::MEDIA_VIDEO) { + return std::dynamic_pointer_cast<video::VideoRtpSession>(rtp); + } + } + return nullptr; +} + bool SIPCall::addDummyVideoRtpSession() { -#ifdef ENABLE_VIDEO JAMI_DBG("[call:%s] Add dummy video stream", getCallId().c_str()); MediaAttribute mediaAttr(MediaType::MEDIA_VIDEO, @@ -2822,9 +2835,6 @@ SIPCall::addDummyVideoRtpSession() auto& stream = rtpStreams_.back(); createRtpSession(stream); return stream.rtpSession_ != nullptr; -#endif - - return false; } void @@ -2850,6 +2860,15 @@ SIPCall::removeDummyVideoRtpSessions() } } +void +SIPCall::setRotation(int rotation) +{ + rotation_ = rotation; + if (auto videoRtp = getVideoRtp()) + videoRtp->setRotation(rotation); +} +#endif + void SIPCall::createSinks(const ConfInfo& infos) { @@ -2887,20 +2906,6 @@ SIPCall::getAudioRtp() const return nullptr; } -#ifdef ENABLE_VIDEO -std::shared_ptr<video::VideoRtpSession> -SIPCall::getVideoRtp() const -{ - for (auto const& stream : rtpStreams_) { - auto rtp = stream.rtpSession_; - if (rtp->getMediaType() == MediaType::MEDIA_VIDEO) { - return std::dynamic_pointer_cast<video::VideoRtpSession>(rtp); - } - } - return nullptr; -} -#endif - std::vector<std::shared_ptr<RtpSession>> SIPCall::getRtpSessionList() const { diff --git a/src/sip/sipcall.h b/src/sip/sipcall.h index 11243c0f77309cf24ef39cc0bae926e7c7bcdf82..70ada6c030b6a3805073011b1c71d3752c163435 100644 --- a/src/sip/sipcall.h +++ b/src/sip/sipcall.h @@ -267,6 +267,7 @@ public: std::shared_ptr<video::VideoRtpSession> getVideoRtp() const; bool addDummyVideoRtpSession() override; void removeDummyVideoRtpSessions() override; + void setRotation(int rotation); #endif // Get the list of current RTP sessions std::vector<std::shared_ptr<RtpSession>> getRtpSessionList() const; @@ -469,6 +470,9 @@ private: void resetMediaReady(); std::mutex setupSuccessMutex_; +#ifdef ENABLE_VIDEO + int rotation_ {0}; +#endif }; // Helpers diff --git a/src/sip/sipvoiplink.cpp b/src/sip/sipvoiplink.cpp index 021be9e068ab5b94da795f1cec2c3cf7fb07d73d..3602b3d5da946a4b702dddac34c18ecd2ff06e55 100644 --- a/src/sip/sipvoiplink.cpp +++ b/src/sip/sipvoiplink.cpp @@ -1190,9 +1190,7 @@ handleMediaControl(SIPCall& call, pjsip_msg_body* body) rotation -= 360; JAMI_WARN("Rotate video %d deg.", rotation); #ifdef ENABLE_VIDEO - auto const& videoRtp = call.getVideoRtp(); - if (videoRtp) - videoRtp->setRotation(rotation); + call.setRotation(rotation); #endif } catch (const std::exception& e) { JAMI_WARN("Error parsing angle: %s", e.what());