Search in sources :

Example 11 with AudioFormat

use of javax.media.format.AudioFormat in project Spark by igniterealtime.

the class MediaPreferencePanel method scanDevices.

@SuppressWarnings("unchecked")
public void scanDevices() {
    // Remove all Items
    audioDevice.removeAllItems();
    videoDevice.removeAllItems();
    playbackDevice.removeAllItems();
    audioSystem.removeAllItems();
    vectorPlaybackDevices.removeAllElements();
    vectorAudioSystem.removeAllElements();
    // FMJ
    System.setProperty(ConfigurationService.PNAME_SC_HOME_DIR_LOCATION, Spark.getUserHome());
    System.setProperty(ConfigurationService.PNAME_SC_HOME_DIR_NAME, ".");
    System.setProperty(ConfigurationService.PNAME_SC_CACHE_DIR_LOCATION, Spark.getUserHome());
    System.setProperty(ConfigurationService.PNAME_SC_LOG_DIR_LOCATION, Spark.getUserHome());
    LibJitsi.start();
    MediaType[] mediaTypes = MediaType.values();
    MediaService mediaService = LibJitsi.getMediaService();
    for (MediaType mediaType : mediaTypes) {
        System.err.println("================================");
        System.err.println("MediaType: " + mediaType);
        System.out.println(mediaService);
        MediaDevice device = mediaService.getDefaultDevice(mediaType, MediaUseCase.CALL);
        if (device != null) {
            System.out.println(device.getDirection());
        }
        System.err.println("Device: " + device);
        System.err.println("================================");
    }
    vectorAudioDevices = CaptureDeviceManager.getDeviceList(new AudioFormat(AudioFormat.LINEAR));
    for (CaptureDeviceInfo infoCaptureDevice : vectorAudioDevices) {
        String protocol = infoCaptureDevice.getLocator().getProtocol();
        audioDevice.addItem("[" + protocol + "]" + convertSysString(infoCaptureDevice.getName()));
    }
    vectorVideoDevices = CaptureDeviceManager.getDeviceList(new AVFrameFormat());
    for (CaptureDeviceInfo infoCaptureDevice : vectorVideoDevices) {
        videoDevice.addItem(convertSysString(infoCaptureDevice.getName()));
    }
    vectorVideoDevices.add(null);
    videoDevice.addItem("<None>");
    AudioSystem mediaAudioSystem = ((MediaServiceImpl) LibJitsi.getMediaService()).getDeviceConfiguration().getAudioSystem();
    for (AudioSystem system : AudioSystem.getAudioSystems()) {
        System.out.println(system);
        vectorAudioSystem.add(system);
        audioSystem.addItem(system);
    }
    for (CaptureDeviceInfo2 device : mediaAudioSystem.getDevices(DataFlow.PLAYBACK)) {
        playbackDevice.addItem(convertSysString(device.getName()));
        vectorPlaybackDevices.add(device);
    }
}
Also used : CaptureDeviceInfo(javax.media.CaptureDeviceInfo) CaptureDeviceInfo2(org.jitsi.impl.neomedia.device.CaptureDeviceInfo2) MediaService(org.jitsi.service.neomedia.MediaService) AVFrameFormat(org.jitsi.impl.neomedia.codec.video.AVFrameFormat) AudioSystem(org.jitsi.impl.neomedia.device.AudioSystem) MediaType(org.jitsi.service.neomedia.MediaType) MediaDevice(org.jitsi.service.neomedia.device.MediaDevice) AudioFormat(javax.media.format.AudioFormat)

Example 12 with AudioFormat

use of javax.media.format.AudioFormat in project Spark by igniterealtime.

the class JmfMediaManager method generateHoldSdpDescription.

/**
 * Generates the Hold Description for a Call.
 *
 * @param setAudio set hold on Audio.
 * @param setVideo set hold on Video.
 * @param call     the call that you want to hold.
 * @return SessionDescription of a call.
 * @throws MediaException
 */
public SessionDescription generateHoldSdpDescription(boolean setAudio, boolean setVideo, Call call) throws MediaException {
    try {
        SessionDescription sessDescr = sdpFactory.createSessionDescription();
        Version v = sdpFactory.createVersion(0);
        InetSocketAddress publicAudioAddress = NetworkAddressManager.getPublicAddressFor(((MediaDescription) (call.getLocalSdpDescription().getMediaDescriptions(true).get(0))).getMedia().getMediaPort());
        InetAddress publicIpAddress = publicAudioAddress.getAddress();
        String addrType = publicIpAddress instanceof Inet6Address ? "IP6" : "IP4";
        Origin o = sdpFactory.createOrigin(SIPConfig.getUserName().replace(' ', '_'), 20109217, 2, "IN", addrType, publicIpAddress.getHostAddress());
        SessionName s = sdpFactory.createSessionName("<SparkPhone>");
        Connection c = sdpFactory.createConnection("IN", addrType, publicIpAddress.getHostAddress());
        TimeDescription t = sdpFactory.createTimeDescription();
        Vector<TimeDescription> timeDescs = new Vector<TimeDescription>();
        timeDescs.add(t);
        String[] formats = new String[getAudioFormats().size()];
        int i = 0;
        for (AudioFormat audioFormat : getAudioFormats()) {
            formats[i++] = AudioFormatUtils.findCorrespondingSdpFormat(audioFormat.getEncoding());
        }
        MediaDescription am = sdpFactory.createMediaDescription("audio", publicAudioAddress.getPort(), 1, "RTP/AVP", formats);
        am.setAttribute(setAudio ? "sendonly" : "sendrecv", null);
        am.setAttribute("rtmap:101", "telephone-event/" + publicAudioAddress.getPort());
        Vector<MediaDescription> mediaDescs = new Vector<MediaDescription>();
        mediaDescs.add(am);
        sessDescr.setVersion(v);
        sessDescr.setOrigin(o);
        sessDescr.setConnection(c);
        sessDescr.setSessionName(s);
        sessDescr.setTimeDescriptions(timeDescs);
        if (mediaDescs.size() > 0)
            sessDescr.setMediaDescriptions(mediaDescs);
        return sessDescr;
    } catch (SdpException exc) {
        throw new MediaException("An SDP exception occurred while generating local sdp description", exc);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Inet6Address(java.net.Inet6Address) AudioFormat(javax.media.format.AudioFormat) InetAddress(java.net.InetAddress) Vector(java.util.Vector)

Example 13 with AudioFormat

use of javax.media.format.AudioFormat in project Spark by igniterealtime.

the class JmfMediaManager method generateSdpDescription.

public SessionDescription generateSdpDescription() throws MediaException {
    try {
        SessionDescription sessDescr = sdpFactory.createSessionDescription();
        int audioPort, videoPort;
        audioPort = (int) (5000 * Math.random()) + 5000;
        if (audioPort % 2 != 0)
            audioPort++;
        do {
            videoPort = (int) (5000 * Math.random()) + 5000;
            if (videoPort % 2 != 0)
                videoPort++;
        } while (audioPort == videoPort);
        // videoPort = "22497";
        // audioPort = "16251";
        Version v = sdpFactory.createVersion(0);
        InetSocketAddress publicVideoAddress = NetworkAddressManager.getPublicAddressFor(videoPort);
        InetSocketAddress publicAudioAddress = NetworkAddressManager.getPublicAddressFor(audioPort);
        InetAddress publicIpAddress = publicAudioAddress.getAddress();
        String addrType = publicIpAddress instanceof Inet6Address ? "IP6" : "IP4";
        // spaces in the user name mess everything up.
        // bug report - Alessandro Melzi
        Origin o = sdpFactory.createOrigin(SIPConfig.getUserName().replace(' ', '_'), 20109217, 2, "IN", addrType, publicIpAddress.getHostAddress());
        // "s=-"
        SessionName s = sdpFactory.createSessionName("<SIPmack>");
        // c=
        Connection c = sdpFactory.createConnection("IN", addrType, publicIpAddress.getHostAddress());
        // "t=0 0"
        TimeDescription t = sdpFactory.createTimeDescription();
        Vector<TimeDescription> timeDescs = new Vector<TimeDescription>();
        timeDescs.add(t);
        // --------Audio media description
        // make sure preferred formats come first
        String[] aformats = new String[getSelectedFormats().size()];
        int i = 0;
        for (AudioFormat audioFormat : getSelectedFormats()) {
            aformats[i++] = AudioFormatUtils.findCorrespondingSdpFormat(audioFormat.getEncoding());
        }
        MediaDescription am = sdpFactory.createMediaDescription("audio", publicAudioAddress.getPort(), 1, "RTP/AVP", aformats);
        am.setAttribute("sendrecv", null);
        am.setAttribute("rtmap:101", "telephone-event/" + publicAudioAddress.getPort());
        i = 0;
        String[] vformats = new String[getVideoFormats().size()];
        for (VideoFormat videoFormat : getVideoFormats()) {
            vformats[i++] = AudioFormatUtils.findCorrespondingSdpFormat(videoFormat.getEncoding());
        }
        MediaDescription vam = sdpFactory.createMediaDescription("video", publicVideoAddress.getPort(), 1, "RTP/AVP", vformats);
        Vector<MediaDescription> mediaDescs = new Vector<MediaDescription>();
        mediaDescs.add(am);
        mediaDescs.add(vam);
        sessDescr.setVersion(v);
        sessDescr.setOrigin(o);
        sessDescr.setConnection(c);
        sessDescr.setSessionName(s);
        sessDescr.setTimeDescriptions(timeDescs);
        if (mediaDescs.size() > 0)
            sessDescr.setMediaDescriptions(mediaDescs);
        return sessDescr;
    } catch (SdpException exc) {
        throw new MediaException("An SDP exception occurred while generating local sdp description", exc);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Inet6Address(java.net.Inet6Address) VideoFormat(javax.media.format.VideoFormat) AudioFormat(javax.media.format.AudioFormat) InetAddress(java.net.InetAddress) Vector(java.util.Vector)

Example 14 with AudioFormat

use of javax.media.format.AudioFormat in project Spark by igniterealtime.

the class AudioChannel method main.

public static void main(String[] args) {
    InetAddress localhost;
    try {
        LibJitsi.start();
        MediaType[] mediaTypes = MediaType.values();
        MediaService mediaService = LibJitsi.getMediaService();
        Vector<CaptureDeviceInfo> vectorAudioDevices = CaptureDeviceManager.getDeviceList(new AudioFormat(AudioFormat.LINEAR));
        for (CaptureDeviceInfo infoCaptureDevice : vectorAudioDevices) {
            System.out.println(infoCaptureDevice.getLocator());
        }
        localhost = InetAddress.getLocalHost();
        byte format = 3;
        AudioChannel audioChannel0 = new AudioChannel(vectorAudioDevices.get(0).getLocator(), localhost.getHostAddress(), localhost.getHostAddress(), 7002, -1, 7020, -1, MediaUtils.getMediaFormat(new AudioFormat(AudioFormat.GSM_RTP)));
        AudioChannel audioChannel1 = new AudioChannel(vectorAudioDevices.get(0).getLocator(), localhost.getHostAddress(), localhost.getHostAddress(), 7020, -1, 7002, -1, MediaUtils.getMediaFormat(new AudioFormat(AudioFormat.GSM_RTP)));
        audioChannel0.start();
        audioChannel1.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        audioChannel0.setTrasmit(false);
        audioChannel1.setTrasmit(false);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        audioChannel0.setTrasmit(true);
        audioChannel1.setTrasmit(true);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        audioChannel0.stop();
        audioChannel1.stop();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) CaptureDeviceInfo(javax.media.CaptureDeviceInfo) MediaService(org.jitsi.service.neomedia.MediaService) MediaType(org.jitsi.service.neomedia.MediaType) AudioFormat(javax.media.format.AudioFormat) InetAddress(java.net.InetAddress)

Example 15 with AudioFormat

use of javax.media.format.AudioFormat in project Spark by igniterealtime.

the class PhoneManager method getMediaLocator.

public static MediaLocator getMediaLocator(String locator) {
    MediaLocator auxLocator;
    System.out.println("--------------------------------");
    System.out.println("locator: " + locator);
    Vector<CaptureDeviceInfo> vectorAudioDevices = CaptureDeviceManager.getDeviceList(new AudioFormat(AudioFormat.LINEAR));
    for (CaptureDeviceInfo infoCaptureDevice : vectorAudioDevices) {
        System.out.println(infoCaptureDevice.getLocator() + "-" + locator);
        if (infoCaptureDevice.getLocator().toString().equals(locator)) {
            System.out.println("Found: " + locator);
            return infoCaptureDevice.getLocator();
        }
    }
    Vector<CaptureDeviceInfo> vectorVideoDevices = CaptureDeviceManager.getDeviceList(new VideoFormat(VideoFormat.RGB));
    for (CaptureDeviceInfo infoCaptureDevice : vectorVideoDevices) {
        System.out.println(infoCaptureDevice.getLocator() + "-" + locator);
        if (infoCaptureDevice.getLocator().toString().equals(locator)) {
            System.out.println("Found: " + locator);
            return infoCaptureDevice.getLocator();
        }
    }
    if (useStaticLocator) {
        if (mediaLocator == null) {
            mediaLocator = new MediaLocator(locator);
        }
        auxLocator = mediaLocator;
    // usingMediaLocator=true;
    } else {
        auxLocator = new MediaLocator(locator);
    }
    return auxLocator;
}
Also used : MediaLocator(javax.media.MediaLocator) CaptureDeviceInfo(javax.media.CaptureDeviceInfo) AudioFormat(javax.media.format.AudioFormat) VideoFormat(javax.media.format.VideoFormat)

Aggregations

AudioFormat (javax.media.format.AudioFormat)15 MediaLocator (javax.media.MediaLocator)5 InetAddress (java.net.InetAddress)4 UnknownHostException (java.net.UnknownHostException)3 CaptureDeviceInfo (javax.media.CaptureDeviceInfo)3 Format (javax.media.Format)3 Inet6Address (java.net.Inet6Address)2 InetSocketAddress (java.net.InetSocketAddress)2 Vector (java.util.Vector)2 Renderer (javax.media.Renderer)2 VideoFormat (javax.media.format.VideoFormat)2 MediaService (org.jitsi.service.neomedia.MediaService)2 MediaType (org.jitsi.service.neomedia.MediaType)2 XMPPException (org.jivesoftware.smack.XMPPException)2 AudioChannel (org.jivesoftware.smackx.jingle.mediaimpl.jmf.AudioChannel)2 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Codec (javax.media.Codec)1 NoProcessorException (javax.media.NoProcessorException)1