diff --git a/include/vcl/CustomVCL.h b/include/vcl/CustomVCL.h deleted file mode 100644 index 069ea26b..00000000 --- a/include/vcl/CustomVCL.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once -#include -#include -#include - -#include -#include -#include - -#include -#include - -#include - -#include "../ExceptionsCommand.h" -#include "Image.h" - -#define SHARED_IMAGE_BUFFER_SIZE 134217728 -enum class vcl_message_type { VCL_MESSAGE_HEARTBEAT = 1, VCL_MESSAGE_DATA }; - -// structure for message queue -// first byte of message must be non negative long -typedef struct data_msg { - long message_type; - unsigned int data_rows; - unsigned int data_cols; - unsigned int data_type; - unsigned int data_image_size; - unsigned int data_json_size; -} data_message; - -typedef struct hb_msg { - long message_type; - unsigned int status; -} heartbeat_message; - -int custom_vcl_function(VCL::Image &img, const Json::Value &ops); diff --git a/include/vcl/utils.h b/include/vcl/utils.h index e6156cb4..a91ad6eb 100644 --- a/include/vcl/utils.h +++ b/include/vcl/utils.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2017 Intel Corporation + * @copyright Copyright (c) 2024 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,9 +29,10 @@ #pragma once -#include #include #include +#include +#include namespace VCL { diff --git a/src/BlobCommand.h b/src/BlobCommand.h index 5aafaeb3..8fd9056c 100644 --- a/src/BlobCommand.h +++ b/src/BlobCommand.h @@ -5,7 +5,7 @@ * * The MIT License * - * @copyright Copyright (c) 2017 Intel Corporation + * @copyright Copyright (c) 2024 Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), @@ -30,7 +30,6 @@ */ #pragma once -#include "vcl/CustomVCL.h" #include "vcl/Image.h" #include #include diff --git a/src/ImageCommand.cc b/src/ImageCommand.cc index 76543834..796d8858 100644 --- a/src/ImageCommand.cc +++ b/src/ImageCommand.cc @@ -79,22 +79,6 @@ int ImageCommand::enqueue_operations(VCL::Image &img, const Json::Value &ops, } } else if (type == "userOp") { img.userOperation(get_value(op, "options")); - } else if (type == "custom") { - VCL::Image *tmp_image = new VCL::Image(img, true); - try { - if (custom_vcl_function(img, op) != 0) { - img.deep_copy_cv(tmp_image->get_cvmat( - true)); // function completed but error detected - delete tmp_image; - return -1; - } - } catch (...) { - img.deep_copy_cv( - tmp_image->get_cvmat(true)); // function threw exception - delete tmp_image; - return -1; - } - delete tmp_image; } else { throw ExceptionCommand(ImageError, "Operation not defined"); return -1; diff --git a/src/ImageCommand.h b/src/ImageCommand.h index 982d5d5a..0afc7b01 100644 --- a/src/ImageCommand.h +++ b/src/ImageCommand.h @@ -30,7 +30,6 @@ */ #pragma once -#include "vcl/CustomVCL.h" #include "vcl/Image.h" #include #include diff --git a/src/vcl/CMakeLists.txt b/src/vcl/CMakeLists.txt index d3a7a1ad..ba36faa3 100644 --- a/src/vcl/CMakeLists.txt +++ b/src/vcl/CMakeLists.txt @@ -23,9 +23,8 @@ add_library(vcl SHARED TDBSparseDescriptorSet.cc utils.cc Video.cc - CustomVCL.cc RemoteConnection.cc - ../../utils/src/timers/TimerMap.cc + ../../utils/src/timers/TimerMap.cc ) link_directories( /usr/local/lib ) target_link_libraries(vcl lapack faiss tiledb flinng avformat avcodec swscale ${OpenCV_LIBS}) diff --git a/src/vcl/CustomVCL.cc b/src/vcl/CustomVCL.cc deleted file mode 100644 index dca5cd6e..00000000 --- a/src/vcl/CustomVCL.cc +++ /dev/null @@ -1,111 +0,0 @@ -#include "vcl/CustomVCL.h" - -int custom_vcl_function(VCL::Image &img, const Json::Value &ops) { - int return_value = 0; - // create IPC structures for communicating between processes - key_t key_ctl_host_remote; - key_ctl_host_remote = ftok("vdms", 60); - int msgid_ctl_host_remote = msgget(key_ctl_host_remote, 0666 | IPC_CREAT); - data_message message_ctl_host_remote; - // need size of data message excluding message_type field for msgsnd and - // msgrcv - size_t data_message_size = sizeof(message_ctl_host_remote.data_rows) + - sizeof(message_ctl_host_remote.data_cols) + - sizeof(message_ctl_host_remote.data_type) + - sizeof(message_ctl_host_remote.data_image_size) + - sizeof(message_ctl_host_remote.data_json_size); - - key_t key_data_host_remote; - key_data_host_remote = ftok("vdms", 61); - int shmid_data_host_remote = - shmget(key_data_host_remote, SHARED_IMAGE_BUFFER_SIZE, 0666 | IPC_CREAT); - uint8_t *image_buffer = - (uint8_t *)shmat(shmid_data_host_remote, (void *)0, 0); - - key_t key_ctl_remote_host; - key_ctl_remote_host = ftok("vdms", 62); - int msgid_ctl_remote_host = msgget(key_ctl_remote_host, 0666 | IPC_CREAT); - data_message message_ctl_remote_host; - - heartbeat_message message_hb_host_remote; - heartbeat_message message_hb_remote_host; - size_t heartbeat_message_size = sizeof(message_hb_host_remote.status); - - // Pass messages to ensure the remote process is functional - message_hb_host_remote.message_type = - (long)vcl_message_type::VCL_MESSAGE_HEARTBEAT; - message_hb_host_remote.status = 0; - int out_alive_msg_status = - msgsnd(msgid_ctl_host_remote, &message_hb_host_remote, - heartbeat_message_size, 0); - - int hb_count = 0; - int in_alive_msg_status = -1; - - // try 10 times to determine if process is running - while (hb_count < 10 && in_alive_msg_status < 0) { - in_alive_msg_status = msgrcv( - msgid_ctl_remote_host, &message_hb_remote_host, heartbeat_message_size, - (long)vcl_message_type::VCL_MESSAGE_HEARTBEAT, IPC_NOWAIT); - hb_count++; - } - - if (in_alive_msg_status > -1) { - // Read image from file and obtain image information to calculate size - cv::Mat in_image = img.get_cvmat(true); - - size_t in_image_size = in_image.total() * in_image.elemSize(); - message_ctl_host_remote.message_type = - (long)vcl_message_type::VCL_MESSAGE_DATA; - message_ctl_host_remote.data_rows = in_image.rows; - message_ctl_host_remote.data_cols = in_image.cols; - message_ctl_host_remote.data_type = in_image.type(); - message_ctl_host_remote.data_image_size = in_image_size; - - // Copy image data into shared memory - memcpy((uint8_t *)&(image_buffer[0]), (uint8_t *)&(in_image.data[0]), - in_image_size); - - std::string *json_string = new std::string(ops.toStyledString()); - message_ctl_host_remote.data_json_size = json_string->size(); - // image size corresponds with first byte after the image - memcpy(&(image_buffer[in_image_size]), json_string->c_str(), - json_string->size()); - int msg_send_result = msgsnd( - msgid_ctl_host_remote, &message_ctl_host_remote, data_message_size, 0); - if (msg_send_result < 0) { - delete json_string; - return -1; - } - - int msg_recv_result = - msgrcv(msgid_ctl_remote_host, &message_ctl_remote_host, - data_message_size, (long)vcl_message_type::VCL_MESSAGE_DATA, 0); - - if (msg_recv_result < 0) { - } - - // Grab data back from shared memory - cv::Mat *out_image = new cv::Mat(message_ctl_remote_host.data_rows, - message_ctl_remote_host.data_cols, - message_ctl_remote_host.data_type); - memcpy(&(out_image->data[0]), &(image_buffer[0]), - message_ctl_remote_host.data_image_size); - - img.deep_copy_cv(*out_image); - - // Free allocated memory - delete out_image; - delete json_string; - - // Free shared IPC components - shmdt(image_buffer); - // msgctl(msgid_ctl_remote_host, IPC_RMID, NULL); - return_value = 0; - } else { - return_value = -1; - throw VDMS::ExceptionCommand(ImageError, "Error in custom Function"); - } - - return return_value; -} diff --git a/src/vcl/Image.cc b/src/vcl/Image.cc index ef5b4f47..42e30e6b 100644 --- a/src/vcl/Image.cc +++ b/src/vcl/Image.cc @@ -538,10 +538,6 @@ void Image::UserOperation::operator()(Image *img) { zmq::context_t context(1); zmq::socket_t socket(context, zmq::socket_type::req); - // This is setting a timeout for avoiding infinite loops - socket.setsockopt(ZMQ_SNDTIMEO, 10000); // milliseconds - socket.setsockopt(ZMQ_RCVTIMEO, 30000); - std::string port = _options["port"].asString(); std::string address = "tcp://127.0.0.1:" + port; @@ -601,7 +597,7 @@ void Image::UserOperation::operator()(Image *img) { } else { if (response == "") { std::string errorMessage = - "UserOperation error: Timeout, no response from the server"; + "UserOperation error: empty response from the server"; std::cout << errorMessage << std::endl; throw VCLException(SystemNotFound, errorMessage); } diff --git a/src/vcl/Video.cc b/src/vcl/Video.cc index e446dc46..f0f97df5 100644 --- a/src/vcl/Video.cc +++ b/src/vcl/Video.cc @@ -1252,9 +1252,6 @@ void Video::UserOperation::operator()(Video *video, cv::Mat &frame, zmq::context_t context(1); zmq::socket_t socket(context, zmq::socket_type::req); - // This is setting a timeout for avoiding infinite loops - socket.setsockopt(ZMQ_SNDTIMEO, 10000); // milliseconds - socket.setsockopt(ZMQ_RCVTIMEO, 30000); std::string port = _options["port"].asString(); std::string address = "tcp://127.0.0.1:" + port; @@ -1296,7 +1293,7 @@ void Video::UserOperation::operator()(Video *video, cv::Mat &frame, } else { if (response == "") { std::string errorMessage = - "UserOperation error: Timeout, no response from the server"; + "UserOperation error: empty response from the server"; std::cout << errorMessage << std::endl; throw VCLException(SystemNotFound, errorMessage); }