Lines Matching full:camera
18 * Contains emulated camera service implementation.
27 #include "android/camera/camera-capture.h"
28 #include "android/camera/camera-format-converters.h"
29 #include "android/camera/camera-service.h"
33 #define D(...) VERBOSE_PRINT(camera,__VA_ARGS__)
34 #define D_ACTIVE VERBOSE_CHECK(camera)
40 #define T(...) VERBOSE_PRINT(camera,__VA_ARGS__)
45 /* Defines name of the camera service. */
46 #define SERVICE_NAME "camera"
51 /* Camera sevice descriptor. */
54 /* Information about camera devices connected to the host.
58 /* Number of camera devices connected to the host. */
62 /* One and only one camera service. */
93 * All parameters that are passed to the camera service are formatted as such:
231 * query - Query string. Query string in the camera service are formatted as such:
318 /* Represents camera information as a string formatted as follows:
321 * ci - Camera information descriptor to convert into a string.
322 * str - Pointer to the string buffer where to save the converted camera
378 /* Stringified camera properties should end with EOL. */
382 /* Gets camera information matching a display name.
385 * arr - Array of camera informations.
388 * Matching camera information, or NULL if matching camera information for the
403 /* Gets camera information matching a device name.
406 * arr - Array of camera informations.
409 * Matching camera information, or NULL if matching camera information for the
428 /* Initializes camera service descriptor.
437 /* Enumerate camera devices connected to the host. */
447 /* For each webcam declared in hw.ini find an actual camera information
486 /* Save to the camera info array that will be used by the service.
495 D("Camera %d '%s' connected to '%s' facing %s using %.4s pixel format",
503 W("Camera name '%s' is not found in the list of connected cameras.\n"
504 "Use '-webcam list' emulator option to obtain the list of connected camera names.\n",
509 /* Make sure that camera 0 and camera 1 are facing in opposite directions.
510 * If they don't the camera application will crash on an attempt to switch
520 cam2_name = "fake camera";
524 "It is required by the camera application that first two emulated cameras\n"
526 "the camera application will crash on an attempt to switch the camera.\n",
533 /* Gets camera information for the given camera device name.
535 * cs - Initialized camera service descriptor.
536 * device_name - Camera's device name to look up the information for.
538 * Camera information pointer on success, or NULL if no camera information has
550 * Helpers for handling camera client queries
569 * Prefixes for replies to camera client queries.
582 * All replies to a query in camera service have a prefix indicating whether the
656 * Camera Factory API
660 * Response to this query is a string that represents each connected camera in
662 * Strings, representing each camera are separated with EOL symbol.
682 /* "Stringify" each camera information into the reply string. */
702 /* Handles a message received from the emulated camera factory client.
706 * opaque - Camera service descriptor.
707 * msg, msglen - Message received from the camera factory client.
708 * client - Camera factory client pipe.
717 * Emulated camera factory client queries.
735 D("%s Camera factory query '%s'", __FUNCTION__, query_name);
742 E("%s: Unknown camera factory query name in '%s'",
748 /* Emulated camera factory client has been disconnected from the service. */
753 * the "root" camera service, that doesn't require anything more, than camera
758 * Camera client API
761 /* Describes an emulated camera client.
767 * On Linux this is the name of the camera device.
771 /* Input channel to use to connect to the camera. */
773 /* Camera information. */
775 /* Emulated camera device descriptor. */
776 CameraDevice* camera;
800 /* Frees emulated camera client descriptor. */
804 /* The only exception to the "read only" rule: we have to mark the camera
809 if (cc->camera != NULL) {
810 camera_device_close(cc->camera);
822 /* Creates descriptor for a connecting emulated camera client.
824 * csd - Camera service descriptor.
827 * identifiying the camera device to create the service for. Also parameters
829 * channel to use when communicating with the camera device.
831 * Emulated camera client descriptor on success, or NULL on failure.
842 * Parse parameter string, containing camera client properties.
866 /* Get camera info for the emulated camera represented with this service.
867 * Array of camera information records has been created when the camera
868 * service was enumerating camera devices during the service initialization.
869 * By the camera service protocol, camera service clients must first obtain
870 * list of enumerated cameras via the 'list' query to the camera service, and
871 * then use device name reported in the list to connect to an emulated camera
872 * service. So, if camera information for the given device name is not found
876 E("%s: Cannot find camera info for device '%s'",
882 /* We can't allow multiple camera services for a single camera device, Lets
883 * make sure that there is no client created for this camera. */
885 E("%s: Camera device '%s' is in use", __FUNCTION__, cc->device_name);
890 /* We're done. Set camera in use, and succeed the connection. */
894 D("%s: Camera service is created for device '%s' using input channel %d",
901 * Camera client queries
904 /* Client has queried conection to the camera.
906 * cc - Queried camera client descriptor.
907 * qc - Qemu client for the emulated camera.
913 if (cc->camera != NULL) {
915 W("%s: Camera '%s' is already connected", __FUNCTION__, cc->device_name);
916 _qemu_client_reply_ok(qc, "Camera is already connected");
920 /* Open camera device. */
921 cc->camera
922 if (cc->camera == NULL) {
923 E("%s: Unable to open camera device '%s'", __FUNCTION__, cc->device_name);
924 _qemu_client_reply_ko(qc, "Unable to open camera device.");
928 D("%s: Camera device '%s' is now connected", __FUNCTION__, cc->device_name);
933 /* Client has queried disconection from the camera.
935 * cc - Queried camera client descriptor.
936 * qc - Qemu client for the emulated camera.
944 if (cc->camera == NULL) {
946 W("%s: Camera '%s' is already disconnected", __FUNCTION__, cc->device_name);
947 _qemu_client_reply_ok(qc, "Camera is not connected");
951 /* Before we can go ahead and disconnect, we must make sure that camera is
954 E("%s: Cannot disconnect camera '%s' while it is not stopped",
956 _qemu_client_reply_ko(qc, "Camera is not stopped");
960 /* Close camera device. */
961 camera_device_close(cc->camera);
962 cc->camera = NULL;
964 D("Camera device '%s' is now disconnected", cc->device_name);
971 * cc - Queried camera client descriptor.
972 * qc - Qemu client for the emulated camera.
988 if (cc->camera == NULL) {
990 E("%s: Camera '%s' is not connected", __FUNCTION__, cc->device_name);
991 _qemu_client_reply_ko(qc, "Camera is not connected");
1036 /* After collecting capture parameters lets see if camera has already
1043 W("%s: Camera '%s' is already started", __FUNCTION__, cc->device_name);
1044 _qemu_client_reply_ok(qc, "Camera is already started");
1047 E("%s: Camera '%s' is already started, and parameters don't match:\n"
1052 "Camera is already started with different capturing parameters");
1058 * Start the camera.
1085 /* Make sure that we have a converters between the original camera pixel
1096 /* TODO: At the moment camera framework in the emulator requires RGB32 pixel
1116 /* Start the camera. */
1117 if (camera_device_start_capturing(cc->camera, cc->camera_info->pixel_format,
1119 E("%s: Cannot start camera '%s' for %.4s[%dx%d]: %s",
1124 _qemu_client_reply_ko(qc, "Cannot start the camera");
1128 D("%s: Camera '%s' is now started for %.4s[%dx%d]",
1137 * cc - Queried camera client descriptor.
1138 * qc - Qemu client for the emulated camera.
1146 W("%s: Camera '%s' is not started", __FUNCTION__, cc->device_name);
1147 _qemu_client_reply_ok(qc, "Camera is not started");
1151 /* Stop the camera. */
1152 if (camera_device_stop_capturing(cc->camera)) {
1153 E("%s: Cannot stop camera device '%s': %s",
1155 _qemu_client_reply_ko(qc, "Cannot stop camera device");
1162 D("%s: Camera device '%s' is now stopped.", __FUNCTION__, cc->device_name);
1168 * cc - Queried camera client descriptor.
1169 * qc - Qemu client for the emulated camera.
1189 E("%s: Camera '%s' is not started", __FUNCTION__, cc->device_name);
1190 _qemu_client_reply_ko(qc, "Camera is not started");
1204 /* Verify that framebuffer sizes match the ones that the started camera
1208 E("%s: Frame sizes don't match for camera '%s':\n"
1234 repeat = camera_device_read_frame(cc->camera, fbs, fbs_num);
1251 repeat = camera_device_read_frame(cc->camera, fbs, fbs_num);
1255 E("%s: Unable to obtain first video frame from the camera '%s' in %d milliseconds: %s.",
1258 _qemu_client_reply_ko(qc, "Unable to obtain video frame from the camera");
1262 E("%s: Unable to obtain video frame from the camera '%s': %s.",
1301 /* Handles a message received from the emulated camera client.
1303 * - 'connect' - Connects to the camera device (opens it).
1304 * - 'disconnect' - Disconnexts from the camera device (closes it).
1305 * - 'start' - Starts capturing video from the connected camera device.
1306 * - 'stop' - Stop capturing video from the connected camera device.
1307 * - 'frame' - Queries video and preview frames captured from the camera.
1309 * opaque - Camera service descriptor.
1310 * msg, msglen - Message received from the camera factory client.
1311 * client - Camera factory client pipe.
1320 * Emulated camera client queries.
1323 /* Connect to the camera. */
1325 /* Disconnect from the camera. */
1339 * Emulated camera queries are formatted as such:
1343 T("%s: Camera client query: '%s'", __FUNCTION__, (char*)msg);
1356 /* Camera connection is queried. */
1359 /* Camera disnection is queried. */
1373 /* Emulated camera client has been disconnected from the service. */
1379 D("%s: Camera client for device '%s' on input channel %d is now closed",
1386 * Camera service API
1389 /* Connects a client to the camera service.
1391 * - Camera factory that is insterested only in listing camera devices attached
1393 * - Camera device emulators that attach to the actual camera devices.
1396 * connects to a camera factory. Otherwise, parameters describe the camera device
1408 D("%s: Connecting camera client '%s'",
1411 /* This is an emulated camera factory client. */
1416 /* This is an emulated camera client. */
1455 /* Enumerate camera devices connected to the host. */
1463 printf(" Camera '%s' is connected to device '%s' on channel %d using pixel format '%.4s'\n",