#endif
#include <stdlib.h>
#include "gstmsdksystemmemory.h"
+#include <string.h>
#ifdef _WIN32
#define posix_memalign(d, a, s) ((*((void**)d) = _aligned_malloc(s, a)) ? 0 : -1)
mem->surface = gst_msdk_system_allocator_create_surface (base_allocator);
vip = &allocator->image_info;
- gst_memory_init (&mem->parent_instance, GST_MEMORY_FLAG_NO_SHARE,
+ gst_memory_init (&mem->parent_instance, 0,
base_allocator, NULL, GST_VIDEO_INFO_SIZE (vip), 0, 0,
GST_VIDEO_INFO_SIZE (vip));
{
}
+static GstMemory *
+gst_msdk_system_memory_copy (GstMemory * base_mem, gssize offset, gssize size)
+{
+ GstMsdkSystemMemory *copy;
+ GstVideoInfo *info;
+ GstMsdkSystemAllocator *msdk_allocator;
+ gsize mem_size;
+
+ /* FIXME: can we consider offset and size here ? */
+ copy =
+ (GstMsdkSystemMemory *) gst_msdk_system_memory_new (base_mem->allocator);
+
+ msdk_allocator = GST_MSDK_SYSTEM_ALLOCATOR_CAST (base_mem->allocator);
+
+ info = &msdk_allocator->image_info;
+ mem_size = GST_VIDEO_INFO_SIZE (info);
+
+ memcpy (copy->cache, GST_MSDK_SYSTEM_MEMORY_CAST (base_mem)->cache, mem_size);
+
+ return GST_MEMORY_CAST (copy);
+}
+
/* GstMsdkSystemAllocator */
G_DEFINE_TYPE (GstMsdkSystemAllocator, gst_msdk_system_allocator,
GST_TYPE_ALLOCATOR);
base_allocator->mem_type = GST_MSDK_SYSTEM_MEMORY_NAME;
base_allocator->mem_map_full = gst_msdk_system_memory_map_full;
base_allocator->mem_unmap = gst_msdk_system_memory_unmap;
+ base_allocator->mem_copy = gst_msdk_system_memory_copy;
GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC);
}
return NULL;
vip = &allocator->image_info;
- gst_memory_init (&mem->parent_instance, GST_MEMORY_FLAG_NO_SHARE,
+ gst_memory_init (&mem->parent_instance, 0,
base_allocator, NULL, GST_VIDEO_INFO_SIZE (vip), 0, 0,
GST_VIDEO_INFO_SIZE (vip));
mem->surface->Data.MemId, &mem->surface->Data);
}
+static GstMemory *
+gst_msdk_video_memory_copy (GstMemory * base_mem, gssize offset, gssize size)
+{
+ GstMemory *copy;
+ GstVideoInfo *info;
+ GstMsdkVideoAllocator *msdk_video_allocator;
+ gsize mem_size;
+ GstMapInfo src_map, dst_map;
+
+ /* FIXME: can we consider offset and size here ? */
+ copy = gst_msdk_video_memory_new (base_mem->allocator);
+
+ if (!copy) {
+ GST_ERROR_OBJECT (base_mem->allocator, "Failed to create new video memory");
+ return NULL;
+ }
+
+ msdk_video_allocator = GST_MSDK_VIDEO_ALLOCATOR_CAST (base_mem->allocator);
+
+ info = &msdk_video_allocator->image_info;
+ mem_size = GST_VIDEO_INFO_SIZE (info);
+
+ gst_memory_map (base_mem, &src_map, GST_MAP_READ);
+ gst_memory_map (copy, &dst_map, GST_MAP_WRITE);
+
+ memcpy (dst_map.data, src_map.data, mem_size);
+ gst_memory_unmap (copy, &dst_map);
+ gst_memory_unmap (base_mem, &src_map);
+
+ return copy;
+}
+
/* GstMsdkVideoAllocator */
G_DEFINE_TYPE (GstMsdkVideoAllocator, gst_msdk_video_allocator,
GST_TYPE_ALLOCATOR);
base_allocator->mem_type = GST_MSDK_VIDEO_MEMORY_NAME;
base_allocator->mem_map_full = gst_msdk_video_memory_map_full;
base_allocator->mem_unmap = gst_msdk_video_memory_unmap;
+ base_allocator->mem_copy = gst_msdk_video_memory_copy;
GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC);
}