summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/MediaCodec.cpp
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2012-05-10 10:54:15 -0700
committerAndreas Huber <andih@google.com>2012-05-10 10:54:15 -0700
commit7541ff5d83a3e77cb533841a0326a241550b95d9 (patch)
tree7ead109f66a97f4290ce58948b90703374d99ad3 /media/libstagefright/MediaCodec.cpp
parentc150ca7dda844891fa684f6898da7f7e0c40329d (diff)
downloadframeworks_av-7541ff5d83a3e77cb533841a0326a241550b95d9.zip
frameworks_av-7541ff5d83a3e77cb533841a0326a241550b95d9.tar.gz
frameworks_av-7541ff5d83a3e77cb533841a0326a241550b95d9.tar.bz2
Properly connect/disconnect to/from the native window in MediaCodec.
Change-Id: Ib5bf90a3b81fca8ff2346235bc28a2bd0bc7bfb1 related-to-bug: 6472161
Diffstat (limited to 'media/libstagefright/MediaCodec.cpp')
-rw-r--r--media/libstagefright/MediaCodec.cpp59
1 files changed, 49 insertions, 10 deletions
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index e032cfc..5b513a8 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -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 =
- static_cast<NativeWindowWrapper *>(obj.get())
- ->getSurfaceTextureClient();
+ status_t err = setNativeWindow(
+ static_cast<NativeWindowWrapper *>(obj.get())
+ ->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