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.Buffer; 26 27 private import glib.Bytes; 28 private import glib.ConstructionException; 29 private import gobject.ObjectG; 30 private import gstreamer.AllocationParams; 31 private import gstreamer.Allocator; 32 private import gstreamer.Caps; 33 private import gstreamer.Memory; 34 private import gstreamer.Meta; 35 private import gstreamer.ProtectionMeta; 36 private import gstreamer.Structure; 37 private import gstreamer.c.functions; 38 public import gstreamer.c.types; 39 public import gstreamerc.gstreamertypes; 40 41 42 /** 43 * Buffers are the basic unit of data transfer in GStreamer. They contain the 44 * timing and offset along with other arbitrary metadata that is associated 45 * with the #GstMemory blocks that the buffer contains. 46 * 47 * Buffers are usually created with gst_buffer_new(). After a buffer has been 48 * created one will typically allocate memory for it and add it to the buffer. 49 * The following example creates a buffer that can hold a given video frame 50 * with a given width, height and bits per plane. 51 * |[<!-- language="C" --> 52 * GstBuffer *buffer; 53 * GstMemory *memory; 54 * gint size, width, height, bpp; 55 * ... 56 * size = width * height * bpp; 57 * buffer = gst_buffer_new (); 58 * memory = gst_allocator_alloc (NULL, size, NULL); 59 * gst_buffer_insert_memory (buffer, -1, memory); 60 * ... 61 * ]| 62 * 63 * Alternatively, use gst_buffer_new_allocate() to create a buffer with 64 * preallocated data of a given size. 65 * 66 * Buffers can contain a list of #GstMemory objects. You can retrieve how many 67 * memory objects with gst_buffer_n_memory() and you can get a pointer 68 * to memory with gst_buffer_peek_memory() 69 * 70 * A buffer will usually have timestamps, and a duration, but neither of these 71 * are guaranteed (they may be set to #GST_CLOCK_TIME_NONE). Whenever a 72 * meaningful value can be given for these, they should be set. The timestamps 73 * and duration are measured in nanoseconds (they are #GstClockTime values). 74 * 75 * The buffer DTS refers to the timestamp when the buffer should be decoded and 76 * is usually monotonically increasing. The buffer PTS refers to the timestamp when 77 * the buffer content should be presented to the user and is not always 78 * monotonically increasing. 79 * 80 * A buffer can also have one or both of a start and an end offset. These are 81 * media-type specific. For video buffers, the start offset will generally be 82 * the frame number. For audio buffers, it will be the number of samples 83 * produced so far. For compressed data, it could be the byte offset in a 84 * source or destination file. Likewise, the end offset will be the offset of 85 * the end of the buffer. These can only be meaningfully interpreted if you 86 * know the media type of the buffer (the preceding CAPS event). Either or both 87 * can be set to #GST_BUFFER_OFFSET_NONE. 88 * 89 * gst_buffer_ref() is used to increase the refcount of a buffer. This must be 90 * done when you want to keep a handle to the buffer after pushing it to the 91 * next element. The buffer refcount determines the writability of the buffer, a 92 * buffer is only writable when the refcount is exactly 1, i.e. when the caller 93 * has the only reference to the buffer. 94 * 95 * To efficiently create a smaller buffer out of an existing one, you can 96 * use gst_buffer_copy_region(). This method tries to share the memory objects 97 * between the two buffers. 98 * 99 * If a plug-in wants to modify the buffer data or metadata in-place, it should 100 * first obtain a buffer that is safe to modify by using 101 * gst_buffer_make_writable(). This function is optimized so that a copy will 102 * only be made when it is necessary. 103 * 104 * Several flags of the buffer can be set and unset with the 105 * GST_BUFFER_FLAG_SET() and GST_BUFFER_FLAG_UNSET() macros. Use 106 * GST_BUFFER_FLAG_IS_SET() to test if a certain #GstBufferFlags flag is set. 107 * 108 * Buffers can be efficiently merged into a larger buffer with 109 * gst_buffer_append(). Copying of memory will only be done when absolutely 110 * needed. 111 * 112 * Arbitrary extra metadata can be set on a buffer with gst_buffer_add_meta(). 113 * Metadata can be retrieved with gst_buffer_get_meta(). See also #GstMeta 114 * 115 * An element should either unref the buffer or push it out on a src pad 116 * using gst_pad_push() (see #GstPad). 117 * 118 * Buffers are usually freed by unreffing them with gst_buffer_unref(). When 119 * the refcount drops to 0, any memory and metadata pointed to by the buffer is 120 * unreffed as well. Buffers allocated from a #GstBufferPool will be returned to 121 * the pool when the refcount drops to 0. 122 * 123 * The #GstParentBufferMeta is a meta which can be attached to a #GstBuffer 124 * to hold a reference to another buffer that is only released when the child 125 * #GstBuffer is released. 126 * 127 * Typically, #GstParentBufferMeta is used when the child buffer is directly 128 * using the #GstMemory of the parent buffer, and wants to prevent the parent 129 * buffer from being returned to a buffer pool until the #GstMemory is available 130 * for re-use. (Since 1.6) 131 */ 132 public class Buffer 133 { 134 /** the main Gtk struct */ 135 protected GstBuffer* gstBuffer; 136 protected bool ownedRef; 137 138 /** Get the main Gtk struct */ 139 public GstBuffer* getBufferStruct(bool transferOwnership = false) 140 { 141 if (transferOwnership) 142 ownedRef = false; 143 return gstBuffer; 144 } 145 146 /** the main Gtk struct as a void* */ 147 protected void* getStruct() 148 { 149 return cast(void*)gstBuffer; 150 } 151 152 /** 153 * Sets our main struct and passes it to the parent class. 154 */ 155 public this (GstBuffer* gstBuffer, bool ownedRef = false) 156 { 157 this.gstBuffer = gstBuffer; 158 this.ownedRef = ownedRef; 159 } 160 161 162 /** */ 163 public static GType getType() 164 { 165 return gst_buffer_get_type(); 166 } 167 168 /** 169 * Creates a newly allocated buffer without any data. 170 * 171 * MT safe. 172 * 173 * Returns: the new #GstBuffer. 174 * 175 * Throws: ConstructionException GTK+ fails to create the object. 176 */ 177 public this() 178 { 179 auto p = gst_buffer_new(); 180 181 if(p is null) 182 { 183 throw new ConstructionException("null returned by new"); 184 } 185 186 this(cast(GstBuffer*) p); 187 } 188 189 /** 190 * Tries to create a newly allocated buffer with data of the given size and 191 * extra parameters from @allocator. If the requested amount of memory can't be 192 * allocated, %NULL will be returned. The allocated buffer memory is not cleared. 193 * 194 * When @allocator is %NULL, the default memory allocator will be used. 195 * 196 * Note that when @size == 0, the buffer will not have memory associated with it. 197 * 198 * MT safe. 199 * 200 * Params: 201 * allocator = the #GstAllocator to use, or %NULL to use the 202 * default allocator 203 * size = the size in bytes of the new buffer's data. 204 * params = optional parameters 205 * 206 * Returns: a new #GstBuffer, or %NULL if 207 * the memory couldn't be allocated. 208 * 209 * Throws: ConstructionException GTK+ fails to create the object. 210 */ 211 public this(Allocator allocator, size_t size, AllocationParams params) 212 { 213 auto p = gst_buffer_new_allocate((allocator is null) ? null : allocator.getAllocatorStruct(), size, (params is null) ? null : params.getAllocationParamsStruct()); 214 215 if(p is null) 216 { 217 throw new ConstructionException("null returned by new_allocate"); 218 } 219 220 this(cast(GstBuffer*) p); 221 } 222 223 /** 224 * Creates a new buffer that wraps the given @data. The memory will be freed 225 * with g_free and will be marked writable. 226 * 227 * MT safe. 228 * 229 * Params: 230 * data = data to wrap 231 * 232 * Returns: a new #GstBuffer 233 * 234 * Throws: ConstructionException GTK+ fails to create the object. 235 */ 236 public this(ubyte[] data) 237 { 238 auto p = gst_buffer_new_wrapped(data.ptr, cast(size_t)data.length); 239 240 if(p is null) 241 { 242 throw new ConstructionException("null returned by new_wrapped"); 243 } 244 245 this(cast(GstBuffer*) p); 246 } 247 248 /** 249 * Creates a new #GstBuffer that wraps the given @bytes. The data inside 250 * @bytes cannot be %NULL and the resulting buffer will be marked as read only. 251 * 252 * MT safe. 253 * 254 * Params: 255 * bytes = a #GBytes to wrap 256 * 257 * Returns: a new #GstBuffer wrapping @bytes 258 * 259 * Since: 1.16 260 * 261 * Throws: ConstructionException GTK+ fails to create the object. 262 */ 263 public this(Bytes bytes) 264 { 265 auto p = gst_buffer_new_wrapped_bytes((bytes is null) ? null : bytes.getBytesStruct()); 266 267 if(p is null) 268 { 269 throw new ConstructionException("null returned by new_wrapped_bytes"); 270 } 271 272 this(cast(GstBuffer*) p); 273 } 274 275 /** 276 * Allocate a new buffer that wraps the given memory. @data must point to 277 * @maxsize of memory, the wrapped buffer will have the region from @offset and 278 * @size visible. 279 * 280 * When the buffer is destroyed, @notify will be called with @user_data. 281 * 282 * The prefix/padding must be filled with 0 if @flags contains 283 * #GST_MEMORY_FLAG_ZERO_PREFIXED and #GST_MEMORY_FLAG_ZERO_PADDED respectively. 284 * 285 * Params: 286 * flags = #GstMemoryFlags 287 * data = data to wrap 288 * maxsize = allocated size of @data 289 * offset = offset in @data 290 * userData = user_data 291 * notify = called with @user_data when the memory is freed 292 * 293 * Returns: a new #GstBuffer 294 * 295 * Throws: ConstructionException GTK+ fails to create the object. 296 */ 297 public this(GstMemoryFlags flags, ubyte[] data, size_t maxsize, size_t offset, void* userData, GDestroyNotify notify) 298 { 299 auto p = gst_buffer_new_wrapped_full(flags, data.ptr, maxsize, offset, cast(size_t)data.length, userData, notify); 300 301 if(p is null) 302 { 303 throw new ConstructionException("null returned by new_wrapped_full"); 304 } 305 306 this(cast(GstBuffer*) p); 307 } 308 309 /** 310 * Add metadata for @info to @buffer using the parameters in @params. 311 * 312 * Params: 313 * info = a #GstMetaInfo 314 * params = params for @info 315 * 316 * Returns: the metadata for the api in @info on @buffer. 317 */ 318 public Meta addMeta(GstMetaInfo* info, void* params) 319 { 320 auto p = gst_buffer_add_meta(gstBuffer, info, params); 321 322 if(p is null) 323 { 324 return null; 325 } 326 327 return ObjectG.getDObject!(Meta)(cast(GstMeta*) p); 328 } 329 330 /** 331 * Add a #GstParentBufferMeta to @buffer that holds a reference on 332 * @ref until the buffer is freed. 333 * 334 * Params: 335 * ref_ = a #GstBuffer to ref 336 * 337 * Returns: The #GstParentBufferMeta that was added to the buffer 338 * 339 * Since: 1.6 340 */ 341 public GstParentBufferMeta* addParentBufferMeta(Buffer ref_) 342 { 343 return gst_buffer_add_parent_buffer_meta(gstBuffer, (ref_ is null) ? null : ref_.getBufferStruct()); 344 } 345 346 /** 347 * Attaches protection metadata to a #GstBuffer. 348 * 349 * Params: 350 * info = a #GstStructure holding cryptographic 351 * information relating to the sample contained in @buffer. This 352 * function takes ownership of @info. 353 * 354 * Returns: a pointer to the added #GstProtectionMeta if successful; %NULL if 355 * unsuccessful. 356 * 357 * Since: 1.6 358 */ 359 public ProtectionMeta addProtectionMeta(Structure info) 360 { 361 auto p = gst_buffer_add_protection_meta(gstBuffer, (info is null) ? null : info.getStructureStruct(true)); 362 363 if(p is null) 364 { 365 return null; 366 } 367 368 return ObjectG.getDObject!(ProtectionMeta)(cast(GstProtectionMeta*) p); 369 } 370 371 /** 372 * Add a #GstReferenceTimestampMeta to @buffer that holds a @timestamp and 373 * optionally @duration based on a specific timestamp @reference. See the 374 * documentation of #GstReferenceTimestampMeta for details. 375 * 376 * Params: 377 * reference = identifier for the timestamp reference. 378 * timestamp = timestamp 379 * duration = duration, or %GST_CLOCK_TIME_NONE 380 * 381 * Returns: The #GstReferenceTimestampMeta that was added to the buffer 382 * 383 * Since: 1.14 384 */ 385 public GstReferenceTimestampMeta* addReferenceTimestampMeta(Caps reference, GstClockTime timestamp, GstClockTime duration) 386 { 387 return gst_buffer_add_reference_timestamp_meta(gstBuffer, (reference is null) ? null : reference.getCapsStruct(), timestamp, duration); 388 } 389 390 /** 391 * Append all the memory from @buf2 to @buf1. The result buffer will contain a 392 * concatenation of the memory of @buf1 and @buf2. 393 * 394 * Params: 395 * buf2 = the second source #GstBuffer to append. 396 * 397 * Returns: the new #GstBuffer that contains the memory 398 * of the two source buffers. 399 */ 400 public Buffer append(Buffer buf2) 401 { 402 auto p = gst_buffer_append(gstBuffer, (buf2 is null) ? null : buf2.getBufferStruct()); 403 404 if(p is null) 405 { 406 return null; 407 } 408 409 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true); 410 } 411 412 /** 413 * Append the memory block @mem to @buffer. This function takes 414 * ownership of @mem and thus doesn't increase its refcount. 415 * 416 * This function is identical to gst_buffer_insert_memory() with an index of -1. 417 * See gst_buffer_insert_memory() for more details. 418 * 419 * Params: 420 * mem = a #GstMemory. 421 */ 422 public void appendMemory(Memory mem) 423 { 424 gst_buffer_append_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct()); 425 } 426 427 /** 428 * Append @size bytes at @offset from @buf2 to @buf1. The result buffer will 429 * contain a concatenation of the memory of @buf1 and the requested region of 430 * @buf2. 431 * 432 * Params: 433 * buf2 = the second source #GstBuffer to append. 434 * offset = the offset in @buf2 435 * size = the size or -1 of @buf2 436 * 437 * Returns: the new #GstBuffer that contains the memory 438 * of the two source buffers. 439 */ 440 public Buffer appendRegion(Buffer buf2, ptrdiff_t offset, ptrdiff_t size) 441 { 442 auto p = gst_buffer_append_region(gstBuffer, (buf2 is null) ? null : buf2.getBufferStruct(), offset, size); 443 444 if(p is null) 445 { 446 return null; 447 } 448 449 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true); 450 } 451 452 /** 453 * Create a copy of the given buffer. This will make a newly allocated 454 * copy of the data the source buffer contains. 455 * 456 * Returns: a new copy of @buf. 457 * 458 * Since: 1.6 459 */ 460 public Buffer copyDeep() 461 { 462 auto p = gst_buffer_copy_deep(gstBuffer); 463 464 if(p is null) 465 { 466 return null; 467 } 468 469 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true); 470 } 471 472 /** 473 * Copies the information from @src into @dest. 474 * 475 * If @dest already contains memory and @flags contains GST_BUFFER_COPY_MEMORY, 476 * the memory from @src will be appended to @dest. 477 * 478 * @flags indicate which fields will be copied. 479 * 480 * Params: 481 * src = a source #GstBuffer 482 * flags = flags indicating what metadata fields should be copied. 483 * offset = offset to copy from 484 * size = total size to copy. If -1, all data is copied. 485 * 486 * Returns: %TRUE if the copying succeeded, %FALSE otherwise. 487 */ 488 public bool copyInto(Buffer src, GstBufferCopyFlags flags, size_t offset, size_t size) 489 { 490 return gst_buffer_copy_into(gstBuffer, (src is null) ? null : src.getBufferStruct(), flags, offset, size) != 0; 491 } 492 493 /** 494 * Creates a sub-buffer from @parent at @offset and @size. 495 * This sub-buffer uses the actual memory space of the parent buffer. 496 * This function will copy the offset and timestamp fields when the 497 * offset is 0. If not, they will be set to #GST_CLOCK_TIME_NONE and 498 * #GST_BUFFER_OFFSET_NONE. 499 * If @offset equals 0 and @size equals the total size of @buffer, the 500 * duration and offset end fields are also copied. If not they will be set 501 * to #GST_CLOCK_TIME_NONE and #GST_BUFFER_OFFSET_NONE. 502 * 503 * MT safe. 504 * 505 * Params: 506 * flags = the #GstBufferCopyFlags 507 * offset = the offset into parent #GstBuffer at which the new sub-buffer 508 * begins. 509 * size = the size of the new #GstBuffer sub-buffer, in bytes. If -1, all 510 * data is copied. 511 * 512 * Returns: the new #GstBuffer or %NULL if the arguments were 513 * invalid. 514 */ 515 public Buffer copyRegion(GstBufferCopyFlags flags, size_t offset, size_t size) 516 { 517 auto p = gst_buffer_copy_region(gstBuffer, flags, offset, size); 518 519 if(p is null) 520 { 521 return null; 522 } 523 524 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p, true); 525 } 526 527 /** 528 * Copy @size bytes starting from @offset in @buffer to @dest. 529 * 530 * Params: 531 * offset = the offset to extract 532 * dest = the destination address 533 * 534 * Returns: The amount of bytes extracted. This value can be lower than @size 535 * when @buffer did not contain enough data. 536 */ 537 public size_t extract(size_t offset, ubyte[] dest) 538 { 539 return gst_buffer_extract(gstBuffer, offset, dest.ptr, cast(size_t)dest.length); 540 } 541 542 /** 543 * Extracts a copy of at most @size bytes the data at @offset into 544 * newly-allocated memory. @dest must be freed using g_free() when done. 545 * 546 * Params: 547 * offset = the offset to extract 548 * size = the size to extract 549 * dest = A pointer where 550 * the destination array will be written. Might be %NULL if the size is 0. 551 * 552 * Since: 1.0.10 553 */ 554 public void extractDup(size_t offset, size_t size, out ubyte[] dest) 555 { 556 ubyte* outdest = null; 557 size_t destSize; 558 559 gst_buffer_extract_dup(gstBuffer, offset, size, cast(void**)&outdest, &destSize); 560 561 dest = outdest[0 .. destSize]; 562 } 563 564 /** 565 * Copy @size bytes from @src to @buffer at @offset. 566 * 567 * Params: 568 * offset = the offset to fill 569 * src = the source address 570 * 571 * Returns: The amount of bytes copied. This value can be lower than @size 572 * when @buffer did not contain enough data. 573 */ 574 public size_t fill(size_t offset, ubyte[] src) 575 { 576 return gst_buffer_fill(gstBuffer, offset, src.ptr, cast(size_t)src.length); 577 } 578 579 /** 580 * Find the memory blocks that span @size bytes starting from @offset 581 * in @buffer. 582 * 583 * When this function returns %TRUE, @idx will contain the index of the first 584 * memory block where the byte for @offset can be found and @length contains the 585 * number of memory blocks containing the @size remaining bytes. @skip contains 586 * the number of bytes to skip in the memory block at @idx to get to the byte 587 * for @offset. 588 * 589 * @size can be -1 to get all the memory blocks after @idx. 590 * 591 * Params: 592 * offset = an offset 593 * size = a size 594 * idx = pointer to index 595 * length = pointer to length 596 * skip = pointer to skip 597 * 598 * Returns: %TRUE when @size bytes starting from @offset could be found in 599 * @buffer and @idx, @length and @skip will be filled. 600 */ 601 public bool findMemory(size_t offset, size_t size, out uint idx, out uint length, out size_t skip) 602 { 603 return gst_buffer_find_memory(gstBuffer, offset, size, &idx, &length, &skip) != 0; 604 } 605 606 /** 607 * Call @func with @user_data for each meta in @buffer. 608 * 609 * @func can modify the passed meta pointer or its contents. The return value 610 * of @func define if this function returns or if the remaining metadata items 611 * in the buffer should be skipped. 612 * 613 * Params: 614 * func = a #GstBufferForeachMetaFunc to call 615 * userData = user data passed to @func 616 * 617 * Returns: %FALSE when @func returned %FALSE for one of the metadata. 618 */ 619 public bool foreachMeta(GstBufferForeachMetaFunc func, void* userData) 620 { 621 return gst_buffer_foreach_meta(gstBuffer, func, userData) != 0; 622 } 623 624 /** 625 * Get all the memory block in @buffer. The memory blocks will be merged 626 * into one large #GstMemory. 627 * 628 * Returns: a #GstMemory that contains the merged memory. 629 * Use gst_memory_unref () after usage. 630 */ 631 public Memory getAllMemory() 632 { 633 auto p = gst_buffer_get_all_memory(gstBuffer); 634 635 if(p is null) 636 { 637 return null; 638 } 639 640 return ObjectG.getDObject!(Memory)(cast(GstMemory*) p, true); 641 } 642 643 /** 644 * Get the #GstBufferFlags flags set on this buffer. 645 * 646 * Returns: the flags set on this buffer. 647 * 648 * Since: 1.10 649 */ 650 public GstBufferFlags getFlags() 651 { 652 return gst_buffer_get_flags(gstBuffer); 653 } 654 655 /** 656 * Get the memory block at index @idx in @buffer. 657 * 658 * Params: 659 * idx = an index 660 * 661 * Returns: a #GstMemory that contains the data of the 662 * memory block at @idx. Use gst_memory_unref () after usage. 663 */ 664 public Memory getMemory(uint idx) 665 { 666 auto p = gst_buffer_get_memory(gstBuffer, idx); 667 668 if(p is null) 669 { 670 return null; 671 } 672 673 return ObjectG.getDObject!(Memory)(cast(GstMemory*) p, true); 674 } 675 676 /** 677 * Get @length memory blocks in @buffer starting at @idx. The memory blocks will 678 * be merged into one large #GstMemory. 679 * 680 * If @length is -1, all memory starting from @idx is merged. 681 * 682 * Params: 683 * idx = an index 684 * length = a length 685 * 686 * Returns: a #GstMemory that contains the merged data of @length 687 * blocks starting at @idx. Use gst_memory_unref () after usage. 688 */ 689 public Memory getMemoryRange(uint idx, int length) 690 { 691 auto p = gst_buffer_get_memory_range(gstBuffer, idx, length); 692 693 if(p is null) 694 { 695 return null; 696 } 697 698 return ObjectG.getDObject!(Memory)(cast(GstMemory*) p, true); 699 } 700 701 /** 702 * Get the metadata for @api on buffer. When there is no such metadata, %NULL is 703 * returned. If multiple metadata with the given @api are attached to this 704 * buffer only the first one is returned. To handle multiple metadata with a 705 * given API use gst_buffer_iterate_meta() or gst_buffer_foreach_meta() instead 706 * and check the meta->info.api member for the API type. 707 * 708 * Params: 709 * api = the #GType of an API 710 * 711 * Returns: the metadata for @api on 712 * @buffer. 713 */ 714 public Meta getMeta(GType api) 715 { 716 auto p = gst_buffer_get_meta(gstBuffer, api); 717 718 if(p is null) 719 { 720 return null; 721 } 722 723 return ObjectG.getDObject!(Meta)(cast(GstMeta*) p); 724 } 725 726 /** 727 * 728 * Params: 729 * apiType = the #GType of an API 730 * Returns: number of metas of type @api_type on @buffer. 731 * 732 * Since: 1.14 733 */ 734 public uint getNMeta(GType apiType) 735 { 736 return gst_buffer_get_n_meta(gstBuffer, apiType); 737 } 738 739 /** 740 * Find the first #GstReferenceTimestampMeta on @buffer that conforms to 741 * @reference. Conformance is tested by checking if the meta's reference is a 742 * subset of @reference. 743 * 744 * Buffers can contain multiple #GstReferenceTimestampMeta metadata items. 745 * 746 * Params: 747 * reference = a reference #GstCaps 748 * 749 * Returns: the #GstReferenceTimestampMeta or %NULL when there 750 * is no such metadata on @buffer. 751 * 752 * Since: 1.14 753 */ 754 public GstReferenceTimestampMeta* getReferenceTimestampMeta(Caps reference) 755 { 756 return gst_buffer_get_reference_timestamp_meta(gstBuffer, (reference is null) ? null : reference.getCapsStruct()); 757 } 758 759 /** 760 * Get the total size of the memory blocks in @buffer. 761 * 762 * Returns: total size of the memory blocks in @buffer. 763 */ 764 public size_t getSize() 765 { 766 return gst_buffer_get_size(gstBuffer); 767 } 768 769 /** 770 * Get the total size of the memory blocks in @b. 771 * 772 * When not %NULL, @offset will contain the offset of the data in the 773 * first memory block in @buffer and @maxsize will contain the sum of 774 * the size and @offset and the amount of extra padding on the last 775 * memory block. @offset and @maxsize can be used to resize the 776 * buffer memory blocks with gst_buffer_resize(). 777 * 778 * Params: 779 * offset = a pointer to the offset 780 * maxsize = a pointer to the maxsize 781 * 782 * Returns: total size of the memory blocks in @buffer. 783 */ 784 public size_t getSizes(out size_t offset, out size_t maxsize) 785 { 786 return gst_buffer_get_sizes(gstBuffer, &offset, &maxsize); 787 } 788 789 /** 790 * Get the total size of @length memory blocks stating from @idx in @buffer. 791 * 792 * When not %NULL, @offset will contain the offset of the data in the 793 * memory block in @buffer at @idx and @maxsize will contain the sum of the size 794 * and @offset and the amount of extra padding on the memory block at @idx + 795 * @length -1. 796 * @offset and @maxsize can be used to resize the buffer memory blocks with 797 * gst_buffer_resize_range(). 798 * 799 * Params: 800 * idx = an index 801 * length = a length 802 * offset = a pointer to the offset 803 * maxsize = a pointer to the maxsize 804 * 805 * Returns: total size of @length memory blocks starting at @idx in @buffer. 806 */ 807 public size_t getSizesRange(uint idx, int length, out size_t offset, out size_t maxsize) 808 { 809 return gst_buffer_get_sizes_range(gstBuffer, idx, length, &offset, &maxsize); 810 } 811 812 /** */ 813 public bool hasFlags(GstBufferFlags flags) 814 { 815 return gst_buffer_has_flags(gstBuffer, flags) != 0; 816 } 817 818 /** 819 * Insert the memory block @mem to @buffer at @idx. This function takes ownership 820 * of @mem and thus doesn't increase its refcount. 821 * 822 * Only gst_buffer_get_max_memory() can be added to a buffer. If more memory is 823 * added, existing memory blocks will automatically be merged to make room for 824 * the new memory. 825 * 826 * Params: 827 * idx = the index to add the memory at, or -1 to append it to the end 828 * mem = a #GstMemory. 829 */ 830 public void insertMemory(int idx, Memory mem) 831 { 832 gst_buffer_insert_memory(gstBuffer, idx, (mem is null) ? null : mem.getMemoryStruct()); 833 } 834 835 /** 836 * Check if all memory blocks in @buffer are writable. 837 * 838 * Note that this function does not check if @buffer is writable, use 839 * gst_buffer_is_writable() to check that if needed. 840 * 841 * Returns: %TRUE if all memory blocks in @buffer are writable 842 * 843 * Since: 1.4 844 */ 845 public bool isAllMemoryWritable() 846 { 847 return gst_buffer_is_all_memory_writable(gstBuffer) != 0; 848 } 849 850 /** 851 * Check if @length memory blocks in @buffer starting from @idx are writable. 852 * 853 * @length can be -1 to check all the memory blocks after @idx. 854 * 855 * Note that this function does not check if @buffer is writable, use 856 * gst_buffer_is_writable() to check that if needed. 857 * 858 * Params: 859 * idx = an index 860 * length = a length should not be 0 861 * 862 * Returns: %TRUE if the memory range is writable 863 * 864 * Since: 1.4 865 */ 866 public bool isMemoryRangeWritable(uint idx, int length) 867 { 868 return gst_buffer_is_memory_range_writable(gstBuffer, idx, length) != 0; 869 } 870 871 /** 872 * Retrieve the next #GstMeta after @current. If @state points 873 * to %NULL, the first metadata is returned. 874 * 875 * @state will be updated with an opaque state pointer 876 * 877 * Params: 878 * state = an opaque state pointer 879 * 880 * Returns: The next #GstMeta or %NULL 881 * when there are no more items. 882 */ 883 public Meta iterateMeta(out void* state) 884 { 885 auto p = gst_buffer_iterate_meta(gstBuffer, &state); 886 887 if(p is null) 888 { 889 return null; 890 } 891 892 return ObjectG.getDObject!(Meta)(cast(GstMeta*) p); 893 } 894 895 /** 896 * Retrieve the next #GstMeta of type @meta_api_type after the current one 897 * according to @state. If @state points to %NULL, the first metadata of 898 * type @meta_api_type is returned. 899 * 900 * @state will be updated with an opaque state pointer 901 * 902 * Params: 903 * state = an opaque state pointer 904 * metaApiType = only return #GstMeta of this type 905 * 906 * Returns: The next #GstMeta of type 907 * @meta_api_type or %NULL when there are no more items. 908 * 909 * Since: 1.12 910 */ 911 public Meta iterateMetaFiltered(out void* state, GType metaApiType) 912 { 913 auto p = gst_buffer_iterate_meta_filtered(gstBuffer, &state, metaApiType); 914 915 if(p is null) 916 { 917 return null; 918 } 919 920 return ObjectG.getDObject!(Meta)(cast(GstMeta*) p); 921 } 922 923 /** 924 * This function fills @info with the #GstMapInfo of all merged memory 925 * blocks in @buffer. 926 * 927 * @flags describe the desired access of the memory. When @flags is 928 * #GST_MAP_WRITE, @buffer should be writable (as returned from 929 * gst_buffer_is_writable()). 930 * 931 * When @buffer is writable but the memory isn't, a writable copy will 932 * automatically be created and returned. The readonly copy of the 933 * buffer memory will then also be replaced with this writable copy. 934 * 935 * The memory in @info should be unmapped with gst_buffer_unmap() after 936 * usage. 937 * 938 * Params: 939 * info = info about the mapping 940 * flags = flags for the mapping 941 * 942 * Returns: %TRUE if the map succeeded and @info contains valid data. 943 */ 944 public bool map(out GstMapInfo info, GstMapFlags flags) 945 { 946 return gst_buffer_map(gstBuffer, &info, flags) != 0; 947 } 948 949 /** 950 * This function fills @info with the #GstMapInfo of @length merged memory blocks 951 * starting at @idx in @buffer. When @length is -1, all memory blocks starting 952 * from @idx are merged and mapped. 953 * 954 * @flags describe the desired access of the memory. When @flags is 955 * #GST_MAP_WRITE, @buffer should be writable (as returned from 956 * gst_buffer_is_writable()). 957 * 958 * When @buffer is writable but the memory isn't, a writable copy will 959 * automatically be created and returned. The readonly copy of the buffer memory 960 * will then also be replaced with this writable copy. 961 * 962 * The memory in @info should be unmapped with gst_buffer_unmap() after usage. 963 * 964 * Params: 965 * idx = an index 966 * length = a length 967 * info = info about the mapping 968 * flags = flags for the mapping 969 * 970 * Returns: %TRUE if the map succeeded and @info contains valid 971 * data. 972 */ 973 public bool mapRange(uint idx, int length, out GstMapInfo info, GstMapFlags flags) 974 { 975 return gst_buffer_map_range(gstBuffer, idx, length, &info, flags) != 0; 976 } 977 978 /** 979 * Compare @size bytes starting from @offset in @buffer with the memory in @mem. 980 * 981 * Params: 982 * offset = the offset in @buffer 983 * mem = the memory to compare 984 * 985 * Returns: 0 if the memory is equal. 986 */ 987 public int memcmp(size_t offset, ubyte[] mem) 988 { 989 return gst_buffer_memcmp(gstBuffer, offset, mem.ptr, cast(size_t)mem.length); 990 } 991 992 /** 993 * Fill @buf with @size bytes with @val starting from @offset. 994 * 995 * Params: 996 * offset = the offset in @buffer 997 * val = the value to set 998 * size = the size to set 999 * 1000 * Returns: The amount of bytes filled. This value can be lower than @size 1001 * when @buffer did not contain enough data. 1002 */ 1003 public size_t memset(size_t offset, ubyte val, size_t size) 1004 { 1005 return gst_buffer_memset(gstBuffer, offset, val, size); 1006 } 1007 1008 /** 1009 * Get the amount of memory blocks that this buffer has. This amount is never 1010 * larger than what gst_buffer_get_max_memory() returns. 1011 * 1012 * Returns: the number of memory blocks this buffer is made of. 1013 */ 1014 public uint nMemory() 1015 { 1016 return gst_buffer_n_memory(gstBuffer); 1017 } 1018 1019 /** 1020 * Get the memory block at @idx in @buffer. The memory block stays valid until 1021 * the memory block in @buffer is removed, replaced or merged, typically with 1022 * any call that modifies the memory in @buffer. 1023 * 1024 * Params: 1025 * idx = an index 1026 * 1027 * Returns: the #GstMemory at @idx. 1028 */ 1029 public Memory peekMemory(uint idx) 1030 { 1031 auto p = gst_buffer_peek_memory(gstBuffer, idx); 1032 1033 if(p is null) 1034 { 1035 return null; 1036 } 1037 1038 return ObjectG.getDObject!(Memory)(cast(GstMemory*) p); 1039 } 1040 1041 /** 1042 * Prepend the memory block @mem to @buffer. This function takes 1043 * ownership of @mem and thus doesn't increase its refcount. 1044 * 1045 * This function is identical to gst_buffer_insert_memory() with an index of 0. 1046 * See gst_buffer_insert_memory() for more details. 1047 * 1048 * Params: 1049 * mem = a #GstMemory. 1050 */ 1051 public void prependMemory(Memory mem) 1052 { 1053 gst_buffer_prepend_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct()); 1054 } 1055 1056 /** 1057 * Remove all the memory blocks in @buffer. 1058 */ 1059 public void removeAllMemory() 1060 { 1061 gst_buffer_remove_all_memory(gstBuffer); 1062 } 1063 1064 /** 1065 * Remove the memory block in @b at index @i. 1066 * 1067 * Params: 1068 * idx = an index 1069 */ 1070 public void removeMemory(uint idx) 1071 { 1072 gst_buffer_remove_memory(gstBuffer, idx); 1073 } 1074 1075 /** 1076 * Remove @length memory blocks in @buffer starting from @idx. 1077 * 1078 * @length can be -1, in which case all memory starting from @idx is removed. 1079 * 1080 * Params: 1081 * idx = an index 1082 * length = a length 1083 */ 1084 public void removeMemoryRange(uint idx, int length) 1085 { 1086 gst_buffer_remove_memory_range(gstBuffer, idx, length); 1087 } 1088 1089 /** 1090 * Remove the metadata for @meta on @buffer. 1091 * 1092 * Params: 1093 * meta = a #GstMeta 1094 * 1095 * Returns: %TRUE if the metadata existed and was removed, %FALSE if no such 1096 * metadata was on @buffer. 1097 */ 1098 public bool removeMeta(Meta meta) 1099 { 1100 return gst_buffer_remove_meta(gstBuffer, (meta is null) ? null : meta.getMetaStruct()) != 0; 1101 } 1102 1103 /** 1104 * Replaces all memory in @buffer with @mem. 1105 * 1106 * Params: 1107 * mem = a #GstMemory 1108 */ 1109 public void replaceAllMemory(Memory mem) 1110 { 1111 gst_buffer_replace_all_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct()); 1112 } 1113 1114 /** 1115 * Replaces the memory block at index @idx in @buffer with @mem. 1116 * 1117 * Params: 1118 * idx = an index 1119 * mem = a #GstMemory 1120 */ 1121 public void replaceMemory(uint idx, Memory mem) 1122 { 1123 gst_buffer_replace_memory(gstBuffer, idx, (mem is null) ? null : mem.getMemoryStruct()); 1124 } 1125 1126 /** 1127 * Replaces @length memory blocks in @buffer starting at @idx with @mem. 1128 * 1129 * If @length is -1, all memory starting from @idx will be removed and 1130 * replaced with @mem. 1131 * 1132 * @buffer should be writable. 1133 * 1134 * Params: 1135 * idx = an index 1136 * length = a length should not be 0 1137 * mem = a #GstMemory 1138 */ 1139 public void replaceMemoryRange(uint idx, int length, Memory mem) 1140 { 1141 gst_buffer_replace_memory_range(gstBuffer, idx, length, (mem is null) ? null : mem.getMemoryStruct()); 1142 } 1143 1144 /** 1145 * Set the offset and total size of the memory blocks in @buffer. 1146 * 1147 * Params: 1148 * offset = the offset adjustment 1149 * size = the new size or -1 to just adjust the offset 1150 */ 1151 public void resize(ptrdiff_t offset, ptrdiff_t size) 1152 { 1153 gst_buffer_resize(gstBuffer, offset, size); 1154 } 1155 1156 /** 1157 * Set the total size of the @length memory blocks starting at @idx in 1158 * @buffer 1159 * 1160 * Params: 1161 * idx = an index 1162 * length = a length 1163 * offset = the offset adjustment 1164 * size = the new size or -1 to just adjust the offset 1165 * 1166 * Returns: %TRUE if resizing succeeded, %FALSE otherwise. 1167 */ 1168 public bool resizeRange(uint idx, int length, ptrdiff_t offset, ptrdiff_t size) 1169 { 1170 return gst_buffer_resize_range(gstBuffer, idx, length, offset, size) != 0; 1171 } 1172 1173 /** 1174 * Sets one or more buffer flags on a buffer. 1175 * 1176 * Params: 1177 * flags = the #GstBufferFlags to set. 1178 * 1179 * Returns: %TRUE if @flags were successfully set on buffer. 1180 * 1181 * Since: 1.10 1182 */ 1183 public bool setFlags(GstBufferFlags flags) 1184 { 1185 return gst_buffer_set_flags(gstBuffer, flags) != 0; 1186 } 1187 1188 /** 1189 * Set the total size of the memory blocks in @buffer. 1190 * 1191 * Params: 1192 * size = the new size 1193 */ 1194 public void setSize(ptrdiff_t size) 1195 { 1196 gst_buffer_set_size(gstBuffer, size); 1197 } 1198 1199 /** 1200 * Release the memory previously mapped with gst_buffer_map(). 1201 * 1202 * Params: 1203 * info = a #GstMapInfo 1204 */ 1205 public void unmap(GstMapInfo* info) 1206 { 1207 gst_buffer_unmap(gstBuffer, info); 1208 } 1209 1210 /** 1211 * Clears one or more buffer flags. 1212 * 1213 * Params: 1214 * flags = the #GstBufferFlags to clear 1215 * 1216 * Returns: true if @flags is successfully cleared from buffer. 1217 * 1218 * Since: 1.10 1219 */ 1220 public bool unsetFlags(GstBufferFlags flags) 1221 { 1222 return gst_buffer_unset_flags(gstBuffer, flags) != 0; 1223 } 1224 1225 /** 1226 * Get the maximum amount of memory blocks that a buffer can hold. This is a 1227 * compile time constant that can be queried with the function. 1228 * 1229 * When more memory blocks are added, existing memory blocks will be merged 1230 * together to make room for the new block. 1231 * 1232 * Returns: the maximum amount of memory blocks that a buffer can hold. 1233 * 1234 * Since: 1.2 1235 */ 1236 public static uint getMaxMemory() 1237 { 1238 return gst_buffer_get_max_memory(); 1239 } 1240 }