diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:43 -0800 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-12-17 18:05:43 -0800 |
commit | f013e1afd1e68af5e3b868c26a653bbfb39538f8 (patch) | |
tree | 7ad6c8fd9c7b55f4b4017171dec1cb760bbd26bf /include | |
parent | e70cfafe580c6f2994c4827cd8a534aabf3eb05c (diff) | |
download | frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.zip frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.tar.gz frameworks_base-f013e1afd1e68af5e3b868c26a653bbfb39538f8.tar.bz2 |
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'include')
40 files changed, 1340 insertions, 479 deletions
diff --git a/include/GLES/eglnatives.h b/include/GLES/eglnatives.h index f9e544c..1cd57d0 100644 --- a/include/GLES/eglnatives.h +++ b/include/GLES/eglnatives.h @@ -33,7 +33,7 @@ typedef struct egl_native_pixmap_t* NativePixmapType; typedef void* NativeDisplayType; /* - * This a conveniance function to create a NativeWindowType surface + * This a convenience function to create a NativeWindowType surface * that maps to the whole screen * This function is actually implemented in libui.so */ @@ -50,6 +50,7 @@ enum native_pixel_format_t { NATIVE_PIXEL_FORMAT_RGBA_8888 = 1, NATIVE_PIXEL_FORMAT_RGB_565 = 4, + NATIVE_PIXEL_FORMAT_BGRA_8888 = 5, NATIVE_PIXEL_FORMAT_RGBA_5551 = 6, NATIVE_PIXEL_FORMAT_RGBA_4444 = 7, NATIVE_PIXEL_FORMAT_YCbCr_422_SP= 0x10, 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 @@ namespace android { 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 @@ public: // 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 @@ public: */ 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 @@ private: 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 @@ private: 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 @@ public: 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 @@ public: 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 @@ private: 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 audio_track_cblk_t; 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 @@ public: 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 @@ public: }; }; - /* 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 @@ public: 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 @@ public: /* 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 @@ private: 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 @@ private: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ enum player_type { }; #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 @@ public: 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 @@ public: 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 @@ public: 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 @@ public: 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 @@ private: 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 @@ private: 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 586dda1..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 @@ enum { 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 { + +class MediaMetadataRetriever: public RefBase +{ 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(); } + 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); - 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. -}; + static const sp<IMediaPlayerService>& getService(); -class MediaMetadataRetrieverImpl -{ -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 DeathNotifier: public IBinder::DeathRecipient + { + public: + DeathNotifier() {} + virtual ~DeathNotifier(); + virtual void binderDied(const wp<IBinder>& who); + }; -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(); + static sp<DeathNotifier> sDeathNotifier; + static Mutex sServiceLock; + static sp<IMediaPlayerService> sService; + + Mutex mLock; + sp<IMediaMetadataRetriever> mRetriever; -private: - MediaMetadataRetriever() {} - static MediaMetadataRetrieverImpl *mRetriever; - static void *mLibHandler; }; }; // 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 @@ enum media_event_type { MEDIA_PLAYBACK_COMPLETE = 2, MEDIA_BUFFERING_UPDATE = 3, MEDIA_SEEK_COMPLETE = 4, + MEDIA_SET_VIDEO_SIZE = 5, MEDIA_ERROR = 100, }; @@ -52,18 +54,18 @@ enum media_player_states { // ---------------------------------------------------------------------------- // 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 @@ public: 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 @@ private: 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 @@ private: virtual void binderDied(const wp<IBinder>& who); }; - static sp<DeathNotifier> mDeathNotifier; - sp<IMediaPlayer> mPlayer; Mutex mLock; Mutex mNotifyLock; @@ -125,11 +127,15 @@ private: 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 @@ typedef void (*media_completion_f)(status_t status, void *cookie); */ enum audio_source { AUDIO_SOURCE_DEFAULT = 0, - AUDIO_SOURCE_MIC = 1, + AUDIO_SOURCE_MIC = 1, }; enum video_source { @@ -39,10 +41,13 @@ enum video_source { 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 @@ enum video_encoder { 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 @@ public: 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 - -#endif // MEDIAPLAYER_H +}; // namespace android +#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 @@ public: 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 @@ private: 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 diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h index 1878f3c..72ed281 100644 --- a/include/private/media/AudioTrackShared.h +++ b/include/private/media/AudioTrackShared.h @@ -31,29 +31,41 @@ namespace android { struct audio_track_cblk_t { - enum { - SEQUENCE_MASK = 0xFFFFFF00, - BUFFER_MASK = 0x000000FF - }; + // The data members are grouped so that members accessed frequently and in the same context + // are in the same line of data cache. Mutex lock; Condition cv; volatile uint32_t user; volatile uint32_t server; + uint32_t userBase; + uint32_t serverBase; + void* buffers; + uint32_t frameCount; + // Cache line boundary + uint32_t loopStart; + uint32_t loopEnd; + int loopCount; volatile union { uint16_t volume[2]; uint32_t volumeLR; }; uint16_t sampleRate; - uint16_t reserved; - - void* buffers; - size_t size; - + uint16_t channels; + int16_t flowControlFlag; // underrun (out) or overrrun (in) indication + uint8_t out; // out equals 1 for AudioTrack and 0 for AudioRecord + uint8_t forceReady; + // Padding ensuring that data buffer starts on a cache line boundary (32 bytes). + // See AudioFlinger::TrackBase constructor + int32_t Padding[4]; + audio_track_cblk_t(); - uint32_t stepUser(int bufferCount); - bool stepServer(int bufferCount); - void* buffer(int id) const; + uint32_t stepUser(uint32_t frameCount); + bool stepServer(uint32_t frameCount); + void* buffer(uint32_t offset) const; + uint32_t framesAvailable(); + uint32_t framesAvailable_l(); + uint32_t framesReady(); }; diff --git a/include/private/media/VideoFrame.h b/include/private/media/VideoFrame.h new file mode 100644 index 0000000..9c35274ba --- /dev/null +++ b/include/private/media/VideoFrame.h @@ -0,0 +1,127 @@ +/* +** +** 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_VIDEO_FRAME_H +#define ANDROID_VIDEO_FRAME_H + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <utils/Log.h> + +namespace android { + +// A simple buffer to hold binary data +class MediaAlbumArt +{ +public: + MediaAlbumArt(): mSize(0), mData(0) {} + + explicit MediaAlbumArt(const char* url) { + mSize = 0; + mData = NULL; + FILE *in = fopen(url, "r"); + if (!in) { + return; + } + fseek(in, 0, SEEK_END); + mSize = ftell(in); // Allocating buffer of size equals to the external file size. + if (mSize == 0 || (mData = new uint8_t[mSize]) == NULL) { + fclose(in); + if (mSize != 0) { + mSize = 0; + } + return; + } + rewind(in); + if (fread(mData, 1, mSize, in) != mSize) { // Read failed. + delete[] mData; + mData = NULL; + mSize = 0; + return; + } + fclose(in); + } + + MediaAlbumArt(const MediaAlbumArt& copy) { + mSize = copy.mSize; + mData = NULL; // initialize it first + if (mSize > 0 && copy.mData != NULL) { + mData = new uint8_t[copy.mSize]; + if (mData != NULL) { + memcpy(mData, copy.mData, mSize); + } else { + mSize = 0; + } + } + } + + ~MediaAlbumArt() { + if (mData != 0) { + delete[] mData; + } + } + + // Intentional public access modifier: + // We have to know the internal structure in order to share it between + // processes? + uint32_t mSize; // Number of bytes in mData + uint8_t* mData; // Actual binary data +}; + +// Represents a color converted (RGB-based) video frame +// with bitmap pixels stored in FrameBuffer +class VideoFrame +{ +public: + VideoFrame(): mWidth(0), mHeight(0), mDisplayWidth(0), mDisplayHeight(0), mSize(0), mData(0) {} + + VideoFrame(const VideoFrame& copy) { + mWidth = copy.mWidth; + mHeight = copy.mHeight; + mDisplayWidth = copy.mDisplayWidth; + mDisplayHeight = copy.mDisplayHeight; + mSize = copy.mSize; + mData = NULL; // initialize it first + if (mSize > 0 && copy.mData != NULL) { + mData = new uint8_t[mSize]; + if (mData != NULL) { + memcpy(mData, copy.mData, mSize); + } else { + mSize = 0; + } + } + } + + ~VideoFrame() { + if (mData != 0) { + delete[] mData; + } + } + + // Intentional public access modifier: + uint32_t mWidth; + uint32_t mHeight; + uint32_t mDisplayWidth; + uint32_t mDisplayHeight; + uint32_t mSize; // Number of bytes in mData + uint8_t* mData; // Actual binary data +}; + +}; // namespace android + +#endif // ANDROID_VIDEO_FRAME_H diff --git a/include/private/opengles/gl_context.h b/include/private/opengles/gl_context.h index 67d50fd..2aa78d8 100644 --- a/include/private/opengles/gl_context.h +++ b/include/private/opengles/gl_context.h @@ -532,6 +532,10 @@ struct compute_iterators_t vertex_t const* v1, vertex_t const* v2); + void initLine( + vertex_t const* v0, + vertex_t const* v1); + inline void initLerp(vertex_t const* v0, uint32_t enables); int iteratorsScale(int32_t it[3], @@ -543,6 +547,9 @@ struct compute_iterators_t void iterators0032(int32_t it[3], int32_t c0, int32_t c1, int32_t c2) const; + void iterators0032(int64_t it[3], + int32_t c0, int32_t c1, int32_t c2) const; + GGLcoord area() const { return m_area; } private: diff --git a/include/ui/BlitHardware.h b/include/ui/BlitHardware.h deleted file mode 100644 index 4de1c12..0000000 --- a/include/ui/BlitHardware.h +++ /dev/null @@ -1,143 +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_BLIT_HARDWARE_H -#define ANDROID_BLIT_HARDWARE_H - -#include <stdint.h> -#include <sys/types.h> - -#if __cplusplus -extern "C" { -#endif - -/******************************************************************************/ - -/* supported pixel-formats. these must be compatible with - * graphics/PixelFormat.java, ui/PixelFormat.h, pixelflinger/format.h - */ - -enum -{ - COPYBIT_RGBA_8888 = 1, - COPYBIT_RGB_565 = 4, - COPYBIT_RGBA_5551 = 6, - COPYBIT_RGBA_4444 = 7, - COPYBIT_YCbCr_422_SP = 0x10, - COPYBIT_YCbCr_420_SP = 0x11 -}; - -/* name for copybit_set_parameter */ -enum -{ - /* rotation of the source image in degrees (0 to 359) */ - COPYBIT_ROTATION_DEG = 1, - /* plane alpha value */ - COPYBIT_PLANE_ALPHA = 2, - /* enable or disable dithering */ - COPYBIT_DITHER = 3, - /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */ - COPYBIT_TRANSFORM = 4, -}; - -/* values for copybit_set_parameter(COPYBIT_TRANSFORM) */ -enum { - /* flip source image horizontally */ - COPYBIT_TRANSFORM_FLIP_H = 0x01, - /* flip source image vertically */ - COPYBIT_TRANSFORM_FLIP_V = 0x02, - /* rotate source image 90 degres */ - COPYBIT_TRANSFORM_ROT_90 = 0x04, - /* rotate source image 180 degres */ - COPYBIT_TRANSFORM_ROT_180 = 0x03, - /* rotate source image 270 degres */ - COPYBIT_TRANSFORM_ROT_270 = 0x07, -}; - -/* enable/disable value copybit_set_parameter */ -enum { - COPYBIT_DISABLE = 0, - COPYBIT_ENABLE = 1 -}; - -/* use get() to query static informations about the hardware */ -enum { - /* Maximum amount of minification supported by the hardware*/ - COPYBIT_MINIFICATION_LIMIT = 1, - /* Maximum amount of magnification supported by the hardware */ - COPYBIT_MAGNIFICATION_LIMIT = 2, - /* Number of fractional bits support by the scaling engine */ - COPYBIT_SCALING_FRAC_BITS = 3, - /* Supported rotation step in degres. */ - COPYBIT_ROTATION_STEP_DEG = 4, -}; - -struct copybit_image_t { - uint32_t w; - uint32_t h; - int32_t format; - uint32_t offset; - void* base; - int fd; -}; - - -struct copybit_rect_t { - int l; - int t; - int r; - int b; -}; - -struct copybit_region_t { - int (*next)(copybit_region_t const*, copybit_rect_t* rect); -}; - -struct copybit_t -{ - int (*set_parameter)(struct copybit_t* handle, int name, int value); - - int (*get)(struct copybit_t* handle, int name); - - int (*blit)( - struct copybit_t* handle, - struct copybit_image_t const* dst, - struct copybit_image_t const* src, - struct copybit_region_t const* region); - - int (*stretch)( - struct copybit_t* handle, - struct copybit_image_t const* dst, - struct copybit_image_t const* src, - struct copybit_rect_t const* dst_rect, - struct copybit_rect_t const* src_rect, - struct copybit_region_t const* region); -}; - -/******************************************************************************/ - -struct copybit_t* copybit_init(); - -int copybit_term(struct copybit_t* handle); - - -/******************************************************************************/ - -#if __cplusplus -} // extern "C" -#endif - -#endif // ANDROID_BLIT_HARDWARE_H diff --git a/include/ui/Camera.h b/include/ui/Camera.h index 562a0a2..124f07f 100644 --- a/include/ui/Camera.h +++ b/include/ui/Camera.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2008 The Android Open Source Project + * Copyright (C) 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. @@ -21,6 +22,39 @@ namespace android { +/* + * A set of bit masks for specifying how the received frames from preview are + * handled before the frame callback call. + * + * The least significant 3 bits of an "int" value are used for this purpose: + * + * ..... 0 0 0 + * ^ ^ ^ + * | | |---------> determine whether the callback is enabled or not + * | |-----------> determine whether the callback is one-shot or not + * |-------------> determine whether the frame is copied out or not + * + * For instance, + * 1. 0x00 disables the callback. In this case, copy out and one shot bits + * are ignored. + * 2. 0x01 enables a callback without copying out the recievied frames. A + * typical use case is the Camcorder application to avoid making costly + * frame copies. + * 3. 0x05 is enabling a callback with frame copied out repeatedly. A typical + * use case is the Camera application. + * 4. 0x07 is enabling a callback with frame copied out only once. A typical use + * case is the Barcode scanner application. + */ +#define FRAME_CALLBACK_FLAG_ENABLE_MASK 0x01 +#define FRAME_CALLBACK_FLAG_ONE_SHOT_MASK 0x02 +#define FRAME_CALLBACK_FLAG_COPY_OUT_MASK 0x04 + +// Typical use cases +#define FRAME_CALLBACK_FLAG_NOOP 0x00 +#define FRAME_CALLBACK_FLAG_CAMCORDER 0x01 +#define FRAME_CALLBACK_FLAG_CAMERA 0x05 +#define FRAME_CALLBACK_FLAG_BARCODE_SCANNER 0x07 + class ICameraService; class ICamera; class Surface; @@ -35,15 +69,21 @@ typedef void (*error_callback)(status_t err, void *cookie); class Camera : public BnCameraClient, public IBinder::DeathRecipient { public: + // construct a camera client from an existing remote + Camera(const sp<ICamera>& camera); + static sp<Camera> connect(); ~Camera(); + void init(); + status_t reconnect(); void disconnect(); status_t getStatus() { return mStatus; } // pass the buffered ISurface to the camera service status_t setPreviewDisplay(const sp<Surface>& surface); + status_t setPreviewDisplay(const sp<ISurface>& surface); // start preview mode, must call setPreviewDisplay first status_t startPreview(); @@ -66,7 +106,11 @@ public: void setShutterCallback(shutter_callback cb, void *cookie); void setRawCallback(frame_callback cb, void *cookie); void setJpegCallback(frame_callback cb, void *cookie); - void setFrameCallback(frame_callback cb, void *cookie); + + void setFrameCallback(frame_callback cb, + void *cookie, + int frame_callback_flag = FRAME_CALLBACK_FLAG_NOOP); + void setErrorCallback(error_callback cb, void *cookie); void setAutoFocusCallback(autofocus_callback cb, void *cookie); // ICameraClient interface @@ -77,7 +121,8 @@ public: virtual void errorCallback(status_t error); virtual void autoFocusCallback(bool focused); - + sp<ICamera> remote(); + private: Camera(); virtual void binderDied(const wp<IBinder>& who); @@ -85,14 +130,14 @@ private: class DeathNotifier: public IBinder::DeathRecipient { public: - DeathNotifier() { + DeathNotifier() { } - + virtual void binderDied(const wp<IBinder>& who); }; - + static sp<DeathNotifier> mDeathNotifier; - + // helper function to obtain camera service handle static const sp<ICameraService>& getCameraService(); @@ -111,12 +156,12 @@ private: void *mErrorCallbackCookie; autofocus_callback mAutoFocusCallback; void *mAutoFocusCallbackCookie; - + friend class DeathNotifier; static Mutex mLock; static sp<ICameraService> mCameraService; - + }; }; // namespace android diff --git a/include/ui/CameraHardwareInterface.h b/include/ui/CameraHardwareInterface.h index 5fa933f..14ac96e 100644 --- a/include/ui/CameraHardwareInterface.h +++ b/include/ui/CameraHardwareInterface.h @@ -39,48 +39,42 @@ typedef void (*jpeg_callback)(const sp<IMemory>& mem, void* user); typedef void (*autofocus_callback)(bool focused, void* user); /** - * This defines the interface to the camera hardware abstraction - * layer. It supports setting and getting parameters, live - * previewing and taking pictures. It is a referenced counted - * interface with RefBase as its base class. + * CameraHardwareInterface.h defines the interface to the + * camera hardware abstraction layer, used for setting and getting + * parameters, live previewing, and taking pictures. * - * The openCameraHardware function is used to - * retrieve a strong pointer to the instance of this interface - * and may be called multiple times. + * It is a referenced counted interface with RefBase as its base class. + * CameraService calls openCameraHardware() to retrieve a strong pointer to the + * instance of this interface and may be called multiple times. The + * following steps describe a typical sequence: * - * After calling openCameraHardware the getParameters and - * setParameters are used to initialize the camera instance. + * -# After CameraService calls openCameraHardware(), getParameters() and + * setParameters() are used to initialize the camera instance. + * CameraService calls getPreviewHeap() to establish access to the + * preview heap so it can be registered with SurfaceFlinger for + * efficient display updating while in preview mode. + * -# startPreview() is called, which is passed a preview_callback() + * function and a user parameter. The camera instance then periodically + * calls preview_callback() each time a new preview frame is available. + * The callback routine has two parameters: the first is a pointer to + * the IMemory containing the frame and the second a user parameter. If + * the preview_callback code needs to use this memory after returning, + * it must copy the data. * - * Then getPreviewHeap is called to get access to the preview - * heap so it can be registered with the SurfaceFlinger for efficient - * display updating while in the preview mode. + * Prior to taking a picture, CameraService calls autofocus() with + * autofocus_callback() and a user parameter. When auto focusing has + * completed, the camera instance calls autofocus_callback(), which informs + * the application whether focusing was successful. The camera instance + * only calls autofocus_callback() once and it is up to the application to + * call autoFocus() again if refocusing is desired. * - * Next startPreview is called which is passed a preview_callback - * function and a user parameter. The camera instance then - * periodically calls preview_callback each time a new - * preview frame is available. The call back routine has - * two parameters, the first is a pointer to the the IMemory containing - * the frame and the other is the user parameter. If the preview_callback - * code needs to use this memory after returning it must copy - * the data. - * - * Prior to taking a picture the autoFocus method is usually called with a - * autofocus_callback and a user parameter. When auto focusing - * has completed the camera instance calls autofocus_callback which - * informs the application if focusing was successful or not. - * The camera instance only calls the autofocus_callback once and it - * is up to the application to call autoFocus again if refocusing is desired. - * - * The method takePicture is called to request that the camera instance take a - * picture. This method has three callbacks: shutter_callback, raw_callback, - * and jpeg_callback. As soon as the shutter snaps and it is safe to move the - * camera, shutter_callback is called. Typically, you would want to play the - * shutter sound at this moment. Later, when the raw image is available the - * raw_callback is called with a pointer to the IMemory containing the raw - * image. Finally, when the encoded jpeg image is available the jpeg_callback - * will be called with a pointer to the IMemory containing the jpeg image. As - * with the preview_callback the memory must be copied if it's needed after - * returning. + * CameraService calls takePicture() to request the camera instance take a + * picture. This method has two callbacks: raw_callback() and jpeg_callback(). + * When the raw image is available, raw_callback() is called with a pointer + * to the IMemory containing the raw image. When the jpeg image is available, + * jpeg_callback() is called with a pointer to the IMemory containing the + * jpeg image. As with preview_callback(), the memory must be copied if it's + * needed after returning. */ class CameraHardwareInterface : public virtual RefBase { public: @@ -104,7 +98,7 @@ public: /** * Start auto focus, the callback routine is called * once when focusing is complete. autoFocus() will - * be called agained if another auto focus is needed. + * be called again if another auto focus is needed. */ virtual status_t autoFocus(autofocus_callback, void* user) = 0; diff --git a/include/ui/EGLDisplaySurface.h b/include/ui/EGLDisplaySurface.h index a9cfd5a..0190e09 100644 --- a/include/ui/EGLDisplaySurface.h +++ b/include/ui/EGLDisplaySurface.h @@ -23,11 +23,12 @@ #include <utils/Timers.h> #include <ui/EGLNativeSurface.h> -#include <ui/BlitHardware.h> #include <pixelflinger/pixelflinger.h> #include <linux/fb.h> +struct copybit_device_t; + // --------------------------------------------------------------------------- namespace android { // --------------------------------------------------------------------------- @@ -71,7 +72,7 @@ private: int32_t mSwapCount; nsecs_t mSleep; uint32_t mFeatureFlags; - copybit_t* mBlitEngine; + copybit_device_t* mBlitEngine; }; // --------------------------------------------------------------------------- diff --git a/include/ui/ICamera.h b/include/ui/ICamera.h index 6aa3940..99c0d86 100644 --- a/include/ui/ICamera.h +++ b/include/ui/ICamera.h @@ -20,13 +20,15 @@ #include <utils/RefBase.h> #include <utils/IInterface.h> #include <utils/Parcel.h> - #include <ui/ISurface.h> #include <utils/IMemory.h> #include <utils/String8.h> +#include <ui/Camera.h> namespace android { +class ICameraClient; + class ICamera: public IInterface { public: @@ -34,11 +36,15 @@ public: virtual void disconnect() = 0; + // connect new client with existing camera remote + virtual status_t connect(const sp<ICameraClient>& client) = 0; + // pass the buffered ISurface to the camera service virtual status_t setPreviewDisplay(const sp<ISurface>& surface) = 0; - - // tell the service whether to callback with each preview frame - virtual void setHasFrameCallback(bool installed) = 0; + + // set the frame callback flag to affect how the received frames from + // preview are handled. + virtual void setFrameCallbackFlag(int frame_callback_flag) = 0; // start preview mode, must call setPreviewDisplay first virtual status_t startPreview() = 0; diff --git a/include/ui/IOverlay.h b/include/ui/IOverlay.h new file mode 100644 index 0000000..323ff07 --- /dev/null +++ b/include/ui/IOverlay.h @@ -0,0 +1,55 @@ +/* + * 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_IOVERLAY_H +#define ANDROID_IOVERLAY_H + +#include <stdint.h> +#include <sys/types.h> + +#include <utils/Errors.h> +#include <utils/IInterface.h> +#include <utils/RefBase.h> +#include <ui/PixelFormat.h> + +namespace android { + +class IOverlay : public IInterface +{ +public: + DECLARE_META_INTERFACE(Overlay); + + virtual void destroy() = 0; // one-way + + virtual ssize_t swapBuffers() = 0; +}; + +// ---------------------------------------------------------------------------- + +class BnOverlay : public BnInterface<IOverlay> +{ +public: + virtual status_t onTransact( uint32_t code, + const Parcel& data, + Parcel* reply, + uint32_t flags = 0); +}; + +// ---------------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_IOVERLAY_H diff --git a/include/ui/ISurface.h b/include/ui/ISurface.h index ca691f5..ff031d5 100644 --- a/include/ui/ISurface.h +++ b/include/ui/ISurface.h @@ -30,6 +30,7 @@ namespace android { typedef int32_t SurfaceID; class IMemoryHeap; +class Overlay; class ISurface : public IInterface { @@ -42,6 +43,9 @@ public: virtual void postBuffer(ssize_t offset) = 0; // one-way virtual void unregisterBuffers() = 0; + + virtual sp<Overlay> createOverlay( + uint32_t w, uint32_t h, int32_t format) = 0; }; // ---------------------------------------------------------------------------- diff --git a/include/ui/ISurfaceFlingerClient.h b/include/ui/ISurfaceFlingerClient.h index bb2d39f..5b9361d 100644 --- a/include/ui/ISurfaceFlingerClient.h +++ b/include/ui/ISurfaceFlingerClient.h @@ -52,7 +52,6 @@ public: struct surface_data_t { int32_t token; int32_t identity; - int32_t type; sp<IMemoryHeap> heap[2]; status_t readFromParcel(const Parcel& parcel); status_t writeToParcel(Parcel* parcel) const; diff --git a/include/ui/KeycodeLabels.h b/include/ui/KeycodeLabels.h index 747925d..53c1188 100644 --- a/include/ui/KeycodeLabels.h +++ b/include/ui/KeycodeLabels.h @@ -107,12 +107,18 @@ static const KeycodeLabel KEYCODES[] = { { "MENU", 82 }, { "NOTIFICATION", 83 }, { "SEARCH", 84 }, + { "PLAYPAUSE", 85 }, + { "STOP", 86 }, + { "NEXTSONG", 87 }, + { "PREVIOUSSONG", 88 }, + { "REWIND", 89 }, + { "FORWARD", 90 }, // NOTE: If you add a new keycode here you must also add it to: // (enum KeyCode, in this file) - // java/android/android/view/KeyEvent.java + // frameworks/base/core/java/android/view/KeyEvent.java // tools/puppet_master/PuppetMaster.nav_keys.py - // apps/common/res/values/attrs.xml + // frameworks/base/core/res/res/values/attrs.xml { NULL, 0 } }; @@ -204,7 +210,13 @@ typedef enum KeyCode { kKeyCodePlus = 81, kKeyCodeMenu = 82, kKeyCodeNotification = 83, - kKeyCodeSearch = 84 + kKeyCodeSearch = 84, + kKeyCodePlayPause = 85, + kKeyCodeStop = 86, + kKeyCodeNextSong = 87, + kKeyCodePreviousSong = 88, + kKeyCodeRewind = 89, + kKeyCodeForward = 90 } KeyCode; static const KeycodeLabel FLAGS[] = { diff --git a/include/ui/Overlay.h b/include/ui/Overlay.h new file mode 100644 index 0000000..f24780f --- /dev/null +++ b/include/ui/Overlay.h @@ -0,0 +1,88 @@ +/* + * 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_OVERLAY_H +#define ANDROID_OVERLAY_H + +#include <stdint.h> +#include <sys/types.h> + +#include <utils/Errors.h> +#include <utils/IInterface.h> +#include <utils/RefBase.h> +#include <ui/PixelFormat.h> + +#include <hardware/overlay.h> + +namespace android { + +class IOverlay; +class IMemory; +class IMemoryHeap; + +class Overlay : public virtual RefBase +{ +public: + Overlay(overlay_t* overlay, + const sp<IOverlay>& o, const sp<IMemoryHeap>& heap); + + /* destroys this overlay */ + void destroy(); + + /* post/swaps buffers */ + status_t swapBuffers(); + + /* get the HAL handle for this overlay */ + overlay_handle_t const* getHandleRef() const; + + /* returns the offset of the current buffer */ + size_t getBufferOffset() const; + + /* returns a heap to this overlay. this may not be supported. */ + sp<IMemoryHeap> getHeap() const; + + /* get physical informations about the overlay */ + uint32_t getWidth() const; + uint32_t getHeight() const; + int32_t getFormat() const; + int32_t getWidthStride() const; + int32_t getHeightStride() const; + + static sp<Overlay> readFromParcel(const Parcel& data); + static status_t writeToParcel(Parcel* reply, const sp<Overlay>& o); + +private: + Overlay(overlay_handle_t*, const sp<IOverlay>&, const sp<IMemoryHeap>&, + uint32_t w, uint32_t h, int32_t f, uint32_t ws, uint32_t hs); + + virtual ~Overlay(); + + sp<IOverlay> mOverlay; + sp<IMemoryHeap> mHeap; + size_t mCurrentBufferOffset; + overlay_handle_t const *mOverlayHandle; + uint32_t mWidth; + uint32_t mHeight; + int32_t mFormat; + int32_t mWidthStride; + int32_t mHeightStride; +}; + +// ---------------------------------------------------------------------------- + +}; // namespace android + +#endif // ANDROID_OVERLAY_H diff --git a/include/ui/PixelFormat.h b/include/ui/PixelFormat.h index d56a4a7..c61df32 100644 --- a/include/ui/PixelFormat.h +++ b/include/ui/PixelFormat.h @@ -61,6 +61,7 @@ enum { PIXEL_FORMAT_RGBX_8888 = GGL_PIXEL_FORMAT_RGBX_8888, // 4x8-bit RGB0 PIXEL_FORMAT_RGB_888 = GGL_PIXEL_FORMAT_RGB_888, // 3x8-bit RGB PIXEL_FORMAT_RGB_565 = GGL_PIXEL_FORMAT_RGB_565, // 16-bit RGB + PIXEL_FORMAT_BGRA_8888 = GGL_PIXEL_FORMAT_BGRA_8888, // 4x8-bit BGRA PIXEL_FORMAT_RGBA_5551 = GGL_PIXEL_FORMAT_RGBA_5551, // 16-bit ARGB PIXEL_FORMAT_RGBA_4444 = GGL_PIXEL_FORMAT_RGBA_4444, // 16-bit ARGB PIXEL_FORMAT_A_8 = GGL_PIXEL_FORMAT_A_8, // 8-bit A diff --git a/include/ui/Region.h b/include/ui/Region.h index a86e630..a0c4608 100644 --- a/include/ui/Region.h +++ b/include/ui/Region.h @@ -24,7 +24,8 @@ #include <utils/Parcel.h> #include <ui/Rect.h> -#include <ui/BlitHardware.h> + +#include <hardware/copybit.h> #include <corecg/SkRegion.h> @@ -166,7 +167,6 @@ private: } mutable Region::iterator i; }; - // --------------------------------------------------------------------------- }; // namespace android diff --git a/include/ui/Surface.h b/include/ui/Surface.h index 0a75bf3..2e24f86 100644 --- a/include/ui/Surface.h +++ b/include/ui/Surface.h @@ -48,7 +48,7 @@ public: void* base; uint32_t reserved[2]; }; - + bool isValid() const { return this && mToken>=0 && mClient!=0; } SurfaceID ID() const { return mToken; } @@ -59,18 +59,17 @@ public: void* heapBase(int i) const; uint32_t getFlags() const { return mFlags; } - int getMemoryType() const { return mMemoryType; } - + // setSwapRectangle() is mainly used by EGL void setSwapRectangle(const Rect& r); const Rect& swapRectangle() const; status_t nextBuffer(SurfaceInfo* info); - + sp<Surface> dup() const; static sp<Surface> readFromParcel(Parcel* parcel); static status_t writeToParcel(const sp<Surface>& surface, Parcel* parcel); static bool isSameSurface(const sp<Surface>& lhs, const sp<Surface>& rhs); - + status_t setLayer(int32_t layer); status_t setPosition(int32_t x, int32_t y); status_t setSize(uint32_t w, uint32_t h); @@ -83,13 +82,14 @@ public: status_t setAlpha(float alpha=1.0f); status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy); status_t setFreezeTint(uint32_t tint); - + uint32_t getIdentity() const { return mIdentity; } private: friend class SurfaceComposerClient; - // camera needs access to the ISurface binder interface for preview + // camera and camcorder need access to the ISurface binder interface for preview friend class Camera; + friend class MediaRecorder; // mediaplayer needs access to ISurface for display friend class MediaPlayer; const sp<ISurface>& getISurface() const { return mSurface; } @@ -98,19 +98,19 @@ private: Surface& operator = (Surface& rhs); Surface(const Surface& rhs); - Surface(const sp<SurfaceComposerClient>& client, + Surface(const sp<SurfaceComposerClient>& client, const sp<ISurface>& surface, const ISurfaceFlingerClient::surface_data_t& data, uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, bool owner = true); - + Surface(Surface const* rhs); ~Surface(); Region dirtyRegion() const; void setDirtyRegion(const Region& region) const; - + // this locks protects calls to lockSurface() / unlockSurface() // and is called by SurfaceComposerClient. Mutex& getLock() const { return mSurfaceLock; } @@ -118,7 +118,6 @@ private: sp<SurfaceComposerClient> mClient; sp<ISurface> mSurface; sp<IMemoryHeap> mHeap[2]; - int mMemoryType; SurfaceID mToken; uint32_t mIdentity; PixelFormat mFormat; diff --git a/include/utils/IPCThreadState.h b/include/utils/IPCThreadState.h index 47043b8..0490fd3 100644 --- a/include/utils/IPCThreadState.h +++ b/include/utils/IPCThreadState.h @@ -20,6 +20,7 @@ #include <utils/Errors.h> #include <utils/Parcel.h> #include <utils/ProcessState.h> +#include <utils/Vector.h> #ifdef HAVE_WIN32_PROC typedef int uid_t; @@ -92,6 +93,8 @@ private: void* cookie); const sp<ProcessState> mProcess; + Vector<BBinder*> mPendingStrongDerefs; + Vector<RefBase::weakref_type*> mPendingWeakDerefs; Parcel mIn; Parcel mOut; diff --git a/include/utils/MemoryHeapPmem.h b/include/utils/MemoryHeapPmem.h index b694b20..60335ad 100644 --- a/include/utils/MemoryHeapPmem.h +++ b/include/utils/MemoryHeapPmem.h @@ -23,7 +23,7 @@ #include <utils/MemoryDealer.h> #include <utils/MemoryHeapBase.h> #include <utils/IMemory.h> -#include <utils/Vector.h> +#include <utils/SortedVector.h> namespace android { @@ -31,11 +31,21 @@ class MemoryHeapBase; // --------------------------------------------------------------------------- -class SubRegionMemory; - class MemoryHeapPmem : public HeapInterface, public MemoryHeapBase { public: + class MemoryPmem : public BnMemory { + public: + MemoryPmem(const sp<MemoryHeapPmem>& heap); + ~MemoryPmem(); + protected: + const sp<MemoryHeapPmem>& getHeap() const { return mClientHeap; } + private: + friend class MemoryHeapPmem; + virtual void revoke() = 0; + sp<MemoryHeapPmem> mClientHeap; + }; + MemoryHeapPmem(const sp<MemoryHeapBase>& pmemHeap, uint32_t flags = IMemoryHeap::MAP_ONCE); ~MemoryHeapPmem(); @@ -51,11 +61,16 @@ public: /* revoke all allocations made by this heap */ virtual void revoke(); - + +private: + /* use this to create your own IMemory for mapMemory */ + virtual sp<MemoryPmem> createMemory(size_t offset, size_t size); + void remove(const wp<MemoryPmem>& memory); + private: sp<MemoryHeapBase> mParentHeap; mutable Mutex mLock; - Vector< wp<SubRegionMemory> > mAllocations; + SortedVector< wp<MemoryPmem> > mAllocations; }; diff --git a/include/utils/ResourceTypes.h b/include/utils/ResourceTypes.h index 31b9aa8..2d56e3e 100644 --- a/include/utils/ResourceTypes.h +++ b/include/utils/ResourceTypes.h @@ -140,8 +140,6 @@ struct Res_png_9patch void serialize(void* outData); // Deserialize/Unmarshall the patch data static Res_png_9patch* deserialize(const void* data); - // Deserialize/Unmarshall the patch data into a newly malloc-ed block - static void deserialize(const void* data, Res_png_9patch* outData); // Compute the size of the serialized data structure size_t serializedSize(); }; @@ -860,6 +858,7 @@ struct ResTable_config KEYSHIDDEN_ANY = 0x0000, KEYSHIDDEN_NO = 0x0001, KEYSHIDDEN_YES = 0x0002, + KEYSHIDDEN_SOFT = 0x0003, }; union { @@ -989,11 +988,20 @@ struct ResTable_config return diffs; } - // Return true if 'this' is more specific than 'o'. + // Return true if 'this' is more specific than 'o'. Optionally, if + // 'requested' is null, then they will also be compared against the + // requested configuration and true will only be returned if 'this' + // is a better candidate than 'o' for the configuration. This assumes that + // match() has already been used to remove any configurations that don't + // match the requested configuration at all; if they are not first filtered, + // non-matching results can be considered better than matching ones. inline bool isBetterThan(const ResTable_config& o, const ResTable_config* requested = NULL) const { + // The order of the following tests defines the importance of one + // configuration parameter over another. Those tests first are more + // important, trumping any values in those following them. if (imsi != 0 && (!requested || requested->imsi != 0)) { - if (mcc != 0 && (!requested || requested->mcc!= 0)) { + if (mcc != 0 && (!requested || requested->mcc != 0)) { if (o.mcc == 0) { return true; } @@ -1034,9 +1042,24 @@ struct ResTable_config } } if (input != 0 && (!requested || requested->input != 0)) { - if ((inputFlags&MASK_KEYSHIDDEN) != 0 && (!requested - || (requested->inputFlags&MASK_KEYSHIDDEN) != 0)) { - if ((o.inputFlags&MASK_KEYSHIDDEN) == 0) { + const int keysHidden = inputFlags&MASK_KEYSHIDDEN; + const int reqKeysHidden = requested + ? requested->inputFlags&MASK_KEYSHIDDEN : 0; + if (keysHidden != 0 && reqKeysHidden != 0) { + const int oKeysHidden = o.inputFlags&MASK_KEYSHIDDEN; + //LOGI("isBetterThan keysHidden: cur=%d, given=%d, config=%d\n", + // keysHidden, oKeysHidden, reqKeysHidden); + if (oKeysHidden == 0) { + //LOGI("Better because 0!"); + return true; + } + // For compatibility, we count KEYSHIDDEN_NO as being + // the same as KEYSHIDDEN_SOFT. Here we disambiguate these + // may making an exact match more specific. + if (keysHidden == reqKeysHidden && oKeysHidden != reqKeysHidden) { + // The current configuration is an exact match, and + // the given one is not, so the current one is better. + //LOGI("Better because other not same!"); return true; } } @@ -1078,7 +1101,8 @@ struct ResTable_config return false; } - // Return true if 'this' matches the parameters in 'settings'. + // Return true if 'this' can be considered a match for the parameters in + // 'settings'. inline bool match(const ResTable_config& settings) const { if (imsi != 0) { if (settings.mcc != 0 && mcc != 0 @@ -1121,7 +1145,14 @@ struct ResTable_config const int setKeysHidden = settings.inputFlags&MASK_KEYSHIDDEN; if (setKeysHidden != 0 && keysHidden != 0 && keysHidden != setKeysHidden) { - return false; + // For compatibility, we count a request for KEYSHIDDEN_NO as also + // matching the more recent KEYSHIDDEN_SOFT. Basically + // KEYSHIDDEN_NO means there is some kind of keyboard available. + //LOGI("Matching keysHidden: have=%d, config=%d\n", keysHidden, setKeysHidden); + if (keysHidden != KEYSHIDDEN_NO || setKeysHidden != KEYSHIDDEN_SOFT) { + //LOGI("No match!"); + return false; + } } if (settings.keyboard != 0 && keyboard != 0 && keyboard != settings.keyboard) { diff --git a/include/utils/TimeUtils.h b/include/utils/TimeUtils.h index 30e5330..b19e021 100644 --- a/include/utils/TimeUtils.h +++ b/include/utils/TimeUtils.h @@ -17,10 +17,11 @@ #ifndef ANDROID_TIME_H #define ANDROID_TIME_H +#include <time.h> +#include <cutils/tztime.h> #include <stdint.h> #include <sys/types.h> #include <sys/time.h> -#include <time.h> #include <utils/String8.h> #include <utils/String16.h> @@ -58,7 +59,7 @@ public: Time(); void switchTimezone(const char *timezone); - String8 format(const char *format) const; + String8 format(const char *format, const struct strftime_locale *locale) const; void format2445(short* buf, bool hasTime) const; String8 toString() const; void setToNow(); diff --git a/include/utils/string_array.h b/include/utils/string_array.h index ede0644..064dda2 100644 --- a/include/utils/string_array.h +++ b/include/utils/string_array.h @@ -111,6 +111,19 @@ public: return mArray[idx]; } + // + // Set entry N to specified string. + // [should use operator[] here] + // + void setEntry(int idx, const char* str) { + if (idx < 0 || idx >= mCurrent) + return; + delete[] mArray[idx]; + int len = strlen(str); + mArray[idx] = new char[len+1]; + memcpy(mArray[idx], str, len+1); + } + private: int mMax; int mCurrent; |