Tuesday, February 26, 2008

sizeof(struct v4l2_requestbuffers) different in kernel and in user compiled program

$ANDROID_M5_KERNEL/kernel/include/linux/videodev2.h:560
struct v4l2_requestbuffers
{
__u32 count;
enum v4l2_buf_type type;
enum v4l2_memory memory;
__u32 reserved[2];
};
The sizeof(struct v4l2_requestbuffers) is 16 bytes running in kernel, while 20 bytes running in user compiled native program. I checked the structure size in detail and found that the sizeof(enum v4l2_buf_type) and sizeof(enum v4l2_memory) are both 1. The actual size of this structure is 4 + 1 + 1 + 8 = 14 bytes. The two continuous enum occupy 4 bytes for DWORD alignment.

In user compiled native program, the sizeof(enum) is 4. Total sizeof(struct) is 20 bytes. Only the size will not cause big problems. But the variable VIDIOC_REQBUFS will be affected by the size of the structure. See following _IOWR definition.
#define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),(_IOC_TYPECHECK(size)))
That causes the VIDIOC_REQBUFS can't be matched in the kernel code.

To fix the problem, change the structure to the following:
struct v4l2_requestbuffers
{
__u32 count;
enum v4l2_buf_type type;
__u32 reserved[2];
enum v4l2_memory memory;
};
For DWORD alignment, both enum will occupy 4 bytes although each one is 1 byte long in kernel.

Thursday, February 21, 2008

More android apps in android m5 sdk

We can see more google android applications in the latest google android sdk (m5-rc14). Following is the applications:
# Prepping: /system/app/AlarmClock.apk:/system/app/AlarmProvider.apk:/system/app/Anagrams.apk:/system/app/ApiDemos.apk:/system/app/Bounce.apk:/system/app/Browser.apk:/system/app/Calculator.apk:/system/app/Calendar.apk:/system/app/CalendarProvider.apk:/system/app/Camera.apk:/system/app/Contacts.apk:/system/app/DataSets.apk:/system/app/Development.apk:/system/app/Drm.apk:/system/app/Fallback.apk:/system/app/GDataFeedsProvider.apk:/system/app/GTalkDiagnostics.apk:/system/app/GTalkSettings.apk:/system/app/GlobalTime.apk:/system/app/Gmail.apk:/system/app/GmailProvider.apk:/system/app/GoogleApps.apk:/system/app/GoogleAppsProvider.apk:/system/app/Home.apk:/system/app/IM.apk:/system/app/ImProvider.apk:/system/app/LocalePicker.apk:/system/app/Maps.apk:/system/app/MasfProxyService.apk:/system/app/MediaProvider.apk:/system/app/Mms.apk:/system/app/Music.apk:/system/app/NotePad.apk:/system/app/PackageInstaller.apk:/system/app/Phone.apk:/system/app/Settings.apk:/system/app/SettingsProvider.apk:/system/app/SetupWizard.apk:/system/app/Snake.apk:/system/app/Street.apk:/system/app/Sync.apk:/system/app/SyncProvider.apk:/system/app/Talk.apk:/system/app/TelephonyProvider.apk:/system/app/Term.apk:/system/app/ToDoList.apk:/system/app/Updater.apk:/system/app/Vending.apk:/system/app/VoiceDialer.apk:/system/app/Voicemail.apk:/system/app/YouTube.apk:/system/app/gtalkservice.apk
File not found: /system/app/AlarmClock.apk
File not found: /system/app/AlarmProvider.apk
File not found: /system/app/Anagrams.apk
File not found: /system/app/ApiDemos.apk
File not found: /system/app/Bounce.apk
File not found: /system/app/Calculator.apk
File not found: /system/app/Calendar.apk
File not found: /system/app/CalendarProvider.apk
File not found: /system/app/Camera.apk
File not found: /system/app/DataSets.apk
File not found: /system/app/Drm.apk
File not found: /system/app/GDataFeedsProvider.apk
File not found: /system/app/GTalkDiagnostics.apk
File not found: /system/app/GlobalTime.apk
File not found: /system/app/Gmail.apk
File not found: /system/app/GmailProvider.apk
File not found: /system/app/IM.apk
File not found: /system/app/LocalePicker.apk
File not found: /system/app/Mms.apk
File not found: /system/app/Music.apk
File not found: /system/app/NotePad.apk
File not found: /system/app/PackageInstaller.apk
File not found: /system/app/Settings.apk
File not found: /system/app/SetupWizard.apk
File not found: /system/app/Snake.apk
File not found: /system/app/Street.apk
File not found: /system/app/Sync.apk
File not found: /system/app/SyncProvider.apk
File not found: /system/app/Talk.apk
File not found: /system/app/Term.apk
File not found: /system/app/ToDoList.apk
File not found: /system/app/Updater.apk
File not found: /system/app/Vending.apk
File not found: /system/app/VoiceDialer.apk
File not found: /system/app/Voicemail.apk
File not found: /system/app/YouTube.apk
Prep complete.
Interesting that there are streat.apk, I guess it may be google streat view application.

Check on "Allow old ABI binaries ..." got Illegal instruction

With the google android kernel source, after "make goldfish_defconfig", check on "Kernel Features" -> "Allow old ABI binaries to run with this kernel", I got following simple native program failed with "Illegal instruction". The test native program source is in the following:
#include
#include
#include
#include
#include

void _sig_handler(int signo)
{
printf("Got it: %d, %x, \n", signo, &signo);
}

int
main(int argc, char * argv[])
{
struct sigaction sa;

memset(&sa, 0x0, sizeof(sa));
sa.sa_flags = SA_RESTART;
sa.sa_handler = _sig_handler;
if (sigaction(SIGALRM, &sa, NULL) < 0) {
perror("sigaction");
return -1;
}

alarm(1);
sleep(2);
printf("Sleep ... done\n");
return 0;
}
Follow the article Initialize libc for Android to create a dynamic linked android native program, and upload it to emulator. This native program will end with "Illegal instruction".

ABI is abbreviated of Application Binary Interface, but I dont know why it will have such problems when check on Old ABI binaries. So dont use it before you know you have to and how to.

Tips:
1. after create a new kernel file, e.g. zImage, use -kernel zImage to use it in android emulator.

Friday, February 1, 2008

Google Android is using ALSA as audio

The Google Android Emulator is using /dev/eac as the audio device. The /dev/eac is the Android QEMU audio driver. The ioctl interface is empty. There is a comment line giving the hints that Google Android is going to use ALSA as audio.
static int goldfish_audio_ioctl(struct inode* ip, struct file* fp, unsigned int cmd, unsigned long arg)
{
/* temporary workaround, until we switch to the ALSA API */
if (cmd == 315)
return -1;
else
return 0;
}
ALSA Introduction:
The Advanced Linux Sound Architecture (ALSA) provides audio and MIDI functionality to the Linux operating system. Here is the Advanced Linux Sound Architecture (ALSA) project homepage. ALSA has the following significant features:
  • Efficient support for all types of audio interfaces, from consumer sound cards to professional multichannel audio interfaces.
  • Fully modularized sound drivers.
  • SMP and thread-safe design.
  • User space library (alsa-lib) to simplify application programming and provide higher level functionality.
  • Support for the older Open Sound System (OSS) API, providing binary compatibility for most OSS programs.