📄 tools.c
字号:
} // CLEAR REMOVED CAMERAS ----------------------------- index=0; //fprintf(stderr,"Getting new GUIDs\n"); // get all new guids for (port=0;port<bi.port_num;port++) { if (bi.handles[port]!=0) { for (i=0;i<bi.port_camera_num[port];i++) { if (dc1394_get_camera_info(bi.handles[port], bi.camera_nodes[port][i], &camera_info)!=DC1394_SUCCESS) MainError("Can't get camera basic information in bus-reset handler"); new_guids[index]=camera_info.euid_64; index++; } } } // look if there is a camera that disappeared from the camera_t struct camera_ptr=cameras; while (camera_ptr!=NULL) { for (i=0;i<index;i++) { if (camera_ptr->camera_info.euid_64==new_guids[i]) break; } if (camera_ptr->camera_info.euid_64!=new_guids[i]) { // the camera "camera_ptr" was unplugged //fprintf(stderr,"found a camera to remove\n"); if (camera->camera_info.euid_64==camera_ptr->camera_info.euid_64) { //fprintf(stderr," The current camera was unplugged\n"); if (bi.camera_num==0) { // the only camera was removed. Close GUI and revert to camera wait prompt //fprintf(stderr," ... and it was the only camera!\n"); waiting_camera_window=create_waiting_camera_window(); gtk_widget_show(waiting_camera_window); // delete structs: RemoveCamera(camera_ptr->camera_info.euid_64); cameras=NULL; camera=NULL; } else { //fprintf(stderr," Selecting the first non-removed camera as current camera\n"); if (cameras->camera_info.euid_64==camera_ptr->camera_info.euid_64) { // is the first camera the one to be removed? // use second cam as current cam SetCurrentCamera(cameras->next->camera_info.euid_64); } else { // use first cam as current cam SetCurrentCamera(cameras->camera_info.euid_64); } // close and remove dead camera RemoveCamera(camera_ptr->camera_info.euid_64); } //fprintf(stderr," removed dead camera\n"); } // end if we are deleting the current camera else { // we delete another camera. This is easy. RemoveCamera(camera_ptr->camera_info.euid_64); } // rescan from the beginning. camera_ptr=cameras; } else { camera_ptr=camera_ptr->next; } } //fprintf(stderr,"Removed all dead camera structs\n"); // restart ISO if necessary cp2=cameras; while(cp2!=NULL) { if (dc1394_get_iso_status(cp2->camera_info.handle,cp2->camera_info.id,&iso_status)!=DC1394_SUCCESS) { MainError("Could not read ISO status"); } else { //fprintf(stderr,"iso is %d and should be %d\n", iso_status,cp2->misc_info.is_iso_on); if ((cp2->misc_info.is_iso_on==DC1394_TRUE)&&(iso_status==DC1394_FALSE)) { if (dc1394_start_iso_transmission(cp2->camera_info.handle,cp2->camera_info.id)!=DC1394_SUCCESS) { MainError("Could start ISO"); } usleep(DELAY); } } cp2=cp2->next; } if (bi.camera_num>0) { //fprintf(stderr,"build/refresh GUI\n"); if (waiting_camera_window!=NULL) { gtk_widget_destroy(GTK_WIDGET(waiting_camera_window)); waiting_camera_window=NULL; //fprintf(stderr," destroyed win\n"); }#ifdef HAVE_SDLLIB watchthread_info.draw=0; watchthread_info.mouse_down=0; watchthread_info.crop=0;#endif /* if (new_camera!=NULL) fprintf(stderr," handle: 0x%x\n",new_camera->camera_info.handle); if (camera!=NULL) fprintf(stderr," handle: 0x%x\n",camera->camera_info.handle); fprintf(stderr,"camera: 0x%x\n",camera); */ //fprintf(stderr,"Want to display: %d\n",camera->want_to_display); if (camera!=NULL) { if (camera->want_to_display>0) DisplayStartThread(camera); BuildAllWindows(); //fprintf(stderr,"finished building GUI\n"); UpdateAllWindows(); //fprintf(stderr,"finished updating GUI\n"); gtk_widget_set_sensitive(main_window,TRUE); } } GrabSelfIds(bi.handles, bi.port_num); /* fprintf(stderr,"Reseting ISO channels\n"); // re-set ISO channels. SetChannels(); fprintf(stderr,"Restarting ISO\n"); // Restart all ISO threads camera_ptr=cameras; while (camera_ptr!=NULL) { if (GetService(camera_ptr,SERVICE_ISO)!=NULL) { IsoStopThread(camera_ptr); usleep(DELAY); IsoStartThread(camera_ptr); } camera_ptr=camera_ptr->next; } */ free(bi.handles); free(bi.port_camera_num); free(bi.camera_nodes); //fprintf(stderr,"resumed fps display\n"); //fprintf(stderr,"Finished handling bus reset\n"); return(1);}intmain_timeout_handler(gpointer* port_num) { int i; //int ports=(int)port_num; quadlet_t quadlet; // the main timeout performs tasks every ms. In order to have less repeated tasks // the main_timeout_ticker can be consulted. main_timeout_ticker=(main_timeout_ticker+10)%1000; // -------------------------------------------------------------------------------------- // cancel display thread if asked by the SDL/WM // We must do this here because it is not allowed to call a GTK function from a thread. At least if we do // so the program progressively breaks with strange GUI behaviour/look. if (!(main_timeout_ticker%100)) { // every 100ms if (WM_cancel_display>0) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (lookup_widget(main_window,"service_display")), FALSE); WM_cancel_display=0; } //fprintf(stderr,"check display cancel\n"); } // -------------------------------------------------------------------------------------- // performs a dummy read on all handles to detect bus resets if (!(main_timeout_ticker%1000)) { // every second for (i=0;i<businfo->port_num;i++) { //fprintf(stderr,"bus reset detection for port %d\n",i); cooked1394_read(businfo->handles[i], 0xffc0 | raw1394_get_local_id(businfo->handles[i]), CSR_REGISTER_BASE + CSR_CYCLE_TIME, 4, (quadlet_t *) &quadlet); } //fprintf(stderr,"dummy read\n"); } // -------------------------------------------------------------------------------------- // update the bandwidth estimtation if (!(main_timeout_ticker%1000)) { // every second UpdateBandwidthFrame(); }#ifdef HAVE_SDLLIB // -------------------------------------------------------------------------------------- // update cursor information if (!(main_timeout_ticker%100)) { // every 100ms if (cursor_info.update_req>0) { UpdateCursorFrame(); cursor_info.update_req=0; } }#endif return(1);}voidSetFormat7Crop(int sx, int sy, int px, int py, int mode) { int state; Format7ModeInfo_t *info; GtkAdjustment *adjsx, *adjsy, *adjpx, *adjpy; info=&camera->format7_info.mode[mode-MODE_FORMAT7_MIN]; adjpx=gtk_range_get_adjustment(GTK_RANGE (lookup_widget(main_window, "format7_hposition_scale"))); adjpy=gtk_range_get_adjustment(GTK_RANGE (lookup_widget(main_window, "format7_vposition_scale"))); adjsx=gtk_range_get_adjustment(GTK_RANGE (lookup_widget(main_window, "format7_hsize_scale"))); adjsy=gtk_range_get_adjustment(GTK_RANGE (lookup_widget(main_window, "format7_vsize_scale"))); // do something if we were called by a first generation signal: if ((gtk_signal_n_emissions_by_name(GTK_OBJECT (adjpx), "changed")==0)&& (gtk_signal_n_emissions_by_name(GTK_OBJECT (adjpy), "changed")==0)&& (gtk_signal_n_emissions_by_name(GTK_OBJECT (adjsx), "changed")==0)&& (gtk_signal_n_emissions_by_name(GTK_OBJECT (adjsy), "changed")==0)) { if (mode==camera->misc_info.mode) { IsoFlowCheck(&state); } // the order in which we apply the F7 changes is important. // example: from size=128x128, pos=128x128, we can't go to size=1280x1024 by just changing the size. // We need to set the position to 0x0 first. //fprintf(stderr,"Setting format7 to pos=[%d %d], size=[%d %d]\n",px,py,sx,sy); if (dc1394_set_format7_image_position(camera->camera_info.handle,camera->camera_info.id, mode, 0, 0)!=DC1394_SUCCESS) MainError("Could not set Format7 image position to zero"); if ((dc1394_set_format7_image_size(camera->camera_info.handle,camera->camera_info.id, mode, sx, sy)!=DC1394_SUCCESS)|| (dc1394_set_format7_image_position(camera->camera_info.handle,camera->camera_info.id, mode, px, py)!=DC1394_SUCCESS)) MainError("Could not set Format7 image size and position"); else { info->size_x=sx; info->size_y=sy; info->pos_x=px; info->pos_y=py; } // tell the ranges to change their settings adjpx->upper=info->max_size_x-sx; adjpx->value=px; gtk_signal_emit_by_name(GTK_OBJECT (adjpx), "changed"); adjpy->upper=info->max_size_y-sy; adjpy->value=py; gtk_signal_emit_by_name(GTK_OBJECT (adjpy), "changed"); adjsx->upper=info->max_size_x-px; adjsx->value=sx; gtk_signal_emit_by_name(GTK_OBJECT (adjsx), "changed"); adjsy->upper=info->max_size_y-py; adjsy->value=sy; gtk_signal_emit_by_name(GTK_OBJECT (adjsy), "changed"); usleep(DELAY); if (mode==camera->misc_info.mode) { IsoFlowResume(&state); } }} intNearestValue(int value, int step, int min, int max) { int low, high; if (((max-min)%step) !=0) { MainError("Stange values entered in NearestValue..."); } low=value-(value%step); high=value-(value%step)+step; if (low<min) low=min; if (high>max) high=max; if (abs(low-value)<abs(high-value)) return low; else return high;}voidwindow_set_icon(GtkWidget* window) { // This function is 'strongly inspired' by the related code found in gqview.#ifdef HAVE_GDK_PIXBUF GdkPixbuf *pb; GdkPixmap *pixmap; GdkBitmap *mask; pb = gdk_pixbuf_new_from_xpm_data((const gchar**)coriander_icon_xpm); gdk_pixbuf_render_pixmap_and_mask(pb, &pixmap, &mask, 128); gdk_pixbuf_unref(pb); gdk_window_set_icon(window->window, NULL, pixmap, mask);#endif}/* The following function is a strip-down version of the program 'xvinfo' of the XFree86 project. */voidGetXvInfo(xvinfo_t *xvinfo) {#ifdef HAVE_XV unsigned int ver, rev, eventB, reqB, errorB; int i, j, n; xvinfo->max_height=-1; xvinfo->max_width=-1; if(!(xvinfo->dpy = XOpenDisplay(NULL))) { MainError("Unable to open display"); return; } if((Success != XvQueryExtension(xvinfo->dpy, &ver, &rev, &reqB, &eventB, &errorB))) { MainError("xvinfo: No X-Video Extension"); return; } i=0; // 0: we use only the first screen XvQueryAdaptors(xvinfo->dpy, RootWindow(xvinfo->dpy, i), &xvinfo->nadaptors, &xvinfo->ainfo); if( !xvinfo->nadaptors || !xvinfo->ainfo ){ MainError( "xvinfo: No adpators present\n" ); return; } j=0; // 0: we use only the first adaptor XvQueryEncodings(xvinfo->dpy, xvinfo->ainfo[j].base_id, &xvinfo->nencode, &xvinfo->encodings); if(xvinfo->encodings && xvinfo->nencode) { xvinfo->ImageEncodings = 0; for(n = 0; n < xvinfo->nencode; n++) { if(!strcmp(xvinfo->encodings[n].name, "XV_IMAGE")) xvinfo->ImageEncodings++; } if(xvinfo->ImageEncodings && (xvinfo->ainfo[j].type & XvImageMask)) { //char imageName[5] = {0, 0, 0, 0, 0}; for(n = 0; n < xvinfo->nencode; n++) { if(!strcmp(xvinfo->encodings[n].name, "XV_IMAGE")) { //fprintf(stdout, "maximum XvImage size: %li x %li\n", xvinfo->encodings[n].width, xvinfo->encodings[n].height); xvinfo->max_height=(int)xvinfo->encodings[n].height; xvinfo->max_width=(int)xvinfo->encodings[n].width; break; } } /* formats = XvListImageFormats(dpy, ainfo[j].base_id, &numImages); fprintf(stdout, " Number of image formats: %i\n", numImages); for(n = 0; n < numImages; n++) { memcpy(imageName, &(formats[n].id), 4); fprintf(stdout, " id: 0x%x", formats[n].id); if(isprint(imageName[0]) && isprint(imageName[1]) && isprint(imageName[2]) && isprint(imageName[3])) { fprintf(stdout, " (%s)\n", imageName); } else { fprintf(stdout, "\n"); } fprintf(stdout, " bits per pixel: %i\n", formats[n].bits_per_pixel); fprintf(stdout, " number of planes: %i\n", formats[n].num_planes); fprintf(stdout, " type: %s (%s)\n", (formats[n].type == XvRGB) ? "RGB" : "YUV", (formats[n].format == XvPacked) ? "packed" : "planar"); if(formats[n].type == XvRGB) { fprintf(stdout, " depth: %i\n", formats[n].depth); fprintf(stdout, " red, green, blue masks: 0x%x, 0x%x, 0x%x\n", formats[n].red_mask, formats[n].green_mask, formats[n].blue_mask); } } if(formats) XFree(formats); */ } XvFreeEncodingInfo(xvinfo->encodings); } XvFreeAdaptorInfo(xvinfo->ainfo);#else xvinfo->max_height=-1; xvinfo->max_width=-1;#endif //fprintf(stderr,"%d %d\n", xvinfo->max_height, xvinfo->max_width);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -