[vorbis-dev] What exactly is threadsafe

Chris Nuernberger christopher.nuernberger at colorado.edu
Wed Mar 27 06:17:01 PST 2002



Hey I am playing with a LOT of threads right now, and I want to know if the 
threads all need their own little vorbis encoders running in them or what 
exactly is threadsafe in vorbis?  

So here are the functions that would be called from many threads of with 
buffer = vorbis_analysis_buffer( &m_vorbisDsp, 4*DATA_CHUNK_SIZE );
vorbis_analysis_wrote( &m_vorbisDsp, dataLength/dataSize );

 while( vorbis_analysis_blockout( &m_vorbisDsp, &m_vorbisBlock ) == 1 ) {
    /* analysis, assume we want to use bitrate management */
    vorbis_analysis( &m_vorbisBlock, NULL );
    vorbis_bitrate_addblock( &m_vorbisBlock );
    while( vorbis_bitrate_flushpacket( &m_vorbisDsp, &m_oggPacket ) ) {
      /* weld the packet into the bitstream */
      ogg_stream_packetin( &m_oggStream, &m_oggPacket );	  
      writePage();
    }
}

**Write Page looks like this**:
int result;
  result = ogg_stream_pageout( &m_oggStream, &m_oggPage );
  
  while( result != 0 ) {
    m_sink->write( (char*)m_oggPage.header, m_oggPage.header_len );
    m_sink->write( (char*)m_oggPage.body, m_oggPage.body_len );
    result = ogg_stream_pageout( &m_oggStream, &m_oggPage );
  }

I would like to be able to call the initialization functions once per 
compression run, and then have many threads compressing various sections of 
data all at once (this is for a video capture system, I think ogg would be 
cool in an AVI-like file). 

Right now I am just going to have each thread own its own compressor, all of 
them set at the same settings.

Also, I want to keep the vbr code there, just not use some of it.  Would it 
be OK if instead of this:
    /* analysis, assume we want to use bitrate management */
    vorbis_analysis( &m_vorbisBlock, NULL );
    vorbis_bitrate_addblock( &m_vorbisBlock );
    while( vorbis_bitrate_flushpacket( &m_vorbisDsp, &m_oggPacket ) ) {
      /* weld the packet into the bitstream */
      ogg_stream_packetin( &m_oggStream, &m_oggPacket );	  
      writePage();
I did this, while still using the vbr initialization functions and such:
  /* analysis, assume we want to use bitrate management */
    vorbis_analysis( &m_vorbisBlock, NULL );
   /* Use the next line if we have the CPU for it */
    // vorbis_bitrate_addblock( &m_vorbisBlock );
    while( vorbis_bitrate_flushpacket( &m_vorbisDsp, &m_oggPacket ) ) {
      /* weld the packet into the bitstream */
      ogg_stream_packetin( &m_oggStream, &m_oggPacket );	  
      writePage();

Thanks in advance, Chris

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list