From bcc9f5fc3b08c2eb932d75b21b546e60527c7499 Mon Sep 17 00:00:00 2001 From: Vladimir Chtchetkine Date: Fri, 23 Sep 2011 12:54:17 -0700 Subject: Merge from 5f8faae on master. Do not merge. Check that first two cameras are facing in opposite direction. Currently camera app will crash on an attempt to switch cameras if camera 0 and 1 are facing in the same direction. So, user should be warned about that on emulator start. Change-Id: I6211093296806cb03be02e543e21154508693eab --- android/avd/hardware-properties.ini | 4 +++- android/camera/camera-service.c | 41 ++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/android/avd/hardware-properties.ini b/android/avd/hardware-properties.ini index fb53536..8fb51b4 100644 --- a/android/avd/hardware-properties.ini +++ b/android/avd/hardware-properties.ini @@ -305,10 +305,12 @@ abstract = 1-st emulated web camera direction description = Direction of the 1-st emulated web camera # Defines direction of the emulated webcam with index 1 +# Note that first two cameras must face in opposite directions in order to enable +# camera switch in the camera application. # name = hw.webcam.1.direction type = string -default = front +default = back abstract = 2-nd emulated web camera direction description = Direction of the 2-nd emulated web camera diff --git a/android/camera/camera-service.c b/android/camera/camera-service.c index 088039f..e40035f 100644 --- a/android/camera/camera-service.c +++ b/android/camera/camera-service.c @@ -445,8 +445,11 @@ _camera_service_init(CameraServiceDesc* csd) } /* For each webcam declared in hw.ini find an actual camera information - * descriptor, and save it into the service descriptor for the emulation. */ - for (i = 0; i < android_hw->hw_webcam_count; i++) { + * descriptor, and save it into the service descriptor for the emulation. + * Stop the loop when all the connected cameras have been added to the + * service. */ + for (i = 0; i < android_hw->hw_webcam_count && + csd->camera_count < connected_cnt; i++) { const char* disp_name; const char* dir; CameraInfo* found; @@ -498,10 +501,33 @@ _camera_service_init(CameraServiceDesc* csd) memset(found, 0, sizeof(CameraInfo)); } else { W("Camera name '%s' is not found in the list of connected cameras.\n" - "Use -webcam-list emulator option to obtain the list of connected camera names", + "Use '-webcam list' emulator option to obtain the list of connected camera names.\n", disp_name); } } + + /* Make sure that camera 0 and camera 1 are facing in opposite directions. + * If they don't the camera application will crash on an attempt to switch + * cameras. */ + if (csd->camera_count > 0) { + const char* cam2_dir = NULL; + const char* cam2_name = NULL; + if (csd->camera_count >= 2) { + cam2_dir = csd->camera_info[1].direction; + cam2_name = csd->camera_info[1].display_name; + } else if (strcmp(android_hw->hw_fakeCamera, "off")) { + cam2_dir = android_hw->hw_fakeCamera; + cam2_name = "fake camera"; + } + if (cam2_dir != NULL && !strcmp(csd->camera_info[0].direction, cam2_dir)) { + W("Cameras '%s' and '%s' are both facing %s.\n" + "It is required by the camera application that first two emulated cameras\n" + "are facing in opposite directions. If they both are facing in the same direction,\n" + "the camera application will crash on an attempt to switch the camera.\n", + csd->camera_info[0].display_name, cam2_name, cam2_dir); + + } + } } /* Gets camera information for the given camera device name. @@ -752,10 +778,6 @@ struct CameraClient * Note that memory allocated for this buffer * also contains preview framebuffer. */ uint8_t* video_frame; - /* Point to Cb pane inside the video frame buffer. */ - uint8_t* video_frame_Cb; - /* Point to Cr pane inside the video frame buffer. */ - uint8_t* video_frame_Cr; /* Preview frame buffer. * This address points inside the 'video_frame' buffer. */ uint16_t* preview_frame; @@ -1090,11 +1112,6 @@ _camera_client_query_start(CameraClient* cc, QemudClient* qc, const char* param) /* Set framebuffer pointers. */ cc->preview_frame = (uint16_t*)(cc->video_frame + cc->video_frame_size); - /* TODO: Get rid if this! It assumes that client's framebuffer is YV12. Let - * the camera do the conversion. All we need is to ensure that framebuffers - * allocated here are large enough! */ - cc->video_frame_Cb = cc->video_frame + cc->pixel_num; - cc->video_frame_Cr = cc->video_frame_Cb + cc->pixel_num / 4; /* Start the camera. */ if (camera_device_start_capturing(cc->camera, cc->camera_info->pixel_format, -- cgit v1.1