Merge "Remove virtual from methods that don't need it"
diff --git a/src/android/AudioPlayer_to_android.cpp b/src/android/AudioPlayer_to_android.cpp
index 8f85e59..57db687 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
@@ -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) {
@@ -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 497bed2..0012fa9 100644
--- a/src/android/AudioRecorder_to_android.cpp
+++ b/src/android/AudioRecorder_to_android.cpp
@@ -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) {
diff --git a/src/android/MediaPlayer_to_android.cpp b/src/android/MediaPlayer_to_android.cpp
index 692aa5c..c204faf 100644
--- a/src/android/MediaPlayer_to_android.cpp
+++ b/src/android/MediaPlayer_to_android.cpp
@@ -142,7 +142,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 +172,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 +382,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 +393,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 +494,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/VideoCodec_to_android.cpp b/src/android/VideoCodec_to_android.cpp
index 20aad28..01c3af2 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..5908189 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);
diff --git a/src/android/android_GenericMediaPlayer.cpp b/src/android/android_GenericMediaPlayer.cpp
index f3cebf5..1931bb9 100644
--- a/src/android/android_GenericMediaPlayer.cpp
+++ b/src/android/android_GenericMediaPlayer.cpp
@@ -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..8ef66b2 100644
--- a/src/android/android_GenericMediaPlayer.h
+++ b/src/android/android_GenericMediaPlayer.h
@@ -120,7 +120,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/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/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 6c5a283..a43cb9e 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;
     }