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

org.jitsi.impl.neomedia.protocol.PushBufferDataSourceDelegate 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.protocol.*;

/**
 * Implements most of PushBufferDataSource for a particular
 * DataSource and requires extenders to only implement
 * {@link PushBufferDataSource#getStreams()}. Intended to allow easier
 * overriding of the streams returned by a DataSource.
 *
 * @param  the very type of DataSource to be wrapped in a
 * PushBufferDataSourceDelegate
 *
 * @author Lyubomir Marinov
 */
public abstract class PushBufferDataSourceDelegate
    extends CaptureDeviceDelegatePushBufferDataSource
{

    /**
     * The wrapped DataSource this instance delegates to.
     */
    protected final T dataSource;

    /**
     * Initializes a new PushBufferDataSourceDelegate which is to
     * delegate to a specific DataSource.
     *
     * @param dataSource the DataSource the new instance is to delegate
     * to
     */
    public PushBufferDataSourceDelegate(T dataSource)
    {
        super(
            (dataSource instanceof CaptureDevice)
                ? (CaptureDevice) dataSource
                : null);

        if (dataSource == null)
            throw new NullPointerException("dataSource");

        this.dataSource = dataSource;
    }

    /**
     * Implements {@link DataSource#connect()}. Delegates to the wrapped
     * DataSource. Overrides
     * {@link CaptureDeviceDelegatePushBufferDataSource#connect()} because the
     * wrapped DataSource may not be a CaptureDevice yet it
     * still needs to be connected.
     *
     * @throws IOException if the wrapped DataSource throws such an
     * exception
     */
    @Override
    public void connect()
        throws IOException
    {
        dataSource.connect();
    }

    /**
     * Implements {@link DataSource#disconnect()}. Delegates to the wrapped
     * DataSource. Overrides
     * {@link CaptureDeviceDelegatePushBufferDataSource#disconnect()} because
     * the wrapped DataSource may not be a CaptureDevice yet
     * it still needs to be disconnected.
     */
    @Override
    public void disconnect()
    {
        dataSource.disconnect();
    }

    /**
     * Implements {@link DataSource#getContentType()}. Delegates to the wrapped
     * DataSource. Overrides
     * {@link CaptureDeviceDelegatePushBufferDataSource#getContentType()}
     * because the wrapped DataSource may not be a
     * CaptureDevice yet it still needs to report the content type.
     *
     * @return a String value which describes the content type of the
     * wrapped DataSource
     */
    @Override
    public String getContentType()
    {
        return dataSource.getContentType();
    }

    /**
     * Implements {@link DataSource#getLocator()}. Delegates to the wrapped
     * DataSource.
     *
     * @return a MediaLocator value which describes the locator of the
     * wrapped DataSource
     */
    @Override
    public MediaLocator getLocator()
    {
        return dataSource.getLocator();
    }

    /**
     * Implements {@link DataSource#getControl(String)}. Delegates to the
     * wrapped DataSource. Overrides
     * {@link CaptureDeviceDelegatePushBufferDataSource#getControl(String)}
     * because the wrapped DataSource may not be a
     * CaptureDevice yet it still needs to give access to the control.
     *
     * @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 DataSource
     */
    @Override
    public Object getControl(String controlType)
    {
        return dataSource.getControl(controlType);
    }

    /**
     * Implements {@link DataSource#getControls()}. Delegates to the wrapped
     * PushBufferDataSource. Overrides
     * {@link CaptureDeviceDelegatePushBufferDataSource#getControls()} because
     * the wrapped DataSource may not be a CaptureDevice yet
     * it still needs to give access to the controls.
     *
     * @return an array of Objects which represent the controls of the
     * wrapped DataSource
     */
    @Override
    public Object[] getControls()
    {
        return dataSource.getControls();
    }

    /**
     * Gets the DataSource wrapped by this instance.
     *
     * @return the DataSource wrapped by this instance
     */
    public T getDataSource()
    {
        return dataSource;
    }

    /**
     * Implements {@link DataSource#getDuration()}. Delegates to the wrapped
     * DataSource. Overrides
     * {@link CaptureDeviceDelegatePushBufferDataSource#getDuration()} because
     * the wrapped DataSource may not be a CaptureDevice yet
     * it still needs to report the duration.
     *
     * @return the duration of the wrapped DataSource
     */
    @Override
    public Time getDuration()
    {
        return dataSource.getDuration();
    }

    /**
     * Gets the PushBufferStreams through which this
     * PushBufferDataSource gives access to its media data.
     *
     * @return an array of PushBufferStreams through which this
     * PushBufferDataSource gives access to its media data
     */
    @Override
    public abstract PushBufferStream[] getStreams();

    /**
     * Implements {@link DataSource#start()}. Delegates to the wrapped
     * DataSource. Overrides
     * {@link CaptureDeviceDelegatePushBufferDataSource#start()} because the
     * wrapped DataSource may not be a CaptureDevice yet it
     * still needs to be started.
     *
     * @throws IOException if the wrapped DataSource throws such an
     * exception
     */
    @Override
    public void start()
        throws IOException
    {
        dataSource.start();
    }

    /**
     * Implements {@link DataSource#stop()}. Delegates to the wrapped
     * DataSource. Overrides
     * {@link CaptureDeviceDelegatePushBufferDataSource#stop()} because the
     * wrapped DataSource may not be a CaptureDevice yet it
     * still needs to be stopped.
     *
     * @throws IOException if the wrapped DataSource throws such an
     * exception
     */
    @Override
    public void stop()
        throws IOException
    {
        dataSource.stop();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy