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 gst.base.BaseSrc; 26 27 private import glib.MemorySlice; 28 private import gobject.ObjectG; 29 private import gst.base.c.functions; 30 public import gst.base.c.types; 31 private import gstreamer.AllocationParams; 32 private import gstreamer.Allocator; 33 private import gstreamer.BufferList; 34 private import gstreamer.BufferPool; 35 private import gstreamer.Caps; 36 private import gstreamer.Element; 37 private import gstreamer.Segment; 38 39 40 /** 41 * This is a generic base class for source elements. The following 42 * types of sources are supported: 43 * 44 * * random access sources like files 45 * * seekable sources 46 * * live sources 47 * 48 * The source can be configured to operate in any #GstFormat with the 49 * gst_base_src_set_format() method. The currently set format determines 50 * the format of the internal #GstSegment and any %GST_EVENT_SEGMENT 51 * events. The default format for #GstBaseSrc is %GST_FORMAT_BYTES. 52 * 53 * #GstBaseSrc always supports push mode scheduling. If the following 54 * conditions are met, it also supports pull mode scheduling: 55 * 56 * * The format is set to %GST_FORMAT_BYTES (default). 57 * * #GstBaseSrcClass.is_seekable() returns %TRUE. 58 * 59 * If all the conditions are met for operating in pull mode, #GstBaseSrc is 60 * automatically seekable in push mode as well. The following conditions must 61 * be met to make the element seekable in push mode when the format is not 62 * %GST_FORMAT_BYTES: 63 * 64 * * #GstBaseSrcClass.is_seekable() returns %TRUE. 65 * * #GstBaseSrcClass.query() can convert all supported seek formats to the 66 * internal format as set with gst_base_src_set_format(). 67 * * #GstBaseSrcClass.do_seek() is implemented, performs the seek and returns 68 * %TRUE. 69 * 70 * When the element does not meet the requirements to operate in pull mode, the 71 * offset and length in the #GstBaseSrcClass.create() method should be ignored. 72 * It is recommended to subclass #GstPushSrc instead, in this situation. If the 73 * element can operate in pull mode but only with specific offsets and 74 * lengths, it is allowed to generate an error when the wrong values are passed 75 * to the #GstBaseSrcClass.create() function. 76 * 77 * #GstBaseSrc has support for live sources. Live sources are sources that when 78 * paused discard data, such as audio or video capture devices. A typical live 79 * source also produces data at a fixed rate and thus provides a clock to publish 80 * this rate. 81 * Use gst_base_src_set_live() to activate the live source mode. 82 * 83 * A live source does not produce data in the PAUSED state. This means that the 84 * #GstBaseSrcClass.create() method will not be called in PAUSED but only in 85 * PLAYING. To signal the pipeline that the element will not produce data, the 86 * return value from the READY to PAUSED state will be 87 * %GST_STATE_CHANGE_NO_PREROLL. 88 * 89 * A typical live source will timestamp the buffers it creates with the 90 * current running time of the pipeline. This is one reason why a live source 91 * can only produce data in the PLAYING state, when the clock is actually 92 * distributed and running. 93 * 94 * Live sources that synchronize and block on the clock (an audio source, for 95 * example) can use gst_base_src_wait_playing() when the 96 * #GstBaseSrcClass.create() function was interrupted by a state change to 97 * PAUSED. 98 * 99 * The #GstBaseSrcClass.get_times() method can be used to implement pseudo-live 100 * sources. It only makes sense to implement the #GstBaseSrcClass.get_times() 101 * function if the source is a live source. The #GstBaseSrcClass.get_times() 102 * function should return timestamps starting from 0, as if it were a non-live 103 * source. The base class will make sure that the timestamps are transformed 104 * into the current running_time. The base source will then wait for the 105 * calculated running_time before pushing out the buffer. 106 * 107 * For live sources, the base class will by default report a latency of 0. 108 * For pseudo live sources, the base class will by default measure the difference 109 * between the first buffer timestamp and the start time of get_times and will 110 * report this value as the latency. 111 * Subclasses should override the query function when this behaviour is not 112 * acceptable. 113 * 114 * There is only support in #GstBaseSrc for exactly one source pad, which 115 * should be named "src". A source implementation (subclass of #GstBaseSrc) 116 * should install a pad template in its class_init function, like so: 117 * |[<!-- language="C" --> 118 * static void 119 * my_element_class_init (GstMyElementClass *klass) 120 * { 121 * GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); 122 * // srctemplate should be a #GstStaticPadTemplate with direction 123 * // %GST_PAD_SRC and name "src" 124 * gst_element_class_add_static_pad_template (gstelement_class, &srctemplate); 125 * 126 * gst_element_class_set_static_metadata (gstelement_class, 127 * "Source name", 128 * "Source", 129 * "My Source element", 130 * "The author <my.sink@my.email>"); 131 * } 132 * ]| 133 * 134 * ## Controlled shutdown of live sources in applications 135 * 136 * Applications that record from a live source may want to stop recording 137 * in a controlled way, so that the recording is stopped, but the data 138 * already in the pipeline is processed to the end (remember that many live 139 * sources would go on recording forever otherwise). For that to happen the 140 * application needs to make the source stop recording and send an EOS 141 * event down the pipeline. The application would then wait for an 142 * EOS message posted on the pipeline's bus to know when all data has 143 * been processed and the pipeline can safely be stopped. 144 * 145 * An application may send an EOS event to a source element to make it 146 * perform the EOS logic (send EOS event downstream or post a 147 * %GST_MESSAGE_SEGMENT_DONE on the bus). This can typically be done 148 * with the gst_element_send_event() function on the element or its parent bin. 149 * 150 * After the EOS has been sent to the element, the application should wait for 151 * an EOS message to be posted on the pipeline's bus. Once this EOS message is 152 * received, it may safely shut down the entire pipeline. 153 */ 154 public class BaseSrc : Element 155 { 156 /** the main Gtk struct */ 157 protected GstBaseSrc* gstBaseSrc; 158 159 /** Get the main Gtk struct */ 160 public GstBaseSrc* getBaseSrcStruct(bool transferOwnership = false) 161 { 162 if (transferOwnership) 163 ownedRef = false; 164 return gstBaseSrc; 165 } 166 167 /** the main Gtk struct as a void* */ 168 protected override void* getStruct() 169 { 170 return cast(void*)gstBaseSrc; 171 } 172 173 /** 174 * Sets our main struct and passes it to the parent class. 175 */ 176 public this (GstBaseSrc* gstBaseSrc, bool ownedRef = false) 177 { 178 this.gstBaseSrc = gstBaseSrc; 179 super(cast(GstElement*)gstBaseSrc, ownedRef); 180 } 181 182 183 /** */ 184 public static GType getType() 185 { 186 return gst_base_src_get_type(); 187 } 188 189 /** 190 * Lets #GstBaseSrc sub-classes to know the memory @allocator 191 * used by the base class and its @params. 192 * 193 * Unref the @allocator after usage. 194 * 195 * Params: 196 * allocator = the #GstAllocator 197 * used 198 * params = the #GstAllocationParams of @allocator 199 */ 200 public void getAllocator(out Allocator allocator, out AllocationParams params) 201 { 202 GstAllocator* outallocator = null; 203 GstAllocationParams* outparams = sliceNew!GstAllocationParams(); 204 205 gst_base_src_get_allocator(gstBaseSrc, &outallocator, outparams); 206 207 allocator = ObjectG.getDObject!(Allocator)(outallocator); 208 params = ObjectG.getDObject!(AllocationParams)(outparams, true); 209 } 210 211 /** 212 * Get the number of bytes that @src will push out with each buffer. 213 * 214 * Returns: the number of bytes pushed with each buffer. 215 */ 216 public uint getBlocksize() 217 { 218 return gst_base_src_get_blocksize(gstBaseSrc); 219 } 220 221 /** 222 * Returns: the instance of the #GstBufferPool used 223 * by the src; unref it after usage. 224 */ 225 public BufferPool getBufferPool() 226 { 227 auto __p = gst_base_src_get_buffer_pool(gstBaseSrc); 228 229 if(__p is null) 230 { 231 return null; 232 } 233 234 return ObjectG.getDObject!(BufferPool)(cast(GstBufferPool*) __p, true); 235 } 236 237 /** 238 * Query if @src timestamps outgoing buffers based on the current running_time. 239 * 240 * Returns: %TRUE if the base class will automatically timestamp outgoing buffers. 241 */ 242 public bool getDoTimestamp() 243 { 244 return gst_base_src_get_do_timestamp(gstBaseSrc) != 0; 245 } 246 247 /** 248 * Get the current async behaviour of @src. See also gst_base_src_set_async(). 249 * 250 * Returns: %TRUE if @src is operating in async mode. 251 */ 252 public bool isAsync() 253 { 254 return gst_base_src_is_async(gstBaseSrc) != 0; 255 } 256 257 /** 258 * Check if an element is in live mode. 259 * 260 * Returns: %TRUE if element is in live mode. 261 */ 262 public bool isLive() 263 { 264 return gst_base_src_is_live(gstBaseSrc) != 0; 265 } 266 267 /** 268 * Negotiates src pad caps with downstream elements. 269 * Unmarks GST_PAD_FLAG_NEED_RECONFIGURE in any case. But marks it again 270 * if #GstBaseSrcClass.negotiate() fails. 271 * 272 * Do not call this in the #GstBaseSrcClass.fill() vmethod. Call this in 273 * #GstBaseSrcClass.create() or in #GstBaseSrcClass.alloc(), _before_ any 274 * buffer is allocated. 275 * 276 * Returns: %TRUE if the negotiation succeeded, else %FALSE. 277 * 278 * Since: 1.18 279 */ 280 public bool negotiate() 281 { 282 return gst_base_src_negotiate(gstBaseSrc) != 0; 283 } 284 285 /** 286 * Prepare a new seamless segment for emission downstream. This function must 287 * only be called by derived sub-classes, and only from the #GstBaseSrcClass::create function, 288 * as the stream-lock needs to be held. 289 * 290 * The format for the new segment will be the current format of the source, as 291 * configured with gst_base_src_set_format() 292 * 293 * Deprecated: Use gst_base_src_new_segment() 294 * 295 * Params: 296 * start = The new start value for the segment 297 * stop = Stop value for the new segment 298 * time = The new time value for the start of the new segment 299 * 300 * Returns: %TRUE if preparation of the seamless segment succeeded. 301 */ 302 public bool newSeamlessSegment(long start, long stop, long time) 303 { 304 return gst_base_src_new_seamless_segment(gstBaseSrc, start, stop, time) != 0; 305 } 306 307 /** 308 * Prepare a new segment for emission downstream. This function must 309 * only be called by derived sub-classes, and only from the #GstBaseSrcClass::create function, 310 * as the stream-lock needs to be held. 311 * 312 * The format for the @segment must be identical with the current format 313 * of the source, as configured with gst_base_src_set_format(). 314 * 315 * The format of @src must not be %GST_FORMAT_UNDEFINED and the format 316 * should be configured via gst_base_src_set_format() before calling this method. 317 * 318 * Params: 319 * segment = a pointer to a #GstSegment 320 * 321 * Returns: %TRUE if preparation of new segment succeeded. 322 * 323 * Since: 1.18 324 */ 325 public bool newSegment(Segment segment) 326 { 327 return gst_base_src_new_segment(gstBaseSrc, (segment is null) ? null : segment.getSegmentStruct()) != 0; 328 } 329 330 /** 331 * Query the source for the latency parameters. @live will be %TRUE when @src is 332 * configured as a live source. @min_latency and @max_latency will be set 333 * to the difference between the running time and the timestamp of the first 334 * buffer. 335 * 336 * This function is mostly used by subclasses. 337 * 338 * Params: 339 * live = if the source is live 340 * minLatency = the min latency of the source 341 * maxLatency = the max latency of the source 342 * 343 * Returns: %TRUE if the query succeeded. 344 */ 345 public bool queryLatency(out bool live, out GstClockTime minLatency, out GstClockTime maxLatency) 346 { 347 int outlive; 348 349 auto __p = gst_base_src_query_latency(gstBaseSrc, &outlive, &minLatency, &maxLatency) != 0; 350 351 live = (outlive == 1); 352 353 return __p; 354 } 355 356 /** 357 * Configure async behaviour in @src, no state change will block. The open, 358 * close, start, stop, play and pause virtual methods will be executed in a 359 * different thread and are thus allowed to perform blocking operations. Any 360 * blocking operation should be unblocked with the unlock vmethod. 361 * 362 * Params: 363 * async = new async mode 364 */ 365 public void setAsync(bool async) 366 { 367 gst_base_src_set_async(gstBaseSrc, async); 368 } 369 370 /** 371 * If @automatic_eos is %TRUE, @src will automatically go EOS if a buffer 372 * after the total size is returned. By default this is %TRUE but sources 373 * that can't return an authoritative size and only know that they're EOS 374 * when trying to read more should set this to %FALSE. 375 * 376 * When @src operates in %GST_FORMAT_TIME, #GstBaseSrc will send an EOS 377 * when a buffer outside of the currently configured segment is pushed if 378 * @automatic_eos is %TRUE. Since 1.16, if @automatic_eos is %FALSE an 379 * EOS will be pushed only when the #GstBaseSrcClass.create() implementation 380 * returns %GST_FLOW_EOS. 381 * 382 * Params: 383 * automaticEos = automatic eos 384 * 385 * Since: 1.4 386 */ 387 public void setAutomaticEos(bool automaticEos) 388 { 389 gst_base_src_set_automatic_eos(gstBaseSrc, automaticEos); 390 } 391 392 /** 393 * Set the number of bytes that @src will push out with each buffer. When 394 * @blocksize is set to -1, a default length will be used. 395 * 396 * Params: 397 * blocksize = the new blocksize in bytes 398 */ 399 public void setBlocksize(uint blocksize) 400 { 401 gst_base_src_set_blocksize(gstBaseSrc, blocksize); 402 } 403 404 /** 405 * Set new caps on the basesrc source pad. 406 * 407 * Params: 408 * caps = a #GstCaps 409 * 410 * Returns: %TRUE if the caps could be set 411 */ 412 public bool setCaps(Caps caps) 413 { 414 return gst_base_src_set_caps(gstBaseSrc, (caps is null) ? null : caps.getCapsStruct()) != 0; 415 } 416 417 /** 418 * Configure @src to automatically timestamp outgoing buffers based on the 419 * current running_time of the pipeline. This property is mostly useful for live 420 * sources. 421 * 422 * Params: 423 * timestamp = enable or disable timestamping 424 */ 425 public void setDoTimestamp(bool timestamp) 426 { 427 gst_base_src_set_do_timestamp(gstBaseSrc, timestamp); 428 } 429 430 /** 431 * If not @dynamic, size is only updated when needed, such as when trying to 432 * read past current tracked size. Otherwise, size is checked for upon each 433 * read. 434 * 435 * Params: 436 * dynamic = new dynamic size mode 437 */ 438 public void setDynamicSize(bool dynamic) 439 { 440 gst_base_src_set_dynamic_size(gstBaseSrc, dynamic); 441 } 442 443 /** 444 * Sets the default format of the source. This will be the format used 445 * for sending SEGMENT events and for performing seeks. 446 * 447 * If a format of GST_FORMAT_BYTES is set, the element will be able to 448 * operate in pull mode if the #GstBaseSrcClass.is_seekable() returns %TRUE. 449 * 450 * This function must only be called in states < %GST_STATE_PAUSED. 451 * 452 * Params: 453 * format = the format to use 454 */ 455 public void setFormat(GstFormat format) 456 { 457 gst_base_src_set_format(gstBaseSrc, format); 458 } 459 460 /** 461 * If the element listens to a live source, @live should 462 * be set to %TRUE. 463 * 464 * A live source will not produce data in the PAUSED state and 465 * will therefore not be able to participate in the PREROLL phase 466 * of a pipeline. To signal this fact to the application and the 467 * pipeline, the state change return value of the live source will 468 * be GST_STATE_CHANGE_NO_PREROLL. 469 * 470 * Params: 471 * live = new live-mode 472 */ 473 public void setLive(bool live) 474 { 475 gst_base_src_set_live(gstBaseSrc, live); 476 } 477 478 /** 479 * Complete an asynchronous start operation. When the subclass overrides the 480 * start method, it should call gst_base_src_start_complete() when the start 481 * operation completes either from the same thread or from an asynchronous 482 * helper thread. 483 * 484 * Params: 485 * ret = a #GstFlowReturn 486 */ 487 public void startComplete(GstFlowReturn ret) 488 { 489 gst_base_src_start_complete(gstBaseSrc, ret); 490 } 491 492 /** 493 * Wait until the start operation completes. 494 * 495 * Returns: a #GstFlowReturn. 496 */ 497 public GstFlowReturn startWait() 498 { 499 return gst_base_src_start_wait(gstBaseSrc); 500 } 501 502 /** 503 * Subclasses can call this from their create virtual method implementation 504 * to submit a buffer list to be pushed out later. This is useful in 505 * cases where the create function wants to produce multiple buffers to be 506 * pushed out in one go in form of a #GstBufferList, which can reduce overhead 507 * drastically, especially for packetised inputs (for data streams where 508 * the packetisation/chunking is not important it is usually more efficient 509 * to return larger buffers instead). 510 * 511 * Subclasses that use this function from their create function must return 512 * %GST_FLOW_OK and no buffer from their create virtual method implementation. 513 * If a buffer is returned after a buffer list has also been submitted via this 514 * function the behaviour is undefined. 515 * 516 * Subclasses must only call this function once per create function call and 517 * subclasses must only call this function when the source operates in push 518 * mode. 519 * 520 * Params: 521 * bufferList = a #GstBufferList 522 * 523 * Since: 1.14 524 */ 525 public void submitBufferList(BufferList bufferList) 526 { 527 gst_base_src_submit_buffer_list(gstBaseSrc, (bufferList is null) ? null : bufferList.getBufferListStruct()); 528 } 529 530 /** 531 * If the #GstBaseSrcClass.create() method performs its own synchronisation 532 * against the clock it must unblock when going from PLAYING to the PAUSED state 533 * and call this method before continuing to produce the remaining data. 534 * 535 * This function will block until a state change to PLAYING happens (in which 536 * case this function returns %GST_FLOW_OK) or the processing must be stopped due 537 * to a state change to READY or a FLUSH event (in which case this function 538 * returns %GST_FLOW_FLUSHING). 539 * 540 * Returns: %GST_FLOW_OK if @src is PLAYING and processing can 541 * continue. Any other return value should be returned from the create vmethod. 542 */ 543 public GstFlowReturn waitPlaying() 544 { 545 return gst_base_src_wait_playing(gstBaseSrc); 546 } 547 }