summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
commit2729ea9262ca60d93047e984739887cfc89e82eb (patch)
tree25962a3f1c5f70586af45c926c037e03c643857f /include
downloadframeworks_av-2729ea9262ca60d93047e984739887cfc89e82eb.zip
frameworks_av-2729ea9262ca60d93047e984739887cfc89e82eb.tar.gz
frameworks_av-2729ea9262ca60d93047e984739887cfc89e82eb.tar.bz2
Initial Contribution
Diffstat (limited to 'include')
-rw-r--r--include/media/AudioRecord.h235
-rw-r--r--include/media/AudioSystem.h122
-rw-r--r--include/media/AudioTrack.h277
-rw-r--r--include/media/IAudioFlinger.h124
-rw-r--r--include/media/IAudioRecord.h68
-rw-r--r--include/media/IAudioTrack.h84
-rw-r--r--include/media/IMediaPlayer.h65
-rw-r--r--include/media/IMediaPlayerClient.h48
-rw-r--r--include/media/IMediaPlayerService.h54
-rw-r--r--include/media/MediaPlayerInterface.h156
-rw-r--r--include/media/PVPlayer.h75
-rw-r--r--include/media/ToneGenerator.h175
-rw-r--r--include/media/mediametadataretriever.h101
-rw-r--r--include/media/mediaplayer.h138
-rw-r--r--include/media/mediarecorder.h120
-rw-r--r--include/media/mediascanner.h63
-rw-r--r--include/media/thread_init.h25
-rw-r--r--include/private/media/AudioTrackShared.h64
-rw-r--r--include/private/opengles/gl_context.h624
-rw-r--r--include/private/ui/LayerState.h75
-rw-r--r--include/private/ui/SharedState.h168
-rw-r--r--include/private/ui/SurfaceFlingerSynchro.h76
-rw-r--r--include/private/utils/Static.h58
-rw-r--r--include/private/utils/binder_module.h148
-rw-r--r--include/private/utils/futex_synchro.h60
25 files changed, 3203 insertions, 0 deletions
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h
new file mode 100644
index 0000000..008569f
--- /dev/null
+++ b/include/media/AudioRecord.h
@@ -0,0 +1,235 @@
+/*
+ * 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 AUDIORECORD_H_
+#define AUDIORECORD_H_
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <media/IAudioFlinger.h>
+#include <media/IAudioRecord.h>
+#include <media/AudioTrack.h>
+
+#include <utils/RefBase.h>
+#include <utils/Errors.h>
+#include <utils/IInterface.h>
+#include <utils/IMemory.h>
+#include <utils/threads.h>
+
+
+namespace android {
+
+// ----------------------------------------------------------------------------
+
+class AudioRecord
+{
+public:
+
+ enum stream_type {
+ DEFAULT_INPUT =-1,
+ MIC_INPUT = 0,
+ NUM_STREAM_TYPES
+ };
+
+ static const int DEFAULT_SAMPLE_RATE = 8000;
+
+ /* Create Buffer on the stack and pass it to obtainBuffer()
+ * and releaseBuffer().
+ */
+
+ class Buffer
+ {
+ public:
+ enum {
+ MUTE = 0x00000001
+ };
+ uint32_t flags;
+ int channelCount;
+ int format;
+ size_t frameCount;
+ size_t size;
+ union {
+ void* raw;
+ short* i16;
+ int8_t* i8;
+ };
+ };
+
+ /* These are static methods to control the system-wide AudioFlinger
+ * only privileged processes can have access to them
+ */
+
+// 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.
+ */
+ typedef bool (*callback_t)(void* user, const Buffer& 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.
+ */
+
+ AudioRecord(int streamType = 0,
+ uint32_t sampleRate = 0,
+ int format = 0,
+ int channelCount = 0,
+ int bufferCount = 0,
+ uint32_t flags = 0,
+ callback_t cbf = 0, void* user = 0);
+
+
+ /* Terminates the AudioRecord and unregisters it from AudioFlinger.
+ * Also destroys all resources assotiated with the AudioRecord.
+ */
+ ~AudioRecord();
+
+
+ /* Initialize an uninitialized AudioRecord. */
+ status_t set(int streamType = 0,
+ uint32_t sampleRate = 0,
+ int format = 0,
+ int channelCount = 0,
+ int bufferCount = 0,
+ uint32_t flags = 0,
+ callback_t cbf = 0, void* user = 0);
+
+
+ /* Result of constructing the AudioRecord. This must be checked
+ * before using any AudioRecord API (except for set()), using
+ * an uninitialized AudioRecord prduces undefined results.
+ */
+ 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.
+ */
+ nsecs_t latency() const;
+
+ /* getters, see constructor */
+
+ uint32_t sampleRate() const;
+ int format() const;
+ int channelCount() const;
+ int bufferCount() const;
+
+
+ /* After it's created the track is not active. Call start() to
+ * make it active. If set, the callback will start being called.
+ */
+ status_t start();
+
+ /* Stop a track. If set, the callback will cease being called and
+ * obtainBuffer returns STOPPED. Note that obtainBuffer() still works
+ * and will fill up buffers until the pool is exhausted.
+ */
+ status_t stop();
+ bool stopped() const;
+
+ /* get sample rate for this track
+ */
+ uint32_t getSampleRate();
+
+ /* 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
+ * or return WOULD_BLOCK depending on the value of the "blocking"
+ * 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.
+ */
+ ssize_t read(void* buffer, size_t size);
+
+private:
+ /* copying audio tracks is not allowed */
+ AudioRecord(const AudioRecord& other);
+ AudioRecord& operator = (const AudioRecord& other);
+
+ /* a small internal class to handle the callback */
+ class ClientRecordThread : public Thread
+ {
+ public:
+ ClientRecordThread(AudioRecord& receiver);
+ private:
+ friend class AudioRecord;
+ virtual bool threadLoop();
+ virtual status_t readyToRun() { return NO_ERROR; }
+ virtual void onFirstRef() {}
+ AudioRecord& mReceiver;
+ };
+
+ bool processAudioBuffer(const sp<ClientRecordThread>& thread);
+
+ sp<IAudioFlinger> mAudioFlinger;
+ sp<IAudioRecord> mAudioRecord;
+ sp<IMemory> mCblkMemory;
+ sp<ClientRecordThread> mClientRecordThread;
+ Mutex mRecordThreadLock;
+
+ uint32_t mSampleRate;
+ size_t mFrameCount;
+
+ audio_track_cblk_t* mCblk;
+ uint8_t mFormat;
+ uint8_t mBufferCount;
+ uint8_t mChannelCount : 4;
+ uint8_t mReserved : 3;
+ status_t mStatus;
+ nsecs_t mLatency;
+
+ volatile int32_t mActive;
+
+ callback_t mCbf;
+ void* mUserData;
+
+ AudioRecord::Buffer mAudioBuffer;
+ size_t mPosition;
+
+ uint32_t mReservedFBC[4];
+};
+
+}; // namespace android
+
+#endif /*AUDIORECORD_H_*/
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
new file mode 100644
index 0000000..9fcbea5
--- /dev/null
+++ b/include/media/AudioSystem.h
@@ -0,0 +1,122 @@
+/*
+ * 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_AUDIOSYSTEM_H_
+#define ANDROID_AUDIOSYSTEM_H_
+
+#include <utils/RefBase.h>
+#include <utils/threads.h>
+#include <media/IAudioFlinger.h>
+
+namespace android {
+
+typedef void (*audio_error_callback)(status_t err);
+
+class AudioSystem
+{
+public:
+
+ enum audio_format {
+ DEFAULT = 0,
+ PCM_16_BIT,
+ PCM_8_BIT,
+ INVALID_FORMAT
+ };
+
+ enum audio_mode {
+ MODE_INVALID = -2,
+ MODE_CURRENT = -1,
+ MODE_NORMAL = 0,
+ MODE_RINGTONE,
+ MODE_IN_CALL,
+ NUM_MODES // not a valid entry, denotes end-of-list
+ };
+
+ enum audio_routes {
+ ROUTE_EARPIECE = (1 << 0),
+ ROUTE_SPEAKER = (1 << 1),
+ ROUTE_BLUETOOTH = (1 << 2),
+ ROUTE_HEADSET = (1 << 3),
+ ROUTE_ALL = (ROUTE_EARPIECE | ROUTE_SPEAKER | ROUTE_BLUETOOTH | ROUTE_HEADSET)
+ };
+
+ /* These are static methods to control the system-wide AudioFlinger
+ * only privileged processes can have access to them
+ */
+
+ // routing helper functions
+ static status_t speakerphone(bool state);
+ static status_t isSpeakerphoneOn(bool* state);
+ static status_t bluetoothSco(bool state);
+ static status_t isBluetoothScoOn(bool* state);
+ static status_t muteMicrophone(bool state);
+ static status_t isMicrophoneMuted(bool *state);
+
+ static status_t setMasterVolume(float value);
+ static status_t setMasterMute(bool mute);
+ static status_t getMasterVolume(float* volume);
+ static status_t getMasterMute(bool* mute);
+
+ static status_t setStreamVolume(int stream, float value);
+ static status_t setStreamMute(int stream, bool mute);
+ static status_t getStreamVolume(int stream, float* volume);
+ static status_t getStreamMute(int stream, bool* mute);
+
+ static status_t setMode(int mode);
+ static status_t getMode(int* mode);
+
+ static status_t setRouting(int mode, uint32_t routes, uint32_t mask);
+ static status_t getRouting(int mode, uint32_t* routes);
+
+ static status_t isMusicActive(bool *state);
+
+ // Temporary interface, do not use
+ // TODO: Replace with a more generic key:value get/set mechanism
+ static status_t setParameter(const char* key, const char* value);
+
+ static void setErrorCallback(audio_error_callback cb);
+
+ // helper function to obtain AudioFlinger service handle
+ static const sp<IAudioFlinger>& get_audio_flinger();
+
+ static float linearToLog(int volume);
+ static int logToLinear(float volume);
+
+ // ----------------------------------------------------------------------------
+
+private:
+
+ class DeathNotifier: public IBinder::DeathRecipient
+ {
+ public:
+ DeathNotifier() {
+ }
+
+ virtual void binderDied(const wp<IBinder>& who);
+ };
+
+ static sp<DeathNotifier> gDeathNotifier;
+
+ friend class DeathNotifier;
+
+ static Mutex gLock;
+ static sp<IAudioFlinger> gAudioFlinger;
+ static audio_error_callback gAudioErrorCallback;
+};
+
+}; // namespace android
+
+#endif /*ANDROID_AUDIOSYSTEM_H_*/
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h
new file mode 100644
index 0000000..a89d7ff
--- /dev/null
+++ b/include/media/AudioTrack.h
@@ -0,0 +1,277 @@
+/*
+ * 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_AUDIOTRACK_H
+#define ANDROID_AUDIOTRACK_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <media/IAudioFlinger.h>
+#include <media/IAudioTrack.h>
+#include <media/AudioSystem.h>
+
+#include <utils/RefBase.h>
+#include <utils/Errors.h>
+#include <utils/IInterface.h>
+#include <utils/IMemory.h>
+#include <utils/threads.h>
+
+
+namespace android {
+
+// ----------------------------------------------------------------------------
+
+class audio_track_cblk_t;
+
+// ----------------------------------------------------------------------------
+
+class AudioTrack
+{
+public:
+
+ enum stream_type {
+ DEFAULT =-1,
+ VOICE_CALL = 0,
+ SYSTEM = 1,
+ RING = 2,
+ MUSIC = 3,
+ ALARM = 4,
+ NUM_STREAM_TYPES
+ };
+
+ enum channel_index {
+ MONO = 0,
+ LEFT = 0,
+ RIGHT = 1
+ };
+
+ /* Create Buffer on the stack and pass it to obtainBuffer()
+ * and releaseBuffer().
+ */
+
+ class Buffer
+ {
+ public:
+ enum {
+ MUTE = 0x00000001
+ };
+ uint32_t flags;
+ int channelCount;
+ int format;
+ size_t frameCount;
+ size_t size;
+ union {
+ void* raw;
+ short* i16;
+ int8_t* i8;
+ };
+ };
+
+ /* 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.
+ */
+ typedef void (*callback_t)(void* user, const Buffer& 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.
+ */
+
+ AudioTrack( int streamType,
+ uint32_t sampleRate = 0,
+ int format = 0,
+ int channelCount = 0,
+ int bufferCount = 0,
+ uint32_t flags = 0,
+ callback_t cbf = 0, void* user = 0);
+
+
+ /* Terminates the AudioTrack and unregisters it from AudioFlinger.
+ * Also destroys all resources assotiated with the AudioTrack.
+ */
+ ~AudioTrack();
+
+
+ /* Initialize an uninitialized AudioTrack. */
+ status_t set(int streamType =-1,
+ uint32_t sampleRate = 0,
+ int format = 0,
+ int channelCount = 0,
+ int bufferCount = 0,
+ uint32_t flags = 0,
+ callback_t cbf = 0, void* user = 0);
+
+
+ /* Result of constructing the AudioTrack. This must be checked
+ * before using any AudioTrack API (except for set()), using
+ * an uninitialized AudoiTrack prduces undefined results.
+ */
+ 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.
+ */
+ nsecs_t latency() const;
+
+ /* getters, see constructor */
+
+ int streamType() const;
+ uint32_t sampleRate() const;
+ int format() const;
+ int channelCount() const;
+ int bufferCount() const;
+
+
+ /* After it's created the track is not active. Call start() to
+ * make it active. If set, the callback will start being called.
+ */
+ void start();
+
+ /* Stop a track. If set, the callback will cease being called and
+ * obtainBuffer returns STOPPED. Note that obtainBuffer() still works
+ * and will fill up buffers until the pool is exhausted.
+ */
+ void stop();
+ bool stopped() const;
+
+ /* flush a stopped track. All pending buffers are discarded.
+ * This function has no effect if the track is not stoped.
+ */
+ void flush();
+
+ /* Pause a track. If set, the callback will cease being called and
+ * obtainBuffer returns STOPPED. Note that obtainBuffer() still works
+ * and will fill up buffers until the pool is exhausted.
+ */
+ void pause();
+
+ /* mute or unmutes this track.
+ * While mutted, the callback, if set, is still called.
+ */
+ void mute(bool);
+ bool muted() const;
+
+
+ /* set volume for this track, mostly used for games' sound effects
+ */
+ void setVolume(float left, float right);
+ void getVolume(float* left, float* right);
+
+ /* set sample rate for this track, mostly used for games' sound effects
+ */
+ void setSampleRate(int sampleRate);
+ uint32_t getSampleRate();
+
+ /* 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
+ * or return WOULD_BLOCK depending on the value of the "blocking"
+ * 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 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.
+ */
+ status_t dump(int fd, const Vector<String16>& args) const;
+
+private:
+ /* copying audio tracks is not allowed */
+ AudioTrack(const AudioTrack& other);
+ AudioTrack& operator = (const AudioTrack& other);
+
+ /* a small internal class to handle the callback */
+ class AudioTrackThread : public Thread
+ {
+ public:
+ AudioTrackThread(AudioTrack& receiver);
+ private:
+ friend class AudioTrack;
+ virtual bool threadLoop();
+ virtual status_t readyToRun();
+ virtual void onFirstRef();
+ 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;
+
+ 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;
+ status_t mStatus;
+ nsecs_t mLatency;
+
+ volatile int32_t mActive;
+
+ callback_t mCbf;
+ void* mUserData;
+
+ AudioTrack::Buffer mAudioBuffer;
+ size_t mPosition;
+
+ uint32_t mReservedFBC[4];
+};
+
+
+}; // namespace android
+
+#endif // ANDROID_AUDIOTRACK_H
diff --git a/include/media/IAudioFlinger.h b/include/media/IAudioFlinger.h
new file mode 100644
index 0000000..fa8e121
--- /dev/null
+++ b/include/media/IAudioFlinger.h
@@ -0,0 +1,124 @@
+/*
+ * 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_IAUDIOFLINGER_H
+#define ANDROID_IAUDIOFLINGER_H
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <utils/RefBase.h>
+#include <utils/Errors.h>
+#include <utils/IInterface.h>
+#include <media/IAudioTrack.h>
+#include <media/IAudioRecord.h>
+
+
+namespace android {
+
+// ----------------------------------------------------------------------------
+
+class IAudioFlinger : public IInterface
+{
+public:
+ DECLARE_META_INTERFACE(AudioFlinger);
+
+ /* create an audio track and registers it with AudioFlinger.
+ * return null if the track cannot be created.
+ */
+ virtual sp<IAudioTrack> createTrack(
+ pid_t pid,
+ int streamType,
+ uint32_t sampleRate,
+ int format,
+ int channelCount,
+ int bufferCount,
+ uint32_t flags) = 0;
+
+ virtual sp<IAudioRecord> openRecord(
+ pid_t pid,
+ int streamType,
+ uint32_t sampleRate,
+ int format,
+ int channelCount,
+ int bufferCount,
+ uint32_t flags) = 0;
+
+ /* query the audio hardware state. This state never changes,
+ * and therefore can be cached.
+ */
+ virtual uint32_t sampleRate() const = 0;
+ virtual int channelCount() const = 0;
+ virtual int format() const = 0;
+ virtual size_t frameCount() const = 0;
+
+ /* set/get the audio hardware state. This will probably be used by
+ * the preference panel, mostly.
+ */
+ virtual status_t setMasterVolume(float value) = 0;
+ virtual status_t setMasterMute(bool muted) = 0;
+
+ virtual float masterVolume() const = 0;
+ virtual bool masterMute() const = 0;
+
+ /* set/get stream type state. This will probably be used by
+ * the preference panel, mostly.
+ */
+ virtual status_t setStreamVolume(int stream, float value) = 0;
+ virtual status_t setStreamMute(int stream, bool muted) = 0;
+
+ virtual float streamVolume(int stream) const = 0;
+ virtual bool streamMute(int stream) const = 0;
+
+ // set/get audio routing
+ virtual status_t setRouting(int mode, uint32_t routes, uint32_t mask) = 0;
+ virtual uint32_t getRouting(int mode) const = 0;
+
+ // set/get audio mode
+ virtual status_t setMode(int mode) = 0;
+ virtual int getMode() const = 0;
+
+ // mic mute/state
+ virtual status_t setMicMute(bool state) = 0;
+ virtual bool getMicMute() const = 0;
+
+ // is a music stream active?
+ virtual bool isMusicActive() const = 0;
+
+ // pass a generic configuration parameter to libaudio
+ // Temporary interface, do not use
+ // TODO: Replace with a more generic key:value get/set mechanism
+ virtual status_t setParameter(const char* key, const char* value) = 0;
+};
+
+
+// ----------------------------------------------------------------------------
+
+class BnAudioFlinger : public BnInterface<IAudioFlinger>
+{
+public:
+ virtual status_t onTransact( uint32_t code,
+ const Parcel& data,
+ Parcel* reply,
+ uint32_t flags = 0);
+};
+
+// ----------------------------------------------------------------------------
+
+}; // namespace android
+
+#endif // ANDROID_IAUDIOFLINGER_H
diff --git a/include/media/IAudioRecord.h b/include/media/IAudioRecord.h
new file mode 100644
index 0000000..9d45d2d
--- /dev/null
+++ b/include/media/IAudioRecord.h
@@ -0,0 +1,68 @@
+/*
+ * 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 IAUDIORECORD_H_
+#define IAUDIORECORD_H_
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <utils/RefBase.h>
+#include <utils/Errors.h>
+#include <utils/IInterface.h>
+#include <utils/IMemory.h>
+
+
+namespace android {
+
+// ----------------------------------------------------------------------------
+
+class IAudioRecord : public IInterface
+{
+public:
+ DECLARE_META_INTERFACE(AudioRecord);
+
+ /* After it's created the track is not active. Call start() to
+ * make it active. If set, the callback will start being called.
+ */
+ virtual status_t start() = 0;
+
+ /* Stop a track. If set, the callback will cease being called and
+ * obtainBuffer will return an error. Buffers that are already released
+ * will be processed, unless flush() is called.
+ */
+ virtual void stop() = 0;
+
+ /* get this tracks control block */
+ virtual sp<IMemory> getCblk() const = 0;
+};
+
+// ----------------------------------------------------------------------------
+
+class BnAudioRecord : public BnInterface<IAudioRecord>
+{
+public:
+ virtual status_t onTransact( uint32_t code,
+ const Parcel& data,
+ Parcel* reply,
+ uint32_t flags = 0);
+};
+
+// ----------------------------------------------------------------------------
+
+}; // namespace android
+
+#endif /*IAUDIORECORD_H_*/
diff --git a/include/media/IAudioTrack.h b/include/media/IAudioTrack.h
new file mode 100644
index 0000000..12f2111
--- /dev/null
+++ b/include/media/IAudioTrack.h
@@ -0,0 +1,84 @@
+/*
+ * 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_IAUDIOTRACK_H
+#define ANDROID_IAUDIOTRACK_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <utils/RefBase.h>
+#include <utils/Errors.h>
+#include <utils/IInterface.h>
+#include <utils/IMemory.h>
+
+
+namespace android {
+
+// ----------------------------------------------------------------------------
+
+class IAudioTrack : public IInterface
+{
+public:
+ DECLARE_META_INTERFACE(AudioTrack);
+
+ /* After it's created the track is not active. Call start() to
+ * make it active. If set, the callback will start being called.
+ */
+ virtual status_t start() = 0;
+
+ /* Stop a track. If set, the callback will cease being called and
+ * obtainBuffer will return an error. Buffers that are already released
+ * will be processed, unless flush() is called.
+ */
+ virtual void stop() = 0;
+
+ /* flush a stopped track. All pending buffers are discarded.
+ * This function has no effect if the track is not stoped.
+ */
+ virtual void flush() = 0;
+
+ /* mute or unmutes this track.
+ * While mutted, the callback, if set, is still called.
+ */
+ virtual void mute(bool) = 0;
+
+ /* Pause a track. If set, the callback will cease being called and
+ * obtainBuffer will return an error. Buffers that are already released
+ * will be processed, unless flush() is called.
+ */
+ virtual void pause() = 0;
+
+ /* get this tracks control block */
+ virtual sp<IMemory> getCblk() const = 0;
+};
+
+// ----------------------------------------------------------------------------
+
+class BnAudioTrack : public BnInterface<IAudioTrack>
+{
+public:
+ virtual status_t onTransact( uint32_t code,
+ const Parcel& data,
+ Parcel* reply,
+ uint32_t flags = 0);
+};
+
+// ----------------------------------------------------------------------------
+
+}; // namespace android
+
+#endif // ANDROID_IAUDIOTRACK_H
diff --git a/include/media/IMediaPlayer.h b/include/media/IMediaPlayer.h
new file mode 100644
index 0000000..43abf77
--- /dev/null
+++ b/include/media/IMediaPlayer.h
@@ -0,0 +1,65 @@
+/*
+ * 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_IMEDIAPLAYER_H
+#define ANDROID_IMEDIAPLAYER_H
+
+#include <utils/RefBase.h>
+#include <utils/IInterface.h>
+#include <utils/Parcel.h>
+
+namespace android {
+
+class ISurface;
+
+class IMediaPlayer: public IInterface
+{
+public:
+ DECLARE_META_INTERFACE(MediaPlayer);
+
+ virtual void disconnect() = 0;
+
+ virtual status_t setVideoSurface(const sp<ISurface>& surface) = 0;
+ virtual status_t prepareAsync() = 0;
+ virtual status_t start() = 0;
+ 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;
+ virtual status_t reset() = 0;
+ virtual status_t setAudioStreamType(int type) = 0;
+ virtual status_t setLooping(int loop) = 0;
+ virtual status_t setVolume(float leftVolume, float rightVolume) = 0;
+};
+
+// ----------------------------------------------------------------------------
+
+class BnMediaPlayer: public BnInterface<IMediaPlayer>
+{
+public:
+ virtual status_t onTransact( uint32_t code,
+ const Parcel& data,
+ Parcel* reply,
+ uint32_t flags = 0);
+};
+
+}; // namespace android
+
+#endif // ANDROID_IMEDIAPLAYER_H
+
diff --git a/include/media/IMediaPlayerClient.h b/include/media/IMediaPlayerClient.h
new file mode 100644
index 0000000..5d32811
--- /dev/null
+++ b/include/media/IMediaPlayerClient.h
@@ -0,0 +1,48 @@
+/*
+ * 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_IMEDIAPLAYERCLIENT_H
+#define ANDROID_IMEDIAPLAYERCLIENT_H
+
+#include <utils/RefBase.h>
+#include <utils/IInterface.h>
+#include <utils/Parcel.h>
+
+namespace android {
+
+class IMediaPlayerClient: public IInterface
+{
+public:
+ DECLARE_META_INTERFACE(MediaPlayerClient);
+
+ virtual void notify(int msg, int ext1, int ext2) = 0;
+};
+
+// ----------------------------------------------------------------------------
+
+class BnMediaPlayerClient: public BnInterface<IMediaPlayerClient>
+{
+public:
+ virtual status_t onTransact( uint32_t code,
+ const Parcel& data,
+ Parcel* reply,
+ uint32_t flags = 0);
+};
+
+}; // namespace android
+
+#endif // ANDROID_IMEDIAPLAYERCLIENT_H
+
diff --git a/include/media/IMediaPlayerService.h b/include/media/IMediaPlayerService.h
new file mode 100644
index 0000000..63c7a00
--- /dev/null
+++ b/include/media/IMediaPlayerService.h
@@ -0,0 +1,54 @@
+/*
+ * 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_IMEDIAPLAYERSERVICE_H
+#define ANDROID_IMEDIAPLAYERSERVICE_H
+
+#include <utils/RefBase.h>
+#include <utils/IInterface.h>
+#include <utils/Parcel.h>
+
+#include <media/IMediaPlayerClient.h>
+#include <media/IMediaPlayer.h>
+
+namespace android {
+
+class IMediaPlayerService: public IInterface
+{
+public:
+ DECLARE_META_INTERFACE(MediaPlayerService);
+
+ 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;
+};
+
+// ----------------------------------------------------------------------------
+
+class BnMediaPlayerService: public BnInterface<IMediaPlayerService>
+{
+public:
+ virtual status_t onTransact( uint32_t code,
+ const Parcel& data,
+ Parcel* reply,
+ uint32_t flags = 0);
+};
+
+}; // namespace android
+
+#endif // ANDROID_IMEDIAPLAYERSERVICE_H
+
diff --git a/include/media/MediaPlayerInterface.h b/include/media/MediaPlayerInterface.h
new file mode 100644
index 0000000..275e789
--- /dev/null
+++ b/include/media/MediaPlayerInterface.h
@@ -0,0 +1,156 @@
+/*
+ * 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_MEDIAPLAYERINTERFACE_H
+#define ANDROID_MEDIAPLAYERINTERFACE_H
+
+#include <pthread.h>
+#include <signal.h>
+
+#ifdef __cplusplus
+
+#include <ui/ISurface.h>
+#include <utils/RefBase.h>
+
+#include <media/mediaplayer.h>
+
+namespace android {
+
+enum player_type {
+ PV_PLAYER = 1,
+ SONIVOX_PLAYER = 2,
+ VORBIS_PLAYER = 3
+};
+
+#define DEFAULT_AUDIOSINK_BUFFERCOUNT 4
+
+// callback mechanism for passing messages to MediaPlayer object
+typedef void (*notify_callback_f)(void* cookie, int msg, int ext1, int ext2);
+
+// abstract base class - use MediaPlayerInterface
+class MediaPlayerBase : public RefBase
+{
+public:
+
+ // AudioSink: abstraction layer for audio output
+ class AudioSink : public RefBase {
+ public:
+ virtual ~AudioSink() {}
+ virtual bool ready() const = 0; // audio output is open and ready
+ virtual bool realtime() const = 0; // audio output is real-time output
+ virtual ssize_t bufferSize() const = 0;
+ virtual ssize_t frameCount() const = 0;
+ virtual ssize_t channelCount() const = 0;
+ 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 void start() = 0;
+ virtual ssize_t write(const void* buffer, size_t size) = 0;
+ virtual void stop() = 0;
+ virtual void flush() = 0;
+ virtual void pause() = 0;
+ virtual void close() = 0;
+ };
+
+ MediaPlayerBase() : mCookie(0), mNotify(0) {}
+ virtual ~MediaPlayerBase() {}
+ virtual status_t initCheck() = 0;
+ virtual bool hardwareOutput() = 0;
+ virtual status_t setSigBusHandlerStructTLSKey(pthread_key_t key) { return 0; }
+ virtual status_t setDataSource(const char *url) = 0;
+ virtual status_t setDataSource(int fd, int64_t offset, int64_t length) = 0;
+ virtual status_t setVideoSurface(const sp<ISurface>& surface) = 0;
+ virtual status_t prepare() = 0;
+ virtual status_t prepareAsync() = 0;
+ virtual status_t start() = 0;
+ 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;
+ virtual status_t reset() = 0;
+ virtual status_t setLooping(int loop) = 0;
+ virtual player_type playerType() = 0;
+ virtual void setNotifyCallback(void* cookie, notify_callback_f notifyFunc) {
+ mCookie = cookie; mNotify = notifyFunc; }
+
+protected:
+ virtual void sendEvent(int msg, int ext1=0, int ext2=0) { if (mNotify) mNotify(mCookie, msg, ext1, ext2); }
+
+ void* mCookie;
+ notify_callback_f mNotify;
+};
+
+// Implement this class for media players that use the AudioFlinger software mixer
+class MediaPlayerInterface : public MediaPlayerBase
+{
+public:
+ virtual ~MediaPlayerInterface() { }
+ virtual bool hardwareOutput() { return false; }
+ virtual void setAudioSink(const sp<AudioSink>& audioSink) { mAudioSink = audioSink; }
+protected:
+ sp<AudioSink> mAudioSink;
+};
+
+// Implement this class for media players that output directo to hardware
+class MediaPlayerHWInterface : public MediaPlayerBase
+{
+public:
+ virtual ~MediaPlayerHWInterface() {}
+ virtual bool hardwareOutput() { return true; }
+ virtual status_t setVolume(float leftVolume, float rightVolume) = 0;
+ virtual status_t setAudioStreamType(int streamType) = 0;
+};
+
+}; // namespace android
+
+#endif // __cplusplus
+
+// A thread can set the thread local variable identified by the pthread_key_t
+// that was passed to the player using the setSigBusHandlerStructTLSKey()
+// method to the address of the following structure.
+// If 'handlesigbus' is non-NULL, the function it points to will be called,
+// and if it returns 0, the signal will be assumed to have been handled,
+// and no other action will be taken. If it returns non-zero, the old SIGBUS
+// handler will be called.
+// If 'handlesigbus is NULL, then sigbusvar must be non NULL. The system's
+// SIGBUS handler will map an accessible page filled with zeroes at the
+// location that caused the original fault, set the variable pointed to by
+// sigbusvar to a non-zero value, and exit (which causes the operation to
+// be retried, which should now succeed).
+// If base and len are non zero, which is strongly recommended, they will
+// be used as additional constraints on the signal handler. That is, when
+// specified, the fault address must be in the range specified by base and
+// len in order for handlesigbus() to be called or sigbusvar to be set.
+// If the fault address is outside of the range, the old SIGBUS handler
+// will be called.
+struct mediasigbushandler {
+ int (*handlesigbus)(siginfo_t *, struct mediasigbushandler *);
+ int *sigbusvar;
+ char *base;
+ int len;
+ // these next two are free for application use
+ struct mediasigbushandler *next;
+ void *data;
+};
+
+
+#endif // ANDROID_MEDIAPLAYERINTERFACE_H
+
diff --git a/include/media/PVPlayer.h b/include/media/PVPlayer.h
new file mode 100644
index 0000000..8164d8c
--- /dev/null
+++ b/include/media/PVPlayer.h
@@ -0,0 +1,75 @@
+/*
+ * 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_PVPLAYER_H
+#define ANDROID_PVPLAYER_H
+
+#include <utils/Errors.h>
+#include <media/MediaPlayerInterface.h>
+
+class PlayerDriver;
+
+namespace android {
+
+class PVPlayer : public MediaPlayerInterface
+{
+public:
+ PVPlayer();
+ virtual ~PVPlayer();
+
+ virtual status_t initCheck();
+ virtual status_t setSigBusHandlerStructTLSKey(pthread_key_t key);
+ virtual status_t setDataSource(const char *url);
+ virtual status_t setDataSource(int fd, int64_t offset, int64_t length);
+ virtual status_t setVideoSurface(const sp<ISurface>& surface);
+ virtual status_t prepare();
+ virtual status_t prepareAsync();
+ virtual status_t start();
+ 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);
+ virtual status_t reset();
+ virtual status_t setLooping(int loop);
+ virtual player_type playerType() { return PV_PLAYER; }
+
+ // make available to PlayerDriver
+ 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);
+
+ PlayerDriver* mPlayerDriver;
+ char * mDataSourcePath;
+ bool mIsDataSourceSet;
+ sp<ISurface> mSurface;
+ void * mMemBase;
+ off_t mMemSize;
+ status_t mInit;
+ int mDuration;
+};
+
+}; // namespace android
+
+#endif // ANDROID_PVPLAYER_H
diff --git a/include/media/ToneGenerator.h b/include/media/ToneGenerator.h
new file mode 100644
index 0000000..bc27d35
--- /dev/null
+++ b/include/media/ToneGenerator.h
@@ -0,0 +1,175 @@
+/*
+ * 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_TONEGENERATOR_H_
+#define ANDROID_TONEGENERATOR_H_
+
+#include <utils/RefBase.h>
+#include <utils/Vector.h>
+#include <utils/threads.h>
+#include <media/AudioSystem.h>
+#include <media/AudioTrack.h>
+
+namespace android {
+
+class ToneGenerator {
+public:
+
+ // List of all available tones
+ // This enum must be kept consistant with constants in ToneGenerator JAVA class
+ enum tone_type {
+ // DTMF tones ITU-T Recommendation Q.23
+ TONE_DTMF_0 = 0, // 0 key: 1336Hz, 941Hz
+ TONE_DTMF_1, // 1 key: 1209Hz, 697Hz
+ TONE_DTMF_2, // 2 key: 1336Hz, 697Hz
+ TONE_DTMF_3, // 3 key: 1477Hz, 697Hz
+ TONE_DTMF_4, // 4 key: 1209Hz, 770Hz
+ TONE_DTMF_5, // 5 key: 1336Hz, 770Hz
+ TONE_DTMF_6, // 6 key: 1477Hz, 770Hz
+ TONE_DTMF_7, // 7 key: 1209Hz, 852Hz
+ TONE_DTMF_8, // 8 key: 1336Hz, 852Hz
+ TONE_DTMF_9, // 9 key: 1477Hz, 852Hz
+ TONE_DTMF_S, // * key: 1209Hz, 941Hz
+ TONE_DTMF_P, // # key: 1477Hz, 941Hz
+ TONE_DTMF_A, // A key: 1633Hz, 697Hz
+ TONE_DTMF_B, // B key: 1633Hz, 770Hz
+ TONE_DTMF_C, // C key: 1633Hz, 852Hz
+ TONE_DTMF_D, // D key: 1633Hz, 941Hz
+ // Call supervisory tones: 3GPP TS 22.001 (CEPT)
+ TONE_SUP_DIAL, // Dial tone: 425Hz, continuous
+ TONE_SUP_BUSY, // Busy tone: 425Hz, 500ms ON, 500ms OFF...
+ TONE_SUP_CONGESTION, // Congestion tone: 425Hz, 200ms ON, 200ms OFF...
+ TONE_SUP_RADIO_ACK, // Radio path acknowlegment: 425Hz, 200ms ON
+ TONE_SUP_RADIO_NOTAVAIL, // Radio path not available: 425Hz, 200ms ON, 200 OFF 3 bursts
+ TONE_SUP_ERROR, // Error/Special info: 950Hz+1400Hz+1800Hz, 330ms ON, 1s OFF...
+ TONE_SUP_CALL_WAITING, // Call Waiting: 425Hz, 200ms ON, 600ms OFF, 200ms ON, 3s OFF...
+ TONE_SUP_RINGTONE, // Ring Tone: 425Hz, 1s ON, 4s OFF...
+ // Proprietary tones: 3GPP TS 31.111
+ TONE_PROP_BEEP, // General beep: 400Hz+1200Hz, 35ms ON
+ TONE_PROP_ACK, // Positive Acknowlgement: 1200Hz, 100ms ON, 100ms OFF 2 bursts
+ TONE_PROP_NACK, // Negative Acknowlgement: 300Hz+400Hz+500Hz, 400ms ON
+ TONE_PROP_PROMPT, // Prompt tone: 400Hz+1200Hz, 200ms ON
+ TONE_PROP_BEEP2, // General double beep: 400Hz+1200Hz, 35ms ON, 200ms OFF, 35ms on
+ NUM_TONES
+ };
+
+ ToneGenerator(int streamType, float volume);
+ ~ToneGenerator();
+
+ bool startTone(int toneType);
+ void stopTone();
+
+ bool isInited() { return (mState == TONE_IDLE)?false:true;}
+
+private:
+
+ enum tone_state {
+ TONE_IDLE, // ToneGenerator is being initialized or initialization failed
+ TONE_INIT, // ToneGenerator has been successfully initialized and is not playing
+ TONE_STARTING, // ToneGenerator is starting playing
+ TONE_PLAYING, // ToneGenerator is playing
+ TONE_STOPPING, // ToneGenerator is stoping
+ TONE_RESTARTING //
+ };
+
+ static const unsigned int NUM_PCM_BUFFERS = 2; // number of pcm buffers of audio track
+
+ static const unsigned int TONEGEN_MAX_WAVES = 3;
+ static const unsigned int TONEGEN_MAX_SEGMENTS = 4; // Maximun number of elenemts in
+ static const unsigned int TONEGEN_INF = 0xFFFFFFFF; // Represents infinite time duration
+ static const float TONEGEN_GAIN = 0.9; // Default gain passed to WaveGenerator().
+
+ // ToneDescriptor class contains all parameters needed to generate a tone:
+ // - The array waveFreq[] contains the frequencies of all individual waves making the multi-tone.
+ // The number of sine waves varies from 1 to TONEGEN_MAX_WAVES.
+ // The first null value indicates that no more waves are needed.
+ // - The array segments[] is used to generate the tone pulses. A segment is a period of time
+ // during which the tone is ON or OFF. Segments with even index (starting from 0)
+ // correspond to tone ON state and segments with odd index to OFF state.
+ // The data stored in segments[] is the duration of the corresponding period in ms.
+ // The first segment encountered with a 0 duration indicates that no more segment follows.
+ // - repeatCnt indicates the number of times the sequence described by segments[] array must be repeated.
+ // When the tone generator encounters the first 0 duration segment, it will compare repeatCnt to mCurCount.
+ // If mCurCount > repeatCnt, the tone is stopped automatically.
+
+ class ToneDescriptor {
+ public:
+ unsigned short waveFreq[TONEGEN_MAX_WAVES+1];
+ unsigned long segments[TONEGEN_MAX_SEGMENTS+1];
+ unsigned long repeatCnt;
+ };
+
+ static const ToneDescriptor toneDescriptors[NUM_TONES];
+
+ unsigned int mTotalSmp; // Total number of audio samples played (gives current time)
+ unsigned int mNextSegSmp; // Position of next segment transition expressed in samples
+ // NOTE: because mTotalSmp, mNextSegSmp are stored on 32 bit, current design will operate properly
+ // only if tone duration is less than about 27 Hours(@44100Hz sampling rate). If this time is exceeded,
+ // no crash will occur but tone sequence will show a glitch.
+
+ unsigned short mCurSegment; // Current segment index in ToneDescriptor segments[]
+ unsigned short mCurCount; // Current sequence repeat count
+ volatile unsigned short mState; // ToneGenerator state (tone_state)
+ const ToneDescriptor *mpToneDesc; // pointer to active tone descriptor
+ const ToneDescriptor *mpNewToneDesc; // pointer to next active tone descriptor
+
+ unsigned int mSamplingRate; // Sampling rate
+ 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
+
+ static void audioCallback(void* user, const AudioTrack::Buffer& info);
+ bool prepareWave();
+ unsigned int numWaves();
+ void clearWaveGens();
+
+ // WaveGenerator generates a single sine wave
+ class WaveGenerator {
+ public:
+ enum gen_command {
+ WAVEGEN_START, // Start/restart wave from phase 0
+ WAVEGEN_CONT, // Continue wave from current phase
+ WAVEGEN_STOP // Stop wave on zero crossing
+ };
+
+ WaveGenerator(unsigned short samplingRate, unsigned short frequency,
+ float volume);
+ ~WaveGenerator();
+
+ void getSamples(short *outBuffer, unsigned int count,
+ unsigned int command);
+
+ private:
+ static const short GEN_AMP = 32000; // amplitude of generator
+ static const short S_Q14 = 14; // shift for Q14
+ static const short S_Q15 = 15; // shift for Q15
+
+ short mA1_Q14; // Q14 coefficient
+ // delay line of full amplitude generator
+ short mS1, mS2; // delay line S2 oldest
+ short mS2_0; // saved value for reinitialisation
+ short mAmplitude_Q15; // Q15 amplitude
+ };
+
+ Vector<WaveGenerator *> mWaveGens; // list of active wave generators.
+};
+
+}
+; // namespace android
+
+#endif /*ANDROID_TONEGENERATOR_H_*/
diff --git a/include/media/mediametadataretriever.h b/include/media/mediametadataretriever.h
new file mode 100644
index 0000000..586dda1c
--- /dev/null
+++ b/include/media/mediametadataretriever.h
@@ -0,0 +1,101 @@
+/*
+ * 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 MEDIAMETADATARETRIEVER_H
+#define MEDIAMETADATARETRIEVER_H
+
+#include <graphics/SkBitmap.h> // for SkBitmap
+
+namespace android {
+
+// Keep these in synch with the constants defined in MediaMetadataRetriever.java
+// class.
+enum {
+ METADATA_KEY_CD_TRACK_NUMBER = 0,
+ METADATA_KEY_ALBUM = 1,
+ METADATA_KEY_ARTIST = 2,
+ METADATA_KEY_AUTHOR = 3,
+ METADATA_KEY_COMPOSER = 4,
+ METADATA_KEY_DATE = 5,
+ METADATA_KEY_GENRE = 6,
+ METADATA_KEY_TITLE = 7,
+ METADATA_KEY_YEAR = 8,
+ METADATA_KEY_DURATION = 9,
+ METADATA_KEY_NUM_TRACKS = 10,
+ METADATA_KEY_IS_DRM_CRIPPLED = 11,
+ METADATA_KEY_CODEC = 12,
+ // Add more here...
+};
+
+// A utility class that holds the size and actual data in album art.
+class MediaAlbumArt {
+public:
+ MediaAlbumArt(): length(0), data(NULL) {}
+ MediaAlbumArt(const MediaAlbumArt& copy) {
+ // Don't be caught by uninitialized variables!!
+ length = 0;
+ data = NULL;
+ setData(copy.length, copy.data);
+ }
+ MediaAlbumArt(const char* url);
+ ~MediaAlbumArt() { clearData(); }
+
+ void clearData();
+ status_t setData(unsigned int len, const char* buf);
+ char *getData() const { return copyData(length, data); }
+ unsigned int getLength() const { return length; }
+
+private:
+ // Disable copy assignment operator!
+ MediaAlbumArt& operator=(const MediaAlbumArt& rhs);
+ static char* copyData(unsigned int len, const char* buf);
+
+ unsigned int length; // Number of bytes in data.
+ char *data; // Actual binary data.
+};
+
+class MediaMetadataRetrieverImpl
+{
+public:
+ virtual ~MediaMetadataRetrieverImpl() {};
+ virtual status_t setDataSource(const char* dataSourceUrl) = 0;
+ virtual SkBitmap *captureFrame() = 0;
+ virtual const char* extractMetadata(int keyCode) = 0;
+ virtual MediaAlbumArt* extractAlbumArt() = 0;
+ virtual void setMode(int mode) = 0;
+};
+
+class MediaMetadataRetriever
+{
+public:
+ static status_t setDataSource(const char* dataSourceUrl);
+ static SkBitmap *captureFrame();
+ static const char* extractMetadata(int keyCode);
+ static MediaAlbumArt* extractAlbumArt();
+ static void setMode(int mode);
+ static void release();
+ static void create();
+
+private:
+ MediaMetadataRetriever() {}
+ static MediaMetadataRetrieverImpl *mRetriever;
+ static void *mLibHandler;
+};
+
+}; // namespace android
+
+#endif // MEDIAMETADATARETRIEVER_H
diff --git a/include/media/mediaplayer.h b/include/media/mediaplayer.h
new file mode 100644
index 0000000..aadfc32
--- /dev/null
+++ b/include/media/mediaplayer.h
@@ -0,0 +1,138 @@
+/*
+ * 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_MEDIAPLAYER_H
+#define ANDROID_MEDIAPLAYER_H
+
+#include <ui/Surface.h>
+#include <media/AudioTrack.h>
+#include <media/IMediaPlayerClient.h>
+#include <media/IMediaPlayer.h>
+#include <media/IMediaPlayerService.h>
+
+namespace android {
+
+enum media_event_type {
+ MEDIA_NOP = 0, // interface test message
+ MEDIA_PREPARED = 1,
+ MEDIA_PLAYBACK_COMPLETE = 2,
+ MEDIA_BUFFERING_UPDATE = 3,
+ MEDIA_SEEK_COMPLETE = 4,
+ MEDIA_ERROR = 100,
+};
+
+typedef int media_error_type;
+const media_error_type MEDIA_ERROR_UNKNOWN = 1;
+const media_error_type MEDIA_ERROR_SERVER_DIED = 100;
+
+enum media_player_states {
+ MEDIA_PLAYER_STATE_ERROR = 0,
+ MEDIA_PLAYER_IDLE = 1 << 0,
+ MEDIA_PLAYER_INITIALIZED = 1 << 1,
+ MEDIA_PLAYER_PREPARING = 1 << 2,
+ MEDIA_PLAYER_PREPARED = 1 << 3,
+ MEDIA_PLAYER_STARTED = 1 << 4,
+ MEDIA_PLAYER_PAUSED = 1 << 5,
+ MEDIA_PLAYER_STOPPED = 1 << 6,
+ MEDIA_PLAYER_PLAYBACK_COMPLETE = 1 << 7
+};
+
+// ----------------------------------------------------------------------------
+// ref-counted object for callbacks
+class MediaPlayerListener: public RefBase
+{
+public:
+ virtual void notify(int msg, int ext1, int ext2) = 0;
+};
+
+class MediaPlayer : public BnMediaPlayerClient, public IBinder::DeathRecipient
+{
+public:
+ MediaPlayer();
+ ~MediaPlayer();
+
+ void disconnect();
+ status_t setDataSource(const char *url);
+ status_t setDataSource(int fd, int64_t offset, int64_t length);
+ status_t setVideoSurface(const sp<Surface>& surface);
+ status_t setListener(const sp<MediaPlayerListener>& listener);
+ status_t prepare();
+ status_t prepareAsync();
+ status_t start();
+ status_t stop();
+ status_t pause();
+ bool isPlaying();
+ status_t getVideoWidth(int *w);
+ status_t getVideoHeight(int *h);
+ status_t seekTo(int msec);
+ status_t getCurrentPosition(int *msec);
+ status_t getDuration(int *msec);
+ status_t reset();
+ status_t setAudioStreamType(int type);
+ status_t setLooping(int loop);
+ 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);
+
+private:
+ void clear_l();
+ status_t seekTo_l(int msec);
+ status_t prepareAsync_l();
+ status_t getDuration_l(int *msec);
+ status_t setDataSource(const sp<IMediaPlayer>& player);
+
+ static const sp<IMediaPlayerService>& getMediaPlayerService();
+ virtual void binderDied(const wp<IBinder>& who);
+
+ class DeathNotifier: public IBinder::DeathRecipient
+ {
+ public:
+ DeathNotifier() {}
+ virtual ~DeathNotifier();
+
+ virtual void binderDied(const wp<IBinder>& who);
+ };
+
+ static sp<DeathNotifier> mDeathNotifier;
+
+ sp<IMediaPlayer> mPlayer;
+ Mutex mLock;
+ Mutex mNotifyLock;
+ Condition mSignal;
+ sp<MediaPlayerListener> mListener;
+ void* mCookie;
+ media_player_states mCurrentState;
+ int mDuration;
+ int mCurrentPosition;
+ int mSeekPosition;
+ bool mPrepareSync;
+ status_t mPrepareStatus;
+ int mStreamType;
+ bool mLoop;
+ float mLeftVolume;
+ float mRightVolume;
+
+ friend class DeathNotifier;
+
+ static Mutex mServiceLock;
+ static sp<IMediaPlayerService> mMediaPlayerService;
+};
+
+}; // namespace android
+
+#endif // ANDROID_MEDIAPLAYER_H
+
diff --git a/include/media/mediarecorder.h b/include/media/mediarecorder.h
new file mode 100644
index 0000000..f247424
--- /dev/null
+++ b/include/media/mediarecorder.h
@@ -0,0 +1,120 @@
+/*
+ * 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
+
+#include <utils.h>
+#include <ui/SurfaceComposerClient.h>
+
+namespace android {
+
+class AuthorDriverWrapper;
+
+typedef void (*media_completion_f)(status_t status, void *cookie);
+
+/* Do not change these values without updating their counterparts
+ * in java/android/android/media/MediaRecorder.java!
+ */
+enum audio_source {
+ AUDIO_SOURCE_DEFAULT = 0,
+ AUDIO_SOURCE_MIC = 1,
+};
+
+enum video_source {
+ VIDEO_SOURCE_DEFAULT = 0,
+ VIDEO_SOURCE_CAMERA = 1,
+};
+
+enum output_format {
+ OUTPUT_FORMAT_DEFAULT = 0,
+ OUTPUT_FORMAT_THREE_GPP = 1,
+ OUTPUT_FORMAT_MPEG_4 = 2,
+};
+
+enum audio_encoder {
+ AUDIO_ENCODER_DEFAULT = 0,
+ AUDIO_ENCODER_AMR_NB = 1,
+};
+
+enum video_encoder {
+ VIDEO_ENCODER_DEFAULT = 0,
+ VIDEO_ENCODER_H263 = 1,
+ VIDEO_ENCODER_H264 = 2,
+ VIDEO_ENCODER_MPEG_4_SP = 3,
+};
+
+/*
+ * 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_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,
+};
+
+class MediaRecorder
+{
+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);
+
+private:
+ AuthorDriverWrapper *mAuthorDriverWrapper;
+ bool mOutputFormatSpecified;
+ media_recorder_states mCurrentState;
+
+};
+
+}; // namespace android
+
+#endif // MEDIAPLAYER_H
+
diff --git a/include/media/mediascanner.h b/include/media/mediascanner.h
new file mode 100644
index 0000000..5d0122d
--- /dev/null
+++ b/include/media/mediascanner.h
@@ -0,0 +1,63 @@
+/*
+ * 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 MEDIASCANNER_H
+#define MEDIASCANNER_H
+
+#include <utils.h>
+#include <pthread.h>
+
+namespace android {
+
+class MediaScannerClient;
+
+class MediaScanner
+{
+public:
+ MediaScanner();
+ ~MediaScanner();
+
+ typedef bool (*ExceptionCheck)(void* env);
+
+ 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);
+
+ // extracts album art as a block of data
+ char* extractAlbumArt(int fd);
+
+ static void uninitializeForThread();
+
+private:
+ status_t doProcessDirectory(char *path, int pathRemaining, const char* extensions,
+ MediaScannerClient& client, ExceptionCheck exceptionCheck, void* exceptionEnv);
+ void initializeForThread();
+};
+
+
+class MediaScannerClient
+{
+public:
+ virtual ~MediaScannerClient() {}
+ 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;
+};
+
+}; // namespace android
+
+#endif // MEDIASCANNER_H
+
diff --git a/include/media/thread_init.h b/include/media/thread_init.h
new file mode 100644
index 0000000..2c0c1f1
--- /dev/null
+++ b/include/media/thread_init.h
@@ -0,0 +1,25 @@
+/*
+ * 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 THREAD_INIT_H
+#define THREAD_INIT_H
+
+bool InitializeForThread();
+void UninitializeForThread();
+void keydestructor(void*);
+
+#endif /* THREAD_INIT_H*/
+
diff --git a/include/private/media/AudioTrackShared.h b/include/private/media/AudioTrackShared.h
new file mode 100644
index 0000000..1878f3c
--- /dev/null
+++ b/include/private/media/AudioTrackShared.h
@@ -0,0 +1,64 @@
+/*
+ * 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_AUDIO_TRACK_SHARED_H
+#define ANDROID_AUDIO_TRACK_SHARED_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <utils/threads.h>
+
+namespace android {
+
+// ----------------------------------------------------------------------------
+
+#define MAX_SAMPLE_RATE 65535
+#define THREAD_PRIORITY_AUDIO_CLIENT (ANDROID_PRIORITY_AUDIO)
+
+struct audio_track_cblk_t
+{
+ enum {
+ SEQUENCE_MASK = 0xFFFFFF00,
+ BUFFER_MASK = 0x000000FF
+ };
+
+ Mutex lock;
+ Condition cv;
+ volatile uint32_t user;
+ volatile uint32_t server;
+ volatile union {
+ uint16_t volume[2];
+ uint32_t volumeLR;
+ };
+ uint16_t sampleRate;
+ uint16_t reserved;
+
+ void* buffers;
+ size_t size;
+
+ audio_track_cblk_t();
+ uint32_t stepUser(int bufferCount);
+ bool stepServer(int bufferCount);
+ void* buffer(int id) const;
+};
+
+
+// ----------------------------------------------------------------------------
+
+}; // namespace android
+
+#endif // ANDROID_AUDIO_TRACK_SHARED_H
diff --git a/include/private/opengles/gl_context.h b/include/private/opengles/gl_context.h
new file mode 100644
index 0000000..67d50fd
--- /dev/null
+++ b/include/private/opengles/gl_context.h
@@ -0,0 +1,624 @@
+/*
+ * Copyright (C) 2006 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_OPENGLES_CONTEXT_H
+#define ANDROID_OPENGLES_CONTEXT_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include <sys/types.h>
+#include <pthread.h>
+#ifdef HAVE_ANDROID_OS
+#include <sys/tls.h>
+#endif
+
+#include <private/pixelflinger/ggl_context.h>
+
+#include <GLES/gl.h>
+
+namespace android {
+
+const unsigned int OGLES_NUM_COMPRESSED_TEXTURE_FORMATS = 10;
+
+class EGLTextureObject;
+class EGLSurfaceManager;
+class EGLBufferObjectManager;
+
+namespace gl {
+
+struct ogles_context_t;
+struct matrixx_t;
+struct transform_t;
+struct buffer_t;
+
+ogles_context_t* getGlContext();
+
+template<typename T>
+static inline void swap(T& a, T& b) {
+ T t(a); a = b; b = t;
+}
+template<typename T>
+inline T max(T a, T b) {
+ return a<b ? b : a;
+}
+template<typename T>
+inline T max(T a, T b, T c) {
+ return max(a, max(b, c));
+}
+template<typename T>
+inline T min(T a, T b) {
+ return a<b ? a : b;
+}
+template<typename T>
+inline T min(T a, T b, T c) {
+ return min(a, min(b, c));
+}
+template<typename T>
+inline T min(T a, T b, T c, T d) {
+ return min(min(a,b), min(c,d));
+}
+
+// ----------------------------------------------------------------------------
+// vertices
+// ----------------------------------------------------------------------------
+
+struct vec3_t {
+ union {
+ struct { GLfixed x, y, z; };
+ struct { GLfixed r, g, b; };
+ struct { GLfixed S, T, R; };
+ GLfixed v[3];
+ };
+};
+
+struct vec4_t {
+ union {
+ struct { GLfixed x, y, z, w; };
+ struct { GLfixed r, g, b, a; };
+ struct { GLfixed S, T, R, Q; };
+ GLfixed v[4];
+ };
+};
+
+struct vertex_t {
+ enum {
+ // these constant matter for our clipping
+ CLIP_L = 0x0001, // clipping flags
+ CLIP_R = 0x0002,
+ CLIP_B = 0x0004,
+ CLIP_T = 0x0008,
+ CLIP_N = 0x0010,
+ CLIP_F = 0x0020,
+
+ EYE = 0x0040,
+ RESERVED = 0x0080,
+
+ USER_CLIP_0 = 0x0100, // user clipping flags
+ USER_CLIP_1 = 0x0200,
+ USER_CLIP_2 = 0x0400,
+ USER_CLIP_3 = 0x0800,
+ USER_CLIP_4 = 0x1000,
+ USER_CLIP_5 = 0x2000,
+
+ LIT = 0x4000, // lighting has been applied
+ TT = 0x8000, // texture coords transformed
+
+ FRUSTUM_CLIP_ALL= 0x003F,
+ USER_CLIP_ALL = 0x3F00,
+ CLIP_ALL = 0x3F3F,
+ };
+
+ // the fields below are arranged to minimize d-cache usage
+ // we group together, by cache-line, the fields most likely to be used
+
+ union {
+ vec4_t obj;
+ vec4_t eye;
+ };
+ vec4_t clip;
+
+ uint32_t flags;
+ size_t index; // cache tag, and vertex index
+ GLfixed fog;
+ uint8_t locked;
+ uint8_t mru;
+ uint8_t reserved[2];
+ vec4_t window;
+
+ vec4_t color;
+ vec4_t texture[GGL_TEXTURE_UNIT_COUNT];
+ uint32_t reserved1[4];
+
+ inline void clear() {
+ flags = index = locked = mru = 0;
+ }
+};
+
+struct point_size_t {
+ GGLcoord size;
+ GLboolean smooth;
+};
+
+struct line_width_t {
+ GGLcoord width;
+ GLboolean smooth;
+};
+
+struct polygon_offset_t {
+ GLfixed factor;
+ GLfixed units;
+ GLboolean enable;
+};
+
+// ----------------------------------------------------------------------------
+// arrays
+// ----------------------------------------------------------------------------
+
+struct array_t {
+ typedef void (*fetcher_t)(ogles_context_t*, GLfixed*, const GLvoid*);
+ fetcher_t fetch;
+ GLvoid const* physical_pointer;
+ GLint size;
+ GLsizei stride;
+ GLvoid const* pointer;
+ buffer_t const* bo;
+ uint16_t type;
+ GLboolean enable;
+ GLboolean pad;
+ GLsizei bounds;
+ void init(GLint, GLenum, GLsizei, const GLvoid *, const buffer_t*, GLsizei);
+ inline void resolve();
+ inline const GLubyte* element(GLint i) const {
+ return (const GLubyte*)physical_pointer + i * stride;
+ }
+};
+
+struct array_machine_t {
+ array_t vertex;
+ array_t normal;
+ array_t color;
+ array_t texture[GGL_TEXTURE_UNIT_COUNT];
+ uint8_t activeTexture;
+ uint8_t tmu;
+ uint16_t cull;
+ uint32_t flags;
+ GLenum indicesType;
+ buffer_t const* array_buffer;
+ buffer_t const* element_array_buffer;
+
+ void (*compileElements)(ogles_context_t*, vertex_t*, GLint, GLsizei);
+ void (*compileElement)(ogles_context_t*, vertex_t*, GLint);
+
+ void (*mvp_transform)(transform_t const*, vec4_t*, vec4_t const*);
+ void (*mv_transform)(transform_t const*, vec4_t*, vec4_t const*);
+ void (*tex_transform[2])(transform_t const*, vec4_t*, vec4_t const*);
+ void (*perspective)(ogles_context_t*c, vertex_t* v);
+ void (*clipVertex)(ogles_context_t* c, vertex_t* nv,
+ GGLfixed t, const vertex_t* s, const vertex_t* p);
+ void (*clipEye)(ogles_context_t* c, vertex_t* nv,
+ GGLfixed t, const vertex_t* s, const vertex_t* p);
+};
+
+struct vertex_cache_t {
+ enum {
+ // must be at least 4
+ // 3 vertice for triangles
+ // or 2 + 2 for indexed triangles w/ cache contention
+ VERTEX_BUFFER_SIZE = 8,
+ // must be a power of two and at least 3
+ VERTEX_CACHE_SIZE = 64, // 8 KB
+
+ INDEX_BITS = 16,
+ INDEX_MASK = ((1LU<<INDEX_BITS)-1),
+ INDEX_SEQ = 1LU<<INDEX_BITS,
+ };
+ vertex_t* vBuffer;
+ vertex_t* vCache;
+ uint32_t sequence;
+ void* base;
+ uint32_t total;
+ uint32_t misses;
+ int64_t startTime;
+ void init();
+ void uninit();
+ void clear();
+ void dump_stats(GLenum mode);
+};
+
+// ----------------------------------------------------------------------------
+// fog
+// ----------------------------------------------------------------------------
+
+struct fog_t {
+ GLfixed density;
+ GLfixed start;
+ GLfixed end;
+ GLfixed invEndMinusStart;
+ GLenum mode;
+ GLfixed (*fog)(ogles_context_t* c, GLfixed z);
+};
+
+// ----------------------------------------------------------------------------
+// user clip planes
+// ----------------------------------------------------------------------------
+
+const unsigned int OGLES_MAX_CLIP_PLANES = 6;
+
+struct clip_plane_t {
+ vec4_t equation;
+};
+
+struct user_clip_planes_t {
+ clip_plane_t plane[OGLES_MAX_CLIP_PLANES];
+ uint32_t enable;
+};
+
+// ----------------------------------------------------------------------------
+// lighting
+// ----------------------------------------------------------------------------
+
+const unsigned int OGLES_MAX_LIGHTS = 8;
+
+struct light_t {
+ vec4_t ambient;
+ vec4_t diffuse;
+ vec4_t specular;
+ vec4_t implicitAmbient;
+ vec4_t implicitDiffuse;
+ vec4_t implicitSpecular;
+ vec4_t position; // position in eye space
+ vec4_t objPosition;
+ vec4_t normalizedObjPosition;
+ vec4_t spotDir;
+ vec4_t normalizedSpotDir;
+ GLfixed spotExp;
+ GLfixed spotCutoff;
+ GLfixed spotCutoffCosine;
+ GLfixed attenuation[3];
+ GLfixed rConstAttenuation;
+ GLboolean enable;
+};
+
+struct material_t {
+ vec4_t ambient;
+ vec4_t diffuse;
+ vec4_t specular;
+ vec4_t emission;
+ GLfixed shininess;
+};
+
+struct light_model_t {
+ vec4_t ambient;
+ GLboolean twoSide;
+};
+
+struct color_material_t {
+ GLenum face;
+ GLenum mode;
+ GLboolean enable;
+};
+
+struct lighting_t {
+ light_t lights[OGLES_MAX_LIGHTS];
+ material_t front;
+ light_model_t lightModel;
+ color_material_t colorMaterial;
+ uint32_t enabledLights;
+ GLboolean enable;
+ vec4_t implicitSceneEmissionAndAmbient;
+ GLenum shadeModel;
+ typedef void (*light_fct_t)(ogles_context_t*, vertex_t*);
+ void (*lightVertex)(ogles_context_t* c, vertex_t* v);
+ void (*lightTriangle)(ogles_context_t* c,
+ vertex_t* v0, vertex_t* v1, vertex_t* v2);
+};
+
+struct culling_t {
+ GLenum cullFace;
+ GLenum frontFace;
+ GLboolean enable;
+};
+
+// ----------------------------------------------------------------------------
+// textures
+// ----------------------------------------------------------------------------
+
+struct texture_unit_t {
+ GLuint name;
+ EGLTextureObject* texture;
+ uint8_t dirty;
+};
+
+struct texture_state_t
+{
+ texture_unit_t tmu[GGL_TEXTURE_UNIT_COUNT];
+ int active; // active tmu
+ EGLTextureObject* defaultTexture;
+ GGLContext* ggl;
+ uint8_t packAlignment;
+ uint8_t unpackAlignment;
+};
+
+// ----------------------------------------------------------------------------
+// transformation and matrices
+// ----------------------------------------------------------------------------
+
+struct matrixf_t;
+
+struct matrixx_t {
+ GLfixed m[16];
+ void load(const matrixf_t& rhs);
+};
+
+struct matrix_stack_t;
+
+
+struct matrixf_t {
+ void loadIdentity();
+ void load(const matrixf_t& rhs);
+
+ inline GLfloat* editElements() { return m; }
+ inline GLfloat const* elements() const { return m; }
+
+ void set(const GLfixed* rhs);
+ void set(const GLfloat* rhs);
+
+ static void multiply(matrixf_t& r,
+ const matrixf_t& lhs, const matrixf_t& rhs);
+
+ void dump(const char* what);
+
+private:
+ friend struct matrix_stack_t;
+ GLfloat m[16];
+ void load(const GLfixed* rhs);
+ void load(const GLfloat* rhs);
+ void multiply(const matrixf_t& rhs);
+ void translate(GLfloat x, GLfloat y, GLfloat z);
+ void scale(GLfloat x, GLfloat y, GLfloat z);
+ void rotate(GLfloat a, GLfloat x, GLfloat y, GLfloat z);
+};
+
+enum {
+ OP_IDENTITY = 0x00,
+ OP_TRANSLATE = 0x01,
+ OP_UNIFORM_SCALE = 0x02,
+ OP_SCALE = 0x05,
+ OP_ROTATE = 0x08,
+ OP_SKEW = 0x10,
+ OP_ALL = 0x1F
+};
+
+struct transform_t {
+ enum {
+ FLAGS_2D_PROJECTION = 0x1
+ };
+ matrixx_t matrix;
+ uint32_t flags;
+ uint32_t ops;
+
+ union {
+ struct {
+ void (*point2)(transform_t const* t, vec4_t*, vec4_t const*);
+ void (*point3)(transform_t const* t, vec4_t*, vec4_t const*);
+ void (*point4)(transform_t const* t, vec4_t*, vec4_t const*);
+ };
+ void (*pointv[3])(transform_t const* t, vec4_t*, vec4_t const*);
+ };
+
+ void loadIdentity();
+ void picker();
+ void dump(const char* what);
+};
+
+struct mvui_transform_t : public transform_t
+{
+ void picker();
+};
+
+struct matrix_stack_t {
+ enum {
+ DO_PICKER = 0x1,
+ DO_FLOAT_TO_FIXED = 0x2
+ };
+ transform_t transform;
+ uint8_t maxDepth;
+ uint8_t depth;
+ uint8_t dirty;
+ uint8_t reserved;
+ matrixf_t *stack;
+ uint8_t *ops;
+ void init(int depth);
+ void uninit();
+ void loadIdentity();
+ void load(const GLfixed* rhs);
+ void load(const GLfloat* rhs);
+ void multiply(const matrixf_t& rhs);
+ void translate(GLfloat x, GLfloat y, GLfloat z);
+ void scale(GLfloat x, GLfloat y, GLfloat z);
+ void rotate(GLfloat a, GLfloat x, GLfloat y, GLfloat z);
+ GLint push();
+ GLint pop();
+ void validate();
+ matrixf_t& top() { return stack[depth]; }
+ const matrixf_t& top() const { return stack[depth]; }
+ const uint32_t top_ops() const { return ops[depth]; }
+ inline bool isRigidBody() const {
+ return !(ops[depth] & ~(OP_TRANSLATE|OP_UNIFORM_SCALE|OP_ROTATE));
+ }
+};
+
+struct vp_transform_t {
+ transform_t transform;
+ matrixf_t matrix;
+ GLfloat zNear;
+ GLfloat zFar;
+ void loadIdentity();
+};
+
+struct transform_state_t {
+ enum {
+ MODELVIEW = 0x01,
+ PROJECTION = 0x02,
+ VIEWPORT = 0x04,
+ TEXTURE = 0x08,
+ MVUI = 0x10,
+ MVIT = 0x20,
+ MVP = 0x40,
+ };
+ matrix_stack_t *current;
+ matrix_stack_t modelview;
+ matrix_stack_t projection;
+ matrix_stack_t texture[GGL_TEXTURE_UNIT_COUNT];
+
+ // modelview * projection
+ transform_t mvp __attribute__((aligned(32)));
+ // viewport transformation
+ vp_transform_t vpt __attribute__((aligned(32)));
+ // same for 4-D vertices
+ transform_t mvp4;
+ // full modelview inverse transpose
+ transform_t mvit4;
+ // upper 3x3 of mv-inverse-transpose (for normals)
+ mvui_transform_t mvui;
+
+ GLenum matrixMode;
+ GLenum rescaleNormals;
+ uint32_t dirty;
+ void invalidate();
+ void update_mvp();
+ void update_mvit();
+ void update_mvui();
+};
+
+struct viewport_t {
+ GLint x;
+ GLint y;
+ GLsizei w;
+ GLsizei h;
+ struct {
+ GLint x;
+ GLint y;
+ } surfaceport;
+ struct {
+ GLint x;
+ GLint y;
+ GLsizei w;
+ GLsizei h;
+ } scissor;
+};
+
+// ----------------------------------------------------------------------------
+// Lerping
+// ----------------------------------------------------------------------------
+
+struct compute_iterators_t
+{
+ void initTriangle(
+ vertex_t const* v0,
+ vertex_t const* v1,
+ vertex_t const* v2);
+
+ inline void initLerp(vertex_t const* v0, uint32_t enables);
+
+ int iteratorsScale(int32_t it[3],
+ int32_t c0, int32_t c1, int32_t c2) const;
+
+ void iterators1616(GGLfixed it[3],
+ GGLfixed c0, GGLfixed c1, GGLfixed c2) const;
+
+ void iterators0032(int32_t it[3],
+ int32_t c0, int32_t c1, int32_t c2) const;
+
+ GGLcoord area() const { return m_area; }
+
+private:
+ // don't change order of members here -- used by iterators.S
+ GGLcoord m_dx01, m_dy10, m_dx20, m_dy02;
+ GGLcoord m_x0, m_y0;
+ GGLcoord m_area;
+ uint8_t m_scale;
+ uint8_t m_area_scale;
+ uint8_t m_reserved[2];
+
+};
+
+// ----------------------------------------------------------------------------
+// state
+// ----------------------------------------------------------------------------
+
+#ifdef HAVE_ANDROID_OS
+ // We have a dedicated TLS slot in bionic
+ inline void setGlThreadSpecific(ogles_context_t *value) {
+ ((uint32_t *)__get_tls())[TLS_SLOT_OPENGL] = (uint32_t)value;
+ }
+ inline ogles_context_t* getGlThreadSpecific() {
+ return (ogles_context_t *)(((unsigned *)__get_tls())[TLS_SLOT_OPENGL]);
+ }
+#else
+ extern pthread_key_t gGLKey;
+ inline void setGlThreadSpecific(ogles_context_t *value) {
+ pthread_setspecific(gGLKey, value);
+ }
+ inline ogles_context_t* getGlThreadSpecific() {
+ return static_cast<ogles_context_t*>(pthread_getspecific(gGLKey));
+ }
+#endif
+
+
+struct prims_t {
+ typedef ogles_context_t* GL;
+ void (*renderPoint)(GL, vertex_t*);
+ void (*renderLine)(GL, vertex_t*, vertex_t*);
+ void (*renderTriangle)(GL, vertex_t*, vertex_t*, vertex_t*);
+};
+
+struct ogles_context_t {
+ context_t rasterizer;
+ array_machine_t arrays __attribute__((aligned(32)));
+ texture_state_t textures;
+ transform_state_t transforms;
+ vertex_cache_t vc;
+ prims_t prims;
+ culling_t cull;
+ lighting_t lighting;
+ user_clip_planes_t clipPlanes;
+ compute_iterators_t lerp; __attribute__((aligned(32)));
+ vertex_t current;
+ vec4_t currentColorClamped;
+ vec3_t currentNormal;
+ viewport_t viewport;
+ point_size_t point;
+ line_width_t line;
+ polygon_offset_t polygonOffset;
+ fog_t fog;
+ uint32_t perspective : 1;
+ uint32_t transformTextures : 1;
+ EGLSurfaceManager* surfaceManager;
+ EGLBufferObjectManager* bufferObjectManager;
+ GLenum error;
+
+ static inline ogles_context_t* get() {
+ return getGlThreadSpecific();
+ }
+
+};
+
+}; // namespace gl
+}; // namespace android
+
+#endif // ANDROID_OPENGLES_CONTEXT_H
+
diff --git a/include/private/ui/LayerState.h b/include/private/ui/LayerState.h
new file mode 100644
index 0000000..b6fcd80
--- /dev/null
+++ b/include/private/ui/LayerState.h
@@ -0,0 +1,75 @@
+/*
+ * 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_COMPOSER_LAYER_STATE_H
+#define ANDROID_COMPOSER_LAYER_STATE_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <utils/Errors.h>
+
+#include <ui/ISurfaceFlingerClient.h>
+#include <ui/Region.h>
+
+#include <private/ui/SharedState.h>
+
+namespace android {
+
+class Parcel;
+
+struct layer_state_t {
+
+ layer_state_t()
+ : surface(0), what(0),
+ x(0), y(0), z(0), w(0), h(0),
+ alpha(0), tint(0), flags(0), mask(0),
+ reserved(0)
+ {
+ matrix.dsdx = matrix.dtdy = 1.0f;
+ matrix.dsdy = matrix.dtdx = 0.0f;
+ }
+
+ status_t write(Parcel& output) const;
+ status_t read(const Parcel& input);
+
+ struct matrix22_t {
+ float dsdx;
+ float dtdx;
+ float dsdy;
+ float dtdy;
+ };
+ SurfaceID surface;
+ uint32_t what;
+ int32_t x;
+ int32_t y;
+ uint32_t z;
+ uint32_t w;
+ uint32_t h;
+ float alpha;
+ uint32_t tint;
+ uint8_t flags;
+ uint8_t mask;
+ uint8_t reserved;
+ matrix22_t matrix;
+ // non POD must be last. see write/read
+ Region transparentRegion;
+};
+
+}; // namespace android
+
+#endif // ANDROID_COMPOSER_LAYER_STATE_H
+
diff --git a/include/private/ui/SharedState.h b/include/private/ui/SharedState.h
new file mode 100644
index 0000000..546d0ad
--- /dev/null
+++ b/include/private/ui/SharedState.h
@@ -0,0 +1,168 @@
+/*
+ * 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_UI_SHARED_STATE_H
+#define ANDROID_UI_SHARED_STATE_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <utils/threads.h>
+
+namespace android {
+
+/*
+ * These structures are shared between the composer process and its clients
+ */
+
+// ---------------------------------------------------------------------------
+
+struct surface_info_t { // 4 longs, 16 bytes
+ enum {
+ eBufferDirty = 0x01
+ };
+ uint16_t w;
+ uint16_t h;
+ uint16_t stride;
+ uint16_t bpr;
+ uint16_t reserved;
+ uint8_t format;
+ uint8_t flags;
+ ssize_t bits_offset;
+};
+
+// ---------------------------------------------------------------------------
+
+const uint32_t NUM_LAYERS_MAX = 31;
+
+enum { // layer_cblk_t swapState
+ eIndex = 0x00000001,
+ eFlipRequested = 0x00000002,
+
+ eResizeBuffer0 = 0x00000004,
+ eResizeBuffer1 = 0x00000008,
+ eResizeRequested = eResizeBuffer0 | eResizeBuffer1,
+
+ eBusy = 0x00000010,
+ eLocked = 0x00000020,
+ eNextFlipPending = 0x00000040,
+ eInvalidSurface = 0x00000080
+};
+
+enum { // layer_cblk_t flags
+ eLayerNotPosted = 0x00000001,
+ eNoCopyBack = 0x00000002,
+ eReserved = 0x0000007C,
+ eBufferIndexShift = 7,
+ eBufferIndex = 1<<eBufferIndexShift,
+};
+
+struct flat_region_t // 40 bytes
+{
+ int32_t count;
+ int16_t l;
+ int16_t t;
+ int16_t r;
+ int16_t b;
+ uint16_t runs[14];
+};
+
+struct layer_cblk_t // (128 bytes)
+{
+ volatile int32_t swapState; // 4
+ volatile int32_t flags; // 4
+ volatile int32_t identity; // 4
+ int32_t reserved; // 4
+ surface_info_t surface[2]; // 32
+ flat_region_t region[2]; // 80
+
+ static inline int backBuffer(uint32_t state) {
+ return ((state & eIndex) ^ ((state & eFlipRequested)>>1));
+ }
+ static inline int frontBuffer(uint32_t state) {
+ return 1 - backBuffer(state);
+ }
+};
+
+// ---------------------------------------------------------------------------
+
+struct per_client_cblk_t // 4KB max
+{
+ Mutex lock;
+ Condition cv;
+ layer_cblk_t layers[NUM_LAYERS_MAX] __attribute__((aligned(32)));
+
+ enum {
+ BLOCKING = 0x00000001,
+ INSPECT = 0x00000002
+ };
+
+ per_client_cblk_t();
+
+ // these functions are used by the clients
+ status_t validate(size_t i) const;
+ int32_t lock_layer(size_t i, uint32_t flags);
+ uint32_t unlock_layer_and_post(size_t i);
+ void unlock_layer(size_t i);
+};
+// ---------------------------------------------------------------------------
+
+const uint32_t NUM_DISPLAY_MAX = 4;
+
+struct display_cblk_t
+{
+ uint16_t w;
+ uint16_t h;
+ uint8_t format;
+ uint8_t orientation;
+ uint8_t reserved[2];
+ float fps;
+ float density;
+ float xdpi;
+ float ydpi;
+ uint32_t pad[2];
+};
+
+struct surface_flinger_cblk_t // 4KB max
+{
+ surface_flinger_cblk_t();
+
+ uint8_t connected;
+ uint8_t reserved[3];
+ uint32_t pad[7];
+
+ display_cblk_t displays[NUM_DISPLAY_MAX];
+};
+
+// ---------------------------------------------------------------------------
+
+template<bool> struct CTA;
+template<> struct CTA<true> { };
+
+// compile-time assertions. just to avoid catastrophes.
+inline void compile_time_asserts() {
+ CTA<sizeof(layer_cblk_t) == 128> sizeof__layer_cblk_t__eq_128;
+ (void)sizeof__layer_cblk_t__eq_128; // we don't want a warning
+ CTA<sizeof(per_client_cblk_t) <= 4096> sizeof__per_client_cblk_t__le_4096;
+ (void)sizeof__per_client_cblk_t__le_4096; // we don't want a warning
+ CTA<sizeof(surface_flinger_cblk_t) <= 4096> sizeof__surface_flinger_cblk_t__le_4096;
+ (void)sizeof__surface_flinger_cblk_t__le_4096; // we don't want a warning
+}
+
+}; // namespace android
+
+#endif // ANDROID_UI_SHARED_STATE_H
+
diff --git a/include/private/ui/SurfaceFlingerSynchro.h b/include/private/ui/SurfaceFlingerSynchro.h
new file mode 100644
index 0000000..ff91b61
--- /dev/null
+++ b/include/private/ui/SurfaceFlingerSynchro.h
@@ -0,0 +1,76 @@
+/*
+ * 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_SURFACE_FLINGER_SYNCHRO_H
+#define ANDROID_SURFACE_FLINGER_SYNCHRO_H
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <utils/Errors.h>
+#include <utils/threads.h>
+#include <ui/ISurfaceComposer.h>
+
+namespace android {
+
+class SurfaceFlinger;
+
+class SurfaceFlingerSynchro
+{
+public:
+
+ // client constructor
+ SurfaceFlingerSynchro(const sp<ISurfaceComposer>& flinger);
+ ~SurfaceFlingerSynchro();
+
+ // signal surfaceflinger for some work
+ status_t signal();
+
+private:
+ class Barrier {
+ public:
+ Barrier();
+ ~Barrier();
+ void open();
+ void close();
+ void waitAndClose();
+ status_t waitAndClose(nsecs_t timeout);
+ private:
+ enum { OPENED, CLOSED };
+ mutable Mutex lock;
+ mutable Condition cv;
+ volatile int state;
+ };
+
+ friend class SurfaceFlinger;
+
+ // server constructor
+ SurfaceFlingerSynchro();
+
+ void open();
+
+ // wait until there is some work to do
+ status_t wait();
+ status_t wait(nsecs_t timeout);
+
+ sp<ISurfaceComposer> mSurfaceComposer;
+ Barrier mBarrier;
+};
+
+}; // namespace android
+
+#endif // ANDROID_SURFACE_FLINGER_SYNCHRO_H
+
diff --git a/include/private/utils/Static.h b/include/private/utils/Static.h
new file mode 100644
index 0000000..f1439b7
--- /dev/null
+++ b/include/private/utils/Static.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// All static variables go here, to control initialization and
+// destruction order in the library.
+
+#include <utils/threads.h>
+#include <utils/KeyedVector.h>
+
+#ifndef LIBUTILS_NATIVE
+#include <utils/IBinder.h>
+#include <utils/IMemory.h>
+#include <utils/ProcessState.h>
+#include <utils/IPermissionController.h>
+#include <utils/IServiceManager.h>
+#endif
+
+namespace android {
+// For TextStream.cpp
+extern Vector<int32_t> gTextBuffers;
+
+// For String8.cpp
+extern void initialize_string8();
+extern void terminate_string8();
+
+// For String16.cpp
+extern void initialize_string16();
+extern void terminate_string16();
+
+
+
+#ifndef LIBUTILS_NATIVE
+
+// For ProcessState.cpp
+extern Mutex gProcessMutex;
+extern sp<ProcessState> gProcess;
+
+// For ServiceManager.cpp
+extern Mutex gDefaultServiceManagerLock;
+extern sp<IServiceManager> gDefaultServiceManager;
+extern sp<IPermissionController> gPermissionController;
+
+#endif
+
+} // namespace android
diff --git a/include/private/utils/binder_module.h b/include/private/utils/binder_module.h
new file mode 100644
index 0000000..fdf327e
--- /dev/null
+++ b/include/private/utils/binder_module.h
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _BINDER_MODULE_H_
+#define _BINDER_MODULE_H_
+
+#ifdef __cplusplus
+namespace android {
+#endif
+
+#if defined(HAVE_ANDROID_OS)
+
+/* obtain structures and constants from the kernel header */
+
+#include <sys/ioctl.h>
+#include <linux/binder.h>
+
+#else
+
+/* Some parts of the simulator need fake versions of this
+ * stuff in order to compile. Really this should go away
+ * entirely...
+ */
+
+#define BINDER_CURRENT_PROTOCOL_VERSION 7
+
+#define BINDER_TYPE_BINDER 1
+#define BINDER_TYPE_WEAK_BINDER 2
+#define BINDER_TYPE_HANDLE 3
+#define BINDER_TYPE_WEAK_HANDLE 4
+#define BINDER_TYPE_FD 5
+
+struct flat_binder_object {
+ unsigned long type;
+ unsigned long flags;
+ union {
+ void *binder;
+ signed long handle;
+ };
+ void *cookie;
+};
+
+struct binder_write_read {
+ signed long write_size;
+ signed long write_consumed;
+ unsigned long write_buffer;
+ signed long read_size;
+ signed long read_consumed;
+ unsigned long read_buffer;
+};
+
+struct binder_transaction_data {
+ union {
+ size_t handle;
+ void *ptr;
+ } target;
+ void *cookie;
+ unsigned int code;
+
+ unsigned int flags;
+ pid_t sender_pid;
+ uid_t sender_euid;
+ size_t data_size;
+ size_t offsets_size;
+
+ union {
+ struct {
+ const void *buffer;
+ const void *offsets;
+ } ptr;
+ uint8_t buf[8];
+ } data;
+};
+
+enum transaction_flags {
+ TF_ONE_WAY = 0x01,
+ TF_ROOT_OBJECT = 0x04,
+ TF_STATUS_CODE = 0x08,
+ TF_ACCEPT_FDS = 0x10,
+};
+
+
+enum {
+ FLAT_BINDER_FLAG_PRIORITY_MASK = 0xff,
+ FLAT_BINDER_FLAG_ACCEPTS_FDS = 0x100,
+};
+
+enum BinderDriverReturnProtocol {
+ BR_ERROR,
+ BR_OK,
+ BR_TRANSACTION,
+ BR_REPLY,
+ BR_ACQUIRE_RESULT,
+ BR_DEAD_REPLY,
+ BR_TRANSACTION_COMPLETE,
+ BR_INCREFS,
+ BR_ACQUIRE,
+ BR_RELEASE,
+ BR_DECREFS,
+ BR_ATTEMPT_ACQUIRE,
+ BR_NOOP,
+ BR_SPAWN_LOOPER,
+ BR_FINISHED,
+ BR_DEAD_BINDER,
+ BR_CLEAR_DEATH_NOTIFICATION_DONE,
+ BR_FAILED_REPLY,
+};
+
+enum BinderDriverCommandProtocol {
+ BC_TRANSACTION,
+ BC_REPLY,
+ BC_ACQUIRE_RESULT,
+ BC_FREE_BUFFER,
+ BC_INCREFS,
+ BC_ACQUIRE,
+ BC_RELEASE,
+ BC_DECREFS,
+ BC_INCREFS_DONE,
+ BC_ACQUIRE_DONE,
+ BC_ATTEMPT_ACQUIRE,
+ BC_REGISTER_LOOPER,
+ BC_ENTER_LOOPER,
+ BC_EXIT_LOOPER,
+ BC_REQUEST_DEATH_NOTIFICATION,
+ BC_CLEAR_DEATH_NOTIFICATION,
+ BC_DEAD_BINDER_DONE,
+};
+
+#endif
+
+#ifdef __cplusplus
+} // namespace android
+#endif
+
+#endif // _BINDER_MODULE_H_
diff --git a/include/private/utils/futex_synchro.h b/include/private/utils/futex_synchro.h
new file mode 100644
index 0000000..ac2ab19
--- /dev/null
+++ b/include/private/utils/futex_synchro.h
@@ -0,0 +1,60 @@
+/*
+ * 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 _FUTEX_SYNCHRO_H
+#define _FUTEX_SYNCHRO_H
+
+#ifndef HAVE_FUTEX
+#error "HAVE_FUTEX not defined"
+#endif
+
+#define FUTEX_WAIT_INFINITE (0)
+
+typedef struct futex_mutex_t futex_mutex_t;
+
+struct futex_mutex_t
+{
+ volatile int value;
+};
+
+typedef struct futex_cond_t futex_cond_t;
+
+struct futex_cond_t
+{
+ volatile int value;
+};
+
+
+#if __cplusplus
+extern "C" {
+#endif
+
+void futex_mutex_init(futex_mutex_t *m);
+int futex_mutex_lock(futex_mutex_t *m, unsigned msec);
+void futex_mutex_unlock(futex_mutex_t *m);
+int futex_mutex_trylock(futex_mutex_t *m);
+
+void futex_cond_init(futex_cond_t *c);
+int futex_cond_wait(futex_cond_t *c, futex_mutex_t *m, unsigned msec);
+void futex_cond_signal(futex_cond_t *c);
+void futex_cond_broadcast(futex_cond_t *c);
+
+#if __cplusplus
+} // extern "C"
+#endif
+
+#endif // _FUTEX_SYNCHRO_H
+