From 5e9c02bce7b241a0bf95c8abca9a91cd25e51ed3 Mon Sep 17 00:00:00 2001
From: Harvey Harrison
* See {@link GLMediaPlayer}.
*
- * AudioSink shall respect texture2D
,
* if not overridden by specialization.
*/
@@ -247,31 +247,31 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer {
checkGLInit();
return "texture2D";
}
-
+
/**
* {@inheritDoc}
- *
- * This implementation simply returns an empty string since it's using
+ *
+ * This implementation simply returns an empty string since it's using
* the build-in function texture2D
,
* if not overridden by specialization.
*/
@Override
public String getTextureLookupFragmentShaderImpl() throws IllegalStateException {
checkGLInit();
- return "";
+ return "";
}
-
+
@Override
public final int getDecodedFrameCount() { return decodedFrameCount; }
-
+
@Override
public final int getPresentedFrameCount() { return presentedFrameCount; }
-
+
@Override
public final int getVideoPTS() { return video_pts_last; }
-
+
@Override
- public final int getAudioPTS() {
+ public final int getAudioPTS() {
if( State.Uninitialized != state ) {
return getAudioPTSImpl();
}
@@ -285,10 +285,10 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer {
return 0;
}
}
-
+
@Override
public final State getState() { return state; }
-
+
@Override
public final State play() {
synchronized( stateLock ) {
@@ -310,7 +310,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer {
}
}
protected abstract boolean playImpl();
-
+
@Override
public final State pause(boolean flush) {
return pauseImpl(flush, 0);
@@ -337,7 +337,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer {
}
}
protected abstract boolean pauseImpl();
-
+
@Override
public final State destroy(GL gl) {
return destroyImpl(gl, 0);
@@ -354,7 +354,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer {
}
}
protected abstract void destroyImpl(GL gl);
-
+
@Override
public final int seek(int msec) {
synchronized( stateLock ) {
@@ -383,12 +383,12 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer {
}
}
protected abstract int seekImpl(int msec);
-
+
@Override
public final float getPlaySpeed() {
return playSpeed;
}
-
+
@Override
public final boolean setPlaySpeed(float rate) {
synchronized( stateLock ) {
@@ -410,18 +410,18 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer {
return res;
}
}
- /**
+ /**
* Override if not using AudioSink, or AudioSink's {@link AudioSink#setPlaySpeed(float)} is not sufficient!
* !audioSinkPlaySpeedSet
to determine data_size
+ * AudioSink shall respect !audioSinkPlaySpeedSet
to determine data_size
* at {@link AudioSink#enqueueData(com.jogamp.opengl.util.av.AudioSink.AudioFrame)}.
- *
* Shall also take care of {@link AudioSink} initialization if appropriate. @@ -593,8 +593,8 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { * @throws GLException */ protected abstract void initGLImpl(GL gl) throws IOException, GLException; - - /** + + /** * Returns the validated number of textures to be handled. *
* Default is {@link #TEXTURE_COUNT_MIN} minimum textures. @@ -606,7 +606,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { protected int validateTextureCount(int desiredTextureCount) { return desiredTextureCount < TEXTURE_COUNT_MIN ? TEXTURE_COUNT_MIN : desiredTextureCount; } - + protected TextureFrame[] createTexFrames(GL gl, final int count) { final int[] texNames = new int[count]; gl.glGenTextures(count, texNames, 0); @@ -621,7 +621,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { return texFrames; } protected abstract TextureFrame createTexImage(GL gl, int texName); - + protected final Texture createTexImageImpl(GL gl, int texName, int tWidth, int tHeight) { if( 0 > texName ) { throw new RuntimeException("TextureName "+toHexString(texName)+" invalid."); @@ -661,19 +661,19 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } } gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MIN_FILTER, texMinMagFilter[0]); - gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MAG_FILTER, texMinMagFilter[1]); + gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_MAG_FILTER, texMinMagFilter[1]); gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_S, texWrapST[0]); gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_T, texWrapST[1]); - + return com.jogamp.opengl.util.texture.TextureIO.newTexture( texName, textureTarget, tWidth, tHeight, width, height, - !isInGLOrientation); + !isInGLOrientation); } - + protected void destroyTexFrame(GL gl, TextureFrame frame) { - frame.getTexture().destroy(gl); + frame.getTexture().destroy(gl); } @Override @@ -683,7 +683,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } return lastFrame; } - + private final void removeAllTextureFrames(GL gl) { final TextureFrame[] texFrames = videoFramesOrig; videoFramesOrig = null; @@ -699,14 +699,14 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } texFrames[i] = null; } - System.err.println(Thread.currentThread().getName()+"> Clear TexFrame["+i+"]: "+frame+" -> null"); - } + System.err.println(Thread.currentThread().getName()+"> Clear TexFrame["+i+"]: "+frame+" -> null"); + } } } - + protected TextureFrame cachedFrame = null; protected long lastTimeMillis = 0; - + @Override public final TextureFrame getNextTexture(GL gl) throws IllegalStateException { synchronized( stateLock ) { @@ -750,7 +750,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } else { d_apts = 0; } - + final int frame_period_last = video_pts - video_pts_last; // rendering loop interrupted ? if( videoSCR_reset || frame_period_last > frame_duration*10 ) { videoSCR_reset = false; @@ -782,7 +782,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { cachedFrame = nextFrame; nextFrame = null; } else if ( !droppedFrame && dt < -maxVideoDelay && videoFramesDecoded.size() > 0 ) { - // only drop if prev. frame has not been dropped and + // only drop if prev. frame has not been dropped and // frame is too late and one decoded frame is already available. dropFrame = true; } @@ -791,7 +791,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { System.err.println( "AV_: dT "+(currentTimeMillis-lastTimeMillis)+", "+ getPerfStringImpl( video_scr, video_pts, d_vpts, audio_scr, audio_pts, d_apts, - video_dpts_avg_diff ) + + video_dpts_avg_diff ) + ", avg dpy-fps "+avg_dpy_duration+" ms/f, maxD "+maxVideoDelay+" ms, "+_nextFrame+", playCached " + playCached + ", dropFrame "+dropFrame); } } @@ -803,7 +803,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { lastFrame = nextFrame; videoFramesFree.putBlocking(_lastFrame); } - } else if( DEBUG ) { + } else if( DEBUG ) { final int video_pts = lastFrame.getPTS(); final int audio_pts = getAudioPTSImpl(); final int audio_scr = (int) ( ( currentTimeMillis - audio_scr_t0 ) * playSpeed ); @@ -835,25 +835,25 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { * Audio frames, i.e. {@link AudioSink.AudioFrame}, shall be handled in the process. *
* Video frames shall be ignored, if {@link #getVID()} is {@link #STREAM_ID_NONE}. - *
+ * ** Audio frames shall be ignored, if {@link #getAID()} is {@link #STREAM_ID_NONE}. *
** Method may be invoked on the StreamWorker decoding thread. - *
+ * ** Implementation shall care of OpenGL synchronization as required, e.g. glFinish()/glFlush()! *
- * @param gl valid and current GL instance, shall benull
for audio only.
+ * @param gl valid and current GL instance, shall be null
for audio only.
* @param nextFrame the {@link TextureFrame} to store the video PTS and texture data,
* shall be null
for audio only.
* @return the last processed video PTS value, maybe {@link TimeFrameI#INVALID_PTS} if video frame is invalid or n/a.
- * Will be {@link TimeFrameI#END_OF_STREAM_PTS} if end of stream reached.
+ * Will be {@link TimeFrameI#END_OF_STREAM_PTS} if end of stream reached.
*/
protected abstract int getNextTextureImpl(GL gl, TextureFrame nextFrame);
-
- /**
+
+ /**
* {@inheritDoc}
* * Note: All {@link AudioSink} operations are performed from {@link GLMediaPlayerImpl}, @@ -866,8 +866,8 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { */ @Override public final AudioSink getAudioSink() { return audioSink; } - - /** + + /** * To be called from implementation at 1st PTS after start * w/ current pts value in milliseconds. * @param audio_scr_t0 @@ -908,10 +908,10 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { private final int getVideoDPTSAvg() { return (int) ( video_dpts_cum * (1.0f - VIDEO_DPTS_COEFF) + 0.5f ); } - + private final void newFrameAvailable(TextureFrame frame, long currentTimeMillis) { decodedFrameCount++; - if( 0 == frame.getDuration() ) { // patch frame duration if not set already + if( 0 == frame.getDuration() ) { // patch frame duration if not set already frame.setDuration( (int) frame_duration ); } synchronized(eventListenersLock) { @@ -920,38 +920,38 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } } } - + class StreamWorker extends Thread { private volatile boolean isRunning = false; private volatile boolean isActive = false; private volatile boolean isBlocked = false; - + private volatile boolean shallPause = true; private volatile boolean shallStop = false; - + private volatile StreamException streamErr = null; private volatile GLContext sharedGLCtx = null; private boolean sharedGLCtxCurrent = false; private GLDrawable dummyDrawable = null; - - /** - * Starts this daemon thread, + + /** + * Starts this daemon thread, * which initializes the stream first via {@link GLMediaPlayerImpl#initStreamImpl(int, int)} first. *
* After stream initialization, this thread pauses! *
- **/ + **/ StreamWorker() { setDaemon(true); start(); } - + private void makeCurrent(GLContext ctx) { if( GLContext.CONTEXT_NOT_CURRENT >= ctx.makeCurrent() ) { throw new GLException("Couldn't make ctx current: "+ctx); } } - + private void destroySharedGL() { if( null != sharedGLCtx ) { if( sharedGLCtx.isCreated() ) { @@ -963,16 +963,16 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { gle.printStackTrace(); } } - sharedGLCtx = null; + sharedGLCtx = null; } if( null != dummyDrawable ) { final AbstractGraphicsDevice device = dummyDrawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(); dummyDrawable.setRealized(false); dummyDrawable = null; device.close(); - } + } } - + public synchronized void initGL(GL gl) { final GLContext glCtx = gl.getContext(); final boolean glCtxCurrent = glCtx.isCurrent(); @@ -1013,7 +1013,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { while( !isActive ) { this.notify(); // wake-up pause-block try { - this.wait(); // wait until resumed + this.wait(); // wait until resumed } catch (InterruptedException e) { e.printStackTrace(); } @@ -1041,12 +1041,12 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } public boolean isRunning() { return isRunning; } public boolean isActive() { return isActive; } - public StreamException getStreamErr() { return streamErr; } - + public StreamException getStreamErr() { return streamErr; } + public void run() { setName(getName()+"-StreamWorker_"+StreamWorkerInstanceId); StreamWorkerInstanceId++; - + synchronized ( this ) { isRunning = true; try { @@ -1061,7 +1061,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { return; // end of thread! } // also initializes width, height, .. etc } - + while( !shallStop ){ if( shallPause ) { synchronized ( this ) { @@ -1100,7 +1100,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } } } - + if( !shallStop ) { TextureFrame nextFrame = null; try { @@ -1121,7 +1121,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { Thread.sleep(STREAM_WORKER_DELAY); } if( !videoFramesDecoded.put(nextFrame) ) { - throw new InternalError("XXX: free "+videoFramesFree+", decoded "+videoFramesDecoded+", "+GLMediaPlayerImpl.this); + throw new InternalError("XXX: free "+videoFramesFree+", decoded "+videoFramesDecoded+", "+GLMediaPlayerImpl.this); } newFrameAvailable(nextFrame, Platform.currentTimeMillis()); nextFrame = null; @@ -1170,10 +1170,10 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { this.notify(); // wake-up doStop() } } - } - static int StreamWorkerInstanceId = 0; + } + static int StreamWorkerInstanceId = 0; private StreamWorker streamWorker = null; - + protected final int addStateEventMask(int event_mask, State newState) { if( state != newState ) { switch( newState ) { @@ -1193,7 +1193,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } return event_mask; } - + protected final void attributesUpdated(int event_mask) { if( 0 != event_mask ) { final long now = Platform.currentTimeMillis(); @@ -1204,7 +1204,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } } } - + protected final void changeState(int event_mask, State newState) { event_mask = addStateEventMask(event_mask, newState); if( 0 != event_mask ) { @@ -1212,9 +1212,9 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { attributesUpdated( event_mask ); } } - - protected final void updateAttributes(int vid, int aid, int width, int height, int bps_stream, - int bps_video, int bps_audio, float fps, + + protected final void updateAttributes(int vid, int aid, int width, int height, int bps_stream, + int bps_video, int bps_audio, float fps, int videoFrames, int audioFrames, int duration, String vcodec, String acodec) { int event_mask = 0; if( state == State.Uninitialized ) { @@ -1227,19 +1227,19 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { if( this.vid != vid ) { event_mask |= GLMediaEventListener.EVENT_CHANGE_VID; this.vid = vid; - } + } if( STREAM_ID_AUTO == vid ) { vid = STREAM_ID_NONE; } if( this.aid != aid ) { event_mask |= GLMediaEventListener.EVENT_CHANGE_AID; this.aid = aid; - } + } if( this.width != width || this.height != height ) { event_mask |= GLMediaEventListener.EVENT_CHANGE_SIZE; this.width = width; this.height = height; - } + } if( this.fps != fps ) { event_mask |= GLMediaEventListener.EVENT_CHANGE_FPS; this.fps = fps; @@ -1257,7 +1257,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { this.audioFrames = audioFrames; this.duration = duration; } - if( (null!=acodec && acodec.length()>0 && !this.acodec.equals(acodec)) ) { + if( (null!=acodec && acodec.length()>0 && !this.acodec.equals(acodec)) ) { event_mask |= GLMediaEventListener.EVENT_CHANGE_CODEC; this.acodec = acodec; } @@ -1283,7 +1283,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { attributesUpdated(GLMediaEventListener.EVENT_CHANGE_SIZE); } } - + @Override public final URI getURI() { return streamLoc; @@ -1291,10 +1291,10 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { @Override public final int getVID() { return vid; } - + @Override public final int getAID() { return aid; } - + @Override public final String getVideoCodec() { return vcodec; @@ -1309,7 +1309,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { public final int getVideoFrames() { return videoFrames; } - + @Override public final int getAudioFrames() { return audioFrames; @@ -1319,7 +1319,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { public final int getDuration() { return duration; } - + @Override public final long getStreamBitrate() { return bps_stream; @@ -1329,12 +1329,12 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { public final int getVideoBitrate() { return bps_video; } - + @Override public final int getAudioBitrate() { return bps_audio; } - + @Override public final float getFramerate() { return fps; @@ -1344,7 +1344,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { public final boolean isGLOriented() { return isInGLOrientation; } - + @Override public final int getWidth() { return width; @@ -1369,11 +1369,11 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { "Video[id "+vid+", <"+vcodec+">, "+width+"x"+height+", glOrient "+isInGLOrientation+", "+fps+" fps, "+frame_duration+" fdur, "+bps_video+" bps], "+ "Audio[id "+aid+", <"+acodec+">, "+bps_audio+" bps, "+audioFrames+" frames], uri "+loc+camPath+"]"; } - + @Override public final String getPerfString() { final long currentTimeMillis = Platform.currentTimeMillis(); - final int video_scr = video_scr_pts + (int) ( ( currentTimeMillis - video_scr_t0 ) * playSpeed ); + final int video_scr = video_scr_pts + (int) ( ( currentTimeMillis - video_scr_t0 ) * playSpeed ); final int d_vpts = video_pts_last - video_scr; final int audio_scr = (int) ( ( currentTimeMillis - audio_scr_t0 ) * playSpeed ); final int audio_pts = getAudioPTSImpl(); @@ -1383,7 +1383,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { private final String getPerfStringImpl(final int video_scr, final int video_pts, final int d_vpts, final int audio_scr, final int audio_pts, final int d_apts, final int video_dpts_avg_diff) { - final float tt = getDuration() / 1000.0f; + final float tt = getDuration() / 1000.0f; final String audioSinkInfo; final AudioSink audioSink = getAudioSink(); if( null != audioSink ) { -- cgit v1.2.3