Monday, December 10, 2012

[Androidx86] How to run Angry Birds on Android x86 ICS (A to Z)

This post will help the beginners to modify Androidx86 ICS in order to execute Android Apps such as Angry Birds. Since Androidx86 supports only Intel x86, Atom, the Android apps which developed for ARM cannot execute on the current Androidx86 (ICS). Now, we try to modify the library of Android x86 so that it can translate ARM library to Intel x86. (It can be clearly explained at http://www.buildroid.org/blog/?p=198). Although there are some tips to do, but it is not easy for the beginners. Therefore, i try to write these guides to help anyone can do by themselves from A to Z.

Note that we use Android x86 ICS for this post.

Step 1: Prepare the Linux environment to build Android x86 ISO file. I use Ubuntu 10.4 in this case.
(Following my previous post to install some necessary tools)

Step 2: Now I start from step Download Android x86 Source :
   # cd ~ 
   # mkdir android_src
   # cd android_src
   # repo init -u http://git.android-x86.org/manifest -b ics-x86
   # repo sync
Step 3:
   # cd android_src
   # sudo make iso_img TARGET_PRODUCT=generic_x86
   (This step will take around 4~5 hours)

Step 4:
   Because i run Virtual Box on Windows 7 , then i copy ISO file in "out" folder to Windows 7.
   Run Virtual Box and create new VM with the ISO we copied.
   Follow the install steps Android x86 in Virtual Box  (http://www.android-x86.org/documents/installhowto)
  ***Note: Choose "Yes" in the below box:

Step 5:
   After finish install Androidx86 in Virtual Box, run it.
   Because ICS does not enable eth0, we have to enable it as follows:
   Use "Alt" + "F1" to enter the console mode.
   //Setting static IP
      # ifconfig eth0 "IP_Address" netmask 255.255.255.0 up
      # route add default gw "Gateway_Address" dev eth0

   OR: (dynamic IP : 10.0.x.x)
      # netcfg eth0 up
      # netcfg eth0 dhcp
      # setprop net.dns1 8.8.8.8

 Now go back the graphic mode by "Alt" + "F7", connect internet succesful

Step 6:
   Since i used static IP, then i will use "IP_Address" to connect in this step.
   Due to Androidx86_ICS cannot download any files or apps from internet. Then i try to use ADB (Android Debug Bridge) to install software into Androidx86.
   Download adt-bundle-windows-x86 from http://developer.android.com/sdk/index.html
   Go to  adt-bundle-windows-x86\sdk, Shift + Right Click on Platform-Tool , Choose "Open Command Windows here"
    Try: download : Andftp (http://www.lysesoft.com/products/andftp/) and AngryBirds Rio 1.4.3 (http://download.pandaapp.com/android-app/angry-birds-rio1.4.2-id6743.html#.UUBf2DeHfTo) and put all the downloaded "files.apk" in the same folder with adb.exe
            # adb.exe connect "IP_Address"
            # adb.exe install Andftp.apk

            # adb.exe install AngryBirds.apk 

Step 7: Now Your Androidx86 already installed FtpClient and AngryBirds. But you can not run AngyBird now.
In order to run Angry Birds, we need to add library "houdini" into Androidx86 file system.
In Windows 7: Download the below libs from http://android-x86.sceners.org/en/?p=536
   - libhoudini.so
   - libdvm_houdini.so
   - arm libs

Now, create FTP server in your Windows 7. From Android x86, use FtpClient to connect FtpServer and download all above libs into /sdcard/Download.

Type Alt + F1:
   # cd /sdcard/Download
   # cp libhoudini.so /system/lib
   # cp libdvm_houdini.so /system/lib
   # mkdir /system/lib/arm
   # cp arm_lib/* /system/lib/arm

Reboot Androidx86 and try to run Angry Birds. It will be something like this:


However, the speed is quite slow due to the ARM binary translations.
(Please feel free to ask if you cannot follow any steps).

Wednesday, June 6, 2012

[Linux] Understanding Shared Libraries

Have you ever wondered how shared libraries work? If you wondered and wanted some good information about it you can check out this website here. But how does shared libraries work with say a header file and maybe a main .cpp program instead of just c files? Well I just learnt how to do this and I thought I would share it with you. There are 3 files that I will list the code for and tell what each one is for. The first one is a header file called programmerFunction.h and it's affiliated .ccp file called programmerFunction.cpp. The last one is the main program called userProgram.cpp.

---------------- programmerFunction.h------------------
//This header defines the programmer function which just returns
//A value for an integer.
#ifndef PROGRAMMERFUNCTION_H
#define PROGRAMMERFUNCTION_H
#ifndef _cplusplus
extern "C"
{
#endif
void returnInteger(int*);
#ifndef _cplusplus
}
#endif
#endif
------------------------------------------------------------------------

--------------- programmerFunction.cpp------------------
//Here is the actual code to return an integer.
//As you can see nothing fancy
#include "programmerFunction.h"
void returnInteger(int * eger)
{
*eger=58008;
}
#endif
------------------------------------------------------------------------

------------------- userProgram.cpp ----------------------

//Here is the main program which just includes the
//The programmer defined function and prints out
//The value of the function
#include < stdio.h >
#include "programmerFunction.h"
int main()
{
int eger;
returnInteger(&eger);
printf("This is the value in eger: %d\n",eger);
return 0;
}

------------------------------------------------------------------------

As you can see there is nothing really to these programs and it was designed for simplicities sake.
First thing we have to do is turn the programmerFunction.cpp into an object file by typing in this command:

" g++ -Wall -fPIC -c programmerFunction.cpp "

This creates the object file that will enable us to create our shared library from.

Now in order to create a shared library we are going to enter in this command:
" g++ -shared -Wl,-soname,libmylib.so.1 -o libmylib.so.1.0 programmerFunction.o "

This creates our shared object file called libmylib.so.1.0. From here we are going to move in into this path (or another suitable path of your choice) which is /opt/lib/.

" sudo mv libmylib.so.1.0 /opt/lib/. "

The next thing we have to do is create two soft links that point to the libmylib.so.1.0 shared library.

" sudo ln -sf /opt/lib/libmylib.so.1.0 /opt/lib/libmylib.so "
" sudo ln -sf /opt/lib/libmylib.so.1.0 /opt/lib/libmylib.sh.1 " and
" sudo ln -sf /opt/lib/libmylib.so.1.0 /opt/lib/libmylib.so.1 "

Next we are going to compile our userProgramm.cpp and link our shared library with it.

" g++ -Wall -L/opt/lib userProgram.cpp -lmylib -o compiledProgram "

Now in order for the program to run we need to export the path of /opt/lib to the environment variable
LD_LIBRARY_PATH. We will do this by entering this command:

" export LD_LIBRARY_PATH=/opt/lib:$LD_LIBRARY_PATH "

Now finally to run our program and get it's output.

" ./compiledProgram "

After you run this command you should get the number " 58008 ".

So after you have done all this why would we want to create a shared or dynamic link? Well for such a small program we may not actually need it but to show the power of a shared library we will change the value of the integer without having to recompile our main program. This is what makes shared libraries powerful. You can update the shared libraries without having to redo massive compilations and might actually end up saving you time in the end.
Lets begin by changing our programmerFunction.cpp. change the value eger by replacing it with the value of " 123456 ".

Now run these commands:

" g++ -Wall -fPIC -c programmerFunction.cpp "
" g++ -shared -Wl,-soname,libmylib.so.1 -o libmylib.so.1.0 programmerFunction.o "
" sudo mv libmylib.so.1.0 /opt/lib/. "

What this effectively does is recompiles your programmerFunction.cpp file into a new object file. We also recreate the shared library and replace your old shared library with the new one. Now rerun your program by typing in this:

" ./compiledProgram "

You should now see the new number of " 123456 ". If you see this number congrats! You now know a little bit about shared libraries and maybe see some use for them.

Thanks,

Almightybeeij

From OKCLugNuts

Tuesday, June 5, 2012

[FreeRDP] How to install FreeRDP on Ubuntu

Install some dependent libraries.

  1. sudo apt-get install build-essential git-core cmake libssl-dev libx11-dev libxext-dev libxinerama-dev libxcursor-dev libxdamage-dev libxv-dev libxkbfile-dev libasound2-dev libcups2-dev libxml2 libxml2-dev 
  2. sudo apt-get install libavutil-dev libavcodec-dev 
  3. sudo apt-get install libcunit1-dev libdirectfb-dev xmlto doxygen libxtst-dev 
  4. cmake -DCMAKE_BUILD_TYPE=Debug -DWITH_SSE2=ON 
  5. Before making Makefile, you should enable CLIENT or SERVER in CMakeList.txt and continue the following steps:
  6. sudo make clean
  7. sudo make
  8. sudo make install 
  9. sudo ldconfig


Wednesday, May 16, 2012

You met a group of old college friends for dinner. Your boyfriend came too, but he seemed upset because no one was talking to him. Now you're riding home, and you're angry that he got upset.

I'm sorry if you felt excluded or ignored, but it's not my job to babysit you.



I'm sorry if (clause)

This is a way that people apologize for something:
I'm sorry if anyone is offended by my remarks.
But when you apologize this way, it doesn't sound like you're truly sorry. It seems like you still think that you did the right thing.
People use this expression in a lot of situations, from talking to their family members to politicians making a public apology.

(someone) feels excluded

"Feeling excluded" means feeling like a group of people isn't including you socially.
You might feel excluded if a group of people that you work with go out for drinks after work and don't invite you, for example. Or you might feel excluded if you go to dinner with a group of people and no one talks to you.

(someone) feels ignored

"Feeling ignored" means that you feel like no one is paying attention to you.
You might feel ignored if you make a suggestion at a meeting at work, but the meeting leader moves on to another topic instead of discussing your suggestion.

it's not my job to (do something)

Use this expression when:
  • someone is expecting you to do something
  • you don't think you should be expected to do it
For example, if your boyfriend leaves dirty dishes on the kitchen counter, you can yell at him:
It's not my job to clean up after you!

babysit (an adult)

Watching someone else's child while the parents are away is called "babysitting".
When you use the word "babysit" to talk about an adult, though, it's a little insulting. It means that you have to watch the adult for some reason like:
  • making sure that the person doesn't make a mistake in their job
  • making sure that a socially awkward friend or partner is having fun at a party
People say things like:
I don't have time to babysit you. Figure it out on your own!
 Source: Phrasemix

Wednesday, April 11, 2012

[Android x86] Streaming audio PCM from Server Android x86 to Android Mobile phone using Socket

So far, i have eventually completed streaming audio on Android x86. The principles look easy and simple: Android x86 records the audio PCM and then dispatches the recorded buffers to the client through Socket(for the easiest way), the client receives the files and plays them by using AudioTrack. However, the difficulty comes from the fully unsupported Android x86 like normal Android, such as AudioRecord. This new system does not provide the way to record audio while playing music. Luckily, i found one blog that showed hacking Android x86 to save buffer of audio mixer (From BY: XZPETER - 20TH, 2011). Following those steps, i finally built the new kernel with the modified AudioFlinger module. The buffer is alternately saved to file (path "/data/") within 500 output files. Due to the continuous of audio, we create such many files instead of only few output files. Then, build kernel into ISO file.

Now, i have the audio PCM files which i want to dispatch to client(android phone). Alternately, i wrote the server app for android x-86 and the client app for android phone by using Socket as the network communication.

Thursday, March 22, 2012

C/C++ : Combination (n,k)

This below code show how to print out all cases for C(n,k):

#include stdio.h
#include conio.h
void print(int a[],int n)
{
for(int i=0;i
printf("%4d",a[i]);
printf("\n");
}
void combine(int a[],int n, int k, int i)
{
for(int j=0;j<=n-k+i+1;j++)
{
a[i]=j;
if(i==k-1)
print(a,k);
else
combine(a,n,k,i+1);
}
}
int main()
{
int a[100],n,k;
printf("N: ");
scanf("%d",&n);
printf("K: ");
scanf("%d",&k);
a[0]=0;
combine(a,n,k,0);
getch();
return 0;
}

Tuesday, March 20, 2012

How to build ISO android-x86 in Ubuntu

Follow these below steps to build ISO android-x86 (generic_x86):

I. Prepare your Ubuntu system:
1. Intall JDK
A. Additional repository
i. $ sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ jaunty multiverse"
ii. $ sudo add-apt-repository "deb http://us.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse"
B. $ sudo apt-get update
i. if you failed update, fallowing next step.
1. $ sudo vim /etc/apt/sources.list
 Add the following lines in the end of source.list
deb http://old-releases.ubuntu.com/ubuntu/ jaunty-updates multiverse
2. sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
3. sudo apt-get update
C. $ sudo apt-get install sun-java6-jdk
D. if this is success, you can see some message. Input that commands.
i. $ javac -version
ii. $ java –version
E. $ sudo vim /etc/profile
 Add the following lines in the end of profile:
JAVA_HOME=/usr/bin/java
ANDROID_JAVA_HOME=$JAVA_HOME
PATH=$PATH :$JAVA_HOME/bin:~/bin:
--> save (wq)
v. $ source /etc/profile
F. $ sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev libncurses5-dev x11proto-core-dev libx11-dev libreadline6-dev libgl1-mesa-dev g++-multilib tofrodos python-markdown libxml2-utils xsltproc
G. Install repo
i. $ cd ~
ii. $ mkdir bin
iv. $ chmod a+x ~/bin/repo
II. Download Android resource
i. $ cd ~
ii. $ mkdir android_src
iii. $ cd android_src
iv. $ repo init -u https://android.googlesource.com/platform/manifest -b gingerbread
v. $ repo sync ß This takes long time

III. Build ISO file:
Go to folder resource:
$sudo make iso_img TARGET_PRODUCT=generic_x86

Well, go to the coffee shop and wait for around 5hours...
Ok, now we got the ISO file ....

Linux C++ : Append int to char*

int count = 1;
char name[10] = "out";
char num[2];

sprintf(num, "%d",count); //int -> char
strcat(name,num); //out1

A Method to Capture Android-x86 System Audio

(From BY: XZPETER - 20TH, 2011 )

I have just posted a note about a month ago about video capturing in android system (that post is written in Chinese). This time I will talk something about audio capture.

Actually, I have looking into the issue for some days, and I didn’t find a good way to do that. There are indeed some articles talked about different ways to do audio recording in android by all kinds of APIs, like OpenSLES (this should be supported after gingerbread) orMediaRecorder which belongs to android SDK API. However nearly all of them were recording the mic input, rather than the system output. Meanwhile, I have seen many posts on android-dev asking for the same question, and it seems that there is currently no valid answer on this. So I hope my method will at least make some sense for those whoreally want to capture the system output and don’t know how, like me.

My method is not good, since you have to recompile the android tree, however this is currently the only way for me to achieve my goal. Please tell me if you know other ways to do that. So download the android source tree will be the first step here. And the main idea of the work is: since there is no API for system audio capture, we have to capture it by ourselves, in a lower level, e.g., the android framework.

The source.android.com is the best place for you if you don’t have a android source tree, andUbuntu is highly suggested as the compiling environment. After you have read that, you should have a workable android source tree. here workable means you should be able to compile the tree and launch emulator successfully with the android kernel you just compiled. To achieve that, you may have to establish the environment first (e.g. to installsun-java-6, not the one called openjdk, which may cause strange compilation errors), run some scripts to initialize macros for compilation (like source build/envsetup.sh andlunch), and finally run make -j8 under your android source root. (if you don’t use -j8, which means enable parallel compilation with eight threads, you will possibly have to wait for a really long time before the compilation is done)

1. Play some audio

Before we try to capture the system sound, we do have to find some audio to play, so that we can know we have captured something. This is really a easy task. Just find any mp3 file (e.g. music.mp3), put it under the android /sdcard/ dir with adb push (CAUTION here: you have to use mksdcard command to create a sdcard image, and then use -sdcard option when launching the emulator. By default, the emulator will have no sdcard mounted).

Then, use the Media Scanner of dev tools in the android system to activate the scan process of audio files. After that, in the application called Music there should be a mp3 file ready for you to play. By playing the song, You should be able to hear the sound on your host, although it is actually played on the emulator.

2. Do the system audio capture

Comes to the main part of this article. first of all let’s see the android audio system in the graph.

Android Audio System

I am not a expert on android system, but we can see here that the lowest level of audio system goes to /dev/eac device file, and there is an AudioHardwareInterface, which is possibly hardware related, to access this file directly. And here AudioFlinger seems to be the best part for us to hack, since it is not depending on hardware, and it should has the final mixer output, which is what we want (we don’t want any single sound track, we need the overall system output, isn’t it?). Actually, here AudioFlinger did not only the mixer work, and also resampling stuff.

AudioFlinger is implemented under dir frameworks/base/services/audioflinger/ (Here I assume that we are currently under the root of android source tree). What we are going to do is to find the mixer output. In the file AudioFlinger.cpp, we can seeAudioFlinger::MixerThread::threadLoop(), which is the working thread of the mixer, and this MixerThread is inherited from AudioFlinger::BaseThread. Then, just search the keyword mOutput->write with your best editor (vim, emacs, gedit, whatever), and we will find something like this under the threadLoop() function:

...
mLastWriteTime = systemTime();
mInWrite = true;
mBytesWritten += mixBufferSize;
int bytesWritten = (int)mOutput->write(mMixBuffer, mixBufferSize);
if (bytesWritten < 0) mBytesWritten -= mixBufferSize;
mNumWrites++;
mInWrite = false;
...

That is the very point that mixer output buffer is transferred to hardware related codes I think, and the audio clip is in mMixbuffer, with size mixBufferSize. In this buffer, there are PCM raw audio data with 44100Hz sampling rate, 2 channels and 16 bits little endian as its param.

If you write this buffer out to a file, like /data/wav.raw, you can just use adb pull to retrieve the data file to your host machine and play it with aplay:

$ aplay -t raw -c 2 -f S16_LE -r 44100 wav.raw

Didn’t you heard the sound? That’s it.