diff options
author | Andreas Huber <andih@google.com> | 2010-06-07 12:50:05 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-06-07 12:50:05 -0700 |
commit | 455d41002e17de93b1486b2b2a97a71a0d62903b (patch) | |
tree | ea51f57aa417fd7b5596355897e84a18352fb386 /include/media | |
parent | b7bb3b3df6cb3743ee43b71455d9525762e55b45 (diff) | |
parent | 7d2f703649e270b635018f8b7219bb0e1d62a2e5 (diff) | |
download | frameworks_base-455d41002e17de93b1486b2b2a97a71a0d62903b.zip frameworks_base-455d41002e17de93b1486b2b2a97a71a0d62903b.tar.gz frameworks_base-455d41002e17de93b1486b2b2a97a71a0d62903b.tar.bz2 |
Merge "Initial checkin of "foundation" library for future stagefright development." into kraken
Diffstat (limited to 'include/media')
-rw-r--r-- | include/media/stagefright/foundation/AAtomizer.h | 51 | ||||
-rw-r--r-- | include/media/stagefright/foundation/ABase.h | 25 | ||||
-rw-r--r-- | include/media/stagefright/foundation/ABuffer.h | 71 | ||||
-rw-r--r-- | include/media/stagefright/foundation/ADebug.h | 105 | ||||
-rw-r--r-- | include/media/stagefright/foundation/AHandler.h | 54 | ||||
-rw-r--r-- | include/media/stagefright/foundation/ALooper.h | 75 | ||||
-rw-r--r-- | include/media/stagefright/foundation/ALooperRoster.h | 52 | ||||
-rw-r--r-- | include/media/stagefright/foundation/AMessage.h | 113 | ||||
-rw-r--r-- | include/media/stagefright/foundation/AString.h | 94 | ||||
-rw-r--r-- | include/media/stagefright/foundation/base64.h | 33 | ||||
-rw-r--r-- | include/media/stagefright/foundation/hexdump.h | 29 |
11 files changed, 702 insertions, 0 deletions
diff --git a/include/media/stagefright/foundation/AAtomizer.h b/include/media/stagefright/foundation/AAtomizer.h new file mode 100644 index 0000000..5f3a678 --- /dev/null +++ b/include/media/stagefright/foundation/AAtomizer.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 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 A_ATOMIZER_H_ + +#define A_ATOMIZER_H_ + +#include <stdint.h> + +#include <media/stagefright/foundation/ABase.h> +#include <media/stagefright/foundation/AString.h> +#include <utils/List.h> +#include <utils/Vector.h> +#include <utils/threads.h> + +namespace android { + +struct AAtomizer { + static const char *Atomize(const char *name); + +private: + static AAtomizer gAtomizer; + + Mutex mLock; + Vector<List<AString> > mAtoms; + + AAtomizer(); + + const char *atomize(const char *name); + + static uint32_t Hash(const char *s); + + DISALLOW_EVIL_CONSTRUCTORS(AAtomizer); +}; + +} // namespace android + +#endif // A_ATOMIZER_H_ diff --git a/include/media/stagefright/foundation/ABase.h b/include/media/stagefright/foundation/ABase.h new file mode 100644 index 0000000..9eceea3 --- /dev/null +++ b/include/media/stagefright/foundation/ABase.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2010 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 A_BASE_H_ + +#define A_BASE_H_ + +#define DISALLOW_EVIL_CONSTRUCTORS(name) \ + name(const name &); \ + name &operator=(const name &) + +#endif // A_BASE_H_ diff --git a/include/media/stagefright/foundation/ABuffer.h b/include/media/stagefright/foundation/ABuffer.h new file mode 100644 index 0000000..28f0aed --- /dev/null +++ b/include/media/stagefright/foundation/ABuffer.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2010 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 A_BUFFER_H_ + +#define A_BUFFER_H_ + +#include <sys/types.h> +#include <stdint.h> + +#include <media/stagefright/foundation/ABase.h> +#include <utils/RefBase.h> + +namespace android { + +struct AMessage; + +struct ABuffer : public RefBase { + ABuffer(size_t capacity); + ABuffer(void *data, size_t capacity); + + void setFarewellMessage(const sp<AMessage> msg); + + uint8_t *base() { return (uint8_t *)mData; } + uint8_t *data() { return (uint8_t *)mData + mRangeOffset; } + size_t capacity() const { return mCapacity; } + size_t size() const { return mRangeLength; } + size_t offset() const { return mRangeOffset; } + + void setRange(size_t offset, size_t size); + + void setInt32Data(int32_t data) { mInt32Data = data; } + int32_t int32Data() const { return mInt32Data; } + + sp<AMessage> meta(); + +protected: + virtual ~ABuffer(); + +private: + sp<AMessage> mFarewell; + sp<AMessage> mMeta; + + void *mData; + size_t mCapacity; + size_t mRangeOffset; + size_t mRangeLength; + + int32_t mInt32Data; + + bool mOwnsData; + + DISALLOW_EVIL_CONSTRUCTORS(ABuffer); +}; + +} // namespace android + +#endif // A_BUFFER_H_ diff --git a/include/media/stagefright/foundation/ADebug.h b/include/media/stagefright/foundation/ADebug.h new file mode 100644 index 0000000..0f986a0 --- /dev/null +++ b/include/media/stagefright/foundation/ADebug.h @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2010 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 A_DEBUG_H_ + +#define A_DEBUG_H_ + +#include <string.h> + +#include <media/stagefright/foundation/ABase.h> +#include <media/stagefright/foundation/AString.h> + +namespace android { + +enum LogType { + VERBOSE, + INFO, + WARNING, + ERROR, + FATAL, +}; + +struct Logger { + Logger(LogType type); + virtual ~Logger(); + + template<class T> Logger &operator<<(const T &x) { + mMessage.append(x); + + return *this; + } + +private: + android::AString mMessage; + LogType mLogType; + + DISALLOW_EVIL_CONSTRUCTORS(Logger); +}; + +const char *LeafName(const char *s); + +#undef LOG +#define LOG(type) Logger(type) << LeafName(__FILE__) << ":" << __LINE__ << " " + +#define CHECK(condition) \ + do { \ + if (!(condition)) { \ + LOG(FATAL) << "CHECK(" #condition ") failed."; \ + } \ + } while (false) + +#define MAKE_COMPARATOR(suffix,op) \ + template<class A, class B> \ + AString Compare_##suffix(const A &a, const B &b) { \ + AString res; \ + if (!(a op b)) { \ + res.append(a); \ + res.append(" vs. "); \ + res.append(b); \ + } \ + return res; \ + } + +MAKE_COMPARATOR(EQ,==) +MAKE_COMPARATOR(NE,!=) +MAKE_COMPARATOR(LE,<=) +MAKE_COMPARATOR(GE,>=) +MAKE_COMPARATOR(LT,<) +MAKE_COMPARATOR(GT,>) + +#define CHECK_OP(x,y,suffix,op) \ + do { \ + AString ___res = Compare_##suffix(x, y); \ + if (!___res.empty()) { \ + LOG(FATAL) << "CHECK_" #suffix "(" #x "," #y ") failed: " \ + << ___res; \ + } \ + } while (false) + +#define CHECK_EQ(x,y) CHECK_OP(x,y,EQ,==) +#define CHECK_NE(x,y) CHECK_OP(x,y,NE,!=) +#define CHECK_LE(x,y) CHECK_OP(x,y,LE,<=) +#define CHECK_LT(x,y) CHECK_OP(x,y,LT,<) +#define CHECK_GE(x,y) CHECK_OP(x,y,GE,>=) +#define CHECK_GT(x,y) CHECK_OP(x,y,GT,>) + +#define TRESPASS() LOG(FATAL) << "Should not be here." + +} // namespace android + +#endif // A_DEBUG_H_ + diff --git a/include/media/stagefright/foundation/AHandler.h b/include/media/stagefright/foundation/AHandler.h new file mode 100644 index 0000000..9fccead --- /dev/null +++ b/include/media/stagefright/foundation/AHandler.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2010 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 A_HANDLER_H_ + +#define A_HANDLER_H_ + +#include <media/stagefright/foundation/ALooper.h> +#include <utils/RefBase.h> + +namespace android { + +struct AMessage; + +struct AHandler : public RefBase { + AHandler() + : mID(0) { + } + + ALooper::handler_id id() const { + return mID; + } + +protected: + virtual void onMessageReceived(const sp<AMessage> &msg) = 0; + +private: + friend struct ALooperRoster; + + ALooper::handler_id mID; + + void setID(ALooper::handler_id id) { + mID = id; + } + + DISALLOW_EVIL_CONSTRUCTORS(AHandler); +}; + +} // namespace android + +#endif // A_HANDLER_H_ diff --git a/include/media/stagefright/foundation/ALooper.h b/include/media/stagefright/foundation/ALooper.h new file mode 100644 index 0000000..69ad837 --- /dev/null +++ b/include/media/stagefright/foundation/ALooper.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2010 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 A_LOOPER_H_ + +#define A_LOOPER_H_ + +#include <media/stagefright/foundation/ABase.h> +#include <utils/Errors.h> +#include <utils/KeyedVector.h> +#include <utils/List.h> +#include <utils/RefBase.h> +#include <utils/threads.h> + +namespace android { + +struct AHandler; +struct AMessage; + +struct ALooper : public RefBase { + typedef int32_t event_id; + typedef int32_t handler_id; + + ALooper(); + + handler_id registerHandler(const sp<AHandler> &handler); + void unregisterHandler(handler_id handlerID); + + status_t start(bool runOnCallingThread = false); + status_t stop(); + + static int64_t GetNowUs(); + +protected: + virtual ~ALooper(); + +private: + friend struct ALooperRoster; + + struct Event { + int64_t mWhenUs; + sp<AMessage> mMessage; + }; + + Mutex mLock; + Condition mQueueChangedCondition; + + List<Event> mEventQueue; + + struct LooperThread; + sp<LooperThread> mThread; + bool mRunningLocally; + + void post(const sp<AMessage> &msg, int64_t delayUs); + bool loop(); + + DISALLOW_EVIL_CONSTRUCTORS(ALooper); +}; + +} // namespace android + +#endif // A_LOOPER_H_ diff --git a/include/media/stagefright/foundation/ALooperRoster.h b/include/media/stagefright/foundation/ALooperRoster.h new file mode 100644 index 0000000..1c6869c --- /dev/null +++ b/include/media/stagefright/foundation/ALooperRoster.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2010 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 A_LOOPER_ROSTER_H_ + +#define A_LOOPER_ROSTER_H_ + +#include <media/stagefright/foundation/ALooper.h> +#include <utils/KeyedVector.h> + +namespace android { + +struct ALooperRoster { + ALooperRoster(); + + ALooper::handler_id registerHandler( + const sp<ALooper> looper, const sp<AHandler> &handler); + + void unregisterHandler(ALooper::handler_id handlerID); + + void postMessage(const sp<AMessage> &msg, int64_t delayUs = 0); + void deliverMessage(const sp<AMessage> &msg); + +private: + struct HandlerInfo { + sp<ALooper> mLooper; + sp<AHandler> mHandler; + }; + + Mutex mLock; + KeyedVector<ALooper::handler_id, HandlerInfo> mHandlers; + ALooper::handler_id mNextHandlerID; + + DISALLOW_EVIL_CONSTRUCTORS(ALooperRoster); +}; + +} // namespace android + +#endif // A_LOOPER_ROSTER_H_ diff --git a/include/media/stagefright/foundation/AMessage.h b/include/media/stagefright/foundation/AMessage.h new file mode 100644 index 0000000..139c620 --- /dev/null +++ b/include/media/stagefright/foundation/AMessage.h @@ -0,0 +1,113 @@ +/* + * Copyright (C) 2010 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 A_MESSAGE_H_ + +#define A_MESSAGE_H_ + +#include <media/stagefright/foundation/ABase.h> +#include <media/stagefright/foundation/ALooper.h> +#include <utils/KeyedVector.h> +#include <utils/RefBase.h> + +namespace android { + +struct AString; + +struct AMessage : public RefBase { + AMessage(uint32_t what = 0, ALooper::handler_id target = 0); + + void setWhat(uint32_t what); + uint32_t what() const; + + void setTarget(ALooper::handler_id target); + ALooper::handler_id target() const; + + void setInt32(const char *name, int32_t value); + void setInt64(const char *name, int64_t value); + void setSize(const char *name, size_t value); + void setFloat(const char *name, float value); + void setDouble(const char *name, double value); + void setPointer(const char *name, void *value); + void setString(const char *name, const char *s, ssize_t len = -1); + void setObject(const char *name, const sp<RefBase> &obj); + void setMessage(const char *name, const sp<AMessage> &obj); + + bool findInt32(const char *name, int32_t *value) const; + bool findInt64(const char *name, int64_t *value) const; + bool findSize(const char *name, size_t *value) const; + bool findFloat(const char *name, float *value) const; + bool findDouble(const char *name, double *value) const; + bool findPointer(const char *name, void **value) const; + bool findString(const char *name, AString *value) const; + bool findObject(const char *name, sp<RefBase> *obj) const; + bool findMessage(const char *name, sp<AMessage> *obj) const; + + void post(int64_t delayUs = 0); + + sp<AMessage> dup() const; + +protected: + virtual ~AMessage(); + +private: + enum Type { + kTypeInt32, + kTypeInt64, + kTypeSize, + kTypeFloat, + kTypeDouble, + kTypePointer, + kTypeString, + kTypeObject, + kTypeMessage, + }; + + uint32_t mWhat; + ALooper::handler_id mTarget; + + struct Item { + union { + int32_t int32Value; + int64_t int64Value; + size_t sizeValue; + float floatValue; + double doubleValue; + void *ptrValue; + RefBase *refValue; + AString *stringValue; + } u; + const char *mName; + Type mType; + }; + + enum { + kMaxNumItems = 16 + }; + Item mItems[kMaxNumItems]; + size_t mNumItems; + + void clear(); + Item *allocateItem(const char *name); + void freeItem(Item *item); + const Item *findItem(const char *name, Type type) const; + + DISALLOW_EVIL_CONSTRUCTORS(AMessage); +}; + +} // namespace android + +#endif // A_MESSAGE_H_ diff --git a/include/media/stagefright/foundation/AString.h b/include/media/stagefright/foundation/AString.h new file mode 100644 index 0000000..55ade64 --- /dev/null +++ b/include/media/stagefright/foundation/AString.h @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2010 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 A_STRING_H_ + +#define A_STRING_H_ + +#include <sys/types.h> + +namespace android { + +struct AString { + AString(); + AString(const char *s); + AString(const char *s, size_t size); + AString(const AString &from); + AString(const AString &from, size_t offset, size_t n); + ~AString(); + + AString &operator=(const AString &from); + void setTo(const char *s); + void setTo(const char *s, size_t size); + void setTo(const AString &from, size_t offset, size_t n); + + size_t size() const; + const char *c_str() const; + + bool empty() const; + + void clear(); + void trim(); + void erase(size_t start, size_t n); + + void append(char c) { append(&c, 1); } + void append(const char *s); + void append(const char *s, size_t size); + void append(const AString &from); + void append(const AString &from, size_t offset, size_t n); + void append(int x); + void append(unsigned x); + void append(long x); + void append(unsigned long x); + void append(long long x); + void append(unsigned long long x); + void append(float x); + void append(double x); + void append(void *x); + + void insert(const AString &from, size_t insertionPos); + void insert(const char *from, size_t size, size_t insertionPos); + + ssize_t find(const char *substring, size_t start = 0) const; + + size_t hash() const; + + bool operator==(const AString &other) const; + bool operator<(const AString &other) const; + bool operator>(const AString &other) const; + + int compare(const AString &other) const; + + bool startsWith(const char *prefix) const; + + void tolower(); + +private: + static const char *kEmptyString; + + char *mData; + size_t mSize; + size_t mAllocSize; + + void makeMutable(); +}; + +AString StringPrintf(const char *format, ...); + +} // namespace android + +#endif // A_STRING_H_ + diff --git a/include/media/stagefright/foundation/base64.h b/include/media/stagefright/foundation/base64.h new file mode 100644 index 0000000..e340b89 --- /dev/null +++ b/include/media/stagefright/foundation/base64.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2010 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 BASE_64_H_ + +#define BASE_64_H_ + +#include <utils/RefBase.h> + +namespace android { + +struct ABuffer; +struct AString; + +sp<ABuffer> decodeBase64(const AString &s); +void encodeBase64(const void *data, size_t size, AString *out); + +} // namespace android + +#endif // BASE_64_H_ diff --git a/include/media/stagefright/foundation/hexdump.h b/include/media/stagefright/foundation/hexdump.h new file mode 100644 index 0000000..f6083a9 --- /dev/null +++ b/include/media/stagefright/foundation/hexdump.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2010 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 HEXDUMP_H_ + +#define HEXDUMP_H_ + +#include <sys/types.h> + +namespace android { + +void hexdump(const void *_data, size_t size); + +} // namespace android + +#endif // HEXDUMP_H_ |