Search in sources :

Example 1 with MediaService

use of org.jitsi.service.neomedia.MediaService in project Spark by igniterealtime.

the class AudioFormatUtils method findCorrespondingJmfFormat.

protected static MediaFormat findCorrespondingJmfFormat(String sdpFormatStr) {
    int sdpFormat = Integer.parseInt(sdpFormatStr);
    MediaService mediaService = LibJitsi.getMediaService();
    switch(sdpFormat) {
        case SdpConstants.PCMU:
            System.out.println("SDPFormat PCMU: " + sdpFormat);
            return mediaService.getFormatFactory().createMediaFormat("PCMU", 8000);
        case SdpConstants.GSM:
            return mediaService.getFormatFactory().createMediaFormat(AudioFormat.GSM, 8000);
        case SdpConstants.G723:
            return mediaService.getFormatFactory().createMediaFormat(AudioFormat.G723, 8000);
        case SdpConstants.DVI4_8000:
            return mediaService.getFormatFactory().createMediaFormat(AudioFormat.DVI, 8000);
        case SdpConstants.DVI4_16000:
            return mediaService.getFormatFactory().createMediaFormat(AudioFormat.DVI, 16000);
        case SdpConstants.PCMA:
            System.out.println("SDPFormat PCMA: " + sdpFormat);
            return mediaService.getFormatFactory().createMediaFormat("PCMA", 8000);
        case SdpConstants.G728:
            return mediaService.getFormatFactory().createMediaFormat(AudioFormat.G728, 8000);
        case SdpConstants.G729:
            return mediaService.getFormatFactory().createMediaFormat(AudioFormat.G729, 8000);
        case // 110
        RTPBonusFormatsMgr.SPEEX_RTP_INDEX:
            System.out.println("SDPFormat SPEEX_RTP_INDEX: " + sdpFormat);
            return mediaService.getFormatFactory().createMediaFormat("SPEEX", 8000);
        case SdpConstants.H263:
            return mediaService.getFormatFactory().createMediaFormat("H263", MediaFormatFactory.CLOCK_RATE_NOT_SPECIFIED);
        case SdpConstants.JPEG:
            return mediaService.getFormatFactory().createMediaFormat("JPEG", MediaFormatFactory.CLOCK_RATE_NOT_SPECIFIED);
        case SdpConstants.H261:
            return mediaService.getFormatFactory().createMediaFormat("H261", MediaFormatFactory.CLOCK_RATE_NOT_SPECIFIED);
        default:
            byte sdpFormat2 = Byte.parseByte(sdpFormatStr);
            return mediaService.getFormatFactory().createMediaFormat(sdpFormat2);
    }
}
Also used : MediaService(org.jitsi.service.neomedia.MediaService)

Example 2 with MediaService

use of org.jitsi.service.neomedia.MediaService 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 3 with MediaService

use of org.jitsi.service.neomedia.MediaService in project Spark by igniterealtime.

the class AudioChannel 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 = null;
        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.SENDRECV);
        mediaStream.setFormat(format);
        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.AUDIO.toString());
        mediaStream.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : MediaStreamTarget(org.jitsi.service.neomedia.MediaStreamTarget) DatagramSocket(java.net.DatagramSocket) InetSocketAddress(java.net.InetSocketAddress) MediaService(org.jitsi.service.neomedia.MediaService) AudioMediaDeviceImpl(org.jitsi.impl.neomedia.device.AudioMediaDeviceImpl) MediaDevice(org.jitsi.service.neomedia.device.MediaDevice) DefaultStreamConnector(org.jitsi.service.neomedia.DefaultStreamConnector) UnknownHostException(java.net.UnknownHostException)

Example 4 with MediaService

use of org.jitsi.service.neomedia.MediaService 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)

Aggregations

MediaService (org.jitsi.service.neomedia.MediaService)4 UnknownHostException (java.net.UnknownHostException)2 CaptureDeviceInfo (javax.media.CaptureDeviceInfo)2 AudioFormat (javax.media.format.AudioFormat)2 MediaType (org.jitsi.service.neomedia.MediaType)2 MediaDevice (org.jitsi.service.neomedia.device.MediaDevice)2 DatagramSocket (java.net.DatagramSocket)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 AVFrameFormat (org.jitsi.impl.neomedia.codec.video.AVFrameFormat)1 AudioMediaDeviceImpl (org.jitsi.impl.neomedia.device.AudioMediaDeviceImpl)1 AudioSystem (org.jitsi.impl.neomedia.device.AudioSystem)1 CaptureDeviceInfo2 (org.jitsi.impl.neomedia.device.CaptureDeviceInfo2)1 DefaultStreamConnector (org.jitsi.service.neomedia.DefaultStreamConnector)1 MediaStreamTarget (org.jitsi.service.neomedia.MediaStreamTarget)1