Mar 15, 2011

Use time function to get timestamp in nanoseconds on Linux


#include < time.h >

#include < stdio.h >

int GetTime()
{

   struct timespec tsp;

   clock_gettime(CLOCK_REALTIME, &tsp);   //Call clock_gettime to fill tsp

   fprintf(stdout, "time=%d.%d\n", tsp.tv_sec, tsp.tv_nsec);

   fflush(stdout);

}

Mar 13, 2011

Exit full screen mode on Chicken of the VNC, Mac OS


When VNC is working in full screen mode, we need to use the key combination

"[CTRL] + [alt/option] + [Apple command] +[`]" to exit it.

How to compile VLC source code on MacOS and Fedora 12


1) On Mac OS (According to http://wiki.videolan.org/OSXCompile)

[*] Set the development environment

Install the Mac OS X Developer Tools or get them online.

You need at least Mac OS X 10.5 and Xcode 3.1.4 for compilation. Mac OS X 10.6 and its 3.2.x Xcode releases are also supported. Make sure that the LLVM GCC 4.2 compiler is installed.

Compiling with earlier releases of Mac OS X and/or Xcode will not work.

Additionally, you may need to install Subversion (SVN) and more importantly Git on your Mac.

[*] Get the source

Download the VLC media player source code (using Git) as described on the "Get the source" page or get a recent source tarball.
Note that the 3rd party libraries will probably break a few months after the release's publication.

[*] Build external libs

$ cd extras/contrib

$ ./bootstrap

$ make

[*] Prepare the VLC build

Now we return to VLC itself. Go back to the top level VLC source directory.

$ cd ../..

$ ./bootstrap

This will create configure and Makefiles for VLC media player (snapshots and releases already include this).

[*] Setup the correct compiler

Current revisions of VLC need to be compiled using Apple's llvm-gcc-4.2 compiler in its latest version. In case of failures, make sure that the latest version of Xcode is installed. To use this compiler, you need to export the respective variables. In a Bourne Shell, type this (if Xcode is installed to its default location; bash is the default shell on OS X):

$ export CC=/Developer/usr/bin/llvm-gcc-4.2

$ export CXX=/Developer/usr/bin/llvm-g++-4.2

$ export OBJC=/Developer/usr/bin/llvm-gcc-4.2

[*] Configure the VLC build

The next step is to configure, in the top level VLC source directory. In current revisions, you can simply run

$ ./configure --enable-debug

[*] Build VLC

After configure is finished, we can finally build VLC media player. A simple make will do the trick. If you want to use the resulting application package on a different Mac or a different account on the same Mac, run

$ make

$ make VLC-release.app

2) On Fedora Linux

[#] Download vlc source code 1.1.5 and log on Linux as root user

[#] $ tar -xzvf vlc-1.1.5.tar.bz

[#] Compile vlc by ./configure --prefix=/usr --enable-run-as-root

(--prefix=/usr is the directory for the installation)

[#] If get an error "configure: error: Could not find libmad on your system: you may get it from http://www.underbit.com/products/mad/. Alternatively you can use --disable-mad to disable the mad plugin.
configure: error: Could not find lua. Lua is needed for some interfaces (rc, telnet, http) as well as many other custom scripts. Use --disable-lua to ignore this error."

Then search and download lua-devel from internet. And install it by "yum install lua-devel"

[#] Compile libmad

Download source from http://www.underbit.com/products/mad, and compile ./configure --prefix=/usr

If it has make error, "cc1: error: unrecognized command line option "-fforce-mem"
make[2]: *** [version.lo] Error 1
make[2]: Leaving directory `/home/izhier/download/libmad-0.15.1b' ", modify the makefile to delete -fforce-mem.

[#] $ ./configure --prefix=/usr --with-mad=/usr

If it has error, "configure: error: Could not find libavcodec or libavutil. Use --disable-avcodec to ignore this error.", download ffmpeg from internet.

compile ffmpeg by "./configure --prefix=/root/soft/ffmpeg --enable-swscale --enable-postproc --enable-gpl" and then

$ make

$ make install

[#] If it has error about libavcodec, use

$ export PKG_CONFIG_PATH="/usr/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/ffmpeg/lib/pkgconfig"

To test it,

$ pkg-config --modversion libavcodec

Then it will show "52.20.1"

[#] Compile vlc by "./configure --prefix=/usr --with-mad=/usr"

If it has error, "configure: error: Could not find libswscale. Use --disable-swscale to ignore this error. Proper software scaling and some video chroma conversion will be missing.", use

$ ./configure --help|grep swscale

it will show "--enable-swscale enable GPLed software scaler support [no]". Then, go back to ffmpeg directory and install it again,

$ ./configure --prefix=/usr/ffmpeg --enable-swscale

$ make

$ make install

[#] If it has error, "checking for ffmpeg/swscale.h... no checking for POSTPROC... no configure: error: Could not find libpostproc. Use --disable-postproc to ignore this error.", use

$ ./configure --help|grep postproc

it will show "--enable-postproc enable GPLed postprocessing support [no]"

Then,

$ ./configure --prefix=/usr/ffmpeg --enable-swscale --enable-postproc --enable-gpl

[#] If it shows error "checking for a52dec/a52.h... no
configure: error: Could not find liba52 on your system: you may get it from http://liba52.sf.net/. Alternatively you can use --disable-a52 to disable the a52 plugin.", download a52 from "http://liba52.sf.net" and then,

$ ./configure --prefix=/usr

$ make

$ make install

[#] Compile vlc,

$ ./configure --prefix=/usr --with-mad=/usr --with-a52=/usr

If it has error, "checking for FRIBIDI... configure: error: Package requirements (fribidi) were not met:
No package 'fribidi' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables FRIBIDI_CFLAGS
and FRIBIDI_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.", download fribidi from website "http://fribidi.org/" and then install it,

$ ./configure --prefix=/usr

$ make

$ make install

[#] Compile vlc,

$ ./configure --prefix=/usr --with-mad=/usr --with-a52=/usr --enable-run-as-root

$ make

$ make install

[#] Now VLC on Fedora could be installed successfully!

Mar 9, 2011

MATLAB will crash when using FIGURE or PLOT function. Solution to version R2008b on Mac OS


I use MatLab R2008b all the time. But after I upgrade my Mac OS, it always crashes when the PLOT or FIGURE function is called.

Now MathWorks post the solution as the following,

The crash is possibly related to upgrading the Mac OS to version 10.5.8 or 10.6.8. This issue has been seen in MATLAB R2007a, R2007b, and R2008a, including both Professional and Student versions. Please note that OS 10.6 is not officially suported for MATLAB R2007a, R2007b, and R2008a.

Configurations reported with this crash:

================================

Mac OS 10.6.8 with Java 1.6.0_26

Mac OS 10.5.8 with Java 1.5.0_30

================================

If MatLab upgrading is not an option, as a workaround, replace a statement in the matlabrc.sh file as follows:

< Step 1 >: Close MATLAB, if there is any session open.

< Step 2 >: Locate the file, 'matlabrc.sh' as follows, In Terminal or xterm , type:

open -a TextEdit /Applications/MATLAB_R2008a/bin/.matlab7rc.sh

< Step 3 >: Open the matlabrc.sh file in the editor to replace a line as follows,

Navigate to Line 407,

if [ "$DYLD_LIBRARY_PATH" != "" ]; then

DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH

else

DYLD_LIBRARY_PATH=

fi


Change the line "DYLD_LIBRARY_PATH=" to "DYLD_LIBRARY_PATH=/System/Library/Frameworks/JavaVM.framework/Libraries"

< Step 5 >:
Save the changes by pressing "Command" + "s" keys.

< Step 6 >:
Restart MATLAB.

Reference: http://www.mathworks.com.au/support/solutions/en/data/1-F37IJB/index.html