Search in sources :

Example 1 with MediaDeviceImpl

use of org.jitsi.impl.neomedia.device.MediaDeviceImpl 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;
}
Also used : MediaFormat(org.jitsi.service.neomedia.format.MediaFormat) InetSocketAddress(java.net.InetSocketAddress) VideoEvent(org.jitsi.util.event.VideoEvent) UnknownHostException(java.net.UnknownHostException) MediaDeviceImpl(org.jitsi.impl.neomedia.device.MediaDeviceImpl) DatagramSocket(java.net.DatagramSocket) MediaDevice(org.jitsi.service.neomedia.device.MediaDevice) VideoListener(org.jitsi.util.event.VideoListener)

Aggregations

DatagramSocket (java.net.DatagramSocket)1 InetSocketAddress (java.net.InetSocketAddress)1 UnknownHostException (java.net.UnknownHostException)1 MediaDeviceImpl (org.jitsi.impl.neomedia.device.MediaDeviceImpl)1 MediaDevice (org.jitsi.service.neomedia.device.MediaDevice)1 MediaFormat (org.jitsi.service.neomedia.format.MediaFormat)1 VideoEvent (org.jitsi.util.event.VideoEvent)1 VideoListener (org.jitsi.util.event.VideoListener)1