
org.jitsi.impl.neomedia.protocol.FakePushBufferDataSource 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.jmfext.media.protocol.*;
/**
* Implements {@link PushBufferDataSource} for the purposes of
* {@link org.jitsi.service.neomedia.RTPTranslator} when it does not have a CaptureDevice yet
* RTPManager.createSendStream(DataSource, int) has to be called to
* have RTPTranslatorImpl send packets.
*
* @author Lyubomir Marinov
*/
public class FakePushBufferDataSource
extends AbstractPushBufferCaptureDevice
{
/**
* The Formats in which this DataSource is capable of
* providing media.
*/
private final Format[] supportedFormats;
/**
* Initializes a new FakePushBufferCaptureDevice instance which is
* to report a specific list of Formats as supported.
*
* @param supportedFormats the list of Formats to be reported as
* supported by the new instance
*/
public FakePushBufferDataSource(Format... supportedFormats)
{
this.supportedFormats
= (supportedFormats == null) ? null : supportedFormats.clone();
}
/**
* Opens a connection to the media source specified by the
* MediaLocator of this DataSource.
*
* @throws IOException if anything goes wrong while opening the connection
* to the media source specified by the MediaLocator of this
* DataSource
*/
@Override
public void connect()
throws IOException
{
/*
* The connect, disconnect, start and stop methods of the super have
* been overridden in order to disable consistency checks with respect
* to the connected and started states.
*/
}
/**
* Create a new PushBufferStream which is to be at a specific
* zero-based index in the list of streams of this
* PushBufferDataSource. The Format-related information of
* the new instance is to be abstracted by a specific
* FormatControl.
*
* @param streamIndex the zero-based index of the PushBufferStream
* in the list of streams of this PushBufferDataSource
* @param formatControl the FormatControl which is to abstract the
* Format-related information of the new instance
* @return a new PushBufferStream which is to be at the specified
* streamIndex in the list of streams of this
* PushBufferDataSource and which has its Format-related
* information abstracted by the specified formatControl
*/
@Override
protected FakePushBufferStream createStream(
int streamIndex,
FormatControl formatControl)
{
return new FakePushBufferStream(this, formatControl);
}
/**
* Closes the connection to the media source specified of this
* AbstractBufferCaptureDevice. If such a connection has not been
* opened, the call is ignored.
*/
@Override
public void disconnect()
{
/*
* The connect, disconnect, start and stop methods of the super have
* been overridden in order to disable consistency checks with respect
* to the connected and started states.
*/
}
/**
* Gets the Formats which are to be reported by a
* FormatControl as supported formats for a
* PushBufferStream at a specific zero-based index in the list of
* streams of this PushBufferDataSource.
*
* @param streamIndex the zero-based index of the PushBufferStream
* for which the specified FormatControl is to report the list of
* supported Formats
* @return an array of Formats to be reported by a
* FormatControl as the supported formats for the
* PushBufferStream at the specified streamIndex in the
* list of streams of this PushBufferDataSource
*/
@Override
protected Format[] getSupportedFormats(int streamIndex)
{
return (supportedFormats == null) ? null : supportedFormats.clone();
}
/**
* {@inheritDoc}
*
* Allows setting an arbitrary Format on this DataSource
* because it does not really provide any media.
*/
@Override
protected Format setFormat(
int streamIndex,
Format oldValue, Format newValue)
{
return newValue;
}
/**
* Starts the transfer of media data from this DataSource.
*
* @throws IOException if anything goes wrong while starting the transfer of
* media data from this DataSource
*/
@Override
public void start()
throws IOException
{
/*
* The connect, disconnect, start and stop methods of the super have
* been overridden in order to disable consistency checks with respect
* to the connected and started states.
*/
}
/**
* Stops the transfer of media data from this DataSource.
*
* @throws IOException if anything goes wrong while stopping the transfer of
* media data from this DataSource
*/
@Override
public void stop()
throws IOException
{
/*
* The connect, disconnect, start and stop methods of the super have
* been overridden in order to disable consistency checks with respect
* to the connected and started states.
*/
}
/**
* Implements {@link PushBufferStream} for the purposes of
* FakePushBufferDataSource.
*/
private static class FakePushBufferStream
extends AbstractPushBufferStream
{
/**
* Initializes a new FakePushBufferStream instance which is to
* have its Format-related information abstracted by a specific
* FormatControl.
*
* @param dataSource the FakePushBufferDataSource which is
* creating the new instance so that it becomes one of its
* streams
* @param formatControl the FormatControl which is to abstract
* the Format-related information of the new instance
*/
FakePushBufferStream(
FakePushBufferDataSource dataSource,
FormatControl formatControl)
{
super(dataSource, formatControl);
}
/**
* {@inheritDoc}
*
* Allows setting an arbitrary format on this SourceStream
* because it does not really provide any media.
*/
@Override
protected Format doSetFormat(Format format)
{
return format;
}
/**
* Reads media data from this PushBufferStream into a specific
* Buffer without blocking.
*
* @param buffer the Buffer in which media data is to be read
* from this PushBufferStream
* @throws IOException if anything goes wrong while reading media data
* from this PushBufferStream into the specified
* buffer
*/
@Override
public void read(Buffer buffer)
throws IOException
{
/*
* The whole point of FakePushBufferDataSource and
* FakePushBufferStream is that this read method is a no-op (and
* this FakePushBufferStream will never invoke its associated
* transferHandler).
*/
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy