Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browser(firefox): exclude frame from screencast video #3372

Merged
merged 1 commit into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions browser_patches/firefox/BUILD_NUMBER
Original file line number Diff line number Diff line change
@@ -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
58 changes: 29 additions & 29 deletions browser_patches/firefox/juggler/screencast/ScreencastEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ void createImage(unsigned int width, unsigned int height,

class ScreencastEncoder::VPXFrame {
public:
VPXFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer>&& buffer, Maybe<double> scale, int offsetTop)
VPXFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer>&& buffer, Maybe<double> 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; }
Expand All @@ -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<int>(image->w, src->width());
int height = std::min<int>(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<int>(image->w, src->width() - m_margin.LeftRight());
int height = std::min<int>(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<webrtc::VideoFrameBuffer> m_frameBuffer;
Maybe<double> m_scale;
int m_offsetTop = 0;
gfx::IntMargin m_margin;
int m_duration = 0;
};

Expand Down Expand Up @@ -264,10 +264,10 @@ class ScreencastEncoder::VPXCodec {
std::unique_ptr<vpx_image_t> m_image;
};

ScreencastEncoder::ScreencastEncoder(std::unique_ptr<VPXCodec>&& vpxCodec, Maybe<double> scale, int offsetTop)
ScreencastEncoder::ScreencastEncoder(std::unique_ptr<VPXCodec>&& vpxCodec, Maybe<double> scale, const gfx::IntMargin& margin)
: m_vpxCodec(std::move(vpxCodec))
, m_scale(scale)
, m_offsetTop(offsetTop)
, m_margin(margin)
{
}

Expand All @@ -277,7 +277,7 @@ ScreencastEncoder::~ScreencastEncoder()

static constexpr int fps = 24;

RefPtr<ScreencastEncoder> ScreencastEncoder::create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe<double> scale, int offsetTop)
RefPtr<ScreencastEncoder> ScreencastEncoder::create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe<double> scale, const gfx::IntMargin& margin)
{
vpx_codec_iface_t* codec_interface = vpx_codec_vp8_cx();
if (!codec_interface) {
Expand Down Expand Up @@ -318,7 +318,7 @@ RefPtr<ScreencastEncoder> ScreencastEncoder::create(nsCString& errorString, cons

std::unique_ptr<VPXCodec> 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()
Expand All @@ -342,7 +342,7 @@ void ScreencastEncoder::encodeFrame(const webrtc::VideoFrame& videoFrame)
fprintf(stderr, "ScreencastEncoder::encodeFrame\n");
flushLastFrame();

m_lastFrame = std::make_unique<VPXFrame>(videoFrame.video_frame_buffer(), m_scale, m_offsetTop);
m_lastFrame = std::make_unique<VPXFrame>(videoFrame.video_frame_buffer(), m_scale, m_margin);
}

void ScreencastEncoder::finish(std::function<void()>&& callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <functional>
#include <memory>
#include "mozilla/gfx/Rect.h"
#include "mozilla/Maybe.h"
#include "mozilla/TimeStamp.h"
#include "nsISupportsImpl.h"
Expand All @@ -21,10 +22,10 @@ class ScreencastEncoder {
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ScreencastEncoder)
public:

static RefPtr<ScreencastEncoder> create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe<double> scale, int offsetTop);
static RefPtr<ScreencastEncoder> create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe<double> scale, const gfx::IntMargin& margin);

class VPXCodec;
ScreencastEncoder(std::unique_ptr<VPXCodec>&&, Maybe<double> scale, int offsetTop);
ScreencastEncoder(std::unique_ptr<VPXCodec>&&, Maybe<double> scale, const gfx::IntMargin& margin);

void encodeFrame(const webrtc::VideoFrame& videoFrame);

Expand All @@ -37,7 +38,7 @@ class ScreencastEncoder {

std::unique_ptr<VPXCodec> m_vpxCodec;
Maybe<double> m_scale;
int m_offsetTop;
gfx::IntMargin m_margin;
TimeStamp m_lastFrameTimestamp;
class VPXFrame;
std::unique_ptr<VPXFrame> m_lastFrame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,15 @@ nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const
Maybe<double> maybeScale;
if (scale)
maybeScale = Some(scale);
RefPtr<ScreencastEncoder> 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<ScreencastEncoder> 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;
Expand Down