1 /*****************************************************************
2  * gmerlin - a general purpose multimedia framework and applications
3  *
4  * Copyright (c) 2001 - 2011 Members of the Gmerlin project
5  * gmerlin-general@lists.sourceforge.net
6  * http://gmerlin.sourceforge.net
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  * *****************************************************************/
21 
22 #include <config.h>
23 #include <gmerlin/translation.h>
24 #include <gmerlin/plugin.h>
25 
26 #include <x11/x11.h>
27 
28 typedef struct
29   {
30   bg_x11_grab_window_t * win;
31   } x11_t;
32 
create_x11()33 static void * create_x11()
34   {
35   x11_t * x11;
36   x11 = calloc(1, sizeof(*x11));
37 
38   x11->win = bg_x11_grab_window_create();
39 
40   return x11;
41   }
42 
destroy_x11(void * priv)43 static void destroy_x11(void * priv)
44   {
45   x11_t * x11 = priv;
46   bg_x11_grab_window_destroy(x11->win);
47   free(priv);
48   }
49 
get_parameters_x11(void * priv)50 static const bg_parameter_info_t * get_parameters_x11(void * priv)
51   {
52   x11_t * x11 = priv;
53   return bg_x11_grab_window_get_parameters(x11->win);
54   }
55 
set_parameter_x11(void * priv,const char * name,const bg_parameter_value_t * val)56 static void set_parameter_x11(void * priv, const char * name,
57                               const bg_parameter_value_t * val)
58   {
59   x11_t * x11 = priv;
60   bg_x11_grab_window_set_parameter(x11->win, name, val);
61   }
62 
get_parameter_x11(void * priv,const char * name,bg_parameter_value_t * val)63 static int get_parameter_x11(void * priv, const char * name,
64                              bg_parameter_value_t * val)
65   {
66   x11_t * x11 = priv;
67   return bg_x11_grab_window_get_parameter(x11->win, name, val);
68   }
69 
open_x11(void * priv,gavl_audio_format_t * audio_format,gavl_video_format_t * format)70 static int open_x11(void * priv,
71                     gavl_audio_format_t * audio_format,
72                     gavl_video_format_t * format)
73   {
74   x11_t * x11 = priv;
75   return bg_x11_grab_window_init(x11->win, format);
76   }
77 
close_x11(void * priv)78 static void close_x11(void * priv)
79   {
80   x11_t * x11 = priv;
81   bg_x11_grab_window_close(x11->win);
82   }
83 
read_frame_x11(void * priv,gavl_video_frame_t * frame,int stream)84 static int read_frame_x11(void * priv, gavl_video_frame_t * frame, int stream)
85   {
86   x11_t * x11 = priv;
87   return bg_x11_grab_window_grab(x11->win, frame);
88   }
89 
90 const bg_recorder_plugin_t the_plugin =
91   {
92     .common =
93     {
94       BG_LOCALE,
95       .name =          "i_x11",
96       .long_name =     TRS("X11"),
97       .description =   TRS("X11 grabber"),
98       .type =          BG_PLUGIN_RECORDER_VIDEO,
99       .flags =         BG_PLUGIN_RECORDER,
100       .priority =      BG_PLUGIN_PRIORITY_MAX-1,
101       .create =        create_x11,
102       .destroy =       destroy_x11,
103 
104       .get_parameters = get_parameters_x11,
105       .set_parameter =  set_parameter_x11,
106       .get_parameter =  get_parameter_x11,
107     },
108 
109     .open =       open_x11,
110     .close =      close_x11,
111     .read_video = read_frame_x11,
112   };
113 
114 /* Include this into all plugin modules exactly once
115    to let the plugin loader obtain the API version */
116 BG_GET_PLUGIN_API_VERSION;
117