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