
org.jitsi.impl.neomedia.device.AbstractMediaDevice 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.device;
import java.io.*;
import java.util.*;
import javax.media.*;
import javax.media.protocol.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.service.neomedia.device.*;
import org.jitsi.service.neomedia.format.*;
/**
* Defines the interface for MediaDevice required by the
* org.jitsi.impl.neomedia implementation of
* org.jitsi.service.neomedia.
*
* @author Lyubomir Marinov
*/
public abstract class AbstractMediaDevice
implements MediaDevice
{
/**
* Connects to a specific CaptureDevice given in the form of a
* DataSource. Explicitly defined in order to allow extenders to
* customize the connect procedure.
*
* @param captureDevice the CaptureDevice to be connected to
* @throws IOException if anything wrong happens while connecting to the
* specified captureDevice
*/
public void connect(DataSource captureDevice)
throws IOException
{
if (captureDevice == null)
throw new NullPointerException("captureDevice");
try
{
captureDevice.connect();
}
catch (NullPointerException npe)
{
/*
* The old media says it happens when the operating system does not
* support the operation.
*/
IOException ioe = new IOException();
ioe.initCause(npe);
throw ioe;
}
}
/**
* Creates a DataSource instance for this MediaDevice
* which gives access to the captured media.
*
* @return a DataSource instance which gives access to the media
* captured by this MediaDevice
*/
protected abstract DataSource createOutputDataSource();
/**
* Initializes a new Processor instance which is to be used to play
* back media on this MediaDevice. Allows extenders to, for
* example, disable the playback on this MediaDevice by completely
* overriding and returning null.
*
* @param dataSource the DataSource which is to be played back by
* the new Processor instance
* @return a new Processor instance which is to be used to play
* back the media provided by the specified dataSource or
* null if the specified dataSource is to not be played
* back
* @throws Exception if an exception is thrown by
* {@link DataSource#connect()},
* {@link Manager#createProcessor(DataSource)}, or
* {@link DataSource#disconnect()}
*/
protected Processor createPlayer(DataSource dataSource)
throws Exception
{
Processor player = null;
// A Player is documented to be created on a connected DataSource.
dataSource.connect();
try
{
player = Manager.createProcessor(dataSource);
}
finally
{
if (player == null)
dataSource.disconnect();
}
return player;
}
/**
* Initializes a new Renderer instance which is to play back media
* on this MediaDevice. Allows extenders to initialize a specific
* Renderer instance. The implementation of
* AbstractMediaDevice returns null which means that it is
* left to FMJ to choose a suitable Renderer irrespective of this
* MediaDevice.
*
* @return a new Renderer instance which is to play back media on
* this MediaDevice or null if a suitable
* Renderer is to be chosen irrespective of this
* MediaDevice
*/
protected Renderer createRenderer()
{
return null;
}
/**
* Creates a new MediaDeviceSession instance which is to represent
* the use of this MediaDevice by a MediaStream.
*
* @return a new MediaDeviceSession instance which is to represent
* the use of this MediaDevice by a MediaStream
*/
public MediaDeviceSession createSession()
{
switch (getMediaType())
{
case VIDEO:
return new VideoMediaDeviceSession(this);
default:
return new AudioMediaDeviceSession(this);
}
}
/**
* Returns a List containing (at the time of writing) a single
* extension descriptor indicating RECVONLY support for
* mixer-to-client audio levels.
*
* @return a List containing the CSRC_AUDIO_LEVEL_URN
* extension descriptor.
*/
public List getSupportedExtensions()
{
return null;
}
/**
* Gets a list of MediaFormats supported by this
* MediaDevice.
*
* @return the list of MediaFormats supported by this device
* @see MediaDevice#getSupportedFormats()
*/
public List getSupportedFormats()
{
return getSupportedFormats(null, null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy