Skip to content

Instantly share code, notes, and snippets.

@mdmower
Created November 11, 2022 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdmower/de7245603f12c3ef413c0beba1f02628 to your computer and use it in GitHub Desktop.
Save mdmower/de7245603f12c3ef413c0beba1f02628 to your computer and use it in GitHub Desktop.
gstreamer mr2928 / gst-plugins-base1.0 part
From 3dd1f8ece2ef57d1678f7c074a7dad170744d081 Mon Sep 17 00:00:00 2001
From: Philipp Zabel <p.zabel@pengutronix.de>
Date: Wed, 28 Mar 2018 17:54:15 +0200
Subject: [PATCH] buffer: drop parent meta in deep copy/foreach_metadata
The purpose of a deep buffer copy is to be able to release the source
buffer and all its dependencies. Attaching the parent buffer meta to
the newly created deep copy needlessly keeps holding a reference to the
parent buffer.
The issue this solves is the fact you need to allocate more
buffers, as you have free buffers being held for no reason. In the good
cases it will use more memory, in the bad case it will stall your
pipeline (since codecs often need a minimum number of buffers to
actually work).
Fixes #283
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2928>
---
gst-libs/gst/audio/gstaudiodecoder.c | 3 ++-
gst-libs/gst/audio/gstaudioencoder.c | 3 ++-
gst-libs/gst/video/gstvideodecoder.c | 3 ++-
gst-libs/gst/video/gstvideoencoder.c | 3 ++-
4 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/gst-libs/gst/audio/gstaudiodecoder.c b/gst-libs/gst/audio/gstaudiodecoder.c
index ec15d6c5..a404256f 100644
--- a/gst-libs/gst/audio/gstaudiodecoder.c
+++ b/gst-libs/gst/audio/gstaudiodecoder.c
@@ -1245,7 +1245,8 @@ foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
const GstMetaInfo *info = (*meta)->info;
gboolean do_copy = FALSE;
- if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)) {
+ if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)
+ || gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory_reference)) {
/* never call the transform_meta with memory specific metadata */
GST_DEBUG_OBJECT (decoder, "not copying memory specific metadata %s",
g_type_name (info->api));
diff --git a/gst-libs/gst/audio/gstaudioencoder.c b/gst-libs/gst/audio/gstaudioencoder.c
index 60cc6af7..4e39c528 100644
--- a/gst-libs/gst/audio/gstaudioencoder.c
+++ b/gst-libs/gst/audio/gstaudioencoder.c
@@ -706,7 +706,8 @@ foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
const GstMetaInfo *info = (*meta)->info;
gboolean do_copy = FALSE;
- if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)) {
+ if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)
+ || gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory_reference)) {
/* never call the transform_meta with memory specific metadata */
GST_DEBUG_OBJECT (encoder, "not copying memory specific metadata %s",
g_type_name (info->api));
diff --git a/gst-libs/gst/video/gstvideodecoder.c b/gst-libs/gst/video/gstvideodecoder.c
index f146fe3a..01ea090b 100644
--- a/gst-libs/gst/video/gstvideodecoder.c
+++ b/gst-libs/gst/video/gstvideodecoder.c
@@ -3358,7 +3358,8 @@ foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
const GstMetaInfo *info = (*meta)->info;
gboolean do_copy = FALSE;
- if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)) {
+ if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)
+ || gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory_reference)) {
/* never call the transform_meta with memory specific metadata */
GST_DEBUG_OBJECT (decoder, "not copying memory specific metadata %s",
g_type_name (info->api));
diff --git a/gst-libs/gst/video/gstvideoencoder.c b/gst-libs/gst/video/gstvideoencoder.c
index ae859a13..daaf51b8 100644
--- a/gst-libs/gst/video/gstvideoencoder.c
+++ b/gst-libs/gst/video/gstvideoencoder.c
@@ -2198,7 +2198,8 @@ foreach_metadata (GstBuffer * inbuf, GstMeta ** meta, gpointer user_data)
const GstMetaInfo *info = (*meta)->info;
gboolean do_copy = FALSE;
- if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)) {
+ if (gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory)
+ || gst_meta_api_type_has_tag (info->api, _gst_meta_tag_memory_reference)) {
/* never call the transform_meta with memory specific metadata */
GST_DEBUG_OBJECT (encoder, "not copying memory specific metadata %s",
g_type_name (info->api));
--
2.34.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment