/** Get Format7 color coding. * * @pre camera is in a Format7 video mode. * * @param camera points to DC1394 camera struct * @param video_mode currently selected Format7 video mode. * @param[in,out] color_coding Config parameter for this option, * updated if the camera does not support the * requested value * @return corresponding dc1394color_coding_t enum value selected */ dc1394color_coding_t getColorCoding(dc1394camera_t *camera, dc1394video_mode_t video_mode, std::string &color_coding) { for (int ccode = DC1394_COLOR_CODING_MIN; ccode <= DC1394_COLOR_CODING_MAX; ++ccode) { if (color_coding_names_[ccode-DC1394_COLOR_CODING_MIN] == color_coding) { // found the requested mode dc1394color_codings_t ccs; dc1394error_t err = dc1394_format7_get_color_codings(camera, video_mode, &ccs); if (err != DC1394_SUCCESS) { ROS_FATAL("unable to get supported color codings"); // TODO raise exception return (dc1394color_coding_t) 0; } // see if requested mode is available for (uint32_t i = 0; i < ccs.num; ++i) { if (ccs.codings[i] == ccode) return (dc1394color_coding_t) ccode; // yes: success } // requested mode not available, revert to current mode of camera ROS_ERROR_STREAM("Color coding " << color_coding << " not supported by this camera"); dc1394color_coding_t current_mode; err = dc1394_format7_get_color_coding(camera, video_mode, ¤t_mode); if (err != DC1394_SUCCESS) { ROS_FATAL("unable to get current color coding"); // TODO raise exception return (dc1394color_coding_t) 0; } // TODO list available modes // change color_coding parameter to show current mode of camera color_coding = colorCodingName(current_mode); return current_mode; } } // Requested color coding does not match any known string, set to // "mono8" and update parameter. ROS_FATAL_STREAM("Unknown color_coding: " << color_coding); color_coding = colorCodingName(DC1394_COLOR_CODING_MONO8); return (dc1394color_coding_t) DC1394_COLOR_CODING_MONO8; }
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; }
int main(int argc, char *argv[]) { FILE* imagefile; dc1394camera_t *camera; unsigned int width, height; dc1394video_frame_t *frame=NULL; //dc1394featureset_t features; dc1394_t * d; dc1394camera_list_t * list; dc1394error_t err; int i,j; d = dc1394_new (); if (!d) return 1; err=dc1394_camera_enumerate (d, &list); DC1394_ERR_RTN(err,"Failed to enumerate cameras"); if (list->num == 0) { dc1394_log_error("No cameras found"); return 1; } printf("Total cameras found %d\n",list->num); camera = dc1394_camera_new (d, list->ids[0].guid); if (!camera) { dc1394_log_error("Failed to initialize camera with guid %llx", list->ids[0].guid); return 1; } dc1394_camera_free_list (list); printf("Using camera with GUID %"PRIx64"\n", camera->guid); dc1394video_modes_t video_modes; err=dc1394_video_get_supported_modes(camera,&video_modes); DC1394_ERR_RTN(err,"Failed get camera modes"); printf("Video Modes:\n"); for( i = 0; i < video_modes.num; i++ ) { printVideoMode(video_modes.modes[i]); if( video_modes.modes[i] < DC1394_VIDEO_MODE_FORMAT7_0 ) { dc1394framerates_t rates; err=dc1394_video_get_supported_framerates(camera,video_modes.modes[i],&rates); DC1394_ERR_RTN(err,"Failed get mode frame rates"); for( j = 0; j < rates.num; j++ ) { printFrameRates(rates.framerates[j]); } } else { dc1394color_codings_t codings; err=dc1394_format7_get_color_codings(camera,video_modes.modes[i],&codings); DC1394_ERR_RTN(err,"Failed get format7 color codings"); for( j = 0; j < codings.num; j++ ) { printColorCodings(codings.codings[j]); } uint32_t width,height; err=dc1394_format7_get_max_image_size(camera,video_modes.modes[i],&width,&height); DC1394_ERR_RTN(err,"Failed get format7 max size"); printf(" Max dimension = %d %d\n",width,height); } } dc1394_camera_free(camera); dc1394_free (d); return 0; }