Logo Search packages:      
Sourcecode: libdc1394-22 version File versions  Download package

dc1394camera_t* dc1394_camera_new_unit ( dc1394_t *  dc1394,
uint64_t  guid,
int  unit 
)

Create a new camera based on a GUID and a unit number (for multi-unit cameras)

Definition at line 1972 of file control.c.

References __dc1394_camera::command_registers_base, dc1394_camera_new_unit(), __dc1394_camera::guid, __dc1394_camera::iidc_version, __dc1394_camera::model, __dc1394_camera::model_id, __dc1394_camera::unit, __dc1394_camera::unit_dependent_directory, __dc1394_camera::unit_directory, __dc1394_camera::unit_spec_ID, __dc1394_camera::unit_sub_sw_version, __dc1394_camera::unit_sw_version, __dc1394_camera::vendor, and __dc1394_camera::vendor_id.

Referenced by dc1394_camera_new(), and dc1394_camera_new_unit().

{
    int i;
    camera_info_t * info = NULL;
    platform_camera_t * pcam;
    uint32_t command_regs_base = 0;
    uint32_t vendor_name_offset = 0;
    uint32_t model_name_offset = 0;
    uint32_t unit_sub_sw_version = 0;
    uint32_t ghigh, glow, quad;
    uint32_t offset, num_entries;
    dc1394camera_t * camera;
    dc1394camera_priv_t * cpriv;

    if (!d->device_list)
        refresh_enumeration (d);

    for (i = 0; i < d->num_cameras; i++) {
        if (d->cameras[i].guid == guid &&
            (unit < 0 || d->cameras[i].unit == unit)) {
            info = d->cameras + i;
            break;
        }
    }
    if (!info)
        return NULL;

    pcam = platform_camera_new (d->platform, info->device, info->unit_dependent_directory);
    if (!pcam)
        return NULL;

    /* Check to make sure the GUID still matches. */
    if (platform_camera_read_quad (pcam, 0x40C, &ghigh) < 0 ||
        platform_camera_read_quad (pcam, 0x410, &glow) < 0)
        goto fail;

    if (ghigh != (info->guid >> 32) || glow != (info->guid & 0xffffffff))
        goto fail;

    if (platform_camera_read_quad (pcam, info->unit_dependent_directory, &quad) < 0)
        goto fail;

    num_entries = quad >> 16;
    offset = info->unit_dependent_directory + 4;
    for (i = 0; i < num_entries; i++) {
        if (platform_camera_read_quad (pcam, offset + 4 * i, &quad) < 0)
            goto fail;
        if ((quad >> 24) == 0x40)
            command_regs_base = quad & 0xffffff;
        else if ((quad >> 24) == 0x81) {
          /*
            The iSight version 1.0.3 has two 0x81 (vendor) leaves instead of a 0x81 and
            a 0x82 (model leaf). To go around this problem, we save the second vendor
            leaf as the model leaf. This is safe because if there is two 0x81 AND a 0x82,
            the real model leaf will overwrite the spurious second vendor string.
          */
          if (vendor_name_offset==0)
            vendor_name_offset = offset + 4 * ((quad & 0xffffff) + i);
          else
            model_name_offset = offset + 4 * ((quad & 0xffffff) + i);
      }
        else if ((quad >> 24) == 0x82)
            model_name_offset = offset + 4 * ((quad & 0xffffff) + i);
        else if ((quad >> 24) == 0x38)
            unit_sub_sw_version = quad & 0xffffff;
    }

    if (!command_regs_base)
        goto fail;

    camera = calloc (1, sizeof (dc1394camera_priv_t));
    cpriv = DC1394_CAMERA_PRIV (camera);

    cpriv->pcam = pcam;
    camera->guid = info->guid;
    camera->unit = info->unit;
    camera->unit_spec_ID = info->unit_spec_ID;
    camera->unit_sw_version = info->unit_sw_version;
    camera->unit_sub_sw_version = unit_sub_sw_version;
    camera->unit_directory = info->unit_directory;
    camera->unit_dependent_directory = info->unit_dependent_directory;
    camera->command_registers_base = command_regs_base * 4;
    camera->vendor_id = info->vendor_id;
    camera->model_id = info->model_id;

    camera->vendor = get_leaf_string (pcam, vendor_name_offset);
    camera->model = get_leaf_string (pcam, model_name_offset);

    if (camera->unit_spec_ID == 0xA02D) {
        if (info->unit_sw_version == 0x100)
            camera->iidc_version = DC1394_IIDC_VERSION_1_04;
        else if (info->unit_sw_version == 0x101)
            camera->iidc_version = DC1394_IIDC_VERSION_1_20;
        else if (info->unit_sw_version == 0x102) {
            camera->iidc_version = DC1394_IIDC_VERSION_1_30;
            // only add sub_sw_version if it is valid. Otherwise
            // consider that it's IIDC 1.30 (hence add nothing)
            if ((unit_sub_sw_version >> 4)<=9)
                camera->iidc_version += unit_sub_sw_version >> 4;
        }
    }
    else
        camera->iidc_version = DC1394_IIDC_VERSION_PTGREY;

    platform_camera_set_parent (cpriv->pcam, camera);
    update_camera_info (camera);

    return camera;

 fail:
    platform_camera_free (pcam);
    return NULL;
}


Generated by  Doxygen 1.6.0   Back to index