UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
screen_linux.c
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2023 CESNET
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, is permitted provided that the following conditions
13 * are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 *
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 *
22 * 3. Neither the name of CESNET nor the names of its contributors may be
23 * used to endorse or promote products derived from this software without
24 * specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
28 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
29 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
30 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
31 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
36 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
37 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 */
39#include "config.h"
40#include "config_unix.h"
41#include "config_win32.h"
42
43#include <stdlib.h>
44#include <string.h>
45
46#include "debug.h"
47#include "lib_common.h"
48#include "utils/color_out.h"
49#include "utils/text.h"
50#include "video_capture.h"
51
52static void vidcap_screen_linux_probe(struct device_info **cards, int *count, void (**deleter)(void *))
53{
54 *cards = NULL;
55 *count = 0;
56 *deleter = free;
57}
58
59static int
61{
62 struct vidcap *device = NULL;
63
64 if (strcmp(vidcap_params_get_fmt(params), "help") == 0) {
65 char desc[] = TRED(TBOLD("screen")) " capture in Linux abstracts X11/PipeWire screen capture and tries to select "
66 "the right implementation. You can also specify directly " TBOLD("screen_x11") " or " TBOLD("screen_pw") ".";
68 color_printf("Compiled modules:");
69#ifdef HAVE_SCREEN_X11
70 color_printf(TBOLD(" X11"));
71#endif
72#ifdef HAVE_SCREEN_PW
73 color_printf(TBOLD(" pipewire"));
74#endif
75 printf("\n\nFollows help for the module that would have been selected:\n\n");
76 }
77
78 struct vidcap_params *params_new = vidcap_params_copy(params);
79 if (getenv("WAYLAND_DISPLAY") != NULL) {
80 vidcap_params_set_driver(params_new, "screen_pw");
81 verbose_msg("Trying to initialize screen_pw\n");
82 int ret = initialize_video_capture(NULL, params_new, &device);
83 if (ret < 0) {
84 error_msg("screen_pw initialization failed\n");
85 } else {
86 vidcap_params_free_struct(params_new);
87 *state = device;
88 return ret;
89 }
90 }
91 verbose_msg("Trying to initialize screen_x11\n");
92 if (getenv("DISPLAY") == NULL) {
93 log_msg(LOG_LEVEL_WARNING, "Trying to initalize screen_x11 but DISPLAY environment variable is not set!\n");
94 }
95 vidcap_params_set_driver(params_new, "screen_x11");
96 int ret = initialize_video_capture(NULL, params_new, &device);
97 vidcap_params_free_struct(params_new);
98
99 *state = device;
100 return ret;
101}
102
103static void
105{
106 vidcap_done((struct vidcap *) state);
107}
108
109static struct video_frame *
111{
112 return vidcap_grab((struct vidcap *) state, audio);
113}
114
122
124
void ** state
struct video_desc desc
struct audio_frame ** audio
int void(** deleter)(void *))
int color_printf(const char *format,...)
#define TRED(x)
Definition color_out.h:75
#define TBOLD(x)
Definition color_out.h:70
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define error_msg(...)
Definition debug.h:89
#define verbose_msg(...)
Definition debug.h:90
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60
struct video_frame * vidcap_grab(struct vidcap *state, struct audio_frame **audio)
Grabs video frame. This function may block for a short period if waiting for incoming frame....
int initialize_video_capture(struct module *parent, struct vidcap_params *param, struct vidcap **state)
Initializes video capture.
void vidcap_done(struct vidcap *state)
Destroys vidap state.
#define VIDEO_CAPTURE_ABI_VERSION
int count
Definition hd-rum.c:44
@ LIBRARY_CLASS_VIDEO_CAPTURE
Definition lib_common.h:78
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
Definition lib_common.h:144
static int vidcap_screen_linux_init(struct vidcap_params *params, void **state)
static const struct video_capture_info vidcap_screen_linux_info
static void vidcap_screen_linux_probe(struct device_info **cards, int *count, void(**deleter)(void *))
static struct video_frame * vidcap_screen_linux_grab(void *state, struct audio_frame **audio)
static void vidcap_screen_linux_done(void *state)
struct used to comunicate with audio capture/playback device
Definition types.h:99
This struct represents video capture state.
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
char * wrap_paragraph(char *text)
Definition text.c:204
void vidcap_params_set_driver(struct vidcap_params *params, const char *driver)
void vidcap_params_free_struct(struct vidcap_params *buf)
struct vidcap_params * vidcap_params_copy(const struct vidcap_params *params)
const char * vidcap_params_get_fmt(const struct vidcap_params *params)