Nov 29 2010

Controlling the Android phone’s Flash light with Python

Yesterday, me, Amar and Sibi (my room mates && colleagues in Sasken) reached our room at 12.30 AM after the late night show of “Due Date”. Amar found it difficult to open the room’s lock since it was too dark.  At that moment, Sibi switched on the Flash light in his new mobile that he recently bought from FlipKart. After reaching the room, he commented like “Hey guys, you got these fancy Android Phones at fancy prices.. yet don’t have a FlashLight facility, which is a must in India :)

Well, I think, he was right. Yet , we have a chance to use the camera flash light present in the Sony Ericsson Xperia X10 Mini handset.  I already have Python installed in the Android handset as part of the android scripting environment which is available here:

http://code.google.com/p/android-scripting/

I decided to give python a chance. After some fights with Android specific UI part of Python in Android scripting environment, I was able to control the flash light in the Android handset through my python script.

Enlight.py

######################################################

import android
import sys
droid = android.Android()

def up():
”’ Open the corresponding sys file and writes ’1′ to enable flashlight ”’
try:
flashLight = open (“/sys/devices/platform/msm_pmic_flash_led/spotlight::enable”, “w”)
flashLight.write(“1″)
flashLight.flush()
flashLight.close()
except IOError:
print “Unable to write to Flashlight device”

def down():
”’ Open the corresponding sys file and writes ’0′ to disable flashlight ”’
try:
flashLight = open (“/sys/devices/platform/msm_pmic_flash_led/spotlight::enable”, “w”)
flashLight.write(“0″)
flashLight.flush()
flashLight.close()
except IOError:
print “Unable to write to Flashlight device”

def enable_disable_light():
”’ UI for enabling/disabling flashlight ”’
title = ‘EnLight’
message = (‘Choose to enable/disable ‘
‘the Flash light present in the Handset’)
droid.dialogCreateAlert(title, message)
droid.dialogSetPositiveButtonText(‘Enable’)
droid.dialogSetNegativeButtonText(‘Disable’)
droid.dialogSetNeutralButtonText(‘Cancel’)
droid.dialogShow()
response = droid.dialogGetResponse().result
if response['which'] == ‘positive’:
up()
elif response['which'] == ‘negative’:
down()
else:
sys.exit(0)

if __name__ == ‘__main__’:
”’ Keep on calling the app till you press cancel ”’
while True:
enable_disable_light()

#############################################################

Python script in proper form is available at this URL:

http://pastebin.com/JiKUziuG

I haven’t used this script in any other Android Handsets other than my SE Xperia X10 Mini. I cannot guarantee that this will work in any other models of Android Phones. But, it works for me !!!

Will upload the Video later :)


Sep 26 2010

Bed time display control switch using arduino

I am a movie buff and I like to watch movies at night in laptop on my bed.  During the movie time , I change my position in bed to reduce strain to my shoulders. I was desperately looking for a solution to adjust the display position the way I want while watching movies without minimizing the screen.  With my new arduino and a python program, I have a whole new solution to my unique problem… An external switch which changes the screen orientation whenever I need.

To interface a switch to arduino, detailed information is available from this URL:   http://www.arduino.cc/playground/Code/Button

Based on the information available on this site, I have coded one simple program which sends the button status to PC using serial port ( Here serial port emulation by Arduino board which uses the USB port)

The DisplayControl.pde file :

/*
|| @file DisplayControl.pde
|| @version 1.0
|| @ Author Maxin B. John (maxinbjohn@gmail.com)
*/

#include <Button.h>

Button button = Button(12,PULLUP);
void setup(){
Serial.begin(9600);
}

void loop(){
if(button.isPressed()){
Serial.println(“H”);
}else{
Serial.println(“L”);
}
}

The arduino board can be accessed from the PC side as “/dev/ttyUSB0″ or similar based on the “dmesg” output. Using the Pyserial module, we can read the state of the switch. Here goes the python program :

maxin@maxin-laptop:~$ cat switch.py
####################################################
#  A sample program to detect the switch state and                             #
#  change the orientation of the display                                                 #
####################################################
import serial
import commands
import time

# Open the Arduino device and read @ 9600 8N1
device = serial.Serial(“/dev/ttyUSB0″,timeout=1)

while(True):

# Makes sure that the true state is read from arduino
if “H” in device.readline() or “H” in device.readline():
print “Switch is on”
# Change the orientation of display using “xrandr”
commands.getoutput(“xrandr -o left”)
device.flushInput()
else:
print “Switch is off”
# Change the orientation of display using “xrandr”
commands.getoutput(“xrandr -o normal”)
device.flushInput()
# Don’t punish the display hardware :)
time.sleep(2)

Connect the switch to ground and pin no: 12 of Arduino board.   Run the minicom program to test whether the values are changing based on the state of the switch. After that, exit from minicom and execute the python program. This program will read button status from arduino and execute “xrandr” command based on the input.

It’s show time… Watch your favorite movie in your favorite player.  Once you feel that you want to relax in bed and watch the movie, press the button and watch the movie in your favorite position. I call this a “Pillow Hacking” :)

Happy Hacking and then … sleeping .. of course !!


Sep 21 2010

Arduino meets LDR

On the way back to my room , after a totally boring day @ work, I was wondering what will I do before sleep… A movie ? Nahh.. Most of the movies in Pix are boring and that’s the only English movie channel that’s available in my room @ chennai.

Near the Thirumalai Railway station, where I get down to reach my room, there are a couple of electronic shops. I have decided to do something with my arduino board which is waiting for me at my room. I got the Light dependent resistor from the second electronic shop for Rs. 7 (1/7 th  of a Dollar).

A quick google search for interfacing LDR with arduino led me to this page:

http://webzone.k3.mah.se/projects/arduino-workshop/projects/arduino_meets_processing/instructions/ldr.html

However, when I tried to connect the LDR using a 1K Ohm pull up resistor, I didn’t get any values from LDR sensor. So, I decided to modify the way the components are connected in a totally foolish way .. I have connected  the LDR between 5v and Analog Input Pin No: 3 (See, there are no pull-up resistors to prevent any issues).  Then I had to make some modifications in the source code to suite my LDR’s sensitivity as well as some other rectifications in syntax of the code. The code is as follows:

/*
*  ap_ReadAnalog
*
*  Reads an analog input from the input pin and sends the value
*  over the serial port.
*
*  This file is part of the Arduino meets Processing Project:
*  For more information visit http://www.arduino.cc.
*
*  copyleft 2005 by Melvin Ochsmann for Malm� University
*  Modified for Arduino Duemilanove by Maxin B. John
*
*/

// variables for input pin and control LED
int analogInput = 3;
int LEDpin = 13;
// variable to store the value
int value = 0;
// a threshold to decide when the LED turns on
int threshold = 1023;

void setup(){
// begin sending over serial port
Serial.begin(9600);
// declaration of pin modes
pinMode(analogInput, INPUT);
pinMode(LEDpin, OUTPUT);
}

void loop()
{
// read the value on analog input
value = analogRead(analogInput);

// if value greater than threshold turn on LED
if (value < threshold)
digitalWrite(LEDpin, HIGH);
else
digitalWrite(LEDpin, LOW);

// print out value over the serial port
Serial.println(value);
// wait for some time
delay(10);
}

Please note that the threshold value changes based on the LDR that we use in the Board (You can find the threshold value by running a minicom on /dev/ttyUSB0). Using my modified code and connections, I have checked the setup and observed the values through minicom.  Yes, it works .

Now, my computer can sense if the tube light is on or off at mid-night in my room through Arduino board :)




Sep 19 2010

Arduino Duemilanove in action

Today, I received my Arduino board from Rhydo Labs, Cochin. For  Rs. 1350/- , I think it’s definitely a cool deal.  Started with some LEDs and some resistors. After some fighting with binutils, gcc, avr-libc and avrdude, I have managed to avoid the following error in my Ubuntu machine:

"unknown MCU 'atmega328p' specified
...
test.c:1: error: MCU "atmega328p" supported for assembler only"

We need to use a gcc which supports the atmega328p micro controller. GCC -4.3.3 onwards supports this micro controller. So, we need to build the binutils, gcc, avr-libc and avrdude for the latest Duemilanove board.  Detailed instructions are present in the link:

http://www.pololu.com/docs/0J31/1

After this, I have managed to run a LED blinking app on arduino. If you can blink an LED, you can control the world :)

Fun begins :)

I will be interfacing the 16×2 LCD display once I get my soldering Iron from my home.


Jun 26 2010

Be a man… Submit a man-page patch today !

All of us (well, at least some of us) like to test the limit of existing things.. That’s what I tried to do with the below given program. I decided to find the limit of the directories created in directories for an ext3 file system using mkdir(). Any one of you could find the reason behind it ? Well, it was for fun :)

# cat test_max_directories.c
————————————————
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>

int main()
{
char dirname[50];
int i;
/* The max number of subdirectories in one directory for ext3 is 32000 */
int limit = 32001;

for (i = 0; i < limit; i++) {
sprintf(dirname, “testdir%d”, i);
if ((mkdir(dirname, 00777)) == -1) {
perror(“Error in creating directory!”);
printf(“errno = %d\n”, errno);
exit(1);
}
}
return 0;

}

———————–

As expected, strace showed that it failed, however with an EMLINK error:

mkdir(“testdir31998″, 0777)             = -1 EMLINK (Too many links)

Here comes the next  thing…. EMLINK error is not present in the man page of mkdir(2) … Wo hoo… a big chance to submit a patch to Linux Kernel Man page project …. I have started the exciting process of preparing the patch, mail and follow up process.

First, I should download the latest kernel man pages which is now in a git repository:

#apt-get install git-core

#git clone git://git.kernel.org/pub/scm/docs/man-pages/man-pages.git

After check out, I have made the necessary changes in mkdir.2 page and prepared the patch using the command:

# git diff

I got the below listed patch:
————

diff –git a/man2/mkdir.2 b/man2/mkdir.2
index e6cb28c..d01bafd 100644
— a/man2/mkdir.2
+++ b/man2/mkdir.2
@@ -73,6 +73,10 @@ is a symbolic link, dangling or not.
Too many symbolic links were encountered in resolving
.IR pathname .
.TP
+.B EMLINK
+The new directory cannot be created because the number of sub directories
+in a directory is limited to LINK_MAX defined by the file system.
+.TP
.B ENAMETOOLONG
.IR pathname ” was too long.”
.TP

—————————

Here comes the most exciting part… Create a proper mail and convince the man page maintainer to include this to the mkdir man page.

First, I should choose the right mail id’s to send the patch. From the mailing list it should be mailed with:

To: mtk.manpages@googlemail.com

CC: linux-man@vger.kernel.org

(make sure that you are already subscribed to linux-man@vger.kernel.org)

Then it is important to give the correct subject line. It gives the required importance to the patch. A wrong subject line could ruin to chances to mainline your patch . As I have previous experience with this mailing list, I chose the subject line:

[PATCH] mkdir.2: Add EMLINK error

Next important thing is what we should write in the mail. We should support our patch and show it’s importance. It should have the “Signed-off-by : Name <mail id> and properly placed patch along with the mail. Some groups will reject the patch right away if we attach the patch with the mail as a separate attachment.  So, observe the mailing list and then decide how to send the patch.

——————————————-

Dear Michael,

While executing the below given program in ext3 file system, I came
across the EMLINK error in mkdir(2) syscall.

# cat test_max_directories.c

#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>

int main()
{
char dirname[50];
int i;
/* The max number of subdirectories in one directory for ext3 is 32000 */
int limit = 32001;

for (i = 0; i < limit; i++) {
sprintf(dirname, “testdir%d”, i);
if ((mkdir(dirname, 00777)) == -1) {
perror(“Error in creating directory!”);
printf(“errno = %d\n”, errno);
exit(1);
}
}
return 0;
}

# ./a.out
Error in creating directory!: Too many links
errno = 29

An strace of this execution shows that the mkdir(2) call generates an
EMLINK error when it reaches the limit of  maximum number of sub
directories in one directory

#strace ./a.out
——————————

—–
…..
mkdir(“testdir31998″, 0777)             = -1 EMLINK (Too many links)
dup(2)                                  = 3
fcntl64(3, F_GETFL)                     = 0×8002 (flags O_RDWR|O_LARGEFILE)
brk(0)                                  = 0x804a000
brk(0x806b000)                          = 0x806b000
fstat64(3, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), …}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb7f71000
_llseek(3, 0, 0xbffc3078, SEEK_CUR)     = -1 ESPIPE (Illegal seek)
write(3, “Error in creating directory!: To”…, 45Error in creating
directory!: Too many links
) = 45
close(3)                                = 0
munmap(0xb7f71000, 4096)                = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), …}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1,
0) = 0xb7f71000
write(1, “errno = 29\n”, 11errno = 29
)            = 11
exit_group(1)                           = ?
Process 16246 detached
———————————–

However, reference to EMLINK is not present in the mkdir(2) man page.
The following patch adds the EMLINK error in the man page of mkdir(2).

Kindly let me know if there are any issues.

Best Regards,
Maxin B. John
www.maxinbjohn.info

Signed-off-by: Maxin B. John <maxinbjohn@gmail.com>

——-

diff –git a/man2/mkdir.2 b/man2/mkdir.2
index e6cb28c..d01bafd 100644
— a/man2/mkdir.2
+++ b/man2/mkdir.2
@@ -73,6 +73,10 @@ is a symbolic link, dangling or not.
Too many symbolic links were encountered in resolving
.IR pathname .
.TP
+.B EMLINK
+The new directory cannot be created because the number of sub directories
+in a directory is limited to LINK_MAX defined by the file system.
+.TP
.B ENAMETOOLONG
.IR pathname ” was too long.”
.TP

—————————————————————————
Next process is to follow it up. I got frustrated when nobody from the list replied to me about the patch for the next two days… So I have sent the follow up mail to the list as a reply to my first mail. All I wanted to show was that my patch was relevant.
—————————–
Hi,

A quick google search shows that the sus v3 version of mkdir(2) has
reference to EMLINK error

http://www.opengroup.org/onlinepubs/000095399/functions/mkdir.html

[EMLINK]
The link count of the parent directory would exceed {LINK_MAX}.

Please let me know your opinion on this.

Best Regards,
Maxin B. John

————————————
There were no replies even after 2 days of sending this mail also. So I just decided to ping the group. A mail as a reply to my previous mails just to let them know that I am waiting to know their opinion:
——
ping …
——
Finally I got this reply from Michael Kerrisk, the Linux Kernel Man pages maintainer:
———————————
Hello Maxin,

- Show quoted text -
On Mon, Jun 21, 2010 at 5:48 PM, Maxin John <maxin.john@gmail.com> wrote:
> Dear Michael,
…..
Thanks for the very precise and well supported bug report!

Yes, the page should be fixed. …..

…………………………
Bingo.. they accepted the patch, with some modifications though… :)
Links:
http://permalink.gmane.org/gmane.linux.man/1484
http://permalink.gmane.org/gmane.linux.man/1471
http://permalink.gmane.org/gmane.linux.man/1478
http://permalink.gmane.org/gmane.linux.man/1483
Come, be a man … Submit some kernel man page patches :)

May 26 2010

webm support for mplayer in Ubuntu

Today, I have read the blog of Praveen (http://www.j4v4m4n.in/2010/05/26/webm-support-for-fedora-13/) about how he added support for webm in Fedora13 (for ffmpeg).  Though I heard about Google releasing VP8 codec as Free Software, I never thought of downloading a .webm file( What’s the use of it , if you can’t play it :) ). However, after downloading the ‘bigbrotherstate.webm” file from Praveen’s blog, I have tried to play it in my favorite media player, ‘mplayer’ and failed.
maxin@maxin-laptop:~$ mplayer /home/maxin/Downloads/bigbrotherstate.webm
MPlayer SVN-r29237-4.4.1 (C) 2000-2009 MPlayer Team
mplayer: could not connect to socket
mplayer: No such file or directory
Failed to open LIRC support. You will not be able to use your remote control.
Playing /home/maxin/Downloads/bigbrotherstate.webm.

Exiting… (End of file)

———————–

It’s all very well having latest o2 Mobile Broadband or a computer with a lightning fast processor, if your mplayer doesn’t work, none of that is quite as good. This is how I fixed my problem:

Then I started my night long effort by tinkering with the mplayer source and VP8 patches and finally made it working in Ubuntu Linux.

Mplayer playing the “bigbrotherstate.webm”

webm in mplayer

webm in mplayer

I have created a log file for this activity: Here it goes:

As per the project (http://www.webmproject.org/code/build-prerequisites/), the VP8 Codec SDK (libvpx) has build dependency on Yasm assember for optimized building on x86 (32 and 64 bit).

At first, get the Yasm assembler from (http://www.tortall.net/projects/yasm/wiki/Download)

wget http://www.tortall.net/projects/yasm/releases/yasm-1.0.1.tar.gz
tar zxvf yasm-1.0.1.tar.gz
cd yasm-1.0.1
./configure
make
sudo make install

Now, go for the libvpx and build it.We can download the libvpx source from webm project page:http://code.google.com/p/webm/

wget http://code.google.com/p/webm/downloads/detail?name=libvpx-0.9.0.tar.bz2
tar jxvf libvpx-0.9.0.tar.bz2
cd libvpx-0.9.0
./configure
make
sudo make install

There comes the mammoth task of downloading the patches for adding webm support to mplayer :mplayer-vp8-encdec-support-r1.tar.bz2

wget http://code.google.com/p/webm/downloads/detail?name=mplayer-vp8-encdec-support-r2.tar.bz2

tar jxvf mplayer-vp8-encdec-support-r1.tar.bz2

ls
allcodecs-register_VP8.diff
avcodec-AVCodecContext_add_VP8_specifics.diff
avcodec-minor_version_bump.diff
avcodec-VP8_CODEC_ID.diff
avformat-minor_version_bump.diff
ffmpeg-only
libavcodec-build_VP8.diff
libavcodec-new_options.diff
libvpxdec.diff
libvpxenc.diff
Makefile-avcodec-add_webm_demux.diff
Makefile-avformat-add_webm_demux.diff
matroska-add_V_VP8.diff
matroskadec-add_webm.diff
matroskaenc-add_webm.diff
mplayer-only
riff-VP80_fourcc.diff

Hmm.. a number of files to fight with :)

Anyways, get the latest mplayer source:
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer

cd mplayer
patch -p1 <../../mplayer-vp8-encdec-support/libvpxdec.diff
patching file libvpxdec.c

Index: allcodecs.c
===================================================================
— allcodecs.c    (revision 23341)
+++ allcodecs.c    (working copy)
@@ -349,6 +349,7 @@
REGISTER_DECODER (LIBSPEEX, libspeex);
REGISTER_ENCODER (LIBTHEORA, libtheora);
REGISTER_ENCODER (LIBVORBIS, libvorbis);
+    REGISTER_ENCDEC  (LIBVPX_VP8, libvpx_vp8);
REGISTER_DECODER (LIBVPX, libvpx);
REGISTER_ENCODER (LIBX264, libx264);
REGISTER_ENCODER (LIBXVID, libxvid);

maxin@maxin-laptop:~/Downloads/mplayer/svn/mplayer/libavcodec$ patch -p1 <../../../mplayer-vp8-encdec-support/libavcodec-new_options.diff
patching file options.c

maxin@maxin-laptop:~/Downloads/mplayer/svn/mplayer/libavcodec$ patch -p1 <../../../mplayer-vp8-encdec-support/libvpxenc.diff
patching file libvpxenc.c

maxin@maxin-laptop:~/Downloads/mplayer/svn/mplayer/libavcodec$ patch -p1 <../../../mplayer-vp8-encdec-support/libvpxenc.diff
patching file libvpxenc.c

maxin@maxin-laptop:~/Downloads/mplayer/svn/mplayer/libavcodec$ patch -p1 <../../../mplayer-vp8-encdec-support/Makefile-avcodec-add_webm_demux.diff
patching file Makefile
Hunk #1 succeeded at 512 with fuzz 1 (offset 14 lines).

maxin@maxin-laptop:~/Downloads/mplayer/svn/mplayer/libavformat$ patch -p1 <../../../mplayer-vp8-encdec-support/Makefile-avformat-add_webm_demux.diff
patching file Makefile
Hunk #1 succeeded at 257 (offset 2 lines).

maxin@maxin-laptop:~/Downloads/mplayer/svn/mplayer/libavformat$ patch -p1 <../../../mplayer-vp8-encdec-support/Makefile-avformat-add_webm_demux.diff
patching file Makefile
Hunk #1 succeeded at 257 (offset 2 lines).

Index: matroskadec.c
===================================================================
— matroskadec.c    (revision 23341)
+++ matroskadec.c    (working copy)
@@ -36,7 +36,9 @@
#include “isom.h”
#include “rm.h”
#include “matroska.h”
-#include “libavcodec/mpeg4audio.h”
+#if CONFIG_MATROSKA_DEMUXER
+ #include “libavcodec/mpeg4audio.h”
+#endif
#include “libavutil/intfloat_readwrite.h”
#include “libavutil/intreadwrite.h”
#include “libavutil/avstring.h”
@@ -824,7 +826,7 @@
/*
* Autodetecting…
*/
-static int matroska_probe(AVProbeData *p)
+static int ebml_probe(AVProbeData *p, const char probe_data[], const int probe_data_size)
{
uint64_t total = 0;
int len_mask = 0×80, size = 1, n = 1, i;
@@ -848,15 +850,13 @@
/* Does the probe data contain the whole header? */
if (p->buf_size < 4 + size + total)
return 0;
-
-    /* The header should contain a known document type. For now,
-     * we don’t parse the whole header but simply check for the
-     * availability of that array of characters inside the header.
-     * Not fully fool-proof, but good enough. */
-    for (i = 0; i < FF_ARRAY_ELEMS(matroska_doctypes); i++) {
-        int probelen = strlen(matroska_doctypes[i]);
-        for (n = 4+size; n <= 4+size+total-probelen; n++)
-            if (!memcmp(p->buf+n, matroska_doctypes[i], probelen))
+    /* The header must contain the document type from the demuxer
+     * specific probe function. For now, we don’t parse the whole
+     * header but simply check for the availability of that array
+     * of characters inside the header. Not fully fool-proof, but
+     * good enough. */
+     for (n = 4+size; n <= 4+size+total-(probe_data_size-1); n++)
+        if (!memcmp(p->buf+n, probe_data, probe_data_size-1))
return AVPROBE_SCORE_MAX;
}

@@ -864,6 +864,23 @@
return AVPROBE_SCORE_MAX/2;
}

+/*
+ * Autodetecting…
+ */
+static int matroska_probe(AVProbeData *p)
+{
+    static const char probe_data[] = “matroska”;
+    return ebml_probe(p, probe_data, sizeof(probe_data));
+}
+#if CONFIG_WEBM_DEMUXER
+static int webm_probe(AVProbeData *p)
+{
+    static const char probe_data[] = “webm”;
+    return ebml_probe(p, probe_data, sizeof(probe_data));
+}
+#endif
+
+
static MatroskaTrack *matroska_find_track_by_num(MatroskaDemuxContext *matroska,
int num)
{
@@ -1117,11 +1134,12 @@

static int matroska_aac_sri(int samplerate)
{
-    int sri;
-
+    int sri = 0;
+#if CONFIG_MATROSKA_DEMUXER
for (sri=0; sri<FF_ARRAY_ELEMS(ff_mpeg4audio_sample_rates); sri++)
if (ff_mpeg4audio_sample_rates[sri] == samplerate)
break;
+#endif
return sri;
}

@@ -1146,6 +1164,7 @@
/* First read the EBML header. */
if (ebml_parse(matroska, ebml_syntax, &ebml)
|| ebml.version > EBML_VERSION       || ebml.max_size > sizeof(uint64_t)
+        || strcmp(ebml.doctype, s->iformat->name)
|| ebml.id_length > sizeof(uint32_t) || ebml.doctype_version > 2) {
av_log(matroska->ctx, AV_LOG_ERROR,
“EBML header using unsupported features\n”
@@ -1274,11 +1293,13 @@
ff_get_wav_header(&b, st->codec, track->codec_priv.size);
codec_id = st->codec->codec_id;
extradata_offset = FFMIN(track->codec_priv.size, 18);
+#if CONFIG_MATROSKA_DEMUXER
} else if (!strcmp(track->codec_id, “V_QUICKTIME”)
&& (track->codec_priv.size >= 86)
&& (track->codec_priv.data != NULL)) {
track->video.fourcc = AV_RL32(track->codec_priv.data);
codec_id=ff_codec_get_id(codec_movvideo_tags, track->video.fourcc);
+#endif
} else if (codec_id == CODEC_ID_PCM_S16BE) {
switch (track->audio.bitdepth) {
case  8:  codec_id = CODEC_ID_PCM_U8;     break;
@@ -1881,6 +1902,7 @@
return 0;
}

+#if CONFIG_MATROSKA_DEMUXER
AVInputFormat matroska_demuxer = {
“matroska”,
NULL_IF_CONFIG_SMALL(“Matroska file format”),
@@ -1892,3 +1914,19 @@
matroska_read_seek,
.metadata_conv = ff_mkv_metadata_conv,
};
+#endif
+
+#if CONFIG_WEBM_DEMUXER
+AVInputFormat webm_demuxer = {
+    “webm”,
+    NULL_IF_CONFIG_SMALL(“WebM file format”),
+    sizeof(MatroskaDemuxContext),
+    webm_probe,
+    matroska_read_header,
+    matroska_read_packet,
+    matroska_read_close,
+    matroska_read_seek,
+    .metadata_conv = ff_mkv_metadata_conv,
+};
+#endif
+

————————————————

No need to apply riff patch:
XXXX patch -p1 < ../../../mplayer-vp8-encdec-support/riff-VP80_fourcc.diff

maxin@maxin-laptop:~/Downloads/mplayer/svn/mplayer/etc$ patch -p1 <../../../mplayer-vp8-encdec-support/mplayer-only/codecs_conf-VP8.diff
patching file codecs.conf
Hunk #1 succeeded at 2183 with fuzz 2 (offset 241 lines).

maxin@maxin-laptop:~/Downloads/mplayer/svn/mplayer/libmpdemux$ patch -p1 < ../../../mplayer-vp8-encdec-support/mplayer-only/demux_mkv-V_VP8__webm_doctype.diff
patching file demux_mkv.c
patching file matroska.h

maxin@maxin-laptop:~/Downloads/mplayer/svn/mplayer/libavcodec$ patch -p1 <../../../mplayer-vp8-encdec-support/avcodec-AVCodecContext_add_VP8_specifics.diff
patching file avcodec.h
Hunk #1 succeeded at 2665 (offset 6 lines).

Index: configure
===================================================================
— configure    (revision 31226)
+++ configure    (working copy)
@@ -300,6 +300,7 @@
–disable-libschroedinger-lavc   disable Dirac in libavcodec (Schroedinger
decoder) [autodetect]
–disable-libvpx-lavc     disable libvpx in libavcodec [autodetect]
+  –disable-libvpx-vp8-lavc disable VP8 in libavcodec [autodetect]
–disable-libnut          disable libnut [autodetect]
–disable-libavutil_a     disable static libavutil [autodetect]
–disable-libavcodec_a    disable static libavcodec [autodetect]
@@ -695,6 +696,7 @@
_libdirac_lavc=auto
_libschroedinger_lavc=auto
_libvpx_lavc=auto
+_libvpx_vp8_lavc=auto
_libnut=auto
_lirc=auto
_lircc=auto
@@ -1141,6 +1143,8 @@
–disable-libschroedinger-lavc)  _libschroedinger_lavc=no   ;;
–enable-libvpx-lavc)   _libvpx_lavc=yes  ;;
–disable-libvpx-lavc)  _libvpx_lavc=no   ;;
+  –enable-libvpx-vp8-lavc)   _libvpx_vp8_lavc=yes  ;;
+  –disable-libvpx-vp8-lavc)  _libvpx_vp8_lavc=no   ;;
–enable-libnut)      _libnut=yes     ;;
–disable-libnut)     _libnut=no      ;;
–enable-libavutil_a)         _libavutil_a=yes        ;;
@@ -7624,6 +7628,45 @@
fi
echores “$_libvpx_lavc”

+
+echocheck “libvpx_vp8″
+if test “$_libvpx_vp8_lavc” = auto; then
+  _libvpx_vp8_lavc=no
+  if test “$_libavcodec_a” != yes; then
+    res_comment=”libavcodec (static) is required by libvpx_vp8, sorry”
+  else
+    cat > $TMPC << EOF
+#define HAVE_STDINT_H 1
+#include <vpx/vpx_decoder.h>
+#include <vpx/vp8dx.h>
+#include <vpx/vpx_encoder.h>
+#include <vpx/vp8cx.h>
+int main(void)
+{
+    vpx_codec_dec_init(NULL,&vpx_codec_vp8_dx_algo,NULL,0);
+    vpx_codec_enc_init(NULL,&vpx_codec_vp8_cx_algo,NULL,0);
+    return 0;
+}
+EOF
+    _inc_vpx_vp8=
+    _ld_vpx_vp8=-lvpx
+    cc_check $_inc_vpx_vp8 $_ld_vpx_vp8        &&
+    _libvpx_vp8_lavc=yes                       &&
+    extra_cflags=”$extra_cflags $_inc_vpx_vp8″ &&
+    extra_ldflags=”$extra_ldflags $_ld_vpx_vp8″
+  fi
+fi
+if test “$_libvpx_vp8_lavc” = yes ; then
+  def_libvpx_vp8_lavc=’#define CONFIG_LIBVPX_VP8 1′
+  _libavencoders=”$_libavencoders LIBVPX_VP8_ENCODER”
+  _libavdecoders=”$_libavdecoders LIBVPX_VP8_DECODER”
+  codecmodules=”libvpx_vp8 $codecmodules”
+else
+  def_libvpx_vp8_lavc=’#define CONFIG_LIBVPX_VP8 0′
+  nocodecmodules=”libvpx_vp8 $nocodecmodules”
+fi
+echores “$_libvpx_vp8_lavc”
+
echocheck “libnut”
if test “$_libnut” = auto ; then
cat > $TMPC << EOF

—————————————

Now Compile mplayer:

./configure  –enable-libvpx-vp8-lavc
make

Finally… after 5 hours of fight with the includer files and Makefiles and modifying some files (sorry.. in half sleep), I got .webm support working with mplayer…

Now, my newly built mplayer can play .webm files.. Yooo.. hoooo…

Thanks to Praveen for inspiration and .webm file.

Finally, see mplayer in action.
./mplayer /home/maxin/Downloads/bigbrotherstate.webm

Hoping to submit the modified patches after re-creating the patches against the latest mplayer source code from SVN.  I will be pushing the modified source code to my blog-site.

Update: The modified tar file is available under the following URL:

http://rapidshare.com/files/398835122/mplayer-with-webm.tar.gz.html


Apr 28 2010

Humor :) from THE CHURCH OF EMACS

Most of  us believe that the people who follow THE CHURCH OF EMACS are very serious guys with little sense of humor. That’s not true … Just follow this URL for some serious techie FUN :

http://www.gnu.org/fun

For example, when you run command in Linux:

$ ^How did the sex change^ operation go?
-bash: :s^How did the sex change^ operation go?: substitution failed

$ [ Where is Bill G?
-bash: [: missing `]‘

(… from : http://www.gnu.org/fun/jokes/unix.errors.html )

Now it’s a fashion to attack the church. I do enjoy it too :)

x——————————————————————————–x

/*  One sample GPL v3 licensed joke. I swear that it’s not created by me */

Hierarchy of the Church

  1. GODS — Creates Free ideas, software and hardware from emptiness and likes to be flattered through prayers.
  2. DEMIGODS — Capable of proving that NP problems and P problems are the same (NP=P), writes free software for to prove it and tries to alleviate the bullying nature of GODS by distributing the ideas of GODS freely. They still insist on flattering GODS through prayers and defends the bullying of GODS.
  3. SAINTS — Writes Free software using Free software tools.
  4. SEMI SAINTS — Use lots of Free software and believes in the church of EMACS but signed NDAs or agreed to proprietary software licenses.
  5. PROPHETS — selected by ALMIGHTY (One of the GODS) to reveal his thoughts about humanity.
  6. LAITY — does not care about NDAs or proprietary software licenses but runs after BUZZWORDS to show that he is capable of grasping BUZZWORDS.
  7. Sinners — Insist on using devil’s software, believing that it is of superior quality.
  8. Devils — Creating NDAs and proprietory software licenses to entangle humanity in their net

Examples of Devils

Evil Empire: Microsoft

Lucifer: Bill Gates

Evil Countries: SUN, HP, ORACLE, etc.

Other major Devil leaders: Scott Mcnalley, Larry Ellison, etc.

CONFESSION AND REPENTANCE

Please take some time to think about yourself. You can repent and confess at any time by visiting our CONFESSION CENTER which is open 7 days a week, 24 hours a day.

Rules for repentance (This is the only important principle of THE CHURCH OF EMACS):

  1. $10 for each invocation of a proprietory licensed software.
  2. $1000 for each NDA you signed.
  3. $10000 for each NDA you participated in creating.
  4. $10000000 for each NDA you wrote.
  5. $100 for each proprietary software license you agreed to.
  6. $1000 for each proprietary software license you participated in creating.
  7. $10000 for each proprietary software license you are responsible for writing.
  8. All your sins will be forgiven if you develop a major new Free software package.

Warning: Taking THE CHURCH OF EMACS seriously is hazardous to your health; especially MENTAL HEALTH.

x—————————————————————————————————-x

+  Some  Hello World C codes ( Side effect of reading “Deep C Secrets”):

0. ifelse1.c

#include <stdio.h>
#include <setjmp.h>

jmp_buf buf;

int main()
{

if (setjmp(buf)) {
printf(” World\n”);
return 0;
} else {
printf(“Hello”);
longjmp(buf, 1);
}
}

1. ifelse2.c

#include <stdio.h>

int main()
{
if (printf(“Hello”) == 0) {
} else
printf(” World \n”);
return 0;
}


Mar 30 2010

902 people downloaded “ChickenWarrior” : my first Mobile game

Today, I have visited the “ChickenWarrior” game page in Betavine: http://www.betavine.net/bvportal/application/ChickenWarrior/index.html

I was amazed to see the number of downloads for that silly simple game: 902

Now, I really feel sad for what I have done. I just created a small game like program for my K300i mobile out of curiosity. All it did was just added some chunk of code to move the half baked images across the phone and a bit of collission detection code as part of game’s logic. I didn’t even added the code to show the score at the end. All I wanted was just to prove that we can do some game programming in GNU/Linux for our dearest Mobile Phones.  After that, I have never looked into that code again and never even thought of improving the game (images and code quality).

The source code of the game is available in Google Code. http://code.google.com/p/chickenwarrior/

Today I feel guilty for publishing a half baked game.  But on the other hand, I did what I felt right that time.. ” Release early Release often!!” : One of the principles of Free Software Movement. I have done the first part right: I released it early.. after that I haven’t followed it… I haven’t released even it’s next version.

I can’t blame anybody else but myself. I dreamt of a number of applications on Mobile Phones. I will be coding it in the near future .


Mar 9 2010

Don’t you have mother and sisters ? Moron !!!

Year 2008…

In one fine morning, I received a mail from my manager in Sony, informing that, I will be visiting Sony Headquarters, Minato, Tokyo, Japan. I will be visiting japan along with the list of people given below:

1. Satheesh-san (Senior manager)

2. Sonali-san (Senior Engineer)

3. Saneesh-san (Engineer)

blah… blah..

Stay will be arranged in Shinagawa Prince Hotel , Tokyo .. aaha..!!!

I have started the epic journey from Bangalore Airport. This time, transit was in Hong Kong International Airport, one of the best in the world. In my previous journey, transit was in Singapore. So, I was pretty excited about visiting each and every part of the Hong Kong Airport. After that, we have reached Narita Airport (Tokyo International Airport) in time and reached the Prince Hotel in “Airport Limousine”: It’s just a bus , nothing to do with limousine cars :)

After attending the amazing annual International technology exhibition of Sony in it’s headquarters and some presentations in Osaki gate city office, we started our journey back to India. This time, Saneesh-san had some more activities to be completed on Sony Erickson office. So, me, Sonali-san and Satheesh-san started our journey to India.

In the way back, during transit at Hong Kong Airport, Sonali-san made a shocking discovery. While waiting for the HongKong -> Bangalore flight in Airport, she thought she lost her credit card. Though I tried to convince her that she might have kept the credit card  in one of those big suitcases, she started weeping.In my broken Hindi, I tried my level best to console her.

HongKong: The land of Jackie Chan… All those people, who are sitting besides me and whoever walking near to us were thinking something else :) .. For them, a lady is crying and a guy is sitting near to her.. both talking in a “pre historic language” . What he might have done .. All those eyes were asking the same question ” Don’t you have mother and sisters ? Moron !!!”

Sonali-san kept on weeping without interruption. Though I am an atheist, this situation demanded the help of gods. My mind started the process of optimally selecting the “God” who fits for this situation.

1. Ganapathy : Rejected.. No…no.. noo… I haven’t started anything new

2. Sri Krishna: Rejected.. No no.. I am not dealing with a number of women

3. Allah : Rejected.. No.. It’s not safe to think about Allah during international travel.. Learn from Shah Rukh Khan

4. Holy Spirit :  Rejected.. No.. though there are a number of “Duty Free” Alcohol shops

5. Jesus:  Perfect fit… here, I am crucified for something that I haven’t done..

One quick idea from God: I have opened my Laptop, booted it and asked Sonali-san to chat with her brother. Luckily, he had the contact number of Bank and along with the necessary details of her card. He made the necessary steps which was just enough to cheer up the weeping girl.

Based on a real story:

Only Jesus saves.. Everyone else make backups :)


Mar 9 2010

Oscar, Hollywood and my memory lane

Yesterday night, before sleeping, I thought about the Oscar award night. Watching Hollywood movies was one of my hobbies and I almost never missed a chance for that. My father , who was also a fan of movies, used to take me to watch English Movies in “Priya”, the first 70MM theater in Kollam (now , Dhanya Theater, part of Muthoot group). That relationship made me a fan of Oscars and I almost never missed the chance to watch the award night ceremonies.

Most of the times, I found joy in finding out the “original” hollywood movie behind the Malayalam/Tamil/Hindi Movies. Whenever I got an opportunity to talk about Movies, I found pride in preaching about “the magic in Hollywood”. I thought of me as a man who knows too much about Hollywood movies and most of the times, that arrogance was visible in my talks. All those thoughts were about to change when I joined Sony….

When I joined Sony India, our office was in Maruti Infotech Centre, Domlur in Bangalore. It was a nice place and the Linux Project group was a small group of amazing people with deep knowledge in Linux. In my work place , cubicles were more or less open. I was sitting near to 3 ladies :

1. Miki – san: Our Japanese teacher who was born in First November (never ask the year, she insists :) ), which happen to be my birthday also.

2. Gayathri-san : My team mate and she is from the most dangerous place in kerala known as Kannur :)

3. Hiromi -san:  A devotee of Satya Sai Baba and a good friend to us all

Most of the ladies from Kannur knows “Kalarippayattu”: A traditional martial art in Kerala. For the Japanese people, it is part of their curriculum to learn Martial arts. This situation demanded me to concentrate on my work mostly because of the following reasons:

1. I don’t know any form of martial arts

2. I would love to be in a normal shape

However, I couldn’t control the tendency to boast about my “deep” knowledge in English movies. In most of the tea times, I used to talk about the movies that I have watched.. the “inspiration” behind the local movies.. etc.. etc..

Once, I happen to talk about the English movies in my cubicle also. I found myself intellectually superior when I talked about various Hollywood movies and how the actors performed in those movies. With ever growing curiosity about Japanese culture and people, I have voiced my question : “Hiromi san, do you watch English movies ? ”

She smiled and after some seconds of silence, she said:

Yes, I do, Maxin-san. In fact, I have acted in a number of Hollywood Movies”

That was a great surprise for me and I couldn’t speak for some time. My colleague, who sits besides me, is a famous Heroine in Hollywood and also in Japan.

Hiromi Nishiyama : http://www.imdb.com/name/nm1036751/

Hiromi-san’s famous movies includes “1st Testament CIA Vengeance”, “Soap girl” ,…etc. Hiromi-san’s mother is  a famous Movie director in Japan .Last year, Malayala Manorama news paper has reported about  Hiromi-san and her mother’s visit to Kerala.

Now, I no longer work for Sony. But I got an opportunity to work with a group of amazingly talented people. I will never forget those people in my life.

Finally, Dear friend, don’t boast.. Just shut up and code.


Get Adobe Flash playerPlugin by wpburn.com wordpress themes