-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathgstinferenceprediction.c
808 lines (613 loc) · 20.7 KB
/
gstinferenceprediction.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
/*
* GStreamer
* Copyright (C) 2018-2020 RidgeRun <support@ridgerun.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#include "gstinferenceprediction.h"
static GType gst_inference_prediction_get_type (void);
GST_DEFINE_MINI_OBJECT_TYPE (GstInferencePrediction, gst_inference_prediction);
typedef struct _PredictionScaleData PredictionScaleData;
struct _PredictionScaleData
{
GstVideoInfo *from;
GstVideoInfo *to;
};
typedef struct _PredictionFindData PredictionFindData;
struct _PredictionFindData
{
GstInferencePrediction *prediction;
guint64 prediction_id;
};
static void gst_inference_prediction_free (GstInferencePrediction * self);
static GstInferencePrediction *prediction_copy (const GstInferencePrediction *
self);
static void prediction_free (GstInferencePrediction * obj);
static gboolean prediction_find (GstInferencePrediction * obj,
PredictionFindData * found);
static GstInferencePrediction *prediction_find_unlocked (GstInferencePrediction
* self, guint64 id);
static void prediction_reset (GstInferencePrediction * self);
static gchar *prediction_to_string (GstInferencePrediction * self, gint level);
static gchar *prediction_children_to_string (GstInferencePrediction * self,
gint level);
static gchar *prediction_classes_to_string (GstInferencePrediction * self,
gint level);
static GstInferencePrediction *prediction_scale (const GstInferencePrediction *
self, GstVideoInfo * to, GstVideoInfo * from);
static void prediction_scale_ip (GstInferencePrediction * self,
GstVideoInfo * to, GstVideoInfo * from);
static GSList *prediction_get_children_unlocked (GstInferencePrediction * self);
static gboolean prediction_merge (GstInferencePrediction * src,
GstInferencePrediction * dst);
static void prediction_get_enabled (GstInferencePrediction * self,
GList ** enabled);
static GstInferenceClassification
* classification_copy (GstInferenceClassification * from, gpointer data);
static void classification_merge (GList * src, GList ** dst);
static gint classification_compare (gconstpointer a, gconstpointer b);
static void bounding_box_reset (BoundingBox * bbox);
static gchar *bounding_box_to_string (BoundingBox * bbox, gint level);
static void node_get_children (GNode * node, gpointer data);
static gpointer node_copy (gconstpointer node, gpointer data);
static gboolean node_scale_ip (GNode * node, gpointer data);
static gpointer node_scale (gconstpointer, gpointer data);
static gboolean node_assign (GNode * node, gpointer data);
static gboolean node_find (GNode * node, gpointer data);
static gboolean node_get_enabled (GNode * node, gpointer data);
static void compute_factors (GstVideoInfo * from, GstVideoInfo * to,
gdouble * hfactor, gdouble * vfactor);
static guint64 get_new_id (void);
static guint64
get_new_id (void)
{
static guint64 _id = G_GUINT64_CONSTANT (0);
static GMutex _id_mutex;
static guint64 ret = 0;
g_mutex_lock (&_id_mutex);
ret = _id++;
g_mutex_unlock (&_id_mutex);
return ret;
}
GstInferencePrediction *
gst_inference_prediction_new (void)
{
GstInferencePrediction *self = g_slice_new (GstInferencePrediction);
gst_mini_object_init (GST_MINI_OBJECT_CAST (self), 0,
gst_inference_prediction_get_type (),
(GstMiniObjectCopyFunction) gst_inference_prediction_copy, NULL,
(GstMiniObjectFreeFunction) gst_inference_prediction_free);
g_mutex_init (&self->mutex);
self->predictions = NULL;
self->classifications = NULL;
prediction_reset (self);
return self;
}
GstInferencePrediction *
gst_inference_prediction_new_full (BoundingBox * bbox)
{
GstInferencePrediction *self = NULL;
g_return_val_if_fail (bbox, NULL);
self = gst_inference_prediction_new ();
GST_INFERENCE_PREDICTION_LOCK (self);
self->bbox = *bbox;
GST_INFERENCE_PREDICTION_UNLOCK (self);
return self;
}
GstInferencePrediction *
gst_inference_prediction_ref (GstInferencePrediction * self)
{
g_return_val_if_fail (self, NULL);
return (GstInferencePrediction *)
gst_mini_object_ref (GST_MINI_OBJECT_CAST (self));
}
void
gst_inference_prediction_unref (GstInferencePrediction * self)
{
g_return_if_fail (self);
gst_mini_object_unref (GST_MINI_OBJECT_CAST (self));
}
void
gst_inference_prediction_append (GstInferencePrediction * self,
GstInferencePrediction * child)
{
g_return_if_fail (self);
g_return_if_fail (child);
GST_INFERENCE_PREDICTION_LOCK (self);
GST_INFERENCE_PREDICTION_LOCK (child);
g_node_append (self->predictions, child->predictions);
GST_INFERENCE_PREDICTION_UNLOCK (child);
GST_INFERENCE_PREDICTION_UNLOCK (self);
}
static GstInferenceClassification *
classification_copy (GstInferenceClassification * from, gpointer data)
{
return gst_inference_classification_copy (from);
}
static GstInferencePrediction *
prediction_copy (const GstInferencePrediction * self)
{
GstInferencePrediction *other = NULL;
g_return_val_if_fail (self, NULL);
other = gst_inference_prediction_new ();
other->prediction_id = self->prediction_id;
other->enabled = self->enabled;
other->bbox = self->bbox;
other->classifications =
g_list_copy_deep (self->classifications, (GCopyFunc) classification_copy,
NULL);
return other;
}
static gpointer
node_copy (gconstpointer node, gpointer data)
{
GstInferencePrediction *self = (GstInferencePrediction *) node;
g_return_val_if_fail (node, NULL);
return prediction_copy (self);
}
static gboolean
node_assign (GNode * node, gpointer data)
{
GstInferencePrediction *pred = (GstInferencePrediction *) node->data;
g_return_val_if_fail (node, FALSE);
pred->predictions = node;
return FALSE;
}
GstInferencePrediction *
gst_inference_prediction_copy (const GstInferencePrediction * self)
{
GNode *other = NULL;
g_return_val_if_fail (self, NULL);
GST_INFERENCE_PREDICTION_LOCK ((GstInferencePrediction *) self);
/* Copy the binary tree */
other = g_node_copy_deep (self->predictions, node_copy, NULL);
/* Now finish assigning the nodes to the predictions */
g_node_traverse (other, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_assign, NULL);
GST_INFERENCE_PREDICTION_UNLOCK ((GstInferencePrediction *) self);
return (GstInferencePrediction *) other->data;
}
static gchar *
bounding_box_to_string (BoundingBox * bbox, gint level)
{
gint indent = level * 2;
g_return_val_if_fail (bbox, NULL);
return g_strdup_printf ("{\n"
"%*s \"x\" : %d,\n"
"%*s \"y\" : %d,\n"
"%*s \"width\" : %u,\n"
"%*s \"height\" : %u\n"
"%*s}",
indent, "", bbox->x,
indent, "", bbox->y,
indent, "", bbox->width, indent, "", bbox->height, indent, "");
}
static gchar *
prediction_children_to_string (GstInferencePrediction * self, gint level)
{
GSList *subpreds = NULL;
GSList *iter = NULL;
GString *string = NULL;
g_return_val_if_fail (self, NULL);
/* Build the child predictions using a GString */
string = g_string_new (NULL);
subpreds = prediction_get_children_unlocked (self);
for (iter = subpreds; iter != NULL; iter = g_slist_next (iter)) {
GstInferencePrediction *pred = (GstInferencePrediction *) iter->data;
gchar *child = prediction_to_string (pred, level + 1);
if (iter == subpreds) {
/* The first element does not need a comma prepended */
g_string_append_printf (string, "%s", child);
} else {
/* Check if more than one element to add list separator */
g_string_append_printf (string, ",%s", child);
}
g_free (child);
}
g_slist_free (subpreds);
return g_string_free (string, FALSE);
}
static gchar *
prediction_classes_to_string (GstInferencePrediction * self, gint level)
{
GList *iter = NULL;
GString *string = NULL;
g_return_val_if_fail (self, NULL);
/* Build the classes for this predictions using a GString */
string = g_string_new (NULL);
for (iter = self->classifications; iter != NULL; iter = g_list_next (iter)) {
GstInferenceClassification *c = (GstInferenceClassification *) iter->data;
gchar *sclass = gst_inference_classification_to_string (c, level + 1);
g_string_append_printf (string, "%s ", sclass);
g_free (sclass);
}
return g_string_free (string, FALSE);
}
static gchar *
prediction_to_string (GstInferencePrediction * self, gint level)
{
gint indent = level * 2;
gchar *bbox = NULL;
gchar *children = NULL;
gchar *classes = NULL;
gchar *prediction = NULL;
g_return_val_if_fail (self, NULL);
bbox = bounding_box_to_string (&self->bbox, level + 1);
classes = prediction_classes_to_string (self, level + 1);
children = prediction_children_to_string (self, level + 1);
prediction = g_strdup_printf ("{\n"
"%*s \"id\" : %" G_GUINT64_FORMAT ",\n"
"%*s \"enabled\" : \"%s\",\n"
"%*s \"bbox\" : %s,\n"
"%*s \"classes\" : [\n"
"%*s %s\n"
"%*s ],\n"
"%*s \"predictions\" : [\n"
"%*s %s\n"
"%*s ]\n"
"%*s}",
indent, "", self->prediction_id,
indent, "", self->enabled ? "True" : "False",
indent, "", bbox,
indent, "", indent, "", classes, indent, "",
indent, "", indent, "", children, indent, "", indent, "");
g_free (bbox);
g_free (children);
g_free (classes);
return prediction;
}
gchar *
gst_inference_prediction_to_string (GstInferencePrediction * self)
{
gchar *serial = NULL;
g_return_val_if_fail (self, NULL);
GST_INFERENCE_PREDICTION_LOCK (self);
serial = prediction_to_string (self, 0);
GST_INFERENCE_PREDICTION_UNLOCK (self);
return serial;
}
static void
node_get_children (GNode * node, gpointer data)
{
GSList **children = (GSList **) data;
GstInferencePrediction *prediction;
g_return_if_fail (node);
g_return_if_fail (children);
prediction = (GstInferencePrediction *) node->data;
*children = g_slist_append (*children, prediction);
}
static GSList *
prediction_get_children_unlocked (GstInferencePrediction * self)
{
GSList *children = NULL;
g_return_val_if_fail (self, NULL);
if (self->predictions) {
g_node_children_foreach (self->predictions, G_TRAVERSE_ALL,
node_get_children, &children);
}
return children;
}
GSList *
gst_inference_prediction_get_children (GstInferencePrediction * self)
{
GSList *children = NULL;
GST_INFERENCE_PREDICTION_LOCK (self);
children = prediction_get_children_unlocked (self);
GST_INFERENCE_PREDICTION_UNLOCK (self);
return children;
}
static void
bounding_box_reset (BoundingBox * bbox)
{
g_return_if_fail (bbox);
bbox->x = 0;
bbox->y = 0;
bbox->width = 0;
bbox->height = 0;
}
static void
prediction_reset (GstInferencePrediction * self)
{
g_return_if_fail (self);
self->prediction_id = get_new_id ();
self->enabled = TRUE;
bounding_box_reset (&self->bbox);
/* Free al children */
prediction_free (self);
self->predictions = g_node_new (self);
}
static void
prediction_free (GstInferencePrediction * self)
{
GSList *children = prediction_get_children_unlocked (self);
/* Free all children recursively */
g_slist_free_full (children, (GDestroyNotify) gst_inference_prediction_unref);
/* Now free our classifications */
g_list_free_full (self->classifications,
(GDestroyNotify) gst_inference_classification_unref);
self->classifications = NULL;
if (self->predictions) {
g_node_destroy (self->predictions);
self->predictions = NULL;
}
}
static void
gst_inference_prediction_free (GstInferencePrediction * self)
{
g_return_if_fail (self);
prediction_free (self);
g_mutex_clear (&self->mutex);
}
void
gst_inference_prediction_append_classification (GstInferencePrediction * self,
GstInferenceClassification * c)
{
g_return_if_fail (self);
g_return_if_fail (c);
GST_INFERENCE_PREDICTION_LOCK (self);
self->classifications = g_list_append (self->classifications, c);
GST_INFERENCE_PREDICTION_UNLOCK (self);
}
static void
compute_factors (GstVideoInfo * from, GstVideoInfo * to, gdouble * hfactor,
gdouble * vfactor)
{
gint fw, fh, tw, th;
g_return_if_fail (from);
g_return_if_fail (to);
g_return_if_fail (hfactor);
g_return_if_fail (vfactor);
fw = GST_VIDEO_INFO_WIDTH (from);
tw = GST_VIDEO_INFO_WIDTH (to);
fh = GST_VIDEO_INFO_HEIGHT (from);
th = GST_VIDEO_INFO_HEIGHT (to);
g_return_if_fail (fw);
g_return_if_fail (fh);
*hfactor = tw * 1.0 / fw;
*vfactor = th * 1.0 / fh;
}
static GstInferencePrediction *
prediction_scale (const GstInferencePrediction * self, GstVideoInfo * to,
GstVideoInfo * from)
{
GstInferencePrediction *dest = NULL;
gdouble hfactor, vfactor;
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (to, NULL);
g_return_val_if_fail (from, NULL);
dest = prediction_copy (self);
compute_factors (from, to, &hfactor, &vfactor);
dest->bbox.x = self->bbox.x * hfactor;
dest->bbox.y = self->bbox.y * vfactor;
dest->bbox.width = self->bbox.width * hfactor;
dest->bbox.height = self->bbox.height * vfactor;
GST_LOG ("scaled bbox: %dx%d@%dx%d -> %dx%d@%dx%d",
self->bbox.x, self->bbox.y, self->bbox.width,
self->bbox.height, dest->bbox.x, dest->bbox.y,
dest->bbox.width, dest->bbox.height);
return dest;
}
static void
prediction_scale_ip (GstInferencePrediction * self, GstVideoInfo * to,
GstVideoInfo * from)
{
gdouble hfactor, vfactor;
g_return_if_fail (self);
g_return_if_fail (to);
g_return_if_fail (from);
compute_factors (from, to, &hfactor, &vfactor);
self->bbox.x = self->bbox.x * hfactor;
self->bbox.y = self->bbox.y * vfactor;
self->bbox.width = self->bbox.width * hfactor;
self->bbox.height = self->bbox.height * vfactor;
}
static gboolean
node_scale_ip (GNode * node, gpointer data)
{
GstInferencePrediction *self = (GstInferencePrediction *) node->data;
PredictionScaleData *sdata = (PredictionScaleData *) data;
prediction_scale_ip (self, sdata->to, sdata->from);
return FALSE;
}
static gpointer
node_scale (gconstpointer node, gpointer data)
{
const GstInferencePrediction *self = (GstInferencePrediction *) node;
PredictionScaleData *sdata = (PredictionScaleData *) data;
return prediction_scale (self, sdata->to, sdata->from);
}
void
gst_inference_prediction_scale_ip (GstInferencePrediction * self,
GstVideoInfo * to, GstVideoInfo * from)
{
PredictionScaleData data = {.from = from,.to = to };
g_return_if_fail (self);
g_return_if_fail (to);
g_return_if_fail (from);
GST_INFERENCE_PREDICTION_LOCK (self);
g_node_traverse (self->predictions, G_IN_ORDER, G_TRAVERSE_ALL, -1,
node_scale_ip, &data);
GST_INFERENCE_PREDICTION_UNLOCK (self);
}
GstInferencePrediction *
gst_inference_prediction_scale (GstInferencePrediction * self,
GstVideoInfo * to, GstVideoInfo * from)
{
GNode *other = NULL;
PredictionScaleData data = {.from = from,.to = to };
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (to, NULL);
g_return_val_if_fail (from, NULL);
GST_INFERENCE_PREDICTION_LOCK (self);
other = g_node_copy_deep (self->predictions, node_scale, &data);
/* Now finish assigning the nodes to the predictions */
g_node_traverse (other, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_assign, NULL);
GST_INFERENCE_PREDICTION_UNLOCK (self);
return (GstInferencePrediction *) other->data;
}
static gboolean
prediction_find (GstInferencePrediction * obj, PredictionFindData * found)
{
gboolean ret = FALSE;
g_return_val_if_fail (obj, TRUE);
g_return_val_if_fail (found, TRUE);
if (obj->prediction_id == found->prediction_id) {
found->prediction = gst_inference_prediction_ref (obj);
ret = TRUE;
}
return ret;
}
static gboolean
node_find (GNode * node, gpointer data)
{
PredictionFindData *found = (PredictionFindData *) data;
GstInferencePrediction *current = (GstInferencePrediction *) node->data;
g_return_val_if_fail (found, TRUE);
return prediction_find (current, found);
}
static GstInferencePrediction *
prediction_find_unlocked (GstInferencePrediction * self, guint64 id)
{
PredictionFindData found = { 0, id };
g_return_val_if_fail (self, NULL);
g_node_traverse (self->predictions, G_IN_ORDER, G_TRAVERSE_ALL, -1, node_find,
&found);
return found.prediction;
}
GstInferencePrediction *
gst_inference_prediction_find (GstInferencePrediction * self, guint64 id)
{
GstInferencePrediction *found = NULL;
g_return_val_if_fail (self, NULL);
GST_INFERENCE_PREDICTION_LOCK (self);
found = prediction_find_unlocked (self, id);
GST_INFERENCE_PREDICTION_UNLOCK (self);
return found;
}
static gint
classification_compare (gconstpointer a, gconstpointer b)
{
GstInferenceClassification *ca = (GstInferenceClassification *) a;
GstInferenceClassification *cb = (GstInferenceClassification *) b;
return ca->classification_id == cb->classification_id ? 0 : 1;
}
static void
classification_merge (GList * src, GList ** dst)
{
GList *iter = NULL;
g_return_if_fail (dst);
/* For each classification in the src, see if it exists in the dst */
for (iter = src; iter; iter = g_list_next (iter)) {
GList *exists =
g_list_find_custom (*dst, iter->data, classification_compare);
/* Copy and append it to the dst if it doesn't exist */
if (!exists) {
GstInferenceClassification *child =
gst_inference_classification_copy (iter->data);
*dst = g_list_append (*dst, child);
}
}
}
static gboolean
prediction_merge (GstInferencePrediction * src, GstInferencePrediction * dst)
{
GSList *src_children = prediction_get_children_unlocked (src);
GSList *iter = NULL;
GSList *new_children = NULL;
gboolean new_added = FALSE;
g_return_val_if_fail (src, FALSE);
g_return_val_if_fail (dst, FALSE);
g_return_val_if_fail (src->prediction_id == dst->prediction_id, FALSE);
/* Two things might've happened:
* 1) A new class was added
* 2) A new subprediction was added
*/
/* Handle 1) here */
classification_merge (src->classifications, &dst->classifications);
/* Handle 2) here */
for (iter = src_children; iter; iter = g_slist_next (iter)) {
GstInferencePrediction *current = (GstInferencePrediction *) iter->data;
/* TODO: Optimize this by only searching the immediate children */
GstInferencePrediction *found =
prediction_find_unlocked (dst, current->prediction_id);
/* No matching prediction, save it to append it later */
if (!found) {
new_children = g_slist_append (new_children, current);
continue;
}
/* Recurse into the children */
new_added = prediction_merge (current, found);
gst_inference_prediction_unref (found);
}
/* Finally append all the new children to dst. Do it after all
children have been processed */
for (iter = new_children; iter; iter = g_slist_next (iter)) {
GstInferencePrediction *prediction =
gst_inference_prediction_copy ((GstInferencePrediction *) iter->data);
gst_inference_prediction_append (dst, prediction);
}
new_added |= new_children ? TRUE : FALSE;
g_slist_free (src_children);
g_slist_free_full (new_children,
(GDestroyNotify) gst_inference_prediction_unref);
return new_added;
}
gboolean
gst_inference_prediction_merge (GstInferencePrediction * src,
GstInferencePrediction * dst)
{
gboolean needs_scale = FALSE;
g_return_val_if_fail (src, FALSE);
g_return_val_if_fail (dst, FALSE);
if (src == dst) {
return needs_scale;
}
GST_INFERENCE_PREDICTION_LOCK (src);
GST_INFERENCE_PREDICTION_LOCK (dst);
needs_scale = prediction_merge (src, dst);
GST_INFERENCE_PREDICTION_UNLOCK (dst);
GST_INFERENCE_PREDICTION_UNLOCK (src);
return needs_scale;
}
static void
prediction_get_enabled (GstInferencePrediction * self, GList ** found)
{
g_return_if_fail (self);
g_return_if_fail (found);
if (self->enabled) {
*found = g_list_append (*found, self);
}
}
static gboolean
node_get_enabled (GNode * node, gpointer data)
{
GstInferencePrediction *self = NULL;
GList **found = (GList **) data;
g_return_val_if_fail (node, TRUE);
g_return_val_if_fail (found, TRUE);
self = (GstInferencePrediction *) node->data;
prediction_get_enabled (self, found);
return FALSE;
}
GList *
gst_inference_prediction_get_enabled (GstInferencePrediction * self)
{
GList *found = NULL;
g_return_val_if_fail (self, NULL);
g_node_traverse (self->predictions, G_IN_ORDER, G_TRAVERSE_ALL, -1,
node_get_enabled, &found);
return found;
}