Example #1
0
static GstFlowReturn
gst_glimage_sink_render (GstBaseSink * bsink, GstBuffer * buf)
{
  GstGLImageSink *glimage_sink = NULL;
  GstGLBuffer *gl_buffer = NULL;

  glimage_sink = GST_GLIMAGE_SINK (bsink);

  GST_INFO ("buffer size: %d", GST_BUFFER_SIZE (buf));

  //is gl
  if (glimage_sink->is_gl) {
    //increment gl buffer ref before storage
    gl_buffer = GST_GL_BUFFER (gst_buffer_ref (buf));
  }
  //is not gl
  else {
    //blocking call
    gl_buffer = gst_gl_buffer_new (glimage_sink->display,
        glimage_sink->width, glimage_sink->height);

    //blocking call
    gst_gl_display_do_upload (glimage_sink->display, gl_buffer->texture,
        glimage_sink->width, glimage_sink->height, GST_BUFFER_DATA (buf));

    //gl_buffer is created in this block, so the gl buffer is already referenced
  }

  if (glimage_sink->window_id != glimage_sink->new_window_id) {
    glimage_sink->window_id = glimage_sink->new_window_id;
    gst_gl_display_set_window_id (glimage_sink->display,
        glimage_sink->window_id);
  }
  //the buffer is cleared when an other comes in
  if (glimage_sink->stored_buffer) {
    gst_buffer_unref (GST_BUFFER_CAST (glimage_sink->stored_buffer));
    glimage_sink->stored_buffer = NULL;
  }
  //store current buffer
  glimage_sink->stored_buffer = gl_buffer;

  //redisplay opengl scene
  if (gl_buffer->texture &&
      gst_gl_display_redisplay (glimage_sink->display,
          gl_buffer->texture, gl_buffer->width, gl_buffer->height,
          glimage_sink->window_width, glimage_sink->window_height,
          glimage_sink->keep_aspect_ratio))
    return GST_FLOW_OK;
  else {
    GST_ELEMENT_ERROR (glimage_sink, RESOURCE, NOT_FOUND,
        GST_GL_DISPLAY_ERR_MSG (glimage_sink->display), (NULL));
    return GST_FLOW_ERROR;
  }
}
Example #2
0
static GstFlowReturn
gst_egl_sink_show_frame (GstVideoSink *video_sink, GstBuffer *buf)
{
  GstEGLSink *egl_sink;
  GstEGLBuffer *egl_buffer;
  GstFlowReturn ret;

  egl_sink = GST_EGL_SINK (video_sink);

  GST_DEBUG("eglsink show_frame count %d\n", ++egl_sink->show_count);
  GST_INFO ("buffer %p, buffer size: %d", buf, GST_BUFFER_SIZE (buf));

  if(egl_sink->draw_callback)
    return egl_sink->draw_callback(buf, egl_sink->client_data);

  //is egl
  if (GST_IS_EGL_BUFFER(buf)) {
    GST_DEBUG("Direct rendering");
    //increment gl buffer ref before storage
    egl_buffer = GST_EGL_BUFFER (gst_buffer_ref(buf));
  }
  //is not egl
  else {
    egl_buffer = gst_gl_display_get_free_buffer (egl_sink->display,
        GST_BUFFER_CAPS(buf), -1, FALSE);
    if(egl_buffer)
      gst_gl_display_do_upload (egl_sink->display, egl_buffer, buf);
    else
      return GST_FLOW_UNEXPECTED;
  }

  if (egl_sink->window_id != egl_sink->new_window_id) {
    egl_sink->window_id = egl_sink->new_window_id;
    gst_gl_display_set_window_id (egl_sink->display,
        egl_sink->window_id);
  }

  GST_INFO("redisplay texture %d, width %d, height %d", egl_buffer->texinfo->texture,
      egl_sink->window_width, egl_sink->window_height);
  //redisplay opengl scene
  if (gst_gl_display_redisplay (egl_sink->display,
          egl_buffer,
          egl_sink->window_width, egl_sink->window_height,
          egl_sink->keep_aspect_ratio))
    ret = GST_FLOW_OK;
  else
    ret = GST_FLOW_UNEXPECTED;
  gst_egl_buffer_unref(egl_buffer);
  return ret;
}
Example #3
0
static void
gst_glimage_sink_expose (GstXOverlay * overlay)
{
  GstGLImageSink *glimage_sink = GST_GLIMAGE_SINK (overlay);

  //redisplay opengl scene
  if (glimage_sink->display && glimage_sink->window_id) {
    
    if (glimage_sink->window_id != glimage_sink->new_window_id) {
      glimage_sink->window_id = glimage_sink->new_window_id;
      gst_gl_display_set_window_id (glimage_sink->display,
          glimage_sink->window_id);
    }

    gst_gl_display_redisplay (glimage_sink->display, 0, 0, 0, 
      glimage_sink->keep_aspect_ratio);
  }
}
Example #4
0
static void
gst_egl_sink_expose (GstXOverlay * overlay)
{
  GstEGLSink *egl_sink = GST_EGL_SINK (overlay);

  //redisplay opengl scene
  if (egl_sink->display && egl_sink->window_id) {

    if (egl_sink->window_id != egl_sink->new_window_id) {
      egl_sink->window_id = egl_sink->new_window_id;
      gst_gl_display_set_window_id (egl_sink->display,
          egl_sink->window_id);
    }

    gst_gl_display_redisplay (egl_sink->display, NULL, 0, 0,
        egl_sink->keep_aspect_ratio);
  }
}
Example #5
0
static GstFlowReturn
gst_glimage_sink_render (GstBaseSink * bsink, GstBuffer * buf)
{
  GstGLImageSink *glimage_sink = NULL;
  GstGLBuffer *gl_buffer = NULL;

  glimage_sink = GST_GLIMAGE_SINK (bsink);

  GST_INFO ("buffer size: %d", GST_BUFFER_SIZE (buf));

  //is gl
  if (glimage_sink->is_gl) {
    //increment gl buffer ref before storage
    gl_buffer = GST_GL_BUFFER (gst_buffer_ref (buf));

    //if glimagesink has not the display yet
    if (glimage_sink->display == NULL) {
      glimage_sink->display = g_object_ref (gl_buffer->display);

      gst_gl_display_set_client_reshape_callback (glimage_sink->display,
          glimage_sink->clientReshapeCallback);

      gst_gl_display_set_client_draw_callback (glimage_sink->display,
          glimage_sink->clientDrawCallback);
    }
  }
  //is not gl
  else {
    //if glimagesink has not the display yet
    if (glimage_sink->display == NULL) {
      //create a display
      glimage_sink->display = gst_gl_display_new ();

      //init opengl context
      gst_gl_display_create_context (glimage_sink->display,
          glimage_sink->width, glimage_sink->height, 0);

      //init colorspace conversion if needed
      gst_gl_display_init_upload (glimage_sink->display, glimage_sink->format,
          glimage_sink->width, glimage_sink->height,
          glimage_sink->width, glimage_sink->height);

      gst_gl_display_set_client_reshape_callback (glimage_sink->display,
          glimage_sink->clientReshapeCallback);

      gst_gl_display_set_client_draw_callback (glimage_sink->display,
          glimage_sink->clientDrawCallback);
    }
    //blocking call
    gl_buffer = gst_gl_buffer_new (glimage_sink->display,
        glimage_sink->width, glimage_sink->height);

    //blocking call
    gst_gl_display_do_upload (glimage_sink->display, gl_buffer->texture,
        glimage_sink->width, glimage_sink->height, GST_BUFFER_DATA (buf));

    //gl_buffer is created in this block, so the gl buffer is already referenced
  }

  if (glimage_sink->window_id != glimage_sink->new_window_id) {
    glimage_sink->window_id = glimage_sink->new_window_id;
    gst_gl_display_set_window_id (glimage_sink->display,
        glimage_sink->window_id);
  }

  //the buffer is cleared when an other comes in
  if (glimage_sink->stored_buffer) {
    gst_buffer_unref (GST_BUFFER_CAST (glimage_sink->stored_buffer));
    glimage_sink->stored_buffer = NULL;
  }
  //store current buffer
  glimage_sink->stored_buffer = gl_buffer;

  //redisplay opengl scene
  if (gl_buffer->texture &&
      gst_gl_display_redisplay (glimage_sink->display,
          gl_buffer->texture, gl_buffer->width, gl_buffer->height, 
          glimage_sink->keep_aspect_ratio))
    return GST_FLOW_OK;
  else
    return GST_FLOW_UNEXPECTED;
}