int
main(int argc, char **argv) {
	Camera	*canon;
	int	retval;
	GPContext *canoncontext = sample_create_context();

	gettimeofday(&starttime,NULL);
	gp_log_add_func(GP_LOG_ERROR, errordumper, NULL);
	gp_camera_new(&canon);

	/* When I set GP_LOG_DEBUG instead of GP_LOG_ERROR above, I noticed that the
	 * init function seems to traverse the entire filesystem on the camera.  This
	 * is partly why it takes so long.
	 * (Marcus: the ptp2 driver does this by default currently.)
	 */
	printf("Camera init.  Takes about 10 seconds.\n");
	retval = gp_camera_init(canon, canoncontext);
	if (retval != GP_OK) {
		printf("  Retval: %d\n", retval);
		exit (1);
	}
	canon_enable_capture(canon, TRUE, canoncontext);
	/*set_capturetarget(canon, canoncontext);*/
	capture_to_file(canon, canoncontext, "foo.jpg");
	gp_camera_exit(canon, canoncontext);
	return 0;
}
Ejemplo n.º 2
0
int init_camera(Camera **camera,GPContext **context)
{
	int retval;
	*context = gp_context_new();
	gp_camera_new(camera);
	retval = gp_camera_init(*camera, *context);
	return retval;
}
Ejemplo n.º 3
0
CAMLprim
value caml_gp_camera_new(value unit_val) {
  CAMLparam0();
  Camera *cam;
  int ret = gp_camera_new(&cam);
  CHECK_RESULT(ret);
  CAMLreturn(encapsulate_pointer(cam));
}
Ejemplo n.º 4
0
int main(int argc, char *argv[]){
        Camera		*camera;
        GPContext	*context = gp_context_new();
        int		retval;
	CameraEventType evttype;
	void    	*evtdata;
	CameraFile	*file;

        gp_camera_new(&camera);
	retval = gp_camera_init(camera, context);
        if(retval != GP_OK)
        {
                printf("Error: %s\n", gp_result_as_string(retval));
                return 1;
        }

	do {
		retval = gp_camera_wait_for_event (camera, 10, &evttype, &evtdata, context);
	} while ((retval == GP_OK) && (evttype != GP_EVENT_TIMEOUT));

	retval = gp_file_new(&file);
	if (retval != GP_OK) {
		printf("gp_file_new: %d\n", retval);
		return 1;
	}
	/*retval = gp_camera_capture_preview(camera, file, context); */
	if (retval != GP_OK) {
		printf("gp_camera_capture_preview: %d\n", retval);
		return 1;
	}
	gp_file_free (file);

        if(argc == 1)
        {
                retval = camera_auto_focus(camera, context);
		if(retval != GP_OK) {
			printf("Error: %s\n", gp_result_as_string(retval));
			return 1;
		}
        }
        else if(argc == 2)
        {
                int value = atoi(argv[1]);
                retval = camera_manual_focus(camera, value, context);
		if(retval != GP_OK) {
			printf("Error: %s\n", gp_result_as_string(retval));
			return 1;
		}
        }
	do {
		retval = gp_camera_wait_for_event (camera, 10, &evttype, &evtdata, context);
	} while ((retval == GP_OK) && (evttype != GP_EVENT_TIMEOUT));

        gp_camera_exit(camera, context);
        return 0;
}
Ejemplo n.º 5
0
gboolean _camera_initialize(const dt_camctl_t *c, dt_camera_t *cam)
{
  dt_camctl_t *camctl=(dt_camctl_t *)c;
  CameraAbilities a;
  GPPortInfo pi;
  if( cam->gpcam==NULL )
  {
    gp_camera_new(&cam->gpcam);
    int m = gp_abilities_list_lookup_model( c->gpcams, cam->model );
    gp_abilities_list_get_abilities (c->gpcams, m, &a);
    gp_camera_set_abilities (cam->gpcam, a);

    int p = gp_port_info_list_lookup_path (c->gpports, cam->port);
    gp_port_info_list_get_info (c->gpports, p, &pi);
    gp_camera_set_port_info (cam->gpcam , pi);

    // Check for abilities
    if( (a.operations&GP_OPERATION_CAPTURE_IMAGE) ) cam->can_tether=TRUE;
    if( (a.operations&GP_OPERATION_CAPTURE_PREVIEW) ) cam->can_live_view=TRUE;
    if(  cam->can_tether && (a.operations&GP_OPERATION_CONFIG) ) cam->can_config=TRUE;
    if( !(a.file_operations&GP_FILE_OPERATION_NONE) ) cam->can_import=TRUE;

    if( gp_camera_init( cam->gpcam ,  camctl->gpcontext) != GP_OK )
    {
      dt_print(DT_DEBUG_CAMCTL,"[camera_control] failed to initialize camera %s on port %s\n", cam->model,cam->port);
      return FALSE;
    }

    // read a full copy of config to configuration cache
    gp_camera_get_config( cam->gpcam, &cam->configuration, c->gpcontext );

    // TODO: find a more robust way for this, once we find out how to do it with non-EOS cameras
    if(cam->can_live_view && dt_camctl_camera_property_exists(camctl, cam, "eoszoomposition"))
      cam->can_live_view_advanced = TRUE;

    // initialize timeout callbacks eg. keep alive, some cameras needs it.
    cam->gpcontext = camctl->gpcontext;
    gp_camera_set_timeout_funcs(cam->gpcam,
                                (CameraTimeoutStartFunc)_camera_start_timeout_func,
                                (CameraTimeoutStopFunc)_camera_stop_timeout_func,
                                cam);


    dt_pthread_mutex_init(&cam->jobqueue_lock, NULL);

    dt_print(DT_DEBUG_CAMCTL,"[camera_control] device %s on port %s initialized\n", cam->model,cam->port);
  }
  else
    dt_print(DT_DEBUG_CAMCTL,"[camera_control] device %s on port %s already initialized\n", cam->model,cam->port);

  return TRUE;
}
Ejemplo n.º 6
0
int initCamera(){
	gp_camera_new(&my_Camera);
	my_Context = gp_context_new();

	int result = gp_camera_init(my_Camera, my_Context);
	printf("\n\nCamera Init Result: %d\n\n", result);

	if(result == -105){
		printf("Camera not found, quitting.\n\n");
		return -105;
	} 
	
	return 0;
}
Ejemplo n.º 7
0
/**
 * Connects to selected device.
 */
bool DigitalCameraCapture::open(int index)
{
    const char * model = 0, *path = 0;
    int m, p;
    GPPortInfo portInfo;

    if (isOpened()) {
        close();
    }

    try
    {
        CR(gp_camera_new(&camera));
        CR(gp_list_get_name(allDevices, index, &model));
        CR(gp_list_get_value(allDevices, index, &path));

        // Set model abilities.
        CR(m = gp_abilities_list_lookup_model(abilitiesList, model));
        CR(gp_abilities_list_get_abilities(abilitiesList, m, &cameraAbilities));
        CR(gp_camera_set_abilities(camera, cameraAbilities));

        // Set port
        CR(p = gp_port_info_list_lookup_path(capablePorts, path));
        CR(gp_port_info_list_get_info(capablePorts, p, &portInfo));
        CR(gp_camera_set_port_info(camera, portInfo));

        // Initialize connection to the camera.
        CR(gp_camera_init(camera, context));

        message(STATUS, "connected camera", model);
        message(STATUS, "connected using", path);

        // State initialization
        firstCapturedFrameTime = 0;
        capturedFrames = 0;
        preview = false;
        reloadOnChange = false;
        collectMsgs = false;

        reloadConfig();

        opened = true;
        return true;
    }
    catch (GPhoto2Exception & e)
    {
        message(WARNING, "opening device failed", e);
        return false;
    }
}
Ejemplo n.º 8
0
int initCamera(){
    gp_camera_new(&my_Camera);
    my_Context = gp_context_new();

    int result = gp_camera_init(my_Camera, my_Context);
    printf(" Camera Init Result: %d ", result);

    if(result == -105){
        printf(" Camera not found, quitting. ");
        return -105;
    }
    printf(" camera successfully found!\n");	

    return 0;
}
Ejemplo n.º 9
0
bool photo_camera::photo_camera_open( photo_camera_list* list, const std::string model_name, const std::string port_name )
{
  // Create a context if necessary
  if( context_ == NULL )
  {
    context_ = photo_camera_create_context();
  }

  // Create new camera
  if( gp_camera_new( &camera_ ) != GP_OK )
  {
    photo_reporter::error( "gp_camera_new()" );
    return false;
  }

  // Find and set camera abilities based on model
  //std::cout << "Model name: " << model_name << " == " << std::endl;
  if( list->lookupAbilities( model_name, &abilities_ ) == true )
  {
    // Set the camera's abilities
    if( gp_camera_set_abilities( camera_, abilities_ ) != GP_OK )
    {
      photo_reporter::error( "gp_camera_set_abilities()" );
      return false;
    }
  }
  else
  {
    return false;
  }

  // Associate camera with port
  if( list->lookupPortInfo( port_name, &port_info_ ) == true )
  {
    if( gp_camera_set_port_info( camera_, port_info_ ) != GP_OK )
    {
      photo_reporter::error( "gp_camera_set_port_info()" );
      return false;
    }
  }
  else
  {
    return false;
  }

  // Camera is open!
  return true;
}
Ejemplo n.º 10
0
	CameraController() {
		int	retval;
		context = sample_create_context();

		gp_log_add_func(GP_LOG_ERROR, errordumper, NULL);
		gp_camera_new(&camera);

		printf("Camera init.  Takes a few seconds.\n");
		signal(SIGTERM, handle_sigterm);
		retval = gp_camera_init(camera, context);
		if (retval != GP_OK) {
			printf("  Retval: %d\n", retval);
			exit (1);
		}

	}
Ejemplo n.º 11
0
bool Image_GPhoto::initCamera(GPhotoCamera& camera)
{
    lock_guard<recursive_mutex> lock(_gpMutex);

    if (camera.cam == nullptr)
    {
        gp_camera_new(&camera.cam);

        int m = gp_abilities_list_lookup_model(_gpCams, camera.model.c_str());
        CameraAbilities abilities{};
        gp_abilities_list_get_abilities(_gpCams, m, &abilities);
        gp_camera_set_abilities(camera.cam, abilities);

        int p = gp_port_info_list_lookup_path(_gpPorts, camera.port.c_str());
        GPPortInfo portInfo;
        gp_port_info_list_get_info(_gpPorts, p, &portInfo);
        gp_camera_set_port_info(camera.cam, portInfo);

        if (abilities.operations & GP_OPERATION_CAPTURE_IMAGE)
        {
            camera.canTether = true;
            if (abilities.operations & GP_OPERATION_CONFIG)
                camera.canConfig = true;
        }
        if (!(abilities.file_operations & GP_FILE_OPERATION_NONE))
            camera.canImport = true;

        if (gp_camera_init(camera.cam, _gpContext) != GP_OK)
            return false;

        gp_camera_get_config(camera.cam, &camera.configuration, _gpContext);

        // Get the available shutterspeeds
        initCameraProperty(camera, "shutterspeed", camera.shutterspeeds);
        initCameraProperty(camera, "aperture", camera.apertures);
        initCameraProperty(camera, "iso", camera.isos);

        return true;
    }
    else
    {
        Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Camera " << camera.model << " already initialized" << Log::endl;
        return false;
    }
}
Ejemplo n.º 12
0
/**
 * @brief QTLCamera::initCamera
 * @return
 */
QTLError QTLCamera::initCamera() {
    QTLError result;
    result.rc = GP_OK;
    result.errorText = "Camera initialized.";

    // Set aside memory for camera
    result.rc = gp_camera_new(&params->camera);
    if (result.rc != GP_OK) {
        result.errorText = gp_result_as_string(result.rc);
        return result;
    }

    // Initialise camera
    qDebug() << "Detecting Camera.";
    result.rc = gp_camera_init(params->camera, params->context);

    if (result.rc != GP_OK) {
        result.errorText = gp_result_as_string(result.rc);

        if (result.rc == -105) {
            result.errorText = "Failed to initialise camera. Please check the camera " \
                    "is turned on, then re-initialise or restart the program to enable" \
                    " camera paramaters.";
        } else if (result.rc == -60 || result.rc == -53) {
            result.errorText = "Failed to initialise camera. Please check the camera " \
                    "is unmounted and that no other applications are using it, then " \
                    "re-initialise or restart the program to enable camera paramaters.";
        }
    } else {
        qDebug() << "Camera detected";
        qDebug() << "Detecting widgets" << endl;
        CameraWidget *rootConfig;
        result.rc = gp_camera_get_config(params->camera, &rootConfig, params->context);
        if (result.rc == GP_OK) {
            char prefix[] = "";
            _getWidgets(params->widgetList, rootConfig, prefix);
            gp_widget_free(rootConfig);
        }
        qDebug() << "Widgets detected";
    }

    return result;
}
Ejemplo n.º 13
0
int main(int argc, char **argv) {
	Camera		*camera;
	int		ret;
	char		*owner;
	GPContext	*context;
	CameraText	text;

	context = sample_create_context (); /* see context.c */
	gp_camera_new (&camera);

	/* This call will autodetect cameras, take the
	 * first one from the list and use it. It will ignore
	 * any others... See the *multi* examples on how to
	 * detect and use more than the first one.
	 */
	ret = gp_camera_init (camera, context);
	if (ret < GP_OK) {
		printf("No camera auto detected.\n");
		gp_camera_free (camera);
		return 0;
	}

	/* Simple query the camera summary text */
	ret = gp_camera_get_summary (camera, &text, context);
	if (ret < GP_OK) {
		printf("Camera failed retrieving summary.\n");
		gp_camera_free (camera);
		return 0;
	}
	printf("Summary:\n%s\n", text.text);

	/* Simple query of a string configuration variable. */
	ret = get_config_value_string (camera, "owner", &owner, context);
	if (ret >= GP_OK) {
		printf("Owner: %s\n", owner);
		free (owner);
	}
	gp_camera_exit (camera, context);
	gp_camera_free (camera);
	gp_context_unref (context);
	return 0;
}
Ejemplo n.º 14
0
int main(int argc, char **argv) {
	Camera		*camera;
	int		ret;
	char		*owner;
	GPContext	*context;

	context = sample_create_context (); /* see context.c */

	gp_log_add_func(GP_LOG_ERROR, errordumper, NULL);

	gp_camera_new (&camera);

	/* This call will autodetect cameras, take the
	 * first one from the list and use it. It will ignore
	 * any others... See the *multi* examples on how to
	 * detect and use more than the first one.
	 */
	ret = gp_camera_init (camera, context);
	if (ret < GP_OK) {
		printf("No camera auto detected.\n");
		gp_camera_free (camera);
		return 0;
	}

	ret = get_config_value_string (camera, "ownername", &owner, context);
	if (ret < GP_OK) {
		printf ("Could not query owner.\n");
		goto out;
	}
	printf("Current owner: %s\n", owner);
	if (argc > 1) {
		ret = set_config_value_string (camera, "ownername", argv[1], context);
		if (ret < GP_OK) {
			fprintf (stderr, "Failed to set camera owner to %s; %d\n", argv[1], ret);
		} else 
			printf("New owner: %s\n", argv[1]);
	}
out:
	gp_camera_exit (camera, context);
	gp_camera_free (camera);
	return 0;
}
void GPhotoCameraWorker::openCamera()
{
    // Camera is already open
    if (m_camera)
        return;

    setStatus(QCamera::LoadingStatus);

    // Create camera object
    int ret = gp_camera_new(&m_camera);
    if (ret != GP_OK) {
        openCameraErrorHandle("Unable to open camera");
        return;
    }

    ret = gp_camera_set_abilities(m_camera, m_abilities);
    if (ret < GP_OK) {
        openCameraErrorHandle("Unable to set abilities for camera");
        return;
    }

    ret = gp_camera_set_port_info(m_camera, m_portInfo.portInfo);
    if (ret < GP_OK) {
        openCameraErrorHandle("Unable to set port info for camera");
        return;
    }

    ret = gp_file_new(&m_file);
    if (ret < GP_OK) {
        openCameraErrorHandle("Could not create capture file");
        return;
    }

    if (parameter("viewfinder").isValid()) {
        if (!setParameter("viewfinder", true))
            qWarning() << "Failed to flap up camera mirror";
    }

    m_capturingFailCount = 0;
    setStatus(QCamera::LoadedStatus);
}
Ejemplo n.º 16
0
bool photoController::initCamera()
{
	gp_camera_new (&camera);
	DEBUG_PRINTF(V_MESSAGE, "Camera initialization (gp_camera_init).\n");
	int retval = gp_camera_init(camera, context);
	if (retval != GP_OK) 
	{
		DEBUG_PRINTF(V_WARNING, "Could not detect any camera!\n");
		camera_detected = false;        
		gp_camera_unref(camera);
		camera = NULL;
		// TODO - Retry camera initialization, if fails, signalize with led (and TCP message?).
	}
	else
	{
		DEBUG_PRINTF(V_MESSAGE, "Camera detected!\n");
		camera_detected = true;
		setPhotoQuality();
	}
	return camera_detected;
}
Ejemplo n.º 17
0
// function to make sure the camara is initalised
void initCamaraAndContext() {

	if(resetNextTime) {
		tc_reset();
		resetNextTime = false;
	}

	if( context == NULL && camera == NULL ) {
		context = create_context ();
		gp_camera_new (&camera);

		if( gp_camera_init (camera, context) < GP_OK ) {
			initFailed = true;
			tc_reset();
		}
		else {
			internal_set_setting("capture", "1");
			initFailed = false;
		}
	}
}
Ejemplo n.º 18
0
int
main(int argc, char **argv) {
	Camera	*camera;
	int	retval;
	GPContext *context = sample_create_context();
	FILE 	*f;
	char	*data;
	unsigned long size;

	gp_log_add_func(GP_LOG_ERROR, errordumper, NULL);
	gp_camera_new(&camera);

	/* When I set GP_LOG_DEBUG instead of GP_LOG_ERROR above, I noticed that the
	 * init function seems to traverse the entire filesystem on the camera.  This
	 * is partly why it takes so long.
	 * (Marcus: the ptp2 driver does this by default currently.)
	 */
	printf("Camera init.  Takes about 10 seconds.\n");
	retval = gp_camera_init(camera, context);
	if (retval != GP_OK) {
		printf("  Retval of capture_to_file: %d\n", retval);
		exit (1);
	}
	capture_to_file(camera, context, "foo.jpg");

	capture_to_memory(camera, context, (const char**)&data, &size);

	f = fopen("foo2.jpg", "wb");
	if (f) {
		retval = fwrite (data, size, 1, f);
		if (retval != size) {
			printf("  fwrite size %ld, written %d\n", size, retval);
		}
		fclose(f);
	} else
		printf("  fopen foo2.jpg failed.\n");
	gp_camera_exit(camera, context);
	return 0;
}
Ejemplo n.º 19
0
void
gp_params_init (GPParams *p, char **envp)
{
	if (!p)
		return;

	memset (p, 0, sizeof (GPParams));

	p->folder = strdup ("/");
	if (!p->folder) {
		fprintf (stderr, _("Not enough memory."));
		fputc ('\n', stderr);
		exit (1);
	}

	gp_camera_new (&p->camera);

	p->cols = 79;
	p->flags = FLAGS_RECURSE;

	/* Create a context. Report progress only if users will see it. */
	p->context = gp_context_new ();
	gp_context_set_cancel_func    (p->context, ctx_cancel_func,  p);
	gp_context_set_error_func     (p->context, ctx_error_func,   p);
	gp_context_set_status_func    (p->context, ctx_status_func,  p);
	gp_context_set_message_func   (p->context, ctx_message_func, p);
	if (isatty (STDOUT_FILENO))
		gp_context_set_progress_funcs (p->context,
			ctx_progress_start_func, ctx_progress_update_func,
			ctx_progress_stop_func, p);

	p->_abilities_list = NULL;

	p->debug_func_id = -1;

	p->envp = envp;
}
Ejemplo n.º 20
0
int		init(t_cam *c)
{
  c->liveview = 0;
  c->liveview_fps = 30;
  c->liveview_fps_time = 1000000 / 30;
  pthread_mutex_init(&c->liveview_mutex, NULL);
  pthread_cond_init(&c->liveview_condvar, NULL);
  c->folder_path = strdup("/tmp/");
  c->camera_value_list = NULL;

  gp_context_set_error_func(c->context, (GPContextErrorFunc)error_func, NULL);
  gp_context_set_message_func(c->context, (GPContextMessageFunc)message_func, NULL);

  gp_camera_new(&c->camera);
  c->context = gp_context_new();
  printf("Camera Init\n");
  c->ret = gp_camera_init(c->camera, c->context);
  if (c->ret != GP_OK) {
    printf("gp_camera_init: %d\n", c->ret);
    return (GP_ERROR);
  }
  /*  get_initial_camera_values(t_cam *c); */
  return (GP_OK);
}
Ejemplo n.º 21
0
int main (int argc, char** argv)
{
      std::cout<<"GP_OK = "<<GP_OK<<std::endl;

      GPContext *currentContext = NULL;
      gp_context_new();

      Camera *camera=NULL;
      gp_camera_new (&camera);
      gp_camera_init (camera, currentContext);

      CameraAbilitiesList * abilitiesList;
      CameraAbilities  abilities;
      CameraAbilities * ptr_abilities;
      ptr_abilities = &abilities;
      int haveListAbilities = gp_abilities_list_get_abilities (abilitiesList, 0, ptr_abilities);
      std::cout<<"haveListAbilities : "<< haveListAbilities<<std::endl;

     /* int haveAbilities = gp_camera_set_abilities(camera, abilities);
      std::cout<<"haveAbilities : "<< haveAbilities<<std::endl;*/

/*      //in case camera driver can't figure out the current camera's speed
      //gp_camera_set_port_path or name => pas TROUVE
      int speed; //AURA BESOIN D4UNE VALEUR (???)
      int hasSpeed = gp_camera_set_port_speed (camera, speed);
*/



      //to know port's camera
      GPPortInfo info;
      GPPortInfo * ptr_info;
      ptr_info = &info;
     /* int infoSetted = gp_camera_set_port_info (camera, info);
      std::cout<<"infoSetted : "<< infoSetted<<std::endl;*/


      ///
      int infoGetted = gp_camera_get_port_info(camera, ptr_info);
      std::cout<<"infoGetted : "<< infoGetted<<std::endl;


      //To have a window with camera's config
      CameraWidget ** widget;
      CameraWidgetType type;
      const char *label;
      int widgetCreated = gp_widget_new (type, label, widget);
      std::cout<<"widgetCreated : "<< widgetCreated<<std::endl;

      //get config
      int configGetted = gp_camera_get_config (camera, widget, currentContext);
      std::cout<<"configGetted : "<< configGetted<<std::endl;

      //set the configuration's camera
//      int cameraSetted = gp_camera_set_config (camera, *widget, currentContext);
//      std::cout<<"cameraSetted : "<< cameraSetted<<std::endl;


      //HAVE TO FIND FUNCTION WHICH GET/SET THE PÄTH
      CameraFilePath * path;
      //IDEM
      CameraCaptureType typeCapture;
      CameraFileType typeFile; //mm type à priori
      //capture
      int captured = gp_camera_capture (camera, typeCapture, path, currentContext);
      std::cout<<"captured : "<< captured<<std::endl;

      //To get capture from camera to computer
      //folder on computer
      //TO COMPLETE
      const char *folder = "../pictures";
      //TO COMPLETE
      //(devra être renseigné en fonction du numéro de la photoprécédente par ex)
      const char *file = "picture001";

      //??
      CameraFile * camera_file;
      int captureGetted = gp_camera_file_get(camera, folder, file, typeFile,camera_file, currentContext);
      std::cout<<"captureGetted : "<< captureGetted<<std::endl;


      int indiceCountCamera = gp_camera_unref (camera);



        //Before the end of using camera => better!
        int cameraExited = gp_camera_exit (camera, currentContext);

        return EXIT_SUCCESS;
}
Ejemplo n.º 22
0
bool GPCamera::doConnect()
{
#ifdef HAVE_GPHOTO2
    int errorCode;

    // -- first step - setup the camera --------------------

    if (d->camera)
    {
        gp_camera_unref(d->camera);
        d->camera = 0;
    }

    CameraAbilitiesList* abilList = 0;
    GPPortInfoList*      infoList = 0;
    GPPortInfo           info;

    gp_camera_new(&d->camera);

    delete d->status;
    d->status = 0;
    d->status = new GPStatus();

    gp_abilities_list_new(&abilList);
    gp_abilities_list_load(abilList, d->status->context);
    gp_port_info_list_new(&infoList);
    gp_port_info_list_load(infoList);

    int modelNum     = gp_abilities_list_lookup_model(abilList, m_model.toLatin1().constData());
    int portNum      = gp_port_info_list_lookup_path(infoList, m_port.toLatin1().constData());

    gp_abilities_list_get_abilities(abilList, modelNum, &d->cameraAbilities);

    errorCode    = gp_camera_set_abilities(d->camera, d->cameraAbilities);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to set camera Abilities!";
        printGphotoErrorDescription(errorCode);
        gp_camera_unref(d->camera);
        d->camera = 0;
        gp_abilities_list_free(abilList);
        gp_port_info_list_free(infoList);
        return false;
    }

    if (m_model != QLatin1String("Directory Browse"))
    {
        gp_port_info_list_get_info(infoList, portNum, &info);
        errorCode = gp_camera_set_port_info(d->camera, info);

        if (errorCode != GP_OK)
        {
            qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to set camera port!";
            printGphotoErrorDescription(errorCode);
            gp_camera_unref(d->camera);
            d->camera = 0;
            gp_abilities_list_free(abilList);
            gp_port_info_list_free(infoList);
            return false;
        }
    }

    gp_abilities_list_free(abilList);
    gp_port_info_list_free(infoList);

    if (d->cameraAbilities.file_operations &
        GP_FILE_OPERATION_PREVIEW)
    {
        m_thumbnailSupport = true;
    }

    if (d->cameraAbilities.file_operations &
        GP_FILE_OPERATION_DELETE)
    {
        m_deleteSupport = true;
    }

    if (d->cameraAbilities.folder_operations &
        GP_FOLDER_OPERATION_PUT_FILE)
    {
        m_uploadSupport = true;
    }

    if (d->cameraAbilities.folder_operations &
        GP_FOLDER_OPERATION_MAKE_DIR)
    {
        m_mkDirSupport = true;
    }

    if (d->cameraAbilities.folder_operations &
        GP_FOLDER_OPERATION_REMOVE_DIR)
    {
        m_delDirSupport = true;
    }

    if (d->cameraAbilities.operations &
        GP_OPERATION_CAPTURE_IMAGE)
    {
        m_captureImageSupport = true;
    }

    if (d->cameraAbilities.operations &
        GP_OPERATION_CAPTURE_PREVIEW)
    {
        m_captureImagePreviewSupport = true;
    }

    // -- Try and initialize the camera to see if its connected -----------------

    errorCode = gp_camera_init(d->camera, d->status->context);

    if (errorCode != GP_OK)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to initialize camera!";
        printGphotoErrorDescription(errorCode);
        gp_camera_unref(d->camera);
        d->camera = 0;
        return false;
    }

    d->cameraInitialized = true;

    return true;
#else
    return false;
#endif /* HAVE_GPHOTO2 */
}
Ejemplo n.º 23
0
int cameraFunction(int command) {
    int i, retval, ss, commandint;

    gp_camera_new(&canon);
    canoncontext = gp_context_new();
    gp_log_add_func(GP_LOG_ERROR, errordumper, NULL);
    printf("Camera init.  Takes about 3 seconds.\n");
    retval = gp_camera_init(canon, canoncontext);
    if (retval != GP_OK) {
        printf("  Retval: %d\n", retval);
        exit(1);
    } else {
        printf("okay");
    }

    canon_enable_capture(canon, TRUE, canoncontext);


    printf("ready to rock\n");

    //i = getchar();
    //getchar();
    //commandint = atoi(command);
    switch (command) {
    case 'c': {
        capture(canon, canoncontext);
        break;
    }
    case 's': {
        ss = getchar();
        getchar();
        printf("ss is %c\n", ss);
        shutterchange(canon, canoncontext, ss);
        break;
    }
    case 'a': {
        int ap;
        ap = getchar();
        getchar();
        aperturechange(canon, canoncontext, ap);
        printf("aperture: %d", ap);
        break;
    }
    case 'i': {
        int iso;
        iso = getchar();
        getchar();
        isochange(canon, canoncontext, iso);
        printf("iso: %d", iso);
        break;
    }
    case 'l': {
        while (1) {
            liveview(canon, canoncontext);
        }
        break;
    }
    case 'q': {
        gp_camera_exit(canon, canoncontext);
        break;
    }
    default:
        capture(canon, canoncontext);
        return 0;

    }

    return 0;
} //end of code
Ejemplo n.º 24
0
int
main(int argc, char **argv) {
	Camera	*canon;
	int	i, retval;
	GPContext *canoncontext = sample_create_context();

	gp_log_add_func(GP_LOG_ERROR, errordumper, 0);
	gp_camera_new(&canon);

	/* When I set GP_LOG_DEBUG instead of GP_LOG_ERROR above, I noticed that the
	 * init function seems to traverse the entire filesystem on the camera.  This
	 * is partly why it takes so long.
	 * (Marcus: the ptp2 driver does this by default currently.)
	 */
	printf("Camera init.  Takes about 10 seconds.\n");
	retval = gp_camera_init(canon, canoncontext);
	if (retval != GP_OK) {
		printf("  Retval: %d\n", retval);
		exit (1);
	}
	canon_enable_capture(canon, TRUE, canoncontext);
	retval = camera_eosviewfinder(canon,canoncontext,1);
	if (retval != GP_OK) {
		fprintf(stderr,"camera_eosviewfinder(1): %d\n", retval);
		exit(1);
	}
	/*set_capturetarget(canon, canoncontext);*/
	printf("Taking 100 previews and saving them to snapshot-XXX.jpg ...\n");
	for (i=0;i<100;i++) {
		CameraFile *file;
		char output_file[32];

		fprintf(stderr,"preview %d\n", i);
		retval = gp_file_new(&file);
		if (retval != GP_OK) {
			fprintf(stderr,"gp_file_new: %d\n", retval);
			exit(1);
		}

		/* autofocus every 10 shots */
		if (i%10 == 9) {
			camera_auto_focus (canon, canoncontext, 1);
			/* FIXME: wait a bit and/or poll events ? */
			camera_auto_focus (canon, canoncontext, 0);
		} else {
			camera_manual_focus (canon, (i/10-5)/2, canoncontext);
		}
#if 0 /* testcase for EOS zooming */
		{
			char buf[20];
			if (i<10) set_config_value_string (canon, "eoszoom", "5", canoncontext);
			sprintf(buf,"%d,%d",(i&0x1f)*64,(i>>5)*64);
			fprintf(stderr, "%d - %s\n", i, buf);
			set_config_value_string (canon, "eoszoomposition", buf, canoncontext);
		}
#endif
		retval = gp_camera_capture_preview(canon, file, canoncontext);
		if (retval != GP_OK) {
			fprintf(stderr,"gp_camera_capture_preview(%d): %d\n", i, retval);
			exit(1);
		}
		sprintf(output_file, "snapshot-%03d.jpg", i);
		retval = gp_file_save(file, output_file);
		if (retval != GP_OK) {
			fprintf(stderr,"gp_camera_capture_preview(%d): %d\n", i, retval);
			exit(1);
		}
		gp_file_unref(file);
	/*
		sprintf(output_file, "image-%03d.jpg", i);
	        capture_to_file(canon, canoncontext, output_file);
	*/
	}
	retval = camera_eosviewfinder(canon,canoncontext,0);
	if (retval != GP_OK) {
		fprintf(stderr,"camera_eosviewfinder(0): %d\n", retval);
		exit(1);
	}

	sleep(10);
	gp_camera_exit(canon, canoncontext);
	return 0;
}
Ejemplo n.º 25
0
static GnoCamCamera *
gnocam_main_get_camera (GnoCamMain *gm, const gchar *model, const gchar *port,
		        CORBA_Environment *ev)
{
	Camera *camera;
	GnoCamCamera *gc = NULL;

	g_message ("Trying to get a camera for model '%s' (port '%s')...",
		   model, port);

	g_return_val_if_fail (GNOCAM_IS_MAIN (gm), NULL);

	gc = gnocam_cache_lookup (gm->priv->cache, model, port);
	if (gc) {
		bonobo_object_ref (gc);
		return gc;
	}

	CR (gp_camera_new (&camera), ev);
	if (BONOBO_EX (ev))
		return (CORBA_OBJECT_NIL);

	if (model && strlen (model)) {
		CameraAbilities a;
		CameraAbilitiesList *al = NULL;
		int m;

	        memset (&a, 0, sizeof (CameraAbilities));
	        gp_abilities_list_new (&al);
	        gp_abilities_list_load (al, NULL);
	        m = gp_abilities_list_lookup_model (al, model);
	        gp_abilities_list_get_abilities (al, m, &a);
	        gp_abilities_list_free (al);
		CR (gp_camera_set_abilities (camera, a), ev);
		if (BONOBO_EX (ev)) {
			gp_camera_unref (camera);
			return NULL;
		}
	}

	if (port && strlen (port)) {
		GPPortInfo info;
		GPPortInfoList *il = NULL;
		int p;

		memset (&info, 0, sizeof (GPPortInfo));
		gp_port_info_list_new (&il);
		gp_port_info_list_load (il);
		p = gp_port_info_list_lookup_name (il, port);
		if (p < 0)
			p = gp_port_info_list_lookup_path (il, port);
		gp_port_info_list_get_info (il, p, &info);
		gp_port_info_list_free (il);
		CR (gp_camera_set_port_info (camera, info), ev); 
		if (BONOBO_EX (ev)) { 
			gp_camera_unref (camera);
			return (CORBA_OBJECT_NIL);
		}
	}

        CR (gp_camera_init (camera, NULL), ev);
        if (BONOBO_EX (ev)) {
                gp_camera_unref (camera); 
                return NULL;
        }

        gc = gnocam_camera_new (camera, ev);
        gp_camera_unref (camera);
        if (BONOBO_EX (ev))
                return NULL;

	gnocam_cache_add (gm->priv->cache, gc);

        g_message ("Successfully created a camera.");

	return gc;
}
Ejemplo n.º 26
0
static TW_UINT16
GPHOTO2_OpenDS( pTW_IDENTITY pOrigin, pTW_IDENTITY self) {
    int ret, m, p, count, i;
    CameraAbilities a;
    GPPortInfo info;
    const char	*model, *port;

    if (TWRC_SUCCESS != gphoto2_auto_detect())
	return TWRC_FAILURE;

    if (lstrcmpA(self->ProductFamily,"GPhoto2 Camera")) {
	FIXME("identity passed is not a gphoto camera, but %s!?!\n", self->ProductFamily);
	return TWRC_FAILURE;
    }
    count = gp_list_count (detected_cameras);
    if (!count) {
	ERR("No camera found by autodetection. Returning failure.\n");
	return TWRC_FAILURE;
    }

    if (!lstrcmpA (self->ProductName, "GPhoto2 Camera")) {
	TRACE("Potential undetected camera. Just using the first autodetected one.\n");
	i = 0;
    } else {
	for (i=0;i<count;i++) {
	    const char *cname, *pname;
	    TW_STR32	name;

	    gp_list_get_name  (detected_cameras, i, &cname);
	    gp_list_get_value (detected_cameras, i, &pname);
	    if (!lstrcmpA(self->ProductName,cname))
		break;
	    snprintf(name, sizeof(name), "%s", cname);
	    if (!lstrcmpA(self->ProductName,name))
		break;
	    snprintf(name, sizeof(name), "%s@%s", cname, pname);
	    if (!lstrcmpA(self->ProductName,name))
		break;
        }
        if (i == count) {
	    TRACE("Camera %s not found in autodetected list. Using first entry.\n", self->ProductName);
	    i=0;
        }
    }
    gp_list_get_name  (detected_cameras, i, &model);
    gp_list_get_value  (detected_cameras, i, &port);
    TRACE("model %s, port %s\n", model, port);
    ret = gp_camera_new (&activeDS.camera);
    if (ret < GP_OK) {
	ERR("gp_camera_new: %d\n", ret);
	return TWRC_FAILURE;
    }
    m = gp_abilities_list_lookup_model (abilities_list, model);
    if (m < GP_OK) {
	FIXME("Model %s not found, %d!\n", model, m);
	return TWRC_FAILURE;
    }
    ret = gp_abilities_list_get_abilities (abilities_list, m, &a);
    if (ret < GP_OK) {
	FIXME("gp_camera_list_get_abilities failed? %d\n", ret);
	return TWRC_FAILURE;
    }
    ret = gp_camera_set_abilities (activeDS.camera, a);
    if (ret < GP_OK) {
	FIXME("gp_camera_set_abilities failed? %d\n", ret);
	return TWRC_FAILURE;
    }

    p = gp_port_info_list_lookup_path (port_list, port);
    if (p < GP_OK) {
	FIXME("port %s not in portlist?\n", port);
	return TWRC_FAILURE;
    }
    ret = gp_port_info_list_get_info (port_list, p, &info);
    if (ret < GP_OK) {
	FIXME("could not get portinfo for port %s?\n", port);
	return TWRC_FAILURE;
    }
    ret = gp_camera_set_port_info (activeDS.camera, info);
    if (ret < GP_OK) {
	FIXME("could not set portinfo for port %s to camera?\n", port);
	return TWRC_FAILURE;
    }
    list_init( &(activeDS.files) );
    activeDS.currentState = 4;
    activeDS.twCC 		= TWRC_SUCCESS;
    activeDS.pixelflavor	= TWPF_CHOCOLATE;
    activeDS.pixeltype		= TWPT_RGB;
    activeDS.capXferMech	= TWSX_MEMORY;
    TRACE("OK!\n");
    return TWRC_SUCCESS;
}
Ejemplo n.º 27
0
static GtkamCamera *
gtkam_chooser_get_camera (GtkamChooser *chooser)
{
	GtkWidget *dialog, *status;
	GPPortInfo info;
	Camera *camera;
	CameraAbilities abilities;
	const gchar *model, *port, *speed;
	gchar *port_path, *right, *tmp;
	int m, p, r;
	gboolean multi;
	GtkamCamera *c;

	model = gtk_entry_get_text (chooser->priv->entry_model);
	port  = gtk_entry_get_text (chooser->priv->entry_port);
	speed = gtk_entry_get_text (chooser->priv->entry_speed);
	multi = GTK_TOGGLE_BUTTON (chooser->priv->check_multi)->active;

	if (!port || !*port)
		port_path = g_strdup (_("None"));
	else {
		port_path = g_strdup (port);
		right = strrchr (port_path, ')');
		*right = '\0';
		tmp = g_strdup (strrchr (port_path, '(') + 1);
		g_free (port_path);
		port_path = tmp;
	}

	gp_camera_new (&camera);
#ifdef HAVE_GP_CAMERA_SET_TIMEOUT_FUNCS
	gp_camera_set_timeout_funcs (camera, start_timeout_func,
				     stop_timeout_func, NULL);
#endif

	/* Model? */
	m = gp_abilities_list_lookup_model (chooser->priv->al, model);
	gp_abilities_list_get_abilities (chooser->priv->al, m, &abilities);
	gp_camera_set_abilities (camera, abilities);

	/* Port? */
	if (strcmp (port_path, _("None"))) {
		p = gp_port_info_list_lookup_path (chooser->priv->il,
						   port_path);
		gp_port_info_list_get_info (chooser->priv->il, p, &info);
		gp_camera_set_port_info (camera, info);
	}

	/* Speed? */
	if (strcmp (speed, _("Best")))
		gp_camera_set_port_speed (camera, atoi (speed));

	/*
	 * Initialize the camera to check if it is really there. Exit
	 * afterwards because other applications could need the camera, too.
	 */
	status = gtkam_status_new (_("Initializing camera..."));
	gtkam_dialog_add_status (GTKAM_DIALOG (chooser), status);
	r = gp_camera_init (camera, GTKAM_STATUS (status)->context->context);
	if (multi)
		gp_camera_exit (camera, NULL);
	switch (r) {
	case GP_OK:
		break;
	case GP_ERROR_CANCEL:
		g_free (port_path);
		break;
	default:
		g_free (port_path);
		dialog = gtkam_error_new (r, GTKAM_STATUS (status)->context,
			NULL, _("Could not initialize camera."));
		gtk_window_set_transient_for (GTK_WINDOW (dialog),
					      GTK_WINDOW (chooser));
		gtk_widget_show (dialog);
		gp_camera_unref (camera);
		camera = NULL;
	}
	gtk_object_destroy (GTK_OBJECT (status));

	c = gtkam_camera_new (camera, multi);
	gp_camera_unref (camera);

	return (c);
}
Ejemplo n.º 28
0
int
main (int argc, char **argv)
{
    fd_set rs;
    struct timeval tv;
    int n, cmd_len;
    char cmd[PATH_MAX + 32];
    const char *arg;
    GFParams params;

    memset (&params, 0, sizeof (GFParams));
    if (gp_camera_new (&(params.camera)) < 0)
        goto ExitError;
    if (gp_abilities_list_new (&(params.al)) < 0)
        goto ExitError;
    if (gp_abilities_list_load (params.al, NULL) < 0)
        goto ExitError;
    if (gp_port_info_list_new (&params.il) < 0)
        goto ExitError;
    if (gp_port_info_list_load (params.il) < 0)
        goto ExitError;
    params.folder = malloc (strlen ("/") + 1);
    if (!params.folder)
        goto ExitError;
    strcpy (params.folder, "/");
    params.idletime = 1800;

    n = sizeof (struct sockaddr_in);
    if (getsockname (0, (struct sockaddr *) &params.sai_sock, &n)) {
        fprintf (stdout, "421 Can not get name of sock.\r\n");
        fflush (stdout);
        goto ExitError;
    }
    n = sizeof (struct sockaddr_in);
    if (getpeername (0, (struct sockaddr *) &params.sai_peer, &n)) {
        fprintf (stdout, "421 Can not get name of peer.\r\n");
        fflush (stdout);
        goto ExitError;
    }
    n = IPTOS_LOWDELAY;
    setsockopt (0, IPPROTO_IP, IP_TOS, (char *) &n, sizeof (int));

    fprintf (stdout, "220-Hello and welcome to the wonderful world\r\n");
    fprintf (stdout, "220-of gphoto!\r\n");
    fprintf (stdout, "220-\r\n");
    fprintf (stdout, "220-Use this server like a standard FTP-Server.\r\n");
    fprintf (stdout, "220-List files in virtual directory\r\n");
    fflush (stdout);
    fprintf (stdout, "220-'/capture-image' in order to capture\r\n");
    fflush (stdout);
    fprintf (stdout, "220-an image, in '/capture-preview' in order\r\n");
    fflush (stdout);
    fprintf (stdout, "220-to capture a preview.\r\n");
    fflush (stdout);
    fprintf (stdout, "220 FTP server ready.\r\n");
    fflush (stdout);

    while (1) {

        /* Read something. */
        syslog (LOG_INFO, "Reading...");
        FD_ZERO (&rs);
        tv.tv_sec = 1800;
        tv.tv_usec = 0;
        memset (cmd, 0, sizeof (cmd));
        cmd_len = n = 0;
        while (1) {
            if (!n) {
                FD_SET (0, &rs);
                select (1, &rs, NULL, NULL, &tv);
                if (ioctl (0, FIONREAD, &n) < 0)
                    n = 0;
            }
            if (FD_ISSET (0, &rs)) {
                if (read (0, cmd + cmd_len, 1) <= 0)
                    goto ExitError;
                if (n)
                    n--;
                if (cmd[cmd_len] == '\n') {
                    cmd[cmd_len + 1] = '\0';
                    break;
                }
                if (cmd_len < sizeof (cmd) - 2)
                    cmd_len++;
            } else
                goto ExitError;
        }

        syslog (LOG_INFO, "Got '%s'...", cmd);
        for (n = 0; isalpha (cmd[n]) && n < sizeof (cmd); n++)
            cmd[n] = tolower (cmd[n]);
        if (!n) {
            printf ("%3d %s\r\n", 221, "Goodbye.");
            fflush (stdout);
            goto ExitOk;
        }
        while (isspace (cmd[n]) && n < sizeof (cmd))
            cmd[n++] = '\0';
        arg = cmd + n;
        while (cmd[n] && n < sizeof (cmd))
            n++;
        n--;
        while (isspace (cmd[n]))
            cmd[n--] = '\0';
        syslog (LOG_INFO, "Processing '%s' - '%s'...", cmd, arg);
        if (!strcasecmp (cmd, "cwd")) {
            gf_cwd (&params, arg);
        } else if (!strcasecmp (cmd, "list")) {
            if (gf_list (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "noop")) {
            fprintf (stdout, "200 NOOP command successful.\r\n");
            fflush (stdout);
        } else if (!strcasecmp (cmd, "pass")) {
            if (gf_pass (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "pasv")) {
            gf_pasv (&params);
        } else if (!strcasecmp (cmd, "port")) {
            if (gf_port (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "pwd") ||
                   !strcasecmp (cmd, "xpwd")) {
            fprintf (stdout, "257 \"%s\"\r\n", params.folder);
            fflush (stdout);
        } else if (!strcasecmp (cmd, "quit")) {
            printf ("%3d %s\r\n", 221, "Goodbye.");
            fflush (stdout);
            syslog (LOG_INFO, "Quit.");
            return (0);
        } else if (!strcasecmp (cmd, "retr")) {
            if (gf_retr (&params, arg) < 0)
                goto ExitError;
        } else if (!strcasecmp (cmd, "syst")) {
            printf ("215 UNIX Type: L8\r\n");
            fflush (stdout);
        } else if (!strcasecmp (cmd, "type")) {
            if (!arg)
                goto ExitError;
            gf_type (&params, *arg);
        } else if (!strcasecmp (cmd, "user")) {
            if (gf_user (&params, arg) < 0)
                goto ExitError;
        } else {
            syslog (LOG_INFO, "Command '%s'...", cmd);
            printf ("%3d %s\r\n", 550, "Unknown command.");
            fflush (stdout);
        }
    }

ExitError:
    gp_abilities_list_free (params.al);
    gp_port_info_list_free (params.il);
    gp_camera_unref (params.camera);
    gp_file_unref (params.file);
    free (params.camera);
    syslog (LOG_INFO, "Error: 1");
    return (1);

ExitOk:
    gp_abilities_list_free (params.al);
    gp_port_info_list_free (params.il);
    gp_camera_unref (params.camera);
    gp_file_unref (params.file);
    free (params.camera);
    return (0);
}
Ejemplo n.º 29
0
int input_run(int id)
{
	int res, i;

	global->in[id].buf = malloc(256 * 1024);
	if(global->in[id].buf == NULL)
	{
		IPRINT(INPUT_PLUGIN_NAME " - could not allocate memory\n");
		exit(EXIT_FAILURE);
	}
	plugin_id = id;

	// auto-detect algorithm
	CameraAbilitiesList* al;
	GPPortInfoList* il;
	CameraList* list;
	const char* model;
	const char* port;
	context = gp_context_new();
	gp_abilities_list_new(&al);
	gp_abilities_list_load(al, context);
	gp_port_info_list_new(&il);
	gp_port_info_list_load(il);
	gp_list_new(&list);
	gp_abilities_list_detect(al, il, list, context);
	int count = gp_list_count(list);
	IPRINT(INPUT_PLUGIN_NAME " - Detected %d camera(s)\n", count);
	if(count == 0)
	{
		IPRINT(INPUT_PLUGIN_NAME " - No cameras detected.\n");
		return 0;
	}
	GPPortInfo info;
	CameraAbilities a;
	int m, p;
	camera = NULL;
	for(i = 0; i < count; i++)
	{
		res = gp_list_get_name(list, i, &model);
		CAMERA_CHECK_GP(res, "gp_list_get_name");
		m = gp_abilities_list_lookup_model(al, model);
		if(m < 0)
		{
			IPRINT(INPUT_PLUGIN_NAME " - Gphoto abilities_list_lookup_model Code: %d - %s\n", m, gp_result_as_string(m));
			return 0;
		}
		res = gp_abilities_list_get_abilities(al, m, &a);
		CAMERA_CHECK_GP(res, "gp_abilities_list_get_abilities");
		res = gp_list_get_value(list, i, &port);
		CAMERA_CHECK_GP(res, "gp_list_get_value"); DBG("Model: %s; port: %s.\n", model, port);
		if(selected_port != NULL && strcmp(selected_port, port) != 0)
			continue;
		p = gp_port_info_list_lookup_path(il, port);
		if(p < 0)
		{
			IPRINT(INPUT_PLUGIN_NAME " - Gphoto port_info_list_lookup_path Code: %d - %s\n", m, gp_result_as_string(m));
			return 0;
		}
		res = gp_port_info_list_get_info(il, p, &info);
		CAMERA_CHECK_GP(res, "gp_port_info_list_get_info");

		res = gp_camera_new(&camera);
		CAMERA_CHECK_GP(res, "gp_camera_new");
		res = gp_camera_set_abilities(camera, a);
		CAMERA_CHECK_GP(res, "gp_camera_set_abilities");
		res = gp_camera_set_port_info(camera, info);
		CAMERA_CHECK_GP(res, "gp_camera_set_port_info");
	}
	if(camera == NULL)
	{
		IPRINT("Camera %s not found, exiting.\n", selected_port);
		exit(EXIT_FAILURE);
	}
	// cleanup
	gp_list_unref(list);
	gp_port_info_list_free(il);
	gp_abilities_list_free(al);

	// open camera and set capture on
	int value = 1;
	res = gp_camera_init(camera, context);
	CAMERA_CHECK_GP(res, "gp_camera_init");
	camera_set("capture", &value);

	// starting thread
	if(pthread_create(&thread, 0, capture, NULL) != 0)
	{
		free(global->in[id].buf);
		IPRINT("could not start worker thread\n");
		exit(EXIT_FAILURE);
	}
	pthread_detach(thread);

	return 0;
}