diff options
author | Sven Gothel <[email protected]> | 2013-08-17 01:30:25 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2013-08-17 01:30:25 +0200 |
commit | 2cb284545a2a0fd35762a104fee8107234808389 (patch) | |
tree | 657e1865c4a941aaee2afaf09f2652c11510034f /src/jogl | |
parent | 3f262a9f4653a09b28a84442378428c18b64775f (diff) |
GLMediaPlayer: Use URI instead of URL / Misc refinements
- GLMediaPlayer: Use URI instead of URL, allowing passing a non resolved location
- Java's URL doesn't allow 'other' protocols, i.e. RTSP
- GLMediaPlayer: Add Table of test streams and their location ..
- FFMPEGMediaPlayer
- Handle av_read_play/pause response on java side, ignore error - simply dump in DEBUG_NATIVE mode
Diffstat (limited to 'src/jogl')
6 files changed, 87 insertions, 54 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java index 1b82bb994..512567f33 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java +++ b/src/jogl/classes/com/jogamp/opengl/util/av/GLMediaPlayer.java @@ -28,7 +28,7 @@ package com.jogamp.opengl.util.av; import java.io.IOException; -import java.net.URLConnection; +import java.net.URI; import javax.media.opengl.GL; import javax.media.opengl.GLException; @@ -42,14 +42,14 @@ import com.jogamp.opengl.util.texture.TextureSequence; * with a video stream as it's source. * <p> * Audio maybe supported and played back internally or via an {@link AudioSink} implementation, - * if an audio stream is selected in {@link #initGLStream(GL, int, URLConnection, int, int)}. + * if an audio stream is selected in {@link #initGLStream(GL, int, URI, int, int)}. * </p> * * <a name="lifecycle"><h5>GLMediaPlayer Lifecycle</h5></a> * <p> * <table border="1"> * <tr><th>action</th> <th>state before</th> <th>state after</th></tr> - * <tr><td>{@link #initGLStream(GL, int, URLConnection, int, int)}</td> <td>Uninitialized</td> <td>Paused</td></tr> + * <tr><td>{@link #initGLStream(GL, int, URI, int, int)}</td> <td>Uninitialized</td> <td>Paused</td></tr> * <tr><td>{@link #play()}</td> <td>Paused</td> <td>Playing</td></tr> * <tr><td>{@link #pause()}</td> <td>Playing</td> <td>Paused</td></tr> * <tr><td>{@link #seek(int)}</td> <td>Playing, Paused</td> <td>Unchanged</td></tr> @@ -121,6 +121,29 @@ import com.jogamp.opengl.util.texture.TextureSequence; * <li>Film: +22ms and -22ms. audio ahead video / audio after video.</li> * </ul> * </p> + * + * <a name="teststreams"><h5>Test Streams</h5></a> + * <p> + * <table border="1"> + * <tr><th colspan=5>Big Buck Bunny 24f 16:9</th></tr> + * <tr><td>Big Buck Bunny</td><td>320p</td><td>h264<td>aac 48000Hz 2 chan</td><td>http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4</td></tr> + * <tr><td>Big Buck Bunny</td><td>720p</td><td>mpeg4<td>ac3 48000Hz 5.1 chan</td><td>http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_720p_surround.avi</td></tr> + * <tr><td>Big Buck Bunny</td><td>720p</td><td>msmpeg4v2<td>mp3 48000Hz 2 chan</td><td>http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_720p_stereo.avi</td></tr> + * <tr><td>Big Buck Bunny</td><td>720p</td><td>theora<td>vorbis 48000Hz 2 chan</td><td>http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_720p_stereo.ogg</td></tr> + * <tr><td>Big Buck Bunny</td><td>1080p</td><td>mpeg4<td>ac3 48000Hz 5.1 chan</td><td>http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_1080p_surround.avi</td></tr> + * <tr><th colspan=5>WebM/Matroska (vp8/vorbis)</th></tr> + * <tr><td>Big Buck Bunny Trailer</td><td>640p</td><td>vp8<td>vorbis 44100Hz 1 chan</td><td>http://video.webmfiles.org/big-buck-bunny_trailer.webm</td></tr> + * <tr><td>Elephants Dream</td><td>540p</td><td>vp8<td>vorbis 44100Hz 1 chan</td><td>http://video.webmfiles.org/elephants-dream.webm</td></tr> + * <tr><th colspan=5>You Tube http/rtsp</th></tr> + * <tr><td>Sintel</td><td colspan=3>http://www.youtube.com/watch?v=eRsGyueVLvQ</td><td>rtsp://v3.cache1.c.youtube.com/CiILENy73wIaGQn0LpXnygYbeRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp</td></tr> + * <tr><th colspan=5>Audio/Video Sync</th></tr> + * <tr><td>Five-minute-sync-test1080p</td><td colspan=3>https://www.youtube.com/watch?v=szoOsG9137U</td><td>rtsp://v7.cache8.c.youtube.com/CiILENy73wIaGQm133VvsA46sxMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp</td></tr> + * <tr><td>Audio-Video-Sync-Test-Calibration-23.98fps-24fps</td><td colspan=4>https://www.youtube.com/watch?v=cGgf_dbDMsw</td></tr> + * <tr><td>sound_in_sync_test</td><td colspan=4>https://www.youtube.com/watch?v=O-zIZkhXNLE</td></tr> + * <!-- <tr><td> title </td><td>1080p</td><td>mpeg4<td>ac3 48000Hz 5.1 chan</td><td> url </td></tr> --> + * <!-- <tr><td> title </td><td colspan=3> url1 </td><td> url2 </td></tr> + * </table> + * </p> */ public interface GLMediaPlayer extends TextureSequence { public static final boolean DEBUG = Debug.debug("GLMediaPlayer"); @@ -186,7 +209,7 @@ public interface GLMediaPlayer extends TextureSequence { * </p> * @param gl current GL object. If null, no video output and textures will be available. * @param textureCount desired number of buffered textures to be decoded off-thread, use <code>1</code> for on-thread decoding. - * @param urlConn the stream connection + * @param streamLoc the stream location * @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> * @return the new state @@ -195,12 +218,12 @@ public interface GLMediaPlayer extends TextureSequence { * @throws IOException in case of difficulties to open or process the stream * @throws GLException in case of difficulties to initialize the GL resources */ - public State initGLStream(GL gl, int textureCount, URLConnection urlConn, int vid, int aid) throws IllegalStateException, GLException, IOException; + public State initGLStream(GL gl, int textureCount, URI streamLoc, int vid, int aid) throws IllegalStateException, GLException, IOException; /** * If implementation uses a {@link AudioSink}, it's instance will be returned. * <p> - * The {@link AudioSink} instance is available after {@link #initGLStream(GL, int, URLConnection, int, int)}, + * The {@link AudioSink} instance is available after {@link #initGLStream(GL, int, URI, int, int)}, * if used by implementation. * </p> */ @@ -308,7 +331,8 @@ public interface GLMediaPlayer extends TextureSequence { @Override public TextureSequence.TextureFrame getNextTexture(GL gl, boolean blocking) throws IllegalStateException; - public URLConnection getURLConnection(); + /** Return the stream location, as set by {@link #initGLStream(GL, int, URI, int, int)}. */ + public URI getURI(); /** * <i>Warning:</i> Optional information, may not be supported by implementation. diff --git a/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java b/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java index 86e6bc121..f87df950c 100644 --- a/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java +++ b/src/jogl/classes/jogamp/opengl/android/av/AndroidGLMediaPlayerAPI14.java @@ -187,15 +187,15 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { @Override protected final void initGLStreamImpl(GL gl, int vid, int aid) throws IOException { - if(null!=mp && null!=urlConn) { + if(null!=mp && null!=streamLoc) { if( GLMediaPlayer.STREAM_ID_NONE == aid ) { mp.setVolume(0f, 0f); // FIXME: Disable audio handling } // else FIXME: Select aid ! // Note: Both FIXMEs seem to be n/a via Android's MediaPlayer -> Switch to API level 16 MediaCodec/MediaExtractor .. try { - final Uri uri = Uri.parse(urlConn.getURL().toExternalForm()); - mp.setDataSource(StaticContext.getContext(), uri); + final Uri _uri = Uri.parse(streamLoc.toString()); + mp.setDataSource(StaticContext.getContext(), _uri); } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (SecurityException e) { @@ -210,7 +210,7 @@ public class AndroidGLMediaPlayerAPI14 extends GLMediaPlayerImpl { try { mp.prepare(); } catch (IOException ioe) { - throw new IOException("MediaPlayer failed to process stream <"+urlConn.getURL().toExternalForm()+">: "+ioe.getMessage(), ioe); + throw new IOException("MediaPlayer failed to process stream <"+streamLoc.toString()+">: "+ioe.getMessage(), ioe); } final int r_aid = GLMediaPlayer.STREAM_ID_NONE == aid ? GLMediaPlayer.STREAM_ID_NONE : GLMediaPlayer.STREAM_ID_AUTO; final String icodec = "android"; diff --git a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java index 8456aca6f..a82c84d17 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java +++ b/src/jogl/classes/jogamp/opengl/util/av/GLMediaPlayerImpl.java @@ -28,7 +28,7 @@ package jogamp.opengl.util.av; import java.io.IOException; -import java.net.URLConnection; +import java.net.URI; import java.util.ArrayList; import java.util.Iterator; @@ -82,7 +82,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { protected int[] texMinMagFilter = { GL.GL_NEAREST, GL.GL_NEAREST }; protected int[] texWrapST = { GL.GL_CLAMP_TO_EDGE, GL.GL_CLAMP_TO_EDGE }; - protected URLConnection urlConn = null; + protected URI streamLoc = null; protected volatile float playSpeed = 1.0f; @@ -378,7 +378,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { } @Override - public final State initGLStream(GL gl, int reqTextureCount, URLConnection urlConn, int vid, int aid) throws IllegalStateException, GLException, IOException { + public final State initGLStream(GL gl, int reqTextureCount, URI streamLoc, int vid, int aid) throws IllegalStateException, GLException, IOException { synchronized( stateLock ) { if(State.Uninitialized != state) { throw new IllegalStateException("Instance not in state "+State.Uninitialized+", but "+state+", "+this); @@ -386,8 +386,8 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { decodedFrameCount = 0; presentedFrameCount = 0; displayedFrameCount = 0; - this.urlConn = urlConn; - if (this.urlConn != null) { + this.streamLoc = streamLoc; + if (this.streamLoc != null) { try { if( null != gl ) { removeAllTextureFrames(gl); @@ -1014,8 +1014,8 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { protected abstract void destroyImpl(GL gl); @Override - public final URLConnection getURLConnection() { - return urlConn; + public final URI getURI() { + return streamLoc; } @Override @@ -1081,7 +1081,7 @@ public abstract class GLMediaPlayerImpl implements GLMediaPlayer { @Override public final String toString() { final float tt = getDuration() / 1000.0f; - final String loc = ( null != urlConn ) ? urlConn.getURL().toExternalForm() : "<undefined stream>" ; + final String loc = ( null != streamLoc ) ? streamLoc.toString() : "<undefined stream>" ; final int freeVideoFrames = null != videoFramesFree ? videoFramesFree.size() : 0; final int decVideoFrames = null != videoFramesDecoded ? videoFramesDecoded.size() : 0; final int video_scr = video_scr_pts + (int) ( ( Platform.currentTimeMillis() - video_scr_t0 ) * playSpeed ); diff --git a/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java b/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java index 8998f689a..9838181ab 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java +++ b/src/jogl/classes/jogamp/opengl/util/av/impl/FFMPEGMediaPlayer.java @@ -105,7 +105,10 @@ import jogamp.opengl.util.av.GLMediaPlayerImpl; */ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl { - // Count of zeroed buffers to return before switching to real sample provider + /** POSIX ENOSYS {@value}: Function not implemented. FIXME: Move to GlueGen ?!*/ + private static final int ENOSYS = 38; + + /** Count of zeroed buffers to return before switching to real sample provider */ private static final int TEMP_BUFFER_COUNT = 20; // Instance data @@ -220,11 +223,13 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl { setGLFuncs0(moviePtr, procAddrGLTexSubImage2D, procAddrGLGetError); } - final String urlS=urlConn.getURL().toExternalForm(); + final String streamLocS=streamLoc.toString(); aFrameCount = AFRAMES_PER_VFRAME * textureCount + AFRAMES_PER_VFRAME/2; - System.err.println("setURL: p1 "+this); + if(DEBUG) { + System.err.println("initGLStream: p1 "+this); + } destroyAudioSink(); AudioSink _audioSink; if( GLMediaPlayer.STREAM_ID_NONE == aid ) { @@ -234,12 +239,16 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl { } final AudioDataFormat preferredAudioFormat = _audioSink.getPreferredFormat(); // setStream(..) issues updateAttributes*(..), and defines avChosenAudioFormat, vid, aid, .. etc - setStream0(moviePtr, urlS, vid, aid, aFrameCount, preferredAudioFormat.channelCount, preferredAudioFormat.sampleRate); + setStream0(moviePtr, streamLocS, vid, aid, aFrameCount, preferredAudioFormat.channelCount, preferredAudioFormat.sampleRate); // final int audioBytesPerFrame = bps_audio/8000 * frame_period * textureCount; - System.err.println("setURL: p2 preferred "+preferredAudioFormat+", avChosen "+avChosenAudioFormat+", "+this); + if(DEBUG) { + System.err.println("initGLStream: p2 preferred "+preferredAudioFormat+", avChosen "+avChosenAudioFormat+", "+this); + } sinkChosenAudioFormat = _audioSink.initSink(avChosenAudioFormat, aFrameCount); - System.err.println("setURL: p3 avChosen "+avChosenAudioFormat+", chosen "+sinkChosenAudioFormat); + if(DEBUG) { + System.err.println("initGLStream: p3 avChosen "+avChosenAudioFormat+", chosen "+sinkChosenAudioFormat); + } if( null == sinkChosenAudioFormat ) { System.err.println("AudioSink "+_audioSink.getClass().getName()+" does not support "+avChosenAudioFormat+", using Null"); _audioSink.destroy(); @@ -434,15 +443,23 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl { if(0==moviePtr) { return false; } - return play0(moviePtr); + final int errno = play0(moviePtr); + if( DEBUG_NATIVE && errno != 0 && errno != -ENOSYS) { + System.err.println("libav play err: "+errno); + } + return true; } - + @Override public final boolean pauseImpl() { if(0==moviePtr) { return false; } - return pause0(moviePtr); + final int errno = pause0(moviePtr); + if( DEBUG_NATIVE && errno != 0 && errno != -ENOSYS) { + System.err.println("libav pause err: "+errno); + } + return true; } @Override @@ -541,8 +558,8 @@ public class FFMPEGMediaPlayer extends GLMediaPlayerImpl { */ private native int readNextPacket0(long moviePtr, int texTarget, int texFmt, int texType); - private native boolean play0(long moviePtr); - private native boolean pause0(long moviePtr); + private native int play0(long moviePtr); + private native int pause0(long moviePtr); private native int seek0(long moviePtr, int position); public static enum SampleFormat { diff --git a/src/jogl/classes/jogamp/opengl/util/av/impl/OMXGLMediaPlayer.java b/src/jogl/classes/jogamp/opengl/util/av/impl/OMXGLMediaPlayer.java index c6f31d81e..d0517fc5f 100644 --- a/src/jogl/classes/jogamp/opengl/util/av/impl/OMXGLMediaPlayer.java +++ b/src/jogl/classes/jogamp/opengl/util/av/impl/OMXGLMediaPlayer.java @@ -29,7 +29,6 @@ package jogamp.opengl.util.av.impl; import java.io.IOException; -import java.net.URL; import javax.media.opengl.GL; import javax.media.opengl.GLException; @@ -101,16 +100,21 @@ public class OMXGLMediaPlayer extends EGLMediaPlayerImpl { if(0==moviePtr) { throw new GLException("OMX native instance null"); } - final URL url = urlConn.getURL(); - if(!url.getProtocol().equals("file")) { - throw new IOException("Only file URLs are allowed: "+url); + if(!streamLoc.getScheme().equals("file")) { + throw new IOException("Only file schemes are allowed: "+streamLoc); + } + final String path=streamLoc.getPath(); + if(DEBUG) { + System.out.println("initGLStream: clean path "+path); } - final String path=url.getPath(); - System.out.println("setURL: clean path "+path); - System.out.println("setURL: p1 "+this); + if(DEBUG) { + System.out.println("initGLStream: p1 "+this); + } _setStream(moviePtr, textureCount, path); - System.out.println("setURL: p2 "+this); + if(DEBUG) { + System.out.println("initGLStream: p2 "+this); + } } @Override diff --git a/src/jogl/native/libav/jogamp_opengl_util_av_impl_FFMPEGMediaPlayer.c b/src/jogl/native/libav/jogamp_opengl_util_av_impl_FFMPEGMediaPlayer.c index ca0bf9bb9..99b385e3c 100644 --- a/src/jogl/native/libav/jogamp_opengl_util_av_impl_FFMPEGMediaPlayer.c +++ b/src/jogl/native/libav/jogamp_opengl_util_av_impl_FFMPEGMediaPlayer.c @@ -877,29 +877,17 @@ JNIEXPORT jint JNICALL Java_jogamp_opengl_util_av_impl_FFMPEGMediaPlayer_readNex return resPTS; } -JNIEXPORT jboolean JNICALL Java_jogamp_opengl_util_av_impl_FFMPEGMediaPlayer_play0 +JNIEXPORT jint JNICALL Java_jogamp_opengl_util_av_impl_FFMPEGMediaPlayer_play0 (JNIEnv *env, jobject instance, jlong ptr) { FFMPEGToolBasicAV_t *pAV = (FFMPEGToolBasicAV_t *)((void *)((intptr_t)ptr)); - int res = sp_av_read_play(pAV->pFormatCtx); - if ( 0 != res && -ENOSYS != res ) { // Ignore ENOSYS (not impl.) - fprintf(stderr, "PLAY: err %d 0x%X\n", res, res); - return JNI_FALSE; - } else { - return JNI_TRUE; - } + return sp_av_read_play(pAV->pFormatCtx); } -JNIEXPORT jboolean JNICALL Java_jogamp_opengl_util_av_impl_FFMPEGMediaPlayer_pause0 +JNIEXPORT jint JNICALL Java_jogamp_opengl_util_av_impl_FFMPEGMediaPlayer_pause0 (JNIEnv *env, jobject instance, jlong ptr) { FFMPEGToolBasicAV_t *pAV = (FFMPEGToolBasicAV_t *)((void *)((intptr_t)ptr)); - int res = sp_av_read_pause(pAV->pFormatCtx); - if ( 0 != res && -ENOSYS != res ) { // Ignore ENOSYS (not impl.) - fprintf(stderr, "PAUSE: err %d 0x%X\n", res, res); - return JNI_FALSE; - } else { - return JNI_TRUE; - } + return sp_av_read_pause(pAV->pFormatCtx); } JNIEXPORT jint JNICALL Java_jogamp_opengl_util_av_impl_FFMPEGMediaPlayer_seek0 |