Ejemplo n.º 1
0
void
gtk_gst_base_widget_set_buffer (GtkGstBaseWidget * widget, GstBuffer * buffer)
{
  /* As we have no type, this is better then no check */
  g_return_if_fail (GTK_IS_WIDGET (widget));

  GTK_GST_BASE_WIDGET_LOCK (widget);

  gst_buffer_replace (&widget->pending_buffer, buffer);

  if (!widget->draw_id) {
    widget->draw_id = g_idle_add_full (G_PRIORITY_DEFAULT,
        (GSourceFunc) _queue_draw, widget, NULL);
  }

  GTK_GST_BASE_WIDGET_UNLOCK (widget);
}
Ejemplo n.º 2
0
gboolean
gtk_gst_base_widget_set_format (GtkGstBaseWidget * widget,
    GstVideoInfo * v_info)
{
  GTK_GST_BASE_WIDGET_LOCK (widget);

  if (gst_video_info_is_equal (&widget->v_info, v_info)) {
    GTK_GST_BASE_WIDGET_UNLOCK (widget);
    return TRUE;
  }

  if (!_calculate_par (widget, v_info)) {
    GTK_GST_BASE_WIDGET_UNLOCK (widget);
    return FALSE;
  }

  widget->pending_resize = TRUE;
  widget->pending_v_info = *v_info;

  GTK_GST_BASE_WIDGET_UNLOCK (widget);

  return TRUE;
}
Ejemplo n.º 3
0
static gboolean
_queue_draw (GtkGstBaseWidget * widget)
{
  GTK_GST_BASE_WIDGET_LOCK (widget);
  widget->draw_id = 0;

  if (widget->pending_resize) {
    widget->pending_resize = FALSE;

    widget->v_info = widget->pending_v_info;
    widget->negotiated = TRUE;

    _apply_par (widget);

    gtk_widget_queue_resize (GTK_WIDGET (widget));
  } else {
    gtk_widget_queue_draw (GTK_WIDGET (widget));
  }

  GTK_GST_BASE_WIDGET_UNLOCK (widget);

  return G_SOURCE_REMOVE;
}
Ejemplo n.º 4
0
static gboolean
gtk_gst_widget_draw (GtkWidget * widget, cairo_t * cr)
{
  GtkGstBaseWidget *gst_widget = (GtkGstBaseWidget *) widget;
  guint widget_width, widget_height;
  cairo_surface_t *surface;
  GstVideoFrame frame;

  widget_width = gtk_widget_get_allocated_width (widget);
  widget_height = gtk_widget_get_allocated_height (widget);

  GTK_GST_BASE_WIDGET_LOCK (gst_widget);

  /* There is not much to optimize in term of redisplay, so simply swap the
   * pending_buffer with the active buffer */
  if (gst_widget->pending_buffer) {
    if (gst_widget->buffer)
      gst_buffer_unref (gst_widget->buffer);
    gst_widget->buffer = gst_widget->pending_buffer;
    gst_widget->pending_buffer = NULL;
  }

  /* failed to map the video frame */
  if (gst_widget->negotiated && gst_widget->buffer
      && gst_video_frame_map (&frame, &gst_widget->v_info,
          gst_widget->buffer, GST_MAP_READ)) {
    gdouble scale_x = (gdouble) widget_width / gst_widget->display_width;
    gdouble scale_y = (gdouble) widget_height / gst_widget->display_height;
    GstVideoRectangle result;
    cairo_format_t format;

    gst_widget->v_info = frame.info;
    if (frame.info.finfo->format == GST_VIDEO_FORMAT_ARGB ||
        frame.info.finfo->format == GST_VIDEO_FORMAT_BGRA) {
      format = CAIRO_FORMAT_ARGB32;
    } else {
      format = CAIRO_FORMAT_RGB24;
    }

    surface = cairo_image_surface_create_for_data (frame.data[0],
        format, frame.info.width, frame.info.height, frame.info.stride[0]);

    if (gst_widget->force_aspect_ratio) {
      GstVideoRectangle src, dst;

      src.x = 0;
      src.y = 0;
      src.w = gst_widget->display_width;
      src.h = gst_widget->display_height;

      dst.x = 0;
      dst.y = 0;
      dst.w = widget_width;
      dst.h = widget_height;

      gst_video_sink_center_rect (src, dst, &result, TRUE);

      scale_x = scale_y = MIN (scale_x, scale_y);
    } else {
      result.x = 0;
      result.y = 0;
      result.w = widget_width;
      result.h = widget_height;
    }

    if (gst_widget->ignore_alpha) {
      GdkRGBA color = { 0.0, 0.0, 0.0, 1.0 };

      gdk_cairo_set_source_rgba (cr, &color);
      if (result.x > 0) {
        cairo_rectangle (cr, 0, 0, result.x, widget_height);
        cairo_fill (cr);
      }
      if (result.y > 0) {
        cairo_rectangle (cr, 0, 0, widget_width, result.y);
        cairo_fill (cr);
      }
      if (result.w < widget_width) {
        cairo_rectangle (cr, result.x + result.w, 0, widget_width - result.w,
            widget_height);
        cairo_fill (cr);
      }
      if (result.h < widget_height) {
        cairo_rectangle (cr, 0, result.y + result.h, widget_width,
            widget_height - result.h);
        cairo_fill (cr);
      }
    }

    scale_x *= (gdouble) gst_widget->display_width / (gdouble) frame.info.width;
    scale_y *=
        (gdouble) gst_widget->display_height / (gdouble) frame.info.height;

    cairo_translate (cr, result.x, result.y);
    cairo_scale (cr, scale_x, scale_y);
    cairo_rectangle (cr, 0, 0, result.w, result.h);
    cairo_set_source_surface (cr, surface, 0, 0);
    cairo_paint (cr);

    cairo_surface_destroy (surface);

    gst_video_frame_unmap (&frame);
  } else {
    GdkRGBA color;

    if (gst_widget->ignore_alpha) {
      color.red = color.blue = color.green = 0.0;
      color.alpha = 1.0;
    } else {
      gtk_style_context_get_color (gtk_widget_get_style_context (widget),
          GTK_STATE_FLAG_NORMAL, &color);
    }
    gdk_cairo_set_source_rgba (cr, &color);
    cairo_rectangle (cr, 0, 0, widget_width, widget_height);
    cairo_fill (cr);
  }

  GTK_GST_BASE_WIDGET_UNLOCK (gst_widget);
  return FALSE;
}