[Open-discuss] Re: playing data using storeData() method.

Christina Dunn <[email protected]>
Newsgroups gmane.comp.multimedia.helix.general
Message-ID <[email protected]>
At 01:37 AM 5/25/2006, Amvya Patel wrote:
>On 5/4/06, Christina Dunn <[email protected]> wrote:
>>At 05:29 AM 5/3/2006, Amvya Patel wrote:
>> >On 5/3/06, Christina Dunn <[email protected]> wrote:
>> >>At 02:40 AM 5/1/2006, Amvya Patel wrote:
>> >> >Hi,
>> >> >
>> >> >I have a question. In splay, we used to give the URL which we wanted to
>> >> play.
>> >> >If the media file is inside a JAR file, I have to create an input
>> >> >stream and pass the stream and MIME type.
>> >> >Now, I have a Emulator where once I create a player with input stream,
>> >> >the actual file data comes to win32 native layer function. I am trying
>> >> >to integrate this emulator with Helix(JSR135 adaption code).
>> >> >
>> >> >Is there any way, I can pass this data to the Helix method (in stead
>> >> >of the URL) along with mimetype? That is, is there any way using which
>> >> >I can pass the data to Helix(JSR135 project code) in place of URL??
>> >>
>> >>Yes, you can use the JSR135 Java interface "createPlayer( InputStream is,
>> >>String mimeType )",
>> >>or use the _DataSourceAdapter C++ interface, where you provide data to the
>> >>engine via a ring buffer.
>> >In my emulator, once I say createPlayer, the call comes to the win32
>> >implementation so I can't use the "createPlayer( InputStream is,
>> >String mimeType )" Java method. If I use
>> >_DataSourceAdapter.stroredata(), how do I call createplayer? Sorry to
>> >disturb you, but could you pls elaborate on that??
>>
>>I'm not sure what you mean by "comes to the win32 implementation". Are you
>>using
>>the Java JSR135 interface, or the C++ version?
>>
>>If you want to use the C++ interface, without the Java layer for
>>InputStream type input,
>>you will need to implement _DataSourceAdapter just as it is done on the
>>Java side,
>>create the _DataSourceAdapter, and pass it into 'createPlayer'.
>>
>>from Manager.java, converted to C++ :
>>
>>
>>         // Create the C++ DataSource and Player objects
>>         _DataSourceAdapter ds = new _DataSourceAdapter(NULL,  mimeType,
>>_DataSourceAdapter::NOT_SEEKABLE);
>>         _Player p = _Manager.createPlayer(ds);
>>
>>         // Add data, look at
>>javax/microedition/media/DataSourceHelper.java for an example on how to add
>>data
>>         ds.storeData(buf_read_from_source, bufsize);
>>
>>--christina
>yes, I did
>_DataSourceAdapter ds = new _DataSourceAdapter(NULL,  mimeType,
>_DataSourceAdapter::NOT_SEEKABLE);
>_Player p = _Manager.createPlayer(ds);
>in createplayer() and when I had the actual file data in realize(), I called
>_DataSourceAdapter.storeData(buf_read_from_source, bufsize);
>Then _Player.start() works fine.
>In the above case I have a small file, the entire file is read at once
>and that data is given to ds.storeData(), it works.
>If I have a large file, I get the file data in packets.
>For each packet recieved, I tried calling
>_DataSourceAdapter.storeData(buf_read_from_source, bufsize); But it
>plays only the first packet. THe packet No.2 onwards, it does not
>play.
>The packet size can be configured but the max limit is appx 300K per packet.

That's about the size of the ring buffer. I suspect that you are calling 
'storeData' when
the ring buffer is full. 'storeData' returns true, for success, and false 
for failure, if it could
not store the specified data. You can also use "IsRingBufferFull(bufsize)" 
to check if you
can store the data. In jsr135, supplying data to the ring buffer is done on 
a separate thread.
It will check the state of the ring buffer, store data or sleep for 20ms if 
it is full.
Refer to "player/kit/jsr135/javax/microedition/media/DataSourceHelper.java" 
for a reference implementation.

--christina

from DataSourceHelper.java :

     public void run() {
         System.out.println("Starting to read from source/input 
stream:"+Thread.currentThread());
         int len = 1024 * 8; // dsa.getMaxBufLen(); ?
         int bytesRead;
         byte[] b= new byte[len];
         int rbState;
         int numTries=0;
         int MAX_TRIES=200;
         boolean bSleep=false;

         try {
           while (!done) {

                 dsa.Lock();
                 rbState = dsa.getRingBufferState();

                 if (p.getState() == Player.CLOSED) {
                         done = true;
                 } else if (rbState == RING_BUFFER_RESET) {
                         long offset = dsa.getOffset();
                         if (seek(offset) == false) {
                                 done = true;
                                 System.out.println("DataSourceHelper: 
(ERROR) Could not seek.");
                                 dsa.setReadCode(HX_FILESTATUS_FATAL_ERROR);
                         } else {
                                 // Seek successful, ring buffer is ready 
to receive data
                                 dsa.Set();
                         }
                 } else if (dsa.IsRingBufferFull(len)) {
                         bSleep = true;
                 } else if (state == DATA_SOURCE_STARTED) {
                         // Read data when :
                         //      - ring buffer is not full
                         //      - ring buffer is not in the 'reset' mode
                         //      - data source has been 'started'
                         bytesRead = read(b, 0, len);
                         if (bytesRead > 0) {
                                 dsa.storeData(b, bytesRead);
                         } else {
                                 // end of file ?
                                 if (bytesRead == -1 || numTries++ >= 
MAX_TRIES) {
                                         System.out.println("DataSourceHelper: 
Reached end of file.");
                                         dsa.setReadCode(HX_FILESTATUS_LOGICAL_EOF);
                                         done = true;
                                 } else {
                                         dsa.setReadCode(HX_FILESTATUS_DATA_PENDING);
                                         bSleep = true;
                                 }
                         }
                 } else {
                         bSleep = true;
                 }

                 dsa.Unlock();

                 if (bSleep) {
                         Thread.currentThread().sleep(20);
                         bSleep = false;
                 }

           }
         } catch (java.lang.InterruptedException ie) {
                 System.out.println("Thread interrupted: " + ie.getMessage());
         }
     }


>Is there any way I can handle packet data instead of complete file data?
>Simulataneous reception of individual packets and playback of the same
>would be possble??
>
>Amvya
>>
>>
>> >Amvya
>> >
>> >>--christina
>> >>
>> >>
>> >> >How do I go about this entire thing??
>> >> >
>> >> >Regards,
>> >> >Amvya Patel
>>
>>



_______________________________________________
Open-discuss mailing list
[email protected]
http://lists.helixcommunity.org/mailman/listinfo/open-discuss
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.