Ejemplo n.º 1
0
void
gst_gl_async_debug_init (GstGLAsyncDebug * ad)
{
  _init_debug ();

  memset (ad, 0, sizeof (*ad));
}
Ejemplo n.º 2
0
gchar *
_gst_glsl_mangle_shader (const gchar * str, guint shader_type,
    GstGLTextureTarget from, GstGLTextureTarget to, GstGLContext * context,
    GstGLSLVersion * version, GstGLSLProfile * profile)
{
  gchar *tmp, *tmp2;

  _init_debug ();

  g_return_val_if_fail (GST_IS_GL_CONTEXT (context), NULL);

  _mangle_version_profile_from_gl_api (context, from, to, version, profile);
  tmp2 =
      _mangle_external_image_extension (str, context, from, to, *version,
      *profile);
  tmp = _mangle_texture_access (tmp2, context, from, to, *version, *profile);
  g_free (tmp2);
  tmp2 = _mangle_sampler_type (tmp, from, to);
  g_free (tmp);
  tmp = _mangle_varying_attribute (tmp2, shader_type, *version, *profile);
  g_free (tmp2);
  if (shader_type == GL_FRAGMENT_SHADER) {
    if ((*profile == GST_GLSL_PROFILE_ES && *version >= GST_GLSL_VERSION_300)
        || (*profile == GST_GLSL_PROFILE_CORE
            && *version >= GST_GLSL_VERSION_150)) {
      tmp2 = _mangle_frag_color_data (tmp);
      g_free (tmp);
      tmp = tmp2;
    }
  }
  return tmp;
}
Ejemplo n.º 3
0
void GSTGLAPI
_gst_gl_debug_callback (GLenum source, GLenum type, GLuint id, GLenum severity,
    GLsizei length, const gchar * message, gpointer user_data)
{
  GstGLContext *context = user_data;
  const gchar *severity_str = _debug_severity_to_string (severity);
  const gchar *source_str = _debug_source_to_string (source);
  const gchar *type_str = _debug_type_to_string (type);

  _init_debug ();

  switch (type) {
    case GL_DEBUG_TYPE_ERROR:
    case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOUR:
      GST_ERROR_OBJECT (context, "%s: GL %s from %s id:%u, %s", severity_str,
          type_str, source_str, id, message);
      break;
    case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOUR:
    case GL_DEBUG_TYPE_PORTABILITY:
      GST_FIXME_OBJECT (context, "%s: GL %s from %s id:%u, %s", severity_str,
          type_str, source_str, id, message);
      break;
    case GL_DEBUG_TYPE_PERFORMANCE:
      GST_CAT_DEBUG_OBJECT (gst_performance, context, "%s: GL %s from %s id:%u,"
          " %s", severity_str, type_str, source_str, id, message);
      break;
    default:
      GST_DEBUG_OBJECT (context, "%s: GL %s from %s id:%u, %s", severity_str,
          type_str, source_str, id, message);
      break;
  }
}
Ejemplo n.º 4
0
/**
 * gst_gl_context_new_wrapped:
 * @display: a #GstGLDisplay
 * @handle: the OpenGL context to wrap
 * @context_type: a #GstGLPlatform specifying the type of context in @handle
 * @available_apis: a #GstGLAPI containing the available OpenGL apis in @handle
 *
 * Wraps an existing OpenGL context into a #GstGLContext.  
 *
 * Returns: a #GstGLContext wrapping @handle
 */
GstGLContext *
gst_gl_context_new_wrapped (GstGLDisplay * display, guintptr handle,
    GstGLPlatform context_type, GstGLAPI available_apis)
{
  GstGLContext *context;
  GstGLWrappedContext *context_wrap = NULL;

  _init_debug ();

  context_wrap = g_object_new (GST_GL_TYPE_WRAPPED_CONTEXT, NULL);

  if (!context_wrap) {
    /* subclass returned a NULL context */
    GST_ERROR ("Could not wrap existing context");

    return NULL;
  }

  context = (GstGLContext *) context_wrap;

  context->priv->display = gst_object_ref (display);
  context_wrap->handle = handle;
  context_wrap->platform = context_type;
  context_wrap->available_apis = available_apis;

  return context;
}
Ejemplo n.º 5
0
void
gst_gl_query_init (GstGLQuery * query, GstGLContext * context,
    GstGLQueryType query_type)
{
  const GstGLFuncs *gl;

  g_return_if_fail (query != NULL);
  g_return_if_fail (GST_IS_GL_CONTEXT (context));
  gl = context->gl_vtable;

  memset (query, 0, sizeof (*query));

  _init_debug ();

  query->context = gst_object_ref (context);
  query->query_type = _gst_gl_query_type_to_gl (query_type);
  query->supported = _context_supports_query_type (context, query->query_type);

  if (query->supported)
    gl->GenQueries (1, &query->query_id);

  gst_gl_async_debug_init (&query->debug);
  query->debug.callback = _log_time;
  query->debug.user_data = query;
}
Ejemplo n.º 6
0
/**
 * gst_gl_context_get_current_gl_context:
 * @context_type: a #GstGLPlatform specifying the type of context to retrieve
 *
 * Returns: The OpenGL context handle current in the calling thread or %NULL
 *
 * Since: 1.6
 */
guintptr
gst_gl_context_get_current_gl_context (GstGLPlatform context_type)
{
  guintptr handle = 0;

  _init_debug ();

#if GST_GL_HAVE_PLATFORM_GLX
  if (!handle && (context_type & GST_GL_PLATFORM_GLX) != 0)
    handle = gst_gl_context_glx_get_current_context ();
#endif
#if GST_GL_HAVE_PLATFORM_EGL
  if (!handle && (context_type & GST_GL_PLATFORM_EGL) != 0)
    handle = gst_gl_context_egl_get_current_context ();
#endif
#if GST_GL_HAVE_PLATFORM_CGL
  if (!handle && (context_type & GST_GL_PLATFORM_CGL) != 0)
    handle = gst_gl_context_cocoa_get_current_context ();
#endif
#if GST_GL_HAVE_PLATFORM_WGL
  if (!handle && (context_type & GST_GL_PLATFORM_WGL) != 0)
    handle = gst_gl_context_wgl_get_current_context ();
#endif
#if GST_GL_HAVE_PLATFORM_EAGL
  if (!handle && (context_type & GST_GL_PLATFORM_EAGL) != 0)
    handle = gst_gl_context_eagl_get_current_context ();
#endif

  if (!handle)
    GST_WARNING ("Could not retrieve current context");

  return handle;
}
Ejemplo n.º 7
0
static void
gst_gl_context_class_init (GstGLContextClass * klass)
{
  g_type_class_add_private (klass, sizeof (GstGLContextPrivate));

  klass->get_proc_address =
      GST_DEBUG_FUNCPTR (gst_gl_context_default_get_proc_address);

  G_OBJECT_CLASS (klass)->finalize = gst_gl_context_finalize;

  _init_debug ();
}
Ejemplo n.º 8
0
/**
 * gst_gl_window_new:
 * @display: a #GstGLDisplay
 *
 * Returns: (transfer full): a new #GstGLWindow using @display's connection
 *
 * Since: 1.4
 */
GstGLWindow *
gst_gl_window_new (GstGLDisplay * display)
{
  GstGLWindow *window = NULL;
  const gchar *user_choice;

  g_return_val_if_fail (display != NULL, NULL);

  _init_debug ();

  user_choice = g_getenv ("GST_GL_WINDOW");
  GST_INFO ("creating a window, user choice:%s", user_choice);

#if GST_GL_HAVE_WINDOW_COCOA
  if (!window && (!user_choice || g_strstr_len (user_choice, 5, "cocoa")))
    window = GST_GL_WINDOW (gst_gl_window_cocoa_new (display));
#endif
#if GST_GL_HAVE_WINDOW_X11
  if (!window && (!user_choice || g_strstr_len (user_choice, 3, "x11")))
    window = GST_GL_WINDOW (gst_gl_window_x11_new (display));
#endif
#if GST_GL_HAVE_WINDOW_WIN32
  if (!window && (!user_choice || g_strstr_len (user_choice, 5, "win32")))
    window = GST_GL_WINDOW (gst_gl_window_win32_new (display));
#endif
#if GST_GL_HAVE_WINDOW_WAYLAND
  if (!window && (!user_choice || g_strstr_len (user_choice, 7, "wayland")))
    window = GST_GL_WINDOW (gst_gl_window_wayland_egl_new (display));
#endif
#if GST_GL_HAVE_WINDOW_DISPMANX
  if (!window && (!user_choice || g_strstr_len (user_choice, 8, "dispmanx")))
    window = GST_GL_WINDOW (gst_gl_window_dispmanx_egl_new (display));
#endif
#if GST_GL_HAVE_WINDOW_ANDROID
  if (!window && (!user_choice || g_strstr_len (user_choice, 7, "android")))
    window = GST_GL_WINDOW (gst_gl_window_android_egl_new (display));
#endif
#if GST_GL_HAVE_WINDOW_EAGL
  if (!window && (!user_choice || g_strstr_len (user_choice, 4, "eagl")))
    window = GST_GL_WINDOW (gst_gl_window_eagl_new (display));
#endif
  if (!window) {
    /* subclass returned a NULL window */
    GST_WARNING ("Could not create window. user specified %s, creating dummy"
        " window", user_choice ? user_choice : "(null)");

    window = GST_GL_WINDOW (gst_gl_dummy_window_new ());
  }

  window->display = gst_object_ref (display);

  return window;
}
Ejemplo n.º 9
0
static void
gst_gl_window_class_init (GstGLWindowClass * klass)
{
  g_type_class_add_private (klass, sizeof (GstGLWindowPrivate));

  klass->open = GST_DEBUG_FUNCPTR (gst_gl_window_default_open);
  klass->close = GST_DEBUG_FUNCPTR (gst_gl_window_default_close);
  klass->run = GST_DEBUG_FUNCPTR (gst_gl_window_default_run);
  klass->quit = GST_DEBUG_FUNCPTR (gst_gl_window_default_quit);
  klass->draw = GST_DEBUG_FUNCPTR (gst_gl_window_default_draw);
  klass->send_message = GST_DEBUG_FUNCPTR (gst_gl_window_default_send_message);
  klass->send_message_async =
      GST_DEBUG_FUNCPTR (gst_gl_window_default_send_message_async);

  G_OBJECT_CLASS (klass)->finalize = gst_gl_window_finalize;

  /**
   * GstGLWindow::mouse-event:
   * @object: the #GstGLWindow
   * @id: the name of the event
   * @button: the id of the button
   * @x: the x coordinate of the mouse event
   * @y: the y coordinate of the mouse event
   *
   * Will be emitted when a mouse event is received by the GstGLwindow.
   *
   * Since: 1.6
   */
  gst_gl_window_signals[EVENT_MOUSE_SIGNAL] =
      g_signal_new ("mouse-event", G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
      G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_DOUBLE);

  /**
   * GstGLWindow::key-event:
   * @object: the #GstGLWindow
   * @id: the name of the event
   * @key: the id of the key pressed
   *
   * Will be emitted when a key event is received by the GstGLwindow.
   *
   * Since: 1.6
   */
  gst_gl_window_signals[EVENT_KEY_SIGNAL] =
      g_signal_new ("key-event", G_TYPE_FROM_CLASS (klass),
      G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
      G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING);

  _init_debug ();
}
Ejemplo n.º 10
0
/**
 * gst_gl_context_new:
 * @display: a #GstGLDisplay
 *
 * Create a new #GstGLContext with the specified @display
 *
 * Returns: a new #GstGLContext
 *
 * Since: 1.4
 */
GstGLContext *
gst_gl_context_new (GstGLDisplay * display)
{
  GstGLContext *context = NULL;
  const gchar *user_choice;

  _init_debug ();

  user_choice = g_getenv ("GST_GL_PLATFORM");
  GST_INFO ("creating a context for display %" GST_PTR_FORMAT
      ", user choice:%s", display, user_choice);
#if GST_GL_HAVE_PLATFORM_CGL
  if (!context && (!user_choice || g_strstr_len (user_choice, 5, "cgl")))
    context = GST_GL_CONTEXT (gst_gl_context_cocoa_new ());
#endif
#if GST_GL_HAVE_PLATFORM_GLX
  if (!context && (!user_choice || g_strstr_len (user_choice, 3, "glx")))
    context = GST_GL_CONTEXT (gst_gl_context_glx_new ());
#endif
#if GST_GL_HAVE_PLATFORM_EGL
  if (!context && (!user_choice || g_strstr_len (user_choice, 7, "egl")))
    context = GST_GL_CONTEXT (gst_gl_context_egl_new ());
#endif
#if GST_GL_HAVE_PLATFORM_WGL
  if (!context && (!user_choice || g_strstr_len (user_choice, 3, "wgl"))) {
    context = GST_GL_CONTEXT (gst_gl_context_wgl_new ());
  }
#endif
#if GST_GL_HAVE_PLATFORM_EAGL
  if (!context && (!user_choice || g_strstr_len (user_choice, 5, "eagl")))
    context = GST_GL_CONTEXT (gst_gl_context_eagl_new ());
#endif

  if (!context) {
    /* subclass returned a NULL context */
    GST_WARNING ("Could not create context. user specified %s",
        user_choice ? user_choice : "(null)");

    return NULL;
  }

  context->priv->display = gst_object_ref (display);

  GST_DEBUG_OBJECT (context,
      "Done creating context for display %" GST_PTR_FORMAT " (user_choice:%s)",
      display, user_choice);

  return context;
}
Ejemplo n.º 11
0
SPDConnection*
spd_open(const char* client_name, const char* connection_name, const char* user_name,
	 SPDConnectionMode mode)
{
  char *error;
  int autospawn = 1;
  SPDConnection *conn;
  conn = spd_open2(client_name, connection_name, user_name,
		   mode, NULL, autospawn, &error);
  if (!conn){
    _init_debug();
    assert(error);
    SPD_DBG("Could not connect to Speech Dispatcher: %s", error);
    xfree(error);
  }
  return conn;
}
Ejemplo n.º 12
0
GstGLSLVersion
gst_gl_version_to_glsl_version (GstGLAPI gl_api, gint maj, gint min)
{
  g_return_val_if_fail (gl_api != GST_GL_API_NONE, 0);

  _init_debug ();

  if (gl_api & GST_GL_API_GLES2) {
    if (maj == 2 && min == 0)
      return 100;

    if (maj == 3 && min >= 0 && min <= 2)
      return maj * 100 + min * 10;

    GST_WARNING ("unknown GLES version");
    return 0;
  }

  /* versions match for >= 3.3 */
  if (gl_api & (GST_GL_API_OPENGL3 | GST_GL_API_OPENGL)) {
    if (maj > 3 || (maj == 3 && min >= 3))
      return maj * 100 + min * 10;

    if (maj == 3 && min == 2)
      return 150;
    if (maj == 3 && min == 1)
      return 140;
    if (maj == 3 && min == 0)
      return 130;
    if (maj == 2 && min == 1)
      return 120;
    if (maj == 2 && min == 0)
      return 110;

    GST_WARNING ("unknown GL version");
    return 0;
  }

  GST_WARNING ("unknown GL API");
  return 0;
}
Ejemplo n.º 13
0
GstVulkanTrash *
gst_vulkan_trash_new (GstVulkanFence * fence, GstVulkanTrashNotify notify,
    gpointer user_data)
{
  GstVulkanTrash *ret = NULL;

  g_return_val_if_fail (fence != NULL, NULL);
  g_return_val_if_fail (GST_IS_VULKAN_DEVICE (fence->device), NULL);
  g_return_val_if_fail (notify != NULL, NULL);

  _init_debug ();

  ret = g_new0 (GstVulkanTrash, 1);
  GST_TRACE ("Creating new trash object %p with fence %" GST_PTR_FORMAT
      " on device %" GST_PTR_FORMAT, ret, fence, fence->device);
  ret->fence = fence;
  ret->notify = notify;
  ret->user_data = user_data;

  return ret;
}
Ejemplo n.º 14
0
gboolean
gst_glsl_version_profile_from_string (const gchar * string,
    GstGLSLVersion * version_ret, GstGLSLProfile * profile_ret)
{
  gchar *str, *version_s, *profile_s;
  GstGLSLVersion version = GST_GLSL_VERSION_NONE;
  GstGLSLProfile profile = GST_GLSL_PROFILE_NONE;
  gint i;

  _init_debug ();

  if (!string)
    goto error;

  str = g_strdup (string);
  version_s = g_strstrip (str);

  /* skip possible #version prefix */
  if (str[0] == '#') {
    if (!(version_s =
            (gchar *) _check_valid_version_preprocessor_string (version_s))) {
      GST_WARNING ("Invalid preprocesser directive detected: %s", version_s);
      g_free (str);
      goto error;
    }
  }

  version_s = g_strstrip (version_s);

  i = 0;
  while (version_s && version_s[i] != '\0' && g_ascii_isdigit (version_s[i]))
    i++;
  /* wrong version length */
  if (i != 3) {
    GST_WARNING ("version number has the wrong number of digits: %s",
        version_s);
    g_free (str);
    goto error;
  }

  if (version_s[i] != 0) {
    version_s[i] = '\0';
    i++;
    profile_s = &version_s[i];
    profile_s = g_strstrip (profile_s);

    profile = gst_glsl_profile_from_string (profile_s);
  }
  version = gst_glsl_version_from_string (version_s);
  g_free (str);

  /* check whether the parsed data is valid */
  if (!version) {
    GST_WARNING ("Could not map the version number to a valid GLSL version:");
    goto error;
  }
  if (!_is_valid_version_profile (version, profile)) {
    GST_WARNING ("Invalid version/profile combination specified: %s %s",
        gst_glsl_version_to_string (version),
        gst_glsl_profile_to_string (profile));
    goto error;
  }
  /* got a profile when none was expected */
  if (version <= GST_GLSL_VERSION_140 && profile != GST_GLSL_PROFILE_NONE) {
    GST_WARNING
        ("Found a profile (%s) with a version (%s) that does not support "
        "profiles", gst_glsl_version_to_string (version),
        gst_glsl_profile_to_string (profile));
    goto error;
  }

  _fixup_version_profile (&version, &profile);

  if (profile_ret)
    *profile_ret = profile;
  if (version_ret)
    *version_ret = version;

  return TRUE;

error:
  {
    if (profile_ret)
      *profile_ret = GST_GLSL_PROFILE_NONE;
    if (version_ret)
      *version_ret = GST_GLSL_VERSION_NONE;
    return FALSE;
  }
}
Ejemplo n.º 15
0
/* returns the pointer in @str to the #version declaration */
const gchar *
_gst_glsl_shader_string_find_version (const gchar * str)
{
  gboolean sl_comment = FALSE;
  gboolean ml_comment = FALSE;
  gboolean newline = TRUE;
  gint i = 0;

  _init_debug ();

  /* search for #version while allowing for preceeding comments/whitespace as
   * permitted by the GLSL specification */
  while (str && str[i] != '\0' && i < 1024) {
    if (str[i] == '\n' || str[i] == '\r') {
      newline = TRUE;
      sl_comment = FALSE;
      i++;
      continue;
    }

    if (g_ascii_isspace (str[i]))
      goto next;

    if (sl_comment)
      goto next;

    if (ml_comment) {
      if (g_strstr_len (&str[i], 2, "*/")) {
        ml_comment = FALSE;
        i++;
      }
      goto next;
    }

    if (g_strstr_len (&str[i], 2, "//")) {
      sl_comment = TRUE;
      i++;
      goto next;
    }

    if (g_strstr_len (&str[i], 2, "/*")) {
      ml_comment = TRUE;
      i++;
      goto next;
    }

    if (str[i] == '#') {
      if (newline && _check_valid_version_preprocessor_string (&str[i])) {
        GST_DEBUG ("found #version declaration at index %i", i);
        return &str[i];
      }
      break;
    }

  next:
    newline = FALSE;
    i++;
  }

  GST_DEBUG ("no #version declaration found in the first 1K");

  return NULL;
}
Ejemplo n.º 16
0
/**
 * gst_gl_context_new_wrapped:
 * @display: a #GstGLDisplay
 * @handle: the OpenGL context to wrap
 * @context_type: a #GstGLPlatform specifying the type of context in @handle
 * @available_apis: a #GstGLAPI containing the available OpenGL apis in @handle
 *
 * Wraps an existing OpenGL context into a #GstGLContext.  
 *
 * Returns: a #GstGLContext wrapping @handle
 *
 * Since: 1.4
 */
GstGLContext *
gst_gl_context_new_wrapped (GstGLDisplay * display, guintptr handle,
    GstGLPlatform context_type, GstGLAPI available_apis)
{
  GstGLContext *context;
  GstGLWrappedContext *context_wrap = NULL;
  GstGLContextClass *context_class;
  GstGLAPI display_api;

  _init_debug ();

  display_api = gst_gl_display_get_gl_api (display);
  g_return_val_if_fail ((display_api & available_apis) != GST_GL_API_NONE,
      NULL);

  context_wrap = g_object_new (GST_GL_TYPE_WRAPPED_CONTEXT, NULL);

  if (!context_wrap) {
    /* subclass returned a NULL context */
    GST_ERROR ("Could not wrap existing context");

    return NULL;
  }

  context = (GstGLContext *) context_wrap;

  context->display = gst_object_ref (display);
  context->priv->sharegroup_id = _new_sharegroup_id ();
  context_wrap->handle = handle;
  context_wrap->platform = context_type;
  context_wrap->available_apis = available_apis;

  context_class = GST_GL_CONTEXT_GET_CLASS (context);

#if GST_GL_HAVE_PLATFORM_GLX
  if (context_type == GST_GL_PLATFORM_GLX) {
    context_class->get_current_context = gst_gl_context_glx_get_current_context;
    context_class->get_proc_address = gst_gl_context_glx_get_proc_address;
  }
#endif
#if GST_GL_HAVE_PLATFORM_EGL
  if (context_type == GST_GL_PLATFORM_EGL) {
    context_class->get_current_context = gst_gl_context_egl_get_current_context;
    context_class->get_proc_address = gst_gl_context_egl_get_proc_address;
  }
#endif
#if GST_GL_HAVE_PLATFORM_CGL
  if (context_type == GST_GL_PLATFORM_CGL) {
    context_class->get_current_context =
        gst_gl_context_cocoa_get_current_context;
    context_class->get_proc_address = gst_gl_context_default_get_proc_address;
  }
#endif
#if GST_GL_HAVE_PLATFORM_WGL
  if (context_type == GST_GL_PLATFORM_WGL) {
    context_class->get_current_context = gst_gl_context_wgl_get_current_context;
    context_class->get_proc_address = gst_gl_context_wgl_get_proc_address;
  }
#endif
#if GST_GL_HAVE_PLATFORM_EAGL
  if (context_type == GST_GL_PLATFORM_EAGL) {
    context_class->get_current_context =
        gst_gl_context_eagl_get_current_context;
    context_class->get_proc_address = gst_gl_context_default_get_proc_address;
  }
#endif

  if (!context_class->get_current_context) {
    /* we don't have API support */
    gst_object_unref (context);
    return NULL;
  }

  return context;
}
Ejemplo n.º 17
0
SPDConnection*
spd_open2(const char* client_name, const char* connection_name, const char* user_name,
	  SPDConnectionMode mode, SPDConnectionAddress *address, int autospawn,
	  char **error_result)
{
    SPDConnection *connection;
    char *set_client_name;
    char* conn_name;
    char* usr_name;
    int ret;
    char tcp_no_delay = 1;

    /* Autospawn related */
    int spawn_err;
    gchar *spawn_report;
    char *host_ip;
    int is_localhost = 1;
    
    struct sockaddr_in address_inet;    
    struct sockaddr_un address_unix;    
    struct sockaddr *sock_address;
    size_t sock_address_len;
    gchar *resolve_error;

    _init_debug();

    if (client_name == NULL){
      *error_result = strdup("ERROR: Client name not specified");
      SPD_DBG(*error_result);
      return NULL;
    }
    
    if (user_name == NULL)
    {
        usr_name = strdup((char*) g_get_user_name());
    }
    else
        usr_name = strdup(user_name);
    
    if(connection_name == NULL)
        conn_name = strdup("main");
    else
        conn_name = strdup(connection_name);

    if (address == NULL){
      char *err = NULL;
      address = spd_get_default_address(&err);
      if (!address){
	assert(err);
	*error_result = err;
	SPD_DBG(*error_result);
	return NULL;
      }
    }
    
    /* Connect to server using the selected method */
    connection = xmalloc(sizeof(SPDConnection));
    if (address->method==SPD_METHOD_INET_SOCKET){    
	host_ip = resolve_host(address->inet_socket_host, &is_localhost, &resolve_error);
	if (host_ip == NULL){
	    *error_result = strdup(resolve_error);
	    g_free(resolve_error);
	    return NULL;
	}	
	address_inet.sin_addr.s_addr = inet_addr(host_ip);
	address_inet.sin_port = htons(address->inet_socket_port);
	address_inet.sin_family = AF_INET;
	connection->socket = socket(AF_INET, SOCK_STREAM, 0);
	sock_address = (struct sockaddr*) &address_inet;
	sock_address_len = sizeof(address_inet);
    }else if (address->method==SPD_METHOD_UNIX_SOCKET){
      /* Create the unix socket */
      address_unix.sun_family = AF_UNIX;
      strncpy (address_unix.sun_path, address->unix_socket_name, sizeof (address_unix.sun_path));
      address_unix.sun_path[sizeof (address_unix.sun_path) - 1] = '\0';
      connection->socket = socket(AF_UNIX, SOCK_STREAM, 0);
      sock_address = (struct sockaddr*) &address_unix;
      sock_address_len = SUN_LEN(&address_unix);
    }else SPD_FATAL("Unsupported connection method for spd_open2()");

    ret = connect(connection->socket, sock_address, sock_address_len);    
    if (ret == -1){
	/* Suppose server might not be running, try to autospawn (autostart) it */
	if (autospawn){	
	    spawn_err = spawn_server(address, is_localhost, &spawn_report);
	    if (!spawn_err)
		spawn_report = g_strdup("Server successfully autospawned");
	    ret = connect(connection->socket, sock_address, sock_address_len);    
	}else{
	    spawn_report = g_strdup("Autospawn disabled");
	}
	if (ret == -1){
	    if (address->method == SPD_METHOD_INET_SOCKET)
		*error_result = g_strdup_printf("Error: Can't connect to %s on port %d using inet sockets: %s. " \
						"Autospawn: %s", address->inet_socket_host,
						address->inet_socket_port, strerror(errno), spawn_report);
	    else if (address->method == SPD_METHOD_UNIX_SOCKET)
		*error_result = g_strdup_printf("Error: Can't connect to unix socket %s: %s. Autospawn: %s",
						address->unix_socket_name, strerror(errno), spawn_report);
	    else assert (0);
	    SPD_DBG(*error_result);
	    close(connection->socket);	
	    return NULL;
	}
    }

    if (address->method == SPD_METHOD_INET_SOCKET)
	setsockopt(connection->socket, IPPROTO_TCP, TCP_NODELAY, &tcp_no_delay, sizeof(int));
    
    connection->callback_begin = NULL;
    connection->callback_end = NULL;
    connection->callback_im = NULL;
    connection->callback_pause = NULL;
    connection->callback_resume = NULL;
    connection->callback_cancel = NULL;

    connection->mode = mode;

    /* Create a stream from the socket */
    connection->stream = fdopen(connection->socket, "r");
    if (!connection->stream) SPD_FATAL("Can't create a stream for socket, fdopen() failed.");
    /* Switch to line buffering mode */
    ret = setvbuf(connection->stream, NULL, _IONBF, SPD_REPLY_BUF_SIZE);
    if (ret) SPD_FATAL("Can't set buffering, setvbuf failed.");

    connection->ssip_mutex = xmalloc(sizeof(pthread_mutex_t));
    pthread_mutex_init(connection->ssip_mutex, NULL);

    if (mode == SPD_MODE_THREADED){
	SPD_DBG("Initializing threads, condition variables and mutexes...");
	connection->events_thread = xmalloc(sizeof(pthread_t));
	connection->cond_reply_ready = xmalloc(sizeof(pthread_cond_t));
	connection->mutex_reply_ready = xmalloc(sizeof(pthread_mutex_t));
	connection->cond_reply_ack = xmalloc(sizeof(pthread_cond_t));
	connection->mutex_reply_ack = xmalloc(sizeof(pthread_mutex_t));
	pthread_cond_init(connection->cond_reply_ready, NULL);
	pthread_mutex_init(connection->mutex_reply_ready, NULL);
	pthread_cond_init(connection->cond_reply_ack, NULL);
	pthread_mutex_init(connection->mutex_reply_ack, NULL);
	ret = pthread_create(connection->events_thread, NULL, spd_events_handler, connection);
	if(ret != 0){
	    *error_result = strdup("Thread initialization failed");
	    SPD_DBG(*error_result);
	    return NULL;
	}
    }

    /* By now, the connection is created and operational */
    set_client_name = g_strdup_printf("SET SELF CLIENT_NAME \"%s:%s:%s\"", usr_name,
				      client_name, conn_name);
    ret = spd_execute_command_wo_mutex(connection, set_client_name);   
    xfree(usr_name);  xfree(conn_name);  xfree(set_client_name);
    return connection;
}
Ejemplo n.º 18
0
/**
 * gst_gl_context_get_current_gl_api:
 * @platform: the #GstGLPlatform to retrieve the API for
 * @major: (out): (allow-none): the major version
 * @minor: (out): (allow-none): the minor version
 *
 * If an error occurs, @major and @minor aren't modified and %GST_GL_API_NONE is
 * returned.
 *
 * Returns: The version supported by the OpenGL context current in the calling
 *          thread or %GST_GL_API_NONE
 *
 * Since: 1.6
 */
GstGLAPI
gst_gl_context_get_current_gl_api (GstGLPlatform platform, guint * major,
    guint * minor)
{
  const GLubyte *(*GetString) (GLenum name);
#if GST_GL_HAVE_OPENGL
  void (*GetIntegerv) (GLenum name, GLuint * n);
#endif
  const gchar *version;
  gint maj, min, n;
  GstGLAPI ret = (1 << 31);

  _init_debug ();

  while (ret != GST_GL_API_NONE) {
    /* FIXME: attempt to delve into the platform specific GetProcAddress */
    GetString =
        gst_gl_context_get_proc_address_with_platform (platform, ret,
        "glGetString");
#if GST_GL_HAVE_OPENGL
    GetIntegerv =
        gst_gl_context_get_proc_address_with_platform (platform, ret,
        "glGetIntegerv");
#endif
    if (!GetString) {
      goto next;
    }

    version = (const gchar *) GetString (GL_VERSION);
    if (!version)
      goto next;

    /* strlen (x.x) == 3 */
    n = strlen (version);
    if (n < 3)
      goto next;

    if (g_strstr_len (version, 9, "OpenGL ES")) {
      /* strlen (OpenGL ES x.x) == 13 */
      if (n < 13)
        goto next;

      sscanf (&version[10], "%d.%d", &maj, &min);

      if (maj <= 0 || min < 0)
        goto next;

      if (maj == 1) {
        ret = GST_GL_API_GLES1;
        break;
      } else if (maj == 2 || maj == 3) {
        ret = GST_GL_API_GLES2;
        break;
      }

      goto next;
    } else {
      sscanf (version, "%d.%d", &maj, &min);

      if (maj <= 0 || min < 0)
        goto next;

#if GST_GL_HAVE_OPENGL
      if (GetIntegerv && (maj > 3 || (maj == 3 && min > 1))) {
        GLuint context_flags = 0;

        ret = GST_GL_API_NONE;
        GetIntegerv (GL_CONTEXT_PROFILE_MASK, &context_flags);
        if (context_flags & GL_CONTEXT_CORE_PROFILE_BIT)
          ret |= GST_GL_API_OPENGL3;
        if (context_flags & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
          ret |= GST_GL_API_OPENGL;
        break;
      }
#endif
      ret = GST_GL_API_OPENGL;
      break;
    }

  next:
    /* iterate through the apis */
    ret >>= 1;
  }

  if (ret == GST_GL_API_NONE)
    return GST_GL_API_NONE;

  if (major)
    *major = maj;
  if (minor)
    *minor = min;

  return ret;
}