📄 avtransmitter.java
字号:
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* Large portions of this software are based upon public domain software
* https://sip-communicator.dev.java.net/
*
*/
package net.sourceforge.gjtapi.raw.sipprovider.media;
import net.sourceforge.gjtapi.raw.sipprovider.common.Console;
/**
* <p>Title: SIP COMMUNICATOR</p>
* <p>Description:JAIN-SIP Audio/Video phone application</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Organisation: LSIIT laboratory (http://lsiit.u-strasbg.fr) </p>
* <p>Network Research Team (http://www-r2.u-strasbg.fr))</p>
* <p>Louis Pasteur University - Strasbourg - France</p>
* @author Emil Ivov (http://www.emcho.com)
* @version 1.1
*
*/
import java.io.*;
import java.net.*;
import java.util.*;
import javax.media.*;
import javax.media.control.*;
import javax.media.protocol.*;
import javax.media.rtp.*;
class AVTransmitter
{
protected static Console console = Console.getConsole(AVTransmitter.class);
// Input MediaLocator
// Can be a file or http or capture source
protected MediaLocator locator;
protected String ipAddress;
protected Processor processor = null;
protected RTPManager rtpMgrs[];
//Used by mobility - keeps rtpMgrs[] corresponding addresses
protected SessionAddress sessionAddresses[] = null;
protected DataSource dataOutput = null;
protected ArrayList ports = null;
protected ArrayList formatSets = null;
protected MediaManager mediaManCallback = null;
private SendStream sendStream;
public AVTransmitter(Processor processor,
String ipAddress,
ArrayList ports,
ArrayList formatSets)
{
try
{
console.logEntry();
this.processor = processor;
this.ipAddress = ipAddress;
this.ports = ports;
this.formatSets = formatSets;
if (console.isDebugEnabled())
{
console.debug(
"Created transmitter for ["
+ ipAddress
+ "] at ports: "
+ ports.toString()
+ " encoded as: "
+ formatSets.toString());
}
}
finally
{
console.logExit();
}
}
void setMediaManagerCallback(MediaManager mediaManager)
{
this.mediaManCallback = mediaManager;
}
/**
* Starts the transmission. Returns null if transmission started ok.
* Otherwise it returns a string with the reason why the setup failed.
*/
synchronized String start() throws MediaException
{
try
{
console.logEntry();
// configureProcessor(processor);
// Create an RTP session to transmit the output of the
// processor to the specified IP address and port no.
try
{
createTransmitter();
}
catch (MediaException ex)
{
console.error("createTransmitter() failed", ex);
processor.close();
processor = null;
throw ex;
}
// Start the transmission
//processor.start();
return null;
}
finally
{
console.logExit();
}
}
/**
* Stops the transmission if already started
*/
void stop(SessionAddress addToStop)
{
try
{
console.logEntry();
synchronized (this)
{
if (processor != null)
{
processor.stop();
if (rtpMgrs != null)
{
for (int i = 0; i < rtpMgrs.length; i++)
{
if (rtpMgrs[i] == null)
{
continue;
}
rtpMgrs[i].removeTarget(addToStop,"Session ended.");
}
}
}
}
}
catch(javax.media.rtp.InvalidSessionAddressException ex)
{
console.debug(ex.toString());
}
finally
{
console.logExit();
}
}
protected void configureProcessor(Processor p) throws MediaException
{
processor = p;
try
{
console.logEntry();
if (processor == null)
{
console.error("Processor is null.");
throw new MediaException("Processor is null.");
}
// Wait for the processor to configure
boolean result = true;
if (processor.getState() < Processor.Configured)
{
result = waitForState(processor, Processor.Configured);
}
if (result == false)
{
console.error("Couldn't configure processor");
throw new MediaException("Couldn't configure processor");
}
// Get the tracks from the processor
TrackControl[] tracks = processor.getTrackControls();
// Do we have atleast one track?
if (tracks == null || tracks.length < 1)
{
console.error("Couldn't find tracks in processor");
throw new MediaException("Couldn't find tracks in processor");
}
// Set the output content descriptor to RAW_RTP
// This will limit the supported formats reported from
// Track.getSupportedFormats to only valid RTP formats.
ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
processor.setContentDescriptor(cd);
Format supported[];
boolean atLeastOneTrack = false;
// Program the tracks.
int i = 0;
if (tracks[i].isEnabled())
{
supported = tracks[i].getSupportedFormats();
if (console.isDebugEnabled())
{
console.debug("Available encodings are:");
for (int j = 0; j < supported.length; j++)
{
console.debug("track[" + (i + 1) + "] format[" +
(j + 1) + "]="
+ supported[j].getEncoding());
}
}
// We've set the output content to the RAW_RTP.
// So all the supported formats should work with RTP.
// We'll pick one that matches those specified by the constructor.
if (supported.length > 0)
{
int index = findFirstMatchingFormat(supported, formatSets);
if (index != -1)
{
tracks[i].setFormat(supported[index]);
if (console.isDebugEnabled())
{
console.debug("Track " + i +
" is set to transmit as: "
+ supported[index]);
}
atLeastOneTrack = true;
}
else
{
tracks[i].setEnabled(false);
}
}
else
{
tracks[i].setEnabled(false);
}
}
else
{
tracks[i].setEnabled(false);
}
if (!atLeastOneTrack)
{
console.error(
"Couldn't set any of the tracks to a valid RTP format");
throw new MediaException(
"Couldn't set any of the tracks to a valid RTP format");
}
// Realize the processor. This will internally create a flow
// graph and attempt to create an output datasource
result = waitForState(processor, Controller.Realized);
if (result == false)
{
console.error("Couldn't realize processor");
throw new MediaException("Couldn't realize processor");
}
// Get the output data source of the processor
dataOutput = processor.getDataOutput();
}
finally
{
console.logExit();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -