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

Commit 0bf47426 authored by Andreas Huber's avatar Andreas Huber Committed by Android Git Automerger
Browse files

am af9e6a17: Merge "Properly connect/disconnect to/from the native window in...

am af9e6a17: Merge "Properly connect/disconnect to/from the native window in MediaCodec." into jb-dev

* commit 'af9e6a17':
  Properly connect/disconnect to/from the native window in MediaCodec.
parents ddebe415 af9e6a17
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -210,6 +210,9 @@ private:
    void extractCSD(const sp<AMessage> &format);
    status_t queueCSDInputBuffer(size_t bufferIndex);

    status_t setNativeWindow(
            const sp<SurfaceTextureClient> &surfaceTextureClient);

    DISALLOW_EVIL_CONSTRUCTORS(MediaCodec);
};

+49 −10
Original line number Diff line number Diff line
@@ -796,9 +796,6 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
                break;
            }

            mReplyID = replyID;
            setState(CONFIGURING);

            sp<RefBase> obj;
            if (!msg->findObject("native-window", &obj)) {
                obj.clear();
@@ -810,15 +807,24 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) {
            if (obj != NULL) {
                format->setObject("native-window", obj);

                if (mFlags & kFlagIsSoftwareCodec) {
                    mNativeWindow =
                status_t err = setNativeWindow(
                    static_cast<NativeWindowWrapper *>(obj.get())
                            ->getSurfaceTextureClient();
                        ->getSurfaceTextureClient());

                if (err != OK) {
                    sp<AMessage> response = new AMessage;
                    response->setInt32("err", err);

                    response->postReply(replyID);
                    break;
                }
            } else {
                mNativeWindow.clear();
                setNativeWindow(NULL);
            }

            mReplyID = replyID;
            setState(CONFIGURING);

            void *crypto;
            if (!msg->findPointer("crypto", &crypto)) {
                crypto = NULL;
@@ -1180,12 +1186,12 @@ status_t MediaCodec::queueCSDInputBuffer(size_t bufferIndex) {
}

void MediaCodec::setState(State newState) {
    if (newState == INITIALIZED) {
    if (newState == INITIALIZED || newState == UNINITIALIZED) {
        delete mSoftRenderer;
        mSoftRenderer = NULL;

        mCrypto.clear();
        mNativeWindow.clear();
        setNativeWindow(NULL);

        mOutputFormat.clear();
        mFlags &= ~kFlagOutputFormatChanged;
@@ -1425,4 +1431,37 @@ ssize_t MediaCodec::dequeuePortBuffer(int32_t portIndex) {
    return index;
}

status_t MediaCodec::setNativeWindow(
        const sp<SurfaceTextureClient> &surfaceTextureClient) {
    status_t err;

    if (mNativeWindow != NULL) {
        err = native_window_api_disconnect(
                mNativeWindow.get(), NATIVE_WINDOW_API_MEDIA);

        if (err != OK) {
            ALOGW("native_window_api_disconnect returned an error: %s (%d)",
                    strerror(-err), err);
        }

        mNativeWindow.clear();
    }

    if (surfaceTextureClient != NULL) {
        err = native_window_api_connect(
                surfaceTextureClient.get(), NATIVE_WINDOW_API_MEDIA);

        if (err != OK) {
            ALOGE("native_window_api_connect returned an error: %s (%d)",
                    strerror(-err), err);

            return err;
        }

        mNativeWindow = surfaceTextureClient;
    }

    return OK;
}

}  // namespace android