Essay on Program: Output and Processor

Submitted By Brahmanandakar
Words: 1129
Pages: 5

import java.awt.*; import javax.media.*; import javax.media.protocol.*; import javax.media.format.*; import javax.media.control.TrackControl; import javax.media.control.QualityControl; import java.io.*;

public class VideoTransmit {

// Input MediaLocator // Can be a file or http or capture source private MediaLocator locator; private String ipAddress; private String port;

private Processor processor = null; private DataSink rtptransmitter = null; private DataSource dataOutput = null; public VideoTransmit(MediaLocator locator, String ipAddress, String port) { this.locator = locator; this.ipAddress = ipAddress; this.port = port; }

/** * Starts the transmission. Returns null if transmission started ok. * Otherwise it returns a string with the reason why the setup failed. */ public synchronized String start() { String result;

// Create a processor for the specified media locator // and program it to output JPEG/RTP result = createProcessor(); if (result != null) return result;

// Create an RTP session to transmit the output of the // processor to the specified IP address and port no. result = createTransmitter(); if (result != null) { processor.close(); processor = null; return result; }

// Start the transmission processor.start(); return null; }

/** * Stops the transmission if already started */ public void stop() { synchronized (this) { if (processor != null) { processor.stop(); processor.close(); processor = null; rtptransmitter.close(); rtptransmitter = null; } } }

private String createProcessor() { if (locator == null) return "Locator is null";

DataSource ds; DataSource clone;

try { ds = Manager.createDataSource(locator); } catch (Exception e) { return "Couldn't create DataSource"; }

// Try to create a processor to handle the input media locator try { processor = Manager.createProcessor(ds); } catch (NoProcessorException npe) { return "Couldn't create processor"; } catch (IOException ioe) { return "IOException creating processor"; }

// Wait for it to configure boolean result = waitForState(processor, Processor.Configured); if (result == false) return "Couldn't configure processor";

// Get the tracks from the processor TrackControl [] tracks = processor.getTrackControls();

// Do we have atleast one track? if (tracks == null || tracks.length < 1) return "Couldn't find tracks in processor";

boolean programmed = false;

// Search through the tracks for a video track for (int i = 0; i < tracks.length; i++) { Format format = tracks[i].getFormat(); if ( tracks[i].isEnabled() && format instanceof VideoFormat && !programmed) { // Found a video track. Try to program it to output JPEG/RTP // Make sure the sizes are multiple of 8's. Dimension size = ((VideoFormat)format).getSize(); float frameRate = ((VideoFormat)format).getFrameRate(); int w = (size.width % 8 == 0 ? size.width : (int)(size.width / 8) * 8); int h = (size.height % 8 == 0 ? size.height :