Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Developer
Posts: 41
Registered: ‎04-10-2009
My Device: Not Specified

Is possible to create the Datasource over UDP

Hi,

I have to create the DataSource over udp, I am taking the reference of RIM sample for Datasource , it is over HTTP and it's working perfectlly, and i am tring to migrate this sample code to UDP, i am writing the in comming data on file and this file is constantly growing , and dataSorce is playing form this file.but player is only playing the intial chunks  while rest of the chunk are not avalable to player. can u suggest me some explaination or some code snippets or some referencess which actully descibes the whole process ...

 

 

thanks

Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Is possible to create the Datasource over UDP

Yes. All you need to do is satisfy the contract of (mainly) SourceStream.read(). In particular:

"... Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown."

 

You probably want to have a buffer and a lock. Your network layer, once new data have been received, acquires the lock, adds the data into the buffer, notifies all threads waiting on the lock (notifyAll()), and releases the lock. Your SourceStream.read acquires the lock; if no data is available, waits (using wait() + availability check in a loop) until some data is available; consumes as much data as it needs from the buffer; releses the lock; and returns the consumed data to the caller.

New Developer
Posts: 9
Registered: ‎09-10-2009
My Device: Not Specified

Re: Is possible to create the Datasource over UDP

I would also remind you that UDP is not a "reliable" transmission mechanism.  There is no guarantee that packets will not be dropped or duplicated.  Whatever media you are trying to transmit better be in a fault-tolerant format.

 

Developer
Posts: 41
Registered: ‎04-10-2009
My Device: Not Specified

Re: Is possible to create the Datasource over UDP

[ Edited ]

Hi klyubi,

 

Thanks for your suggestion ,  now i am able to play the audio on simulator, but on device the player just play the initial few second of audio, after that it stop playing . after dubuging the appliction i found that the plyer stop calling the read method of source stream . here is the code for read method ..

public int read(byte[] bytes, int off, int len) throws IOException { //Limit bytes read to our readLimit. int readLength = len; if (readLength > getReadLimit()) { readLength = getReadLimit(); } int available; for (;;) { // TODO: Need to block here on the stream until some bytes are available available = _baseSharedStream.size(); if (_bufferingComplete && available > (currentPosition+readLength)) { System.arraycopy(_baseSharedStream.getByteArray(), (int) currentPosition, bytes, off, readLength); this.currentPosition += readLength; BBEventLogger.logEventForString("available "+available +" currentPosition "+currentPosition+" readLength "+readLength ); System.out.println("available "+available +" currentPosition "+currentPosition+" readLength "+readLength ); available = _baseSharedStream.size(); Thread.yield(); return readLength; } else { //We are not ready to start yet, try sleeping to allow the //buffer to increase. try { //BBEventLogger.logEventForString("We are not ready to start yet "); System.out.println("We are not ready to start yet "); Thread.sleep(500); } catch (Exception e) { System.err.println(e.getMessage()); } } } }

 

 

Message Edited by naveen4nkp on 09-24-2009 07:11 AM
New Developer
Posts: 21
Registered: ‎09-18-2009
My Device: Not Specified

Re: Is possible to create the Datasource over UDP

Hello,

 

I am facing the same problem. It plays realtime audio , but after sometime read function is not called.

I tried to check player state , but it's in "STARTED"  state.

 

So have you solved this problem ???

 

I can play only 10-12 seconds audio , then player stops without any notification.

 

Let me know if anyone have solution. Please reply.

Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Is possible to create the Datasource over UDP

[ Edited ]

1. How does getReadLimit() work?

2. What's the type of _baseSharedStream?

Message Edited by klyubin on 30-09-2009 08:56 AM
Developer
Posts: 41
Registered: ‎04-10-2009
My Device: Not Specified

Re: Is possible to create the Datasource over UDP

Hi klyubi,

 

Now all things are working properlly on simulator as well as on device, but the plyer takes some initial time to strat playing ,the player itself creating the buffer of around 60Kb before start playing the data .is it posssible to some how reduse the initial delay in player,  

 

thanks. 

 

New Developer
Posts: 21
Registered: ‎09-18-2009
My Device: Not Specified

Re: Is possible to create the Datasource over UDP

Hello,

 

How does it work ?? What fixes u did to solve this issue ???

 

I am facing the same problem , after sometime read function is not getting called.

 

So what is the soution ???

 

Please reply if u know the solution...

Developer
Posts: 41
Registered: ‎04-10-2009
My Device: Not Specified

Re: Is possible to create the Datasource over UDP

hi jparmar,

 

You need to manage the both( one thread that is reading the data, amd other thread the writing the data on buffer) thread proper in manner. the read method should wait for notification of writing thread untill some data is avalable for read. and wrting thread should notify the all thread after writing the data on it.

 

Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Is possible to create the Datasource over UDP

Don't give the player too much data (give it, say, 1 second max) while the player is in PREFETCHING state.