Issuu on Google+

2009 제3회 Korea Android 세미나

Android HAL – Case Study

2009. 3. 27.

MtekVision: Kwangwoo Lee (kwangwoo.lee at gmail dot com)


목차 Input Keymaps and Keyboard Touchscreen Display Framebuffer, LCD Audio ALSA Camera HAL Overview V4L2 Interface Layer Interaction of Camera App. PDK/NDK Native Library build


Input: overview struct input_event { struct timeval time; unsigned short type; unsigned short code; unsigned int value; };

> adb shell # mount –t rootfs –o remount,rw rootfs / # cat /dev/input/event0 > /eventdump.bin … ctrl+c > adb pull /eventdump.bin .

3rd Korea Android Seminar - www.kandroid.org

3


Input: overview  Mouse #define EV_KEY EV_REL: relative change #define EV_REL  Touchscreen #define EV_ABS EV_ABS: absolute value  Keyboard/Keypad EV_KEY: release(0), press(1), autorepeat(2)  Resources • Documentation/input/input.txt • Documentation/input/input-programming.txt • Include/linux/input.h

0x01 0x02 0x03

kernel/drivers/input/evdev.c static long evdev_do_ioctl(struct file *file, unsigned int cmd, void __user *p, int compat_mode) { … if (_IOC_NR(cmd) == _IOC_NR(EVIOCGNAME(0))) return str_to_user(dev->name, _IOC_SIZE(cmd), p); … } 3rd Korea Android Seminar - www.kandroid.org

4


Input: keymaps and keyboard Window Manager /system/usr/keylayout/qwerty.kl /system/usr/keylayout/sample-kpd.kl

EventHub KeyInputQueue

I/SystemServer( 1633): Starting Window Manager. I/EventHub( 1633): New device: path=/dev/input/event1 name=TSC2007 Touchscreen id=0x10000 (of 0x1) index=1 fd=46 classes=0x4 D/SensorManager( 1633): found sensor: null, handle=0 I/EventHub( 1633): New device: path=/dev/input/event0 name=sample-kpd id=0x10001 (of 0x2) index=2 fd=47 classes=0xf I/EventHub( 1633): New keyboard: publicID=65537 device->id=65537 devname=‘sample-kpd' propName='hw.keyboards.65537.devname' keylayout='/system/usr/keylayout/qwerty.kl' I/KeyInputQueue( 1633): Device added: id=0x0, name=sample-kpd, classes=f I/KeyInputQueue( 1633): X: unknown values I/KeyInputQueue( 1633): Y: unknown values I/KeyInputQueue( 1633): Pressure: unknown values I/KeyInputQueue( 1633): Size: unknown values I/KeyInputQueue( 1633): Device added: id=0x10000, name=null, classes=4 I/KeyInputQueue( 1633): X: min=0 max=480 flat=0 fuzz=0 I/KeyInputQueue( 1633): Y: min=0 max=272 flat=0 fuzz=0 I/KeyInputQueue( 1633): Pressure: min=0 max=4095 flat=0 fuzz=0 I/KeyInputQueue( 1633): Size: unknown values

3rd Korea Android Seminar - www.kandroid.org

5


Input: keymaps and keyboard frameworks/base/libs/ui/EventHub.cpp int EventHub::open_device(const char *deviceName) { … if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask) >= 0) { device->classes |= CLASS_KEYBOARD; } if (test_bit(BTN_MOUSE, key_bitmask)) { if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask) >= 0) { if (test_bit(REL_X, rel_bitmask) && test_bit(REL_Y, rel_bitmask)) { device->classes |= CLASS_TRACKBALL; } } }

}

if (test_bit(BTN_TOUCH, key_bitmask)) { if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) >= 0) { if (test_bit(ABS_X, abs_bitmask) && test_bit(ABS_Y, abs_bitmask)) { device->classes |= CLASS_TOUCHSCREEN; } } } …

3rd Korea Android Seminar - www.kandroid.org

6


Input: keymaps and keyboard frameworks/base/libs/ui/EventHub.cpp int EventHub::open_device(const char *deviceName) { … if ((device->classes&CLASS_KEYBOARD) != 0) { ioctl(mFDs[mFDCount].fd, EVIOCGNAME(sizeof(devname)-1), devname); strcpy(tmpfn, devname); for (char *p = strchr(tmpfn, ' '); p && *p; p = strchr(tmpfn, ' ')) *p = '_'; const char* root = getenv("ANDROID_ROOT"); snprintf(keylayoutFilename, sizeof(keylayoutFilename), "%s/usr/keylayout/%s.kl", root, tmpfn); bool defaultKeymap = false;

}

} …

if (access(keylayoutFilename, R_OK)) { snprintf(keylayoutFilename, sizeof(keylayoutFilename), "%s/usr/keylayout/%s", root, "qwerty.kl"); defaultKeymap = true; } device->layoutMap->load(keylayoutFilename); …

3rd Korea Android Seminar - www.kandroid.org

7


Input: keymaps and keyboard $ cat sample-kpd.kl key key key key key key key key key key key key key key key key

42 103 28 38 108 49 30 32 46 31 50 22 34 105 106 14

BACK WAKE_DROPPED SOFT_RIGHT WAKE ENDCALL WAKE_DROPPED MENU WAKE_DROPPED SEARCH WAKE_DROPPED CALL WAKE_DROPPED DPAD_CENTER WAKE_DROPPED DPAD_DOWN WAKE_DROPPED DPAD_UP WAKE_DROPPED HOME WAKE DPAD_LEFT WAKE_DROPPED DPAD_RIGHT WAKE_DROPPED VOLUME_UP VOLUME_DOWN POWER WAKE CAMERA

 key SCANCODE KEYCODE [FLAGS...]  FLAGS • SHIFT • ALT • CAPS • WAKE • WAKE_DROPPED

 Resources • • • •

frameworks/base/services/java/com/android/server/WindowManagerService.java frameworks/base/services/java/com/android/server/KeyInputQueue.java frameworks/base/core/jni/server/com_android_server_KeyInputQueue.cpp frameworks/base/libs/ui/EventHub.cpp 3rd Korea Android Seminar - www.kandroid.org

8


Input: Touchscreen kernel/drivers/input/touchscreen/tsc2007.c static void tsc2007_send_event(void *tsc) { input_report_key(input, BTN_TOUCH, 1); // Down input_report_abs(input, ABS_X, x); input_report_abs(input, ABS_Y, y); input_report_abs(input, ABS_PRESSURE, rt); }

input_sync(input);

static enum hrtimer_restart tsc2007_timer(struct hrtimer *handle) { input_report_key(input, BTN_TOUCH, 0); // Up input_report_abs(input, ABS_PRESSURE, 0); input_sync(input); } static int tsc2007_probe(struct i2c_client *client, const struct i2c_device_id *id) { input_dev->name = "TSC2007 Touchscreen"; input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); } 3rd Korea Android Seminar - www.kandroid.org

9


Input: Touchscreen kernel/drivers/input/touchscreen/tsc2007.c static void tsc2007_send_event(void *tsc) { static int cal[7] = {8194, -39, -906232, 12, -4879, 18556954, 65536}; int tx, ty; /* 재호아빠님의 Calibration scheme 적용 */ tx = x, ty = y; x = (cal[2] + cal[0]*tx + cal[1]*ty) / cal[6]; y = (cal[5] + cal[3]*tx + cal[4]*ty) / cal[6]; if (((x >= 0) && (x < 480)) && ((y >= 0) && (y < 272))) { input_report_abs(input, ABS_X, x); input_report_abs(input, ABS_Y, y); input_report_abs(input, ABS_PRESSURE, rt);

}

}

input_sync(input);

static int tsc2007_probe(struct i2c_client *client, const struct i2c_device_id *id) { input_set_abs_params(input_dev, ABS_X, 0, 480 /* MAX_12BIT */, 0, 0); input_set_abs_params(input_dev, ABS_Y, 0, 272 /* MAX_12BIT */, 0, 0); } 3rd Korea Android Seminar - www.kandroid.org

10


Input: Wake Lock  Even if input drivers work correctly, events can be dropped. • Enable wake lock in the kernel config • workaround: return true in PowerManagerService::screenIsOn()  android-2.6.25 config  Device Drivers  Android  Android power drvier (CONFIG_ANDROID_POWER = y)  Android power driver lock stats (CONFIG_ANDROID_POWER_STAT =y)  android-2.6.27 config  Power management options  Wake lock (CONFIG_WAKELOCK = y)  Wake lock stats (CONFIG_WAKELOCK_STAT = y)  Userspace wake locks (CONFIG_USER_WAKELOCK = y)  Early suspend (CONFIG_EARLYSUSPEND = y)

3rd Korea Android Seminar - www.kandroid.org

11


Input: Wake Lock frameworks/base/services/java/com/android/server/PowerManagerService.java class PowerManagerService extends IPowerManager.Stub implements LocalPowerManager, Watchdog.Monitor { private class UnsynchronizedWakeLock { public void acquire(); public void release(); }

}

}

boolean screenIsOn() { synchronized (mLocks) { return (mPowerState & SCREEN_ON_BIT) != 0; }

 Resources

• frameworks/base/services/java/com/android/server/PowerManagerService.java • frameworks/base/services/java/com/android/server/WindowManagerService.java • frameworks/base/services/java/com/android/server/KeyInputQueue.java

3rd Korea Android Seminar - www.kandroid.org

12


Input: event ď&#x192;&#x2DC; Window Manager Service waits event and dispatch each event frameworks/base/services/java/com/android/server/WindowManagerService.java public class WindowManagerService extends IWindowManager.Stub implements Watchdog.Monitor { PowerManagerService mPowerManager; private final class InputDispatcherThread extends Thread { while (true) { QueuedEvent ev = mQueue.getEvent( (int)((!configChanged && curTime < nextKeyTime) ? (nextKeyTime-curTime) : 0));

}

}

}

dispatchKey((KeyEvent)ev.event, 0, 0); dispatchPointer(ev, (MotionEvent)ev.event, 0, 0); dispatchTrackball(ev, (MotionEvent)ev.event, 0, 0)

3rd Korea Android Seminar - www.kandroid.org

13


Input: event  Check power status  Add event and acquire wake lock frameworks/base/services/java/com/android/server/KeyInputQueue.java public abstract class KeyInputQueue { Thread mThread = new Thread("InputDeviceReader") { … send = preprocessEvent(di, ev); if (!send) { continue; }

}

}

addLocked(di, curTime, ev.flags, RawInputEvent.CLASS_KEYBOARD, newKeyEvent(di, di.mDownTime, curTime, down, keycode, 0, scancode, ((ev.flags & WindowManagerPolicy.FLAG_WOKE_HERE) != 0) ? KeyEvent.FLAG_WOKE_HERE : 0)); addLocked(di, curTime, ev.flags, RawInputEvent.CLASS_TOUCHSCREEN, me); addLocked(di, curTime, ev.flags, RawInputEvent.CLASS_TRACKBALL, me);

3rd Korea Android Seminar - www.kandroid.org

14


Input: event ď&#x192;&#x2DC; Check mPowerState frameworks/base/services/java/com/android/server/WindowManagerService.java public class WindowManagerService extends IWindowManager.Stub implements Watchdog.Monitor { private class KeyQ extends KeyInputQueue implements KeyInputQueue.FilterCallback { @Override boolean preprocessEvent(InputDevice device, RawInputEvent event) { switch (event.type) { case RawInputEvent.EV_KEY: { boolean screenIsOff = !mPowerManager.screenIsOn(); boolean screenIsDim = !mPowerManager.screenIsBright(); return true/flase; } case RawInputEvent.EV_REL: { return true/flase; } case RawInputEvent.EV_ABS: { boolean screenIsOff = !mPowerManager.screenIsOn(); boolean screenIsDim = !mPowerManager.screenIsBright(); return true/false; } } } 3rd Korea Android Seminar - www.kandroid.org

15


Display: Framebuffer, LCD  Device node • /dev/fb0 or /dev/graphics/fb0  ioctl • FBIOGET_FSCREENINFO • FBIOGET_VSCREENINFO • FBIOPUT_VSCREENINFO  Create a virtual display twice the size of the physical screen.  RGB565  Page flipping  fb_pan_display • flip buffer • activated by ioctl(FBIOPUT_VSCREENINFO) fb->fb.fix.ypanstep = 1; fb->fb.var.xres = width; fb->fb.var.yres = height; fb->fb.var.xres_virtual = width; fb->fb.var.yres_virtual = height * ANDROID_NUMBER_OF_BUFFERS; framesize = width * height * ANDROID_BYTES_PER_PIXEL * ANDROID_NUMBER_OF_BUFFERS; fb->fb.fix.smem_len = framesize; 3rd Korea Android Seminar - www.kandroid.org

16


Audio: ALSA • • • •

3rd Korea Android Seminar - www.kandroid.org

ALSA Proprietary Library /dev/audio libaudio.so

17


Audio: ALSA

3rd Korea Android Seminar - www.kandroid.org

18


Audio: ALSA  Reference introduced by invain http://labs.embinux.org/index.php/Android_Porting_Guide_to_Beagle_Board 1. cd ~ 2. Clone alsa-lib $ git clone git://android.git.kernel.org/platform/external/alsa-lib.git 3. Clone ALSA based libaudio $ git clone git://android.git.kernel.org/platform/hardware/alsa_sound.git 4. Change directory to the root "android_build" $ cd ~/android_build 5. Add ALSA audio support and comment out generic audio support $ vim ~/android_build/build/target/board/generic/BoardConfig.mk #BOARD_USES_GENERIC_AUDIO := true BOARD_USES_ALSA_AUDIO := true 6. Copy ALSA support supporting code from steps 2 and 3 above $ cd ~/android_build $ cp –a ~/alsa-lib external $ cp –a ~/alsa_sound hardware 7. Compile $ make –j2

3rd Korea Android Seminar - www.kandroid.org

19


Audio: ALSA  Souces frameworks/base/libs/audioflinger/*

 Config files /system/usr/share/alsa/alsa.conf /system/usr/share/alsa/pcm/dsnoop.conf /system/usr/share/alsa/pcm/modem.conf /system/usr/share/alsa/pcm/dpl.conf /system/usr/share/alsa/pcm/default.conf /system/usr/share/alsa/pcm/surround51.conf /system/usr/share/alsa/pcm/surround41.conf /system/usr/share/alsa/pcm/surround50.conf /system/usr/share/alsa/pcm/dmix.conf /system/usr/share/alsa/pcm/center_lfe.conf /system/usr/share/alsa/pcm/surround40.conf /system/usr/share/alsa/pcm/side.conf /system/usr/share/alsa/pcm/iec958.conf /system/usr/share/alsa/pcm/rear.conf /system/usr/share/alsa/pcm/surround71.conf /system/usr/share/alsa/pcm/front.conf /system/usr/share/alsa/cards/aliases.conf

 Compiled binaries /system/lib/libaudio.so /system/lib/libaudioflinger.so /system/lib/libsystem_server.so /system/lib/libandroid_servers.so /system/bin/mediaserver /system/bin/system_server 3rd Korea Android Seminar - www.kandroid.org

20


Camera: HAL Overview • • • •

3rd Korea Android Seminar - www.kandroid.org

V4L2 Proprietary Library /dev/video0 libcamera.so

21


Camera: HAL Overview

3rd Korea Android Seminar - www.kandroid.org

22


Camera: HAL Overview  Reference files ./frameworks/base/camera/libcameraservice/FakeCamera.h ./frameworks/base/camera/libcameraservice/FakeCamera.cpp ./frameworks/base/camera/libcameraservice/CameraHardwareStub.h ./frameworks/base/camera/libcameraservice/CameraHardwareStub.cpp ./frameworks/base/camera/libcameraservice/CameraService.h ./frameworks/base/camera/libcameraservice/CameraService.cpp ./frameworks/base/camera/libcameraservice/CannedJpeg.h ./frameworks/base/include/ui/CameraHardwareInterface.h ./frameworks/base/core/jni/android_hardware_Camera.cpp ./frameworks/base/core/java/android/hardware/Camera.java  Compiled binaries • /system/bin mediaserver system_server • /system/lib libandroid_servers.so libcameraservice.so libsystem_server.so 3rd Korea Android Seminar - www.kandroid.org

23


Camera: CameraHardwareStub void CameraHardwareStub::initDefaultParameters() - p.setPreviewSize(176, 144); - p.setPreviewFrameRate(15); - p.setPreviewFormat("yuv422sp"); + p.setPreviewSize(272, 480); + p.setPreviewFrameRate(30); + p.setPreviewFormat("rgb565"); +

p.setPictureSize(kCannedJpegWidth, kCannedJpegHeight); p.setPictureSize(640, 480);

int CameraHardwareStub::previewThread() fakeCamera->getNextFrameAsYuv422(frame); + realCamera->getNextFrameAsRgb565(frame); + +

RealCamera* realCamera = mRealCamera; realCamera->startPreview();

void CameraHardwareStub::stopPreview() + RealCamera* realCamera = mRealCamera; + realCamera->stopPreview(); 3rd Korea Android Seminar - www.kandroid.org

24


Camera: CameraHardwareStub int CameraHardwareStub::pictureThread() + RealCamera* cam = mRealCamera; +

FakeCamera cam(w, h); cam.getNextFrameAsYuv422((uint8_t *)heap->base()); cam->getNextFrameAsRgb565((uint8_t *)heap->base());

+ + + + + + +

sp<MemoryHeapBase> heap = new MemoryHeapBase(kCannedJpegSize); sp<MemoryBase> mem = new MemoryBase(heap, 0, kCannedJpegSize); memcpy(heap->base(), kCannedJpeg, kCannedJpegSize); int length; int w, h; mParameters.getPictureSize(&w, &h); sp<MemoryHeapBase> heap = new MemoryHeapBase(w * 2 * h); sp<MemoryBase> mem = new MemoryBase(heap, 0, w * 2 * h); length = cam->takePicture((uint8_t *)heap->base());

3rd Korea Android Seminar - www.kandroid.org

25


Camera: CameraHardwareStub status_t CameraHardwareStub::setParameters(const CameraParameters& params) - if (strcmp(params.getPreviewFormat(), "yuv422sp") != 0) { LOGE("Only yuv422sp preview is supported"); return -1; - } -

if (w != kCannedJpegWidth && h != kCannedJpegHeight) { LOGE("Still picture size must be size of canned JPEG (%dx%d)", kCannedJpegWidth, kCannedJpegHeight); return -1; }

status_t CameraService::Client::startPreview() mSurface->registerBuffers(w, h, w, h, PIXEL_FORMAT_YCbCr_420_SP, + mSurface->registerBuffers(w, h, w, h, PIXEL_FORMAT_RGB_565, void CameraService::Client::yuvPictureCallback() PIXEL_FORMAT_YCbCr_420_SP, heap); + PIXEL_FORMAT_RGB_565, heap);

3rd Korea Android Seminar - www.kandroid.org

26


Camera: V4L2 Interface  Documentation/video4linux/API.html http://www.linuxtv.org/downloads/video4linux/API/V4L2_API/ video capture example: capture.c Structures static struct file_operations; static struct video_device;  Functions video_register_device(,VFL_TYPE_GRABBER,); video_device_release();  ioctl VIDIOC_DQBUF VIDIOC_QBUF VIDIOC_STREAMON VIDIOC_STREAMOFF CUSTOM FIELD  init.rc On boot chmod 666 /dev/video0

3rd Korea Android Seminar - www.kandroid.org

27


Camera: V4L2 Interface RealCamera::RealCamera(int width, int height) : mFd(-1), mIO(IO_METHOD_MMAP) { setSize(width, height); mFd = open_device(); init_device(mFd, mIO); LOGD ("ctor: mFd (%d), mIO (%s)\n", mFd, (mIO == IO_METHOD_MMAP)? "MMAP" : "OTHER"); } RealCamera::~RealCamera() { LOGD ("dtor: mFd (%d), mIO (%s)\n", mFd, (mIO == IO_METHOD_MMAP)? "MMAP" : "OTHER"); uninit_device(mIO); close_device(mFd); } int RealCamera::startPreview(void) { LOGD ("startPreview: mFd (%d), mIO (%s)\n", mFd, (mIO == IO_METHOD_MMAP)? "MMAP" : "OTHER"); start_capturing(mFd, mIO); } int RealCamera::stopPreview(void) { LOGD ("stopPreview: mFd (%d), mIO (%s)\n", mFd, (mIO == IO_METHOD_MMAP)? "MMAP" : "OTHER"); stop_capturing(mFd, mIO); }

3rd Korea Android Seminar - www.kandroid.org

28


Camera: V4L2 Interface int RealCamera::takePicture(uint8_t *buffer) { struct mv_jpeg_info jpeg_info; int result; jpeg_info.size.width = 640; jpeg_info.size.height = 480; if (-1 == xioctl (mFd, MVIOC_STILLJCAPT, &jpeg_info)){ LOGE("takePicture: ioctl error!!!\n"); return -1; } LOGD ("takePicture: dest 0x%08x length %d\n", buffer, jpeg_info.length);

}

result = read(mFd, buffer, jpeg_info.length); if (result != jpeg_info.length) { LOGE("takePicture: read error!!!\n"); return -1; } return result;

void RealCamera::getNextFrameAsRgb565(uint8_t *buffer) { int frameSize = mWidth * mHeight * 2;

}

read_frame(mFd, mIO, (uint8_t *) buffer, frameSize); mCounter++;

3rd Korea Android Seminar - www.kandroid.org

29


Camera: V4L2 Interface static void stop_capturing(int fd, io_method io) { type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (-1 == xioctl (fd, VIDIOC_STREAMOFF, &type)) { LOGE ("VIDIOC_STREAMOFF\n"); } } static void start_capturing(int fd, io_method io) { switch (io) { … case IO_METHOD_MMAP: for (i = 0; i < n_buffers; ++i) { struct v4l2_buffer buf; CLEAR (buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; buf.index = i; if (-1 == xioctl (fd, VIDIOC_QBUF, &buf)) LOGE ("VIDIOC_QBUF\n");

}

}

} type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if (-1 == xioctl (fd, VIDIOC_STREAMON, &type)) LOGE ("VIDIOC_STREAMON\n"); break;

3rd Korea Android Seminar - www.kandroid.org

30


Camera: V4L2 Interface static int read_frame(int fd, io_method io, uint8_t *dest, int frame_size) { switch (io) { … case IO_METHOD_MMAP: CLEAR (buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; if (-1 == xioctl (fd, VIDIOC_DQBUF, &buf)) { switch (errno) { } } assert (buf.index < n_buffers); //LOGD ("read_frame: 0x%08x, 0x%08x, %d\n", buffers[buf.index].start, dest, frame_size); process_image (buffers[buf.index].start, dest, frame_size); if (-1 == xioctl (fd, VIDIOC_QBUF, &buf)) { LOGE ("VIDIOC_QBUF\n"); return -1; } break;

}

… } … return 1;

3rd Korea Android Seminar - www.kandroid.org

31


Camera: Layer Interaction of Camera App.

3rd Korea Android Seminar - www.kandroid.org

32


Camera: Layer Interaction of Camera App.

3rd Korea Android Seminar - www.kandroid.org

33


Camera: Layer Interaction of Camera App. ď&#x192;&#x2DC; Log messages by logcat I/ActivityManager( 1632): Starting activity: Intent { action=android.intent.action.MAIN categories={android.intent.category.LAUNCHER} flags=0x10200000 comp={com.android.camera/com.android.camera.Camera} } I/ActivityManager( 1632): Start proc com.android.camera for activity com.android.camera/.Camera: pid=1834 uid=10012 gids={1006, 2001, 3003} I/NotificationService( 1632): enqueueToast pkg=com.android.camera callback=android.app.ITransientNotification$Stub$Proxy@437802e0 duration=5000 D/CameraService( 1601): Connect E from ICameraClient 0x15250 D/CameraService( 1601): Client E constructor D/CameraHardwareV4L: buffer_memory: dma=005c0000 cpu=feff0000 size=00040000 Stub( 1601): initHeapLocked: preview size=272x480 V4L: buffer_memory: dma=00780000 cpu=ff030000 size=00040000 D/RealCamera( 1601): ctor: mFd (11), mIO (MMAP) D/CameraService( 1601): Client X constructor D/CameraService( 1601): Connect X D/CameraService( 1601): setPreviewDisplay(0xa8b8) D/CameraService( 1601): getParameters E/Camera ( 1834): _getParameters: picture-format=jpeg;picture-size=272x480;preview-format=rgb565;preview-frame-rate=30;previewsize=272x480 E/Camera ( 1834): setParameters() D/CameraService( 1601): setParameters(picture-size=272x480;preview-frame-rate=30;preview-size=272x480;picture-format=jpeg;previewformat=rgb565) D/CameraHardwareStub( 1601): initHeapLocked: preview size=272x480 D/CameraService( 1601): startPreview() D/CameraService( 1601): Don't use Overlays D/RealCamera( 1601): startPreview: mFd (11), mIO (MMAP) D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 0 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 1 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 2 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 3 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 0 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 1 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 2 3rd Korea Android Seminar - www.kandroid.org

34


Camera: Layer Interaction of Camera App. ď&#x192;&#x2DC; Log messages by logcat D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 0 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 1 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 2 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 3 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 0 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 1 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 2 D/CameraService( 1601): takePicture D/RealCamera( 1601): stopPreview: mFd (12), mIO (MMAP) D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 3 D/CameraService( 1601): postRaw D/RealCamera( 1601): takePicture: dest 0x40bc8000 length 22400 D/CameraService( 1601): postJpeg I/VideoPreview( 1834): ar 0.56666666 setting size: 272x480 W/AudioFlinger( 1601): write blocked for 132 msecs D/dalvikvm( 1834): Trying to load lib /system/lib/libexif.so 0x436b6238 D/dalvikvm( 1834): Added shared lib /system/lib/libexif.so 0x436b6238 D/CameraService( 1601): setPreviewDisplay(0x15808) D/CameraService( 1601): getParameters E/Camera ( 1834): _getParameters: jpeg-quality=85;picture-format=jpeg;picture-size=272x480;preview-format=rgb565;preview-frame-ra te=30;preview-size=272x480;rotation=90 E/Camera ( 1834): setParameters() D/CameraService( 1601): setParameters(picture-size=272x480;preview-frame-rate=30;preview-size=272x480;picture-format=jpeg;jpeg-qua lity=85;preview-format=rgb565;rotation=90) D/CameraHardwareStub( 1601): initHeapLocked: preview size=272x480 D/CameraService( 1601): startPreview()ioctl_qbuf error buf->state D/CameraService( 1601): Don't use Overlays D/RealCamera( 1601): startPreview: mFd (12), mIO (MMAP) D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 0 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 1 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 3 3rd Korea Android Seminar - www.kandroid.org

35


Camera: Layer Interaction of Camera App. ď&#x192;&#x2DC; Log messages by logcat D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 0 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 1 D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 2 D/CameraService( 1601): stopPreview() D/RealCamera( 1601): stopPreview: mFd (11), mIO (MMAP) D/CameraHardwareStub( 1601): previewThread: generated frame to buffer 3 D/CameraService( 1601): stopPreview(), hardware stopped OK D/CameraService( 1601): Client E disconnect D/RealCamera( 1601): stopPreview: mFd (11), mIO (MMAP) D/RealCamera( 1601): dtor: mFd (11), mIO (MMAP) D/CameraService( 1601): Client X disconnect D/CameraService( 1601): Client E destructor D/CameraService( 1601): Client E disconnect D/CameraService( 1601): Client X disconnect D/CameraService( 1601): Client X destructor W/ActivityManager( 1632): Activity pause timeout for HistoryRecord{4380f5e8 {com.android.camera/com.android.camera.Camera}} D/LocationManager( 1834): removeUpdates: listener = com.android.camera.Camera$LocationListener@436c6a98 D/LocationManager( 1834): removeUpdates: listener = com.android.camera.Camera$LocationListener@436c6c50 I/WindowManager( 1632): Input configuration changed: { scale=1.0 imsi=0/0 locale=en_US touch=3 key=2/1/2 nav=3 orien=2 } V/ActivityThread( 1678): Resuming ActivityRecord{436b7bb8 token=android.os.BinderProxy@436b7648 {com.android.launcher/com.android. launcher.Launcher}} with isForward=false

3rd Korea Android Seminar - www.kandroid.org

36


Camera: Layer Interaction of Camera App.

3rd Korea Android Seminar - www.kandroid.org

37


Camera: Layer Interaction of Camera App.

3rd Korea Android Seminar - www.kandroid.org

38


Camera: Layer Interaction of Camera App.

3rd Korea Android Seminar - www.kandroid.org

39


PDK/NDK: Native Library Build     

Build full source and kernel (git branch –r and make local branch) Build PDK target: pdk_all, ndk, pdk_docs(required doxygen) Unpack NDK Set environment variables Build Native Library, Application, and JNI example.

$ mkdir dist $ make –j2 pdk pdk_all dist DIST_DIR=dist 2>&1 | tee pdk_build.log $ cd dist $ ls dist android_ndk-generic-eng.kwlee.20090323.141557-jni-src.tar.gz android_ndk-generic-eng.kwlee.20090323.141557-src.tar.gz android_ndk-generic-eng.kwlee.20090323.141557.tar.gz android_pdk_docs--eng.kwlee.20090323.141557.tar.gz $ tar –xvzf *.tar.gz $ ls docs/ ndk/ 3rd Korea Android Seminar - www.kandroid.org

40


PDK/NDK: Native Library Build  Native library: PREBUILT, NDK_BASE  JNI: PREBUILT, NDK_BASE, ANDROID_SDK_BASE(tools/apkbuilder)  Read documents in docs/. Link is not broken.  Read README in ndk/samples/sample/ and ndk/samples/samplejni/ $ export PREBUILT=~/android_0316/prebuilt/linux-x86/ $ export NDK_BASE=~/android_0316/dist/ndk/ $ cd $NDK_BASE/samples/sample/ $ make clean && make $ make -f Makefile.lib clean && make –f Makefile.lib … >adb remount >adb push hello system/app … hello, hello_cpp, libhello-shared.so, use_hellolibrary-so, use_hellolibrary-a 3rd Korea Android Seminar - www.kandroid.org

41


kandroid_3rd_seminar_20090327_session_5_HAL_Case_Study