Merge "audiohal: Wait for IAllocator to become available"
diff --git a/media/libaudiohal/DeviceHalHidl.cpp b/media/libaudiohal/DeviceHalHidl.cpp
index a6ced12..dcedfd3 100644
--- a/media/libaudiohal/DeviceHalHidl.cpp
+++ b/media/libaudiohal/DeviceHalHidl.cpp
@@ -50,6 +50,10 @@
 status_t deviceAddressFromHal(
         audio_devices_t device, const char* halAddress, DeviceAddress* address) {
     address->device = AudioDevice(device);
+
+    if (address == nullptr || strnlen(halAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0) {
+        return OK;
+    }
     const bool isInput = (device & AUDIO_DEVICE_BIT_IN) != 0;
     if (isInput) device &= ~AUDIO_DEVICE_BIT_IN;
     if ((!isInput && (device & AUDIO_DEVICE_OUT_ALL_A2DP) != 0)
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index 6c32433..d46ef3c 100755
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -2748,9 +2748,11 @@
             if (mLastDecodingTimeUs < 0) {
                 decodingTimeUs = std::max((int64_t)0, decodingTimeUs);
             } else {
-                // increase decoding time by at least 1 tick
-                decodingTimeUs = std::max(
-                        mLastDecodingTimeUs + divUp(1000000, mTimeScale), decodingTimeUs);
+                // increase decoding time by at least the larger vaule of 1 tick and
+                // 0.1 milliseconds. This needs to take into account the possible
+                // delta adjustment in DurationTicks in below.
+                decodingTimeUs = std::max(mLastDecodingTimeUs +
+                        std::max(100, divUp(1000000, mTimeScale)), decodingTimeUs);
             }
 
             mLastDecodingTimeUs = decodingTimeUs;
diff --git a/services/camera/libcameraservice/Android.mk b/services/camera/libcameraservice/Android.mk
index 5b4d10d..9328d65 100644
--- a/services/camera/libcameraservice/Android.mk
+++ b/services/camera/libcameraservice/Android.mk
@@ -90,12 +90,6 @@
 
 LOCAL_CFLAGS += -Wall -Wextra -Werror
 
-ifeq ($(ENABLE_TREBLE), true)
-
-  LOCAL_CFLAGS += -DENABLE_TREBLE
-
-endif # ENABLE_TREBLE
-
 LOCAL_MODULE:= libcameraservice
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index f439590..f708654 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -18,12 +18,6 @@
 #define ATRACE_TAG ATRACE_TAG_CAMERA
 //#define LOG_NDEBUG 0
 
-#ifdef ENABLE_TREBLE
-  #define USE_HIDL true
-#else
-  #define USE_HIDL false
-#endif
-
 #include <algorithm>
 #include <climits>
 #include <stdio.h>
@@ -197,10 +191,13 @@
     notifier.noteResetFlashlight();
 
     status_t res = INVALID_OPERATION;
-    if (USE_HIDL) {
-        res = enumerateProviders();
-    } else {
+
+    bool disableTreble = property_get_bool("camera.disable_treble", false);
+    if (disableTreble) {
+        ALOGI("Treble disabled - using legacy path");
         res = loadLegacyHalModule();
+    } else {
+        res = enumerateProviders();
     }
     if (res == OK) {
         mInitialized = true;