2014-02-17 23:58:40 +01:00
|
|
|
/**
|
2014-02-19 10:38:30 +01:00
|
|
|
*
|
2014-02-17 23:58:40 +01:00
|
|
|
* Copyright 2003-2006 Jive Software.
|
2014-02-19 10:38:30 +01:00
|
|
|
*
|
2014-02-17 23:58:40 +01:00
|
|
|
* 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
|
2014-02-19 10:38:30 +01:00
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
2014-02-17 23:58:40 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
2014-08-20 00:25:57 +02:00
|
|
|
package org.jivesoftware.smackx.jingleold.mediaimpl.jmf;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2014-02-19 10:38:30 +01:00
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
import javax.media.ControllerErrorEvent;
|
|
|
|
import javax.media.ControllerEvent;
|
|
|
|
import javax.media.ControllerListener;
|
|
|
|
import javax.media.Player;
|
|
|
|
import javax.media.RealizeCompleteEvent;
|
|
|
|
import javax.media.protocol.DataSource;
|
|
|
|
import javax.media.rtp.Participant;
|
|
|
|
import javax.media.rtp.RTPControl;
|
|
|
|
import javax.media.rtp.ReceiveStream;
|
|
|
|
import javax.media.rtp.ReceiveStreamListener;
|
|
|
|
import javax.media.rtp.SessionListener;
|
|
|
|
import javax.media.rtp.event.ByeEvent;
|
|
|
|
import javax.media.rtp.event.NewParticipantEvent;
|
|
|
|
import javax.media.rtp.event.NewReceiveStreamEvent;
|
|
|
|
import javax.media.rtp.event.ReceiveStreamEvent;
|
|
|
|
import javax.media.rtp.event.RemotePayloadChangeEvent;
|
|
|
|
import javax.media.rtp.event.SessionEvent;
|
|
|
|
import javax.media.rtp.event.StreamMappedEvent;
|
|
|
|
|
2014-08-20 00:25:57 +02:00
|
|
|
import org.jivesoftware.smackx.jingleold.media.JingleMediaSession;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* This class implements receive methods and listeners to be used in AudioChannel.
|
2014-02-17 23:58:40 +01:00
|
|
|
*
|
|
|
|
* @author Thiago Camargo
|
|
|
|
*/
|
|
|
|
public class AudioReceiver implements ReceiveStreamListener, SessionListener,
|
|
|
|
ControllerListener {
|
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
private static final Logger LOGGER = Logger.getLogger(AudioReceiver.class.getName());
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2017-02-07 22:02:40 +01:00
|
|
|
boolean dataReceived = false;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2015-09-13 18:12:33 +02:00
|
|
|
final Object dataSync;
|
2014-02-17 23:58:40 +01:00
|
|
|
JingleMediaSession jingleMediaSession;
|
|
|
|
|
|
|
|
public AudioReceiver(final Object dataSync, final JingleMediaSession jingleMediaSession) {
|
|
|
|
this.dataSync = dataSync;
|
|
|
|
this.jingleMediaSession = jingleMediaSession;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* JingleSessionListener.
|
|
|
|
*/
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2014-02-17 23:58:40 +01:00
|
|
|
public synchronized void update(SessionEvent evt) {
|
|
|
|
if (evt instanceof NewParticipantEvent) {
|
|
|
|
Participant p = ((NewParticipantEvent) evt).getParticipant();
|
2014-02-19 10:38:30 +01:00
|
|
|
LOGGER.fine(" - A new participant had just joined: " + p.getCNAME());
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* ReceiveStreamListener.
|
2014-02-17 23:58:40 +01:00
|
|
|
*/
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2014-02-17 23:58:40 +01:00
|
|
|
public synchronized void update(ReceiveStreamEvent evt) {
|
|
|
|
|
|
|
|
Participant participant = evt.getParticipant(); // could be null.
|
|
|
|
ReceiveStream stream = evt.getReceiveStream(); // could be null.
|
|
|
|
|
|
|
|
if (evt instanceof RemotePayloadChangeEvent) {
|
2014-02-19 10:38:30 +01:00
|
|
|
LOGGER.severe(" - Received an RTP PayloadChangeEvent.");
|
|
|
|
LOGGER.severe("Sorry, cannot handle payload change.");
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
else if (evt instanceof NewReceiveStreamEvent) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
stream = evt.getReceiveStream();
|
|
|
|
DataSource ds = stream.getDataSource();
|
|
|
|
|
|
|
|
// Find out the formats.
|
|
|
|
RTPControl ctl = (RTPControl) ds.getControl("javax.jmf.rtp.RTPControl");
|
|
|
|
if (ctl != null) {
|
2017-12-13 23:10:11 +01:00
|
|
|
LOGGER.severe(" - Received new RTP stream: " + ctl.getFormat());
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
else
|
2017-12-13 23:10:11 +01:00
|
|
|
LOGGER.severe(" - Received new RTP stream");
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
if (participant == null)
|
2014-02-19 10:38:30 +01:00
|
|
|
LOGGER.severe(" The sender of this stream had yet to be identified.");
|
2014-02-17 23:58:40 +01:00
|
|
|
else {
|
2014-02-19 10:38:30 +01:00
|
|
|
LOGGER.severe(" The stream comes from: " + participant.getCNAME());
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// create a player by passing datasource to the Media Manager
|
|
|
|
Player p = javax.media.Manager.createPlayer(ds);
|
|
|
|
if (p == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
p.addControllerListener(this);
|
|
|
|
p.realize();
|
|
|
|
jingleMediaSession.mediaReceived(participant != null ? participant.getCNAME() : "");
|
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
// Notify initialize() that a new stream had arrived.
|
2014-02-17 23:58:40 +01:00
|
|
|
synchronized (dataSync) {
|
|
|
|
dataReceived = true;
|
|
|
|
dataSync.notifyAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (Exception e) {
|
2014-02-19 10:38:30 +01:00
|
|
|
LOGGER.severe("NewReceiveStreamEvent exception " + e.getMessage());
|
2014-02-17 23:58:40 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (evt instanceof StreamMappedEvent) {
|
|
|
|
|
|
|
|
if (stream != null && stream.getDataSource() != null) {
|
|
|
|
DataSource ds = stream.getDataSource();
|
|
|
|
// Find out the formats.
|
|
|
|
RTPControl ctl = (RTPControl) ds.getControl("javax.jmf.rtp.RTPControl");
|
2014-02-19 10:38:30 +01:00
|
|
|
LOGGER.severe(" - The previously unidentified stream ");
|
2014-02-17 23:58:40 +01:00
|
|
|
if (ctl != null)
|
2014-02-19 10:38:30 +01:00
|
|
|
LOGGER.severe(" " + ctl.getFormat());
|
|
|
|
LOGGER.severe(" had now been identified as sent by: " + participant.getCNAME());
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (evt instanceof ByeEvent) {
|
|
|
|
|
2014-02-19 10:38:30 +01:00
|
|
|
LOGGER.severe(" - Got \"bye\" from: " + participant.getCNAME());
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ControllerListener for the Players.
|
|
|
|
*/
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2014-02-17 23:58:40 +01:00
|
|
|
public synchronized void controllerUpdate(ControllerEvent ce) {
|
|
|
|
|
|
|
|
Player p = (Player) ce.getSourceController();
|
|
|
|
|
|
|
|
if (p == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Get this when the internal players are realized.
|
|
|
|
if (ce instanceof RealizeCompleteEvent) {
|
|
|
|
p.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ce instanceof ControllerErrorEvent) {
|
|
|
|
p.removeControllerListener(this);
|
2014-02-19 10:38:30 +01:00
|
|
|
LOGGER.severe("Receiver internal error: " + ce);
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|