Camera: Fix passing video native handle for 64-bit app
Add new binder calls to pass video native handle so the video native
handle can be passed between 32-bit and 64-bit processes.
Remove problematic code that used IMemory to pass video native
handle because the sizes of VideoNativeMetadata are different in
32-bit and 64-bit processes.
Bug: 28403412
Change-Id: I3341b1812ecc41d61846bb72ca926ecb1674c9ec
diff --git a/camera/ICameraClient.cpp b/camera/ICameraClient.cpp
index d058138..68cbfb8 100644
--- a/camera/ICameraClient.cpp
+++ b/camera/ICameraClient.cpp
@@ -31,6 +31,7 @@
NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION,
DATA_CALLBACK,
DATA_CALLBACK_TIMESTAMP,
+ RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP,
};
class BpCameraClient: public BpInterface<ICameraClient>
@@ -78,15 +79,18 @@
data.writeInt64(timestamp);
data.writeInt32(msgType);
data.writeStrongBinder(IInterface::asBinder(imageData));
- // If imageData is metadata and it contains a native handle, write the native handle to
- // parcel.
- if (CameraUtils::isNativeHandleMetadata(imageData)) {
- VideoNativeHandleMetadata *metadata =
- (VideoNativeHandleMetadata*)(imageData->pointer());
- data.writeNativeHandle(metadata->pHandle);
- }
remote()->transact(DATA_CALLBACK_TIMESTAMP, data, &reply, IBinder::FLAG_ONEWAY);
}
+
+ void recordingFrameHandleCallbackTimestamp(nsecs_t timestamp, native_handle_t* handle) {
+ ALOGV("recordingFrameHandleCallbackTimestamp");
+ Parcel data, reply;
+ data.writeInterfaceToken(ICameraClient::getInterfaceDescriptor());
+ data.writeInt64(timestamp);
+ data.writeNativeHandle(handle);
+ remote()->transact(RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP, data, &reply,
+ IBinder::FLAG_ONEWAY);
+ }
};
IMPLEMENT_META_INTERFACE(CameraClient, "android.hardware.ICameraClient");
@@ -128,20 +132,26 @@
nsecs_t timestamp = data.readInt64();
int32_t msgType = data.readInt32();
sp<IMemory> imageData = interface_cast<IMemory>(data.readStrongBinder());
-
- // If the image data contains a native handle, read the native handle from the parcel
- // and replace the native handle in the image data. (The native handle in image data is
- // not serielized/deserialized so it's not valid in the process.)
- if (CameraUtils::isNativeHandleMetadata(imageData)) {
- VideoNativeHandleMetadata *metadata =
- (VideoNativeHandleMetadata*)(imageData->pointer());
- metadata->pHandle = data.readNativeHandle();
-
- // The native handle will be freed in
- // BpCameraRecordingProxyListener::releaseRecordingFrame.
+ dataCallbackTimestamp(timestamp, msgType, imageData);
+ return NO_ERROR;
+ } break;
+ case RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP: {
+ ALOGV("RECORDING_FRAME_HANDLE_CALLBACK_TIMESTAMP");
+ CHECK_INTERFACE(ICameraClient, data, reply);
+ nsecs_t timestamp;
+ status_t res = data.readInt64(×tamp);
+ if (res != OK) {
+ ALOGE("%s: Failed to read timestamp: %s (%d)", __FUNCTION__, strerror(-res), res);
+ return BAD_VALUE;
+ }
+ native_handle_t* handle = data.readNativeHandle();
+ if (handle == nullptr) {
+ ALOGE("%s: Received a null native handle", __FUNCTION__);
+ return BAD_VALUE;
}
- dataCallbackTimestamp(timestamp, msgType, imageData);
+ // The native handle will be freed in BpCamera::releaseRecordingFrameHandle.
+ recordingFrameHandleCallbackTimestamp(timestamp, handle);
return NO_ERROR;
} break;
default: