Help me creating datasource from inputstream please its urgent

Hi i want to create custom data source as i have read in different post and also on sun site so i tried to create one one for my self actually i was going to get stream from tcp port. using socket programming i save the input stream into file and played and its working fine and then i transfer that file using avtransmiter2.java and it work fine again its mean it confirm that the data i am getting from skype is working fine . now my question is how to get that input stream and instead of saving to the file play it using player or send it on rtp session. i read different post how to create custom data source from inputstreams but havenot any luck all the example does not work for me ... i modified a user code posted http://archives.java.sun.com/cgi-bin/wa?A2=ind0106&L=jmf-interest&D=0&P=25865 in that post some body recommanded to implement seekable so i implemented that one als in that code..... below is the code

the error is

LoadInputStream.loadBytes() - realizing player

Exception in thread "JMF thread: com.sun.media.PlaybackEngine@8ed465[ com.sun.media.PlaybackEngine@8ed465 ] ( configureThread)" java.lang.NullPointerException

at com.skype.sample.InputSourceStream.read(InputSourceStream.java:89)

at com.sun.media.parser.BasicPullParser.readBytes(BasicPullParser.java:142)

at com.sun.media.parser.BasicPullParser.readBytes(BasicPullParser.java:114)

at com.sun.media.parser.BasicPullParser.readInt(BasicPullParser.java:191)

at com.sun.media.parser.audio.AuParser.readHeader(AuParser.java:109)

at com.sun.media.parser.audio.AuParser.getTracks(AuParser.java:76)

at com.sun.media.BasicSourceModule.doRealize(BasicSourceModule.java:180)

at com.sun.media.PlaybackEngine.doConfigure1(PlaybackEngine.java:229)

at com.sun.media.PlaybackEngine.doConfigure(PlaybackEngine.java:193)

at com.sun.media.ConfigureWorkThread.process(BasicController.java:1370)

at com.sun.media.StateTransitionWorkThread.run(BasicController.java:1339)

i need urgent help to this matter so please help me in that i would be very thankfulll ......

below is the code

skype use the standard audio format

Audio format

*

File: WAV PCM

Sockets: raw PCM samples

16 KHz mono, 16 bit

Note

*

import javax.media.*;

import java.io.*;

import java.net.ServerSocket;

import java.net.Socket;

import javax.swing.*;

import java.awt.*;

import java.util.*;

public class LoadInputStream extends JFrame implements ControllerListener {

private Player player;

/** Creates new LoadInputStream */

public LoadInputStream() {

try{

// declaration section:

// declare a server socket and a client socket for the server

// declare an input and an output stream

ServerSocket SkypeServer = null;

DataInputStream is;

Socket clientSocket = null;

try {

SkypeServer = new ServerSocket(4447);

}

catch (IOException e) {

System.out.println(e);

}

// Open input stream

clientSocket = SkypeServer.accept();

is = new DataInputStream(clientSocket.getInputStream());

loadBytes(is);

setBounds(100, 100, 300, 300);

setVisible(true);

}

catch(Exception e){

System.out.println(e);

}

}

/* Loads the given byte [] into the MediaPlayer and starts playing it immediately. */

public void loadBytes(InputStream is){

DataSource ds=new DataSource(is);

System.out.println("LoadInputStream.loadBytes() - Creating DataSource (InputStream)");

System.out.println("LoadInputStream.loadBytes() - Creating Player");

try {

player = Manager.createPlayer(ds);

} catch(NoPlayerException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch(IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

System.out.println("LoadInputStream.loadBytes() - Adding Controller Listener");

player.addControllerListener(this);

System.out.println("LoadInputStream.loadBytes() - realizing player");

player.realize();

}

public static void main(String[] args){

new LoadInputStream();

}

public void controllerUpdate(javax.media.ControllerEvent e) {

if(e instanceof RealizeCompleteEvent){

System.out.println("Adding visual component");

getContentPane().add(player.getVisualComponent());

player.start();

}

}

}

=============================Datasource==========================================================

import java.io.*;

import java.nio.ByteBuffer;

import javax.media.*;

import javax.media.protocol.*;

public class DataSource extends PullDataSource{

private InputStream is;

private byte [] bytes;

/** Creates new MediaViewerDataSource */

public DataSource(InputStream is) {

super();

this.is = is;

try{

int byteCount = is.available();

bytes = new byte [byteCount];

is.read(bytes);

}

catch (Exception e){

System.out.println(e);

}

}

public PullSourceStream [] getStreams() {

PullSourceStream [] streams = new PullSourceStream [1];

InputSourceStream iss = new InputSourceStream(new ByteArrayInputStream(bytes), new FileTypeDescriptor(ContentDescriptor.RAW_RTP));

streams[0] = iss;

return streams;

}

public void connect() {}

public void disconnect() {}

public String getContentType() {

return new String("audio.x-wav");

}

public MediaLocator getLocator() {

return null;

}

public void initCheck() {}

public void setLocator(MediaLocator source) {}

public void start() {}

public void stop() {}

public Object getControl(String s){

return null;

}

public Object [] getControls(){

return null;

}

public Time getDuration(){

return null;

}

}

=================================InputStream======================================================

import java.io.InputStream;

import java.io.IOException;

import java.nio.ByteBuffer;

import javax.media.protocol.ContentDescriptor;

import javax.media.protocol.PullSourceStream;

import javax.media.protocol.Seekable;

import javax.media.protocol.SourceStream;

/**

* Build a source stream out of an input stream.

*

* @see DataSource

* @see SourceStream

* @see java.io.InputStream

*

* @version %I%, %E%.

*

*/

public

class InputSourceStream implements PullSourceStream, Seekable {

protected InputStream stream;

protected boolean eosReached;

ContentDescriptor contentType;

protected ByteBuffer inputBuffer;

/**

* Construct an <CODE>InputSourceStream</CODE> from an input stream.

*

* @param s The input stream to build the source stream from.

* @param type The content-type of the source stream.

*/

public InputSourceStream(InputStream s, ContentDescriptor type) {

stream = s;

eosReached = false;

contentType = type;

}

/**

* Get the content type for this stream.

*

* @return content descriptor for the stream.

*/

public ContentDescriptor getContentDescriptor() {

return contentType;

}

/**

* Obtain the content length

*

* @return content length for this stream.

*/

public long getContentLength() {

return SourceStream.LENGTH_UNKNOWN;

}

/**

* Query if the next read will block.

*

* @return true if a read will block.

*/

public boolean willReadBlock() {

if( eosReached == true) {

return true;

} else {

try {

return stream.available() == 0;

} catch (IOException e) {

return true;

}

}

}

/**

* Read a buffer of data.

*

* @param buffer The buffer to read data into.

* @param offset The offset into the buffer for reading.

* @param length The number of bytes to read.

* @return The number of bytes read or -1 indicating end-of-stream.

*/

public int read(byte[] buffer, int offset, int length) throws IOException {

int bytesRead = stream.read(buffer, offset, length);

if( bytesRead == -1) {

eosReached = true;

}

inputBuffer.get(buffer,offset,length);

return bytesRead;

}

/**

* Turn the stream off.

*

* @exception IOException Thrown if there is a problem closing the stream.

*/

public void close() throws IOException {

stream.close();

}

/**

* Return if the end of stream has been reached.

* @return true if the end of the stream has been reached.

*/

// $jdr: This is a bug. Need to figure out

// the "correct" way to determine, before a read

// is done, if we're at EOS.

public boolean endOfStream() {

return eosReached;

}

/**

* Returns an zero length array because no controls

* are supported.

*

* @return a zero length <code>Object</code> array.

*/

public Object[] getControls() {

return new Object[0];

}

/**

* Returns <code>null</code> because no controls are implemented.

*

* @return <code>null</code>.

*/

public Object getControl(String controlName) {

return null;

}

public long seek(long where) {

try {

inputBuffer.position((int)(where));

return where;

}

catch (IllegalArgumentException E) {

return this.tell(); // staying at the current position

}

}

public long tell() {

return inputBuffer.position();

}

public void SeekableStream(ByteBuffer byteBuffer) {

inputBuffer = byteBuffer;

this.seek((long)(0)); // set the ByteBuffer to to beginning

}

public boolean isRandomAccess() {

// TODO Auto-generated method stub

return false;

}

}

[10320 byte] By [amjadkhana] at [2007-11-27 8:11:14]
# 1

I solved a problem similar to yours. You got the NullPointerException because the content type you return ("audio.x-wav") is not supported - I believe that only the content types specified in ContentDescriptor and FileTypeDescriptor are allowed, if someone from Sun would tell whether my guess is right or not he's welcome. Try to replace the content type with FileTypeDescriptor.WAVE.

I hope this will be helpful.

Marco_Massagliaa at 2007-7-12 19:55:08 > top of Java-index,Security,Cryptography...
# 2
note that do not split one frame date into more,or you will get the exception. but i always want to know why sun do not povide an inputStream interface except url.
capea at 2007-7-12 19:55:08 > top of Java-index,Security,Cryptography...