Skip to content

Commit a96fb56

Browse files
hujiajieYang Gu
andauthored
De-flake fromPixels test failure (#6626)
`HTMLVideoElement.requestVideoFrameCallback()` provides a realiable way to guarantee the readiness of a video frame, whereas the browser may not update the ready state until a few frames later. In such cases, false alarms will be raised by the validation in `fromPixels()`. Fixes #6577 Co-authored-by: Yang Gu <[email protected]>
1 parent bb926ed commit a96fb56

File tree

2 files changed

+0
-19
lines changed

2 files changed

+0
-19
lines changed

tfjs-core/src/ops/browser.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,6 @@ function fromPixels_(
107107
` or {data: Uint32Array, width: number, height: number}, ` +
108108
`but was ${(pixels as {}).constructor.name}`);
109109
}
110-
if (isVideo) {
111-
const HAVE_CURRENT_DATA_READY_STATE = 2;
112-
if (isVideo &&
113-
(pixels as HTMLVideoElement).readyState <
114-
HAVE_CURRENT_DATA_READY_STATE) {
115-
throw new Error(
116-
'The video element has not loaded data yet. Please wait for ' +
117-
'`loadeddata` event on the <video> element.');
118-
}
119-
}
120110
// If the current backend has 'FromPixels' registered, it has a more
121111
// efficient way of handling pixel uploads, so we call that.
122112
const kernel = getKernel(FromPixels, ENGINE.backendName);

tfjs-core/src/ops/from_pixels_test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,6 @@ describeWithFlags('fromPixels', BROWSER_ENVS, () => {
233233
document.body.removeChild(video);
234234
}, 30_000 /* 30 seconds */);
235235

236-
it('fromPixels for HTMLVideoElement throws without loadeddata', async () => {
237-
const video = document.createElement('video');
238-
video.width = 1;
239-
video.height = 1;
240-
video.src = 'data:image/gif;base64' +
241-
',R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';
242-
expect(() => tf.browser.fromPixels(video)).toThrowError();
243-
});
244-
245236
it('throws when passed a primitive number', () => {
246237
const msg = /pixels passed to tf.browser.fromPixels\(\) must be either/;
247238
// tslint:disable-next-line:no-any

0 commit comments

Comments
 (0)