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 * Conversion parameters: 26 * inFile = gstreamer-GstBuffer.html 27 * outPack = gstreamer 28 * outFile = Buffer 29 * strct = GstBuffer 30 * realStrct= 31 * ctorStrct= 32 * clss = Buffer 33 * interf = 34 * class Code: Yes 35 * interface Code: No 36 * template for: 37 * extend = 38 * implements: 39 * prefixes: 40 * - gst_buffer_ 41 * omit structs: 42 * - GstBuffer 43 * omit prefixes: 44 * omit code: 45 * - gst_buffer_extract_dup 46 * omit signals: 47 * imports: 48 * - glib.Str 49 * - gstreamer.Allocator 50 * - gstreamer.Memory 51 * - gstreamer.Meta 52 * structWrap: 53 * - GstAllocator* -> Allocator 54 * - GstBuffer* -> Buffer 55 * - GstMemory* -> Memory 56 * module aliases: 57 * local aliases: 58 * overrides: 59 */ 60 61 module gstreamer.Buffer; 62 63 public import gstreamerc.gstreamertypes; 64 65 private import gstreamerc.gstreamer; 66 private import glib.ConstructionException; 67 private import gobject.ObjectG; 68 69 private import glib.Str; 70 private import gstreamer.Allocator; 71 private import gstreamer.Memory; 72 private import gstreamer.Meta; 73 74 75 76 /** 77 * Buffers are the basic unit of data transfer in GStreamer. They contain the 78 * timing and offset along with other arbitrary metadata that is associated 79 * with the GstMemory blocks that the buffer contains. 80 * 81 * Buffers are usually created with gst_buffer_new(). After a buffer has been 82 * created one will typically allocate memory for it and add it to the buffer. 83 * The following example creates a buffer that can hold a given video frame 84 * with a given width, height and bits per plane. 85 * 86 * $(DDOC_COMMENT example) 87 * 88 * Alternatively, use gst_buffer_new_allocate() 89 * to create a buffer with preallocated data of a given size. 90 * 91 * Buffers can contain a list of GstMemory objects. You can retrieve how many 92 * memory objects with gst_buffer_n_memory() and you can get a pointer 93 * to memory with gst_buffer_peek_memory() 94 * 95 * A buffer will usually have timestamps, and a duration, but neither of these 96 * are guaranteed (they may be set to GST_CLOCK_TIME_NONE). Whenever a 97 * meaningful value can be given for these, they should be set. The timestamps 98 * and duration are measured in nanoseconds (they are GstClockTime values). 99 * 100 * The buffer DTS refers to the timestamp when the buffer should be decoded and 101 * is usually monotonically increasing. The buffer PTS refers to the timestamp when 102 * the buffer content should be presented to the user and is not always 103 * monotonically increasing. 104 * 105 * A buffer can also have one or both of a start and an end offset. These are 106 * media-type specific. For video buffers, the start offset will generally be 107 * the frame number. For audio buffers, it will be the number of samples 108 * produced so far. For compressed data, it could be the byte offset in a 109 * source or destination file. Likewise, the end offset will be the offset of 110 * the end of the buffer. These can only be meaningfully interpreted if you 111 * know the media type of the buffer (the preceeding CAPS event). Either or both 112 * can be set to GST_BUFFER_OFFSET_NONE. 113 * 114 * gst_buffer_ref() is used to increase the refcount of a buffer. This must be 115 * done when you want to keep a handle to the buffer after pushing it to the 116 * next element. The buffer refcount determines the writability of the buffer, a 117 * buffer is only writable when the refcount is exactly 1, i.e. when the caller 118 * has the only reference to the buffer. 119 * 120 * To efficiently create a smaller buffer out of an existing one, you can 121 * use gst_buffer_copy_region(). This method tries to share the memory objects 122 * between the two buffers. 123 * 124 * If a plug-in wants to modify the buffer data or metadata in-place, it should 125 * first obtain a buffer that is safe to modify by using 126 * gst_buffer_make_writable(). This function is optimized so that a copy will 127 * only be made when it is necessary. 128 * 129 * Several flags of the buffer can be set and unset with the 130 * GST_BUFFER_FLAG_SET() and GST_BUFFER_FLAG_UNSET() macros. Use 131 * GST_BUFFER_FLAG_IS_SET() to test if a certain GstBufferFlag is set. 132 * 133 * Buffers can be efficiently merged into a larger buffer with 134 * gst_buffer_append(). Copying of memory will only be done when absolutely 135 * needed. 136 * 137 * Arbitrary extra metadata can be set on a buffer with gst_buffer_add_meta(). 138 * Metadata can be retrieved with gst_buffer_get_meta(). See also GstMeta 139 * 140 * An element should either unref the buffer or push it out on a src pad 141 * using gst_pad_push() (see GstPad). 142 * 143 * Buffers are usually freed by unreffing them with gst_buffer_unref(). When 144 * the refcount drops to 0, any memory and metadata pointed to by the buffer is 145 * unreffed as well. Buffers allocated from a GstBufferPool will be returned to 146 * the pool when the refcount drops to 0. 147 * 148 * Last reviewed on 2012-03-28 (0.11.3) 149 */ 150 public class Buffer 151 { 152 153 /** the main Gtk struct */ 154 protected GstBuffer* gstBuffer; 155 156 157 /** Get the main Gtk struct */ 158 public GstBuffer* getBufferStruct() 159 { 160 return gstBuffer; 161 } 162 163 164 /** the main Gtk struct as a void* */ 165 protected void* getStruct() 166 { 167 return cast(void*)gstBuffer; 168 } 169 170 /** 171 * Sets our main struct and passes it to the parent class 172 */ 173 public this (GstBuffer* gstBuffer) 174 { 175 this.gstBuffer = gstBuffer; 176 } 177 178 /** 179 * Extracts a copy of at most size bytes the data at offset into a GBytes. 180 * dest must be freed using g_free() when done. 181 * Since 1.0.10 182 * Params: 183 * offset = the offset to extract 184 * size = the size to extract 185 * dest = A pointer where 186 * the destination array will be written. [array length=dest_size][element-type guint8][out] 187 */ 188 public void extractDup(gsize offset, gsize size, out void[] dest) 189 { 190 // void gst_buffer_extract_dup (GstBuffer *buffer, gsize offset, gsize size, gpointer *dest, gsize *dest_size); 191 void* outdest = null; 192 gsize destSize; 193 194 gst_buffer_extract_dup(gstBuffer, offset, size, &outdest, &destSize); 195 196 dest = outdest[0 .. destSize]; 197 } 198 199 /** 200 */ 201 202 /** 203 * Creates a newly allocated buffer without any data. 204 * MT safe. 205 * Throws: ConstructionException GTK+ fails to create the object. 206 */ 207 public this () 208 { 209 // GstBuffer * gst_buffer_new (void); 210 auto p = gst_buffer_new(); 211 if(p is null) 212 { 213 throw new ConstructionException("null returned by gst_buffer_new()"); 214 } 215 this(cast(GstBuffer*) p); 216 } 217 218 /** 219 * Tries to create a newly allocated buffer with data of the given size and 220 * extra parameters from allocator. If the requested amount of memory can't be 221 * allocated, NULL will be returned. The allocated buffer memory is not cleared. 222 * When allocator is NULL, the default memory allocator will be used. 223 * Note that when size == 0, the buffer will not have memory associated with it. 224 * MT safe. 225 * Params: 226 * allocator = the GstAllocator to use, or NULL to use the 227 * default allocator. [transfer none][allow-none] 228 * size = the size in bytes of the new buffer's data. 229 * params = optional parameters. [transfer none][allow-none] 230 * Throws: ConstructionException GTK+ fails to create the object. 231 */ 232 public this (Allocator allocator, gsize size, GstAllocationParams* params) 233 { 234 // GstBuffer * gst_buffer_new_allocate (GstAllocator *allocator, gsize size, GstAllocationParams *params); 235 auto p = gst_buffer_new_allocate((allocator is null) ? null : allocator.getAllocatorStruct(), size, params); 236 if(p is null) 237 { 238 throw new ConstructionException("null returned by gst_buffer_new_allocate((allocator is null) ? null : allocator.getAllocatorStruct(), size, params)"); 239 } 240 this(cast(GstBuffer*) p); 241 } 242 243 /** 244 * Creates a new buffer that wraps the given data. The memory will be freed 245 * with g_free and will be marked writable. 246 * MT safe. 247 * Params: 248 * data = data to wrap. [array length=size][element-type guint8][transfer full] 249 * Throws: ConstructionException GTK+ fails to create the object. 250 */ 251 public this (void[] data) 252 { 253 // GstBuffer * gst_buffer_new_wrapped (gpointer data, gsize size); 254 auto p = gst_buffer_new_wrapped(data.ptr, cast(int) data.length); 255 if(p is null) 256 { 257 throw new ConstructionException("null returned by gst_buffer_new_wrapped(data.ptr, cast(int) data.length)"); 258 } 259 this(cast(GstBuffer*) p); 260 } 261 262 /** 263 * Allocate a new buffer that wraps the given memory. data must point to 264 * maxsize of memory, the wrapped buffer will have the region from offset and 265 * size visible. 266 * When the buffer is destroyed, notify will be called with user_data. 267 * The prefix/padding must be filled with 0 if flags contains 268 * GST_MEMORY_FLAG_ZERO_PREFIXED and GST_MEMORY_FLAG_ZERO_PADDED respectively. 269 * Params: 270 * flags = GstMemoryFlags 271 * data = data to wrap. [array length=size][element-type guint8][transfer none] 272 * maxsize = allocated size of data 273 * offset = offset in data 274 * size = size of valid data 275 * userData = user_data. [allow-none] 276 * notify = called with user_data when the memory is freed. [allow-none][scope async][closure user_data] 277 * Throws: ConstructionException GTK+ fails to create the object. 278 */ 279 public this (GstMemoryFlags flags, void* data, gsize maxsize, gsize offset, gsize size, void* userData, GDestroyNotify notify) 280 { 281 // GstBuffer * gst_buffer_new_wrapped_full (GstMemoryFlags flags, gpointer data, gsize maxsize, gsize offset, gsize size, gpointer user_data, GDestroyNotify notify); 282 auto p = gst_buffer_new_wrapped_full(flags, data, maxsize, offset, size, userData, notify); 283 if(p is null) 284 { 285 throw new ConstructionException("null returned by gst_buffer_new_wrapped_full(flags, data, maxsize, offset, size, userData, notify)"); 286 } 287 this(cast(GstBuffer*) p); 288 } 289 290 /** 291 * Increases the refcount of the given buffer by one. 292 * Note that the refcount affects the writeability 293 * of buf and its metadata, see gst_buffer_is_writable(). 294 * It is important to note that keeping additional references to 295 * GstBuffer instances can potentially increase the number 296 * of memcpy operations in a pipeline. 297 * Returns: buf. [transfer full] 298 */ 299 public Buffer doref() 300 { 301 // GstBuffer * gst_buffer_ref (GstBuffer *buf); 302 auto p = gst_buffer_ref(gstBuffer); 303 304 if(p is null) 305 { 306 return null; 307 } 308 309 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p); 310 } 311 312 /** 313 * Decreases the refcount of the buffer. If the refcount reaches 0, the buffer 314 * with the associated metadata and memory will be freed. 315 */ 316 public void unref() 317 { 318 // void gst_buffer_unref (GstBuffer *buf); 319 gst_buffer_unref(gstBuffer); 320 } 321 322 /** 323 * Get the total size of the memory blocks in b. 324 * When not NULL, offset will contain the offset of the data in the 325 * first memory block in buffer and maxsize will contain the sum of 326 * the size and offset and the amount of extra padding on the last 327 * memory block. offset and maxsize can be used to resize the 328 * buffer memory blocks with gst_buffer_resize(). 329 * Params: 330 * offset = a pointer to the offset. [out] 331 * maxsize = a pointer to the maxsize. [out] 332 * Returns: total size of the memory blocks in buffer. 333 */ 334 public gsize getSizes(out gsize offset, out gsize maxsize) 335 { 336 // gsize gst_buffer_get_sizes (GstBuffer *buffer, gsize *offset, gsize *maxsize); 337 return gst_buffer_get_sizes(gstBuffer, &offset, &maxsize); 338 } 339 340 /** 341 * Get the total size of the memory blocks in buffer. 342 * Returns: total size of the memory blocks in buffer. 343 */ 344 public gsize getSize() 345 { 346 // gsize gst_buffer_get_size (GstBuffer *buffer); 347 return gst_buffer_get_size(gstBuffer); 348 } 349 350 /** 351 * Get the total size of length memory blocks stating from idx in buffer. 352 * When not NULL, offset will contain the offset of the data in the 353 * memory block in buffer at idx and maxsize will contain the sum of the size 354 * and offset and the amount of extra padding on the memory block at idx + 355 * length -1. 356 * offset and maxsize can be used to resize the buffer memory blocks with 357 * gst_buffer_resize_range(). 358 * Params: 359 * idx = an index 360 * length = a length 361 * offset = a pointer to the offset. [out] 362 * maxsize = a pointer to the maxsize. [out] 363 * Returns: total size of length memory blocks starting at idx in buffer. 364 */ 365 public gsize getSizesRange(uint idx, int length, out gsize offset, out gsize maxsize) 366 { 367 // gsize gst_buffer_get_sizes_range (GstBuffer *buffer, guint idx, gint length, gsize *offset, gsize *maxsize); 368 return gst_buffer_get_sizes_range(gstBuffer, idx, length, &offset, &maxsize); 369 } 370 371 /** 372 * Set the total size of the length memory blocks starting at idx in 373 * buffer 374 * Params: 375 * idx = an index 376 * length = a length 377 * offset = the offset adjustement 378 * size = the new size or -1 to just adjust the offset 379 * Returns: TRUE if resizing succeeded, FALSE otherwise. 380 */ 381 public int resizeRange(uint idx, int length, gssize offset, gssize size) 382 { 383 // gboolean gst_buffer_resize_range (GstBuffer *buffer, guint idx, gint length, gssize offset, gssize size); 384 return gst_buffer_resize_range(gstBuffer, idx, length, offset, size); 385 } 386 387 /** 388 * Set the offset and total size of the memory blocks in buffer. 389 * Params: 390 * offset = the offset adjustement 391 * size = the new size or -1 to just adjust the offset 392 */ 393 public void resize(gssize offset, gssize size) 394 { 395 // void gst_buffer_resize (GstBuffer *buffer, gssize offset, gssize size); 396 gst_buffer_resize(gstBuffer, offset, size); 397 } 398 399 /** 400 * Set the total size of the memory blocks in buffer. 401 * Params: 402 * size = the new size 403 */ 404 public void setSize(gssize size) 405 { 406 // void gst_buffer_set_size (GstBuffer *buffer, gssize size); 407 gst_buffer_set_size(gstBuffer, size); 408 } 409 410 /** 411 * Get the memory block at idx in buffer. The memory block stays valid until 412 * the memory block in buffer is removed, replaced or merged, typically with 413 * any call that modifies the memory in buffer. 414 * Since this call does not influence the refcount of the memory, 415 * gst_memory_is_writable() can be used to check if buffer is the sole owner 416 * of the returned memory. 417 * Params: 418 * idx = an index 419 * Returns: the GstMemory at idx. [transfer none] 420 */ 421 public Memory peekMemory(uint idx) 422 { 423 // GstMemory * gst_buffer_peek_memory (GstBuffer *buffer, guint idx); 424 auto p = gst_buffer_peek_memory(gstBuffer, idx); 425 426 if(p is null) 427 { 428 return null; 429 } 430 431 return ObjectG.getDObject!(Memory)(cast(GstMemory*) p); 432 } 433 434 /** 435 * Get the amount of memory blocks that this buffer has. This amount is never 436 * larger than what gst_buffer_get_max_memory() returns. 437 * Returns: the amount of memory block in this buffer. [transfer full] 438 */ 439 public uint nMemory() 440 { 441 // guint gst_buffer_n_memory (GstBuffer *buffer); 442 return gst_buffer_n_memory(gstBuffer); 443 } 444 445 /** 446 * Insert the memory block mem to buffer at idx. This function takes ownership 447 * of mem and thus doesn't increase its refcount. 448 * Only gst_buffer_get_max_memory() can be added to a buffer. If more memory is 449 * added, existing memory blocks will automatically be merged to make room for 450 * the new memory. 451 * Params: 452 * idx = the index to add the memory at, or -1 to append it to the end 453 * mem = a GstMemory. [transfer full] 454 */ 455 public void insertMemory(int idx, Memory mem) 456 { 457 // void gst_buffer_insert_memory (GstBuffer *buffer, gint idx, GstMemory *mem); 458 gst_buffer_insert_memory(gstBuffer, idx, (mem is null) ? null : mem.getMemoryStruct()); 459 } 460 461 /** 462 * Replaces length memory blocks in buffer starting at idx with mem. 463 * If length is -1, all memory starting from idx will be removed and 464 * replaced with mem. 465 * buffer should be writable. 466 * Params: 467 * idx = an index 468 * length = a length should not be 0 469 * mem = a GstMemory. [transfer full] 470 */ 471 public void replaceMemoryRange(uint idx, int length, Memory mem) 472 { 473 // void gst_buffer_replace_memory_range (GstBuffer *buffer, guint idx, gint length, GstMemory *mem); 474 gst_buffer_replace_memory_range(gstBuffer, idx, length, (mem is null) ? null : mem.getMemoryStruct()); 475 } 476 477 /** 478 * Get length memory blocks in buffer starting at idx. The memory blocks will 479 * be merged into one large GstMemory. 480 * If length is -1, all memory starting from idx is merged. 481 * Params: 482 * idx = an index 483 * length = a length 484 * Returns: a GstMemory that contains the merged data of length blocks starting at idx. Use gst_memory_unref() after usage. [transfer full] 485 */ 486 public Memory getMemoryRange(uint idx, int length) 487 { 488 // GstMemory * gst_buffer_get_memory_range (GstBuffer *buffer, guint idx, gint length); 489 auto p = gst_buffer_get_memory_range(gstBuffer, idx, length); 490 491 if(p is null) 492 { 493 return null; 494 } 495 496 return ObjectG.getDObject!(Memory)(cast(GstMemory*) p); 497 } 498 499 /** 500 * Remove length memory blocks in buffer starting from idx. 501 * length can be -1, in which case all memory starting from idx is removed. 502 * Params: 503 * idx = an index 504 * length = a length 505 */ 506 public void removeMemoryRange(uint idx, int length) 507 { 508 // void gst_buffer_remove_memory_range (GstBuffer *buffer, guint idx, gint length); 509 gst_buffer_remove_memory_range(gstBuffer, idx, length); 510 } 511 512 /** 513 * Find the memory blocks that span size bytes starting from offset 514 * in buffer. 515 * When this function returns TRUE, idx will contain the index of the first 516 * memory bock where the byte for offset can be found and length contains the 517 * number of memory blocks containing the size remaining bytes. skip contains 518 * the number of bytes to skip in the memory bock at idx to get to the byte 519 * for offset. 520 * size can be -1 to get all the memory blocks after idx. 521 * Params: 522 * offset = an offset 523 * size = a size 524 * idx = pointer to index. [out] 525 * length = pointer to length. [out] 526 * skip = pointer to skip. [out] 527 * Returns: TRUE when size bytes starting from offset could be found in buffer and idx, length and skip will be filled. 528 */ 529 public int findMemory(gsize offset, gsize size, out uint idx, out uint length, out gsize skip) 530 { 531 // gboolean gst_buffer_find_memory (GstBuffer *buffer, gsize offset, gsize size, guint *idx, guint *length, gsize *skip); 532 return gst_buffer_find_memory(gstBuffer, offset, size, &idx, &length, &skip); 533 } 534 535 /** 536 * Prepend the memory block mem to buffer. This function takes 537 * ownership of mem and thus doesn't increase its refcount. 538 * This function is identical to gst_buffer_insert_memory() with an index of 0. 539 * See gst_buffer_insert_memory() for more details. 540 * Params: 541 * mem = a GstMemory. [transfer full] 542 */ 543 public void prependMemory(Memory mem) 544 { 545 // void gst_buffer_prepend_memory (GstBuffer *buffer, GstMemory *mem); 546 gst_buffer_prepend_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct()); 547 } 548 549 /** 550 * Append the memory block mem to buffer. This function takes 551 * ownership of mem and thus doesn't increase its refcount. 552 * This function is identical to gst_buffer_insert_memory() with an index of -1. 553 * See gst_buffer_insert_memory() for more details. 554 * Params: 555 * mem = a GstMemory. [transfer full] 556 */ 557 public void appendMemory(Memory mem) 558 { 559 // void gst_buffer_append_memory (GstBuffer *buffer, GstMemory *mem); 560 gst_buffer_append_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct()); 561 } 562 563 /** 564 * Replaces the memory block at index idx in buffer with mem. 565 * Params: 566 * idx = an index 567 * mem = a GstMemory. [transfer full] 568 */ 569 public void replaceMemory(uint idx, Memory mem) 570 { 571 // void gst_buffer_replace_memory (GstBuffer *buffer, guint idx, GstMemory *mem); 572 gst_buffer_replace_memory(gstBuffer, idx, (mem is null) ? null : mem.getMemoryStruct()); 573 } 574 575 /** 576 * Replaces all memory in buffer with mem. 577 * Params: 578 * mem = a GstMemory. [transfer full] 579 */ 580 public void replaceAllMemory(Memory mem) 581 { 582 // void gst_buffer_replace_all_memory (GstBuffer *buffer, GstMemory *mem); 583 gst_buffer_replace_all_memory(gstBuffer, (mem is null) ? null : mem.getMemoryStruct()); 584 } 585 586 /** 587 * Get the memory block at index idx in buffer. 588 * Params: 589 * idx = an index 590 * Returns: a GstMemory that contains the data of the memory block at idx. Use gst_memory_unref() after usage. [transfer full] 591 */ 592 public Memory getMemory(uint idx) 593 { 594 // GstMemory * gst_buffer_get_memory (GstBuffer *buffer, guint idx); 595 auto p = gst_buffer_get_memory(gstBuffer, idx); 596 597 if(p is null) 598 { 599 return null; 600 } 601 602 return ObjectG.getDObject!(Memory)(cast(GstMemory*) p); 603 } 604 605 /** 606 * Get all the memory block in buffer. The memory blocks will be merged 607 * into one large GstMemory. 608 * Returns: a GstMemory that contains the merged memory. Use gst_memory_unref() after usage. [transfer full] 609 */ 610 public Memory getAllMemory() 611 { 612 // GstMemory * gst_buffer_get_all_memory (GstBuffer *buffer); 613 auto p = gst_buffer_get_all_memory(gstBuffer); 614 615 if(p is null) 616 { 617 return null; 618 } 619 620 return ObjectG.getDObject!(Memory)(cast(GstMemory*) p); 621 } 622 623 /** 624 * Remove the memory block in b at index i. 625 * Params: 626 * idx = an index 627 */ 628 public void removeMemory(uint idx) 629 { 630 // void gst_buffer_remove_memory (GstBuffer *buffer, guint idx); 631 gst_buffer_remove_memory(gstBuffer, idx); 632 } 633 634 /** 635 * Remove all the memory blocks in buffer. 636 */ 637 public void removeAllMemory() 638 { 639 // void gst_buffer_remove_all_memory (GstBuffer *buffer); 640 gst_buffer_remove_all_memory(gstBuffer); 641 } 642 643 /** 644 * This function fills info with the GstMapInfo of all merged memory 645 * blocks in buffer. 646 * flags describe the desired access of the memory. When flags is 647 * GST_MAP_WRITE, buffer should be writable (as returned from 648 * gst_buffer_is_writable()). 649 * When buffer is writable but the memory isn't, a writable copy will 650 * automatically be created and returned. The readonly copy of the 651 * buffer memory will then also be replaced with this writable copy. 652 * The memory in info should be unmapped with gst_buffer_unmap() after 653 * usage. 654 * Params: 655 * info = info about the mapping. [out] 656 * flags = flags for the mapping 657 * Returns: TRUE if the map succeeded and info contains valid data. 658 */ 659 public int map(out GstMapInfo info, GstMapFlags flags) 660 { 661 // gboolean gst_buffer_map (GstBuffer *buffer, GstMapInfo *info, GstMapFlags flags); 662 return gst_buffer_map(gstBuffer, &info, flags); 663 } 664 665 /** 666 * This function fills info with the GstMapInfo of length merged memory blocks 667 * starting at idx in buffer. When length is -1, all memory blocks starting 668 * from idx are merged and mapped. 669 * flags describe the desired access of the memory. When flags is 670 * GST_MAP_WRITE, buffer should be writable (as returned from 671 * gst_buffer_is_writable()). 672 * When buffer is writable but the memory isn't, a writable copy will 673 * automatically be created and returned. The readonly copy of the buffer memory 674 * will then also be replaced with this writable copy. 675 * The memory in info should be unmapped with gst_buffer_unmap() after usage. 676 * Params: 677 * idx = an index 678 * length = a length 679 * info = info about the mapping. [out] 680 * flags = flags for the mapping 681 * Returns: TRUE if the map succeeded and info contains valid data. 682 */ 683 public int mapRange(uint idx, int length, out GstMapInfo info, GstMapFlags flags) 684 { 685 // gboolean gst_buffer_map_range (GstBuffer *buffer, guint idx, gint length, GstMapInfo *info, GstMapFlags flags); 686 return gst_buffer_map_range(gstBuffer, idx, length, &info, flags); 687 } 688 689 /** 690 * Release the memory previously mapped with gst_buffer_map(). 691 * Params: 692 * info = a GstMapInfo 693 */ 694 public void unmap(ref GstMapInfo info) 695 { 696 // void gst_buffer_unmap (GstBuffer *buffer, GstMapInfo *info); 697 gst_buffer_unmap(gstBuffer, &info); 698 } 699 700 /** 701 * Compare size bytes starting from offset in buffer with the memory in mem. 702 * Params: 703 * offset = the offset in buffer 704 * mem = the memory to compare. [array length=size][element-type guint8] 705 * size = the size to compare 706 * Returns: 0 if the memory is equal. 707 */ 708 public int memcmp(gsize offset, void[] mem) 709 { 710 // gint gst_buffer_memcmp (GstBuffer *buffer, gsize offset, gconstpointer mem, gsize size); 711 return gst_buffer_memcmp(gstBuffer, offset, mem.ptr, cast(int) mem.length); 712 } 713 714 /** 715 * Copy size bytes starting from offset in buffer to dest. 716 * Params: 717 * offset = the offset to extract 718 * dest = the destination address 719 * size = the size to extract 720 * Returns: The amount of bytes extracted. This value can be lower than size when buffer did not contain enough data. 721 */ 722 public gsize extract(gsize offset, void[] dest) 723 { 724 // gsize gst_buffer_extract (GstBuffer *buffer, gsize offset, gpointer dest, gsize size); 725 return gst_buffer_extract(gstBuffer, offset, dest.ptr, cast(int) dest.length); 726 } 727 728 /** 729 * Copy size bytes from src to buffer at offset. 730 * Params: 731 * offset = the offset to fill 732 * src = the source address. [array length=size][element-type guint8] 733 * size = the size to fill 734 * Returns: The amount of bytes copied. This value can be lower than size when buffer did not contain enough data. 735 */ 736 public gsize fill(gsize offset, void[] src) 737 { 738 // gsize gst_buffer_fill (GstBuffer *buffer, gsize offset, gconstpointer src, gsize size); 739 return gst_buffer_fill(gstBuffer, offset, src.ptr, cast(int) src.length); 740 } 741 742 /** 743 * Fill buf with size bytes with val starting from offset. 744 * Params: 745 * offset = the offset in buffer 746 * val = the value to set 747 * size = the size to set 748 * Returns: The amount of bytes filled. This value can be lower than size when buffer did not contain enough data. 749 */ 750 public gsize memset(gsize offset, ubyte val, gsize size) 751 { 752 // gsize gst_buffer_memset (GstBuffer *buffer, gsize offset, guint8 val, gsize size); 753 return gst_buffer_memset(gstBuffer, offset, val, size); 754 } 755 756 /** 757 * Create a copy of the given buffer. This will also make a newly allocated 758 * copy of the data the source buffer contains. 759 * Returns: a new copy of buf. [transfer full] 760 */ 761 public Buffer copy() 762 { 763 // GstBuffer * gst_buffer_copy (const GstBuffer *buf); 764 auto p = gst_buffer_copy(gstBuffer); 765 766 if(p is null) 767 { 768 return null; 769 } 770 771 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p); 772 } 773 774 /** 775 * Copies the information from src into dest. 776 * If dest already contains memory and flags contains GST_BUFFER_COPY_MEMORY, 777 * the memory from src will be appended to dest. 778 * flags indicate which fields will be copied. 779 * Params: 780 * src = a source GstBuffer 781 * flags = flags indicating what metadata fields should be copied. 782 * offset = offset to copy from 783 * size = total size to copy. If -1, all data is copied. 784 * Returns: TRUE if the copying succeeded, FALSE otherwise. 785 */ 786 public int copyInto(Buffer src, GstBufferCopyFlags flags, gsize offset, gsize size) 787 { 788 // gboolean gst_buffer_copy_into (GstBuffer *dest, GstBuffer *src, GstBufferCopyFlags flags, gsize offset, gsize size); 789 return gst_buffer_copy_into(gstBuffer, (src is null) ? null : src.getBufferStruct(), flags, offset, size); 790 } 791 792 /** 793 * Creates a sub-buffer from parent at offset and size. 794 * This sub-buffer uses the actual memory space of the parent buffer. 795 * This function will copy the offset and timestamp fields when the 796 * offset is 0. If not, they will be set to GST_CLOCK_TIME_NONE and 797 * GST_BUFFER_OFFSET_NONE. 798 * If offset equals 0 and size equals the total size of buffer, the 799 * duration and offset end fields are also copied. If not they will be set 800 * to GST_CLOCK_TIME_NONE and GST_BUFFER_OFFSET_NONE. 801 * MT safe. 802 * Params: 803 * flags = the GstBufferCopyFlags 804 * offset = the offset into parent GstBuffer at which the new sub-buffer 805 * begins. 806 * size = the size of the new GstBuffer sub-buffer, in bytes. 807 * Returns: the new GstBuffer or NULL if the arguments were invalid. [transfer full] 808 */ 809 public Buffer copyRegion(GstBufferCopyFlags flags, gsize offset, gsize size) 810 { 811 // GstBuffer * gst_buffer_copy_region (GstBuffer *parent, GstBufferCopyFlags flags, gsize offset, gsize size); 812 auto p = gst_buffer_copy_region(gstBuffer, flags, offset, size); 813 814 if(p is null) 815 { 816 return null; 817 } 818 819 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p); 820 } 821 822 /** 823 * Modifies a pointer to a GstBuffer to point to a different GstBuffer. The 824 * modification is done atomically (so this is useful for ensuring thread safety 825 * in some cases), and the reference counts are updated appropriately (the old 826 * buffer is unreffed, the new is reffed). 827 * Either nbuf or the GstBuffer pointed to by obuf may be NULL. 828 * Params: 829 * obuf = pointer to a pointer to a GstBuffer to be 830 * replaced. [inout][transfer full] 831 * nbuf = pointer to a GstBuffer that will 832 * replace the buffer pointed to by obuf. [transfer none][allow-none] 833 * Returns: TRUE when obuf was different from nbuf. 834 */ 835 public static int replace(ref Buffer obuf, Buffer nbuf) 836 { 837 // gboolean gst_buffer_replace (GstBuffer **obuf, GstBuffer *nbuf); 838 GstBuffer* outobuf = (obuf is null) ? null : obuf.getBufferStruct(); 839 840 auto p = gst_buffer_replace(&outobuf, (nbuf is null) ? null : nbuf.getBufferStruct()); 841 842 obuf = ObjectG.getDObject!(Buffer)(outobuf); 843 return p; 844 } 845 846 /** 847 * Append all the memory from buf2 to buf1. The result buffer will contain a 848 * concatenation of the memory of buf1 and buf2. 849 * Params: 850 * buf2 = the second source GstBuffer to append. [transfer full] 851 * Returns: the new GstBuffer that contains the memory of the two source buffers. [transfer full] 852 */ 853 public Buffer append(Buffer buf2) 854 { 855 // GstBuffer * gst_buffer_append (GstBuffer *buf1, GstBuffer *buf2); 856 auto p = gst_buffer_append(gstBuffer, (buf2 is null) ? null : buf2.getBufferStruct()); 857 858 if(p is null) 859 { 860 return null; 861 } 862 863 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p); 864 } 865 866 /** 867 * Append size bytes at offset from buf2 to buf1. The result buffer will 868 * contain a concatenation of the memory of buf1 and the requested region of 869 * buf2. 870 * Params: 871 * buf2 = the second source GstBuffer to append. [transfer full] 872 * offset = the offset in buf2 873 * size = the size or -1 of buf2 874 * Returns: the new GstBuffer that contains the memory of the two source buffers. [transfer full] 875 */ 876 public Buffer appendRegion(Buffer buf2, gssize offset, gssize size) 877 { 878 // GstBuffer * gst_buffer_append_region (GstBuffer *buf1, GstBuffer *buf2, gssize offset, gssize size); 879 auto p = gst_buffer_append_region(gstBuffer, (buf2 is null) ? null : buf2.getBufferStruct(), offset, size); 880 881 if(p is null) 882 { 883 return null; 884 } 885 886 return ObjectG.getDObject!(Buffer)(cast(GstBuffer*) p); 887 } 888 889 /** 890 * Get the metadata for api on buffer. When there is no such 891 * metadata, NULL is returned. 892 * Params: 893 * api = the GType of an API 894 * Returns: the metadata for api on buffer. [transfer none] 895 */ 896 public GstMeta* getMeta(GType api) 897 { 898 // GstMeta * gst_buffer_get_meta (GstBuffer *buffer, GType api); 899 return gst_buffer_get_meta(gstBuffer, api); 900 } 901 902 /** 903 * Add metadata for info to buffer using the parameters in params. 904 * Params: 905 * info = a GstMetaInfo 906 * params = params for info 907 * Returns: the metadata for the api in info on buffer. [transfer none] 908 */ 909 public GstMeta* addMeta(GstMetaInfo* info, void* params) 910 { 911 // GstMeta * gst_buffer_add_meta (GstBuffer *buffer, const GstMetaInfo *info, gpointer params); 912 return gst_buffer_add_meta(gstBuffer, info, params); 913 } 914 915 /** 916 * Remove the metadata for meta on buffer. 917 * Params: 918 * meta = a GstMeta 919 * Returns: TRUE if the metadata existed and was removed, FALSE if no such metadata was on buffer. 920 */ 921 public int removeMeta(GstMeta* meta) 922 { 923 // gboolean gst_buffer_remove_meta (GstBuffer *buffer, GstMeta *meta); 924 return gst_buffer_remove_meta(gstBuffer, meta); 925 } 926 927 /** 928 * Retrieve the next GstMeta after current. If state points 929 * to NULL, the first metadata is returned. 930 * state will be updated with an opage state pointer 931 * Params: 932 * state = an opaque state pointer 933 * Returns: The next GstMeta or NULL when there are no more items. [transfer none] 934 */ 935 public GstMeta* iterateMeta(void** state) 936 { 937 // GstMeta * gst_buffer_iterate_meta (GstBuffer *buffer, gpointer *state); 938 return gst_buffer_iterate_meta(gstBuffer, state); 939 } 940 941 /** 942 * Call func with user_data for each meta in buffer. 943 * func can modify the passed meta pointer or its contents. The return value 944 * of func define if this function returns or if the remaining metadata items 945 * in the buffer should be skipped. 946 * Params: 947 * func = a GstBufferForeachMetaFunc to call. [scope call] 948 * userData = user data passed to func. [closure] 949 * Returns: FALSE when func returned FALSE for one of the metadata. 950 */ 951 public int foreachMeta(GstBufferForeachMetaFunc func, void* userData) 952 { 953 // gboolean gst_buffer_foreach_meta (GstBuffer *buffer, GstBufferForeachMetaFunc func, gpointer user_data); 954 return gst_buffer_foreach_meta(gstBuffer, func, userData); 955 } 956 }