Skip to content

Commit

Permalink
chore(ff): remove some dead code (#6423)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed May 5, 2021
1 parent 9e36f5c commit 765d749
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 46 deletions.
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 @@
1252
Changed: joel.einbinder@gmail.com Tue 04 May 2021 02:47:58 AM PDT
1253
Changed: pavel.feldman@gmail.com Wed 05 May 2021 01:22:39 PM PDT
7 changes: 2 additions & 5 deletions browser_patches/firefox/juggler/TargetRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,24 +488,21 @@ class PageTarget {
return await this._channel.connect('').send('hasFailedToOverrideTimezone').catch(e => true);
}

async _startVideoRecording({width, height, scale, dir}) {
async _startVideoRecording({width, height, dir}) {
// On Mac the window may not yet be visible when TargetCreated and its
// NSWindow.windowNumber may be -1, so we wait until the window is known
// to be initialized and visible.
await this.windowReady();
const file = OS.Path.join(dir, helper.generateId() + '.webm');
if (width < 10 || width > 10000 || height < 10 || height > 10000)
throw new Error("Invalid size");
if (scale && (scale <= 0 || scale > 1))
throw new Error("Unsupported scale");

const screencast = Cc['@mozilla.org/juggler/screencast;1'].getService(Ci.nsIScreencastService);
const docShell = this._gBrowser.ownerGlobal.docShell;
// Exclude address bar and navigation control from the video.
const rect = this.linkedBrowser().getBoundingClientRect();
const devicePixelRatio = this._window.devicePixelRatio;
const viewport = this._viewportSize || this._browserContext.defaultViewportSize || {width: 0, height: 0};
const videoSessionId = screencast.startVideoRecording(docShell, file, width, height, viewport.width, viewport.height, scale || 0, devicePixelRatio * rect.top);
const videoSessionId = screencast.startVideoRecording(docShell, file, width, height, devicePixelRatio * rect.top);
this._screencastInfo = { videoSessionId, file };
this.emit(PageTarget.Events.ScreencastStarted);
}
Expand Down
4 changes: 0 additions & 4 deletions browser_patches/firefox/juggler/protocol/PageHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,6 @@ class PageHandler {
throw new Error('ERROR: cannot find worker with id ' + workerId);
return await worker.sendMessage(JSON.parse(message));
}

async ['Page.stopVideoRecording']() {
await this._pageTarget.stopVideoRecording();
}
}

var EXPORTED_SYMBOLS = ['PageHandler'];
Expand Down
11 changes: 0 additions & 11 deletions browser_patches/firefox/juggler/protocol/Protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ const Browser = {
dir: t.String,
width: t.Number,
height: t.Number,
scale: t.Optional(t.Number),
},
},
},
Expand Down Expand Up @@ -896,16 +895,6 @@ const Page = {
message: t.String,
},
},
'startVideoRecording': {
params: {
file: t.String,
width: t.Number,
height: t.Number,
scale: t.Optional(t.Number),
},
},
'stopVideoRecording': {
},
},
};

Expand Down
17 changes: 7 additions & 10 deletions browser_patches/firefox/juggler/screencast/ScreencastEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ void createImage(unsigned int width, unsigned int height,

class ScreencastEncoder::VPXFrame {
public:
VPXFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer>&& buffer, Maybe<double> scale, const gfx::IntMargin& margin)
VPXFrame(rtc::scoped_refptr<webrtc::VideoFrameBuffer>&& buffer, const gfx::IntMargin& margin)
: m_frameBuffer(std::move(buffer))
, m_scale(scale)
, m_margin(margin)
{ }

Expand All @@ -137,8 +136,8 @@ class ScreencastEncoder::VPXFrame {
double src_width = src->width() - m_margin.LeftRight();
double src_height = src->height() - m_margin.top;

if (m_scale || (src_width > image->w || src_height > image->h)) {
double scale = m_scale ? m_scale.value() : std::min(image->w / src_width, image->h / src_height);
if (src_width > image->w || src_height > image->h) {
double scale = std::min(image->w / src_width, image->h / src_height);
double dst_width = src_width * scale;
if (dst_width > image->w) {
src_width *= image->w / dst_width;
Expand Down Expand Up @@ -174,7 +173,6 @@ class ScreencastEncoder::VPXFrame {

private:
rtc::scoped_refptr<webrtc::VideoFrameBuffer> m_frameBuffer;
Maybe<double> m_scale;
gfx::IntMargin m_margin;
TimeDuration m_duration;
};
Expand Down Expand Up @@ -276,9 +274,8 @@ class ScreencastEncoder::VPXCodec {
std::unique_ptr<vpx_image_t> m_image;
};

ScreencastEncoder::ScreencastEncoder(std::unique_ptr<VPXCodec>&& vpxCodec, Maybe<double> scale, const gfx::IntMargin& margin)
ScreencastEncoder::ScreencastEncoder(std::unique_ptr<VPXCodec>&& vpxCodec, const gfx::IntMargin& margin)
: m_vpxCodec(std::move(vpxCodec))
, m_scale(scale)
, m_margin(margin)
{
}
Expand All @@ -287,7 +284,7 @@ ScreencastEncoder::~ScreencastEncoder()
{
}

RefPtr<ScreencastEncoder> ScreencastEncoder::create(nsCString& errorString, const nsCString& filePath, int width, int height, Maybe<double> scale, const gfx::IntMargin& margin)
RefPtr<ScreencastEncoder> ScreencastEncoder::create(nsCString& errorString, const nsCString& filePath, int width, int height, const gfx::IntMargin& margin)
{
vpx_codec_iface_t* codec_interface = vpx_codec_vp8_cx();
if (!codec_interface) {
Expand Down Expand Up @@ -328,7 +325,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, margin);
return new ScreencastEncoder(std::move(vpxCodec), margin);
}

void ScreencastEncoder::flushLastFrame()
Expand All @@ -350,7 +347,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_margin);
m_lastFrame = std::make_unique<VPXFrame>(videoFrame.video_frame_buffer(), m_margin);
}

void ScreencastEncoder::finish(std::function<void()>&& callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class ScreencastEncoder {
public:
static constexpr int fps = 25;

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

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

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

Expand All @@ -38,7 +38,6 @@ class ScreencastEncoder {
void flushLastFrame();

std::unique_ptr<VPXCodec> m_vpxCodec;
Maybe<double> m_scale;
gfx::IntMargin m_margin;
TimeStamp m_lastFrameTimestamp;
class VPXFrame;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface nsIDocShell;
[scriptable, uuid(d8c4d9e0-9462-445e-9e43-68d3872ad1de)]
interface nsIScreencastService : nsISupports
{
AString startVideoRecording(in nsIDocShell docShell, in ACString fileName, in uint32_t width, in uint32_t height, in uint32_t viewportWidth, in uint32_t viewportHeight, in double scale, in int32_t offset_top);
AString startVideoRecording(in nsIDocShell docShell, in ACString fileName, in uint32_t width, in uint32_t height, in int32_t offset_top);

/**
* Will emit 'juggler-screencast-stopped' when the video file is saved.
Expand Down
13 changes: 3 additions & 10 deletions browser_patches/firefox/juggler/screencast/nsScreencastService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ nsScreencastService::nsScreencastService() = default;
nsScreencastService::~nsScreencastService() {
}

nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const nsACString& aFileName, uint32_t width, uint32_t height, uint32_t viewportWidth, uint32_t viewportHeight, double scale, int32_t offsetTop, nsAString& sessionId) {
nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const nsACString& aFileName, uint32_t width, uint32_t height, int32_t offsetTop, nsAString& sessionId) {
MOZ_RELEASE_ASSERT(NS_IsMainThread(), "Screencast service must be started on the Main thread.");

PresShell* presShell = aDocShell->GetPresShell();
Expand All @@ -158,23 +158,16 @@ nsresult nsScreencastService::StartVideoRecording(nsIDocShell* aDocShell, const
if (!capturer)
return NS_ERROR_FAILURE;

nsCString error;
Maybe<double> maybeScale;
if (scale)
maybeScale = Some(scale);

gfx::IntMargin margin;
auto bounds = widget->GetScreenBounds().ToUnknownRect();
auto clientBounds = widget->GetClientBounds().ToUnknownRect();
// The browser window has a minimum size, so it might be larger than the viewport size.
clientBounds.width = std::min((int)viewportWidth, clientBounds.width);
clientBounds.height = std::min((int)viewportHeight, clientBounds.height);
// Crop the image to exclude frame (if any).
margin = bounds - clientBounds;
// Crop the image to exclude controls.
margin.top += offsetTop;

RefPtr<ScreencastEncoder> encoder = ScreencastEncoder::create(error, PromiseFlatCString(aFileName), width, height, maybeScale, margin);
nsCString error;
RefPtr<ScreencastEncoder> encoder = ScreencastEncoder::create(error, PromiseFlatCString(aFileName), width, height, margin);
if (!encoder) {
fprintf(stderr, "Failed to create ScreencastEncoder: %s\n", error.get());
return NS_ERROR_FAILURE;
Expand Down

0 comments on commit 765d749

Please sign in to comment.