Skip to content

Commit

Permalink
clean up ios hls tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ngokevin committed May 17, 2017
1 parent da71c5f commit a2d641a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/systems/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,14 @@ module.exports.System = registerSystem('material', {
texture.minFilter = THREE.LinearFilter;
setTextureProperties(texture, data);

// if we're on iOS, and the video is HLS, we currently need to do some hacks
if (this.sceneEl.isIOS && isHLS(videoEl.src || videoEl.getAttribute('src'), videoEl.type || videoEl.getAttribute('type'))) {
// really it's BGRA, so this needs correction in shader
// If iOS and video is HLS, do some hacks.
if (this.sceneEl.isIOS &&
isHLS(videoEl.src || videoEl.getAttribute('src'),
videoEl.type || videoEl.getAttribute('type'))) {
// Actually BGRA. Tell shader to correct later.
texture.format = THREE.RGBAFormat;
texture.needsCorrectionBGRA = true;
// apparently this is needed for HLS, so this needs correction in shader
// Apparently needed for HLS. Tell shader to correct later.
texture.flipY = false;
texture.needsCorrectionFlipY = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/material.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function handleTextureEvents (el, texture) {
// Check to see if we need to use iOS 10 HLS shader.
// Only override the shader if it is a stock (or test) shader that we know doesn't correct.
if (texture.needsCorrectionBGRA && texture.needsCorrectionFlipY &&
['standard', 'flat', 'testShader'].indexOf(el.components.material.data.shader) !== -1) {
['standard', 'flat'].indexOf(el.components.material.data.shader) !== -1) {
el.setAttribute('material', 'shader', 'ios10hls');
}

Expand Down
34 changes: 34 additions & 0 deletions tests/shaders/ios10hls.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* global AFRAME, CustomEvent, assert, process, setup, suite, test */
var entityFactory = require('../helpers').entityFactory;

var VIDEO = 'base/tests/assets/test.mp4';

suite('ios10hls', function () {
setup(function (done) {
this.el = entityFactory();
if (this.el.hasLoaded) {
done();
} else {
this.el.addEventListener('loaded', function () { done(); });
}
});

test('iOS HLS video uses appropriate shader', function (done) {
var el = this.el;
el.sceneEl.isIOS = true;

// Set up and verify video element to be treated as HLS.
var videoEl = document.createElement('video');
videoEl.src = VIDEO;
videoEl.type = 'application/x-mpegurl';
assert.equal(AFRAME.utils.material.isHLS(videoEl.src, videoEl.type), true);

el.setAttribute('material', {src: videoEl});
videoEl.dispatchEvent(new CustomEvent('loadeddata'));

setTimeout(function () {
assert.equal(el.getAttribute('material').shader, 'ios10hls');
done();
});
});
});

0 comments on commit a2d641a

Please sign in to comment.