38 _release_server_data (gpointer
data)
45 g_mutex_lock (&_data->
lock);
47 nns_edge_release_handle (_data->
edge_h);
50 g_mutex_unlock (&_data->
lock);
52 g_mutex_clear (&_data->
lock);
53 g_cond_clear (&_data->
cond);
66 G_LOCK (query_server_table);
67 data = g_hash_table_lookup (
_qs_table, GUINT_TO_POINTER (
id));
68 G_UNLOCK (query_server_table);
90 nns_loge (
"Failed to allocate memory for tensor query server data.");
94 g_mutex_init (&
data->lock);
95 g_cond_init (&
data->cond);
99 G_LOCK (query_server_table);
100 ret = g_hash_table_insert (
_qs_table, GUINT_TO_POINTER (
id),
data);
102 _release_server_data (
data);
103 nns_loge (
"Failed to add tensor query server data into the table.");
105 G_UNLOCK (query_server_table);
118 gchar *port_str, *id_str;
119 gboolean prepared =
FALSE;
127 g_mutex_lock (&
data->lock);
128 if (
data->edge_h == NULL) {
129 id_str = g_strdup_printf (
"%u",
id);
131 ret = nns_edge_create_handle (id_str, connect_type,
132 NNS_EDGE_NODE_TYPE_QUERY_SERVER, &
data->edge_h);
135 if (NNS_EDGE_ERROR_NONE != ret) {
136 GST_ERROR (
"Failed to get nnstreamer edge handle.");
142 if (edge_info->
host) {
143 nns_edge_set_info (
data->edge_h,
"HOST", edge_info->
host);
145 if (edge_info->
port > 0) {
146 port_str = g_strdup_printf (
"%u", edge_info->
port);
147 nns_edge_set_info (
data->edge_h,
"PORT", port_str);
151 nns_edge_set_info (
data->edge_h,
"DEST_HOST", edge_info->
dest_host);
154 port_str = g_strdup_printf (
"%u", edge_info->
dest_port);
155 nns_edge_set_info (
data->edge_h,
"DEST_PORT", port_str);
158 if (edge_info->
topic) {
159 nns_edge_set_info (
data->edge_h,
"TOPIC", edge_info->
topic);
162 nns_edge_set_event_callback (
data->edge_h, edge_info->
cb, edge_info->
pdata);
164 ret = nns_edge_start (
data->edge_h);
165 if (NNS_EDGE_ERROR_NONE != ret) {
167 (
"Failed to start NNStreamer-edge. Please check server IP and port.");
175 g_mutex_unlock (&
data->lock);
187 nns_edge_data_h data_h;
188 guint i, num_tensors = 0;
189 gint ret = NNS_EDGE_ERROR_NONE;
193 gboolean sent =
FALSE;
198 nns_loge (
"Failed to send buffer, server handle is null.");
204 nns_loge (
"Failed to send buffer, cannot get tensor query meta.");
208 ret = nns_edge_data_create (&data_h);
209 if (ret != NNS_EDGE_ERROR_NONE) {
210 nns_loge (
"Failed to create edge data handle in query server.");
215 for (i = 0; i < num_tensors; i++) {
218 if (!gst_memory_map (mem[i], &map[i], GST_MAP_READ)) {
219 ml_loge (
"Cannot map the %uth memory in gst-buffer.", i);
220 gst_memory_unref (mem[i]);
225 nns_edge_data_add (data_h, map[i].
data, map[i].size, NULL);
228 val = g_strdup_printf (
"%lld", (
long long) meta_query->
client_id);
229 nns_edge_data_set_info (data_h,
"client_id", val);
232 g_mutex_lock (&
data->lock);
233 ret = nns_edge_send (
data->edge_h, data_h);
234 g_mutex_unlock (&
data->lock);
236 if (ret != NNS_EDGE_ERROR_NONE) {
237 nns_loge (
"Failed to send edge data handle in query server.");
244 for (i = 0; i < num_tensors; i++) {
245 gst_memory_unmap (mem[i], &map[i]);
246 gst_memory_unref (mem[i]);
249 nns_edge_data_destroy (data_h);
268 g_mutex_lock (&
data->lock);
270 nns_edge_release_handle (
data->edge_h);
273 g_mutex_unlock (&
data->lock);
282 G_LOCK (query_server_table);
283 if (g_hash_table_lookup (
_qs_table, GUINT_TO_POINTER (
id)))
284 g_hash_table_remove (
_qs_table, GUINT_TO_POINTER (
id));
285 G_UNLOCK (query_server_table);
303 end_time = g_get_monotonic_time () +
305 g_mutex_lock (&
data->lock);
306 while (!
data->configured) {
307 if (!g_cond_wait_until (&
data->cond, &
data->lock, end_time)) {
308 g_mutex_unlock (&
data->lock);
309 ml_loge (
"Failed to get server sink info.");
313 g_mutex_unlock (&
data->lock);
332 g_mutex_lock (&
data->lock);
334 g_cond_broadcast (&
data->cond);
335 g_mutex_unlock (&
data->lock);
345 gchar *prev_caps_str, *new_caps_str;
353 g_mutex_lock (&
data->lock);
355 prev_caps_str = new_caps_str = NULL;
356 nns_edge_get_info (
data->edge_h,
"CAPS", &prev_caps_str);
358 prev_caps_str = g_strdup (
"");
359 new_caps_str = g_strdup_printf (
"%s%s", prev_caps_str, caps_str);
360 nns_edge_set_info (
data->edge_h,
"CAPS", new_caps_str);
365 g_mutex_unlock (&
data->lock);
374 G_LOCK (query_server_table);
376 _qs_table = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
377 _release_server_data);
378 G_UNLOCK (query_server_table);
387 G_LOCK (query_server_table);
391 G_UNLOCK (query_server_table);