diff options
author | Lajos Molnar <lajos@google.com> | 2015-03-04 17:00:10 -0800 |
---|---|---|
committer | Lajos Molnar <lajos@google.com> | 2015-03-05 17:49:50 -0800 |
commit | 5804a76ac5f9f3c311f1bbbcc5ebdc8f8568ae14 (patch) | |
tree | 159660930b1c7f6300ea3054e47ce46719083a16 /include | |
parent | c10e7f121d346b433c32d1c0d791c4b547cbe60e (diff) | |
download | frameworks_av-5804a76ac5f9f3c311f1bbbcc5ebdc8f8568ae14.zip frameworks_av-5804a76ac5f9f3c311f1bbbcc5ebdc8f8568ae14.tar.gz frameworks_av-5804a76ac5f9f3c311f1bbbcc5ebdc8f8568ae14.tar.bz2 |
stagefright: use handler instead of handler-id in AMessage
This avoids locking gLooperRoster mutex on post() and deliver().
Bug: 19607784
Change-Id: If6d9d7884dbb08fc390983bda896d223803476ba
Diffstat (limited to 'include')
-rw-r--r-- | include/media/stagefright/foundation/AHandler.h | 24 | ||||
-rw-r--r-- | include/media/stagefright/foundation/ALooper.h | 8 | ||||
-rw-r--r-- | include/media/stagefright/foundation/ALooperRoster.h | 6 | ||||
-rw-r--r-- | include/media/stagefright/foundation/AMessage.h | 18 |
4 files changed, 44 insertions, 12 deletions
diff --git a/include/media/stagefright/foundation/AHandler.h b/include/media/stagefright/foundation/AHandler.h index 41ade77..fe02a86 100644 --- a/include/media/stagefright/foundation/AHandler.h +++ b/include/media/stagefright/foundation/AHandler.h @@ -29,6 +29,7 @@ struct AMessage; struct AHandler : public RefBase { AHandler() : mID(0), + mVerboseStats(false), mMessageCounter(0) { } @@ -36,23 +37,40 @@ struct AHandler : public RefBase { return mID; } - sp<ALooper> looper(); + sp<ALooper> looper() const { + return mLooper.promote(); + } + + wp<ALooper> getLooper() const { + return mLooper; + } + + wp<AHandler> getHandler() const { + // allow getting a weak reference to a const handler + return const_cast<AHandler *>(this); + } protected: virtual void onMessageReceived(const sp<AMessage> &msg) = 0; private: - friend struct ALooperRoster; + friend struct AMessage; // deliverMessage() + friend struct ALooperRoster; // setID() ALooper::handler_id mID; + wp<ALooper> mLooper; - void setID(ALooper::handler_id id) { + inline void setID(ALooper::handler_id id, wp<ALooper> looper) { mID = id; + mLooper = looper; } + bool mVerboseStats; uint32_t mMessageCounter; KeyedVector<uint32_t, uint32_t> mMessages; + void deliverMessage(const sp<AMessage> &msg); + DISALLOW_EVIL_CONSTRUCTORS(AHandler); }; diff --git a/include/media/stagefright/foundation/ALooper.h b/include/media/stagefright/foundation/ALooper.h index 70e0c5e..150cdba 100644 --- a/include/media/stagefright/foundation/ALooper.h +++ b/include/media/stagefright/foundation/ALooper.h @@ -53,11 +53,15 @@ struct ALooper : public RefBase { static int64_t GetNowUs(); + const char *getName() const { + return mName.c_str(); + } + protected: virtual ~ALooper(); private: - friend struct ALooperRoster; + friend struct AMessage; // post() struct Event { int64_t mWhenUs; @@ -81,6 +85,6 @@ private: DISALLOW_EVIL_CONSTRUCTORS(ALooper); }; -} // namespace android +} // namespace android #endif // A_LOOPER_H_ diff --git a/include/media/stagefright/foundation/ALooperRoster.h b/include/media/stagefright/foundation/ALooperRoster.h index a0be8eb..63d52d9 100644 --- a/include/media/stagefright/foundation/ALooperRoster.h +++ b/include/media/stagefright/foundation/ALooperRoster.h @@ -33,15 +33,13 @@ struct ALooperRoster { void unregisterHandler(ALooper::handler_id handlerID); void unregisterStaleHandlers(); - status_t postMessage(const sp<AMessage> &msg, int64_t delayUs = 0); - void deliverMessage(const sp<AMessage> &msg); - status_t postAndAwaitResponse( const sp<AMessage> &msg, sp<AMessage> *response); void postReply(uint32_t replyID, const sp<AMessage> &reply); - sp<ALooper> findLooper(ALooper::handler_id handlerID); + void getHandlerAndLooper( + ALooper::handler_id handlerID, wp<AHandler> *handler, wp<ALooper> *looper); void dump(int fd, const Vector<String16>& args); diff --git a/include/media/stagefright/foundation/AMessage.h b/include/media/stagefright/foundation/AMessage.h index a9e235b..beaefdd 100644 --- a/include/media/stagefright/foundation/AMessage.h +++ b/include/media/stagefright/foundation/AMessage.h @@ -26,11 +26,14 @@ namespace android { struct ABuffer; +struct AHandler; struct AString; struct Parcel; struct AMessage : public RefBase { - AMessage(uint32_t what = 0, ALooper::handler_id target = 0); + AMessage(); + AMessage(uint32_t what, ALooper::handler_id target = 0); + AMessage(uint32_t what, const sp<const AHandler> &handler); static sp<AMessage> FromParcel(const Parcel &parcel); void writeToParcel(Parcel *parcel) const; @@ -39,7 +42,7 @@ struct AMessage : public RefBase { uint32_t what() const; void setTarget(ALooper::handler_id target); - ALooper::handler_id target() const; + void setTarget(const sp<const AHandler> &handler); void clear(); @@ -76,7 +79,7 @@ struct AMessage : public RefBase { const char *name, int32_t *left, int32_t *top, int32_t *right, int32_t *bottom) const; - void post(int64_t delayUs = 0); + status_t post(int64_t delayUs = 0); // Posts the message to its target and waits for a response (or error) // before returning. @@ -117,9 +120,16 @@ protected: virtual ~AMessage(); private: + friend struct ALooper; // deliver() + uint32_t mWhat; + + // used only for debugging ALooper::handler_id mTarget; + wp<AHandler> mHandler; + wp<ALooper> mLooper; + struct Rect { int32_t mLeft, mTop, mRight, mBottom; }; @@ -157,6 +167,8 @@ private: size_t findItemIndex(const char *name, size_t len) const; + void deliver(); + DISALLOW_EVIL_CONSTRUCTORS(AMessage); }; |