diff --git a/browser_patches/firefox/BUILD_NUMBER b/browser_patches/firefox/BUILD_NUMBER index a644ec8dc24d8..80a313e6ac310 100644 --- a/browser_patches/firefox/BUILD_NUMBER +++ b/browser_patches/firefox/BUILD_NUMBER @@ -1,2 +1,2 @@ -1155 -Changed: lushnikov@chromium.org Fri Aug 7 15:25:51 PDT 2020 +1156 +Changed: yurys@chromium.org Mon Aug 10 20:28:44 GMTST 2020 diff --git a/browser_patches/firefox/juggler/screencast/ScreencastEncoder.cpp b/browser_patches/firefox/juggler/screencast/ScreencastEncoder.cpp index cf6fca0f72387..99894848246c9 100644 --- a/browser_patches/firefox/juggler/screencast/ScreencastEncoder.cpp +++ b/browser_patches/firefox/juggler/screencast/ScreencastEncoder.cpp @@ -105,10 +105,10 @@ void createImage(unsigned int width, unsigned int height, class ScreencastEncoder::VPXFrame { public: - VPXFrame(rtc::scoped_refptr&& buffer, Maybe scale, int offsetTop) + VPXFrame(rtc::scoped_refptr&& buffer, Maybe scale, const gfx::IntMargin& margin) : m_frameBuffer(std::move(buffer)) , m_scale(scale) - , m_offsetTop(offsetTop) + , m_margin(margin) { } void setDuration(int duration) { m_duration = duration; } @@ -131,45 +131,45 @@ class ScreencastEncoder::VPXFrame { uint8_t* v_data = image->planes[2]; if (m_scale) { - int src_width = src->width(); + int src_width = src->width() - m_margin.LeftRight(); double dst_width = src_width * m_scale.value(); if (dst_width > image->w) { src_width *= image->w / dst_width; dst_width = image->w; } - int src_height = src->height() - m_offsetTop; + int src_height = src->height() - m_margin.TopBottom(); double dst_height = src_height * m_scale.value(); if (dst_height > image->h) { src_height *= image->h / dst_height; dst_height = image->h; } - libyuv::I420Scale(src->DataY() + m_offsetTop * src->StrideY(), src->StrideY(), - src->DataU() + (m_offsetTop + 1) / 2 * src->StrideU(), src->StrideU(), - src->DataV() + (m_offsetTop + 1) / 2 * src->StrideV(), src->StrideV(), - src_width, src_height, - y_data, y_stride, - u_data, uv_stride, - v_data, uv_stride, - dst_width, dst_height, - libyuv::kFilterBilinear); + libyuv::I420Scale(src->DataY() + m_margin.top * src->StrideY() + m_margin.left, src->StrideY(), + src->DataU() + (m_margin.top * src->StrideU() + m_margin.left) / 2, src->StrideU(), + src->DataV() + (m_margin.top * src->StrideV() + m_margin.left) / 2, src->StrideV(), + src_width, src_height, + y_data, y_stride, + u_data, uv_stride, + v_data, uv_stride, + dst_width, dst_height, + libyuv::kFilterBilinear); } else { - int width = std::min(image->w, src->width()); - int height = std::min(image->h, src->height() - m_offsetTop); - - libyuv::I420Copy(src->DataY() + m_offsetTop * src->StrideY(), src->StrideY(), - src->DataU() + (m_offsetTop + 1) / 2 * src->StrideU(), src->StrideU(), - src->DataV() + (m_offsetTop + 1) / 2 * src->StrideV(), src->StrideV(), - y_data, y_stride, - u_data, uv_stride, - v_data, uv_stride, - width, height); + int width = std::min(image->w, src->width() - m_margin.LeftRight()); + int height = std::min(image->h, src->height() - m_margin.TopBottom()); + + libyuv::I420Copy(src->DataY() + m_margin.top * src->StrideY() + m_margin.left, src->StrideY(), + src->DataU() + (m_margin.top * src->StrideU() + m_margin.left) / 2, src->StrideU(), + src->DataV() + (m_margin.top * src->StrideV() + m_margin.left) / 2, src->StrideV(), + y_data, y_stride, + u_data, uv_stride, + v_data, uv_stride, + width, height); } } private: rtc::scoped_refptr m_frameBuffer; Maybe m_scale; - int m_offsetTop = 0; + gfx::IntMargin m_margin; int m_duration = 0; }; @@ -264,10 +264,10 @@ class ScreencastEncoder::VPXCodec { std::unique_ptr m_image; }; -ScreencastEncoder::ScreencastEncoder(std::unique_ptr&& vpxCodec, Maybe scale, int offsetTop) +ScreencastEncoder::ScreencastEncoder(std::unique_ptr&& vpxCodec, Maybe scale, const gfx::IntMargin& margin) : m_vpxCodec(std::move(vpxCodec)) , m_scale(scale) - , m_offsetTop(offsetTop) + , m_margin(margin) { } @@ -277,7 +277,7 @@ ScreencastEncoder::~ScreencastEncoder() static constexpr int fps = 24; -RefPtr ScreencastEncoder::create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe scale, int offsetTop) +RefPtr ScreencastEncoder::create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe scale, const gfx::IntMargin& margin) { vpx_codec_iface_t* codec_interface = vpx_codec_vp8_cx(); if (!codec_interface) { @@ -318,7 +318,7 @@ RefPtr ScreencastEncoder::create(nsCString& errorString, cons std::unique_ptr vpxCodec(new VPXCodec(codec, cfg, file)); fprintf(stderr, "ScreencastEncoder initialized with: %s\n", vpx_codec_iface_name(codec_interface)); - return new ScreencastEncoder(std::move(vpxCodec), scale, offsetTop); + return new ScreencastEncoder(std::move(vpxCodec), scale, margin); } void ScreencastEncoder::flushLastFrame() @@ -342,7 +342,7 @@ void ScreencastEncoder::encodeFrame(const webrtc::VideoFrame& videoFrame) fprintf(stderr, "ScreencastEncoder::encodeFrame\n"); flushLastFrame(); - m_lastFrame = std::make_unique(videoFrame.video_frame_buffer(), m_scale, m_offsetTop); + m_lastFrame = std::make_unique(videoFrame.video_frame_buffer(), m_scale, m_margin); } void ScreencastEncoder::finish(std::function&& callback) diff --git a/browser_patches/firefox/juggler/screencast/ScreencastEncoder.h b/browser_patches/firefox/juggler/screencast/ScreencastEncoder.h index 80208f069750e..afdd1b284d7a3 100644 --- a/browser_patches/firefox/juggler/screencast/ScreencastEncoder.h +++ b/browser_patches/firefox/juggler/screencast/ScreencastEncoder.h @@ -6,6 +6,7 @@ #include #include +#include "mozilla/gfx/Rect.h" #include "mozilla/Maybe.h" #include "mozilla/TimeStamp.h" #include "nsISupportsImpl.h" @@ -21,10 +22,10 @@ class ScreencastEncoder { NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ScreencastEncoder) public: - static RefPtr create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe scale, int offsetTop); + static RefPtr create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe scale, const gfx::IntMargin& margin); class VPXCodec; - ScreencastEncoder(std::unique_ptr&&, Maybe scale, int offsetTop); + ScreencastEncoder(std::unique_ptr&&, Maybe scale, const gfx::IntMargin& margin); void encodeFrame(const webrtc::VideoFrame& videoFrame); @@ -37,7 +38,7 @@ class ScreencastEncoder { std::unique_ptr m_vpxCodec; Maybe m_scale; - int m_offsetTop; + gfx::IntMargin m_margin; TimeStamp m_lastFrameTimestamp; class VPXFrame; std::unique_ptr m_lastFrame; diff --git a/browser_patches/firefox/juggler/screencast/nsScreencastService.cpp b/browser_patches/firefox/juggler/screencast/nsScreencastService.cpp index c30aa4c7e4416..595a7cef5ea2e 100644 --- a/browser_patches/firefox/juggler/screencast/nsScreencastService.cpp +++ b/browser_patches/firefox/juggler/screencast/nsScreencastService.cpp @@ -147,7 +147,15 @@ nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const Maybe maybeScale; if (scale) maybeScale = Some(scale); - RefPtr encoder = ScreencastEncoder::create(error, PromiseFlatCString(aFileName), width, height, maybeScale, offsetTop); + + auto bounds = widget->GetScreenBounds().ToUnknownRect(); + auto clientBounds = widget->GetClientBounds().ToUnknownRect(); + // Crop the image to exclude frame (if any). + gfx::IntMargin margin = bounds - clientBounds; + // Crop the image to exclude controls. + margin.top += offsetTop; + + RefPtr encoder = ScreencastEncoder::create(error, PromiseFlatCString(aFileName), width, height, maybeScale, margin); if (!encoder) { fprintf(stderr, "Failed to create ScreencastEncoder: %s\n", error.get()); return NS_ERROR_FAILURE;