All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jitsi.impl.neomedia.protocol.CaptureDeviceDelegatePushBufferDataSource Maven / Gradle / Ivy

Go to download

libjitsi is an advanced Java media library for secure real-time audio/video communication

The newest version!
/*
 * 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 PushBufferDataSource which is also a
 * CaptureDevice through delegation to a specific
 * CaptureDevice.
 *
 * @author Lubomir Marinov
 */
public class CaptureDeviceDelegatePushBufferDataSource
    extends PushBufferDataSource
    implements CaptureDevice
{

    /**
     * The constant which represents an empty array with
     * PushBufferStream element type. Explicitly defined in order to
     * reduce unnecessary allocations.
     */
    protected static final PushBufferStream[] EMPTY_STREAMS
        = new PushBufferStream[0];

    /**
     * The CaptureDevice this instance delegates to in order to
     * implement its CaptureDevice functionality.
     */
    protected final CaptureDevice captureDevice;

    /**
     * Initializes a new CaptureDeviceDelegatePushBufferDataSource
     * 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 CaptureDeviceDelegatePushBufferDataSource(
        CaptureDevice captureDevice)
    {
        this.captureDevice = captureDevice;
    }

    /**
     * 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#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;
    }

    /**
     * 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 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 PushBufferDataSource#getStreams()}. Delegates to the
     * wrapped CaptureDevice if it implements
     * PushBufferDataSource; otherwise, returns an empty array with
     * PushBufferStream element type.
     *
     * @return an array of PushBufferStreams as returned by the wrapped
     * CaptureDevice if it implements PushBufferDataSource;
     * otherwise, an empty array with PushBufferStream element type
     */
    @Override
    public PushBufferStream[] getStreams()
    {
        if (captureDevice instanceof PushBufferDataSource)
            return ((PushBufferDataSource) captureDevice).getStreams();
        return EMPTY_STREAMS;
    }

    /**
     * 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#stop()}. 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();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy