Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3f27436a authored by Lajos Molnar's avatar Lajos Molnar
Browse files

stagefright: don't use ALooperRoster mutex for reply handling

Change replyID-s from uint32_t to an object
Move reply handling into the loopers (to reuse a common mutex)

Bug: 19607784
Change-Id: Iaa035b846c424c5687ed17ce1079b325e86c54be
parent 0655386a
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ void SimplePlayer::onMessageReceived(const sp<AMessage> &msg) {
                mState = UNPREPARED;
            }

            uint32_t replyID;
            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));

            sp<AMessage> response = new AMessage;
@@ -139,7 +139,7 @@ void SimplePlayer::onMessageReceived(const sp<AMessage> &msg) {
                err = OK;
            }

            uint32_t replyID;
            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));

            sp<AMessage> response = new AMessage;
@@ -161,7 +161,7 @@ void SimplePlayer::onMessageReceived(const sp<AMessage> &msg) {
                }
            }

            uint32_t replyID;
            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));

            sp<AMessage> response = new AMessage;
@@ -194,7 +194,7 @@ void SimplePlayer::onMessageReceived(const sp<AMessage> &msg) {
                }
            }

            uint32_t replyID;
            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));

            sp<AMessage> response = new AMessage;
@@ -217,7 +217,7 @@ void SimplePlayer::onMessageReceived(const sp<AMessage> &msg) {
                }
            }

            uint32_t replyID;
            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));

            sp<AMessage> response = new AMessage;
@@ -240,7 +240,7 @@ void SimplePlayer::onMessageReceived(const sp<AMessage> &msg) {
                mState = UNINITIALIZED;
            }

            uint32_t replyID;
            sp<AReplyToken> replyID;
            CHECK(msg->senderAwaitsResponse(&replyID));

            sp<AMessage> response = new AMessage;
+7 −6
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ namespace android {

struct ABuffer;
struct AMessage;
struct AReplyToken;
struct AString;
struct CodecBase;
struct ICrypto;
@@ -222,7 +223,7 @@ private:
    sp<ALooper> mCodecLooper;
    sp<CodecBase> mCodec;
    AString mComponentName;
    uint32_t mReplyID;
    sp<AReplyToken> mReplyID;
    uint32_t mFlags;
    status_t mStickyError;
    sp<Surface> mNativeWindow;
@@ -249,10 +250,10 @@ private:
    Vector<BufferInfo> mPortBuffers[2];

    int32_t mDequeueInputTimeoutGeneration;
    uint32_t mDequeueInputReplyID;
    sp<AReplyToken> mDequeueInputReplyID;

    int32_t mDequeueOutputTimeoutGeneration;
    uint32_t mDequeueOutputReplyID;
    sp<AReplyToken> mDequeueOutputReplyID;

    sp<ICrypto> mCrypto;

@@ -267,7 +268,7 @@ private:
    static status_t PostAndAwaitResponse(
            const sp<AMessage> &msg, sp<AMessage> *response);

    static void PostReplyWithError(int32_t replyID, int32_t err);
    static void PostReplyWithError(const sp<AReplyToken> &replyID, int32_t err);

    status_t init(const AString &name, bool nameIsType, bool encoder);

@@ -283,8 +284,8 @@ private:
            size_t portIndex, size_t index,
            sp<ABuffer> *buffer, sp<AMessage> *format);

    bool handleDequeueInputBuffer(uint32_t replyID, bool newRequest = false);
    bool handleDequeueOutputBuffer(uint32_t replyID, bool newRequest = false);
    bool handleDequeueInputBuffer(const sp<AReplyToken> &replyID, bool newRequest = false);
    bool handleDequeueOutputBuffer(const sp<AReplyToken> &replyID, bool newRequest = false);
    void cancelPendingDequeueOperations();

    void extractCSD(const sp<AMessage> &format);
+2 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ namespace android {

class ALooper;
class AMessage;
struct AReplyToken;
class IGraphicBufferProducer;
class MediaCodec;
class MetaData;
@@ -99,7 +100,7 @@ private:
    sp<Puller> mPuller;
    sp<MediaCodec> mEncoder;
    uint32_t mFlags;
    List<uint32_t> mStopReplyIDQueue;
    List<sp<AReplyToken>> mStopReplyIDQueue;
    bool mIsVideo;
    bool mStarted;
    bool mStopping;
+21 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ namespace android {

struct AHandler;
struct AMessage;
struct AReplyToken;

struct ALooper : public RefBase {
    typedef int32_t event_id;
@@ -79,7 +80,27 @@ private:
    sp<LooperThread> mThread;
    bool mRunningLocally;

    // use a separate lock for reply handling, as it is always on another thread
    // use a central lock, however, to avoid creating a mutex for each reply
    Mutex mRepliesLock;
    Condition mRepliesCondition;

    // START --- methods used only by AMessage

    // posts a message on this looper with the given timeout
    void post(const sp<AMessage> &msg, int64_t delayUs);

    // creates a reply token to be used with this looper
    sp<AReplyToken> createReplyToken();
    // waits for a response for the reply token.  If status is OK, the response
    // is stored into the supplied variable.  Otherwise, it is unchanged.
    status_t awaitResponse(const sp<AReplyToken> &replyToken, sp<AMessage> *response);
    // posts a reply for a reply token.  If the reply could be successfully posted,
    // it returns OK. Otherwise, it returns an error value.
    status_t postReply(const sp<AReplyToken> &replyToken, const sp<AMessage> &msg);

    // END --- methods used only by AMessage

    bool loop();

    DISALLOW_EVIL_CONSTRUCTORS(ALooper);
+0 −9
Original line number Diff line number Diff line
@@ -33,11 +33,6 @@ struct ALooperRoster {
    void unregisterHandler(ALooper::handler_id handlerID);
    void unregisterStaleHandlers();

    status_t postAndAwaitResponse(
            const sp<AMessage> &msg, sp<AMessage> *response);

    void postReply(uint32_t replyID, const sp<AMessage> &reply);

    void dump(int fd, const Vector<String16>& args);

private:
@@ -49,10 +44,6 @@ private:
    Mutex mLock;
    KeyedVector<ALooper::handler_id, HandlerInfo> mHandlers;
    ALooper::handler_id mNextHandlerID;
    uint32_t mNextReplyID;
    Condition mRepliesCondition;

    KeyedVector<uint32_t, sp<AMessage> > mReplies;

    DISALLOW_EVIL_CONSTRUCTORS(ALooperRoster);
};
Loading