int main(int argc, char **argv) {
    CameraList	*list;
    Camera		**cams;
    int		ret, i, count;
    const char	*name, *value;
    GPContext	*context;

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

    /* Detect all the cameras that can be autodetected... */
    ret = gp_list_new (&list);
    if (ret < GP_OK) return 1;
    count = sample_autodetect (list, context);

    /* Now open all cameras we autodected for usage */
    printf("Number of cameras: %d\n", count);
    cams = calloc (sizeof (Camera*),count);
    for (i = 0; i < count; i++) {
        gp_list_get_name  (list, i, &name);
        gp_list_get_value (list, i, &value);
        ret = sample_open_camera (&cams[i], name, value, context);
        if (ret < GP_OK) fprintf(stderr,"Camera %s on port %s failed to open\n", name, value);
    }
    /* Now call a simple function in each of those cameras. */
    for (i = 0; i < count; i++) {
        CameraText	text;
        char 		*owner;
        ret = gp_camera_get_summary (cams[i], &text, context);
        if (ret < GP_OK) {
            fprintf (stderr, "Failed to get summary.\n");
            continue;
        }

        gp_list_get_name  (list, i, &name);
        gp_list_get_value (list, i, &value);
        printf("%-30s %-16s\n", name, value);
        printf("Summary:\n%s\n", text.text);

        /* Query a simple string configuration variable. */
        ret = get_config_value_string (cams[i], "owner", &owner, context);
        if (ret >= GP_OK) {
            printf("Owner: %s\n", owner);
            free (owner);
        } else {
            printf("Owner: No owner found.\n");
        }

    }
    return 0;
}
Esempio n. 2
0
static TW_UINT16
GPHOTO2_GetIdentity( pTW_IDENTITY pOrigin, pTW_IDENTITY self) {
    int count;
    const char *cname, *pname;

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

    count = gp_list_count (detected_cameras);
    if (count < GP_OK) {
	gp_list_free (detected_cameras);
	return TWRC_FAILURE;
    }
    TRACE("%d cameras detected.\n", count);
    self->ProtocolMajor = TWON_PROTOCOLMAJOR;
    self->ProtocolMinor = TWON_PROTOCOLMINOR;
    lstrcpynA (self->Manufacturer, "The Wine Team", sizeof(self->Manufacturer) - 1);
    lstrcpynA (self->ProductFamily, "GPhoto2 Camera", sizeof(self->ProductFamily) - 1);

    if (!count) { /* No camera detected. But we need to return an IDENTITY anyway. */
	lstrcpynA (self->ProductName, "GPhoto2 Camera", sizeof(self->ProductName) - 1);
	return TWRC_SUCCESS;
    }
    gp_list_get_name  (detected_cameras, curcamera, &cname);
    gp_list_get_value (detected_cameras, curcamera, &pname);
    if (count == 1) /* Normal case, only one camera. */
	snprintf (self->ProductName, sizeof(self->ProductName), "%s", cname);
    else
	snprintf (self->ProductName, sizeof(self->ProductName), "%s@%s", cname, pname);
    curcamera = (curcamera+1) % count;
    return TWRC_SUCCESS;
}
Esempio n. 3
0
int cam_detect_camera (GPParams *gp_params)
{
	int x, count;
    CameraList *list;
    const char *name = NULL, *value = NULL;
	int ret = 0;
	
	_get_portinfo_list (gp_params);
	if  ( (ret = gp_list_new (&list)) < 0)
		goto err_no;
    gp_abilities_list_detect (gp_params_abilities_list(gp_params), gp_params->portinfo_list, list, gp_params->context);


    if ((ret = count = gp_list_count (list)) < 0)
		goto err_list;

    LOG_I(("%-30s %-16s\n"), ("Model"), ("Port"));
    LOG_I(("----------------------------------------------------------\n"));
    for (x = 0; x < count; x++) {
            (gp_list_get_name  (list, x, &name), list);
            (gp_list_get_value (list, x, &value), list);
            LOG_I(("%-30s %-16s\n"), name, value);
    }
	gp_list_free (list);
	
    return count;
err_list:
	gp_list_free (list);
err_no:
	return ret;
}
bool photo_camera_list::filterCameraList( GPContext* context, const std::string match_string )
{
  CameraList *working_list = NULL;
  const char *name, *value;
  int count = 0;

  if( gp_list_new( &working_list ) != GP_OK )
  {
    photo_reporter::error( "gp_list_new()" );
    gp_list_free( working_list );
    return false;
  }

  // Autodetect the currently attached photo_cameras.
  if( gp_abilities_list_detect( abilities_list_, port_info_list_, working_list, context) != GP_OK )
  {
    photo_reporter::error( "gp_abilities_list_detect()" );
    gp_list_free( working_list );
    return false;
  }
  
 
  count = gp_list_count( working_list );
  if( count < GP_OK )
  {
    photo_reporter::error( "gp_list_count()" );
    gp_list_free( working_list );
    return false;
  }
  
  // Clear camera_list_ for appending
  if( gp_list_reset( camera_list_ ) != GP_OK )
  {
    photo_reporter::error( "gp_list_reset()" );
    gp_list_free( working_list );
    return false;
  }

  // Filter out the generic 'usb:' entry
  for( int i = 0; i < count; i++ )
  {

    gp_list_get_name( working_list, i, &name );
    gp_list_get_value( working_list, i, &value );

    if( match_string.compare( value ) != 0 )
    {
      gp_list_append( camera_list_, name, value );
    }
  }
  
  gp_list_free( working_list );

  return true;
}
Esempio n. 5
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;
    }
}
Esempio n. 6
0
/**
 * Autodetect all detectable camera
 *
 * @param list a #CameraList that receives the autodetected cameras
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * This camera will autodetected all cameras that can be autodetected.
 * This will for instance detect all USB cameras.
 *
 *   CameraList *list;
 *   gp_list_new (&list);
 *   gp_camera_autodetect (list, context);
 *   ... done! ...
 */
int
gp_camera_autodetect (CameraList *list, GPContext *context)
{
	CameraAbilitiesList	*al = NULL;
	GPPortInfoList		*il = NULL;
	int			ret, i;
	CameraList		*xlist = NULL;

	ret = gp_list_new (&xlist);
	if (ret < GP_OK) goto out;
	if (!il) {
		/* Load all the port drivers we have... */
		ret = gp_port_info_list_new (&il);
		if (ret < GP_OK) goto out;
		ret = gp_port_info_list_load (il);
		if (ret < 0) goto out;
		ret = gp_port_info_list_count (il);
		if (ret < 0) goto out;
	}
	/* Load all the camera drivers we have... */
	ret = gp_abilities_list_new (&al);
	if (ret < GP_OK) goto out;
	ret = gp_abilities_list_load (al, context);
	if (ret < GP_OK) goto out;

	/* ... and autodetect the currently attached cameras. */
        ret = gp_abilities_list_detect (al, il, xlist, context);
	if (ret < GP_OK) goto out;

	/* Filter out the "usb:" entry */
        ret = gp_list_count (xlist);
	if (ret < GP_OK) goto out;
	for (i=0;i<ret;i++) {
		const char *name, *value;

		gp_list_get_name (xlist, i, &name);
		gp_list_get_value (xlist, i, &value);
		if (!strcmp ("usb:",value)) continue;
		gp_list_append (list, name, value);
	}
out:
	if (il) gp_port_info_list_free (il);
	if (al) gp_abilities_list_free (al);
	gp_list_free (xlist);
	if (ret < GP_OK)
		return ret;
	return gp_list_count(list);
}
Esempio n. 7
0
bool photo_camera::photo_camera_open( photo_camera_list* list, int n )
{
  const char *name, *value; 

  gp_list_get_name( list->getCameraList(), n, &name);
  gp_list_get_value( list->getCameraList(), n, &value);
 
  std::cout << "Opening camera " << n << " by name (" << name << ") and value (" << value << ")" << std::endl;

  if( photo_camera_open( list, name, value ) == false )
  {
    photo_reporter::error( "photo_camera_open()" );
    return false;
  }
  return true;
}
Esempio n. 8
0
void Image_GPhoto::detectCameras()
{
    lock_guard<recursive_mutex> lock(_gpMutex);

    if (_gpPorts != nullptr)
        gp_port_info_list_free(_gpPorts);
    gp_port_info_list_new(&_gpPorts);
    gp_port_info_list_load(_gpPorts);

    CameraList* availableCameras = nullptr;
    gp_list_new(&availableCameras);
    gp_abilities_list_detect(_gpCams, _gpPorts, availableCameras, _gpContext);

    Log::get() << Log::MESSAGE << "Image_GPhoto::" << __FUNCTION__ << " - " << (gp_list_count(availableCameras) > 0 ? gp_list_count(availableCameras) : 0) << " cameras detected"
               << Log::endl;

    // Create the list of tetherable cameras
    for (int i = 0; i < gp_list_count(availableCameras); ++i)
    {
        GPhotoCamera camera;
        const char* s;
        gp_list_get_name(availableCameras, i, &s);
        camera.model = string(s);
        gp_list_get_value(availableCameras, i, &s);
        camera.port = string(s);

        if (!initCamera(camera))
        {
            releaseCamera(camera);
            Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Unable to initialize camera " << camera.model << " on port " << camera.port << Log::endl;
        }
        else if (!camera.canTether && !camera.canImport)
        {
            releaseCamera(camera);
            Log::get() << Log::WARNING << "Image_GPhoto::" << __FUNCTION__ << " - Camera " << camera.model << " on port " << camera.port << " does not support import or tethering"
                       << Log::endl;
        }
        else
        {
            releaseCamera(camera);
            _cameras.push_back(camera);
            Log::get() << Log::MESSAGE << "Image_GPhoto::" << __FUNCTION__ << " - Camera " << camera.model << " on port " << camera.port << " initialized correctly" << Log::endl;
        }
    }
}
Esempio n. 9
0
std::vector<std::shared_ptr<Camera>> Context::all_cameras() {
	auto list = GP_NEW_UNIQUE(CameraList, gp_list);
	int ret;
	if ((ret = gp_camera_autodetect(list.get(), context)) < GP_OK) {
		throw Exception("gp_camera_autodetect", ret);
	}

    std::vector<std::shared_ptr<Camera>> cams;
	for (int i = 0, count = ret; i < count; i++) {
		const char *name, *value;
		gp_list_get_name(list.get(), i, &name);
		gp_list_get_value(list.get(), i, &value);
		// XXX: remove this debug message?
		std::cout << name << "|" << value << std::endl;
		// cannot emplace because private ctor
        cams.push_back(std::shared_ptr<Camera>(new Camera(name, value, *this)));
	}
	return cams;
}
Esempio n. 10
0
void dt_camctl_detect_cameras(const dt_camctl_t *c)
{

  dt_camctl_t *camctl=(dt_camctl_t *)c;
  dt_pthread_mutex_lock(&camctl->lock);

  /* reload portdrivers */
  if (camctl->gpports)
    gp_port_info_list_free (camctl->gpports);

  gp_port_info_list_new( &camctl->gpports );
  gp_port_info_list_load( camctl->gpports );
  dt_print(DT_DEBUG_CAMCTL,"[camera_control] loaded %d port drivers.\n", gp_port_info_list_count( camctl->gpports ) );



  CameraList *available_cameras=NULL;
  gp_list_new( &available_cameras );
  gp_abilities_list_detect (c->gpcams,c->gpports, available_cameras, c->gpcontext );
  dt_print(DT_DEBUG_CAMCTL,"[camera_control] %d cameras connected\n",gp_list_count( available_cameras )>0?gp_list_count( available_cameras ):0);


  for(int i=0; i<gp_list_count( available_cameras ); i++)
  {
    dt_camera_t *camera=g_malloc(sizeof(dt_camera_t));
    memset( camera,0,sizeof(dt_camera_t));
    gp_list_get_name (available_cameras, i, &camera->model);
    gp_list_get_value (available_cameras, i, &camera->port);
    dt_pthread_mutex_init(&camera->config_lock, NULL);
    dt_pthread_mutex_init(&camera->live_view_pixbuf_mutex, NULL);
    dt_pthread_mutex_init(&camera->live_view_synch, NULL);

    // if(strcmp(camera->port,"usb:")==0) { g_free(camera); continue; }
    GList *citem;
    if( (citem=g_list_find_custom(c->cameras,camera,_compare_camera_by_port)) == NULL || strcmp(((dt_camera_t *)citem->data)->model,camera->model)!=0 )
    {
      if(citem==NULL)
      {
        // Newly connected camera
        if(_camera_initialize(c,camera)==FALSE)
        {
          dt_print(DT_DEBUG_CAMCTL,"[camera_control] failed to initialize device %s on port %s, probably causes are: locked by another application, no access to udev etc.\n", camera->model,camera->port);
          g_free(camera);
          continue;
        }

        // Check if camera has capabililties for being presented to darktable
        if( camera->can_import==FALSE && camera->can_tether==FALSE )
        {
          dt_print(DT_DEBUG_CAMCTL,"[camera_control] device %s on port %s doesn't support import or tether, skipping device.\n", camera->model,camera->port);
          g_free(camera);
          continue;
        }

        // Fetch some summary of camera
        if( gp_camera_get_summary(camera->gpcam, &camera->summary, c->gpcontext) == GP_OK )
        {
          // Remove device property summary:
          char *eos=strstr(camera->summary.text,"Device Property Summary:\n");
          if (eos) eos[0]='\0';
        }

        // Add to camera list
        camctl->cameras = g_list_append(camctl->cameras,camera);

        // Notify listeners of connected camera
        _dispatch_camera_connected(camctl,camera);
      }
    }
    else
      g_free(camera);
  }

  /* check c->cameras in available_cameras */
  if( c->cameras && g_list_length(c->cameras)>0)
  {
    GList *citem = c->cameras;
    do
    {
      int index=0;
      dt_camera_t *cam=(dt_camera_t *)citem->data;
      if (gp_list_find_by_name(available_cameras,&index,cam->model)!= GP_OK)
      {
        /* remove camera from cached list.. */
        dt_camctl_t *camctl=(dt_camctl_t *)c;
        dt_camera_t *oldcam = (dt_camera_t *)citem->data;
        camctl->cameras=citem= g_list_delete_link (c->cameras,citem);
        g_free(oldcam);
      }
    }
    while ( citem && (citem=g_list_next(citem))!=NULL);
  }

  dt_pthread_mutex_unlock(&camctl->lock);
}
Esempio n. 11
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;
}
Esempio n. 12
0
void KKameraConfig::load(bool useDefaults )
{
	m_config->setReadDefaults( useDefaults );
	QStringList groupList = m_config->groupList();
	QStringList::Iterator it;
        int i, count;
        CameraList *list;
        CameraAbilitiesList *al;
        GPPortInfoList *il;
        const char *model, *value;
	KCamera *kcamera;
	
	for (it = groupList.begin(); it != groupList.end(); it++) {
		if (*it != "<default>")	{
			m_config->setGroup(*it);
			if (m_config->readEntry("Path").contains("usb:"))
				continue;

			kcamera = new KCamera(*it,m_config->readEntry("Path"));
			connect(kcamera, SIGNAL(error(const QString &)), SLOT(slot_error(const QString &)));
			connect(kcamera, SIGNAL(error(const QString &, const QString &)), SLOT(slot_error(const QString &, const QString &)));
			kcamera->load(m_config);
			m_devices[*it] = kcamera;
		}
	}
	m_cancelPending = false;

	gp_list_new (&list);

        gp_abilities_list_new (&al);
        gp_abilities_list_load (al, m_context);
        gp_port_info_list_new (&il);
        gp_port_info_list_load (il);
        gp_abilities_list_detect (al, il, list, m_context);
        gp_abilities_list_free (al);
        gp_port_info_list_free (il);

        count = gp_list_count (list);

	QMap<QString,QString>	ports, names;
	
	for (i = 0 ; i<count ; i++) {
		gp_list_get_name  (list, i, &model);
		gp_list_get_value (list, i, &value);

		ports[value] = model;
		if (!strcmp(value,"usb:"))
			names[model] = value;
	}
	if (ports.contains("usb:") && names[ports["usb:"]]!="usb:")
		ports.remove("usb:");

	QMap<QString,QString>::iterator portit;

	for (portit = ports.begin() ; portit != ports.end(); portit++) {
		/* kdDebug() << "Adding USB camera: " << portit.data() << " at " << portit.key() << endl; */

		kcamera = new KCamera(portit.data(),portit.key());
		connect(kcamera, SIGNAL(error(const QString &)), SLOT(slot_error(const QString &)));
		connect(kcamera, SIGNAL(error(const QString &, const QString &)), SLOT(slot_error(const QString &, const QString &)));
		m_devices[portit.data()] = kcamera;
	}
	populateDeviceListView();

	gp_list_free (list);

	emit changed( useDefaults );
}
Esempio n. 13
0
bool GPCamera::findConnectedUsbCamera(int vendorId, int productId, QString& model, QString& port)
{
#ifdef HAVE_GPHOTO2
    CameraAbilitiesList* abilList = 0;
    GPPortInfoList*      list     = 0;
    GPContext*           context  = 0;
    CameraList*          camList  = 0;
    bool                 success  = false;
    // get name and port of detected camera
    const char* model_str         = 0;
    const char* port_str          = 0;
    context                       = gp_context_new();

    // get list of all ports
    gp_port_info_list_new(&list);
    gp_port_info_list_load(list);

    gp_abilities_list_new(&abilList);
    // get list of all supported cameras
    gp_abilities_list_load(abilList, context);

    // autodetect all cameras, then match the list to the passed in USB ids
    gp_list_new (&camList);
    gp_abilities_list_detect(abilList, list, camList, context);
    gp_context_unref(context);

    int count = gp_list_count(camList);
    int cnt   = 0;

    for (int i = 0 ; i < count ; i++)
    {
        const char* xmodel = 0;
        gp_list_get_name(camList, i, &xmodel);
        int model          = gp_abilities_list_lookup_model (abilList, xmodel);
        CameraAbilities ab;
        gp_abilities_list_get_abilities(abilList, model, &ab);

        if (ab.port != GP_PORT_USB)
            continue;

        /* KDE provides us USB Vendor and Product, but we might just
         * have covered this via a class match. Check class matched
         * cameras also for matchingo USB vendor/product id
         */
        if (ab.usb_vendor == 0)
        {
            int ret;
            GPPortInfo info;
            const char* xport = 0;
            GPPort* gpport    = 0;

            /* get the port path so we only look at this bus position */
            gp_list_get_value(camList, i, &xport);
            ret = gp_port_info_list_lookup_path (list, xport);

            if (ret < GP_OK) /* should not happen */
                continue;

            /* get the lowlevel port info  for the path
             */
            gp_port_info_list_get_info(list, ret, &info);

            /* open lowlevel driver interface briefly to search */
            gp_port_new(&gpport);
            gp_port_set_info(gpport, info);

            /* And now call into the lowlevel usb driver to see if the bus position
             * has that specific vendor/product id
             */
            if (gp_port_usb_find_device(gpport, vendorId, productId) == GP_OK)
            {
                ab.usb_vendor  = vendorId;
                ab.usb_product = productId;
            }

            gp_port_free (gpport);
        }

        if (ab.usb_vendor != vendorId)
            continue;

        if (ab.usb_product != productId)
            continue;

        /* keep it, and continue iterating, in case we find another one
         */
        gp_list_get_name (camList, i, &model_str);
        gp_list_get_value(camList, i, &port_str);

        cnt++;
    }

    gp_port_info_list_free(list);
    gp_abilities_list_free(abilList);

    if (cnt > 0)
    {
       if (cnt > 1)
       {
          qCWarning(DIGIKAM_IMPORTUI_LOG) << "More than one camera detected on port " << port
                                  << ". Due to restrictions in the GPhoto2 API, "
                                  << "only the first camera is used.";
       }

       model   = QString::fromLatin1(model_str);
       port    = QString::fromLatin1(port_str);
       success = true;
    }
    else
    {
       qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to get information for the listed camera";
    }

    gp_list_free(camList);
    return success;
#else
    Q_UNUSED(vendorId);
    Q_UNUSED(productId);
    Q_UNUSED(model);
    Q_UNUSED(port);
    return false;
#endif /* HAVE_GPHOTO2 */
}
Esempio n. 14
0
int GPCamera::autoDetect(QString& model, QString& port)
{
#ifdef HAVE_GPHOTO2
    CameraList*          camList   = 0;
    CameraAbilitiesList* abilList  = 0;
    GPPortInfoList*      infoList  = 0;
    const char*          camModel_ = 0, *camPort_ = 0;
    GPContext*           context   = 0;
    context                        = gp_context_new();

    gp_list_new(&camList);

    gp_abilities_list_new(&abilList);
    gp_abilities_list_load(abilList, context);
    gp_port_info_list_new(&infoList);
    gp_port_info_list_load(infoList);
    gp_abilities_list_detect(abilList, infoList, camList, context);
    gp_abilities_list_free(abilList);
    gp_port_info_list_free(infoList);

    gp_context_unref(context);

    int count = gp_list_count(camList);

    if (count <= 0)
    {
        qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to autodetect camera!";
        printGphotoErrorDescription(count);
        gp_list_free(camList);
        return -1;
    }

    camModel_ = 0;
    camPort_  = 0;

    for (int i = 0; i < count; i++)
    {
        if (gp_list_get_name(camList, i, &camModel_) != GP_OK)
        {
            qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to autodetect camera!";
            gp_list_free(camList);
            return -1;
        }

        if (gp_list_get_value(camList, i, &camPort_) != GP_OK)
        {
            qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to autodetect camera!";
            gp_list_free(camList);
            return -1;
        }

        if (camModel_ && camPort_)
        {
            model = QString::fromLatin1(camModel_);
            port  = QString::fromLatin1(camPort_);
            gp_list_free(camList);
            return 0;
        }
    }

    qCDebug(DIGIKAM_IMPORTUI_LOG) << "Failed to autodetect camera!";
    gp_list_free(camList);
#else
    Q_UNUSED(model);
    Q_UNUSED(port);
#endif /* HAVE_GPHOTO2 */
    return -1;
}
Esempio n. 15
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;
}
Esempio n. 16
0
/**
 * Initiate a connection to the \c camera. 
 *
 * @param camera a #Camera
 * @param context a #GPContext
 * @return a gphoto2 error code
 *
 * Before calling this function, the
 * \c camera should be set up using #gp_camera_set_port_path or
 * #gp_camera_set_port_name and #gp_camera_set_abilities. If that has been
 * omitted, gphoto2 tries to autodetect any cameras and chooses the first one
 * if any cameras are found. It is generally a good idea to call
 * #gp_camera_exit after transactions have been completed in order to give
 * other applications the chance to access the camera, too.
 *
 */
int
gp_camera_init (Camera *camera, GPContext *context)
{
	CameraAbilities a;
	const char *model, *port;
	CameraLibraryInitFunc init_func;
	int result;

	gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Initializing camera...");

	CHECK_NULL (camera);
	/*
	 * Reset the exit_requested flag. If this flag is set, 
	 * gp_camera_exit will be called as soon as the camera is no
	 * longer in use (used flag).
	 */
	camera->pc->exit_requested = 0;

	/*
	 * If the model hasn't been indicated, try to
	 * figure it out (USB only). Beware of "Directory Browse".
	 */
	if (strcasecmp (camera->pc->a.model, "Directory Browse") &&
	    !strcmp ("", camera->pc->a.model)) {
		CameraAbilitiesList *al;
		GPPortInfo	pinfo;
		GPPortInfoList	*il;
		int		m, p;
		GPPortInfo	info;
        	CameraList	*list;

		result = gp_list_new (&list);
		if (result < GP_OK)
			return result;

		result = gp_port_get_info (camera->port, &pinfo);
		if (result < GP_OK)
			return result;

		gp_log (GP_LOG_DEBUG, "gphoto2-camera", "pinfo.type %d", pinfo.type);
		gp_log (GP_LOG_DEBUG, "gphoto2-camera", "pinfo.path %s", pinfo.path);
		gp_log (GP_LOG_DEBUG, "gphoto2-camera", "pinfo.name %s", pinfo.name);
		gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Neither "
			"port nor model set. Trying auto-detection...");

		/* Call auto-detect and choose the first camera */
		gp_abilities_list_new (&al);
		gp_abilities_list_load (al, context);
		gp_port_info_list_new (&il);
		gp_port_info_list_load (il);
		gp_abilities_list_detect (al, il, list, context);
		if (!gp_list_count (list)) {
			gp_abilities_list_free (al);
			gp_port_info_list_free (il);
			gp_context_error (context, _("Could not detect any camera"));
			gp_list_free (list);
			return (GP_ERROR_MODEL_NOT_FOUND);
		}
		p = 0;
		/* if the port was set before, then use that entry. but not if it is "usb:" */
		if (	(pinfo.type == GP_PORT_USB) &&
			strlen(pinfo.path) &&
			strcmp(pinfo.path,"usb:")
		) {
			for (p = gp_list_count (list);p--;) {
				const char *xp;

				gp_list_get_value (list, p, &xp);
				if (!strcmp (xp, pinfo.path))
					break;
			}
			if (p<0) {
				gp_context_error (context, _("Could not detect any camera at port %s"), pinfo.path);
				return (GP_ERROR_FILE_NOT_FOUND);
			}
		}

		gp_list_get_name  (list, p, &model);
		m = gp_abilities_list_lookup_model (al, model);
		gp_abilities_list_get_abilities (al, m, &a);
		gp_abilities_list_free (al);
		CRSL (camera, gp_camera_set_abilities (camera, a), context, list);
		CRSL (camera, gp_list_get_value (list, p, &port), context, list);
		p = gp_port_info_list_lookup_path (il, port);
		gp_port_info_list_get_info (il, p, &info);
		gp_port_info_list_free (il);
		CRSL (camera, gp_camera_set_port_info (camera, info), context, list);
		gp_list_free (list);
	}

	if (strcasecmp (camera->pc->a.model, "Directory Browse")) {
		switch (camera->port->type) {
		case GP_PORT_NONE:
			gp_context_error (context, _("You have to set the "
				"port prior to initialization of the camera."));
			return (GP_ERROR_UNKNOWN_PORT);
		case GP_PORT_USB:
			if (gp_port_usb_find_device (camera->port,
					camera->pc->a.usb_vendor,
					camera->pc->a.usb_product) != GP_OK) {
				CRS (camera, gp_port_usb_find_device_by_class
					(camera->port,
					camera->pc->a.usb_class,
					camera->pc->a.usb_subclass,
					camera->pc->a.usb_protocol), context);
					}
			break;
		default:
			break;
		}
	}

	/* Load the library. */
	gp_log (GP_LOG_DEBUG, "gphoto2-camera", "Loading '%s'...",
		camera->pc->a.library);
	lt_dlinit ();
	camera->pc->lh = lt_dlopenext (camera->pc->a.library);
	if (!camera->pc->lh) {
		gp_context_error (context, _("Could not load required "
			"camera driver '%s' (%s)."), camera->pc->a.library,
			lt_dlerror ());
		lt_dlexit ();
		return (GP_ERROR_LIBRARY);
	}

	/* Initialize the camera */
	init_func = lt_dlsym (camera->pc->lh, "camera_init");
	if (!init_func) {
		lt_dlclose (camera->pc->lh);
		lt_dlexit ();
		camera->pc->lh = NULL;
		gp_context_error (context, _("Camera driver '%s' is "
			"missing the 'camera_init' function."), 
			camera->pc->a.library);
		return (GP_ERROR_LIBRARY);
	}

	if (strcasecmp (camera->pc->a.model, "Directory Browse")) {
		result = gp_port_open (camera->port);
		if (result < 0) {
			lt_dlclose (camera->pc->lh);
			lt_dlexit ();
			camera->pc->lh = NULL;
			return (result);
		}
	}

	result = init_func (camera, context);
	if (result < 0) {
		gp_port_close (camera->port);
		lt_dlclose (camera->pc->lh);
		lt_dlexit ();
		camera->pc->lh = NULL;
		memset (camera->functions, 0, sizeof (CameraFunctions));
		return (result);
	}

	/* We don't care if that goes wrong */
#ifdef HAVE_MULTI
	gp_port_close (camera->port);
#endif

	return (GP_OK);
}