/* Base encoder initialization (internal) */
static gboolean
gst_vaapi_encoder_init (GstVaapiEncoder * encoder, GstVaapiDisplay * display)
{
  GstVaapiEncoderClass *const klass = GST_VAAPI_ENCODER_GET_CLASS (encoder);

  g_return_val_if_fail (display != NULL, FALSE);

#define CHECK_VTABLE_HOOK(FUNC) do {            \
    if (!klass->FUNC)                           \
      goto error_invalid_vtable;                \
  } while (0)

  CHECK_VTABLE_HOOK (init);
  CHECK_VTABLE_HOOK (finalize);
  CHECK_VTABLE_HOOK (get_default_properties);
  CHECK_VTABLE_HOOK (reconfigure);
  CHECK_VTABLE_HOOK (encode);
  CHECK_VTABLE_HOOK (reordering);
  CHECK_VTABLE_HOOK (flush);

#undef CHECK_VTABLE_HOOK

  encoder->display = gst_vaapi_display_ref (display);
  encoder->va_display = gst_vaapi_display_get_display (display);
  encoder->va_context = VA_INVALID_ID;

  gst_video_info_init (&encoder->video_info);

  g_mutex_init (&encoder->mutex);
  g_cond_init (&encoder->surface_free);
  g_cond_init (&encoder->codedbuf_free);

  encoder->codedbuf_queue = g_async_queue_new_full ((GDestroyNotify)
      gst_vaapi_coded_buffer_proxy_unref);
  if (!encoder->codedbuf_queue)
    return FALSE;

  if (!klass->init (encoder))
    return FALSE;
  if (!gst_vaapi_encoder_init_properties (encoder))
    return FALSE;
  return TRUE;

  /* ERRORS */
error_invalid_vtable:
  {
    GST_ERROR ("invalid subclass hook (internal error)");
    return FALSE;
  }
}
Exemple #2
0
GstVaapiDisplay *
video_output_create_display (const gchar * display_name)
{
  const VideoOutputInfo *o = g_video_output;
  GstVaapiDisplay *egl_display, *display = NULL;

  if (!o) {
    if (g_output_name)
      o = video_output_lookup (g_output_name);
    else {
      for (o = g_video_outputs; o->name != NULL; o++) {
        display = o->create_display (display_name);
        if (display) {
          if (gst_vaapi_display_get_display (display))
            break;
          gst_vaapi_display_unref (display);
          display = NULL;
        }
      }
    }
    if (!o || !o->name)
      return NULL;
    g_print ("Using %s video output\n", o->name);
    g_video_output = o;
  }

  if (!display)
    display = o->create_display (display_name);

  if (g_egl_mode) {
#if USE_EGL
    egl_display = gst_vaapi_display_egl_new (display, g_gles_version);
#else
    egl_display = NULL;
    g_print ("error: unsupported EGL renderering mode\n");
#endif
    gst_vaapi_display_unref (display);
    if (!egl_display)
      return NULL;
    display = egl_display;
  }
  return display;
}
int
main(int argc, char *argv[])
{
    GstVaapiDisplay *display, *display2;
    guint width, height, par_n, par_d;

    gst_init(&argc, &argv);

#if USE_DRM
    g_print("#\n");
    g_print("# Create display with gst_vaapi_display_drm_new()\n");
    g_print("#\n");
    {
        display = gst_vaapi_display_drm_new(NULL);
        if (!display)
            g_error("could not create Gst/VA display");

        dump_info(display);
        gst_vaapi_display_unref(display);
    }
    g_print("\n");

    g_print("#\n");
    g_print("# Create display with gst_vaapi_display_drm_new_with_device()\n");
    g_print("#\n");
    {
        int drm_device;

        drm_device = open(DRM_DEVICE_PATH, O_RDWR|O_CLOEXEC);
        if (drm_device < 0)
            g_error("could not open DRM device");

        display = gst_vaapi_display_drm_new_with_device(drm_device);
        if (!display)
            g_error("could not create Gst/VA display");

        dump_info(display);
        gst_vaapi_display_unref(display);
        close(drm_device);
    }
    g_print("\n");

    g_print("#\n");
    g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayDRM()]\n");
    g_print("#\n");
    {
        int drm_device;
        VADisplay va_display;

        drm_device = open(DRM_DEVICE_PATH, O_RDWR|O_CLOEXEC);
        if (drm_device < 0)
            g_error("could not open DRM device");

        va_display = vaGetDisplayDRM(drm_device);
        if (!va_display)
            g_error("could not create VA display");

        display = gst_vaapi_display_new_with_display(va_display);
        if (!display)
            g_error("could not create Gst/VA display");

        dump_info(display);
        gst_vaapi_display_unref(display);
        close(drm_device);
    }
    g_print("\n");
#endif

#if USE_X11
    g_print("#\n");
    g_print("# Create display with gst_vaapi_display_x11_new()\n");
    g_print("#\n");
    {
        display = gst_vaapi_display_x11_new(NULL);
        if (!display)
            g_error("could not create Gst/VA display");

        if (CHECK_DISPLAY_CACHE) {
            display2 = gst_vaapi_display_x11_new(NULL);

            /* Check for the same X11 display */
            g_assert(gst_vaapi_display_x11_get_display(
                         GST_VAAPI_DISPLAY_X11(display)) ==
                     gst_vaapi_display_x11_get_display(
                         GST_VAAPI_DISPLAY_X11(display2)));

            /* Check for the same VA display */
            g_assert(gst_vaapi_display_get_display(display) ==
                     gst_vaapi_display_get_display(display2));

            gst_vaapi_display_unref(display2);

#if USE_GLX
            display2 = gst_vaapi_display_glx_new(NULL);

            /* Check for the different X11 display */
            /* XXX: it is also desired to cache underlying X11 displays */
            g_assert(gst_vaapi_display_x11_get_display(
                         GST_VAAPI_DISPLAY_X11(display)) !=
                     gst_vaapi_display_x11_get_display(
                         GST_VAAPI_DISPLAY_X11(display2)));

            /* Check for different VA display */
            g_assert(gst_vaapi_display_get_display(display) !=
                     gst_vaapi_display_get_display(display2));

            gst_vaapi_display_unref(display2);
#endif
        }

        gst_vaapi_display_get_size(display, &width, &height);
        g_print("Display size: %ux%u\n", width, height);

        gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
        g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);

        dump_info(display);
        gst_vaapi_display_unref(display);
    }
    g_print("\n");

    g_print("#\n");
    g_print("# Create display with gst_vaapi_display_x11_new_with_display()\n");
    g_print("#\n");
    {
        Display *x11_display;

        x11_display = XOpenDisplay(NULL);
        if (!x11_display)
            g_error("could not create X11 display");

        display = gst_vaapi_display_x11_new_with_display(x11_display);
        if (!display)
            g_error("could not create Gst/VA display");

        if (CHECK_DISPLAY_CACHE) {
            display2 = gst_vaapi_display_x11_new_with_display(x11_display);

            /* Check for the same VA display */
            g_assert(gst_vaapi_display_get_display(display) ==
                     gst_vaapi_display_get_display(display2));

            gst_vaapi_display_unref(display2);
        }

        dump_info(display);
        gst_vaapi_display_unref(display);
        XCloseDisplay(x11_display);
    }
    g_print("\n");

    g_print("#\n");
    g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplay()]\n");
    g_print("#\n");
    {
        Display *x11_display;
        VADisplay va_display;

        x11_display = XOpenDisplay(NULL);
        if (!x11_display)
            g_error("could not create X11 display");

        va_display = vaGetDisplay(x11_display);
        if (!va_display)
            g_error("could not create VA display");

        display = gst_vaapi_display_new_with_display(va_display);
        if (!display)
            g_error("could not create Gst/VA display");

        dump_info(display);
        gst_vaapi_display_unref(display);
        XCloseDisplay(x11_display);
    }
    g_print("\n");
#endif

#if USE_GLX
    g_print("#\n");
    g_print("# Create display with gst_vaapi_display_glx_new()\n");
    g_print("#\n");
    {
        display = gst_vaapi_display_glx_new(NULL);
        if (!display)
            g_error("could not create Gst/VA display");

        if (CHECK_DISPLAY_CACHE) {
            display2 = gst_vaapi_display_glx_new(NULL);

            /* Check for the same X11 display */
            g_assert(gst_vaapi_display_x11_get_display(
                         GST_VAAPI_DISPLAY_X11(display)) ==
                     gst_vaapi_display_x11_get_display(
                         GST_VAAPI_DISPLAY_X11(display2)));

            /* Check for the same VA display */
            g_assert(gst_vaapi_display_get_display(display) ==
                     gst_vaapi_display_get_display(display2));

            gst_vaapi_display_unref(display2);

            display2 = gst_vaapi_display_x11_new(NULL);

            /* Check for the same X11 display */
            g_assert(gst_vaapi_display_x11_get_display(
                         GST_VAAPI_DISPLAY_X11(display)) ==
                     gst_vaapi_display_x11_get_display(
                         GST_VAAPI_DISPLAY_X11(display2)));

            /* Check for the same VA display */
            g_assert(gst_vaapi_display_get_display(display) ==
                     gst_vaapi_display_get_display(display2));

            gst_vaapi_display_unref(display2);
        }

        gst_vaapi_display_get_size(display, &width, &height);
        g_print("Display size: %ux%u\n", width, height);

        gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
        g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);

        dump_info(display);
        gst_vaapi_display_unref(display);
    }
    g_print("\n");

    g_print("#\n");
    g_print("# Create display with gst_vaapi_display_glx_new_with_display()\n");
    g_print("#\n");
    {
        Display *x11_display;

        x11_display = XOpenDisplay(NULL);
        if (!x11_display)
            g_error("could not create X11 display");

        display = gst_vaapi_display_glx_new_with_display(x11_display);
        if (!display)
            g_error("could not create Gst/VA display");

        dump_info(display);
        gst_vaapi_display_unref(display);
        XCloseDisplay(x11_display);
    }
    g_print("\n");

#ifdef HAVE_VA_VA_GLX_H
    g_print("#\n");
    g_print("# Create display with gst_vaapi_display_new_with_display() [vaGetDisplayGLX()]\n");
    g_print("#\n");
    {
        Display *x11_display;
        VADisplay va_display;

        x11_display = XOpenDisplay(NULL);
        if (!x11_display)
            g_error("could not create X11 display");

        va_display = vaGetDisplayGLX(x11_display);
        if (!va_display)
            g_error("could not create VA display");

        display = gst_vaapi_display_new_with_display(va_display);
        if (!display)
            g_error("could not create Gst/VA display");

        dump_info(display);
        gst_vaapi_display_unref(display);
        XCloseDisplay(x11_display);
    }
    g_print("\n");
#endif
#endif

#if USE_WAYLAND
    g_print("#\n");
    g_print("# Create display with gst_vaapi_display_wayland_new()\n");
    g_print("#\n");
    {
        display = gst_vaapi_display_wayland_new(NULL);
        if (!display)
            g_error("could not create Gst/VA display");

        gst_vaapi_display_get_size(display, &width, &height);
        g_print("Display size: %ux%u\n", width, height);

        gst_vaapi_display_get_pixel_aspect_ratio(display, &par_n, &par_d);
        g_print("Pixel aspect ratio: %u/%u\n", par_n, par_d);

        dump_info(display);
        gst_vaapi_display_unref(display);
    }
    g_print("\n");
#endif

    gst_deinit();
    return 0;
}