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 628996 - pulsesink broken after shared context patch (bug #624338)
pulsesink broken after shared context patch (bug #624338)
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
git master
Other Linux
: Normal blocker
: 0.10.26
Assigned To: Stefan Sauer (gstreamer, gtkdoc dev)
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2010-09-07 21:19 UTC by Stefan Sauer (gstreamer, gtkdoc dev)
Modified: 2010-09-13 14:00 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
add asserts to trap the crash (2.47 KB, patch)
2010-09-08 11:25 UTC, Stefan Sauer (gstreamer, gtkdoc dev)
none Details | Review
valgrind log (259.28 KB, text/text)
2010-09-09 20:45 UTC, Stefan Sauer (gstreamer, gtkdoc dev)
  Details

Description Stefan Sauer (gstreamer, gtkdoc dev) 2010-09-07 21:19:01 UTC
Program received signal SIGSEGV, Segmentation fault.

Thread 2874461040 (LWP 27693)

  • #0 ??
    from /usr/lib/libpulse.so.0
  • #1 pa_pstream_send_packet
    from /usr/lib/libpulsecommon-0.9.21.so
  • #2 pa_pstream_send_tagstruct_with_creds
    from /usr/lib/libpulsecommon-0.9.21.so
  • #3 pa_context_subscribe
    from /usr/lib/libpulse.so.0
  • #4 gst_pulseringbuffer_acquire
    at pulsesink.c line 757
  • #5 gst_ring_buffer_acquire
    at gstringbuffer.c line 809
  • #6 gst_base_audio_sink_setcaps
    at gstbaseaudiosink.c line 715
  • #7 gst_base_sink_pad_setcaps
    at gstbasesink.c line 586

Comment 1 Philippe Normand 2010-09-08 06:34:17 UTC
Would you have a test-case please? Also what version of PA are you using?
Comment 2 Stefan Sauer (gstreamer, gtkdoc dev) 2010-09-08 10:48:24 UTC
pulseaudio: 0.9.21 (ubuntu lucid)
same happens at home suse 11.3
so it is probably not the pa version

I get this when playing songs in buzztard. I'll dig it, but just filed the bug to make sure it gets fixed before we release next one.

That said, I think the context array should be in initializen when the pulse plugin is initialized and both pulsesrc and sink should use it.
Comment 3 Stefan Sauer (gstreamer, gtkdoc dev) 2010-09-08 11:25:10 UTC
Created attachment 169757 [details] [review]
add asserts to trap the crash

It crashes here, pctx->context is NULL. Dunno yet why:

  /* we need a context and a no stream */
  pctx = gst_pulsering_get_context (pbuf);
  g_assert (!pbuf->stream);
  g_assert (pctx);
  g_assert (pctx->context);

  /* enable event notifications */
  GST_LOG_OBJECT (psink, "subscribing to context events");
  if (!(o = pa_context_subscribe (pctx->context,
              PA_SUBSCRIPTION_MASK_SINK_INPUT, NULL, NULL)))
    goto subscribe_failed;
Comment 4 Stefan Sauer (gstreamer, gtkdoc dev) 2010-09-08 12:58:12 UTC
pulsesink.c:466:gst_pulseringbuffer_open_device:<player> new context with name Buzztard
pulsesink.c:374:gst_pulsering_context_state_cb:<player> got new context state 1
pulsesink.c:500:gst_pulseringbuffer_open_device:<player> context state is now 1
pulsesink.c:374:gst_pulsering_context_state_cb:<player> got new context state 2
pulsesink.c:374:gst_pulsering_context_state_cb:<player> got new context state 3
pulsesink.c:374:gst_pulsering_context_state_cb:<player> got new context state 4
pulsesink.c:385:gst_pulsering_context_state_cb:<player> signaling
pulsesink.c:500:gst_pulseringbuffer_open_device:<player> context state is now 4
pulsesink.c:491:gst_pulseringbuffer_open_device:<player> reusing shared pulseaudio context with name Buzztard
pulsesink.c:500:gst_pulseringbuffer_open_device:<player> context state is now 4
pulsesink.c:294:gst_pulsering_destroy_context:<player> destroying context for pbuf=0x8e06140 'Buzztard'
pulsesink.c:294:gst_pulsering_destroy_context: destroying context for pbuf=0x8e06140 'Buzztard'
pulsesink.c:761:gst_pulseringbuffer_acquire:<player> subscribing to context events

it shows that buzztard triggers the sharing part. what I wonder is why gst_pulsering_destroy_context() is called twice, the 2nd time pbuf seems to be in the process of destruction (has no gst-object name anymore).
Comment 5 Stefan Sauer (gstreamer, gtkdoc dev) 2010-09-09 20:03:14 UTC
open suse also has 0.9.21

This also fails:
gst-launch-0.10 audiotestsrc num-buffers=15 ! pulsesink audiotestsrc num-buffers=25 ! pulsesink

It eitehr hangs or segfaults. It works with released -good. I am now bisecting.
Comment 6 Stefan Sauer (gstreamer, gtkdoc dev) 2010-09-09 20:18:09 UTC
git bisect brought me to:

69a397c32f4baf07a7b2937c610f9e8f383e9ae9 is the first bad commit
commit 69a397c32f4baf07a7b2937c610f9e8f383e9ae9
Author: Philippe Normand <pnormand@igalia.com>
Date:   Mon Aug 16 09:12:04 2010 +0200

    pulsesink: share the PA context between all clients with the same name
    
    Avoid to create a new PA context for each new client by using a hash
    table containing the list of ring-buffers and the shared PA context
    for each client. Doing this will improve application memory usage in
    the cases where multiple pipelines involving multiple pulsesink
    elements are used.
    
    Fixes bug #624338.
Comment 7 Philippe Normand 2010-09-09 20:38:55 UTC
That pipeline works fine here, although I use an old PA (0.9.19-0ubuntu4.1) on this laptop running karmic.
Comment 8 Philippe Normand 2010-09-09 20:42:56 UTC
(In reply to comment #7)
> That pipeline works fine here, although I use an old PA (0.9.19-0ubuntu4.1) on
> this laptop running karmic.

Nevermind that, got it to hang ;)
Well I guess this is my fault, right? :) Will have a look, sorry for breaking the thing
Comment 9 Stefan Sauer (gstreamer, gtkdoc dev) 2010-09-09 20:45:02 UTC
Created attachment 169895 [details]
valgrind log
Comment 10 Stefan Sauer (gstreamer, gtkdoc dev) 2010-09-09 20:48:30 UTC
in gst_pulseringbuffer_open_device()
it does
    api = pa_threaded_mainloop_get_api (psink->mainloop);
    if (!(pctx->context = pa_context_new (api, pbuf->context_name)))
      goto create_failed;

it seems that the context is cleared when the mainloop that was used to create it is freed in gst_pulsesink_change_state() (see valgrind log).

I wonder if the main_loop that was used to create the context can be keep and only be cleared when the last instance it released.
Comment 11 Stefan Sauer (gstreamer, gtkdoc dev) 2010-09-10 14:50:51 UTC
I have now tried to use extra
pa_context_ref (pctx->context);
pa_context_unref (pctx->context);
for each user of the context, to no avail.

Honestly I doubt the contexy is actualy shareable.

The mainloop itself is not easily shareable either, as it is started/stopped with the state-changes. We would need a patch that shares the mainloop, starts it upon creation and stops it on last unref.
Comment 12 Sebastian Dröge (slomo) 2010-09-10 15:08:06 UTC
I think we need some changes on the pulseaudio side for this then and should revert the change until there's a solution in PA.
Comment 13 Sebastian Dröge (slomo) 2010-09-10 15:36:23 UTC
Actually forget the last comment. Sharing the mainloop should be really possible, start it from the first element that goes to READY and stop it from the last element that goes to NULL.
Comment 14 Stefan Sauer (gstreamer, gtkdoc dev) 2010-09-10 17:20:43 UTC
(In reply to comment #13)
> Actually forget the last comment. Sharing the mainloop should be really
> possible, start it from the first element that goes to READY and stop it from
> the last element that goes to NULL.

Thats what I said in IRC. Phil, are you try to implement that change? Otherwise I'll try tomorrow.
Comment 15 Philippe Normand 2010-09-10 17:26:51 UTC
(In reply to comment #14)
> (In reply to comment #13)
> > Actually forget the last comment. Sharing the mainloop should be really
> > possible, start it from the first element that goes to READY and stop it from
> > the last element that goes to NULL.
> 
> Thats what I said in IRC. Phil, are you try to implement that change? Otherwise
> I'll try tomorrow.

I had a look yesterday night but today was busy with other stuff, please don't wait on me, tomorrow i'll be offline most of the day too.
Comment 16 Stefan Sauer (gstreamer, gtkdoc dev) 2010-09-10 17:51:06 UTC
Phil, I was not waiting on you for the whole week already. This totally blocks the work on my own app. I already spend all my evening this week on this. But so it is then. I'll try fixing it tomorrow, tonight I am too tired.
Comment 17 Stefan Sauer (gstreamer, gtkdoc dev) 2010-09-13 14:00:59 UTC
commit f62dc6976b611384c98efb37d407b5299daf8c17
Author: Stefan Kost <ensonic@users.sf.net>
Date:   Mon Sep 13 16:24:26 2010 +0300

    pulsesink: rework context sharing
    
    We also need to share the main-loop threads as this owns the context. Thus have
    a class wide main-loop thread. From this we create a context per client-name.
    Instead of always looking up the context, we keep this with the instance. The
    reverse mapping is only needed in pulse singal handlers. This saves a lot of
    locking. Also one signal handler becomes simpler as ther eis only one mainloop
    to notify.
    
    Now valgind happy - no leaks, no bad reads/writes.
    
    This reverts major parts of commit 69a397c32f4baf07a7b2937c610f9e8f383e9ae9.
    
    Fixes #628996