Firefox Flash Linux Hack

Here’s the first in my series of Linux naunces/gems. Sometimes one of the most annoying things for a computer user of any breed is to navigate to a page that loads a Flash applet. Why is it annoying? For starters, Flash is likely not installed (typical on most Linux distros) and if it is installed it’s the wrong version. Adobe played a little trick on us Flash lovers with the introduction of Flash 8+. Until recently Linux users have been left in the cold next to Fred Flinstone after he’s placed on the stoop by that Saber tooth cat thing in the opening credits. More important (and more to the point of my posting) it becomes hell when you’re watching a presentation on the latest thing in technology, the presentor’s mouth and hands are in motion but for some reason he appears out of tune with the beat. As you watch you realize his lyrical prowess is unprecedented while his voice sounds exactly like Method Man. Somewhere between waiting for the hand gestures to catch up with the background drumming and pondering how the speaker comes up with those fantastic metaphors you realize he’s not rhyming at all, instead your Amarok playlist has casually advanced and faded in the next song on your playlist and it’s blocking the audio from the Flash plugin. While it’s nice to imagine how that smart guy from the Ruby RSpec development team has suddenly become passionate for your favorite genre of music it is more infuriating than ever to manually kill your MP3 jukebox app and manually restart Firefox only to find it blocked again from your buddy pinging you via IM about your latest check in. Before I get too far with my ramblings make sure you have this line in your /etc/firefox/firefoxrc file: FIREFOX_DSP="aoss" I’ll explain what it means in a moment.

Linux Sound Archtecture
Unless you spend your holidays importing headers and setting flags in the kernel for the new inotify feature you’ll most likely be unfamiliar with what I’m about to explain. Linux has this cool way of handling audio signals from programs that run. Remeber how you would try to sneak to the front of the line in the cafeteria so you wouldn’t miss out on the chocolate chip cookies that were always limited in supply in fourth grade? Remember the teacher that would send you to the back of the line when you got caught? Yeah, that’s kinda how Linux handles the audio signals from differnt apps. Well, in a round about way, that’s how it works at the lowest level. You see there are these different sound systems that are fighting each other over the kernels attention. (My explanation here is not totally accurate but it’s an easy way for me to make sense of things in my mind.) In one corner you have OSS which is like the kernels wife. He’s been married to her for most of his life so she get’s the most attention. Then you have ALSA. She’s the hot chick in the office that wears the tight thigh-high mini skirts and always cuts her eyes at him when he isn’t looking. (If my wife’s reading this post, which is highly unlikely but still possible I have to insert a disclaimer: There are no hot chicks in my office cutting their eyes at me. I include the story only as a visual aid to color the text around boring topics like audio signal processing priority and the like.) ALSA gets the kernels attention when he’s away from OSS, away from home. Then there’s the chicks in pub he sometimes hangs in, aRTs (let’s call her Artisia for our story) and eSD (Eshia). Artsia (aRTS) and Eshia are promiscuous. They like to play with ALSA but not with each other because they’re in competition. There are other women in the Kernels life too who fight over him but will remain nameless. Since the Kernel is one kernel he can’t use all of them. So the competition is on. My story is falling to pieces and making much less sense so let me break it down like this. The girls from the story are various APIs and services for handling audio. Sound normally goes through one of them before it hits the actual sound card in your PC tower which plays the noise so your ears can hear it. Some of these APIs and services can be shared while others can handle only one audio stream at a time. Some apps (not as many as before) like the Flash plugin write directly to OSS, which is an API that doesn’t share the sound card. Some apps use ALSA which is an API that can handle multiple sound streams. Many other apps use sound servers like Arts and ESD. (Sound servers can be particular to a desktop like aRTS is used for KDE while Gnome uses eSD.) You can make an app use a mix of both. What often happens on Linux is a bunch of apps will hook up to ALSA while the sound server for the desktop hooks directly into the sound card. When that happens you get wierd behaviour like apps taking turns on the sound card. (A blip from Kopete might preempt the signal from XMMS but you wait a minute and play XMMS again and it plays just fine while the other blips from Kopete go unheard.) The reccommended fix is to redirect your sound from XMMS through the window manager-s sound server. To do that you need a DSP app. (I think DSP stands for Digital Signal Processor but it could just as well stand for Driving Sick and Pregnant) A DSP app launches another app and pretends to be an audio device so when an app binds directly to the low level audio device (/dev/dsp) the signal is intercepted by the DSP app. The DSP app sends all audio it receives to a predetermined output location. For example, artsdsp is an app that redirects sound into aRTS.

The above hack is telling firefox to use the aoss app as it’s DSP app. The aoss app intercepts calls to oss and sends all audio it receives to ALSA. As long as other apps use ALSA then they will play along side with no problems. If it were that simple I would end here. The turth is, there are many DSP apps and many audio servers and many audio APIs. So the above hack worked for me because I’m running KDE without the sound system enabled. I’ve also conciously configured all of my apps to play through ALSA. Finally I’ve written a bash script to play all of my system sounds directly with ALSA. If had had been running the KDE sound system (which uses arts and has long been the default in KDE) and tried the above I would likely have the same behaviour. There is an option in later versions of KDE that allow you to connect Arts to ALSA which side steps the issue but creates another issue. Arts has a bad rep. So much so that I’ve heard rumors of it being discontinued. Furthermore I’ve compared using the sound system with using my bash script for system sounds and there’s a notcieable difference. Sound played though aRTS just doesn’t play as loud as it does when played directly by ALSA. (It gets truncated too for some wierd reason.)

Sound on Linux is very picky and difficult to understand. I’ve been a devot Linux user for years now and I still don’t fully understand it. If you got some info and would like to share it fill out the box below.

2 thoughts on “Firefox Flash Linux Hack

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s