Merge "Fix indentation and redundant whitespace"
diff --git a/src/Android.mk b/src/Android.mk
index 93f85a0..9c69bfa 100644
--- a/src/Android.mk
+++ b/src/Android.mk
@@ -162,7 +162,7 @@
system/media/wilhelm/include \
frameworks/base/media/libstagefright \
frameworks/base/media/libstagefright/include \
- frameworks/base/include/media/stagefright/openmax \
+ frameworks/native/include/media/openmax \
system/media/audio_effects/include
# __pthread_gettid
@@ -202,7 +202,7 @@
system/media/wilhelm/include \
frameworks/base/media/libstagefright \
frameworks/base/media/libstagefright/include \
- frameworks/base/include/media/stagefright/openmax
+ frameworks/native/include/media/openmax
LOCAL_MODULE := libOpenSLES
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_TAGS := optional
@@ -217,7 +217,7 @@
system/media/wilhelm/include \
frameworks/base/media/libstagefright \
frameworks/base/media/libstagefright/include \
- frameworks/base/include/media/stagefright/openmax
+ frameworks/native/include/media/openmax
LOCAL_MODULE := libOpenMAXAL
LOCAL_PRELINK_MODULE := false
LOCAL_MODULE_TAGS := optional
diff --git a/src/android/AudioPlayer_to_android.cpp b/src/android/AudioPlayer_to_android.cpp
index 0e8a8be..ae526fe 100644
--- a/src/android/AudioPlayer_to_android.cpp
+++ b/src/android/AudioPlayer_to_android.cpp
@@ -448,7 +448,7 @@
SLresult result = EnqueueAsyncCallback_ppi(ap, playCallback, &ap->mPlay.mItf, playContext,
SL_PLAYEVENT_HEADATEND);
if (SL_RESULT_SUCCESS != result) {
- LOGW("Callback %p(%p, %p, SL_PLAYEVENT_HEADATEND) dropped", playCallback,
+ ALOGW("Callback %p(%p, %p, SL_PLAYEVENT_HEADATEND) dropped", playCallback,
&ap->mPlay.mItf, playContext);
}
#endif
@@ -462,7 +462,7 @@
SLresult result = SL_RESULT_SUCCESS;
SL_LOGV("type %d", type);
- int newStreamType = ANDROID_DEFAULT_OUTPUT_STREAM_TYPE;
+ audio_stream_type_t newStreamType = ANDROID_DEFAULT_OUTPUT_STREAM_TYPE;
switch(type) {
case SL_ANDROID_STREAM_VOICE:
newStreamType = AUDIO_STREAM_VOICE_CALL;
@@ -544,12 +544,6 @@
//-----------------------------------------------------------------------------
-void audioPlayer_setInvalid(CAudioPlayer* ap) {
- ap->mAndroidObjType = INVALID_TYPE;
-}
-
-
-//-----------------------------------------------------------------------------
/*
* returns true if the given data sink is supported by AudioPlayer that doesn't
* play to an OutputMix object, false otherwise
@@ -831,7 +825,7 @@
SLresult result = EnqueueAsyncCallback_ppi(ap, callback, &ap->mPlay.mItf,
callbackPContext, event);
if (SL_RESULT_SUCCESS != result) {
- LOGW("Callback %p(%p, %p, 0x%x) dropped", callback,
+ ALOGW("Callback %p(%p, %p, 0x%x) dropped", callback,
&ap->mPlay.mItf, callbackPContext, event);
}
#endif
@@ -1251,53 +1245,48 @@
//-----------------------------------------------------------------------------
-SLresult android_audioPlayer_create(CAudioPlayer *pAudioPlayer) {
+void android_audioPlayer_create(CAudioPlayer *pAudioPlayer) {
- SLresult result = SL_RESULT_SUCCESS;
- // pAudioPlayer->mAndroidObjType has been set in audioPlayer_getAndroidObjectTypeForSourceSink()
- if (INVALID_TYPE == pAudioPlayer->mAndroidObjType) {
- audioPlayer_setInvalid(pAudioPlayer);
- result = SL_RESULT_PARAMETER_INVALID;
- } else {
+ // pAudioPlayer->mAndroidObjType has been set in android_audioPlayer_checkSourceSink()
+ // and if it was == INVALID_TYPE, then IEngine_CreateAudioPlayer would never call us
+ assert(INVALID_TYPE != pAudioPlayer->mAndroidObjType);
- // These initializations are in the same order as the field declarations in classes.h
+ // These initializations are in the same order as the field declarations in classes.h
- // FIXME Consolidate initializations (many of these already in IEngine_CreateAudioPlayer)
- // mAndroidObjType: see above comment
- pAudioPlayer->mAndroidObjState = ANDROID_UNINITIALIZED;
- pAudioPlayer->mSessionId = android::AudioSystem::newAudioSessionId();
- pAudioPlayer->mStreamType = ANDROID_DEFAULT_OUTPUT_STREAM_TYPE;
+ // FIXME Consolidate initializations (many of these already in IEngine_CreateAudioPlayer)
+ // mAndroidObjType: see above comment
+ pAudioPlayer->mAndroidObjState = ANDROID_UNINITIALIZED;
+ pAudioPlayer->mSessionId = android::AudioSystem::newAudioSessionId();
- // mAudioTrack
- pAudioPlayer->mCallbackProtector = new android::CallbackProtector();
- // mAPLayer
- // mAuxEffect
+ // placeholder: not necessary yet as session ID lifetime doesn't extend beyond player
+ // android::AudioSystem::acquireAudioSessionId(pAudioPlayer->mSessionId);
- pAudioPlayer->mAuxSendLevel = 0;
- pAudioPlayer->mAmplFromDirectLevel = 1.0f; // matches initial mDirectLevel value
- pAudioPlayer->mDeferredStart = false;
+ pAudioPlayer->mStreamType = ANDROID_DEFAULT_OUTPUT_STREAM_TYPE;
- // Already initialized in IEngine_CreateAudioPlayer, to be consolidated
- pAudioPlayer->mDirectLevel = 0; // no attenuation
+ // mAudioTrack
+ pAudioPlayer->mCallbackProtector = new android::CallbackProtector();
+ // mAPLayer
+ // mAuxEffect
- // This section re-initializes interface-specific fields that
- // can be set or used regardless of whether the interface is
- // exposed on the AudioPlayer or not
+ pAudioPlayer->mAuxSendLevel = 0;
+ pAudioPlayer->mAmplFromDirectLevel = 1.0f; // matches initial mDirectLevel value
+ pAudioPlayer->mDeferredStart = false;
- // Only AudioTrack supports a non-trivial playback rate
- switch (pAudioPlayer->mAndroidObjType) {
- case AUDIOPLAYER_FROM_PCM_BUFFERQUEUE:
- pAudioPlayer->mPlaybackRate.mMinRate = AUDIOTRACK_MIN_PLAYBACKRATE_PERMILLE;
- pAudioPlayer->mPlaybackRate.mMaxRate = AUDIOTRACK_MAX_PLAYBACKRATE_PERMILLE;
- break;
- default:
- // use the default range
- break;
- }
+ // This section re-initializes interface-specific fields that
+ // can be set or used regardless of whether the interface is
+ // exposed on the AudioPlayer or not
+ // Only AudioTrack supports a non-trivial playback rate
+ switch (pAudioPlayer->mAndroidObjType) {
+ case AUDIOPLAYER_FROM_PCM_BUFFERQUEUE:
+ pAudioPlayer->mPlaybackRate.mMinRate = AUDIOTRACK_MIN_PLAYBACKRATE_PERMILLE;
+ pAudioPlayer->mPlaybackRate.mMaxRate = AUDIOTRACK_MAX_PLAYBACKRATE_PERMILLE;
+ break;
+ default:
+ // use the default range
+ break;
}
- return result;
}
@@ -1308,7 +1297,7 @@
SLresult result;
assert(NULL != ap && NULL != configKey && NULL != pConfigValue);
- if(strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_STREAM_TYPE) == 0) {
+ if (strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_STREAM_TYPE) == 0) {
// stream type
if (KEY_STREAM_TYPE_PARAMSIZE > valueSize) {
@@ -1334,7 +1323,7 @@
SLresult result;
assert(NULL != ap && NULL != configKey && NULL != pValueSize);
- if(strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_STREAM_TYPE) == 0) {
+ if (strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_STREAM_TYPE) == 0) {
// stream type
if (NULL == pConfigValue) {
@@ -1389,7 +1378,7 @@
sles_to_android_channelMaskOut(df_pcm->numChannels, df_pcm->channelMask),
//channel mask
0, // frameCount (here min)
- 0, // flags
+ AUDIO_POLICY_OUTPUT_FLAG_NONE, // flags
audioTrack_callBack_pullFromBuffQueue, // callback
(void *) pAudioPlayer, // user
0 // FIXME find appropriate frame count // notificationFrame
@@ -1639,10 +1628,10 @@
break;
}
- pAudioPlayer->mCallbackProtector.clear();
+ // placeholder: not necessary yet as session ID lifetime doesn't extend beyond player
+ // android::AudioSystem::releaseAudioSessionId(pAudioPlayer->mSessionId);
- // FIXME might not be needed
- pAudioPlayer->mAndroidObjType = INVALID_TYPE;
+ pAudioPlayer->mCallbackProtector.clear();
// explicit destructor
pAudioPlayer->mAudioTrack.~sp();
diff --git a/src/android/AudioPlayer_to_android.h b/src/android/AudioPlayer_to_android.h
index 430b622..12113b5 100644
--- a/src/android/AudioPlayer_to_android.h
+++ b/src/android/AudioPlayer_to_android.h
@@ -28,14 +28,9 @@
extern SLresult android_audioPlayer_checkSourceSink(CAudioPlayer *pAudioPlayer);
/*
- * Determines the Android media framework object that maps to the given audio source and sink.
- * Return
- * SL_RESULT_SUCCESS if the Android resources were successfully created
- * SL_PARAMETER_INVALID if the Android resources couldn't be created due to an invalid or
- * unsupported parameter or value
- * SL_RESULT_CONTENT_UNSUPPORTED if a format is not supported (e.g. sample rate too high)
+ * Finish the Android-specific pre-Realize initialization of a CAudioPlayer.
*/
-extern SLresult android_audioPlayer_create(CAudioPlayer *pAudioPlayer);
+extern void android_audioPlayer_create(CAudioPlayer *pAudioPlayer);
/*
* Allocates and initializes the Android media framework objects intended to be used with the
diff --git a/src/android/AudioRecorder_to_android.cpp b/src/android/AudioRecorder_to_android.cpp
index d7bafcb..326b8c9 100644
--- a/src/android/AudioRecorder_to_android.cpp
+++ b/src/android/AudioRecorder_to_android.cpp
@@ -39,7 +39,7 @@
SLresult audioRecorder_setPreset(CAudioRecorder* ar, SLuint32 recordPreset) {
SLresult result = SL_RESULT_SUCCESS;
- int newRecordSource = AUDIO_SOURCE_DEFAULT;
+ audio_source_t newRecordSource = AUDIO_SOURCE_DEFAULT;
switch (recordPreset) {
case SL_ANDROID_RECORDING_PRESET_GENERIC:
newRecordSource = AUDIO_SOURCE_DEFAULT;
@@ -328,7 +328,7 @@
SLresult result;
assert(NULL != ar && NULL != configKey && NULL != pConfigValue);
- if(strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_RECORDING_PRESET) == 0) {
+ if (strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_RECORDING_PRESET) == 0) {
// recording preset
if (KEY_RECORDING_PRESET_PARAMSIZE > valueSize) {
@@ -354,7 +354,7 @@
SLresult result;
assert(NULL != ar && NULL != configKey && NULL != pValueSize);
- if(strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_RECORDING_PRESET) == 0) {
+ if (strcmp((const char*)configKey, (const char*)SL_ANDROID_KEY_RECORDING_PRESET) == 0) {
// recording preset
if (NULL == pConfigValue) {
@@ -401,7 +401,7 @@
sles_to_android_channelMaskIn(ar->mNumChannels, 0 /*no channel mask*/),
// channel config
0, //frameCount min
- 0, // flags
+ (android::AudioRecord::record_flags) 0, // flags
audioRecorder_callback,// callback_t
(void*)ar, // user, callback data, here the AudioRecorder
0, // notificationFrames
diff --git a/src/android/BufferQueueSource.cpp b/src/android/BufferQueueSource.cpp
index 9257f53..6cf04fb 100644
--- a/src/android/BufferQueueSource.cpp
+++ b/src/android/BufferQueueSource.cpp
@@ -19,7 +19,7 @@
#include "sles_allinclusive.h"
#include "android/BufferQueueSource.h"
-#include <media/stagefright/MediaDebug.h>
+#include <media/stagefright/foundation/ADebug.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
@@ -94,7 +94,7 @@
}
//assert(mStreamToBqOffset <= offset);
- CHECK(mStreamToBqOffset <= offset);
+ CHECK_LE(mStreamToBqOffset, offset);
if (offset + size <= mStreamToBqOffset + oldFront->mDataSize) {
pSrc = ((char*)oldFront->mDataBuffer) + (offset - mStreamToBqOffset);
diff --git a/src/android/MediaPlayer_to_android.cpp b/src/android/MediaPlayer_to_android.cpp
index 692aa5c..981a6bd 100644
--- a/src/android/MediaPlayer_to_android.cpp
+++ b/src/android/MediaPlayer_to_android.cpp
@@ -14,15 +14,17 @@
* limitations under the License.
*/
+#include <system/window.h>
+#include <utils/StrongPointer.h>
+#include <gui/Surface.h>
+
#include "sles_allinclusive.h"
-#include "utils/RefBase.h"
#include "android_prompts.h"
// LocAVPlayer and StreamPlayer derive from GenericMediaPlayer,
// so no need to #include "android_GenericMediaPlayer.h"
#include "android_LocAVPlayer.h"
#include "android_StreamPlayer.h"
-
//-----------------------------------------------------------------------------
static void player_handleMediaPlayerEventNotifications(int event, int data1, int data2, void* user)
{
@@ -142,7 +144,7 @@
/*i2*/ 1 /*streamIndex, only one stream supported here, 0 is reserved*/,
/*p2*/ NULL /*pEventData, always NULL in OpenMAX AL 1.0.1*/,
/*p3*/ callbackPContext /*pContext*/);
- LOGW_IF(SL_RESULT_SUCCESS != res,
+ ALOGW_IF(SL_RESULT_SUCCESS != res,
"Callback %p(%p, XA_STREAMCBEVENT_PROPERTYCHANGE, 1, NULL, %p) dropped",
callback, &mp->mStreamInfo.mItf, callbackPContext);
#endif
@@ -172,7 +174,7 @@
#else
SLresult res = EnqueueAsyncCallback_ppi(mp, playCallback, &mp->mPlay.mItf, playContext,
XA_PLAYEVENT_HEADATEND);
- LOGW_IF(SL_RESULT_SUCCESS != res,
+ ALOGW_IF(SL_RESULT_SUCCESS != res,
"Callback %p(%p, %p, SL_PLAYEVENT_HEADATEND) dropped", playCallback,
&mp->mPlay.mItf, playContext);
#endif
@@ -382,6 +384,7 @@
break;
case XA_DATALOCATOR_ADDRESS: // intended fall-through
default:
+ mp->mAndroidObjType = INVALID_TYPE;
SL_LOGE("Unable to create MediaPlayer for data source locator 0x%x", sourceLocator);
result = XA_RESULT_PARAMETER_INVALID;
break;
@@ -392,6 +395,9 @@
mp->mStreamType = ANDROID_DEFAULT_OUTPUT_STREAM_TYPE;
mp->mSessionId = android::AudioSystem::newAudioSessionId();
+ // placeholder: not necessary yet as session ID lifetime doesn't extend beyond player
+ // android::AudioSystem::acquireAudioSessionId(mp->mSessionId);
+
mp->mCallbackProtector = new android::CallbackProtector();
return result;
@@ -490,6 +496,10 @@
SL_LOGV("android_Player_destroy(%p)", mp);
mp->mAVPlayer.clear();
+
+ // placeholder: not necessary yet as session ID lifetime doesn't extend beyond player
+ // android::AudioSystem::releaseAudioSessionId(mp->mSessionId);
+
mp->mCallbackProtector.clear();
// explicit destructor
diff --git a/src/android/MediaPlayer_to_android.h b/src/android/MediaPlayer_to_android.h
index e83439d..1b491cb 100644
--- a/src/android/MediaPlayer_to_android.h
+++ b/src/android/MediaPlayer_to_android.h
@@ -14,9 +14,7 @@
* limitations under the License.
*/
-#include <surfaceflinger/Surface.h>
-#include <gui/ISurfaceTexture.h>
-
+#include <system/window.h>
/**************************************************************************************************
* Player lifecycle
diff --git a/src/android/VideoCodec_to_android.cpp b/src/android/VideoCodec_to_android.cpp
index 5f3deaa..113bd8c 100644
--- a/src/android/VideoCodec_to_android.cpp
+++ b/src/android/VideoCodec_to_android.cpp
@@ -65,7 +65,7 @@
sp<IOMX> omx(service->getOMX());
if (omx.get() == NULL) {
- LOGE("android_videoCodec_expose() couldn't access OMX interface");
+ ALOGE("android_videoCodec_expose() couldn't access OMX interface");
return false;
}
diff --git a/src/android/android_AudioSfDecoder.cpp b/src/android/android_AudioSfDecoder.cpp
index a29f09f..1a50ccb 100644
--- a/src/android/android_AudioSfDecoder.cpp
+++ b/src/android/android_AudioSfDecoder.cpp
@@ -488,7 +488,7 @@
mDecodeBuffer->release();
mDecodeBuffer = NULL;
}
- if(!mAudioSourceStarted) {
+ if (!mAudioSourceStarted) {
return;
}
err = mAudioSource->read(&mDecodeBuffer, &readOptions);
@@ -696,7 +696,7 @@
// fill level is ratio of how much has been played + how much is
// cached, divided by total duration
- uint32_t currentPositionUsec = getPositionUsec();
+ int64_t currentPositionUsec = getPositionUsec();
if (currentPositionUsec == ANDROID_UNKNOWN_TIME) {
// if we don't know where we are, assume the worst for the fill ratio
currentPositionUsec = 0;
diff --git a/src/android/android_GenericMediaPlayer.cpp b/src/android/android_GenericMediaPlayer.cpp
index f3cebf5..04f4f8e 100644
--- a/src/android/android_GenericMediaPlayer.cpp
+++ b/src/android/android_GenericMediaPlayer.cpp
@@ -19,9 +19,9 @@
#include "sles_allinclusive.h"
#include "android_GenericMediaPlayer.h"
+#include <system/window.h>
+
#include <media/IMediaPlayerService.h>
-#include <surfaceflinger/ISurfaceComposer.h>
-#include <surfaceflinger/SurfaceComposerClient.h>
#include <media/stagefright/foundation/ADebug.h>
#include <media/mediaplayer.h> // media_event_type media_error_type media_info_type
@@ -542,7 +542,7 @@
// now that we know the channel count, re-calculate the volumes
notify(PLAYEREVENT_CHANNEL_COUNT, channelCount, true /*async*/);
} else {
- LOGW("channel count is still unknown after prepare");
+ ALOGW("channel count is still unknown after prepare");
}
delete reply;
// retrieve duration
diff --git a/src/android/android_GenericMediaPlayer.h b/src/android/android_GenericMediaPlayer.h
index 3e8fe81..c0497ba 100644
--- a/src/android/android_GenericMediaPlayer.h
+++ b/src/android/android_GenericMediaPlayer.h
@@ -20,7 +20,6 @@
#include "android_GenericPlayer.h"
#include <binder/IServiceManager.h>
-#include <surfaceflinger/Surface.h>
#include <gui/ISurfaceTexture.h>
@@ -120,7 +119,7 @@
// Receives notifications about death of media.player service
const sp<MediaPlayerDeathNotifier> mPlayerDeathNotifier;
- // Return a reference to the media player service, or LOGE and return NULL after retries fail
+ // Return a reference to the media player service, or ALOGE and return NULL after retries fail
static const sp<IMediaPlayerService> getMediaPlayerService() {
return IMediaDeathNotifier::getMediaPlayerService();
}
diff --git a/src/android/android_GenericPlayer.cpp b/src/android/android_GenericPlayer.cpp
index 219c856..0fd975c 100644
--- a/src/android/android_GenericPlayer.cpp
+++ b/src/android/android_GenericPlayer.cpp
@@ -279,7 +279,7 @@
if (async) {
msg->post();
} else {
- this->onNotify(msg);
+ onNotify(msg);
}
}
@@ -292,7 +292,7 @@
if (async) {
msg->post();
} else {
- this->onNotify(msg);
+ onNotify(msg);
}
}
diff --git a/src/android/android_GenericPlayer.h b/src/android/android_GenericPlayer.h
index d3206a1..bc52846 100644
--- a/src/android/android_GenericPlayer.h
+++ b/src/android/android_GenericPlayer.h
@@ -60,22 +60,22 @@
GenericPlayer(const AudioPlayback_Parameters* params);
virtual ~GenericPlayer();
- virtual void init(const notif_cbf_t cbf, void* notifUser);
+ void init(const notif_cbf_t cbf, void* notifUser);
virtual void preDestroy();
void setDataSource(const char *uri);
void setDataSource(int fd, int64_t offset, int64_t length, bool closeAfterUse = false);
- void prepare();
+ void prepare();
virtual void play();
- virtual void pause();
- virtual void stop();
+ void pause();
+ void stop();
// timeMsec must be >= 0 or == ANDROID_UNKNOWN_TIME (used by StreamPlayer after discontinuity)
- virtual void seek(int64_t timeMsec);
- virtual void loop(bool loop);
- virtual void setBufferingUpdateThreshold(int16_t thresholdPercent);
+ void seek(int64_t timeMsec);
+ void loop(bool loop);
+ void setBufferingUpdateThreshold(int16_t thresholdPercent);
- virtual void getDurationMsec(int* msec); //msec != NULL, ANDROID_UNKNOWN_TIME if unknown
+ void getDurationMsec(int* msec); //msec != NULL, ANDROID_UNKNOWN_TIME if unknown
virtual void getPositionMsec(int* msec) = 0; //msec != NULL, ANDROID_UNKNOWN_TIME if unknown
virtual void setVideoSurfaceTexture(const sp<ISurfaceTexture> &surfaceTexture) {}
diff --git a/src/android/android_defs.h b/src/android/android_defs.h
index 5ac11e1..8519226 100644
--- a/src/android/android_defs.h
+++ b/src/android/android_defs.h
@@ -66,7 +66,7 @@
#define MPEG2_TS_PACKET_SYNC 0x47
struct AudioPlayback_Parameters {
- int streamType;
+ audio_stream_type_t streamType;
int sessionId;
};
diff --git a/src/android/android_sles_conversions.h b/src/android/android_sles_conversions.h
index ebef1e6..b818cc4 100644
--- a/src/android/android_sles_conversions.h
+++ b/src/android/android_sles_conversions.h
@@ -44,7 +44,7 @@
return (uint32_t)(sampleRateMilliHertz / 1000);
}
-static inline int sles_to_android_sampleFormat(SLuint32 pcmFormat) {
+static inline audio_format_t sles_to_android_sampleFormat(SLuint32 pcmFormat) {
switch (pcmFormat) {
case SL_PCMSAMPLEFORMAT_FIXED_16:
return AUDIO_FORMAT_PCM_16_BIT;
diff --git a/src/android/include/AacAdtsExtractor.h b/src/android/include/AacAdtsExtractor.h
index af0b38b..a3c0973 100644
--- a/src/android/include/AacAdtsExtractor.h
+++ b/src/android/include/AacAdtsExtractor.h
@@ -20,9 +20,9 @@
#include <utils/Vector.h>
#include <media/stagefright/foundation/ABuffer.h>
+#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/DataSource.h>
#include <media/stagefright/MediaBufferGroup.h>
-#include <media/stagefright/MediaDebug.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaErrors.h>
#include <media/stagefright/MediaExtractor.h>
diff --git a/src/classes.h b/src/classes.h
index 3c481ee..5ccbbae 100644
--- a/src/classes.h
+++ b/src/classes.h
@@ -95,7 +95,7 @@
/** identifies which group of effects ("session") this player belongs to */
int mSessionId;
/** identifies the Android stream type playback will occur on */
- int mStreamType;
+ audio_stream_type_t mStreamType;
// FIXME consolidate the next several variables into one class to avoid placement new
/** plays the PCM data for this player */
android::sp<android::AudioTrack> mAudioTrack;
@@ -149,7 +149,7 @@
#ifdef ANDROID
enum AndroidObjectType mAndroidObjType;
android::AudioRecord *mAudioRecord; //FIXME candidate to be encapsulated in a ARecorder subclass
- int mRecordSource; //FIXME candidate to be encapsulated in a ARecorder subclass
+ audio_source_t mRecordSource; //FIXME candidate to be encapsulated in a ARecorder subclass
#endif
} /*CAudioRecorder*/;
@@ -340,6 +340,6 @@
/** identifies which group of effects ("session") this player belongs to */
int mSessionId;
/** identifies the Android stream type playback will occur on */
- int mStreamType;
+ audio_stream_type_t mStreamType;
#endif
} CMediaPlayer;
diff --git a/src/itf/IEngine.c b/src/itf/IEngine.c
index b024fca..4b6d2b6 100644
--- a/src/itf/IEngine.c
+++ b/src/itf/IEngine.c
@@ -212,7 +212,7 @@
thiz->mSampleRateMilliHz = UNKNOWN_SAMPLERATE;
// More default values, in case destructor needs to be called early
- thiz->mDirectLevel = 0;
+ thiz->mDirectLevel = 0; // no attenuation
#ifdef USE_OUTPUTMIXEXT
thiz->mTrack = NULL;
thiz->mGains[0] = 1.0f;
@@ -237,6 +237,8 @@
android::sp<android::CallbackProtector>();
(void) new (&thiz->mAuxEffect) android::sp<android::AudioEffect>();
(void) new (&thiz->mAPlayer) android::sp<android::GenericPlayer>();
+ // Android-specific POD fields are initialized in android_audioPlayer_create,
+ // and assume calloc or memset 0 during allocation
#endif
// Check the source and sink parameters against generic constraints,
@@ -1087,8 +1089,6 @@
// More default values, in case destructor needs to be called early
thiz->mNumChannels = UNKNOWN_NUMCHANNELS;
- // (assume calloc or memset 0 during allocation)
- // placement new
#ifdef ANDROID
// placement new (explicit constructor)
// FIXME unnecessary once those fields are encapsulated in one class, rather
@@ -1096,6 +1096,8 @@
(void) new (&thiz->mAVPlayer) android::sp<android::GenericPlayer>();
(void) new (&thiz->mCallbackProtector)
android::sp<android::CallbackProtector>();
+ // Android-specific POD fields are initialized in android_Player_create,
+ // and assume calloc or memset 0 during allocation
#endif
// Check the source and sink parameters against generic constraints
diff --git a/src/itf/IPlay.c b/src/itf/IPlay.c
index 458ea30..8e44463 100644
--- a/src/itf/IPlay.c
+++ b/src/itf/IPlay.c
@@ -395,8 +395,9 @@
CAudioPlayer *audioPlayer = (CAudioPlayer *) thiz->mThis;
SLuint32 frameUpdatePeriod = ((long long) mSec *
(long long) audioPlayer->mSampleRateMilliHz) / 1000000LL;
- if (0 == frameUpdatePeriod)
+ if (0 == frameUpdatePeriod) {
frameUpdatePeriod = ~0;
+ }
thiz->mFrameUpdatePeriod = frameUpdatePeriod;
// setting a new update period postpones the next callback
thiz->mFramesSincePositionUpdate = 0;
diff --git a/src/itf/IVolume.c b/src/itf/IVolume.c
index 52f4da4..aaef4a9 100644
--- a/src/itf/IVolume.c
+++ b/src/itf/IVolume.c
@@ -32,8 +32,9 @@
if (oldLevel != level) {
thiz->mLevel = level;
interface_unlock_exclusive_attributes(thiz, ATTR_GAIN);
- } else
+ } else {
interface_unlock_exclusive(thiz);
+ }
result = SL_RESULT_SUCCESS;
}
@@ -86,8 +87,9 @@
if (oldMute != mute) {
thiz->mMute = (SLuint8) mute;
interface_unlock_exclusive_attributes(thiz, ATTR_GAIN);
- } else
+ } else {
interface_unlock_exclusive(thiz);
+ }
result = SL_RESULT_SUCCESS;
SL_LEAVE_INTERFACE
@@ -165,8 +167,9 @@
if (oldStereoPosition != stereoPosition) {
thiz->mStereoPosition = stereoPosition;
interface_unlock_exclusive_attributes(thiz, ATTR_GAIN);
- } else
+ } else {
interface_unlock_exclusive(thiz);
+ }
result = SL_RESULT_SUCCESS;
}
diff --git a/src/objects/CMediaPlayer.c b/src/objects/CMediaPlayer.c
index 7b995c5..f77720e 100644
--- a/src/objects/CMediaPlayer.c
+++ b/src/objects/CMediaPlayer.c
@@ -19,7 +19,6 @@
#include "sles_allinclusive.h"
#ifdef ANDROID
-#include <gui/SurfaceTextureClient.h>
#include "android/android_GenericMediaPlayer.h"
using namespace android;
#endif
diff --git a/src/sles.c b/src/sles.c
index 270d01a..5c4d3eb 100644
--- a/src/sles.c
+++ b/src/sles.c
@@ -58,8 +58,9 @@
const ClassTable *clazz = thiz->mClass;
assert(NULL != clazz);
SLuint32 id = clazz->mSLObjectID;
- if (!id)
+ if (!id) {
id = clazz->mXAObjectID;
+ }
return id;
}
diff --git a/src/sles_allinclusive.h b/src/sles_allinclusive.h
index 0b33dcb..a202242 100644
--- a/src/sles_allinclusive.h
+++ b/src/sles_allinclusive.h
@@ -442,7 +442,7 @@
// SLresult result = EnqueueAsyncCallback_ppi(ap, playCallback, &ap->mPlay.mItf, playContext,
// SL_PLAYEVENT_HEADATEND);
// if (SL_RESULT_SUCCESS != result) {
-// LOGW("Callback %p(%p, %p, SL_PLAYEVENT_HEADATEND) dropped", playCallback, &ap->mPlay.mItf,
+// ALOGW("Callback %p(%p, %p, SL_PLAYEVENT_HEADATEND) dropped", playCallback, &ap->mPlay.mItf,
// playContext);
// }
// which replaces:
diff --git a/tests/native-media/jni/native-media-jni.c b/tests/native-media/jni/native-media-jni.c
index e8db6f2..6d7ec28 100644
--- a/tests/native-media/jni/native-media-jni.c
+++ b/tests/native-media/jni/native-media-jni.c
@@ -248,7 +248,7 @@
XAVideoStreamInformation videoInfo;
res = (*caller)->QueryStreamInformation(caller, streamIndex, &videoInfo);
assert(XA_RESULT_SUCCESS == res);
- LOGI("Found video size %u x %u, codec ID=%u, frameRate=%u, bitRate=%u, duration=%u ms",
+ ALOGI("Found video size %u x %u, codec ID=%u, frameRate=%u, bitRate=%u, duration=%u ms",
videoInfo.width, videoInfo.height, videoInfo.codecId, videoInfo.frameRate,
videoInfo.bitRate, videoInfo.duration);
} break;
@@ -301,7 +301,7 @@
nbRead = fread(dataCache, BUFFER_SIZE, NB_BUFFERS, file);
if (nbRead <= 0) {
// could be premature EOF or I/O error
- LOGE("Error filling cache, exiting\n");
+ ALOGE("Error filling cache, exiting\n");
return JNI_FALSE;
}
assert(1 <= nbRead && nbRead <= NB_BUFFERS);
@@ -349,7 +349,7 @@
// open the file to play
file = fopen(utf8, "rb");
if (file == NULL) {
- LOGE("Failed to open %s", utf8);
+ ALOGE("Failed to open %s", utf8);
return JNI_FALSE;
}
diff --git a/tests/sandbox/nativewindow.cpp b/tests/sandbox/nativewindow.cpp
index 8fe7fb0..9f5b6ae 100644
--- a/tests/sandbox/nativewindow.cpp
+++ b/tests/sandbox/nativewindow.cpp
@@ -20,8 +20,8 @@
// that are not part of the NDK supported APIs, and are subject to change at any time.
#include <binder/ProcessState.h>
-#include <surfaceflinger/ISurfaceComposer.h>
-#include <surfaceflinger/SurfaceComposerClient.h>
+#include <gui/Surface.h>
+#include <gui/SurfaceComposerClient.h>
#include <utils/String8.h>
#include "nativewindow.h"
diff --git a/tests/sandbox/playbq.c b/tests/sandbox/playbq.c
index aaa72f1..c0f71a7 100644
--- a/tests/sandbox/playbq.c
+++ b/tests/sandbox/playbq.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include <SLES/OpenSLES.h>
@@ -30,6 +31,9 @@
#include <sndfile.h>
#endif
+#define max(a, b) ((a) > (b) ? (a) : (b))
+#define min(a, b) ((a) < (b) ? (a) : (b))
+
unsigned numBuffers = 2;
int framesPerBuffer = 512;
SNDFILE *sndfile;
@@ -114,14 +118,18 @@
byteOrder = nativeByteOrder;
SLboolean enableReverb = SL_BOOLEAN_FALSE;
- SLpermille rate = 1000;
+ SLpermille initialRate = 0;
+ SLpermille finalRate = 0;
+ SLpermille deltaRate = 1;
+ SLmillisecond deltaRateMs = 0;
// process command-line options
int i;
for (i = 1; i < argc; ++i) {
char *arg = argv[i];
- if (arg[0] != '-')
+ if (arg[0] != '-') {
break;
+ }
if (!strcmp(arg, "-b")) {
byteOrder = SL_BYTEORDER_BIGENDIAN;
} else if (!strcmp(arg, "-l")) {
@@ -133,7 +141,17 @@
} else if (!strncmp(arg, "-n", 2)) {
numBuffers = atoi(&arg[2]);
} else if (!strncmp(arg, "-p", 2)) {
- rate = atoi(&arg[2]);
+ initialRate = atoi(&arg[2]);
+ } else if (!strncmp(arg, "-P", 2)) {
+ finalRate = atoi(&arg[2]);
+ } else if (!strncmp(arg, "-q", 2)) {
+ deltaRate = atoi(&arg[2]);
+ // deltaRate is a magnitude, so take absolute value
+ if (deltaRate < 0) {
+ deltaRate = -deltaRate;
+ }
+ } else if (!strncmp(arg, "-Q", 2)) {
+ deltaRateMs = atoi(&arg[2]);
} else if (!strcmp(arg, "-r")) {
enableReverb = SL_BOOLEAN_TRUE;
} else {
@@ -143,6 +161,16 @@
if (argc - i != 1) {
fprintf(stderr, "usage: [-b/l] [-8] [-f#] [-n#] [-p#] [-r] %s filename\n", argv[0]);
+ fprintf(stderr, " -b force big-endian byte order (default is native byte order)\n");
+ fprintf(stderr, " -l force little-endian byte order (default is native byte order)\n");
+ fprintf(stderr, " -8 output 8-bits per sample (default is 16-bits per sample)\n");
+ fprintf(stderr, " -f# frames per buffer (default 512)\n");
+ fprintf(stderr, " -n# number of buffers (default 2)\n");
+ fprintf(stderr, " -p# initial playback rate in per mille (default 1000)\n");
+ fprintf(stderr, " -P# final playback rate in per mille (default same as -p#)\n");
+ fprintf(stderr, " -q# magnitude of playback rate changes in per mille (default 1)\n");
+ fprintf(stderr, " -Q# period between playback rate changes in ms (default 50)\n");
+ fprintf(stderr, " -r enable reverb (default disabled)\n");
return EXIT_FAILURE;
}
@@ -162,8 +190,9 @@
break;
default:
fprintf(stderr, "unsupported channel count %d\n", sfinfo.channels);
- break;
+ goto close_sndfile;
}
+
switch (sfinfo.samplerate) {
case 8000:
case 11025:
@@ -177,15 +206,17 @@
break;
default:
fprintf(stderr, "unsupported sample rate %d\n", sfinfo.samplerate);
- break;
+ goto close_sndfile;
}
+
switch (sfinfo.format & SF_FORMAT_TYPEMASK) {
case SF_FORMAT_WAV:
break;
default:
fprintf(stderr, "unsupported format type 0x%x\n", sfinfo.format & SF_FORMAT_TYPEMASK);
- break;
+ goto close_sndfile;
}
+
switch (sfinfo.format & SF_FORMAT_SUBMASK) {
case SF_FORMAT_PCM_16:
case SF_FORMAT_PCM_U8:
@@ -195,7 +226,7 @@
break;
default:
fprintf(stderr, "unsupported sub-format 0x%x\n", sfinfo.format & SF_FORMAT_SUBMASK);
- break;
+ goto close_sndfile;
}
buffers = (short *) malloc(framesPerBuffer * sfinfo.channels * sizeof(short) * numBuffers);
@@ -264,7 +295,10 @@
SLObjectItf playerObject;
result = (*engineEngine)->CreateAudioPlayer(engineEngine, &playerObject, &audioSrc,
&audioSnk, enableReverb ? 3 : 2, ids2, req2);
- assert(SL_RESULT_SUCCESS == result);
+ if (SL_RESULT_SUCCESS != result) {
+ fprintf(stderr, "can't create audio player\n");
+ goto no_player;
+ }
// realize the player
result = (*playerObject)->Realize(playerObject, SL_BOOLEAN_FALSE);
@@ -291,14 +325,29 @@
result = (*playerPlaybackRate)->GetProperties(playerPlaybackRate, &defaultProperties);
assert(SL_RESULT_SUCCESS == result);
printf("default playback rate %d per mille, properties 0x%x\n", defaultRate, defaultProperties);
- if (rate != defaultRate) {
- result = (*playerPlaybackRate)->SetRate(playerPlaybackRate, rate);
+ if (initialRate <= 0) {
+ initialRate = defaultRate;
+ }
+ if (finalRate <= 0) {
+ finalRate = initialRate;
+ }
+ SLpermille currentRate = defaultRate;
+ if (finalRate == initialRate) {
+ deltaRate = 0;
+ } else if (finalRate < initialRate) {
+ deltaRate = -deltaRate;
+ }
+ if (initialRate != defaultRate) {
+ result = (*playerPlaybackRate)->SetRate(playerPlaybackRate, initialRate);
if (SL_RESULT_FEATURE_UNSUPPORTED == result) {
- fprintf(stderr, "playback rate %d is unsupported\n", rate);
+ fprintf(stderr, "initial playback rate %d is unsupported\n", initialRate);
+ deltaRate = 0;
} else if (SL_RESULT_PARAMETER_INVALID == result) {
- fprintf(stderr, "playback rate %d is invalid", rate);
+ fprintf(stderr, "initial playback rate %d is invalid\n", initialRate);
+ deltaRate = 0;
} else {
assert(SL_RESULT_SUCCESS == result);
+ currentRate = initialRate;
}
}
@@ -336,8 +385,9 @@
result = (*playerBufferQueue)->Enqueue(playerBufferQueue, buffer, nbytes);
assert(SL_RESULT_SUCCESS == result);
}
- if (which >= numBuffers)
+ if (which >= numBuffers) {
which = 0;
+ }
// register a callback on the buffer queue
result = (*playerBufferQueue)->RegisterCallback(playerBufferQueue, callback, NULL);
@@ -347,6 +397,12 @@
result = (*playerPlay)->SetPlayState(playerPlay, SL_PLAYSTATE_PLAYING);
assert(SL_RESULT_SUCCESS == result);
+ // get the initial time
+ struct timespec prevTs;
+ clock_gettime(CLOCK_MONOTONIC, &prevTs);
+ long elapsedNs = 0;
+ long deltaRateNs = deltaRateMs * 1000000;
+
// wait until the buffer queue is empty
SLBufferQueueState bufqstate;
for (;;) {
@@ -355,17 +411,54 @@
if (0 >= bufqstate.count) {
break;
}
- sleep(1);
+ if (deltaRate == 0) {
+ sleep(1);
+ } else {
+ struct timespec curTs;
+ clock_gettime(CLOCK_MONOTONIC, &curTs);
+ elapsedNs += (curTs.tv_sec - prevTs.tv_sec) * 1000000000 +
+ // this term can be negative
+ (curTs.tv_nsec - prevTs.tv_nsec);
+ prevTs = curTs;
+ if (elapsedNs < deltaRateNs) {
+ usleep((deltaRateNs - elapsedNs) / 1000);
+ continue;
+ }
+ elapsedNs -= deltaRateNs;
+ SLpermille nextRate = currentRate + deltaRate;
+ result = (*playerPlaybackRate)->SetRate(playerPlaybackRate, nextRate);
+ if (SL_RESULT_SUCCESS != result) {
+ fprintf(stderr, "next playback rate %d is unsupported\n", nextRate);
+ } else if (SL_RESULT_PARAMETER_INVALID == result) {
+ fprintf(stderr, "next playback rate %d is invalid\n", nextRate);
+ } else {
+ assert(SL_RESULT_SUCCESS == result);
+ }
+ currentRate = nextRate;
+ if (currentRate >= max(initialRate, finalRate)) {
+ currentRate = max(initialRate, finalRate);
+ deltaRate = -abs(deltaRate);
+ } else if (currentRate <= min(initialRate, finalRate)) {
+ currentRate = min(initialRate, finalRate);
+ deltaRate = abs(deltaRate);
+ }
+ }
}
// destroy audio player
(*playerObject)->Destroy(playerObject);
+no_player:
+
// destroy output mix
(*outputMixObject)->Destroy(outputMixObject);
// destroy engine
(*engineObject)->Destroy(engineObject);
+close_sndfile:
+
+ (void) sf_close(sndfile);
+
return EXIT_SUCCESS;
}