#include <tensor_meta.h>\r
#include <unistd.h>\r
\r
-#include "../gst/nnstreamer/elements/gsttensor_sparseutil.h"\r
-#include "../gst/nnstreamer/elements/gsttensor_transform.h"\r
-#include "../unittest_util.h"\r
-\r
-#if defined(ENABLE_TENSORFLOW_LITE) || defined(ENABLE_TENSORFLOW2_LITE)\r
-#define TEST_REQUIRE_TFLITE(Case, Name) TEST (Case, Name)\r
-#else\r
-#define TEST_REQUIRE_TFLITE(Case, Name) TEST (Case, DISABLED_##Name)\r
-#endif\r
\r
/**\r
* @brief Call back function for tensor_region to parse outbuf\r
- * \r
+ *\r
* @param sink The sink element\r
* @param user_data User data passed to the callback function\r
*/\r
-static void new_data_cb(GstElement* sink, const gpointer user_data)\r
+static void\r
+new_data_cb (GstElement *sink, const gpointer user_data)\r
{\r
- GstSample* sample = nullptr;\r
+ GstSample *sample = nullptr;\r
\r
- g_signal_emit_by_name(sink, "pull-sample", &sample);\r
+ g_signal_emit_by_name (sink, "pull-sample", &sample);\r
\r
/** Expected values of cropping info for orange.png */\r
- guint32 expected_values[] = {58, 62, 219, 211};\r
+ guint32 expected_values[] = { 58U, 62U, 219U, 211U };\r
\r
if (sample != nullptr) {\r
- GstBuffer* outbuf = gst_sample_get_buffer(sample);\r
- GstMemory* mem = gst_buffer_peek_memory(outbuf, 0);\r
+ GstBuffer *outbuf = gst_sample_get_buffer (sample);\r
+ GstMemory *mem = gst_buffer_peek_memory (outbuf, 0);\r
\r
if (mem != nullptr) {\r
GstMapInfo out_info;\r
\r
- if (gst_memory_map(mem, &out_info, GST_MAP_READ)) {\r
+ if (gst_memory_map (mem, &out_info, GST_MAP_READ)) {\r
GstTensorMetaInfo map;\r
- int* data_ptr = nullptr;\r
+ guint32 *data_ptr = nullptr;\r
\r
- gst_tensor_meta_info_parse_header(&map, out_info.data);\r
+ gst_tensor_meta_info_parse_header (&map, out_info.data);\r
\r
- gsize hsize = gst_tensor_meta_info_get_header_size(&map);\r
- gsize dsize = gst_tensor_meta_info_get_data_size(&map);\r
- ASSERT_EQ(map.type, _NNS_UINT32);\r
+ gsize hsize = gst_tensor_meta_info_get_header_size (&map);\r
+ gsize dsize = gst_tensor_meta_info_get_data_size (&map);\r
+ ASSERT_EQ (_NNS_UINT32, map.type);\r
\r
- gsize esize = sizeof(guint32);\r
+ gsize esize = sizeof (guint32);\r
\r
- ASSERT_EQ(hsize + dsize, out_info.size);\r
- ASSERT_EQ((dsize % (esize * 4)), 0);\r
+ ASSERT_EQ (hsize + dsize, out_info.size);\r
+ ASSERT_EQ (0U, (dsize % (esize * 4)));\r
\r
- data_ptr = reinterpret_cast<int*>(out_info.data + hsize);\r
+ data_ptr = (guint32 *) (out_info.data + hsize);\r
\r
for (int i = 0; i < 4; i++) {\r
- EXPECT_EQ(data_ptr[i], expected_values[i]);\r
+ EXPECT_EQ (expected_values[i], data_ptr[i]);\r
}\r
\r
- gst_memory_unmap(mem, &out_info);\r
+ gst_memory_unmap (mem, &out_info);\r
}\r
}\r
\r
- gst_sample_unref(sample);\r
+ gst_sample_unref (sample);\r
}\r
}\r
\r
* @brief Structure to hold information related to TensorRegion.\r
*/\r
struct TensorRegion {\r
- GstElement* pipeline; /**< The pipeline element */\r
- GstElement* app_sink; /**< The app sink element */\r
- GMainLoop* main_loop; /**< The main loop */\r
+ GstElement *pipeline; /**< The pipeline element */\r
+ GstElement *app_sink; /**< The app sink element */\r
};\r
\r
\r
* @param data Pointer to the TensorRegion structure.\r
* @return gboolean Returns TRUE to continue receiving messages.\r
*/\r
-static gboolean on_pipeline_message(GstBus* bus, GstMessage* message, TensorRegion* data)\r
+static gboolean\r
+on_pipeline_message (GstBus *bus, GstMessage *message, TensorRegion *data)\r
{\r
- switch (GST_MESSAGE_TYPE(message)) {\r
+ switch (GST_MESSAGE_TYPE (message)) {\r
case GST_MESSAGE_EOS:\r
- g_main_loop_quit(data->main_loop);\r
break;\r
- case GST_MESSAGE_ERROR: {\r
- g_print("Received error\n");\r
-\r
- GError* err = NULL;\r
- gchar* dbg_info = NULL;\r
-\r
- gst_message_parse_error(message, &err, &dbg_info);\r
- g_printerr("ERROR from element %s: %s\n", GST_OBJECT_NAME(message->src), err->message);\r
- g_printerr("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");\r
- g_error_free(err);\r
- g_free(dbg_info);\r
- }\r
+ case GST_MESSAGE_ERROR:\r
+ {\r
+ g_print ("Received error\n");\r
+\r
+ GError *err = NULL;\r
+ gchar *dbg_info = NULL;\r
+\r
+ gst_message_parse_error (message, &err, &dbg_info);\r
+ g_printerr ("ERROR from element %s: %s\n",\r
+ GST_OBJECT_NAME (message->src), err->message);\r
+ g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");\r
+ g_error_free (err);\r
+ g_free (dbg_info);\r
+ }\r
\r
- g_main_loop_quit(data->main_loop);\r
- break;\r
+ break;\r
case GST_MESSAGE_STATE_CHANGED:\r
break;\r
default:\r
}\r
\r
/** Return FALSE to stop receiving messages after the callback function\r
- * has handled the current message. */\r
+ * has handled the current message. */\r
return G_SOURCE_CONTINUE;\r
}\r
\r
/**\r
* @brief Test for tensor_decoder::tensor_region\r
*/\r
-TEST_REQUIRE_TFLITE (TensorDecoder, TensorRegion)\r
+TEST (tensorDecoder, tensorRegion)\r
{\r
- GstBus* bus;\r
- const gchar* root_path = g_getenv("NNSTREAMER_SOURCE_ROOT_PATH");\r
+ GstBus *bus;\r
+ const gchar *root_path = g_getenv ("NNSTREAMER_SOURCE_ROOT_PATH");\r
if (root_path == nullptr)\r
root_path = "..";\r
\r
- const gchar* tensor_0 = g_build_filename(root_path, "tests", "nnstreamer_decoder_tensor_region", "mobilenet_ssd_tensor.0", nullptr);\r
- const gchar* tensor_1 = g_build_filename(root_path, "tests", "nnstreamer_decoder_tensor_region", "mobilenet_ssd_tensor.1", nullptr);\r
- const gchar* labels_path = g_build_filename(root_path, "tests", "test_models", "labels", "labels.txt", nullptr);\r
- const gchar* box_priors_path = g_build_filename(root_path, "tests", "nnstreamer_decoder_boundingbox", "box_priors.txt", nullptr);\r
+ const gchar *tensor_0 = g_build_filename (root_path, "tests",\r
+ "nnstreamer_decoder_tensor_region", "mobilenet_ssd_tensor.0", nullptr);\r
+ const gchar *tensor_1 = g_build_filename (root_path, "tests",\r
+ "nnstreamer_decoder_tensor_region", "mobilenet_ssd_tensor.1", nullptr);\r
+ const gchar *labels_path = g_build_filename (\r
+ root_path, "tests", "test_models", "labels", "labels.txt", nullptr);\r
+ const gchar *box_priors_path = g_build_filename (root_path, "tests",\r
+ "nnstreamer_decoder_boundingbox", "box_priors.txt", nullptr);\r
\r
- ASSERT_TRUE(g_file_test(tensor_0, G_FILE_TEST_EXISTS));\r
- ASSERT_TRUE(g_file_test(tensor_1, G_FILE_TEST_EXISTS));\r
- ASSERT_TRUE(g_file_test(labels_path, G_FILE_TEST_EXISTS));\r
- ASSERT_TRUE(g_file_test(box_priors_path, G_FILE_TEST_EXISTS));\r
+ ASSERT_TRUE (g_file_test (tensor_0, G_FILE_TEST_EXISTS));\r
+ ASSERT_TRUE (g_file_test (tensor_1, G_FILE_TEST_EXISTS));\r
+ ASSERT_TRUE (g_file_test (labels_path, G_FILE_TEST_EXISTS));\r
+ ASSERT_TRUE (g_file_test (box_priors_path, G_FILE_TEST_EXISTS));\r
\r
/** Create the GStreamer pipeline */\r
- gchar* pipeline_str = g_strdup_printf(\r
- "multifilesrc name=fs1 location=%s start-index=0 stop-index=1 caps=application/octet-stream ! tensor_converter name=el1 input-dim=4:1:1917:1 input-type=float32 ! mux.sink_0 \\r
+ gchar *pipeline_str = g_strdup_printf ("multifilesrc name=fs1 location=%s start-index=0 stop-index=1 caps=application/octet-stream ! tensor_converter name=el1 input-dim=4:1:1917:1 input-type=float32 ! mux.sink_0 \\r
multifilesrc name=fs2 location=%s start-index=0 stop-index=1 caps=application/octet-stream ! tensor_converter name=el2 input-dim=91:1917:1 input-type=float32 ! mux.sink_1 \\r
tensor_mux name=mux ! other/tensors,format=static ! tensor_decoder mode=tensor_region option1=1 option2=%s option3=%s ! appsink name=sinkx ",\r
tensor_0, tensor_1, labels_path, box_priors_path);\r
\r
- GstElement* pipeline = gst_parse_launch(pipeline_str, nullptr);\r
- g_free(pipeline_str);\r
+ GstElement *pipeline = gst_parse_launch (pipeline_str, nullptr);\r
+ g_free (pipeline_str);\r
\r
- GstElement* app_sink = gst_bin_get_by_name(GST_BIN(pipeline), "sinkx");\r
+ GstElement *app_sink = gst_bin_get_by_name (GST_BIN (pipeline), "sinkx");\r
\r
/** Create the TensorRegion structure and assign pipeline and app_sink */\r
TensorRegion data;\r
data.pipeline = pipeline;\r
data.app_sink = app_sink;\r
- bus = gst_element_get_bus(data.pipeline);\r
- gst_bus_add_watch(bus, (GstBusFunc)on_pipeline_message, &data);\r
- gst_object_unref(bus);\r
+ bus = gst_element_get_bus (data.pipeline);\r
+ gst_bus_add_watch (bus, (GstBusFunc) on_pipeline_message, &data);\r
+ gst_object_unref (bus);\r
\r
/** Enable signal emission from the app_sink */\r
- g_object_set(app_sink, "emit-signals", TRUE, NULL);\r
+ g_object_set (app_sink, "emit-signals", TRUE, NULL);\r
\r
/** Connect the new-sample callback to the app_sink */\r
- g_signal_connect(app_sink, "new-sample", G_CALLBACK(new_data_cb), nullptr);\r
+ g_signal_connect (app_sink, "new-sample", G_CALLBACK (new_data_cb), nullptr);\r
\r
/** Start playing the pipeline */\r
- gst_element_set_state(pipeline, GST_STATE_PLAYING);\r
+ gst_element_set_state (pipeline, GST_STATE_PLAYING);\r
\r
- /** Create a GLib Main Loop and set it to run */\r
- data.main_loop = g_main_loop_new(NULL, FALSE);\r
- g_main_loop_run(data.main_loop);\r
+ g_usleep (1000000);\r
\r
/** Free resources */\r
- gst_element_set_state(pipeline, GST_STATE_NULL);\r
- gst_object_unref(pipeline);\r
+ gst_element_set_state (pipeline, GST_STATE_NULL);\r
+ gst_object_unref (pipeline);\r
+\r
+ /** Unref app_sink */\r
+ gst_object_unref (app_sink);\r
}\r
\r
\r