Monday, November 19, 2007

Confused about sound on Linux?

I know I am... With the arrival of PulseAudio to join OSS, ALSA, GStreamer, aRts, ESOUND, NAS, Phonon etc etc it's a bit hard to see any clarity. A linux.com article clears up things a bit.

I seems to me the "standard" way for Gnome will probably be:
- Applications decode/generate audio using GStreamer
- GStreamer sends the audio to PulseAudio which performs volume control and routing
- ALSA drivers play the routed audio onto physical cards

All three projects have some overlap and do not require any of the others to work. OSS was replaced by ALSA. ESOUND was replaced by PulseAudio.

KDE is also using Phonon as a fourth layer for API stability and to allow applications an easy way to play sounds.

OpenGL 2.0



I noticed that since upgrading to Gutsy I appear to have OpenGL 2.0 support callable from Python... Since I've never done any OpenGL 2.0 and I have the Orange Book sitting beside my I should give it a try.

After hacking the installed libraries I got the early result of the shaders in the picture which shows hemispherical lighting (not possible in OpenGL 1).

It all seems to work quite well. I was working on some cell shading but changing shaders while drawing the scene makes everything go black. I hope it's not a driver/binding issue but something I'm doing wrong (can't work it out yet though). Hopefully sometime in the future there will be fluffy chess pieces too :)

As for putting this into glChess I think this one will have to be handled very carefully. There is enough bugs from differing OpenGL setups (and broken drivers) that the code will have to be very robust. When things start working better I'll add a secret gconf key that turns on the shaders for those in the know...

Tuesday, October 30, 2007

No more glchess.sourceforge.net

Well I finally got around to it and have removes glchess.sourceforge.net and the glChess launchpad account. They were very neglected and no longer appropriate with the work in Gnome. The sourceforge page now points to live.gnome.

That is all; move along.

Is Gnome for the 80%?

I work with Engineers with most of us running Ubuntu for day to day work. I however seem to be the only vocal supporter of Gnome. The loudest bunch of GUI users seem to be the KDE (Kubuntu) camp with the general complaint being "it's too simple/dumbed down" (also heard outside of work). My complaint with KDE is "it's too complex". :) The question is:

Is Gnome for the 80% of users like subversion?

I think that is the direction Gnome has been going in for some time and I think this is the direction Gnome should be going. In saying that I don't think Gnome leaves a power user like me high and dry. I like how Gnome keeps my day to day problems simple and for power tasks I stay in Gnome Terminal and use the odd app like Firefox, Gedit, Gimp, Inkscape, Glade and Meld.

Wednesday, October 17, 2007

Moving gcalctool UI to Glade

The another night the Gnome Calculator (another "core" open-source project without a website) was annoying me in how it has a separate memory register window. I'm a big fan of reducing the number of floating dialogs (unless there is a good reason to have them) so I made a patch to move this window inside the main window (Bug 485398). I blind tested this on Henry and he agreed it was better. Unfortunately it doesn't work when the numbers in the registers are huge (can't think of a good UI workaround) so it hasn't been accepted.

However I was foolishly tempted to convert the ~3500 line gtk.c into using Glade (Bug 485919). Which has been taking up all my glChess/GGZ development time but is nearly finished. But I think it's a useful addition for the future of gcalctool.

Saturday, August 25, 2007

Seam Carving for Content-Aware Image Resizing

This is a very cool algorithm. Makes me a little keen to go back to and do a signal processing post-graduate degree at Uni...



Researchers are Shai Avidan and Ariel Shamir.

Friday, August 03, 2007

Got a spare computer lying around?

Quite a cool idea; load a display driver onto a spare computer and use it as more screen real estate for another. The video showing it in action is quite impressive.

SSL in Java

Got SSL working in Python, and for my next trick the Java end! As you may know I am no fan of Java and so this seemingly simple task took much longer than expected...

The initial program is quite simple:

import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.SSLSocket;

public class JVT
{
    public static void main(final String[] args) throws Throwable
    {
        SSLSocketFactory sslSocketFactory = (SSLSocketFactory)SSLSocketFactory.getDefault();

        SSLSocket sslsocket = (SSLSocket)sslSocketFactory.createSocket("localhost", 12345);

        sslsocket.getOutputStream().write("Hello from the world of Java\n".getBytes());
    }
}


But when I connected I got:

Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Oh, what a readable exception... So it appears it doesn't like the certificate of my Python end and I should probably supply that to Java somehow. keytool is the tool for the job (a very cheap and nasty tool). I tried doing a:

$ keytool -import cert

Which did seem to import it (shows with keytool -list) but still the exception.

Tried some debugging:

-Djava.protocol.handler.pkgs=com.sun.net.ssl.internal.www.protocol -Djavax.net.debug=ssl

It showed the standard signing authority certificates but not my one...

And that's when I give up and copy someone else's solution to the problem. This is how to replace the certificate checking with a null implementation:

import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;

public class JVT
{
    public static void main(final String[] args) throws Throwable
    {
        // Create empty HostnameVerifier
        HostnameVerifier hv = new HostnameVerifier()
        {
            public boolean verify(String urlHostName, SSLSession session)
            {
                System.out.println("Warning: URL Host: " + urlHostName + " vs. " + session.getPeerHost());
                return true;
            }
        };

        // Create a trust manager that does not validate certificate chains
        TrustManager[] trustAllCerts = new TrustManager[]
        {
            new X509TrustManager()
            {
                public java.security.cert.X509Certificate[] getAcceptedIssuers()
                {
                    return null;
                }

                public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType)
                {
                }

                public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType)
                {
                }
            }
        };

        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());
        SSLSocketFactory sslSocketFactory = sc.getSocketFactory();

        SSLSocket sslsocket = (SSLSocket)sslSocketFactory.createSocket("localhost", 12345);

        sslsocket.getOutputStream().write("Hello from the world of Java\n".getBytes());
    }
}


So now it works (for transport) but I must find out how to do the certificates properly.

Making an SSL connection in Python

For a work project I want to make a secure point-to-point link between a Java application and a Python server. Here is the result of googling/tinkering to get the link working in Python...

The client side is pretty simple. Python comes with built in SSL support for connecting sockets. Basically you just wrap a standard socket with an SSL socket:

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('localhost', 12345))
sslSocket = socket.ssl(s)
print repr(sslSocket.server())
print repr(sslSocket.issuer())
sslSocket.write('Hello secure socket\n')
s.close()


The server is a bit more tricky, you need to install pyopenssl (apt-get install python-pyopenssl) for more SSL features. The server needs a private key and certificate to identify itself with.

The quick and dirty way to generate a test key+certificate is:

openssl genrsa 1024 > key
openssl req -new -x509 -nodes -sha1 -days 365 -key key > cert


And the server wraps the sockets much like the client does:

import socket
from OpenSSL import SSL

context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file('key')
context.use_certificate_file('cert')

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s = SSL.Connection(context, s)
s.bind(('', 12345))
s.listen(5)

(connection, address) = s.accept()
while True:
    print repr(connection.recv(65535))


OpenSSL also provides a test SSL client/server in the style of telnet/netcat, great for debugging:

openssl s_server -accept 12345 -cert cert -key key
openssl s_client -connect localhost:12345

Friday, July 27, 2007

Tool for checking key events with curses

I'm doing a bit of curses programming at the moment. I've made a tool to check the keys entered are as expected. Do what you like with it.


#!/usr/bin/evn python
import curses
import curses.ascii

keys = {}
for name in dir(curses):
    if name.startswith('KEY_'):
        keys[getattr(curses, name)] = name

for name in dir(curses.ascii):
  if name.isupper():
    keys[getattr(curses.ascii, name)] = name

for i in xrange(128):
    if curses.ascii.isprint(i):
        keys[i] = "'%s'" % chr(i)

s = curses.initscr()
s.keypad(1)
curses.noecho()
try:
    while True:
        c = s.getch()
        s.clear()
        try:
            key = keys[c]
        except KeyError:
            key = '%d' % c
        s.addstr("Key = %s" % key)
        s.refresh()
except:
    curses.endwin()

Wednesday, June 13, 2007

Google Analytics = WOW

Wow.

I just went back to Google Analytics for the first time in a while and their new interface is just amazing.

Check it out:

Safari on Windows

So apparently you can get Safari for Windows.

There are two possible reasons I can see Apple doing this:
  1. The want to improve website compatibility with Safari - by having a Windows version hopefully more page designers will check compatibility and thus their core OSX users will get better support.

  2. They want to use this as their iPhone development platform - Safari will have a mode for running iPhone applications in a browser window the same size and behaviour as the iPhone (which will be like Dashboard applications?).

My gut instinct is that this started when the iTunes developers tried to see how easy it would be to port other apps. Apple must have a reasonable number of Windows savvy developers by now...

Wednesday, June 06, 2007

Have you mooed today?

I notice that apt-get is not the only mooer in town. Try ip moo (from iputils).

Sunday, June 03, 2007

The thin Gnome line

I'm finding recently I'm not making any significant progress on glChess. When I get around to some development after I've gone through the flood of incoming bugs there's no time to add new features! I really want to get the GGZ support into 2.20... I stopped spending time on the flood of Sudoku bugs a while ago.

It is interesting as more distributions change to Gnome 2.18 how many 1 in a million (or other appropriate large number) bugs turn up. I can only assume this user has somehow overwritten their gobject install... Weird *. There seem to be a lot of errors in peoples libraries. Hard to know what to do with these bugs as they're outside the scope of glchess but I'd prefer not to close them NOTGNOME too quickly.


* It would be good from a maintainers point of view if the big distributions like Ubuntu had a background process that audited all installed files so corruption could be picked up (and the packages re-installed).

Monday, May 21, 2007

Nouveau + Linux Graphics

One thing the Nouveau project is doing well is to make open-source graphics more accessible. There are links to a bunch of articles which while still young give insights into what does what. Looking at the nouveau source code shows it really isn't overly complicated - that hard work has already been done by Mesa. A DRI 3D driver basically requires a kernel module to do the IO and an X driver that can convert OpenGL to native card protocol. The difficulty is this protocol is not (publically) documented. But looking through the code and googling shows that a lot of the information is out there. It needs to be compiled into a "Missing Manual".

If I had the time I would love to work on a project like this. Once past a critical point the value to the open-source world would be immense.

As Dave Airlie and Ben Skeggs said at LinuxConf.au; "Graphics drivers are not that hard..."

Sunday, May 20, 2007

Gnome Games Icons

Gnome games now has new Tango icons in all resolutions:


These were made some time ago by (mostly) Daniel Derozier but only some of them were in use in 2.18. I found out about these icons from the Tango mailing list and found there was some complications getting these icons used (see bug 354507).

What seemed to happen was an all too common situation in open-source where everyone wanted the change but it wasn't used due to confusion/politics/endless discussion. It seems very common with distributed development (with people you have never met) that feedback can come across as criticism. Without formal management it's very easy for issues like this to be missed and fall through the cracks.

One thing that I think helps is to divide the change into smaller parts. For instance if a bug is opened with a change that is generally good then commit that change and aim to open more bugs to fix details with the change. If all the details must be fixed before committing then the change is in danger of never reaching completion or ending up in a design by committee situation.

(note that this post is feedback and not criticism!)

Sunday, May 13, 2007

Too many parodies...

I've just watched too many Get a Mac parodies... This one was quite good though:



I use Macs a lot a work for point-of-sale and applications and have been generally impressed with them. They can be tricky locking down but I imagine the other OSs are similarly difficult.

Monday, May 07, 2007

GGZ

It got to 3pm today and I decided I just couldn't be bothered battling Java all afternoon when I'd really prefer to be working on glChess. So I just went home and did that (I love being a contractor!).

So glChess is getting closer to having GGZ support...



Oh, and it really is wonderful to work on a well designed protocol like GGZ. ICS is OK if you're a human but a nightmare for a computer!

Wednesday, May 02, 2007

Poisonous People

I finally got around to watching my first Google Tech Talk, How Open Source Projects Survive Poisonous People (And You Can Too). It's a really good watch as it both shows how to spot and avoid trouble makers but also how to give good feedback as a project member (hopefully so you're not poisonous too!).

One point of particular interest was their recommendation not to put your name in files - by doing this you are implicitly claiming "ownership" of the code which will discourage potential developers. From looking at other peoples code I think I agree with this idea and plan to remove my name from code in the future.