Code drop from //branches/cupcake/...@124589
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h
index 008569f..71744be 100644
--- a/include/media/AudioRecord.h
+++ b/include/media/AudioRecord.h
@@ -37,16 +37,29 @@
 
 class AudioRecord
 {
-public: 
-    
+public:
+
     enum stream_type {
         DEFAULT_INPUT   =-1,
         MIC_INPUT       = 0,
         NUM_STREAM_TYPES
     };
-    
-    static const int DEFAULT_SAMPLE_RATE = 8000; 
-    
+
+    static const int DEFAULT_SAMPLE_RATE = 8000;
+
+    /* Events used by AudioRecord callback function (callback_t).
+     * 
+     * to keep in sync with frameworks/base/media/java/android/media/AudioRecord.java
+     */
+    enum event_type {
+        EVENT_MORE_DATA = 0,        // Request to reqd more data from PCM buffer.
+        EVENT_OVERRUN = 1,          // PCM buffer overrun occured.
+        EVENT_MARKER = 2,           // Record head is at the specified marker position
+                                    // (See setMarkerPosition()).
+        EVENT_NEW_POS = 3,          // Record head is at a new position 
+                                    // (See setPositionUpdatePeriod()).
+    };
+
     /* Create Buffer on the stack and pass it to obtainBuffer()
      * and releaseBuffer().
      */
@@ -75,71 +88,108 @@
 
 //    static status_t setMasterMute(bool mute);
 
-    /* Returns AudioFlinger's frame count. AudioRecord's buffers will
-     * be created with this size.
-     */
-    static  size_t      frameCount();
-
     /* As a convenience, if a callback is supplied, a handler thread
      * is automatically created with the appropriate priority. This thread
-     * invokes the callback when a new buffer becomes availlable.
+     * invokes the callback when a new buffer becomes ready or an overrun condition occurs.
+     * Parameters:
+     *
+     * event:   type of event notified (see enum AudioRecord::event_type).
+     * user:    Pointer to context for use by the callback receiver.
+     * info:    Pointer to optional parameter according to event type:
+     *          - EVENT_MORE_DATA: pointer to AudioRecord::Buffer struct. The callback must not read
+     *          more bytes than indicated by 'size' field and update 'size' if less bytes are
+     *          read.
+     *          - EVENT_OVERRUN: unused.
+     *          - EVENT_MARKER: pointer to an uin32_t containing the marker position in frames.
+     *          - EVENT_NEW_POS: pointer to an uin32_t containing the new position in frames.
      */
-    typedef bool (*callback_t)(void* user, const Buffer& info);
+
+    typedef void (*callback_t)(int event, void* user, void *info);
 
     /* Constructs an uninitialized AudioRecord. No connection with
      * AudioFlinger takes place.
      */
                         AudioRecord();
-                        
+
     /* Creates an AudioRecord track and registers it with AudioFlinger.
      * Once created, the track needs to be started before it can be used.
      * Unspecified values are set to the audio hardware's current
      * values.
+     *
+     * Parameters:
+     *
+     * streamType:         Select the audio input to record to (e.g. AudioRecord::MIC_INPUT).
+     * sampleRate:         Track sampling rate in Hz.
+     * format:             PCM sample format (e.g AudioSystem::PCM_16_BIT for signed
+     *                     16 bits per sample).
+     * channelCount:       Number of PCM channels (e.g 2 for stereo).
+     * frameCount:         Total size of track PCM buffer in frames. This defines the
+     *                     latency of the track.
+     * flags:              Reserved for future use.
+     * cbf:                Callback function. If not null, this function is called periodically
+     *                     to provide new PCM data.
+     * notificationFrames: The callback function is called each time notificationFrames PCM
+     *                     frames are ready in record track output buffer.
+     * user                Context for use by the callback receiver.
      */
-     
-                        AudioRecord(int streamType      = 0,
+
+                        AudioRecord(int streamType,
                                     uint32_t sampleRate = 0,
                                     int format          = 0,
                                     int channelCount    = 0,
-                                    int bufferCount     = 0,
+                                    int frameCount      = 0,
                                     uint32_t flags      = 0,
-                                    callback_t cbf = 0, void* user = 0);
+                                    callback_t cbf = 0,
+                                    void* user = 0,
+                                    int notificationFrames = 0);
 
 
     /* Terminates the AudioRecord and unregisters it from AudioFlinger.
      * Also destroys all resources assotiated with the AudioRecord.
-     */ 
+     */
                         ~AudioRecord();
 
 
-    /* Initialize an uninitialized AudioRecord. */
+    /* Initialize an uninitialized AudioRecord.
+     * Returned status (from utils/Errors.h) can be:
+     *  - NO_ERROR: successful intialization
+     *  - INVALID_OPERATION: AudioRecord is already intitialized or record device is already in use
+     *  - BAD_VALUE: invalid parameter (channelCount, format, sampleRate...)
+     *  - NO_INIT: audio server or audio hardware not initialized
+     *  - PERMISSION_DENIED: recording is not allowed for the requesting process
+     * */
             status_t    set(int streamType      = 0,
                             uint32_t sampleRate = 0,
                             int format          = 0,
                             int channelCount    = 0,
-                            int bufferCount     = 0,
+                            int frameCount      = 0,
                             uint32_t flags      = 0,
-                            callback_t cbf = 0, void* user = 0);
-        
+                            callback_t cbf = 0,
+                            void* user = 0,
+                            int notificationFrames = 0,
+                            bool threadCanCallJava = false);
+
 
     /* Result of constructing the AudioRecord. This must be checked
      * before using any AudioRecord API (except for set()), using
-     * an uninitialized AudioRecord prduces undefined results.
+     * an uninitialized AudioRecord produces undefined results.
+     * See set() method above for possible return codes.
      */
             status_t    initCheck() const;
 
-    /* Returns this track's latency in nanoseconds or framecount.
-     * This only includes the latency due to the fill buffer size.
-     * In particular, the hardware or driver latencies are not accounted.
+    /* Returns this track's latency in milliseconds.
+     * This includes the latency due to AudioRecord buffer size
+     * and audio hardware driver.
      */
-            nsecs_t     latency() const;
+            uint32_t     latency() const;
 
-   /* getters, see constructor */ 
-            
+   /* getters, see constructor */
+
             uint32_t    sampleRate() const;
             int         format() const;
             int         channelCount() const;
-            int         bufferCount() const;
+            uint32_t    frameCount() const;
+            int         frameSize() const;
 
 
     /* After it's created the track is not active. Call start() to
@@ -158,27 +208,79 @@
      */
             uint32_t    getSampleRate();
 
+    /* Sets marker position. When record reaches the number of frames specified,
+     * a callback with event type EVENT_MARKER is called. Calling setMarkerPosition
+     * with marker == 0 cancels marker notification callback. 
+     * If the AudioRecord has been opened with no callback function associated, 
+     * the operation will fail.
+     *
+     * Parameters:
+     *
+     * marker:   marker position expressed in frames.
+     *
+     * Returned status (from utils/Errors.h) can be:
+     *  - NO_ERROR: successful operation
+     *  - INVALID_OPERATION: the AudioRecord has no callback installed.
+     */
+            status_t    setMarkerPosition(uint32_t marker);
+            status_t    getMarkerPosition(uint32_t *marker);
+
+
+    /* Sets position update period. Every time the number of frames specified has been recorded, 
+     * a callback with event type EVENT_NEW_POS is called. 
+     * Calling setPositionUpdatePeriod with updatePeriod == 0 cancels new position notification 
+     * callback. 
+     * If the AudioRecord has been opened with no callback function associated,
+     * the operation will fail.
+     *
+     * Parameters:
+     *
+     * updatePeriod:  position update notification period expressed in frames.
+     *
+     * Returned status (from utils/Errors.h) can be:
+     *  - NO_ERROR: successful operation
+     *  - INVALID_OPERATION: the AudioRecord has no callback installed.
+     */
+            status_t    setPositionUpdatePeriod(uint32_t updatePeriod);
+            status_t    getPositionUpdatePeriod(uint32_t *updatePeriod);
+
+
+    /* Gets record head position. The position is the  total number of frames 
+     * recorded since record start. 
+     *
+     * Parameters:
+     *
+     *  position:  Address where to return record head position within AudioRecord buffer.
+     *
+     * Returned status (from utils/Errors.h) can be:
+     *  - NO_ERROR: successful operation
+     *  - BAD_VALUE:  position is NULL
+     */
+            status_t    getPosition(uint32_t *position);
+
+            
+            
     /* obtains a buffer of "frameCount" frames. The buffer must be
      * filled entirely. If the track is stopped, obtainBuffer() returns
      * STOPPED instead of NO_ERROR as long as there are buffers availlable,
      * at which point NO_MORE_BUFFERS is returned.
      * Buffers will be returned until the pool (buffercount())
-     * is exhausted, at which point obtainBuffer() will either block 
+     * is exhausted, at which point obtainBuffer() will either block
      * or return WOULD_BLOCK depending on the value of the "blocking"
-     * parameter. 
+     * parameter.
      */
-     
+
         enum {
             NO_MORE_BUFFERS = 0x80000001,
             STOPPED = 1
         };
-     
+
             status_t    obtainBuffer(Buffer* audioBuffer, bool blocking);
             void        releaseBuffer(Buffer* audioBuffer);
 
 
     /* As a convenience we provide a read() interface to the audio buffer.
-     * This is implemented on top of lockBuffer/unlockBuffer. 
+     * This is implemented on top of lockBuffer/unlockBuffer.
      */
             ssize_t     read(void* buffer, size_t size);
 
@@ -191,15 +293,16 @@
     class ClientRecordThread : public Thread
     {
     public:
-        ClientRecordThread(AudioRecord& receiver);
+        ClientRecordThread(AudioRecord& receiver, bool bCanCallJava = false);
     private:
         friend class AudioRecord;
         virtual bool        threadLoop();
         virtual status_t    readyToRun() { return NO_ERROR; }
         virtual void        onFirstRef() {}
         AudioRecord& mReceiver;
+        Mutex       mLock;
     };
-    
+
             bool processAudioBuffer(const sp<ClientRecordThread>& thread);
 
     sp<IAudioFlinger>       mAudioFlinger;
@@ -207,27 +310,26 @@
     sp<IMemory>             mCblkMemory;
     sp<ClientRecordThread>  mClientRecordThread;
     Mutex                   mRecordThreadLock;
-    
+
     uint32_t                mSampleRate;
-    size_t                  mFrameCount;
+    uint32_t                mFrameCount;
 
     audio_track_cblk_t*     mCblk;
     uint8_t                 mFormat;
-    uint8_t                 mBufferCount;
-    uint8_t                 mChannelCount   : 4;
-    uint8_t                 mReserved       : 3;
+    uint8_t                 mChannelCount;
+    uint8_t                 mReserved[2];
     status_t                mStatus;
-    nsecs_t                 mLatency;
+    uint32_t                mLatency;
 
     volatile int32_t        mActive;
 
     callback_t              mCbf;
     void*                   mUserData;
-    
-    AudioRecord::Buffer      mAudioBuffer;
-    size_t                  mPosition;
-
-    uint32_t                mReservedFBC[4];
+    uint32_t                mNotificationFrames;
+    uint32_t                mRemainingFrames;
+    uint32_t                mMarkerPosition;
+    uint32_t                mNewPosition;
+    uint32_t                mUpdatePeriod;
 };
 
 }; // namespace android
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index 9fcbea5..77676bf 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -48,9 +48,10 @@
     enum audio_routes {
         ROUTE_EARPIECE       = (1 << 0),
         ROUTE_SPEAKER        = (1 << 1),
-        ROUTE_BLUETOOTH      = (1 << 2),
+        ROUTE_BLUETOOTH_SCO  = (1 << 2),
         ROUTE_HEADSET        = (1 << 3),
-        ROUTE_ALL       = (ROUTE_EARPIECE | ROUTE_SPEAKER | ROUTE_BLUETOOTH | ROUTE_HEADSET)
+        ROUTE_BLUETOOTH_A2DP = (1 << 4),
+        ROUTE_ALL       = 0xFFFFFFFF
     };
 
     /* These are static methods to control the system-wide AudioFlinger
@@ -95,6 +96,10 @@
     static float linearToLog(int volume);
     static int logToLinear(float volume);
 
+    static status_t getOutputSamplingRate(int* samplingRate);
+    static status_t getOutputFrameCount(int* frameCount);
+    static status_t getOutputLatency(uint32_t* latency);
+
     // ----------------------------------------------------------------------------
 
 private:
@@ -115,6 +120,9 @@
     static Mutex gLock;
     static sp<IAudioFlinger> gAudioFlinger;
     static audio_error_callback gAudioErrorCallback;
+    static int gOutSamplingRate;
+    static int gOutFrameCount;
+    static uint32_t gOutLatency;
 };
 
 };  // namespace android
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
index a89d7ff..f382451 100644
--- a/include/media/AudioTrack.h
+++ b/include/media/AudioTrack.h
@@ -41,15 +41,16 @@
 
 class AudioTrack
 {
-public: 
+public:
 
     enum stream_type {
-        DEFAULT     =-1,
-        VOICE_CALL  = 0,
-        SYSTEM      = 1,
-        RING        = 2,
-        MUSIC       = 3,
-        ALARM       = 4,
+        DEFAULT         =-1,
+        VOICE_CALL      = 0,
+        SYSTEM          = 1,
+        RING            = 2,
+        MUSIC           = 3,
+        ALARM           = 4,
+        NOTIFICATION    = 5,
         NUM_STREAM_TYPES
     };
 
@@ -59,6 +60,17 @@
         RIGHT  = 1
     };
 
+    /* Events used by AudioTrack callback function (audio_track_cblk_t).
+     */
+    enum event_type {
+        EVENT_MORE_DATA = 0,        // Request to write more data to PCM buffer.
+        EVENT_UNDERRUN = 1,         // PCM buffer underrun occured.
+        EVENT_LOOP_END = 2,         // Sample loop end was reached; playback restarted from loop start if loop count was not 0.
+        EVENT_MARKER = 3,           // Playback head is at the specified marker position (See setMarkerPosition()).
+        EVENT_NEW_POS = 4,          // Playback head is at a new position (See setPositionUpdatePeriod()).
+        EVENT_BUFFER_END = 5        // Playback head is at the end of the buffer.
+    };
+
     /* Create Buffer on the stack and pass it to obtainBuffer()
      * and releaseBuffer().
      */
@@ -81,72 +93,132 @@
         };
     };
 
-    /* Returns AudioFlinger's frame count. AudioTrack's buffers will
-     * be created with this size.
-     */
-    static  size_t      frameCount();
 
     /* As a convenience, if a callback is supplied, a handler thread
      * is automatically created with the appropriate priority. This thread
-     * invokes the callback when a new buffer becomes availlable.
+     * invokes the callback when a new buffer becomes availlable or an underrun condition occurs.
+     * Parameters:
+     *
+     * event:   type of event notified (see enum AudioTrack::event_type).
+     * user:    Pointer to context for use by the callback receiver.
+     * info:    Pointer to optional parameter according to event type:
+     *          - EVENT_MORE_DATA: pointer to AudioTrack::Buffer struct. The callback must not write
+     *          more bytes than indicated by 'size' field and update 'size' if less bytes are
+     *          written.
+     *          - EVENT_UNDERRUN: unused.
+     *          - EVENT_LOOP_END: pointer to an int indicating the number of loops remaining.
+     *          - EVENT_MARKER: pointer to an uin32_t containing the marker position in frames.
+     *          - EVENT_NEW_POS: pointer to an uin32_t containing the new position in frames.
+     *          - EVENT_BUFFER_END: unused.
      */
-    typedef void (*callback_t)(void* user, const Buffer& info);
+
+    typedef void (*callback_t)(int event, void* user, void *info);
 
     /* Constructs an uninitialized AudioTrack. No connection with
      * AudioFlinger takes place.
      */
                         AudioTrack();
-                        
+
     /* Creates an audio track and registers it with AudioFlinger.
      * Once created, the track needs to be started before it can be used.
      * Unspecified values are set to the audio hardware's current
      * values.
+     *
+     * Parameters:
+     *
+     * streamType:         Select the type of audio stream this track is attached to
+     *                     (e.g. AudioTrack::MUSIC).
+     * sampleRate:         Track sampling rate in Hz.
+     * format:             PCM sample format (e.g AudioSystem::PCM_16_BIT for signed
+     *                     16 bits per sample).
+     * channelCount:       Number of PCM channels (e.g 2 for stereo).
+     * frameCount:         Total size of track PCM buffer in frames. This defines the
+     *                     latency of the track.
+     * flags:              Reserved for future use.
+     * cbf:                Callback function. If not null, this function is called periodically
+     *                     to request new PCM data.
+     * notificationFrames: The callback function is called each time notificationFrames PCM
+     *                     frames have been comsumed from track input buffer.
+     * user                Context for use by the callback receiver.
      */
-     
+
+                        AudioTrack( int streamType,
+                                    uint32_t sampleRate  = 0,
+                                    int format           = 0,
+                                    int channelCount     = 0,
+                                    int frameCount       = 0,
+                                    uint32_t flags       = 0,
+                                    callback_t cbf       = 0,
+                                    void* user           = 0,
+                                    int notificationFrames = 0);
+
+    /* Creates an audio track and registers it with AudioFlinger. With this constructor,
+     * The PCM data to be rendered by AudioTrack is passed in a shared memory buffer
+     * identified by the argument sharedBuffer. This prototype is for static buffer playback.
+     * PCM data must be present into memory before the AudioTrack is started.
+     * The Write() and Flush() methods are not supported in this case.
+     * It is recommented to pass a callback function to be notified of playback end by an
+     * EVENT_UNDERRUN event.
+     */
+
                         AudioTrack( int streamType,
                                     uint32_t sampleRate = 0,
                                     int format          = 0,
                                     int channelCount    = 0,
-                                    int bufferCount     = 0,
+                                    const sp<IMemory>& sharedBuffer = 0,
                                     uint32_t flags      = 0,
-                                    callback_t cbf = 0, void* user = 0);
-
+                                    callback_t cbf      = 0,
+                                    void* user          = 0,
+                                    int notificationFrames = 0);
 
     /* Terminates the AudioTrack and unregisters it from AudioFlinger.
      * Also destroys all resources assotiated with the AudioTrack.
-     */ 
+     */
                         ~AudioTrack();
 
 
-    /* Initialize an uninitialized AudioTrack. */
+    /* Initialize an uninitialized AudioTrack.
+     * Returned status (from utils/Errors.h) can be:
+     *  - NO_ERROR: successful intialization
+     *  - INVALID_OPERATION: AudioTrack is already intitialized
+     *  - BAD_VALUE: invalid parameter (channelCount, format, sampleRate...)
+     *  - NO_INIT: audio server or audio hardware not initialized
+     * */
             status_t    set(int streamType      =-1,
                             uint32_t sampleRate = 0,
                             int format          = 0,
                             int channelCount    = 0,
-                            int bufferCount     = 0,
+                            int frameCount      = 0,
                             uint32_t flags      = 0,
-                            callback_t cbf = 0, void* user = 0);
-        
+                            callback_t cbf      = 0,
+                            void* user          = 0,
+                            int notificationFrames = 0,
+                            const sp<IMemory>& sharedBuffer = 0,
+                            bool threadCanCallJava = false);
+
 
     /* Result of constructing the AudioTrack. This must be checked
      * before using any AudioTrack API (except for set()), using
-     * an uninitialized AudoiTrack prduces undefined results.
+     * an uninitialized AudioTrack produces undefined results.
+     * See set() method above for possible return codes.
      */
             status_t    initCheck() const;
 
-    /* Returns this track's latency in nanoseconds or framecount.
-     * This only includes the latency due to the fill buffer size.
-     * In particular, the hardware or driver latencies are not accounted.
+    /* Returns this track's latency in milliseconds.
+     * This includes the latency due to AudioTrack buffer size, AudioMixer (if any)
+     * and audio hardware driver.
      */
-            nsecs_t     latency() const;
+            uint32_t     latency() const;
 
-   /* getters, see constructor */ 
-            
+    /* getters, see constructor */
+
             int         streamType() const;
             uint32_t    sampleRate() const;
             int         format() const;
             int         channelCount() const;
-            int         bufferCount() const;
+            uint32_t    frameCount() const;
+            int         frameSize() const;
+            sp<IMemory>& sharedBuffer();
 
 
     /* After it's created the track is not active. Call start() to
@@ -189,21 +261,103 @@
             void        setSampleRate(int sampleRate);
             uint32_t    getSampleRate();
 
+    /* Enables looping and sets the start and end points of looping.
+     *
+     * Parameters:
+     *
+     * loopStart:   loop start expressed as the number of PCM frames played since AudioTrack start.
+     * loopEnd:     loop end expressed as the number of PCM frames played since AudioTrack start.
+     * loopCount:   number of loops to execute. Calling setLoop() with loopCount == 0 cancels any pending or
+     *          active loop. loopCount = -1 means infinite looping.
+     *
+     * For proper operation the following condition must be respected:
+     *          (loopEnd-loopStart) <= framecount()
+     */
+            status_t    setLoop(uint32_t loopStart, uint32_t loopEnd, int loopCount);
+            status_t    getLoop(uint32_t *loopStart, uint32_t *loopEnd, int *loopCount);
+
+
+    /* Sets marker position. When playback reaches the number of frames specified, a callback with event 
+     * type EVENT_MARKER is called. Calling setMarkerPosition with marker == 0 cancels marker notification 
+     * callback. 
+     * If the AudioTrack has been opened with no callback function associated, the operation will fail.
+     *
+     * Parameters:
+     *
+     * marker:   marker position expressed in frames.
+     *
+     * Returned status (from utils/Errors.h) can be:
+     *  - NO_ERROR: successful operation
+     *  - INVALID_OPERATION: the AudioTrack has no callback installed.
+     */
+            status_t    setMarkerPosition(uint32_t marker);
+            status_t    getMarkerPosition(uint32_t *marker);
+
+
+    /* Sets position update period. Every time the number of frames specified has been played, 
+     * a callback with event type EVENT_NEW_POS is called. 
+     * Calling setPositionUpdatePeriod with updatePeriod == 0 cancels new position notification 
+     * callback. 
+     * If the AudioTrack has been opened with no callback function associated, the operation will fail.
+     *
+     * Parameters:
+     *
+     * updatePeriod:  position update notification period expressed in frames.
+     *
+     * Returned status (from utils/Errors.h) can be:
+     *  - NO_ERROR: successful operation
+     *  - INVALID_OPERATION: the AudioTrack has no callback installed.
+     */
+            status_t    setPositionUpdatePeriod(uint32_t updatePeriod);
+            status_t    getPositionUpdatePeriod(uint32_t *updatePeriod);
+
+
+    /* Sets playback head position within AudioTrack buffer. The new position is specified
+     * in number of frames. 
+     * This method must be called with the AudioTrack in paused or stopped state.
+     * Note that the actual position set is <position> modulo the AudioTrack buffer size in frames. 
+     * Therefore using this method makes sense only when playing a "static" audio buffer 
+     * as opposed to streaming.
+     * The getPosition() method on the other hand returns the total number of frames played since
+     * playback start.
+     *
+     * Parameters:
+     *
+     * position:  New playback head position within AudioTrack buffer.
+     *
+     * Returned status (from utils/Errors.h) can be:
+     *  - NO_ERROR: successful operation
+     *  - INVALID_OPERATION: the AudioTrack is not stopped.
+     *  - BAD_VALUE: The specified position is beyond the number of frames present in AudioTrack buffer 
+     */
+            status_t    setPosition(uint32_t position);
+            status_t    getPosition(uint32_t *position);
+
+    /* Forces AudioTrack buffer full condition. When playing a static buffer, this method avoids 
+     * rewriting the buffer before restarting playback after a stop.
+     * This method must be called with the AudioTrack in paused or stopped state.
+     *
+     * Returned status (from utils/Errors.h) can be:
+     *  - NO_ERROR: successful operation
+     *  - INVALID_OPERATION: the AudioTrack is not stopped.
+     */
+            status_t    reload();
+
     /* obtains a buffer of "frameCount" frames. The buffer must be
      * filled entirely. If the track is stopped, obtainBuffer() returns
      * STOPPED instead of NO_ERROR as long as there are buffers availlable,
      * at which point NO_MORE_BUFFERS is returned.
      * Buffers will be returned until the pool (buffercount())
-     * is exhausted, at which point obtainBuffer() will either block 
+     * is exhausted, at which point obtainBuffer() will either block
      * or return WOULD_BLOCK depending on the value of the "blocking"
-     * parameter. 
+     * parameter.
      */
-     
+
         enum {
             NO_MORE_BUFFERS = 0x80000001,
             STOPPED = 1
         };
-     
+
             status_t    obtainBuffer(Buffer* audioBuffer, bool blocking);
             void        releaseBuffer(Buffer* audioBuffer);
 
@@ -211,10 +365,10 @@
     /* As a convenience we provide a write() interface to the audio buffer.
      * This is implemented on top of lockBuffer/unlockBuffer. For best
      * performance
-     * 
+     *
      */
             ssize_t     write(const void* buffer, size_t size);
-            
+
     /*
      * Dumps the state of an audio track.
      */
@@ -229,7 +383,7 @@
     class AudioTrackThread : public Thread
     {
     public:
-        AudioTrackThread(AudioTrack& receiver);
+        AudioTrackThread(AudioTrack& receiver, bool bCanCallJava = false);
     private:
         friend class AudioTrack;
         virtual bool        threadLoop();
@@ -238,37 +392,37 @@
         AudioTrack& mReceiver;
         Mutex       mLock;
     };
-    
+
             bool processAudioBuffer(const sp<AudioTrackThread>& thread);
 
     sp<IAudioFlinger>       mAudioFlinger;
     sp<IAudioTrack>         mAudioTrack;
     sp<IMemory>             mCblkMemory;
     sp<AudioTrackThread>    mAudioTrackThread;
-    
+
     float                   mVolume[2];
     uint32_t                mSampleRate;
-    size_t                  mFrameCount;
+    uint32_t                mFrameCount;
 
     audio_track_cblk_t*     mCblk;
     uint8_t                 mStreamType;
     uint8_t                 mFormat;
-    uint8_t                 mBufferCount;
-    uint8_t                 mChannelCount   : 4;
-    uint8_t                 mMuted          : 1;
-    uint8_t                 mReserved       : 2;
+    uint8_t                 mChannelCount;
+    uint8_t                 mMuted;
     status_t                mStatus;
-    nsecs_t                 mLatency;
+    uint32_t                mLatency;
 
     volatile int32_t        mActive;
 
     callback_t              mCbf;
     void*                   mUserData;
-    
-    AudioTrack::Buffer      mAudioBuffer;
-    size_t                  mPosition;
-
-    uint32_t                mReservedFBC[4];
+    uint32_t                mNotificationFrames;
+    sp<IMemory>             mSharedBuffer;
+    int                     mLoopCount;
+    uint32_t                mRemainingFrames;
+    uint32_t                mMarkerPosition;
+    uint32_t                mNewPosition;
+    uint32_t                mUpdatePeriod;
 };
 
 
diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.h
index fa8e121..69703b2 100644
--- a/include/media/IAudioFlinger.h
+++ b/include/media/IAudioFlinger.h
@@ -46,8 +46,10 @@
                                 uint32_t sampleRate,
                                 int format,
                                 int channelCount,
-                                int bufferCount,
-                                uint32_t flags) = 0;
+                                int frameCount,
+                                uint32_t flags,
+                                const sp<IMemory>& sharedBuffer,
+                                status_t *status) = 0;
 
     virtual sp<IAudioRecord> openRecord(
                                 pid_t pid,
@@ -55,8 +57,9 @@
                                 uint32_t sampleRate,
                                 int format,
                                 int channelCount,
-                                int bufferCount,
-                                uint32_t flags) = 0;
+                                int frameCount,
+                                uint32_t flags,
+                                status_t *status) = 0;
 
     /* query the audio hardware state. This state never changes,
      * and therefore can be cached.
@@ -65,6 +68,7 @@
     virtual     int         channelCount() const = 0;
     virtual     int         format() const = 0;
     virtual     size_t      frameCount() const = 0;
+    virtual     uint32_t    latency() const = 0;
 
     /* set/get the audio hardware state. This will probably be used by
      * the preference panel, mostly.
diff --git a/include/media/IMediaMetadataRetriever.h b/include/media/IMediaMetadataRetriever.h
new file mode 100644
index 0000000..c677e83
--- /dev/null
+++ b/include/media/IMediaMetadataRetriever.h
@@ -0,0 +1,56 @@
+/*
+**
+** 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_IMEDIAMETADATARETRIEVER_H
+#define ANDROID_IMEDIAMETADATARETRIEVER_H
+
+#include <utils/RefBase.h>
+#include <utils/IInterface.h>
+#include <utils/Parcel.h>
+#include <utils/IMemory.h>
+
+namespace android {
+
+class IMediaMetadataRetriever: public IInterface
+{
+public:
+    DECLARE_META_INTERFACE(MediaMetadataRetriever);
+    virtual void            disconnect() = 0;
+    virtual status_t        setDataSource(const char* srcUrl) = 0;
+    virtual status_t        setDataSource(int fd, int64_t offset, int64_t length) = 0;
+    virtual status_t        setMode(int mode) = 0;
+    virtual status_t        getMode(int* mode) const = 0;
+    virtual sp<IMemory>     captureFrame() = 0;
+    virtual sp<IMemory>     extractAlbumArt() = 0;
+    virtual const char*     extractMetadata(int keyCode) = 0;
+};
+
+// ----------------------------------------------------------------------------
+
+class BnMediaMetadataRetriever: public BnInterface<IMediaMetadataRetriever>
+{
+public:
+    virtual status_t    onTransact(uint32_t code,
+                                   const Parcel& data,
+                                   Parcel* reply,
+                                   uint32_t flags = 0);
+};
+
+}; // namespace android
+
+#endif // ANDROID_IMEDIAMETADATARETRIEVER_H
+
diff --git a/include/media/IMediaPlayer.h b/include/media/IMediaPlayer.h
index 43abf77..a683e74 100644
--- a/include/media/IMediaPlayer.h
+++ b/include/media/IMediaPlayer.h
@@ -38,7 +38,6 @@
     virtual status_t        stop() = 0;
     virtual status_t        pause() = 0;
     virtual status_t        isPlaying(bool* state) = 0;
-    virtual status_t        getVideoSize(int* w, int* h) = 0;
     virtual status_t        seekTo(int msec) = 0;
     virtual status_t        getCurrentPosition(int* msec) = 0;
     virtual status_t        getDuration(int* msec) = 0;
diff --git a/include/media/IMediaPlayerService.h b/include/media/IMediaPlayerService.h
index 63c7a00..8125cc9 100644
--- a/include/media/IMediaPlayerService.h
+++ b/include/media/IMediaPlayerService.h
@@ -23,18 +23,24 @@
 
 #include <media/IMediaPlayerClient.h>
 #include <media/IMediaPlayer.h>
+#include <media/IMediaMetadataRetriever.h>
 
 namespace android {
 
+class IMediaRecorder;
+
 class IMediaPlayerService: public IInterface
 {
 public:
     DECLARE_META_INTERFACE(MediaPlayerService);
 
+    virtual sp<IMediaRecorder>  createMediaRecorder(pid_t pid) = 0;  
+    virtual sp<IMediaMetadataRetriever> createMetadataRetriever(pid_t pid) = 0;
+
     virtual sp<IMediaPlayer>    create(pid_t pid, const sp<IMediaPlayerClient>& client, const char* url) = 0;
     virtual sp<IMediaPlayer>    create(pid_t pid, const sp<IMediaPlayerClient>& client, int fd, int64_t offset, int64_t length) = 0;
-    virtual sp<IMemory>         decode(const char* url, uint32_t *pSampleRate, int* pNumChannels) = 0;
-    virtual sp<IMemory>         decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels) = 0;
+    virtual sp<IMemory>         decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat) = 0;
+    virtual sp<IMemory>         decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat) = 0;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/include/media/IMediaRecorder.h b/include/media/IMediaRecorder.h
new file mode 100644
index 0000000..49e45d1
--- /dev/null
+++ b/include/media/IMediaRecorder.h
@@ -0,0 +1,67 @@
+/*
+ **
+ ** Copyright 2008, HTC Inc.
+ **
+ ** 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_IMEDIARECORDER_H
+#define ANDROID_IMEDIARECORDER_H
+
+#include <utils/IInterface.h>
+
+namespace android {
+
+class ISurface;
+class ICamera;
+
+class IMediaRecorder: public IInterface
+{
+public:
+    DECLARE_META_INTERFACE(MediaRecorder);
+
+    virtual	status_t		setCamera(const sp<ICamera>& camera) = 0;
+    virtual	status_t		setPreviewSurface(const sp<ISurface>& surface) = 0;
+    virtual	status_t		setVideoSource(int vs) = 0;
+    virtual	status_t		setAudioSource(int as) = 0;
+    virtual	status_t		setOutputFormat(int of) = 0;
+    virtual	status_t		setVideoEncoder(int ve) = 0;
+    virtual	status_t		setAudioEncoder(int ae) = 0;
+    virtual	status_t		setOutputFile(const char* path) = 0;
+    virtual	status_t		setVideoSize(int width, int height) = 0;
+    virtual	status_t		setVideoFrameRate(int frames_per_second) = 0;
+    virtual	status_t		prepare() = 0;
+    virtual	status_t		getMaxAmplitude(int* max) = 0;
+    virtual	status_t		start() = 0;
+    virtual	status_t		stop() = 0;
+    virtual	status_t		reset() = 0;
+    virtual status_t        init() = 0;
+    virtual status_t        close() = 0;
+    virtual	status_t		release() = 0;
+};
+
+// ----------------------------------------------------------------------------
+
+class BnMediaRecorder: public BnInterface<IMediaRecorder>
+{
+public:
+    virtual status_t    onTransact( uint32_t code,
+                                    const Parcel& data,
+                                    Parcel* reply,
+                                    uint32_t flags = 0);
+};
+
+}; // namespace android
+
+#endif // ANDROID_IMEDIARECORDER_H
+
diff --git a/include/media/MediaMetadataRetrieverInterface.h b/include/media/MediaMetadataRetrieverInterface.h
new file mode 100644
index 0000000..b178836
--- /dev/null
+++ b/include/media/MediaMetadataRetrieverInterface.h
@@ -0,0 +1,52 @@
+/*
+**
+** 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_MEDIAMETADATARETRIEVERINTERFACE_H
+#define ANDROID_MEDIAMETADATARETRIEVERINTERFACE_H
+
+#include <utils/RefBase.h>
+#include <media/mediametadataretriever.h>
+#include <private/media/VideoFrame.h>
+
+namespace android {
+
+// Abstract base class
+class MediaMetadataRetrieverBase : public RefBase
+{
+public:
+                        MediaMetadataRetrieverBase() {}
+    virtual             ~MediaMetadataRetrieverBase() {}
+    virtual status_t    setDataSource(const char *url) = 0;
+    virtual status_t    setDataSource(int fd, int64_t offset, int64_t length) = 0;
+    virtual status_t    setMode(int mode) = 0;
+    virtual status_t    getMode(int* mode) const = 0;
+    virtual VideoFrame* captureFrame() = 0;
+    virtual MediaAlbumArt* extractAlbumArt() = 0;
+    virtual const char* extractMetadata(int keyCode) = 0;
+};
+
+// MediaMetadataRetrieverInterface
+class MediaMetadataRetrieverInterface : public MediaMetadataRetrieverBase
+{
+public:
+    virtual             ~MediaMetadataRetrieverInterface() {}
+};
+
+}; // namespace android
+
+#endif // ANDROID_MEDIAMETADATARETRIEVERINTERFACE_H
+
diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h
index 275e789..30e4578 100644
--- a/include/media/MediaPlayerInterface.h
+++ b/include/media/MediaPlayerInterface.h
@@ -26,6 +26,7 @@
 #include <utils/RefBase.h>
 
 #include <media/mediaplayer.h>
+#include <media/AudioSystem.h>
 
 namespace android {
 
@@ -36,6 +37,9 @@
 };
 
 #define DEFAULT_AUDIOSINK_BUFFERCOUNT 4
+#define DEFAULT_AUDIOSINK_BUFFERSIZE 1200
+#define DEFAULT_AUDIOSINK_SAMPLERATE 44100
+
 
 // callback mechanism for passing messages to MediaPlayer object
 typedef void (*notify_callback_f)(void* cookie, int msg, int ext1, int ext2);
@@ -57,7 +61,7 @@
         virtual ssize_t     frameSize() const = 0;
         virtual uint32_t    latency() const = 0;
         virtual float       msecsPerFrame() const = 0;
-        virtual status_t    open(uint32_t sampleRate, int channelCount, int bufferCount=DEFAULT_AUDIOSINK_BUFFERCOUNT) = 0;
+        virtual status_t    open(uint32_t sampleRate, int channelCount, int format=AudioSystem::PCM_16_BIT, int bufferCount=DEFAULT_AUDIOSINK_BUFFERCOUNT) = 0;
         virtual void        start() = 0;
         virtual ssize_t     write(const void* buffer, size_t size) = 0;
         virtual void        stop() = 0;
@@ -80,8 +84,6 @@
     virtual status_t    stop() = 0;
     virtual status_t    pause() = 0;
     virtual bool        isPlaying() = 0;
-    virtual status_t    getVideoWidth(int *w) {return 0;}
-    virtual status_t    getVideoHeight(int *h) {return 0;}
     virtual status_t    seekTo(int msec) = 0;
     virtual status_t    getCurrentPosition(int *msec) = 0;
     virtual status_t    getDuration(int *msec) = 0;
diff --git a/include/media/PVMediaRecorder.h b/include/media/PVMediaRecorder.h
new file mode 100644
index 0000000..ec497ae
--- /dev/null
+++ b/include/media/PVMediaRecorder.h
@@ -0,0 +1,60 @@
+/*
+ **
+ ** Copyright 2008, HTC Inc.
+ **
+ ** 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_PVMEDIARECORDER_H
+#define ANDROID_PVMEDIARECORDER_H
+
+#include <media/mediarecorder.h>
+
+namespace android {
+
+class ISurface;
+class ICamera;
+class AuthorDriverWrapper;
+
+class PVMediaRecorder
+{
+public:
+    PVMediaRecorder();
+    ~PVMediaRecorder();
+
+    status_t init();
+    status_t setAudioSource(audio_source as);
+    status_t setVideoSource(video_source vs);
+    status_t setOutputFormat(output_format of);
+    status_t setAudioEncoder(audio_encoder ae);
+    status_t setVideoEncoder(video_encoder ve);
+    status_t setVideoSize(int width, int height);
+    status_t setVideoFrameRate(int frames_per_second);
+    status_t setCamera(const sp<ICamera>& camera);
+    status_t setPreviewSurface(const sp<ISurface>& surface);
+    status_t setOutputFile(const char *path);
+    status_t prepare();
+    status_t start();
+    status_t stop();
+    status_t close();
+    status_t reset();
+    status_t getMaxAmplitude(int *max);
+
+private:
+    AuthorDriverWrapper*            mAuthorDriverWrapper;
+};
+
+}; // namespace android
+
+#endif // ANDROID_PVMEDIARECORDER_H
+
diff --git a/include/media/PVMetadataRetriever.h b/include/media/PVMetadataRetriever.h
new file mode 100644
index 0000000..c202dfe
--- /dev/null
+++ b/include/media/PVMetadataRetriever.h
@@ -0,0 +1,51 @@
+/*
+**
+** 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_PVMETADATARETRIEVER_H
+#define ANDROID_PVMETADATARETRIEVER_H
+
+#include <utils/Errors.h>
+#include <media/MediaMetadataRetrieverInterface.h>
+#include <private/media/VideoFrame.h>
+
+namespace android {
+
+class MetadataDriver;
+
+class PVMetadataRetriever : public MediaMetadataRetrieverInterface
+{
+public:
+                        PVMetadataRetriever();
+    virtual             ~PVMetadataRetriever();
+
+    virtual status_t    setDataSource(const char *url);
+    virtual status_t    setDataSource(int fd, int64_t offset, int64_t length);
+    virtual status_t    setMode(int mode);
+    virtual status_t    getMode(int* mode) const;
+    virtual VideoFrame* captureFrame();
+    virtual MediaAlbumArt* extractAlbumArt();
+    virtual const char* extractMetadata(int keyCode);
+
+private:
+    mutable Mutex       mLock;
+    MetadataDriver*     mMetadataDriver;
+    char*               mDataSourcePath;
+};
+
+}; // namespace android
+
+#endif // ANDROID_PVMETADATARETRIEVER_H
diff --git a/include/media/PVPlayer.h b/include/media/PVPlayer.h
index 8164d8c..5f302ed 100644
--- a/include/media/PVPlayer.h
+++ b/include/media/PVPlayer.h
@@ -41,8 +41,6 @@
     virtual status_t    stop();
     virtual status_t    pause();
     virtual bool        isPlaying();
-    virtual status_t    getVideoWidth(int *w);
-    virtual status_t    getVideoHeight(int *h);
     virtual status_t    seekTo(int msec);
     virtual status_t    getCurrentPosition(int *msec);
     virtual status_t    getDuration(int *msec);
@@ -54,11 +52,11 @@
             void        sendEvent(int msg, int ext1=0, int ext2=0) { MediaPlayerBase::sendEvent(msg, ext1, ext2); }
 
 private:
-    static void         do_nothing(status_t s, void *cookie) { }
-    static void         run_init(status_t s, void *cookie);
-    static void         run_set_video_surface(status_t s, void *cookie);
-    static void         run_set_audio_output(status_t s, void *cookie);
-    static void         run_prepare(status_t s, void *cookie);
+    static void         do_nothing(status_t s, void *cookie, bool cancelled) { }
+    static void         run_init(status_t s, void *cookie, bool cancelled);
+    static void         run_set_video_surface(status_t s, void *cookie, bool cancelled);
+    static void         run_set_audio_output(status_t s, void *cookie, bool cancelled);
+    static void         run_prepare(status_t s, void *cookie, bool cancelled);
 
     PlayerDriver*               mPlayerDriver;
     char *                      mDataSourcePath;
diff --git a/include/media/ToneGenerator.h b/include/media/ToneGenerator.h
index bc27d35..da1489f 100644
--- a/include/media/ToneGenerator.h
+++ b/include/media/ToneGenerator.h
@@ -85,7 +85,7 @@
         TONE_RESTARTING  //
     };
 
-    static const unsigned int NUM_PCM_BUFFERS = 2; // number of pcm buffers of audio track
+    static const unsigned int NUM_PCM_BUFFERS = 2; // Number of AudioTrack pcm buffers
     
     static const unsigned int TONEGEN_MAX_WAVES = 3;
     static const unsigned int TONEGEN_MAX_SEGMENTS = 4;  // Maximun number of elenemts in
@@ -126,14 +126,17 @@
     const ToneDescriptor *mpToneDesc;  // pointer to active tone descriptor
     const ToneDescriptor *mpNewToneDesc;  // pointer to next active tone descriptor
 
-    unsigned int mSamplingRate;  // Sampling rate
+    int mSamplingRate;  // AudioFlinger Sampling rate
+    int mBufferSize;  // PCM buffer size in frames
     AudioTrack *mpAudioTrack;  // Pointer to audio track used for playback
     Mutex mLock;  // Mutex to control concurent access to ToneGenerator object from audio callback and application API
     Mutex mCbkCondLock; // Mutex associated to mWaitCbkCond
     Condition mWaitCbkCond; // condition enabling interface to wait for audio callback completion after a change is requested
     float mVolume;  // Volume applied to audio track
+    int mStreamType; // Audio stream used for output
 
-    static void audioCallback(void* user, const AudioTrack::Buffer& info);
+    bool initAudioTrack();
+    static void audioCallback(int event, void* user, void *info);
     bool prepareWave();
     unsigned int numWaves();
     void clearWaveGens();
diff --git a/include/media/mediametadataretriever.h b/include/media/mediametadataretriever.h
index 586dda1c..05cba30 100644
--- a/include/media/mediametadataretriever.h
+++ b/include/media/mediametadataretriever.h
@@ -18,10 +18,16 @@
 #ifndef MEDIAMETADATARETRIEVER_H
 #define MEDIAMETADATARETRIEVER_H
 
-#include <graphics/SkBitmap.h>      // for SkBitmap
+#include <utils/Errors.h>  // for status_t
+#include <utils/threads.h>
+#include <utils/IMemory.h>
+#include <media/IMediaMetadataRetriever.h>
 
 namespace android {
 
+class IMediaPlayerService;
+class IMediaMetadataRetriever;
+
 // Keep these in synch with the constants defined in MediaMetadataRetriever.java
 // class.
 enum {
@@ -38,62 +44,45 @@
     METADATA_KEY_NUM_TRACKS      = 10,
     METADATA_KEY_IS_DRM_CRIPPLED = 11,
     METADATA_KEY_CODEC           = 12,
+    METADATA_KEY_RATING          = 13,
+    METADATA_KEY_COMMENT         = 14,
+    METADATA_KEY_COPYRIGHT       = 15,
     // Add more here...
 };
 
-// A utility class that holds the size and actual data in album art.
-class MediaAlbumArt {
-public:
-    MediaAlbumArt(): length(0), data(NULL) {}
-    MediaAlbumArt(const MediaAlbumArt& copy) { 
-        // Don't be caught by uninitialized variables!!
-        length = 0; 
-        data = NULL; 
-        setData(copy.length, copy.data);
-    }
-    MediaAlbumArt(const char* url);
-    ~MediaAlbumArt() { clearData(); }
 
-    void clearData();
-    status_t setData(unsigned int len, const char* buf);
-    char *getData() const { return copyData(length, data); }
-    unsigned int getLength() const { return length; }
-    
-private:
-    // Disable copy assignment operator!
-    MediaAlbumArt& operator=(const MediaAlbumArt& rhs);
-    static char* copyData(unsigned int len, const char* buf);
-    
-    unsigned int length;    // Number of bytes in data.
-    char *data;             // Actual binary data.
-};
-
-class MediaMetadataRetrieverImpl
+class MediaMetadataRetriever: public RefBase
 {
 public:
-    virtual ~MediaMetadataRetrieverImpl() {};
-    virtual status_t setDataSource(const char* dataSourceUrl) = 0;
-    virtual SkBitmap *captureFrame() = 0;
-    virtual const char* extractMetadata(int keyCode) = 0;
-    virtual MediaAlbumArt* extractAlbumArt() = 0;
-    virtual void setMode(int mode) = 0;
-};
-
-class MediaMetadataRetriever
-{
-public:
-    static status_t setDataSource(const char* dataSourceUrl);
-    static SkBitmap *captureFrame();
-    static const char* extractMetadata(int keyCode);
-    static MediaAlbumArt* extractAlbumArt();
-    static void setMode(int mode);
-    static void release();
-    static void create();
+    MediaMetadataRetriever();
+    ~MediaMetadataRetriever();
+    void disconnect();
+    status_t setDataSource(const char* dataSourceUrl);
+    status_t setDataSource(int fd, int64_t offset, int64_t length);
+    status_t setMode(int mode);
+    status_t getMode(int* mode);
+    sp<IMemory> captureFrame();
+    sp<IMemory> extractAlbumArt();
+    const char* extractMetadata(int keyCode);
 
 private:
-    MediaMetadataRetriever() {}
-    static MediaMetadataRetrieverImpl *mRetriever;
-    static void                       *mLibHandler;
+    static const sp<IMediaPlayerService>& getService();
+
+    class DeathNotifier: public IBinder::DeathRecipient
+    {
+    public:
+        DeathNotifier() {}
+        virtual ~DeathNotifier();
+        virtual void binderDied(const wp<IBinder>& who);
+    };
+
+    static sp<DeathNotifier>                  sDeathNotifier;
+    static Mutex                              sServiceLock;
+    static sp<IMediaPlayerService>            sService;
+
+    Mutex                                     mLock;
+    sp<IMediaMetadataRetriever>               mRetriever;
+
 };
 
 }; // namespace android
diff --git a/include/media/mediaplayer.h b/include/media/mediaplayer.h
index aadfc32..7288445 100644
--- a/include/media/mediaplayer.h
+++ b/include/media/mediaplayer.h
@@ -17,11 +17,12 @@
 #ifndef ANDROID_MEDIAPLAYER_H
 #define ANDROID_MEDIAPLAYER_H
 
+#include <utils/IMemory.h>
 #include <ui/Surface.h>
-#include <media/AudioTrack.h>
 #include <media/IMediaPlayerClient.h>
 #include <media/IMediaPlayer.h>
 #include <media/IMediaPlayerService.h>
+#include <utils/SortedVector.h>
 
 namespace android {
 
@@ -31,6 +32,7 @@
     MEDIA_PLAYBACK_COMPLETE = 2,
     MEDIA_BUFFERING_UPDATE  = 3,
     MEDIA_SEEK_COMPLETE     = 4,
+    MEDIA_SET_VIDEO_SIZE    = 5,
     MEDIA_ERROR             = 100,
 };
 
@@ -52,18 +54,18 @@
 
 // ----------------------------------------------------------------------------
 // ref-counted object for callbacks
-class MediaPlayerListener: public RefBase
+class MediaPlayerListener: virtual public RefBase
 {
 public:
     virtual void notify(int msg, int ext1, int ext2) = 0;
 };
 
-class MediaPlayer : public BnMediaPlayerClient, public IBinder::DeathRecipient
+class MediaPlayer : public BnMediaPlayerClient
 {
 public:
     MediaPlayer();
     ~MediaPlayer();
-
+            void            onFirstRef();
             void            disconnect();
             status_t        setDataSource(const char *url);
             status_t        setDataSource(int fd, int64_t offset, int64_t length);
@@ -83,10 +85,11 @@
             status_t        reset();
             status_t        setAudioStreamType(int type);
             status_t        setLooping(int loop);
+            bool            isLooping();
             status_t        setVolume(float leftVolume, float rightVolume);
             void            notify(int msg, int ext1, int ext2);
-    static  sp<IMemory>     decode(const char* url, uint32_t *pSampleRate, int* pNumChannels);
-    static  sp<IMemory>     decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels);
+    static  sp<IMemory>     decode(const char* url, uint32_t *pSampleRate, int* pNumChannels, int* pFormat);
+    static  sp<IMemory>     decode(int fd, int64_t offset, int64_t length, uint32_t *pSampleRate, int* pNumChannels, int* pFormat);
 
 private:
             void            clear_l();
@@ -96,7 +99,8 @@
             status_t        setDataSource(const sp<IMediaPlayer>& player);
 
     static const sp<IMediaPlayerService>& getMediaPlayerService();
-    virtual void binderDied(const wp<IBinder>& who);
+    static void addObitRecipient(const wp<MediaPlayer>& recipient);
+    static void removeObitRecipient(const wp<MediaPlayer>& recipient);
 
     class DeathNotifier: public IBinder::DeathRecipient
     {
@@ -107,8 +111,6 @@
         virtual void binderDied(const wp<IBinder>& who);
     };
 
-    static sp<DeathNotifier> mDeathNotifier;
-
     sp<IMediaPlayer>            mPlayer;
     Mutex                       mLock;
     Mutex                       mNotifyLock;
@@ -125,11 +127,15 @@
     bool                        mLoop;
     float                       mLeftVolume;
     float                       mRightVolume;
+    int                         mVideoWidth;
+    int                         mVideoHeight;
 
     friend class DeathNotifier;
 
-    static  Mutex               mServiceLock;
-    static  sp<IMediaPlayerService>    mMediaPlayerService;
+    static  Mutex                           sServiceLock;
+    static  sp<IMediaPlayerService>         sMediaPlayerService;
+    static  sp<DeathNotifier>               sDeathNotifier;
+    static  SortedVector< wp<MediaPlayer> > sObitRecipients;
 };
 
 }; // namespace android
diff --git a/include/media/mediarecorder.h b/include/media/mediarecorder.h
index f247424..a901d32 100644
--- a/include/media/mediarecorder.h
+++ b/include/media/mediarecorder.h
@@ -1,28 +1,30 @@
 /*
- * 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.
+ ** 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 MEDIARECORDER_H
-#define MEDIARECORDER_H
+#ifndef ANDROID_MEDIARECORDER_H
+#define ANDROID_MEDIARECORDER_H
 
 #include <utils.h>
-#include <ui/SurfaceComposerClient.h>
 
 namespace android {
 
-class AuthorDriverWrapper;
+class Surface;
+class IMediaRecorder;
+class ICamera;
 
 typedef void (*media_completion_f)(status_t status, void *cookie);
 
@@ -31,7 +33,7 @@
  */
 enum audio_source {
     AUDIO_SOURCE_DEFAULT = 0,
-    AUDIO_SOURCE_MIC = 1, 
+    AUDIO_SOURCE_MIC = 1,
 };
 
 enum video_source {
@@ -39,10 +41,13 @@
     VIDEO_SOURCE_CAMERA = 1,
 };
 
+//Please update java/android/android/media/MediaRecorder.java if the following is updated.
 enum output_format {
     OUTPUT_FORMAT_DEFAULT = 0,
-    OUTPUT_FORMAT_THREE_GPP = 1,
-    OUTPUT_FORMAT_MPEG_4 = 2,
+    OUTPUT_FORMAT_THREE_GPP,
+    OUTPUT_FORMAT_MPEG_4,
+    OUTPUT_FORMAT_RAW_AMR,
+    OUTPUT_FORMAT_LIST_END // must be last - used to validate format type
 };
 
 enum audio_encoder {
@@ -57,26 +62,29 @@
     VIDEO_ENCODER_MPEG_4_SP = 3,
 };
 
+// Maximum frames per second is 24
+#define MEDIA_RECORDER_MAX_FRAME_RATE         24
+
 /*
  * The state machine of the media_recorder uses a set of different state names.
  * The mapping between the media_recorder and the pvauthorengine is shown below:
- * 
+ *
  *    mediarecorder                        pvauthorengine
  * ----------------------------------------------------------------
  *    MEDIA_RECORDER_ERROR                 ERROR
  *    MEDIA_RECORDER_IDLE                  IDLE
  *    MEDIA_RECORDER_INITIALIZED           OPENED
- *    MEDIA_RECORDER_PREPARING
+ *    MEDIA_RECORDER_DATASOURCE_CONFIGURED
  *    MEDIA_RECORDER_PREPARED              INITIALIZED
  *    MEDIA_RECORDER_RECORDING             RECORDING
  */
 enum media_recorder_states {
-    MEDIA_RECORDER_ERROR =         0,
-    MEDIA_RECORDER_IDLE =          1 << 0,
-    MEDIA_RECORDER_INITIALIZED =   1 << 1,
-    MEDIA_RECORDER_PREPARING =     1 << 2,
-    MEDIA_RECORDER_PREPARED =      1 << 3,
-    MEDIA_RECORDER_RECORDING =     1 << 4,
+    MEDIA_RECORDER_ERROR                 =      0,
+    MEDIA_RECORDER_IDLE                  = 1 << 0,
+    MEDIA_RECORDER_INITIALIZED           = 1 << 1,
+    MEDIA_RECORDER_DATASOURCE_CONFIGURED = 1 << 2,
+    MEDIA_RECORDER_PREPARED              = 1 << 3,
+    MEDIA_RECORDER_RECORDING             = 1 << 4,
 };
 
 class MediaRecorder
@@ -85,36 +93,39 @@
     MediaRecorder();
     ~MediaRecorder();
 
-    status_t init();
-
-    status_t setAudioSource(audio_source as);
-    status_t setVideoSource(video_source vs);
-    status_t setOutputFormat(output_format of);
-    status_t setAudioEncoder(audio_encoder ae);
-    status_t setVideoEncoder(video_encoder ve);
-    status_t setVideoSize(int width, int height);
-    status_t setVideoFrameRate(int frames_per_second);
-    status_t setPreviewSurface(const sp<Surface>& surface);
-
-    status_t setOutputFile(const char *path);
-    // XXX metadata setup
-
-    status_t prepare();
-    status_t start();
-    status_t stop();
-    status_t reset();
-    status_t getIfOutputFormatSpecified();
-
-    status_t getMaxAmplitude(int *max);
+    status_t    initCheck();
+    status_t    setCamera(const sp<ICamera>& camera);
+    status_t    setPreviewSurface(const sp<Surface>& surface);
+    status_t    setVideoSource(int vs);
+    status_t    setAudioSource(int as);
+    status_t    setOutputFormat(int of);
+    status_t    setVideoEncoder(int ve);
+    status_t    setAudioEncoder(int ae);
+    status_t    setOutputFile(const char* path);
+    status_t    setVideoSize(int width, int height);
+    status_t    setVideoFrameRate(int frames_per_second);
+    status_t    prepare();
+    status_t    getMaxAmplitude(int* max);
+    status_t    start();
+    status_t    stop();
+    status_t    reset();
+    status_t    init();
+    status_t    close();
+    status_t    release();
 
 private:
-    AuthorDriverWrapper            *mAuthorDriverWrapper;
-    bool                           mOutputFormatSpecified;
-    media_recorder_states          mCurrentState;
+    void                    doCleanUp();
+    status_t                doReset();
 
+    sp<IMediaRecorder>      mMediaRecorder;
+    media_recorder_states   mCurrentState;
+    bool                    mIsAudioSourceSet;
+    bool                    mIsVideoSourceSet;
+    bool                    mIsAudioEncoderSet;
+    bool                    mIsVideoEncoderSet;
+    bool                    mIsOutputFileSet;
 };
 
-}; // namespace android
+};  // namespace android
 
-#endif // MEDIAPLAYER_H
-
+#endif // ANDROID_MEDIARECORDER_H
diff --git a/include/media/mediascanner.h b/include/media/mediascanner.h
index 5d0122d..fbef1db 100644
--- a/include/media/mediascanner.h
+++ b/include/media/mediascanner.h
@@ -23,6 +23,7 @@
 namespace android {
 
 class MediaScannerClient;
+class StringArray;
 
 class MediaScanner 
 {
@@ -35,6 +36,7 @@
     status_t processFile(const char *path, const char *mimeType, MediaScannerClient& client);
     status_t processDirectory(const char *path, const char* extensions, 
             MediaScannerClient& client, ExceptionCheck exceptionCheck, void* exceptionEnv);
+    void setLocale(const char* locale);
     
     // extracts album art as a block of data
     char* extractAlbumArt(int fd);
@@ -45,16 +47,36 @@
     status_t doProcessDirectory(char *path, int pathRemaining, const char* extensions, 
             MediaScannerClient& client, ExceptionCheck exceptionCheck, void* exceptionEnv);
     void initializeForThread();
+    
+    // current locale (like "ja_JP"), created/destroyed with strdup()/free()
+    char* mLocale;
 };
 
 
 class MediaScannerClient
 {
 public:
-	virtual ~MediaScannerClient() {}
+	MediaScannerClient();
+	virtual ~MediaScannerClient();
+	void setLocale(const char* locale);
+	void beginFile();
+	bool addStringTag(const char* name, const char* value);
+	void endFile();
+	
 	virtual bool scanFile(const char* path, long long lastModified, long long fileSize) = 0;
 	virtual bool handleStringTag(const char* name, const char* value) = 0;
 	virtual bool setMimeType(const char* mimeType) = 0;
+
+protected:
+    void convertValues(uint32_t encoding);
+
+protected:
+    // cached name and value strings, for native encoding support.
+    StringArray*    mNames;
+    StringArray*    mValues;
+    
+    // default encoding based on MediaScanner::mLocale string
+    uint32_t        mLocaleEncoding;
 };
 
 }; // namespace android