Bug 172427 - [GStreamerGL] Release GstVideoFrame when there is a flush event from the pipeline
Summary: [GStreamerGL] Release GstVideoFrame when there is a flush event from the pipe...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Gwang Yoon Hwang
URL:
Keywords:
Depends on: 173410
Blocks:
  Show dependency treegraph
 
Reported: 2017-05-21 07:20 PDT by Gwang Yoon Hwang
Modified: 2017-08-10 05:28 PDT (History)
5 users (show)

See Also:


Attachments
Patch (24.38 KB, patch)
2017-05-21 07:21 PDT, Gwang Yoon Hwang
no flags Details | Formatted Diff | Diff
Patch (25.87 KB, patch)
2017-06-02 08:09 PDT, Gwang Yoon Hwang
no flags Details | Formatted Diff | Diff
Patch (28.43 KB, patch)
2017-06-07 04:31 PDT, Gwang Yoon Hwang
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gwang Yoon Hwang 2017-05-21 07:20:51 PDT
[GStreamerGL] Release GstVideoFrame when there is a flush event from the pipeline
Comment 1 Gwang Yoon Hwang 2017-05-21 07:21:51 PDT
Created attachment 310807 [details]
Patch
Comment 2 Gwang Yoon Hwang 2017-06-02 08:09:27 PDT
Created attachment 311826 [details]
Patch
Comment 3 Gwang Yoon Hwang 2017-06-02 08:10:43 PDT
(In reply to Gwang Yoon Hwang from comment #2)
> Created attachment 311826 [details]
> Patch

Fixed a memory leak while handling flush event from the gst pipeline.
Comment 4 Zan Dobersek 2017-06-05 06:27:40 PDT
Comment on attachment 311826 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=311826&action=review

> Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp:151
> +void TextureMapperPlatformLayerProxy::appendToUnusedBuffers(std::unique_ptr<TextureMapperPlatformLayerBuffer> buffer)
> +{
> +    ASSERT(m_compositorThreadID == WTF::currentThread());
> +    RunLoop::main().dispatch([this, protectedThis = makeRef(*this), buffer = WTFMove(buffer)] () mutable {
> +        m_usedBuffers.append(WTFMove(buffer));
> +        scheduleReleaseUnusedBuffers();
> +    });
> +}

Why does this have to be handled on the main thread?
Comment 5 Gwang Yoon Hwang 2017-06-05 06:57:01 PDT
Comment on attachment 311826 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=311826&action=review

>> Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp:151
>> +}
> 
> Why does this have to be handled on the main thread?

AFAIU, RunLoop::TimerBase::start is not thread safe, no?
Comment 6 Zan Dobersek 2017-06-05 08:49:20 PDT
Comment on attachment 311826 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=311826&action=review

>>> Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp:151
>>> +}
>> 
>> Why does this have to be handled on the main thread?
> 
> AFAIU, RunLoop::TimerBase::start is not thread safe, no?

Internally it is due to GSource being used underneath. But even externally, it's protected through m_lock. 

There's other problems in this class related to this, for instance the timer shouldn't be scheduled if the Proxy object isn't active anymore, otherwise the object can be destructed on one thread while releaseUnusedBuffersTimerFired() runs on a different thread. But this shouldn't need to dispatch to any other thread.
Comment 7 Michael Catanzaro 2017-06-05 09:10:44 PDT
(In reply to Zan Dobersek from comment #6)
> There's other problems in this class related to this, for instance the timer
> shouldn't be scheduled if the Proxy object isn't active anymore, otherwise
> the object can be destructed on one thread while
> releaseUnusedBuffersTimerFired() runs on a different thread. But this
> shouldn't need to dispatch to any other thread.

Will you handle making another bug report to make sure this doesn't get forgotten?
Comment 8 Gwang Yoon Hwang 2017-06-07 04:31:23 PDT
Created attachment 312177 [details]
Patch
Comment 9 Gwang Yoon Hwang 2017-06-07 04:41:10 PDT
(In reply to Zan Dobersek from comment #6)
> Comment on attachment 311826 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=311826&action=review
> 
> >>> Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp:151
> >>> +}
> >> 
> >> Why does this have to be handled on the main thread?
> > 
> > AFAIU, RunLoop::TimerBase::start is not thread safe, no?
> 
> Internally it is due to GSource being used underneath. But even externally,
> it's protected through m_lock. 
> 
It is correct. Since PlatformLayerProxy uses locks to protect runLoop, it is thread-safe.
It is a side-topic, but we doesn't use locks in RunLoop::TimerBase::start while updating m_fireInterval and m_isRepeating. I think it is not thread safe at this point.
https://github.com/WebKit/webkit/blob/master/Source/WTF/wtf/glib/RunLoopGLib.cpp#L204

Anyway, I modified to fire the timer in compositing thread, also I changed release timer to be attached to the compositing run loop. Now all operations about m_usedBuffers works on the compositing thread.

> There's other problems in this class related to this, for instance the timer
> shouldn't be scheduled if the Proxy object isn't active anymore, otherwise
> the object can be destructed on one thread while
> releaseUnusedBuffersTimerFired() runs on a different thread. But this
> shouldn't need to dispatch to any other thread.

I thought a bit more deeper about this problem.
But when the proxy became invalidated, we removes and stops all timers and then destructs objects on the compositing thread, so I think it is quite okay at this point.

But still needs improvements, regarding ::getAvailableBuffers, I made a patch to use the TexmapGL's bitmap texture pool, so it can be handled at different bug.
Comment 10 WebKit Commit Bot 2017-06-13 01:29:10 PDT
Comment on attachment 312177 [details]
Patch

Clearing flags on attachment: 312177

Committed r218170: <http://trac.webkit.org/changeset/218170>
Comment 11 WebKit Commit Bot 2017-06-13 01:29:11 PDT
All reviewed patches have been landed.  Closing bug.