From df24bfd482061604db929824f5f67a82d27bf35d Mon Sep 17 00:00:00 2001 From: Bartosz Firyn Date: Tue, 23 Sep 2014 18:19:18 +0200 Subject: [PATCH] Fix more javadocs, change repos, fix classpaths --- .../driver-fswebcam/.classpath | 7 - .../webcam/ds/ipcam/IpCamDeviceRegistry.java | 29 +- .../sarxos/webcam/ds/ipcam/IpCamDriver.java | 30 +- .../sarxos/webcam/ds/vlcj/VlcjDriver.java | 63 ++-- .../webcam-capture-applet/.classpath | 2 +- .../webcam-capture-detect-face/.classpath | 39 ++- .../webcam-capture-detect-face/pom.xml | 17 +- .../webcam-capture-javafx/.classpath | 7 - .../video/stream/agent/StreamServer.java | 6 +- .../stream/handler/H264StreamDecoder.java | 307 +++++++++--------- .../webcam-capture-onejar/.classpath | 10 - 11 files changed, 232 insertions(+), 285 deletions(-) diff --git a/webcam-capture-drivers/driver-fswebcam/.classpath b/webcam-capture-drivers/driver-fswebcam/.classpath index b3d934d4..216478e2 100644 --- a/webcam-capture-drivers/driver-fswebcam/.classpath +++ b/webcam-capture-drivers/driver-fswebcam/.classpath @@ -6,13 +6,6 @@ - - - - - - - diff --git a/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDeviceRegistry.java b/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDeviceRegistry.java index d7a72ab3..4ed097c6 100644 --- a/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDeviceRegistry.java +++ b/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDeviceRegistry.java @@ -17,7 +17,7 @@ /** * Class used to register IP camera devices. - * + * * @author Bartosz Firyn (SarXos) */ public class IpCamDeviceRegistry { @@ -29,8 +29,9 @@ public class IpCamDeviceRegistry { /** * Register IP camera. - * + * * @param ipcam the IP camera to be register + * @return IP camera device */ public static IpCamDevice register(IpCamDevice ipcam) { @@ -62,7 +63,7 @@ public static IpCamDevice register(String name, String url, IpCamMode mode, IpCa /** * Register new IP camera device. - * + * * @param name the name of the device * @param url the URL to be used * @param mode the camera mode to be used @@ -75,7 +76,7 @@ public static IpCamDevice register(String name, URL url, IpCamMode mode, IpCamAu /** * Is device registered? - * + * * @param ipcam the IP camera device * @return True if device is registsred, false otherwise */ @@ -97,7 +98,7 @@ public static boolean isRegistered(IpCamDevice ipcam) { /** * Is device with given name registered? - * + * * @param name the name of device * @return True if device is registered, false otherwise */ @@ -119,7 +120,7 @@ public static boolean isRegistered(String name) { /** * Is device with given URL registered? - * + * * @param url the URL used by device * @return True if device is registered, false otherwise */ @@ -138,8 +139,8 @@ public static boolean isRegistered(URL url) { /** * Is device with given URL registered? - * - * @param url the URL used by device + * + * @param uri the URI used by device * @return True if device is registered, false otherwise */ public static boolean isRegistered(URI uri) { @@ -167,8 +168,9 @@ public static boolean isRegistered(URI uri) { /** * Unregister IP camera. - * + * * @param ipcam the IP camera to be unregister + * @return True if IP camera device has been unregistered, false otherwise */ public static boolean unregister(IpCamDevice ipcam) { try { @@ -179,8 +181,8 @@ public static boolean unregister(IpCamDevice ipcam) { } /** - * Run discovery service once if device has been removed to trigger - * disconnected webcam discovery event and keep webcams list up-to-date. + * Run discovery service once if device has been removed to trigger disconnected webcam + * discovery event and keep webcams list up-to-date. */ private static void rescan() { WebcamDiscoveryService discovery = Webcam.getDiscoveryServiceRef(); @@ -192,7 +194,8 @@ private static void rescan() { /** * Unregister IP camera with given name. * - * @param ipcam the IP camera to be unregister + * @param name the name of IP camera to be unregister + * @return True if device has been registered, false otherwise */ public static boolean unregister(String name) { Iterator di = DEVICES.iterator(); @@ -209,7 +212,7 @@ public static boolean unregister(String name) { /** * Get all registered IP cameras. - * + * * @return Collection of registered IP cameras */ public static List getIpCameras() { diff --git a/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDriver.java b/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDriver.java index 40c283a4..3fa62020 100644 --- a/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDriver.java +++ b/webcam-capture-drivers/driver-ipcam/src/main/java/com/github/sarxos/webcam/ds/ipcam/IpCamDriver.java @@ -25,14 +25,14 @@ /** * IP camera driver. - * + * * @author Bartosz Firyn (sarxos) */ public class IpCamDriver implements WebcamDriver, WebcamDiscoverySupport { /** * Thread factory. - * + * * @author Bartosz Firyn (sarxos) */ private static class DeviceCheckThreadFactory implements ThreadFactory { @@ -62,9 +62,9 @@ public Thread newThread(Runnable r) { private static final ThreadFactory THREAD_FACTORY = new DeviceCheckThreadFactory(); /** - * The callable to query single IP camera device. Callable getter will - * return device if it's online or null if it's offline. - * + * The callable to query single IP camera device. Callable getter will return device if it's + * online or null if it's offline. + * * @author Bartosz Firyn (sarxos) */ private static class DeviceOnlineCheck implements Callable { @@ -78,8 +78,9 @@ private static class DeviceOnlineCheck implements Callable { /** * The callable to query single IP camera device. - * + * * @param device the device to check online status + * @param latch the count down latch */ public DeviceOnlineCheck(IpCamDevice device, CountDownLatch latch) { this.device = device; @@ -102,8 +103,8 @@ public IpCamDevice call() throws Exception { private volatile long scanInterval = 10000; /** - * Discovery scan timeout in milliseconds. This is maximum time which - * executor will wait for online detection to succeed. + * Discovery scan timeout in milliseconds. This is maximum time which executor will wait for + * online detection to succeed. */ private volatile long scanTimeout = 10000; @@ -214,9 +215,8 @@ public long getScanInterval() { } /** - * Set new scan interval. Value must be given in milliseconds and shall not - * be negative. - * + * Set new scan interval. Value must be given in milliseconds and shall not be negative. + * * @param scanInterval */ public void setScanInterval(long scanInterval) { @@ -234,7 +234,7 @@ public boolean isScanPossible() { /** * Set discovery scanning possible. - * + * * @param scanning */ public void setScanPossible(boolean scanning) { @@ -249,9 +249,9 @@ public long getScanTimeout() { } /** - * Set new scan timeout. This value cannot be less than 1000 milliseconds - * (which equals 1 second). - * + * Set new scan timeout. This value cannot be less than 1000 milliseconds (which equals 1 + * second). + * * @param scanTimeout the scan timeout in milliseconds */ public void setScanTimeout(long scanTimeout) { diff --git a/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/VlcjDriver.java b/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/VlcjDriver.java index 55b2667d..fe8a6b95 100644 --- a/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/VlcjDriver.java +++ b/webcam-capture-drivers/driver-vlcj/src/main/java/com/github/sarxos/webcam/ds/vlcj/VlcjDriver.java @@ -1,33 +1,28 @@ package com.github.sarxos.webcam.ds.vlcj; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; -import uk.co.caprica.vlcj.binding.LibVlc; import uk.co.caprica.vlcj.discovery.NativeDiscovery; import uk.co.caprica.vlcj.medialist.MediaList; import uk.co.caprica.vlcj.medialist.MediaListItem; import uk.co.caprica.vlcj.player.MediaPlayerFactory; import uk.co.caprica.vlcj.player.discoverer.MediaDiscoverer; -import uk.co.caprica.vlcj.runtime.RuntimeUtil; -import uk.co.caprica.vlcj.runtime.windows.WindowsRuntimeUtil; import com.github.sarxos.webcam.WebcamDevice; import com.github.sarxos.webcam.WebcamDiscoverySupport; import com.github.sarxos.webcam.WebcamDriver; import com.github.sarxos.webcam.util.OsUtils; -import com.sun.jna.Native; /** - * This is capture driver which uses vlcj library to gain access to - * the camera device. - * + * This is capture driver which uses vlcj library to gain access to the camera device. + * The library can be found at:
+ *
+ * http://www.capricasoftware.co.uk/projects/vlcj/index.html + * * @author Bartosz Firyn (SarXos) - * @see http://www.capricasoftware.co.uk/projects/vlcj/index.html */ public class VlcjDriver implements WebcamDriver, WebcamDiscoverySupport { @@ -36,7 +31,7 @@ public class VlcjDriver implements WebcamDriver, WebcamDiscoverySupport { System.setProperty("vlcj.log", "DEBUG"); } } - + /** * Default webcam discovery scan interval in milliseconds. */ @@ -51,7 +46,7 @@ public class VlcjDriver implements WebcamDriver, WebcamDiscoverySupport { * Native library discoverer. */ private static NativeDiscovery nativeDiscovery; - + /** * The scan interval. */ @@ -67,7 +62,7 @@ public VlcjDriver() { } public VlcjDriver(List mediaListItems) { - this.mediaListItems = mediaListItems; + this.mediaListItems = mediaListItems; initialize(); } @@ -79,9 +74,9 @@ protected static void initialize() { } /** - * Initialize natives. If argument is true the natives are being loaded. In - * case of false this method do nothing. It's used mostly in unit tests. - * + * Initialize natives. If argument is true the natives are being loaded. In case of false this + * method do nothing. It's used mostly in unit tests. + * * @param load the control to decide whether to load natives or ignore them */ protected static void initialize(boolean load) { @@ -90,32 +85,13 @@ protected static void initialize(boolean load) { if (!nativeFound) { throw new IllegalStateException("The libvlc native library has not been found"); } - //Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class); + // Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class); } } - - /** - * Method to get devices list on Windows. - * - * @return Webcam devices list - */ - private List getDevicesPreconf() { - - - - List devices = new ArrayList(); - - MediaListItem mli = new MediaListItem("HP HD Webcam [Fixed]", "dshow://", new ArrayList()); - - devices.add(mediaListItemToDevice(mli)); - - return devices; - } - @Override public List getDevices() { - + if (OsUtils.getOS() == OsUtils.WIN) { System.err.println("WARNING: VLCj does not support webcam devices discovery on Windows platform"); } @@ -149,7 +125,7 @@ public List getDevices() { /** * Converts media list itemn into webcam device. - * + * * @param item the item to be converted to webcam device instance * @return Webcam device created from media list item */ @@ -159,7 +135,7 @@ protected WebcamDevice mediaListItemToDevice(MediaListItem item) { /** * Creates media player factory. - * + * * @return New media player factory */ protected MediaPlayerFactory createMediaPlayerFactory() { @@ -185,10 +161,9 @@ public long getScanInterval() { } /** - * Set new scan interval. Value must be positive number. If negative or zero - * is used, then the corresponding getter will return default scan interval - * value. - * + * Set new scan interval. Value must be positive number. If negative or zero is used, then the + * corresponding getter will return default scan interval value. + * * @param scanInterval the new scan interval in milliseconds * @see VlcjDriver#DEFAULT_SCAN_INTERVAL */ @@ -200,7 +175,7 @@ public void setScanInterval(long scanInterval) { public boolean isScanPossible() { return OsUtils.getOS() != OsUtils.WIN; } - + protected static NativeDiscovery getNativeDiscovery() { if (nativeDiscovery == null) { nativeDiscovery = new NativeDiscovery(); diff --git a/webcam-capture-examples/webcam-capture-applet/.classpath b/webcam-capture-examples/webcam-capture-applet/.classpath index b4dc627b..398c9896 100644 --- a/webcam-capture-examples/webcam-capture-applet/.classpath +++ b/webcam-capture-examples/webcam-capture-applet/.classpath @@ -14,7 +14,7 @@
- + diff --git a/webcam-capture-examples/webcam-capture-detect-face/.classpath b/webcam-capture-examples/webcam-capture-detect-face/.classpath index 8fe0193e..ffc8458a 100644 --- a/webcam-capture-examples/webcam-capture-detect-face/.classpath +++ b/webcam-capture-examples/webcam-capture-detect-face/.classpath @@ -1,8 +1,31 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/webcam-capture-examples/webcam-capture-detect-face/pom.xml b/webcam-capture-examples/webcam-capture-detect-face/pom.xml index a764e2a9..b33d5a16 100644 --- a/webcam-capture-examples/webcam-capture-detect-face/pom.xml +++ b/webcam-capture-examples/webcam-capture-detect-face/pom.xml @@ -14,21 +14,6 @@ Webcam Capture - Detect Face Example Example of how to use painter interface to mark detected face - - - sarxos-repo - http://repo.sarxos.pl/maven2 - - - OpenIMAJ maven repository - http://maven.openimaj.org/ - - - OpenIMAJ snapshots maven repository - http://snapshots.openimaj.org - - - com.github.sarxos @@ -38,7 +23,7 @@ org.openimaj faces - 1.1 + 1.3 diff --git a/webcam-capture-examples/webcam-capture-javafx/.classpath b/webcam-capture-examples/webcam-capture-javafx/.classpath index 03d699bf..8db15f69 100644 --- a/webcam-capture-examples/webcam-capture-javafx/.classpath +++ b/webcam-capture-examples/webcam-capture-javafx/.classpath @@ -6,18 +6,11 @@ - - - - - - - diff --git a/webcam-capture-examples/webcam-capture-live-streaming/src/main/java/us/sosia/video/stream/agent/StreamServer.java b/webcam-capture-examples/webcam-capture-live-streaming/src/main/java/us/sosia/video/stream/agent/StreamServer.java index 65768a78..d0b1c4b9 100644 --- a/webcam-capture-examples/webcam-capture-live-streaming/src/main/java/us/sosia/video/stream/agent/StreamServer.java +++ b/webcam-capture-examples/webcam-capture-live-streaming/src/main/java/us/sosia/video/stream/agent/StreamServer.java @@ -5,17 +5,19 @@ import com.github.sarxos.webcam.Webcam; + public class StreamServer { /** * @author kerr + * @param args */ public static void main(String[] args) { Webcam.setAutoOpenMode(true); Webcam webcam = Webcam.getDefault(); - Dimension dimension = new Dimension(320,240); + Dimension dimension = new Dimension(320, 240); webcam.setViewSize(dimension); - + StreamServerAgent serverAgent = new StreamServerAgent(webcam, dimension); serverAgent.start(new InetSocketAddress("localhost", 20000)); } diff --git a/webcam-capture-examples/webcam-capture-live-streaming/src/main/java/us/sosia/video/stream/handler/H264StreamDecoder.java b/webcam-capture-examples/webcam-capture-live-streaming/src/main/java/us/sosia/video/stream/handler/H264StreamDecoder.java index 4c4a9d0f..6b49d088 100644 --- a/webcam-capture-examples/webcam-capture-live-streaming/src/main/java/us/sosia/video/stream/handler/H264StreamDecoder.java +++ b/webcam-capture-examples/webcam-capture-live-streaming/src/main/java/us/sosia/video/stream/handler/H264StreamDecoder.java @@ -24,154 +24,155 @@ import com.xuggle.xuggler.video.ConverterFactory; import com.xuggle.xuggler.video.ConverterFactory.Type; import com.xuggle.xuggler.video.IConverter; + + /** * This codec will encode the bufferedImage to h264 stream - * **/ -public class H264StreamDecoder extends OneToOneDecoder{ + **/ +public class H264StreamDecoder extends OneToOneDecoder { + protected final static Logger logger = LoggerFactory.getLogger(H264StreamDecoder.class); protected final IStreamCoder iStreamCoder = IStreamCoder.make(Direction.DECODING, ICodec.ID.CODEC_ID_H264); - protected final Type type = ConverterFactory.findRegisteredConverter(ConverterFactory.XUGGLER_BGR_24); + protected final Type type = ConverterFactory.findRegisteredConverter(ConverterFactory.XUGGLER_BGR_24); protected final StreamFrameListener streamFrameListener; protected final Dimension dimension; - - protected final FrameDecoder frameDecoder; - protected final ExecutorService decodeWorker ; - /** - * - * Cause there may be one or more image in the frame,so we need an Stream listener here to get all the image - * - * */ - - - + protected final FrameDecoder frameDecoder; + protected final ExecutorService decodeWorker; + /** + * Cause there may be one or more image in the frame,so we need an Stream listener here to get + * all the image + * + * @param streamFrameListener + * @param dimension + * @param internalFrameDecoder + * @param decodeInOtherThread + */ public H264StreamDecoder(StreamFrameListener streamFrameListener, - Dimension dimension,boolean internalFrameDecoder,boolean decodeInOtherThread) { + Dimension dimension, boolean internalFrameDecoder, + boolean decodeInOtherThread) { + super(); + this.streamFrameListener = streamFrameListener; this.dimension = dimension; if (internalFrameDecoder) { frameDecoder = new FrameDecoder(4); - }else { + } else { frameDecoder = null; } if (decodeInOtherThread) { - decodeWorker = Executors.newSingleThreadExecutor(); - }else { + decodeWorker = Executors.newSingleThreadExecutor(); + } else { decodeWorker = null; } - + initialize(); } - - - private void initialize(){ - //iStreamCoder.setNumPicturesInGroupOfPictures(20); - //iStreamCoder.setBitRate(250000); - //iStreamCoder.setBitRateTolerance(9000); - //iStreamCoder.setPixelType(IPixelFormat.Type.YUV420P); - //iStreamCoder.setHeight(dimension.height); - //iStreamCoder.setWidth(dimension.width); - //iStreamCoder.setFlag(IStreamCoder.Flags.FLAG_QSCALE, true); - //iStreamCoder.setGlobalQuality(0); - //rate - //IRational rate = IRational.make(25, 1); - //iStreamCoder.setFrameRate(rate); - //time base - //iStreamCoder.setAutomaticallyStampPacketsForStream(true); - //iStreamCoder.setTimeBase(IRational.make(rate.getDenominator(),rate.getNumerator())); + private void initialize() { + // iStreamCoder.setNumPicturesInGroupOfPictures(20); + // iStreamCoder.setBitRate(250000); + // iStreamCoder.setBitRateTolerance(9000); + // iStreamCoder.setPixelType(IPixelFormat.Type.YUV420P); + // iStreamCoder.setHeight(dimension.height); + // iStreamCoder.setWidth(dimension.width); + // iStreamCoder.setFlag(IStreamCoder.Flags.FLAG_QSCALE, true); + // iStreamCoder.setGlobalQuality(0); + // rate + // IRational rate = IRational.make(25, 1); + // iStreamCoder.setFrameRate(rate); + // time base + // iStreamCoder.setAutomaticallyStampPacketsForStream(true); + // iStreamCoder.setTimeBase(IRational.make(rate.getDenominator(),rate.getNumerator())); iStreamCoder.open(null, null); } - - - - - @Override - protected Object decode(ChannelHandlerContext ctx, Channel channel, - final Object msg) throws Exception { + protected Object decode(ChannelHandlerContext ctx, Channel channel, final Object msg) throws Exception { + if (decodeWorker != null) { decodeWorker.execute(new decodeTask(msg)); return null; - }else { + } else { if (msg == null) { throw new NullPointerException("you cannot pass into an null to the decode"); } ChannelBuffer frameBuffer; if (frameDecoder != null) { - frameBuffer = frameDecoder.decode((ChannelBuffer)msg); - if (frameBuffer == null) { - return null; - } + frameBuffer = frameDecoder.decode((ChannelBuffer) msg); + if (frameBuffer == null) { + return null; + } - }else { - frameBuffer = (ChannelBuffer)msg; + } else { + frameBuffer = (ChannelBuffer) msg; } - + int size = frameBuffer.readableBytes(); - logger.info("decode the frame size :{}",size); - //start to decode + logger.info("decode the frame size :{}", size); + // start to decode IBuffer iBuffer = IBuffer.make(null, size); IPacket iPacket = IPacket.make(iBuffer); iPacket.getByteBuffer().put(frameBuffer.toByteBuffer()); - //decode the packet + // decode the packet if (!iPacket.isComplete()) { return null; } - + IVideoPicture picture = IVideoPicture.make(IPixelFormat.Type.YUV420P, - dimension.width, dimension.height); - try { - // decode the packet into the video picture - int postion = 0; - int packageSize = iPacket.getSize(); - while(postion < packageSize){ - postion+= iStreamCoder.decodeVideo(picture, iPacket, postion); - if (postion < 0) - throw new RuntimeException("error " - + " decoding video"); - // if this is a complete picture, dispatch the picture - if (picture.isComplete()){ - IConverter converter = ConverterFactory.createConverter(type - .getDescriptor(), picture); - BufferedImage image = converter.toImage(picture); - //BufferedImage convertedImage = ImageUtils.convertToType(image, BufferedImage.TYPE_3BYTE_BGR); - //here ,put out the image - if (streamFrameListener != null) { - streamFrameListener.onFrameReceived(image); + dimension.width, dimension.height); + try { + // decode the packet into the video picture + int postion = 0; + int packageSize = iPacket.getSize(); + while (postion < packageSize) { + postion += iStreamCoder.decodeVideo(picture, iPacket, postion); + if (postion < 0) { + throw new RuntimeException("error " + + " decoding video"); + } + // if this is a complete picture, dispatch the picture + if (picture.isComplete()) { + IConverter converter = ConverterFactory.createConverter(type + .getDescriptor(), picture); + BufferedImage image = converter.toImage(picture); + // BufferedImage convertedImage = ImageUtils.convertToType(image, + // BufferedImage.TYPE_3BYTE_BGR); + // here ,put out the image + if (streamFrameListener != null) { + streamFrameListener.onFrameReceived(image); } - converter.delete(); - }else{ - picture.delete(); - iPacket.delete(); - return null; - } - //clean the picture and reuse it - picture.getByteBuffer().clear(); - } - } finally { - if (picture != null) - picture.delete(); - iPacket.delete(); - // ByteBufferUtil.destroy(data); - } - return null; + converter.delete(); + } else { + picture.delete(); + iPacket.delete(); + return null; + } + // clean the picture and reuse it + picture.getByteBuffer().clear(); + } + } finally { + if (picture != null) { + picture.delete(); + } + iPacket.delete(); + // ByteBufferUtil.destroy(data); + } + return null; } } - - - private class decodeTask implements Runnable{ + + private class decodeTask implements Runnable { + private final Object msg; - + public decodeTask(Object msg) { super(); this.msg = msg; } - @Override public void run() { if (msg == null) { @@ -180,89 +181,71 @@ public void run() { ChannelBuffer frameBuffer; if (frameDecoder != null) { try { - frameBuffer = frameDecoder.decode((ChannelBuffer)msg); + frameBuffer = frameDecoder.decode((ChannelBuffer) msg); if (frameBuffer == null) { - return ; + return; } } catch (Exception e) { return; } - }else { - frameBuffer = (ChannelBuffer)msg; + } else { + frameBuffer = (ChannelBuffer) msg; } - + int size = frameBuffer.readableBytes(); - logger.info("decode the frame size :{}",size); - //start to decode + logger.info("decode the frame size :{}", size); + // start to decode IBuffer iBuffer = IBuffer.make(null, size); IPacket iPacket = IPacket.make(iBuffer); iPacket.getByteBuffer().put(frameBuffer.toByteBuffer()); - //decode the packet + // decode the packet if (!iPacket.isComplete()) { - return ; + return; } - - + IVideoPicture picture = IVideoPicture.make(IPixelFormat.Type.YUV420P, - dimension.width, dimension.height); - try { - // decode the packet into the video picture - int postion = 0; - int packageSize = iPacket.getSize(); - while(postion < packageSize){ - postion+= iStreamCoder.decodeVideo(picture, iPacket, postion); - if (postion < 0) - throw new RuntimeException("error " - + " decoding video"); - // if this is a complete picture, dispatch the picture - if (picture.isComplete()){ - IConverter converter = ConverterFactory.createConverter(type - .getDescriptor(), picture); - BufferedImage image = converter.toImage(picture); - //BufferedImage convertedImage = ImageUtils.convertToType(image, BufferedImage.TYPE_3BYTE_BGR); - //here ,put out the image - if (streamFrameListener != null) { - streamFrameListener.onFrameReceived(image); + dimension.width, dimension.height); + try { + // decode the packet into the video picture + int postion = 0; + int packageSize = iPacket.getSize(); + while (postion < packageSize) { + postion += iStreamCoder.decodeVideo(picture, iPacket, postion); + if (postion < 0) { + throw new RuntimeException("error " + + " decoding video"); + } + // if this is a complete picture, dispatch the picture + if (picture.isComplete()) { + IConverter converter = ConverterFactory.createConverter(type + .getDescriptor(), picture); + BufferedImage image = converter.toImage(picture); + // BufferedImage convertedImage = ImageUtils.convertToType(image, + // BufferedImage.TYPE_3BYTE_BGR); + // here ,put out the image + if (streamFrameListener != null) { + streamFrameListener.onFrameReceived(image); } - converter.delete(); - }else{ - picture.delete(); - iPacket.delete(); - return ; - } - //clean the picture and reuse it - picture.getByteBuffer().clear(); - } - } finally { - if (picture != null) - picture.delete(); - iPacket.delete(); - // ByteBufferUtil.destroy(data); - } - return ; + converter.delete(); + } else { + picture.delete(); + iPacket.delete(); + return; + } + // clean the picture and reuse it + picture.getByteBuffer().clear(); + } + } finally { + if (picture != null) { + picture.delete(); + } + iPacket.delete(); + // ByteBufferUtil.destroy(data); + } + return; } - + } - - - - - - - - - - - - - - - - - - - - } diff --git a/webcam-capture-examples/webcam-capture-onejar/.classpath b/webcam-capture-examples/webcam-capture-onejar/.classpath index 534b5e52..fd7ad7fb 100644 --- a/webcam-capture-examples/webcam-capture-onejar/.classpath +++ b/webcam-capture-examples/webcam-capture-onejar/.classpath @@ -6,22 +6,12 @@ - - - - - - - - - -