Skip to content

Commit

Permalink
Better handle AVPro texture workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
JLChnToZ committed Jan 30, 2024
1 parent 8a72f4d commit a956ba1
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions Packages/idv.jlchntoz.vvmw/Runtime/VVMW/VideoPlayerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public float Time {

public float Duration => isRTSP ? float.PositiveInfinity : videoPlayer.GetDuration();

public Texture Texture => bufferedTexture != null ? bufferedTexture : texture;
public Texture Texture => texture != null && bufferedTexture != null ? bufferedTexture : texture;

public AudioSource PrimaryAudioSource => primaryAudioSource;

Expand Down Expand Up @@ -96,29 +96,33 @@ public void _GetTexture() {
}
if (texture != null) {
isWaitingForTexture = false;
if (isAvPro && useFlickerWorkaround && !isFlickerWorkaroundTextureRunning && blitMaterial != null) {
isFlickerWorkaroundTextureRunning = true;
SendCustomEventDelayedFrames(nameof(_BlitBufferScreen), 0, EventTiming.LateUpdate);
}
BlitBufferScreen();
core._OnTextureChanged();
} else
SendCustomEventDelayedSeconds(nameof(_GetTexture), 0.2F);
}

// Experimental workaround for AVPro screen flickering issue.
void BlitBufferScreen() {
if (!isAvPro || !useFlickerWorkaround || isFlickerWorkaroundTextureRunning ||
isPaused || blitMaterial == null || texture == null || !videoPlayer.IsPlaying)
return;
isFlickerWorkaroundTextureRunning = true;
SendCustomEventDelayedFrames(nameof(_BlitBufferScreen), 0, EventTiming.LateUpdate);
if (bufferedTexture != null && texture.width == bufferedTexture.width && texture.height == bufferedTexture.height)
return;
Debug.Log($"[VVMW] Released temporary render texture for {playerName}.");
VRCRenderTexture.ReleaseTemporary(bufferedTexture);
bufferedTexture = null;
}

public void _BlitBufferScreen() {
if (!isActive || !videoPlayer.IsPlaying || texture == null) {
if (!isActive || isPaused || !videoPlayer.IsPlaying || texture == null) {
isFlickerWorkaroundTextureRunning = false;
return;
}
SendCustomEventDelayedFrames(nameof(_BlitBufferScreen), 0, EventTiming.LateUpdate);
int width = texture.width, height = texture.height;
if (bufferedTexture != null && (bufferedTexture.width != width || bufferedTexture.height != height)) {
Debug.Log($"[VVMW] The size of temporary render texture for {playerName} has changed, releasing the old one.");
VRCRenderTexture.ReleaseTemporary(bufferedTexture);
bufferedTexture = null;
}
if (bufferedTexture == null) {
int width = texture.width, height = texture.height;
Debug.Log($"[VVMW] Created temporary render texture for {playerName}: {width}x{height}");
bufferedTexture = VRCRenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGB64, RenderTextureReadWrite.sRGB, 1);
bufferedTexture.filterMode = FilterMode.Bilinear;
Expand Down Expand Up @@ -192,6 +196,7 @@ public override void OnVideoStart() {
public override void OnVideoPlay() {
isPaused = false;
if (!isActive) return;
BlitBufferScreen();
core.OnVideoPlay();
}

Expand Down

0 comments on commit a956ba1

Please sign in to comment.