static void list_cameras (dc1394_t *dc1394_cxt, dc1394camera_list_t *cam_list) { dc1394error_t err; int i; printf ("bus_id\tguid \tunit\tmodel (vendor)\n"); for (i = 0; i < cam_list->num; ++i) { dc1394camera_t *camera = NULL; camera = dc1394_camera_new_unit (dc1394_cxt, cam_list->ids[i].guid, cam_list->ids[i].unit); if (camera != NULL) { uint32_t port = -1; err = dc1394_camera_get_linux_port (camera, &port); if (err == DC1394_SUCCESS) { printf ("%6d", port); } else { printf (" n/a"); } printf ("\t0x%016" PRIx64 "\t%4" PRIu16 "\t%s (%s)\n", camera->guid, camera->unit, camera->model, camera->vendor); dc1394_camera_free (camera); camera = NULL; } } }
CameraInfo* FWCamera::getCameraInfos(int deviceNumber) { #ifdef AVG_ENABLE_1394_2 dc1394_t* pDC1394 = dc1394_new(); if (pDC1394 == 0) { AVG_ASSERT(false); return NULL; } dc1394camera_list_t * pCameraList; int err=dc1394_camera_enumerate(pDC1394, &pCameraList); if (err != DC1394_SUCCESS) { AVG_ASSERT(false); return NULL; } if (pCameraList->num != 0) { dc1394camera_id_t id = pCameraList->ids[deviceNumber]; dc1394camera_t * pCamera = dc1394_camera_new_unit(pDC1394, id.guid, id.unit); if (pCamera) { stringstream deviceID; deviceID << hex << id.guid;//pCamera->guid; CameraInfo* camInfo = new CameraInfo("Firewire", deviceID.str()); getCameraControls(pCamera, camInfo); getCameraImageFormats(pCamera, camInfo); dc1394_camera_free(pCamera); dc1394_camera_free_list(pCameraList); dc1394_free(pDC1394); return camInfo; } } #endif return NULL; }
static void reset_bus (opts_t *opts, dc1394_t *dc1394_cxt, dc1394camera_list_t *cam_list) { int is_found[MAX_NUM_ID] = { 0 }; dc1394camera_id_t target[MAX_NUM_ID]; dc1394error_t err; int i; /* search target cameras connected to the buses for resetting */ for (i = 0; i < cam_list->num; ++i) { dc1394camera_t *camera = NULL; camera = dc1394_camera_new_unit (dc1394_cxt, cam_list->ids[i].guid, cam_list->ids[i].unit); if (camera != NULL) { uint32_t port = -1; err = dc1394_camera_get_linux_port (camera, &port); if (err == DC1394_SUCCESS) { int j; for (j = 0; j < opts->num_id; ++j) { if ((is_found[j] == 0) && (opts->bus_id[j] == port)) { target[j] = cam_list->ids[i]; is_found[j] = -1; break; } } } dc1394_camera_free (camera); camera = NULL; } } /* reset buses in the specified order */ for (i = 0; i < opts->num_id; ++i) { if (is_found[i] != 0) { dc1394camera_t *camera = NULL; printf ("resetting bus %d...", opts->bus_id[i]); camera = dc1394_camera_new_unit (dc1394_cxt, target[i].guid, target[i].unit); if (camera != NULL) { err = dc1394_reset_bus (camera); dc1394_camera_free (camera); camera = NULL; } else { err = DC1394_FAILURE; } if (err == DC1394_SUCCESS) { printf ("OK\n"); } else { printf ("NG\n"); } } else { printf ("warning: bus %d is not found.\n", opts->bus_id[i]); } } }
GstCaps * gst_dc1394_get_cam_caps (GstDc1394 * src) { dc1394camera_t *camera = NULL; dc1394camera_list_t *cameras = NULL; dc1394error_t camerr; gint i, j; dc1394video_modes_t modes; dc1394framerates_t framerates; GstCaps *gcaps = NULL; gcaps = gst_caps_new_empty (); camerr = dc1394_camera_enumerate (src->dc1394, &cameras); if (camerr != DC1394_SUCCESS || cameras == NULL) { GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, ("Can't find cameras error : %d", camerr), ("Can't find cameras error : %d", camerr)); goto error; } if (cameras->num == 0) { GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, ("There were no cameras"), ("There were no cameras")); goto error; } if (src->camnum > (cameras->num - 1)) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Invalid camera number"), ("Invalid camera number %d", src->camnum)); goto error; } camera = dc1394_camera_new_unit (src->dc1394, cameras->ids[src->camnum].guid, cameras->ids[src->camnum].unit); dc1394_camera_free_list (cameras); cameras = NULL; camerr = dc1394_video_get_supported_modes (camera, &modes); if (camerr != DC1394_SUCCESS) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Error getting supported modes"), ("Error getting supported modes")); goto error; } for (i = modes.num - 1; i >= 0; i--) { int m = modes.modes[i]; if (m < DC1394_VIDEO_MODE_EXIF) { GstStructure *gs = gst_structure_empty_new ("video"); gst_structure_set (gs, "vmode", G_TYPE_INT, m, NULL); if (gst_dc1394_caps_set_format_vmode_caps (gs, m) < 0) { GST_ELEMENT_ERROR (src, STREAM, FAILED, ("attempt to set mode to %d failed", m), ("attempt to set mode to %d failed", m)); goto error; } else { camerr = dc1394_video_get_supported_framerates (camera, m, &framerates); gst_dc1394_caps_set_framerate_list (gs, &framerates); gst_caps_append_structure (gcaps, gs); } } else { // FORMAT 7 guint maxx, maxy; GstStructure *gs = gst_structure_empty_new ("video"); dc1394color_codings_t colormodes; guint xunit, yunit; gst_structure_set (gs, "vmode", G_TYPE_INT, m, NULL); // Get the maximum frame size camerr = dc1394_format7_get_max_image_size (camera, m, &maxx, &maxy); if (camerr != DC1394_SUCCESS) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Error getting format 7 max image size"), ("Error getting format 7 max image size")); goto error; } GST_LOG_OBJECT (src, "Format 7 maxx=%d maxy=%d", maxx, maxy); camerr = dc1394_format7_get_unit_size (camera, m, &xunit, &yunit); if (camerr != DC1394_SUCCESS) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Error getting format 7 image unit size"), ("Error getting format 7 image unit size")); goto error; } GST_LOG_OBJECT (src, "Format 7 unitx=%d unity=%d", xunit, yunit); gst_dc1394_set_caps_framesize_range (gs, xunit, maxx, xunit, yunit, maxy, yunit); // note that format 7 has no concept of a framerate, so we pass the // full range gst_structure_set (gs, "framerate", GST_TYPE_FRACTION_RANGE, 0, 1, G_MAXINT, 1, NULL); // get the available color codings camerr = dc1394_format7_get_color_codings (camera, m, &colormodes); if (camerr != DC1394_SUCCESS) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Error getting format 7 color modes"), ("Error getting format 7 color modes")); goto error; } for (j = 0; j < colormodes.num; j++) { GstStructure *newgs = gst_structure_copy (gs); gst_dc1394_set_caps_color (newgs, colormodes.codings[j]); GST_LOG_OBJECT (src, "Format 7 colormode set : %d", colormodes.codings[j]); // note that since there are multiple color modes, we append // multiple structures. gst_caps_append_structure (gcaps, newgs); } } } if (camera) { dc1394_camera_free (camera); } return gcaps; error: if (gcaps) { gst_caps_unref (gcaps); } if (cameras) { dc1394_camera_free_list (cameras); cameras = NULL; } if (camera) { dc1394_camera_free (camera); camera = NULL; } return NULL; }
static gboolean gst_dc1394_open_cam_with_best_caps (GstDc1394 * src) { dc1394camera_list_t *cameras = NULL; gint err = 0; int framerateconst; GST_LOG_OBJECT (src, "Opening the camera!!!"); if (dc1394_camera_enumerate (src->dc1394, &cameras) != DC1394_SUCCESS) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Can't find cameras"), ("Can't find cameras")); goto error; } GST_LOG_OBJECT (src, "Found %d cameras", cameras->num); if (src->camnum > (cameras->num - 1)) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Invalid camera number"), ("Invalid camera number")); goto error; } GST_LOG_OBJECT (src, "Opening camera : %d", src->camnum); src->camera = dc1394_camera_new_unit (src->dc1394, cameras->ids[src->camnum].guid, cameras->ids[src->camnum].unit); dc1394_camera_free_list (cameras); cameras = NULL; // figure out mode framerateconst = gst_dc1394_framerate_frac_to_const (src->rate_numerator, src->rate_denominator); GST_LOG_OBJECT (src, "The dma buffer queue size is %d buffers", src->bufsize); switch (src->iso_speed) { case 100: err = dc1394_video_set_iso_speed (src->camera, DC1394_ISO_SPEED_100); break; case 200: err = dc1394_video_set_iso_speed (src->camera, DC1394_ISO_SPEED_200); break; case 400: err = dc1394_video_set_iso_speed (src->camera, DC1394_ISO_SPEED_400); break; case 800: if (src->camera->bmode_capable > 0) { dc1394_video_set_operation_mode (src->camera, DC1394_OPERATION_MODE_1394B); err = dc1394_video_set_iso_speed (src->camera, DC1394_ISO_SPEED_800); } break; case 1600: if (src->camera->bmode_capable > 0) { dc1394_video_set_operation_mode (src->camera, DC1394_OPERATION_MODE_1394B); err = dc1394_video_set_iso_speed (src->camera, DC1394_ISO_SPEED_1600); } break; case 3200: if (src->camera->bmode_capable > 0) { dc1394_video_set_operation_mode (src->camera, DC1394_OPERATION_MODE_1394B); err = dc1394_video_set_iso_speed (src->camera, DC1394_ISO_SPEED_3200); } break; default: GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Invalid ISO speed"), ("Invalid ISO speed")); goto error; break; } if (err != DC1394_SUCCESS) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Could not set ISO speed"), ("Could not set ISO speed")); goto error; } GST_LOG_OBJECT (src, "Setting mode : %d", src->vmode); err = dc1394_video_set_mode (src->camera, src->vmode); if (err != DC1394_SUCCESS) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Could not set video mode %d", src->vmode), ("Could not set video mode %d", src->vmode)); goto error; } GST_LOG_OBJECT (src, "Setting framerate : %d", framerateconst); dc1394_video_set_framerate (src->camera, framerateconst); if (err != DC1394_SUCCESS) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Could not set framerate to %d", framerateconst), ("Could not set framerate to %d", framerateconst)); goto error; } // set any format-7 parameters if this is a format-7 mode if (src->vmode >= DC1394_VIDEO_MODE_FORMAT7_MIN && src->vmode <= DC1394_VIDEO_MODE_FORMAT7_MAX) { // the big thing we care about right now is frame size err = dc1394_format7_set_image_size (src->camera, src->vmode, src->width, src->height); if (err != DC1394_SUCCESS) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Could not set format 7 image size to %d x %d", src->width, src->height), ("Could not set format 7 image size to %d x %d", src->width, src->height)); goto error; } } err = dc1394_capture_setup (src->camera, src->bufsize, DC1394_CAPTURE_FLAGS_DEFAULT); if (err != DC1394_SUCCESS) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Error setting capture mode"), ("Error setting capture mode")); } if (err != DC1394_SUCCESS) { if (err == DC1394_NO_BANDWIDTH) { GST_LOG_OBJECT (src, "Capture setup_dma failed." "Trying to cleanup the iso_channels_and_bandwidth and retrying"); // try to cleanup the bandwidth and retry err = dc1394_iso_release_all (src->camera); if (err != DC1394_SUCCESS) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("Could not cleanup bandwidth"), ("Could not cleanup bandwidth")); goto error; } else { err = dc1394_capture_setup (src->camera, src->bufsize, DC1394_CAPTURE_FLAGS_DEFAULT); if (err != DC1394_SUCCESS) { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("unable to setup camera error %d", err), ("unable to setup camera error %d", err)); goto error; } } } else { GST_ELEMENT_ERROR (src, RESOURCE, FAILED, ("unable to setup camera error %d", err), ("unable to setup camera error %d", err)); goto error; } } return TRUE; error: if (src->camera) { dc1394_camera_free (src->camera); src->camera = NULL; } return FALSE; }