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
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
|
/* GStreamer
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wtay@chello.be>
*
* gstelement.c: The base element, all elements derive from this
*
* 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.
*/
/* #define GST_DEBUG_ENABLED */
#include <glib.h>
#include <stdarg.h>
#include "gst_private.h"
#include "gstelement.h"
#include "gstextratypes.h"
#include "gstbin.h"
#include "gstscheduler.h"
#include "gstevent.h"
#include "gstutils.h"
/* Element signals and args */
enum {
STATE_CHANGE,
NEW_PAD,
PAD_REMOVED,
ERROR,
EVENT,
EOS,
LAST_SIGNAL
};
enum {
ARG_0,
/* FILL ME */
};
static void gst_element_class_init (GstElementClass *klass);
static void gst_element_init (GstElement *element);
static void gst_element_base_class_init (GstElementClass *klass);
static void gst_element_set_property (GObject *object, guint prop_id,
const GValue *value, GParamSpec *pspec);
static void gst_element_get_property (GObject *object, guint prop_id, GValue *value,
GParamSpec *pspec);
static void gst_element_dispose (GObject *object);
static GstElementStateReturn gst_element_change_state (GstElement *element);
static void gst_element_send_event_func (GstElement *element, GstEvent *event);
#ifndef GST_DISABLE_LOADSAVE
static xmlNodePtr gst_element_save_thyself (GstObject *object, xmlNodePtr parent);
GstElement* gst_element_restore_thyself (xmlNodePtr self, GstObject *parent);
#endif
GType _gst_element_type = 0;
static GstObjectClass *parent_class = NULL;
static guint gst_element_signals[LAST_SIGNAL] = { 0 };
GType gst_element_get_type (void)
{
if (!_gst_element_type) {
static const GTypeInfo element_info = {
sizeof(GstElementClass),
(GBaseInitFunc)gst_element_base_class_init,
NULL,
(GClassInitFunc)gst_element_class_init,
NULL,
NULL,
sizeof(GstElement),
0,
(GInstanceInitFunc)gst_element_init,
NULL
};
_gst_element_type = g_type_register_static(GST_TYPE_OBJECT, "GstElement", &element_info, G_TYPE_FLAG_ABSTRACT);
}
return _gst_element_type;
}
static void
gst_element_class_init (GstElementClass *klass)
{
GObjectClass *gobject_class;
GstObjectClass *gstobject_class;
gobject_class = (GObjectClass*) klass;
gstobject_class = (GstObjectClass*) klass;
parent_class = g_type_class_ref(GST_TYPE_OBJECT);
gst_element_signals[STATE_CHANGE] =
g_signal_new ("state_change", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstElementClass, state_change), NULL, NULL,
gst_marshal_VOID__INT_INT, G_TYPE_NONE, 2,
G_TYPE_INT, G_TYPE_INT);
gst_element_signals[NEW_PAD] =
g_signal_new ("new_pad", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstElementClass, new_pad), NULL, NULL,
gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
G_TYPE_POINTER);
gst_element_signals[PAD_REMOVED] =
g_signal_new ("pad_removed", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstElementClass, pad_removed), NULL, NULL,
gst_marshal_VOID__POINTER, G_TYPE_NONE, 1,
G_TYPE_POINTER);
gst_element_signals[ERROR] =
g_signal_new ("error", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstElementClass, error), NULL, NULL,
gst_marshal_VOID__STRING, G_TYPE_NONE,1,
G_TYPE_STRING);
gst_element_signals[EVENT] =
g_signal_new ("event", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstElementClass, event), NULL, NULL,
gst_marshal_VOID__POINTER, G_TYPE_NONE,1,
G_TYPE_POINTER);
gst_element_signals[EOS] =
g_signal_new ("eos", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GstElementClass,eos), NULL, NULL,
gst_marshal_VOID__VOID, G_TYPE_NONE, 0);
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_element_set_property);
gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_element_get_property);
gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_element_dispose);
#ifndef GST_DISABLE_LOADSAVE
gstobject_class->save_thyself = GST_DEBUG_FUNCPTR (gst_element_save_thyself);
gstobject_class->restore_thyself = GST_DEBUG_FUNCPTR (gst_element_restore_thyself);
#endif
klass->change_state = GST_DEBUG_FUNCPTR (gst_element_change_state);
klass->send_event = GST_DEBUG_FUNCPTR (gst_element_send_event_func);
klass->elementfactory = NULL;
klass->padtemplates = NULL;
klass->numpadtemplates = 0;
}
static void
gst_element_base_class_init (GstElementClass *klass)
{
GObjectClass *gobject_class;
gobject_class = (GObjectClass*) klass;
gobject_class->set_property = GST_DEBUG_FUNCPTR(gst_element_set_property);
gobject_class->get_property = GST_DEBUG_FUNCPTR(gst_element_get_property);
}
static void
gst_element_init (GstElement *element)
{
element->current_state = GST_STATE_NULL;
element->pending_state = GST_STATE_VOID_PENDING;
element->numpads = 0;
element->numsrcpads = 0;
element->numsinkpads = 0;
element->pads = NULL;
element->loopfunc = NULL;
element->sched = NULL;
element->sched_private = NULL;
element->state_mutex = g_mutex_new ();
element->state_cond = g_cond_new ();
}
static void
gst_element_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
GstElementClass *oclass = (GstElementClass *)G_OBJECT_GET_CLASS(object);
if (oclass->set_property)
(oclass->set_property)(object,prop_id,value,pspec);
}
static void
gst_element_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
GstElementClass *oclass = (GstElementClass *)G_OBJECT_GET_CLASS(object);
if (oclass->get_property)
(oclass->get_property)(object,prop_id,value,pspec);
}
/**
* gst_element_set_name:
* @element: GstElement to set name of
* @name: new name of element
*
* Set the name of the element, getting rid of the old name if there was
* one.
*/
void
gst_element_set_name (GstElement *element, const gchar *name)
{
g_return_if_fail (element != NULL);
g_return_if_fail (GST_IS_ELEMENT (element));
g_return_if_fail (name != NULL);
gst_object_set_name (GST_OBJECT (element), name);
}
/**
* gst_element_get_name:
* @element: GstElement to get name of
*
* Get the name of the element.
*
* Returns: name of the element
*/
const gchar*
gst_element_get_name (GstElement *element)
{
g_return_val_if_fail (element != NULL, NULL);
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
return GST_OBJECT_NAME (element);
}
/**
* gst_element_set_parent:
* @element: GstElement to set parent of
* @parent: new parent of the object
*
* Set the parent of the element.
*/
void
gst_element_set_parent (GstElement *element, GstObject *parent)
{
g_return_if_fail (element != NULL);
g_return_if_fail (GST_IS_ELEMENT (element));
g_return_if_fail (GST_OBJECT_PARENT (element) == NULL);
g_return_if_fail (parent != NULL);
g_return_if_fail (GST_IS_OBJECT (parent));
g_return_if_fail ((gpointer)element != (gpointer)parent);
gst_object_set_parent (GST_OBJECT (element), parent);
}
/**
* gst_element_get_parent:
* @element: GstElement to get the parent of
*
* Get the parent of the element.
*
* Returns: parent of the element
*/
GstObject*
gst_element_get_parent (GstElement *element)
{
g_return_val_if_fail (element != NULL, NULL);
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
return GST_OBJECT_PARENT (element);
}
/**
* gst_element_add_pad:
* @element: element to add pad to
* @pad: pad to add
*
* Add a pad (connection point) to the element, setting the parent of the
* pad to the element (and thus adding a reference).
*/
void
gst_element_add_pad (GstElement *element, GstPad *pad)
{
g_return_if_fail (element != NULL);
g_return_if_fail (GST_IS_ELEMENT (element));
g_return_if_fail (pad != NULL);
g_return_if_fail (GST_IS_PAD (pad));
/* first check to make sure the pad's parent is already set */
g_return_if_fail (GST_PAD_PARENT (pad) == NULL);
/* then check to see if there's already a pad by that name here */
g_return_if_fail (gst_object_check_uniqueness (element->pads, GST_PAD_NAME(pad)) == TRUE);
/* set the pad's parent */
GST_DEBUG (GST_CAT_ELEMENT_PADS,"setting parent of pad '%s' to '%s'\n",
GST_PAD_NAME (pad), GST_ELEMENT_NAME (element));
gst_object_set_parent (GST_OBJECT (pad), GST_OBJECT (element));
/* add it to the list */
element->pads = g_list_append (element->pads, pad);
element->numpads++;
if (gst_pad_get_direction (pad) == GST_PAD_SRC)
element->numsrcpads++;
else
element->numsinkpads++;
/* emit the NEW_PAD signal */
g_signal_emit (G_OBJECT (element), gst_element_signals[NEW_PAD], 0, pad);
}
/**
* gst_element_remove_pad:
* @element: element to remove pad from
* @pad: pad to remove
*
* Remove a pad (connection point) from the element,
*/
void
gst_element_remove_pad (GstElement *element, GstPad *pad)
{
g_return_if_fail (element != NULL);
g_return_if_fail (GST_IS_ELEMENT (element));
g_return_if_fail (pad != NULL);
g_return_if_fail (GST_IS_PAD (pad));
g_return_if_fail (GST_PAD_PARENT (pad) == element);
/* add it to the list */
element->pads = g_list_remove (element->pads, pad);
element->numpads--;
if (gst_pad_get_direction (pad) == GST_PAD_SRC)
element->numsrcpads--;
else
element->numsinkpads--;
g_signal_emit (G_OBJECT (element), gst_element_signals[PAD_REMOVED], 0, pad);
gst_object_unparent (GST_OBJECT (pad));
}
/**
* gst_element_add_ghost_pad:
* @element: element to add ghost pad to
* @pad: pad from which the new ghost pad will be created
* @name: name of the new ghost pad
*
* Create a ghost pad from the given pad, and add it to the list of pads
* for this element.
*/
void
gst_element_add_ghost_pad (GstElement *element, GstPad *pad, gchar *name)
{
GstPad *ghostpad;
g_return_if_fail (element != NULL);
g_return_if_fail (GST_IS_ELEMENT (element));
g_return_if_fail (pad != NULL);
g_return_if_fail (GST_IS_PAD (pad));
/* then check to see if there's already a pad by that name here */
g_return_if_fail (gst_object_check_uniqueness (element->pads, name) == TRUE);
GST_DEBUG(GST_CAT_ELEMENT_PADS,"creating new ghost pad called %s, from pad %s:%s\n",
name,GST_DEBUG_PAD_NAME(pad));
ghostpad = gst_ghost_pad_new (name, pad);
/* add it to the list */
GST_DEBUG(GST_CAT_ELEMENT_PADS,"adding ghost pad %s to element %s\n",
name, GST_ELEMENT_NAME (element));
element->pads = g_list_append (element->pads, ghostpad);
element->numpads++;
/* set the parent of the ghostpad */
gst_object_set_parent (GST_OBJECT (ghostpad), GST_OBJECT (element));
GST_DEBUG(GST_CAT_ELEMENT_PADS,"added ghostpad %s:%s\n",GST_DEBUG_PAD_NAME(ghostpad));
/* emit the NEW_GHOST_PAD signal */
g_signal_emit (G_OBJECT (element), gst_element_signals[NEW_PAD], 0, ghostpad);
}
/**
* gst_element_remove_ghost_pad:
* @element: element to remove the ghost pad from
* @pad: ghost pad to remove
*
* removes a ghost pad from an element
*
*/
void
gst_element_remove_ghost_pad (GstElement *element, GstPad *pad)
{
g_return_if_fail (element != NULL);
g_return_if_fail (GST_IS_ELEMENT (element));
g_return_if_fail (pad != NULL);
g_return_if_fail (GST_IS_GHOST_PAD (pad));
/* FIXME this is redundant?
* wingo 10-july-2001: I don't think so, you have to actually remove the pad
* from the element. gst_pad_remove_ghost_pad just removes the ghostpad from
* the real pad's ghost pad list
*/
gst_pad_remove_ghost_pad (GST_PAD (GST_PAD_REALIZE (pad)), pad);
gst_element_remove_pad (element, pad);
}
/**
* gst_element_get_pad:
* @element: element to find pad of
* @name: name of pad to retrieve
*
* Retrieve a pad from the element by name.
*
* Returns: requested pad if found, otherwise NULL.
*/
GstPad*
gst_element_get_pad (GstElement *element, const gchar *name)
{
GList *walk;
g_return_val_if_fail (element != NULL, NULL);
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
g_return_val_if_fail (name != NULL, NULL);
/* if there aren't any pads, well, we're not likely to find one */
if (!element->numpads)
return NULL;
/* look through the list, matching by name */
walk = element->pads;
while (walk) {
GstPad *pad = GST_PAD(walk->data);
if (!strcmp (GST_PAD_NAME(pad), name)) {
GST_INFO(GST_CAT_ELEMENT_PADS,"found pad %s:%s",GST_DEBUG_PAD_NAME(pad));
return pad;
}
walk = g_list_next (walk);
}
GST_INFO(GST_CAT_ELEMENT_PADS,"no such pad '%s' in element \"%s\"",name,GST_ELEMENT_NAME(element));
return NULL;
}
/**
* gst_element_get_pad_list:
* @element: element to get pads of
*
* Retrieve a list of the pads associated with the element.
*
* Returns: GList of pads
*/
GList*
gst_element_get_pad_list (GstElement *element)
{
g_return_val_if_fail (element != NULL, NULL);
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
/* return the list of pads */
return element->pads;
}
/**
* gst_element_class_add_padtemplate:
* @klass: element class to add padtemplate to
* @templ: padtemplate to add
*
* Add a padtemplate to an element class. This is useful if you have derived a custom
* bin and wish to provide an on-request pad at runtime. Plugin writers should use
* gst_elementfactory_add_padtemplate instead.
*/
void
gst_element_class_add_padtemplate (GstElementClass *klass, GstPadTemplate *templ)
{
g_return_if_fail (klass != NULL);
g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
g_return_if_fail (templ != NULL);
g_return_if_fail (GST_IS_PADTEMPLATE (templ));
klass->padtemplates = g_list_append (klass->padtemplates, templ);
klass->numpadtemplates++;
}
/**
* gst_element_get_padtemplate_list:
* @element: element to get padtemplates of
*
* Retrieve a list of the padtemplates associated with the element.
*
* Returns: GList of padtemplates
*/
GList*
gst_element_get_padtemplate_list (GstElement *element)
{
GstElementClass *oclass;
g_return_val_if_fail (element != NULL, NULL);
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
oclass = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS(element));
return oclass->padtemplates;
}
/**
* gst_element_get_padtemplate_by_name:
* @element: element to get padtemplate of
* @name: the name of the padtemplate to get.
*
* Retrieve a padtemplate from this element with the
* given name.
*
* Returns: the padtemplate with the given name
*/
GstPadTemplate*
gst_element_get_padtemplate_by_name (GstElement *element, const guchar *name)
{
GList *padlist;
g_return_val_if_fail (element != NULL, NULL);
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
g_return_val_if_fail (name != NULL, NULL);
padlist = gst_element_get_padtemplate_list (element);
while (padlist) {
GstPadTemplate *padtempl = (GstPadTemplate*) padlist->data;
if (!strcmp (padtempl->name_template, name))
return padtempl;
padlist = g_list_next (padlist);
}
return NULL;
}
/**
* gst_element_get_padtemplate_by_compatible:
* @element: element to get padtemplate of
* @templ: a template to find a compatible template for
*
* Generate a padtemplate for this element compatible with the given
* template, ie able to link to it.
*
* Returns: the padtemplate
*/
static GstPadTemplate*
gst_element_get_padtemplate_by_compatible (GstElement *element, GstPadTemplate *compattempl)
{
GstPadTemplate *newtempl = NULL;
GList *padlist;
GST_DEBUG(GST_CAT_ELEMENT_PADS,"gst_element_get_padtemplate_by_compatible()\n");
g_return_val_if_fail (element != NULL, NULL);
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
g_return_val_if_fail (compattempl != NULL, NULL);
padlist = gst_element_get_padtemplate_list (element);
while (padlist) {
GstPadTemplate *padtempl = (GstPadTemplate*) padlist->data;
gboolean compat = FALSE;
/* Ignore name
* Ignore presence
* Check direction (must be opposite)
* Check caps
*/
GST_DEBUG(GST_CAT_CAPS,"checking direction and caps\n");
if (padtempl->direction == GST_PAD_SRC &&
compattempl->direction == GST_PAD_SINK) {
GST_DEBUG(GST_CAT_CAPS,"compatible direction: found src pad template\n");
compat = gst_caps_check_compatibility(GST_PADTEMPLATE_CAPS (padtempl),
GST_PADTEMPLATE_CAPS (compattempl));
GST_DEBUG(GST_CAT_CAPS,"caps are %scompatible\n", (compat?"":"not "));
} else if (padtempl->direction == GST_PAD_SINK &&
compattempl->direction == GST_PAD_SRC) {
GST_DEBUG(GST_CAT_CAPS,"compatible direction: found sink pad template\n");
compat = gst_caps_check_compatibility(GST_PADTEMPLATE_CAPS (compattempl),
GST_PADTEMPLATE_CAPS (padtempl));
GST_DEBUG(GST_CAT_CAPS,"caps are %scompatible\n", (compat?"":"not "));
}
if (compat) {
newtempl = padtempl;
break;
}
padlist = g_list_next (padlist);
}
return newtempl;
}
static GstPad*
gst_element_request_pad (GstElement *element, GstPadTemplate *templ, const gchar* name)
{
GstPad *newpad = NULL;
GstElementClass *oclass;
oclass = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS(element));
if (oclass->request_new_pad)
newpad = (oclass->request_new_pad)(element, templ, name);
return newpad;
}
/**
* gst_element_request_compatible_pad:
* @element: element to request a new pad from
* @templ: a pad template to which the new pad should be able to connect
*
* Request a new pad from the element. The template will
* be used to decide what type of pad to create. This function
* is typically used for elements with a padtemplate with presence
* GST_PAD_REQUEST.
*
* Returns: the new pad that was created.
*/
GstPad*
gst_element_request_compatible_pad (GstElement *element, GstPadTemplate *templ)
{
GstPadTemplate *templ_new;
GstPad *pad = NULL;
g_return_val_if_fail (element != NULL, NULL);
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
g_return_val_if_fail (templ != NULL, NULL);
templ_new = gst_element_get_padtemplate_by_compatible (element, templ);
if (templ_new != NULL)
pad = gst_element_request_pad (element, templ_new, NULL);
return pad;
}
/**
* gst_element_request_pad_by_name:
* @element: element to request a new pad from
* @name: the name of the padtemplate to use.
*
* Request a new pad from the element. The name argument will
* be used to decide what padtemplate to use. This function
* is typically used for elements with a padtemplate with presence
* GST_PAD_REQUEST.
*
* Returns: the new pad that was created.
*/
GstPad*
gst_element_request_pad_by_name (GstElement *element, const gchar *name)
{
GstPadTemplate *templ = NULL;
GstPad *pad;
const gchar *req_name = NULL;
gboolean templ_found = FALSE;
GList *list;
gint n;
g_return_val_if_fail (element != NULL, NULL);
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
g_return_val_if_fail (name != NULL, NULL);
if (strstr (name, "%d")) {
templ = gst_element_get_padtemplate_by_name (element, name);
req_name = NULL;
} else {
list = gst_element_get_padtemplate_list(element);
while (!templ_found && list) {
templ = (GstPadTemplate*) list->data;
if (strstr (templ->name_template, "%d")) {
if (sscanf(name, templ->name_template, &n)) {
templ_found = TRUE;
req_name = name;
break;
}
}
list = list->next;
}
}
if (templ == NULL)
return NULL;
pad = gst_element_request_pad (element, templ, req_name);
return pad;
}
/**
* gst_element_connect:
* @src: element containing source pad
* @srcpadname: name of pad in source element
* @dest: element containing destination pad
* @destpadname: name of pad in destination element
*
* Connect the two named pads of the source and destination elements.
* Side effect is that if one of the pads has no parent, it becomes a
* child of the parent of the other element. If they have different
* parents, the connection fails.
*/
void
gst_element_connect (GstElement *src, const gchar *srcpadname,
GstElement *dest, const gchar *destpadname)
{
GstPad *srcpad,*destpad;
g_return_if_fail (src != NULL);
g_return_if_fail (GST_IS_ELEMENT(src));
g_return_if_fail (srcpadname != NULL);
g_return_if_fail (dest != NULL);
g_return_if_fail (GST_IS_ELEMENT(dest));
g_return_if_fail (destpadname != NULL);
/* obtain the pads requested */
srcpad = gst_element_get_pad (src, srcpadname);
if (srcpad == NULL) {
GST_ERROR(src,"source element has no pad \"%s\"",srcpadname);
return;
}
destpad = gst_element_get_pad (dest, destpadname);
if (srcpad == NULL) {
GST_ERROR(dest,"destination element has no pad \"%s\"",destpadname);
return;
}
/* we're satisified they can be connected, let's do it */
gst_pad_connect(srcpad,destpad);
}
/**
* gst_element_disconnect:
* @src: element containing source pad
* @srcpadname: name of pad in source element
* @dest: element containing destination pad
* @destpadname: name of pad in destination element
*
* Disconnect the two named pads of the source and destination elements.
*/
void
gst_element_disconnect (GstElement *src, const gchar *srcpadname,
GstElement *dest, const gchar *destpadname)
{
GstPad *srcpad,*destpad;
g_return_if_fail (src != NULL);
g_return_if_fail (GST_IS_ELEMENT(src));
g_return_if_fail (srcpadname != NULL);
g_return_if_fail (dest != NULL);
g_return_if_fail (GST_IS_ELEMENT(dest));
g_return_if_fail (destpadname != NULL);
/* obtain the pads requested */
srcpad = gst_element_get_pad (src, srcpadname);
if (srcpad == NULL) {
GST_ERROR(src,"source element has no pad \"%s\"",srcpadname);
return;
}
destpad = gst_element_get_pad (dest, destpadname);
if (srcpad == NULL) {
GST_ERROR(dest,"destination element has no pad \"%s\"",destpadname);
return;
}
/* we're satisified they can be disconnected, let's do it */
gst_pad_disconnect(srcpad,destpad);
}
static void
gst_element_message (GstElement *element, const gchar *type, const gchar *info, va_list var_args)
{
GstEvent *event;
GstProps *props;
gchar *string;
string = g_strdup_vprintf (info, var_args);
GST_INFO (GST_CAT_EVENT, "%s sends message %s", GST_ELEMENT_NAME (element),
string);
event = gst_event_new_info (type, GST_PROPS_STRING (string), NULL);
gst_element_send_event (element, event);
g_free (string);
}
/**
* gst_element_error:
* @element: Element with the error
* @error: A printf-like string describing the error
* @...: optional arguments for the string
*
* This function is used internally by elements to signal an error
* condition. It results in the "error" signal.
*/
void
gst_element_error (GstElement *element, const gchar *error, ...)
{
va_list var_args;
GstObject *parent;
g_return_if_fail (GST_IS_ELEMENT (element));
g_return_if_fail (error != NULL);
va_start (var_args, error);
gst_element_message (element, "error", error, var_args);
va_end (var_args);
parent = GST_ELEMENT_PARENT (element);
if (parent && GST_IS_BIN (parent)) {
gst_bin_child_error (GST_BIN (parent), element);
}
if (element->sched) {
gst_scheduler_error (element->sched, element);
}
}
/**
* gst_element_info:
* @element: Element with the info
* @info: String describing the info
* @...: arguments for the string.
*
* This function is used internally by elements to signal an info
* condition. It results in the "info" signal.
*/
void
gst_element_info (GstElement *element, const gchar *info, ...)
{
va_list var_args;
g_return_if_fail (GST_IS_ELEMENT (element));
g_return_if_fail (info != NULL);
va_start (var_args, info);
gst_element_message (element, "info", info, var_args);
va_end (var_args);
}
static void
gst_element_send_event_func (GstElement *element, GstEvent *event)
{
if (GST_OBJECT_PARENT (element)) {
gst_element_send_event (GST_ELEMENT (GST_OBJECT_PARENT (element)), event);
}
else {
switch (GST_EVENT_TYPE (event)) {
default:
g_signal_emit (G_OBJECT (element), gst_element_signals[EVENT], 0, event);
}
gst_event_free (event);
}
}
/**
* gst_element_send_event:
* @element: Element generating the event
* @event: the event to send
*
* This function is used intenally by elements to send an event to
* the app. It will result in an "event" signal.
*/
void
gst_element_send_event (GstElement *element, GstEvent *event)
{
GstElementClass *oclass = (GstElementClass *) G_OBJECT_GET_CLASS (element);
g_return_if_fail (GST_IS_ELEMENT (element));
g_return_if_fail (event);
if (GST_EVENT_SRC (event) == NULL)
GST_EVENT_SRC (event) = gst_object_ref (GST_OBJECT (element));
if (oclass->send_event)
(oclass->send_event) (element, event);
}
/**
* gst_element_get_state:
* @element: element to get state of
*
* Gets the state of the element.
*
* Returns: The element state
*/
GstElementState
gst_element_get_state (GstElement *element)
{
g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_VOID_PENDING);
return GST_STATE (element);
}
/**
* gst_element_wait_state_change:
* @element: element wait for
*
* Wait and block until the element changed its state.
*/
void
gst_element_wait_state_change (GstElement *element)
{
g_mutex_lock (element->state_mutex);
g_cond_wait (element->state_cond, element->state_mutex);
g_mutex_unlock (element->state_mutex);
}
/**
* gst_element_set_state:
* @element: element to change state of
* @state: new element state
*
* Sets the state of the element. This function will only set
* the elements pending state.
*
* Returns: whether or not the state was successfully set.
*/
gint
gst_element_set_state (GstElement *element, GstElementState state)
{
GstElementClass *oclass;
GstElementState curpending;
GstElementStateReturn return_val = GST_STATE_SUCCESS;
/* g_print("gst_element_set_state(\"%s\",%08lx)\n", */
/* element->name,state); */
g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_FAILURE);
GST_DEBUG_ELEMENT (GST_CAT_STATES,element, "setting state from %s to %s\n",
gst_element_statename(GST_STATE(element)),
gst_element_statename(state));
/* start with the current state */
curpending = GST_STATE(element);
/* loop until the final requested state is set */
while (GST_STATE(element) != state && GST_STATE (element) != GST_STATE_VOID_PENDING) {
/* move the curpending state in the correct direction */
if (curpending < state) curpending<<=1;
else curpending>>=1;
/* set the pending state variable */
/* FIXME: should probably check to see that we don't already have one */
GST_STATE_PENDING (element) = curpending;
if (curpending != state)
GST_DEBUG_ELEMENT (GST_CAT_STATES,element,"intermediate: setting state to %s\n",
gst_element_statename(curpending));
/* call the state change function so it can set the state */
oclass = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS(element));
if (oclass->change_state)
return_val = (oclass->change_state)(element);
switch (return_val) {
case GST_STATE_FAILURE:
GST_DEBUG_ELEMENT (GST_CAT_STATES,element,"have failed change_state return\n");
return return_val;
case GST_STATE_ASYNC:
GST_DEBUG_ELEMENT (GST_CAT_STATES,element,"element will change state async\n");
return return_val;
default:
/* Last thing we do is verify that a successful state change really
* did change the state... */
if (GST_STATE(element) != curpending) {
GST_DEBUG_ELEMENT (GST_CAT_STATES, element, "element claimed state-change success, but state didn't change\n");
return GST_STATE_FAILURE;
}
break;
}
}
return return_val;
}
static GstElementStateReturn
gst_element_change_state (GstElement *element)
{
GstElementState old_state;
GstObject *parent;
g_return_val_if_fail (GST_IS_ELEMENT (element), GST_STATE_FAILURE);
old_state = GST_STATE (element);
if (GST_STATE_PENDING (element) == GST_STATE_VOID_PENDING || old_state == GST_STATE_PENDING (element)) {
GST_INFO (GST_CAT_STATES, "no state change needed for element %s (VOID_PENDING)", GST_ELEMENT_NAME (element));
return GST_STATE_SUCCESS;
}
GST_INFO (GST_CAT_STATES, "%s default handler sets state from %s to %s %d", GST_ELEMENT_NAME (element),
gst_element_statename (old_state),
gst_element_statename (GST_STATE_PENDING (element)),
GST_STATE_TRANSITION (element));
/* tell the scheduler if we have one */
if (element->sched) {
if (gst_scheduler_state_transition (element->sched, element, GST_STATE_TRANSITION (element))
!= GST_STATE_SUCCESS) {
return GST_STATE_FAILURE;
}
}
GST_STATE (element) = GST_STATE_PENDING (element);
GST_STATE_PENDING (element) = GST_STATE_VOID_PENDING;
parent = GST_ELEMENT_PARENT (element);
if (parent && GST_IS_BIN (parent)) {
gst_bin_child_state_change (GST_BIN (parent), old_state, GST_STATE (element), element);
}
g_mutex_lock (element->state_mutex);
g_cond_signal (element->state_cond);
g_mutex_unlock (element->state_mutex);
return GST_STATE_SUCCESS;
}
/**
* gst_element_get_factory:
* @element: element to request the factory
*
* Retrieves the factory that was used to create this element
*
* Returns: the factory used for creating this element
*/
GstElementFactory*
gst_element_get_factory (GstElement *element)
{
GstElementClass *oclass;
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
oclass = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS(element));
return oclass->elementfactory;
}
static void
gst_element_dispose (GObject *object)
{
GstElement *element = GST_ELEMENT (object);
GList *pads, *test;
GstPad *pad;
gint i;
GST_DEBUG_ELEMENT (GST_CAT_REFCOUNTING, element, "dispose\n");
/* first we break all our connections with the ouside */
if (element->pads) {
GList *orig;
orig = pads = g_list_copy (element->pads);
while (pads) {
pad = GST_PAD (pads->data);
gst_object_destroy (GST_OBJECT (pad));
pads = g_list_next (pads);
}
g_list_free (orig);
g_list_free (element->pads);
element->pads = NULL;
}
element->numsrcpads = 0;
element->numsinkpads = 0;
element->numpads = 0;
g_mutex_free (element->state_mutex);
g_cond_free (element->state_cond);
G_OBJECT_CLASS (parent_class)->dispose (object);
}
#ifndef GST_DISABLE_LOADSAVE
/**
* gst_element_save_thyself:
* @element: GstElement to save
* @parent: the xml parent node
*
* Saves the element as part of the given XML structure
*
* Returns: the new xml node
*/
static xmlNodePtr
gst_element_save_thyself (GstObject *object,
xmlNodePtr parent)
{
GList *pads;
GstElementClass *oclass;
/* FIXME : this is needed for glib2 */
/* GType type; */
GstElement *element;
g_return_val_if_fail (GST_IS_ELEMENT (object), parent);
element = GST_ELEMENT (object);
oclass = GST_ELEMENT_CLASS (G_OBJECT_GET_CLASS(element));
xmlNewChild(parent, NULL, "name", GST_ELEMENT_NAME(element));
if (oclass->elementfactory != NULL) {
GstElementFactory *factory = (GstElementFactory *)oclass->elementfactory;
xmlNewChild (parent, NULL, "type", GST_OBJECT_NAME (factory));
xmlNewChild (parent, NULL, "version", factory->details->version);
}
/* if (element->manager) */
/* xmlNewChild(parent, NULL, "manager", GST_ELEMENT_NAME(element->manager)); */
/* FIXME FIXME FIXME! */
/* output all args to the element */
/*
type = G_OBJECT_TYPE (element);
while (type != G_TYPE_INVALID) {
GtkArg *args;
guint32 *flags;
guint num_args,i;
args = gtk_object_query_args (type, &flags, &num_args);
for (i=0; i<num_args; i++) {
if ((args[i].type > G_TYPE_NONE) &&
(flags[i] & GTK_ARG_READABLE)) {
xmlNodePtr arg;
gtk_object_getv (G_OBJECT (element), 1, &args[i]);
arg = xmlNewChild (parent, NULL, "arg", NULL);
xmlNewChild (arg, NULL, "name", args[i].name);
switch (args[i].type) {
case G_TYPE_CHAR:
xmlNewChild (arg, NULL, "value",
g_strdup_printf ("%c", G_VALUE_CHAR (args[i])));
break;
case G_TYPE_UCHAR:
xmlNewChild (arg, NULL, "value",
g_strdup_printf ("%d", G_VALUE_UCHAR (args[i])));
break;
case G_TYPE_BOOLEAN:
xmlNewChild (arg, NULL, "value",
G_VALUE_BOOL (args[i]) ? "true" : "false");
break;
case G_TYPE_INT:
xmlNewChild (arg, NULL, "value",
g_strdup_printf ("%d", G_VALUE_INT (args[i])));
break;
case G_TYPE_LONG:
xmlNewChild (arg, NULL, "value",
g_strdup_printf ("%ld", G_VALUE_LONG (args[i])));
break;
case G_TYPE_ULONG:
xmlNewChild (arg, NULL, "value",
g_strdup_printf ("%lu", G_VALUE_ULONG (args[i])));
break;
case G_TYPE_FLOAT:
xmlNewChild (arg, NULL, "value",
g_strdup_printf ("%f", G_VALUE_FLOAT (args[i])));
break;
case G_TYPE_DOUBLE:
xmlNewChild (arg, NULL, "value",
g_strdup_printf ("%g", G_VALUE_DOUBLE (args[i])));
break;
case G_TYPE_STRING:
xmlNewChild (arg, NULL, "value", G_VALUE_STRING (args[i]));
break;
default:
if (args[i].type == GST_TYPE_FILENAME) {
xmlNewChild (arg, NULL, "value", G_VALUE_STRING (args[i]));
}
break;
}
}
}
type = gtk_type_parent (type);
}
*/
pads = GST_ELEMENT_PADS (element);
while (pads) {
GstPad *pad = GST_PAD (pads->data);
/* figure out if it's a direct pad or a ghostpad */
if (GST_ELEMENT (GST_OBJECT_PARENT (pad)) == element) {
xmlNodePtr padtag = xmlNewChild (parent, NULL, "pad", NULL);
gst_object_save_thyself (GST_OBJECT (pad), padtag);
}
pads = g_list_next (pads);
}
return parent;
}
/**
* gst_element_restore_thyself:
* @self: the xml node
* @parent: the parent of this object when it's loaded
*
* Load the element from the XML description
*
* Returns: the new element
*/
GstElement*
gst_element_restore_thyself (xmlNodePtr self, GstObject *parent)
{
xmlNodePtr children = self->xmlChildrenNode;
GstElement *element;
GstObjectClass *oclass;
guchar *name = NULL;
guchar *value = NULL;
guchar *type = NULL;
/* first get the needed tags to construct the element */
while (children) {
if (!strcmp (children->name, "name")) {
name = xmlNodeGetContent (children);
} else if (!strcmp (children->name, "type")) {
type = xmlNodeGetContent (children);
}
children = children->next;
}
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (type != NULL, NULL);
GST_INFO (GST_CAT_XML,"loading \"%s\" of type \"%s\"", name, type);
element = gst_elementfactory_make (type, name);
g_return_val_if_fail (element != NULL, NULL);
/* ne need to set the parent on this object bacause the pads */
/* will go through the hierarchy to connect to thier peers */
if (parent)
gst_object_set_parent (GST_OBJECT (element), parent);
/* we have the element now, set the arguments */
children = self->xmlChildrenNode;
while (children) {
if (!strcmp (children->name, "arg")) {
xmlNodePtr child = children->xmlChildrenNode;
while (child) {
if (!strcmp (child->name, "name")) {
name = xmlNodeGetContent (child);
}
else if (!strcmp (child->name, "value")) {
value = xmlNodeGetContent (child);
}
child = child->next;
}
gst_util_set_object_arg ((GObject *)G_OBJECT (element), name, value);
}
children = children->next;
}
/* we have the element now, set the pads */
children = self->xmlChildrenNode;
while (children) {
if (!strcmp (children->name, "pad")) {
gst_pad_load_and_connect (children, GST_OBJECT (element));
}
children = children->next;
}
oclass = GST_OBJECT_CLASS (G_OBJECT_GET_CLASS(element));
if (oclass->restore_thyself)
(oclass->restore_thyself) (GST_OBJECT (element), self);
if (parent)
gst_object_unparent (GST_OBJECT (element));
gst_class_signal_emit_by_name (GST_OBJECT (element), "object_loaded", self);
return element;
}
#endif /* GST_DISABLE_LOADSAVE */
/**
* gst_element_yield:
* @element: Element to yield
*
* Request a yield operation for the child. The scheduler will typically
* give control to another element.
*/
void
gst_element_yield (GstElement *element)
{
if (GST_ELEMENT_SCHED (element)) {
gst_scheduler_yield (GST_ELEMENT_SCHED (element), element);
}
}
/**
* gst_element_interrupt:
* @element: Element to interrupt
*
* Request the scheduler of this element to interrupt the execution of
* this element and scheduler another one.
*
* Returns: a boolean indicating that the child should exit its chain/loop/get
* function ASAP, depending on the scheduler implementation.
*/
gboolean
gst_element_interrupt (GstElement *element)
{
if (GST_ELEMENT_SCHED (element)) {
return gst_scheduler_interrupt (GST_ELEMENT_SCHED (element), element);
}
else
return FALSE;
}
/**
* gst_element_set_sched:
* @element: Element to set manager of.
* @sched: @GstScheduler to set.
*
* Sets the scheduler of the element. For internal use only, unless you're
* writing a new bin subclass.
*/
void
gst_element_set_sched (GstElement *element,
GstScheduler *sched)
{
g_return_if_fail (GST_IS_ELEMENT (element));
GST_INFO_ELEMENT (GST_CAT_PARENTAGE, element, "setting scheduler to %p", sched);
element->sched = sched;
}
/**
* gst_element_get_sched:
* @element: Element to get manager of.
*
* Returns the scheduler of the element.
*
* Returns: Element's scheduler
*/
GstScheduler*
gst_element_get_sched (GstElement *element)
{
g_return_val_if_fail (GST_IS_ELEMENT (element), NULL);
return element->sched;
}
/**
* gst_element_set_loop_function:
* @element: Element to set loop function of.
* @loop: Pointer to loop function.
*
* This sets the loop function for the element. The function pointed to
* can deviate from the GstElementLoopFunction definition in type of
* pointer only.
*
* NOTE: in order for this to take effect, the current loop function *must*
* exit. Assuming the loop function itself is the only one who will cause
* a new loopfunc to be assigned, this should be no problem.
*/
void
gst_element_set_loop_function(GstElement *element,
GstElementLoopFunction loop)
{
g_return_if_fail (GST_IS_ELEMENT (element));
/* set the loop function */
element->loopfunc = loop;
/* set the NEW_LOOPFUNC flag so everyone knows to go try again */
GST_FLAG_SET (element, GST_ELEMENT_NEW_LOOPFUNC);
}
/**
* gst_element_set_eos:
* @element: element to set to the EOS state
*
* Perform the actions needed to bring the element in the EOS state.
*/
void
gst_element_set_eos (GstElement *element)
{
g_return_if_fail (GST_IS_ELEMENT (element));
GST_DEBUG (GST_CAT_EVENT, "setting EOS on element %s\n", GST_OBJECT_NAME (element));
gst_element_set_state (element, GST_STATE_PAUSED);
g_signal_emit (G_OBJECT (element), gst_element_signals[EOS], 0);
}
/**
* gst_element_statename:
* @state: The state to get the name of
*
* Gets a string representing the given state.
*
* Returns: a string with the statename.
*/
const gchar*
gst_element_statename (GstElementState state)
{
switch (state) {
#ifdef GST_DEBUG_COLOR
case GST_STATE_VOID_PENDING: return "NONE_PENDING";break;
case GST_STATE_NULL: return "\033[01;37mNULL\033[00m";break;
case GST_STATE_READY: return "\033[01;31mREADY\033[00m";break;
case GST_STATE_PLAYING: return "\033[01;32mPLAYING\033[00m";break;
case GST_STATE_PAUSED: return "\033[01;33mPAUSED\033[00m";break;
default: return g_strdup_printf ("\033[01;37;41mUNKNOWN!\033[00m(%d)", state);
#else
case GST_STATE_VOID_PENDING: return "NONE_PENDING";break;
case GST_STATE_NULL: return "NULL";break;
case GST_STATE_READY: return "READY";break;
case GST_STATE_PLAYING: return "PLAYING";break;
case GST_STATE_PAUSED: return "PAUSED";break;
default: return "UNKNOWN!";
#endif
}
return "";
}
static void
gst_element_populate_std_props (GObjectClass * klass,
const char *prop_name, guint arg_id, GParamFlags flags)
{
GQuark prop_id = g_quark_from_string (prop_name);
GParamSpec *pspec;
static GQuark fd_id = 0;
static GQuark blocksize_id;
static GQuark bytesperread_id;
static GQuark dump_id;
static GQuark filesize_id;
static GQuark mmapsize_id;
static GQuark location_id;
static GQuark offset_id;
static GQuark silent_id;
static GQuark touch_id;
if (!fd_id) {
fd_id = g_quark_from_static_string ("fd");
blocksize_id = g_quark_from_static_string ("blocksize");
bytesperread_id = g_quark_from_static_string ("bytesperread");
dump_id = g_quark_from_static_string ("dump");
filesize_id = g_quark_from_static_string ("filesize");
mmapsize_id = g_quark_from_static_string ("mmapsize");
location_id = g_quark_from_static_string ("location");
offset_id = g_quark_from_static_string ("offset");
silent_id = g_quark_from_static_string ("silent");
touch_id = g_quark_from_static_string ("touch");
}
if (prop_id == fd_id) {
pspec = g_param_spec_int ("fd", "File-descriptor",
"File-descriptor for the file being read",
0, G_MAXINT, 0, flags);
}
else if (prop_id == blocksize_id) {
pspec = g_param_spec_ulong ("blocksize", "Block Size",
"Block size to read per buffer",
0, G_MAXULONG, 4096, flags);
}
else if (prop_id == bytesperread_id) {
pspec = g_param_spec_int ("bytesperread", "bytesperread",
"bytesperread",
G_MININT, G_MAXINT, 0, flags);
}
else if (prop_id == dump_id) {
pspec = g_param_spec_boolean ("dump", "dump", "dump", FALSE, flags);
}
else if (prop_id == filesize_id) {
pspec = g_param_spec_int64 ("filesize", "File Size",
"Size of the file being read",
0, G_MAXINT64, 0, flags);
}
else if (prop_id == mmapsize_id) {
pspec = g_param_spec_ulong ("mmapsize", "mmap() Block Size",
"Size in bytes of mmap()d regions",
0, G_MAXULONG, 4 * 1048576, flags);
}
else if (prop_id == location_id) {
pspec = g_param_spec_string ("location", "File Location",
"Location of the file to read",
NULL, flags);
}
else if (prop_id == offset_id) {
pspec = g_param_spec_int64 ("offset", "File Offset",
"Byte offset of current read pointer",
0, G_MAXINT64, 0, flags);
}
else if (prop_id == silent_id) {
pspec = g_param_spec_boolean ("silent", "silent", "silent",
FALSE, flags);
}
else if (prop_id == touch_id) {
pspec = g_param_spec_boolean ("touch", "Touch read data",
"Touch data to force disk read before "
"push ()", TRUE, flags);
}
else {
g_warning ("Unknown - 'standard' property '%s' id %d from klass %s",
prop_name, arg_id, g_type_name (G_OBJECT_CLASS_TYPE (klass)));
pspec = NULL;
}
if (pspec) {
g_object_class_install_property (klass, arg_id, pspec);
}
}
/**
* gst_element_install_std_props:
* @klass: the class to add the properties to
* @first_name: the first in a NULL terminated
* 'name', 'id', 'flags' triplet list.
* @...: the triplet list
*
* Add a list of standardized properties with types to the @klass.
* the id is for the property switch in your get_prop method, and
* the flags determine readability / writeability.
**/
void
gst_element_install_std_props (GstElementClass * klass, const char *first_name, ...)
{
const char *name;
va_list args;
g_return_if_fail (GST_IS_ELEMENT_CLASS (klass));
va_start (args, first_name);
name = first_name;
while (name) {
int arg_id = va_arg (args, int);
int flags = va_arg (args, int);
gst_element_populate_std_props ((GObjectClass *) klass, name, arg_id, flags);
name = va_arg (args, char *);
}
va_end (args);
}
|