
org.jitsi.impl.neomedia.protocol.CaptureDeviceDelegatePullBufferDataSource Maven / Gradle / Ivy
/*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jitsi.impl.neomedia.protocol;
import java.io.*;
import javax.media.*;
import javax.media.control.*;
import javax.media.protocol.*;
import org.jitsi.impl.neomedia.control.*;
/**
* Represents a PullBufferDataSource which is also a
* CaptureDevice through delegation to a specific
* CaptureDevice.
*
* @author Damian Minkov
* @author Lubomir Marinov
*/
public class CaptureDeviceDelegatePullBufferDataSource
extends PullBufferDataSource
implements CaptureDevice
{
/**
* The CaptureDevice this instance delegates to in order to
* implement its CaptureDevice functionality.
*/
protected final CaptureDevice captureDevice;
/**
* The constant which represents an empty array with
* PullBufferStream element type. Explicitly defined in order to
* reduce unnecessary allocations.
*/
protected static final PullBufferStream[] EMPTY_STREAMS
= new PullBufferStream[0];
/**
* Initializes a new CaptureDeviceDelegatePullBufferDataSource
* instance which delegates to a specific CaptureDevice in order to
* implement its CaptureDevice functionality.
*
* @param captureDevice the CaptureDevice the new instance is to
* delegate to in order to provide its CaptureDevice functionality
*/
public CaptureDeviceDelegatePullBufferDataSource(
CaptureDevice captureDevice)
{
this.captureDevice = captureDevice;
}
/**
* Implements {@link PullBufferDataSource#getStreams()}. Delegates to the
* wrapped CaptureDevice if it implements
* PullBufferDataSource; otherwise, returns an empty array with
* PullBufferStream element type.
*
* @return an array of PullBufferStreams as returned by the wrapped
* CaptureDevice if it implements PullBufferDataSource;
* otherwise, an empty array with PullBufferStream element type
*/
@Override
public PullBufferStream[] getStreams()
{
if (captureDevice instanceof PullBufferDataSource)
return ((PullBufferDataSource) captureDevice).getStreams();
return EMPTY_STREAMS;
}
/**
* Implements {@link DataSource#getContentType()}. Delegates to the wrapped
* CaptureDevice if it implements DataSource; otherwise,
* returns {@link ContentDescriptor#CONTENT_UNKNOWN}.
*
* @return a String value which describes the content type of the
* wrapped CaptureDevice if it implements DataSource;
* otherwise, ContentDescriptor#CONTENT_UNKNOWN
*/
@Override
public String getContentType()
{
if (captureDevice instanceof DataSource)
return ((DataSource) captureDevice).getContentType();
return ContentDescriptor.CONTENT_UNKNOWN;
}
/**
* Implements {@link CaptureDevice#connect()}. Delegates to the wrapped
* CaptureDevice if available; otherwise, does nothing.
*
* @throws IOException if the wrapped CaptureDevice throws such an
* exception
*/
@Override
public void connect()
throws IOException
{
if (captureDevice != null)
captureDevice.connect();
}
/**
* Implements {@link CaptureDevice#disconnect()}. Delegates to the wrapped
* CaptureDevice if available; otherwise, does nothing.
*/
@Override
public void disconnect()
{
if (captureDevice != null)
captureDevice.disconnect();
}
/**
* Implements {@link CaptureDevice#start()}. Delegates to the wrapped
* CaptureDevice if available; otherwise, does nothing.
*
* @throws IOException if the wrapped CaptureDevice throws such an
* exception
*/
@Override
public void start()
throws IOException
{
if (captureDevice != null)
captureDevice.start();
}
/**
* Implements {@link CaptureDevice#start()}. Delegates to the wrapped
* CaptureDevice if available; otherwise, does nothing.
*
* @throws IOException if the wrapped CaptureDevice throws such an
* exception
*/
@Override
public void stop()
throws IOException
{
if (captureDevice != null)
captureDevice.stop();
}
/**
* Implements {@link DataSource#getControl(String)}. Delegates to the
* wrapped CaptureDevice if it implements DataSource;
* otherwise, returns null.
*
* @param controlType a String value which names the type of the
* control to be retrieved
* @return an Object which represents the control of the requested
* controlType of the wrapped CaptureDevice if it
* implements DataSource; otherwise, null
*/
@Override
public Object getControl(String controlType)
{
if (captureDevice instanceof DataSource)
return ((DataSource) captureDevice).getControl(controlType);
return null;
}
/**
* Implements {@link DataSource#getControls()}. Delegates to the wrapped
* CaptureDevice if it implements DataSource; otherwise,
* returns an empty array with Object element type.
*
* @return the array of controls for the wrapped CaptureDevice if
* it implements DataSource; otherwise, an empty array with
* Object element type
*/
@Override
public Object[] getControls()
{
if (captureDevice instanceof DataSource)
return ((DataSource) captureDevice).getControls();
return ControlsAdapter.EMPTY_CONTROLS;
}
/**
* Implements {@link DataSource#getDuration()}. Delegates to the wrapped
* CaptureDevice if it implements DataSource; otherwise,
* returns {@link DataSource#DURATION_UNKNOWN}.
*
* @return the duration of the wrapped CaptureDevice as returned by
* its implementation of DataSource if any; otherwise, returns
* DataSource#DURATION_UNKNOWN
*/
@Override
public Time getDuration()
{
if (captureDevice instanceof DataSource)
return ((DataSource) captureDevice).getDuration();
return DataSource.DURATION_UNKNOWN;
}
/**
* Implements {@link CaptureDevice#getFormatControls()}. Delegates to the
* wrapped CaptureDevice if available; otherwise, returns an empty
* array with FormatControl element type.
*
* @return the array of FormatControls of the wrapped
* CaptureDevice if available; otherwise, an empty array with
* FormatControl element type
*/
public FormatControl[] getFormatControls()
{
return
(captureDevice != null)
? captureDevice.getFormatControls()
: new FormatControl[0];
}
/**
* Implements {@link CaptureDevice#getCaptureDeviceInfo()}. Delegates to the
* wrapped CaptureDevice if available; otherwise, returns
* null.
*
* @return the CaptureDeviceInfo of the wrapped
* CaptureDevice if available; otherwise, null
*/
public CaptureDeviceInfo getCaptureDeviceInfo()
{
return
(captureDevice != null)
? captureDevice.getCaptureDeviceInfo()
: null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy