From 221ae089a6268818e5e39032680e65ef392caf95 Mon Sep 17 00:00:00 2001 From: Fabian Orccon Date: Tue, 5 Nov 2024 12:05:25 +0100 Subject: [PATCH] webvideoframe: Cache map data Ref #RDI-2056 --- .../gst-libs/gst/web/gstwebvideoframe.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/gst.wasm/subprojects/gst-plugins-web/gst-libs/gst/web/gstwebvideoframe.cpp b/gst.wasm/subprojects/gst-plugins-web/gst-libs/gst/web/gstwebvideoframe.cpp index d5a698f..5750ef2 100644 --- a/gst.wasm/subprojects/gst-plugins-web/gst-libs/gst/web/gstwebvideoframe.cpp +++ b/gst.wasm/subprojects/gst-plugins-web/gst-libs/gst/web/gstwebvideoframe.cpp @@ -68,6 +68,7 @@ struct _GstWebVideoFramePrivate GstWebRunner *runner; /* The Emscripten's JS VideoFrame */ val video_frame; + guint8 *data; }; typedef struct _GstWebVideoFrameAllocator @@ -190,14 +191,19 @@ gst_web_video_frame_allocator_map_full ( GstWebVideoFrame *self, GstMapInfo *info, gsize size) { GstWebVideoFrameAllocatorMapCpuData data = { - .self = self, .data = NULL, .size = size, .info = NULL, .result = FALSE + .self = self, .info = NULL, .result = FALSE }; if ((info->flags & GST_MAP_WRITE) == GST_MAP_WRITE) { GST_DEBUG ("Write flags not supported"); + return NULL; } - data.data = (guint8 *) g_malloc (data.size); + if (self->priv->data) + goto beach; + + data.data = self->priv->data = (guint8 *) g_malloc (size); + data.size = size; gst_web_runner_send_message ( self->priv->runner, gst_web_video_frame_allocator_map_cpu_access, &data); @@ -206,14 +212,15 @@ gst_web_video_frame_allocator_map_full ( return NULL; } - return data.data; +beach: + return self->priv->data; } static void gst_web_video_frame_allocator_unmap_full ( GstWebVideoFrame *mem, GstMapInfo *info) { - g_free (info->data); + /* Nothing to do. */ } static GstMemory * @@ -250,6 +257,7 @@ gst_web_video_frame_allocator_alloc ( mem->priv = g_new0 (GstWebVideoFramePrivate, 1); mem->priv->video_frame = vf_params->video_frame; mem->priv->runner = vf_params->runner; + mem->priv->data = NULL; /* Chain the memory init */ /* We need to get the allocationSize from the video_frame to know the buffer @@ -273,6 +281,7 @@ gst_web_video_frame_allocator_free (GstAllocator *allocator, GstMemory *memory) gst_object_unref (self->priv->runner); self->priv->video_frame = val::undefined (); + g_free (self->priv->data); g_free (self->priv); }