@Override protected final synchronized int seekImpl(final int msec) { if (0 == moviePtr) { throw new GLException("FFMPEG native instance null"); } return natives.seek0(moviePtr, msec); }
@Override protected final void destroyImpl(final GL gl) { if (moviePtr != 0) { natives.destroyInstance0(moviePtr); moviePtr = 0; } destroyAudioSink(); }
public FFMPEGMediaPlayer() { if (!available) { throw new RuntimeException("FFMPEGMediaPlayer not available"); } moviePtr = natives.createInstance0(this, DEBUG_NATIVE); if (0 == moviePtr) { throw new GLException("Couldn't create FFMPEGInstance"); } psm = new GLPixelStorageModes(); audioSink = null; }
@Override public final boolean pauseImpl() { if (0 == moviePtr) { return false; } final int errno = natives.pause0(moviePtr); if (DEBUG_NATIVE && errno != 0 && errno != -ENOSYS) { System.err.println("libav pause err: " + errno); } return true; }
@Override protected final int getNextTextureImpl(final GL gl, final TextureFrame nextFrame) { if (0 == moviePtr) { throw new GLException("FFMPEG native instance null"); } int vPTS = TimeFrameI.INVALID_PTS; if (null != gl) { final Texture tex = nextFrame.getTexture(); tex.enable(gl); tex.bind(gl); } /** Try decode up to 10 packets to find one containing video. */ for (int i = 0; TimeFrameI.INVALID_PTS == vPTS && 10 > i; i++) { vPTS = natives.readNextPacket0( moviePtr, getTextureTarget(), getTextureFormat(), getTextureType()); } if (null != nextFrame) { nextFrame.setPTS(vPTS); } return vPTS; }
@Override protected final void initStreamImpl(final int vid, final int aid) throws IOException { if (0 == moviePtr) { throw new GLException("FFMPEG native instance null"); } if (DEBUG) { System.err.println("initStream: p1 " + this); } final String streamLocS = IOUtil.decodeURIIfFilePath(getURI()); destroyAudioSink(); if (GLMediaPlayer.STREAM_ID_NONE == aid) { audioSink = AudioSinkFactory.createNull(); } else { audioSink = AudioSinkFactory.createDefault(); } final AudioFormat preferredAudioFormat = audioSink.getPreferredFormat(); if (DEBUG) { System.err.println("initStream: p2 preferred " + preferredAudioFormat + ", " + this); } final boolean isCameraInput = null != cameraPath; final String resStreamLocS; // int rw=640, rh=480, rr=15; int rw = -1, rh = -1, rr = -1; String sizes = null; if (isCameraInput) { switch (PlatformPropsImpl.OS_TYPE) { case ANDROID: // ?? case FREEBSD: case HPUX: case LINUX: case SUNOS: resStreamLocS = dev_video_linux + cameraPath; break; case WINDOWS: resStreamLocS = cameraPath; break; case MACOS: case OPENKODE: default: resStreamLocS = streamLocS; // FIXME: ?? break; } if (null != cameraProps) { sizes = cameraProps.get(CameraPropSizeS); int v = getPropIntVal(cameraProps, CameraPropWidth); if (v > 0) { rw = v; } v = getPropIntVal(cameraProps, CameraPropHeight); if (v > 0) { rh = v; } v = getPropIntVal(cameraProps, CameraPropRate); if (v > 0) { rr = v; } } } else { resStreamLocS = streamLocS; } final int aMaxChannelCount = audioSink.getMaxSupportedChannels(); final int aPrefSampleRate = preferredAudioFormat.sampleRate; // setStream(..) issues updateAttributes*(..), and defines avChosenAudioFormat, vid, aid, .. etc if (DEBUG) { System.err.println( "initStream: p3 cameraPath " + cameraPath + ", isCameraInput " + isCameraInput); System.err.println( "initStream: p3 stream " + getURI() + " -> " + streamLocS + " -> " + resStreamLocS); System.err.println( "initStream: p3 vid " + vid + ", sizes " + sizes + ", reqVideo " + rw + "x" + rh + "@" + rr + ", aid " + aid + ", aMaxChannelCount " + aMaxChannelCount + ", aPrefSampleRate " + aPrefSampleRate); } natives.setStream0( moviePtr, resStreamLocS, isCameraInput, vid, sizes, rw, rh, rr, aid, aMaxChannelCount, aPrefSampleRate); }
static { final boolean libAVGood = FFMPEGDynamicLibraryBundleInfo.initSingleton(); final boolean libAVVersionGood; if (FFMPEGDynamicLibraryBundleInfo.libsLoaded()) { natives = FFMPEGDynamicLibraryBundleInfo.getNatives(); if (null != natives) { avCodecMajorVersionCC = natives.getAvCodecMajorVersionCC0(); avFormatMajorVersionCC = natives.getAvFormatMajorVersionCC0(); avUtilMajorVersionCC = natives.getAvUtilMajorVersionCC0(); avResampleMajorVersionCC = natives.getAvResampleMajorVersionCC0(); swResampleMajorVersionCC = natives.getSwResampleMajorVersionCC0(); } else { avUtilMajorVersionCC = 0; avFormatMajorVersionCC = 0; avCodecMajorVersionCC = 0; avResampleMajorVersionCC = 0; swResampleMajorVersionCC = 0; } final VersionNumber avCodecVersion = FFMPEGDynamicLibraryBundleInfo.avCodecVersion; final VersionNumber avFormatVersion = FFMPEGDynamicLibraryBundleInfo.avFormatVersion; final VersionNumber avUtilVersion = FFMPEGDynamicLibraryBundleInfo.avUtilVersion; final VersionNumber avResampleVersion = FFMPEGDynamicLibraryBundleInfo.avResampleVersion; final boolean avResampleLoaded = FFMPEGDynamicLibraryBundleInfo.avResampleLoaded(); final VersionNumber swResampleVersion = FFMPEGDynamicLibraryBundleInfo.swResampleVersion; final boolean swResampleLoaded = FFMPEGDynamicLibraryBundleInfo.swResampleLoaded(); if (DEBUG) { System.err.println( "LIB_AV Codec : " + avCodecVersion + " [cc " + avCodecMajorVersionCC + "]"); System.err.println( "LIB_AV Format : " + avFormatVersion + " [cc " + avFormatMajorVersionCC + "]"); System.err.println( "LIB_AV Util : " + avUtilVersion + " [cc " + avUtilMajorVersionCC + "]"); System.err.println( "LIB_AV Resample: " + avResampleVersion + " [cc " + avResampleMajorVersionCC + ", loaded " + avResampleLoaded + "]"); System.err.println( "LIB_SW Resample: " + swResampleVersion + " [cc " + swResampleMajorVersionCC + ", loaded " + swResampleLoaded + "]"); System.err.println( "LIB_AV Device : [loaded " + FFMPEGDynamicLibraryBundleInfo.avDeviceLoaded() + "]"); System.err.println( "LIB_AV Class : " + (null != natives ? natives.getClass().getSimpleName() : "n/a")); } final int avCodecMajor = avCodecVersion.getMajor(); final int avFormatMajor = avFormatVersion.getMajor(); final int avUtilMajor = avUtilVersion.getMajor(); libAVVersionGood = avCodecMajorVersionCC == avCodecMajor && avFormatMajorVersionCC == avFormatMajor && (avUtilMajorVersionCC == avUtilMajor || 55 == avCodecMajorVersionCC && 53 == avUtilMajorVersionCC && 52 == avUtilMajor /* ffmpeg 2.x */) && (!avResampleLoaded || avResampleMajorVersionCC < 0 || avResampleMajorVersionCC == avResampleVersion.getMajor()) && (!swResampleLoaded || swResampleMajorVersionCC < 0 || swResampleMajorVersionCC == swResampleVersion.getMajor()); if (!libAVVersionGood) { System.err.println("LIB_AV Not Matching Compile-Time / Runtime Major-Version"); } } else { natives = null; avUtilMajorVersionCC = 0; avFormatMajorVersionCC = 0; avCodecMajorVersionCC = 0; avResampleMajorVersionCC = 0; swResampleMajorVersionCC = 0; libAVVersionGood = false; } available = libAVGood && libAVVersionGood && null != natives; }