1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gstreamer.Element; 26 27 private import glib.ErrorG; 28 private import glib.GException; 29 private import glib.Str; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gobject.Type; 33 private import gstreamer.Bus; 34 private import gstreamer.Caps; 35 private import gstreamer.Clock; 36 private import gstreamer.Context; 37 private import gstreamer.ElementFactory; 38 private import gstreamer.Event; 39 private import gstreamer.Iterator; 40 private import gstreamer.Message; 41 private import gstreamer.ObjectGst; 42 private import gstreamer.Pad; 43 private import gstreamer.PadTemplate; 44 private import gstreamer.Plugin; 45 private import gstreamer.Query; 46 private import gstreamerc.gstreamer; 47 public import gstreamerc.gstreamertypes; 48 public import gtkc.gdktypes; 49 private import gtkc.gobject; 50 51 52 /** 53 * GstElement is the abstract base class needed to construct an element that 54 * can be used in a GStreamer pipeline. Please refer to the plugin writers 55 * guide for more information on creating #GstElement subclasses. 56 * 57 * The name of a #GstElement can be get with gst_element_get_name() and set with 58 * gst_element_set_name(). For speed, GST_ELEMENT_NAME() can be used in the 59 * core when using the appropriate locking. Do not use this in plug-ins or 60 * applications in order to retain ABI compatibility. 61 * 62 * Elements can have pads (of the type #GstPad). These pads link to pads on 63 * other elements. #GstBuffer flow between these linked pads. 64 * A #GstElement has a #GList of #GstPad structures for all their input (or sink) 65 * and output (or source) pads. 66 * Core and plug-in writers can add and remove pads with gst_element_add_pad() 67 * and gst_element_remove_pad(). 68 * 69 * An existing pad of an element can be retrieved by name with 70 * gst_element_get_static_pad(). A new dynamic pad can be created using 71 * gst_element_request_pad() with a #GstPadTemplate. 72 * An iterator of all pads can be retrieved with gst_element_iterate_pads(). 73 * 74 * Elements can be linked through their pads. 75 * If the link is straightforward, use the gst_element_link() 76 * convenience function to link two elements, or gst_element_link_many() 77 * for more elements in a row. 78 * Use gst_element_link_filtered() to link two elements constrained by 79 * a specified set of #GstCaps. 80 * For finer control, use gst_element_link_pads() and 81 * gst_element_link_pads_filtered() to specify the pads to link on 82 * each element by name. 83 * 84 * Each element has a state (see #GstState). You can get and set the state 85 * of an element with gst_element_get_state() and gst_element_set_state(). 86 * Setting a state triggers a #GstStateChange. To get a string representation 87 * of a #GstState, use gst_element_state_get_name(). 88 * 89 * You can get and set a #GstClock on an element using gst_element_get_clock() 90 * and gst_element_set_clock(). 91 * Some elements can provide a clock for the pipeline if 92 * the #GST_ELEMENT_FLAG_PROVIDE_CLOCK flag is set. With the 93 * gst_element_provide_clock() method one can retrieve the clock provided by 94 * such an element. 95 * Not all elements require a clock to operate correctly. If the 96 * #GST_ELEMENT_FLAG_REQUIRE_CLOCK() flag is set, a clock should be set on the 97 * element with gst_element_set_clock(). 98 * 99 * Note that clock selection and distribution is normally handled by the 100 * toplevel #GstPipeline so the clock functions are only to be used in very 101 * specific situations. 102 */ 103 public class Element : ObjectGst 104 { 105 /** the main Gtk struct */ 106 protected GstElement* gstElement; 107 108 /** Get the main Gtk struct */ 109 public GstElement* getElementStruct() 110 { 111 return gstElement; 112 } 113 114 /** the main Gtk struct as a void* */ 115 protected override void* getStruct() 116 { 117 return cast(void*)gstElement; 118 } 119 120 protected override void setStruct(GObject* obj) 121 { 122 gstElement = cast(GstElement*)obj; 123 super.setStruct(obj); 124 } 125 126 /** 127 * Sets our main struct and passes it to the parent class. 128 */ 129 public this (GstElement* gstElement, bool ownedRef = false) 130 { 131 this.gstElement = gstElement; 132 super(cast(GstObject*)gstElement, ownedRef); 133 } 134 135 /** 136 * Queries an element for the stream position. 137 * This is a convenience function for gstreamerD. 138 * Returns: 139 * The current position in nanoseconds - GstFormat.TIME. 140 */ 141 public long queryPosition() 142 { 143 GstFormat form = GstFormat.TIME; 144 long cur_pos; 145 queryPosition( form, cur_pos ); 146 return cur_pos; 147 } 148 149 /** 150 * Queries an element for the stream duration. 151 * This is a convenience function for gstreamerD. 152 * Returns: 153 * The duration in nanoseconds - GstFormat.TIME. 154 */ 155 public long queryDuration() 156 { 157 GstFormat form = GstFormat.TIME; 158 long cur_dur; 159 queryDuration( form, cur_dur ); 160 return cur_dur; 161 } 162 163 /** 164 * This set's the filename for a filesrc element. 165 */ 166 public void location( string set ) 167 { 168 //g_object_set( G_OBJECT(getElementStruct()), "location", set, NULL); 169 setProperty("location", set); 170 } 171 172 /** 173 * Set the caps property of an Element. 174 */ 175 void caps( Caps cp ) 176 { 177 g_object_set( getElementStruct(), Str.toStringz("caps"), cp.getCapsStruct(), null ); 178 } 179 180 /** 181 * For your convenience in gstreamerD: you can seek to the 182 * position of the pipeline measured in time_nanoseconds. 183 */ 184 public int seek( long time_nanoseconds ) //gint64 185 { 186 return seek( 1.0, GstFormat.TIME, GstSeekFlags.FLUSH, 187 GstSeekType.SET, time_nanoseconds, 188 GstSeekType.NONE, GST_CLOCK_TIME_NONE); 189 } 190 191 /** 192 * Get's all the pads from an element in a Pad[]. 193 */ 194 public Pad[] pads() 195 { 196 Pad[] result; 197 GValue* pad = g_value_init(new GValue(), Type.fromName("GstPad")); 198 GstIterator* iter = gst_element_iterate_pads(gstElement); 199 200 while ( gst_iterator_next(iter, pad) == GstIteratorResult.OK ) 201 { 202 result ~= new Pad(cast(GstPad*)g_value_get_object(pad)); 203 g_value_reset(pad); 204 } 205 206 g_value_unset(pad); 207 208 return result; 209 } 210 211 /** 212 */ 213 214 /** */ 215 public static GType getType() 216 { 217 return gst_element_get_type(); 218 } 219 220 /** 221 * Creates an element for handling the given URI. 222 * 223 * Params: 224 * type = Whether to create a source or a sink 225 * uri = URI to create an element for 226 * elementname = Name of created element, can be %NULL. 227 * 228 * Return: a new element or %NULL if none could be created 229 * 230 * Throws: GException on failure. 231 */ 232 public static Element makeFromUri(GstURIType type, string uri, string elementname) 233 { 234 GError* err = null; 235 236 auto p = gst_element_make_from_uri(type, Str.toStringz(uri), Str.toStringz(elementname), &err); 237 238 if (err !is null) 239 { 240 throw new GException( new ErrorG(err) ); 241 } 242 243 if(p is null) 244 { 245 return null; 246 } 247 248 return ObjectG.getDObject!(Element)(cast(GstElement*) p); 249 } 250 251 /** 252 * Create a new elementfactory capable of instantiating objects of the 253 * @type and add the factory to @plugin. 254 * 255 * Params: 256 * plugin = #GstPlugin to register the element with, or %NULL for 257 * a static element. 258 * name = name of elements of this type 259 * rank = rank of element (higher rank means more importance when autoplugging) 260 * type = GType of element to register 261 * 262 * Return: %TRUE, if the registering succeeded, %FALSE on error 263 */ 264 public static bool register(Plugin plugin, string name, uint rank, GType type) 265 { 266 return gst_element_register((plugin is null) ? null : plugin.getPluginStruct(), Str.toStringz(name), rank, type) != 0; 267 } 268 269 /** 270 * Gets a string representing the given state change result. 271 * 272 * Params: 273 * stateRet = a #GstStateChangeReturn to get the name of. 274 * 275 * Return: a string with the name of the state 276 * result. 277 */ 278 public static string stateChangeReturnGetName(GstStateChangeReturn stateRet) 279 { 280 return Str.toString(gst_element_state_change_return_get_name(stateRet)); 281 } 282 283 /** 284 * Gets a string representing the given state. 285 * 286 * Params: 287 * state = a #GstState to get the name of. 288 * 289 * Return: a string with the name of the state. 290 */ 291 public static string stateGetName(GstState state) 292 { 293 return Str.toString(gst_element_state_get_name(state)); 294 } 295 296 /** 297 * Abort the state change of the element. This function is used 298 * by elements that do asynchronous state changes and find out 299 * something is wrong. 300 * 301 * This function should be called with the STATE_LOCK held. 302 * 303 * MT safe. 304 */ 305 public void abortState() 306 { 307 gst_element_abort_state(gstElement); 308 } 309 310 /** 311 * Adds a pad (link point) to @element. @pad's parent will be set to @element; 312 * see gst_object_set_parent() for refcounting information. 313 * 314 * Pads are not automatically activated so elements should perform the needed 315 * steps to activate the pad in case this pad is added in the PAUSED or PLAYING 316 * state. See gst_pad_set_active() for more information about activating pads. 317 * 318 * The pad and the element should be unlocked when calling this function. 319 * 320 * This function will emit the #GstElement::pad-added signal on the element. 321 * 322 * Params: 323 * pad = the #GstPad to add to the element. 324 * 325 * Return: %TRUE if the pad could be added. This function can fail when 326 * a pad with the same name already existed or the pad already had another 327 * parent. 328 * 329 * MT safe. 330 */ 331 public bool addPad(Pad pad) 332 { 333 return gst_element_add_pad(gstElement, (pad is null) ? null : pad.getPadStruct()) != 0; 334 } 335 336 /** 337 * Perform @transition on @element. 338 * 339 * This function must be called with STATE_LOCK held and is mainly used 340 * internally. 341 * 342 * Params: 343 * transition = the requested transition 344 * 345 * Return: the #GstStateChangeReturn of the state transition. 346 */ 347 public GstStateChangeReturn changeState(GstStateChange transition) 348 { 349 return gst_element_change_state(gstElement, transition); 350 } 351 352 /** 353 * Commit the state change of the element and proceed to the next 354 * pending state if any. This function is used 355 * by elements that do asynchronous state changes. 356 * The core will normally call this method automatically when an 357 * element returned %GST_STATE_CHANGE_SUCCESS from the state change function. 358 * 359 * If after calling this method the element still has not reached 360 * the pending state, the next state change is performed. 361 * 362 * This method is used internally and should normally not be called by plugins 363 * or applications. 364 * 365 * Params: 366 * ret = The previous state return value 367 * 368 * Return: The result of the commit state change. 369 * 370 * MT safe. 371 */ 372 public GstStateChangeReturn continueState(GstStateChangeReturn ret) 373 { 374 return gst_element_continue_state(gstElement, ret); 375 } 376 377 /** 378 * Creates a pad for each pad template that is always available. 379 * This function is only useful during object initialization of 380 * subclasses of #GstElement. 381 */ 382 public void createAllPads() 383 { 384 gst_element_create_all_pads(gstElement); 385 } 386 387 /** 388 * Returns the base time of the element. The base time is the 389 * absolute time of the clock when this element was last put to 390 * PLAYING. Subtracting the base time from the clock time gives 391 * the running time of the element. 392 * 393 * Return: the base time of the element. 394 * 395 * MT safe. 396 */ 397 public GstClockTime getBaseTime() 398 { 399 return gst_element_get_base_time(gstElement); 400 } 401 402 /** 403 * Returns the bus of the element. Note that only a #GstPipeline will provide a 404 * bus for the application. 405 * 406 * Return: the element's #GstBus. unref after usage. 407 * 408 * MT safe. 409 */ 410 public Bus getBus() 411 { 412 auto p = gst_element_get_bus(gstElement); 413 414 if(p is null) 415 { 416 return null; 417 } 418 419 return ObjectG.getDObject!(Bus)(cast(GstBus*) p, true); 420 } 421 422 /** 423 * Gets the currently configured clock of the element. This is the clock as was 424 * last set with gst_element_set_clock(). 425 * 426 * Elements in a pipeline will only have their clock set when the 427 * pipeline is in the PLAYING state. 428 * 429 * Return: the #GstClock of the element. unref after usage. 430 * 431 * MT safe. 432 */ 433 public Clock getClock() 434 { 435 auto p = gst_element_get_clock(gstElement); 436 437 if(p is null) 438 { 439 return null; 440 } 441 442 return ObjectG.getDObject!(Clock)(cast(GstClock*) p, true); 443 } 444 445 /** 446 * Looks for an unlinked pad to which the given pad can link. It is not 447 * guaranteed that linking the pads will work, though it should work in most 448 * cases. 449 * 450 * This function will first attempt to find a compatible unlinked ALWAYS pad, 451 * and if none can be found, it will request a compatible REQUEST pad by looking 452 * at the templates of @element. 453 * 454 * Params: 455 * pad = the #GstPad to find a compatible one for. 456 * caps = the #GstCaps to use as a filter. 457 * 458 * Return: the #GstPad to which a link 459 * can be made, or %NULL if one cannot be found. gst_object_unref() 460 * after usage. 461 */ 462 public Pad getCompatiblePad(Pad pad, Caps caps) 463 { 464 auto p = gst_element_get_compatible_pad(gstElement, (pad is null) ? null : pad.getPadStruct(), (caps is null) ? null : caps.getCapsStruct()); 465 466 if(p is null) 467 { 468 return null; 469 } 470 471 return ObjectG.getDObject!(Pad)(cast(GstPad*) p, true); 472 } 473 474 /** 475 * Retrieves a pad template from @element that is compatible with @compattempl. 476 * Pads from compatible templates can be linked together. 477 * 478 * Params: 479 * compattempl = the #GstPadTemplate to find a compatible 480 * template for 481 * 482 * Return: a compatible #GstPadTemplate, 483 * or %NULL if none was found. No unreferencing is necessary. 484 */ 485 public PadTemplate getCompatiblePadTemplate(PadTemplate compattempl) 486 { 487 auto p = gst_element_get_compatible_pad_template(gstElement, (compattempl is null) ? null : compattempl.getPadTemplateStruct()); 488 489 if(p is null) 490 { 491 return null; 492 } 493 494 return ObjectG.getDObject!(PadTemplate)(cast(GstPadTemplate*) p); 495 } 496 497 /** 498 * Retrieves the factory that was used to create this element. 499 * 500 * Return: the #GstElementFactory used for creating this 501 * element. no refcounting is needed. 502 */ 503 public ElementFactory getFactory() 504 { 505 auto p = gst_element_get_factory(gstElement); 506 507 if(p is null) 508 { 509 return null; 510 } 511 512 return ObjectG.getDObject!(ElementFactory)(cast(GstElementFactory*) p); 513 } 514 515 /** 516 * Retrieves a pad from the element by name (e.g. "src_\%d"). This version only 517 * retrieves request pads. The pad should be released with 518 * gst_element_release_request_pad(). 519 * 520 * This method is slower than manually getting the pad template and calling 521 * gst_element_request_pad() if the pads should have a specific name (e.g. 522 * @name is "src_1" instead of "src_\%u"). 523 * 524 * Params: 525 * name = the name of the request #GstPad to retrieve. 526 * 527 * Return: requested #GstPad if found, 528 * otherwise %NULL. Release after usage. 529 */ 530 public Pad getRequestPad(string name) 531 { 532 auto p = gst_element_get_request_pad(gstElement, Str.toStringz(name)); 533 534 if(p is null) 535 { 536 return null; 537 } 538 539 return ObjectG.getDObject!(Pad)(cast(GstPad*) p, true); 540 } 541 542 /** 543 * Returns the start time of the element. The start time is the 544 * running time of the clock when this element was last put to PAUSED. 545 * 546 * Usually the start_time is managed by a toplevel element such as 547 * #GstPipeline. 548 * 549 * MT safe. 550 * 551 * Return: the start time of the element. 552 */ 553 public GstClockTime getStartTime() 554 { 555 return gst_element_get_start_time(gstElement); 556 } 557 558 /** 559 * Gets the state of the element. 560 * 561 * For elements that performed an ASYNC state change, as reported by 562 * gst_element_set_state(), this function will block up to the 563 * specified timeout value for the state change to complete. 564 * If the element completes the state change or goes into 565 * an error, this function returns immediately with a return value of 566 * %GST_STATE_CHANGE_SUCCESS or %GST_STATE_CHANGE_FAILURE respectively. 567 * 568 * For elements that did not return %GST_STATE_CHANGE_ASYNC, this function 569 * returns the current and pending state immediately. 570 * 571 * This function returns %GST_STATE_CHANGE_NO_PREROLL if the element 572 * successfully changed its state but is not able to provide data yet. 573 * This mostly happens for live sources that only produce data in 574 * %GST_STATE_PLAYING. While the state change return is equivalent to 575 * %GST_STATE_CHANGE_SUCCESS, it is returned to the application to signal that 576 * some sink elements might not be able to complete their state change because 577 * an element is not producing data to complete the preroll. When setting the 578 * element to playing, the preroll will complete and playback will start. 579 * 580 * Params: 581 * state = a pointer to #GstState to hold the state. 582 * Can be %NULL. 583 * pending = a pointer to #GstState to hold the pending 584 * state. Can be %NULL. 585 * timeout = a #GstClockTime to specify the timeout for an async 586 * state change or %GST_CLOCK_TIME_NONE for infinite timeout. 587 * 588 * Return: %GST_STATE_CHANGE_SUCCESS if the element has no more pending state 589 * and the last state change succeeded, %GST_STATE_CHANGE_ASYNC if the 590 * element is still performing a state change or 591 * %GST_STATE_CHANGE_FAILURE if the last state change failed. 592 * 593 * MT safe. 594 */ 595 public GstStateChangeReturn getState(out GstState state, out GstState pending, GstClockTime timeout) 596 { 597 return gst_element_get_state(gstElement, &state, &pending, timeout); 598 } 599 600 /** 601 * Retrieves a pad from @element by name. This version only retrieves 602 * already-existing (i.e. 'static') pads. 603 * 604 * Params: 605 * name = the name of the static #GstPad to retrieve. 606 * 607 * Return: the requested #GstPad if 608 * found, otherwise %NULL. unref after usage. 609 * 610 * MT safe. 611 */ 612 public Pad getStaticPad(string name) 613 { 614 auto p = gst_element_get_static_pad(gstElement, Str.toStringz(name)); 615 616 if(p is null) 617 { 618 return null; 619 } 620 621 return ObjectG.getDObject!(Pad)(cast(GstPad*) p, true); 622 } 623 624 /** 625 * Checks if the state of an element is locked. 626 * If the state of an element is locked, state changes of the parent don't 627 * affect the element. 628 * This way you can leave currently unused elements inside bins. Just lock their 629 * state before changing the state from #GST_STATE_NULL. 630 * 631 * MT safe. 632 * 633 * Return: %TRUE, if the element's state is locked. 634 */ 635 public bool isLockedState() 636 { 637 return gst_element_is_locked_state(gstElement) != 0; 638 } 639 640 /** 641 * Retrieves an iterator of @element's pads. The iterator should 642 * be freed after usage. Also more specialized iterators exists such as 643 * gst_element_iterate_src_pads() or gst_element_iterate_sink_pads(). 644 * 645 * The order of pads returned by the iterator will be the order in which 646 * the pads were added to the element. 647 * 648 * Return: the #GstIterator of #GstPad. 649 * 650 * MT safe. 651 */ 652 public Iterator iteratePads() 653 { 654 auto p = gst_element_iterate_pads(gstElement); 655 656 if(p is null) 657 { 658 return null; 659 } 660 661 return ObjectG.getDObject!(Iterator)(cast(GstIterator*) p); 662 } 663 664 /** 665 * Retrieves an iterator of @element's sink pads. 666 * 667 * The order of pads returned by the iterator will be the order in which 668 * the pads were added to the element. 669 * 670 * Return: the #GstIterator of #GstPad. 671 * 672 * MT safe. 673 */ 674 public Iterator iterateSinkPads() 675 { 676 auto p = gst_element_iterate_sink_pads(gstElement); 677 678 if(p is null) 679 { 680 return null; 681 } 682 683 return ObjectG.getDObject!(Iterator)(cast(GstIterator*) p); 684 } 685 686 /** 687 * Retrieves an iterator of @element's source pads. 688 * 689 * The order of pads returned by the iterator will be the order in which 690 * the pads were added to the element. 691 * 692 * Return: the #GstIterator of #GstPad. 693 * 694 * MT safe. 695 */ 696 public Iterator iterateSrcPads() 697 { 698 auto p = gst_element_iterate_src_pads(gstElement); 699 700 if(p is null) 701 { 702 return null; 703 } 704 705 return ObjectG.getDObject!(Iterator)(cast(GstIterator*) p); 706 } 707 708 /** 709 * Links @src to @dest. The link must be from source to 710 * destination; the other direction will not be tried. The function looks for 711 * existing pads that aren't linked yet. It will request new pads if necessary. 712 * Such pads need to be released manually when unlinking. 713 * If multiple links are possible, only one is established. 714 * 715 * Make sure you have added your elements to a bin or pipeline with 716 * gst_bin_add() before trying to link them. 717 * 718 * Params: 719 * dest = the #GstElement containing the destination pad. 720 * 721 * Return: %TRUE if the elements could be linked, %FALSE otherwise. 722 */ 723 public bool link(Element dest) 724 { 725 return gst_element_link(gstElement, (dest is null) ? null : dest.getElementStruct()) != 0; 726 } 727 728 /** 729 * Links @src to @dest using the given caps as filtercaps. 730 * The link must be from source to 731 * destination; the other direction will not be tried. The function looks for 732 * existing pads that aren't linked yet. It will request new pads if necessary. 733 * If multiple links are possible, only one is established. 734 * 735 * Make sure you have added your elements to a bin or pipeline with 736 * gst_bin_add() before trying to link them. 737 * 738 * Params: 739 * dest = the #GstElement containing the destination pad. 740 * filter = the #GstCaps to filter the link, 741 * or %NULL for no filter. 742 * 743 * Return: %TRUE if the pads could be linked, %FALSE otherwise. 744 */ 745 public bool linkFiltered(Element dest, Caps filter) 746 { 747 return gst_element_link_filtered(gstElement, (dest is null) ? null : dest.getElementStruct(), (filter is null) ? null : filter.getCapsStruct()) != 0; 748 } 749 750 /** 751 * Links the two named pads of the source and destination elements. 752 * Side effect is that if one of the pads has no parent, it becomes a 753 * child of the parent of the other element. If they have different 754 * parents, the link fails. 755 * 756 * Params: 757 * srcpadname = the name of the #GstPad in source element 758 * or %NULL for any pad. 759 * dest = the #GstElement containing the destination pad. 760 * destpadname = the name of the #GstPad in destination element, 761 * or %NULL for any pad. 762 * 763 * Return: %TRUE if the pads could be linked, %FALSE otherwise. 764 */ 765 public bool linkPads(string srcpadname, Element dest, string destpadname) 766 { 767 return gst_element_link_pads(gstElement, Str.toStringz(srcpadname), (dest is null) ? null : dest.getElementStruct(), Str.toStringz(destpadname)) != 0; 768 } 769 770 /** 771 * Links the two named pads of the source and destination elements. Side effect 772 * is that if one of the pads has no parent, it becomes a child of the parent of 773 * the other element. If they have different parents, the link fails. If @caps 774 * is not %NULL, makes sure that the caps of the link is a subset of @caps. 775 * 776 * Params: 777 * srcpadname = the name of the #GstPad in source element 778 * or %NULL for any pad. 779 * dest = the #GstElement containing the destination pad. 780 * destpadname = the name of the #GstPad in destination element 781 * or %NULL for any pad. 782 * filter = the #GstCaps to filter the link, 783 * or %NULL for no filter. 784 * 785 * Return: %TRUE if the pads could be linked, %FALSE otherwise. 786 */ 787 public bool linkPadsFiltered(string srcpadname, Element dest, string destpadname, Caps filter) 788 { 789 return gst_element_link_pads_filtered(gstElement, Str.toStringz(srcpadname), (dest is null) ? null : dest.getElementStruct(), Str.toStringz(destpadname), (filter is null) ? null : filter.getCapsStruct()) != 0; 790 } 791 792 /** 793 * Links the two named pads of the source and destination elements. 794 * Side effect is that if one of the pads has no parent, it becomes a 795 * child of the parent of the other element. If they have different 796 * parents, the link fails. 797 * 798 * Calling gst_element_link_pads_full() with @flags == %GST_PAD_LINK_CHECK_DEFAULT 799 * is the same as calling gst_element_link_pads() and the recommended way of 800 * linking pads with safety checks applied. 801 * 802 * This is a convenience function for gst_pad_link_full(). 803 * 804 * Params: 805 * srcpadname = the name of the #GstPad in source element 806 * or %NULL for any pad. 807 * dest = the #GstElement containing the destination pad. 808 * destpadname = the name of the #GstPad in destination element, 809 * or %NULL for any pad. 810 * flags = the #GstPadLinkCheck to be performed when linking pads. 811 * 812 * Return: %TRUE if the pads could be linked, %FALSE otherwise. 813 */ 814 public bool linkPadsFull(string srcpadname, Element dest, string destpadname, GstPadLinkCheck flags) 815 { 816 return gst_element_link_pads_full(gstElement, Str.toStringz(srcpadname), (dest is null) ? null : dest.getElementStruct(), Str.toStringz(destpadname), flags) != 0; 817 } 818 819 /** 820 * Brings the element to the lost state. The current state of the 821 * element is copied to the pending state so that any call to 822 * gst_element_get_state() will return %GST_STATE_CHANGE_ASYNC. 823 * 824 * An ASYNC_START message is posted. If the element was PLAYING, it will 825 * go to PAUSED. The element will be restored to its PLAYING state by 826 * the parent pipeline when it prerolls again. 827 * 828 * This is mostly used for elements that lost their preroll buffer 829 * in the %GST_STATE_PAUSED or %GST_STATE_PLAYING state after a flush, 830 * they will go to their pending state again when a new preroll buffer is 831 * queued. This function can only be called when the element is currently 832 * not in error or an async state change. 833 * 834 * This function is used internally and should normally not be called from 835 * plugins or applications. 836 */ 837 public void lostState() 838 { 839 gst_element_lost_state(gstElement); 840 } 841 842 /** 843 * Post an error, warning or info message on the bus from inside an element. 844 * 845 * @type must be of #GST_MESSAGE_ERROR, #GST_MESSAGE_WARNING or 846 * #GST_MESSAGE_INFO. 847 * 848 * MT safe. 849 * 850 * Params: 851 * type = the #GstMessageType 852 * domain = the GStreamer GError domain this message belongs to 853 * code = the GError code belonging to the domain 854 * text = an allocated text string to be used 855 * as a replacement for the default message connected to code, 856 * or %NULL 857 * dbg = an allocated debug message to be 858 * used as a replacement for the default debugging information, 859 * or %NULL 860 * file = the source code file where the error was generated 861 * funct = the source code function where the error was generated 862 * line = the source code line where the error was generated 863 */ 864 public void messageFull(GstMessageType type, GQuark domain, int code, string text, string dbg, string file, string funct, int line) 865 { 866 gst_element_message_full(gstElement, type, domain, code, Str.toStringz(text), Str.toStringz(dbg), Str.toStringz(file), Str.toStringz(funct), line); 867 } 868 869 /** 870 * Use this function to signal that the element does not expect any more pads 871 * to show up in the current pipeline. This function should be called whenever 872 * pads have been added by the element itself. Elements with #GST_PAD_SOMETIMES 873 * pad templates use this in combination with autopluggers to figure out that 874 * the element is done initializing its pads. 875 * 876 * This function emits the #GstElement::no-more-pads signal. 877 * 878 * MT safe. 879 */ 880 public void noMorePads() 881 { 882 gst_element_no_more_pads(gstElement); 883 } 884 885 /** 886 * Post a message on the element's #GstBus. This function takes ownership of the 887 * message; if you want to access the message after this call, you should add an 888 * additional reference before calling. 889 * 890 * Params: 891 * message = a #GstMessage to post 892 * 893 * Return: %TRUE if the message was successfully posted. The function returns 894 * %FALSE if the element did not have a bus. 895 * 896 * MT safe. 897 */ 898 public bool postMessage(Message message) 899 { 900 return gst_element_post_message(gstElement, (message is null) ? null : message.getMessageStruct()) != 0; 901 } 902 903 /** 904 * Get the clock provided by the given element. 905 * <note>An element is only required to provide a clock in the PAUSED 906 * state. Some elements can provide a clock in other states.</note> 907 * 908 * Return: the GstClock provided by the 909 * element or %NULL if no clock could be provided. Unref after usage. 910 * 911 * MT safe. 912 */ 913 public Clock provideClock() 914 { 915 auto p = gst_element_provide_clock(gstElement); 916 917 if(p is null) 918 { 919 return null; 920 } 921 922 return ObjectG.getDObject!(Clock)(cast(GstClock*) p, true); 923 } 924 925 /** 926 * Performs a query on the given element. 927 * 928 * For elements that don't implement a query handler, this function 929 * forwards the query to a random srcpad or to the peer of a 930 * random linked sinkpad of this element. 931 * 932 * Please note that some queries might need a running pipeline to work. 933 * 934 * Params: 935 * query = the #GstQuery. 936 * 937 * Return: %TRUE if the query could be performed. 938 * 939 * MT safe. 940 */ 941 public bool query(Query query) 942 { 943 return gst_element_query(gstElement, (query is null) ? null : query.getQueryStruct()) != 0; 944 } 945 946 /** 947 * Queries an element to convert @src_val in @src_format to @dest_format. 948 * 949 * Params: 950 * srcFormat = a #GstFormat to convert from. 951 * srcVal = a value to convert. 952 * destFormat = the #GstFormat to convert to. 953 * destVal = a pointer to the result. 954 * 955 * Return: %TRUE if the query could be performed. 956 */ 957 public bool queryConvert(GstFormat srcFormat, long srcVal, GstFormat destFormat, out long destVal) 958 { 959 return gst_element_query_convert(gstElement, srcFormat, srcVal, destFormat, &destVal) != 0; 960 } 961 962 /** 963 * Queries an element (usually top-level pipeline or playbin element) for the 964 * total stream duration in nanoseconds. This query will only work once the 965 * pipeline is prerolled (i.e. reached PAUSED or PLAYING state). The application 966 * will receive an ASYNC_DONE message on the pipeline bus when that is the case. 967 * 968 * If the duration changes for some reason, you will get a DURATION_CHANGED 969 * message on the pipeline bus, in which case you should re-query the duration 970 * using this function. 971 * 972 * Params: 973 * format = the #GstFormat requested 974 * duration = A location in which to store the total duration, or %NULL. 975 * 976 * Return: %TRUE if the query could be performed. 977 */ 978 public bool queryDuration(GstFormat format, out long duration) 979 { 980 return gst_element_query_duration(gstElement, format, &duration) != 0; 981 } 982 983 /** 984 * Queries an element (usually top-level pipeline or playbin element) for the 985 * stream position in nanoseconds. This will be a value between 0 and the 986 * stream duration (if the stream duration is known). This query will usually 987 * only work once the pipeline is prerolled (i.e. reached PAUSED or PLAYING 988 * state). The application will receive an ASYNC_DONE message on the pipeline 989 * bus when that is the case. 990 * 991 * If one repeatedly calls this function one can also create a query and reuse 992 * it in gst_element_query(). 993 * 994 * Params: 995 * format = the #GstFormat requested 996 * cur = a location in which to store the current 997 * position, or %NULL. 998 * 999 * Return: %TRUE if the query could be performed. 1000 */ 1001 public bool queryPosition(GstFormat format, out long cur) 1002 { 1003 return gst_element_query_position(gstElement, format, &cur) != 0; 1004 } 1005 1006 /** 1007 * Makes the element free the previously requested pad as obtained 1008 * with gst_element_request_pad(). 1009 * 1010 * This does not unref the pad. If the pad was created by using 1011 * gst_element_request_pad(), gst_element_release_request_pad() needs to be 1012 * followed by gst_object_unref() to free the @pad. 1013 * 1014 * MT safe. 1015 * 1016 * Params: 1017 * pad = the #GstPad to release. 1018 */ 1019 public void releaseRequestPad(Pad pad) 1020 { 1021 gst_element_release_request_pad(gstElement, (pad is null) ? null : pad.getPadStruct()); 1022 } 1023 1024 /** 1025 * Removes @pad from @element. @pad will be destroyed if it has not been 1026 * referenced elsewhere using gst_object_unparent(). 1027 * 1028 * This function is used by plugin developers and should not be used 1029 * by applications. Pads that were dynamically requested from elements 1030 * with gst_element_request_pad() should be released with the 1031 * gst_element_release_request_pad() function instead. 1032 * 1033 * Pads are not automatically deactivated so elements should perform the needed 1034 * steps to deactivate the pad in case this pad is removed in the PAUSED or 1035 * PLAYING state. See gst_pad_set_active() for more information about 1036 * deactivating pads. 1037 * 1038 * The pad and the element should be unlocked when calling this function. 1039 * 1040 * This function will emit the #GstElement::pad-removed signal on the element. 1041 * 1042 * Params: 1043 * pad = the #GstPad to remove from the element. 1044 * 1045 * Return: %TRUE if the pad could be removed. Can return %FALSE if the 1046 * pad does not belong to the provided element. 1047 * 1048 * MT safe. 1049 */ 1050 public bool removePad(Pad pad) 1051 { 1052 return gst_element_remove_pad(gstElement, (pad is null) ? null : pad.getPadStruct()) != 0; 1053 } 1054 1055 /** 1056 * Retrieves a request pad from the element according to the provided template. 1057 * Pad templates can be looked up using 1058 * gst_element_factory_get_static_pad_templates(). 1059 * 1060 * The pad should be released with gst_element_release_request_pad(). 1061 * 1062 * Params: 1063 * templ = a #GstPadTemplate of which we want a pad of. 1064 * name = the name of the request #GstPad 1065 * to retrieve. Can be %NULL. 1066 * caps = the caps of the pad we want to 1067 * request. Can be %NULL. 1068 * 1069 * Return: requested #GstPad if found, 1070 * otherwise %NULL. Release after usage. 1071 */ 1072 public Pad requestPad(PadTemplate templ, string name, Caps caps) 1073 { 1074 auto p = gst_element_request_pad(gstElement, (templ is null) ? null : templ.getPadTemplateStruct(), Str.toStringz(name), (caps is null) ? null : caps.getCapsStruct()); 1075 1076 if(p is null) 1077 { 1078 return null; 1079 } 1080 1081 return ObjectG.getDObject!(Pad)(cast(GstPad*) p, true); 1082 } 1083 1084 /** 1085 * Sends a seek event to an element. See gst_event_new_seek() for the details of 1086 * the parameters. The seek event is sent to the element using 1087 * gst_element_send_event(). 1088 * 1089 * MT safe. 1090 * 1091 * Params: 1092 * rate = The new playback rate 1093 * format = The format of the seek values 1094 * flags = The optional seek flags. 1095 * startType = The type and flags for the new start position 1096 * start = The value of the new start position 1097 * stopType = The type and flags for the new stop position 1098 * stop = The value of the new stop position 1099 * 1100 * Return: %TRUE if the event was handled. Flushing seeks will trigger a 1101 * preroll, which will emit %GST_MESSAGE_ASYNC_DONE. 1102 */ 1103 public bool seek(double rate, GstFormat format, GstSeekFlags flags, GstSeekType startType, long start, GstSeekType stopType, long stop) 1104 { 1105 return gst_element_seek(gstElement, rate, format, flags, startType, start, stopType, stop) != 0; 1106 } 1107 1108 /** 1109 * Simple API to perform a seek on the given element, meaning it just seeks 1110 * to the given position relative to the start of the stream. For more complex 1111 * operations like segment seeks (e.g. for looping) or changing the playback 1112 * rate or seeking relative to the last configured playback segment you should 1113 * use gst_element_seek(). 1114 * 1115 * In a completely prerolled PAUSED or PLAYING pipeline, seeking is always 1116 * guaranteed to return %TRUE on a seekable media type or %FALSE when the media 1117 * type is certainly not seekable (such as a live stream). 1118 * 1119 * Some elements allow for seeking in the READY state, in this 1120 * case they will store the seek event and execute it when they are put to 1121 * PAUSED. If the element supports seek in READY, it will always return %TRUE when 1122 * it receives the event in the READY state. 1123 * 1124 * Params: 1125 * format = a #GstFormat to execute the seek in, such as #GST_FORMAT_TIME 1126 * seekFlags = seek options; playback applications will usually want to use 1127 * GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT here 1128 * seekPos = position to seek to (relative to the start); if you are doing 1129 * a seek in #GST_FORMAT_TIME this value is in nanoseconds - 1130 * multiply with #GST_SECOND to convert seconds to nanoseconds or 1131 * with #GST_MSECOND to convert milliseconds to nanoseconds. 1132 * 1133 * Return: %TRUE if the seek operation succeeded. Flushing seeks will trigger a 1134 * preroll, which will emit %GST_MESSAGE_ASYNC_DONE. 1135 */ 1136 public bool seekSimple(GstFormat format, GstSeekFlags seekFlags, long seekPos) 1137 { 1138 return gst_element_seek_simple(gstElement, format, seekFlags, seekPos) != 0; 1139 } 1140 1141 /** 1142 * Sends an event to an element. If the element doesn't implement an 1143 * event handler, the event will be pushed on a random linked sink pad for 1144 * downstream events or a random linked source pad for upstream events. 1145 * 1146 * This function takes ownership of the provided event so you should 1147 * gst_event_ref() it if you want to reuse the event after this call. 1148 * 1149 * MT safe. 1150 * 1151 * Params: 1152 * event = the #GstEvent to send to the element. 1153 * 1154 * Return: %TRUE if the event was handled. Events that trigger a preroll (such 1155 * as flushing seeks and steps) will emit %GST_MESSAGE_ASYNC_DONE. 1156 */ 1157 public bool sendEvent(Event event) 1158 { 1159 return gst_element_send_event(gstElement, (event is null) ? null : event.getEventStruct()) != 0; 1160 } 1161 1162 /** 1163 * Set the base time of an element. See gst_element_get_base_time(). 1164 * 1165 * MT safe. 1166 * 1167 * Params: 1168 * time = the base time to set. 1169 */ 1170 public void setBaseTime(GstClockTime time) 1171 { 1172 gst_element_set_base_time(gstElement, time); 1173 } 1174 1175 /** 1176 * Sets the bus of the element. Increases the refcount on the bus. 1177 * For internal use only, unless you're testing elements. 1178 * 1179 * MT safe. 1180 * 1181 * Params: 1182 * bus = the #GstBus to set. 1183 */ 1184 public void setBus(Bus bus) 1185 { 1186 gst_element_set_bus(gstElement, (bus is null) ? null : bus.getBusStruct()); 1187 } 1188 1189 /** 1190 * Sets the clock for the element. This function increases the 1191 * refcount on the clock. Any previously set clock on the object 1192 * is unreffed. 1193 * 1194 * Params: 1195 * clock = the #GstClock to set for the element. 1196 * 1197 * Return: %TRUE if the element accepted the clock. An element can refuse a 1198 * clock when it, for example, is not able to slave its internal clock to the 1199 * @clock or when it requires a specific clock to operate. 1200 * 1201 * MT safe. 1202 */ 1203 public bool setClock(Clock clock) 1204 { 1205 return gst_element_set_clock(gstElement, (clock is null) ? null : clock.getClockStruct()) != 0; 1206 } 1207 1208 /** 1209 * Sets the context of the element. Increases the refcount of the context. 1210 * 1211 * MT safe. 1212 * 1213 * Params: 1214 * context = the #GstContext to set. 1215 */ 1216 public void setContext(Context context) 1217 { 1218 gst_element_set_context(gstElement, (context is null) ? null : context.getContextStruct()); 1219 } 1220 1221 /** 1222 * Locks the state of an element, so state changes of the parent don't affect 1223 * this element anymore. 1224 * 1225 * MT safe. 1226 * 1227 * Params: 1228 * lockedState = %TRUE to lock the element's state 1229 * 1230 * Return: %TRUE if the state was changed, %FALSE if bad parameters were given 1231 * or the elements state-locking needed no change. 1232 */ 1233 public bool setLockedState(bool lockedState) 1234 { 1235 return gst_element_set_locked_state(gstElement, lockedState) != 0; 1236 } 1237 1238 /** 1239 * Set the start time of an element. The start time of the element is the 1240 * running time of the element when it last went to the PAUSED state. In READY 1241 * or after a flushing seek, it is set to 0. 1242 * 1243 * Toplevel elements like #GstPipeline will manage the start_time and 1244 * base_time on its children. Setting the start_time to #GST_CLOCK_TIME_NONE 1245 * on such a toplevel element will disable the distribution of the base_time to 1246 * the children and can be useful if the application manages the base_time 1247 * itself, for example if you want to synchronize capture from multiple 1248 * pipelines, and you can also ensure that the pipelines have the same clock. 1249 * 1250 * MT safe. 1251 * 1252 * Params: 1253 * time = the base time to set. 1254 */ 1255 public void setStartTime(GstClockTime time) 1256 { 1257 gst_element_set_start_time(gstElement, time); 1258 } 1259 1260 /** 1261 * Sets the state of the element. This function will try to set the 1262 * requested state by going through all the intermediary states and calling 1263 * the class's state change function for each. 1264 * 1265 * This function can return #GST_STATE_CHANGE_ASYNC, in which case the 1266 * element will perform the remainder of the state change asynchronously in 1267 * another thread. 1268 * An application can use gst_element_get_state() to wait for the completion 1269 * of the state change or it can wait for a %GST_MESSAGE_ASYNC_DONE or 1270 * %GST_MESSAGE_STATE_CHANGED on the bus. 1271 * 1272 * State changes to %GST_STATE_READY or %GST_STATE_NULL never return 1273 * #GST_STATE_CHANGE_ASYNC. 1274 * 1275 * Params: 1276 * state = the element's new #GstState. 1277 * 1278 * Return: Result of the state change using #GstStateChangeReturn. 1279 * 1280 * MT safe. 1281 */ 1282 public GstStateChangeReturn setState(GstState state) 1283 { 1284 return gst_element_set_state(gstElement, state); 1285 } 1286 1287 /** 1288 * Tries to change the state of the element to the same as its parent. 1289 * If this function returns %FALSE, the state of element is undefined. 1290 * 1291 * Return: %TRUE, if the element's state could be synced to the parent's state. 1292 * 1293 * MT safe. 1294 */ 1295 public bool syncStateWithParent() 1296 { 1297 return gst_element_sync_state_with_parent(gstElement) != 0; 1298 } 1299 1300 /** 1301 * Unlinks all source pads of the source element with all sink pads 1302 * of the sink element to which they are linked. 1303 * 1304 * If the link has been made using gst_element_link(), it could have created an 1305 * requestpad, which has to be released using gst_element_release_request_pad(). 1306 * 1307 * Params: 1308 * dest = the sink #GstElement to unlink. 1309 */ 1310 public void unlink(Element dest) 1311 { 1312 gst_element_unlink(gstElement, (dest is null) ? null : dest.getElementStruct()); 1313 } 1314 1315 /** 1316 * Unlinks the two named pads of the source and destination elements. 1317 * 1318 * This is a convenience function for gst_pad_unlink(). 1319 * 1320 * Params: 1321 * srcpadname = the name of the #GstPad in source element. 1322 * dest = a #GstElement containing the destination pad. 1323 * destpadname = the name of the #GstPad in destination element. 1324 */ 1325 public void unlinkPads(string srcpadname, Element dest, string destpadname) 1326 { 1327 gst_element_unlink_pads(gstElement, Str.toStringz(srcpadname), (dest is null) ? null : dest.getElementStruct(), Str.toStringz(destpadname)); 1328 } 1329 1330 int[string] connectedSignals; 1331 1332 void delegate(Element)[] onNoMorePadsListeners; 1333 /** 1334 * This signals that the element will not generate more dynamic pads. 1335 * Note that this signal will usually be emitted from the context of 1336 * the streaming thread. 1337 */ 1338 void addOnNoMorePads(void delegate(Element) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1339 { 1340 if ( "no-more-pads" !in connectedSignals ) 1341 { 1342 Signals.connectData( 1343 this, 1344 "no-more-pads", 1345 cast(GCallback)&callBackNoMorePads, 1346 cast(void*)this, 1347 null, 1348 connectFlags); 1349 connectedSignals["no-more-pads"] = 1; 1350 } 1351 onNoMorePadsListeners ~= dlg; 1352 } 1353 extern(C) static void callBackNoMorePads(GstElement* elementStruct, Element _element) 1354 { 1355 foreach ( void delegate(Element) dlg; _element.onNoMorePadsListeners ) 1356 { 1357 dlg(_element); 1358 } 1359 } 1360 1361 void delegate(Pad, Element)[] onPadAddedListeners; 1362 /** 1363 * a new #GstPad has been added to the element. Note that this signal will 1364 * usually be emitted from the context of the streaming thread. Also keep in 1365 * mind that if you add new elements to the pipeline in the signal handler 1366 * you will need to set them to the desired target state with 1367 * gst_element_set_state() or gst_element_sync_state_with_parent(). 1368 * 1369 * Params: 1370 * newPad = the pad that has been added 1371 */ 1372 void addOnPadAdded(void delegate(Pad, Element) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1373 { 1374 if ( "pad-added" !in connectedSignals ) 1375 { 1376 Signals.connectData( 1377 this, 1378 "pad-added", 1379 cast(GCallback)&callBackPadAdded, 1380 cast(void*)this, 1381 null, 1382 connectFlags); 1383 connectedSignals["pad-added"] = 1; 1384 } 1385 onPadAddedListeners ~= dlg; 1386 } 1387 extern(C) static void callBackPadAdded(GstElement* elementStruct, GstPad* newPad, Element _element) 1388 { 1389 foreach ( void delegate(Pad, Element) dlg; _element.onPadAddedListeners ) 1390 { 1391 dlg(ObjectG.getDObject!(Pad)(newPad), _element); 1392 } 1393 } 1394 1395 void delegate(Pad, Element)[] onPadRemovedListeners; 1396 /** 1397 * a #GstPad has been removed from the element 1398 * 1399 * Params: 1400 * oldPad = the pad that has been removed 1401 */ 1402 void addOnPadRemoved(void delegate(Pad, Element) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 1403 { 1404 if ( "pad-removed" !in connectedSignals ) 1405 { 1406 Signals.connectData( 1407 this, 1408 "pad-removed", 1409 cast(GCallback)&callBackPadRemoved, 1410 cast(void*)this, 1411 null, 1412 connectFlags); 1413 connectedSignals["pad-removed"] = 1; 1414 } 1415 onPadRemovedListeners ~= dlg; 1416 } 1417 extern(C) static void callBackPadRemoved(GstElement* elementStruct, GstPad* oldPad, Element _element) 1418 { 1419 foreach ( void delegate(Pad, Element) dlg; _element.onPadRemovedListeners ) 1420 { 1421 dlg(ObjectG.getDObject!(Pad)(oldPad), _element); 1422 } 1423 } 1424 }