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 * |[ 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 133 /** Get the main Gtk struct */ 134 public GstBuffer* getBufferStruct() 135 { 136 return gstBuffer; 137 } 138 139 /** the main Gtk struct as a void* */ 140 protected void* getStruct() 141 { 142 return cast(void*)gstBuffer; 143 } 144 145 /** 146 * Sets our main struct and passes it to the parent class. 147 */ 148 public this (GstBuffer* gstBuffer) 149 { 150 this.gstBuffer = gstBuffer; 151 } 152 153 154 /** */ 155 public static GType getType() 156 { 157 return gst_buffer_get_type(); 158 } 159 160 /** 161 * Creates a newly allocated buffer without any data. 162 * 163 * MT safe. 164 * 165 * Return: the new #GstBuffer. 166 * 167 * Throws: ConstructionException GTK+ fails to create the object. 168 */ 169 public this() 170 { 171 auto p = gst_buffer_new(); 172 173 if(p is null) 174 { 175 throw new ConstructionException("null returned by new"); 176 } 177 178 this(cast(GstBuffer*) p); 179 } 180 181 /** 182 * Tries to create a newly allocated buffer with data of the given size and 183 * extra parameters from @allocator. If the requested amount of memory can't be 184 * allocated, %NULL will be returned. The allocated buffer memory is not cleared. 185 * 186 * When @allocator is %NULL, the default memory allocator will be used. 187 * 188 * Note that when @size == 0, the buffer will not have memory associated with it. 189 * 190 * MT safe. 191 * 192 * Params: 193 * allocator = the #GstAllocator to use, or %NULL to use the 194 * default allocator 195 * size = the size in bytes of the new buffer's data. 196 * params = optional parameters 197 * 198 * Return: a new #GstBuffer, or %NULL if 199 * the memory couldn't be allocated. 200 * 201 * Throws: ConstructionException GTK+ fails to create the object. 202 */ 203 public this(Allocator allocator, size_t size, AllocationParams params) 204 { 205 auto p = gst_buffer_new_allocate((allocator is null) ? null : allocator.getAllocatorStruct(), size, (params is null) ? null : params.getAllocationParamsStruct()); 206 207 if(p is null) 208 { 209 throw new ConstructionException("null returned by new_allocate"); 210 } 211 212 this(cast(GstBuffer*) p); 213 } 214 215 /** 216 * Creates a new buffer that wraps the given @data. The memory will be freed 217 * with g_free and will be marked writable. 218 * 219 * MT safe. 220 * 221 * Params: 222 * data = data to wrap 223 * size = allocated size of @data 224 * 225 * Return: a new #GstBuffer 226 * 227 * Throws: ConstructionException GTK+ fails to create the object. 228 */ 229 public this(ubyte[] data) 230 { 231 auto p = gst_buffer_new_wrapped(data.ptr, cast(size_t)data.length); 232 233 if(p is null) 234 { 235 throw new ConstructionException("null returned by new_wrapped"); 236 } 237 238 this(cast(GstBuffer*) p); 239 } 240 241 /** 242 * Allocate a new buffer that wraps the given memory. @data must point to 243 * @maxsize of memory, the wrapped buffer will have the region from @offset and 244 * @size visible. 245 * 246 * When the buffer is destroyed, @notify will be called with @user_data. 247 * 248 * The prefix/padding must be filled with 0 if @flags contains 249 * #GST_MEMORY_FLAG_ZERO_PREFIXED and #GST_MEMORY_FLAG_ZERO_PADDED respectively. 250 * 251 * Params: 252 * flags = #GstMemoryFlags 253 * data = data to wrap 254 * maxsize = allocated size of @data 255 * offset = offset in @data 256 * size = size of valid data 257 * userData = user_data 258 * notify = called with @user_data when the memory is freed 259 * 260 * Return: a new #GstBuffer 261 * 262 * Throws: ConstructionException GTK+ fails to create the object. 263 */ 264 public this(GstMemoryFlags flags, ubyte[] data, size_t maxsize, size_t offset, void* userData, GDestroyNotify notify) 265 { 266 auto p = gst_buffer_new_wrapped_full(flags, data.ptr, maxsize, offset, cast(size_t)data.length, userData, notify); 267 268 if(p is null) 269 { 270 throw new ConstructionException("null returned by new_wrapped_full"); 271 } 272 273 this(cast(GstBuffer*) p); 274 } 275 276 /** 277 * Add metadata for @info to @buffer using the parameters in @params. 278 * 279 * Params: 280 * info = a #GstMetaInfo 281 * params = params for @info 282 * 283 * Return: the metadata for the api in @info on @buffer. 284 */ 285 public GstMeta* addMeta(GstMetaInfo* info, void* params) 286 { 287 return gst_buffer_add_meta(gstBuffer, info, params); 288 } 289 290 /** 291 * Add a #GstParentBufferMeta to @buffer that holds a reference on 292 * @ref until the buffer is freed. 293 * 294 * Params: 295 * doref = a #GstBuffer to ref 296 * 297 * Return: The #GstParentBufferMeta that was added to the buffer 298 * 299 * Since: 1.6 300 */ 301 public GstParentBufferMeta* addParentBufferMeta(Buffer doref) 302 { 303 return gst_buffer_add_parent_buffer_meta(gstBuffer, (doref is null) ? null : doref.getBufferStruct()); 304 } 305 306 /** 307 * Attaches protection metadata to a #GstBuffer. 308 * 309 * Params: 310 * info = a #GstStructure holding cryptographic 311 * information relating to the sample contained in @buffer. This 312 * function takes ownership of @info. 313 * 314 * Return: a pointer to the added #GstProtectionMeta if successful; %NULL if 315 * unsuccessful. 316 * 317 * Since: 1.6 318 */ 319 public ProtectionMeta addProtectionMeta(Structure info) 320 { 321 auto p = gst_buffer_add_protection_meta(gstBuffer, (info is null) ? null : info.getStructureStruct()); 322 323 if(p is null) 324 { 325 return null; 326 } 327 328 return ObjectG.getDObject!(ProtectionMeta)(cast(GstProtectionMeta*) p); 329 } 330 331 /** 332 * Append all the memory from @buf2 to @buf1. The result buffer will contain a 333 * concatenation of the memory of @buf1 and @buf2. 334 * 335 * Params: 336 * buf2 = the second source #GstBuffer to append. 337 * 338 * Return: the new #GstBuffer that contains the memory 339 * of the two source buffers. 340 */ 341 public Buffer append(Buffer buf2) 342 { 343 auto p = gst_buffer_append(gstBuffer, (buf2 is null) ? null : buf2.getBufferStruct()); 344 345 if(p is null) 346 { 347 return null; 348 } 349 350 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p); 351 } 352 353 /** 354 * Append the memory block @mem to @buffer. This function takes 355 * ownership of @mem and thus doesn't increase its refcount. 356 * 357 * This function is identical to gst_buffer_insert_memory() with an index of -1. 358 * See gst_buffer_insert_memory() for more details. 359 * 360 * Params: 361 * mem = a #GstMemory. 362 */ 363 public void appendMemory(Memory mem) 364 { 365 gst_buffer_append_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct()); 366 } 367 368 /** 369 * Append @size bytes at @offset from @buf2 to @buf1. The result buffer will 370 * contain a concatenation of the memory of @buf1 and the requested region of 371 * @buf2. 372 * 373 * Params: 374 * buf2 = the second source #GstBuffer to append. 375 * offset = the offset in @buf2 376 * size = the size or -1 of @buf2 377 * 378 * Return: the new #GstBuffer that contains the memory 379 * of the two source buffers. 380 */ 381 public Buffer appendRegion(Buffer buf2, ptrdiff_t offset, ptrdiff_t size) 382 { 383 auto p = gst_buffer_append_region(gstBuffer, (buf2 is null) ? null : buf2.getBufferStruct(), offset, size); 384 385 if(p is null) 386 { 387 return null; 388 } 389 390 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p); 391 } 392 393 /** 394 * Create a copy of the given buffer. This will make a newly allocated 395 * copy of the data the source buffer contains. 396 * 397 * Return: a new copy of @buf. 398 * 399 * Since: 1.6 400 */ 401 public Buffer copyDeep() 402 { 403 auto p = gst_buffer_copy_deep(gstBuffer); 404 405 if(p is null) 406 { 407 return null; 408 } 409 410 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p); 411 } 412 413 /** 414 * Copies the information from @src into @dest. 415 * 416 * If @dest already contains memory and @flags contains GST_BUFFER_COPY_MEMORY, 417 * the memory from @src will be appended to @dest. 418 * 419 * @flags indicate which fields will be copied. 420 * 421 * Params: 422 * src = a source #GstBuffer 423 * flags = flags indicating what metadata fields should be copied. 424 * offset = offset to copy from 425 * size = total size to copy. If -1, all data is copied. 426 * 427 * Return: %TRUE if the copying succeeded, %FALSE otherwise. 428 */ 429 public bool copyInto(Buffer src, GstBufferCopyFlags flags, size_t offset, size_t size) 430 { 431 return gst_buffer_copy_into(gstBuffer, (src is null) ? null : src.getBufferStruct(), flags, offset, size) != 0; 432 } 433 434 /** 435 * Creates a sub-buffer from @parent at @offset and @size. 436 * This sub-buffer uses the actual memory space of the parent buffer. 437 * This function will copy the offset and timestamp fields when the 438 * offset is 0. If not, they will be set to #GST_CLOCK_TIME_NONE and 439 * #GST_BUFFER_OFFSET_NONE. 440 * If @offset equals 0 and @size equals the total size of @buffer, the 441 * duration and offset end fields are also copied. If not they will be set 442 * to #GST_CLOCK_TIME_NONE and #GST_BUFFER_OFFSET_NONE. 443 * 444 * MT safe. 445 * 446 * Params: 447 * flags = the #GstBufferCopyFlags 448 * offset = the offset into parent #GstBuffer at which the new sub-buffer 449 * begins. 450 * size = the size of the new #GstBuffer sub-buffer, in bytes. If -1, all 451 * data is copied. 452 * 453 * Return: the new #GstBuffer or %NULL if the arguments were 454 * invalid. 455 */ 456 public Buffer copyRegion(GstBufferCopyFlags flags, size_t offset, size_t size) 457 { 458 auto p = gst_buffer_copy_region(gstBuffer, flags, offset, size); 459 460 if(p is null) 461 { 462 return null; 463 } 464 465 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p); 466 } 467 468 /** 469 * Copy @size bytes starting from @offset in @buffer to @dest. 470 * 471 * Params: 472 * offset = the offset to extract 473 * dest = the destination address 474 * size = the size to extract 475 * 476 * Return: The amount of bytes extracted. This value can be lower than @size 477 * when @buffer did not contain enough data. 478 */ 479 public size_t extract(size_t offset, void* dest, size_t size) 480 { 481 return gst_buffer_extract(gstBuffer, offset, dest, size); 482 } 483 484 /** 485 * Extracts a copy of at most @size bytes the data at @offset into 486 * newly-allocated memory. @dest must be freed using g_free() when done. 487 * 488 * Params: 489 * offset = the offset to extract 490 * size = the size to extract 491 * dest = A pointer where 492 * the destination array will be written. 493 * destSize = A location where the size of @dest can be written 494 * 495 * Since: 1.0.10 496 */ 497 public void extractDup(size_t offset, size_t size, out ubyte[] dest) 498 { 499 ubyte* outdest = null; 500 size_t destSize; 501 502 gst_buffer_extract_dup(gstBuffer, offset, size, cast(void**)&outdest, &destSize); 503 504 dest = outdest[0 .. destSize]; 505 } 506 507 /** 508 * Copy @size bytes from @src to @buffer at @offset. 509 * 510 * Params: 511 * offset = the offset to fill 512 * src = the source address 513 * size = the size to fill 514 * 515 * Return: The amount of bytes copied. This value can be lower than @size 516 * when @buffer did not contain enough data. 517 */ 518 public size_t fill(size_t offset, ubyte[] src) 519 { 520 return gst_buffer_fill(gstBuffer, offset, src.ptr, cast(size_t)src.length); 521 } 522 523 /** 524 * Find the memory blocks that span @size bytes starting from @offset 525 * in @buffer. 526 * 527 * When this function returns %TRUE, @idx will contain the index of the first 528 * memory block where the byte for @offset can be found and @length contains the 529 * number of memory blocks containing the @size remaining bytes. @skip contains 530 * the number of bytes to skip in the memory block at @idx to get to the byte 531 * for @offset. 532 * 533 * @size can be -1 to get all the memory blocks after @idx. 534 * 535 * Params: 536 * offset = an offset 537 * size = a size 538 * idx = pointer to index 539 * length = pointer to length 540 * skip = pointer to skip 541 * 542 * Return: %TRUE when @size bytes starting from @offset could be found in 543 * @buffer and @idx, @length and @skip will be filled. 544 */ 545 public bool findMemory(size_t offset, size_t size, out uint idx, out uint length, out size_t skip) 546 { 547 return gst_buffer_find_memory(gstBuffer, offset, size, &idx, &length, &skip) != 0; 548 } 549 550 /** 551 * Call @func with @user_data for each meta in @buffer. 552 * 553 * @func can modify the passed meta pointer or its contents. The return value 554 * of @func define if this function returns or if the remaining metadata items 555 * in the buffer should be skipped. 556 * 557 * Params: 558 * func = a #GstBufferForeachMetaFunc to call 559 * userData = user data passed to @func 560 * 561 * Return: %FALSE when @func returned %FALSE for one of the metadata. 562 */ 563 public bool foreachMeta(GstBufferForeachMetaFunc func, void* userData) 564 { 565 return gst_buffer_foreach_meta(gstBuffer, func, userData) != 0; 566 } 567 568 /** 569 * Get all the memory block in @buffer. The memory blocks will be merged 570 * into one large #GstMemory. 571 * 572 * Return: a #GstMemory that contains the merged memory. 573 * Use gst_memory_unref () after usage. 574 */ 575 public Memory getAllMemory() 576 { 577 auto p = gst_buffer_get_all_memory(gstBuffer); 578 579 if(p is null) 580 { 581 return null; 582 } 583 584 return ObjectG.getDObject!(Memory)(cast(GstMemory*) p); 585 } 586 587 /** 588 * Get the memory block at index @idx in @buffer. 589 * 590 * Params: 591 * idx = an index 592 * 593 * Return: a #GstMemory that contains the data of the 594 * memory block at @idx. Use gst_memory_unref () after usage. 595 */ 596 public Memory getMemory(uint idx) 597 { 598 auto p = gst_buffer_get_memory(gstBuffer, idx); 599 600 if(p is null) 601 { 602 return null; 603 } 604 605 return ObjectG.getDObject!(Memory)(cast(GstMemory*) p); 606 } 607 608 /** 609 * Get @length memory blocks in @buffer starting at @idx. The memory blocks will 610 * be merged into one large #GstMemory. 611 * 612 * If @length is -1, all memory starting from @idx is merged. 613 * 614 * Params: 615 * idx = an index 616 * length = a length 617 * 618 * Return: a #GstMemory that contains the merged data of @length 619 * blocks starting at @idx. Use gst_memory_unref () after usage. 620 */ 621 public Memory getMemoryRange(uint idx, int length) 622 { 623 auto p = gst_buffer_get_memory_range(gstBuffer, idx, length); 624 625 if(p is null) 626 { 627 return null; 628 } 629 630 return ObjectG.getDObject!(Memory)(cast(GstMemory*) p); 631 } 632 633 /** 634 * Get the metadata for @api on buffer. When there is no such metadata, %NULL is 635 * returned. If multiple metadata with the given @api are attached to this 636 * buffer only the first one is returned. To handle multiple metadata with a 637 * given API use gst_buffer_iterate_meta() or gst_buffer_foreach_meta() instead 638 * and check the meta->info.api member for the API type. 639 * 640 * Params: 641 * api = the #GType of an API 642 * 643 * Return: the metadata for @api on 644 * @buffer. 645 */ 646 public GstMeta* getMeta(GType api) 647 { 648 return gst_buffer_get_meta(gstBuffer, api); 649 } 650 651 /** 652 * Get the total size of the memory blocks in @buffer. 653 * 654 * Return: total size of the memory blocks in @buffer. 655 */ 656 public size_t getSize() 657 { 658 return gst_buffer_get_size(gstBuffer); 659 } 660 661 /** 662 * Get the total size of the memory blocks in @b. 663 * 664 * When not %NULL, @offset will contain the offset of the data in the 665 * first memory block in @buffer and @maxsize will contain the sum of 666 * the size and @offset and the amount of extra padding on the last 667 * memory block. @offset and @maxsize can be used to resize the 668 * buffer memory blocks with gst_buffer_resize(). 669 * 670 * Params: 671 * offset = a pointer to the offset 672 * maxsize = a pointer to the maxsize 673 * 674 * Return: total size of the memory blocks in @buffer. 675 */ 676 public size_t getSizes(out size_t offset, out size_t maxsize) 677 { 678 return gst_buffer_get_sizes(gstBuffer, &offset, &maxsize); 679 } 680 681 /** 682 * Get the total size of @length memory blocks stating from @idx in @buffer. 683 * 684 * When not %NULL, @offset will contain the offset of the data in the 685 * memory block in @buffer at @idx and @maxsize will contain the sum of the size 686 * and @offset and the amount of extra padding on the memory block at @idx + 687 * @length -1. 688 * @offset and @maxsize can be used to resize the buffer memory blocks with 689 * gst_buffer_resize_range(). 690 * 691 * Params: 692 * idx = an index 693 * length = a length 694 * offset = a pointer to the offset 695 * maxsize = a pointer to the maxsize 696 * 697 * Return: total size of @length memory blocks starting at @idx in @buffer. 698 */ 699 public size_t getSizesRange(uint idx, int length, out size_t offset, out size_t maxsize) 700 { 701 return gst_buffer_get_sizes_range(gstBuffer, idx, length, &offset, &maxsize); 702 } 703 704 /** 705 * Insert the memory block @mem to @buffer at @idx. This function takes ownership 706 * of @mem and thus doesn't increase its refcount. 707 * 708 * Only gst_buffer_get_max_memory() can be added to a buffer. If more memory is 709 * added, existing memory blocks will automatically be merged to make room for 710 * the new memory. 711 * 712 * Params: 713 * idx = the index to add the memory at, or -1 to append it to the end 714 * mem = a #GstMemory. 715 */ 716 public void insertMemory(int idx, Memory mem) 717 { 718 gst_buffer_insert_memory(gstBuffer, idx, (mem is null) ? null : mem.getMemoryStruct()); 719 } 720 721 /** 722 * Check if all memory blocks in @buffer are writable. 723 * 724 * Note that this function does not check if @buffer is writable, use 725 * gst_buffer_is_writable() to check that if needed. 726 * 727 * Return: %TRUE if all memory blocks in @buffer are writable 728 * 729 * Since: 1.4 730 */ 731 public bool isAllMemoryWritable() 732 { 733 return gst_buffer_is_all_memory_writable(gstBuffer) != 0; 734 } 735 736 /** 737 * Check if @length memory blocks in @buffer starting from @idx are writable. 738 * 739 * @length can be -1 to check all the memory blocks after @idx. 740 * 741 * Note that this function does not check if @buffer is writable, use 742 * gst_buffer_is_writable() to check that if needed. 743 * 744 * Params: 745 * idx = an index 746 * length = a length should not be 0 747 * 748 * Return: %TRUE if the memory range is writable 749 * 750 * Since: 1.4 751 */ 752 public bool isMemoryRangeWritable(uint idx, int length) 753 { 754 return gst_buffer_is_memory_range_writable(gstBuffer, idx, length) != 0; 755 } 756 757 /** 758 * Retrieve the next #GstMeta after @current. If @state points 759 * to %NULL, the first metadata is returned. 760 * 761 * @state will be updated with an opaque state pointer 762 * 763 * Params: 764 * state = an opaque state pointer 765 * 766 * Return: The next #GstMeta or %NULL 767 * when there are no more items. 768 */ 769 public GstMeta* iterateMeta(void** state) 770 { 771 return gst_buffer_iterate_meta(gstBuffer, state); 772 } 773 774 /** 775 * This function fills @info with the #GstMapInfo of all merged memory 776 * blocks in @buffer. 777 * 778 * @flags describe the desired access of the memory. When @flags is 779 * #GST_MAP_WRITE, @buffer should be writable (as returned from 780 * gst_buffer_is_writable()). 781 * 782 * When @buffer is writable but the memory isn't, a writable copy will 783 * automatically be created and returned. The readonly copy of the 784 * buffer memory will then also be replaced with this writable copy. 785 * 786 * The memory in @info should be unmapped with gst_buffer_unmap() after 787 * usage. 788 * 789 * Params: 790 * info = info about the mapping 791 * flags = flags for the mapping 792 * 793 * Return: %TRUE if the map succeeded and @info contains valid data. 794 */ 795 public bool map(out GstMapInfo info, GstMapFlags flags) 796 { 797 return gst_buffer_map(gstBuffer, &info, flags) != 0; 798 } 799 800 /** 801 * This function fills @info with the #GstMapInfo of @length merged memory blocks 802 * starting at @idx in @buffer. When @length is -1, all memory blocks starting 803 * from @idx are merged and mapped. 804 * 805 * @flags describe the desired access of the memory. When @flags is 806 * #GST_MAP_WRITE, @buffer should be writable (as returned from 807 * gst_buffer_is_writable()). 808 * 809 * When @buffer is writable but the memory isn't, a writable copy will 810 * automatically be created and returned. The readonly copy of the buffer memory 811 * will then also be replaced with this writable copy. 812 * 813 * The memory in @info should be unmapped with gst_buffer_unmap() after usage. 814 * 815 * Params: 816 * idx = an index 817 * length = a length 818 * info = info about the mapping 819 * flags = flags for the mapping 820 * 821 * Return: %TRUE if the map succeeded and @info contains valid 822 * data. 823 */ 824 public bool mapRange(uint idx, int length, out GstMapInfo info, GstMapFlags flags) 825 { 826 return gst_buffer_map_range(gstBuffer, idx, length, &info, flags) != 0; 827 } 828 829 /** 830 * Compare @size bytes starting from @offset in @buffer with the memory in @mem. 831 * 832 * Params: 833 * offset = the offset in @buffer 834 * mem = the memory to compare 835 * size = the size to compare 836 * 837 * Return: 0 if the memory is equal. 838 */ 839 public int memcmp(size_t offset, ubyte[] mem) 840 { 841 return gst_buffer_memcmp(gstBuffer, offset, mem.ptr, cast(size_t)mem.length); 842 } 843 844 /** 845 * Fill @buf with @size bytes with @val starting from @offset. 846 * 847 * Params: 848 * offset = the offset in @buffer 849 * val = the value to set 850 * size = the size to set 851 * 852 * Return: The amount of bytes filled. This value can be lower than @size 853 * when @buffer did not contain enough data. 854 */ 855 public size_t memset(size_t offset, ubyte val, size_t size) 856 { 857 return gst_buffer_memset(gstBuffer, offset, val, size); 858 } 859 860 /** 861 * Get the amount of memory blocks that this buffer has. This amount is never 862 * larger than what gst_buffer_get_max_memory() returns. 863 * 864 * Return: the amount of memory block in this buffer. 865 */ 866 public uint nMemory() 867 { 868 return gst_buffer_n_memory(gstBuffer); 869 } 870 871 /** 872 * Get the memory block at @idx in @buffer. The memory block stays valid until 873 * the memory block in @buffer is removed, replaced or merged, typically with 874 * any call that modifies the memory in @buffer. 875 * 876 * Params: 877 * idx = an index 878 * 879 * Return: the #GstMemory at @idx. 880 */ 881 public Memory peekMemory(uint idx) 882 { 883 auto p = gst_buffer_peek_memory(gstBuffer, idx); 884 885 if(p is null) 886 { 887 return null; 888 } 889 890 return ObjectG.getDObject!(Memory)(cast(GstMemory*) p); 891 } 892 893 /** 894 * Prepend the memory block @mem to @buffer. This function takes 895 * ownership of @mem and thus doesn't increase its refcount. 896 * 897 * This function is identical to gst_buffer_insert_memory() with an index of 0. 898 * See gst_buffer_insert_memory() for more details. 899 * 900 * Params: 901 * mem = a #GstMemory. 902 */ 903 public void prependMemory(Memory mem) 904 { 905 gst_buffer_prepend_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct()); 906 } 907 908 /** 909 * Remove all the memory blocks in @buffer. 910 */ 911 public void removeAllMemory() 912 { 913 gst_buffer_remove_all_memory(gstBuffer); 914 } 915 916 /** 917 * Remove the memory block in @b at index @i. 918 * 919 * Params: 920 * idx = an index 921 */ 922 public void removeMemory(uint idx) 923 { 924 gst_buffer_remove_memory(gstBuffer, idx); 925 } 926 927 /** 928 * Remove @length memory blocks in @buffer starting from @idx. 929 * 930 * @length can be -1, in which case all memory starting from @idx is removed. 931 * 932 * Params: 933 * idx = an index 934 * length = a length 935 */ 936 public void removeMemoryRange(uint idx, int length) 937 { 938 gst_buffer_remove_memory_range(gstBuffer, idx, length); 939 } 940 941 /** 942 * Remove the metadata for @meta on @buffer. 943 * 944 * Params: 945 * meta = a #GstMeta 946 * 947 * Return: %TRUE if the metadata existed and was removed, %FALSE if no such 948 * metadata was on @buffer. 949 */ 950 public bool removeMeta(GstMeta* meta) 951 { 952 return gst_buffer_remove_meta(gstBuffer, meta) != 0; 953 } 954 955 /** 956 * Replaces all memory in @buffer with @mem. 957 * 958 * Params: 959 * mem = a #GstMemory 960 */ 961 public void replaceAllMemory(Memory mem) 962 { 963 gst_buffer_replace_all_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct()); 964 } 965 966 /** 967 * Replaces the memory block at index @idx in @buffer with @mem. 968 * 969 * Params: 970 * idx = an index 971 * mem = a #GstMemory 972 */ 973 public void replaceMemory(uint idx, Memory mem) 974 { 975 gst_buffer_replace_memory(gstBuffer, idx, (mem is null) ? null : mem.getMemoryStruct()); 976 } 977 978 /** 979 * Replaces @length memory blocks in @buffer starting at @idx with @mem. 980 * 981 * If @length is -1, all memory starting from @idx will be removed and 982 * replaced with @mem. 983 * 984 * @buffer should be writable. 985 * 986 * Params: 987 * idx = an index 988 * length = a length should not be 0 989 * mem = a #GstMemory 990 */ 991 public void replaceMemoryRange(uint idx, int length, Memory mem) 992 { 993 gst_buffer_replace_memory_range(gstBuffer, idx, length, (mem is null) ? null : mem.getMemoryStruct()); 994 } 995 996 /** 997 * Set the offset and total size of the memory blocks in @buffer. 998 * 999 * Params: 1000 * offset = the offset adjustment 1001 * size = the new size or -1 to just adjust the offset 1002 */ 1003 public void resize(ptrdiff_t offset, ptrdiff_t size) 1004 { 1005 gst_buffer_resize(gstBuffer, offset, size); 1006 } 1007 1008 /** 1009 * Set the total size of the @length memory blocks starting at @idx in 1010 * @buffer 1011 * 1012 * Params: 1013 * idx = an index 1014 * length = a length 1015 * offset = the offset adjustment 1016 * size = the new size or -1 to just adjust the offset 1017 * 1018 * Return: %TRUE if resizing succeeded, %FALSE otherwise. 1019 */ 1020 public bool resizeRange(uint idx, int length, ptrdiff_t offset, ptrdiff_t size) 1021 { 1022 return gst_buffer_resize_range(gstBuffer, idx, length, offset, size) != 0; 1023 } 1024 1025 /** 1026 * Set the total size of the memory blocks in @buffer. 1027 * 1028 * Params: 1029 * size = the new size 1030 */ 1031 public void setSize(ptrdiff_t size) 1032 { 1033 gst_buffer_set_size(gstBuffer, size); 1034 } 1035 1036 /** 1037 * Release the memory previously mapped with gst_buffer_map(). 1038 * 1039 * Params: 1040 * info = a #GstMapInfo 1041 */ 1042 public void unmap(GstMapInfo* info) 1043 { 1044 gst_buffer_unmap(gstBuffer, info); 1045 } 1046 1047 /** 1048 * Get the maximum amount of memory blocks that a buffer can hold. This is a 1049 * compile time constant that can be queried with the function. 1050 * 1051 * When more memory blocks are added, existing memory blocks will be merged 1052 * together to make room for the new block. 1053 * 1054 * Return: the maximum amount of memory blocks that a buffer can hold. 1055 * 1056 * Since: 1.2 1057 */ 1058 public static uint getMaxMemory() 1059 { 1060 return gst_buffer_get_max_memory(); 1061 } 1062 }