Skip to content

Commit

Permalink
Bug 885 - GLMediaPlayer: Allow single threaded mode - Especially wher…
Browse files Browse the repository at this point in the history
…e multiple media textures (Android) or shared GL context are not usable.

- GLMediaPlayer:
  - TEXTURE_COUNT_MIN is the new minimum: '1' - i.e. no multithreading, single threaded player
  - TEXTURE_COUNT_DEFAULT is '4' - multithreaded

- GLMediaPlayerImpl:
  - Add Single threaded mode, but perform initStreamImpl(..) off-thread.
  -
  • Loading branch information
sgothel committed Nov 1, 2013
1 parent 33db458 commit f4574bf
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 112 deletions.
3 changes: 2 additions & 1 deletion make/scripts/adb-launch-activity.sh
Expand Up @@ -2,7 +2,8 @@

#ANAME="com.jogamp.opengl.test/com.jogamp.opengl.test.android.NEWTGenericActivity"
#ANAME="com.jogamp.android.launcher/com.jogamp.android.launcher.NEWTLauncherActivity2"
ANAME="com.jogamp.opengl.test/com.jogamp.opengl.test.android.NEWTGearsES2ActivityLauncher"
#ANAME="com.jogamp.opengl.test/com.jogamp.opengl.test.android.NEWTGearsES2ActivityLauncher"
ANAME="com.jogamp.opengl.test/com.jogamp.opengl.test.android.MovieCubeActivityLauncher0"

adb $* shell "setprop log.redirect-stdio true ; setprop log.redirect-stderr true ; \
am start -a android.intent.action.MAIN -n $ANAME"
Expand Down
6 changes: 3 additions & 3 deletions make/scripts/tests.sh
Expand Up @@ -136,7 +136,7 @@ function jrun() {
#D_ARGS="-Djogl.debug.DebugGL -Djogl.debug.TraceGL -Djogl.debug.GLContext.TraceSwitch -Djogl.debug=all"
#D_ARGS="-Djogamp.debug.IOUtil -Djogl.debug.GLSLCode -Djogl.debug.GLMediaPlayer"
#D_ARGS="-Djogl.debug.GLMediaPlayer -Djogl.debug.AudioSink"
#D_ARGS="-Djogl.debug.GLMediaPlayer -Djogl.debug.GLMediaPlayer.Native"
D_ARGS="-Djogl.debug.GLMediaPlayer -Djogl.debug.GLMediaPlayer.Native"
#D_ARGS="-Djogl.debug.GLMediaPlayer"
#D_ARGS="-Djogl.debug.GLMediaPlayer.StreamWorker.delay=25 -Djogl.debug.GLMediaPlayer"
#D_ARGS="-Djogl.debug.GLMediaPlayer.Native"
Expand Down Expand Up @@ -328,7 +328,7 @@ function testawtswt() {
# av demos
#
#testnoawt jogamp.opengl.openal.av.ALDummyUsage $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube $*
testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieCube $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.av.MovieSimple $*

#
Expand Down Expand Up @@ -375,7 +375,7 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestBug669RecursiveGLContext01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestBug669RecursiveGLContext02NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestBug692GL3VAONEWT $*
testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestCPUSourcingAPINEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestCPUSourcingAPINEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLExtensionQueryOffscreen $*

#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestSharedContextListNEWT $*
Expand Down
9 changes: 6 additions & 3 deletions src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java
Expand Up @@ -186,8 +186,11 @@ public interface GLMediaPlayer extends TextureSequence {
public static final boolean DEBUG = Debug.debug("GLMediaPlayer");
public static final boolean DEBUG_NATIVE = Debug.debug("GLMediaPlayer.Native");

/** Minimum texture count, value {@value}. */
public static final int TEXTURE_COUNT_MIN = 4;
/** Default texture count, value {@value}. */
public static final int TEXTURE_COUNT_DEFAULT = 4;

/** Minimum texture count, value {@value}. Using the minimum texture count disables multi-threaded decoding. */
public static final int TEXTURE_COUNT_MIN = 1;

/** Constant {@value} for <i>mute</i> or <i>not available</i>. See <a href="#streamIDs">Audio and video Stream IDs</a>. */
public static final int STREAM_ID_NONE = -2;
Expand Down Expand Up @@ -350,7 +353,7 @@ public enum State {
* @param vid video stream id, see <a href="#streamIDs">audio and video Stream IDs</a>
* @param aid video stream id, see <a href="#streamIDs">audio and video Stream IDs</a>
* @param textureCount desired number of buffered textures to be decoded off-thread, will be validated by implementation.
* The minimum value is {@link #TEXTURE_COUNT_MIN}.
* The minimum value is {@link #TEXTURE_COUNT_DEFAULT}.
* Ignored if video is muted.
* @throws IllegalStateException if not invoked in {@link State#Uninitialized}
* @throws IllegalArgumentException if arguments are invalid
Expand Down
Expand Up @@ -56,6 +56,11 @@
* Android implementation utilizes API level 14 (4.0.? ICS) features
* as listed below.
* <p>
* Implementation is single threaded only, since we are not able to utilize multiple textures.
* We would need to add an implementation for API level 16 using MediaCodec/MediaExtractor
* to expose multithreading on multiple surface/textures.
* </p>
* <p>
* We utilize the {@link MediaPlayer} with direct to texture streaming.
* The MediaPlayer uses <code>libstagefright</code> to access the OpenMAX AL implementation
* for hardware decoding.
Expand Down Expand Up @@ -248,8 +253,7 @@ public String toString() {
}

@Override
protected final void initStreamImpl(int vid, int aid) throws IOException {

protected final void initStreamImpl(final int vid, final int aid) throws IOException {
if( null == streamLoc ) {
return;
}
Expand Down Expand Up @@ -297,6 +301,21 @@ protected final void initStreamImpl(int vid, int aid) throws IOException {
mp.getVideoWidth(), mp.getVideoHeight(), 0,
0, 0, 0f,
0, 0, mp.getDuration(), icodec, icodec);
/**
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(final MediaPlayer mp) {
final int r_aid = GLMediaPlayer.STREAM_ID_NONE == aid ? GLMediaPlayer.STREAM_ID_NONE : 1; // fake
final String icodec = "android";
updateAttributes(0, r_aid, // fake
mp.getVideoWidth(), mp.getVideoHeight(), 0,
0, 0, 0f,
0, 0, mp.getDuration(), icodec, icodec);
}
});
mp.prepareAsync();
*
*/
} else if( null != cam ) {
final String icodec = "android";
final int[] fpsRange = { 0, 0 };
Expand Down Expand Up @@ -336,23 +355,20 @@ protected final void initGLImpl(GL gl) throws IOException, GLException {
/**
* {@inheritDoc}
* <p>
* Returns 2 - implementation duplicates single texture
* Returns {@link #TEXTURE_COUNT_MIN}, using a single texture
* </p>
*/
@Override
protected int validateTextureCount(int desiredTextureCount) {
return 2;
return TEXTURE_COUNT_MIN;
}

@Override
protected final int getNextTextureImpl(GL gl, TextureFrame nextFrame) {
int pts = TimeFrameI.INVALID_PTS;
if(null != mp || null != cam) {
final SurfaceTextureFrame sTexFrame = (SurfaceTextureFrame) nextFrame;
final SurfaceTextureFrame sTexFrame = null != nextFrame ? (SurfaceTextureFrame) nextFrame : singleSTexFrame;
final SurfaceTexture surfTex = sTexFrame.surfaceTex;
if( sTexFrame != singleSTexFrame ) {
throw new InternalError("XXX: sTexFrame: "+sTexFrame+", singleSTexFrame "+singleSTexFrame);
}
if( !sTexFrameAttached ) {
sTexFrameAttached = true;
final Surface surface;
Expand Down

0 comments on commit f4574bf

Please sign in to comment.