videometa: use new buffer methods when mapping memory
Use _find_memory and _map_range to simplify, improve and optimize the memory mapping of video frames.
This commit is contained in:
parent
6f8347de9f
commit
1d60bd12e5
@ -119,45 +119,24 @@ static gboolean
|
|||||||
default_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
|
default_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
|
||||||
gpointer * data, gint * stride, GstMapFlags flags)
|
gpointer * data, gint * stride, GstMapFlags flags)
|
||||||
{
|
{
|
||||||
guint n, i;
|
guint offset, idx, length;
|
||||||
guint offset;
|
gsize skip;
|
||||||
GstBuffer *buffer = meta->buffer;
|
GstBuffer *buffer = meta->buffer;
|
||||||
|
|
||||||
if ((n = gst_buffer_n_memory (buffer)) == 0)
|
offset = meta->offset[plane];
|
||||||
|
|
||||||
|
/* find the memory block for this plane, this is the memory block containing
|
||||||
|
* the plane offset. FIXME use plane size */
|
||||||
|
if (!gst_buffer_find_memory (buffer, offset, 1, &idx, &length, &skip))
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
offset = meta->offset[plane];
|
if (!gst_buffer_map_range (buffer, idx, length, info, flags))
|
||||||
*stride = meta->stride[plane];
|
|
||||||
/* find the memory block for this plane, this is the memory block containing
|
|
||||||
* the plane offset. @offset will be updated with the offset inside the memory
|
|
||||||
* block where the plane starts. */
|
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
GstMemory *mem = NULL;
|
|
||||||
gsize size;
|
|
||||||
|
|
||||||
mem = gst_buffer_get_memory (buffer, i);
|
|
||||||
size = gst_memory_get_sizes (mem, NULL, NULL);
|
|
||||||
|
|
||||||
if (offset < size) {
|
|
||||||
GstMemory *mapped;
|
|
||||||
|
|
||||||
if (!(mapped = gst_memory_make_mapped (mem, info, flags)))
|
|
||||||
goto cannot_map;
|
goto cannot_map;
|
||||||
|
|
||||||
/* buffer is writable when WRITE map is requested, we checked this in
|
*stride = meta->stride[plane];
|
||||||
* _map * */
|
*data = (guint8 *) info->data + skip;
|
||||||
if (mapped != mem && (flags & GST_MAP_WRITE))
|
|
||||||
gst_buffer_replace_memory (buffer, i, gst_memory_ref (mapped));
|
|
||||||
|
|
||||||
*data = (guint8 *) info->data + offset;
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
|
||||||
offset -= size;
|
|
||||||
gst_memory_unref (mem);
|
|
||||||
}
|
|
||||||
GST_DEBUG ("no memory found for offset %" G_GSIZE_FORMAT,
|
|
||||||
meta->offset[plane]);
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
/* ERRORS */
|
/* ERRORS */
|
||||||
no_memory:
|
no_memory:
|
||||||
@ -175,8 +154,9 @@ cannot_map:
|
|||||||
static gboolean
|
static gboolean
|
||||||
default_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info)
|
default_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info)
|
||||||
{
|
{
|
||||||
gst_memory_unmap (info->memory, info);
|
GstBuffer *buffer = meta->buffer;
|
||||||
gst_memory_unref (info->memory);
|
|
||||||
|
gst_buffer_unmap (buffer, info);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user