forked from libgdx/gdx-video
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add setFilter to video player, create AbstractVideoPlayer
- Loading branch information
1 parent
4b7f515
commit e543296
Showing
7 changed files
with
73 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,20 +36,18 @@ | |
import com.badlogic.gdx.files.FileHandle; | ||
import com.badlogic.gdx.graphics.GL20; | ||
import com.badlogic.gdx.graphics.Pixmap; | ||
import com.badlogic.gdx.graphics.Texture; | ||
import com.badlogic.gdx.graphics.glutils.FrameBuffer; | ||
import com.badlogic.gdx.graphics.glutils.ImmediateModeRenderer20; | ||
import com.badlogic.gdx.graphics.glutils.ShaderProgram; | ||
import com.badlogic.gdx.math.Matrix4; | ||
import com.badlogic.gdx.utils.Null; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
|
||
/** Android implementation of the VideoPlayer class. | ||
* | ||
* @author Rob Bogie <[email protected]> */ | ||
public class VideoPlayerAndroid implements VideoPlayer, OnFrameAvailableListener { | ||
public class VideoPlayerAndroid extends AbstractVideoPlayer implements VideoPlayer, OnFrameAvailableListener { | ||
//@off | ||
String vertexShaderCode = | ||
"#define highp\n" + | ||
|
@@ -78,7 +76,6 @@ public class VideoPlayerAndroid implements VideoPlayer, OnFrameAvailableListener | |
private final int[] textures = new int[1]; | ||
private SurfaceTexture videoTexture; | ||
private FrameBuffer fbo; | ||
private Texture frame; | ||
private ImmediateModeRenderer20 renderer; | ||
|
||
private MediaPlayer player; | ||
|
@@ -231,20 +228,15 @@ public boolean update () { | |
renderer.vertex(1, 1, 0); | ||
renderer.end(); | ||
fbo.end(); | ||
frame = fbo.getColorBufferTexture(); | ||
texture = fbo.getColorBufferTexture(); | ||
texture.setFilter(minFilter, magFilter); | ||
} | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
@Null | ||
public Texture getTexture () { | ||
return frame; | ||
} | ||
|
||
/** For android, this will return whether the prepareAsync method of the android MediaPlayer is done with preparing. | ||
* | ||
* @return whether the buffer is filled. */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,15 +25,13 @@ | |
import com.badlogic.gdx.graphics.GL20; | ||
import com.badlogic.gdx.graphics.Pixmap.Format; | ||
import com.badlogic.gdx.graphics.Texture; | ||
import com.badlogic.gdx.utils.Null; | ||
import com.badlogic.gdx.video.VideoDecoder.VideoDecoderBuffers; | ||
|
||
/** Desktop implementation of the VideoPlayer | ||
* | ||
* @author Rob Bogie [email protected] */ | ||
abstract public class CommonVideoPlayerDesktop implements VideoPlayer { | ||
abstract public class CommonVideoPlayerDesktop extends AbstractVideoPlayer implements VideoPlayer { | ||
VideoDecoder decoder; | ||
Texture texture; | ||
Music audio; | ||
long startTime = 0; | ||
boolean showAlreadyDecodedFrame = false; | ||
|
@@ -135,7 +133,10 @@ public boolean update () { | |
if (!showAlreadyDecodedFrame) { | ||
ByteBuffer videoData = decoder.nextVideoFrame(); | ||
if (videoData != null) { | ||
if (texture == null) texture = new Texture(getTextureWidth(), getTextureHeight(), Format.RGB888); | ||
if (texture == null) { | ||
texture = new Texture(getTextureWidth(), getTextureHeight(), Format.RGB888); | ||
texture.setFilter(minFilter, magFilter); | ||
} | ||
texture.bind(); | ||
Gdx.gl.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGB, getTextureWidth(), getTextureHeight(), 0, GL20.GL_RGB, | ||
GL20.GL_UNSIGNED_BYTE, videoData); | ||
|
@@ -168,12 +169,6 @@ public boolean update () { | |
return false; | ||
} | ||
|
||
@Override | ||
@Null | ||
public Texture getTexture () { | ||
return texture; | ||
} | ||
|
||
/** Will return whether the buffer is filled. At the time of writing, the buffer used can store 10 frames of video. You can | ||
* find the value in jni/VideoDecoder.h | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ | |
/** iOS implementation of the VideoPlayer class. | ||
* | ||
* @author Maximilian Wende <[email protected]> */ | ||
public class VideoPlayerIos implements VideoPlayer { | ||
public class VideoPlayerIos extends AbstractVideoPlayer implements VideoPlayer { | ||
|
||
protected FileHandle file; | ||
protected AVAsset asset; | ||
|
@@ -74,7 +74,6 @@ public class VideoPlayerIos implements VideoPlayer { | |
CMVideoFormatDescription videoFormat; | ||
CMVideoDimensions videoDimensions; | ||
AVPlayerItemVideoOutput videoOutput; | ||
private Texture texture; | ||
|
||
/* --- Audio --- */ | ||
AVAssetTrack audioTrack; | ||
|
@@ -203,6 +202,7 @@ protected void updateTextureFromBuffer (CVImageBuffer buffer) { | |
int texHeight = (int)(pixelBuffer.getDataSize() / bpr); | ||
if (texture == null) { | ||
texture = new Texture(texWidth, texHeight, Pixmap.Format.RGB888); | ||
texture.setFilter(minFilter, magFilter); | ||
} | ||
texture.bind(); | ||
pixelBuffer.lockBaseAddress(CVPixelBufferLockFlags.ReadOnly); | ||
|
@@ -224,11 +224,6 @@ public boolean update () { | |
return true; | ||
} | ||
|
||
@Override | ||
public Texture getTexture () { | ||
return texture; | ||
} | ||
|
||
@Override | ||
public boolean isBuffered () { | ||
return playerIsPrerolled; | ||
|
42 changes: 42 additions & 0 deletions
42
gdx-video/src/com/badlogic/gdx/video/AbstractVideoPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/******************************************************************************* | ||
* Copyright 2023 See AUTHORS file. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
******************************************************************************/ | ||
|
||
package com.badlogic.gdx.video; | ||
|
||
import com.badlogic.gdx.graphics.Texture; | ||
import com.badlogic.gdx.graphics.Texture.TextureFilter; | ||
import com.badlogic.gdx.utils.Null; | ||
|
||
public abstract class AbstractVideoPlayer implements VideoPlayer { | ||
protected Texture texture; | ||
protected TextureFilter minFilter = TextureFilter.Linear; | ||
protected TextureFilter magFilter = TextureFilter.Linear; | ||
|
||
@Null | ||
@Override | ||
public final Texture getTexture () { | ||
return texture; | ||
} | ||
|
||
@Override | ||
public void setFilter (TextureFilter minFilter, TextureFilter magFilter) { | ||
if (this.minFilter == minFilter && this.magFilter == magFilter) return; | ||
this.minFilter = minFilter; | ||
this.magFilter = magFilter; | ||
if (texture == null) return; | ||
texture.setFilter(minFilter, magFilter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters