Search in sources :

Example 1 with MediaLocator

use of javax.media.MediaLocator in project Smack by igniterealtime.

the class AudioChannel method createProcessor.

private String createProcessor() {
    if (locator == null)
        return "Locator is null";
    DataSource ds;
    try {
        ds = javax.media.Manager.createDataSource(locator);
    } catch (Exception e) {
        // Try JavaSound Locator as a last resort
        try {
            ds = javax.media.Manager.createDataSource(new MediaLocator("javasound://"));
        } catch (Exception ee) {
            return "Couldn't create DataSource";
        }
    }
    // Try to create a processor to handle the input jmf locator
    try {
        processor = javax.media.Manager.createProcessor(ds);
    } catch (NoProcessorException npe) {
        LOGGER.log(Level.WARNING, "exception", npe);
        return "Couldn't create processor";
    } catch (IOException ioe) {
        LOGGER.log(Level.WARNING, "exception", ioe);
        return "IOException creating processor";
    }
    // Wait for it to configure
    boolean result = waitForState(processor, Processor.Configured);
    if (!result) {
        return "Couldn't configure processor";
    }
    // Get the tracks from the processor
    TrackControl[] tracks = processor.getTrackControls();
    // Do we have at least one track?
    if (tracks == null || tracks.length < 1) {
        return "Couldn't find tracks in processor";
    }
    // Set the output content descriptor to RAW_RTP
    // This will limit the supported formats reported from
    // Track.getSupportedFormats to only valid RTP formats.
    ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
    processor.setContentDescriptor(cd);
    Format[] supported;
    Format chosen = null;
    boolean atLeastOneTrack = false;
    // Program the tracks.
    for (int i = 0; i < tracks.length; i++) {
        if (tracks[i].isEnabled()) {
            supported = tracks[i].getSupportedFormats();
            if (supported.length > 0) {
                for (Format format : supported) {
                    if (format instanceof AudioFormat) {
                        if (this.format.matches(format))
                            chosen = format;
                    }
                }
                if (chosen != null) {
                    tracks[i].setFormat(chosen);
                    LOGGER.severe("Track " + i + " is set to transmit as: " + chosen);
                    if (tracks[i].getFormat() instanceof AudioFormat) {
                        int packetRate = 20;
                        PacketSizeControl pktCtrl = (PacketSizeControl) processor.getControl(PacketSizeControl.class.getName());
                        if (pktCtrl != null) {
                            try {
                                pktCtrl.setPacketSize(getPacketSize(tracks[i].getFormat(), packetRate));
                            } catch (IllegalArgumentException e) {
                                pktCtrl.setPacketSize(80);
                            // Do nothing
                            }
                        }
                        if (tracks[i].getFormat().getEncoding().equals(AudioFormat.ULAW_RTP)) {
                            Codec[] codec = new Codec[3];
                            codec[0] = new com.ibm.media.codec.audio.rc.RCModule();
                            codec[1] = new com.ibm.media.codec.audio.ulaw.JavaEncoder();
                            codec[2] = new com.sun.media.codec.audio.ulaw.Packetizer();
                            ((com.sun.media.codec.audio.ulaw.Packetizer) codec[2]).setPacketSize(160);
                            try {
                                tracks[i].setCodecChain(codec);
                            } catch (UnsupportedPlugInException e) {
                                LOGGER.log(Level.WARNING, "exception", e);
                            }
                        }
                    }
                    atLeastOneTrack = true;
                } else
                    tracks[i].setEnabled(false);
            } else
                tracks[i].setEnabled(false);
        }
    }
    if (!atLeastOneTrack)
        return "Couldn't set any of the tracks to a valid RTP format";
    result = waitForState(processor, Controller.Realized);
    if (!result)
        return "Couldn't realize processor";
    // Get the output data source of the processor
    dataOutput = processor.getDataOutput();
    return null;
}
Also used : TrackControl(javax.media.control.TrackControl) NoProcessorException(javax.media.NoProcessorException) Codec(javax.media.Codec) MediaLocator(javax.media.MediaLocator) Format(javax.media.Format) AudioFormat(javax.media.format.AudioFormat) PacketSizeControl(javax.media.control.PacketSizeControl) AudioFormat(javax.media.format.AudioFormat) IOException(java.io.IOException) NoProcessorException(javax.media.NoProcessorException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) InvalidSessionAddressException(javax.media.rtp.InvalidSessionAddressException) UnsupportedPlugInException(javax.media.UnsupportedPlugInException) PushBufferDataSource(javax.media.protocol.PushBufferDataSource) DataSource(javax.media.protocol.DataSource) ContentDescriptor(javax.media.protocol.ContentDescriptor) UnsupportedPlugInException(javax.media.UnsupportedPlugInException)

Example 2 with MediaLocator

use of javax.media.MediaLocator in project Smack by igniterealtime.

the class JingleMediaTest method testAudioChannelOpenClose.

public void testAudioChannelOpenClose() {
    for (int i = 0; i < 5; i++) {
        try {
            AudioChannel audioChannel0 = new AudioChannel(new MediaLocator("javasound://"), InetAddress.getLocalHost().getHostAddress(), InetAddress.getLocalHost().getHostAddress(), 7002, 7020, new AudioFormat(AudioFormat.GSM_RTP), null);
            AudioChannel audioChannel1 = new AudioChannel(new MediaLocator("javasound://"), InetAddress.getLocalHost().getHostAddress(), InetAddress.getLocalHost().getHostAddress(), 7020, 7002, new AudioFormat(AudioFormat.GSM_RTP), null);
            audioChannel0.start();
            audioChannel1.start();
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                LOGGER.log(Level.WARNING, "exception", e);
            }
            audioChannel0.stop();
            audioChannel1.stop();
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                LOGGER.log(Level.WARNING, "exception", e);
            }
        } catch (Exception e) {
            LOGGER.log(Level.WARNING, "exception", e);
        }
    }
}
Also used : MediaLocator(javax.media.MediaLocator) AudioChannel(org.jivesoftware.smackx.jingle.mediaimpl.jmf.AudioChannel) AudioFormat(javax.media.format.AudioFormat) XMPPException(org.jivesoftware.smack.XMPPException)

Example 3 with MediaLocator

use of javax.media.MediaLocator in project Smack by igniterealtime.

the class JingleMediaTest method testAudioChannelStartStop.

public void testAudioChannelStartStop() {
    try {
        AudioChannel audioChannel0 = new AudioChannel(new MediaLocator("javasound://"), InetAddress.getLocalHost().getHostAddress(), InetAddress.getLocalHost().getHostAddress(), 7002, 7020, new AudioFormat(AudioFormat.GSM_RTP), null);
        AudioChannel audioChannel1 = new AudioChannel(new MediaLocator("javasound://"), InetAddress.getLocalHost().getHostAddress(), InetAddress.getLocalHost().getHostAddress(), 7020, 7002, new AudioFormat(AudioFormat.GSM_RTP), null);
        for (int i = 0; i < 5; i++) {
            audioChannel0.start();
            audioChannel1.start();
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                LOGGER.log(Level.WARNING, "exception", e);
            }
            audioChannel0.stop();
            audioChannel1.stop();
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                LOGGER.log(Level.WARNING, "exception", e);
            }
        }
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "exception", e);
    }
}
Also used : MediaLocator(javax.media.MediaLocator) AudioChannel(org.jivesoftware.smackx.jingle.mediaimpl.jmf.AudioChannel) AudioFormat(javax.media.format.AudioFormat) XMPPException(org.jivesoftware.smack.XMPPException)

Example 4 with MediaLocator

use of javax.media.MediaLocator in project Smack by igniterealtime.

the class AudioChannel method main.

public static void main(String[] args) {
    InetAddress localhost;
    try {
        localhost = InetAddress.getLocalHost();
        AudioChannel audioChannel0 = new AudioChannel(new MediaLocator("javasound://8000"), localhost.getHostAddress(), localhost.getHostAddress(), 7002, 7020, new AudioFormat(AudioFormat.GSM_RTP), null);
        AudioChannel audioChannel1 = new AudioChannel(new MediaLocator("javasound://8000"), localhost.getHostAddress(), localhost.getHostAddress(), 7020, 7002, new AudioFormat(AudioFormat.GSM_RTP), null);
        audioChannel0.start();
        audioChannel1.start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            LOGGER.log(Level.WARNING, "exception", e);
        }
        audioChannel0.setTrasmit(false);
        audioChannel1.setTrasmit(false);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            LOGGER.log(Level.WARNING, "exception", e);
        }
        audioChannel0.setTrasmit(true);
        audioChannel1.setTrasmit(true);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            LOGGER.log(Level.WARNING, "exception", e);
        }
        audioChannel0.stop();
        audioChannel1.stop();
    } catch (UnknownHostException e) {
        LOGGER.log(Level.WARNING, "exception", e);
    }
}
Also used : MediaLocator(javax.media.MediaLocator) UnknownHostException(java.net.UnknownHostException) AudioFormat(javax.media.format.AudioFormat) InetAddress(java.net.InetAddress)

Example 5 with MediaLocator

use of javax.media.MediaLocator in project Spark by igniterealtime.

the class VideoChannel method main.

public static void main(String[] args) {
    InetAddress localhost;
    try {
        // FMJ
        RegistryDefaults.registerAll(RegistryDefaults.FMJ | RegistryDefaults.FMJ_NATIVE);
        // PlugInManager.addPlugIn(, in, out, type)
        LibJitsi.start();
        // Add Device
        MediaType[] mediaTypes = MediaType.values();
        MediaService mediaService = LibJitsi.getMediaService();
        // LOG ALL Devices
        final Vector<CaptureDeviceInfo> vectorDevices = CaptureDeviceManager.getDeviceList(null);
        for (CaptureDeviceInfo infoCaptureDevice : vectorDevices) {
            System.err.println("===========> " + infoCaptureDevice.getName());
            for (Format format : infoCaptureDevice.getFormats()) {
                System.err.println(format);
            }
        }
        localhost = InetAddress.getLocalHost();
        VideoChannel videoChannel0 = new VideoChannel(new MediaLocator("civil:/dev/video0"), localhost.getHostAddress(), localhost.getHostAddress(), 7002, 7020, new VideoFormat(VideoFormat.JPEG_RTP));
        VideoChannel videoChannel1 = new VideoChannel(new MediaLocator("civil:/dev/video1"), localhost.getHostAddress(), localhost.getHostAddress(), 7020, 7002, new VideoFormat(VideoFormat.JPEG_RTP));
        videoChannel0.start();
        videoChannel1.start();
        try {
            Thread.sleep(50000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        videoChannel0.setTrasmit(false);
        videoChannel1.setTrasmit(false);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        videoChannel0.setTrasmit(true);
        videoChannel1.setTrasmit(true);
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        videoChannel0.stop();
        videoChannel1.stop();
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
}
Also used : Format(javax.media.Format) MediaFormat(org.jitsi.service.neomedia.format.MediaFormat) VideoFormat(javax.media.format.VideoFormat) MediaLocator(javax.media.MediaLocator) UnknownHostException(java.net.UnknownHostException) CaptureDeviceInfo(javax.media.CaptureDeviceInfo) VideoFormat(javax.media.format.VideoFormat) InetAddress(java.net.InetAddress)

Aggregations

MediaLocator (javax.media.MediaLocator)6 AudioFormat (javax.media.format.AudioFormat)5 UnknownHostException (java.net.UnknownHostException)3 InetAddress (java.net.InetAddress)2 CaptureDeviceInfo (javax.media.CaptureDeviceInfo)2 Format (javax.media.Format)2 VideoFormat (javax.media.format.VideoFormat)2 XMPPException (org.jivesoftware.smack.XMPPException)2 AudioChannel (org.jivesoftware.smackx.jingle.mediaimpl.jmf.AudioChannel)2 IOException (java.io.IOException)1 Codec (javax.media.Codec)1 NoProcessorException (javax.media.NoProcessorException)1 UnsupportedPlugInException (javax.media.UnsupportedPlugInException)1 PacketSizeControl (javax.media.control.PacketSizeControl)1 TrackControl (javax.media.control.TrackControl)1 ContentDescriptor (javax.media.protocol.ContentDescriptor)1 DataSource (javax.media.protocol.DataSource)1 PushBufferDataSource (javax.media.protocol.PushBufferDataSource)1 InvalidSessionAddressException (javax.media.rtp.InvalidSessionAddressException)1 MediaFormat (org.jitsi.service.neomedia.format.MediaFormat)1