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 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501
|
/* gst-editing-services
* Copyright (C) <2013> Thibault Saunier <thibault.saunier@collabora.com>
* <2013> Collabora Ltd.
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
/**
* SECTION:gestimelineelement
* @title: GESTimelineElement
* @short_description: Base Class for all elements with some temporal extent
* within a #GESTimeline.
*
* A #GESTimelineElement will have some temporal extent in its
* corresponding #GESTimelineElement:timeline, controlled by its
* #GESTimelineElement:start and #GESTimelineElement:duration. This
* determines when its content will be displayed, or its effect applied,
* in the timeline. Several objects may overlap within a given
* #GESTimeline, in which case their #GESTimelineElement:priority is used
* to determine their ordering in the timeline. Priority is mostly handled
* internally by #GESLayer-s and #GESClip-s.
*
* A timeline element can have a #GESTimelineElement:parent,
* such as a #GESClip, which is responsible for controlling its timing.
*
* ## Editing
*
* Elements can be moved around in their #GESTimelineElement:timeline by
* setting their #GESTimelineElement:start and
* #GESTimelineElement:duration using ges_timeline_element_set_start()
* and ges_timeline_element_set_duration(). Additionally, which parts of
* the underlying content are played in the timeline can be adjusted by
* setting the #GESTimelineElement:in-point using
* ges_timeline_element_set_inpoint(). The library also provides
* ges_timeline_element_edit(), with various #GESEditMode-s, which can
* adjust these properties in a convenient way, as well as introduce
* similar changes in neighbouring or later elements in the timeline.
*
* However, a timeline may refuse a change in these properties if they
* would place the timeline in an unsupported configuration. See
* #GESTimeline for its overlap rules.
*
* Additionally, an edit may be refused if it would place one of the
* timing properties out of bounds (such as a negative time value for
* #GESTimelineElement:start, or having insufficient internal
* content to last for the desired #GESTimelineElement:duration).
*
* ## Time Coordinates
*
* There are three main sets of time coordinates to consider when using
* timeline elements:
*
* + Timeline coordinates: these are the time coordinates used in the
* output of the timeline in its #GESTrack-s. Each track share the same
* coordinates, so there is only one set of coordinates for the
* timeline. These extend indefinitely from 0. The times used for
* editing (including setting #GESTimelineElement:start and
* #GESTimelineElement:duration) use these coordinates, since these
* define when an element is present and for how long the element lasts
* for in the timeline.
* + Internal source coordinates: these are the time coordinates used
* internally at the element's output. This is only really defined for
* #GESTrackElement-s, where it refers to time coordinates used at the
* final source pad of the wrapped #GstElement-s. However, these
* coordinates may also be used in a #GESClip in reference to its
* children. In particular, these are the coordinates used for
* #GESTimelineElement:in-point and #GESTimelineElement:max-duration.
* + Internal sink coordinates: these are the time coordinates used
* internally at the element's input. A #GESSource has no input, so
* these would be undefined. Otherwise, for most #GESTrackElement-s
* these will be the same set of coordinates as the internal source
* coordinates because the element does not change the timing
* internally. Only #GESBaseEffect can support elements where these
* are different. See #GESBaseEffect for more information.
*
* You can determine the timeline time for a given internal source time
* in a #GESTrack in a #GESClip using
* ges_clip_get_timeline_time_from_internal_time(), and vice versa using
* ges_clip_get_internal_time_from_timeline_time(), for the purposes of
* editing and setting timings properties.
*
* ## Children Properties
*
* If a timeline element owns another #GstObject and wishes to expose
* some of its properties, it can do so by registering the property as one
* of the timeline element's children properties using
* ges_timeline_element_add_child_property(). The registered property of
* the child can then be read and set using the
* ges_timeline_element_get_child_property() and
* ges_timeline_element_set_child_property() methods, respectively. Some
* sub-classed objects will be created with pre-registered children
* properties; for example, to expose part of an underlying #GstElement
* that is used internally. The registered properties can be listed with
* ges_timeline_element_list_children_properties().
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ges-utils.h"
#include "ges-timeline-element.h"
#include "ges-extractable.h"
#include "ges-meta-container.h"
#include "ges-internal.h"
#include "ges-effect.h"
#include <string.h>
#include <gobject/gvaluecollector.h>
/* maps type name quark => count */
static GData *object_name_counts = NULL;
static void
extractable_set_asset (GESExtractable * extractable, GESAsset * asset)
{
GES_TIMELINE_ELEMENT (extractable)->asset = asset;
}
static void
ges_extractable_interface_init (GESExtractableInterface * iface)
{
iface->set_asset = extractable_set_asset;
}
enum
{
PROP_0,
PROP_PARENT,
PROP_TIMELINE,
PROP_START,
PROP_INPOINT,
PROP_DURATION,
PROP_MAX_DURATION,
PROP_PRIORITY,
PROP_NAME,
PROP_SERIALIZE,
PROP_LAST
};
enum
{
DEEP_NOTIFY,
CHILD_PROPERTY_ADDED,
CHILD_PROPERTY_REMOVED,
LAST_SIGNAL
};
static guint ges_timeline_element_signals[LAST_SIGNAL] = { 0 };
static GParamSpec *properties[PROP_LAST] = { NULL, };
typedef struct
{
GObject *child;
GESTimelineElement *owner;
gulong handler_id;
GESTimelineElement *self;
} ChildPropHandler;
struct _GESTimelineElementPrivate
{
gboolean serialize;
/* We keep a link between properties name and elements internally
* The hashtable should look like
* {GParamaSpec ---> child}*/
GHashTable *children_props;
GESTimelineElement *copied_from;
GESTimelineElementFlags flags;
};
typedef struct
{
GObject *child;
GParamSpec *arg;
GESTimelineElement *self;
} EmitDeepNotifyInIdleData;
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GESTimelineElement, ges_timeline_element,
G_TYPE_INITIALLY_UNOWNED, G_ADD_PRIVATE (GESTimelineElement)
G_IMPLEMENT_INTERFACE (GES_TYPE_EXTRACTABLE, ges_extractable_interface_init)
G_IMPLEMENT_INTERFACE (GES_TYPE_META_CONTAINER, NULL));
/*********************************************
* Virtual methods implementation *
*********************************************/
static void
_set_child_property (GESTimelineElement * self G_GNUC_UNUSED, GObject * child,
GParamSpec * pspec, GValue * value)
{
if (G_VALUE_TYPE (value) != pspec->value_type
&& G_VALUE_TYPE (value) == G_TYPE_STRING)
gst_util_set_object_arg (child, pspec->name, g_value_get_string (value));
else
g_object_set_property (child, pspec->name, value);
}
static gboolean
_set_child_property_full (GESTimelineElement * self, GObject * child,
GParamSpec * pspec, const GValue * value, GError ** error)
{
GES_TIMELINE_ELEMENT_GET_CLASS (self)->set_child_property (self, child,
pspec, (GValue *) value);
return TRUE;
}
static gboolean
_lookup_child (GESTimelineElement * self, const gchar * prop_name,
GObject ** child, GParamSpec ** pspec)
{
GHashTableIter iter;
gpointer key, value;
gchar **names, *name, *classename;
gboolean res;
classename = NULL;
res = FALSE;
names = g_strsplit (prop_name, "::", 2);
if (names[1] != NULL) {
classename = names[0];
name = names[1];
} else
name = names[0];
g_hash_table_iter_init (&iter, self->priv->children_props);
while (g_hash_table_iter_next (&iter, &key, &value)) {
if (g_strcmp0 (G_PARAM_SPEC (key)->name, name) == 0) {
ChildPropHandler *handler = (ChildPropHandler *) value;
if (classename == NULL ||
g_strcmp0 (G_OBJECT_TYPE_NAME (G_OBJECT (handler->child)),
classename) == 0 ||
g_strcmp0 (g_type_name (G_PARAM_SPEC (key)->owner_type),
classename) == 0) {
GST_DEBUG_OBJECT (self, "The %s property from %s has been found", name,
classename);
if (child)
*child = gst_object_ref (handler->child);
if (pspec)
*pspec = g_param_spec_ref (key);
res = TRUE;
break;
}
}
}
g_strfreev (names);
return res;
}
GParamSpec **
ges_timeline_element_get_children_properties (GESTimelineElement * self,
guint * n_properties)
{
GParamSpec **pspec, *spec;
GHashTableIter iter;
gpointer key, value;
guint i = 0;
*n_properties = g_hash_table_size (self->priv->children_props);
pspec = g_new (GParamSpec *, *n_properties);
g_hash_table_iter_init (&iter, self->priv->children_props);
while (g_hash_table_iter_next (&iter, &key, &value)) {
spec = G_PARAM_SPEC (key);
pspec[i] = g_param_spec_ref (spec);
i++;
}
return pspec;
}
static void
_get_property (GObject * object, guint property_id,
GValue * value, GParamSpec * pspec)
{
GESTimelineElement *self = GES_TIMELINE_ELEMENT (object);
switch (property_id) {
case PROP_PARENT:
g_value_take_object (value, self->parent);
break;
case PROP_TIMELINE:
g_value_take_object (value, self->timeline);
break;
case PROP_START:
g_value_set_uint64 (value, self->start);
break;
case PROP_INPOINT:
g_value_set_uint64 (value, self->inpoint);
break;
case PROP_DURATION:
g_value_set_uint64 (value, self->duration);
break;
case PROP_MAX_DURATION:
g_value_set_uint64 (value, self->maxduration);
break;
case PROP_PRIORITY:
g_value_set_uint (value, self->priority);
break;
case PROP_NAME:
g_value_take_string (value, ges_timeline_element_get_name (self));
break;
case PROP_SERIALIZE:
g_value_set_boolean (value, self->priv->serialize);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec);
}
}
static void
_set_property (GObject * object, guint property_id,
const GValue * value, GParamSpec * pspec)
{
GESTimelineElement *self = GES_TIMELINE_ELEMENT (object);
switch (property_id) {
case PROP_PARENT:
ges_timeline_element_set_parent (self, g_value_get_object (value));
break;
case PROP_TIMELINE:
ges_timeline_element_set_timeline (self, g_value_get_object (value));
break;
case PROP_START:
ges_timeline_element_set_start (self, g_value_get_uint64 (value));
break;
case PROP_INPOINT:
ges_timeline_element_set_inpoint (self, g_value_get_uint64 (value));
break;
case PROP_DURATION:
ges_timeline_element_set_duration (self, g_value_get_uint64 (value));
break;
case PROP_PRIORITY:
ges_timeline_element_set_priority (self, g_value_get_uint (value));
break;
case PROP_MAX_DURATION:
ges_timeline_element_set_max_duration (self, g_value_get_uint64 (value));
break;
case PROP_NAME:
ges_timeline_element_set_name (self, g_value_get_string (value));
break;
case PROP_SERIALIZE:
self->priv->serialize = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (self, property_id, pspec);
}
}
static void
ges_timeline_element_dispose (GObject * object)
{
GESTimelineElement *self = GES_TIMELINE_ELEMENT (object);
if (self->priv->children_props) {
g_hash_table_unref (self->priv->children_props);
self->priv->children_props = NULL;
}
g_clear_object (&self->priv->copied_from);
G_OBJECT_CLASS (ges_timeline_element_parent_class)->dispose (object);
}
static void
ges_timeline_element_finalize (GObject * self)
{
GESTimelineElement *tle = GES_TIMELINE_ELEMENT (self);
g_free (tle->name);
G_OBJECT_CLASS (ges_timeline_element_parent_class)->finalize (self);
}
static void
_child_prop_handler_free (ChildPropHandler * handler)
{
g_object_freeze_notify (handler->child);
if (handler->handler_id)
g_signal_handler_disconnect (handler->child, handler->handler_id);
g_object_thaw_notify (handler->child);
if (handler->child != (GObject *) handler->self &&
handler->child != (GObject *) handler->owner)
gst_object_unref (handler->child);
g_slice_free (ChildPropHandler, handler);
}
static gboolean
_get_natural_framerate (GESTimelineElement * self, gint * framerate_n,
gint * framerate_d)
{
GST_INFO_OBJECT (self, "No natural framerate");
return FALSE;
}
static void
ges_timeline_element_init (GESTimelineElement * self)
{
self->priv = ges_timeline_element_get_instance_private (self);
self->priv->serialize = TRUE;
self->priv->children_props =
g_hash_table_new_full ((GHashFunc) ges_pspec_hash, ges_pspec_equal,
(GDestroyNotify) g_param_spec_unref,
(GDestroyNotify) _child_prop_handler_free);
}
static void
ges_timeline_element_class_init (GESTimelineElementClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = _get_property;
object_class->set_property = _set_property;
/**
* GESTimelineElement:parent:
*
* The parent container of the element.
*/
properties[PROP_PARENT] =
g_param_spec_object ("parent", "Parent",
"The parent container of the object", GES_TYPE_TIMELINE_ELEMENT,
G_PARAM_READWRITE);
/**
* GESTimelineElement:timeline:
*
* The timeline that the element lies within.
*/
properties[PROP_TIMELINE] =
g_param_spec_object ("timeline", "Timeline",
"The timeline the object is in", GES_TYPE_TIMELINE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GESTimelineElement:start:
*
* The starting position of the element in the timeline (in nanoseconds
* and in the time coordinates of the timeline). For example, for a
* source element, this would determine the time at which it should
* start outputting its internal content. For an operation element, this
* would determine the time at which it should start applying its effect
* to any source content.
*/
properties[PROP_START] = g_param_spec_uint64 ("start", "Start",
"The position in the timeline", 0, G_MAXUINT64, 0,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GESTimelineElement:in-point:
*
* The initial offset to use internally when outputting content (in
* nanoseconds, but in the time coordinates of the internal content).
*
* For example, for a #GESVideoUriSource that references some media
* file, the "internal content" is the media file data, and the
* in-point would correspond to some timestamp in the media file.
* When playing the timeline, and when the element is first reached at
* timeline-time #GESTimelineElement:start, it will begin outputting the
* data from the timestamp in-point **onwards**, until it reaches the
* end of its #GESTimelineElement:duration in the timeline.
*
* For elements that have no internal content, this should be kept
* as 0.
*/
properties[PROP_INPOINT] =
g_param_spec_uint64 ("in-point", "In-point", "The in-point", 0,
G_MAXUINT64, 0, G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GESTimelineElement:duration:
*
* The duration that the element is in effect for in the timeline (a
* time difference in nanoseconds using the time coordinates of the
* timeline). For example, for a source element, this would determine
* for how long it should output its internal content for. For an
* operation element, this would determine for how long its effect
* should be applied to any source content.
*/
properties[PROP_DURATION] =
g_param_spec_uint64 ("duration", "Duration", "The play duration", 0,
G_MAXUINT64, GST_CLOCK_TIME_NONE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
* GESTimelineElement:max-duration:
*
* The full duration of internal content that is available (a time
* difference in nanoseconds using the time coordinates of the internal
* content).
*
* This will act as a cap on the #GESTimelineElement:in-point of the
* element (which is in the same time coordinates), and will sometimes
* be used to limit the #GESTimelineElement:duration of the element in
* the timeline.
*
* For example, for a #GESVideoUriSource that references some media
* file, this would be the length of the media file.
*
* For elements that have no internal content, or whose content is
* indefinite, this should be kept as #GST_CLOCK_TIME_NONE.
*/
properties[PROP_MAX_DURATION] =
g_param_spec_uint64 ("max-duration", "Maximum duration",
"The maximum duration of the object", 0, G_MAXUINT64, GST_CLOCK_TIME_NONE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_EXPLICIT_NOTIFY);
/**
* GESTimelineElement:priority:
*
* The priority of the element.
*
* Deprecated: 1.10: Priority management is now done by GES itself.
*/
properties[PROP_PRIORITY] = g_param_spec_uint ("priority", "Priority",
"The priority of the object", 0, G_MAXUINT, 0, G_PARAM_READWRITE);
/**
* GESTimelineElement:name:
*
* The name of the element. This should be unique within its timeline.
*/
properties[PROP_NAME] =
g_param_spec_string ("name", "Name", "The name of the timeline object",
NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
/**
* GESTimelineElement:serialize:
*
* Whether the element should be serialized.
*/
properties[PROP_SERIALIZE] = g_param_spec_boolean ("serialize", "Serialize",
"Whether the element should be serialized", TRUE,
G_PARAM_READWRITE | GES_PARAM_NO_SERIALIZATION);
g_object_class_install_properties (object_class, PROP_LAST, properties);
/**
* GESTimelineElement::deep-notify:
* @timeline_element: A #GESTtimelineElement
* @prop_object: The child whose property has been set
* @prop: The specification for the property that been set
*
* Emitted when a child of the element has one of its registered
* properties set. See ges_timeline_element_add_child_property().
* Note that unlike #GObject::notify, a child property name can not be
* used as a signal detail.
*/
ges_timeline_element_signals[DEEP_NOTIFY] =
g_signal_new ("deep-notify", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED |
G_SIGNAL_NO_HOOKS, 0, NULL, NULL, NULL,
G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_PARAM);
/**
* GESTimelineElement::child-property-added:
* @timeline_element: A #GESTtimelineElement
* @prop_object: The child whose property has been registered
* @prop: The specification for the property that has been registered
*
* Emitted when the element has a new child property registered. See
* ges_timeline_element_add_child_property().
*
* Note that some GES elements will be automatically created with
* pre-registered children properties. You can use
* ges_timeline_element_list_children_properties() to list these.
*
* Since: 1.18
*/
ges_timeline_element_signals[CHILD_PROPERTY_ADDED] =
g_signal_new ("child-property-added", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 2,
G_TYPE_OBJECT, G_TYPE_PARAM);
/**
* GESTimelineElement::child-property-removed:
* @timeline_element: A #GESTimelineElement
* @prop_object: The child whose property has been unregistered
* @prop: The specification for the property that has been unregistered
*
* Emitted when the element has a child property unregistered. See
* ges_timeline_element_remove_child_property().
*
* Since: 1.18
*/
ges_timeline_element_signals[CHILD_PROPERTY_REMOVED] =
g_signal_new ("child-property-removed", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, G_TYPE_NONE, 2,
G_TYPE_OBJECT, G_TYPE_PARAM);
object_class->dispose = ges_timeline_element_dispose;
object_class->finalize = ges_timeline_element_finalize;
klass->set_parent = NULL;
klass->set_start = NULL;
klass->set_inpoint = NULL;
klass->set_duration = NULL;
klass->set_max_duration = NULL;
klass->set_priority = NULL;
klass->ripple = NULL;
klass->ripple_end = NULL;
klass->roll_start = NULL;
klass->roll_end = NULL;
klass->trim = NULL;
klass->list_children_properties =
ges_timeline_element_get_children_properties;
klass->lookup_child = _lookup_child;
klass->set_child_property = _set_child_property;
klass->set_child_property_full = _set_child_property_full;
klass->get_natural_framerate = _get_natural_framerate;
}
static void
_set_name (GESTimelineElement * self, const gchar * wanted_name)
{
const gchar *type_name;
gchar *lowcase_type;
gint count;
GQuark q;
guint i, l;
gchar *name = NULL;
if (!object_name_counts) {
g_datalist_init (&object_name_counts);
}
q = g_type_qname (G_OBJECT_TYPE (self));
count = GPOINTER_TO_INT (g_datalist_id_get_data (&object_name_counts, q));
/* GstFooSink -> foosink<N> */
type_name = g_quark_to_string (q);
if (strncmp (type_name, "GES", 3) == 0)
type_name += 3;
lowcase_type = g_strdup (type_name);
l = strlen (lowcase_type);
for (i = 0; i < l; i++)
lowcase_type[i] = g_ascii_tolower (lowcase_type[i]);
if (wanted_name == NULL) {
/* give the 20th "uriclip" element and the first "uriclip2" (if needed in the future)
* different names */
l = strlen (type_name);
if (l > 0 && g_ascii_isdigit (type_name[l - 1])) {
name = g_strdup_printf ("%s-%d", lowcase_type, count++);
} else {
name = g_strdup_printf ("%s%d", lowcase_type, count++);
}
} else {
/* If the wanted name uses the same 'namespace' as default, make
* sure it does not badly interfere with our counting system */
/* FIXME: should we really be allowing a user to set the name
* "uriclip1" for, say, a GESTransition? The below code *does not*
* capture this case (because the prefix does not match "transition").
* If the user subsequently calls _set_name with name == NULL, on a
* GESClip *for the first time*, then the GES library will
* automatically choose the *same* name "uriclip1", but this is not
* unique! */
if (g_str_has_prefix (wanted_name, lowcase_type)) {
guint64 tmpcount =
g_ascii_strtoull (&wanted_name[strlen (lowcase_type)], NULL, 10);
if (tmpcount > count) {
count = tmpcount + 1;
GST_DEBUG_OBJECT (self, "Using same naming %s but updated count to %i",
wanted_name, count);
} else if (tmpcount < count) {
/* FIXME: this can unexpectedly change names given by the user
* E.g. if "transition2" already exists, and a user then wants to
* set a GESTransition to have the name "transition-custom" or
* "transition 1 too many" then tmpcount would in fact be 0 or 1,
* and the name would then be changed to "transition3"! */
name = g_strdup_printf ("%s%d", lowcase_type, count);
count++;
GST_DEBUG_OBJECT (self, "Name %s already allocated, giving: %s instead"
" New count is %i", wanted_name, name, count);
} else {
count++;
GST_DEBUG_OBJECT (self, "Perfect name, just bumping object count");
}
}
if (name == NULL)
name = g_strdup (wanted_name);
}
g_free (lowcase_type);
g_datalist_id_set_data (&object_name_counts, q, GINT_TO_POINTER (count));
g_free (self->name);
self->name = name;
}
/*********************************************
* Internal and private helpers *
*********************************************/
GESTimelineElement *
ges_timeline_element_peak_toplevel (GESTimelineElement * self)
{
GESTimelineElement *toplevel = self;
while (toplevel->parent)
toplevel = toplevel->parent;
return toplevel;
}
GESTimelineElement *
ges_timeline_element_get_copied_from (GESTimelineElement * self)
{
GESTimelineElement *copied_from = self->priv->copied_from;
self->priv->copied_from = NULL;
return copied_from;
}
GESTimelineElementFlags
ges_timeline_element_flags (GESTimelineElement * self)
{
return self->priv->flags;
}
void
ges_timeline_element_set_flags (GESTimelineElement * self,
GESTimelineElementFlags flags)
{
self->priv->flags = flags;
}
static gboolean
emit_deep_notify_in_idle (EmitDeepNotifyInIdleData * data)
{
g_signal_emit (data->self, ges_timeline_element_signals[DEEP_NOTIFY], 0,
data->child, data->arg);
gst_object_unref (data->child);
g_param_spec_unref (data->arg);
gst_object_unref (data->self);
g_slice_free (EmitDeepNotifyInIdleData, data);
return FALSE;
}
static void
child_prop_changed_cb (GObject * child, GParamSpec * arg,
GESTimelineElement * self)
{
EmitDeepNotifyInIdleData *data;
/* Emit "deep-notify" right away if in main thread */
if (g_main_context_acquire (g_main_context_default ())) {
g_main_context_release (g_main_context_default ());
g_signal_emit (self, ges_timeline_element_signals[DEEP_NOTIFY], 0,
child, arg);
return;
}
data = g_slice_new (EmitDeepNotifyInIdleData);
data->child = gst_object_ref (child);
data->arg = g_param_spec_ref (arg);
data->self = gst_object_ref (self);
ges_idle_add ((GSourceFunc) emit_deep_notify_in_idle, data, NULL);
}
static gboolean
set_child_property_by_pspec (GESTimelineElement * self,
GParamSpec * pspec, const GValue * value, GError ** error)
{
GESTimelineElementClass *klass;
GESTimelineElement *setter = self;
ChildPropHandler *handler =
g_hash_table_lookup (self->priv->children_props, pspec);
if (!handler) {
GST_ERROR_OBJECT (self, "The %s property doesn't exist", pspec->name);
return FALSE;
}
if (handler->owner) {
klass = GES_TIMELINE_ELEMENT_GET_CLASS (handler->owner);
setter = handler->owner;
} else {
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
}
if (klass->set_child_property_full)
return klass->set_child_property_full (setter, handler->child, pspec,
value, error);
g_assert (klass->set_child_property);
klass->set_child_property (setter, handler->child, pspec, (GValue *) value);
return TRUE;
}
gboolean
ges_timeline_element_add_child_property_full (GESTimelineElement * self,
GESTimelineElement * owner, GParamSpec * pspec, GObject * child)
{
gchar *signame;
ChildPropHandler *handler;
/* FIXME: allow the same pspec, provided the child is different. This
* is important for containers that may have duplicate children
* If this is changed, _remove_childs_child_property in ges-container.c
* should be changed to reflect this.
* We could hack around this by copying the pspec into a new instance
* of GParamSpec, but there is no such GLib method, and it would break
* the usage of get_..._from_pspec and set_..._from_pspec */
if (g_hash_table_contains (self->priv->children_props, pspec)) {
GST_INFO_OBJECT (self, "Child property already exists: %s", pspec->name);
return FALSE;
}
GST_DEBUG_OBJECT (self, "Adding child property: %" GST_PTR_FORMAT "::%s",
child, pspec->name);
signame = g_strconcat ("notify::", pspec->name, NULL);
handler = (ChildPropHandler *) g_slice_new0 (ChildPropHandler);
handler->self = self;
if (child == G_OBJECT (self) || child == G_OBJECT (owner))
handler->child = child;
else
handler->child = gst_object_ref (child);
handler->owner = owner;
handler->handler_id =
g_signal_connect (child, signame, G_CALLBACK (child_prop_changed_cb),
self);
g_hash_table_insert (self->priv->children_props, g_param_spec_ref (pspec),
handler);
g_signal_emit (self, ges_timeline_element_signals[CHILD_PROPERTY_ADDED], 0,
child, pspec);
g_free (signame);
return TRUE;
}
GObject *
ges_timeline_element_get_child_from_child_property (GESTimelineElement * self,
GParamSpec * pspec)
{
ChildPropHandler *handler =
g_hash_table_lookup (self->priv->children_props, pspec);
if (handler)
return handler->child;
return NULL;
}
/*********************************************
* API implementation *
*********************************************/
/**
* ges_timeline_element_set_parent:
* @self: A #GESTimelineElement
* @parent (nullable): New parent of @self
*
* Sets the #GESTimelineElement:parent for the element.
*
* This is used internally and you should normally not call this. A
* #GESContainer will set the #GESTimelineElement:parent of its children
* in ges_container_add() and ges_container_remove().
*
* Note, if @parent is not %NULL, @self must not already have a parent
* set. Therefore, if you wish to switch parents, you will need to call
* this function twice: first to set the parent to %NULL, and then to the
* new parent.
*
* If @parent is not %NULL, you must ensure it already has a
* (non-floating) reference to @self before calling this.
*
* Returns: %TRUE if @parent could be set for @self.
*/
gboolean
ges_timeline_element_set_parent (GESTimelineElement * self,
GESTimelineElement * parent)
{
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (parent == NULL
|| GES_IS_TIMELINE_ELEMENT (parent), FALSE);
if (self == parent) {
GST_INFO_OBJECT (self, "Trying to add %p in itself, not a good idea!",
self);
/* FIXME: why are we sinking and then unreffing self when we do not
* own it? */
gst_object_ref_sink (self);
gst_object_unref (self);
return FALSE;
}
GST_DEBUG_OBJECT (self, "set parent to %" GST_PTR_FORMAT, parent);
if (self->parent != NULL && parent != NULL)
goto had_parent;
if (GES_TIMELINE_ELEMENT_GET_CLASS (self)->set_parent) {
if (!GES_TIMELINE_ELEMENT_GET_CLASS (self)->set_parent (self, parent))
return FALSE;
}
self->parent = parent;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PARENT]);
return TRUE;
/* ERROR handling */
had_parent:
{
GST_WARNING_OBJECT (self, "set parent failed, object already had a parent");
/* FIXME: why are we sinking and then unreffing self when we do not
* own it? */
gst_object_ref_sink (self);
gst_object_unref (self);
return FALSE;
}
}
/**
* ges_timeline_element_get_parent:
* @self: A #GESTimelineElement
*
* Gets the #GESTimelineElement:parent for the element.
*
* Returns: (transfer full) (nullable): The parent of @self, or %NULL if
* @self has no parent.
*/
GESTimelineElement *
ges_timeline_element_get_parent (GESTimelineElement * self)
{
GESTimelineElement *result = NULL;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), NULL);
result = self->parent;
if (G_LIKELY (result))
gst_object_ref (result);
return result;
}
/**
* ges_timeline_element_set_timeline:
* @self: A #GESTimelineElement
* @timeline (nullable): The #GESTimeline @self should be in
*
* Sets the #GESTimelineElement:timeline of the element.
*
* This is used internally and you should normally not call this. A
* #GESClip will have its #GESTimelineElement:timeline set through its
* #GESLayer. A #GESTrack will similarly take care of setting the
* #GESTimelineElement:timeline of its #GESTrackElement-s. A #GESGroup
* will adopt the same #GESTimelineElement:timeline as its children.
*
* If @timeline is %NULL, this will stop its current
* #GESTimelineElement:timeline from tracking it, otherwise @timeline will
* start tracking @self. Note, in the latter case, @self must not already
* have a timeline set. Therefore, if you wish to switch timelines, you
* will need to call this function twice: first to set the timeline to
* %NULL, and then to the new timeline.
*
* Returns: %TRUE if @timeline could be set for @self.
*/
gboolean
ges_timeline_element_set_timeline (GESTimelineElement * self,
GESTimeline * timeline)
{
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (timeline == NULL || GES_IS_TIMELINE (timeline), FALSE);
GST_DEBUG_OBJECT (self, "set timeline to %" GST_PTR_FORMAT, timeline);
if (self->timeline == timeline)
return TRUE;
if (timeline != NULL && G_UNLIKELY (self->timeline != NULL))
goto had_timeline;
if (timeline == NULL) {
if (self->timeline) {
if (!timeline_remove_element (self->timeline, self)) {
GST_INFO_OBJECT (self, "Could not remove from"
" currently set timeline %" GST_PTR_FORMAT, self->timeline);
return FALSE;
}
}
} else {
if (!timeline_add_element (timeline, self)) {
GST_INFO_OBJECT (self, "Could not add to timeline %" GST_PTR_FORMAT,
self);
return FALSE;
}
}
self->timeline = timeline;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TIMELINE]);
return TRUE;
/* ERROR handling */
had_timeline:
{
GST_DEBUG_OBJECT (self, "set timeline failed, object already had a "
"timeline");
return FALSE;
}
}
/**
* ges_timeline_element_get_timeline:
* @self: A #GESTimelineElement
*
* Gets the #GESTimelineElement:timeline for the element.
*
* Returns: (transfer full) (nullable): The timeline of @self, or %NULL
* if @self has no timeline.
*/
GESTimeline *
ges_timeline_element_get_timeline (GESTimelineElement * self)
{
GESTimeline *result = NULL;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), NULL);
result = self->timeline;
if (G_LIKELY (result))
gst_object_ref (result);
return result;
}
/**
* ges_timeline_element_set_start:
* @self: A #GESTimelineElement
* @start: The desired start position of the element in its timeline
*
* Sets #GESTimelineElement:start for the element. If the element has a
* parent, this will also move its siblings with the same shift.
*
* Whilst the element is part of a #GESTimeline, this is the same as
* editing the element with ges_timeline_element_edit() under
* #GES_EDIT_MODE_NORMAL with #GES_EDGE_NONE. In particular, the
* #GESTimelineElement:start of the element may be snapped to a different
* timeline time from the one given. In addition, setting may fail if it
* would place the timeline in an unsupported configuration.
*
* Returns: %TRUE if @start could be set for @self.
*/
gboolean
ges_timeline_element_set_start (GESTimelineElement * self, GstClockTime start)
{
GESTimelineElementClass *klass;
GESTimelineElement *toplevel_container, *parent;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (start), FALSE);
if (self->start == start)
return TRUE;
GST_DEBUG_OBJECT (self, "current start: %" GST_TIME_FORMAT
" new start: %" GST_TIME_FORMAT,
GST_TIME_ARGS (GES_TIMELINE_ELEMENT_START (self)), GST_TIME_ARGS (start));
if (self->timeline && !GES_TIMELINE_ELEMENT_BEING_EDITED (self))
return ges_timeline_element_edit (self, NULL, -1, GES_EDIT_MODE_NORMAL,
GES_EDGE_NONE, start);
toplevel_container = ges_timeline_element_peak_toplevel (self);
parent = self->parent;
/* FIXME This should not belong to GESTimelineElement */
/* only check if no timeline, otherwise the timeline-tree will handle this
* check */
if (!self->timeline && toplevel_container &&
((gint64) (_START (toplevel_container) + start - _START (self))) < 0 &&
parent
&& GES_CONTAINER (parent)->children_control_mode == GES_CHILDREN_UPDATE) {
GST_INFO_OBJECT (self,
"Can not move the object as it would imply its "
"container to have a negative start value");
return FALSE;
}
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
if (klass->set_start) {
gint res = klass->set_start (self, start);
if (res == FALSE)
return FALSE;
if (res == TRUE) {
self->start = start;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_START]);
}
GST_DEBUG_OBJECT (self, "New start: %" GST_TIME_FORMAT,
GST_TIME_ARGS (GES_TIMELINE_ELEMENT_START (self)));
return TRUE;
}
GST_WARNING_OBJECT (self, "No set_start virtual method implementation"
" on class %s. Can not set start %" GST_TIME_FORMAT,
G_OBJECT_CLASS_NAME (klass), GST_TIME_ARGS (start));
return FALSE;
}
/**
* ges_timeline_element_set_inpoint:
* @self: A #GESTimelineElement
* @inpoint: The in-point, in internal time coordinates
*
* Sets #GESTimelineElement:in-point for the element. If the new in-point
* is above the current #GESTimelineElement:max-duration of the element,
* this method will fail.
*
* Returns: %TRUE if @inpoint could be set for @self.
*/
gboolean
ges_timeline_element_set_inpoint (GESTimelineElement * self,
GstClockTime inpoint)
{
GESTimelineElementClass *klass;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
GST_DEBUG_OBJECT (self, "current inpoint: %" GST_TIME_FORMAT
" new inpoint: %" GST_TIME_FORMAT, GST_TIME_ARGS (self->inpoint),
GST_TIME_ARGS (inpoint));
if (G_UNLIKELY (inpoint == self->inpoint))
return TRUE;
if (GES_CLOCK_TIME_IS_LESS (self->maxduration, inpoint)) {
GST_WARNING_OBJECT (self, "Can not set an in-point of %" GST_TIME_FORMAT
" because it exceeds the element's max-duration: %" GST_TIME_FORMAT,
GST_TIME_ARGS (inpoint), GST_TIME_ARGS (self->maxduration));
return FALSE;
}
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
if (klass->set_inpoint) {
/* FIXME: Could we instead use g_object_freeze_notify() to prevent
* duplicate notify signals? Rather than relying on the return value
* being -1 for setting that succeeds but does not want a notify
* signal because it will call this method on itself a second time. */
if (!klass->set_inpoint (self, inpoint))
return FALSE;
self->inpoint = inpoint;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_INPOINT]);
return TRUE;
}
GST_DEBUG_OBJECT (self, "No set_inpoint virtual method implementation"
" on class %s. Can not set inpoint %" GST_TIME_FORMAT,
G_OBJECT_CLASS_NAME (klass), GST_TIME_ARGS (inpoint));
return FALSE;
}
/**
* ges_timeline_element_set_max_duration:
* @self: A #GESTimelineElement
* @maxduration: The maximum duration, in internal time coordinates
*
* Sets #GESTimelineElement:max-duration for the element. If the new
* maximum duration is below the current #GESTimelineElement:in-point of
* the element, this method will fail.
*
* Returns: %TRUE if @maxduration could be set for @self.
*/
gboolean
ges_timeline_element_set_max_duration (GESTimelineElement * self,
GstClockTime maxduration)
{
GESTimelineElementClass *klass;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
GST_DEBUG_OBJECT (self, "current max-duration: %" GST_TIME_FORMAT
" new max-duration: %" GST_TIME_FORMAT,
GST_TIME_ARGS (self->maxduration), GST_TIME_ARGS (maxduration));
if (G_UNLIKELY (maxduration == self->maxduration))
return TRUE;
if (GES_CLOCK_TIME_IS_LESS (maxduration, self->inpoint)) {
GST_WARNING_OBJECT (self, "Can not set a max-duration of %"
GST_TIME_FORMAT " because it lies below the element's in-point: %"
GST_TIME_FORMAT, GST_TIME_ARGS (maxduration),
GST_TIME_ARGS (self->inpoint));
return FALSE;
}
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
if (klass->set_max_duration) {
if (!klass->set_max_duration (self, maxduration))
return FALSE;
self->maxduration = maxduration;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MAX_DURATION]);
return TRUE;
}
GST_DEBUG_OBJECT (self, "No set_max_duration virtual method implementation"
" on class %s. Can not set max-duration %" GST_TIME_FORMAT,
G_OBJECT_CLASS_NAME (klass), GST_TIME_ARGS (maxduration));
return FALSE;
}
/**
* ges_timeline_element_set_duration:
* @self: A #GESTimelineElement
* @duration: The desired duration in its timeline
*
* Sets #GESTimelineElement:duration for the element.
*
* Whilst the element is part of a #GESTimeline, this is the same as
* editing the element with ges_timeline_element_edit() under
* #GES_EDIT_MODE_TRIM with #GES_EDGE_END. In particular, the
* #GESTimelineElement:duration of the element may be snapped to a
* different timeline time difference from the one given. In addition,
* setting may fail if it would place the timeline in an unsupported
* configuration, or the element does not have enough internal content to
* last the desired duration.
*
* Returns: %TRUE if @duration could be set for @self.
*/
gboolean
ges_timeline_element_set_duration (GESTimelineElement * self,
GstClockTime duration)
{
GESTimelineElementClass *klass;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
if (duration == self->duration)
return TRUE;
if (self->timeline && !GES_TIMELINE_ELEMENT_BEING_EDITED (self))
return ges_timeline_element_edit (self, NULL, -1, GES_EDIT_MODE_TRIM,
GES_EDGE_END, self->start + duration);
GST_DEBUG_OBJECT (self, "current duration: %" GST_TIME_FORMAT
" new duration: %" GST_TIME_FORMAT,
GST_TIME_ARGS (GES_TIMELINE_ELEMENT_DURATION (self)),
GST_TIME_ARGS (duration));
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
if (klass->set_duration) {
gint res = klass->set_duration (self, duration);
if (res == FALSE)
return FALSE;
if (res == TRUE) {
self->duration = duration;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DURATION]);
}
return TRUE;
}
GST_WARNING_OBJECT (self, "No set_duration virtual method implementation"
" on class %s. Can not set duration %" GST_TIME_FORMAT,
G_OBJECT_CLASS_NAME (klass), GST_TIME_ARGS (duration));
return FALSE;
}
/**
* ges_timeline_element_get_start:
* @self: A #GESTimelineElement
*
* Gets the #GESTimelineElement:start for the element.
*
* Returns: The start of @self (in nanoseconds).
*/
GstClockTime
ges_timeline_element_get_start (GESTimelineElement * self)
{
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), GST_CLOCK_TIME_NONE);
return self->start;
}
/**
* ges_timeline_element_get_inpoint:
* @self: A #GESTimelineElement
*
* Gets the #GESTimelineElement:in-point for the element.
*
* Returns: The in-point of @self (in nanoseconds).
*/
GstClockTime
ges_timeline_element_get_inpoint (GESTimelineElement * self)
{
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), GST_CLOCK_TIME_NONE);
return self->inpoint;
}
/**
* ges_timeline_element_get_duration:
* @self: A #GESTimelineElement
*
* Gets the #GESTimelineElement:duration for the element.
*
* Returns: The duration of @self (in nanoseconds).
*/
GstClockTime
ges_timeline_element_get_duration (GESTimelineElement * self)
{
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), GST_CLOCK_TIME_NONE);
return self->duration;
}
/**
* ges_timeline_element_get_max_duration:
* @self: A #GESTimelineElement
*
* Gets the #GESTimelineElement:max-duration for the element.
*
* Returns: The max-duration of @self (in nanoseconds).
*/
GstClockTime
ges_timeline_element_get_max_duration (GESTimelineElement * self)
{
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), GST_CLOCK_TIME_NONE);
return self->maxduration;
}
/**
* ges_timeline_element_get_priority:
* @self: A #GESTimelineElement
*
* Gets the #GESTimelineElement:priority for the element.
*
* Returns: The priority of @self.
*/
guint32
ges_timeline_element_get_priority (GESTimelineElement * self)
{
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), 0);
return self->priority;
}
/**
* ges_timeline_element_set_priority:
* @self: A #GESTimelineElement
* @priority: The priority
*
* Sets the priority of the element within the containing layer.
*
* Deprecated:1.10: All priority management is done by GES itself now.
* To set #GESEffect priorities #ges_clip_set_top_effect_index should
* be used.
*
* Returns: %TRUE if @priority could be set for @self.
*/
gboolean
ges_timeline_element_set_priority (GESTimelineElement * self, guint32 priority)
{
GESTimelineElementClass *klass;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
GST_DEBUG_OBJECT (self, "current priority: %d new priority: %d",
self->priority, priority);
if (klass->set_priority) {
gboolean res = klass->set_priority (self, priority);
if (res) {
self->priority = priority;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PRIORITY]);
}
return res;
}
GST_WARNING_OBJECT (self, "No set_priority virtual method implementation"
" on class %s. Can not set priority %d", G_OBJECT_CLASS_NAME (klass),
priority);
return FALSE;
}
/**
* ges_timeline_element_ripple:
* @self: The #GESTimelineElement to ripple
* @start: The new start time of @self in ripple mode
*
* Edits the start time of an element within its timeline in ripple mode.
* See ges_timeline_element_edit() with #GES_EDIT_MODE_RIPPLE and
* #GES_EDGE_NONE.
*
* Returns: %TRUE if the ripple edit of @self completed, %FALSE on
* failure.
*/
gboolean
ges_timeline_element_ripple (GESTimelineElement * self, GstClockTime start)
{
GESTimelineElementClass *klass;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (start), FALSE);
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
if (klass->ripple)
return klass->ripple (self, start);
return ges_timeline_element_edit (self, NULL, -1, GES_EDIT_MODE_RIPPLE,
GES_EDGE_NONE, start);
return FALSE;
}
/**
* ges_timeline_element_ripple_end:
* @self: The #GESTimelineElement to ripple
* @end: The new end time of @self in ripple mode
*
* Edits the end time of an element within its timeline in ripple mode.
* See ges_timeline_element_edit() with #GES_EDIT_MODE_RIPPLE and
* #GES_EDGE_END.
*
* Returns: %TRUE if the ripple edit of @self completed, %FALSE on
* failure.
*/
gboolean
ges_timeline_element_ripple_end (GESTimelineElement * self, GstClockTime end)
{
GESTimelineElementClass *klass;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (end), FALSE);
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
if (klass->ripple_end)
return klass->ripple_end (self, end);
return ges_timeline_element_edit (self, NULL, -1, GES_EDIT_MODE_RIPPLE,
GES_EDGE_END, end);
}
/**
* ges_timeline_element_roll_start:
* @self: The #GESTimelineElement to roll
* @start: The new start time of @self in roll mode
*
* Edits the start time of an element within its timeline in roll mode.
* See ges_timeline_element_edit() with #GES_EDIT_MODE_ROLL and
* #GES_EDGE_START.
*
* Returns: %TRUE if the roll edit of @self completed, %FALSE on failure.
*/
gboolean
ges_timeline_element_roll_start (GESTimelineElement * self, GstClockTime start)
{
GESTimelineElementClass *klass;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (start), FALSE);
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
if (klass->roll_start)
return klass->roll_start (self, start);
return ges_timeline_element_edit (self, NULL, -1, GES_EDIT_MODE_ROLL,
GES_EDGE_START, start);
}
/**
* ges_timeline_element_roll_end:
* @self: The #GESTimelineElement to roll
* @end: The new end time of @self in roll mode
*
* Edits the end time of an element within its timeline in roll mode.
* See ges_timeline_element_edit() with #GES_EDIT_MODE_ROLL and
* #GES_EDGE_END.
*
* Returns: %TRUE if the roll edit of @self completed, %FALSE on failure.
*/
gboolean
ges_timeline_element_roll_end (GESTimelineElement * self, GstClockTime end)
{
GESTimelineElementClass *klass;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (end), FALSE);
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
if (klass->roll_end)
return klass->roll_end (self, end);
return ges_timeline_element_edit (self, NULL, -1, GES_EDIT_MODE_ROLL,
GES_EDGE_END, end);
}
/**
* ges_timeline_element_trim:
* @self: The #GESTimelineElement to trim
* @start: The new start time of @self in trim mode
*
* Edits the start time of an element within its timeline in trim mode.
* See ges_timeline_element_edit() with #GES_EDIT_MODE_TRIM and
* #GES_EDGE_START.
*
* Returns: %TRUE if the trim edit of @self completed, %FALSE on failure.
*/
gboolean
ges_timeline_element_trim (GESTimelineElement * self, GstClockTime start)
{
GESTimelineElementClass *klass;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (start), FALSE);
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
if (klass->trim)
return klass->trim (self, start);
return ges_timeline_element_edit (self, NULL, -1, GES_EDIT_MODE_TRIM,
GES_EDGE_START, start);
}
/**
* ges_timeline_element_copy:
* @self: The #GESTimelineElement to copy
* @deep: Whether the copy is needed for pasting
*
* Create a copy of @self. All the properties of @self are copied into
* a new element, with the exception of #GESTimelineElement:parent,
* #GESTimelineElement:timeline and #GESTimelineElement:name. Other data,
* such the list of a #GESContainer's children, is **not** copied.
*
* If @deep is %TRUE, then the new element is prepared so that it can be
* used in ges_timeline_element_paste() or ges_timeline_paste_element().
* In the case of copying a #GESContainer, this ensures that the children
* of @self will also be pasted. The new element should not be used for
* anything else and can only be used **once** in a pasting operation. In
* particular, the new element itself is not an actual 'deep' copy of
* @self, but should be thought of as an intermediate object used for a
* single paste operation.
*
* Returns: (transfer floating): The newly create element, copied from @self.
*/
G_GNUC_BEGIN_IGNORE_DEPRECATIONS; /* Start ignoring GParameter deprecation */
GESTimelineElement *
ges_timeline_element_copy (GESTimelineElement * self, gboolean deep)
{
GESAsset *asset;
GParamSpec **specs;
GESTimelineElementClass *klass;
guint n, n_specs;
GESTimelineElement *ret = NULL;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), NULL);
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (self), &n_specs);
asset = ges_extractable_get_asset (GES_EXTRACTABLE (self));
g_assert (asset);
ret = GES_TIMELINE_ELEMENT (ges_asset_extract (asset, NULL));
for (n = 0; n < n_specs; ++n) {
/* We do not want the timeline or the name to be copied */
if (g_strcmp0 (specs[n]->name, "parent") &&
g_strcmp0 (specs[n]->name, "timeline") &&
g_strcmp0 (specs[n]->name, "name") &&
(specs[n]->flags & G_PARAM_READWRITE) == G_PARAM_READWRITE &&
(specs[n]->flags & G_PARAM_CONSTRUCT_ONLY) == 0) {
GValue v = G_VALUE_INIT;
g_value_init (&v, specs[n]->value_type);
g_object_get_property (G_OBJECT (self), specs[n]->name, &v);
g_object_set_property (G_OBJECT (ret), specs[n]->name, &v);
g_value_reset (&v);
}
}
g_free (specs);
if (deep) {
if (klass->deep_copy)
klass->deep_copy (self, ret);
else
GST_WARNING_OBJECT (self, "No deep_copy virtual method implementation"
" on class %s. Can not finish the copy", G_OBJECT_CLASS_NAME (klass));
}
if (deep) {
ret->priv->copied_from = gst_object_ref (self);
}
return ret;
}
G_GNUC_END_IGNORE_DEPRECATIONS; /* End ignoring GParameter deprecation */
/**
* ges_timeline_element_get_toplevel_parent:
* @self: The #GESTimelineElement to get the toplevel parent from
*
* Gets the toplevel #GESTimelineElement:parent of the element.
*
* Returns: (transfer full): The toplevel parent of @self.
*/
GESTimelineElement *
ges_timeline_element_get_toplevel_parent (GESTimelineElement * self)
{
GESTimelineElement *toplevel;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), NULL);
toplevel = ges_timeline_element_peak_toplevel (self);
return gst_object_ref (toplevel);
}
/**
* ges_timeline_element_get_name:
* @self: A #GESTimelineElement
*
* Gets the #GESTimelineElement:name for the element.
*
* Returns: (transfer full) (nullable): The name of @self.
*/
gchar *
ges_timeline_element_get_name (GESTimelineElement * self)
{
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), NULL);
return g_strdup (self->name);
}
/**
* ges_timeline_element_set_name:
* @self: A #GESTimelineElement
* @name: (nullable): The name @self should take
*
* Sets the #GESTimelineElement:name for the element. If %NULL is given
* for @name, then the library will instead generate a new name based on
* the type name of the element, such as the name "uriclip3" for a
* #GESUriClip, and will set that name instead.
*
* If @self already has a #GESTimelineElement:timeline, you should not
* call this function with @name set to %NULL.
*
* You should ensure that, within each #GESTimeline, every element has a
* unique name. If you call this function with @name as %NULL, then
* the library should ensure that the set generated name is unique from
* previously **generated** names. However, if you choose a @name that
* interferes with the naming conventions of the library, the library will
* attempt to ensure that the generated names will not conflict with the
* chosen name, which may lead to a different name being set instead, but
* the uniqueness between generated and user-chosen names is not
* guaranteed.
*
* Returns: %TRUE if @name or a generated name for @self could be set.
*/
gboolean
ges_timeline_element_set_name (GESTimelineElement * self, const gchar * name)
{
gboolean result = TRUE, readd_to_timeline = FALSE;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
if (name != NULL && !g_strcmp0 (name, self->name)) {
GST_DEBUG_OBJECT (self, "Same name!");
return TRUE;
}
/* parented objects cannot be renamed */
if (self->timeline != NULL && name) {
GESTimelineElement *tmp = ges_timeline_get_element (self->timeline, name);
/* FIXME: if tmp == self then this means that we setting the name of
* self to its existing name. There is no need to throw an error */
if (tmp) {
gst_object_unref (tmp);
goto had_timeline;
}
timeline_remove_element (self->timeline, self);
readd_to_timeline = TRUE;
}
/* FIXME: if self already has a timeline and name is NULL, then it also
* needs to be re-added to the timeline (or, at least its entry in
* timeline->priv->all_elements needs its key to be updated) using the
* new generated name */
_set_name (self, name);
/* FIXME: the set name may not always be unique in a given timeline, see
* _set_name(). This can cause timeline_add_element to fail! */
if (readd_to_timeline)
timeline_add_element (self->timeline, self);
return result;
/* error */
had_timeline:
{
/* FIXME: message is misleading. We are here if some other object in
* the timeline was added under @name (see above) */
GST_WARNING ("Object %s already in a timeline can't be renamed to %s",
self->name, name);
return FALSE;
}
}
/**
* ges_timeline_element_add_child_property:
* @self: A #GESTimelineElement
* @pspec: The specification for the property to add
* @child: The #GstObject who the property belongs to
*
* Register a property of a child of the element to allow it to be
* written with ges_timeline_element_set_child_property() and read with
* ges_timeline_element_get_child_property(). A change in the property
* will also appear in the #GESTimelineElement::deep-notify signal.
*
* @pspec should be unique from other children properties that have been
* registered on @self.
*
* Returns: %TRUE if the property was successfully registered.
*/
gboolean
ges_timeline_element_add_child_property (GESTimelineElement * self,
GParamSpec * pspec, GObject * child)
{
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
g_return_val_if_fail (G_IS_OBJECT (child), FALSE);
return ges_timeline_element_add_child_property_full (self, NULL, pspec,
child);
}
/**
* ges_timeline_element_get_child_property_by_pspec:
* @self: A #GESTimelineElement
* @pspec: The specification of a registered child property to get
* @value: (out): The return location for the value
*
* Gets the property of a child of the element. Specifically, the property
* corresponding to the @pspec used in
* ges_timeline_element_add_child_property() is copied into @value.
*/
void
ges_timeline_element_get_child_property_by_pspec (GESTimelineElement * self,
GParamSpec * pspec, GValue * value)
{
ChildPropHandler *handler;
g_return_if_fail (GES_IS_TIMELINE_ELEMENT (self));
g_return_if_fail (G_IS_PARAM_SPEC (pspec));
handler = g_hash_table_lookup (self->priv->children_props, pspec);
if (!handler)
goto not_found;
g_object_get_property (G_OBJECT (handler->child), pspec->name, value);
return;
not_found:
{
GST_ERROR_OBJECT (self, "The %s property doesn't exist", pspec->name);
return;
}
}
/**
* ges_timeline_element_set_child_property_by_pspec:
* @self: A #GESTimelineElement
* @pspec: The specification of a registered child property to set
* @value: The value to set the property to
*
* Sets the property of a child of the element. Specifically, the property
* corresponding to the @pspec used in
* ges_timeline_element_add_child_property() is set to @value.
*/
void
ges_timeline_element_set_child_property_by_pspec (GESTimelineElement * self,
GParamSpec * pspec, const GValue * value)
{
g_return_if_fail (GES_IS_TIMELINE_ELEMENT (self));
g_return_if_fail (G_IS_PARAM_SPEC (pspec));
set_child_property_by_pspec (self, pspec, value, NULL);
}
/**
* ges_timeline_element_set_child_property_full:
* @self: A #GESTimelineElement
* @property_name: The name of the child property to set
* @value: The value to set the property to
* @error: (nullable): Return location for an error
*
* Sets the property of a child of the element.
*
* @property_name can either be in the format "prop-name" or
* "TypeName::prop-name", where "prop-name" is the name of the property
* to set (as used in g_object_set()), and "TypeName" is the type name of
* the child (as returned by G_OBJECT_TYPE_NAME()). The latter format is
* useful when two children of different types share the same property
* name.
*
* The first child found with the given "prop-name" property that was
* registered with ges_timeline_element_add_child_property() (and of the
* type "TypeName", if it was given) will have the corresponding
* property set to @value. Other children that may have also matched the
* property name (and type name) are left unchanged!
*
* Returns: %TRUE if the property was found and set.
* Since: 1.18
*/
gboolean
ges_timeline_element_set_child_property_full (GESTimelineElement * self,
const gchar * property_name, const GValue * value, GError ** error)
{
GParamSpec *pspec;
GObject *child;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
if (!ges_timeline_element_lookup_child (self, property_name, &child, &pspec))
goto not_found;
return set_child_property_by_pspec (self, pspec, value, error);
not_found:
{
GST_WARNING_OBJECT (self, "The %s property doesn't exist", property_name);
return FALSE;
}
}
/**
* ges_timeline_element_set_child_property:
* @self: A #GESTimelineElement
* @property_name: The name of the child property to set
* @value: The value to set the property to
*
* See ges_timeline_element_set_child_property_full(), which also gives an
* error.
*
* Note that ges_timeline_element_set_child_properties() may be more
* convenient for C programming.
*
* Returns: %TRUE if the property was found and set.
*/
gboolean
ges_timeline_element_set_child_property (GESTimelineElement * self,
const gchar * property_name, const GValue * value)
{
return ges_timeline_element_set_child_property_full (self, property_name,
value, NULL);
}
/**
* ges_timeline_element_get_child_property:
* @self: A #GESTimelineElement
* @property_name: The name of the child property to get
* @value: (out): The return location for the value
*
* Gets the property of a child of the element.
*
* @property_name can either be in the format "prop-name" or
* "TypeName::prop-name", where "prop-name" is the name of the property
* to get (as used in g_object_get()), and "TypeName" is the type name of
* the child (as returned by G_OBJECT_TYPE_NAME()). The latter format is
* useful when two children of different types share the same property
* name.
*
* The first child found with the given "prop-name" property that was
* registered with ges_timeline_element_add_child_property() (and of the
* type "TypeName", if it was given) will have the corresponding
* property copied into @value.
*
* Note that ges_timeline_element_get_child_properties() may be more
* convenient for C programming.
*
* Returns: %TRUE if the property was found and copied to @value.
*/
gboolean
ges_timeline_element_get_child_property (GESTimelineElement * self,
const gchar * property_name, GValue * value)
{
GParamSpec *pspec;
GObject *child;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
if (!ges_timeline_element_lookup_child (self, property_name, &child, &pspec))
goto not_found;
/* FIXME: since GLib 2.60, g_object_get_property() will automatically
* initialize the type */
if (G_VALUE_TYPE (value) == G_TYPE_INVALID)
g_value_init (value, pspec->value_type);
g_object_get_property (child, pspec->name, value);
gst_object_unref (child);
g_param_spec_unref (pspec);
return TRUE;
not_found:
{
GST_WARNING_OBJECT (self, "The %s property doesn't exist", property_name);
return FALSE;
}
}
/**
* ges_timeline_element_lookup_child:
* @self: A #GESTimelineElement
* @prop_name: The name of a child property
* @child: (out) (optional) (transfer full): The return location for the
* found child
* @pspec: (out) (optional) (transfer full): The return location for the
* specification of the child property
*
* Looks up a child property of the element.
*
* @prop_name can either be in the format "prop-name" or
* "TypeName::prop-name", where "prop-name" is the name of the property
* to look up (as used in g_object_get()), and "TypeName" is the type name
* of the child (as returned by G_OBJECT_TYPE_NAME()). The latter format is
* useful when two children of different types share the same property
* name.
*
* The first child found with the given "prop-name" property that was
* registered with ges_timeline_element_add_child_property() (and of the
* type "TypeName", if it was given) will be passed to @child, and the
* registered specification of this property will be passed to @pspec.
*
* Returns: %TRUE if a child corresponding to the property was found, in
* which case @child and @pspec are set.
*/
gboolean
ges_timeline_element_lookup_child (GESTimelineElement * self,
const gchar * prop_name, GObject ** child, GParamSpec ** pspec)
{
GESTimelineElementClass *class;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
class = GES_TIMELINE_ELEMENT_GET_CLASS (self);
g_return_val_if_fail (class->lookup_child, FALSE);
return class->lookup_child (self, prop_name, child, pspec);
}
/**
* ges_timeline_element_set_child_property_valist:
* @self: A #GESTimelineElement
* @first_property_name: The name of the first child property to set
* @var_args: The value for the first property, followed optionally by more
* name/value pairs, followed by %NULL
*
* Sets several of the children properties of the element. See
* ges_timeline_element_set_child_property().
*/
void
ges_timeline_element_set_child_property_valist (GESTimelineElement * self,
const gchar * first_property_name, va_list var_args)
{
const gchar *name;
GParamSpec *pspec;
gchar *error = NULL;
GValue value = { 0, };
g_return_if_fail (GES_IS_TIMELINE_ELEMENT (self));
name = first_property_name;
/* Note: This part is in big part copied from the gst_child_object_set_valist
* method. */
/* iterate over pairs */
while (name) {
if (!ges_timeline_element_lookup_child (self, name, NULL, &pspec))
goto not_found;
G_VALUE_COLLECT_INIT (&value, pspec->value_type, var_args,
G_VALUE_NOCOPY_CONTENTS, &error);
if (error)
goto cant_copy;
set_child_property_by_pspec (self, pspec, &value, NULL);
g_param_spec_unref (pspec);
g_value_unset (&value);
name = va_arg (var_args, gchar *);
}
return;
not_found:
{
GST_WARNING_OBJECT (self, "No property %s in OBJECT\n", name);
return;
}
cant_copy:
{
GST_WARNING_OBJECT (self, "error copying value %s in %p: %s", pspec->name,
self, error);
g_param_spec_unref (pspec);
g_value_unset (&value);
return;
}
}
/**
* ges_timeline_element_set_child_properties:
* @self: A #GESTimelineElement
* @first_property_name: The name of the first child property to set
* @...: The value for the first property, followed optionally by more
* name/value pairs, followed by %NULL
*
* Sets several of the children properties of the element. See
* ges_timeline_element_set_child_property().
*/
void
ges_timeline_element_set_child_properties (GESTimelineElement * self,
const gchar * first_property_name, ...)
{
va_list var_args;
g_return_if_fail (GES_IS_TIMELINE_ELEMENT (self));
va_start (var_args, first_property_name);
ges_timeline_element_set_child_property_valist (self, first_property_name,
var_args);
va_end (var_args);
}
/**
* ges_timeline_element_get_child_property_valist:
* @self: A #GESTimelineElement
* @first_property_name: The name of the first child property to get
* @var_args: The return location for the first property, followed
* optionally by more name/return location pairs, followed by %NULL
*
* Gets several of the children properties of the element. See
* ges_timeline_element_get_child_property().
*/
void
ges_timeline_element_get_child_property_valist (GESTimelineElement * self,
const gchar * first_property_name, va_list var_args)
{
const gchar *name;
gchar *error = NULL;
GValue value = { 0, };
GParamSpec *pspec;
GObject *child;
g_return_if_fail (GES_IS_TIMELINE_ELEMENT (self));
name = first_property_name;
/* This part is in big part copied from the gst_child_object_get_valist method */
while (name) {
if (!ges_timeline_element_lookup_child (self, name, &child, &pspec))
goto not_found;
g_value_init (&value, pspec->value_type);
g_object_get_property (child, pspec->name, &value);
gst_object_unref (child);
g_param_spec_unref (pspec);
G_VALUE_LCOPY (&value, var_args, 0, &error);
if (error)
goto cant_copy;
g_value_unset (&value);
name = va_arg (var_args, gchar *);
}
return;
not_found:
{
GST_WARNING_OBJECT (self, "no child property %s", name);
return;
}
cant_copy:
{
GST_WARNING_OBJECT (self, "error copying value %s in %s", pspec->name,
error);
g_value_unset (&value);
return;
}
}
static gint
compare_gparamspec (GParamSpec ** a, GParamSpec ** b, gpointer udata)
{
return g_strcmp0 ((*a)->name, (*b)->name);
}
/**
* ges_timeline_element_list_children_properties:
* @self: A #GESTimelineElement
* @n_properties: (out): The return location for the length of the
* returned array
*
* Get a list of children properties of the element, which is a list of
* all the specifications passed to
* ges_timeline_element_add_child_property().
*
* Returns: (transfer full) (array length=n_properties): An array of
* #GParamSpec corresponding to the child properties of @self, or %NULL if
* something went wrong.
*/
GParamSpec **
ges_timeline_element_list_children_properties (GESTimelineElement * self,
guint * n_properties)
{
GParamSpec **ret;
GESTimelineElementClass *class;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), NULL);
class = GES_TIMELINE_ELEMENT_GET_CLASS (self);
if (!class->list_children_properties) {
GST_INFO_OBJECT (self, "No %s->list_children_properties implementation",
G_OBJECT_TYPE_NAME (self));
*n_properties = 0;
return NULL;
}
ret = class->list_children_properties (self, n_properties);
g_qsort_with_data (ret, *n_properties, sizeof (GParamSpec *),
(GCompareDataFunc) compare_gparamspec, NULL);
return ret;
}
/**
* ges_timeline_element_get_child_properties:
* @self: A #GESTimelineElement
* @first_property_name: The name of the first child property to get
* @...: The return location for the first property, followed
* optionally by more name/return location pairs, followed by %NULL
*
* Gets several of the children properties of the element. See
* ges_timeline_element_get_child_property().
*/
void
ges_timeline_element_get_child_properties (GESTimelineElement * self,
const gchar * first_property_name, ...)
{
va_list var_args;
g_return_if_fail (GES_IS_TIMELINE_ELEMENT (self));
va_start (var_args, first_property_name);
ges_timeline_element_get_child_property_valist (self, first_property_name,
var_args);
va_end (var_args);
}
/**
* ges_timeline_element_remove_child_property:
* @self: A #GESTimelineElement
* @pspec: The specification for the property to remove
*
* Remove a child property from the element. @pspec should be a
* specification that was passed to
* ges_timeline_element_add_child_property(). The corresponding property
* will no longer be registered as a child property for the element.
*
* Returns: %TRUE if the property was successfully un-registered for @self.
*/
gboolean
ges_timeline_element_remove_child_property (GESTimelineElement * self,
GParamSpec * pspec)
{
gpointer key, value;
GParamSpec *found_pspec;
ChildPropHandler *handler;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (G_IS_PARAM_SPEC (pspec), FALSE);
if (!g_hash_table_lookup_extended (self->priv->children_props, pspec,
&key, &value)) {
GST_WARNING_OBJECT (self, "No child property with pspec %p (%s) found",
pspec, pspec->name);
return FALSE;
}
g_hash_table_steal (self->priv->children_props, pspec);
found_pspec = G_PARAM_SPEC (key);
handler = (ChildPropHandler *) value;
g_signal_emit (self, ges_timeline_element_signals[CHILD_PROPERTY_REMOVED], 0,
handler->child, found_pspec);
g_param_spec_unref (found_pspec);
_child_prop_handler_free (handler);
return TRUE;
}
/**
* ges_timeline_element_get_track_types:
* @self: A #GESTimelineElement
*
* Gets the track types that the element can interact with, i.e. the type
* of #GESTrack it can exist in, or will create #GESTrackElement-s for.
*
* Returns: The track types that @self supports.
*
* Since: 1.6.0
*/
GESTrackType
ges_timeline_element_get_track_types (GESTimelineElement * self)
{
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), 0);
g_return_val_if_fail (GES_TIMELINE_ELEMENT_GET_CLASS (self)->get_track_types,
0);
return GES_TIMELINE_ELEMENT_GET_CLASS (self)->get_track_types (self);
}
/**
* ges_timeline_element_paste:
* @self: The #GESTimelineElement to paste
* @paste_position: The position in the timeline @element should be pasted
* to, i.e. the #GESTimelineElement:start value for the pasted element.
*
* Paste an element inside the same timeline and layer as @self. @self
* **must** be the return of ges_timeline_element_copy() with `deep=TRUE`,
* and it should not be changed before pasting.
* @self is not placed in the timeline, instead a new element is created,
* alike to the originally copied element. Note that the originally
* copied element must stay within the same timeline and layer, at both
* the point of copying and pasting.
*
* Pasting may fail if it would place the timeline in an unsupported
* configuration.
*
* After calling this function @element should not be used. In particular,
* @element can **not** be pasted again. Instead, you can copy the
* returned element and paste that copy (although, this is only possible
* if the paste was successful).
*
* See also ges_timeline_paste_element().
*
* Returns: (transfer full) (nullable): The newly created element, or
* %NULL if pasting fails.
*
* Since: 1.6.0
*/
GESTimelineElement *
ges_timeline_element_paste (GESTimelineElement * self,
GstClockTime paste_position)
{
GESTimelineElement *res;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (paste_position), FALSE);
if (!self->priv->copied_from) {
GST_ERROR_OBJECT (self, "Is not being 'deeply' copied!");
return NULL;
}
if (!GES_TIMELINE_ELEMENT_GET_CLASS (self)->paste) {
GST_ERROR_OBJECT (self, "No paste vmethod implemented");
return NULL;
}
res = GES_TIMELINE_ELEMENT_GET_CLASS (self)->paste (self,
self->priv->copied_from, paste_position);
g_clear_object (&self->priv->copied_from);
return res ? g_object_ref_sink (res) : res;
}
/**
* ges_timeline_element_get_layer_priority:
* @self: A #GESTimelineElement
*
* Gets the priority of the layer the element is in. A #GESGroup may span
* several layers, so this would return the highest priority (numerically,
* the smallest) amongst them.
*
* Returns: The priority of the layer @self is in, or
* #GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY if @self does not exist in a
* layer.
*
* Since: 1.16
*/
guint32
ges_timeline_element_get_layer_priority (GESTimelineElement * self)
{
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self),
GES_TIMELINE_ELEMENT_NO_LAYER_PRIORITY);
if (!GES_TIMELINE_ELEMENT_GET_CLASS (self)->get_layer_priority)
return self->priority;
return GES_TIMELINE_ELEMENT_GET_CLASS (self)->get_layer_priority (self);
}
/**
* ges_timeline_element_edit_full:
* @self: The #GESTimelineElement to edit
* @new_layer_priority: The priority/index of the layer @self should be
* moved to. -1 means no move
* @mode: The edit mode
* @edge: The edge of @self where the edit should occur
* @position: The edit position: a new location for the edge of @self
* (in nanoseconds) in the timeline coordinates
* @error: Return location for an error
*
* Edits the element within its timeline by adjusting its
* #GESTimelineElement:start, #GESTimelineElement:duration or
* #GESTimelineElement:in-point, and potentially doing the same for
* other elements in the timeline. See #GESEditMode for details about each
* edit mode. An edit may fail if it would place one of these properties
* out of bounds, or if it would place the timeline in an unsupported
* configuration.
*
* Note that if you act on a #GESTrackElement, this will edit its parent
* #GESClip instead. Moreover, for any #GESTimelineElement, if you select
* #GES_EDGE_NONE for #GES_EDIT_MODE_NORMAL or #GES_EDIT_MODE_RIPPLE, this
* will edit the toplevel instead, but still in such a way as to make the
* #GESTimelineElement:start of @self reach the edit @position.
*
* Note that if the element's timeline has a
* #GESTimeline:snapping-distance set, then the edit position may be
* snapped to the edge of some element under the edited element.
*
* @new_layer_priority can be used to switch @self, and other elements
* moved by the edit, to a new layer. New layers may be be created if the
* the corresponding layer priority/index does not yet exist for the
* timeline.
*
* Returns: %TRUE if the edit of @self completed, %FALSE on failure.
* Since: 1.18
*/
gboolean
ges_timeline_element_edit_full (GESTimelineElement * self,
gint64 new_layer_priority, GESEditMode mode, GESEdge edge, guint64 position,
GError ** error)
{
GESTimeline *timeline;
guint32 layer_prio;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (GST_CLOCK_TIME_IS_VALID (position), FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
timeline = GES_TIMELINE_ELEMENT_TIMELINE (self);
g_return_val_if_fail (timeline, FALSE);
layer_prio = GES_TIMELINE_ELEMENT_LAYER_PRIORITY (self);
if (new_layer_priority < 0)
new_layer_priority = layer_prio;
GST_DEBUG_OBJECT (self, "Editing %s at edge %s to position %"
GST_TIME_FORMAT " under %s mode, and to layer %" G_GINT64_FORMAT,
self->name, ges_edge_name (edge), GST_TIME_ARGS (position),
ges_edit_mode_name (mode), new_layer_priority);
return ges_timeline_edit (timeline, self, new_layer_priority, mode,
edge, position, error);
}
/**
* ges_timeline_element_edit:
* @self: The #GESTimelineElement to edit
* @layers: (element-type GESLayer) (nullable): A whitelist of layers
* where the edit can be performed, %NULL allows all layers in the
* timeline.
* @new_layer_priority: The priority/index of the layer @self should be
* moved to. -1 means no move
* @mode: The edit mode
* @edge: The edge of @self where the edit should occur
* @position: The edit position: a new location for the edge of @self
* (in nanoseconds) in the timeline coordinates
*
* See ges_timeline_element_edit_full(), which also gives an error.
*
* Note that the @layers argument is currently ignored, so you should
* just pass %NULL.
*
* Returns: %TRUE if the edit of @self completed, %FALSE on failure.
*
* Since: 1.18
*/
/* FIXME: handle the layers argument. Currently we always treat it as if
* it is NULL in the ges-timeline code */
gboolean
ges_timeline_element_edit (GESTimelineElement * self, GList * layers,
gint64 new_layer_priority, GESEditMode mode, GESEdge edge, guint64 position)
{
return ges_timeline_element_edit_full (self, new_layer_priority, mode, edge,
position, NULL);
}
/**
* ges_timeline_element_get_natural_framerate:
* @self: The #GESTimelineElement to get "natural" framerate from
* @framerate_n: (out): The framerate numerator
* @framerate_d: (out): The framerate denominator
*
* Get the "natural" framerate of @self. This is to say, for example
* for a #GESVideoUriSource the framerate of the source.
*
* Note that a #GESAudioSource may also have a natural framerate if it derives
* from the same #GESSourceClip asset as a #GESVideoSource, and its value will
* be that of the video source. For example, if the uri of a #GESUriClip points
* to a file that contains both a video and audio stream, then the corresponding
* #GESAudioUriSource will share the natural framerate of the corresponding
* #GESVideoUriSource.
*
* Returns: Whether @self has a natural framerate or not, @framerate_n
* and @framerate_d will be set to, respectively, 0 and -1 if it is
* not the case.
*
* Since: 1.18
*/
gboolean
ges_timeline_element_get_natural_framerate (GESTimelineElement * self,
gint * framerate_n, gint * framerate_d)
{
GESTimelineElementClass *klass;
g_return_val_if_fail (GES_IS_TIMELINE_ELEMENT (self), FALSE);
g_return_val_if_fail (framerate_n && framerate_d, FALSE);
klass = GES_TIMELINE_ELEMENT_GET_CLASS (self);
*framerate_n = 0;
*framerate_d = -1;
return klass->get_natural_framerate (self, framerate_n, framerate_d);
}
|