diff options
-rw-r--r-- | include/SLES/OpenSLES_Android.h | 4 | ||||
-rw-r--r-- | libopensles/Android.mk | 3 | ||||
-rw-r--r-- | libopensles/CEngine.c | 4 | ||||
-rw-r--r-- | libopensles/IEngine.c | 2 | ||||
-rw-r--r-- | libopensles/IEqualizer.c | 2 | ||||
-rw-r--r-- | libopensles/SndFile.c | 2 | ||||
-rw-r--r-- | libopensles/android_AudioPlayer.cpp | 22 | ||||
-rw-r--r-- | libopensles/android_AudioRecorder.cpp | 6 | ||||
-rw-r--r-- | libopensles/android_OutputMix.cpp | 6 | ||||
-rw-r--r-- | libopensles/android_SfPlayer.cpp | 99 | ||||
-rw-r--r-- | libopensles/locks.c | 6 | ||||
-rw-r--r-- | libopensles/sles_allinclusive.h | 24 | ||||
-rw-r--r-- | libopensles/sllog.c | 42 | ||||
-rw-r--r-- | libopensles/sllog.h | 120 | ||||
-rw-r--r-- | libopensles/trace.c | 17 |
15 files changed, 247 insertions, 112 deletions
diff --git a/include/SLES/OpenSLES_Android.h b/include/SLES/OpenSLES_Android.h index 37ec2c1..81bef1d 100644 --- a/include/SLES/OpenSLES_Android.h +++ b/include/SLES/OpenSLES_Android.h @@ -19,6 +19,7 @@ #ifdef __cplusplus extern "C" { +#endif /*---------------------------------------------------------------------------*/ /* Android common types */ @@ -166,7 +167,7 @@ struct SLAndroidConfigurationItf_ { #define SL_DATALOCATOR_ANDROIDFD_USE_FILE_SIZE ((SLAint64) 0xFFFFFFFFFFFFFFFFll) -/** File Descriptor-based data locator definition where locatorType must be SL_DATALOCATOR_ANDROIDFD */ +/** File Descriptor-based data locator definition, locatorType must be SL_DATALOCATOR_ANDROIDFD */ typedef struct SLDataLocator_AndroidFD_ { SLuint32 locatorType; SLint32 fd; @@ -175,6 +176,7 @@ typedef struct SLDataLocator_AndroidFD_ { } SLDataLocator_AndroidFD; +#ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/libopensles/Android.mk b/libopensles/Android.mk index 5ccb491..b491a87 100644 --- a/libopensles/Android.mk +++ b/libopensles/Android.mk @@ -26,7 +26,7 @@ include $(BUILD_STATIC_LIBRARY) include $(CLEAR_VARS) LOCAL_CFLAGS += -DUSE_BASE -DUSE_GAME -DUSE_MUSIC -DUSE_PHONE -DUSE_OPTIONAL \ --DUSE_TRACE -DUSE_DEBUG -UNDEBUG -DUSE_VERBOSE +-UUSE_TRACE -DUSE_DEBUG -UNDEBUG -DUSE_LOG=SLAndroidLogLevel_Verbose # Reduce size of .so and hide internal global symbols LOCAL_CFLAGS += -fvisibility=hidden -DSLAPIENTRY='__attribute__((visibility("default")))' @@ -39,6 +39,7 @@ LOCAL_SRC_FILES:= \ interfaces.c \ locks.c \ sles.c \ + sllog.c \ android_AudioPlayer.cpp \ android_AudioRecorder.cpp \ android_OutputMix.cpp \ diff --git a/libopensles/CEngine.c b/libopensles/CEngine.c index eee1208..688c2f3 100644 --- a/libopensles/CEngine.c +++ b/libopensles/CEngine.c @@ -59,11 +59,11 @@ void CEngine_Destroy(void *self) unsigned instanceCount = this->mEngine.mInstanceCount; unsigned instanceMask = this->mEngine.mInstanceMask; if ((0 < instanceCount) || (0 != instanceMask)) { - SL_LOGE("Object::Destroy of engine %p with %u active objects", this, instanceCount); + SL_LOGE("Object::Destroy(%p) for engine with %u active objects", this, instanceCount); while (0 != instanceMask) { unsigned i = ctz(instanceMask); assert(MAX_INSTANCE > i); - SL_LOGE("Object::Destroy of engine %p with active object ID %u", this, i + 1); + SL_LOGE("Object::Destroy(%p) for engine with active object ID %u", this, i + 1); instanceMask &= ~(1 << i); } diff --git a/libopensles/IEngine.c b/libopensles/IEngine.c index ad272d3..5e8a7c7 100644 --- a/libopensles/IEngine.c +++ b/libopensles/IEngine.c @@ -264,7 +264,7 @@ static SLresult IEngine_CreateAudioRecorder(SLEngineItf self, SLObjectItf *pReco #ifdef ANDROID result = android_audioRecorder_checkSourceSinkSupport(this); if (SL_RESULT_SUCCESS != result) { - SL_LOGE("Android: Cannot create AudioRecorder: invalid source or sink"); + SL_LOGE("Cannot create AudioRecorder: invalid source or sink"); break; } #endif diff --git a/libopensles/IEqualizer.c b/libopensles/IEqualizer.c index 37b546e..41e9c9e 100644 --- a/libopensles/IEqualizer.c +++ b/libopensles/IEqualizer.c @@ -377,7 +377,7 @@ static SLresult IEqualizer_GetCurrentPreset(SLEqualizerItf self, SLuint16 *pPres static SLresult IEqualizer_UsePreset(SLEqualizerItf self, SLuint16 index) { SL_ENTER_INTERFACE - SL_LOGV("index=%d", index); + SL_LOGV("Equalizer::UsePreset index=%u", index); IEqualizer *this = (IEqualizer *) self; if (index >= this->mNumPresets) { diff --git a/libopensles/SndFile.c b/libopensles/SndFile.c index d3abbdd..f4e57ad 100644 --- a/libopensles/SndFile.c +++ b/libopensles/SndFile.c @@ -81,7 +81,7 @@ void SndFile_Callback(SLBufferQueueItf caller, void *pContext) result = IBufferQueue_Enqueue(caller, pBuffer, size); // not much we can do if the Enqueue fails, so we'll just drop the decoded data if (SL_RESULT_SUCCESS != result) { - SL_LOGE("enqueue failed 0x%x", (unsigned) result); + SL_LOGE("enqueue failed 0x%lx", result); } } else { // FIXME This is really hosed, you can't do this anymore! diff --git a/libopensles/android_AudioPlayer.cpp b/libopensles/android_AudioPlayer.cpp index 7fabc72..3cfa5f5 100644 --- a/libopensles/android_AudioPlayer.cpp +++ b/libopensles/android_AudioPlayer.cpp @@ -381,7 +381,7 @@ static void sfplayer_handlePrefetchEvent(const int event, const int data1, void* break; } // FIXME implement buffer filler level updates - SL_LOGE("[ FIXME implement buffer filler level updates ]"); + SL_LOGD("[ FIXME implement buffer filler level updates ]"); //ap->mPrefetchStatus.mLevel = ; } break; @@ -571,7 +571,7 @@ SLresult android_audioPlayer_checkSourceSink(CAudioPlayer *pAudioPlayer) break; case SL_DATAFORMAT_PCM: // FIXME implement - SL_LOGE("[ FIXME implement PCM FD data sources ]"); + SL_LOGD("[ FIXME implement PCM FD data sources ]"); break; case SL_DATAFORMAT_RESERVED3: SL_LOGE("Cannot create audio player with SL_DATALOCATOR_ANDROIDFD data source " @@ -866,7 +866,7 @@ SLresult android_audioPlayer_getConfig(CAudioPlayer* ap, const SLchar *configKey SLresult android_audioPlayer_realize(CAudioPlayer *pAudioPlayer, SLboolean async) { SLresult result = SL_RESULT_SUCCESS; - SL_LOGV("pAudioPlayer=%p", pAudioPlayer); + SL_LOGV("Realize pAudioPlayer=%p", pAudioPlayer); switch (pAudioPlayer->mAndroidObjType) { //----------------------------------- @@ -1200,15 +1200,15 @@ void android_audioPlayer_setPlayState(CAudioPlayer *ap) { case AUDIOTRACK_PULL: switch (state) { case SL_PLAYSTATE_STOPPED: - SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_STOPPED"); + SL_LOGI("setting AudioPlayer to SL_PLAYSTATE_STOPPED"); ap->mAudioTrack->stop(); break; case SL_PLAYSTATE_PAUSED: - SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_PAUSED"); + SL_LOGI("setting AudioPlayer to SL_PLAYSTATE_PAUSED"); ap->mAudioTrack->pause(); break; case SL_PLAYSTATE_PLAYING: - SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_PLAYING"); + SL_LOGI("setting AudioPlayer to SL_PLAYSTATE_PLAYING"); ap->mAudioTrack->start(); break; default: @@ -1220,13 +1220,13 @@ void android_audioPlayer_setPlayState(CAudioPlayer *ap) { case MEDIAPLAYER: switch (state) { case SL_PLAYSTATE_STOPPED: { - SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_STOPPED"); + SL_LOGI("setting AudioPlayer to SL_PLAYSTATE_STOPPED"); if (ap->mSfPlayer != 0) { ap->mSfPlayer->stop(); } } break; case SL_PLAYSTATE_PAUSED: { - SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_PAUSED"); + SL_LOGI("setting AudioPlayer to SL_PLAYSTATE_PAUSED"); object_lock_peek(&ap); AndroidObject_state state = ap->mAndroidObjState; object_unlock_peek(&ap); @@ -1252,7 +1252,7 @@ void android_audioPlayer_setPlayState(CAudioPlayer *ap) { } } break; case SL_PLAYSTATE_PLAYING: { - SL_LOGV("setting AudioPlayer to SL_PLAYSTATE_PLAYING"); + SL_LOGI("setting AudioPlayer to SL_PLAYSTATE_PLAYING"); object_lock_peek(&ap); AndroidObject_state state = ap->mAndroidObjState; object_unlock_peek(&ap); @@ -1308,7 +1308,7 @@ void android_audioPlayer_useEventMask(CAudioPlayer *ap) { if (eventFlags & SL_PLAYEVENT_HEADMOVING) { // FIXME support SL_PLAYEVENT_HEADMOVING - SL_LOGE("[ FIXME: IPlay_SetCallbackEventsMask(SL_PLAYEVENT_HEADMOVING) on an " + SL_LOGD("[ FIXME: IPlay_SetCallbackEventsMask(SL_PLAYEVENT_HEADMOVING) on an " "SL_OBJECTID_AUDIOPLAYER to be implemented ]"); } if (eventFlags & SL_PLAYEVENT_HEADSTALLED) { @@ -1327,7 +1327,7 @@ SLresult android_audioPlayer_getDuration(IPlay *pPlayItf, SLmillisecond *pDurMse *pDurMsec = SL_TIME_UNKNOWN; // FIXME if the data source is not a buffer queue, and the audio data is saved in // shared memory with the mixer process, the duration is the size of the buffer - SL_LOGE("FIXME: android_audioPlayer_getDuration() verify if duration can be retrieved"); + SL_LOGD("FIXME: android_audioPlayer_getDuration() verify if duration can be retrieved"); break; #ifndef USE_BACKPORT case MEDIAPLAYER: { diff --git a/libopensles/android_AudioRecorder.cpp b/libopensles/android_AudioRecorder.cpp index 5e403e3..3dd4e56 100644 --- a/libopensles/android_AudioRecorder.cpp +++ b/libopensles/android_AudioRecorder.cpp @@ -405,7 +405,7 @@ SLresult android_audioRecorder_realize(CAudioRecorder* ar, SLboolean async) { #ifdef MONITOR_RECORDING gMonitorFp = fopen(MONITOR_TARGET, "w"); if (NULL == gMonitorFp) { SL_LOGE("error opening %s", MONITOR_TARGET); } - else { SL_LOGE("recording to %s", MONITOR_TARGET); } // LOGE so it's always displayed + else { SL_LOGE("recording to %s", MONITOR_TARGET); } // SL_LOGE so it's always displayed #endif return result; @@ -486,13 +486,13 @@ void android_audioRecorder_useEventMask(CAudioRecorder *ar) { if (eventFlags & SL_RECORDEVENT_HEADATLIMIT) { // FIXME support SL_RECORDEVENT_HEADATLIMIT - SL_LOGE("[ FIXME: IRecord_SetCallbackEventsMask(SL_RECORDEVENT_HEADATLIMIT) on an " + SL_LOGD("[ FIXME: IRecord_SetCallbackEventsMask(SL_RECORDEVENT_HEADATLIMIT) on an " "SL_OBJECTID_AUDIORECORDER to be implemented ]"); } if (eventFlags & SL_RECORDEVENT_HEADMOVING) { // FIXME support SL_RECORDEVENT_HEADMOVING - SL_LOGE("[ FIXME: IRecord_SetCallbackEventsMask(SL_RECORDEVENT_HEADMOVING) on an " + SL_LOGD("[ FIXME: IRecord_SetCallbackEventsMask(SL_RECORDEVENT_HEADMOVING) on an " "SL_OBJECTID_AUDIORECORDER to be implemented ]"); } diff --git a/libopensles/android_OutputMix.cpp b/libopensles/android_OutputMix.cpp index aa711bd..fb08207 100644 --- a/libopensles/android_OutputMix.cpp +++ b/libopensles/android_OutputMix.cpp @@ -22,7 +22,7 @@ SLresult android_outputMix_create(COutputMix *om) { SLresult result = SL_RESULT_SUCCESS; - SL_LOGV("om=%p", om); + SL_LOGV("Create outputMix=%p", om); om->mAndroidEffect.mEffects = new android::KeyedVector<SLuint32, android::AudioEffect* >(); @@ -32,7 +32,7 @@ SLresult android_outputMix_create(COutputMix *om) { SLresult android_outputMix_realize(COutputMix *om, SLboolean async) { SLresult result = SL_RESULT_SUCCESS; - SL_LOGV("om=%p", om); + SL_LOGV("Realize outputMix=%p", om); // initialize effects // initialize EQ @@ -69,7 +69,7 @@ SLresult android_outputMix_realize(COutputMix *om, SLboolean async) { SLresult android_outputMix_destroy(COutputMix *om) { SLresult result = SL_RESULT_SUCCESS; - SL_LOGV("om=%p", om); + SL_LOGV("Destroy outputMix=%p", om); #ifndef USE_BACKPORT diff --git a/libopensles/android_SfPlayer.cpp b/libopensles/android_SfPlayer.cpp index 93b5a22..35ca33c 100644 --- a/libopensles/android_SfPlayer.cpp +++ b/libopensles/android_SfPlayer.cpp @@ -17,18 +17,9 @@ #include "android_SfPlayer.h" #include <stdio.h> - -// The usual SL_LOGx macros and Android LOGx are not available -#ifdef LOGE -#undef LOGE -#endif -#ifdef LOGV -#undef LOGV -#endif -#define LOGE(fmt, ...) do { fprintf(stderr, "%s:%s:%d:E ", __FUNCTION__, __FILE__, __LINE__); \ - fprintf(stderr, fmt, ## __VA_ARGS__); fputc('\n', stderr); } while(0) -#define LOGV(fmt, ...) do { fprintf(stdout, "%s:%s:%d:V ", __FUNCTION__, __FILE__, __LINE__); \ - fprintf(stdout, fmt, ## __VA_ARGS__); fputc('\n', stdout); } while(0) +#include "SLES/OpenSLES.h" +#include "SLES/OpenSLES_Android.h" +#include "sllog.h" namespace android { @@ -53,7 +44,7 @@ SfPlayer::SfPlayer() SfPlayer::~SfPlayer() { - LOGV("SfPlayer::~SfPlayer()"); + SL_LOGV("SfPlayer::~SfPlayer()"); mRenderLooper->stop(); mRenderLooper->unregisterHandler(this->id()); @@ -106,7 +97,7 @@ void SfPlayer::setDataSource(const char *uri) { char* newUri = (char*) malloc(len + 1); if (NULL == newUri) { // mem issue - LOGE("SfPlayer::setDataSource: ERROR not enough memory to allocator URI string"); + SL_LOGE("SfPlayer::setDataSource: not enough memory to allocator URI string"); return; } memcpy(newUri, uri, len + 1); @@ -124,12 +115,12 @@ void SfPlayer::setDataSource(const int fd, const int64_t offset, const int64_t l int ret = fstat(fd, &sb); if (ret != 0) { // sockets are not supported - LOGE("SfPlayer::setDataSource: ERROR fstat(%d) failed: %d, %s", fd, ret, strerror(errno)); + SL_LOGE("SfPlayer::setDataSource: fstat(%d) failed: %d, %s", fd, ret, strerror(errno)); return; } if (offset >= sb.st_size) { - LOGE("SfPlayer::setDataSource: ERROR invalid offset"); + SL_LOGE("SfPlayer::setDataSource: invalid offset"); return; } mDataLocator.fdi.offset = offset; @@ -146,25 +137,25 @@ void SfPlayer::setDataSource(const int fd, const int64_t offset, const int64_t l } void SfPlayer::prepare_async() { - //LOGV("SfPlayer::prepare_async()"); + //SL_LOGV("SfPlayer::prepare_async()"); sp<AMessage> msg = new AMessage(kWhatPrepare, id()); msg->post(); } int SfPlayer::prepare_sync() { - //LOGV("SfPlayer::prepare_sync()"); + //SL_LOGV("SfPlayer::prepare_sync()"); sp<AMessage> msg = new AMessage(kWhatPrepare, id()); return onPrepare(msg); } int SfPlayer::onPrepare(const sp<AMessage> &msg) { - //LOGV("SfPlayer::onPrepare"); + //SL_LOGV("SfPlayer::onPrepare"); sp<DataSource> dataSource; switch (mDataLocatorType) { case kDataLocatorNone: - LOGE("SfPlayer::onPrepare: ERROR no data locator set"); + SL_LOGE("SfPlayer::onPrepare: no data locator set"); return MEDIA_ERROR_BASE; break; @@ -197,13 +188,13 @@ int SfPlayer::onPrepare(const sp<AMessage> &msg) { } if (dataSource == NULL) { - LOGE("SfPlayer::onPrepare: ERROR: Could not create datasource."); + SL_LOGE("SfPlayer::onPrepare: Could not create data source."); return ERROR_UNSUPPORTED; } sp<MediaExtractor> extractor = MediaExtractor::Create(dataSource); if (extractor == NULL) { - LOGE("SfPlayer::onPrepare: ERROR: Could not instantiate extractor."); + SL_LOGE("SfPlayer::onPrepare: Could not instantiate extractor."); return ERROR_UNSUPPORTED; } @@ -226,7 +217,7 @@ int SfPlayer::onPrepare(const sp<AMessage> &msg) { } if (audioTrackIndex < 0) { - LOGE("SfPlayer::onPrepare: ERROR: Could not find an audio track."); + SL_LOGE("SfPlayer::onPrepare: Could not find an audio track."); return ERROR_UNSUPPORTED; } @@ -253,7 +244,7 @@ int SfPlayer::onPrepare(const sp<AMessage> &msg) { source); if (source == NULL) { - LOGE("SfPlayer::onPrepare: ERROR: Could not instantiate decoder."); + SL_LOGE("SfPlayer::onPrepare: Could not instantiate decoder."); return ERROR_UNSUPPORTED; } @@ -261,7 +252,7 @@ int SfPlayer::onPrepare(const sp<AMessage> &msg) { } if (source->start() != OK) { - LOGE("SfPlayer::onPrepare: ERROR: Failed to start source/decoder."); + SL_LOGE("SfPlayer::onPrepare: Failed to start source/decoder."); return MEDIA_ERROR_BASE; } @@ -272,7 +263,7 @@ int SfPlayer::onPrepare(const sp<AMessage> &msg) { CHECK(meta->findInt32(kKeySampleRate, &mSampleRateHz)); if (!wantPrefetch()) { - LOGV("SfPlayer::onPrepare: no need to prefetch"); + SL_LOGV("SfPlayer::onPrepare: no need to prefetch"); // doesn't need prefetching, notify good to go sp<AMessage> msg = new AMessage(kWhatNotif, id()); msg->setInt32(EVENT_PREFETCHSTATUSCHANGE, (int32_t)kStatusEnough); @@ -280,7 +271,7 @@ int SfPlayer::onPrepare(const sp<AMessage> &msg) { notify(msg, true /*async*/); } - //LOGV("SfPlayer::onPrepare: end"); + //SL_LOGV("SfPlayer::onPrepare: end"); return SFPLAYER_SUCCESS; } @@ -292,9 +283,9 @@ bool SfPlayer::wantPrefetch() { void SfPlayer::startPrefetch_async() { - //LOGV("SfPlayer::startPrefetch_async()"); + //SL_LOGV("SfPlayer::startPrefetch_async()"); if (wantPrefetch()) { - //LOGV("SfPlayer::startPrefetch_async(): sending check cache msg"); + //SL_LOGV("SfPlayer::startPrefetch_async(): sending check cache msg"); mFlags |= kFlagPreparing; mFlags |= kFlagBuffering; @@ -305,7 +296,7 @@ void SfPlayer::startPrefetch_async() { void SfPlayer::play() { - LOGV("SfPlayer::play"); + SL_LOGV("SfPlayer::play"); if (NULL == mAudioTrack) { return; } @@ -318,7 +309,7 @@ void SfPlayer::play() { void SfPlayer::stop() { - LOGV("SfPlayer::stop"); + SL_LOGV("SfPlayer::stop"); if (NULL == mAudioTrack) { return; @@ -332,7 +323,7 @@ void SfPlayer::stop() { } void SfPlayer::pause() { - LOGV("SfPlayer::pause"); + SL_LOGV("SfPlayer::pause"); if (NULL == mAudioTrack) { return; } @@ -341,7 +332,7 @@ void SfPlayer::pause() { } void SfPlayer::seek(int64_t timeMsec) { - LOGV("SfPlayer::seek %lld", timeMsec); + SL_LOGV("SfPlayer::seek %lld", timeMsec); sp<AMessage> msg = new AMessage(kWhatSeek, id()); msg->setInt64("seek", timeMsec); msg->post(); @@ -366,17 +357,17 @@ uint32_t SfPlayer::getPositionMsec() { */ void SfPlayer::onPlay() { - LOGV("SfPlayer::onPlay"); + SL_LOGV("SfPlayer::onPlay"); mFlags |= kFlagPlaying; } void SfPlayer::onPause() { - LOGV("SfPlayer::onPause"); + SL_LOGV("SfPlayer::onPause"); mFlags &= ~kFlagPlaying; } void SfPlayer::onSeek(const sp<AMessage> &msg) { - LOGV("SfPlayer::onSeek"); + SL_LOGV("SfPlayer::onSeek"); int64_t timeMsec; CHECK(msg->findInt64("seek", &timeMsec)); @@ -389,12 +380,12 @@ void SfPlayer::onSeek(const sp<AMessage> &msg) { void SfPlayer::onDecode() { - //LOGV("SfPlayer::onDecode"); + //SL_LOGV("SfPlayer::onDecode"); bool eos; if ((mDataSource->flags() & DataSource::kWantsPrefetching) && (getCacheRemaining(&eos) == kStatusLow) && !eos) { - LOGV("buffering more."); + SL_LOGV("buffering more."); if (mFlags & kFlagPlaying) { mAudioTrack->pause(); @@ -406,7 +397,7 @@ void SfPlayer::onDecode() { if (!(mFlags & (kFlagPlaying | kFlagBuffering | kFlagPreparing))) { // don't decode if we're not buffering, prefetching or playing - //LOGV("don't decode: not buffering, prefetching or playing"); + //SL_LOGV("don't decode: not buffering, prefetching or playing"); return; } @@ -431,12 +422,12 @@ void SfPlayer::onDecode() { if (err != OK) { if (err != ERROR_END_OF_STREAM) { - LOGE("MediaSource::read returned error %d", err); + SL_LOGE("MediaSource::read returned error %d", err); // FIXME handle error } else { - //LOGV("SfPlayer::onDecode hit ERROR_END_OF_STREAM"); + //SL_LOGV("SfPlayer::onDecode hit ERROR_END_OF_STREAM"); if (mFlags & kFlagPlaying) { - //LOGV("SfPlayer::onDecode hit ERROR_END_OF_STREAM while playing"); + //SL_LOGV("SfPlayer::onDecode hit ERROR_END_OF_STREAM while playing"); // async notification of end of stream reached during playback sp<AMessage> msg = new AMessage(kWhatNotif, id()); msg->setInt32(EVENT_ENDOFSTREAM, 1); @@ -462,13 +453,13 @@ void SfPlayer::onDecode() { int64_t delayUs = mLastDecodedPositionUs + mTimeDelta - ALooper::GetNowUs(); msg->post(delayUs); // negative delays are ignored - //LOGV("timeUs=%lld, mTimeDelta=%lld, delayUs=%lld", + //SL_LOGV("timeUs=%lld, mTimeDelta=%lld, delayUs=%lld", //mLastDecodedPositionUs, mTimeDelta, delayUs); } void SfPlayer::onRender(const sp<AMessage> &msg) { - //LOGV("SfPlayer::onRender"); + //SL_LOGV("SfPlayer::onRender"); Mutex::Autolock _l(mDecodeBufferLock); @@ -490,7 +481,7 @@ void SfPlayer::onRender(const sp<AMessage> &msg) { void SfPlayer::onCheckCache(const sp<AMessage> &msg) { - //LOGV("SfPlayer::onCheckCache"); + //SL_LOGV("SfPlayer::onCheckCache"); bool eos; CacheStatus status = getCacheRemaining(&eos); @@ -501,10 +492,10 @@ void SfPlayer::onCheckCache(const sp<AMessage> &msg) { } mFlags &= ~kFlagBuffering; - LOGV("SfPlayer::onCheckCache: buffering done."); + SL_LOGV("SfPlayer::onCheckCache: buffering done."); if (mFlags & kFlagPreparing) { - //LOGV("SfPlayer::onCheckCache: preparation done."); + //SL_LOGV("SfPlayer::onCheckCache: preparation done."); mFlags &= ~kFlagPreparing; } @@ -524,15 +515,15 @@ void SfPlayer::onNotify(const sp<AMessage> &msg) { } int32_t cacheInfo; if (msg->findInt32(EVENT_PREFETCHSTATUSCHANGE, &cacheInfo)) { - LOGV("\tSfPlayer notifying %s = %d", EVENT_PREFETCHSTATUSCHANGE, cacheInfo); + SL_LOGV("\tSfPlayer notifying %s = %d", EVENT_PREFETCHSTATUSCHANGE, cacheInfo); mNotifyClient(kEventPrefetchStatusChange, cacheInfo, mNotifyUser); } if (msg->findInt32(EVENT_PREFETCHFILLLEVELUPDATE, &cacheInfo)) { - LOGV("\tSfPlayer notifying %s = %d", EVENT_PREFETCHFILLLEVELUPDATE, cacheInfo); + SL_LOGV("\tSfPlayer notifying %s = %d", EVENT_PREFETCHFILLLEVELUPDATE, cacheInfo); mNotifyClient(kEventPrefetchFillLevelUpdate, cacheInfo, mNotifyUser); } if (msg->findInt32(EVENT_ENDOFSTREAM, &cacheInfo)) { - LOGV("\tSfPlayer notifying %s = %d", EVENT_ENDOFSTREAM, cacheInfo); + SL_LOGV("\tSfPlayer notifying %s = %d", EVENT_ENDOFSTREAM, cacheInfo); mNotifyClient(kEventEndOfStream, cacheInfo, mNotifyUser); } } @@ -549,13 +540,13 @@ SfPlayer::CacheStatus SfPlayer::getCacheRemaining(bool *eos) { int64_t dataRemainingUs = dataRemaining * 8000000ll / mBitrate; - LOGV("SfPlayer::getCacheRemaining: approx %.2f secs remaining (eos=%d)", + SL_LOGV("SfPlayer::getCacheRemaining: approx %.2f secs remaining (eos=%d)", dataRemainingUs / 1E6, *eos); // FIXME improve if (dataRemainingUs >= mDurationUsec*0.95) { mCacheStatus = kStatusEnough; - LOGV("SfPlayer::getCacheRemaining: cached most of the content"); + SL_LOGV("SfPlayer::getCacheRemaining: cached most of the content"); } else { // FIXME evaluate also against the sound duration if (dataRemainingUs > 30000000) { @@ -570,12 +561,12 @@ SfPlayer::CacheStatus SfPlayer::getCacheRemaining(bool *eos) { } if (oldStatus != mCacheStatus) { - //LOGV("SfPlayer::getCacheRemaining: Status change to %d", mCacheStatus); + //SL_LOGV("SfPlayer::getCacheRemaining: Status change to %d", mCacheStatus); sp<AMessage> msg = new AMessage(kWhatNotif, id()); msg->setInt32(EVENT_PREFETCHSTATUSCHANGE, mCacheStatus); notify(msg, true /*async*/); // FIXME update cache level - LOGE("[ FIXME update cache level in SfPlayer::getCacheRemaining() ]"); + SL_LOGD("[ FIXME update cache level in SfPlayer::getCacheRemaining() ]"); } return mCacheStatus; diff --git a/libopensles/locks.c b/libopensles/locks.c index 3e4ad1a..efe6f30 100644 --- a/libopensles/locks.c +++ b/libopensles/locks.c @@ -133,11 +133,11 @@ void object_unlock_exclusive_attributes(IObject *this, unsigned attributes) break; case SL_OBJECTID_OUTPUTMIX: // FIXME update gains on all players attached to this outputmix - SL_LOGE("[ FIXME: gain update on an SL_OBJECTID_OUTPUTMIX to be implemented ]"); + SL_LOGD("[ FIXME: gain update on an SL_OBJECTID_OUTPUTMIX to be implemented ]"); break; case SL_OBJECTID_MIDIPLAYER: // MIDI - SL_LOGE("[ FIXME: gain update on an SL_OBJECTID_MIDIPLAYER to be implemented ]"); + SL_LOGD("[ FIXME: gain update on an SL_OBJECTID_MIDIPLAYER to be implemented ]"); break; default: break; @@ -157,7 +157,7 @@ void object_unlock_exclusive_attributes(IObject *this, unsigned attributes) break; case SL_OBJECTID_MIDIPLAYER: // MIDI - SL_LOGE("[ FIXME: position update on an SL_OBJECTID_MIDIPLAYER to be implemented ]"); + SL_LOGD("[ FIXME: position update on an SL_OBJECTID_MIDIPLAYER to be implemented ]"); break; default: break; diff --git a/libopensles/sles_allinclusive.h b/libopensles/sles_allinclusive.h index dcb12ae..2b2ae4e 100644 --- a/libopensles/sles_allinclusive.h +++ b/libopensles/sles_allinclusive.h @@ -92,6 +92,8 @@ typedef struct COutputMix_struct COutputMix; #include "OutputMixExt.h" #endif +#include "sllog.h" + // Hook functions typedef void (*VoidHook)(void *self); @@ -1314,28 +1316,6 @@ extern void slTraceLeaveInterfaceVoid(const char *function); #endif -#ifdef ANDROID -extern const char tag[]; -#define SL_LOGE(...) __android_log_print(ANDROID_LOG_ERROR, tag, __VA_ARGS__) -#define SL_LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, tag, __VA_ARGS__) -#else -#define SL_LOGE(...) do { fprintf(stderr, "SL_LOGE: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) -#define SL_LOGD(...) do { fprintf(stderr, "SL_LOGD: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) -#endif - -#ifdef USE_VERBOSE -#ifdef ANDROID -#define SL_LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, tag, __VA_ARGS__) -#else -#define SL_LOGV(...) do { fprintf(stderr, "SL_LOGV: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ - fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) -#endif -#else -#define SL_LOGV(...) do { } while (0) -#endif - #ifdef USE_OUTPUTMIXEXT #define SL_PLAYSTATE_STOPPING ((SLuint32) 0x4) // Play::Stop while PLAYING diff --git a/libopensles/sllog.c b/libopensles/sllog.c new file mode 100644 index 0000000..e827437 --- /dev/null +++ b/libopensles/sllog.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sles_allinclusive.h" + +#ifdef ANDROID +/** \brief Log messages are prefixed by this tag */ +const char slLogTag[] = "libOpenSLES"; +#endif + +#if 0 +// There is no support for configuring the logging level at runtime. +// If that was needed, it could be done like this: +// #define SL_LOGx(...) do { if (slLogLevel <= ...) ... } while (0) + +/** \brief Default runtime log level */ + +SLAndroidLogLevel slLogLevel = USE_LOG_RUNTIME; + +/** \brief Set the runtime log level */ + +SLAPIENTRY void slAndroidSetLogLevel(SLAndroidLogLevel logLevel) +{ + // Errors can't be disabled + if (logLevel > SLAndroidLogLevel_Error) + logLevel = SLAndroidLogLevel_Error; + slLogLevel = logLevel; +} +#endif diff --git a/libopensles/sllog.h b/libopensles/sllog.h new file mode 100644 index 0000000..56a1723 --- /dev/null +++ b/libopensles/sllog.h @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Logging + +// In order of decreasing priority, the log priority levels are: +// Assert +// E(rror) +// W(arn) +// I(nfo) +// D(ebug) +// V(erbose) +// Debug and verbose are usually compiled out except during development. + +/** These values match the definitions in core/include/cutils/log.h */ +typedef enum { + SLAndroidLogLevel_Unknown = 0, + SLAndroidLogLevel_Default = 1, + SLAndroidLogLevel_Verbose = 2, + SLAndroidLogLevel_Debug = 3, + SLAndroidLogLevel_Info = 4, + SLAndroidLogLevel_Warn = 5, + SLAndroidLogLevel_Error = 6, + SLAndroidLogLevel_Fatal = 7, + SLAndroidLogLevel_Silent = 8 +} SLAndroidLogLevel; + +// USE_LOG is the minimum log priority level that is enabled at build time. +// It is configured in Android.mk but can be overridden per source file. +#ifndef USE_LOG +#define USE_LOG SLAndroidLogLevel_Info +#endif + + +#ifdef ANDROID + +// The usual Android LOGx macros are not available, so we use the lower-level APIs. +extern const char slLogTag[]; + +#if (USE_LOG <= SLAndroidLogLevel_Error) +#define SL_LOGE(...) __android_log_print(SLAndroidLogLevel_Error, slLogTag, __VA_ARGS__) +#else +#define SL_LOGE(...) do { } while (0) +#endif + +#if (USE_LOG <= SLAndroidLogLevel_Warn) +#define SL_LOGW(...) __android_log_print(SLAndroidLogLevel_Warn, slLogTag, __VA_ARGS__) +#else +#define SL_LOGW(...) do { } while (0) +#endif + +#if (USE_LOG <= SLAndroidLogLevel_Info) +#define SL_LOGI(...) __android_log_print(SLAndroidLogLevel_Info, slLogTag, __VA_ARGS__) +#else +#define SL_LOGI(...) do { } while (0) +#endif + +#if (USE_LOG <= SLAndroidLogLevel_Debug) +#define SL_LOGD(...) __android_log_print(SLAndroidLogLevel_Debug, slLogTag, __VA_ARGS__) +#else +#define SL_LOGD(...) do { } while (0) +#endif + +#if (USE_LOG <= SLAndroidLogLevel_Verbose) +#define SL_LOGV(...) __android_log_print(SLAndroidLogLevel_Verbose, slLogTag, __VA_ARGS__) +#else +#define SL_LOGV(...) do { } while (0) +#endif + +#else // !defined(ANDROID) + +#if (USE_LOG <= SLAndroidLogLevel_Error) +#define SL_LOGE(...) do { fprintf(stderr, "SL_LOGE: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } while(0) +#else +#define SL_LOGE(...) do { } while (0) +#endif + +#if (USE_LOG <= SLAndroidLogLevel_Warn) +#define SL_LOGW(...) do { fprintf(stderr, "SL_LOGW: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } } while(0) +#else +#define SL_LOGW(...) do { } while (0) +#endif + +#if (USE_LOG <= SLAndroidLogLevel_Info) +#define SL_LOGI(...) do { fprintf(stderr, "SL_LOGI: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } } while(0) +#else +#define SL_LOGI(...) do { } while (0) +#endif + +#if (USE_LOG <= SLAndroidLogLevel_Debug) +#define SL_LOGD(...) do { fprintf(stderr, "SL_LOGD: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } } while(0) +#else +#define SL_LOGD(...) do { } while (0) +#endif + +#if (USE_LOG <= SLAndroidLogLevel_Verbose) +#define SL_LOGV(...) do { fprintf(stderr, "SL_LOGV: %s:%s:%d ", __FILE__, __FUNCTION__, __LINE__); \ + fprintf(stderr, __VA_ARGS__); fputc('\n', stderr); } } while(0) +#else +#define SL_LOGV(...) do { } while (0) +#endif + +#endif // ANDROID diff --git a/libopensles/trace.c b/libopensles/trace.c index 010857f..3af7aea 100644 --- a/libopensles/trace.c +++ b/libopensles/trace.c @@ -18,8 +18,6 @@ #include "sles_allinclusive.h" -const char tag[] = "libOpenSLES"; - #ifdef USE_TRACE // This should be the only global variable @@ -49,9 +47,9 @@ void slTraceLeaveGlobal(const char *function, SLresult result) } else { if (SL_TRACE_LEAVE_FAILURE & slTraceEnabled) { if (SLESUT_RESULT_MAX > result) { - SL_LOGE("Leaving %s (%s)", function, slesutResultStrings[result]); + SL_LOGW("Leaving %s (%s)", function, slesutResultStrings[result]); } else { - SL_LOGE("Leaving %s (0x%X)", function, (unsigned) result); + SL_LOGW("Leaving %s (0x%X)", function, (unsigned) result); } } } @@ -102,7 +100,8 @@ void slTraceLeaveInterface(const char *function, SLresult result) if (SL_RESULT_SUCCESS == result) { if (SL_TRACE_LEAVE_SUCCESS & slTraceEnabled) { if (*underscore == '_') { - SL_LOGD("Leaving %.*s::%s", (int) (underscore - function), function, &underscore[1]); + SL_LOGD("Leaving %.*s::%s", (int) (underscore - function), function, + &underscore[1]); } else { SL_LOGD("Leaving %s", function); } @@ -111,17 +110,17 @@ void slTraceLeaveInterface(const char *function, SLresult result) if (SL_TRACE_LEAVE_FAILURE & slTraceEnabled) { if (*underscore == '_') { if (SLESUT_RESULT_MAX > result) { - SL_LOGE("Leaving %.*s::%s (%s)", (int) (underscore - function), function, + SL_LOGW("Leaving %.*s::%s (%s)", (int) (underscore - function), function, &underscore[1], slesutResultStrings[result]); } else { - SL_LOGE("Leaving %.*s::%s (0x%X)", (int) (underscore - function), function, + SL_LOGW("Leaving %.*s::%s (0x%X)", (int) (underscore - function), function, &underscore[1], (unsigned) result); } } else { if (SLESUT_RESULT_MAX > result) { - SL_LOGE("Leaving %s (%s)", function, slesutResultStrings[result]); + SL_LOGW("Leaving %s (%s)", function, slesutResultStrings[result]); } else { - SL_LOGE("Leaving %s (0x%X)", function, (unsigned) result); + SL_LOGW("Leaving %s (0x%X)", function, (unsigned) result); } } } |