diff options
author | Havard Graff <havard.graff@gmail.com> | 2019-05-22 11:16:56 +0200 |
---|---|---|
committer | GStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org> | 2021-08-23 14:31:37 +0000 |
commit | 068c2a71ba58a0a68e6e7258025be81537822249 (patch) | |
tree | 86c50df20ca3249aebb886df3828f49009d03da0 | |
parent | 660517435837a09098c1ade9662c4aaa31176e73 (diff) |
vpxdec: Fix direct rendering, avoid holding write access
When a buffer is pushed downstream, we should try not to hold the
buffer mapped with write access. Doing so would often lead to
an unneccesary memcpy later.
For instance, gst_buffer_make_writable() in
gst_video_decoder_finish_frame() will cause a memcpy because of
_memory_get_exclusive_reference().
We know that we can perform a two-step remap when using system
memory, as this will not cause the location of the memory to
change.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/812>
-rw-r--r-- | ext/vpx/gstvpxdec.c | 13 | ||||
-rw-r--r-- | ext/vpx/gstvpxdec.h | 1 |
2 files changed, 14 insertions, 0 deletions
diff --git a/ext/vpx/gstvpxdec.c b/ext/vpx/gstvpxdec.c index adf842813..03adba8fc 100644 --- a/ext/vpx/gstvpxdec.c +++ b/ext/vpx/gstvpxdec.c @@ -286,6 +286,7 @@ gst_vpx_dec_start (GstVideoDecoder * decoder) GST_DEBUG_OBJECT (gst_vpx_dec, "start"); gst_vpx_dec->decoder_inited = FALSE; + gst_vpx_dec->safe_remap = FALSE; return TRUE; } @@ -401,6 +402,15 @@ gst_vpx_dec_prepare_image (GstVPXDec * dec, const vpx_image_t * img) buffer = gst_buffer_ref (frame->buffer); + /* FIXME: an atomic remap would be preferable, for now we simply + * remap the buffer from RW to RO when using a sysmem allocator, + * in order to avoid a useless memcpy in GstVideoDecoder. + */ + if (dec->safe_remap) { + gst_buffer_unmap (buffer, &frame->info); + gst_buffer_map (buffer, &frame->info, GST_MAP_READ); + } + vmeta = gst_buffer_get_video_meta (buffer); vmeta->format = GST_VIDEO_INFO_FORMAT (info); vmeta->width = GST_VIDEO_INFO_WIDTH (info); @@ -450,6 +460,9 @@ gst_vpx_dec_get_buffer_cb (gpointer priv, gsize min_size, allocator = NULL; } + dec->safe_remap = (allocator == NULL + || !g_strcmp0 (allocator->mem_type, GST_ALLOCATOR_SYSMEM)); + pool = gst_buffer_pool_new (); config = gst_buffer_pool_get_config (pool); gst_buffer_pool_config_set_allocator (config, allocator, ¶ms); diff --git a/ext/vpx/gstvpxdec.h b/ext/vpx/gstvpxdec.h index 35ea4289b..00035f5d4 100644 --- a/ext/vpx/gstvpxdec.h +++ b/ext/vpx/gstvpxdec.h @@ -82,6 +82,7 @@ struct _GstVPXDec gboolean have_video_meta; GstBufferPool *pool; gsize buf_size; + gboolean safe_remap; }; struct _GstVPXDecClass |