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

Use video.requestVideoFrameCallback if it exists #19905

Closed

Conversation

greggman
Copy link
Contributor

This appears to be the new correct way to know if there is
actually data in a video so you can safely call texImage2D

@greggman greggman force-pushed the use-requestVideoFrameCallback-if-exists branch from f5ae39f to f2742e0 Compare July 22, 2020 04:31
@greggman
Copy link
Contributor Author

greggman commented Jul 22, 2020

#19880

@greggman greggman force-pushed the use-requestVideoFrameCallback-if-exists branch 2 times, most recently from c31ab21 to 7a9bdae Compare July 22, 2020 08:29
@mrdoob
Copy link
Owner

mrdoob commented Jul 22, 2020

Nice!

While we're at it... How about this?

function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {

	Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );

	this.format = format !== undefined ? format : RGBFormat;

	this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
	this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;

	this.generateMipmaps = false;

	if ( 'requestVideoFrameCallback' in video ) {

		video.requestVideoFrameCallback( () => {

			this.needsUpdate = true;

		} );

	}

}

VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {

	constructor: VideoTexture,

	isVideoTexture: true,

	update: function () {

		const video = this.image;
		const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;

		if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {

			this.needsUpdate = true;

		}

	}

} );

Eventually, VideoTexture's update() will no longer be needed.

@mrdoob mrdoob added this to the r119 milestone Jul 22, 2020
@greggman greggman force-pushed the use-requestVideoFrameCallback-if-exists branch from 7a9bdae to 8650b93 Compare July 22, 2020 08:33
This appears to be the new correct way to know if there is
actually data in a video so you can safely call texImage2D
@greggman greggman force-pushed the use-requestVideoFrameCallback-if-exists branch from 8650b93 to 8632d09 Compare July 22, 2020 08:36
@greggman greggman closed this Jul 22, 2020
@greggman
Copy link
Contributor Author

You can fix it however you want. BTW though my first usage was wrong. I had a typo. requestVideoFrameCallback works like requestAnimationFrame in that it only calls you back once. If you want to be called again you have to request another callback.

@mrdoob mrdoob removed this from the r119 milestone Jul 22, 2020
@greggman greggman deleted the use-requestVideoFrameCallback-if-exists branch July 22, 2020 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants