Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
Hubs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ar-noc
Hubs
Commits
da53bb74
Unverified
Commit
da53bb74
authored
6 years ago
by
Dominick D'Aniello
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #525 from mozilla/feature/multiple-video-fix
Don't use TextureCache for videos
parents
4655c70a
c170dd7a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/components/media-views.js
+29
-28
29 additions, 28 deletions
src/components/media-views.js
with
29 additions
and
28 deletions
src/components/media-views.js
+
29
−
28
View file @
da53bb74
...
@@ -161,6 +161,16 @@ function createImageTexture(url) {
...
@@ -161,6 +161,16 @@ function createImageTexture(url) {
});
});
}
}
function
disposeTexture
(
texture
)
{
if
(
texture
.
image
instanceof
HTMLVideoElement
)
{
const
video
=
texture
.
image
;
video
.
pause
();
video
.
src
=
""
;
video
.
load
();
}
texture
.
dispose
();
}
class
TextureCache
{
class
TextureCache
{
cache
=
new
Map
();
cache
=
new
Map
();
...
@@ -193,13 +203,7 @@ class TextureCache {
...
@@ -193,13 +203,7 @@ class TextureCache {
// console.log("release", src, cacheItem.count);
// console.log("release", src, cacheItem.count);
if
(
cacheItem
.
count
<=
0
)
{
if
(
cacheItem
.
count
<=
0
)
{
// Unload the video element to prevent it from continuing to play in the background
// Unload the video element to prevent it from continuing to play in the background
if
(
cacheItem
.
texture
.
image
instanceof
HTMLVideoElement
)
{
disposeTexture
(
cacheItem
.
texture
);
const
video
=
cacheItem
.
texture
.
image
;
video
.
pause
();
video
.
src
=
""
;
video
.
load
();
}
cacheItem
.
texture
.
dispose
();
this
.
cache
.
delete
(
src
);
this
.
cache
.
delete
(
src
);
}
}
}
}
...
@@ -253,8 +257,12 @@ AFRAME.registerComponent("media-video", {
...
@@ -253,8 +257,12 @@ AFRAME.registerComponent("media-video", {
},
},
remove
()
{
remove
()
{
if
(
this
.
data
.
src
)
{
if
(
this
.
mesh
&&
this
.
mesh
.
material
)
{
textureCache
.
release
(
this
.
data
.
src
);
disposeTexture
(
this
.
mesh
.
material
.
map
);
}
if
(
this
.
video
)
{
this
.
video
.
removeEventListener
(
"
pause
"
,
this
.
onPauseStateChange
);
this
.
video
.
removeEventListener
(
"
play
"
,
this
.
onPauseStateChange
);
}
}
},
},
...
@@ -265,24 +273,19 @@ AFRAME.registerComponent("media-video", {
...
@@ -265,24 +273,19 @@ AFRAME.registerComponent("media-video", {
async
updateTexture
(
src
)
{
async
updateTexture
(
src
)
{
let
texture
;
let
texture
;
try
{
try
{
if
(
textureCache
.
has
(
src
))
{
texture
=
await
createVideoTexture
(
src
);
texture
=
textureCache
.
retain
(
src
);
}
else
{
texture
=
await
createVideoTexture
(
src
);
texture
.
audioSource
=
this
.
el
.
sceneEl
.
audioListener
.
context
.
createMediaElementSource
(
texture
.
image
);
this
.
video
=
texture
.
image
;
this
.
video
.
addEventListener
(
"
pause
"
,
this
.
onPauseStateChange
);
// No way to cancel promises, so if src has changed while we were creating the texture just throw it away.
this
.
video
.
addEventListener
(
"
play
"
,
this
.
onPauseStateChange
);
if
(
this
.
data
.
src
!==
src
)
{
disposeTexture
(
texture
);
return
;
}
textureCache
.
set
(
src
,
texture
);
texture
.
audioSource
=
this
.
el
.
sceneEl
.
audioListener
.
context
.
createMediaElementSource
(
texture
.
image
);
this
.
video
=
texture
.
image
;
// No way to cancel promises, so if src has changed while we were creating the texture just throw it away.
this
.
video
.
addEventListener
(
"
pause
"
,
this
.
onPauseStateChange
);
if
(
this
.
data
.
src
!==
src
)
{
this
.
video
.
addEventListener
(
"
play
"
,
this
.
onPauseStateChange
);
textureCache
.
release
(
src
);
return
;
}
}
const
sound
=
new
THREE
.
PositionalAudio
(
this
.
el
.
sceneEl
.
audioListener
);
const
sound
=
new
THREE
.
PositionalAudio
(
this
.
el
.
sceneEl
.
audioListener
);
sound
.
setNodeSource
(
texture
.
audioSource
);
sound
.
setNodeSource
(
texture
.
audioSource
);
...
@@ -325,12 +328,10 @@ AFRAME.registerComponent("media-video", {
...
@@ -325,12 +328,10 @@ AFRAME.registerComponent("media-video", {
if
(
!
src
||
src
===
oldData
.
src
)
return
;
if
(
!
src
||
src
===
oldData
.
src
)
return
;
if
(
this
.
mesh
&&
this
.
mesh
.
map
)
{
this
.
remove
();
if
(
this
.
mesh
&&
this
.
mesh
.
material
)
{
this
.
mesh
.
material
.
map
=
null
;
this
.
mesh
.
material
.
map
=
null
;
this
.
mesh
.
material
.
needsUpdate
=
true
;
this
.
mesh
.
material
.
needsUpdate
=
true
;
if
(
this
.
mesh
.
map
!==
errorTexture
)
{
textureCache
.
release
(
oldData
.
src
);
}
}
}
this
.
updateTexture
(
src
);
this
.
updateTexture
(
src
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment