use of org.jitsi.service.neomedia.format.MediaFormat in project Spark by igniterealtime.
the class JmfMediaManager method extractTransmittableJmfFormats.
/**
* Extract the supported formats for JMF from a Vector
*
* @param sdpFormats
* @return
* @throws MediaException
*/
protected ArrayList<MediaFormat> extractTransmittableJmfFormats(Vector<?> sdpFormats) throws MediaException {
ArrayList<MediaFormat> jmfFormats = new ArrayList<MediaFormat>();
for (int i = 0; i < sdpFormats.size(); i++) {
System.out.println("Add1 ++++++++++++++++++" + sdpFormats);
if (Integer.parseInt((String) sdpFormats.get(0)) == 31) {
System.out.println(sdpFormats.get(0));
MediaFormat videoformat = LibJitsi.getMediaService().getFormatFactory().createMediaFormat("H264", MediaFormatFactory.CLOCK_RATE_NOT_SPECIFIED);
jmfFormats.add(videoformat);
}
MediaFormat mediaFormat = AudioFormatUtils.findCorrespondingJmfFormat(sdpFormats.elementAt(i).toString());
if (mediaFormat != null) {
System.out.println("Add2 ++++++++++++++++++" + mediaFormat);
jmfFormats.add(mediaFormat);
}
}
if (jmfFormats.size() == 0) {
throw new MediaException("None of the supplied sdp formats for is supported by SIP COMMUNICATOR");
}
return jmfFormats;
}
use of org.jitsi.service.neomedia.format.MediaFormat in project Spark by igniterealtime.
the class AudioReceiverChannel method start.
/**
* Starts the transmission. Returns null if transmission started ok.
* Otherwise it returns a string with the reason why the setup failed.
* Starts receive also.
*/
public synchronized String start() {
try {
MediaService mediaService = LibJitsi.getMediaService();
MediaDevice device = mediaService.getDefaultDevice(MediaType.AUDIO, MediaUseCase.CALL);
List<MediaDevice> devices = mediaService.getDevices(MediaType.AUDIO, MediaUseCase.CALL);
for (MediaDevice foundDevice : devices) {
if (foundDevice instanceof AudioMediaDeviceImpl) {
AudioMediaDeviceImpl amdi = (AudioMediaDeviceImpl) foundDevice;
if (inLocator == amdi.getCaptureDeviceInfo().getLocator()) {
System.out.println("Test" + inLocator + "-" + amdi.getCaptureDeviceInfo().getLocator());
device = foundDevice;
}
}
System.out.println(foundDevice.getClass() + "-" + inLocator);
}
mediaStream = mediaService.createMediaStream(device);
mediaStream.setDirection(MediaDirection.RECVONLY);
System.out.println("TEST");
MediaFormat format = mediaService.getFormatFactory().createMediaFormat("PCMA", 8000);
mediaStream.setFormat(format);
StreamConnector connector = new DefaultStreamConnector(new DatagramSocket(this.localPort), new DatagramSocket(this.localPort + 1));
mediaStream.setConnector(connector);
mediaStream.setTarget(new MediaStreamTarget(new InetSocketAddress(this.remoteIpAddress, this.remotePort), new InetSocketAddress(this.remoteIpAddress, this.remotePort + 1)));
mediaStream.setName(MediaType.AUDIO.toString());
mediaStream.start();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.jitsi.service.neomedia.format.MediaFormat in project Spark by igniterealtime.
the class VideoChannel method start.
/**
* Starts the transmission. Returns null if transmission started ok.
* Otherwise it returns a string with the reason why the setup failed.
* Starts receive also.
*/
public synchronized String start() {
try {
MediaService mediaService = LibJitsi.getMediaService();
MediaDevice device = mediaService.getDefaultDevice(MediaType.VIDEO, MediaUseCase.ANY);
List<MediaDevice> devices = mediaService.getDevices(MediaType.VIDEO, MediaUseCase.ANY);
for (MediaDevice foundDevice : devices) {
if (foundDevice instanceof MediaDeviceImpl) {
MediaDeviceImpl amdi = (MediaDeviceImpl) foundDevice;
if (locator.equals(amdi.getCaptureDeviceInfo().getLocator())) {
System.out.println("Test" + locator + "-" + amdi.getCaptureDeviceInfo().getLocator());
device = foundDevice;
}
}
}
System.out.println("Device:" + device);
mediaStream = mediaService.createMediaStream(device);
mediaStream.setDirection(MediaDirection.SENDRECV);
MediaFormat usedformat = mediaService.getFormatFactory().createMediaFormat("H264", MediaFormatFactory.CLOCK_RATE_NOT_SPECIFIED);
byte dynamicRTPPayloadType = 99;
mediaStream.addDynamicRTPPayloadType(dynamicRTPPayloadType, usedformat);
mediaStream.setFormat(usedformat);
connector = new DefaultStreamConnector(new DatagramSocket(this.localPort), new DatagramSocket(this.localRTCPPort));
mediaStream.setConnector(connector);
mediaStream.setTarget(new MediaStreamTarget(new InetSocketAddress(this.ipAddress, this.remotePort), new InetSocketAddress(this.ipAddress, this.remoteRTCPPort)));
mediaStream.setName(MediaType.VIDEO.toString());
((VideoMediaStream) mediaStream).addVideoListener(new VideoListener() {
@Override
public void videoAdded(VideoEvent arg0) {
checkVideo();
}
@Override
public void videoRemoved(VideoEvent arg0) {
}
@Override
public void videoUpdate(VideoEvent arg0) {
}
});
mediaStream.start();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of org.jitsi.service.neomedia.format.MediaFormat in project Spark by igniterealtime.
the class JmfMediaManager method createAudioMediaSession.
/**
* Creates a new AudioMedia Session for a given sdpData
*
* @param sdpData
* @return
* @throws MediaException
*/
public AudioMediaSession createAudioMediaSession(String sdpData, int localPort) throws MediaException {
SessionDescription sessionDescription = null;
if (sdpData == null) {
throw new MediaException("The SDP data was null! Cannot open " + "a stream withour an SDP Description!");
}
try {
sessionDescription = sdpFactory.createSessionDescription(sdpData);
} catch (SdpParseException ex) {
throw new MediaException("Incorrect SDP data!", ex);
}
Vector<?> mediaDescriptions;
try {
mediaDescriptions = sessionDescription.getMediaDescriptions(true);
} catch (SdpException ex) {
throw new MediaException("Failed to extract media descriptions from provided session description!", ex);
}
Connection sessionConnection = sessionDescription.getConnection();
String sessionRemoteAddress = null;
if (sessionConnection != null) {
try {
sessionRemoteAddress = sessionConnection.getAddress();
} catch (SdpParseException ex) {
throw new MediaException("Failed to extract the connection address parameter" + "from privided session description", ex);
}
}
int mediaPort = -1;
boolean atLeastOneTransmitterStarted = false;
// ArrayList mediaTypes = new ArrayList();
ArrayList<String> remoteAddresses = new ArrayList<String>();
// A hashtable that indicates what addresses are different media
// types
// coming from.
Hashtable<String, String> remoteTransmisionDetails = new Hashtable<String, String>();
// this address for now.
if (sessionRemoteAddress != null) {
remoteTransmisionDetails.put("audio", sessionRemoteAddress);
remoteTransmisionDetails.put("video", sessionRemoteAddress);
}
ArrayList<Integer> ports = new ArrayList<Integer>();
ArrayList<ArrayList<MediaFormat>> formatSets = new ArrayList<ArrayList<MediaFormat>>();
ArrayList<String> contents = new ArrayList<String>();
ArrayList<Integer> localPorts = new ArrayList<Integer>();
for (int i = 0; i < mediaDescriptions.size(); i++) {
MediaDescription mediaDescription = (MediaDescription) mediaDescriptions.get(i);
Media media = mediaDescription.getMedia();
// Media Type
String mediaType = null;
try {
mediaType = media.getMediaType();
} catch (SdpParseException ex) {
continue;
}
// Find ports
try {
mediaPort = media.getMediaPort();
System.out.println("MediaType:" + mediaType + ":" + mediaPort);
} catch (SdpParseException ex) {
throw (new MediaException("Failed to extract port for media type [" + mediaType + "]. Ignoring description!", ex));
}
// Find formats
Vector<?> sdpFormats = null;
try {
sdpFormats = media.getMediaFormats(true);
} catch (SdpParseException ex) {
throw (new MediaException("Failed to extract media formats for media type [" + mediaType + "]. Ignoring description!", ex));
}
Connection mediaConnection = mediaDescription.getConnection();
String mediaRemoteAddress = null;
if (mediaConnection == null) {
if (sessionConnection == null) {
throw new MediaException("A connection parameter was not present in provided session/media description");
} else {
mediaRemoteAddress = sessionRemoteAddress;
}
} else {
try {
mediaRemoteAddress = mediaConnection.getAddress();
} catch (SdpParseException ex) {
throw new MediaException("Failed to extract the connection address parameter" + "from privided media description", ex);
}
}
// update the remote address for the current media type in case
// it is specific for this media (i.e. differs from the main
// connection address)
remoteTransmisionDetails.put(mediaType, mediaRemoteAddress);
// START TRANSMISSION
try {
remoteAddresses.add(mediaRemoteAddress);
ports.add(new Integer(mediaPort));
contents.add(mediaType);
if (mediaType.trim().equals("video"))
localPorts.add(Integer.valueOf(22445));
else if (mediaType.trim().equals("audio"))
localPorts.add(Integer.valueOf(localPort));
else
localPorts.add(Integer.valueOf(mediaPort));
// formatSets
// .add();
formatSets.add(extractTransmittableJmfFormats(sdpFormats));
} catch (MediaException ex) {
Log.error("StartMedia", ex);
throw (new MediaException("Could not start a transmitter for media type [" + mediaType + "]\nIgnoring media [" + mediaType + "]!", ex));
}
atLeastOneTransmitterStarted = true;
}
if (atLeastOneTransmitterStarted) {
System.out.println("Remote Port: " + ports.get(0));
TransportCandidate.Fixed remote = new TransportCandidate.Fixed(remoteAddresses.get(0).toString(), (Integer) ports.get(0));
TransportCandidate.Fixed local = new TransportCandidate.Fixed(NetworkAddressManager.getLocalHost().getHostAddress(), localPort);
MediaFormat mediaFormat = (formatSets.get(0)).get(0);
// System.out.println("MediaFormat: " + format);
// System.out.println("MediaFormat: " + format.getRTPPayloadType());
// System.out.println("MediaFormat: " + format.getMediaType());
//
// MediaFormat mediaFormat = LibJitsi.getMediaService().getFormatFactory().createMediaFormat("speex", 8000);
// System.out.println("MediaFormat: " + mediaFormat);
// System.out.println("MediaFormat: " + mediaFormat.getRTPPayloadType());
// System.out.println("MediaFormat: " + mediaFormat.getMediaType());
AudioMediaSession audioMediaSession = new AudioMediaSession(mediaFormat, remote, local, SettingsManager.getLocalPreferences().getAudioDevice());
return audioMediaSession;
}
return null;
}
use of org.jitsi.service.neomedia.format.MediaFormat in project Spark by igniterealtime.
the class JmfMediaManager method createVideoMediaSession.
/**
* Creates a new VideoMedia Session for a given sdpData
*
* @param sdpData
* @return
* @throws MediaException
*/
public VideoMediaSession createVideoMediaSession(String sdpData, int localPort) throws MediaException {
SessionDescription sessionDescription = null;
if (sdpData == null) {
throw new MediaException("The SDP data was null! Cannot open " + "a stream withour an SDP Description!");
}
try {
sessionDescription = sdpFactory.createSessionDescription(sdpData);
} catch (SdpParseException ex) {
throw new MediaException("Incorrect SDP data!", ex);
}
Vector<?> mediaDescriptions;
try {
mediaDescriptions = sessionDescription.getMediaDescriptions(true);
} catch (SdpException ex) {
throw new MediaException("Failed to extract media descriptions from provided session description!", ex);
}
Connection sessionConnection = sessionDescription.getConnection();
String sessionRemoteAddress = null;
if (sessionConnection != null) {
try {
sessionRemoteAddress = sessionConnection.getAddress();
} catch (SdpParseException ex) {
throw new MediaException("Failed to extract the connection address parameter" + "from privided session description", ex);
}
}
int mediaPort = -1;
boolean atLeastOneTransmitterStarted = false;
// ArrayList mediaTypes = new ArrayList();
ArrayList<String> remoteAddresses = new ArrayList<String>();
// A hashtable that indicates what addresses are different media
// types
// coming from.
Hashtable<String, String> remoteTransmisionDetails = new Hashtable<String, String>();
// this address for now.
if (sessionRemoteAddress != null) {
remoteTransmisionDetails.put("audio", sessionRemoteAddress);
remoteTransmisionDetails.put("video", sessionRemoteAddress);
}
ArrayList<Integer> ports = new ArrayList<Integer>();
ArrayList<ArrayList<MediaFormat>> formatSets = new ArrayList<ArrayList<MediaFormat>>();
ArrayList<String> contents = new ArrayList<String>();
ArrayList<Integer> localPorts = new ArrayList<Integer>();
for (int i = 0; i < mediaDescriptions.size(); i++) {
MediaDescription mediaDescription = (MediaDescription) mediaDescriptions.get(i);
Media media = mediaDescription.getMedia();
// Media Type
String mediaType = null;
try {
mediaType = media.getMediaType();
} catch (SdpParseException ex) {
continue;
}
// Find ports
try {
mediaPort = media.getMediaPort();
System.out.println("MediaType:" + mediaType + ":" + mediaPort);
} catch (SdpParseException ex) {
throw (new MediaException("Failed to extract port for media type [" + mediaType + "]. Ignoring description!", ex));
}
// Find formats
Vector<?> sdpFormats = null;
try {
sdpFormats = media.getMediaFormats(true);
} catch (SdpParseException ex) {
throw (new MediaException("Failed to extract media formats for media type [" + mediaType + "]. Ignoring description!", ex));
}
Connection mediaConnection = mediaDescription.getConnection();
String mediaRemoteAddress = null;
if (mediaConnection == null) {
if (sessionConnection == null) {
throw new MediaException("A connection parameter was not present in provided session/media description");
} else {
mediaRemoteAddress = sessionRemoteAddress;
}
} else {
try {
mediaRemoteAddress = mediaConnection.getAddress();
} catch (SdpParseException ex) {
throw new MediaException("Failed to extract the connection address parameter" + "from privided media description", ex);
}
}
// update the remote address for the current media type in case
// it is specific for this media (i.e. differs from the main
// connection address)
remoteTransmisionDetails.put(mediaType, mediaRemoteAddress);
// START TRANSMISSION
try {
remoteAddresses.add(mediaRemoteAddress);
ports.add(new Integer(mediaPort));
contents.add(mediaType);
if (mediaType.trim().equals("video"))
localPorts.add(Integer.valueOf(22444));
else if (mediaType.trim().equals("audio"))
localPorts.add(Integer.valueOf(localPort));
else
localPorts.add(Integer.valueOf(mediaPort));
formatSets.add(extractTransmittableJmfFormats(sdpFormats));
} catch (MediaException ex) {
Log.error("StartMedia", ex);
throw (new MediaException("Could not start a transmitter for media type [" + mediaType + "]\nIgnoring media [" + mediaType + "]!", ex));
}
atLeastOneTransmitterStarted = true;
}
if (atLeastOneTransmitterStarted) {
TransportCandidate.Fixed remote = new TransportCandidate.Fixed(remoteAddresses.get(0).toString(), (Integer) ports.get(0));
TransportCandidate.Fixed local = new TransportCandidate.Fixed(NetworkAddressManager.getLocalHost().getHostAddress(), localPort);
// TODO : FORCED TO JPEG_RTP -> deteced format
// VideoFormat videoFormat = new VideoFormat((String) (((ArrayList) formatSets.get(0)).get(0)));
VideoFormat videoFormat = new VideoFormat(VideoFormat.JPEG_RTP);
VideoMediaSession videoMediaSession = new VideoMediaSession(videoFormat, remote, local, SettingsManager.getLocalPreferences().getVideoDevice());
;
return videoMediaSession;
}
return null;
}
Aggregations