Skip to content

Commit 9640dbf

Browse files
authored
browser(firefox): exclude browser controls from screencast (#2855)
1 parent 39144dd commit 9640dbf

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

browser_patches/firefox/BUILD_NUMBER

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1123
2-
Changed: [email protected] Mon Jul 6 11:13:23 PDT 2020
1+
1124
2+
Changed: [email protected] Mon Jul 6 17:16:56 PDT 2020

browser_patches/firefox/juggler/protocol/PageHandler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,9 @@ class PageHandler {
294294

295295
const screencast = Cc['@mozilla.org/juggler/screencast;1'].getService(Ci.nsIScreencastService);
296296
const docShell = this._pageTarget._gBrowser.ownerGlobal.docShell;
297-
this._videoSessionId = screencast.startVideoRecording(docShell, file, width, height, scale || 0);
297+
// Exclude address bar and navigation control from the video.
298+
const rect = this._pageTarget.linkedBrowser().getBoundingClientRect();
299+
this._videoSessionId = screencast.startVideoRecording(docShell, file, width, height, scale || 0, rect.top);
298300
}
299301

300302
stopVideoRecording() {

browser_patches/firefox/juggler/screencast/ScreencastEncoder.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ void ivf_write_frame_header(FILE *outfile, int64_t pts, size_t frame_size) {
158158

159159
class ScreencastEncoder::VPXFrame {
160160
public:
161-
VPXFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer>&& buffer, Maybe<double> scale)
161+
VPXFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer>&& buffer, Maybe<double> scale, int offsetTop)
162162
: m_frameBuffer(std::move(buffer))
163163
, m_scale(scale)
164+
, m_offsetTop(offsetTop)
164165
{ }
165166

166167
void setDuration(int duration) { m_duration = duration; }
@@ -189,15 +190,15 @@ class ScreencastEncoder::VPXFrame {
189190
src_width *= image->w / dst_width;
190191
dst_width = image->w;
191192
}
192-
int src_height = src->height();
193+
int src_height = src->height() - m_offsetTop;
193194
double dst_height = src_height * m_scale.value();
194195
if (dst_height > image->h) {
195196
src_height *= image->h / dst_height;
196197
dst_height = image->h;
197198
}
198-
libyuv::I420Scale(src->DataY(), src->StrideY(),
199-
src->DataU(), src->StrideU(),
200-
src->DataV(), src->StrideV(),
199+
libyuv::I420Scale(src->DataY() + m_offsetTop * src->StrideY(), src->StrideY(),
200+
src->DataU() + (m_offsetTop + 1) / 2 * src->StrideU(), src->StrideU(),
201+
src->DataV() + (m_offsetTop + 1) / 2 * src->StrideV(), src->StrideV(),
201202
src_width, src_height,
202203
y_data, y_stride,
203204
u_data, uv_stride,
@@ -206,10 +207,11 @@ class ScreencastEncoder::VPXFrame {
206207
libyuv::kFilterBilinear);
207208
} else {
208209
int width = std::min<int>(image->w, src->width());
209-
int height = std::min<int>(image->h, src->height());
210-
libyuv::I420Copy(src->DataY(), src->StrideY(),
211-
src->DataU(), src->StrideU(),
212-
src->DataV(), src->StrideV(),
210+
int height = std::min<int>(image->h, src->height() - m_offsetTop);
211+
212+
libyuv::I420Copy(src->DataY() + m_offsetTop * src->StrideY(), src->StrideY(),
213+
src->DataU() + (m_offsetTop + 1) / 2 * src->StrideU(), src->StrideU(),
214+
src->DataV() + (m_offsetTop + 1) / 2 * src->StrideV(), src->StrideV(),
213215
y_data, y_stride,
214216
u_data, uv_stride,
215217
v_data, uv_stride,
@@ -220,6 +222,7 @@ class ScreencastEncoder::VPXFrame {
220222
private:
221223
rtc::scoped_refptr<webrtc::VideoFrameBuffer> m_frameBuffer;
222224
Maybe<double> m_scale;
225+
int m_offsetTop = 0;
223226
int m_duration = 0;
224227
};
225228

@@ -325,11 +328,10 @@ class ScreencastEncoder::VPXCodec {
325328
std::unique_ptr<vpx_image_t> m_image;
326329
};
327330

328-
ScreencastEncoder::ScreencastEncoder(std::unique_ptr<VPXCodec>&& vpxCodec, int width, int height, Maybe<double> scale)
331+
ScreencastEncoder::ScreencastEncoder(std::unique_ptr<VPXCodec>&& vpxCodec, Maybe<double> scale, int offsetTop)
329332
: m_vpxCodec(std::move(vpxCodec))
330-
, m_width(width)
331-
, m_height(height)
332333
, m_scale(scale)
334+
, m_offsetTop(offsetTop)
333335
{
334336
}
335337

@@ -338,10 +340,9 @@ ScreencastEncoder::~ScreencastEncoder()
338340
}
339341

340342
static constexpr uint32_t vp8fourcc = 0x30385056;
341-
static constexpr uint32_t vp9fourcc = 0x30395056;
342-
static constexpr int fps = 30;
343+
static constexpr int fps = 24;
343344

344-
RefPtr<ScreencastEncoder> ScreencastEncoder::create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe<double> scale)
345+
RefPtr<ScreencastEncoder> ScreencastEncoder::create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe<double> scale, int offsetTop)
345346
{
346347
const uint32_t fourcc = vp8fourcc;
347348
vpx_codec_iface_t* codec_interface = vpx_codec_vp8_cx();
@@ -383,7 +384,7 @@ RefPtr<ScreencastEncoder> ScreencastEncoder::create(nsCString& errorString, cons
383384

384385
std::unique_ptr<VPXCodec> vpxCodec(new VPXCodec(fourcc, codec, cfg, file));
385386
fprintf(stderr, "ScreencastEncoder initialized with: %s\n", vpx_codec_iface_name(codec_interface));
386-
return new ScreencastEncoder(std::move(vpxCodec), width, height, scale);
387+
return new ScreencastEncoder(std::move(vpxCodec), scale, offsetTop);
387388
}
388389

389390
void ScreencastEncoder::flushLastFrame()
@@ -407,7 +408,7 @@ void ScreencastEncoder::encodeFrame(const webrtc::VideoFrame& videoFrame)
407408
fprintf(stderr, "ScreencastEncoder::encodeFrame\n");
408409
flushLastFrame();
409410

410-
m_lastFrame = std::make_unique<VPXFrame>(videoFrame.video_frame_buffer(), m_scale);
411+
m_lastFrame = std::make_unique<VPXFrame>(videoFrame.video_frame_buffer(), m_scale, m_offsetTop);
411412
}
412413

413414
void ScreencastEncoder::finish(std::function<void()>&& callback)

browser_patches/firefox/juggler/screencast/ScreencastEncoder.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class ScreencastEncoder {
2121
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(ScreencastEncoder)
2222
public:
2323

24-
static RefPtr<ScreencastEncoder> create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe<double> scale);
24+
static RefPtr<ScreencastEncoder> create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe<double> scale, int offsetTop);
2525

2626
class VPXCodec;
27-
ScreencastEncoder(std::unique_ptr<VPXCodec>&&, int width, int height, Maybe<double> scale);
27+
ScreencastEncoder(std::unique_ptr<VPXCodec>&&, Maybe<double> scale, int offsetTop);
2828

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

@@ -36,9 +36,8 @@ class ScreencastEncoder {
3636
void flushLastFrame();
3737

3838
std::unique_ptr<VPXCodec> m_vpxCodec;
39-
int m_width;
40-
int m_height;
4139
Maybe<double> m_scale;
40+
int m_offsetTop;
4241
TimeStamp m_lastFrameTimestamp;
4342
class VPXFrame;
4443
std::unique_ptr<VPXFrame> m_lastFrame;

browser_patches/firefox/juggler/screencast/nsIScreencastService.idl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ interface nsIDocShell;
1212
[scriptable, uuid(d8c4d9e0-9462-445e-9e43-68d3872ad1de)]
1313
interface nsIScreencastService : nsISupports
1414
{
15-
long startVideoRecording(in nsIDocShell docShell, in ACString fileName, in uint32_t width, in uint32_t height, in double scale);
15+
long startVideoRecording(in nsIDocShell docShell, in ACString fileName, in uint32_t width, in uint32_t height, in double scale, in int32_t offset_top);
1616
void stopVideoRecording(in long sessionId);
1717
};

browser_patches/firefox/juggler/screencast/nsScreencastService.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ StaticRefPtr<nsScreencastService> gScreencastService;
3333
class nsScreencastService::Session : public rtc::VideoSinkInterface<webrtc::VideoFrame> {
3434
public:
3535
Session(int sessionId, const nsCString& windowId, RefPtr<ScreencastEncoder>&& encoder)
36-
: mSessionId(sessionId)
37-
, mCaptureModule(webrtc::DesktopCaptureImpl::Create(
36+
: mCaptureModule(webrtc::DesktopCaptureImpl::Create(
3837
sessionId, windowId.get(), webrtc::CaptureDeviceType::Window))
3938
, mEncoder(std::move(encoder)) {
4039
}
@@ -71,7 +70,6 @@ class nsScreencastService::Session : public rtc::VideoSinkInterface<webrtc::Vide
7170
}
7271

7372
private:
74-
int mSessionId;
7573
rtc::scoped_refptr<webrtc::VideoCaptureModule> mCaptureModule;
7674
RefPtr<ScreencastEncoder> mEncoder;
7775
};
@@ -93,7 +91,7 @@ nsScreencastService::nsScreencastService() = default;
9391
nsScreencastService::~nsScreencastService() {
9492
}
9593

96-
nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const nsACString& aFileName, uint32_t width, uint32_t height, double scale, int32_t* sessionId) {
94+
nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const nsACString& aFileName, uint32_t width, uint32_t height, double scale, int32_t offsetTop, int32_t* sessionId) {
9795
MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Screencast service must be started on the Main thread.");
9896
*sessionId = -1;
9997

@@ -124,7 +122,7 @@ nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const
124122
Maybe<double> maybeScale;
125123
if (scale)
126124
maybeScale = Some(scale);
127-
RefPtr<ScreencastEncoder> encoder = ScreencastEncoder::create(error, PromiseFlatCString(aFileName), width, height, maybeScale);
125+
RefPtr<ScreencastEncoder> encoder = ScreencastEncoder::create(error, PromiseFlatCString(aFileName), width, height, maybeScale, offsetTop);
128126
if (!encoder) {
129127
fprintf(stderr, "Failed to create ScreencastEncoder: %s\n", error.get());
130128
return NS_ERROR_FAILURE;

0 commit comments

Comments
 (0)