?? avtransmitter.java
字號:
int remoteVideo = at.findPortForLocal(Integer.parseInt(mediaManCallback.getVideoPort()));
if(((String)contents.get(i)).equals("video")){
sessions.add(remoteAddress.getHostAddress() + "/" + /* audioPort */ /*mediaManCallback.getVideoPort() */ remoteVideo + "/" + remoteVideo + "/1/video");
//avReceiver[i]= new AVReceive2(("200.233.219.41/" + mediaManCallback.getVideoPort()).split("t"),rtpMgrs[i]);
}else{
sessions.add(remoteAddress.getHostAddress() + "/" + remoteAudio /*mediaManCallback.getAudioPort()*/ + "/" + remoteAudio + "/1/audio");
//avReceiver[i]= new AVReceive2(("200.233.219.41/" + remoteAudio).split("t"),rtpMgrs[i]);
}
/////////////////////////////////////////////////////////
avReceiver[i] = new AVReceiverMais(sessions,rtpMgrs[i]);
avReceiver[i].setMediaManager(mediaManCallback);
rtpMgrs[i].initialize(localAddr);
avReceiver[i].initialize();
rtpMgrs[i].addTarget(destAddr);
sessionAddresses[i] = destAddr;
}
catch (InvalidSessionAddressException ex) {
//port was occupied
success = false;
}
catch (IOException ex) {
//we should just try to notify user and continue with other tracks
mediaManCallback.fireNonFatalMediaError(new
MediaException(
"Failed to initialize an RTPManager for address pair:\n"
+ "Local address:" + localAddr.toString()
+ " data port:" + localAddr.getDataPort()
+ " control port:" + localAddr.getControlPort() +
"\n"
+ "Dest address:" + destAddr
+ " data port:" + destAddr.getDataPort()
+ " control port:" + destAddr.getControlPort(),
ex));
success = false;
retries = 0;
}
}
while (!success && --retries > 0);
//notify user if we could bind at all
if (!success) {
mediaManCallback.fireNonFatalMediaError(
new MediaException(
"Failed to initialise rtp manager for track " + i
+ " encoded as " + pbss[i].getFormat().getEncoding()
+ " @ [" + ipAddress + "]:" + port + "!"));
continue;
}
if(createdRtpManager)
mediaManCallback.putRtpManager(localAddr, rtpMgrs[i]);
try {
sendStream = rtpMgrs[i].createSendStream(dataOutput, i);
sendStream.setBitRate(56000);
sendStream.start();
System.out.println("CODEC: "+contents.get(i));
//if(contents.get(i).equals("video")){
// sendStream.stop();
//}
sendStreams.add(sendStream);
}
catch (Exception ex) {
mediaManCallback.fireNonFatalMediaError( new MediaException(
"Session " + i + " failed to start transmitting.", ex));
}
}
}finally{}
}finally{
}
}
/**
* For JPEG and H263, we know that they only work for particular
* sizes. So we'll perform extra checking here to make sure they
* are of the right sizes.
*/
Format checkForVideoSizes(Format original, Format supported)
{
try {
int width, height;
Dimension size = ( (VideoFormat) original).getSize();
Format jpegFmt = new Format(VideoFormat.JPEG_RTP);
Format h263Fmt = new Format(VideoFormat.H263_RTP);
if (supported.matches(jpegFmt)) {
// For JPEG, make sure width and height are divisible by 8.
width = (size.width % 8 == 0 ? size.width :
(int) (size.width / 8) * 8);
height = (size.height % 8 == 0 ? size.height :
(int) (size.height / 8) * 8);
}
else if (supported.matches(h263Fmt)) {
// For H.263, we only support some specific sizes.
if (size.width < 128) {
width = 128;
height = 96;
}
else if (size.width < 176||true) {
width = 176;
height = 144;
}
else {
width = 352;
height = 288;
}
}
else {
// We don't know this particular format. We'll just
// leave it alone then.
return supported;
}
return (new VideoFormat(null,
new Dimension(width, height),
Format.NOT_SPECIFIED,
null,
Format.NOT_SPECIFIED)).intersects(supported);
}
finally {
}
}
protected String findIPAddressForFormat(String format)
{
try {
for (int i = 0; i < formatSets.size(); i++) {
ArrayList currentSet = (ArrayList) formatSets.get(i);
for (int j = 0; j < currentSet.size(); j++) {
if ( ( (String) currentSet.get(j)).equals(format)) {
return (String) ipAddresses.get(i);
}
}
}
return null;
}
finally {
}
}
protected int findPortForFormat(String format)
{
try {
for (int i = 0; i < formatSets.size(); i++) {
ArrayList currentSet = (ArrayList) formatSets.get(i);
for (int j = 0; j < currentSet.size(); j++) {
if ( ( (String) currentSet.get(j)).equals(format)) {
return ( (Integer) ports.get(i)).intValue();
}
}
}
return -1;
}
finally {
}
}
protected int findPortForLocal(int local)
{
try {
//
ArrayList currentSet = (ArrayList) localPorts;
for (int i = 0; i < localPorts.size(); i++) {
System.out.println("PORT: "+ports.get(i));
System.out.println("LOCALPORT: "+((Integer)currentSet.get(i)));
if ( ((Integer)currentSet.get(i)).intValue() == local) {
return ( (Integer) ports.get(i)).intValue();
}
}
return -1;
}
finally {
}
}
protected int findLocalPortForFormat(String format)
{
try {
for (int i = 0; i < formatSets.size(); i++) {
ArrayList currentSet = (ArrayList) formatSets.get(i);
for (int j = 0; j < currentSet.size(); j++) {
if ( ( (String) currentSet.get(j)).equals(format)) {
return ( (Integer) localPorts.get(i)).intValue();
}
}
}
return -1;
}
finally {
}
}
protected String findContentForFormat(String format)
{
try {
for (int i = 0; i < formatSets.size(); i++) {
ArrayList currentSet = (ArrayList) formatSets.get(i);
for (int j = 0; j < currentSet.size(); j++) {
if ( ( (String) currentSet.get(j)).equals(format)) {
return (String)contents.get(i);
}
}
}
return "";
}
finally {
}
}
/**
* Setting the encoding quality to the specified value on the JPEG encoder.
* 0.5 is a good default.
*/
void setJPEGQuality(Player p, float val)
{
try {
Control cs[] = p.getControls();
QualityControl qc = null;
VideoFormat jpegFmt = new VideoFormat(VideoFormat.JPEG);
// Loop through the controls to find the Quality control for
// the JPEG encoder.
for (int i = 0; i < cs.length; i++) {
if (cs[i] instanceof QualityControl &&
cs[i] instanceof Owned) {
Object owner = ( (Owned) cs[i]).getOwner();
// Check to see if the owner is a Codec.
// Then check for the output format.
if (owner instanceof Codec) {
Format fmts[] = ( (Codec) owner).
getSupportedOutputFormats(null);
for (int j = 0; j < fmts.length; j++) {
if (fmts[j].matches(jpegFmt)) {
qc = (QualityControl) cs[i];
qc.setQuality(val);
break;
}
}
}
if (qc != null) {
break;
}
}
}
}
finally {
}
}
public RTPManager[] getRTPs(){
return rtpMgrs;
}
protected int findFirstMatchingFormat(Format[] hayStack, ArrayList needles)
{
try {
if (hayStack == null || needles == null) {
return -1;
}
for (int j = 0; j < needles.size(); j++) {
ArrayList currentSet = (ArrayList) needles.get(j);
for (int k = 0; k < currentSet.size(); k++) {
for (int i = 0; i < hayStack.length; i++) {
if (hayStack[i].getEncoding().equals( (String)
currentSet.get(k))) {
return i;
}
}
}
}
return -1;
}
finally {
}
}
/****************************************************************
* Convenience methods to handle processor's state changes.
****************************************************************/
protected Integer stateLock = new Integer(0);
protected boolean failed = false;
Integer getStateLock()
{
return stateLock;
}
void setFailed()
{
failed = true;
}
protected synchronized boolean waitForState(Processor p, int state)
{
p.addControllerListener(new StateListener());
failed = false;
// Call the required method on the processor
if (state == Processor.Configured) {
p.configure();
}
else if (state == Processor.Realized) {
p.realize();
}
// Wait until we get an event that confirms the
// success of the method, or a failure event.
// See StateListener inner class
while (p.getState() < state && !failed) {
synchronized (getStateLock()) {
try {
getStateLock().wait();
}
catch (InterruptedException ie) {
return false;
}
}
}
if (failed) {
return false;
}
else {
return true;
}
}
/****************************************************************
* Inner Classes
****************************************************************/
class StateListener
implements ControllerListener
{
public void controllerUpdate(ControllerEvent ce)
{
try {
// If there was an error during configure or
// realize, the processor will be closed
if (ce instanceof ControllerClosedEvent) {
setFailed();
// All controller events, send a notification
// to the waiting thread in waitForState method.
}
if (ce instanceof ControllerEvent) {
synchronized (getStateLock()) {
getStateLock().notifyAll();
}
}
//Loop media files
if (ce instanceof EndOfMediaEvent) {
processor.setMediaTime(new Time(0));
processor.start();
}
}
finally {
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -