Created
November 11, 2014 06:04
-
-
Save yashi/759ace2a249e75d2ca18 to your computer and use it in GitHub Desktop.
Appending GstBuffers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -*- compile-command: "gcc -Wall -Wextra -g $(pkg-config --cflags --libs gstreamer-1.0) a.c" -*- */ | |
#include <gst/gst.h> | |
void dump_buf(GstBuffer *buf) | |
{ | |
gsize max; | |
gsize bufsize; | |
gsize offset; | |
bufsize = gst_buffer_get_sizes(buf, &offset, &max); | |
g_message("%p", buf); | |
g_message(" size: %" G_GSIZE_FORMAT, bufsize); | |
g_message(" max: %" G_GSIZE_FORMAT, max); | |
g_message(" offset : %" G_GSIZE_FORMAT, offset); | |
g_message(" ref: %d", GST_MINI_OBJECT_REFCOUNT_VALUE(buf)); | |
} | |
int main(int argc, char *argv[]) | |
{ | |
GstBuffer *buf1; | |
GstBuffer *buf2; | |
GstBuffer *buf3; | |
char *s; | |
gst_init(&argc, &argv); | |
buf1 = gst_buffer_new_allocate(NULL, 10, NULL); | |
gst_buffer_fill(buf1, 0, "0123456789", 10); | |
dump_buf(buf1); | |
buf2 = gst_buffer_new_allocate(NULL, 6, NULL); | |
gst_buffer_fill(buf2, 0, "abcdef", 6); | |
dump_buf(buf2); | |
/* | |
* all bufs (buf1, buf2 and buf3) are "transfer full", meaning | |
* that: a. both argument is not accessible after the call | |
* (might be freed by the function), b. the memory region for | |
* the buf3 is caller's responsibility. The function might | |
* return the address of buf2, but that's just a coincidence | |
* from API's point of view. | |
*/ | |
buf3 = gst_buffer_append(buf2, buf1); | |
dump_buf(buf3); | |
s = g_new0(char, 17); | |
gst_buffer_extract(buf2, 0, s, 17); | |
g_message("%s", s); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment