Friday, February 17, 2006

Getting Gtalk working on linux...

In today's google world, those using linux as theur primary OS would have many reasons to hate google (some of them listed here) but with Google releasing Google Talk, I guess the anger if i can call it so has become more pronounced. This is because of the fact that this piece of software called Google Talk is just too good and beats all other voice IM services black and blue. The quality of the voice, the clarity and speed and afaik, the ability to work even on a normal dial up connection make it simply too good. But yet again, google has failed to address the concerns of the linux community and didnt release the source code or atleast a linux port..and so the situation was that you could sign onto the google server using other clients like gaim, psi and the rest but you couldnt talk..but whats the fun in using google talk without being able to talk?!? it took more than 2 months (gtalk first released in september last and google released libjingle sometime in december) for google to release the libraries that code for the audio component of the software, namely libjingle..And the open source community being as it is, this was lapped up quicker than expected and soon, we had Psi releasing a branch of its psi client which included incorporated libjingle into itself...i think within days of google releasing libjingle, this saw the light of the day...shows the real power of open source, something i really doubt would have happened so fast in the other case. Gaim too has kept saying they too will soon add it into their main branch though there are no signs of that happening in the very near future (a month or so). meanwhile, we alsa have other jabber clients popping up which have included libjingle like jabbin though from the looks of it, its nothing but psi remodelled a bit. you can be pretty sure that in the coming days, many more jabber clients like Gizmo too will include the voice support.

Now, coming to the topic, i will put down a few points here which i used to get the talk feature of gtalk working on linux using psi's jingle branch..the wiki page has very good info. first up, you need to get the latest sources through darcs (something similar to cvs) from their repos..being behind a stupid proxy server, cvs/darcs was not going to work on its own...so, from a good friend of mine, i got to know of a thing called Proxychains which from what i comprehend kind of links up your comp to the external server by connecting many (proxy?) servers in between in a chain..with some more work(again our insti proxy server didnt support some thing (dono what :D), i had to use Your Freedom), i got proxychains working..and downloaded the latest sources from the darcs repos (i tried downloading from the web interface using wget/webhtcopier but thats just too arbitrary...gets you many unnecessary files and wastes a lot of time). The wiki and more so, the forums helped in a lot in getting it to work...forums are indeed a boon to the linux community apart from irc channels of course. both are extremely good ways to get help with your problems. i havent used mailing lists as much so am not sure of their usefullness, though i suspect its more prone to spam once in a while. installing psi-jingle was the standard 3 step procedure (or 4 if u prefer to call it so). (all this was done back in the 3rd week of january when i was still on ubuntu..)...and lo and behold, i get a nice cute voice call button next to each person's name on my list..but unfortunately (or fortunately?) i was just not able to get my mic to work...no amount of tweaking settings worked...from alsamixer to different mics to asking on irc channels, i tried everything i could think of but all i got whenever i tried to record was a long blank sound..:(..it was then that i decided to give gentoo a try...one of my principal criteria when choosing a distro is that it should have a amd64 version...else there is no point in me having bought a 64 bit processor if my OS doesnt make use of it (like M$ Windoze)..as a result, though i wanted to try debian instead of ubuntu, dint use it as the amd64 version afaik is still under lotsa development..and i had heard before that when it comes to customization and getting the max out of your box, gentoo is second to none..so here we go..2 reasons to install gentoo..one of which was a hope that my mic would work there..(silly reason to install a whole new OS :D )..and thankfully, my mic worked in gentoo (again though loads of work had to be done though this time i knew what to do and what was going wrong where)...that day will remain special in my life forever..the day when i got both gentoo and gtalk working flawlessly!!

one thing that is striking when comparing linux to windows is the fact that linux still does not have a very good way of being able to handle many programs trying to access the same device (especially the sound card) simultaneously..so you need to completely stop all your other music and movie player (and even kill them sometimes if necessary) and then only can you talk in relative peace. and for this, i got to know of this command called fuser that tells one the processes that are accessing a specific file/device...so i used to find PIDs of these proggies and kill them..yesterday, i struck upon the idea of writing a shell script to do this and assign a shortcut key (using xbindkeys though gnome has an inbuilt shortcut assigning feature..why i prefer the former, i wil try to take it up separately later). this was the small script i managed to come up with...


#!/bin/bash
fuser -k /dev/snd/*


not too bad eh? ;) tested it when no one was calling me on psi and it worked fine..my xmms stopped playing and same happened with mplayer too..little did i realise my folly then..someone did call and give me the chance to test it out real time but i promptly rejected the call instead of acceping it and then ran this script and then called him...everything went on fine..the talk worked like magic..i thought "yes, i have managed to achieve something useful"...to my horror of horrors, a similar situation arose today morning when another good friend of mine called me..this time around, i forgot to cancel the call and let it stay while i executed the script...and unfortunately, as i realise now, psi too is actually trying to access the sound card when i execute the command..and so, it too got screwed :(...so if u know a good way of stopping all programs other than psi, please do let me know..

on the whole, it was a good experience trying to get gtalk working..one hope gaim too adds libjingle sooner than later so that i dont need to run a separate program just for gtalk. i keep checking the cvs but still if i miss out and it comes out, do let me know here by way of a comment. thanks!! :)

phew!! that was a real loong post by any standards..easily beats any other post of mine ever in terms of length (and hopefully usefullness of content too)..Thanks for reading it all the way to down this bit :)

19 Comments:

Blogger Hari Sundararajan said...

I am not really familiar with a quick way to kill all processes that are not related to PSI, but we can give something like this a try:

(Assuming you are root of course.)

(1) fuser -v /dev/snd/*
This gives a neat and comprehensive list of everything. Note here that the only numbers displayed in the entire output are PIDs.
(2) The thing to note is, PIDs get sent to standard error, names get sent to standard output. Let's redirect everything to standard output.
fuser -v /dev/snd/* 2>&1
(3) Then let's search for all lines that do NOT contain PSI.
fuser -v /dev/snd/* 2>&1 | grep -v psi
(4) You would have observed that everything that gets listed now needs to be killed, right? So let's grab the process ids of all of those.
fuser -v /dev/snd/* 2>&1 | grep -v psi | grep -o '[0-9]\{1,\}'
(5) Aha ! Now you have the list of PIDs that deserves to be killed in order to allow you to successfully chat, and PSI itself is not included in this.
(6) Now that you have a neat listing of all that which needs to be killed, we simply need to send it to the kill function.
fuser -v /dev/snd/* 2>&1 | grep -v psi | grep -o '[0-9]\{1,\}' | xargs kill -9

And hopefully they would have all got killed. So essentially

fuser -v /dev/snd/* 2>&1 | grep -v psi | grep -o '[0-9]\{1,\}' | xargs kill -9

fuser -v /dev/snd/*
show me everything
2>&1
send everything to standard output
grep -v psi
show everything that doesn't have psi
grep -o '[0-9]\{1,\}'
show me the numbers alone.
xargs kill -9
DIE !

Of course, it might not work immediately, and you might want to test it out on some other thing perhaps. I tested it out by running apache2, and then asking fuser to show me everything that is being run from /usr/sbin. It included apache2, SSH, cron, Samba among others. I said kill everything related to apache2 and it worked.

11:34 PM  
Blogger Hari Sundararajan said...

I forgot to add, I simply love the command line.

11:38 PM  
Blogger Ganesh said...

wowowow!! thats *awesome* dude..real awesome..i hope i could have engineered such a solution..havent tested it as yet but from the way you describe it, i am pretty much sure it will work. thanks a ton man...especially for taking the time to put a scrap which rivals the post in its length..:)

11:43 PM  
Blogger Ganesh said...

and yes, i dint know that the grep -v option existed..should have guessed though :(..man pages are sometimes just too boring to read through :D

11:49 PM  
Blogger Hari Sundararajan said...

Hmm.. let's look at when it could probably not work.. if you have a process or a file that is accessing /dev/snd but has numbers in it. For example, let's say you have some deadly mp3 player that has the name player2004. Now, since our code filters numbers, 2004 would get filtered. And since it doesn't have PSI in its name, it gets added to our kill list.

And process 2004 would get killed. Hopefully it is not dangerous.

For example, when I tried to kill apache2, it tried to kill the process with PID "2" Of course, it was ok to do that....

11:51 PM  
Blogger Ganesh said...

ya you are right..that is a very valid point..but i think we can use perl to achieve the job in an easier way..wil check up and comment back soon..

12:03 AM  
Blogger Hari Sundararajan said...

yeah. Please do inform if you were to able to tweak it with Perl.

Also, what is your degree in? Biotechnology?

I am doing computer science engineering out here, Louisiana State University. (I know it is a bit late for an introduction, but hey.. getting to know someone through blogs is definitely fun, wouldn't you agree?)

12:41 AM  
Blogger Ganesh said...

yup..it can be done with perl..this way..

fuser -v /dev/snd/* 2>&1 | grep -v psi |grep -v firefox | perl -lane 'print $F[1]' |grep -v kbg |xargs kill -9

the perl -line 'print $F[1]' part just prints the values that appear in the second column which are the PIDs..i am sure you know why it is F[1] and not F[2]. and also, the name of the user of one of the process(es) was getting printed..so to remove that, i added the "grep -v kbg" part..but adding this beofre the perl part would be disastrous as every line would have kbg under the user column..thats why i made it act on the output of the perl part..but still not got a chance to try this out in an actual situation though..have to try and see..will let you know if it works as expected..

yup, you are right..i am doing my bachelors in Biotech here..though it was never my aim to do biotech..i actually did computer science in my 11th and 12th..fate decided that i land up in BT and so i let it be..i must say that it isnt as boring as i thought it might be though..and ya, it sure is real fun knowing someone through blogs ;)

btw, which school in bangalore did u study in? you know tejas personally right?

12:47 AM  
Blogger Ganesh said...

oops..forgot to add..i added grep -v firefox as i dint want firefox to crash everytime i get a call (which isnt too often, atleast till now)..but i dont think firefox should cause a problem..again only an actual situation will tell us if we are right in assuming so..

12:49 AM  
Blogger Hari Sundararajan said...

a neater perl solution indeed.. great..

I am not quite familiar with Perl, but you do have made things a good bit clear.

Yes, as far I know only Pascal, Visual basic among other languages allow array indexing from [1] instead of [0].

true, you can pipe through as many greps as you want.. though I think you can link them all through one regex..

Yes, I do know Tejas personally .. we studied in Sindhi High School together, and he then studied in national public school Rajajinagar, and I did my schooling in national junior school.

great then.. I think I will go sleep ! (considering it is 3am in the morning here.. )

1:05 AM  
Blogger Ganesh said...

ah..i cant lay claim to good knowledge of perl either...just know a tiny wee bit of it from the time when i was writing a php script on my comp to show a list of people online on my irc server at any given moment..i know nothing more about perl as yet :(

1:09 AM  
Blogger Hari Sundararajan said...

I just wanted to thank you a ton for your perl script (in this comments thread). It gained me quite a name on IRC the other day.

Here's what happened. Somebody wanted a list of packages installed in their system, in a mere package list, so that he can use it to reinstall.

Here was the sequence which followed:

dpkg --list List all packages
dpkg --list | grep "^ii" List all installed packages
dpkg --list | grep "^ii" | perl -lane 'print $F[1]' List the names of installed package names.

At this point, a couple of guys joked about how I (thanks to you) mixed Perl and Bash together, and all I had to do was throw in a sed too. So I suggested him an alternative that uses sed instead of perl.

dpkg-query -W -f='${Package},${status}\n' | grep installed | sed -e 's/,install ok installed//g'

We were having a lot of fun, and felt really foolish when we realized what the guy was originally intending to be doing was merely these 2 commands

dpkg --get-selections > someFileName
dpkg --set-selections < someFileName


The chat was pretty interesting.. thanks for your script again !

11:00 PM  
Blogger Ganesh said...

thats very interesting to hear..

looks like you have really gotten addicted to irc :)

1:41 AM  
Blogger Pratik said...

Hi there...

I tried installing psi...and in the connection field put our good old hproxy and the connection type as 'Socks V.5'.
But it doesnt happen to connect at all...Did you face the same prob? (Tried HTTP Connect...but that gives a mesg of 'error during proxy negotiation'..

Also, Wht's to be filled up in the Data Transfer proxy?

Any info wud be very much appreciated...Thanx.

3:02 AM  
Blogger Ganesh said...

as i said in the post, i used your freedom.. our good old hproxy blocks the required ports and so you need to run your freedom to get it to work..afaik, i dint fill/change anything in the data transfer proxy field.. but then, back when i wrote this post, file transfer wasnt there in gtalk but now is.. so if you find a way to get it to work (which doesnt seem to work with connecting to gtalk via gaim though gaim has file transfer capability), please let me know :) (PS: i long ago gave up on psi..after i realised typing is faaar better than talking :D)

3:15 AM  
Blogger Pratik said...

Oops..didnt c the Your Freedom thing at all..

Guess good old hproxy is only old...:)

3:24 AM  
Blogger Ganesh said...

just curious...where from did you come to my (pretty much forgotten) blog?

3:33 AM  
Blogger Shreesh said...

Nice informative post.

Btw your post currently ranks 6th for "libjingle+perl" on Google.

Fallouts of the long article i guess :)

10:14 AM  
Blogger landy said...

quoting you:
one thing that is striking when comparing linux to windows is the fact that linux still does not have a very good way of being able to handle many programs trying to access the same device (especially the sound card) simultaneously..so you need to completely stop all your other music and movie player (and even kill them sometimes if necessary) and then only can you talk in relative peace.

well it isnt the problem of linux not able to handle sound card properly.it is somewhere in the libjingle code or maybe psi( i am not sure) that causing the whole trouble of killing everything.

psi is actually wanting to use the soundcard alone which it cant rather and hence the problem of killing other process using /dev/snd/*
you may notice that skype works just fine even when u r playing songs through mplayer and stuffs.

4:32 PM  

Post a Comment

<< Home