From 9ca0368803531e47df01fdfd3db30786cbb52ab1 Mon Sep 17 00:00:00 2001 From: Lyubomir Marinov Date: Wed, 9 Nov 2011 20:27:07 +0000 Subject: [PATCH] Reduces the number of times that Jitsi's CaptureDevices get started/stopped in order to, for example, bring down the number of times that (some) webcams flash on and off. --- .../protocol/AbstractBufferCaptureDevice.java | 100 +++++++++++++++--- 1 file changed, 85 insertions(+), 15 deletions(-) diff --git a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/AbstractBufferCaptureDevice.java b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/AbstractBufferCaptureDevice.java index 822118638..077c6a3aa 100644 --- a/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/AbstractBufferCaptureDevice.java +++ b/src/net/java/sip/communicator/impl/neomedia/jmfext/media/protocol/AbstractBufferCaptureDevice.java @@ -11,13 +11,15 @@ import java.util.*; import javax.media.*; -import javax.media.Controls; // disambiguation +import javax.media.Controls; import javax.media.control.*; import javax.media.protocol.*; import net.java.sip.communicator.impl.neomedia.control.*; import net.java.sip.communicator.util.*; +import com.sun.media.util.*; + /** * Facilitates the implementations of the CaptureDevice and * DataSource interfaces provided by @@ -71,6 +73,11 @@ public abstract class AbstractBufferCaptureDevice */ private FrameRateControl[] frameRateControls; + /** + * The RTPInfos of this AbstractBufferCaptureDevice. + */ + private RTPInfo[] rtpInfos; + /** * The indicator which determines whether the transfer of media data from * this DataSource has been started. @@ -225,6 +232,26 @@ protected FrameRateControl createFrameRateControl() return null; } + /** + * Creates a new RTPInfo instance of this + * AbstractBufferCaptureDevice. + * + * @return a new RTPInfo instance of this + * AbstractBufferCaptureDevice + */ + protected RTPInfo createRTPInfo() + { + return + new RTPInfo() + { + public String getCNAME() + { + // TODO Auto-generated method stub + return null; + } + }; + } + /** * Create a new AbstractBufferStream which is to be at a specific * zero-based index in the list of streams of this @@ -289,27 +316,48 @@ final void defaultDoStop() final Object[] defaultGetControls() { FormatControl[] formatControls = internalGetFormatControls(); + int formatControlCount + = (formatControls == null) ? 0 : formatControls.length; FrameRateControl[] frameRateControls = internalGetFrameRateControls(); - - if (((formatControls == null) || (formatControls.length == 0)) - && ((frameRateControls == null) - || (frameRateControls.length == 0))) + int frameRateControlCount + = (frameRateControls == null) ? 0 : frameRateControls.length; + RTPInfo[] rtpInfos = internalGetRTPInfos(); + int rtpInfoCount = (rtpInfos == null) ? 0 : rtpInfos.length; + + if ((formatControlCount == 0) + && (frameRateControlCount == 0) + && (rtpInfoCount == 0)) return ControlsAdapter.EMPTY_CONTROLS; else { Object[] controls - = new Object[formatControls.length + frameRateControls.length]; + = new Object[ + formatControlCount + + frameRateControlCount + + rtpInfoCount]; int offset = 0; - System.arraycopy( - formatControls, 0, - controls, offset, - formatControls.length); - offset += formatControls.length; - System.arraycopy( - frameRateControls, 0, - controls, offset, - frameRateControls.length); + if (formatControlCount != 0) + { + System.arraycopy( + formatControls, 0, + controls, offset, + formatControlCount); + offset += formatControlCount; + } + if (frameRateControlCount != 0) + { + System.arraycopy( + frameRateControls, 0, + controls, offset, + frameRateControlCount); + offset += frameRateControlCount; + } + if (rtpInfoCount != 0) + { + System.arraycopy(rtpInfos, 0, controls, offset, rtpInfoCount); + offset += rtpInfoCount; + } return controls; } } @@ -688,6 +736,28 @@ private synchronized FrameRateControl[] internalGetFrameRateControls() return frameRateControls; } + /** + * Gets an array of RTPInfo instances of this + * AbstractBufferCaptureDevice. + * + * @return an array of RTPInfo instances of this + * AbstractBufferCaptureDevice. + */ + private synchronized RTPInfo[] internalGetRTPInfos() + { + if (rtpInfos == null) + { + RTPInfo rtpInfo = createRTPInfo(); + + // Don't try to create the RTPInfo more than once. + rtpInfos + = (rtpInfo == null) + ? new RTPInfo[0] + : new RTPInfo[] { rtpInfo }; + } + return rtpInfos; + } + /** * Attempts to set the Format to be reported by the * FormatControl of a PushBufferStream at a specific