Thread: [Jahshaka-cvs] SF.net SVN: openlibraries:[1432] trunk/src/openmedialib/plugins/openal/ openal_plugi
Status: Beta
Brought to you by:
jahshaka
From: <tim...@us...> - 2008-11-10 15:46:00
|
Revision: 1432 http://openlibraries.svn.sourceforge.net/openlibraries/?rev=1432&view=rev Author: timdewhirst Date: 2008-11-10 15:45:52 +0000 (Mon, 10 Nov 2008) Log Message: ----------- olibs * fix for unguarded initialization of openal plugin Modified Paths: -------------- trunk/src/openmedialib/plugins/openal/openal_plugin.cpp Modified: trunk/src/openmedialib/plugins/openal/openal_plugin.cpp =================================================================== --- trunk/src/openmedialib/plugins/openal/openal_plugin.cpp 2008-11-06 10:03:26 UTC (rev 1431) +++ trunk/src/openmedialib/plugins/openal/openal_plugin.cpp 2008-11-10 15:45:52 UTC (rev 1432) @@ -55,32 +55,41 @@ static ALCdevice *device = NULL; static ALCcontext *context = NULL; + static boost::recursive_mutex mutex; + void reflib( int init ) - { - boost::recursive_mutex mutex; + { + boost::recursive_mutex::scoped_lock lock( mutex ); - static long refs = 0; + static long refs = 0; - assert( refs >= 0 && L"openal_plugin::refinit: refs is negative." ); + assert( refs >= 0 && L"openal_plugin::refinit: refs is negative." ); - if( init > 0 && ++refs == 1 ) + if( init > 0 && ++refs == 1 ) + { + assert( context==NULL && L"openal_plugin::refinit: already have context." ); + assert( device==NULL && L"openal_plugin::refinit: already have device." ); + + // Initialise the op + // Initialise the openal libs + device = alcOpenDevice( NULL ); + if( alcGetError( device ) == ALC_NO_ERROR ) + context = alcCreateContext( device, NULL ); + if ( context != NULL ) + alcMakeContextCurrent( context ); + } + else if( init < 0 && --refs == 0 ) + { + // Uninitialise + if ( context != NULL ) { - // Initialise the openal libs - device = alcOpenDevice( NULL ); - if( alcGetError( device ) == ALC_NO_ERROR ) - context = alcCreateContext( device, NULL ); - if ( context != NULL ) - alcMakeContextCurrent( context ); + alcMakeContextCurrent( NULL ); + alcDestroyContext( context ); + context = NULL; + alcCloseDevice( device ); + device = NULL; } - else if( init < 0 && --refs == 0 ) - { - // Uninitialise - if ( context != NULL ) - { - alcDestroyContext( context ); - alcCloseDevice( device ); - } - } + } } } @@ -123,8 +132,8 @@ void play( ) { - ALenum state; - alGetSourcei( source_, AL_SOURCE_STATE, &state ); + ALenum state; + alGetSourcei( source_, AL_SOURCE_STATE, &state ); if ( state != AL_PLAYING ) alSourcePlay( source_ ); } @@ -142,7 +151,7 @@ do { // Determine how many buffers are processed - alGetSourcei( source_, AL_BUFFERS_PROCESSED, &processed ); + alGetSourcei( source_, AL_BUFFERS_PROCESSED, &processed ); // Special case - if we have no buffers processed and no more available // for use, then we need to wait until we recover at least one @@ -152,12 +161,12 @@ while ( processed == 0 && buffers_.size( ) == 0 ); // Unqueue the processed buffers and return them to our pool - while( processed -- ) - { - ALuint buffer; - alSourceUnqueueBuffers( source_, 1, &buffer ); + while( processed -- ) + { + ALuint buffer; + alSourceUnqueueBuffers( source_, 1, &buffer ); buffers_.push_back( buffer ); - } + } } virtual bool init( ) @@ -203,7 +212,7 @@ recover( ); // If we have audio in this frame then schedule for playout - if ( aud != 0 && buffers_.size( ) > 0 ) + if ( aud != 0 && buffers_.size( ) > 0 ) { // TODO: complete mapping from audio type (combination of af and channels) if( aud->channels( ) == 1 ) @@ -222,7 +231,7 @@ for( int i = 0; i < aud->size( ) / sizeof( short ); ++i ) buf[ i ] = ( buf[ i ] >> 8 ) | ( buf[ i ] << 8 ); # endif - alBufferData( *buffers_.begin( ), format_, aud->data( ), aud->size( ), aud->frequency( ) ); + alBufferData( *buffers_.begin( ), format_, aud->data( ), aud->size( ), aud->frequency( ) ); alSourceQueueBuffers( source_, 1, &( *buffers_.begin( ) ) ); buffers_.pop_front( ); } @@ -247,20 +256,20 @@ play( ); // Recover all buffers - ALenum state; - alGetSourcei( source_, AL_SOURCE_STATE, &state ); + ALenum state; + alGetSourcei( source_, AL_SOURCE_STATE, &state ); while ( state == AL_PLAYING && buffers_.size( ) < prop_preroll_.value< int >( ) ) { recover( ); - alGetSourcei( source_, AL_SOURCE_STATE, &state ); + alGetSourcei( source_, AL_SOURCE_STATE, &state ); } alSourceStop( source_ ); } virtual bool empty( ) { - ALenum state; - alGetSourcei( source_, AL_SOURCE_STATE, &state ); + ALenum state; + alGetSourcei( source_, AL_SOURCE_STATE, &state ); return state == AL_PLAYING && buffers_.size( ) > 2; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tim...@us...> - 2008-12-19 13:49:10
|
Revision: 1435 http://openlibraries.svn.sourceforge.net/openlibraries/?rev=1435&view=rev Author: timdewhirst Date: 2008-12-19 13:48:59 +0000 (Fri, 19 Dec 2008) Log Message: ----------- olibs * fix for flush not working correctly on OS X Modified Paths: -------------- trunk/src/openmedialib/plugins/openal/openal_plugin.cpp Modified: trunk/src/openmedialib/plugins/openal/openal_plugin.cpp =================================================================== --- trunk/src/openmedialib/plugins/openal/openal_plugin.cpp 2008-12-16 21:26:26 UTC (rev 1434) +++ trunk/src/openmedialib/plugins/openal/openal_plugin.cpp 2008-12-19 13:48:59 UTC (rev 1435) @@ -1,3 +1,4 @@ +/* -*- mode: C++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*- */ // openal - A openal plugin to ml. @@ -17,13 +18,17 @@ #include <windows.h> #endif // WIN32 +// std #include <iostream> #include <cstdlib> #include <deque> +#include <vector> +#include <algorithm> #include <string> +// boost +#include <boost/thread/thread.hpp> #include <boost/thread/recursive_mutex.hpp> -#include <boost/thread/thread.hpp> #if defined ( WIN32 ) #include <al.h> @@ -58,15 +63,15 @@ static boost::recursive_mutex mutex; void reflib( int init ) - { - boost::recursive_mutex::scoped_lock lock( mutex ); + { + boost::recursive_mutex::scoped_lock lock( mutex ); - static long refs = 0; + static long refs = 0; - assert( refs >= 0 && L"openal_plugin::refinit: refs is negative." ); + assert( refs >= 0 && L"openal_plugin::refinit: refs is negative." ); - if( init > 0 && ++refs == 1 ) - { + if( init > 0 && ++refs == 1 ) + { assert( context==NULL && L"openal_plugin::refinit: already have context." ); assert( device==NULL && L"openal_plugin::refinit: already have device." ); @@ -74,22 +79,22 @@ // Initialise the openal libs device = alcOpenDevice( NULL ); if( alcGetError( device ) == ALC_NO_ERROR ) - context = alcCreateContext( device, NULL ); + context = alcCreateContext( device, NULL ); if ( context != NULL ) - alcMakeContextCurrent( context ); - } - else if( init < 0 && --refs == 0 ) - { + alcMakeContextCurrent( context ); + } + else if( init < 0 && --refs == 0 ) + { // Uninitialise if ( context != NULL ) { - alcMakeContextCurrent( NULL ); - alcDestroyContext( context ); - context = NULL; - alcCloseDevice( device ); - device = NULL; + alcMakeContextCurrent( NULL ); + alcDestroyContext( context ); + context = NULL; + alcCloseDevice( device ); + device = NULL; } - } + } } } @@ -138,20 +143,28 @@ alSourcePlay( source_ ); } + void stop( ) + { + ALenum state; + alGetSourcei( source_, AL_SOURCE_STATE, &state ); + if ( state == AL_PLAYING ) + alSourceStop( source_ ); + } + void sleep( int microseconds ) { value_type time = { microseconds / 1000000, microseconds % 1000000 }; timer_.sleep( time ); } - void recover( ) + void recover( int flag = AL_BUFFERS_PROCESSED ) { int processed; do { // Determine how many buffers are processed - alGetSourcei( source_, AL_BUFFERS_PROCESSED, &processed ); + alGetSourcei( source_, flag, &processed ); // Special case - if we have no buffers processed and no more available // for use, then we need to wait until we recover at least one @@ -160,13 +173,14 @@ } while ( processed == 0 && buffers_.size( ) == 0 ); + if ( flag == AL_BUFFERS_QUEUED && processed && !buffers_.empty() ) + buffers_.clear(); + // Unqueue the processed buffers and return them to our pool - while( processed -- ) - { - ALuint buffer; - alSourceUnqueueBuffers( source_, 1, &buffer ); - buffers_.push_back( buffer ); - } + std::vector< ALuint > recovered( processed ); + alSourceUnqueueBuffers( source_, processed, &recovered[0] ); + std::back_insert_iterator< BufferQueue > bii( buffers_ ); + std::copy( recovered.begin(), recovered.end(), bii ); } virtual bool init( ) @@ -235,6 +249,10 @@ alSourceQueueBuffers( source_, 1, &( *buffers_.begin( ) ) ); buffers_.pop_front( ); } + else + { + std::cerr << "openal_store::push: " << aud << ", " << buffers_.size() << "\n"; + } // Make sure the source is playing if ( buffers_.size( ) == 0 ) @@ -245,8 +263,8 @@ virtual frame_type_ptr flush( ) { - alSourceStop( source_ ); - recover( ); + stop( ); + recover( AL_BUFFERS_QUEUED ); return frame_type_ptr( ); } @@ -260,10 +278,10 @@ alGetSourcei( source_, AL_SOURCE_STATE, &state ); while ( state == AL_PLAYING && buffers_.size( ) < prop_preroll_.value< int >( ) ) { - recover( ); + recover( AL_BUFFERS_QUEUED ); alGetSourcei( source_, AL_SOURCE_STATE, &state ); } - alSourceStop( source_ ); + stop( ); } virtual bool empty( ) @@ -275,7 +293,8 @@ private: pcos::property prop_preroll_; - std::deque < ALuint > buffers_; + typedef std::deque < ALuint > BufferQueue; + BufferQueue buffers_; ALuint source_; ALenum format_; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tim...@us...> - 2008-12-19 16:19:43
|
Revision: 1436 http://openlibraries.svn.sourceforge.net/openlibraries/?rev=1436&view=rev Author: timdewhirst Date: 2008-12-19 16:19:38 +0000 (Fri, 19 Dec 2008) Log Message: ----------- oml * fix for possible crash on windows caused by no available buffers Modified Paths: -------------- trunk/src/openmedialib/plugins/openal/openal_plugin.cpp Modified: trunk/src/openmedialib/plugins/openal/openal_plugin.cpp =================================================================== --- trunk/src/openmedialib/plugins/openal/openal_plugin.cpp 2008-12-19 13:48:59 UTC (rev 1435) +++ trunk/src/openmedialib/plugins/openal/openal_plugin.cpp 2008-12-19 16:19:38 UTC (rev 1436) @@ -159,13 +159,20 @@ void recover( int flag = AL_BUFFERS_PROCESSED ) { - int processed; + int processed = 0; do { // Determine how many buffers are processed alGetSourcei( source_, flag, &processed ); + int error = alGetError(); + if ( error != AL_NO_ERROR ) + { + std::cerr << "openal_store::recover: an error occured when calling alGetSourcei: " << error << "\n"; + return; + } + // Special case - if we have no buffers processed and no more available // for use, then we need to wait until we recover at least one if ( processed == 0 && buffers_.size( ) == 0 ) @@ -173,6 +180,10 @@ } while ( processed == 0 && buffers_.size( ) == 0 ); + // if we have thing to process, return + if ( processed == 0 ) + return; + if ( flag == AL_BUFFERS_QUEUED && processed && !buffers_.empty() ) buffers_.clear(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tim...@us...> - 2008-12-19 17:50:13
|
Revision: 1438 http://openlibraries.svn.sourceforge.net/openlibraries/?rev=1438&view=rev Author: timdewhirst Date: 2008-12-19 17:50:09 +0000 (Fri, 19 Dec 2008) Log Message: ----------- oml * remove noisy debug Modified Paths: -------------- trunk/src/openmedialib/plugins/openal/openal_plugin.cpp Modified: trunk/src/openmedialib/plugins/openal/openal_plugin.cpp =================================================================== --- trunk/src/openmedialib/plugins/openal/openal_plugin.cpp 2008-12-19 16:20:19 UTC (rev 1437) +++ trunk/src/openmedialib/plugins/openal/openal_plugin.cpp 2008-12-19 17:50:09 UTC (rev 1438) @@ -260,10 +260,6 @@ alSourceQueueBuffers( source_, 1, &( *buffers_.begin( ) ) ); buffers_.pop_front( ); } - else - { - std::cerr << "openal_store::push: " << aud << ", " << buffers_.size() << "\n"; - } // Make sure the source is playing if ( buffers_.size( ) == 0 ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tim...@us...> - 2009-01-27 09:29:16
|
Revision: 1460 http://openlibraries.svn.sourceforge.net/openlibraries/?rev=1460&view=rev Author: timdewhirst Date: 2009-01-27 09:29:12 +0000 (Tue, 27 Jan 2009) Log Message: ----------- OML * fixes for openal plugin * use correct flags when recovering buffers * simplify functionality of flush(), complete() * N.B. ensure that no frames are being pushed during a call to complete() or flush() Modified Paths: -------------- trunk/src/openmedialib/plugins/openal/openal_plugin.cpp Modified: trunk/src/openmedialib/plugins/openal/openal_plugin.cpp =================================================================== --- trunk/src/openmedialib/plugins/openal/openal_plugin.cpp 2009-01-27 09:26:10 UTC (rev 1459) +++ trunk/src/openmedialib/plugins/openal/openal_plugin.cpp 2009-01-27 09:29:12 UTC (rev 1460) @@ -13,6 +13,7 @@ #include <openmedialib/ml/openmedialib_plugin.hpp> #include <openpluginlib/pl/timer.hpp> +#include <openpluginlib/pl/log.hpp> #ifdef WIN32 #include <windows.h> @@ -70,31 +71,31 @@ assert( refs >= 0 && L"openal_plugin::refinit: refs is negative." ); - if( init > 0 && ++refs == 1 ) + if ( init > 0 && ++refs == 1 ) { - assert( context==NULL && L"openal_plugin::refinit: already have context." ); - assert( device==NULL && L"openal_plugin::refinit: already have device." ); - - // Initialise the op - // Initialise the openal libs - device = alcOpenDevice( NULL ); - if( alcGetError( device ) == ALC_NO_ERROR ) - context = alcCreateContext( device, NULL ); - if ( context != NULL ) - alcMakeContextCurrent( context ); + assert( context==NULL && L"openal_plugin::refinit: already have context." ); + assert( device==NULL && L"openal_plugin::refinit: already have device." ); + + // Initialise the op + // Initialise the openal libs + device = alcOpenDevice( NULL ); + if( alcGetError( device ) == ALC_NO_ERROR ) + context = alcCreateContext( device, NULL ); + if ( context != NULL ) + alcMakeContextCurrent( context ); } - else if( init < 0 && --refs == 0 ) + else if ( init < 0 && --refs == 0 ) { - // Uninitialise - if ( context != NULL ) - { - alcMakeContextCurrent( NULL ); - alcDestroyContext( context ); - context = NULL; - alcCloseDevice( device ); - device = NULL; + // Uninitialise + if ( context != NULL ) + { + alcMakeContextCurrent( NULL ); + alcDestroyContext( context ); + context = NULL; + alcCloseDevice( device ); + device = NULL; + } } - } } } @@ -169,8 +170,8 @@ int error = alGetError(); if ( error != AL_NO_ERROR ) { - std::cerr << "openal_store::recover: an error occured when calling alGetSourcei: " << error << "\n"; - return; + std::cerr << "openal_store::recover: an error occured when calling alGetSourcei: " << error << "\n"; + return; } // Special case - if we have no buffers processed and no more available @@ -184,9 +185,6 @@ if ( processed == 0 ) return; - if ( flag == AL_BUFFERS_QUEUED && processed && !buffers_.empty() ) - buffers_.clear(); - // Unqueue the processed buffers and return them to our pool std::vector< ALuint > recovered( processed ); alSourceUnqueueBuffers( source_, processed, &recovered[0] ); @@ -236,6 +234,8 @@ // Recover any played out buffers recover( ); + // DEBUG_LOG << "buffers: " << buffers_.size(); + // If we have audio in this frame then schedule for playout if ( aud != 0 && buffers_.size( ) > 0 ) { @@ -260,6 +260,10 @@ alSourceQueueBuffers( source_, 1, &( *buffers_.begin( ) ) ); buffers_.pop_front( ); } + else + { + DEBUG_LOG << aud << ", " << buffers_.size(); + } // Make sure the source is playing if ( buffers_.size( ) == 0 ) @@ -270,25 +274,29 @@ virtual frame_type_ptr flush( ) { - stop( ); - recover( AL_BUFFERS_QUEUED ); + // save state + ALenum state; + alGetSourcei( source_, AL_SOURCE_STATE, &state ); + + // play to enable recovery of all buffers + play(); + while ( buffers_.size( ) < prop_preroll_.value< int >( ) ) + { + // DEBUG_LOG << "buffers: " << buffers_.size() << ", preroll: " << prop_preroll_.value< int >(); + recover(); + } + + // restore state + if ( state != AL_PLAYING ) + alSourceStop( source_ ); + return frame_type_ptr( ); } virtual void complete( ) { - // Force play - play( ); - - // Recover all buffers - ALenum state; - alGetSourcei( source_, AL_SOURCE_STATE, &state ); - while ( state == AL_PLAYING && buffers_.size( ) < prop_preroll_.value< int >( ) ) - { - recover( AL_BUFFERS_QUEUED ); - alGetSourcei( source_, AL_SOURCE_STATE, &state ); - } - stop( ); + flush(); + stop(); } virtual bool empty( ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |