diff --git a/src/manager.cpp b/src/manager.cpp index edd0427778f0ce0730a763297b5f7240fb1c8357..a6922ce09bc91749621982445fb434e8c741067a 100644 --- a/src/manager.cpp +++ b/src/manager.cpp @@ -3414,14 +3414,14 @@ Manager::createSinkClients(const std::string& callId, if (participant.w && participant.h) { auto currentSink = getSinkClient(sinkId); if (currentSink) { - currentSink->setFramePosition(participant.x, participant.y); + currentSink->setCrop(participant.x, participant.y, participant.w, participant.h); currentSink->setFrameSize(participant.w, participant.h); sinkIdsList.emplace(sinkId); continue; } auto newSink = createSinkClient(sinkId); newSink->start(); - newSink->setFramePosition(participant.x, participant.y); + newSink->setCrop(participant.x, participant.y, participant.w, participant.h); newSink->setFrameSize(participant.w, participant.h); videoStream->attach(newSink.get()); diff --git a/src/media/video/sinkclient.cpp b/src/media/video/sinkclient.cpp index cea0f780d65825a94069ec6cfd5258a09b0bfdf4..f77fbb670f5d21c78b580fb6c39355dbbb9d7706 100644 --- a/src/media/video/sinkclient.cpp +++ b/src/media/video/sinkclient.cpp @@ -292,7 +292,7 @@ bool SinkClient::stop() noexcept { setFrameSize(0, 0); - setFramePosition(0, 0); + setCrop(0, 0, 0, 0); shm_.reset(); return true; } @@ -315,7 +315,7 @@ bool SinkClient::stop() noexcept { setFrameSize(0, 0); - setFramePosition(0, 0); + setCrop(0, 0, 0, 0); return true; } @@ -337,10 +337,6 @@ void SinkClient::update(Observable<std::shared_ptr<MediaFrame>>* /*obs*/, const std::shared_ptr<MediaFrame>& frame_p) { - int width = width_; - int height = height_; - int x = x_; - int y = y_; #ifdef DEBUG_FPS auto currentTime = std::chrono::system_clock::now(); const std::chrono::duration<double> seconds = currentTime - lastFrameDebug_; @@ -357,16 +353,13 @@ SinkClient::update(Observable<std::shared_ptr<MediaFrame>>* /*obs*/, if (avTarget_.push) { auto outFrame = std::make_unique<VideoFrame>(); outFrame->copyFrom(*std::static_pointer_cast<VideoFrame>(frame_p)); - if (y + height <= outFrame->pointer()->height) { - outFrame->pointer()->crop_top = y; - outFrame->pointer()->crop_bottom = outFrame->pointer()->height - y - height; - } - if (x + width <= outFrame->pointer()->width) { - outFrame->pointer()->crop_left = x; - outFrame->pointer()->crop_right = outFrame->pointer()->width - x - width; - } - if (height && width) + if (crop_.w || crop_.h) { + outFrame->pointer()->crop_top = crop_.y; + outFrame->pointer()->crop_bottom = (size_t) outFrame->height() - crop_.y - crop_.h; + outFrame->pointer()->crop_left = crop_.x; + outFrame->pointer()->crop_right = (size_t) outFrame->width() - crop_.x - crop_.w; av_frame_apply_cropping(outFrame->pointer(), AV_FRAME_CROP_UNALIGNED); + } avTarget_.push(std::move(outFrame)); } @@ -405,10 +398,6 @@ SinkClient::update(Observable<std::shared_ptr<MediaFrame>>* /*obs*/, frame->height(), frame->format(), false); - if (std::abs(rotation_ - angle) == 90) { - width = height_; - height = width_; - } rotation_ = angle; } if (filter_) { @@ -417,16 +406,13 @@ SinkClient::update(Observable<std::shared_ptr<MediaFrame>>* /*obs*/, std::shared_ptr<MediaFrame>(filter_->readOutput())); } - if (height < frame->height()) { - frame->pointer()->crop_top = y; - frame->pointer()->crop_bottom = (size_t) frame->height() - y - height; - } - if (width < frame->width()) { - frame->pointer()->crop_left = x; - frame->pointer()->crop_right = (size_t) frame->width() - x - width; - } - if (height < frame->height() || width < frame->width()) + if (crop_.w || crop_.h) { + frame->pointer()->crop_top = crop_.y; + frame->pointer()->crop_bottom = (size_t) frame->height() - crop_.y - crop_.h; + frame->pointer()->crop_left = crop_.x; + frame->pointer()->crop_right = (size_t) frame->width() - crop_.x - crop_.w; av_frame_apply_cropping(frame->pointer(), AV_FRAME_CROP_UNALIGNED); + } if (frame->height() != height_ || frame->width() != width_) { setFrameSize(0, 0); @@ -437,8 +423,8 @@ SinkClient::update(Observable<std::shared_ptr<MediaFrame>>* /*obs*/, #endif std::lock_guard<std::mutex> lock(mtx_); if (target_.pull) { - width = frame->width(); - height = frame->height(); + int width = frame->width(); + int height = frame->height(); #if defined(__ANDROID__) || (defined(__APPLE__) && !TARGET_OS_IPHONE) const int format = AV_PIX_FMT_RGBA; #else @@ -489,11 +475,13 @@ SinkClient::setFrameSize(int width, int height) } void -SinkClient::setFramePosition(int x, int y) +SinkClient::setCrop(int x, int y, int w, int h) { - JAMI_DBG("[Sink:%p] Change frame position from [%d, %d] to [%d, %d]", this, x_, y_, x, y); - x_ = x; - y_ = y; + JAMI_DBG("[Sink:%p] Change crop to [%dx%d at (%d, %d)]", this, w, h, x, y); + crop_.x = x; + crop_.y = y; + crop_.w = w; + crop_.h = h; } } // namespace video diff --git a/src/media/video/sinkclient.h b/src/media/video/sinkclient.h index 77e66263ebfedd64cbd62465902cc7175c446394..adc46321ee20e2b36bc11b6c495dfb30eab3f9d3 100644 --- a/src/media/video/sinkclient.h +++ b/src/media/video/sinkclient.h @@ -74,7 +74,7 @@ public: bool stop() noexcept; void setFrameSize(int width, int height); - void setFramePosition(int x, int y); + void setCrop(int x, int y, int w, int h); void registerTarget(const DRing::SinkTarget& target) noexcept { std::lock_guard<std::mutex> lock(mtx_); @@ -88,8 +88,10 @@ private: const bool mixer_ {false}; int width_ {0}; int height_ {0}; - int x_ {0}; - int y_ {0}; + + struct Rect { int x {0}, y {0}, w {0}, h {0}; }; + Rect crop_ {}; + bool started_ {false}; // used to arbitrate client's stop signal. int rotation_ {0}; DRing::SinkTarget target_; diff --git a/src/sip/sipcall.cpp b/src/sip/sipcall.cpp index c10db059fb011901c17787b2bbc68d5926e91d52..a6f482b18e2fd9c7ef2fede8b6b2b9fd5034d618 100644 --- a/src/sip/sipcall.cpp +++ b/src/sip/sipcall.cpp @@ -1410,7 +1410,7 @@ SIPCall::setVideoOrientation(int rotation) + "/>" "</to_encoder></vc_primitive></media_control>"; - JAMI_DBG("Sending device orientation via SIP INFO"); + JAMI_DBG("Sending device orientation via SIP INFO %d", rotation); sendSIPInfo(sip_body, "media_control+xml"); }