0
0

I’m trying to open radio stream with FMOD_NONBLOCKING flag and receiving FMOD_ERR_MEMORY on some streams. I’ve tested various radio stations and it seems that I’m experiencing this problems with OGG streams only (MP3 opens OK).

  1. How I initialize FMOD system:
    [code:1r7fvp17]
    // char* memPool = new char[8192 * 1024];
    // FMOD::Memory_Initialize (memPool, 8192 * 1024, NULL, NULL, NULL);

    FMOD_RESULT result = FMOD::EventSystem_Create( &eventSystem_ );

    if (result == FMOD_OK)
    {
    result = eventSystem_->init( sMaxChannels, FMOD_INIT_NORMAL, NULL );

    if (result != FMOD_OK)
    {
        ERROR_MSG( "SoundManager::initialise: "
            "Couldn't initialise event system: %s\n",
            FMOD_ErrorString( result ) );
    
        eventSystem_ = NULL;
    }
    

    }
    else
    {
    ERROR_MSG( "SoundManager::initialise: "
    "Couldn’t create event system: %s\n",
    FMOD_ErrorString( result ) );

    eventSystem_ = NULL;
    

    }

    if (eventSystem_ == NULL)
    {
    NOTICE_MSG( "SoundManager::initialise: "
    "Sound init has failed, suppressing all sound error messages\n" );

    errorLevel_ = ErrorLevel_Silent;
    return false;
    

    }

    ASSERT (!desc.mediaPath_.empty());
    setPath ( desc.mediaPath_ );

    for (SoundManagerDesc::BanksFiles::const_iterator it = desc.banks_.begin(),
    it_end = desc.banks_.end(); it != it_end; ++it )
    {
    ASSERT (!it->empty());
    if (loadSoundBank( *it ))
    {
    INFO_MSG( "SoundManager::initialise: "
    "Loaded soundbank %s\n",
    it->c_str() );
    }
    else
    {
    ERROR_MSG( "SoundManager::initialise: "
    "Failed to load sound bank %s\n",
    it->c_str() );
    }
    }

    /*
    Create a System object and initialize.
    */

    // TODO: More nice error checking and recovery.
    result = FMOD::System_Create( &system_ );
    if (result != FMOD_OK)
    {
    SoundManager::instance().logError ( result );
    return false;
    }

    unsigned int version;
    result = system_->getVersion( &version );
    if (result != FMOD_OK)
    {
    SoundManager::instance().logError ( result );
    system_->release();
    system_ = NULL;
    return false;
    }

    if (version < FMOD_VERSION)
    {
    printf("Error! You are using an old version of FMOD %08x. This program requires %08x\n", version, FMOD_VERSION);
    return 0;
    }

    result = system_->init (sMaxChannels, FMOD_INIT_NORMAL, 0);
    if (result != FMOD_OK)
    {
    SoundManager::instance().logError ( result );
    system_->release();
    system_ = NULL;
    return false;
    }

    result = system_->setStreamBufferSize (sStreamBufferSize, sStreamBufferSizeUnit);
    if (result != FMOD_OK)
    {
    SoundManager::instance().logError ( result );
    system_->release();
    system_ = NULL;
    return false;
    }
    [/code:1r7fvp17]

  2. Here’s how I open stream:
    [code:1r7fvp17]bool Stream::createStream
    ( const std::string& url, const bool is3D )
    {
    ASSERT(!sound_);
    if (sound_)
    {
    ERROR_MSG("Stream::createStream: sound exists: 0x%x.\n", sound_);
    return false;
    }

    SoundManager& manager = SoundManager::instance();

    FMOD_MODE mode = (is3D ? FMOD_3D : FMOD_2D);
    mode |= (FMOD_LOOP_NORMAL | FMOD_HARDWARE | FMOD_NONBLOCKING | FMOD_CREATESTREAM);

    FMOD::Sound* sound = NULL;
    FMOD_RESULT result = system_->createStream (url.c_str(), mode, NULL, &soundHandle);
    DEBUG_MSG("Stream::createStream: sound handle: 0x%x.\n", sound);
    if (result != FMOD_OK)
    {
    manager.logError ( result );
    return false;
    }

    // .....
    

    return true;
    }
    [/code:1r7fvp17]

  3. After non-blocking open request is created I periodically check open status in Stream::update() function (up to tens times per second, depends on my fps). If it fails – sound is immediately released, else play starts:
    [code:1r7fvp17]
    //—————————————————————————
    bool Stream::update ()
    {
    if (sound_ && !channel_ && start_)
    {
    SoundManager& manager = SoundManager::instance();

    FMOD_OPENSTATE state = FMOD_OPENSTATE_CONNECTING;
    {
        FMOD_RESULT result = sound_-&gt;getOpenState (&amp;state, NULL, NULL); // &lt;-- Error happens here!
    
        if (result != FMOD_OK || state == FMOD_OPENSTATE_ERROR) 
        {
            ERROR_MSG (&quot;Stream::update: getOpenState returned error.\n&quot;);
            manager.logError ( result );
            sound_-&gt;release();
            sound_ = NULL;
            start_ = false;
            return false;
        }
    }
    
    if (state == FMOD_OPENSTATE_READY)
    {
        DEBUG_MSG(&quot;Stream::update: sound handle: 0x%x.\n&quot;, sound_);
        FMOD_RESULT result = system_-&gt;playSound
            (FMOD_CHANNEL_FREE, sound_, false, channel_);
    
        if ( result == FMOD_OK )
        {
            MF_ASSERT(channel_);
            if ( is3D_ )
            {
                MF_VERIFY(((FMOD::Channel*)channel_)-&gt;set3DAttributes( &amp;newVec_ , NULL ) == FMOD_OK);
                vec_ = newVec_;
                MF_VERIFY(((FMOD::Channel*)channel_)-&gt;set3DMinMaxDistance( minDistance_, maxDistance_ ) == FMOD_OK);
            }
            MF_VERIFY(((FMOD::Channel*)channel_)-&gt;setVolume (volume_) == FMOD_OK);
    
            //  release();
    
            return true;
        }
        else
        {
            MF_ASSERT(!channel_);
            manager.logError ( result );
            sound_-&gt;release();
            sound_ = NULL;
            start_ = false; // Do not try to start again...
            return false;
        }
    }
    

    }
    [/code:1r7fvp17]

  4. And on getOpenState I receive state == FMOD_OPENSTATE_ERROR and result == FMOD_ERR_MEMORY for some streams. I have tested many radio stations and it seems that it fails for OGG streams and works for MPEG streams.

Here’s initialization part of fmod.log :
[quote:1r7fvp17]
FMOD: SystemI::init : FMOD Ex Version: 00041428
FMOD: SystemI::init : maxchannels = 64, flags = 00000000, extradriverdata = 00000000
FMOD: SystemI::close :
FMOD: SystemI::close : Remove miscllaneous DSP stuff.
FMOD: SystemI::close : done.

FMOD: OutputDSound::init : Register DLL
FMOD: OutputDSound::registerDLL : Detected DIRECTX 9
FMOD: OutputDSound::init : Enumerate Drivers
FMOD: FMOD_Output_DSound_EnumProc : Enumerating "C-Media USB Headphone Set "
FMOD: OutputDSound::init : CoInitialize
FMOD: OutputDSound::init : DirectSoundCreate8 : mSelectedDriver = 0
FMOD: OutputDSound::init : SetCooperativeLevel
FMOD: OutputDSound::init : GetCaps
FMOD: OutputDSound::init : Bad Caps or emulated driver. Reverting back to software
FMOD: OutputDSound::init : Create Primary Buffer
FMOD: OutputDSound::init : Set Primary Buffer Format
FMOD: OutputDSound::init : Getting Listener Interface
FMOD: OutputDSound::init : Done
FMOD: SystemI::init : Set up software engine
FMOD: OutputDSound::createSample : length 24576, channels 2, format 2, mode 0002002a
FMOD: OutputDSound::createSample : done
FMOD: Thread::initThread : Initializing FMOD mixer thread. priority 3
FMOD: Thread::initThread : – Stacksize 32768. Stack pointer 00000000 : usesemaphore = 0 : sleeptime = 10
FMOD: Thread::callback : * FMOD mixer thread started
FMOD: Thread::initThread : done.
FMOD: SystemI::init : Set up emulated output
FMOD: SystemI::init : create the channel pool
FMOD: SystemI::init : Set up streamer
FMOD: Thread::initThread : Initializing FMOD stream thread. priority 2
FMOD: Thread::initThread : – Stacksize 49152. Stack pointer 00000000 : usesemaphore = 0 : sleeptime = 10
FMOD: Thread::callback : * FMOD stream thread started
FMOD: Thread::initThread : done.
FMOD: SystemI::init : done

FMOD: EventSystemI::init : done
FMOD: EventSystemI::load : name_or_data xxxxx.fev
FMOD: EventSystemI::load : fileversion = 0x00320000 (0x00070000, 0x00340000)
FMOD: EventSystemI::rebuildEventTable : 2 entries
FMOD: EventSystemI::load : done.
[/quote:1r7fvp17]

Here’s log for [b:1r7fvp17]successful[/b:1r7fvp17] opening of MP3 stream and then releasing sound (release is called after some time, when I pressed stop button):
[quote:1r7fvp17]
FMOD: SystemI::createSound : filename = http://glob.radiogroup.com.ua:8000/avtoradio128 : mode 000100aa
FMOD: SystemI::createSound : FMOD_NONBLOCKING specified. Putting into queue to be opened asynchronously!
FMOD: SystemI::createSound : allocated async data mem
FMOD: SystemI::createSound : getasyncthread
FMOD: SystemI::createSound : setdata soundi = 14987DF0 : node = 1E8EDC5C
FMOD: SystemI::createSound : add node to async list : head = 14987D04. list count = 0
FMOD: SystemI::createSound : done
FMOD: AsyncThread::threadFunc : Starting Asynchronous operation on sound 14987DF0
FMOD: SystemI::createSoundInternal : filename = http://glob.radiogroup.com.ua:8000/avtoradio128 : mode 000100aa
FMOD: SystemI::createSoundInternal : 19 codecs found. Scan all until one succeeds
FMOD: CodecTag::openInternal : attempting to open ID3 or ASF tags..
FMOD: Codec::release :
FMOD: Plugin::release : (1E8EDD08)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecCDDA::openInternal : attempting to open as CDDA..
FMOD: Codec::release :
FMOD: Plugin::release : (1E8EDD08)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecFSB::openInternal : attempting to open as FSB..
FMOD: CodecFSB::openInternal : Header check failed. Not an FSB
FMOD: Codec::release :
FMOD: CodecFSB::closeInternal :
FMOD: CodecFSB::closeInternal : done
FMOD: Plugin::release : (1EAE1D50)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecVAG::openInternal : attempting to open as VAG..
FMOD: CodecVAG::openInternal : ‘VAG’ ID check failed [6єi]
FMOD: Codec::release :
FMOD: Plugin::release : (1EAE1D50)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecWav::openInternal : attempting to open as WAV..
FMOD: Codec::release :
FMOD: Plugin::release : (1EAE1D50)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecOggVorbis::openInternal : attempting to open as OGG..
FMOD: CodecOggVorbis::openInternal : failed to open as ogg
FMOD: Codec::release :
FMOD: Plugin::release : (1EAEB018)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecAIFF::openInternal : attempting to open as AIFF..
FMOD: Codec::release :
FMOD: Plugin::release : (1E8EDD08)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecFLAC::openInternal : attempting to open as FLAC..
FMOD: Codec::release :
FMOD: Plugin::release : (1E8EDD08)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: Codec::release :
FMOD: MusicSong::stop :
FMOD: MusicSong::stop : done
FMOD: Plugin::release : (14A5A018)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecS3M::openInternal : attempting to open as S3M..
FMOD: CodecS3M::openInternal : ‘SCRM’ ID check failed [жf$]
FMOD: Codec::release :
FMOD: MusicSong::stop :
FMOD: MusicSong::stop : done
FMOD: Plugin::release : (14A7B030)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: Codec::release :
FMOD: MusicSong::stop :
FMOD: MusicSong::stop : done
FMOD: Plugin::release : (1E9B5018)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: Codec::release :
FMOD: MusicSong::stop :
FMOD: MusicSong::stop : done
FMOD: Plugin::release : (14A7B030)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecMIDI::openInternal : attempting to open as MIDI..
FMOD: CodecMIDI::openInternal : ‘HThd’ ID check failed [6єiT]
FMOD: Codec::release :
FMOD: Plugin::release : (14A7B030)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecDLS::openInternal : attempting to open as DLS..
FMOD: Codec::release :
FMOD: Plugin::release : (1E8EDD08)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecASF::openInternal : attempting to open as ASF..
FMOD: Codec::release :
FMOD: Plugin::release : (1E8EDD08)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecPlaylist::openInternal : attempting to open playlist file
FMOD: Codec::release :
FMOD: Plugin::release : (1EAE1D50)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecMPEG::openInternal : attempting to open as MPEG..
FMOD: SystemI::createSoundInternal : Format has 0 subsounds.
FMOD: SystemI::createSoundInternal : Create as FMOD_CREATESTREAM
FMOD: System::createSoundInternal : decode buffersize = 12672 : blocksize = 1152
FMOD: SystemI::createSample : mode 000100aa length 12672 samples, lengthbytes -1
FMOD: SystemI::createSample : subsamples = 1, channels = 2
FMOD: SystemI::createSample : subsample 0. output = 0824AA80
FMOD: SystemI::createSample : use hw
FMOD: OutputDSound::createSample : length 12672, channels 2, format 2, mode 000100aa
FMOD: OutputDSound::createSample : done
FMOD: SystemI::createSample : done
FMOD: System::createSoundInternal : Seek stream to start
FMOD: System::createSoundInternal : flush stream buffer
FMOD: System::createSoundInternal : flush successful.
FMOD: System::createSoundInternal : switch file handle from small blocking single buffered to large nonblocking doublebuffered.
FMOD: Thread::initThread : Initializing FMOD file thread. priority 1
FMOD: Thread::initThread : – Stacksize 8192. Stack pointer 00000000 : usesemaphore = 1 : sleeptime = 0
FMOD: Thread::callback : * FMOD file thread started
FMOD: Thread::initThread : done.
FMOD: SystemI::createSoundInternal : No name found in file, use filename.
FMOD: SystemI::createSoundInternal : done. OpenState now = FMOD_OPENSTATE_READY. 1080089 bytes used

FMOD: AsyncThread::threadFunc : Finished Asynchronous operation on sound 14987DF0
FMOD: SoundI::release : avtoradio128 (14987DF0)
FMOD: SoundI::release : remove stream samples. (14987DF0)
FMOD: SoundI::release : (14A35338)
FMOD: SoundI::release : free this. (14A35338)
FMOD: SoundI::release : done (14A35338)
FMOD: SoundI::release : release codec. (14987DF0)
FMOD: Codec::release :
FMOD: Codec::release : Close file (mFile = 14993BD0)
FMOD: Thread::callback : * FMOD file thread finished
FMOD: Thread::close : FMOD file thread thread destroyed
FMOD: Plugin::release : (1E8EDD08)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: SoundI::release : free this. (14987DF0)
FMOD: SoundI::release : done (14987DF0)
[/quote:1r7fvp17]

And here’s log for failed stream (release is called immediately after error in Stream::update() ):
[quote:1r7fvp17]
FMOD: SystemI::createSound : filename = http://okfm.ria.ua:8000/dance32.ogg : mode 000100aa
FMOD: SystemI::createSound : FMOD_NONBLOCKING specified. Putting into queue to be opened asynchronously!
FMOD: SystemI::createSound : allocated async data mem
FMOD: SystemI::createSound : getasyncthread
FMOD: SystemI::createSound : setdata soundi = 14987DF0 : node = 1E8EDC5C
FMOD: SystemI::createSound : add node to async list : head = 14987D04. list count = 0
FMOD: SystemI::createSound : done
FMOD: AsyncThread::threadFunc : Starting Asynchronous operation on sound 14987DF0
FMOD: SystemI::createSoundInternal : filename = http://okfm.ria.ua:8000/dance32.ogg : mode 000100aa
FMOD: SystemI::createSoundInternal : 19 codecs found. Scan all until one succeeds
FMOD: CodecTag::openInternal : attempting to open ID3 or ASF tags..
FMOD: Codec::release :
FMOD: Plugin::release : (1E8EDD08)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecCDDA::openInternal : attempting to open as CDDA..
FMOD: Codec::release :
FMOD: Plugin::release : (1E8EDD08)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecFSB::openInternal : attempting to open as FSB..
FMOD: CodecFSB::openInternal : Header check failed. Not an FSB
FMOD: Codec::release :
FMOD: CodecFSB::closeInternal :
FMOD: CodecFSB::closeInternal : done
FMOD: Plugin::release : (1EAEB018)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecVAG::openInternal : attempting to open as VAG..
FMOD: CodecVAG::openInternal : ‘VAG’ ID check failed [Ogg]
FMOD: Codec::release :
FMOD: Plugin::release : (1EAEB018)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecWav::openInternal : attempting to open as WAV..
FMOD: Codec::release :
FMOD: Plugin::release : (1EAEB018)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: CodecOggVorbis::openInternal : attempting to open as OGG..
FMOD: SystemI::createSoundInternal : Format has 0 subsounds.
FMOD: SystemI::createSoundInternal : Create as FMOD_CREATESTREAM
FMOD: System::createSoundInternal : decode buffersize = 17408 : blocksize = 256
FMOD: SystemI::createSample : mode 000100aa length 17408 samples, lengthbytes -1
FMOD: SystemI::createSample : subsamples = 1, channels = 2
FMOD: SystemI::createSample : subsample 0. output = 0824AA80
FMOD: SystemI::createSample : use hw
FMOD: OutputDSound::createSample : length 17408, channels 2, format 2, mode 000100aa
FMOD: OutputDSound::createSample : done
FMOD: SystemI::createSample : done
FMOD: System::createSoundInternal : Seek stream to start
FMOD: System::createSoundInternal : flush stream buffer
FMOD: AsyncThread::threadFunc : Finished Asynchronous operation on sound 14987DF0
FMOD: SoundI::release : (14987DF0)
FMOD: SoundI::release : remove stream samples. (14987DF0)
FMOD: SoundI::release : (1EB38D20)
FMOD: SoundI::release : free this. (1EB38D20)
FMOD: SoundI::release : done (1EB38D20)
FMOD: SoundI::release : release codec. (14987DF0)
FMOD: Codec::release :
FMOD: Codec::release : Close file (mFile = 14993BD0)
FMOD: Plugin::release : (1EAEB018)
FMOD: Plugin::release : done
FMOD: Codec::release :
FMOD: SoundI::release : free this. (14987DF0)
FMOD: SoundI::release : done (14987DF0)
[/quote:1r7fvp17]

I can provide other failed logs for OGG streams if needed – but they are similar.

  1. Additional information:

– Tested on all latest stable builds of FMODEx starting from 4.14:
4.14.28, 4.16.20, 4.18.10, 4.20.00 – results are same;
– No asynchronous action or calls to FMod from other threads on my part, everything is done from main thread;
– Those streams play fine in Winamp;
– I’m using FModExL_vc.lib library and fmodexL.dll DLL for running debug builds;
– Tried both FMOD_HARDWARE and FMOD_SOFTWARE flags – results are same;
– Tried to preallocate 8M of memory for FMod (commented code in FMod init code) – no changes.

  • You must to post comments
0
0

Hi, i had a look at this and it looks like an internal ogg codec return value was being misinterpreted so i changed it and the ogg url you gave plays ok now. This change will be in the next release on all branches which should be released tomorrow.

  • You must to post comments
0
0

Thanks! It’s working in 4.20.02 .

One related question: what, if I want to release() sound that is in state of opening… can I do this? Will it block, or it cancels opening nicely and without long delays?

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.