Saturday, April 26, 2008

Tuesday, April 15, 2008

Audacious. Gnome. Multimedia keys.

Unfortunately, multimedia keys don't work in Audacious plug-ins like global hotkeys if ones were binded in gnome-keybinding-properties application. I wrote the following plug-in to enable multimedia keys (play, stop, prev, and next) in Audacious player. The plug-in was tested in Ubuntu 7.10. Here is it:
Audacious - Gnome Mmkeys

Friday, April 11, 2008

Ubuntu 7.10 + Jabra BT620s + Jabra 320s

I have bought bluetooth headphones and adapter. Here is an instruction how to configure bluetooth audio under Ubuntu 7.10. Maybe it will be helpful for other distros.

At first you should obtain MAC for you bluetooth audio device:

hcitool scan

Obtained address you should replace in scripts and configuration below instead of "XX:XX:XX:XX:XX:XX".

Create the following file in home directory to configure alsa plug in:
~/.asoundrc
pcm.bluetooth {
type bluetooth
device XX:XX:XX:XX:XX:XX
profile "auto"
}

Then create python scripts. The first script turns on headset profile, the second one turns on A2DP profile for stereo streaming.

Headset proifle (headset.py file):

#!/usr/bin/env python

import dbus
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'), 'org.bluez.Manager')

bus_id = manager.ActivateService('audio')
audio = dbus.Interface(bus.get_object(bus_id, '/org/bluez/audio'), 'org.bluez.audio.Manager')

path = audio.CreateHeadset('XX:XX:XX:XX:XX:XX')
#audio.ChangeDefaultHeadset(path) #change the device to be used by default
headset = dbus.Interface (bus.get_object(bus_id, path), 'org.bluez.audio.Headset')

#Connect and Play are not required in PCM mode
headset.Connect()
headset.Play()

A2DP profile (a2dp.py file):

#!/usr/bin/env python

import dbus
bus = dbus.SystemBus()
manager = dbus.Interface(bus.get_object('org.bluez', '/org/bluez'), 'org.bluez.Manager')

bus_id = manager.ActivateService('audio')
audio = dbus.Interface(bus.get_object(bus_id, '/org/bluez/audio'), 'org.bluez.audio.Manager')

path = audio.CreateDevice('XX:XX:XX:XX:XX:X')
#audio.ChangeDefaultDevice(path) #change the device to be used by default
sink = dbus.Interface (bus.get_object(bus_id, path), 'org.bluez.audio.Sink')

sink.Connect()

Okay. bluetooth-applet should be run. To turn on A2DP profile you should execute a2dp.py and to turn on Headset profile you should execute headset.py. Now you can test sound via audacious: options->preferences->Audio->Current Output Plugin->ALSA
Output Plugin Preferences->Device Settings->audio device: "bluetooth". In other players you should select "bluetooth" device instead of default or any other. See here how to set bluetooth support to another players.

Another way to set bluetooth support is to install Blueman manager.

URLs:
UPD: Audacous writes to console: ALSA lib pcm_bluetooth.c:238:(playback_hw_thread) poll error: Interrupted system call (4). I don't know what it means...

Monday, April 07, 2008

#! /bin/bash
# eth0 - local network
# ppp0 - internet
# eth1 - home wnetwork

IPTABLES=/sbin/iptables

echo 1 > /proc/sys/net/ipv4/ip_forward

# Clearing
$IPTABLES -P INPUT ACCEPTs
$IPTABLES -F INPUT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F OUTPUT
$IPTABLES -P FORWARD DROP
$IPTABLES -F FORWARD
$IPTABLES -t nat -F

$IPTABLES -t nat -A POSTROUTING -o eth0 -j MASQUERADE
$IPTABLES -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

$IPTABLES -A FORWARD -i eth0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -A FORWARD -i eth1 -o eth0 -j ACCEPT
$IPTABLES -A FORWARD -i ppp0 -o eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT
$IPTABLES -A FORWARD -i eth1 -o ppp0 -j ACCEPT