Commit 0cf39283 authored by Wim Taymans's avatar Wim Taymans

xvimagesink: use xvcontext for allocation

Make a new refcounted xvcontext object that handles the X connection.
Use the xvcontext to allocate images and windows. Move some code
around so that all X calls are made from the xvcontext object.
Make a GstXvImageAllocator object that allocates images from the xvcontext. We
can implement a copy function now for these memory objects now.
Make the bufferpool use the xvimageallocator object for its images.
parent 5127d31c
plugin_LTLIBRARIES = libgstxvimagesink.la
libgstxvimagesink_la_SOURCES = xvimagesink.c xvimage.c xvimagepool.c
libgstxvimagesink_la_SOURCES = xvimagesink.c xvimage.c xvimagepool.c xvimageallocator.c xvcontext.c
libgstxvimagesink_la_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(X_CFLAGS)
libgstxvimagesink_la_LIBADD = \
$(top_builddir)/gst-libs/gst/video/libgstvideo-$(GST_API_VERSION).la \
......@@ -11,4 +11,4 @@ libgstxvimagesink_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstxvimagesink_la_DEPENDENCIES = $(top_builddir)/gst-libs/gst/video/libgstvideo-$(GST_API_VERSION).la
libgstxvimagesink_la_LIBTOOLFLAGS = --tag=disable-static
noinst_HEADERS = xvimagesink.h xvimagepool.h
noinst_HEADERS = xvimagesink.h xvimagepool.h xvimageallocator.h xvcontext.h
This diff is collapsed.
/* GStreamer
* Copyright (C) <2005> Julien Moutte <julien@moutte.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_XVCONTEXT_H__
#define __GST_XVCONTEXT_H__
#ifdef HAVE_XSHM
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#endif /* HAVE_XSHM */
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef HAVE_XSHM
#include <X11/extensions/XShm.h>
#endif /* HAVE_XSHM */
#include <X11/extensions/Xv.h>
#include <X11/extensions/Xvlib.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <gst/video/video.h>
G_BEGIN_DECLS
typedef struct _GstXvContextConfig GstXvContextConfig;
typedef struct _GstXvImageFormat GstXvImageFormat;
typedef struct _GstXvContext GstXvContext;
/**
* GstXvContextConfig:
*
* current configuration of the context
*/
struct _GstXvContextConfig
{
gchar *display_name;
guint adaptor_nr;
/* port attributes */
gboolean autopaint_colorkey;
gint colorkey;
gboolean double_buffer;
gint brightness;
gint contrast;
gint hue;
gint saturation;
gboolean cb_changed;
};
/**
* GstXvImageFormat:
* @format: the image format
* @caps: generated #GstCaps for this image format
*
* Structure storing image format to #GstCaps association.
*/
struct _GstXvImageFormat
{
gint format;
GstVideoFormat vformat;
GstCaps *caps;
};
#define GST_TYPE_XVCONTEXT (gst_xvcontext_get_type())
#define GST_IS_XVCONTEXT(obj) (GST_IS_MINI_OBJECT_TYPE(obj, GST_TYPE_XVCONTEXT))
#define GST_XVCONTEXT_CAST(obj) ((GstXvContext *)obj)
#define GST_XVCONTEXT(obj) (GST_XVCONTEXT_CAST(obj))
/*
* GstXvContext:
* @disp: the X11 Display of this context
* @screen: the default Screen of Display @disp
* @screen_num: the Screen number of @screen
* @visual: the default Visual of Screen @screen
* @root: the root Window of Display @disp
* @white: the value of a white pixel on Screen @screen
* @black: the value of a black pixel on Screen @screen
* @depth: the color depth of Display @disp
* @bpp: the number of bits per pixel on Display @disp
* @endianness: the endianness of image bytes on Display @disp
* @width: the width in pixels of Display @disp
* @height: the height in pixels of Display @disp
* @widthmm: the width in millimeters of Display @disp
* @heightmm: the height in millimeters of Display @disp
* @par: the pixel aspect ratio calculated from @width, @widthmm and @height,
* @heightmm ratio
* @use_xshm: used to known wether of not XShm extension is usable or not even
* if the Extension is present
* @xv_port_id: the XVideo port ID
* @im_format: used to store at least a valid format for XShm calls checks
* @formats_list: list of supported image formats on @xv_port_id
* @channels_list: list of #GstColorBalanceChannels
* @caps: the #GstCaps that Display @disp can accept
*
* Structure used to store various informations collected/calculated for a
* Display.
*/
struct _GstXvContext
{
GstMiniObject parent;
GMutex lock;
Display *disp;
Screen *screen;
gint screen_num;
Visual *visual;
Window root;
gulong white, black;
gint depth;
gint bpp;
gint endianness;
gint width, height;
gint widthmm, heightmm;
GValue *par; /* calculated pixel aspect ratio */
gboolean use_xshm;
XvPortID xv_port_id;
guint nb_adaptors;
gchar **adaptors;
guint adaptor_nr;
gint im_format;
/* port features */
gboolean have_autopaint_colorkey;
gboolean have_colorkey;
gboolean have_double_buffer;
GList *formats_list;
GList *channels_list;
GstCaps *caps;
/* Optimisation storage for buffer_alloc return */
GstCaps *last_caps;
gint last_format;
gint last_width;
gint last_height;
};
GType gst_xvcontext_get_type (void);
void gst_xvcontext_config_clear (GstXvContextConfig *config);
GstXvContext * gst_xvcontext_new (GstXvContextConfig *config, GError **error);
/* refcounting */
static inline GstXvContext *
gst_xvcontext_ref (GstXvContext * xvcontext)
{
return GST_XVCONTEXT_CAST (gst_mini_object_ref (GST_MINI_OBJECT_CAST (
xvcontext)));
}
static inline void
gst_xvcontext_unref (GstXvContext * xvcontext)
{
gst_mini_object_unref (GST_MINI_OBJECT_CAST (xvcontext));
}
gint gst_xvcontext_get_format_from_info (GstXvContext * xvcontext,
GstVideoInfo * info);
void gst_xvcontext_set_synchronous (GstXvContext * xvcontext,
gboolean synchronous);
void gst_xvcontext_update_colorbalance (GstXvContext * xvcontext,
GstXvContextConfig * config);
typedef struct _GstXWindow GstXWindow;
/*
* GstXWindow:
* @win: the Window ID of this X11 window
* @width: the width in pixels of Window @win
* @height: the height in pixels of Window @win
* @internal: used to remember if Window @win was created internally or passed
* through the #GstVideoOverlay interface
* @gc: the Graphical Context of Window @win
*
* Structure used to store informations about a Window.
*/
struct _GstXWindow
{
GstXvContext *context;
Window win;
gint width, height;
gboolean have_render_rect;
GstVideoRectangle render_rect;
gboolean internal;
GC gc;
};
G_END_DECLS
GstXWindow * gst_xvcontext_create_xwindow (GstXvContext * context,
gint width, gint height);
GstXWindow * gst_xvcontext_create_xwindow_from_xid (GstXvContext * context, XID xid);
void gst_xwindow_destroy (GstXWindow * window);
void gst_xwindow_set_event_handling (GstXWindow * window, gboolean handle_events);
void gst_xwindow_set_title (GstXWindow * window, const gchar * title);
void gst_xwindow_update_geometry (GstXWindow * window);
void gst_xwindow_clear (GstXWindow * window);
void gst_xwindow_set_render_rectangle (GstXWindow * window,
gint x, gint y, gint width, gint height);
#endif /* __GST_XVCONTEXT_H__ */
......@@ -23,6 +23,7 @@
#include "xvimagesink.h"
GST_DEBUG_CATEGORY (gst_debug_xvcontext);
GST_DEBUG_CATEGORY (gst_debug_xvimagepool);
GST_DEBUG_CATEGORY (gst_debug_xvimagesink);
GST_DEBUG_CATEGORY_STATIC (GST_CAT_PERFORMANCE);
......@@ -34,6 +35,8 @@ plugin_init (GstPlugin * plugin)
GST_RANK_PRIMARY, GST_TYPE_XVIMAGESINK))
return FALSE;
GST_DEBUG_CATEGORY_INIT (gst_debug_xvcontext, "xcontext", 0,
"xcontext miniobject");
GST_DEBUG_CATEGORY_INIT (gst_debug_xvimagesink, "xvimagesink", 0,
"xvimagesink element");
GST_DEBUG_CATEGORY_INIT (gst_debug_xvimagepool, "xvimagepool", 0,
......
This diff is collapsed.
/* GStreamer
* Copyright (C) <2005> Julien Moutte <julien@moutte.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __GST_XVIMAGEALLOCATOR_H__
#define __GST_XVIMAGEALLOCATOR_H__
typedef struct _GstXvImageMemory GstXvImageMemory;
typedef struct _GstXvImageAllocator GstXvImageAllocator;
typedef struct _GstXvImageAllocatorClass GstXvImageAllocatorClass;
#include "xvcontext.h"
G_BEGIN_DECLS
/* allocator functions */
#define GST_TYPE_XVIMAGE_ALLOCATOR (gst_xvimage_allocator_get_type())
#define GST_IS_XVIMAGE_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_XVIMAGE_ALLOCATOR))
#define GST_XVIMAGE_ALLOCATOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_XVIMAGE_ALLOCATOR, GstXvImageAllocator))
#define GST_XVIMAGE_ALLOCATOR_CAST(obj) ((GstXvImageAllocator*)(obj))
GType gst_xvimage_allocator_get_type (void);
/* the allocator */
GstXvImageAllocator * gst_xvimage_allocator_new (GstXvContext * context);
GstXvContext * gst_xvimage_allocator_peek_context (GstXvImageAllocator * allocator);
GstMemory * gst_xvimage_allocator_alloc (GstXvImageAllocator * allocator,
gint im_format,
gint padded_width,
gint padded_height,
GstVideoRectangle *crop,
GError ** error);
/* memory from the allocator */
gboolean gst_xvimage_memory_is_from_context (GstMemory *mem,
GstXvContext * context);
gint gst_xvimage_memory_get_format (GstXvImageMemory *mem);
XvImage * gst_xvimage_memory_get_xvimage (GstXvImageMemory *mem);
gboolean gst_xvimage_memory_get_crop (GstXvImageMemory *mem,
GstVideoRectangle *crop);
void gst_xvimage_memory_render (GstXvImageMemory *mem,
GstVideoRectangle *src_crop,
GstXWindow *window,
GstVideoRectangle *dst_crop,
gboolean draw_border);
G_END_DECLS
#endif /*__GST_XVIMAGEALLOCATOR_H__*/
This diff is collapsed.
......@@ -20,63 +20,16 @@
#ifndef __GST_XVIMAGEPOOL_H__
#define __GST_XVIMAGEPOOL_H__
#ifdef HAVE_XSHM
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#endif /* HAVE_XSHM */
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef HAVE_XSHM
#include <X11/extensions/XShm.h>
#endif /* HAVE_XSHM */
#include <string.h>
#include <math.h>
#include <gst/gst.h>
#include "xvimageallocator.h"
G_BEGIN_DECLS
typedef struct _GstXvImageMemory GstXvImageMemory;
typedef struct _GstXvImageBufferPool GstXvImageBufferPool;
typedef struct _GstXvImageBufferPoolClass GstXvImageBufferPoolClass;
typedef struct _GstXvImageBufferPoolPrivate GstXvImageBufferPoolPrivate;
#include "xvimagesink.h"
/**
* GstXvImageMemory:
* @sink: a reference to the our #GstXvImageSink
* @xvimage: the XvImage of this buffer
* @width: the width in pixels of XvImage @xvimage
* @height: the height in pixels of XvImage @xvimage
* @im_format: the format of XvImage @xvimage
* @size: the size in bytes of XvImage @xvimage
*
* Subclass of #GstMemory containing additional information about an XvImage.
*/
struct _GstXvImageMemory
{
GstMemory parent;
/* Reference to the xvimagesink we belong to */
GstXvImageSink *sink;
XvImage *xvimage;
#ifdef HAVE_XSHM
XShmSegmentInfo SHMInfo;
#endif /* HAVE_XSHM */
gint x, y;
gint width, height;
gint im_format;
size_t size;
};
/* buffer pool functions */
#define GST_TYPE_XVIMAGE_BUFFER_POOL (gst_xvimage_buffer_pool_get_type())
#define GST_IS_XVIMAGE_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_XVIMAGE_BUFFER_POOL))
......@@ -87,9 +40,6 @@ struct _GstXvImageBufferPool
{
GstBufferPool bufferpool;
GstXvImageSink *sink;
GstAllocator *allocator;
GstXvImageBufferPoolPrivate *priv;
};
......@@ -100,13 +50,7 @@ struct _GstXvImageBufferPoolClass
GType gst_xvimage_buffer_pool_get_type (void);
GstBufferPool *gst_xvimage_buffer_pool_new (GstXvImageSink * xvimagesink);
gboolean gst_xvimagesink_check_xshm_calls (GstXvImageSink * xvimagesink,
GstXContext * xcontext);
gint gst_xvimagesink_get_format_from_info (GstXvImageSink * xvimagesink,
GstVideoInfo * info);
GstBufferPool * gst_xvimage_buffer_pool_new (GstXvImageAllocator *allocator);
G_END_DECLS
......
This diff is collapsed.
......@@ -22,26 +22,6 @@
#include <gst/video/gstvideosink.h>
#ifdef HAVE_XSHM
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#endif /* HAVE_XSHM */
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef HAVE_XSHM
#include <X11/extensions/XShm.h>
#endif /* HAVE_XSHM */
#include <X11/extensions/Xv.h>
#include <X11/extensions/Xvlib.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
/* Helper functions */
#include <gst/video/video.h>
......@@ -56,122 +36,18 @@ G_BEGIN_DECLS
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_XVIMAGESINK))
#define GST_IS_XVIMAGESINK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_XVIMAGESINK))
typedef struct _GstXContext GstXContext;
typedef struct _GstXWindow GstXWindow;
typedef struct _GstXvImageFormat GstXvImageFormat;
typedef struct _GstXvImageSink GstXvImageSink;
typedef struct _GstXvImageSinkClass GstXvImageSinkClass;
#include "xvimageallocator.h"
#include "xvimagepool.h"
/*
* GstXContext:
* @disp: the X11 Display of this context
* @screen: the default Screen of Display @disp
* @screen_num: the Screen number of @screen
* @visual: the default Visual of Screen @screen
* @root: the root Window of Display @disp
* @white: the value of a white pixel on Screen @screen
* @black: the value of a black pixel on Screen @screen
* @depth: the color depth of Display @disp
* @bpp: the number of bits per pixel on Display @disp
* @endianness: the endianness of image bytes on Display @disp
* @width: the width in pixels of Display @disp
* @height: the height in pixels of Display @disp
* @widthmm: the width in millimeters of Display @disp
* @heightmm: the height in millimeters of Display @disp
* @par: the pixel aspect ratio calculated from @width, @widthmm and @height,
* @heightmm ratio
* @use_xshm: used to known wether of not XShm extension is usable or not even
* if the Extension is present
* @xv_port_id: the XVideo port ID
* @im_format: used to store at least a valid format for XShm calls checks
* @formats_list: list of supported image formats on @xv_port_id
* @channels_list: list of #GstColorBalanceChannels
* @caps: the #GstCaps that Display @disp can accept
*
* Structure used to store various informations collected/calculated for a
* Display.
*/
struct _GstXContext
{
Display *disp;
Screen *screen;
gint screen_num;
Visual *visual;
Window root;
gulong white, black;
gint depth;
gint bpp;
gint endianness;
gint width, height;
gint widthmm, heightmm;
GValue *par; /* calculated pixel aspect ratio */
gboolean use_xshm;
XvPortID xv_port_id;
guint nb_adaptors;
gchar **adaptors;
gint im_format;
GList *formats_list;
GList *channels_list;
GstCaps *caps;
/* Optimisation storage for buffer_alloc return */
GstCaps *last_caps;
gint last_format;
gint last_width;
gint last_height;
};
/*
* GstXWindow:
* @win: the Window ID of this X11 window
* @width: the width in pixels of Window @win
* @height: the height in pixels of Window @win
* @internal: used to remember if Window @win was created internally or passed
* through the #GstVideoOverlay interface
* @gc: the Graphical Context of Window @win
*
* Structure used to store informations about a Window.
*/
struct _GstXWindow
{
Window win;
gint width, height;
gboolean internal;
GC gc;
};
/**
* GstXvImageFormat:
* @format: the image format
* @caps: generated #GstCaps for this image format
*
* Structure storing image format to #GstCaps association.
*/
struct _GstXvImageFormat
{
gint format;
GstVideoFormat vformat;
GstCaps *caps;
};
#include "xvcontext.h"
/**
* GstXvImageSink:
* @display_name: the name of the Display we want to render to
* @xcontext: our instance's #GstXContext
* @xvcontext: our instance's #GstXvContext
* @xwindow: the #GstXWindow we are rendering to
* @cur_image: a reference to the last #GstXvImage that was put to @xwindow. It
* is used when Expose events are received to redraw the latest video frame
......@@ -183,7 +59,7 @@ struct _GstXvImageFormat
* mode
* @flow_lock: used to protect data flow routines from external calls such as
* events from @event_thread or methods from the #GstVideoOverlay interface
* @par: used to override calculated pixel aspect ratio from @xcontext
* @par: used to override calculated pixel aspect ratio from @xvcontext
* @pool_lock: used to protect the buffer pool
* @image_pool: a list of #GstXvImageBuffer that could be reused at next buffer
* allocation call
......@@ -207,10 +83,9 @@ struct _GstXvImageSink
/* Our element stuff */
GstVideoSink videosink;
char *display_name;
guint adaptor_no;
GstXContext *xcontext;
GstXvContextConfig config;
GstXvContext *context;
GstXvImageAllocator *allocator;
GstXWindow *xwindow;
GstBuffer *cur_image;
......@@ -223,7 +98,6 @@ struct _GstXvImageSink
gint fps_n;
gint fps_d;
GMutex x_lock;
GMutex flow_lock;
/* object-set pixel aspect ratio */
......@@ -239,32 +113,13 @@ struct _GstXvImageSink
gboolean handle_events;
gboolean handle_expose;
gint brightness;
gint contrast;
gint hue;
gint saturation;
gboolean cb_changed;
/* size of incoming video, used as the size for XvImage */
guint video_width, video_height;
/* port attributes */
gboolean autopaint_colorkey;
gint colorkey;
gboolean draw_borders;
/* port features */
gboolean have_autopaint_colorkey;
gboolean have_colorkey;
gboolean have_double_buffer;
/* stream metadata */
gchar *media_title;
/* target video rectangle */
GstVideoRectangle render_rect;
gboolean have_render_rect;
};
struct _GstXvImageSinkClass
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment