Bug 35747

Summary: [GStreamer] on Mac OS use a runloop observer to process the glib context iterations
Product: WebKit Reporter: Philippe Normand <pnormand>
Component: WebKitGTKAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, eric.carlson, eric, gustavo, webkit.review.bot, xan.lopez
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: PC   
OS: OS X 10.5   
Bug Depends on:    
Bug Blocks: 39202    
Attachments:
Description Flags
proposed patch
gustavo: review-
proposed patch
none
GLib runloop observer in WebView eric.carlson: review+

Philippe Normand
Reported 2010-03-04 07:39:33 PST
Applications using the GTK+ port will most likely use a glib main loop but in the eventuality of reusing the media player backend from a port not depending on glib main loop we'd need to have a Timer periodically polling messages from the GStreamer bus.
Attachments
proposed patch (4.90 KB, patch)
2010-03-04 07:43 PST, Philippe Normand
gustavo: review-
proposed patch (3.83 KB, patch)
2010-05-17 02:25 PDT, Philippe Normand
no flags
GLib runloop observer in WebView (5.40 KB, patch)
2010-06-23 02:15 PDT, Philippe Normand
eric.carlson: review+
Philippe Normand
Comment 1 2010-03-04 07:43:46 PST
Created attachment 50023 [details] proposed patch
Gustavo Noronha (kov)
Comment 2 2010-03-08 13:52:13 PST
Comment on attachment 50023 [details] proposed patch Hrm. I don't know. I don't like the runtime checking, also the polling time seems to be pretty arbitrary. I'm worried we may end up in that situation in the gtk+ port, in some cases (say, the application hasn't run gtk_main(), but is running the mainloop itself). Why not have ports that would like to use the GStreamer backend run the glib main loop?
Philippe Normand
Comment 3 2010-03-09 02:14:56 PST
(In reply to comment #2) > (From update of attachment 50023 [details]) > Hrm. I don't know. I don't like the runtime checking What would be a better checking? > also the polling time > seems to be pretty arbitrary. Agreed, it'd probably need some tweaking > I'm worried we may end up in that situation in > the gtk+ port, in some cases (say, the application hasn't run gtk_main(), but > is running the mainloop itself). Why not have ports that would like to use the > GStreamer backend run the glib main loop? I'm not sure this would be an option for, say, the mac or win port :) It'd be nice to propose the GStreamer backend as an optional replacement for these ports and avoiding use of a glib loop inside apps running on these platforms would be good, I think...
Philippe Normand
Comment 4 2010-03-10 07:38:44 PST
(In reply to comment #3) > > I'm worried we may end up in that situation in > > the gtk+ port, in some cases (say, the application hasn't run gtk_main(), but > > is running the mainloop itself). Why not have ports that would like to use the > > GStreamer backend run the glib main loop? > > I'm not sure this would be an option for, say, the mac or win port :) It'd be > nice to propose the GStreamer backend as an optional replacement for these > ports and avoiding use of a glib loop inside apps running on these platforms > would be good, I think... Another approach would be to do the polling only on win and mac platforms (#if PLATFORM(WIN)...). So the GTK+ port wouldn't be affected, as webkitgtk apps use a glib mainloop in most (all?) cases. BTW I tested the polling on my laptop and couldn't really notice a difference in terms of CPU usage, apart from the obvious overhead of wakeups :)
Gustavo Noronha (kov)
Comment 5 2010-03-10 07:52:26 PST
Eric, could you share some thoughts on this? =D
Eric Carlson
Comment 6 2010-03-10 08:34:06 PST
(In reply to comment #5) > Eric, could you share some thoughts on this? =D Well, I know *nothing* about the gtk main loop but I wonder if it is a good idea to do this by default, even on Mac in Windows. I assume anyone using WebKit with the GStreamer backend in their app will be building from source, so why not make it a compile time option?
Eric Carlson
Comment 7 2010-03-10 08:34:55 PST
(In reply to comment #4) > BTW I tested the polling on my laptop and couldn't really notice a difference > in terms of CPU usage, apart from the obvious overhead of wakeups :) I'll bet you weren't monitoring battery consumption ;-)
Gustavo Noronha (kov)
Comment 8 2010-03-11 12:18:00 PST
(In reply to comment #6) > (In reply to comment #5) > > Eric, could you share some thoughts on this? =D > > Well, I know *nothing* about the gtk main loop but I wonder if it is a good > idea to do this by default, even on Mac in Windows. My question is more along the lines of - would it be a problem to add running the glib main loop along with the win/mac mainloop if you decide to build those ports with the GStreamer backend included? That would mean adding this call: g_main_context_iteration(NULL, FALSE); To these functions: [WebCore/platform/mac/EventLoopMac.mm] void EventLoop::cycle() { // FIXME: Should this use NSRunLoopCommonModes? Switching to NSRunLoopCommonModes causes Safari to hang in a tight loop. [NSApp setWindowsNeedUpdate:YES]; NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES]; [NSApp sendEvent:event]; } [WebCore/platform/win/EventLoopWin.cpp] void EventLoop::cycle() { MSG msg; if (!GetMessage(&msg, 0, 0, 0)) { m_ended = true; return; } TranslateMessage(&msg); DispatchMessage(&msg); } > I assume anyone using WebKit with the GStreamer backend in their app will be > building from source, so why not make it a compile time option? Yes, build time option defeats runtime choice, IMO.
Eric Carlson
Comment 9 2010-03-11 13:01:19 PST
(In reply to comment #8) > (In reply to comment #6) > > (In reply to comment #5) > > > Eric, could you share some thoughts on this? =D > > > > Well, I know *nothing* about the gtk main loop but I wonder if it is a good > > idea to do this by default, even on Mac in Windows. > > My question is more along the lines of - would it be a problem to add running > the glib main loop along with the win/mac mainloop if you decide to build those > ports with the GStreamer backend included? That would mean adding this call: > I don't know :-( > > I assume anyone using WebKit with the GStreamer backend in their app will be > > building from source, so why not make it a compile time option? > > Yes, build time option defeats runtime choice, IMO. My point was that *if* people that want to use the GStreamer backend are likely to build WebKit, they can easily enable polling if their app doesn't already run the gtk main loop.
Philippe Normand
Comment 10 2010-04-13 16:55:05 PDT
Some news about this. I am now experimenting on a new approach, setting a synchronous handler on the gst bus with gst_bus_set_sync_handler() and processing the message in the mainloop using a one-shot timer. Songbird uses a similar approach. It works fine if I use a g_timeout_add but not with the higher level WebCore Timer API... Trying to figure out why the timer callback is never fired :/
Philippe Normand
Comment 11 2010-05-17 02:25:13 PDT
Created attachment 56226 [details] proposed patch I had some success with this patch. Would it make sense to extract it from the player code? The EventLoop code mentionned by Gustavo doesn't seem to be used by WebCore.
Gustavo Noronha (kov)
Comment 12 2010-06-11 07:09:10 PDT
Comment on attachment 56226 [details] proposed patch I don't know a lot about the mac part of this, but it sounds sane. I do think this should be extracted from the player and added to the main loop part of the Mac port, though, since running the glib mainloop affects more and is useful to more than just the player.
Philippe Normand
Comment 13 2010-06-11 07:15:06 PDT
Comment on attachment 56226 [details] proposed patch Thanks Gustavo, I'll see if I can do that :)
Philippe Normand
Comment 14 2010-06-23 01:14:57 PDT
This bug is specific to Mac OS, a similar approach would be needed on Windows though.
Philippe Normand
Comment 15 2010-06-23 02:15:51 PDT
Created attachment 59495 [details] GLib runloop observer in WebView
Gustavo Noronha (kov)
Comment 16 2010-07-01 11:54:26 PDT
Comment on attachment 59495 [details] GLib runloop observer in WebView glib-wise looks sane, might want to poke someone from the mac camp to look at the rest =)
Eric Carlson
Comment 17 2010-07-02 10:15:40 PDT
Comment on attachment 59495 [details] GLib runloop observer in WebView The Mac specific code look OK to me, so marking r+ since kov signed off on the glib parts.
Philippe Normand
Comment 18 2010-07-05 00:20:16 PDT
Landed in http://trac.webkit.org/changeset/62476 Thanks for the review :)
WebKit Review Bot
Comment 19 2010-07-05 02:00:37 PDT
http://trac.webkit.org/changeset/62476 might have broken Leopard Intel Release (Tests)
Philippe Normand
Comment 20 2010-07-05 02:05:01 PDT
(In reply to comment #19) > http://trac.webkit.org/changeset/62476 might have broken Leopard Intel Release (Tests) I don't see how this patch could break any test because the GSTREAMER feature is not enabled yet in the build.
Note You need to log in before you can comment on or make changes to this bug.