xref: /OK3568_Linux_fs/external/gstreamer-rockchip/gst/rkximage/ximagesink.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun #ifndef __GST_X_IMAGE_SINK_H__
2*4882a593Smuzhiyun #define __GST_X_IMAGE_SINK_H__
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun #include <gst/video/gstvideosink.h>
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #ifdef HAVE_XSHM
7*4882a593Smuzhiyun #include <sys/types.h>
8*4882a593Smuzhiyun #include <sys/ipc.h>
9*4882a593Smuzhiyun #include <sys/shm.h>
10*4882a593Smuzhiyun #endif /* HAVE_XSHM */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <X11/Xlib.h>
13*4882a593Smuzhiyun #include <X11/Xutil.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <string.h>
16*4882a593Smuzhiyun #include <math.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /* Helper functions */
19*4882a593Smuzhiyun #include <gst/video/video.h>
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun G_BEGIN_DECLS
22*4882a593Smuzhiyun #define GST_TYPE_X_IMAGE_SINK \
23*4882a593Smuzhiyun   (gst_x_image_sink_get_type())
24*4882a593Smuzhiyun #define GST_X_IMAGE_SINK(obj) \
25*4882a593Smuzhiyun   (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_X_IMAGE_SINK, GstRkXImageSink))
26*4882a593Smuzhiyun #define GST_X_IMAGE_SINK_CLASS(klass) \
27*4882a593Smuzhiyun   (G_TYPE_CHECK_CLASS_CAST((klass), GST_TYPE_X_IMAGE_SINK, GstRkXImageSinkClass))
28*4882a593Smuzhiyun #define GST_IS_X_IMAGE_SINK(obj) \
29*4882a593Smuzhiyun   (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_X_IMAGE_SINK))
30*4882a593Smuzhiyun #define GST_IS_X_IMAGE_SINK_CLASS(klass) \
31*4882a593Smuzhiyun   (G_TYPE_CHECK_CLASS_TYPE((klass), GST_TYPE_X_IMAGE_SINK))
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun typedef struct _GstXContext GstXContext;
34*4882a593Smuzhiyun typedef struct _GstXWindow GstXWindow;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun typedef struct _GstRkXImageSink GstRkXImageSink;
37*4882a593Smuzhiyun typedef struct _GstRkXImageSinkClass GstRkXImageSinkClass;
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /*
40*4882a593Smuzhiyun  * GstXContext:
41*4882a593Smuzhiyun  * @disp: the X11 Display of this context
42*4882a593Smuzhiyun  * @screen: the default Screen of Display @disp
43*4882a593Smuzhiyun  * @screen_num: the Screen number of @screen
44*4882a593Smuzhiyun  * @visual: the default Visual of Screen @screen
45*4882a593Smuzhiyun  * @root: the root Window of Display @disp
46*4882a593Smuzhiyun  * @white: the value of a white pixel on Screen @screen
47*4882a593Smuzhiyun  * @black: the value of a black pixel on Screen @screen
48*4882a593Smuzhiyun  * @depth: the color depth of Display @disp
49*4882a593Smuzhiyun  * @bpp: the number of bits per pixel on Display @disp
50*4882a593Smuzhiyun  * @endianness: the endianness of image bytes on Display @disp
51*4882a593Smuzhiyun  * @width: the width in pixels of Display @disp
52*4882a593Smuzhiyun  * @height: the height in pixels of Display @disp
53*4882a593Smuzhiyun  * @widthmm: the width in millimeters of Display @disp
54*4882a593Smuzhiyun  * @heightmm: the height in millimeters of Display @disp
55*4882a593Smuzhiyun  *
56*4882a593Smuzhiyun  * Structure used to store various informations collected/calculated for a
57*4882a593Smuzhiyun  * Display.
58*4882a593Smuzhiyun  */
59*4882a593Smuzhiyun struct _GstXContext
60*4882a593Smuzhiyun {
61*4882a593Smuzhiyun   Display *disp;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun   Screen *screen;
64*4882a593Smuzhiyun   gint screen_num;
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun   Visual *visual;
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun   Window root;
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun   gulong white, black;
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun   gint depth;
73*4882a593Smuzhiyun   gint bpp;
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun   gint width, height;
76*4882a593Smuzhiyun   gint widthmm, heightmm;
77*4882a593Smuzhiyun };
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /*
80*4882a593Smuzhiyun  * GstXWindow:
81*4882a593Smuzhiyun  * @win: the Window ID of this X11 window
82*4882a593Smuzhiyun  * @width: the width in pixels of Window @win
83*4882a593Smuzhiyun  * @height: the height in pixels of Window @win
84*4882a593Smuzhiyun  * @internal: used to remember if Window @win was created internally or passed
85*4882a593Smuzhiyun  * through the #GstVideoOverlay interface
86*4882a593Smuzhiyun  * @gc: the Graphical Context of Window @win
87*4882a593Smuzhiyun  *
88*4882a593Smuzhiyun  * Structure used to store informations about a Window.
89*4882a593Smuzhiyun  */
90*4882a593Smuzhiyun struct _GstXWindow
91*4882a593Smuzhiyun {
92*4882a593Smuzhiyun   Window win;
93*4882a593Smuzhiyun   gint width, height;
94*4882a593Smuzhiyun   gboolean internal;
95*4882a593Smuzhiyun   GC gc;
96*4882a593Smuzhiyun };
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun /**
99*4882a593Smuzhiyun  * GstRkXImageSink:
100*4882a593Smuzhiyun  * @display_name: the name of the Display we want to render to
101*4882a593Smuzhiyun  * @xcontext: our instance's #GstXContext
102*4882a593Smuzhiyun  * @xwindow: the #GstXWindow we are rendering to
103*4882a593Smuzhiyun  * @ximage: internal #GstXImage used to store incoming buffers and render when
104*4882a593Smuzhiyun  * not using the buffer_alloc optimization mechanism
105*4882a593Smuzhiyun  * @cur_image: a reference to the last #GstXImage that was put to @xwindow. It
106*4882a593Smuzhiyun  * is used when Expose events are received to redraw the latest video frame
107*4882a593Smuzhiyun  * @event_thread: a thread listening for events on @xwindow and handling them
108*4882a593Smuzhiyun  * @running: used to inform @event_thread if it should run/shutdown
109*4882a593Smuzhiyun  * @fps_n: the framerate fraction numerator
110*4882a593Smuzhiyun  * @fps_d: the framerate fraction denominator
111*4882a593Smuzhiyun  * @x_lock: used to protect X calls as we are not using the XLib in threaded
112*4882a593Smuzhiyun  * mode
113*4882a593Smuzhiyun  * @flow_lock: used to protect data flow routines from external calls such as
114*4882a593Smuzhiyun  * events from @event_thread or methods from the #GstVideoOverlay interface
115*4882a593Smuzhiyun  * @par: used to override calculated pixel aspect ratio from @xcontext
116*4882a593Smuzhiyun  * @pool_lock: used to protect the buffer pool
117*4882a593Smuzhiyun  * @buffer_pool: a list of #GstXImageBuffer that could be reused at next buffer
118*4882a593Smuzhiyun  * allocation call
119*4882a593Smuzhiyun  * @synchronous: used to store if XSynchronous should be used or not (for
120*4882a593Smuzhiyun  * debugging purpose only)
121*4882a593Smuzhiyun  * @handle_events: used to know if we should handle select XEvents or not
122*4882a593Smuzhiyun  *
123*4882a593Smuzhiyun  * The #GstRkXImageSink data structure.
124*4882a593Smuzhiyun  */
125*4882a593Smuzhiyun struct _GstRkXImageSink
126*4882a593Smuzhiyun {
127*4882a593Smuzhiyun   /* Our element stuff */
128*4882a593Smuzhiyun   GstVideoSink videosink;
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun   gint fd;
131*4882a593Smuzhiyun   gint conn_id;
132*4882a593Smuzhiyun   gint crtc_id;
133*4882a593Smuzhiyun   gint plane_id;
134*4882a593Smuzhiyun   guint pipe;
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun   guint16 hdisplay, vdisplay;
137*4882a593Smuzhiyun   guint32 buffer_id;
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun   /* capabilities */
140*4882a593Smuzhiyun   gboolean has_prime_import;
141*4882a593Smuzhiyun   gboolean has_prime_export;
142*4882a593Smuzhiyun   gboolean has_async_page_flip;
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun   char *display_name;
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun   GstXContext *xcontext;
147*4882a593Smuzhiyun   GstXWindow *xwindow;
148*4882a593Smuzhiyun   GstBuffer *cur_image;
149*4882a593Smuzhiyun   GstVideoRectangle clip_rect;
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun   GThread *event_thread;
152*4882a593Smuzhiyun   gboolean running;
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun   /* Framerate numerator and denominator */
155*4882a593Smuzhiyun   gint fps_n;
156*4882a593Smuzhiyun   gint fps_d;
157*4882a593Smuzhiyun   gint par_n;
158*4882a593Smuzhiyun   gint par_d;
159*4882a593Smuzhiyun   gboolean keep_aspect;
160*4882a593Smuzhiyun 
161*4882a593Smuzhiyun   GMutex x_lock;
162*4882a593Smuzhiyun   GMutex flow_lock;
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun   gboolean synchronous;
165*4882a593Smuzhiyun   gboolean handle_events;
166*4882a593Smuzhiyun   gboolean handle_expose;
167*4882a593Smuzhiyun   gboolean draw_border;
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun   /* stream metadata */
170*4882a593Smuzhiyun   gchar *media_title;
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun   GstVideoInfo vinfo;
173*4882a593Smuzhiyun   GstCaps *allowed_caps;
174*4882a593Smuzhiyun   GstBufferPool *pool;
175*4882a593Smuzhiyun   GstAllocator *allocator;
176*4882a593Smuzhiyun   GstBuffer *last_buffer;
177*4882a593Smuzhiyun 
178*4882a593Smuzhiyun   gchar *devname;
179*4882a593Smuzhiyun   gchar *bus_id;
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun   guint32 mm_width, mm_height;
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun   GstPoll *poll;
184*4882a593Smuzhiyun   GstPollFD pollfd;
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun   guint32 last_fb_id;
187*4882a593Smuzhiyun   GstVideoRectangle save_rect;
188*4882a593Smuzhiyun   gboolean paused;
189*4882a593Smuzhiyun };
190*4882a593Smuzhiyun 
191*4882a593Smuzhiyun struct _GstRkXImageSinkClass
192*4882a593Smuzhiyun {
193*4882a593Smuzhiyun   GstVideoSinkClass parent_class;
194*4882a593Smuzhiyun };
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun GType gst_x_image_sink_get_type (void);
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun G_END_DECLS
199*4882a593Smuzhiyun #endif /* __GST_X_IMAGE_SINK_H__ */
200