Beispiel #1
0
int main(int args, char *argv[]) {
    droid_media_init();

    int cameras = droid_media_camera_get_number_of_cameras();
    printf("%d cameras\n", cameras);

    for (int x = 0; x < cameras; x++) {
        DroidMediaCameraInfo info;

        if (!droid_media_camera_get_info(&info, x)) {
            printf("Failed to get camera %d info\n", x);
        }

        printf("Camera %d: Orientation: %d, facing: %d\n", x, info.orientation, info.facing);

        printf("Initializing camera %d\n", x);
        DroidMediaCamera *cam = droid_media_camera_connect(x);
        if (!cam) {
            printf("Failed\n");
            continue;
        }

        printf("Starting\n");

        if (!droid_media_camera_lock(cam)) {
            printf("Failed to lock camera\n");
            continue;
        }

        if (!droid_media_camera_start_preview(cam)) {
            printf("Failed\n");
            droid_media_camera_disconnect(cam);
            continue;
        }

        printf("Started\n");
        sleep(2);

        printf("Stopping\n");
        droid_media_camera_stop_preview(cam);
        droid_media_camera_unlock(cam);
        printf("Stopped\n");
        droid_media_camera_disconnect(cam);
    }

    droid_media_deinit();
}
Beispiel #2
0
gboolean
gst_droidcamsrc_dev_open (GstDroidCamSrcDev * dev, GstDroidCamSrcCamInfo * info)
{
  GstDroidCamSrc *src;

  g_rec_mutex_lock (dev->lock);

  src = GST_DROIDCAMSRC (GST_PAD_PARENT (dev->imgsrc->pad));

  GST_DEBUG_OBJECT (src, "dev open");

  dev->info = info;
  dev->cam = droid_media_camera_connect (dev->info->num);

  if (!dev->cam) {
    g_rec_mutex_unlock (dev->lock);

    GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL), ("error opening camera"));
    return FALSE;
  }

  dev->queue = droid_media_camera_get_buffer_queue (dev->cam);

  if (!droid_media_camera_lock (dev->cam)) {
    droid_media_camera_disconnect (dev->cam);
    dev->cam = NULL;
    dev->queue = NULL;

    GST_ELEMENT_ERROR (src, LIBRARY, INIT, (NULL), ("error locking camera"));
    return FALSE;
  }

  /* disable shutter sound */
  gst_droidcamsrc_dev_send_command (dev,
      dev->c.CAMERA_CMD_ENABLE_SHUTTER_SOUND, 0, 0);

  g_rec_mutex_unlock (dev->lock);

  return TRUE;
}