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 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743
// Take a look at the license at the top of the repository in the LICENSE file.
use std::{ffi::CStr, future::Future, mem, num::NonZeroU64, pin::Pin};
use glib::translate::*;
use itertools::Itertools;
use crate::{
ffi,
format::{
CompatibleFormattedValue, FormattedValue, SpecificFormattedValueFullRange,
SpecificFormattedValueIntrinsic,
},
prelude::*,
ClockTime, Element, ElementFlags, Event, Format, GenericFormattedValue, Pad, PadTemplate,
Plugin, QueryRef, Rank, State,
};
impl Element {
#[doc(alias = "gst_element_link_many")]
pub fn link_many(
elements: impl IntoIterator<Item = impl AsRef<Element> + Clone>,
) -> Result<(), glib::BoolError> {
skip_assert_initialized!();
for (src, dest) in elements.into_iter().tuple_windows() {
unsafe {
glib::result_from_gboolean!(
ffi::gst_element_link(
src.as_ref().to_glib_none().0,
dest.as_ref().to_glib_none().0,
),
"Failed to link elements '{}' and '{}'",
src.as_ref().name(),
dest.as_ref().name(),
)?;
}
}
Ok(())
}
#[doc(alias = "gst_element_unlink_many")]
pub fn unlink_many(elements: impl IntoIterator<Item = impl AsRef<Element> + Clone>) {
skip_assert_initialized!();
for (src, dest) in elements.into_iter().tuple_windows() {
unsafe {
ffi::gst_element_unlink(
src.as_ref().to_glib_none().0,
dest.as_ref().to_glib_none().0,
);
}
}
}
/// Create a new elementfactory capable of instantiating objects of the
/// `type_` and add the factory to `plugin`.
/// ## `plugin`
/// [`Plugin`][crate::Plugin] to register the element with, or [`None`] for
/// a static element.
/// ## `name`
/// name of elements of this type
/// ## `rank`
/// rank of element (higher rank means more importance when autoplugging)
/// ## `type_`
/// GType of element to register
///
/// # Returns
///
/// [`true`], if the registering succeeded, [`false`] on error
#[doc(alias = "gst_element_register")]
pub fn register(
plugin: Option<&Plugin>,
name: &str,
rank: Rank,
type_: glib::types::Type,
) -> Result<(), glib::error::BoolError> {
skip_assert_initialized!();
unsafe {
glib::result_from_gboolean!(
ffi::gst_element_register(
plugin.to_glib_none().0,
name.to_glib_none().0,
rank.into_glib() as u32,
type_.into_glib()
),
"Failed to register element factory"
)
}
}
}
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
pub enum ElementMessageType {
Error,
Warning,
Info,
}
#[derive(Debug, PartialEq, Eq)]
pub struct NotifyWatchId(NonZeroU64);
impl IntoGlib for NotifyWatchId {
type GlibType = libc::c_ulong;
#[inline]
fn into_glib(self) -> libc::c_ulong {
self.0.get() as libc::c_ulong
}
}
impl FromGlib<libc::c_ulong> for NotifyWatchId {
#[inline]
unsafe fn from_glib(val: libc::c_ulong) -> NotifyWatchId {
skip_assert_initialized!();
debug_assert_ne!(val, 0);
NotifyWatchId(NonZeroU64::new_unchecked(val as _))
}
}
mod sealed {
pub trait Sealed {}
impl<T: super::IsA<super::Element>> Sealed for T {}
}
pub trait ElementExtManual: sealed::Sealed + IsA<Element> + 'static {
#[doc(alias = "get_element_class")]
#[inline]
fn element_class(&self) -> &glib::Class<Element> {
unsafe { self.unsafe_cast_ref::<Element>().class() }
}
#[doc(alias = "get_current_state")]
fn current_state(&self) -> State {
self.state(Some(ClockTime::ZERO)).1
}
#[doc(alias = "get_pending_state")]
fn pending_state(&self) -> State {
self.state(Some(ClockTime::ZERO)).2
}
/// Performs a query on the given element.
///
/// For elements that don't implement a query handler, this function
/// forwards the query to a random srcpad or to the peer of a
/// random linked sinkpad of this element.
///
/// Please note that some queries might need a running pipeline to work.
/// ## `query`
/// the [`Query`][crate::Query].
///
/// # Returns
///
/// [`true`] if the query could be performed.
///
/// MT safe.
#[doc(alias = "gst_element_query")]
fn query(&self, query: &mut QueryRef) -> bool {
unsafe {
from_glib(ffi::gst_element_query(
self.as_ref().to_glib_none().0,
query.as_mut_ptr(),
))
}
}
/// Sends an event to an element. If the element doesn't implement an
/// event handler, the event will be pushed on a random linked sink pad for
/// downstream events or a random linked source pad for upstream events.
///
/// This function takes ownership of the provided event so you should
/// `gst_event_ref()` it if you want to reuse the event after this call.
///
/// MT safe.
/// ## `event`
/// the [`Event`][crate::Event] to send to the element.
///
/// # Returns
///
/// [`true`] if the event was handled. Events that trigger a preroll (such
/// as flushing seeks and steps) will emit `GST_MESSAGE_ASYNC_DONE`.
#[doc(alias = "gst_element_send_event")]
fn send_event(&self, event: impl Into<Event>) -> bool {
unsafe {
from_glib(ffi::gst_element_send_event(
self.as_ref().to_glib_none().0,
event.into().into_glib_ptr(),
))
}
}
/// Get metadata with `key` in `klass`.
/// ## `key`
/// the key to get
///
/// # Returns
///
/// the metadata for `key`.
#[doc(alias = "get_metadata")]
#[doc(alias = "gst_element_class_get_metadata")]
fn metadata<'a>(&self, key: &str) -> Option<&'a str> {
self.element_class().metadata(key)
}
/// Retrieves a padtemplate from `self` with the given name.
/// ## `name`
/// the name of the [`PadTemplate`][crate::PadTemplate] to get.
///
/// # Returns
///
/// the [`PadTemplate`][crate::PadTemplate] with the
/// given name, or [`None`] if none was found. No unreferencing is
/// necessary.
#[doc(alias = "get_pad_template")]
#[doc(alias = "gst_element_class_get_pad_template")]
fn pad_template(&self, name: &str) -> Option<PadTemplate> {
self.element_class().pad_template(name)
}
/// Retrieves a list of the pad templates associated with `self`. The
/// list must not be modified by the calling code.
///
/// # Returns
///
/// the `GList` of
/// pad templates.
#[doc(alias = "get_pad_template_list")]
#[doc(alias = "gst_element_class_get_pad_template_list")]
fn pad_template_list(&self) -> glib::List<PadTemplate> {
self.element_class().pad_template_list()
}
/// Post an error, warning or info message on the bus from inside an element.
///
/// `type_` must be of `GST_MESSAGE_ERROR`, `GST_MESSAGE_WARNING` or
/// `GST_MESSAGE_INFO`.
///
/// MT safe.
/// ## `type_`
/// the `GstMessageType`
/// ## `domain`
/// the GStreamer GError domain this message belongs to
/// ## `code`
/// the GError code belonging to the domain
/// ## `text`
/// an allocated text string to be used
/// as a replacement for the default message connected to code,
/// or [`None`]
/// ## `debug`
/// an allocated debug message to be
/// used as a replacement for the default debugging information,
/// or [`None`]
/// ## `file`
/// the source code file where the error was generated
/// ## `function`
/// the source code function where the error was generated
/// ## `line`
/// the source code line where the error was generated
#[allow(clippy::too_many_arguments)]
#[doc(alias = "gst_element_message_full")]
fn message_full<T: crate::MessageErrorDomain>(
&self,
type_: ElementMessageType,
code: T,
message: Option<&str>,
debug: Option<&str>,
file: &str,
function: &str,
line: u32,
) {
unsafe {
let type_ = match type_ {
ElementMessageType::Error => ffi::GST_MESSAGE_ERROR,
ElementMessageType::Warning => ffi::GST_MESSAGE_WARNING,
ElementMessageType::Info => ffi::GST_MESSAGE_INFO,
};
ffi::gst_element_message_full(
self.as_ref().to_glib_none().0,
type_,
T::domain().into_glib(),
code.code(),
message.to_glib_full(),
debug.to_glib_full(),
file.to_glib_none().0,
function.to_glib_none().0,
line as i32,
);
}
}
fn set_element_flags(&self, flags: ElementFlags) {
unsafe {
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = self.as_ref().object_lock();
(*ptr).flags |= flags.into_glib();
}
}
fn unset_element_flags(&self, flags: ElementFlags) {
unsafe {
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = self.as_ref().object_lock();
(*ptr).flags &= !flags.into_glib();
}
}
#[doc(alias = "get_element_flags")]
fn element_flags(&self) -> ElementFlags {
unsafe {
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
let _guard = self.as_ref().object_lock();
from_glib((*ptr).flags)
}
}
/// Post an error, warning or info message on the bus from inside an element.
///
/// `type_` must be of `GST_MESSAGE_ERROR`, `GST_MESSAGE_WARNING` or
/// `GST_MESSAGE_INFO`.
/// ## `type_`
/// the `GstMessageType`
/// ## `domain`
/// the GStreamer GError domain this message belongs to
/// ## `code`
/// the GError code belonging to the domain
/// ## `text`
/// an allocated text string to be used
/// as a replacement for the default message connected to code,
/// or [`None`]
/// ## `debug`
/// an allocated debug message to be
/// used as a replacement for the default debugging information,
/// or [`None`]
/// ## `file`
/// the source code file where the error was generated
/// ## `function`
/// the source code function where the error was generated
/// ## `line`
/// the source code line where the error was generated
/// ## `structure`
/// optional details structure
#[allow(clippy::too_many_arguments)]
#[doc(alias = "gst_element_message_full_with_details")]
fn message_full_with_details<T: crate::MessageErrorDomain>(
&self,
type_: ElementMessageType,
code: T,
message: Option<&str>,
debug: Option<&str>,
file: &str,
function: &str,
line: u32,
structure: crate::Structure,
) {
unsafe {
let type_ = match type_ {
ElementMessageType::Error => ffi::GST_MESSAGE_ERROR,
ElementMessageType::Warning => ffi::GST_MESSAGE_WARNING,
ElementMessageType::Info => ffi::GST_MESSAGE_INFO,
};
ffi::gst_element_message_full_with_details(
self.as_ref().to_glib_none().0,
type_,
T::domain().into_glib(),
code.code(),
message.to_glib_full(),
debug.to_glib_full(),
file.to_glib_none().0,
function.to_glib_none().0,
line as i32,
structure.into_glib_ptr(),
);
}
}
fn post_error_message(&self, msg: crate::ErrorMessage) {
let crate::ErrorMessage {
error_domain,
error_code,
ref message,
ref debug,
filename,
function,
line,
} = msg;
unsafe {
ffi::gst_element_message_full(
self.as_ref().to_glib_none().0,
ffi::GST_MESSAGE_ERROR,
error_domain.into_glib(),
error_code,
message.to_glib_full(),
debug.to_glib_full(),
filename.to_glib_none().0,
function.to_glib_none().0,
line as i32,
);
}
}
/// Retrieves an iterator of `self`'s pads. The iterator should
/// be freed after usage. Also more specialized iterators exists such as
/// [`iterate_src_pads()`][Self::iterate_src_pads()] or [`iterate_sink_pads()`][Self::iterate_sink_pads()].
///
/// The order of pads returned by the iterator will be the order in which
/// the pads were added to the element.
///
/// # Returns
///
/// the `GstIterator` of [`Pad`][crate::Pad].
///
/// MT safe.
#[doc(alias = "gst_element_iterate_pads")]
fn iterate_pads(&self) -> crate::Iterator<Pad> {
unsafe {
from_glib_full(ffi::gst_element_iterate_pads(
self.as_ref().to_glib_none().0,
))
}
}
/// Retrieves an iterator of `self`'s sink pads.
///
/// The order of pads returned by the iterator will be the order in which
/// the pads were added to the element.
///
/// # Returns
///
/// the `GstIterator` of [`Pad`][crate::Pad].
///
/// MT safe.
#[doc(alias = "gst_element_iterate_sink_pads")]
fn iterate_sink_pads(&self) -> crate::Iterator<Pad> {
unsafe {
from_glib_full(ffi::gst_element_iterate_sink_pads(
self.as_ref().to_glib_none().0,
))
}
}
/// Retrieves an iterator of `self`'s source pads.
///
/// The order of pads returned by the iterator will be the order in which
/// the pads were added to the element.
///
/// # Returns
///
/// the `GstIterator` of [`Pad`][crate::Pad].
///
/// MT safe.
#[doc(alias = "gst_element_iterate_src_pads")]
fn iterate_src_pads(&self) -> crate::Iterator<Pad> {
unsafe {
from_glib_full(ffi::gst_element_iterate_src_pads(
self.as_ref().to_glib_none().0,
))
}
}
#[doc(alias = "get_pads")]
#[doc(alias = "gst_element_foreach_pad")]
fn pads(&self) -> Vec<Pad> {
unsafe {
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
let _guard = self.as_ref().object_lock();
FromGlibPtrContainer::from_glib_none(elt.pads)
}
}
#[doc(alias = "get_sink_pads")]
#[doc(alias = "gst_element_foreach_sink_pad")]
fn sink_pads(&self) -> Vec<Pad> {
unsafe {
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
let _guard = self.as_ref().object_lock();
FromGlibPtrContainer::from_glib_none(elt.sinkpads)
}
}
#[doc(alias = "get_src_pads")]
#[doc(alias = "gst_element_foreach_src_pad")]
fn src_pads(&self) -> Vec<Pad> {
unsafe {
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
let _guard = self.as_ref().object_lock();
FromGlibPtrContainer::from_glib_none(elt.srcpads)
}
}
fn num_pads(&self) -> u16 {
unsafe {
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
let _guard = self.as_ref().object_lock();
elt.numpads
}
}
fn num_sink_pads(&self) -> u16 {
unsafe {
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
let _guard = self.as_ref().object_lock();
elt.numsinkpads
}
}
fn num_src_pads(&self) -> u16 {
unsafe {
let elt: &ffi::GstElement = &*(self.as_ptr() as *const _);
let _guard = self.as_ref().object_lock();
elt.numsrcpads
}
}
/// ## `property_name`
/// name of property to watch for changes, or
/// NULL to watch all properties
/// ## `include_value`
/// whether to include the new property value in the message
///
/// # Returns
///
/// a watch id, which can be used in connection with
/// [`remove_property_notify_watch()`][Self::remove_property_notify_watch()] to remove the watch again.
#[doc(alias = "gst_element_add_property_deep_notify_watch")]
fn add_property_deep_notify_watch(
&self,
property_name: Option<&str>,
include_value: bool,
) -> NotifyWatchId {
let property_name = property_name.to_glib_none();
unsafe {
from_glib(ffi::gst_element_add_property_deep_notify_watch(
self.as_ref().to_glib_none().0,
property_name.0,
include_value.into_glib(),
))
}
}
/// ## `property_name`
/// name of property to watch for changes, or
/// NULL to watch all properties
/// ## `include_value`
/// whether to include the new property value in the message
///
/// # Returns
///
/// a watch id, which can be used in connection with
/// [`remove_property_notify_watch()`][Self::remove_property_notify_watch()] to remove the watch again.
#[doc(alias = "gst_element_add_property_notify_watch")]
fn add_property_notify_watch(
&self,
property_name: Option<&str>,
include_value: bool,
) -> NotifyWatchId {
let property_name = property_name.to_glib_none();
unsafe {
from_glib(ffi::gst_element_add_property_notify_watch(
self.as_ref().to_glib_none().0,
property_name.0,
include_value.into_glib(),
))
}
}
/// ## `watch_id`
/// watch id to remove
#[doc(alias = "gst_element_remove_property_notify_watch")]
fn remove_property_notify_watch(&self, watch_id: NotifyWatchId) {
unsafe {
ffi::gst_element_remove_property_notify_watch(
self.as_ref().to_glib_none().0,
watch_id.into_glib(),
);
}
}
/// Queries an element to convert `src_val` in `src_format` to `dest_format`.
/// ## `src_format`
/// a [`Format`][crate::Format] to convert from.
/// ## `src_val`
/// a value to convert.
/// ## `dest_format`
/// the [`Format`][crate::Format] to convert to.
///
/// # Returns
///
/// [`true`] if the query could be performed.
///
/// ## `dest_val`
/// a pointer to the result.
#[doc(alias = "gst_element_query_convert")]
fn query_convert<U: SpecificFormattedValueFullRange>(
&self,
src_val: impl FormattedValue,
) -> Option<U> {
unsafe {
let mut dest_val = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_element_query_convert(
self.as_ref().to_glib_none().0,
src_val.format().into_glib(),
src_val.into_raw_value(),
U::default_format().into_glib(),
dest_val.as_mut_ptr(),
));
if ret {
Some(U::from_raw(U::default_format(), dest_val.assume_init()))
} else {
None
}
}
}
#[doc(alias = "gst_element_query_convert")]
fn query_convert_generic(
&self,
src_val: impl FormattedValue,
dest_format: Format,
) -> Option<GenericFormattedValue> {
unsafe {
let mut dest_val = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_element_query_convert(
self.as_ref().to_glib_none().0,
src_val.format().into_glib(),
src_val.into_raw_value(),
dest_format.into_glib(),
dest_val.as_mut_ptr(),
));
if ret {
Some(GenericFormattedValue::new(
dest_format,
dest_val.assume_init(),
))
} else {
None
}
}
}
/// Queries an element (usually top-level pipeline or playbin element) for the
/// total stream duration in nanoseconds. This query will only work once the
/// pipeline is prerolled (i.e. reached PAUSED or PLAYING state). The application
/// will receive an ASYNC_DONE message on the pipeline bus when that is the case.
///
/// If the duration changes for some reason, you will get a DURATION_CHANGED
/// message on the pipeline bus, in which case you should re-query the duration
/// using this function.
/// ## `format`
/// the [`Format`][crate::Format] requested
///
/// # Returns
///
/// [`true`] if the query could be performed.
///
/// ## `duration`
/// A location in which to store the total duration, or [`None`].
#[doc(alias = "gst_element_query_duration")]
fn query_duration<T: SpecificFormattedValueIntrinsic>(&self) -> Option<T> {
unsafe {
let mut duration = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_element_query_duration(
self.as_ref().to_glib_none().0,
T::default_format().into_glib(),
duration.as_mut_ptr(),
));
if ret {
try_from_glib(duration.assume_init()).ok()
} else {
None
}
}
}
#[doc(alias = "gst_element_query_duration")]
fn query_duration_generic(&self, format: Format) -> Option<GenericFormattedValue> {
unsafe {
let mut duration = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_element_query_duration(
self.as_ref().to_glib_none().0,
format.into_glib(),
duration.as_mut_ptr(),
));
if ret {
Some(GenericFormattedValue::new(format, duration.assume_init()))
} else {
None
}
}
}
/// Queries an element (usually top-level pipeline or playbin element) for the
/// stream position in nanoseconds. This will be a value between 0 and the
/// stream duration (if the stream duration is known). This query will usually
/// only work once the pipeline is prerolled (i.e. reached PAUSED or PLAYING
/// state). The application will receive an ASYNC_DONE message on the pipeline
/// bus when that is the case.
///
/// If one repeatedly calls this function one can also create a query and reuse
/// it in [`query()`][Self::query()].
/// ## `format`
/// the [`Format`][crate::Format] requested
///
/// # Returns
///
/// [`true`] if the query could be performed.
///
/// ## `cur`
/// a location in which to store the current
/// position, or [`None`].
#[doc(alias = "gst_element_query_position")]
fn query_position<T: SpecificFormattedValueIntrinsic>(&self) -> Option<T> {
unsafe {
let mut cur = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_element_query_position(
self.as_ref().to_glib_none().0,
T::default_format().into_glib(),
cur.as_mut_ptr(),
));
if ret {
try_from_glib(cur.assume_init()).ok()
} else {
None
}
}
}
#[doc(alias = "gst_element_query_position")]
fn query_position_generic(&self, format: Format) -> Option<GenericFormattedValue> {
unsafe {
let mut cur = mem::MaybeUninit::uninit();
let ret = from_glib(ffi::gst_element_query_position(
self.as_ref().to_glib_none().0,
format.into_glib(),
cur.as_mut_ptr(),
));
if ret {
Some(GenericFormattedValue::new(format, cur.assume_init()))
} else {
None
}
}
}
/// Sends a seek event to an element. See `gst_event_new_seek()` for the details of
/// the parameters. The seek event is sent to the element using
/// [`send_event()`][Self::send_event()].
///
/// MT safe.
/// ## `rate`
/// The new playback rate
/// ## `format`
/// The format of the seek values
/// ## `flags`
/// The optional seek flags.
/// ## `start_type`
/// The type and flags for the new start position
/// ## `start`
/// The value of the new start position
/// ## `stop_type`
/// The type and flags for the new stop position
/// ## `stop`
/// The value of the new stop position
///
/// # Returns
///
/// [`true`] if the event was handled. Flushing seeks will trigger a
/// preroll, which will emit `GST_MESSAGE_ASYNC_DONE`.
#[doc(alias = "gst_element_seek")]
fn seek<V: FormattedValue>(
&self,
rate: f64,
flags: crate::SeekFlags,
start_type: crate::SeekType,
start: V,
stop_type: crate::SeekType,
stop: impl CompatibleFormattedValue<V>,
) -> Result<(), glib::error::BoolError> {
let stop = stop.try_into_checked(start).unwrap();
unsafe {
glib::result_from_gboolean!(
ffi::gst_element_seek(
self.as_ref().to_glib_none().0,
rate,
start.format().into_glib(),
flags.into_glib(),
start_type.into_glib(),
start.into_raw_value(),
stop_type.into_glib(),
stop.into_raw_value(),
),
"Failed to seek",
)
}
}
/// Simple API to perform a seek on the given element, meaning it just seeks
/// to the given position relative to the start of the stream. For more complex
/// operations like segment seeks (e.g. for looping) or changing the playback
/// rate or seeking relative to the last configured playback segment you should
/// use [`seek()`][Self::seek()].
///
/// In a completely prerolled PAUSED or PLAYING pipeline, seeking is always
/// guaranteed to return [`true`] on a seekable media type or [`false`] when the media
/// type is certainly not seekable (such as a live stream).
///
/// Some elements allow for seeking in the READY state, in this
/// case they will store the seek event and execute it when they are put to
/// PAUSED. If the element supports seek in READY, it will always return [`true`] when
/// it receives the event in the READY state.
/// ## `format`
/// a [`Format`][crate::Format] to execute the seek in, such as [`Format::Time`][crate::Format::Time]
/// ## `seek_flags`
/// seek options; playback applications will usually want to use
/// GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT here
/// ## `seek_pos`
/// position to seek to (relative to the start); if you are doing
/// a seek in [`Format::Time`][crate::Format::Time] this value is in nanoseconds -
/// multiply with `GST_SECOND` to convert seconds to nanoseconds or
/// with `GST_MSECOND` to convert milliseconds to nanoseconds.
///
/// # Returns
///
/// [`true`] if the seek operation succeeded. Flushing seeks will trigger a
/// preroll, which will emit `GST_MESSAGE_ASYNC_DONE`.
#[doc(alias = "gst_element_seek_simple")]
fn seek_simple(
&self,
seek_flags: crate::SeekFlags,
seek_pos: impl FormattedValue,
) -> Result<(), glib::error::BoolError> {
unsafe {
glib::result_from_gboolean!(
ffi::gst_element_seek_simple(
self.as_ref().to_glib_none().0,
seek_pos.format().into_glib(),
seek_flags.into_glib(),
seek_pos.into_raw_value(),
),
"Failed to seek",
)
}
}
/// Calls `func` from another thread and passes `user_data` to it. This is to be
/// used for cases when a state change has to be performed from a streaming
/// thread, directly via [`ElementExt::set_state()`][crate::prelude::ElementExt::set_state()] or indirectly e.g. via SEEK
/// events.
///
/// Calling those functions directly from the streaming thread will cause
/// deadlocks in many situations, as they might involve waiting for the
/// streaming thread to shut down from this very streaming thread.
///
/// MT safe.
/// ## `func`
/// Function to call asynchronously from another thread
/// ## `destroy_notify`
/// GDestroyNotify for `user_data`
#[doc(alias = "gst_element_call_async")]
fn call_async<F>(&self, func: F)
where
F: FnOnce(&Self) + Send + 'static,
{
let user_data: Box<Option<F>> = Box::new(Some(func));
unsafe extern "C" fn trampoline<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>(
element: *mut ffi::GstElement,
user_data: glib::ffi::gpointer,
) {
let user_data: &mut Option<F> = &mut *(user_data as *mut _);
let callback = user_data.take().unwrap();
callback(Element::from_glib_borrow(element).unsafe_cast_ref());
}
unsafe extern "C" fn free_user_data<O: IsA<Element>, F: FnOnce(&O) + Send + 'static>(
user_data: glib::ffi::gpointer,
) {
let _: Box<Option<F>> = Box::from_raw(user_data as *mut _);
}
unsafe {
ffi::gst_element_call_async(
self.as_ref().to_glib_none().0,
Some(trampoline::<Self, F>),
Box::into_raw(user_data) as *mut _,
Some(free_user_data::<Self, F>),
);
}
}
fn call_async_future<F, T>(&self, func: F) -> Pin<Box<dyn Future<Output = T> + Send + 'static>>
where
F: FnOnce(&Self) -> T + Send + 'static,
T: Send + 'static,
{
use futures_channel::oneshot;
let (sender, receiver) = oneshot::channel();
self.call_async(move |element| {
let _ = sender.send(func(element));
});
Box::pin(async move { receiver.await.expect("sender dropped") })
}
/// Returns the running time of the element. The running time is the
/// element's clock time minus its base time. Will return GST_CLOCK_TIME_NONE
/// if the element has no clock, or if its base time has not been set.
///
/// # Returns
///
/// the running time of the element, or GST_CLOCK_TIME_NONE if the
/// element has no clock or its base time has not been set.
#[doc(alias = "get_current_running_time")]
#[doc(alias = "gst_element_get_current_running_time")]
fn current_running_time(&self) -> Option<crate::ClockTime> {
let base_time = self.base_time();
let clock_time = self.current_clock_time();
clock_time
.zip(base_time)
.and_then(|(ct, bt)| ct.checked_sub(bt))
}
/// Returns the current clock time of the element, as in, the time of the
/// element's clock, or GST_CLOCK_TIME_NONE if there is no clock.
///
/// # Returns
///
/// the clock time of the element, or GST_CLOCK_TIME_NONE if there is
/// no clock.
#[doc(alias = "get_current_clock_time")]
#[doc(alias = "gst_element_get_current_clock_time")]
fn current_clock_time(&self) -> Option<crate::ClockTime> {
if let Some(clock) = self.clock() {
clock.time()
} else {
crate::ClockTime::NONE
}
}
/// The name of this function is confusing to people learning GStreamer.
/// [`request_pad_simple()`][Self::request_pad_simple()] aims at making it more explicit it is
/// a simplified [`ElementExt::request_pad()`][crate::prelude::ElementExt::request_pad()].
///
/// # Deprecated since 1.20
///
/// Prefer using [`request_pad_simple()`][Self::request_pad_simple()] which
/// provides the exact same functionality.
/// ## `name`
/// the name of the request [`Pad`][crate::Pad] to retrieve.
///
/// # Returns
///
/// requested [`Pad`][crate::Pad] if found,
/// otherwise [`None`]. Release after usage.
#[doc(alias = "gst_element_get_request_pad")]
#[doc(alias = "get_request_pad")]
#[doc(alias = "gst_element_request_pad_simple")]
fn request_pad_simple(&self, name: &str) -> Option<Pad> {
unsafe {
#[cfg(feature = "v1_20")]
{
from_glib_full(ffi::gst_element_request_pad_simple(
self.as_ref().to_glib_none().0,
name.to_glib_none().0,
))
}
#[cfg(not(feature = "v1_20"))]
{
from_glib_full(ffi::gst_element_get_request_pad(
self.as_ref().to_glib_none().0,
name.to_glib_none().0,
))
}
}
}
/// Links `self` to `dest`. The link must be from source to
/// destination; the other direction will not be tried. The function looks for
/// existing pads that aren't linked yet. It will request new pads if necessary.
/// Such pads need to be released manually when unlinking.
/// If multiple links are possible, only one is established.
///
/// Make sure you have added your elements to a bin or pipeline with
/// [`GstBinExt::add()`][crate::prelude::GstBinExt::add()] before trying to link them.
/// ## `dest`
/// the [`Element`][crate::Element] containing the destination pad.
///
/// # Returns
///
/// [`true`] if the elements could be linked, [`false`] otherwise.
#[doc(alias = "gst_element_link")]
fn link(&self, dest: &impl IsA<Element>) -> Result<(), glib::error::BoolError> {
unsafe {
glib::result_from_gboolean!(
ffi::gst_element_link(
self.as_ref().to_glib_none().0,
dest.as_ref().to_glib_none().0
),
"Failed to link elements '{}' and '{}'",
self.as_ref().name(),
dest.as_ref().name(),
)
}
}
/// Links `self` to `dest` using the given caps as filtercaps.
/// The link must be from source to
/// destination; the other direction will not be tried. The function looks for
/// existing pads that aren't linked yet. It will request new pads if necessary.
/// If multiple links are possible, only one is established.
///
/// Make sure you have added your elements to a bin or pipeline with
/// [`GstBinExt::add()`][crate::prelude::GstBinExt::add()] before trying to link them.
/// ## `dest`
/// the [`Element`][crate::Element] containing the destination pad.
/// ## `filter`
/// the [`Caps`][crate::Caps] to filter the link,
/// or [`None`] for no filter.
///
/// # Returns
///
/// [`true`] if the pads could be linked, [`false`] otherwise.
#[doc(alias = "gst_element_link_filtered")]
fn link_filtered(
&self,
dest: &impl IsA<Element>,
filter: &crate::Caps,
) -> Result<(), glib::error::BoolError> {
unsafe {
glib::result_from_gboolean!(
ffi::gst_element_link_filtered(
self.as_ref().to_glib_none().0,
dest.as_ref().to_glib_none().0,
filter.to_glib_none().0
),
"Failed to link elements '{}' and '{}' with filter '{:?}'",
self.as_ref().name(),
dest.as_ref().name(),
filter,
)
}
}
/// Links 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 link fails.
/// ## `srcpadname`
/// the name of the [`Pad`][crate::Pad] in source element
/// or [`None`] for any pad.
/// ## `dest`
/// the [`Element`][crate::Element] containing the destination pad.
/// ## `destpadname`
/// the name of the [`Pad`][crate::Pad] in destination element,
/// or [`None`] for any pad.
///
/// # Returns
///
/// [`true`] if the pads could be linked, [`false`] otherwise.
#[doc(alias = "gst_element_link_pads")]
fn link_pads(
&self,
srcpadname: Option<&str>,
dest: &impl IsA<Element>,
destpadname: Option<&str>,
) -> Result<(), glib::error::BoolError> {
unsafe {
glib::result_from_gboolean!(
ffi::gst_element_link_pads(
self.as_ref().to_glib_none().0,
srcpadname.to_glib_none().0,
dest.as_ref().to_glib_none().0,
destpadname.to_glib_none().0
),
"Failed to link pads '{}' and '{}'",
if let Some(srcpadname) = srcpadname {
format!("{}:{}", self.as_ref().name(), srcpadname)
} else {
format!("{}:*", self.as_ref().name())
},
if let Some(destpadname) = destpadname {
format!("{}:{}", dest.as_ref().name(), destpadname)
} else {
format!("{}:*", dest.as_ref().name())
},
)
}
}
/// Links 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 link fails. If `caps`
/// is not [`None`], makes sure that the caps of the link is a subset of `caps`.
/// ## `srcpadname`
/// the name of the [`Pad`][crate::Pad] in source element
/// or [`None`] for any pad.
/// ## `dest`
/// the [`Element`][crate::Element] containing the destination pad.
/// ## `destpadname`
/// the name of the [`Pad`][crate::Pad] in destination element
/// or [`None`] for any pad.
/// ## `filter`
/// the [`Caps`][crate::Caps] to filter the link,
/// or [`None`] for no filter.
///
/// # Returns
///
/// [`true`] if the pads could be linked, [`false`] otherwise.
#[doc(alias = "gst_element_link_pads_filtered")]
fn link_pads_filtered(
&self,
srcpadname: Option<&str>,
dest: &impl IsA<Element>,
destpadname: Option<&str>,
filter: &crate::Caps,
) -> Result<(), glib::error::BoolError> {
unsafe {
glib::result_from_gboolean!(
ffi::gst_element_link_pads_filtered(
self.as_ref().to_glib_none().0,
srcpadname.to_glib_none().0,
dest.as_ref().to_glib_none().0,
destpadname.to_glib_none().0,
filter.to_glib_none().0
),
"Failed to link pads '{}' and '{}' with filter '{:?}'",
if let Some(srcpadname) = srcpadname {
format!("{}:{}", self.as_ref().name(), srcpadname)
} else {
format!("{}:*", self.as_ref().name())
},
if let Some(destpadname) = destpadname {
format!("{}:{}", dest.as_ref().name(), destpadname)
} else {
format!("{}:*", dest.as_ref().name())
},
filter,
)
}
}
/// Links 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 link fails.
///
/// Calling [`link_pads_full()`][Self::link_pads_full()] with `flags` == [`PadLinkCheck::DEFAULT`][crate::PadLinkCheck::DEFAULT]
/// is the same as calling [`link_pads()`][Self::link_pads()] and the recommended way of
/// linking pads with safety checks applied.
///
/// This is a convenience function for [`PadExt::link_full()`][crate::prelude::PadExt::link_full()].
/// ## `srcpadname`
/// the name of the [`Pad`][crate::Pad] in source element
/// or [`None`] for any pad.
/// ## `dest`
/// the [`Element`][crate::Element] containing the destination pad.
/// ## `destpadname`
/// the name of the [`Pad`][crate::Pad] in destination element,
/// or [`None`] for any pad.
/// ## `flags`
/// the [`PadLinkCheck`][crate::PadLinkCheck] to be performed when linking pads.
///
/// # Returns
///
/// [`true`] if the pads could be linked, [`false`] otherwise.
#[doc(alias = "gst_element_link_pads_full")]
fn link_pads_full(
&self,
srcpadname: Option<&str>,
dest: &impl IsA<Element>,
destpadname: Option<&str>,
flags: crate::PadLinkCheck,
) -> Result<(), glib::error::BoolError> {
unsafe {
glib::result_from_gboolean!(
ffi::gst_element_link_pads_full(
self.as_ref().to_glib_none().0,
srcpadname.to_glib_none().0,
dest.as_ref().to_glib_none().0,
destpadname.to_glib_none().0,
flags.into_glib()
),
"Failed to link pads '{}' and '{}' with flags '{:?}'",
if let Some(srcpadname) = srcpadname {
format!("{}:{}", self.as_ref().name(), srcpadname)
} else {
format!("{}:*", self.as_ref().name())
},
if let Some(destpadname) = destpadname {
format!("{}:{}", dest.as_ref().name(), destpadname)
} else {
format!("{}:*", dest.as_ref().name())
},
flags,
)
}
}
}
impl<O: IsA<Element>> ElementExtManual for O {}
pub unsafe trait ElementClassExt {
/// Get metadata with `key` in `self`.
/// ## `key`
/// the key to get
///
/// # Returns
///
/// the metadata for `key`.
#[doc(alias = "get_metadata")]
#[doc(alias = "gst_element_class_get_metadata")]
fn metadata<'a>(&self, key: &str) -> Option<&'a str> {
unsafe {
let klass = self as *const _ as *const ffi::GstElementClass;
let ptr = ffi::gst_element_class_get_metadata(klass as *mut _, key.to_glib_none().0);
if ptr.is_null() {
None
} else {
Some(CStr::from_ptr(ptr).to_str().unwrap())
}
}
}
/// Retrieves a padtemplate from `self` with the given name.
/// > If you use this function in the GInstanceInitFunc of an object class
/// > that has subclasses, make sure to pass the g_class parameter of the
/// > GInstanceInitFunc here.
/// ## `name`
/// the name of the [`PadTemplate`][crate::PadTemplate] to get.
///
/// # Returns
///
/// the [`PadTemplate`][crate::PadTemplate] with the
/// given name, or [`None`] if none was found. No unreferencing is
/// necessary.
#[doc(alias = "get_pad_template")]
#[doc(alias = "gst_element_class_get_pad_template")]
fn pad_template(&self, name: &str) -> Option<PadTemplate> {
unsafe {
let klass = self as *const _ as *const ffi::GstElementClass;
from_glib_none(ffi::gst_element_class_get_pad_template(
klass as *mut _,
name.to_glib_none().0,
))
}
}
/// Retrieves a list of the pad templates associated with `self`. The
/// list must not be modified by the calling code.
/// > If you use this function in the GInstanceInitFunc of an object class
/// > that has subclasses, make sure to pass the g_class parameter of the
/// > GInstanceInitFunc here.
///
/// # Returns
///
/// the `GList` of
/// pad templates.
#[doc(alias = "get_pad_template_list")]
#[doc(alias = "gst_element_class_get_pad_template_list")]
fn pad_template_list(&self) -> glib::List<PadTemplate> {
unsafe {
let klass = self as *const _ as *const ffi::GstElementClass;
glib::List::from_glib_none(ffi::gst_element_class_get_pad_template_list(
klass as *mut _,
))
}
}
}
unsafe impl<T: IsA<Element> + glib::object::IsClass> ElementClassExt for glib::object::Class<T> {}
/// Name and contact details of the author(s). Use \n to separate
/// multiple author details.
/// E.g: "Joe Bloggs <joe.blogs at foo.com>"
#[doc(alias = "GST_ELEMENT_METADATA_AUTHOR")]
pub static ELEMENT_METADATA_AUTHOR: &glib::GStr =
unsafe { glib::GStr::from_utf8_with_nul_unchecked(ffi::GST_ELEMENT_METADATA_AUTHOR) };
/// Sentence describing the purpose of the element.
/// E.g: "Write stream to a file"
#[doc(alias = "GST_ELEMENT_METADATA_DESCRIPTION")]
pub static ELEMENT_METADATA_DESCRIPTION: &glib::GStr =
unsafe { glib::GStr::from_utf8_with_nul_unchecked(ffi::GST_ELEMENT_METADATA_DESCRIPTION) };
/// Set uri pointing to user documentation. Applications can use this to show
/// help for e.g. effects to users.
#[doc(alias = "GST_ELEMENT_METADATA_DOC_URI")]
pub static ELEMENT_METADATA_DOC_URI: &glib::GStr =
unsafe { glib::GStr::from_utf8_with_nul_unchecked(ffi::GST_ELEMENT_METADATA_DOC_URI) };
/// Elements that bridge to certain other products can include an icon of that
/// used product. Application can show the icon in menus/selectors to help
/// identifying specific elements.
#[doc(alias = "GST_ELEMENT_METADATA_ICON_NAME")]
pub static ELEMENT_METADATA_ICON_NAME: &glib::GStr =
unsafe { glib::GStr::from_utf8_with_nul_unchecked(ffi::GST_ELEMENT_METADATA_ICON_NAME) };
/// String describing the type of element, as an unordered list
/// separated with slashes ('/'). See draft-klass.txt of the design docs
/// for more details and common types. E.g: "Sink/File"
#[doc(alias = "GST_ELEMENT_METADATA_KLASS")]
pub static ELEMENT_METADATA_KLASS: &glib::GStr =
unsafe { glib::GStr::from_utf8_with_nul_unchecked(ffi::GST_ELEMENT_METADATA_KLASS) };
/// The long English name of the element. E.g. "File Sink"
#[doc(alias = "GST_ELEMENT_METADATA_LONGNAME")]
pub static ELEMENT_METADATA_LONGNAME: &glib::GStr =
unsafe { glib::GStr::from_utf8_with_nul_unchecked(ffi::GST_ELEMENT_METADATA_LONGNAME) };
#[doc(alias = "GST_ELEMENT_ERROR")]
#[doc(alias = "GST_ELEMENT_ERROR_WITH_DETAILS")]
#[macro_export]
macro_rules! element_error(
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Error,
$err,
Some(&format!($($msg)*)),
Some(&format!($($debug)*)),
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, ($($msg:tt)*)) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Error,
$err,
Some(&format!($($msg)*)),
None,
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, [$($debug:tt)*]) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Error,
$err,
None,
Some(&format!($($debug)*)),
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Error,
$err,
Some(&format!($($msg)*)),
Some(&format!($($debug)*)),
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, ($($msg:tt)*), details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Error,
$err,
Some(&format!($($msg)*)),
None,
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, [$($debug:tt)*], details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Error,
$err,
None,
Some(&format!($($debug)*)),
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
);
#[doc(alias = "GST_ELEMENT_WARNING")]
#[doc(alias = "GST_ELEMENT_WARNING_WITH_DETAILS")]
#[macro_export]
macro_rules! element_warning(
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Warning,
$err,
Some(&format!($($msg)*)),
Some(&format!($($debug)*)),
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, ($($msg:tt)*)) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Warning,
$err,
Some(&format!($($msg)*)),
None,
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, [$($debug:tt)*]) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Warning,
$err,
None,
Some(&format!($($debug)*)),
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Warning,
$err,
Some(&format!($($msg)*)),
Some(&format!($($debug)*)),
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, ($($msg:tt)*), details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Warning,
$err,
Some(&format!($($msg)*)),
None,
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, [$($debug:tt)*], details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Warning,
$err,
None,
Some(&format!($($debug)*)),
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
);
#[doc(alias = "GST_ELEMENT_INFO")]
#[doc(alias = "GST_ELEMENT_INFO_WITH_DETAILS")]
#[macro_export]
macro_rules! element_info(
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Info,
$err,
Some(&format!($($msg)*)),
Some(&format!($($debug)*)),
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, ($($msg:tt)*)) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Info,
$err,
Some(&format!($($msg)*)),
None,
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, [$($debug:tt)*]) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full(
$crate::ElementMessageType::Info,
$err,
None,
Some(&format!($($debug)*)),
file!(),
$crate::glib::function_name!(),
line!(),
);
}};
($obj:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Info,
$err,
Some(&format!($($msg)*)),
Some(&format!($($debug)*)),
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, ($($msg:tt)*), details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Info,
$err,
Some(&format!($($msg)*)),
None,
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
($obj:expr, $err:expr, [$($debug:tt)*], details: $details:expr) => { {
use $crate::prelude::ElementExtManual;
$obj.message_full_with_details(
$crate::ElementMessageType::Info,
$err,
None,
Some(&format!($($debug)*)),
file!(),
$crate::glib::function_name!(),
line!(),
$details,
);
}};
);
#[doc(alias = "GST_ELEMENT_ERROR")]
#[doc(alias = "GST_ELEMENT_ERROR_WITH_DETAILS")]
#[macro_export]
macro_rules! element_imp_error(
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
let obj = $imp.obj();
$crate::element_error!(obj, $err, ($($msg)*), [$($debug)*]);
}};
($imp:expr, $err:expr, ($($msg:tt)*)) => { {
let obj = $imp.obj();
$crate::element_error!(obj, $err, ($($msg)*));
}};
($imp:expr, $err:expr, [$($debug:tt)*]) => { {
let obj = $imp.obj();
$crate::element_error!(obj, $err, [$($debug)*]);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_error!(obj, $err, ($($msg)*), [$($debug)*], details: $details);
}};
($imp:expr, $err:expr, ($($msg:tt)*), details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_error!(obj, $err, ($($msg)*), details: $details);
}};
($imp:expr, $err:expr, [$($debug:tt)*], details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_error!(obj, $err, [$($debug)*], details: $details);
}};
);
#[doc(alias = "GST_ELEMENT_WARNING")]
#[doc(alias = "GST_ELEMENT_WARNING_WITH_DETAILS")]
#[macro_export]
macro_rules! element_imp_warning(
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
let obj = $imp.obj();
$crate::element_warning!(obj, $err, ($($msg)*), [$($debug)*]);
}};
($imp:expr, $err:expr, ($($msg:tt)*)) => { {
let obj = $imp.obj();
$crate::element_warning!(obj, $err, ($($msg)*));
}};
($imp:expr, $err:expr, [$($debug:tt)*]) => { {
let obj = $imp.obj();
$crate::element_warning!(obj, $err, [$($debug)*]);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_warning!(obj, $err, ($($msg)*), [$($debug)*], details: $details);
}};
($imp:expr, $err:expr, ($($msg:tt)*), details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_warning!(obj, $err, ($($msg)*), details: $details);
}};
($imp:expr, $err:expr, [$($debug:tt)*], details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_warning!(obj, $err, [$($debug)*], details: $details);
}};
);
#[doc(alias = "GST_ELEMENT_INFO")]
#[doc(alias = "GST_ELEMENT_INFO_WITH_DETAILS")]
#[macro_export]
macro_rules! element_imp_info(
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*]) => { {
let obj = $imp.obj();
$crate::element_info!(obj, $err, ($($msg)*), [$($debug)*]);
}};
($imp:expr, $err:expr, ($($msg:tt)*)) => { {
let obj = $imp.obj();
$crate::element_info!(obj, $err, ($($msg)*));
}};
($imp:expr, $err:expr, [$($debug:tt)*]) => { {
let obj = $imp.obj();
$crate::element_info!(obj, $err, [$($debug)*]);
}};
($imp:expr, $err:expr, ($($msg:tt)*), [$($debug:tt)*], details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_info!(obj, $err, ($($msg)*), [$($debug)*], details: $details);
}};
($imp:expr, $err:expr, ($($msg:tt)*), details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_info!(obj, $err, ($($msg)*), details: $details);
}};
($imp:expr, $err:expr, [$($debug:tt)*], details: $details:expr) => { {
let obj = $imp.obj();
$crate::element_info!(obj, $err, [$($debug)*], details: $details);
}};
);
#[cfg(test)]
mod tests {
use std::sync::mpsc::channel;
use glib::GString;
use super::*;
#[test]
fn test_get_pads() {
crate::init().unwrap();
let identity = crate::ElementFactory::make("identity").build().unwrap();
let mut pad_names = identity
.pads()
.iter()
.map(|p| p.name())
.collect::<Vec<GString>>();
pad_names.sort();
assert_eq!(pad_names, vec![String::from("sink"), String::from("src")]);
let mut pad_names = identity
.sink_pads()
.iter()
.map(|p| p.name())
.collect::<Vec<GString>>();
pad_names.sort();
assert_eq!(pad_names, vec![String::from("sink")]);
let mut pad_names = identity
.src_pads()
.iter()
.map(|p| p.name())
.collect::<Vec<GString>>();
pad_names.sort();
assert_eq!(pad_names, vec![String::from("src")]);
}
#[test]
fn test_foreach_pad() {
crate::init().unwrap();
let identity = crate::ElementFactory::make("identity").build().unwrap();
let mut pad_names = Vec::new();
identity.foreach_pad(|_element, pad| {
pad_names.push(pad.name());
true
});
pad_names.sort();
assert_eq!(pad_names, vec![String::from("sink"), String::from("src")]);
}
#[test]
fn test_call_async() {
crate::init().unwrap();
let identity = crate::ElementFactory::make("identity").build().unwrap();
let (sender, receiver) = channel();
identity.call_async(move |_| {
sender.send(()).unwrap();
});
assert_eq!(receiver.recv(), Ok(()));
}
#[test]
fn test_element_error() {
crate::init().unwrap();
let identity = crate::ElementFactory::make("identity").build().unwrap();
crate::element_error!(identity, crate::CoreError::Failed, ("msg"), ["debug"]);
crate::element_error!(identity, crate::CoreError::Failed, ["debug"]);
crate::element_error!(identity, crate::CoreError::Failed, ("msg"));
// We define a new variable for each call so there would be a compiler warning if the
// string formatting did not actually use it.
let x = 123i32;
crate::element_error!(identity, crate::CoreError::Failed, ("msg {x}"), ["debug"]);
let x = 123i32;
crate::element_error!(identity, crate::CoreError::Failed, ["debug {x}"]);
let x = 123i32;
crate::element_error!(identity, crate::CoreError::Failed, ("msg {}", x));
}
}