gboolean
gst_droidcamsrc_dev_start (GstDroidCamSrcDev * dev, gboolean apply_settings)
{
  gboolean ret = FALSE;
  GstDroidCamSrc *src = GST_DROIDCAMSRC (GST_PAD_PARENT (dev->imgsrc->pad));

  g_rec_mutex_lock (dev->lock);

  if (dev->running) {
    GST_WARNING_OBJECT (src, "preview is already running");
    ret = TRUE;
    goto out;
  }

  GST_DEBUG_OBJECT (src, "dev start");

  if (!gst_buffer_pool_set_active (dev->pool, TRUE)) {
    GST_ERROR_OBJECT (src, "Failed to activate buffer pool");
    goto out;
  }

  if (apply_settings) {
    gst_droidcamsrc_apply_mode_settings (src, SET_ONLY);
  }

  /* now set params */
  if (!gst_droidcamsrc_dev_set_params (dev)) {
    goto out;
  }

  if (dev->use_raw_data) {
    GST_INFO_OBJECT (src, "Using raw data mode");
    droid_media_camera_set_preview_callback_flags (dev->cam,
        dev->c.CAMERA_FRAME_CALLBACK_FLAG_CAMERA);
  } else {
    GST_INFO_OBJECT (src, "Using native buffers mode");
    droid_media_camera_set_preview_callback_flags (dev->cam,
        dev->c.CAMERA_FRAME_CALLBACK_FLAG_NOOP);
  }

  if (!droid_media_camera_start_preview (dev->cam)) {
    GST_ERROR_OBJECT (src, "error starting preview");
    goto out;
  }

  dev->running = TRUE;

  ret = TRUE;

out:
  if (ret != TRUE) {
    gst_buffer_pool_set_active (dev->pool, FALSE);
  }

  g_rec_mutex_unlock (dev->lock);
  return ret;
}
Exemple #2
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();
}