Reduces the number of times that CaptureDevices get opened. In the case of video this may be visible as flashes of the camera indicator light.

cusax-fix
Lyubomir Marinov 16 years ago
parent 011af719e8
commit df59303827

@ -108,8 +108,8 @@ CaptureDevice createCaptureDevice()
{
captureDevice
= (CaptureDevice)
Manager
.createDataSource(captureDeviceInfo.getLocator());
Manager.createDataSource(
captureDeviceInfo.getLocator());
}
catch (IOException ioe)
{

@ -362,22 +362,18 @@ protected DataSource createCaptureDevice()
// Try to enable muting.
if (captureDevice instanceof PushBufferDataSource)
{
MutePushBufferDataSource mutePushBufferDataSource
captureDevice
= new MutePushBufferDataSource(
(PushBufferDataSource) captureDevice);
mutePushBufferDataSource.setMute(mute);
captureDevice = mutePushBufferDataSource;
}
else if (captureDevice instanceof PullBufferDataSource)
{
MutePullBufferDataSource mutePullBufferDataSource
captureDevice
= new MutePullBufferDataSource(
(PullBufferDataSource) captureDevice);
mutePullBufferDataSource.setMute(mute);
captureDevice = mutePullBufferDataSource;
}
if (captureDevice instanceof MuteDataSource)
((MuteDataSource) captureDevice).setMute(mute);
return captureDevice;
}

@ -170,8 +170,8 @@ protected DataSource createCaptureDevice()
*/
FrameRateControl frameRateControl
= (FrameRateControl)
captureDevice
.getControl(FrameRateControl.class.getName());
captureDevice.getControl(
FrameRateControl.class.getName());
float defaultFrameRate = 10;
if ((frameRateControl != null)
@ -295,6 +295,49 @@ protected void fireVideoEvent(VideoEvent videoEvent)
videoNotifierSupport.fireVideoEvent(videoEvent);
}
/**
* Gets the JMF <tt>Format</tt> of the <tt>captureDevice</tt> of this
* <tt>MediaDeviceSession</tt>.
*
* @return the JMF <tt>Format</tt> of the <tt>captureDevice</tt> of this
* <tt>MediaDeviceSession</tt>
*/
private Format getCaptureDeviceFormat()
{
DataSource captureDevice = getCaptureDevice();
if (captureDevice != null)
{
FormatControl[] formatControls = null;
if (captureDevice instanceof CaptureDevice)
{
formatControls
= ((CaptureDevice) captureDevice).getFormatControls();
}
if ((formatControls == null) || (formatControls.length == 0))
{
FormatControl formatControl
= (FormatControl)
captureDevice.getControl(FormatControl.class.getName());
if (formatControl != null)
formatControls = new FormatControl[] { formatControl };
}
if (formatControls != null)
{
for (FormatControl formatControl : formatControls)
{
Format format = formatControl.getFormat();
if (format != null)
return format;
}
}
}
return null;
}
/**
* Get the local <tt>Player</tt> if it exists,
* create it otherwise
@ -1012,31 +1055,39 @@ public void setRemoteSSRC(long remoteSSRC)
@Override
protected void setProcessorFormat(Processor processor, Format format)
{
Format newFormat = null;
VideoFormat tmp = (VideoFormat)format;
Dimension deviceSize = ((VideoMediaFormat)getDevice().getFormat()).getSize();
/* Add a size in the output format. As VideoFormat has no setter, we
* recreate the object. Check also if capture device can output
* this size.
/*
* Add a size in the output format. As VideoFormat has no setter, we
* recreate the object. Also check whether capture device can output
* such a size.
*/
if((deviceSize != null && outputSize != null) &&
(outputSize.width > 0 && outputSize.height > 0) &&
(deviceSize.width > outputSize.width ||
deviceSize.height > outputSize.height))
if((outputSize != null)
&& (outputSize.width > 0)
&& (outputSize.height > 0))
{
newFormat = new VideoFormat(tmp.getEncoding(), outputSize,
tmp.getMaxDataLength(), tmp.getDataType(),
tmp.getFrameRate());
Dimension deviceSize
= ((VideoFormat) getCaptureDeviceFormat()).getSize();
if ((deviceSize != null)
&& ((deviceSize.width > outputSize.width)
|| (deviceSize.height > outputSize.height)))
{
VideoFormat videoFormat = (VideoFormat) format;
format
= new VideoFormat(
videoFormat.getEncoding(),
outputSize,
videoFormat.getMaxDataLength(),
videoFormat.getDataType(),
videoFormat.getFrameRate());
}
else
outputSize = null;
}
else
{
outputSize = null;
}
super.setProcessorFormat(
processor,
newFormat != null ? newFormat : format);
super.setProcessorFormat(processor, format);
}
/**

@ -108,14 +108,14 @@ private MutePullBufferStream(PullBufferStream stream)
}
/**
* Implements PullBufferStream#willReadBlock(). Delegates to the wrapped
* PullSourceStream.
* @return <tt>true</tt> if read would block; otherwise returns
* <tt>false</tt>.
* Implements {@link PullBufferStream#getFormat()}. Delegates to the
* wrapped <tt>PullBufferStream</tt>.
*
* @return the <tt>Format</tt> of the wrapped <tt>PullBufferStream</tt>
*/
public boolean willReadBlock()
public Format getFormat()
{
return stream.willReadBlock();
return stream.getFormat();
}
/**
@ -135,14 +135,14 @@ public void read(Buffer buffer)
}
/**
* Implements {@link PullBufferStream#getFormat()}. Delegates to the
* wrapped <tt>PullBufferStream</tt>.
*
* @return the <tt>Format</tt> of the wrapped <tt>PullBufferStream</tt>
* Implements PullBufferStream#willReadBlock(). Delegates to the wrapped
* PullSourceStream.
* @return <tt>true</tt> if read would block; otherwise returns
* <tt>false</tt>.
*/
public Format getFormat()
public boolean willReadBlock()
{
return stream.getFormat();
return stream.willReadBlock();
}
}
}

@ -677,7 +677,6 @@ private Vector<MediaDescription> createMediaDescriptions()
{
MediaDescription md =
createMediaDescription(
dev.getFormat(),
dev.getSupportedFormats(),
getStreamConnector(mediaType),
direction,
@ -1272,7 +1271,6 @@ private Vector<MediaDescription> createMediaDescriptionsForAnswer(
// create the answer description
answerDescriptions.add(createMediaDescription(
dev.getFormat(),
supportedAdvancedParameters, connector,
direction, rtpExtensions));
@ -1542,7 +1540,6 @@ private String getUserName()
* taking account the local streaming preference for the corresponding
* media type.
*
* @param captureFormat capture <tt>MediaFormat</tt> of the device.
* @param formats the list of <tt>MediaFormats</tt> that we'd like to
* advertise.
* @param connector the <tt>StreamConnector</tt> that we will be using
@ -1559,15 +1556,13 @@ private String getUserName()
* <tt>MediaDescription</tt> fails for some reason.
*/
private MediaDescription createMediaDescription(
MediaFormat captureFormat,
List<MediaFormat> formats,
StreamConnector connector,
MediaDirection direction,
List<RTPExtension> extensions )
throws OperationFailedException
{
return SdpUtils.createMediaDescription(
captureFormat, formats, connector,
return SdpUtils.createMediaDescription(formats, connector,
direction, extensions,
dynamicPayloadTypes, rtpExtensionsRegistry);
}

@ -1233,7 +1233,6 @@ public static URL getCallInfoURL(SessionDescription sessDesc)
* description is determined via from the type of the first
* <tt>MediaFormat</tt> in the <tt>formats</tt> list.
*
* @param captureFormat capture <tt>MediaFormat</tt> of the device.
* @param formats the list of formats that should be advertised in the newly
* created <tt>MediaDescription</tt>.
* @param connector the socket couple that will be used for the media stream
@ -1256,7 +1255,6 @@ public static URL getCallInfoURL(SessionDescription sessDesc)
* some other reason.
*/
public static MediaDescription createMediaDescription(
MediaFormat captureFormat,
List<MediaFormat> formats,
StreamConnector connector,
MediaDirection direction,
@ -1266,8 +1264,8 @@ public static MediaDescription createMediaDescription(
throws OperationFailedException
{
int[] payloadTypesArray = new int[formats.size()];
Vector<Attribute> mediaAttributes = new Vector<Attribute>(
2 * payloadTypesArray.length + 1);
Vector<Attribute> mediaAttributes
= new Vector<Attribute>(2 * payloadTypesArray.length + 1);
MediaType mediaType = null;
// a=sendonly|sendrecv|recvonly|inactive

Loading…
Cancel
Save