After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 736118 - videofilter: The buffer is not writable in transform_frame_ip
videofilter: The buffer is not writable in transform_frame_ip
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-base
1.4.1
Other Linux
: Normal normal
: 1.4.2
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-09-05 10:57 UTC by Matt Clarkson
Modified: 2014-09-13 13:50 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Example test case. (2.36 KB, application/gzip)
2014-09-05 10:57 UTC, Matt Clarkson
  Details
videofilter: Unref buffers before calling the transform_frame functions (1.78 KB, patch)
2014-09-05 11:07 UTC, Sebastian Dröge (slomo)
committed Details | Review

Description Matt Clarkson 2014-09-05 10:57:13 UTC
Created attachment 285476 [details]
Example test case.

When creating a simple video filter the buffer is not writable in transform_frame_ip:

static GstFlowReturn
gst_test_transform_frame_ip (GstVideoFilter * filter, GstVideoFrame * frame)
{
  GstTest *test = GST_TEST (filter);

  GST_DEBUG_OBJECT (test, "transform_frame_ip");
  GST_INFO_OBJECT (test, gst_buffer_is_writable(frame->buffer) ?
    "writable" :
    "not writable");

  return GST_FLOW_OK;
}
Comment 1 Sebastian Dröge (slomo) 2014-09-05 11:03:56 UTC
Happens because the GstVideoFrame has yet another reference to the buffer.
Comment 2 Sebastian Dröge (slomo) 2014-09-05 11:04:45 UTC
We could probably unref the buffer once before calling transform/transform_ip
Comment 3 Sebastian Dröge (slomo) 2014-09-05 11:07:07 UTC
Created attachment 285480 [details] [review]
videofilter: Unref buffers before calling the transform_frame functions

GstVideoFrame has another reference, so the buffer looks unwriteable,
meaning that we can't attach any metas or anything to it
Comment 4 Sebastian Dröge (slomo) 2014-09-05 11:07:43 UTC
Untested patch, ugly but maybe the best we can do here.
Comment 5 Matt Clarkson 2014-09-05 12:09:49 UTC
Works great for me! Thanks. Do you think this will turn up in 1.4.2 or 1.6.0?
Comment 6 Nicolas Dufresne (ndufresne) 2014-09-05 12:45:53 UTC
Review of attachment 285480 [details] [review]:

That is really ugly. Can't we find a way to transfer the buffer ownership to the VideoFrame instead, and keep that around ?
Comment 7 Sebastian Dröge (slomo) 2014-09-06 14:16:58 UTC
Yeah, maybe a custom map flag? GST_VIDEO_FRAME_MAP_NOREF?
Comment 8 Nicolas Dufresne (ndufresne) 2014-09-07 16:11:52 UTC
(In reply to comment #7)
> Yeah, maybe a custom map flag? GST_VIDEO_FRAME_MAP_NOREF?

Hmm, seems tricky, mapping memory will ref it, though it's more at buffer level that it fails. It's not like if we where to create a Frame and then map/unmap it, that would have been simple to solve the issue ... I need to think a bit more about that.
Comment 9 Sebastian Dröge (slomo) 2014-09-07 17:33:54 UTC
Mapping buffers or memory does not ref it, only the GstVideoFrame API refs the buffer when mapping
Comment 10 Nicolas Dufresne (ndufresne) 2014-09-08 02:18:29 UTC
Review of attachment 285480 [details] [review]:

Ok, the context is a bit missing in the patch itself, but as we map the frame (hence ref the buffer), unref the buffer, transform frame, ref buffer and finally unmap the frame (hence unref the buffer), this patch clearly works. It a weird dance, but it clearly show that we know what we are doing. I like the flag in the end, but we need this method first in the likely case we want to backport to 1.4. Feel free to introduce the flag in 1.5 though, then it would be worth adding this change at the other places (e.g. in OpenCV elements base class, which isn't base on VideoFilter).
Comment 11 Sebastian Dröge (slomo) 2014-09-12 11:30:24 UTC
Let's do that then. I added a longer explanation in the code.

commit f711288c7c86c33aed18f52ed6d7787d19b7741d
Author: Sebastian Dröge <sebastian@centricular.com>
Date:   Fri Sep 12 14:27:44 2014 +0300

    videofilter: Unref buffers before calling the transform_frame functions
    
    GstVideoFrame has another reference, so the buffer looks unwriteable,
    meaning that we can't attach any metas or anything to it
    
    https://bugzilla.gnome.org/show_bug.cgi?id=736118
Comment 12 Sebastian Dröge (slomo) 2014-09-12 11:42:18 UTC
I'll backport the first patch to 1.4 later, for 1.5 we have a better solution now:

commit 3a7cdcdfc9c5b0d20394fe51b3b8cda23931ca6d
Author: Sebastian Dröge <sebastian@centricular.com>
Date:   Fri Sep 12 14:41:01 2014 +0300

    videofilter: Use new GST_VIDEO_FRAME_MAP_FLAG_NO_REF
    
    https://bugzilla.gnome.org/show_bug.cgi?id=736118

commit 40a293d44d1aeccf5eb8e86f23a0b13666111c5c
Author: Sebastian Dröge <sebastian@centricular.com>
Date:   Fri Sep 12 14:39:16 2014 +0300

    video-frame: Add GST_VIDEO_FRAME_MAP_FLAG_NO_REF
    
    This makes sure that the buffer is not reffed another time when
    storing it in the GstVideoFrame, keeping it writable if it was
    writable.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=736118