mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 22:36:33 +00:00
Add new GstMapInfo
Use a structure to hold info about the mapping. The application then keeps track of this state and we can use it to unmap the memory again later.
This commit is contained in:
parent
ea7c1225c1
commit
a521252845
32 changed files with 645 additions and 636 deletions
|
@ -56,12 +56,12 @@ cb_have_data (GstPad *pad,
|
|||
gpointer u_data)
|
||||
{
|
||||
gint x, y;
|
||||
guint16 *data, *ptr, t;
|
||||
gsize size;
|
||||
GstMapInfo info;
|
||||
guint16 *ptr, t;
|
||||
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_WRITE);
|
||||
gst_buffer_map (buffer, &info, GST_MAP_WRITE);
|
||||
|
||||
ptr = data;
|
||||
ptr = info.data;
|
||||
/* invert data */
|
||||
for (y = 0; y < 288; y++) {
|
||||
for (x = 0; x < 384 / 2; x++) {
|
||||
|
@ -71,8 +71,7 @@ cb_have_data (GstPad *pad,
|
|||
}
|
||||
ptr += 384;
|
||||
}
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -288,16 +287,15 @@ cb_handoff (GstElement *fakesrc,
|
|||
gpointer user_data)
|
||||
{
|
||||
static gboolean white = FALSE;
|
||||
gpointer data;
|
||||
gsize size;
|
||||
GstMapInfo info;
|
||||
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_WRITE);
|
||||
gst_buffer_map (buffer, &info, GST_MAP_WRITE);
|
||||
|
||||
/* this makes the image black/white */
|
||||
memset (data, white ? 0xff : 0x0, size);
|
||||
memset (info.data, white ? 0xff : 0x0, info.size);
|
||||
white = !white;
|
||||
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
}
|
||||
|
||||
gint
|
||||
|
|
261
gst/gstbuffer.c
261
gst/gstbuffer.c
|
@ -177,8 +177,8 @@ _replace_memory (GstBuffer * buffer, GstMemory * mem)
|
|||
{
|
||||
gsize len, i;
|
||||
|
||||
/* unref old buffers */
|
||||
len = GST_BUFFER_MEM_LEN (buffer);
|
||||
/* unref old buffers */
|
||||
for (i = 0; i < len; i++)
|
||||
gst_memory_unref (GST_BUFFER_MEM_PTR (buffer, i));
|
||||
|
||||
|
@ -745,6 +745,42 @@ gst_buffer_remove_memory_range (GstBuffer * buffer, guint idx, guint length)
|
|||
GST_BUFFER_MEM_LEN (buffer) = len - length;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_buffer_get_merged_memory:
|
||||
* @buffer: a #GstBuffer.
|
||||
*
|
||||
* Return a #GstMemory object that contains all the memory in @buffer. If there
|
||||
* was only one memory in @buffer, it will be returned directly, otherwise all
|
||||
* memory objects will be merged into one object that will be returned.
|
||||
*
|
||||
* Returns: a #GstMemory with the merged memory in @buffer. This function can
|
||||
* return %NULL if there is no memory in @buffer. Use gst_memory_unref() after
|
||||
* usage.
|
||||
*/
|
||||
static GstMemory *
|
||||
gst_buffer_get_merged_memory (GstBuffer * buffer)
|
||||
{
|
||||
guint len;
|
||||
GstMemory *mem;
|
||||
|
||||
g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
|
||||
|
||||
len = GST_BUFFER_MEM_LEN (buffer);
|
||||
|
||||
if (G_UNLIKELY (len == 0)) {
|
||||
/* no memory */
|
||||
mem = NULL;
|
||||
} else if (G_LIKELY (len == 1)) {
|
||||
/* we can take the first one */
|
||||
mem = GST_BUFFER_MEM_PTR (buffer, 0);
|
||||
gst_memory_ref (mem);
|
||||
} else {
|
||||
/* we need to span memory */
|
||||
mem = _span_memory (buffer, 0, -1, FALSE);
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_buffer_get_sizes:
|
||||
* @buffer: a #GstBuffer.
|
||||
|
@ -892,17 +928,13 @@ gst_buffer_resize (GstBuffer * buffer, gssize offset, gssize size)
|
|||
/**
|
||||
* gst_buffer_map:
|
||||
* @buffer: a #GstBuffer.
|
||||
* @size: (out) (allow-none): a location for the size
|
||||
* @maxsize: (out) (allow-none): a location for the max size
|
||||
* @info: (out): info about the mapping
|
||||
* @flags: flags for the mapping
|
||||
*
|
||||
* This function return a pointer to the memory in @buffer. @flags describe the
|
||||
* desired access of the memory. When @flags is #GST_MAP_WRITE, @buffer should
|
||||
* be writable (as returned from gst_buffer_is_writable()).
|
||||
*
|
||||
* @size and @maxsize will contain the current valid number of bytes in the
|
||||
* returned memory area and the total maximum mount of bytes available in the
|
||||
* returned memory area respectively. Both parameters can be %NULL.
|
||||
* This function fills @info with a pointer to the merged memory in @buffer.
|
||||
* @flags describe the desired access of the memory. When @flags is
|
||||
* #GST_MAP_WRITE, @buffer should be writable (as returned from
|
||||
* gst_buffer_is_writable()).
|
||||
*
|
||||
* When @buffer is writable but the memory isn't, a writable copy will
|
||||
* automatically be created and returned. The readonly copy of the buffer memory
|
||||
|
@ -911,18 +943,17 @@ gst_buffer_resize (GstBuffer * buffer, gssize offset, gssize size)
|
|||
* When the buffer contains multiple memory blocks, the returned pointer will be
|
||||
* a concatenation of the memory blocks.
|
||||
*
|
||||
* Returns: (transfer none): a pointer to the memory for the buffer.
|
||||
* Returns: (transfer full): %TRUE if the map succeeded and @info contains valid
|
||||
* data.
|
||||
*/
|
||||
gpointer
|
||||
gst_buffer_map (GstBuffer * buffer, gsize * size, gsize * maxsize,
|
||||
GstMapFlags flags)
|
||||
gboolean
|
||||
gst_buffer_map (GstBuffer * buffer, GstMapInfo * info, GstMapFlags flags)
|
||||
{
|
||||
guint len;
|
||||
gpointer data;
|
||||
GstMemory *mem;
|
||||
gboolean write, writable;
|
||||
|
||||
g_return_val_if_fail (GST_IS_BUFFER (buffer), NULL);
|
||||
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
||||
g_return_val_if_fail (info != NULL, FALSE);
|
||||
|
||||
write = (flags & GST_MAP_WRITE) != 0;
|
||||
writable = gst_buffer_is_writable (buffer);
|
||||
|
@ -931,97 +962,72 @@ gst_buffer_map (GstBuffer * buffer, gsize * size, gsize * maxsize,
|
|||
if (G_UNLIKELY (write && !writable))
|
||||
goto not_writable;
|
||||
|
||||
len = GST_BUFFER_MEM_LEN (buffer);
|
||||
mem = gst_buffer_get_merged_memory (buffer);
|
||||
if (mem == NULL)
|
||||
goto no_memory;
|
||||
|
||||
if (G_UNLIKELY (len == 0)) {
|
||||
/* no memory, return immediately */
|
||||
if (size)
|
||||
*size = 0;
|
||||
if (maxsize)
|
||||
*maxsize = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (G_LIKELY (len == 1)) {
|
||||
/* we can take the first one */
|
||||
mem = GST_BUFFER_MEM_PTR (buffer, 0);
|
||||
} else {
|
||||
/* we need to span memory */
|
||||
if (writable) {
|
||||
/* if we can write, we can change the memory with the spanned
|
||||
* memory */
|
||||
mem = _span_memory (buffer, 0, -1, write);
|
||||
_replace_memory (buffer, mem);
|
||||
} else {
|
||||
gsize bsize;
|
||||
|
||||
/* extract all data in new memory, FIXME slow!! */
|
||||
bsize = gst_buffer_get_size (buffer);
|
||||
|
||||
data = g_malloc (bsize);
|
||||
gst_buffer_extract (buffer, 0, data, bsize);
|
||||
if (size)
|
||||
*size = bsize;
|
||||
if (maxsize)
|
||||
*maxsize = bsize;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
if (G_UNLIKELY (write && !gst_memory_is_writable (mem))) {
|
||||
/* now try to map */
|
||||
if (!gst_memory_map (mem, info, flags) && write) {
|
||||
GstMemory *copy;
|
||||
/* replace with a writable copy */
|
||||
/* make a (writable) copy */
|
||||
copy = gst_memory_copy (mem, 0, -1);
|
||||
GST_BUFFER_MEM_PTR (buffer, 0) = copy;
|
||||
gst_memory_unref (mem);
|
||||
mem = copy;
|
||||
if (G_UNLIKELY (mem == NULL))
|
||||
goto cannot_map;
|
||||
|
||||
/* try again */
|
||||
if (!gst_memory_map (mem, info, flags))
|
||||
goto cannot_map;
|
||||
}
|
||||
|
||||
data = gst_memory_map (mem, size, maxsize, flags);
|
||||
/* if the buffer is writable, replace the memory */
|
||||
if (writable)
|
||||
_replace_memory (buffer, gst_memory_ref (mem));
|
||||
|
||||
return data;
|
||||
return TRUE;
|
||||
|
||||
/* ERROR */
|
||||
not_writable:
|
||||
{
|
||||
g_return_val_if_fail (gst_buffer_is_writable (buffer), NULL);
|
||||
return NULL;
|
||||
g_critical ("write map requested on non-writable buffer");
|
||||
return FALSE;
|
||||
}
|
||||
no_memory:
|
||||
{
|
||||
/* empty buffer, we need to return NULL */
|
||||
GST_DEBUG_OBJECT (buffer, "can't get buffer memory");
|
||||
info->memory = NULL;
|
||||
info->data = NULL;
|
||||
info->size = 0;
|
||||
info->maxsize = 0;
|
||||
return TRUE;
|
||||
}
|
||||
cannot_map:
|
||||
{
|
||||
GST_DEBUG_OBJECT (buffer, "cannot map memory");
|
||||
gst_memory_unref (mem);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_buffer_unmap:
|
||||
* @buffer: a #GstBuffer.
|
||||
* @data: the previously mapped data
|
||||
* @size: the size of @data, or -1
|
||||
* @info: a #GstMapInfo
|
||||
*
|
||||
* Release the memory previously mapped with gst_buffer_map(). Pass -1 to size
|
||||
* if no update is needed.
|
||||
*
|
||||
* Returns: #TRUE on success. #FALSE can be returned when the new size is larger
|
||||
* than the maxsize of the memory.
|
||||
* Release the memory previously mapped with gst_buffer_map().
|
||||
*/
|
||||
gboolean
|
||||
gst_buffer_unmap (GstBuffer * buffer, gpointer data, gssize size)
|
||||
void
|
||||
gst_buffer_unmap (GstBuffer * buffer, GstMapInfo * info)
|
||||
{
|
||||
guint len;
|
||||
g_return_if_fail (GST_IS_BUFFER (buffer));
|
||||
g_return_if_fail (info != NULL);
|
||||
|
||||
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
||||
g_return_val_if_fail (size >= -1, FALSE);
|
||||
|
||||
len = GST_BUFFER_MEM_LEN (buffer);
|
||||
|
||||
if (G_LIKELY (len == 1)) {
|
||||
GstMemory *mem = GST_BUFFER_MEM_PTR (buffer, 0);
|
||||
|
||||
gst_memory_unmap (mem);
|
||||
} else {
|
||||
/* this must have been from read-only access. After _map, the buffer either
|
||||
* only contains 1 memory block or it allocated memory to join memory
|
||||
* blocks. It's not allowed to add buffers between _map and _unmap. */
|
||||
g_free (data);
|
||||
if (info->memory) {
|
||||
gst_memory_unmap (info->memory, info);
|
||||
gst_memory_unref (info->memory);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1051,25 +1057,25 @@ gst_buffer_fill (GstBuffer * buffer, gsize offset, gconstpointer src,
|
|||
left = size;
|
||||
|
||||
for (i = 0; i < len && left > 0; i++) {
|
||||
guint8 *data;
|
||||
gsize ssize, tocopy;
|
||||
GstMapInfo info;
|
||||
gsize tocopy;
|
||||
GstMemory *mem;
|
||||
|
||||
mem = _get_memory (buffer, i, TRUE);
|
||||
|
||||
data = gst_memory_map (mem, &ssize, NULL, GST_MAP_WRITE);
|
||||
if (ssize > offset) {
|
||||
gst_memory_map (mem, &info, GST_MAP_WRITE);
|
||||
if (info.size > offset) {
|
||||
/* we have enough */
|
||||
tocopy = MIN (ssize - offset, left);
|
||||
memcpy (data + offset, ptr, tocopy);
|
||||
tocopy = MIN (info.size - offset, left);
|
||||
memcpy ((guint8 *) info.data + offset, ptr, tocopy);
|
||||
left -= tocopy;
|
||||
ptr += tocopy;
|
||||
offset = 0;
|
||||
} else {
|
||||
/* offset past buffer, skip */
|
||||
offset -= ssize;
|
||||
offset -= info.size;
|
||||
}
|
||||
gst_memory_unmap (mem);
|
||||
gst_memory_unmap (mem, &info);
|
||||
}
|
||||
return size - left;
|
||||
}
|
||||
|
@ -1099,25 +1105,25 @@ gst_buffer_extract (GstBuffer * buffer, gsize offset, gpointer dest, gsize size)
|
|||
left = size;
|
||||
|
||||
for (i = 0; i < len && left > 0; i++) {
|
||||
guint8 *data;
|
||||
gsize ssize, tocopy;
|
||||
GstMapInfo info;
|
||||
gsize tocopy;
|
||||
GstMemory *mem;
|
||||
|
||||
mem = GST_BUFFER_MEM_PTR (buffer, i);
|
||||
|
||||
data = gst_memory_map (mem, &ssize, NULL, GST_MAP_READ);
|
||||
if (ssize > offset) {
|
||||
gst_memory_map (mem, &info, GST_MAP_READ);
|
||||
if (info.size > offset) {
|
||||
/* we have enough */
|
||||
tocopy = MIN (ssize - offset, left);
|
||||
memcpy (ptr, data + offset, tocopy);
|
||||
tocopy = MIN (info.size - offset, left);
|
||||
memcpy (ptr, (guint8 *) info.data + offset, tocopy);
|
||||
left -= tocopy;
|
||||
ptr += tocopy;
|
||||
offset = 0;
|
||||
} else {
|
||||
/* offset past buffer, skip */
|
||||
offset -= ssize;
|
||||
offset -= info.size;
|
||||
}
|
||||
gst_memory_unmap (mem);
|
||||
gst_memory_unmap (mem, &info);
|
||||
}
|
||||
return size - left;
|
||||
}
|
||||
|
@ -1147,25 +1153,25 @@ gst_buffer_memcmp (GstBuffer * buffer, gsize offset, gconstpointer mem,
|
|||
len = GST_BUFFER_MEM_LEN (buffer);
|
||||
|
||||
for (i = 0; i < len && size > 0 && res == 0; i++) {
|
||||
guint8 *data;
|
||||
gsize ssize, tocmp;
|
||||
GstMapInfo info;
|
||||
gsize tocmp;
|
||||
GstMemory *mem;
|
||||
|
||||
mem = GST_BUFFER_MEM_PTR (buffer, i);
|
||||
|
||||
data = gst_memory_map (mem, &ssize, NULL, GST_MAP_READ);
|
||||
if (ssize > offset) {
|
||||
gst_memory_map (mem, &info, GST_MAP_READ);
|
||||
if (info.size > offset) {
|
||||
/* we have enough */
|
||||
tocmp = MIN (ssize - offset, size);
|
||||
res = memcmp (ptr, data + offset, tocmp);
|
||||
tocmp = MIN (info.size - offset, size);
|
||||
res = memcmp (ptr, (guint8 *) info.data + offset, tocmp);
|
||||
size -= tocmp;
|
||||
ptr += tocmp;
|
||||
offset = 0;
|
||||
} else {
|
||||
/* offset past buffer, skip */
|
||||
offset -= ssize;
|
||||
offset -= info.size;
|
||||
}
|
||||
gst_memory_unmap (mem);
|
||||
gst_memory_unmap (mem, &info);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
@ -1194,24 +1200,24 @@ gst_buffer_memset (GstBuffer * buffer, gsize offset, guint8 val, gsize size)
|
|||
left = size;
|
||||
|
||||
for (i = 0; i < len && left > 0; i++) {
|
||||
guint8 *data;
|
||||
gsize ssize, toset;
|
||||
GstMapInfo info;
|
||||
gsize toset;
|
||||
GstMemory *mem;
|
||||
|
||||
mem = _get_memory (buffer, i, TRUE);
|
||||
|
||||
data = gst_memory_map (mem, &ssize, NULL, GST_MAP_WRITE);
|
||||
if (ssize > offset) {
|
||||
gst_memory_map (mem, &info, GST_MAP_WRITE);
|
||||
if (info.size > offset) {
|
||||
/* we have enough */
|
||||
toset = MIN (ssize - offset, left);
|
||||
memset (data + offset, val, toset);
|
||||
toset = MIN (info.size - offset, left);
|
||||
memset ((guint8 *) info.data + offset, val, toset);
|
||||
left -= toset;
|
||||
offset = 0;
|
||||
} else {
|
||||
/* offset past buffer, skip */
|
||||
offset -= ssize;
|
||||
offset -= info.size;
|
||||
}
|
||||
gst_memory_unmap (mem);
|
||||
gst_memory_unmap (mem, &info);
|
||||
}
|
||||
return size - left;
|
||||
}
|
||||
|
@ -1312,37 +1318,38 @@ _gst_buffer_arr_span (GstMemory ** mem[], gsize len[], guint n, gsize offset,
|
|||
span = gst_memory_share (parent, offset + poffset, size);
|
||||
} else {
|
||||
gsize count, left;
|
||||
guint8 *dest, *ptr;
|
||||
GstMapInfo dinfo;
|
||||
guint8 *ptr;
|
||||
|
||||
span = gst_allocator_alloc (NULL, size, 0);
|
||||
dest = gst_memory_map (span, NULL, NULL, GST_MAP_WRITE);
|
||||
gst_memory_map (span, &dinfo, GST_MAP_WRITE);
|
||||
|
||||
ptr = dest;
|
||||
ptr = dinfo.data;
|
||||
left = size;
|
||||
|
||||
for (count = 0; count < n; count++) {
|
||||
gsize i, tocopy, clen, ssize;
|
||||
guint8 *src;
|
||||
GstMapInfo sinfo;
|
||||
gsize i, tocopy, clen;
|
||||
GstMemory **cmem;
|
||||
|
||||
cmem = mem[count];
|
||||
clen = len[count];
|
||||
|
||||
for (i = 0; i < clen && left > 0; i++) {
|
||||
src = gst_memory_map (cmem[i], &ssize, NULL, GST_MAP_READ);
|
||||
tocopy = MIN (ssize, left);
|
||||
gst_memory_map (cmem[i], &sinfo, GST_MAP_READ);
|
||||
tocopy = MIN (sinfo.size, left);
|
||||
if (tocopy > offset) {
|
||||
memcpy (ptr, src + offset, tocopy - offset);
|
||||
memcpy (ptr, (guint8 *) sinfo.data + offset, tocopy - offset);
|
||||
left -= tocopy;
|
||||
ptr += tocopy;
|
||||
offset = 0;
|
||||
} else {
|
||||
offset -= tocopy;
|
||||
}
|
||||
gst_memory_unmap (cmem[i]);
|
||||
gst_memory_unmap (cmem[i], &sinfo);
|
||||
}
|
||||
}
|
||||
gst_memory_unmap (span);
|
||||
gst_memory_unmap (span, &dinfo);
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
|
|
@ -314,10 +314,8 @@ void gst_buffer_resize (GstBuffer *buffer, gssize offset, gs
|
|||
*/
|
||||
#define gst_buffer_set_size(b,s) gst_buffer_resize ((b), 0, (s))
|
||||
|
||||
/* getting memory */
|
||||
gpointer gst_buffer_map (GstBuffer *buffer, gsize *size, gsize *maxsize,
|
||||
GstMapFlags flags);
|
||||
gboolean gst_buffer_unmap (GstBuffer *buffer, gpointer data, gssize size);
|
||||
gboolean gst_buffer_map (GstBuffer *buffer, GstMapInfo *info, GstMapFlags flags);
|
||||
void gst_buffer_unmap (GstBuffer *buffer, GstMapInfo *info);
|
||||
|
||||
/* refcounting */
|
||||
/**
|
||||
|
|
|
@ -267,22 +267,27 @@ static GstMemory *
|
|||
_fallback_copy (GstMemory * mem, gssize offset, gssize size)
|
||||
{
|
||||
GstMemory *copy;
|
||||
guint8 *data, *dest;
|
||||
gsize msize;
|
||||
GstMapInfo sinfo, dinfo;
|
||||
|
||||
data = gst_memory_map (mem, &msize, NULL, GST_MAP_READ);
|
||||
if (data == NULL)
|
||||
if (!gst_memory_map (mem, &sinfo, GST_MAP_READ))
|
||||
return NULL;
|
||||
|
||||
if (size == -1)
|
||||
size = msize > offset ? msize - offset : 0;
|
||||
size = sinfo.size > offset ? sinfo.size - offset : 0;
|
||||
|
||||
/* use the same allocator as the memory we copy */
|
||||
copy = gst_allocator_alloc (mem->allocator, size, mem->align);
|
||||
dest = gst_memory_map (copy, NULL, NULL, GST_MAP_WRITE);
|
||||
memcpy (dest, data + offset, size);
|
||||
gst_memory_unmap (copy);
|
||||
gst_memory_unmap (mem);
|
||||
if (!gst_memory_map (copy, &dinfo, GST_MAP_WRITE)) {
|
||||
GST_WARNING ("could not write map memory %p", copy);
|
||||
gst_memory_unmap (mem, &sinfo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (GstMemory *) copy;
|
||||
memcpy (dinfo.data, (guint8 *) sinfo.data + offset, size);
|
||||
gst_memory_unmap (copy, &dinfo);
|
||||
gst_memory_unmap (mem, &sinfo);
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -497,75 +502,73 @@ gst_memory_unlock (GstMemory * mem)
|
|||
/**
|
||||
* gst_memory_map:
|
||||
* @mem: a #GstMemory
|
||||
* @size: (out) (allow-none): pointer for size
|
||||
* @maxsize: (out) (allow-none): pointer for maxsize
|
||||
* @info: (out): pointer for info
|
||||
* @flags: mapping flags
|
||||
*
|
||||
* Get a pointer to the memory of @mem that can be accessed according to @flags.
|
||||
* Fill @info with the pointer and sizes of the memory in @mem that can be
|
||||
* accessed according to @flags.
|
||||
*
|
||||
* @size and @maxsize will contain the size of the memory and the maximum
|
||||
* allocated memory of @mem respectively. They can be set to NULL.
|
||||
*
|
||||
* This function can return NULL for various reasons:
|
||||
* This function can return %FALSE for various reasons:
|
||||
* - the memory backed by @mem is not accessible with the given @flags.
|
||||
* - the memory was already mapped with a different mapping.
|
||||
*
|
||||
* @pointer remains valid for as long as @mem is alive and until
|
||||
* @info and its contents remains valid for as long as @mem is alive and until
|
||||
* gst_memory_unmap() is called.
|
||||
*
|
||||
* For each gst_memory_map() call, a corresponding gst_memory_unmap() call
|
||||
* should be done.
|
||||
*
|
||||
* Returns: (transfer none): a pointer to the memory of @mem.
|
||||
* Returns: %TRUE if the map operation was successful.
|
||||
*/
|
||||
gpointer
|
||||
gst_memory_map (GstMemory * mem, gsize * size, gsize * maxsize,
|
||||
GstMapFlags flags)
|
||||
gboolean
|
||||
gst_memory_map (GstMemory * mem, GstMapInfo * info, GstMapFlags flags)
|
||||
{
|
||||
guint8 *res;
|
||||
|
||||
g_return_val_if_fail (mem != NULL, NULL);
|
||||
g_return_val_if_fail (mem != NULL, FALSE);
|
||||
g_return_val_if_fail (info != NULL, FALSE);
|
||||
|
||||
if (!gst_memory_lock (mem, flags))
|
||||
goto lock_failed;
|
||||
|
||||
res = mem->allocator->info.map (mem, mem->maxsize, flags);
|
||||
info->data = mem->allocator->info.map (mem, mem->maxsize, flags);
|
||||
|
||||
if (G_UNLIKELY (res == NULL))
|
||||
if (G_UNLIKELY (info->data == NULL))
|
||||
goto error;
|
||||
|
||||
if (size)
|
||||
*size = mem->size;
|
||||
if (maxsize)
|
||||
*maxsize = mem->maxsize - mem->offset;
|
||||
info->memory = mem;
|
||||
info->size = mem->size;
|
||||
info->maxsize = mem->maxsize - mem->offset;
|
||||
info->data = (guint8 *) info->data + mem->offset;
|
||||
|
||||
return res + mem->offset;
|
||||
return TRUE;
|
||||
|
||||
/* ERRORS */
|
||||
lock_failed:
|
||||
{
|
||||
g_critical ("memory %p: failed to lock memory", mem);
|
||||
return NULL;
|
||||
GST_DEBUG ("mem %p: lock %d failed", flags);
|
||||
return FALSE;
|
||||
}
|
||||
error:
|
||||
{
|
||||
/* something went wrong, restore the orginal state again */
|
||||
GST_ERROR ("mem %p: map failed", mem);
|
||||
gst_memory_unlock (mem);
|
||||
return NULL;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gst_memory_unmap:
|
||||
* @mem: a #GstMemory
|
||||
* @info: a #GstMapInfo
|
||||
*
|
||||
* Release the memory obtained with gst_memory_map()
|
||||
*/
|
||||
void
|
||||
gst_memory_unmap (GstMemory * mem)
|
||||
gst_memory_unmap (GstMemory * mem, GstMapInfo * info)
|
||||
{
|
||||
g_return_if_fail (mem != NULL);
|
||||
g_return_if_fail (info != NULL);
|
||||
g_return_if_fail (info->memory == mem);
|
||||
/* there must be a ref */
|
||||
g_return_if_fail (g_atomic_int_get (&mem->state) >= 4);
|
||||
|
||||
|
|
|
@ -98,6 +98,23 @@ typedef enum {
|
|||
GST_MAP_FLAG_LAST = (1 << 16)
|
||||
} GstMapFlags;
|
||||
|
||||
/**
|
||||
* GstMapInfo:
|
||||
* @memory: a pointer to the mapped memory
|
||||
* @data: a pointer to the mapped data
|
||||
* @size: the valid size in @data
|
||||
* @maxsize: the maximum bytes in @data
|
||||
*
|
||||
* A structure containing the result of a map operation such as
|
||||
* gst_memory_map(). It contains the data and size.
|
||||
*/
|
||||
typedef struct {
|
||||
GstMemory *memory;
|
||||
gpointer data;
|
||||
gsize size;
|
||||
gsize maxsize;
|
||||
} GstMapInfo;
|
||||
|
||||
/**
|
||||
* GST_MAP_READWRITE:
|
||||
*
|
||||
|
@ -260,9 +277,8 @@ void gst_memory_resize (GstMemory *mem, gssize offset, gsize size);
|
|||
/* retrieving data */
|
||||
gboolean gst_memory_is_writable (GstMemory *mem);
|
||||
|
||||
gpointer gst_memory_map (GstMemory *mem, gsize *size, gsize *maxsize,
|
||||
GstMapFlags flags);
|
||||
void gst_memory_unmap (GstMemory *mem);
|
||||
gboolean gst_memory_map (GstMemory *mem, GstMapInfo *info, GstMapFlags flags);
|
||||
void gst_memory_unmap (GstMemory *mem, GstMapInfo *info);
|
||||
|
||||
/* copy and subregions */
|
||||
GstMemory * gst_memory_copy (GstMemory *mem, gssize offset, gssize size);
|
||||
|
|
|
@ -1871,7 +1871,7 @@ gst_value_compare_buffer (const GValue * value1, const GValue * value2)
|
|||
GstBuffer *buf1 = gst_value_get_buffer (value1);
|
||||
GstBuffer *buf2 = gst_value_get_buffer (value2);
|
||||
gsize size1, size2;
|
||||
gpointer data1, data2;
|
||||
GstMapInfo info1, info2;
|
||||
gint result = GST_VALUE_UNORDERED;
|
||||
|
||||
size1 = gst_buffer_get_size (buf1);
|
||||
|
@ -1883,16 +1883,14 @@ gst_value_compare_buffer (const GValue * value1, const GValue * value2)
|
|||
if (size1 == 0)
|
||||
return GST_VALUE_EQUAL;
|
||||
|
||||
data1 = gst_buffer_map (buf1, &size1, NULL, GST_MAP_READ);
|
||||
data2 = gst_buffer_map (buf2, &size2, NULL, GST_MAP_READ);
|
||||
g_assert (data1);
|
||||
g_assert (data2);
|
||||
g_assert (gst_buffer_map (buf1, &info1, GST_MAP_READ));
|
||||
g_assert (gst_buffer_map (buf2, &info2, GST_MAP_READ));
|
||||
|
||||
if (memcmp (data1, data2, size1) == 0)
|
||||
if (memcmp (info1.data, info2.data, info1.size) == 0)
|
||||
result = GST_VALUE_EQUAL;
|
||||
|
||||
gst_buffer_unmap (buf2, data2, size2);
|
||||
gst_buffer_unmap (buf1, data1, size1);
|
||||
gst_buffer_unmap (buf2, &info1);
|
||||
gst_buffer_unmap (buf1, &info2);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -1900,9 +1898,9 @@ gst_value_compare_buffer (const GValue * value1, const GValue * value2)
|
|||
static gchar *
|
||||
gst_value_serialize_buffer (const GValue * value)
|
||||
{
|
||||
GstMapInfo info;
|
||||
guint8 *data;
|
||||
gint i;
|
||||
gsize size;
|
||||
gchar *string;
|
||||
GstBuffer *buffer;
|
||||
|
||||
|
@ -1910,15 +1908,16 @@ gst_value_serialize_buffer (const GValue * value)
|
|||
if (buffer == NULL)
|
||||
return NULL;
|
||||
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
g_assert (gst_buffer_map (buffer, &info, GST_MAP_READ));
|
||||
data = info.data;
|
||||
|
||||
string = g_malloc (size * 2 + 1);
|
||||
for (i = 0; i < size; i++) {
|
||||
string = g_malloc (info.size * 2 + 1);
|
||||
for (i = 0; i < info.size; i++) {
|
||||
sprintf (string + i * 2, "%02x", data[i]);
|
||||
}
|
||||
string[size * 2] = 0;
|
||||
string[info.size * 2] = 0;
|
||||
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
return string;
|
||||
}
|
||||
|
@ -1929,16 +1928,17 @@ gst_value_deserialize_buffer (GValue * dest, const gchar * s)
|
|||
GstBuffer *buffer;
|
||||
gint len;
|
||||
gchar ts[3];
|
||||
GstMapInfo info;
|
||||
guint8 *data;
|
||||
gint i;
|
||||
gsize size;
|
||||
|
||||
len = strlen (s);
|
||||
if (len & 1)
|
||||
goto wrong_length;
|
||||
|
||||
buffer = gst_buffer_new_allocate (NULL, len / 2, 0);
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_WRITE);
|
||||
g_assert (gst_buffer_map (buffer, &info, GST_MAP_WRITE));
|
||||
data = info.data;
|
||||
|
||||
for (i = 0; i < len / 2; i++) {
|
||||
if (!isxdigit ((int) s[i * 2]) || !isxdigit ((int) s[i * 2 + 1]))
|
||||
|
@ -1950,7 +1950,7 @@ gst_value_deserialize_buffer (GValue * dest, const gchar * s)
|
|||
|
||||
data[i] = (guint8) strtoul (ts, NULL, 16);
|
||||
}
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
gst_value_take_buffer (dest, buffer);
|
||||
|
||||
|
@ -1964,7 +1964,7 @@ wrong_length:
|
|||
wrong_char:
|
||||
{
|
||||
gst_buffer_unref (buffer);
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,8 +137,7 @@ struct _GstAdapterPrivate
|
|||
gsize scan_offset;
|
||||
GSList *scan_entry;
|
||||
|
||||
gpointer cdata;
|
||||
gsize csize;
|
||||
GstMapInfo info;
|
||||
};
|
||||
|
||||
#define _do_init \
|
||||
|
@ -214,11 +213,14 @@ gst_adapter_new (void)
|
|||
void
|
||||
gst_adapter_clear (GstAdapter * adapter)
|
||||
{
|
||||
GstAdapterPrivate *priv;
|
||||
|
||||
g_return_if_fail (GST_IS_ADAPTER (adapter));
|
||||
|
||||
if (adapter->priv->cdata) {
|
||||
priv = adapter->priv;
|
||||
|
||||
if (priv->info.memory)
|
||||
gst_adapter_unmap (adapter);
|
||||
}
|
||||
|
||||
g_slist_foreach (adapter->buflist, (GFunc) gst_mini_object_unref, NULL);
|
||||
g_slist_free (adapter->buflist);
|
||||
|
@ -227,12 +229,12 @@ gst_adapter_clear (GstAdapter * adapter)
|
|||
adapter->size = 0;
|
||||
adapter->skip = 0;
|
||||
adapter->assembled_len = 0;
|
||||
adapter->priv->pts = GST_CLOCK_TIME_NONE;
|
||||
adapter->priv->pts_distance = 0;
|
||||
adapter->priv->dts = GST_CLOCK_TIME_NONE;
|
||||
adapter->priv->dts_distance = 0;
|
||||
adapter->priv->scan_offset = 0;
|
||||
adapter->priv->scan_entry = NULL;
|
||||
priv->pts = GST_CLOCK_TIME_NONE;
|
||||
priv->pts_distance = 0;
|
||||
priv->dts = GST_CLOCK_TIME_NONE;
|
||||
priv->dts_distance = 0;
|
||||
priv->scan_offset = 0;
|
||||
priv->scan_entry = NULL;
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
@ -414,6 +416,7 @@ gst_adapter_try_to_merge_up (GstAdapter * adapter, gsize size)
|
|||
gconstpointer
|
||||
gst_adapter_map (GstAdapter * adapter, gsize size)
|
||||
{
|
||||
GstAdapterPrivate *priv;
|
||||
GstBuffer *cur;
|
||||
gsize skip, csize;
|
||||
gsize toreuse, tocopy;
|
||||
|
@ -422,9 +425,10 @@ gst_adapter_map (GstAdapter * adapter, gsize size)
|
|||
g_return_val_if_fail (GST_IS_ADAPTER (adapter), NULL);
|
||||
g_return_val_if_fail (size > 0, NULL);
|
||||
|
||||
if (adapter->priv->cdata) {
|
||||
priv = adapter->priv;
|
||||
|
||||
if (priv->info.memory)
|
||||
gst_adapter_unmap (adapter);
|
||||
}
|
||||
|
||||
/* we don't have enough data, return NULL. This is unlikely
|
||||
* as one usually does an _available() first instead of peeking a
|
||||
|
@ -442,10 +446,8 @@ gst_adapter_map (GstAdapter * adapter, gsize size)
|
|||
|
||||
csize = gst_buffer_get_size (cur);
|
||||
if (csize >= size + skip) {
|
||||
data = gst_buffer_map (cur, &csize, NULL, GST_MAP_READ);
|
||||
adapter->priv->cdata = data;
|
||||
adapter->priv->csize = csize;
|
||||
return data + skip;
|
||||
g_assert (gst_buffer_map (cur, &priv->info, GST_MAP_READ));
|
||||
return (guint8 *) priv->info.data + skip;
|
||||
}
|
||||
/* We may be able to efficiently merge buffers in our pool to
|
||||
* gather a big enough chunk to return it from the head buffer directly */
|
||||
|
@ -493,12 +495,16 @@ gst_adapter_map (GstAdapter * adapter, gsize size)
|
|||
void
|
||||
gst_adapter_unmap (GstAdapter * adapter)
|
||||
{
|
||||
GstAdapterPrivate *priv;
|
||||
|
||||
g_return_if_fail (GST_IS_ADAPTER (adapter));
|
||||
|
||||
if (adapter->priv->cdata) {
|
||||
priv = adapter->priv;
|
||||
|
||||
if (priv->info.memory) {
|
||||
GstBuffer *cur = adapter->buflist->data;
|
||||
gst_buffer_unmap (cur, adapter->priv->cdata, adapter->priv->csize);
|
||||
adapter->priv->cdata = NULL;
|
||||
gst_buffer_unmap (cur, &priv->info);
|
||||
priv->info.memory = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -548,12 +554,11 @@ gst_adapter_flush_unchecked (GstAdapter * adapter, gsize flush)
|
|||
|
||||
GST_LOG_OBJECT (adapter, "flushing %" G_GSIZE_FORMAT " bytes", flush);
|
||||
|
||||
if (adapter->priv->cdata) {
|
||||
gst_adapter_unmap (adapter);
|
||||
}
|
||||
|
||||
priv = adapter->priv;
|
||||
|
||||
if (priv->info.memory)
|
||||
gst_adapter_unmap (adapter);
|
||||
|
||||
/* clear state */
|
||||
adapter->size -= flush;
|
||||
adapter->assembled_len = 0;
|
||||
|
@ -956,9 +961,10 @@ gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask,
|
|||
guint32 pattern, gsize offset, gsize size, guint32 * value)
|
||||
{
|
||||
GSList *g;
|
||||
gsize skip, bsize, osize, i;
|
||||
gsize skip, bsize, i;
|
||||
guint32 state;
|
||||
guint8 *bdata, *odata;
|
||||
GstMapInfo info;
|
||||
guint8 *bdata;
|
||||
GstBuffer *buf;
|
||||
|
||||
g_return_val_if_fail (size > 0, -1);
|
||||
|
@ -992,10 +998,10 @@ gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask,
|
|||
bsize = gst_buffer_get_size (buf);
|
||||
}
|
||||
/* get the data now */
|
||||
odata = gst_buffer_map (buf, &osize, NULL, GST_MAP_READ);
|
||||
g_assert (gst_buffer_map (buf, &info, GST_MAP_READ));
|
||||
|
||||
bdata = odata + skip;
|
||||
bsize = osize - skip;
|
||||
bdata = (guint8 *) info.data + skip;
|
||||
bsize = info.size - skip;
|
||||
skip = 0;
|
||||
|
||||
/* set the state to something that does not match */
|
||||
|
@ -1012,7 +1018,7 @@ gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask,
|
|||
if (G_LIKELY (skip + i >= 3)) {
|
||||
if (G_LIKELY (value))
|
||||
*value = state;
|
||||
gst_buffer_unmap (buf, odata, osize);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
return offset + skip + i - 3;
|
||||
}
|
||||
}
|
||||
|
@ -1024,17 +1030,17 @@ gst_adapter_masked_scan_uint32_peek (GstAdapter * adapter, guint32 mask,
|
|||
/* nothing found yet, go to next buffer */
|
||||
skip += bsize;
|
||||
g = g_slist_next (g);
|
||||
adapter->priv->scan_offset += osize;
|
||||
adapter->priv->scan_offset += info.size;
|
||||
adapter->priv->scan_entry = g;
|
||||
gst_buffer_unmap (buf, odata, osize);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
buf = g->data;
|
||||
|
||||
odata = gst_buffer_map (buf, &osize, NULL, GST_MAP_READ);
|
||||
bsize = osize;
|
||||
bdata = odata;
|
||||
gst_buffer_map (buf, &info, GST_MAP_READ);
|
||||
bsize = info.size;
|
||||
bdata = info.data;
|
||||
} while (TRUE);
|
||||
|
||||
gst_buffer_unmap (buf, odata, osize);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
|
||||
/* nothing found */
|
||||
return -1;
|
||||
|
|
|
@ -1878,21 +1878,20 @@ no_qos:
|
|||
GST_DEBUG_OBJECT (trans, "doing inplace transform");
|
||||
|
||||
if (inbuf != *outbuf) {
|
||||
guint8 *indata, *outdata;
|
||||
gsize insize, outsize;
|
||||
GstMapInfo ininfo, outinfo;
|
||||
|
||||
/* Different buffer. The data can still be the same when we are dealing
|
||||
* with subbuffers of the same buffer. Note that because of the FIXME in
|
||||
* prepare_output_buffer() we have decreased the refcounts of inbuf and
|
||||
* outbuf to keep them writable */
|
||||
indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
|
||||
outdata = gst_buffer_map (*outbuf, &outsize, NULL, GST_MAP_WRITE);
|
||||
g_assert (gst_buffer_map (inbuf, &ininfo, GST_MAP_READ));
|
||||
g_assert (gst_buffer_map (*outbuf, &outinfo, GST_MAP_WRITE));
|
||||
|
||||
if (indata != outdata)
|
||||
memcpy (outdata, indata, insize);
|
||||
if (ininfo.data != outinfo.data)
|
||||
memcpy (outinfo.data, ininfo.data, ininfo.size);
|
||||
|
||||
gst_buffer_unmap (inbuf, indata, insize);
|
||||
gst_buffer_unmap (*outbuf, outdata, outsize);
|
||||
gst_buffer_unmap (inbuf, &ininfo);
|
||||
gst_buffer_unmap (*outbuf, &outinfo);
|
||||
}
|
||||
ret = bclass->transform_ip (trans, *outbuf);
|
||||
} else {
|
||||
|
|
|
@ -80,6 +80,7 @@ helper_find_peek (gpointer data, gint64 offset, guint size)
|
|||
GSList *insert_pos = NULL;
|
||||
gsize buf_size;
|
||||
guint64 buf_offset;
|
||||
GstMapInfo info;
|
||||
#if 0
|
||||
GstCaps *caps;
|
||||
#endif
|
||||
|
@ -113,12 +114,10 @@ helper_find_peek (gpointer data, gint64 offset, guint size)
|
|||
* we're after the searched end offset */
|
||||
if (buf_offset <= offset) {
|
||||
if ((offset + size) < (buf_offset + buf_size)) {
|
||||
guint8 *data;
|
||||
|
||||
/* FIXME, unmap after usage */
|
||||
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_READ);
|
||||
g_assert (gst_buffer_map (buf, &info, GST_MAP_READ));
|
||||
|
||||
return data + (offset - buf_offset);
|
||||
return (guint8 *) info.data + (offset - buf_offset);
|
||||
}
|
||||
} else if (offset + size >= buf_offset + buf_size) {
|
||||
insert_pos = walk;
|
||||
|
@ -181,7 +180,8 @@ helper_find_peek (gpointer data, gint64 offset, guint size)
|
|||
}
|
||||
|
||||
/* FIXME, unmap */
|
||||
return gst_buffer_map (buffer, NULL, NULL, GST_MAP_READ);
|
||||
g_assert (gst_buffer_map (buffer, &info, GST_MAP_READ));
|
||||
return info.data;
|
||||
|
||||
error:
|
||||
{
|
||||
|
@ -563,17 +563,16 @@ gst_type_find_helper_for_buffer (GstObject * obj, GstBuffer * buf,
|
|||
GstTypeFindProbability * prob)
|
||||
{
|
||||
GstCaps *result;
|
||||
guint8 *data;
|
||||
gsize size;
|
||||
GstMapInfo info;
|
||||
|
||||
g_return_val_if_fail (buf != NULL, NULL);
|
||||
g_return_val_if_fail (GST_IS_BUFFER (buf), NULL);
|
||||
g_return_val_if_fail (GST_BUFFER_OFFSET (buf) == 0 ||
|
||||
GST_BUFFER_OFFSET (buf) == GST_BUFFER_OFFSET_NONE, NULL);
|
||||
|
||||
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
|
||||
result = gst_type_find_helper_for_data (obj, data, size, prob);
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
g_assert (gst_buffer_map (buf, &info, GST_MAP_READ));
|
||||
result = gst_type_find_helper_for_data (obj, info.data, info.size, prob);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -359,20 +359,20 @@ gst_check_caps_equal (GstCaps * caps1, GstCaps * caps2)
|
|||
void
|
||||
gst_check_buffer_data (GstBuffer * buffer, gconstpointer data, gsize size)
|
||||
{
|
||||
guint8 *bdata;
|
||||
gsize bsize;
|
||||
GstMapInfo info;
|
||||
|
||||
bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
|
||||
GST_MEMDUMP ("Converted data", bdata, bsize);
|
||||
gst_buffer_map (buffer, &info, GST_MAP_READ);
|
||||
GST_MEMDUMP ("Converted data", info.data, info.size);
|
||||
GST_MEMDUMP ("Expected data", data, size);
|
||||
if (memcmp (bdata, data, size) != 0) {
|
||||
if (memcmp (info.data, data, size) != 0) {
|
||||
g_print ("\nConverted data:\n");
|
||||
gst_util_dump_mem (bdata, bsize);
|
||||
gst_util_dump_mem (info.data, info.size);
|
||||
g_print ("\nExpected data:\n");
|
||||
gst_util_dump_mem (data, size);
|
||||
}
|
||||
fail_unless (memcmp (bdata, data, size) == 0, "buffer contents not equal");
|
||||
gst_buffer_unmap (buffer, bdata, bsize);
|
||||
fail_unless (memcmp (info.data, data, size) == 0,
|
||||
"buffer contents not equal");
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -492,30 +492,30 @@ gst_check_element_push_buffer_list (const gchar * element_name,
|
|||
while (buffers != NULL) {
|
||||
GstBuffer *new = GST_BUFFER (buffers->data);
|
||||
GstBuffer *orig = GST_BUFFER (buffer_out->data);
|
||||
gsize newsize, origsize;
|
||||
guint8 *newdata, *origdata;
|
||||
GstMapInfo newinfo, originfo;
|
||||
|
||||
newdata = gst_buffer_map (new, &newsize, NULL, GST_MAP_READ);
|
||||
origdata = gst_buffer_map (orig, &origsize, NULL, GST_MAP_READ);
|
||||
gst_buffer_map (new, &newinfo, GST_MAP_READ);
|
||||
gst_buffer_map (orig, &originfo, GST_MAP_READ);
|
||||
|
||||
GST_LOG ("orig buffer: size %" G_GSIZE_FORMAT, origsize);
|
||||
GST_LOG ("new buffer: size %" G_GSIZE_FORMAT, newsize);
|
||||
GST_MEMDUMP ("orig buffer", origdata, origsize);
|
||||
GST_MEMDUMP ("new buffer", newdata, newsize);
|
||||
GST_LOG ("orig buffer: size %" G_GSIZE_FORMAT, originfo.size);
|
||||
GST_LOG ("new buffer: size %" G_GSIZE_FORMAT, newinfo.size);
|
||||
GST_MEMDUMP ("orig buffer", originfo.data, originfo.size);
|
||||
GST_MEMDUMP ("new buffer", newinfo.data, newinfo.size);
|
||||
|
||||
/* remove the buffers */
|
||||
buffers = g_list_remove (buffers, new);
|
||||
buffer_out = g_list_remove (buffer_out, orig);
|
||||
|
||||
fail_unless (origsize == newsize, "size of the buffers are not the same");
|
||||
fail_unless (memcmp (origdata, newdata, newsize) == 0,
|
||||
fail_unless (originfo.size == newinfo.size,
|
||||
"size of the buffers are not the same");
|
||||
fail_unless (memcmp (originfo.data, newinfo.data, newinfo.size) == 0,
|
||||
"data is not the same");
|
||||
#if 0
|
||||
gst_check_caps_equal (GST_BUFFER_CAPS (orig), GST_BUFFER_CAPS (new));
|
||||
#endif
|
||||
|
||||
gst_buffer_unmap (orig, origdata, origsize);
|
||||
gst_buffer_unmap (new, newdata, newsize);
|
||||
gst_buffer_unmap (orig, &originfo);
|
||||
gst_buffer_unmap (new, &newinfo);
|
||||
|
||||
gst_buffer_unref (new);
|
||||
gst_buffer_unref (orig);
|
||||
|
|
|
@ -509,12 +509,11 @@ gst_fake_sink_render (GstBaseSink * bsink, GstBuffer * buf)
|
|||
bsink->sinkpad);
|
||||
|
||||
if (sink->dump) {
|
||||
guint8 *data;
|
||||
gsize size;
|
||||
GstMapInfo info;
|
||||
|
||||
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
|
||||
gst_util_dump_mem (data, size);
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
gst_buffer_map (buf, &info, GST_MAP_READ);
|
||||
gst_util_dump_mem (info.data, info.size);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
}
|
||||
if (sink->num_buffers_left == 0)
|
||||
goto eos;
|
||||
|
|
|
@ -719,7 +719,7 @@ gst_fake_src_create_buffer (GstFakeSrc * src, gsize * bufsize)
|
|||
GstBuffer *buf;
|
||||
gsize size = gst_fake_src_get_size (src);
|
||||
gboolean dump = src->dump;
|
||||
guint8 *data;
|
||||
GstMapInfo info;
|
||||
|
||||
*bufsize = size;
|
||||
|
||||
|
@ -746,9 +746,9 @@ gst_fake_src_create_buffer (GstFakeSrc * src, gsize * bufsize)
|
|||
/* try again (this will allocate a new parent) */
|
||||
return gst_fake_src_create_buffer (src, bufsize);
|
||||
}
|
||||
data = gst_buffer_map (buf, &size, NULL, GST_MAP_WRITE);
|
||||
gst_fake_src_prepare_buffer (src, data, size);
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
gst_buffer_map (buf, &info, GST_MAP_WRITE);
|
||||
gst_fake_src_prepare_buffer (src, info.data, info.size);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
break;
|
||||
default:
|
||||
g_warning ("fakesrc: dunno how to allocate buffers !");
|
||||
|
@ -756,9 +756,9 @@ gst_fake_src_create_buffer (GstFakeSrc * src, gsize * bufsize)
|
|||
break;
|
||||
}
|
||||
if (dump) {
|
||||
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
|
||||
gst_util_dump_mem (data, size);
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
gst_buffer_map (buf, &info, GST_MAP_READ);
|
||||
gst_util_dump_mem (info.data, info.size);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
}
|
||||
|
||||
return buf;
|
||||
|
|
|
@ -220,8 +220,9 @@ static GstFlowReturn
|
|||
gst_fd_sink_render (GstBaseSink * sink, GstBuffer * buffer)
|
||||
{
|
||||
GstFdSink *fdsink;
|
||||
guint8 *data, *ptr;
|
||||
gsize size, left;
|
||||
GstMapInfo info;
|
||||
guint8 *ptr;
|
||||
gsize left;
|
||||
gint written;
|
||||
|
||||
#ifndef HAVE_WIN32
|
||||
|
@ -232,16 +233,16 @@ gst_fd_sink_render (GstBaseSink * sink, GstBuffer * buffer)
|
|||
|
||||
g_return_val_if_fail (fdsink->fd >= 0, GST_FLOW_ERROR);
|
||||
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
gst_buffer_map (buffer, &info, GST_MAP_READ);
|
||||
|
||||
ptr = data;
|
||||
left = size;
|
||||
ptr = info.data;
|
||||
left = info.size;
|
||||
|
||||
again:
|
||||
#ifndef HAVE_WIN32
|
||||
do {
|
||||
GST_DEBUG_OBJECT (fdsink, "going into select, have %" G_GSIZE_FORMAT
|
||||
" bytes to write", size);
|
||||
" bytes to write", info.size);
|
||||
retval = gst_poll_wait (fdsink->fdset, GST_CLOCK_TIME_NONE);
|
||||
} while (retval == -1 && (errno == EINTR || errno == EAGAIN));
|
||||
|
||||
|
@ -254,7 +255,7 @@ again:
|
|||
#endif
|
||||
|
||||
GST_DEBUG_OBJECT (fdsink, "writing %" G_GSIZE_FORMAT " bytes to"
|
||||
" file descriptor %d", size, fdsink->fd);
|
||||
" file descriptor %d", info.size, fdsink->fd);
|
||||
|
||||
written = write (fdsink->fd, ptr, left);
|
||||
|
||||
|
@ -281,7 +282,7 @@ again:
|
|||
if (G_UNLIKELY (left > 0))
|
||||
goto again;
|
||||
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
return GST_FLOW_OK;
|
||||
|
||||
|
@ -291,13 +292,13 @@ select_error:
|
|||
GST_ELEMENT_ERROR (fdsink, RESOURCE, READ, (NULL),
|
||||
("select on file descriptor: %s.", g_strerror (errno)));
|
||||
GST_DEBUG_OBJECT (fdsink, "Error during select");
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
stopped:
|
||||
{
|
||||
GST_DEBUG_OBJECT (fdsink, "Select stopped");
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
return GST_FLOW_WRONG_STATE;
|
||||
}
|
||||
#endif
|
||||
|
@ -314,7 +315,7 @@ write_error:
|
|||
fdsink->fd, g_strerror (errno)));
|
||||
}
|
||||
}
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -393,8 +393,7 @@ gst_fd_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
|
|||
gssize readbytes;
|
||||
guint blocksize;
|
||||
GstClockTime timeout;
|
||||
guint8 *data;
|
||||
gsize maxsize;
|
||||
GstMapInfo info;
|
||||
|
||||
#ifndef HAVE_WIN32
|
||||
gboolean try_again;
|
||||
|
@ -446,17 +445,18 @@ gst_fd_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
|
|||
if (G_UNLIKELY (buf == NULL))
|
||||
goto alloc_failed;
|
||||
|
||||
data = gst_buffer_map (buf, NULL, &maxsize, GST_MAP_WRITE);
|
||||
gst_buffer_map (buf, &info, GST_MAP_WRITE);
|
||||
|
||||
do {
|
||||
readbytes = read (src->fd, data, blocksize);
|
||||
readbytes = read (src->fd, info.data, blocksize);
|
||||
GST_LOG_OBJECT (src, "read %" G_GSSIZE_FORMAT, readbytes);
|
||||
} while (readbytes == -1 && errno == EINTR); /* retry if interrupted */
|
||||
|
||||
if (readbytes < 0)
|
||||
goto read_error;
|
||||
|
||||
gst_buffer_unmap (buf, data, readbytes);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
gst_buffer_resize (buf, 0, readbytes);
|
||||
|
||||
if (readbytes == 0)
|
||||
goto eos;
|
||||
|
@ -503,7 +503,7 @@ read_error:
|
|||
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL),
|
||||
("read on file descriptor: %s.", g_strerror (errno)));
|
||||
GST_DEBUG_OBJECT (psrc, "Error reading from fd");
|
||||
gst_buffer_unmap (buf, data, 0);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
gst_buffer_unref (buf);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
|
|
@ -631,24 +631,23 @@ static GstFlowReturn
|
|||
gst_file_sink_render (GstBaseSink * sink, GstBuffer * buffer)
|
||||
{
|
||||
GstFileSink *filesink;
|
||||
gsize size;
|
||||
guint8 *data;
|
||||
GstMapInfo info;
|
||||
|
||||
filesink = GST_FILE_SINK (sink);
|
||||
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
gst_buffer_map (buffer, &info, GST_MAP_READ);
|
||||
|
||||
GST_DEBUG_OBJECT (filesink,
|
||||
"writing %" G_GSIZE_FORMAT " bytes at %" G_GUINT64_FORMAT,
|
||||
size, filesink->current_pos);
|
||||
info.size, filesink->current_pos);
|
||||
|
||||
if (size > 0 && data != NULL) {
|
||||
if (fwrite (data, size, 1, filesink->file) != 1)
|
||||
if (info.size > 0 && info.data != NULL) {
|
||||
if (fwrite (info.data, info.size, 1, filesink->file) != 1)
|
||||
goto handle_error;
|
||||
|
||||
filesink->current_pos += size;
|
||||
filesink->current_pos += info.size;
|
||||
}
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
return GST_FLOW_OK;
|
||||
|
||||
|
@ -665,7 +664,7 @@ handle_error:
|
|||
("%s", g_strerror (errno)));
|
||||
}
|
||||
}
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -323,6 +323,7 @@ gst_file_src_fill (GstBaseSrc * basesrc, guint64 offset, guint length,
|
|||
GstFileSrc *src;
|
||||
guint to_read, bytes_read;
|
||||
int ret;
|
||||
GstMapInfo info;
|
||||
guint8 *data;
|
||||
|
||||
src = GST_FILE_SRC_CAST (basesrc);
|
||||
|
@ -337,7 +338,8 @@ gst_file_src_fill (GstBaseSrc * basesrc, guint64 offset, guint length,
|
|||
src->read_position = offset;
|
||||
}
|
||||
|
||||
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
|
||||
gst_buffer_map (buf, &info, GST_MAP_WRITE);
|
||||
data = info.data;
|
||||
|
||||
bytes_read = 0;
|
||||
to_read = length;
|
||||
|
@ -366,7 +368,8 @@ gst_file_src_fill (GstBaseSrc * basesrc, guint64 offset, guint length,
|
|||
src->read_position += ret;
|
||||
}
|
||||
|
||||
gst_buffer_unmap (buf, data, bytes_read);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
gst_buffer_resize (buf, 0, bytes_read);
|
||||
|
||||
GST_BUFFER_OFFSET (buf) = offset;
|
||||
GST_BUFFER_OFFSET_END (buf) = offset + bytes_read;
|
||||
|
@ -382,13 +385,15 @@ seek_failed:
|
|||
could_not_read:
|
||||
{
|
||||
GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), GST_ERROR_SYSTEM);
|
||||
gst_buffer_unmap (buf, data, 0);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
gst_buffer_resize (buf, 0, 0);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
eos:
|
||||
{
|
||||
GST_DEBUG ("EOS");
|
||||
gst_buffer_unmap (buf, data, 0);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
gst_buffer_resize (buf, 0, 0);
|
||||
return GST_FLOW_EOS;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -600,10 +600,9 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|||
GstFlowReturn ret = GST_FLOW_OK;
|
||||
GstIdentity *identity = GST_IDENTITY (trans);
|
||||
GstClockTime runtimestamp = G_GINT64_CONSTANT (0);
|
||||
guint8 *data;
|
||||
gsize size;
|
||||
GstMapInfo info;
|
||||
|
||||
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
|
||||
gst_buffer_map (buf, &info, GST_MAP_READ);
|
||||
|
||||
if (identity->check_perfect)
|
||||
gst_identity_check_perfect (identity, buf);
|
||||
|
@ -630,11 +629,12 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|||
}
|
||||
|
||||
if (identity->dump) {
|
||||
gst_util_dump_mem (data, size);
|
||||
gst_util_dump_mem (info.data, info.size);
|
||||
}
|
||||
|
||||
if (!identity->silent) {
|
||||
gst_identity_update_last_message_for_buffer (identity, "chain", buf, size);
|
||||
gst_identity_update_last_message_for_buffer (identity, "chain", buf,
|
||||
info.size);
|
||||
}
|
||||
|
||||
if (identity->datarate > 0) {
|
||||
|
@ -642,7 +642,7 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|||
GST_SECOND, identity->datarate);
|
||||
|
||||
GST_BUFFER_TIMESTAMP (buf) = time;
|
||||
GST_BUFFER_DURATION (buf) = size * GST_SECOND / identity->datarate;
|
||||
GST_BUFFER_DURATION (buf) = info.size * GST_SECOND / identity->datarate;
|
||||
}
|
||||
|
||||
if (identity->signal_handoffs)
|
||||
|
@ -679,7 +679,7 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|||
GST_OBJECT_UNLOCK (identity);
|
||||
}
|
||||
|
||||
identity->offset += size;
|
||||
identity->offset += info.size;
|
||||
|
||||
if (identity->sleep_time && ret == GST_FLOW_OK)
|
||||
g_usleep (identity->sleep_time);
|
||||
|
@ -691,7 +691,7 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|||
GST_BUFFER_OFFSET_END (buf) = GST_CLOCK_TIME_NONE;
|
||||
}
|
||||
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
|
||||
return ret;
|
||||
|
||||
|
@ -700,16 +700,16 @@ error_after:
|
|||
{
|
||||
GST_ELEMENT_ERROR (identity, CORE, FAILED,
|
||||
(_("Failed after iterations as requested.")), (NULL));
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
dropped:
|
||||
{
|
||||
if (!identity->silent) {
|
||||
gst_identity_update_last_message_for_buffer (identity, "dropping", buf,
|
||||
size);
|
||||
info.size);
|
||||
}
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
/* return DROPPED to basetransform. */
|
||||
return GST_BASE_TRANSFORM_FLOW_DROPPED;
|
||||
}
|
||||
|
|
|
@ -1152,7 +1152,8 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length,
|
|||
GstBuffer ** buffer)
|
||||
{
|
||||
GstBuffer *buf;
|
||||
guint8 *data, *orig;
|
||||
GstMapInfo info;
|
||||
guint8 *data;
|
||||
guint64 file_offset;
|
||||
guint block_length, remaining, read_length;
|
||||
guint64 rb_size;
|
||||
|
@ -1161,7 +1162,8 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length,
|
|||
|
||||
/* allocate the output buffer of the requested size */
|
||||
buf = gst_buffer_new_allocate (NULL, length, 0);
|
||||
orig = data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
|
||||
gst_buffer_map (buf, &info, GST_MAP_WRITE);
|
||||
data = info.data;
|
||||
|
||||
GST_DEBUG_OBJECT (queue, "Reading %u bytes from %" G_GUINT64_FORMAT, length,
|
||||
offset);
|
||||
|
@ -1272,7 +1274,8 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length,
|
|||
GST_DEBUG_OBJECT (queue, "%u bytes left to read", remaining);
|
||||
}
|
||||
|
||||
gst_buffer_unmap (buf, orig, length);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
gst_buffer_resize (buf, 0, length);
|
||||
|
||||
GST_BUFFER_OFFSET (buf) = offset;
|
||||
GST_BUFFER_OFFSET_END (buf) = offset + length;
|
||||
|
@ -1297,7 +1300,7 @@ out_flushing:
|
|||
read_error:
|
||||
{
|
||||
GST_DEBUG_OBJECT (queue, "we have a read error");
|
||||
gst_buffer_unmap (buf, data, 0);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
gst_buffer_unref (buf);
|
||||
return ret;
|
||||
}
|
||||
|
@ -1523,9 +1526,9 @@ out_flushing:
|
|||
static gboolean
|
||||
gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer)
|
||||
{
|
||||
guint8 *odata, *data, *ring_buffer;
|
||||
GstMapInfo info;
|
||||
guint8 *data, *ring_buffer;
|
||||
guint size, rb_size;
|
||||
gsize osize;
|
||||
guint64 writing_pos, new_writing_pos;
|
||||
GstQueue2Range *range, *prev, *next;
|
||||
|
||||
|
@ -1536,10 +1539,10 @@ gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer)
|
|||
ring_buffer = queue->ring_buffer;
|
||||
rb_size = queue->ring_buffer_max_size;
|
||||
|
||||
odata = gst_buffer_map (buffer, &osize, NULL, GST_MAP_READ);
|
||||
gst_buffer_map (buffer, &info, GST_MAP_READ);
|
||||
|
||||
size = osize;
|
||||
data = odata;
|
||||
size = info.size;
|
||||
data = info.data;
|
||||
|
||||
GST_DEBUG_OBJECT (queue, "Writing %u bytes to %" G_GUINT64_FORMAT, size,
|
||||
GST_BUFFER_OFFSET (buffer));
|
||||
|
@ -1763,7 +1766,7 @@ gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer)
|
|||
GST_QUEUE2_SIGNAL_ADD (queue);
|
||||
}
|
||||
|
||||
gst_buffer_unmap (buffer, odata, osize);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
@ -1771,14 +1774,14 @@ gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer)
|
|||
out_flushing:
|
||||
{
|
||||
GST_DEBUG_OBJECT (queue, "we are flushing");
|
||||
gst_buffer_unmap (buffer, odata, osize);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
/* FIXME - GST_FLOW_EOS ? */
|
||||
return FALSE;
|
||||
}
|
||||
seek_failed:
|
||||
{
|
||||
GST_ELEMENT_ERROR (queue, RESOURCE, SEEK, (NULL), GST_ERROR_SYSTEM);
|
||||
gst_buffer_unmap (buffer, odata, osize);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
return FALSE;
|
||||
}
|
||||
handle_error:
|
||||
|
@ -1794,7 +1797,7 @@ handle_error:
|
|||
("%s", g_strerror (errno)));
|
||||
}
|
||||
}
|
||||
gst_buffer_unmap (buffer, odata, osize);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,12 +85,12 @@ cleanup_filesink (GstElement * filesink)
|
|||
G_STMT_START { \
|
||||
GstBuffer *buf = gst_buffer_new_and_alloc(num_bytes); \
|
||||
GRand *rand = g_rand_new_with_seed (num_bytes); \
|
||||
guint8 *data; \
|
||||
GstMapInfo info; \
|
||||
guint i; \
|
||||
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE); \
|
||||
fail_unless (gst_buffer_map (buf, &info, GST_MAP_WRITE)); \
|
||||
for (i = 0; i < num_bytes; ++i) \
|
||||
data[i] = (g_rand_int (rand) >> 24) & 0xff; \
|
||||
gst_buffer_unmap (buf, data, num_bytes); \
|
||||
((guint8 *)info.data)[i] = (g_rand_int (rand) >> 24) & 0xff; \
|
||||
gst_buffer_unmap (buf, &info); \
|
||||
fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK); \
|
||||
g_rand_free (rand); \
|
||||
} G_STMT_END
|
||||
|
|
|
@ -171,8 +171,7 @@ GST_START_TEST (test_pull)
|
|||
GstPad *pad;
|
||||
GstFlowReturn ret;
|
||||
GstBuffer *buffer1, *buffer2;
|
||||
guint8 *data1, *data2;
|
||||
gsize size1, size2;
|
||||
GstMapInfo info1, info2;
|
||||
|
||||
src = setup_filesrc ();
|
||||
|
||||
|
@ -218,10 +217,10 @@ GST_START_TEST (test_pull)
|
|||
fail_unless (gst_buffer_get_size (buffer2) == 50);
|
||||
|
||||
/* this should be the same */
|
||||
data1 = gst_buffer_map (buffer1, &size1, NULL, GST_MAP_READ);
|
||||
data2 = gst_buffer_map (buffer2, &size2, NULL, GST_MAP_READ);
|
||||
fail_unless (memcmp (data1, data2, 50) == 0);
|
||||
gst_buffer_unmap (buffer2, data2, size2);
|
||||
fail_unless (gst_buffer_map (buffer1, &info1, GST_MAP_READ));
|
||||
fail_unless (gst_buffer_map (buffer2, &info2, GST_MAP_READ));
|
||||
fail_unless (memcmp (info1.data, info2.data, 50) == 0);
|
||||
gst_buffer_unmap (buffer2, &info2);
|
||||
|
||||
gst_buffer_unref (buffer2);
|
||||
|
||||
|
@ -232,11 +231,11 @@ GST_START_TEST (test_pull)
|
|||
fail_unless (gst_buffer_get_size (buffer2) == 50);
|
||||
|
||||
/* compare with previously read data */
|
||||
data2 = gst_buffer_map (buffer2, &size2, NULL, GST_MAP_READ);
|
||||
fail_unless (memcmp (data1 + 50, data2, 50) == 0);
|
||||
gst_buffer_unmap (buffer2, data2, size2);
|
||||
fail_unless (gst_buffer_map (buffer2, &info2, GST_MAP_READ));
|
||||
fail_unless (memcmp ((guint8 *) info1.data + 50, info2.data, 50) == 0);
|
||||
gst_buffer_unmap (buffer2, &info2);
|
||||
|
||||
gst_buffer_unmap (buffer1, data1, size1);
|
||||
gst_buffer_unmap (buffer1, &info1);
|
||||
gst_buffer_unref (buffer1);
|
||||
gst_buffer_unref (buffer2);
|
||||
|
||||
|
|
|
@ -87,7 +87,6 @@ GST_START_TEST (test_one_buffer)
|
|||
{
|
||||
GstElement *identity;
|
||||
GstBuffer *buffer;
|
||||
gpointer data;
|
||||
|
||||
identity = setup_identity ();
|
||||
fail_unless (gst_element_set_state (identity,
|
||||
|
@ -97,9 +96,7 @@ GST_START_TEST (test_one_buffer)
|
|||
buffer = gst_buffer_new_and_alloc (4);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
|
||||
|
||||
data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
|
||||
memcpy (data, "data", 4);
|
||||
gst_buffer_unmap (buffer, data, 4);
|
||||
gst_buffer_fill (buffer, 0, "data", 4);
|
||||
|
||||
/* pushing gives away my reference ... */
|
||||
fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK,
|
||||
|
|
|
@ -330,8 +330,7 @@ mq_dummypad_chain (GstPad * sinkpad, GstObject * parent, GstBuffer * buf)
|
|||
{
|
||||
guint32 cur_id;
|
||||
struct PadData *pad_data;
|
||||
guint8 *data;
|
||||
gsize size;
|
||||
GstMapInfo info;
|
||||
|
||||
pad_data = gst_pad_get_element_private (sinkpad);
|
||||
|
||||
|
@ -339,11 +338,11 @@ mq_dummypad_chain (GstPad * sinkpad, GstObject * parent, GstBuffer * buf)
|
|||
fail_if (pad_data == NULL);
|
||||
/* Read an ID from the first 4 bytes of the buffer data and check it's
|
||||
* what we expect */
|
||||
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (size >= 4);
|
||||
fail_unless (gst_buffer_map (buf, &info, GST_MAP_READ));
|
||||
fail_unless (info.size >= 4);
|
||||
g_mutex_unlock (&_check_lock);
|
||||
cur_id = GST_READ_UINT32_BE (data);
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
cur_id = GST_READ_UINT32_BE (info.data);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
|
||||
g_mutex_lock (pad_data->mutex);
|
||||
|
||||
|
@ -496,7 +495,7 @@ run_output_order_test (gint n_linked)
|
|||
guint8 cur_pad;
|
||||
GstBuffer *buf;
|
||||
GstFlowReturn ret;
|
||||
gpointer data;
|
||||
GstMapInfo info;
|
||||
|
||||
cur_pad = pad_pattern[i % n];
|
||||
|
||||
|
@ -505,9 +504,9 @@ run_output_order_test (gint n_linked)
|
|||
fail_if (buf == NULL);
|
||||
g_mutex_unlock (&_check_lock);
|
||||
|
||||
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
|
||||
GST_WRITE_UINT32_BE (data, i + 1);
|
||||
gst_buffer_unmap (buf, data, 4);
|
||||
fail_unless (gst_buffer_map (buf, &info, GST_MAP_WRITE));
|
||||
GST_WRITE_UINT32_BE (info.data, i + 1);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
GST_BUFFER_TIMESTAMP (buf) = (i + 1) * GST_SECOND;
|
||||
|
||||
ret = gst_pad_push (inputpads[cur_pad], buf);
|
||||
|
@ -655,7 +654,7 @@ GST_START_TEST (test_sparse_stream)
|
|||
GstBuffer *buf;
|
||||
GstFlowReturn ret;
|
||||
GstClockTime ts;
|
||||
gpointer data;
|
||||
GstMapInfo info;
|
||||
|
||||
ts = gst_util_uint64_scale_int (GST_SECOND, i, 10);
|
||||
|
||||
|
@ -664,9 +663,9 @@ GST_START_TEST (test_sparse_stream)
|
|||
fail_if (buf == NULL);
|
||||
g_mutex_unlock (&_check_lock);
|
||||
|
||||
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
|
||||
GST_WRITE_UINT32_BE (data, i + 1);
|
||||
gst_buffer_unmap (buf, data, 4);
|
||||
fail_unless (gst_buffer_map (buf, &info, GST_MAP_WRITE));
|
||||
GST_WRITE_UINT32_BE (info.data, i + 1);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
|
||||
GST_BUFFER_TIMESTAMP (buf) = gst_util_uint64_scale_int (GST_SECOND, i, 10);
|
||||
|
||||
|
|
|
@ -35,19 +35,18 @@
|
|||
GST_START_TEST (test_subbuffer)
|
||||
{
|
||||
GstBuffer *buffer, *sub;
|
||||
gsize size, maxsize, ssize;
|
||||
guint8 *data, *sdata;
|
||||
GstMapInfo info, sinfo;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
|
||||
/* check sizes, buffer starts out empty */
|
||||
data = gst_buffer_map (buffer, &size, &maxsize, GST_MAP_WRITE);
|
||||
fail_unless (size == 4, "buffer has wrong size");
|
||||
fail_unless (maxsize >= 4, "buffer has wrong size");
|
||||
memset (data, 0, 4);
|
||||
gst_buffer_unmap (buffer, data, 4);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_WRITE));
|
||||
fail_unless (info.size == 4, "buffer has wrong size");
|
||||
fail_unless (info.maxsize >= 4, "buffer has wrong size");
|
||||
memset (info.data, 0, 4);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_READ));
|
||||
/* set some metadata */
|
||||
GST_BUFFER_TIMESTAMP (buffer) = 1;
|
||||
GST_BUFFER_DURATION (buffer) = 2;
|
||||
|
@ -57,9 +56,9 @@ GST_START_TEST (test_subbuffer)
|
|||
sub = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 1, 2);
|
||||
fail_if (sub == NULL, "copy region of buffer returned NULL");
|
||||
|
||||
sdata = gst_buffer_map (sub, &ssize, NULL, GST_MAP_READ);
|
||||
fail_unless (ssize == 2, "subbuffer has wrong size");
|
||||
fail_unless (memcmp (data + 1, sdata, 2) == 0,
|
||||
fail_unless (gst_buffer_map (sub, &sinfo, GST_MAP_READ));
|
||||
fail_unless (sinfo.size == 2, "subbuffer has wrong size");
|
||||
fail_unless (memcmp ((guint8 *) info.data + 1, sinfo.data, 2) == 0,
|
||||
"subbuffer contains the wrong data");
|
||||
ASSERT_BUFFER_REFCOUNT (sub, "subbuffer", 1);
|
||||
fail_unless (GST_BUFFER_TIMESTAMP (sub) == -1,
|
||||
|
@ -68,18 +67,18 @@ GST_START_TEST (test_subbuffer)
|
|||
fail_unless (GST_BUFFER_OFFSET (sub) == -1, "subbuffer has wrong offset");
|
||||
fail_unless (GST_BUFFER_OFFSET_END (sub) == -1,
|
||||
"subbuffer has wrong offset end");
|
||||
gst_buffer_unmap (sub, sdata, ssize);
|
||||
gst_buffer_unmap (sub, &sinfo);
|
||||
gst_buffer_unref (sub);
|
||||
|
||||
/* create a subbuffer of size 0 */
|
||||
sub = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 1, 0);
|
||||
fail_if (sub == NULL, "copy_region of buffer returned NULL");
|
||||
sdata = gst_buffer_map (sub, &ssize, NULL, GST_MAP_READ);
|
||||
fail_unless (ssize == 0, "subbuffer has wrong size");
|
||||
fail_unless (memcmp (data + 1, sdata, 0) == 0,
|
||||
fail_unless (gst_buffer_map (sub, &sinfo, GST_MAP_READ));
|
||||
fail_unless (sinfo.size == 0, "subbuffer has wrong size");
|
||||
fail_unless (memcmp ((guint8 *) info.data + 1, sinfo.data, 0) == 0,
|
||||
"subbuffer contains the wrong data");
|
||||
ASSERT_BUFFER_REFCOUNT (sub, "subbuffer", 1);
|
||||
gst_buffer_unmap (sub, sdata, ssize);
|
||||
gst_buffer_unmap (sub, &sinfo);
|
||||
gst_buffer_unref (sub);
|
||||
|
||||
/* test if metadata is coppied, not a complete buffer copy so only the
|
||||
|
@ -110,7 +109,7 @@ GST_START_TEST (test_subbuffer)
|
|||
/* clean up */
|
||||
gst_buffer_unref (sub);
|
||||
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
||||
|
@ -148,14 +147,13 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_span)
|
||||
{
|
||||
GstBuffer *buffer, *sub1, *sub2, *span;
|
||||
guint8 *data;
|
||||
gsize size;
|
||||
GstMapInfo info;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_WRITE);
|
||||
memcpy (data, "data", 4);
|
||||
gst_buffer_unmap (buffer, data, 4);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_WRITE));
|
||||
memcpy (info.data, "data", 4);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
ASSERT_CRITICAL (gst_buffer_span (NULL, 1, NULL, 2));
|
||||
ASSERT_CRITICAL (gst_buffer_span (buffer, 1, NULL, 2));
|
||||
|
@ -174,56 +172,56 @@ GST_START_TEST (test_span)
|
|||
|
||||
/* span will create a new subbuffer from the parent */
|
||||
span = gst_buffer_span (sub1, 0, sub2, 4);
|
||||
data = gst_buffer_map (span, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (size == 4, "spanned buffer is wrong size");
|
||||
fail_unless (gst_buffer_map (span, &info, GST_MAP_READ));
|
||||
fail_unless (info.size == 4, "spanned buffer is wrong size");
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
|
||||
fail_unless (memcmp (data, "data", 4) == 0,
|
||||
fail_unless (memcmp (info.data, "data", 4) == 0,
|
||||
"spanned buffer contains the wrong data");
|
||||
gst_buffer_unmap (span, data, size);
|
||||
gst_buffer_unmap (span, &info);
|
||||
gst_buffer_unref (span);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 1);
|
||||
|
||||
/* span from non-contiguous buffers will create new buffers */
|
||||
span = gst_buffer_span (sub2, 0, sub1, 4);
|
||||
data = gst_buffer_map (span, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (size == 4, "spanned buffer is wrong size");
|
||||
fail_unless (gst_buffer_map (span, &info, GST_MAP_READ));
|
||||
fail_unless (info.size == 4, "spanned buffer is wrong size");
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
|
||||
fail_unless (memcmp (data, "tada", 4) == 0,
|
||||
fail_unless (memcmp (info.data, "tada", 4) == 0,
|
||||
"spanned buffer contains the wrong data");
|
||||
gst_buffer_unmap (span, data, size);
|
||||
gst_buffer_unmap (span, &info);
|
||||
gst_buffer_unref (span);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 1);
|
||||
|
||||
/* span with different sizes */
|
||||
span = gst_buffer_span (sub1, 1, sub2, 3);
|
||||
data = gst_buffer_map (span, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (size == 3, "spanned buffer is wrong size");
|
||||
fail_unless (gst_buffer_map (span, &info, GST_MAP_READ));
|
||||
fail_unless (info.size == 3, "spanned buffer is wrong size");
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
|
||||
fail_unless (memcmp (data, "ata", 3) == 0,
|
||||
fail_unless (memcmp (info.data, "ata", 3) == 0,
|
||||
"spanned buffer contains the wrong data");
|
||||
gst_buffer_unmap (span, data, size);
|
||||
gst_buffer_unmap (span, &info);
|
||||
gst_buffer_unref (span);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 1);
|
||||
|
||||
span = gst_buffer_span (sub2, 0, sub1, 3);
|
||||
data = gst_buffer_map (span, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (size == 3, "spanned buffer is wrong size");
|
||||
fail_unless (gst_buffer_map (span, &info, GST_MAP_READ));
|
||||
fail_unless (info.size == 3, "spanned buffer is wrong size");
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub1, "sub1", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (sub2, "sub2", 1);
|
||||
ASSERT_BUFFER_REFCOUNT (span, "span", 1);
|
||||
fail_unless (memcmp (data, "tad", 3) == 0,
|
||||
fail_unless (memcmp (info.data, "tad", 3) == 0,
|
||||
"spanned buffer contains the wrong data");
|
||||
gst_buffer_unmap (span, data, size);
|
||||
gst_buffer_unmap (span, &info);
|
||||
gst_buffer_unref (span);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "parent", 1);
|
||||
|
||||
|
@ -257,15 +255,14 @@ create_read_only_buffer (void)
|
|||
GST_START_TEST (test_make_writable)
|
||||
{
|
||||
GstBuffer *buf, *buf2;
|
||||
guint8 *data;
|
||||
gsize size;
|
||||
GstMapInfo info;
|
||||
|
||||
/* create read-only buffer and make it writable */
|
||||
buf = create_read_only_buffer ();
|
||||
|
||||
data = gst_buffer_map (buf, &size, NULL, GST_MAP_WRITE);
|
||||
data[4] = 'a';
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
fail_unless (gst_buffer_map (buf, &info, GST_MAP_WRITE));
|
||||
((guint8 *) info.data)[4] = 'a';
|
||||
gst_buffer_unmap (buf, &info);
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
/* alloc'ed buffer with refcount 1 should be writable */
|
||||
|
@ -289,18 +286,17 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_subbuffer_make_writable)
|
||||
{
|
||||
GstBuffer *buf, *sub_buf;
|
||||
guint8 *data;
|
||||
gsize size;
|
||||
GstMapInfo info;
|
||||
|
||||
/* create sub-buffer of read-only buffer and make it writable */
|
||||
buf = create_read_only_buffer ();
|
||||
|
||||
sub_buf = gst_buffer_copy_region (buf, GST_BUFFER_COPY_ALL, 0, 8);
|
||||
|
||||
data = gst_buffer_map (sub_buf, &size, NULL, GST_MAP_WRITE);
|
||||
fail_if (data == NULL);
|
||||
data[4] = 'a';
|
||||
gst_buffer_unmap (sub_buf, data, size);
|
||||
fail_unless (gst_buffer_map (sub_buf, &info, GST_MAP_WRITE));
|
||||
fail_if (info.data == NULL);
|
||||
((guint8 *) info.data)[4] = 'a';
|
||||
gst_buffer_unmap (sub_buf, &info);
|
||||
gst_buffer_unref (sub_buf);
|
||||
gst_buffer_unref (buf);
|
||||
}
|
||||
|
@ -354,8 +350,7 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_copy)
|
||||
{
|
||||
GstBuffer *buffer, *copy;
|
||||
gsize size, ssize;
|
||||
guint8 *data, *sdata;
|
||||
GstMapInfo info, sinfo;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1);
|
||||
|
@ -366,30 +361,30 @@ GST_START_TEST (test_copy)
|
|||
/* buffers are copied and must point to different memory */
|
||||
fail_if (buffer == copy);
|
||||
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
sdata = gst_buffer_map (copy, &ssize, NULL, GST_MAP_READ);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_READ));
|
||||
fail_unless (gst_buffer_map (copy, &sinfo, GST_MAP_READ));
|
||||
|
||||
/* NOTE that data is refcounted */
|
||||
fail_unless (size == ssize);
|
||||
fail_unless (info.size == sinfo.size);
|
||||
|
||||
gst_buffer_unmap (copy, sdata, ssize);
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (copy, &sinfo);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
gst_buffer_unref (copy);
|
||||
gst_buffer_unref (buffer);
|
||||
|
||||
/* a 0-sized buffer has NULL data as per docs */
|
||||
buffer = gst_buffer_new_and_alloc (0);
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (data == NULL);
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_READ));
|
||||
fail_unless (info.data == NULL);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
/* copying a 0-sized buffer should not crash and also set
|
||||
* the data member NULL. */
|
||||
copy = gst_buffer_copy (buffer);
|
||||
data = gst_buffer_map (copy, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (data == NULL);
|
||||
gst_buffer_unmap (copy, data, size);
|
||||
fail_unless (gst_buffer_map (copy, &info, GST_MAP_READ));
|
||||
fail_unless (info.data == NULL);
|
||||
gst_buffer_unmap (copy, &info);
|
||||
|
||||
gst_buffer_unref (copy);
|
||||
gst_buffer_unref (buffer);
|
||||
|
@ -400,27 +395,26 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_try_new_and_alloc)
|
||||
{
|
||||
GstBuffer *buf;
|
||||
gsize size;
|
||||
guint8 *data;
|
||||
GstMapInfo info;
|
||||
|
||||
/* special case: alloc of 0 bytes results in new buffer with NULL data */
|
||||
buf = gst_buffer_new_and_alloc (0);
|
||||
fail_unless (buf != NULL);
|
||||
fail_unless (GST_IS_BUFFER (buf));
|
||||
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (data == NULL);
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
fail_unless (gst_buffer_map (buf, &info, GST_MAP_READ));
|
||||
fail_unless (info.data == NULL);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
/* normal alloc should still work */
|
||||
buf = gst_buffer_new_and_alloc (640 * 480 * 4);
|
||||
fail_unless (buf != NULL);
|
||||
fail_unless (GST_IS_BUFFER (buf));
|
||||
data = gst_buffer_map (buf, &size, NULL, GST_MAP_WRITE);
|
||||
fail_unless (data != NULL);
|
||||
fail_unless (size == (640 * 480 * 4));
|
||||
data[640 * 479 * 4 + 479] = 0xff;
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
fail_unless (gst_buffer_map (buf, &info, GST_MAP_WRITE));
|
||||
fail_unless (info.data != NULL);
|
||||
fail_unless (info.size == (640 * 480 * 4));
|
||||
((guint8 *) info.data)[640 * 479 * 4 + 479] = 0xff;
|
||||
gst_buffer_unmap (buf, &info);
|
||||
|
||||
gst_buffer_unref (buf);
|
||||
|
||||
|
|
|
@ -35,40 +35,39 @@
|
|||
GST_START_TEST (test_submemory)
|
||||
{
|
||||
GstMemory *memory, *sub;
|
||||
gsize size, maxsize, ssize;
|
||||
guint8 *data, *sdata;
|
||||
GstMapInfo info, sinfo;
|
||||
|
||||
memory = gst_allocator_alloc (NULL, 4, 0);
|
||||
|
||||
/* check sizes, memory starts out empty */
|
||||
data = gst_memory_map (memory, &size, &maxsize, GST_MAP_WRITE);
|
||||
fail_unless (size == 4, "memory has wrong size");
|
||||
fail_unless (maxsize >= 4, "memory has wrong size");
|
||||
memset (data, 0, 4);
|
||||
gst_memory_unmap (memory);
|
||||
fail_unless (gst_memory_map (memory, &info, GST_MAP_WRITE));
|
||||
fail_unless (info.size == 4, "memory has wrong size");
|
||||
fail_unless (info.maxsize >= 4, "memory has wrong size");
|
||||
memset (info.data, 0, 4);
|
||||
gst_memory_unmap (memory, &info);
|
||||
|
||||
data = gst_memory_map (memory, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (gst_memory_map (memory, &info, GST_MAP_READ));
|
||||
|
||||
sub = gst_memory_share (memory, 1, 2);
|
||||
fail_if (sub == NULL, "share of memory returned NULL");
|
||||
|
||||
sdata = gst_memory_map (sub, &ssize, NULL, GST_MAP_READ);
|
||||
fail_unless (ssize == 2, "submemory has wrong size");
|
||||
fail_unless (memcmp (data + 1, sdata, 2) == 0,
|
||||
fail_unless (gst_memory_map (sub, &sinfo, GST_MAP_READ));
|
||||
fail_unless (sinfo.size == 2, "submemory has wrong size");
|
||||
fail_unless (memcmp (((guint8 *) info.data) + 1, sinfo.data, 2) == 0,
|
||||
"submemory contains the wrong data");
|
||||
ASSERT_MEMORY_REFCOUNT (sub, "submemory", 1);
|
||||
gst_memory_unmap (sub);
|
||||
gst_memory_unmap (sub, &sinfo);
|
||||
gst_memory_unref (sub);
|
||||
|
||||
/* create a submemory of size 0 */
|
||||
sub = gst_memory_share (memory, 1, 0);
|
||||
fail_if (sub == NULL, "share memory returned NULL");
|
||||
sdata = gst_memory_map (sub, &ssize, NULL, GST_MAP_READ);
|
||||
fail_unless (ssize == 0, "submemory has wrong size");
|
||||
fail_unless (memcmp (data + 1, sdata, 0) == 0,
|
||||
fail_unless (gst_memory_map (sub, &sinfo, GST_MAP_READ));
|
||||
fail_unless (sinfo.size == 0, "submemory has wrong size");
|
||||
fail_unless (memcmp (((guint8 *) info.data) + 1, sinfo.data, 0) == 0,
|
||||
"submemory contains the wrong data");
|
||||
ASSERT_MEMORY_REFCOUNT (sub, "submemory", 1);
|
||||
gst_memory_unmap (sub);
|
||||
gst_memory_unmap (sub, &sinfo);
|
||||
gst_memory_unref (sub);
|
||||
|
||||
/* test if metadata is coppied, not a complete memory copy so only the
|
||||
|
@ -89,7 +88,7 @@ GST_START_TEST (test_submemory)
|
|||
/* clean up */
|
||||
gst_memory_unref (sub);
|
||||
|
||||
gst_memory_unmap (memory);
|
||||
gst_memory_unmap (memory, &info);
|
||||
gst_memory_unref (memory);
|
||||
}
|
||||
|
||||
|
@ -142,30 +141,29 @@ create_read_only_memory (void)
|
|||
GST_START_TEST (test_writable)
|
||||
{
|
||||
GstMemory *mem, *mem2;
|
||||
guint8 *data;
|
||||
gsize size;
|
||||
GstMapInfo info;
|
||||
|
||||
/* create read-only memory and try to write */
|
||||
mem = create_read_only_memory ();
|
||||
|
||||
ASSERT_CRITICAL (gst_memory_map (mem, &size, NULL, GST_MAP_WRITE));
|
||||
fail_if (gst_memory_map (mem, &info, GST_MAP_WRITE));
|
||||
fail_if (gst_memory_is_writable (mem));
|
||||
|
||||
mem2 = gst_memory_copy (mem, 0, -1);
|
||||
fail_if (gst_memory_is_writable (mem));
|
||||
fail_unless (gst_memory_is_writable (mem2));
|
||||
|
||||
data = gst_memory_map (mem2, &size, NULL, GST_MAP_WRITE);
|
||||
data[4] = 'a';
|
||||
gst_memory_unmap (mem2);
|
||||
fail_unless (gst_memory_map (mem2, &info, GST_MAP_WRITE));
|
||||
((guint8 *) info.data)[4] = 'a';
|
||||
gst_memory_unmap (mem2, &info);
|
||||
|
||||
gst_memory_ref (mem2);
|
||||
ASSERT_CRITICAL (gst_memory_map (mem, &size, NULL, GST_MAP_WRITE));
|
||||
fail_if (gst_memory_map (mem, &info, GST_MAP_WRITE));
|
||||
gst_memory_unref (mem2);
|
||||
|
||||
data = gst_memory_map (mem2, &size, NULL, GST_MAP_WRITE);
|
||||
data[4] = 'a';
|
||||
gst_memory_unmap (mem2);
|
||||
fail_unless (gst_memory_map (mem2, &info, GST_MAP_WRITE));
|
||||
((guint8 *) info.data)[4] = 'a';
|
||||
gst_memory_unmap (mem2, &info);
|
||||
gst_memory_unref (mem2);
|
||||
|
||||
gst_memory_unref (mem);
|
||||
|
@ -176,7 +174,7 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_submemory_writable)
|
||||
{
|
||||
GstMemory *mem, *sub_mem;
|
||||
gsize size;
|
||||
GstMapInfo info;
|
||||
|
||||
/* create sub-memory of read-only memory and try to write */
|
||||
mem = create_read_only_memory ();
|
||||
|
@ -184,8 +182,8 @@ GST_START_TEST (test_submemory_writable)
|
|||
sub_mem = gst_memory_share (mem, 0, 8);
|
||||
fail_if (gst_memory_is_writable (sub_mem));
|
||||
|
||||
ASSERT_CRITICAL (gst_memory_map (mem, &size, NULL, GST_MAP_WRITE));
|
||||
ASSERT_CRITICAL (gst_memory_map (sub_mem, &size, NULL, GST_MAP_WRITE));
|
||||
fail_if (gst_memory_map (mem, &info, GST_MAP_WRITE));
|
||||
fail_if (gst_memory_map (sub_mem, &info, GST_MAP_WRITE));
|
||||
|
||||
gst_memory_unref (sub_mem);
|
||||
gst_memory_unref (mem);
|
||||
|
@ -196,7 +194,7 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_copy)
|
||||
{
|
||||
GstMemory *memory, *copy;
|
||||
gsize size, ssize;
|
||||
GstMapInfo info, sinfo;
|
||||
|
||||
memory = gst_allocator_alloc (NULL, 4, 0);
|
||||
ASSERT_MEMORY_REFCOUNT (memory, "memory", 1);
|
||||
|
@ -207,28 +205,28 @@ GST_START_TEST (test_copy)
|
|||
/* memorys are copied and must point to different memory */
|
||||
fail_if (memory == copy);
|
||||
|
||||
gst_memory_map (memory, &size, NULL, GST_MAP_READ);
|
||||
gst_memory_map (copy, &ssize, NULL, GST_MAP_READ);
|
||||
fail_unless (gst_memory_map (memory, &info, GST_MAP_READ));
|
||||
fail_unless (gst_memory_map (copy, &sinfo, GST_MAP_READ));
|
||||
|
||||
/* NOTE that data is refcounted */
|
||||
fail_unless (size == ssize);
|
||||
fail_unless (info.size == sinfo.size);
|
||||
|
||||
gst_memory_unmap (copy);
|
||||
gst_memory_unmap (memory);
|
||||
gst_memory_unmap (copy, &sinfo);
|
||||
gst_memory_unmap (memory, &info);
|
||||
|
||||
gst_memory_unref (copy);
|
||||
gst_memory_unref (memory);
|
||||
|
||||
memory = gst_allocator_alloc (NULL, 0, 0);
|
||||
gst_memory_map (memory, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (size == 0);
|
||||
gst_memory_unmap (memory);
|
||||
fail_unless (gst_memory_map (memory, &info, GST_MAP_READ));
|
||||
fail_unless (info.size == 0);
|
||||
gst_memory_unmap (memory, &info);
|
||||
|
||||
/* copying a 0-sized memory should not crash */
|
||||
copy = gst_memory_copy (memory, 0, -1);
|
||||
gst_memory_map (copy, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (size == 0);
|
||||
gst_memory_unmap (copy);
|
||||
fail_unless (gst_memory_map (copy, &info, GST_MAP_READ));
|
||||
fail_unless (info.size == 0);
|
||||
gst_memory_unmap (copy, &info);
|
||||
|
||||
gst_memory_unref (copy);
|
||||
gst_memory_unref (memory);
|
||||
|
@ -239,24 +237,23 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_try_new_and_alloc)
|
||||
{
|
||||
GstMemory *mem;
|
||||
gsize size;
|
||||
guint8 *data;
|
||||
GstMapInfo info;
|
||||
|
||||
mem = gst_allocator_alloc (NULL, 0, 0);
|
||||
fail_unless (mem != NULL);
|
||||
data = gst_memory_map (mem, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (size == 0);
|
||||
gst_memory_unmap (mem);
|
||||
fail_unless (gst_memory_map (mem, &info, GST_MAP_READ));
|
||||
fail_unless (info.size == 0);
|
||||
gst_memory_unmap (mem, &info);
|
||||
gst_memory_unref (mem);
|
||||
|
||||
/* normal alloc should still work */
|
||||
mem = gst_allocator_alloc (NULL, 640 * 480 * 4, 0);
|
||||
fail_unless (mem != NULL);
|
||||
data = gst_memory_map (mem, &size, NULL, GST_MAP_WRITE);
|
||||
fail_unless (data != NULL);
|
||||
fail_unless (size == (640 * 480 * 4));
|
||||
data[640 * 479 * 4 + 479] = 0xff;
|
||||
gst_memory_unmap (mem);
|
||||
fail_unless (gst_memory_map (mem, &info, GST_MAP_WRITE));
|
||||
fail_unless (info.data != NULL);
|
||||
fail_unless (info.size == (640 * 480 * 4));
|
||||
((guint8 *) info.data)[640 * 479 * 4 + 479] = 0xff;
|
||||
gst_memory_unmap (mem, &info);
|
||||
|
||||
gst_memory_unref (mem);
|
||||
|
||||
|
@ -378,9 +375,9 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_map)
|
||||
{
|
||||
GstMemory *mem;
|
||||
GstMapInfo info;
|
||||
gsize maxalloc;
|
||||
gsize size, maxsize, offset;
|
||||
gpointer data;
|
||||
gsize size, offset;
|
||||
|
||||
/* one memory block */
|
||||
mem = gst_allocator_alloc (NULL, 100, 0);
|
||||
|
@ -391,12 +388,12 @@ GST_START_TEST (test_map)
|
|||
fail_unless (maxalloc >= 100);
|
||||
|
||||
/* see if simply mapping works */
|
||||
data = gst_memory_map (mem, &size, &maxsize, GST_MAP_READ);
|
||||
fail_unless (data != NULL);
|
||||
fail_unless (size == 100);
|
||||
fail_unless (maxsize == maxalloc);
|
||||
fail_unless (gst_memory_map (mem, &info, GST_MAP_READ));
|
||||
fail_unless (info.data != NULL);
|
||||
fail_unless (info.size == 100);
|
||||
fail_unless (info.maxsize == maxalloc);
|
||||
|
||||
gst_memory_unmap (mem);
|
||||
gst_memory_unmap (mem, &info);
|
||||
gst_memory_unref (mem);
|
||||
}
|
||||
|
||||
|
@ -405,51 +402,50 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_map_nested)
|
||||
{
|
||||
GstMemory *mem;
|
||||
gsize size1, maxsize1, size2, maxsize2;
|
||||
gpointer data1, data2;
|
||||
GstMapInfo info1, info2;
|
||||
|
||||
mem = gst_allocator_alloc (NULL, 100, 0);
|
||||
|
||||
/* nested mapping */
|
||||
data1 = gst_memory_map (mem, &size1, &maxsize1, GST_MAP_READ);
|
||||
fail_unless (data1 != NULL);
|
||||
fail_unless (size1 == 100);
|
||||
fail_unless (gst_memory_map (mem, &info1, GST_MAP_READ));
|
||||
fail_unless (info1.data != NULL);
|
||||
fail_unless (info1.size == 100);
|
||||
|
||||
data2 = gst_memory_map (mem, &size2, &maxsize2, GST_MAP_READ);
|
||||
fail_unless (data2 == data1);
|
||||
fail_unless (size2 == 100);
|
||||
fail_unless (gst_memory_map (mem, &info2, GST_MAP_READ));
|
||||
fail_unless (info2.data == info1.data);
|
||||
fail_unless (info2.size == 100);
|
||||
|
||||
/* unmap */
|
||||
gst_memory_unmap (mem);
|
||||
gst_memory_unmap (mem);
|
||||
gst_memory_unmap (mem, &info2);
|
||||
gst_memory_unmap (mem, &info1);
|
||||
|
||||
data1 = gst_memory_map (mem, &size1, &maxsize1, GST_MAP_READ);
|
||||
fail_unless (gst_memory_map (mem, &info1, GST_MAP_READ));
|
||||
/* not allowed */
|
||||
ASSERT_CRITICAL (gst_memory_map (mem, &size2, &maxsize2, GST_MAP_WRITE));
|
||||
ASSERT_CRITICAL (gst_memory_map (mem, &size2, &maxsize2, GST_MAP_READWRITE));
|
||||
data2 = gst_memory_map (mem, &size2, &maxsize2, GST_MAP_READ);
|
||||
gst_memory_unmap (mem);
|
||||
gst_memory_unmap (mem);
|
||||
fail_if (gst_memory_map (mem, &info2, GST_MAP_WRITE));
|
||||
fail_if (gst_memory_map (mem, &info2, GST_MAP_READWRITE));
|
||||
fail_unless (gst_memory_map (mem, &info2, GST_MAP_READ));
|
||||
gst_memory_unmap (mem, &info2);
|
||||
gst_memory_unmap (mem, &info1);
|
||||
fail_unless (mem->state == 0);
|
||||
|
||||
data1 = gst_memory_map (mem, &size1, &maxsize1, GST_MAP_WRITE);
|
||||
fail_unless (gst_memory_map (mem, &info1, GST_MAP_WRITE));
|
||||
/* not allowed */
|
||||
ASSERT_CRITICAL (gst_memory_map (mem, &size2, &maxsize2, GST_MAP_READ));
|
||||
ASSERT_CRITICAL (gst_memory_map (mem, &size2, &maxsize2, GST_MAP_READWRITE));
|
||||
data2 = gst_memory_map (mem, &size2, &maxsize2, GST_MAP_WRITE);
|
||||
gst_memory_unmap (mem);
|
||||
gst_memory_unmap (mem);
|
||||
fail_if (gst_memory_map (mem, &info2, GST_MAP_READ));
|
||||
fail_if (gst_memory_map (mem, &info2, GST_MAP_READWRITE));
|
||||
fail_unless (gst_memory_map (mem, &info2, GST_MAP_WRITE));
|
||||
gst_memory_unmap (mem, &info1);
|
||||
gst_memory_unmap (mem, &info2);
|
||||
/* nothing was mapped */
|
||||
ASSERT_CRITICAL (gst_memory_unmap (mem));
|
||||
ASSERT_CRITICAL (gst_memory_unmap (mem, &info2));
|
||||
|
||||
data1 = gst_memory_map (mem, &size1, &maxsize1, GST_MAP_READWRITE);
|
||||
data2 = gst_memory_map (mem, &size2, &maxsize2, GST_MAP_READ);
|
||||
gst_memory_unmap (mem);
|
||||
data2 = gst_memory_map (mem, &size2, &maxsize2, GST_MAP_WRITE);
|
||||
gst_memory_unmap (mem);
|
||||
gst_memory_unmap (mem);
|
||||
fail_unless (gst_memory_map (mem, &info1, GST_MAP_READWRITE));
|
||||
fail_unless (gst_memory_map (mem, &info2, GST_MAP_READ));
|
||||
gst_memory_unmap (mem, &info2);
|
||||
fail_unless (gst_memory_map (mem, &info2, GST_MAP_WRITE));
|
||||
gst_memory_unmap (mem, &info2);
|
||||
gst_memory_unmap (mem, &info1);
|
||||
/* nothing was mapped */
|
||||
ASSERT_CRITICAL (gst_memory_unmap (mem));
|
||||
ASSERT_CRITICAL (gst_memory_unmap (mem, &info1));
|
||||
|
||||
gst_memory_unref (mem);
|
||||
}
|
||||
|
@ -459,48 +455,47 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_map_resize)
|
||||
{
|
||||
GstMemory *mem;
|
||||
gsize size, maxsize, maxalloc, offset;
|
||||
gpointer data;
|
||||
GstMapInfo info;
|
||||
gsize size, maxalloc, offset;
|
||||
|
||||
mem = gst_allocator_alloc (NULL, 100, 0);
|
||||
|
||||
/* do mapping */
|
||||
data = gst_memory_map (mem, &size, &maxsize, GST_MAP_READ);
|
||||
fail_unless (data != NULL);
|
||||
fail_unless (size == 100);
|
||||
fail_unless (gst_memory_map (mem, &info, GST_MAP_READ));
|
||||
fail_unless (info.data != NULL);
|
||||
fail_unless (info.size == 100);
|
||||
|
||||
/* resize the buffer */
|
||||
gst_memory_resize (mem, 1, size - 1);
|
||||
gst_memory_resize (mem, 1, info.size - 1);
|
||||
size = gst_memory_get_sizes (mem, &offset, &maxalloc);
|
||||
fail_unless (size == 99);
|
||||
fail_unless (offset == 1);
|
||||
fail_unless (maxalloc >= 100);
|
||||
gst_memory_unmap (mem);
|
||||
gst_memory_unmap (mem, &info);
|
||||
|
||||
size = gst_memory_get_sizes (mem, &offset, &maxalloc);
|
||||
fail_unless (size == 99);
|
||||
fail_unless (offset == 1);
|
||||
fail_unless (maxalloc >= 100);
|
||||
|
||||
data = gst_memory_map (mem, &size, &maxsize, GST_MAP_READ);
|
||||
fail_unless (data != NULL);
|
||||
fail_unless (size == 99);
|
||||
fail_unless (offset == 1);
|
||||
fail_unless (maxsize >= 100);
|
||||
gst_memory_unmap (mem);
|
||||
fail_unless (gst_memory_map (mem, &info, GST_MAP_READ));
|
||||
fail_unless (info.data != NULL);
|
||||
fail_unless (info.size == 99);
|
||||
fail_unless (info.maxsize >= 100);
|
||||
gst_memory_unmap (mem, &info);
|
||||
|
||||
/* and larger */
|
||||
data = gst_memory_map (mem, &size, &maxsize, GST_MAP_READ);
|
||||
fail_unless (gst_memory_map (mem, &info, GST_MAP_READ));
|
||||
gst_memory_resize (mem, -1, 100);
|
||||
gst_memory_unmap (mem);
|
||||
gst_memory_unmap (mem, &info);
|
||||
|
||||
size = gst_memory_get_sizes (mem, &offset, &maxalloc);
|
||||
fail_unless (size == 100);
|
||||
fail_unless (offset == 0);
|
||||
fail_unless (maxalloc >= 100);
|
||||
|
||||
data = gst_memory_map (mem, &size, &maxsize, GST_MAP_READ);
|
||||
gst_memory_unmap (mem);
|
||||
fail_unless (gst_memory_map (mem, &info, GST_MAP_READ));
|
||||
gst_memory_unmap (mem, &info);
|
||||
gst_memory_unref (mem);
|
||||
}
|
||||
|
||||
|
|
|
@ -127,15 +127,15 @@ GST_START_TEST (test_meta_test)
|
|||
{
|
||||
GstBuffer *buffer, *copy, *subbuf;
|
||||
GstMetaTest *meta;
|
||||
gpointer data;
|
||||
GstMapInfo info;
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (4);
|
||||
fail_if (buffer == NULL);
|
||||
|
||||
data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
|
||||
fail_if (data == NULL);
|
||||
memset (data, 0, 4);
|
||||
gst_buffer_unmap (buffer, data, 4);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_WRITE));
|
||||
fail_if (info.data == NULL);
|
||||
memset (info.data, 0, 4);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
/* add some metadata */
|
||||
meta = GST_META_TEST_ADD (buffer);
|
||||
|
|
|
@ -721,14 +721,11 @@ buffer_from_string (const gchar * str)
|
|||
{
|
||||
guint size;
|
||||
GstBuffer *buf;
|
||||
gpointer data;
|
||||
|
||||
size = strlen (str);
|
||||
buf = gst_buffer_new_and_alloc (size);
|
||||
|
||||
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
|
||||
memcpy (data, str, size);
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
gst_buffer_fill (buf, 0, str, size);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
@ -737,12 +734,12 @@ static gboolean
|
|||
buffer_compare (GstBuffer * buf, const gchar * str, gsize size)
|
||||
{
|
||||
gboolean res;
|
||||
gpointer data;
|
||||
GstMapInfo info;
|
||||
|
||||
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_READ);
|
||||
res = memcmp (data, str, size) == 0;
|
||||
GST_DEBUG ("%s <-> %s: %d", (gchar *) data, str, res);
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
fail_unless (gst_buffer_map (buf, &info, GST_MAP_READ));
|
||||
res = memcmp (info.data, str, size) == 0;
|
||||
GST_DEBUG ("%s <-> %s: %d", (gchar *) info.data, str, res);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -505,6 +505,7 @@ GST_START_TEST (test_vararg_getters)
|
|||
GstBuffer *buf, *buf2;
|
||||
gboolean ret;
|
||||
GstCaps *caps, *caps2;
|
||||
GstMapInfo info;
|
||||
gdouble d;
|
||||
gint64 i64;
|
||||
gchar *c;
|
||||
|
@ -513,11 +514,12 @@ GST_START_TEST (test_vararg_getters)
|
|||
|
||||
buf = gst_buffer_new_and_alloc (3);
|
||||
|
||||
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
|
||||
fail_unless (gst_buffer_map (buf, &info, GST_MAP_WRITE));
|
||||
data = info.data;
|
||||
data[0] = 0xf0;
|
||||
data[1] = 0x66;
|
||||
data[2] = 0x0d;
|
||||
gst_buffer_unmap (buf, data, 3);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
|
||||
caps = gst_caps_new_empty_simple ("video/x-foo");
|
||||
|
||||
|
|
|
@ -53,14 +53,11 @@ GST_START_TEST (test_serialize_buffer)
|
|||
gchar *serialized;
|
||||
static const char *buf_data = "1234567890abcdef";
|
||||
gint len;
|
||||
gpointer data;
|
||||
|
||||
len = strlen (buf_data);
|
||||
buf = gst_buffer_new_and_alloc (len);
|
||||
|
||||
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
|
||||
memcpy (data, buf_data, len);
|
||||
gst_buffer_unmap (buf, data, len);
|
||||
gst_buffer_fill (buf, 0, buf_data, len);
|
||||
|
||||
ASSERT_MINI_OBJECT_REFCOUNT (buf, "buffer", 1);
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@ GST_START_TEST (test_peek1)
|
|||
GstAdapter *adapter;
|
||||
GstBuffer *buffer;
|
||||
guint avail;
|
||||
const guint8 *bufdata, *data1, *data2;
|
||||
GstMapInfo info;
|
||||
const guint8 *data1, *data2;
|
||||
|
||||
adapter = gst_adapter_new ();
|
||||
fail_if (adapter == NULL);
|
||||
|
@ -44,7 +45,7 @@ GST_START_TEST (test_peek1)
|
|||
/* push single buffer in adapter */
|
||||
buffer = gst_buffer_new_and_alloc (512);
|
||||
|
||||
bufdata = gst_buffer_map (buffer, NULL, NULL, GST_MAP_READ);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_READ));
|
||||
|
||||
fail_if (buffer == NULL);
|
||||
gst_adapter_push (adapter, buffer);
|
||||
|
@ -68,7 +69,7 @@ GST_START_TEST (test_peek1)
|
|||
data1 = gst_adapter_map (adapter, 512);
|
||||
fail_if (data1 == NULL);
|
||||
/* it should point to the buffer data as well */
|
||||
fail_if (data1 != bufdata);
|
||||
fail_if (data1 != info.data);
|
||||
gst_adapter_unmap (adapter);
|
||||
|
||||
data2 = gst_adapter_map (adapter, 512);
|
||||
|
@ -98,7 +99,7 @@ GST_START_TEST (test_peek1)
|
|||
fail_if (data2 == NULL);
|
||||
/* peek should return the same old pointer + 10 */
|
||||
fail_if (data2 != data1 + 10);
|
||||
fail_if (data2 != bufdata + 10);
|
||||
fail_if (data2 != (guint8 *) info.data + 10);
|
||||
gst_adapter_unmap (adapter);
|
||||
|
||||
/* flush some more */
|
||||
|
@ -113,7 +114,7 @@ GST_START_TEST (test_peek1)
|
|||
data2 = gst_adapter_map (adapter, 2);
|
||||
fail_if (data2 == NULL);
|
||||
fail_if (data2 != data1 + 510);
|
||||
fail_if (data2 != bufdata + 510);
|
||||
fail_if (data2 != (guint8 *) info.data + 510);
|
||||
gst_adapter_unmap (adapter);
|
||||
|
||||
/* flush some more */
|
||||
|
@ -158,17 +159,16 @@ GST_START_TEST (test_take1)
|
|||
GstAdapter *adapter;
|
||||
GstBuffer *buffer, *buffer2;
|
||||
guint avail;
|
||||
guint8 *data, *data2;
|
||||
gsize size, size2;
|
||||
GstMapInfo info, info2;
|
||||
|
||||
adapter = gst_adapter_new ();
|
||||
fail_unless (adapter != NULL);
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (100);
|
||||
fail_unless (buffer != NULL);
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (data != NULL);
|
||||
fail_unless (size == 100);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_READ));
|
||||
fail_unless (info.data != NULL);
|
||||
fail_unless (info.size == 100);
|
||||
|
||||
/* push in the adapter */
|
||||
gst_adapter_push (adapter, buffer);
|
||||
|
@ -180,19 +180,19 @@ GST_START_TEST (test_take1)
|
|||
buffer2 = gst_adapter_take_buffer (adapter, 100);
|
||||
fail_unless (buffer2 != NULL);
|
||||
|
||||
data2 = gst_buffer_map (buffer2, &size2, NULL, GST_MAP_READ);
|
||||
fail_unless (data2 != NULL);
|
||||
fail_unless (size2 == 100);
|
||||
fail_unless (gst_buffer_map (buffer2, &info2, GST_MAP_READ));
|
||||
fail_unless (info2.data != NULL);
|
||||
fail_unless (info2.size == 100);
|
||||
|
||||
avail = gst_adapter_available (adapter);
|
||||
fail_unless (avail == 0);
|
||||
|
||||
/* the buffer should be the same */
|
||||
fail_unless (buffer == buffer2);
|
||||
fail_unless (data == data2);
|
||||
fail_unless (info.data == info2.data);
|
||||
|
||||
gst_buffer_unmap (buffer, data, size);
|
||||
gst_buffer_unmap (buffer2, data2, size2);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
gst_buffer_unmap (buffer2, &info2);
|
||||
|
||||
gst_buffer_unref (buffer2);
|
||||
|
||||
|
@ -218,17 +218,16 @@ GST_START_TEST (test_take3)
|
|||
GstAdapter *adapter;
|
||||
GstBuffer *buffer, *buffer2;
|
||||
guint avail;
|
||||
guint8 *data, *data2;
|
||||
gsize size, size2;
|
||||
GstMapInfo info, info2;
|
||||
|
||||
adapter = gst_adapter_new ();
|
||||
fail_unless (adapter != NULL);
|
||||
|
||||
buffer = gst_buffer_new_and_alloc (100);
|
||||
fail_unless (buffer != NULL);
|
||||
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (data != NULL);
|
||||
fail_unless (size == 100);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_READ));
|
||||
fail_unless (info.data != NULL);
|
||||
fail_unless (info.size == 100);
|
||||
|
||||
/* set up and push subbuffers */
|
||||
buffer2 = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, 0, 25);
|
||||
|
@ -248,15 +247,15 @@ GST_START_TEST (test_take3)
|
|||
/* take out buffer */
|
||||
buffer2 = gst_adapter_take_buffer (adapter, 100);
|
||||
fail_unless (buffer2 != NULL);
|
||||
data2 = gst_buffer_map (buffer2, &size2, NULL, GST_MAP_READ);
|
||||
fail_unless (data2 != NULL);
|
||||
fail_unless (size2 == 100);
|
||||
fail_unless (gst_buffer_map (buffer2, &info2, GST_MAP_READ));
|
||||
fail_unless (info2.data != NULL);
|
||||
fail_unless (info2.size == 100);
|
||||
|
||||
avail = gst_adapter_available (adapter);
|
||||
fail_unless (avail == 0);
|
||||
|
||||
/* the data should be the same */
|
||||
fail_unless (data == data2);
|
||||
fail_unless (info.data == info2.data);
|
||||
|
||||
gst_buffer_unref (buffer2);
|
||||
|
||||
|
@ -276,18 +275,20 @@ create_and_fill_adapter (void)
|
|||
|
||||
for (i = 0; i < 10000; i += 4) {
|
||||
GstBuffer *buf;
|
||||
guint8 *data, *ptr;
|
||||
GstMapInfo info;
|
||||
guint8 *ptr;
|
||||
|
||||
buf = gst_buffer_new_and_alloc (sizeof (guint32) * 4);
|
||||
fail_unless (buf != NULL);
|
||||
|
||||
ptr = data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
|
||||
fail_unless (gst_buffer_map (buf, &info, GST_MAP_WRITE));
|
||||
ptr = info.data;
|
||||
|
||||
for (j = 0; j < 4; j++) {
|
||||
GST_WRITE_UINT32_LE (ptr, i + j);
|
||||
ptr += sizeof (guint32);
|
||||
}
|
||||
gst_buffer_unmap (buf, data, sizeof (guint32) * 4);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
|
||||
gst_adapter_push (adapter, buf);
|
||||
}
|
||||
|
@ -330,12 +331,11 @@ GST_START_TEST (test_take_buf_order)
|
|||
adapter = create_and_fill_adapter ();
|
||||
while (gst_adapter_available (adapter) >= sizeof (guint32)) {
|
||||
GstBuffer *buf = gst_adapter_take_buffer (adapter, sizeof (guint32));
|
||||
gpointer data;
|
||||
gsize size;
|
||||
GstMapInfo info;
|
||||
|
||||
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (GST_READ_UINT32_LE (data) == i);
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
fail_unless (gst_buffer_map (buf, &info, GST_MAP_READ));
|
||||
fail_unless (GST_READ_UINT32_LE (info.data) == i);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
|
||||
i++;
|
||||
|
||||
|
@ -561,7 +561,7 @@ GST_START_TEST (test_scan)
|
|||
{
|
||||
GstAdapter *adapter;
|
||||
GstBuffer *buffer;
|
||||
guint8 *data;
|
||||
GstMapInfo info;
|
||||
guint offset;
|
||||
guint i;
|
||||
|
||||
|
@ -570,11 +570,11 @@ GST_START_TEST (test_scan)
|
|||
|
||||
buffer = gst_buffer_new_and_alloc (100);
|
||||
|
||||
data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_WRITE));
|
||||
/* fill with pattern */
|
||||
for (i = 0; i < 100; i++)
|
||||
data[i] = i;
|
||||
gst_buffer_unmap (buffer, data, 100);
|
||||
((guint8 *) info.data)[i] = i;
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
gst_adapter_push (adapter, buffer);
|
||||
|
||||
|
@ -634,11 +634,11 @@ GST_START_TEST (test_scan)
|
|||
/* add another buffer */
|
||||
buffer = gst_buffer_new_and_alloc (100);
|
||||
|
||||
data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_WRITE));
|
||||
/* fill with pattern */
|
||||
for (i = 0; i < 100; i++)
|
||||
data[i] = i + 100;
|
||||
gst_buffer_unmap (buffer, data, 100);
|
||||
((guint8 *) info.data)[i] = i + 100;
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
gst_adapter_push (adapter, buffer);
|
||||
|
||||
|
@ -766,8 +766,9 @@ GST_START_TEST (test_take_list)
|
|||
while (gst_adapter_available (adapter) >= sizeof (guint32)) {
|
||||
GList *list, *walk;
|
||||
GstBuffer *buf;
|
||||
gsize size, left;
|
||||
guint8 *data, *ptr;
|
||||
gsize left;
|
||||
GstMapInfo info;
|
||||
guint8 *ptr;
|
||||
|
||||
list = gst_adapter_take_list (adapter, sizeof (guint32) * 5);
|
||||
fail_unless (list != NULL);
|
||||
|
@ -775,16 +776,18 @@ GST_START_TEST (test_take_list)
|
|||
for (walk = list; walk; walk = g_list_next (walk)) {
|
||||
buf = walk->data;
|
||||
|
||||
ptr = data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
|
||||
fail_unless (gst_buffer_map (buf, &info, GST_MAP_READ));
|
||||
|
||||
ptr = info.data;
|
||||
left = info.size;
|
||||
|
||||
left = size;
|
||||
while (left > 0) {
|
||||
fail_unless (GST_READ_UINT32_LE (ptr) == i);
|
||||
i++;
|
||||
ptr += sizeof (guint32);
|
||||
left -= sizeof (guint32);
|
||||
}
|
||||
gst_buffer_unmap (buf, data, size);
|
||||
gst_buffer_unmap (buf, &info);
|
||||
|
||||
gst_buffer_unref (buf);
|
||||
}
|
||||
|
|
|
@ -46,8 +46,7 @@ GST_START_TEST (test_initialization)
|
|||
GstBitReader reader = GST_BIT_READER_INIT (data, 4);
|
||||
GstBitReader *reader2;
|
||||
guint8 x = 0;
|
||||
guint8 *bdata;
|
||||
gsize bsize;
|
||||
GstMapInfo info;
|
||||
|
||||
gst_buffer_take_memory (buffer, -1,
|
||||
gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, data, NULL, 4, 0, 4));
|
||||
|
@ -65,13 +64,13 @@ GST_START_TEST (test_initialization)
|
|||
fail_unless (gst_bit_reader_get_bits_uint8 (&reader, &x, 8));
|
||||
fail_unless_equals_int (x, 0x02);
|
||||
|
||||
bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
|
||||
gst_bit_reader_init (&reader, bdata, bsize);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_READ));
|
||||
gst_bit_reader_init (&reader, info.data, info.size);
|
||||
fail_unless (gst_bit_reader_get_bits_uint8 (&reader, &x, 8));
|
||||
fail_unless_equals_int (x, 0x01);
|
||||
fail_unless (gst_bit_reader_get_bits_uint8 (&reader, &x, 8));
|
||||
fail_unless_equals_int (x, 0x02);
|
||||
gst_buffer_unmap (buffer, bdata, bsize);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
reader2 = gst_bit_reader_new (data, 4);
|
||||
fail_unless (gst_bit_reader_get_bits_uint8 (reader2, &x, 8));
|
||||
|
@ -80,14 +79,14 @@ GST_START_TEST (test_initialization)
|
|||
fail_unless_equals_int (x, 0x02);
|
||||
gst_bit_reader_free (reader2);
|
||||
|
||||
bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
|
||||
reader2 = gst_bit_reader_new (bdata, bsize);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_READ));
|
||||
reader2 = gst_bit_reader_new (info.data, info.size);
|
||||
fail_unless (gst_bit_reader_get_bits_uint8 (reader2, &x, 8));
|
||||
fail_unless_equals_int (x, 0x01);
|
||||
fail_unless (gst_bit_reader_get_bits_uint8 (reader2, &x, 8));
|
||||
fail_unless_equals_int (x, 0x02);
|
||||
gst_bit_reader_free (reader2);
|
||||
gst_buffer_unmap (buffer, bdata, bsize);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
|
|
@ -46,8 +46,7 @@ GST_START_TEST (test_initialization)
|
|||
GstByteReader reader = GST_BYTE_READER_INIT (data, 4);
|
||||
GstByteReader *reader2;
|
||||
guint8 x = 0;
|
||||
guint8 *bdata;
|
||||
gsize bsize;
|
||||
GstMapInfo info;
|
||||
|
||||
gst_buffer_take_memory (buffer, -1,
|
||||
gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, data, NULL, 4, 0, 4));
|
||||
|
@ -65,13 +64,13 @@ GST_START_TEST (test_initialization)
|
|||
fail_unless (gst_byte_reader_get_uint8 (&reader, &x));
|
||||
fail_unless_equals_int (x, 0x02);
|
||||
|
||||
bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
|
||||
gst_byte_reader_init (&reader, bdata, bsize);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_READ));
|
||||
gst_byte_reader_init (&reader, info.data, info.size);
|
||||
fail_unless (gst_byte_reader_get_uint8 (&reader, &x));
|
||||
fail_unless_equals_int (x, 0x01);
|
||||
fail_unless (gst_byte_reader_get_uint8 (&reader, &x));
|
||||
fail_unless_equals_int (x, 0x02);
|
||||
gst_buffer_unmap (buffer, bdata, bsize);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
reader2 = gst_byte_reader_new (data, 4);
|
||||
fail_unless (gst_byte_reader_get_uint8 (reader2, &x));
|
||||
|
@ -80,14 +79,14 @@ GST_START_TEST (test_initialization)
|
|||
fail_unless_equals_int (x, 0x02);
|
||||
gst_byte_reader_free (reader2);
|
||||
|
||||
bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
|
||||
reader2 = gst_byte_reader_new (bdata, bsize);
|
||||
fail_unless (gst_buffer_map (buffer, &info, GST_MAP_READ));
|
||||
reader2 = gst_byte_reader_new (info.data, info.size);
|
||||
fail_unless (gst_byte_reader_get_uint8 (reader2, &x));
|
||||
fail_unless_equals_int (x, 0x01);
|
||||
fail_unless (gst_byte_reader_get_uint8 (reader2, &x));
|
||||
fail_unless_equals_int (x, 0x02);
|
||||
gst_byte_reader_free (reader2);
|
||||
gst_buffer_unmap (buffer, bdata, bsize);
|
||||
gst_buffer_unmap (buffer, &info);
|
||||
|
||||
gst_buffer_unref (buffer);
|
||||
}
|
||||
|
|
|
@ -47,9 +47,7 @@ run_test_take (struct TestParams *params)
|
|||
for (i = 0; i < ntimes; i++) {
|
||||
buf = gst_buffer_new_and_alloc (params->write_size);
|
||||
|
||||
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
|
||||
memset (data, 0, params->write_size);
|
||||
gst_buffer_unmap (buf, data, params->write_size);
|
||||
gst_buffer_memset (buf, 0, 0, params->write_size);
|
||||
|
||||
gst_adapter_push (adapter, buf);
|
||||
}
|
||||
|
@ -74,14 +72,11 @@ run_test_take_buffer (struct TestParams *params)
|
|||
GstBuffer *buf;
|
||||
int i;
|
||||
gint ntimes = params->tot_size / params->write_size;
|
||||
guint8 *data;
|
||||
|
||||
for (i = 0; i < ntimes; i++) {
|
||||
buf = gst_buffer_new_and_alloc (params->write_size);
|
||||
|
||||
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
|
||||
memset (data, 0, params->write_size);
|
||||
gst_buffer_unmap (buf, data, params->write_size);
|
||||
gst_buffer_memset (buf, 0, 0, params->write_size);
|
||||
|
||||
gst_adapter_push (adapter, buf);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue