Opened 16 years ago

Closed 14 years ago

Last modified 14 years ago

#5473 closed patch (fixed)

audio out, PulseAudio

Reported by: Alan Calvert <cal@…> Owned by: JYA
Priority: minor Milestone: unknown
Component: MythTV - Audio Output Version: head
Severity: medium Keywords:
Cc: Ticket locked: yes

Description

Here is an attempt to put PulseAudio? output into MythTV. This _is_ my first encounter with PulseAudio?, so no doubt the code's a bit saggy, baggy in places, and no doubt it has bugs. Improvements are most welcome.

Attachments (15)

audiooutpulseaudio-0.5.patch.gz (6.4 KB) - added by Alan Calvert <cal@…> 16 years ago.
base patch for audiooutputpulseaudio
audiooutpulse-0.6.patch.gz (6.4 KB) - added by Alan Calvert <cal@…> 16 years ago.
patch against trunk 17643
audiooutpulse-0.7.patch.gz (6.5 KB) - added by Alan Calvert <cal@…> 16 years ago.
patch against trunk 17646
audiooutpulse-0.21-fixes-0.7.patch.gz (6.5 KB) - added by Alan Calvert <cal@…> 16 years ago.
against 0.21-fixes svn 17646
audiooutpulse-0.9.patch.gz (6.6 KB) - added by Alan Calvert <cal@…> 16 years ago.
against trunk svn17745
audiooutpulse-0.10.patch.gz (6.4 KB) - added by Alan Calvert <cal@…> 16 years ago.
against trunk 17747
audiooutpulse-0.11.patch.gz (6.2 KB) - added by Alan Calvert <cal@…> 16 years ago.
@ trunk 18161
audiooutpulse-0.21-fixes-0.11.patch.gz (6.2 KB) - added by Alan Calvert <cal@…> 16 years ago.
@ 18166
audiooutpulse-0.12.patch (29.1 KB) - added by Alan Calvert <cal@…> 15 years ago.
@ 18528
audiooutpulse-0.12.1.patch (29.0 KB) - added by Alan Calvert <cal@…> 15 years ago.
++ a couple of minor fixups I missed. @18528
audiooutpulse-0.12.2.patch (30.4 KB) - added by Colin Guthrie <mythtv@…> 15 years ago.
Minor update to increase backwords compatibility, fix linking and fix a potential uninitialised variable use.
30_pulseaudio_output.dpatch (31.5 KB) - added by IntuitiveNipple 15 years ago.
0.21+fixes18722 (Ubuntu Intrepid) patch
pulse-audio-disable-proof-of-concept.patch (15.2 KB) - added by danielk 15 years ago.
Proof of concept patch for disabling pulse audio at startup. This IS NOT usable for production purposes.
5473-v1.patch (31.6 KB) - added by danielk 15 years ago.
Updates pulse audio output support to trunk (basically work with the pulse audio disable code for other output methods).
pulse_debug.log (3.2 KB) - added by Adolfo R. Brandes <arbrandes@…> 14 years ago.
Audio verbose output for r22694

Download all attachments as: .zip

Change History (49)

Changed 16 years ago by Alan Calvert <cal@…>

base patch for audiooutputpulseaudio

comment:1 Changed 16 years ago by Alan Calvert <cal@…>

patch 0.5 was against trunk r17642.

Changed 16 years ago by Alan Calvert <cal@…>

Attachment: audiooutpulse-0.6.patch.gz added

patch against trunk 17643

comment:2 Changed 16 years ago by Alan Calvert <cal@…>

A few refinements:

  • change the patch name to match the class name,
  • reduce the buffer size from the default 96k bytes to 16k,
  • move a public to protected and a couple of protecteds to private,
  • clean up a generous sprinkling of unused vars,
  • and adjust some formatting and assorted stuff.

patch audiooutpulse-0.6.patch was against trunk 17643.

comment:3 Changed 16 years ago by Alan Calvert <cal@…>

Another refinement, 0.7, with a couple of significant issues resolved. Some notes on usage ...

  • The patch plugs itself into the configure/build system ok. It was developed against PA 0.9.10, so I can't see any version issues given the current state of PulseAudio? & distros.
  • With PulseAudio? enabled, the main audio device setting presents an option: PulseAudio:default:default. The two extra fields allow nomination of the desired PulseAudio? server/host and sink names to use. If no names are nominated, it checks the environment for $PULSE_SERVER and $PULSE_SINK, and uses them if set. Otherwise it just goes for the defaults. This stuff is only lightly tested. The gui is currently broken when it comes to editing those fields.
  • The buffer metrics are eminently tunable. There's over/underflow callback to assist in that. As is, it's lookin' pretty smooth.

Fit & ready for other interested parties (if any!) to test & break perhaps.

Changed 16 years ago by Alan Calvert <cal@…>

Attachment: audiooutpulse-0.7.patch.gz added

patch against trunk 17646

Changed 16 years ago by Alan Calvert <cal@…>

against 0.21-fixes svn 17646

comment:4 Changed 16 years ago by Jeremy Nickurak <mythtv-bugs@…>

This fixes some bad stuttering issues I was getting with direct ALSA playback, thanks muchly.

Unfortunately, there's a weird loud-static problem that occurs maybe about 50% of the time. Instead of playing audio, I'll get just loud static. Pausing/unpausing or skipping backwards several times generally seems to fix it, but I haven't established anything special to differentiate the times it works to the times it doesn't.

comment:5 Changed 16 years ago by Alan Calvert <cal@…>

further refinements, patch 0.9 ...

  • PA stream buffer parameters were way too tight, worked ok on my grunty little workstation but proved erratic on lesser hardware. Hopefully, these more conservative settings will solve Jeremy's stuttering/static.

Changed 16 years ago by Alan Calvert <cal@…>

Attachment: audiooutpulse-0.9.patch.gz added

against trunk svn17745

comment:6 Changed 16 years ago by Alan Calvert <cal@…>

Sigh ... patch 0.10, strip some extraneous debugging rubbish and a couple of potential asserts.

Changed 16 years ago by Alan Calvert <cal@…>

Attachment: audiooutpulse-0.10.patch.gz added

against trunk 17747

comment:7 Changed 16 years ago by rob@…

Any word on this? The patch is no longer available from the links and I see that the trunk has progressed a bit since the last version. Did it get migrated in, or??

Changed 16 years ago by Alan Calvert <cal@…>

Attachment: audiooutpulse-0.11.patch.gz added

@ trunk 18161

comment:8 Changed 16 years ago by Alan Calvert <cal@…>

0.11 is a refresh to trunk 18161, and bumps the fragment size 10ms -> 20ms.

comment:9 Changed 16 years ago by mythtv-bugs@…

Any chance we could trouble you for an update for -fixes?

Changed 16 years ago by Alan Calvert <cal@…>

@ 18166

comment:10 Changed 16 years ago by Alan Calvert <cal@…>

0.21-fixes-0.11 is a refresh to 18166, and bumps the fragment size, 10msec -> 20msec.

comment:11 Changed 15 years ago by Jeremy Nickurak <mythtv-bugs@…>

I've finally had a chance to apply these patches and rebuild. I'm still seeing the weird static issues with the latest patches. Pausing/unpausing repeatedly still gets it working again eventually.

When I'm pausing/unpausing, I see the following, regardless of whether or not the audio was in the static or normal state, or whether it changed:

2008-09-29 09:25:44.075 PulseAudio? Error: stream buffer underflow 2008-09-29 09:25:44.930 DPMS Deactivated 2008-09-29 09:25:46.233 DPMS Reactivated. 2008-09-29 09:25:46.544 PulseAudio? Error: stream buffer underflow 2008-09-29 09:25:47.868 DPMS Deactivated 2008-09-29 09:25:48.672 DPMS Reactivated. 2008-09-29 09:25:49.036 PulseAudio? Error: stream buffer underflow 2008-09-29 09:25:50.236 DPMS Deactivated

Changed 15 years ago by Alan Calvert <cal@…>

Attachment: audiooutpulse-0.12.patch added

@ 18528

comment:12 Changed 15 years ago by Alan Calvert <cal@…>

Patch 0.12 - based on speculative analysis of Jeremy's report, plus some more reading of the PA API docs (especially the buffer metrics bits) ...

  • revised the structure of WriteAudio?(),
  • implemented Pause() (also Reset() & Drain(), but they're irrelevant trivialities),
  • revised the buffer settings to something less whacko.

Also did some minor rationalizations, and hopefully I've caught all the resultant PA asserts & seg faults.

Changed 15 years ago by Alan Calvert <cal@…>

Attachment: audiooutpulse-0.12.1.patch added

++ a couple of minor fixups I missed. @18528

Changed 15 years ago by Colin Guthrie <mythtv@…>

Attachment: audiooutpulse-0.12.2.patch added

Minor update to increase backwords compatibility, fix linking and fix a potential uninitialised variable use.

comment:13 Changed 15 years ago by Colin Guthrie <mythtv@…>

Hi,

Just a small update to the patch:

  • Add in a a PULSE_LIBS definition in settings.pro to fix linking.
  • Do not use the PA_STREAM_IS_GOOD() function as this was included in PA API 0.9.11 and many distros still ship 0.9.10.
  • Fix the potentially uninitialised use of write_status in WriteAudio?().

Patch generated at [19037]

comment:14 Changed 15 years ago by IntuitiveNipple

I've back-ported this patch to 0.21+fixess18722 (for Ubuntu Intrepid). Aside from the re-factoring required to deal with using QT3 rather than QT4, and the MythTV changes, I found a few issues some of which are not yet resolved:

  1. Mixed use of USE_PULSEAUDIO and USING_PULSEAUDIO confused things. I've used USING_PULSEAUDIO throughout.
  1. Mixer name needs to be "PulseAudio:default" (not "PulseAudio") in globalsettings.cpp AudioOutputDevice():
    diff --git a/programs/mythfrontend/globalsettings.cpp b/programs/mythfrontend/globalsettings.cpp
    index b1012d1..b8ff8cb 100644
    --- a/programs/mythfrontend/globalsettings.cpp
    +++ b/programs/mythfrontend/globalsettings.cpp
    @@ -168,6 +171,9 @@ static HostComboBox *MixerDevice()
     #ifdef USING_WINAUDIO
         gc->addSelection("Windows:", "Windows:");
     #endif
    +#ifdef USING_PULSEAUDIO
    +    gc->addSelection("PulseAudio:default", "PulseAudio:default");
    +#endif
     
         return gc;
     }
    

Not yet resolved:

  1. Matching the number of PulseAudio channels. On a 7.1 channel audio system MythTV only outputs 5.1 maximum (doesn't output Side Left/Right?). This looks to be easily fixable but I need to check before making changes.
  1. Occasional "PulseAudio Error: stream buffer underflow" reports. No clues to the reason yet.
  1. Occasional bursts of static when changing to new channel (sounds like a 16-bit sample getting out of step by 8 bits). This will sometimes self-correct (another 8 bits dropped would align the samples correctly again).
  1. Frequently audio is lost completely for long periods, with the report "NVP::AddAudioData():p1: Audio buffer overflow, audio data lost!"
  1. Seemingly excessive CPU load by the pulseaudio process and mythtvfrontend.real when using PulseAudio. I need to do more systematic comparisons before confirming this.

I'll attach the current patch I'm using in Ubuntu Intrepid and update as I make progress with the discovered issues.

Changed 15 years ago by IntuitiveNipple

Attachment: 30_pulseaudio_output.dpatch added

0.21+fixes18722 (Ubuntu Intrepid) patch

comment:15 Changed 15 years ago by anonymous

I think 4, 6 and 7 point to a wrong use of buffers, might be all the same bug.

comment:16 Changed 15 years ago by sPOiDar

FYI, I get ~300ms lag on 0.22 with audiooutpulse-0.12.2 when using pulse.

comment:17 Changed 15 years ago by danielk

(In [20310]) Refs #5473. Adds a check for PulseAudio? at startup of mythfrontend and mythtv. PulseAudio? causes delays that range randomly between 500-2000 ms when playing back audio, so we abort startup if the pulse audio server is currently running. Note: I've referenced a ticket that adds PulseAudio? support to MythTV, but even using the PulseAudio? API's the delay is still 300 ms; if we can get that down in the 20 to 50 ms range we can adjust when we display the video frames to compensate for the delay (which we should be doing anyway when using multiframe deinterlacers).

comment:18 in reply to:  17 Changed 15 years ago by anonymous

Can you please add a flag to force startup of mythtv even if the pulse audio server is running? I have my system configured to use pulse and I don't notice any significant audio delay. (I'm using realtime and outputting over hdmi if it matters.) In addition, I'm sure pulse will continue to improve as it matures, so having it completely blocked now (without editing the source) might be detrimental to future users.

Thanks!

Replying to danielk:

(In [20310]) Refs #5473. Adds a check for PulseAudio? at startup of mythfrontend and mythtv. PulseAudio? causes delays that range randomly between 500-2000 ms when playing back audio, so we abort startup if the pulse audio server is currently running. Note: I've referenced a ticket that adds PulseAudio? support to MythTV, but even using the PulseAudio? API's the delay is still 300 ms; if we can get that down in the 20 to 50 ms range we can adjust when we display the video frames to compensate for the delay (which we should be doing anyway when using multiframe deinterlacers).

Changed 15 years ago by danielk

Proof of concept patch for disabling pulse audio at startup. This IS NOT usable for production purposes.

comment:19 Changed 15 years ago by danielk

(In [20421]) Refs #5473. Add code to deal with pulse audio.

By default when compiled on a system with pulse audio we just tell the pulse audio server to leave us alone. For those that want to experiment with pulse audio, we now read the EXPERIMENTALLY_ALLOW_PULSE_AUDIO environment variable and when it is set allow MythTV to run with pulse audio enabled.

comment:20 Changed 15 years ago by danielk

(In [20425]) Refs #5473. Backport pulse audio fix to 0.21-fixes.

comment:21 Changed 15 years ago by danielk

(In [20431]) Refs #5473. Add symbol visibility stuff to audiopulseutil.{cpp,h}

comment:22 Changed 15 years ago by herbert@…

On openSUSE 11.1, mythfrontend does not start with pulseaudio support from 0.21-fixes, pulseaudio 0.9.12 installed and EXPERIMENTALLY_ALLOW_PULSE_AUDIO not set. Message is

2009-05-15 22:42:03.218 AudioPulseUtil?, Error: Failure to suspend: Ungültiges Argument 2009-05-15 22:42:03.225 AudioPulseUtil?, Error: Failure to suspend: Ungültiges Argument 2009-05-15 22:42:03.226 ERROR: *Pulse Audio is running!!!*** 2009-05-15 22:42:03.226 ERROR: But MythTV was not able to suspend it. EXITING!

Without pulseaudio installed or when EXPERIMENTALLY_ALLOW_PULSE_AUDIO is set, it works.

Changed 15 years ago by danielk

Attachment: 5473-v1.patch added

Updates pulse audio output support to trunk (basically work with the pulse audio disable code for other output methods).

comment:23 Changed 15 years ago by danielk

Milestone: unknown0.22
Owner: changed from Isaac Richards to danielk
Status: newassigned

Note: I've done basic testing on 5473-v1.patch to ensure that it does use pulse audio for output, but please consider it proof-of-concept grade as I have not fully reviewed the new code.

comment:24 Changed 15 years ago by databubble

Tried this with trunk 20964. Initial play seems fine, but discovered that after commercial skip or fast-forward, I never seem to pick up audio again.

PulseAudio? 0.9.15 on kubuntu 9.10. Previously was running with ALSA through Pulse and EXPERIMENTALLY_ALLOW_PULSE_AUDIO set.

comment:25 Changed 15 years ago by danielk

Milestone: 0.22unknown

comment:26 Changed 14 years ago by stuartm

Component: mythtvMythTV - Audio Output
Owner: changed from danielk to JYA

comment:27 Changed 14 years ago by danielk

Resolution: fixed
Status: assignedclosed

(In [22690]) Fixes #5473. Add pulse audio output method. The A/V sync is not great, but it is considerably better than when using pulse audio ALSA emulation.

Improvements in A/V sync are welcome, please open a new patch for those. To use pulse audio for output, just select PulseAudio:default as your audio output method.

comment:28 Changed 14 years ago by Adolfo R. Brandes <arbrandes@…>

When compiling 22690:

audiooutput.cpp:28:30: error: audiooutputpulse.h: No such file or directory

Missing file from commit?

comment:29 Changed 14 years ago by danielk

(In [22693]) Refs #5473. Adds two files missing in [22690] commit.

Changed 14 years ago by Adolfo R. Brandes <arbrandes@…>

Attachment: pulse_debug.log added

Audio verbose output for r22694

comment:30 Changed 14 years ago by Adolfo R. Brandes <arbrandes@…>

No sound with PulseAudio:default and r22694. Verbose output attached in previous comment. Running Ubuntu Karmic.

comment:31 Changed 14 years ago by Jeremy Nickurak <jeremy@…>

Does this appy to the -fixes branch?

comment:32 Changed 14 years ago by Adolfo R. Brandes

Update: I got it to output sound using PulseAudio:default (fiddled with system configuration, not sure what made it work), but somewhat intermitently. The sync really is not ideal, as advertised.

comment:33 in reply to:  32 Changed 14 years ago by anonymous

Replying to Adolfo R. Brandes:

Update: I got it to output sound using PulseAudio:default (fiddled with system configuration, not sure what made it work), but somewhat intermitently. The sync really is not ideal, as advertised.

Pray tel what-n-how

[haycorn] /home/jam/release-0-22-fixes/mythtv [94]% mythfrontend 2009-11-07 12:03:49.429 mythfrontend version: branches/release-0-22-fixes [22754] www.mythtv.org 2009-11-07 12:03:49.470 ERROR: *Pulse Audio is running!!!*** 2009-11-07 12:03:49.470 ERROR: But MythTV has not been compiled with Pulse Audio disabling support. EXITING!

Nothing obvious in configure either ?? James

comment:34 Changed 14 years ago by Dibblah

Ticket locked: set

Discussion and troubleshooting on the mailing lists, please. You need the pulse development packages installed - and the pulseaudio output code only applies in Trunk.

Note: See TracTickets for help on using tickets.