Add semantic data dispatch to runner IPC
semantic data is copied to the client.
Bug: 146464279
Change-Id: Ib14a97bc13c94912a093fd6e99da411770ed04de
diff --git a/computepipe/runner/utils/InterfaceImpl.cc b/computepipe/runner/utils/InterfaceImpl.cc
index 245e59b..67b7bc6 100644
--- a/computepipe/runner/utils/InterfaceImpl.cc
+++ b/computepipe/runner/utils/InterfaceImpl.cc
@@ -12,14 +12,18 @@
// See the License for the specific language governing permissions and
// limitations under the License.c
-#define LOG_TAG "RunnerIpcInterface"
-
#include "InterfaceImpl.h"
-#include <android-base/logging.h>
+#include "OutputConfig.pb.h"
#include "PacketDescriptor.pb.h"
#include "PipeOptionsConverter.h"
+#define LOG_TAG "RunnerIpcInterface"
+#include <aidl/android/automotive/computepipe/runner/PacketDescriptor.h>
+#include <aidl/android/automotive/computepipe/runner/PacketDescriptorPacketType.h>
+#include <android-base/logging.h>
+#include <android/binder_auto_utils.h>
+
namespace android {
namespace automotive {
namespace computepipe {
@@ -28,6 +32,8 @@
using ::aidl::android::automotive::computepipe::runner::IPipeStateCallback;
using ::aidl::android::automotive::computepipe::runner::IPipeStream;
+using ::aidl::android::automotive::computepipe::runner::PacketDescriptor;
+using ::aidl::android::automotive::computepipe::runner::PacketDescriptorPacketType;
using ::aidl::android::automotive::computepipe::runner::PipeDescriptor;
using ::aidl::android::automotive::computepipe::runner::PipeState;
using ::ndk::ScopedAStatus;
@@ -67,13 +73,65 @@
iface->clientDied();
}
+Status ToAidlPacketType(proto::PacketType type, PacketDescriptorPacketType& outType) {
+ switch (type) {
+ case proto::SEMANTIC_DATA:
+ outType = PacketDescriptorPacketType::SEMANTIC_DATA;
+ return Status::SUCCESS;
+ case proto::PIXEL_DATA:
+ outType = PacketDescriptorPacketType::PIXEL_DATA;
+ return Status::SUCCESS;
+ default:
+ LOG(ERROR) << "unknown packet type " << type;
+ return Status::INVALID_ARGUMENT;
+ }
+}
+
} // namespace
+Status InterfaceImpl::DispatchSemanticData(int32_t streamId,
+ const std::shared_ptr<MemHandle>& packetHandle) {
+ PacketDescriptor desc;
+
+ if (mPacketHandlers.find(streamId) == mPacketHandlers.end()) {
+ LOG(ERROR) << "Bad streamId";
+ return Status::INVALID_ARGUMENT;
+ }
+ Status status = ToAidlPacketType(packetHandle->getType(), desc.type);
+ if (status != SUCCESS) {
+ return status;
+ }
+ desc.data = packetHandle->getData();
+ desc.size = packetHandle->getSize();
+ if (static_cast<int32_t>(desc.data.size()) != desc.size) {
+ LOG(ERROR) << "mismatch in char data size and reported size";
+ return Status::INVALID_ARGUMENT;
+ }
+ desc.sourceTimeStampMillis = packetHandle->getTimeStamp();
+ desc.bufId = 0;
+ ScopedAStatus ret = mPacketHandlers[streamId]->deliverPacket(desc);
+ if (!ret.isOk()) {
+ LOG(ERROR) << "Dropping Semantic packet due to error ";
+ }
+ return Status::SUCCESS;
+}
+
// Thread-safe function to deliver new packets to client.
Status InterfaceImpl::newPacketNotification(int32_t streamId,
const std::shared_ptr<MemHandle>& packetHandle) {
// TODO(146464279) implement.
- (void)packetHandle;
+ if (!packetHandle) {
+ LOG(ERROR) << "invalid packetHandle";
+ return Status::INVALID_ARGUMENT;
+ }
+ proto::PacketType packetType = packetHandle->getType();
+ switch (packetType) {
+ case proto::SEMANTIC_DATA:
+ return DispatchSemanticData(streamId, packetHandle);
+ default:
+ LOG(ERROR) << "Unsupported packet type " << packetHandle->getType();
+ return Status::INVALID_ARGUMENT;
+ }
return Status::SUCCESS;
}
diff --git a/computepipe/runner/utils/InterfaceImpl.h b/computepipe/runner/utils/InterfaceImpl.h
index 26684c2..6727659 100644
--- a/computepipe/runner/utils/InterfaceImpl.h
+++ b/computepipe/runner/utils/InterfaceImpl.h
@@ -20,13 +20,12 @@
#include <memory>
#include <string>
-#include "RunnerInterfaceCallbacks.h"
#include "MemHandle.h"
+#include "Options.pb.h"
+#include "RunnerInterfaceCallbacks.h"
#include "types/GraphState.h"
#include "types/Status.h"
-#include "Options.pb.h"
-
namespace android {
namespace automotive {
namespace computepipe {
@@ -75,6 +74,9 @@
void clientDied();
private:
+ // Dispatch semantic data to client. Has copy semantics and does not expect
+ // client to invoke doneWithPacket.
+ Status DispatchSemanticData(int32_t streamId, const std::shared_ptr<MemHandle>& packetHandle);
const proto::Options mGraphOptions;
const RunnerInterfaceCallbacks& mRunnerInterfaceCallbacks;