Merge "Don't ask policy manager about invalid stream type"
diff --git a/cmds/stagefright/codec.cpp b/cmds/stagefright/codec.cpp
index fbf800c..0414b98 100644
--- a/cmds/stagefright/codec.cpp
+++ b/cmds/stagefright/codec.cpp
@@ -35,7 +35,8 @@
 static void usage(const char *me) {
     fprintf(stderr, "usage: %s [-a] use audio\n"
                     "\t\t[-v] use video\n"
-                    "\t\t[-p] playback\n", me);
+                    "\t\t[-p] playback\n"
+                    "\t\t[-S] allocate buffers from a surface\n", me);
 
     exit(1);
 }
@@ -49,6 +50,9 @@
     Vector<sp<ABuffer> > mInBuffers;
     Vector<sp<ABuffer> > mOutBuffers;
     bool mSawOutputEOS;
+    int64_t mNumBuffersDecoded;
+    int64_t mNumBytesDecoded;
+    bool mIsAudio;
 };
 
 }  // namespace android
@@ -57,9 +61,12 @@
         const android::sp<android::ALooper> &looper,
         const char *path,
         bool useAudio,
-        bool useVideo) {
+        bool useVideo,
+        const android::sp<android::Surface> &surface) {
     using namespace android;
 
+    static int64_t kTimeout = 500ll;
+
     sp<NuMediaExtractor> extractor = new NuMediaExtractor;
     if (extractor->setDataSource(path) != OK) {
         fprintf(stderr, "unable to instantiate extractor.\n");
@@ -78,11 +85,12 @@
         AString mime;
         CHECK(format->findString("mime", &mime));
 
-        if (useAudio && !haveAudio
-                && !strncasecmp(mime.c_str(), "audio/", 6)) {
+        bool isAudio = !strncasecmp(mime.c_str(), "audio/", 6);
+        bool isVideo = !strncasecmp(mime.c_str(), "video/", 6);
+
+        if (useAudio && !haveAudio && isAudio) {
             haveAudio = true;
-        } else if (useVideo && !haveVideo
-                && !strncasecmp(mime.c_str(), "video/", 6)) {
+        } else if (useVideo && !haveVideo && isVideo) {
             haveVideo = true;
         } else {
             continue;
@@ -96,13 +104,17 @@
         CodecState *state =
             &stateByTrack.editValueAt(stateByTrack.add(i, CodecState()));
 
+        state->mNumBytesDecoded = 0;
+        state->mNumBuffersDecoded = 0;
+        state->mIsAudio = isAudio;
+
         state->mCodec = MediaCodec::CreateByType(
                 looper, mime.c_str(), false /* encoder */);
 
         CHECK(state->mCodec != NULL);
 
         err = state->mCodec->configure(
-                format, NULL /* surfaceTexture */, 0 /* flags */);
+                format, isVideo ? surface : NULL, 0 /* flags */);
 
         CHECK_EQ(err, (status_t)OK);
 
@@ -122,6 +134,8 @@
 
     CHECK(!stateByTrack.isEmpty());
 
+    int64_t startTimeUs = ALooper::GetNowUs();
+
     for (size_t i = 0; i < stateByTrack.size(); ++i) {
         CodecState *state = &stateByTrack.editValueAt(i);
 
@@ -137,13 +151,7 @@
 
         while (state->mCSDIndex < state->mCSD.size()) {
             size_t index;
-            status_t err = codec->dequeueInputBuffer(&index);
-
-            if (err == -EAGAIN) {
-                usleep(10000);
-                continue;
-            }
-
+            status_t err = codec->dequeueInputBuffer(&index, -1ll);
             CHECK_EQ(err, (status_t)OK);
 
             const sp<ABuffer> &srcBuffer =
@@ -179,7 +187,7 @@
 
                     for (;;) {
                         size_t index;
-                        err = state->mCodec->dequeueInputBuffer(&index);
+                        err = state->mCodec->dequeueInputBuffer(&index, kTimeout);
 
                         if (err == -EAGAIN) {
                             continue;
@@ -204,7 +212,7 @@
                 CodecState *state = &stateByTrack.editValueFor(trackIndex);
 
                 size_t index;
-                err = state->mCodec->dequeueInputBuffer(&index);
+                err = state->mCodec->dequeueInputBuffer(&index, kTimeout);
 
                 if (err == OK) {
                     ALOGV("filling input buffer %d", index);
@@ -261,12 +269,15 @@
             uint32_t flags;
             status_t err = state->mCodec->dequeueOutputBuffer(
                     &index, &offset, &size, &presentationTimeUs, &flags,
-                    10000ll);
+                    kTimeout);
 
             if (err == OK) {
                 ALOGV("draining output buffer %d, time = %lld us",
                       index, presentationTimeUs);
 
+                ++state->mNumBuffersDecoded;
+                state->mNumBytesDecoded += size;
+
                 err = state->mCodec->releaseOutputBuffer(index);
                 CHECK_EQ(err, (status_t)OK);
 
@@ -292,10 +303,27 @@
         }
     }
 
+    int64_t elapsedTimeUs = ALooper::GetNowUs() - startTimeUs;
+
     for (size_t i = 0; i < stateByTrack.size(); ++i) {
         CodecState *state = &stateByTrack.editValueAt(i);
 
         CHECK_EQ((status_t)OK, state->mCodec->release());
+
+        if (state->mIsAudio) {
+            printf("track %d: %lld bytes received. %.2f KB/sec\n",
+                   i,
+                   state->mNumBytesDecoded,
+                   state->mNumBytesDecoded * 1E6 / 1024 / elapsedTimeUs);
+        } else {
+            printf("track %d: %lld frames decoded, %.2f fps. %lld bytes "
+                   "received. %.2f KB/sec\n",
+                   i,
+                   state->mNumBuffersDecoded,
+                   state->mNumBuffersDecoded * 1E6 / elapsedTimeUs,
+                   state->mNumBytesDecoded,
+                   state->mNumBytesDecoded * 1E6 / 1024 / elapsedTimeUs);
+        }
     }
 
     return 0;
@@ -309,9 +337,10 @@
     bool useAudio = false;
     bool useVideo = false;
     bool playback = false;
+    bool useSurface = false;
 
     int res;
-    while ((res = getopt(argc, argv, "havp")) >= 0) {
+    while ((res = getopt(argc, argv, "havpS")) >= 0) {
         switch (res) {
             case 'a':
             {
@@ -331,6 +360,12 @@
                 break;
             }
 
+            case 'S':
+            {
+                useSurface = true;
+                break;
+            }
+
             case '?':
             case 'h':
             default:
@@ -358,8 +393,12 @@
     sp<ALooper> looper = new ALooper;
     looper->start();
 
-    if (playback) {
-        sp<SurfaceComposerClient> composerClient = new SurfaceComposerClient;
+    sp<SurfaceComposerClient> composerClient;
+    sp<SurfaceControl> control;
+    sp<Surface> surface;
+
+    if (playback || (useSurface && useVideo)) {
+        composerClient = new SurfaceComposerClient;
         CHECK_EQ(composerClient->initCheck(), (status_t)OK);
 
         ssize_t displayWidth = composerClient->getDisplayWidth(0);
@@ -367,14 +406,13 @@
 
         ALOGV("display is %ld x %ld\n", displayWidth, displayHeight);
 
-        sp<SurfaceControl> control =
-            composerClient->createSurface(
-                    String8("A Surface"),
-                    0,
-                    displayWidth,
-                    displayHeight,
-                    PIXEL_FORMAT_RGB_565,
-                    0);
+        control = composerClient->createSurface(
+                String8("A Surface"),
+                0,
+                displayWidth,
+                displayHeight,
+                PIXEL_FORMAT_RGB_565,
+                0);
 
         CHECK(control != NULL);
         CHECK(control->isValid());
@@ -384,9 +422,11 @@
         CHECK_EQ(control->show(), (status_t)OK);
         SurfaceComposerClient::closeGlobalTransaction();
 
-        sp<Surface> surface = control->getSurface();
+        surface = control->getSurface();
         CHECK(surface != NULL);
+    }
 
+    if (playback) {
         sp<SimplePlayer> player = new SimplePlayer;
         looper->registerHandler(player);
 
@@ -396,10 +436,12 @@
         sleep(60);
         player->stop();
         player->reset();
-
-        composerClient->dispose();
     } else {
-        decode(looper, argv[0], useAudio, useVideo);
+        decode(looper, argv[0], useAudio, useVideo, surface);
+    }
+
+    if (playback || (useSurface && useVideo)) {
+        composerClient->dispose();
     }
 
     looper->stop();
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index d54ab35..cc0a594 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -185,7 +185,7 @@
                                          audio_devices_t device);
 
     static uint32_t getStrategyForStream(audio_stream_type_t stream);
-    static uint32_t getDevicesForStream(audio_stream_type_t stream);
+    static audio_devices_t getDevicesForStream(audio_stream_type_t stream);
 
     static audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc);
     static status_t registerEffect(effect_descriptor_t *desc,
diff --git a/include/media/IAudioPolicyService.h b/include/media/IAudioPolicyService.h
index bdd7747..04c927a 100644
--- a/include/media/IAudioPolicyService.h
+++ b/include/media/IAudioPolicyService.h
@@ -79,7 +79,7 @@
                                           int *index,
                                           audio_devices_t device) = 0;
     virtual uint32_t getStrategyForStream(audio_stream_type_t stream) = 0;
-    virtual uint32_t getDevicesForStream(audio_stream_type_t stream) = 0;
+    virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream) = 0;
     virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc) = 0;
     virtual status_t registerEffect(effect_descriptor_t *desc,
                                     audio_io_handle_t io,
diff --git a/include/private/binder/Static.h b/include/private/binder/Static.h
deleted file mode 100644
index 5b0f9fc..0000000
--- a/include/private/binder/Static.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-// All static variables go here, to control initialization and
-// destruction order in the library.
-
-#include <utils/threads.h>
-
-#include <binder/IBinder.h>
-#include <binder/IMemory.h>
-#include <binder/ProcessState.h>
-#include <binder/IPermissionController.h>
-#include <binder/IServiceManager.h>
-
-namespace android {
-
-// For ProcessState.cpp
-extern Mutex gProcessMutex;
-extern sp<ProcessState> gProcess;
-
-// For ServiceManager.cpp
-extern Mutex gDefaultServiceManagerLock;
-extern sp<IServiceManager> gDefaultServiceManager;
-extern sp<IPermissionController> gPermissionController;
-
-}   // namespace android
diff --git a/include/private/binder/binder_module.h b/include/private/binder/binder_module.h
deleted file mode 100644
index a8dd64f..0000000
--- a/include/private/binder/binder_module.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-#ifndef _BINDER_MODULE_H_
-#define _BINDER_MODULE_H_
-
-#ifdef __cplusplus
-namespace android {
-#endif
-
-/* obtain structures and constants from the kernel header */
-
-#include <sys/ioctl.h>
-#include <linux/binder.h>
-
-#ifdef __cplusplus
-}   // namespace android
-#endif
-
-#endif // _BINDER_MODULE_H_
diff --git a/include/private/gui/ComposerService.h b/include/private/gui/ComposerService.h
deleted file mode 100644
index d04491a..0000000
--- a/include/private/gui/ComposerService.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2011 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.
- */
-
-#ifndef ANDROID_PRIVATE_GUI_COMPOSER_SERVICE_H
-#define ANDROID_PRIVATE_GUI_COMPOSER_SERVICE_H
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <utils/Singleton.h>
-#include <utils/StrongPointer.h>
-
-
-namespace android {
-
-// ---------------------------------------------------------------------------
-
-class IMemoryHeap;
-class ISurfaceComposer;
-class surface_flinger_cblk_t;
-
-// ---------------------------------------------------------------------------
-
-class ComposerService : public Singleton<ComposerService>
-{
-    // these are constants
-    sp<ISurfaceComposer> mComposerService;
-    sp<IMemoryHeap> mServerCblkMemory;
-    surface_flinger_cblk_t volatile* mServerCblk;
-    ComposerService();
-    friend class Singleton<ComposerService>;
-public:
-    static sp<ISurfaceComposer> getComposerService();
-    static surface_flinger_cblk_t const volatile * getControlBlock();
-};
-
-// ---------------------------------------------------------------------------
-}; // namespace android
-
-#endif // ANDROID_PRIVATE_GUI_COMPOSER_SERVICE_H
diff --git a/include/private/gui/LayerState.h b/include/private/gui/LayerState.h
deleted file mode 100644
index ca277e0..0000000
--- a/include/private/gui/LayerState.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-#ifndef ANDROID_SF_LAYER_STATE_H
-#define ANDROID_SF_LAYER_STATE_H
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <utils/Errors.h>
-
-#include <ui/Region.h>
-#include <gui/ISurface.h>
-
-namespace android {
-
-class Parcel;
-class ISurfaceComposerClient;
-
-struct layer_state_t {
-
-    layer_state_t()
-        :   surface(0), what(0),
-            x(0), y(0), z(0), w(0), h(0),
-            alpha(0), tint(0), flags(0), mask(0),
-            reserved(0)
-    {
-        matrix.dsdx = matrix.dtdy = 1.0f;
-        matrix.dsdy = matrix.dtdx = 0.0f;
-    }
-
-    status_t    write(Parcel& output) const;
-    status_t    read(const Parcel& input);
-
-            struct matrix22_t {
-                float   dsdx;
-                float   dtdx;
-                float   dsdy;
-                float   dtdy;
-            };
-            SurfaceID       surface;
-            uint32_t        what;
-            float           x;
-            float           y;
-            uint32_t        z;
-            uint32_t        w;
-            uint32_t        h;
-            float           alpha;
-            uint32_t        tint;
-            uint8_t         flags;
-            uint8_t         mask;
-            uint8_t         reserved;
-            matrix22_t      matrix;
-            // non POD must be last. see write/read
-            Region          transparentRegion;
-};
-
-struct ComposerState {
-    sp<ISurfaceComposerClient> client;
-    layer_state_t state;
-    status_t    write(Parcel& output) const;
-    status_t    read(const Parcel& input);
-};
-
-}; // namespace android
-
-#endif // ANDROID_SF_LAYER_STATE_H
-
diff --git a/include/private/gui/SharedBufferStack.h b/include/private/gui/SharedBufferStack.h
deleted file mode 100644
index 0da03d1..0000000
--- a/include/private/gui/SharedBufferStack.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2007 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.
- */
-
-#ifndef ANDROID_SF_SHARED_BUFFER_STACK_H
-#define ANDROID_SF_SHARED_BUFFER_STACK_H
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <utils/Debug.h>
-
-namespace android {
-// ---------------------------------------------------------------------------
-
-#define NUM_DISPLAY_MAX 4
-
-struct display_cblk_t
-{
-    uint16_t    w;
-    uint16_t    h;
-    uint8_t     format;
-    uint8_t     orientation;
-    uint8_t     reserved[2];
-    float       fps;
-    float       density;
-    float       xdpi;
-    float       ydpi;
-    uint32_t    pad[2];
-};
-
-struct surface_flinger_cblk_t   // 4KB max
-{
-    uint8_t         connected;
-    uint8_t         reserved[3];
-    uint32_t        pad[7];
-    display_cblk_t  displays[NUM_DISPLAY_MAX];
-};
-
-// ---------------------------------------------------------------------------
-
-COMPILE_TIME_ASSERT(sizeof(surface_flinger_cblk_t) <= 4096)
-
-// ---------------------------------------------------------------------------
-}; // namespace android
-
-#endif /* ANDROID_SF_SHARED_BUFFER_STACK_H */
diff --git a/include/private/ui/RegionHelper.h b/include/private/ui/RegionHelper.h
deleted file mode 100644
index 8d76533..0000000
--- a/include/private/ui/RegionHelper.h
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef ANDROID_UI_PRIVATE_REGION_HELPER_H
-#define ANDROID_UI_PRIVATE_REGION_HELPER_H
-
-#include <stdint.h>
-#include <sys/types.h>
-
-namespace android {
-// ----------------------------------------------------------------------------
-
-template<typename RECT>
-class region_operator
-{
-    typedef typename RECT::value_type TYPE;    
-    static const TYPE max_value = 0x7FFFFFF;
-
-public:
-    /* 
-     * Common boolean operations:
-     * value is computed as 0b101 op 0b110
-     *    other boolean operation are possible, simply compute
-     *    their corresponding value with the above formulae and use
-     *    it when instantiating a region_operator.
-     */
-    static const uint32_t LHS = 0x5;  // 0b101
-    static const uint32_t RHS = 0x6;  // 0b110
-    enum {
-        op_nand = LHS & ~RHS,
-        op_and  = LHS &  RHS,
-        op_or   = LHS |  RHS,
-        op_xor  = LHS ^  RHS
-    };
-
-    struct region {
-        RECT const* rects;
-        size_t count;
-        TYPE dx;
-        TYPE dy;
-        inline region(const region& rhs) 
-            : rects(rhs.rects), count(rhs.count), dx(rhs.dx), dy(rhs.dy) { }
-        inline region(RECT const* r, size_t c) 
-            : rects(r), count(c), dx(), dy() { }
-        inline region(RECT const* r, size_t c, TYPE dx, TYPE dy) 
-            : rects(r), count(c), dx(dx), dy(dy) { }
-    };
-
-    class region_rasterizer {
-        friend class region_operator;
-        virtual void operator()(const RECT& rect) = 0;
-    public:
-        virtual ~region_rasterizer() { };
-    };
-    
-    inline region_operator(int op, const region& lhs, const region& rhs) 
-        : op_mask(op), spanner(lhs, rhs) 
-    {
-    }
-
-    void operator()(region_rasterizer& rasterizer) {
-        RECT current;
-        do {
-            SpannerInner spannerInner(spanner.lhs, spanner.rhs);
-            int inside = spanner.next(current.top, current.bottom);
-            spannerInner.prepare(inside);
-            do {
-                TYPE left, right;
-                int inside = spannerInner.next(current.left, current.right);
-                if ((op_mask >> inside) & 1) {
-                    if (current.left < current.right && 
-                            current.top < current.bottom) {
-                        rasterizer(current);
-                    }
-                }
-            } while(!spannerInner.isDone());
-        } while(!spanner.isDone());
-    }
-
-private:    
-    uint32_t op_mask;
-
-    class SpannerBase
-    {
-    public:
-        enum {
-            lhs_before_rhs   = 0,
-            lhs_after_rhs    = 1,
-            lhs_coincide_rhs = 2
-        };
-
-    protected:
-        TYPE lhs_head;
-        TYPE lhs_tail;
-        TYPE rhs_head;
-        TYPE rhs_tail;
-
-        inline int next(TYPE& head, TYPE& tail,
-                bool& more_lhs, bool& more_rhs) 
-        {
-            int inside;
-            more_lhs = false;
-            more_rhs = false;
-            if (lhs_head < rhs_head) {
-                inside = lhs_before_rhs;
-                head = lhs_head;
-                if (lhs_tail <= rhs_head) {
-                    tail = lhs_tail;
-                    more_lhs = true;
-                } else {
-                    lhs_head = rhs_head;
-                    tail = rhs_head;
-                }
-            } else if (rhs_head < lhs_head) {
-                inside = lhs_after_rhs;
-                head = rhs_head;
-                if (rhs_tail <= lhs_head) {
-                    tail = rhs_tail;
-                    more_rhs = true;
-                } else {
-                    rhs_head = lhs_head;
-                    tail = lhs_head;
-                }
-            } else {
-                inside = lhs_coincide_rhs;
-                head = lhs_head;
-                if (lhs_tail <= rhs_tail) {
-                    tail = rhs_head = lhs_tail;
-                    more_lhs = true;
-                }
-                if (rhs_tail <= lhs_tail) {
-                    tail = lhs_head = rhs_tail;
-                    more_rhs = true;
-                }
-            }
-            return inside;
-        }
-    };
-
-    class Spanner : protected SpannerBase 
-    {
-        friend class region_operator;
-        region lhs;
-        region rhs;
-
-    public:
-        inline Spanner(const region& lhs, const region& rhs)
-            : lhs(lhs), rhs(rhs) 
-        {
-            SpannerBase::lhs_head = lhs.rects->top      + lhs.dy;
-            SpannerBase::lhs_tail = lhs.rects->bottom   + lhs.dy;
-            SpannerBase::rhs_head = rhs.rects->top      + rhs.dy;
-            SpannerBase::rhs_tail = rhs.rects->bottom   + rhs.dy;
-        }
-
-        inline bool isDone() const {
-            return !rhs.count && !lhs.count;
-        }
-
-        inline int next(TYPE& top, TYPE& bottom) 
-        {
-            bool more_lhs = false;
-            bool more_rhs = false;
-            int inside = SpannerBase::next(top, bottom, more_lhs, more_rhs);
-            if (more_lhs) {
-                advance(lhs, SpannerBase::lhs_head, SpannerBase::lhs_tail);
-            }
-            if (more_rhs) {
-                advance(rhs, SpannerBase::rhs_head, SpannerBase::rhs_tail);
-            }
-            return inside;
-        }
-
-    private:
-        static inline 
-        void advance(region& reg, TYPE& aTop, TYPE& aBottom) {
-            // got to next span
-            size_t count = reg.count;
-            RECT const * rects = reg.rects;
-            RECT const * const end = rects + count;
-            const int top = rects->top;
-            while (rects != end && rects->top == top) {
-                rects++;
-                count--;
-            }
-            if (rects != end) {
-                aTop    = rects->top    + reg.dy;
-                aBottom = rects->bottom + reg.dy;
-            } else {
-                aTop    = max_value;
-                aBottom = max_value;
-            }
-            reg.rects = rects;
-            reg.count = count;
-        }
-    };
-
-    class SpannerInner : protected SpannerBase 
-    {
-        region lhs;
-        region rhs;
-        
-    public:
-        inline SpannerInner(const region& lhs, const region& rhs)
-            : lhs(lhs), rhs(rhs) 
-        {
-        }
-
-        inline void prepare(int inside) {
-            if (inside == SpannerBase::lhs_before_rhs) {
-                SpannerBase::lhs_head = lhs.rects->left  + lhs.dx;
-                SpannerBase::lhs_tail = lhs.rects->right + lhs.dx;
-                SpannerBase::rhs_head = max_value;
-                SpannerBase::rhs_tail = max_value;
-            } else if (inside == SpannerBase::lhs_after_rhs) {
-                SpannerBase::lhs_head = max_value;
-                SpannerBase::lhs_tail = max_value;
-                SpannerBase::rhs_head = rhs.rects->left  + rhs.dx;
-                SpannerBase::rhs_tail = rhs.rects->right + rhs.dx;
-            } else {
-                SpannerBase::lhs_head = lhs.rects->left  + lhs.dx;
-                SpannerBase::lhs_tail = lhs.rects->right + lhs.dx;
-                SpannerBase::rhs_head = rhs.rects->left  + rhs.dx;
-                SpannerBase::rhs_tail = rhs.rects->right + rhs.dx;
-            }
-        }
-
-        inline bool isDone() const {
-            return SpannerBase::lhs_head == max_value && 
-                   SpannerBase::rhs_head == max_value;
-        }
-
-        inline int next(TYPE& left, TYPE& right) 
-        {
-            bool more_lhs = false;
-            bool more_rhs = false;
-            int inside = SpannerBase::next(left, right, more_lhs, more_rhs);
-            if (more_lhs) {
-                advance(lhs, SpannerBase::lhs_head, SpannerBase::lhs_tail);
-            }
-            if (more_rhs) {
-                advance(rhs, SpannerBase::rhs_head, SpannerBase::rhs_tail);
-            }
-            return inside;
-        }
-
-    private:
-        static inline 
-        void advance(region& reg, TYPE& left, TYPE& right) {
-            if (reg.rects && reg.count) {
-                const int cur_span_top = reg.rects->top;
-                reg.rects++;
-                reg.count--;
-                if (!reg.count || reg.rects->top != cur_span_top) {
-                    left  = max_value;
-                    right = max_value;
-                } else {
-                    left  = reg.rects->left  + reg.dx;
-                    right = reg.rects->right + reg.dx;
-                }
-            }
-        }
-    };
-
-    Spanner spanner;
-};
-
-// ----------------------------------------------------------------------------
-};
-
-#endif /* ANDROID_UI_PRIVATE_REGION_HELPER_H */
diff --git a/include/private/utils/Static.h b/include/private/utils/Static.h
deleted file mode 100644
index d95ae0d..0000000
--- a/include/private/utils/Static.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-// All static variables go here, to control initialization and
-// destruction order in the library.
-
-#include <utils/threads.h>
-#include <utils/KeyedVector.h>
-
-namespace android {
-// For TextStream.cpp
-extern Vector<int32_t> gTextBuffers;
-
-// For String8.cpp
-extern void initialize_string8();
-extern void terminate_string8();
-
-// For String16.cpp
-extern void initialize_string16();
-extern void terminate_string16();
-
-}   // namespace android
diff --git a/media/libmedia/AudioSystem.cpp b/media/libmedia/AudioSystem.cpp
index e0b186a..a1cbf0f 100644
--- a/media/libmedia/AudioSystem.cpp
+++ b/media/libmedia/AudioSystem.cpp
@@ -701,10 +701,10 @@
     return aps->getStrategyForStream(stream);
 }
 
-uint32_t AudioSystem::getDevicesForStream(audio_stream_type_t stream)
+audio_devices_t AudioSystem::getDevicesForStream(audio_stream_type_t stream)
 {
     const sp<IAudioPolicyService>& aps = AudioSystem::get_audio_policy_service();
-    if (aps == 0) return 0;
+    if (aps == 0) return (audio_devices_t)0;
     return aps->getDevicesForStream(stream);
 }
 
diff --git a/media/libmedia/IAudioPolicyService.cpp b/media/libmedia/IAudioPolicyService.cpp
index 99385aa..da7c124 100644
--- a/media/libmedia/IAudioPolicyService.cpp
+++ b/media/libmedia/IAudioPolicyService.cpp
@@ -267,13 +267,13 @@
         return reply.readInt32();
     }
 
-    virtual uint32_t getDevicesForStream(audio_stream_type_t stream)
+    virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream)
     {
         Parcel data, reply;
         data.writeInterfaceToken(IAudioPolicyService::getInterfaceDescriptor());
         data.writeInt32(static_cast <uint32_t>(stream));
         remote()->transact(GET_DEVICES_FOR_STREAM, data, &reply);
-        return (uint32_t) reply.readInt32();
+        return (audio_devices_t) reply.readInt32();
     }
 
     virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc)
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index b21e86a..9e00bb3 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -2108,6 +2108,8 @@
 
         mWVMExtractor = new WVMExtractor(dataSource);
         mWVMExtractor->setAdaptiveStreamingMode(true);
+        if (mUIDValid)
+            mWVMExtractor->setUID(mUID);
         extractor = mWVMExtractor;
     } else {
         extractor = MediaExtractor::Create(
diff --git a/media/libstagefright/WVMExtractor.cpp b/media/libstagefright/WVMExtractor.cpp
index c7ad513..dac8106 100644
--- a/media/libstagefright/WVMExtractor.cpp
+++ b/media/libstagefright/WVMExtractor.cpp
@@ -123,6 +123,12 @@
     }
 }
 
+void WVMExtractor::setUID(uid_t uid) {
+    if (mImpl != NULL) {
+        mImpl->setUID(uid);
+    }
+}
+
 bool SniffWVM(
     const sp<DataSource> &source, String8 *mimeType, float *confidence,
         sp<AMessage> *) {
diff --git a/media/libstagefright/codecs/m4v_h263/dec/src/vop.cpp b/media/libstagefright/codecs/m4v_h263/dec/src/vop.cpp
index 74fe478..b3c350f 100644
--- a/media/libstagefright/codecs/m4v_h263/dec/src/vop.cpp
+++ b/media/libstagefright/codecs/m4v_h263/dec/src/vop.cpp
@@ -1041,7 +1041,7 @@
     /* Marker Bit */
     if (!BitstreamRead1Bits(stream))
     {
-        mp4dec_log("DecodeShortHeader(): Market bit wrong.\n");
+        mp4dec_log("DecodeShortHeader(): Marker bit wrong.\n");
         status = PV_FAIL;
         goto return_point;
     }
diff --git a/media/libstagefright/include/WVMExtractor.h b/media/libstagefright/include/WVMExtractor.h
index 9f763f9..3c3ca89 100644
--- a/media/libstagefright/include/WVMExtractor.h
+++ b/media/libstagefright/include/WVMExtractor.h
@@ -34,6 +34,7 @@
 
     virtual int64_t getCachedDurationUs(status_t *finalStatus) = 0;
     virtual void setAdaptiveStreamingMode(bool adaptive) = 0;
+    virtual void setUID(uid_t uid) = 0;
 };
 
 class WVMExtractor : public MediaExtractor {
@@ -60,6 +61,8 @@
     // is used.
     void setAdaptiveStreamingMode(bool adaptive);
 
+    void setUID(uid_t uid);
+
     static bool getVendorLibHandle();
 
 protected:
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index ae868fb..f9b033b 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -1462,7 +1462,9 @@
         // Assumes constructor is called by AudioFlinger with it's mLock held,
         // but it would be safer to explicitly pass initial masterVolume as parameter
         mMasterVolume(audioFlinger->masterVolumeSW_l()),
-        mLastWriteTime(0), mNumWrites(0), mNumDelayedWrites(0), mInWrite(false)
+        mLastWriteTime(0), mNumWrites(0), mNumDelayedWrites(0), mInWrite(false),
+        // mMixerStatus
+        mPrevMixerStatus(MIXER_IDLE)
 {
     snprintf(mName, kNameLength, "AudioOut_%X", id);
 
@@ -1922,7 +1924,6 @@
     :   PlaybackThread(audioFlinger, output, id, device, type)
 {
     mAudioMixer = new AudioMixer(mFrameCount, mSampleRate);
-    mPrevMixerStatus = MIXER_IDLE;
     // FIXME - Current mixer implementation only supports stereo output
     if (mChannelCount == 1) {
         ALOGE("Invalid audio hardware channel count");
@@ -2043,11 +2044,7 @@
 
         processConfigEvents();
 
-if (mType == DIRECT) {
-        activeTrack.clear();
-}
-
-        mixerStatus = MIXER_IDLE;
+        mMixerStatus = MIXER_IDLE;
         { // scope for mLock
 
             Mutex::Autolock _l(mLock);
@@ -2102,9 +2099,7 @@
                     ALOGV("Thread %p type %d TID %d waking up", this, mType, gettid());
                     acquireWakeLock_l();
 
-if (mType == MIXER || mType == DUPLICATING) {
                     mPrevMixerStatus = MIXER_IDLE;
-}
 
                     checkSilentMode_l();
 
@@ -2126,11 +2121,11 @@
                 }
             }
 
-            mixerStatus = prepareTracks_l(&tracksToRemove);
-            // see FIXME in AudioFlinger.h
-            if (mixerStatus == MIXER_CONTINUE) {
-                continue;
-            }
+            mixer_state newMixerStatus = prepareTracks_l(&tracksToRemove);
+            // Shift in the new status; this could be a queue if it's
+            // useful to filter the mixer status over several cycles.
+            mPrevMixerStatus = mMixerStatus;
+            mMixerStatus = newMixerStatus;
 
             // prevent any changes in effect chain list and in each effect chain
             // during mixing and effect process as the audio buffers could be deleted
@@ -2138,11 +2133,7 @@
             lockEffectChains_l(effectChains);
         }
 
-if (mType == DIRECT) {
-        // For DirectOutputThread, this test is equivalent to "activeTrack != 0"
-}
-
-        if (CC_LIKELY(mixerStatus == MIXER_TRACKS_READY)) {
+        if (CC_LIKELY(mMixerStatus == MIXER_TRACKS_READY)) {
             threadLoop_mix();
         } else {
             threadLoop_sleepTime();
@@ -2196,10 +2187,6 @@
         // same lock.
         tracksToRemove.clear();
 
-// FIXME merge these
-if (mType == DIRECT) {
-        activeTrack.clear();
-}
         // FIXME I don't understand the need for this here;
         //       it was in the original code but maybe the
         //       assignment in saveOutputTracks() makes this unnecessary?
@@ -2283,7 +2270,7 @@
     // If no tracks are ready, sleep once for the duration of an output
     // buffer size, then write 0s to the output
     if (sleepTime == 0) {
-        if (mixerStatus == MIXER_TRACKS_ENABLED) {
+        if (mMixerStatus == MIXER_TRACKS_ENABLED) {
             sleepTime = activeSleepTime >> sleepTimeShift;
             if (sleepTime < kMinThreadSleepTimeUs) {
                 sleepTime = kMinThreadSleepTimeUs;
@@ -2299,10 +2286,10 @@
             sleepTime = idleSleepTime;
         }
     } else if (mBytesWritten != 0 ||
-               (mixerStatus == MIXER_TRACKS_ENABLED && longStandbyExit)) {
+               (mMixerStatus == MIXER_TRACKS_ENABLED && longStandbyExit)) {
         memset (mMixBuffer, 0, mixBufferSize);
         sleepTime = 0;
-        ALOGV_IF((mBytesWritten == 0 && (mixerStatus == MIXER_TRACKS_ENABLED && longStandbyExit)), "anticipated start");
+        ALOGV_IF((mBytesWritten == 0 && (mMixerStatus == MIXER_TRACKS_ENABLED && longStandbyExit)), "anticipated start");
     }
     // TODO add standby time extension fct of effect tail
 }
@@ -2558,7 +2545,6 @@
         memset(mMixBuffer, 0, mFrameCount * mChannelCount * sizeof(int16_t));
     }
 
-    mPrevMixerStatus = mixerStatus;
     return mixerStatus;
 }
 
@@ -2825,15 +2811,13 @@
 {
     sp<Track> trackToRemove;
 
-    // FIXME Temporarily renamed to avoid confusion with the member "mixerStatus"
-    mixer_state mixerStatus_ = MIXER_IDLE;
+    mixer_state mixerStatus = MIXER_IDLE;
 
     // find out which tracks need to be processed
     if (mActiveTracks.size() != 0) {
         sp<Track> t = mActiveTracks[0].promote();
-        // see FIXME in AudioFlinger.h, return MIXER_IDLE might also work
-        if (t == 0) return MIXER_CONTINUE;
-        //if (t == 0) continue;
+        // The track died recently
+        if (t == 0) return MIXER_IDLE;
 
         Track* const track = t.get();
         audio_track_cblk_t* cblk = track->cblk();
@@ -2918,8 +2902,8 @@
 
             // reset retry count
             track->mRetryCount = kMaxTrackRetriesDirect;
-            activeTrack = t;
-            mixerStatus_ = MIXER_TRACKS_READY;
+            mActiveTrack = t;
+            mixerStatus = MIXER_TRACKS_READY;
         } else {
             //ALOGV("track %d u=%08x, s=%08x [NOT READY]", track->name(), cblk->user, cblk->server);
             if (track->isStopped()) {
@@ -2936,7 +2920,7 @@
                     ALOGV("BUFFER TIMEOUT: remove(%d) from active list", track->name());
                     trackToRemove = track;
                 } else {
-                    mixerStatus_ = MIXER_TRACKS_ENABLED;
+                    mixerStatus = MIXER_TRACKS_ENABLED;
                 }
             }
         }
@@ -2957,7 +2941,7 @@
         }
     }
 
-    return mixerStatus_;
+    return mixerStatus;
 }
 
 void AudioFlinger::DirectOutputThread::threadLoop_mix()
@@ -2968,7 +2952,7 @@
     // output audio to hardware
     while (frameCount) {
         buffer.frameCount = frameCount;
-        activeTrack->getNextBuffer(&buffer);
+        mActiveTrack->getNextBuffer(&buffer);
         if (CC_UNLIKELY(buffer.raw == NULL)) {
             memset(curBuf, 0, frameCount * mFrameSize);
             break;
@@ -2976,17 +2960,18 @@
         memcpy(curBuf, buffer.raw, buffer.frameCount * mFrameSize);
         frameCount -= buffer.frameCount;
         curBuf += buffer.frameCount * mFrameSize;
-        activeTrack->releaseBuffer(&buffer);
+        mActiveTrack->releaseBuffer(&buffer);
     }
     sleepTime = 0;
     standbyTime = systemTime() + standbyDelay;
+    mActiveTrack.clear();
     applyVolume();
 }
 
 void AudioFlinger::DirectOutputThread::threadLoop_sleepTime()
 {
     if (sleepTime == 0) {
-        if (mixerStatus == MIXER_TRACKS_ENABLED) {
+        if (mMixerStatus == MIXER_TRACKS_ENABLED) {
             sleepTime = activeSleepTime;
         } else {
             sleepTime = idleSleepTime;
@@ -3122,7 +3107,7 @@
 void AudioFlinger::DuplicatingThread::threadLoop_sleepTime()
 {
     if (sleepTime == 0) {
-        if (mixerStatus == MIXER_TRACKS_ENABLED) {
+        if (mMixerStatus == MIXER_TRACKS_ENABLED) {
             sleepTime = activeSleepTime;
         } else {
             sleepTime = idleSleepTime;
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index e26466f..2e259c0 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -607,10 +607,6 @@
             MIXER_TRACKS_READY      // at least one active track, and at least one track has data
             // standby mode does not have an enum value
             // suspend by audio policy manager is orthogonal to mixer state
-#if 1
-            // FIXME remove this hack for prepareTracks_l()
-            , MIXER_CONTINUE        // "continue;"
-#endif
         };
 
         // playback track
@@ -962,19 +958,17 @@
         uint32_t                        activeSleepTime;
         uint32_t                        idleSleepTime;
         uint32_t                        sleepTime;
-        // mixerStatus was local to the while !exitingPending loop
-        mixer_state                     mixerStatus;
+
+        // mixer status returned by prepareTracks_l()
+        mixer_state                     mMixerStatus;       // current cycle
+        mixer_state                     mPrevMixerStatus;   // previous cycle
 
         // FIXME move these declarations into the specific sub-class that needs them
         // MIXER only
         bool                            longStandbyExit;
         uint32_t                        sleepTimeShift;
-        // MIXER and DUPLICATING only
-        mixer_state mPrevMixerStatus; // previous status returned by prepareTracks_l()
         // DIRECT only
         nsecs_t                         standbyDelay;
-        // activeTrack was local to the while !exitingPending loop
-        sp<Track>                       activeTrack;
         // DUPLICATING only
         uint32_t                        writeFrames;
     };
@@ -1046,6 +1040,9 @@
 
 private:
                     void        applyVolume();  // FIXME inline into threadLoop_mix()
+
+        // prepareTracks_l() tells threadLoop_mix() the name of the single active track
+        sp<Track>               mActiveTrack;
     };
 
     class DuplicatingThread : public MixerThread {
diff --git a/services/audioflinger/AudioPolicyService.cpp b/services/audioflinger/AudioPolicyService.cpp
index 753b1d2..d57326b 100644
--- a/services/audioflinger/AudioPolicyService.cpp
+++ b/services/audioflinger/AudioPolicyService.cpp
@@ -298,8 +298,7 @@
     ssize_t idx = mInputs.indexOfKey(input);
     InputDesc *inputDesc;
     if (idx < 0) {
-        inputDesc = new InputDesc();
-        inputDesc->mSessionId = audioSession;
+        inputDesc = new InputDesc(audioSession);
         mInputs.add(input, inputDesc);
     } else {
         inputDesc = mInputs.valueAt(idx);
@@ -358,7 +357,6 @@
     }
     InputDesc *inputDesc = mInputs.valueAt(index);
     setPreProcessorEnabled(inputDesc, false);
-    inputDesc->mEffects.clear();
     delete inputDesc;
     mInputs.removeItemsAt(index);
 }
@@ -432,10 +430,12 @@
     return mpAudioPolicy->get_strategy_for_stream(mpAudioPolicy, stream);
 }
 
-uint32_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream)
+//audio policy: use audio_device_t appropriately
+
+audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream)
 {
     if (mpAudioPolicy == NULL) {
-        return 0;
+        return (audio_devices_t)0;
     }
     return mpAudioPolicy->get_devices_for_stream(mpAudioPolicy, stream);
 }
@@ -600,9 +600,9 @@
     return NO_ERROR;
 }
 
-void AudioPolicyService::setPreProcessorEnabled(InputDesc *inputDesc, bool enabled)
+void AudioPolicyService::setPreProcessorEnabled(const InputDesc *inputDesc, bool enabled)
 {
-    Vector<sp<AudioEffect> > fxVector = inputDesc->mEffects;
+    const Vector<sp<AudioEffect> > &fxVector = inputDesc->mEffects;
     for (size_t i = 0; i < fxVector.size(); i++) {
         fxVector.itemAt(i)->setEnabled(enabled);
     }
diff --git a/services/audioflinger/AudioPolicyService.h b/services/audioflinger/AudioPolicyService.h
index 962c917..7119b90 100644
--- a/services/audioflinger/AudioPolicyService.h
+++ b/services/audioflinger/AudioPolicyService.h
@@ -95,7 +95,7 @@
                                           audio_devices_t device);
 
     virtual uint32_t getStrategyForStream(audio_stream_type_t stream);
-    virtual uint32_t getDevicesForStream(audio_stream_type_t stream);
+    virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream);
 
     virtual audio_io_handle_t getOutputForEffect(effect_descriptor_t *desc);
     virtual status_t registerEffect(effect_descriptor_t *desc,
@@ -279,15 +279,15 @@
 
     class InputDesc {
     public:
-        InputDesc() {}
-        virtual ~InputDesc() {}
-        int mSessionId;
+        InputDesc(int session) : mSessionId(session) {}
+        /*virtual*/ ~InputDesc() {}
+        const int mSessionId;
         Vector< sp<AudioEffect> >mEffects;
     };
 
     static const char * const kInputSourceNames[AUDIO_SOURCE_CNT -1];
 
-    void setPreProcessorEnabled(InputDesc *inputDesc, bool enabled);
+    void setPreProcessorEnabled(const InputDesc *inputDesc, bool enabled);
     status_t loadPreProcessorConfig(const char *path);
     status_t loadEffects(cnode *root, Vector <EffectDesc *>& effects);
     EffectDesc *loadEffect(cnode *root);