Rename linux-xshm module to linux-capture
This commit is contained in:
30
plugins/linux-capture/CMakeLists.txt
Normal file
30
plugins/linux-capture/CMakeLists.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
project(linux-capture)
|
||||
|
||||
find_package(X11 REQUIRED)
|
||||
|
||||
include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/libobs")
|
||||
|
||||
set(linux-capture_SOURCES
|
||||
linux-capture.c
|
||||
xcursor.c
|
||||
xhelpers.c
|
||||
capture-input.c
|
||||
)
|
||||
set(linux-capture_HEADERS
|
||||
xcursor.h
|
||||
xhelpers.h
|
||||
)
|
||||
|
||||
add_library(linux-capture MODULE
|
||||
${linux-capture_SOURCES}
|
||||
${linux-capture_HEADERS}
|
||||
)
|
||||
target_link_libraries(linux-capture
|
||||
libobs
|
||||
${X11_LIBRARIES}
|
||||
${X11_XShm_LIB}
|
||||
${X11_Xfixes_LIB}
|
||||
${X11_Xinerama_LIB}
|
||||
)
|
||||
|
||||
install_obs_plugin_with_data(linux-capture data)
|
19
plugins/linux-capture/README
Normal file
19
plugins/linux-capture/README
Normal file
@@ -0,0 +1,19 @@
|
||||
|
||||
Linux XShm capture plugin
|
||||
|
||||
This plugin uses the MIT-SHM extension for the X-server to capture the
|
||||
desktop.
|
||||
|
||||
Todo:
|
||||
|
||||
- handle resolution changes of screens
|
||||
- handle adding/removing screens while recording
|
||||
- support different depths
|
||||
|
||||
Contributing:
|
||||
|
||||
If you are interested in helping out with the plugin, please drop by in the
|
||||
#obs-dev channel on quakenet.
|
||||
|
||||
References:
|
||||
- http://www.x.org/releases/current/doc/xextproto/shm.html
|
4
plugins/linux-capture/data/locale/ar-SA.ini
Normal file
4
plugins/linux-capture/data/locale/ar-SA.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="التقاط الشاشة (XSHM)"
|
||||
Screen="الشاشة"
|
||||
CaptureCursor="مؤشر الالتقاط"
|
||||
|
4
plugins/linux-capture/data/locale/da-DK.ini
Normal file
4
plugins/linux-capture/data/locale/da-DK.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Indfang Skærm (XSHM)"
|
||||
Screen="Skærm"
|
||||
CaptureCursor="Indfang markøren"
|
||||
|
4
plugins/linux-capture/data/locale/de-DE.ini
Normal file
4
plugins/linux-capture/data/locale/de-DE.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Monitoraufnahme (XSHM)"
|
||||
Screen="Monitor"
|
||||
CaptureCursor="Mauszeiger aufnehmen"
|
||||
|
3
plugins/linux-capture/data/locale/en-US.ini
Normal file
3
plugins/linux-capture/data/locale/en-US.ini
Normal file
@@ -0,0 +1,3 @@
|
||||
X11SharedMemoryScreenInput="Screen Capture (XSHM)"
|
||||
Screen="Screen"
|
||||
CaptureCursor="Capture Cursor"
|
4
plugins/linux-capture/data/locale/es-ES.ini
Normal file
4
plugins/linux-capture/data/locale/es-ES.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Captura de pantalla (XSHM)"
|
||||
Screen="Pantalla"
|
||||
CaptureCursor="Captura de Cursor"
|
||||
|
4
plugins/linux-capture/data/locale/eu-ES.ini
Normal file
4
plugins/linux-capture/data/locale/eu-ES.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Ikusleiho Harpena (XSHM)"
|
||||
Screen="Ikusleihoa"
|
||||
CaptureCursor="Hartu Kurtsorea"
|
||||
|
4
plugins/linux-capture/data/locale/fi-FI.ini
Normal file
4
plugins/linux-capture/data/locale/fi-FI.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Ruudunkaappaus (XSHM)"
|
||||
Screen="Kuvaruutu"
|
||||
CaptureCursor="Kaappaa kursori"
|
||||
|
4
plugins/linux-capture/data/locale/fr-FR.ini
Normal file
4
plugins/linux-capture/data/locale/fr-FR.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Capture d'écran (XSHM)"
|
||||
Screen="Écran"
|
||||
CaptureCursor="Enregistrer le Curseur"
|
||||
|
4
plugins/linux-capture/data/locale/gl-ES.ini
Normal file
4
plugins/linux-capture/data/locale/gl-ES.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Captura de pantalla (XSHM)"
|
||||
Screen="Pantalla"
|
||||
CaptureCursor="Captura de cursor"
|
||||
|
4
plugins/linux-capture/data/locale/hr-HR.ini
Normal file
4
plugins/linux-capture/data/locale/hr-HR.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Ekranski ulaz (XSHM)"
|
||||
Screen="Ekran"
|
||||
CaptureCursor="Snimaj kursor"
|
||||
|
4
plugins/linux-capture/data/locale/hu-HU.ini
Normal file
4
plugins/linux-capture/data/locale/hu-HU.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Képernyő Felvétel (XSHM)"
|
||||
Screen="Képernyő"
|
||||
CaptureCursor="Kurzor Rögztítése"
|
||||
|
4
plugins/linux-capture/data/locale/it-IT.ini
Normal file
4
plugins/linux-capture/data/locale/it-IT.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Cattura schermo (XSHM)"
|
||||
Screen="Schermo"
|
||||
CaptureCursor="Cattura il cursore"
|
||||
|
4
plugins/linux-capture/data/locale/ja-JP.ini
Normal file
4
plugins/linux-capture/data/locale/ja-JP.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="画面キャプチャ (XSHM)"
|
||||
Screen="画面"
|
||||
CaptureCursor="カーソルをキャプチャ"
|
||||
|
4
plugins/linux-capture/data/locale/ko-KR.ini
Normal file
4
plugins/linux-capture/data/locale/ko-KR.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="화면 캡쳐 (XSHM)"
|
||||
Screen="화면"
|
||||
CaptureCursor="커서 캡쳐"
|
||||
|
4
plugins/linux-capture/data/locale/nb-NO.ini
Normal file
4
plugins/linux-capture/data/locale/nb-NO.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Skjermopptak (XSHM)"
|
||||
Screen="Skjerm"
|
||||
CaptureCursor="Ta opp musepeker"
|
||||
|
4
plugins/linux-capture/data/locale/nl-NL.ini
Normal file
4
plugins/linux-capture/data/locale/nl-NL.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Schermcapture (XSHM)"
|
||||
Screen="Scherm"
|
||||
CaptureCursor="Cursor Opnemen"
|
||||
|
4
plugins/linux-capture/data/locale/pl-PL.ini
Normal file
4
plugins/linux-capture/data/locale/pl-PL.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Przechwytywanie ekranu (XSHM)"
|
||||
Screen="Ekran"
|
||||
CaptureCursor="Przechwytywanie kursora"
|
||||
|
4
plugins/linux-capture/data/locale/pt-BR.ini
Normal file
4
plugins/linux-capture/data/locale/pt-BR.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Captura de Tela (XSHM)"
|
||||
Screen="Tela"
|
||||
CaptureCursor="Capturar o Cursor"
|
||||
|
4
plugins/linux-capture/data/locale/pt-PT.ini
Normal file
4
plugins/linux-capture/data/locale/pt-PT.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Captura de tela (XSHM)"
|
||||
Screen="Tela"
|
||||
CaptureCursor="Capturar o Cursor"
|
||||
|
4
plugins/linux-capture/data/locale/ro-RO.ini
Normal file
4
plugins/linux-capture/data/locale/ro-RO.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Captură de ecran (XSHM)"
|
||||
Screen="Ecran"
|
||||
CaptureCursor="Capturează cursorul"
|
||||
|
4
plugins/linux-capture/data/locale/ru-RU.ini
Normal file
4
plugins/linux-capture/data/locale/ru-RU.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Захват экрана (XSHM)"
|
||||
Screen="Экран"
|
||||
CaptureCursor="Захват курсора"
|
||||
|
4
plugins/linux-capture/data/locale/sl-SI.ini
Normal file
4
plugins/linux-capture/data/locale/sl-SI.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Zajemanje zaslona (XSHM)"
|
||||
Screen="Zaslon"
|
||||
CaptureCursor="Zajemaj kazalec"
|
||||
|
4
plugins/linux-capture/data/locale/sr-CS.ini
Normal file
4
plugins/linux-capture/data/locale/sr-CS.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Ekranski ulaz (XSHM)"
|
||||
Screen="Ekran"
|
||||
CaptureCursor="Snimaj kursor"
|
||||
|
4
plugins/linux-capture/data/locale/sr-SP.ini
Normal file
4
plugins/linux-capture/data/locale/sr-SP.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Екрански улаз (XSHM)"
|
||||
Screen="Екран"
|
||||
CaptureCursor="Снимај курсор"
|
||||
|
4
plugins/linux-capture/data/locale/sv-SE.ini
Normal file
4
plugins/linux-capture/data/locale/sv-SE.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Bildskärmskälla (XSHM)"
|
||||
Screen="Skärm"
|
||||
CaptureCursor="Visa muspekare"
|
||||
|
4
plugins/linux-capture/data/locale/tr-TR.ini
Normal file
4
plugins/linux-capture/data/locale/tr-TR.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="Ekran Yakalama (XSHM)"
|
||||
Screen="Ekran"
|
||||
CaptureCursor="İmleci Yakala"
|
||||
|
4
plugins/linux-capture/data/locale/zh-TW.ini
Normal file
4
plugins/linux-capture/data/locale/zh-TW.ini
Normal file
@@ -0,0 +1,4 @@
|
||||
X11SharedMemoryScreenInput="截取螢幕(XSHM)"
|
||||
Screen="螢幕"
|
||||
CaptureCursor="捕捉游標"
|
||||
|
28
plugins/linux-capture/linux-capture.c
Normal file
28
plugins/linux-capture/linux-capture.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Leonhard Oelke <leonhard@in-verted.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <obs-module.h>
|
||||
|
||||
OBS_DECLARE_MODULE()
|
||||
OBS_MODULE_USE_DEFAULT_LOCALE("linux-xshm", "en-US")
|
||||
|
||||
extern struct obs_source_info xshm_input;
|
||||
|
||||
bool obs_module_load(void)
|
||||
{
|
||||
obs_register_source(&xshm_input);
|
||||
return true;
|
||||
}
|
114
plugins/linux-capture/xcursor.c
Normal file
114
plugins/linux-capture/xcursor.c
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Leonhard Oelke <leonhard@in-verted.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <X11/extensions/Xfixes.h>
|
||||
|
||||
#include <util/bmem.h>
|
||||
#include "xcursor.h"
|
||||
|
||||
/*
|
||||
* Get pixel data for the cursor
|
||||
*
|
||||
* XFixes has the data defined as unsigned long, so we can not use memcpy.
|
||||
* Theres a lot of talk about this in other implementation and they tend to
|
||||
* be really complicated, but this naive approach seems to work fine ...
|
||||
*/
|
||||
static uint32_t *xcursor_pixels(XFixesCursorImage *xc) {
|
||||
uint_fast32_t size = xc->width * xc->height;
|
||||
uint32_t *pixels = bmalloc(size * sizeof(uint32_t));
|
||||
|
||||
for (uint_fast32_t i = 0; i < size; ++i)
|
||||
pixels[i] = (uint32_t) xc->pixels[i];
|
||||
|
||||
return pixels;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the cursor texture, either by updating if the new cursor has the same
|
||||
* size or by creating a new texture if the size is different
|
||||
*/
|
||||
static void xcursor_create(xcursor_t *data, XFixesCursorImage *xc) {
|
||||
uint32_t *pixels = xcursor_pixels(xc);
|
||||
|
||||
if (data->tex
|
||||
&& data->last_height == xc->width
|
||||
&& data->last_width == xc->height) {
|
||||
gs_texture_set_image(data->tex, (const uint8_t *) pixels,
|
||||
xc->width * sizeof(uint32_t), False);
|
||||
} else {
|
||||
if (data->tex)
|
||||
gs_texture_destroy(data->tex);
|
||||
|
||||
data->tex = gs_texture_create(xc->width, xc->height,
|
||||
GS_BGRA, 1, (const uint8_t **) &pixels, GS_DYNAMIC);
|
||||
}
|
||||
|
||||
bfree(pixels);
|
||||
|
||||
data->last_serial = xc->cursor_serial;
|
||||
data->last_width = xc->width;
|
||||
data->last_height = xc->height;
|
||||
}
|
||||
|
||||
xcursor_t *xcursor_init(Display *dpy) {
|
||||
xcursor_t *data = bzalloc(sizeof(xcursor_t));
|
||||
|
||||
data->dpy = dpy;
|
||||
xcursor_tick(data);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void xcursor_destroy(xcursor_t *data) {
|
||||
if (data->tex)
|
||||
gs_texture_destroy(data->tex);
|
||||
bfree(data);
|
||||
}
|
||||
|
||||
void xcursor_tick(xcursor_t *data) {
|
||||
XFixesCursorImage *xc = XFixesGetCursorImage(data->dpy);
|
||||
|
||||
if (!data->tex || data->last_serial != xc->cursor_serial)
|
||||
xcursor_create(data, xc);
|
||||
data->pos_x = xc->x - xc->xhot - data->x_org;
|
||||
data->pos_y = xc->y - xc->yhot - data->y_org;
|
||||
|
||||
XFree(xc);
|
||||
}
|
||||
|
||||
void xcursor_render(xcursor_t *data) {
|
||||
gs_effect_t effect = gs_get_effect();
|
||||
gs_eparam_t image = gs_effect_get_param_by_name(effect, "image");
|
||||
gs_effect_set_texture(image, data->tex);
|
||||
|
||||
gs_matrix_push();
|
||||
gs_matrix_translate3f(data->pos_x, data->pos_y, 0.0f);
|
||||
|
||||
gs_enable_blending(True);
|
||||
gs_blend_function(GS_BLEND_ONE, GS_BLEND_INVSRCALPHA);
|
||||
gs_draw_sprite(data->tex, 0, 0, 0);
|
||||
|
||||
gs_matrix_pop();
|
||||
}
|
||||
|
||||
void xcursor_offset(xcursor_t* data, int_fast32_t x_org, int_fast32_t y_org)
|
||||
{
|
||||
data->x_org = x_org;
|
||||
data->y_org = y_org;
|
||||
}
|
||||
|
72
plugins/linux-capture/xcursor.h
Normal file
72
plugins/linux-capture/xcursor.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Leonhard Oelke <leonhard@in-verted.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <obs.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
Display *dpy;
|
||||
float pos_x;
|
||||
float pos_y;
|
||||
unsigned long last_serial;
|
||||
uint_fast32_t last_width;
|
||||
uint_fast32_t last_height;
|
||||
gs_texture_t tex;
|
||||
|
||||
int_fast32_t x_org;
|
||||
int_fast32_t y_org;
|
||||
} xcursor_t;
|
||||
|
||||
/**
|
||||
* Initializes the xcursor object
|
||||
*
|
||||
* This needs to be executed within a valid render context
|
||||
*/
|
||||
xcursor_t *xcursor_init(Display *dpy);
|
||||
|
||||
/**
|
||||
* Destroys the xcursor object
|
||||
*/
|
||||
void xcursor_destroy(xcursor_t *data);
|
||||
|
||||
/**
|
||||
* Update the cursor texture
|
||||
*
|
||||
* This needs to be executed within a valid render context
|
||||
*/
|
||||
void xcursor_tick(xcursor_t *data);
|
||||
|
||||
/**
|
||||
* Draw the cursor
|
||||
*
|
||||
* This needs to be executed within a valid render context
|
||||
*/
|
||||
void xcursor_render(xcursor_t *data);
|
||||
|
||||
/**
|
||||
* Specify offset for the cursor
|
||||
*/
|
||||
void xcursor_offset(xcursor_t *data, int_fast32_t x_org, int_fast32_t y_org);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
150
plugins/linux-capture/xhelpers.c
Normal file
150
plugins/linux-capture/xhelpers.c
Normal file
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Leonhard Oelke <leonhard@in-verted.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/shm.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/extensions/Xinerama.h>
|
||||
|
||||
#include "xhelpers.h"
|
||||
|
||||
int_fast32_t xinerama_is_active(Display *dpy)
|
||||
{
|
||||
int minor, major;
|
||||
if (!dpy)
|
||||
return 0;
|
||||
if (!XineramaQueryVersion(dpy, &minor, &major))
|
||||
return 0;
|
||||
if (!XineramaIsActive(dpy))
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int_fast32_t xinerama_screen_count(Display *dpy)
|
||||
{
|
||||
int screens;
|
||||
if (!dpy)
|
||||
return 0;
|
||||
XFree(XineramaQueryScreens(dpy, &screens));
|
||||
return screens;
|
||||
}
|
||||
|
||||
int_fast32_t xinerama_screen_geo(Display *dpy, const int_fast32_t screen,
|
||||
int_fast32_t *x, int_fast32_t *y, int_fast32_t *w, int_fast32_t *h)
|
||||
{
|
||||
int screens;
|
||||
XineramaScreenInfo *info = NULL;
|
||||
|
||||
if (!dpy)
|
||||
goto fail;
|
||||
info = XineramaQueryScreens(dpy, &screens);
|
||||
if (screen < 0 || screen >= screens)
|
||||
goto fail;
|
||||
|
||||
*x = info[screen].x_org;
|
||||
*y = info[screen].y_org;
|
||||
*w = info[screen].width;
|
||||
*h = info[screen].height;
|
||||
|
||||
XFree(info);
|
||||
return 0;
|
||||
fail:
|
||||
if (info)
|
||||
XFree(info);
|
||||
|
||||
*x = *y = *w = *h = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int_fast32_t x11_screen_geo(Display *dpy, const int_fast32_t screen,
|
||||
int_fast32_t *w, int_fast32_t *h)
|
||||
{
|
||||
Screen *scr;
|
||||
|
||||
if (!dpy || screen < 0 || screen >= XScreenCount(dpy))
|
||||
goto fail;
|
||||
|
||||
scr = XScreenOfDisplay(dpy, screen);
|
||||
if (!scr)
|
||||
goto fail;
|
||||
|
||||
*w = XWidthOfScreen(scr);
|
||||
*h = XHeightOfScreen(scr);
|
||||
|
||||
return 0;
|
||||
fail:
|
||||
*w = *h = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
xshm_t *xshm_attach(Display *dpy, Screen *screen,
|
||||
int_fast32_t w, int_fast32_t h)
|
||||
{
|
||||
if (!dpy || !screen)
|
||||
return NULL;
|
||||
|
||||
xshm_t *xshm = bzalloc(sizeof(xshm_t));
|
||||
|
||||
xshm->dpy = dpy;
|
||||
xshm->image = XShmCreateImage(xshm->dpy, DefaultVisualOfScreen(screen),
|
||||
DefaultDepthOfScreen(screen), ZPixmap, NULL, &xshm->info,
|
||||
w, h);
|
||||
if (!xshm->image)
|
||||
goto fail;
|
||||
|
||||
xshm->info.shmid = shmget(IPC_PRIVATE,
|
||||
xshm->image->bytes_per_line * xshm->image->height,
|
||||
IPC_CREAT | 0700);
|
||||
if (xshm->info.shmid < 0)
|
||||
goto fail;
|
||||
|
||||
xshm->info.shmaddr
|
||||
= xshm->image->data
|
||||
= (char *) shmat(xshm->info.shmid, 0, 0);
|
||||
if (xshm->info.shmaddr == (char *) -1)
|
||||
goto fail;
|
||||
xshm->info.readOnly = false;
|
||||
|
||||
if (!XShmAttach(xshm->dpy, &xshm->info))
|
||||
goto fail;
|
||||
|
||||
xshm->attached = true;
|
||||
return xshm;
|
||||
fail:
|
||||
xshm_detach(xshm);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void xshm_detach(xshm_t *xshm)
|
||||
{
|
||||
if (!xshm)
|
||||
return;
|
||||
|
||||
if (xshm->attached)
|
||||
XShmDetach(xshm->dpy, &xshm->info);
|
||||
|
||||
if (xshm->info.shmaddr != (char *) -1)
|
||||
shmdt(xshm->info.shmaddr);
|
||||
|
||||
if (xshm->info.shmid != -1)
|
||||
shmctl(xshm->info.shmid, IPC_RMID, NULL);
|
||||
|
||||
if (xshm->image)
|
||||
XDestroyImage(xshm->image);
|
||||
|
||||
bfree(xshm);
|
||||
}
|
101
plugins/linux-capture/xhelpers.h
Normal file
101
plugins/linux-capture/xhelpers.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Leonhard Oelke <leonhard@in-verted.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/XShm.h>
|
||||
#include <obs.h>
|
||||
|
||||
typedef struct {
|
||||
XShmSegmentInfo info;
|
||||
XImage *image;
|
||||
Display *dpy;
|
||||
bool attached;
|
||||
} xshm_t;
|
||||
|
||||
/**
|
||||
* Check for Xinerama extension
|
||||
*
|
||||
* @return > 0 if Xinerama is available and active
|
||||
*/
|
||||
int_fast32_t xinerama_is_active(Display *dpy);
|
||||
|
||||
/**
|
||||
* Get the number of Xinerama screens
|
||||
*
|
||||
* @return number of screens
|
||||
*/
|
||||
int_fast32_t xinerama_screen_count(Display *dpy);
|
||||
|
||||
/**
|
||||
* Get screen geometry for a Xinerama screen
|
||||
*
|
||||
* @note On error the passed coordinates/sizes will be set to 0.
|
||||
*
|
||||
* @param dpy X11 display
|
||||
* @param screen screen number to get geometry for
|
||||
* @param x x-coordinate of the screen
|
||||
* @param y y-coordinate of the screen
|
||||
* @param w width of the screen
|
||||
* @param h height of the screen
|
||||
*
|
||||
* @return < 0 on error
|
||||
*/
|
||||
int_fast32_t xinerama_screen_geo(Display *dpy, const int_fast32_t screen,
|
||||
int_fast32_t *x, int_fast32_t *y, int_fast32_t *w, int_fast32_t *h);
|
||||
|
||||
/**
|
||||
* Get screen geometry for a X11 screen
|
||||
*
|
||||
* @note On error the passed sizes will be set to 0.
|
||||
*
|
||||
* @param dpy X11 display
|
||||
* @param screen screen number to get geometry for
|
||||
* @param w width of the screen
|
||||
* @param h height of the screen
|
||||
*
|
||||
* @return < 0 on error
|
||||
*/
|
||||
int_fast32_t x11_screen_geo(Display *dpy, const int_fast32_t screen,
|
||||
int_fast32_t *w, int_fast32_t *h);
|
||||
|
||||
/**
|
||||
* Attach a shared memory segment to the X-Server
|
||||
*
|
||||
* @param dpy X11 Display
|
||||
* @param screen X11 Screen
|
||||
* @param w width for the shared memory segment
|
||||
* @param h height for the shared memory segment
|
||||
*
|
||||
* @return NULL on error
|
||||
*/
|
||||
xshm_t *xshm_attach(Display *dpy, Screen *screen,
|
||||
int_fast32_t w, int_fast32_t h);
|
||||
|
||||
/**
|
||||
* Detach a shared memory segment
|
||||
*/
|
||||
void xshm_detach(xshm_t *xshm);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
314
plugins/linux-capture/xshm-input.c
Normal file
314
plugins/linux-capture/xshm-input.c
Normal file
@@ -0,0 +1,314 @@
|
||||
/*
|
||||
Copyright (C) 2014 by Leonhard Oelke <leonhard@in-verted.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#include <obs-module.h>
|
||||
#include "xcursor.h"
|
||||
#include "xhelpers.h"
|
||||
|
||||
#define XSHM_DATA(voidptr) struct xshm_data *data = voidptr;
|
||||
|
||||
struct xshm_data {
|
||||
Display *dpy;
|
||||
Screen *screen;
|
||||
|
||||
int_fast32_t x_org, y_org;
|
||||
int_fast32_t width, height;
|
||||
|
||||
xshm_t *xshm;
|
||||
gs_texture_t texture;
|
||||
|
||||
bool show_cursor;
|
||||
xcursor_t *cursor;
|
||||
|
||||
bool use_xinerama;
|
||||
};
|
||||
|
||||
/**
|
||||
* Resize the texture
|
||||
*
|
||||
* This will automatically create the texture if it does not exist
|
||||
*/
|
||||
static void xshm_resize_texture(struct xshm_data *data)
|
||||
{
|
||||
obs_enter_graphics();
|
||||
|
||||
if (data->texture)
|
||||
gs_texture_destroy(data->texture);
|
||||
data->texture = gs_texture_create(data->width, data->height,
|
||||
GS_BGRA, 1, NULL, GS_DYNAMIC);
|
||||
|
||||
obs_leave_graphics();
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the capture
|
||||
*
|
||||
* @return < 0 on error, 0 when size is unchanged, > 1 on size change
|
||||
*/
|
||||
static int_fast32_t xshm_update_geometry(struct xshm_data *data,
|
||||
obs_data_t settings)
|
||||
{
|
||||
int_fast32_t old_width = data->width;
|
||||
int_fast32_t old_height = data->height;
|
||||
int_fast32_t screen = obs_data_get_int(settings, "screen");
|
||||
|
||||
if (data->use_xinerama) {
|
||||
if (xinerama_screen_geo(data->dpy, screen,
|
||||
&data->x_org, &data->y_org,
|
||||
&data->width, &data->height) < 0) {
|
||||
return -1;
|
||||
}
|
||||
data->screen = XDefaultScreenOfDisplay(data->dpy);
|
||||
}
|
||||
else {
|
||||
data->x_org = 0;
|
||||
data->y_org = 0;
|
||||
if (x11_screen_geo(data->dpy, screen,
|
||||
&data->width, &data->height) < 0) {
|
||||
return -1;
|
||||
}
|
||||
data->screen = XScreenOfDisplay(data->dpy, screen);
|
||||
}
|
||||
|
||||
if (!data->width || !data->height) {
|
||||
blog(LOG_ERROR, "xshm-input: Failed to get geometry");
|
||||
return -1;
|
||||
}
|
||||
|
||||
blog(LOG_INFO, "xshm-input: Geometry %"PRIdFAST32"x%"PRIdFAST32
|
||||
" @ %"PRIdFAST32",%"PRIdFAST32,
|
||||
data->width, data->height, data->x_org, data->y_org);
|
||||
|
||||
if (old_width == data->width && old_height == data->height)
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the plugin
|
||||
*/
|
||||
static const char* xshm_getname(void)
|
||||
{
|
||||
return obs_module_text("X11SharedMemoryScreenInput");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the capture with changed settings
|
||||
*/
|
||||
static void xshm_update(void *vptr, obs_data_t settings)
|
||||
{
|
||||
XSHM_DATA(vptr);
|
||||
|
||||
data->show_cursor = obs_data_get_bool(settings, "show_cursor");
|
||||
|
||||
if (data->xshm)
|
||||
xshm_detach(data->xshm);
|
||||
|
||||
if (xshm_update_geometry(data, settings) < 0) {
|
||||
blog(LOG_ERROR, "xshm-input: failed to update geometry !");
|
||||
return;
|
||||
}
|
||||
|
||||
xshm_resize_texture(data);
|
||||
xcursor_offset(data->cursor, data->x_org, data->y_org);
|
||||
|
||||
data->xshm = xshm_attach(data->dpy, data->screen,
|
||||
data->width, data->height);
|
||||
if (!data->xshm) {
|
||||
blog(LOG_ERROR, "xshm-input: failed to attach shm !");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default settings for the capture
|
||||
*/
|
||||
static void xshm_defaults(obs_data_t defaults)
|
||||
{
|
||||
obs_data_set_default_int(defaults, "screen", 0);
|
||||
obs_data_set_default_bool(defaults, "show_cursor", true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the properties for the capture
|
||||
*/
|
||||
static obs_properties_t xshm_properties(void)
|
||||
{
|
||||
obs_properties_t props = obs_properties_create();
|
||||
int_fast32_t screen_max;
|
||||
|
||||
Display *dpy = XOpenDisplay(NULL);
|
||||
screen_max = xinerama_is_active(dpy)
|
||||
? xinerama_screen_count(dpy)
|
||||
: XScreenCount(dpy);
|
||||
screen_max = (screen_max) ? screen_max - 1 : 0;
|
||||
XCloseDisplay(dpy);
|
||||
|
||||
obs_properties_add_int(props, "screen",
|
||||
obs_module_text("Screen"), 0, screen_max, 1);
|
||||
obs_properties_add_bool(props, "show_cursor",
|
||||
obs_module_text("CaptureCursor"));
|
||||
|
||||
return props;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the capture
|
||||
*/
|
||||
static void xshm_destroy(void *vptr)
|
||||
{
|
||||
XSHM_DATA(vptr);
|
||||
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
obs_enter_graphics();
|
||||
|
||||
if (data->texture)
|
||||
gs_texture_destroy(data->texture);
|
||||
if (data->cursor)
|
||||
xcursor_destroy(data->cursor);
|
||||
|
||||
obs_leave_graphics();
|
||||
|
||||
if (data->xshm)
|
||||
xshm_detach(data->xshm);
|
||||
if (data->dpy)
|
||||
XCloseDisplay(data->dpy);
|
||||
|
||||
bfree(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the capture
|
||||
*/
|
||||
static void *xshm_create(obs_data_t settings, obs_source_t source)
|
||||
{
|
||||
UNUSED_PARAMETER(source);
|
||||
|
||||
struct xshm_data *data = bzalloc(sizeof(struct xshm_data));
|
||||
|
||||
data->dpy = XOpenDisplay(NULL);
|
||||
if (!data->dpy) {
|
||||
blog(LOG_ERROR, "xshm-input: Unable to open X display !");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (!XShmQueryExtension(data->dpy)) {
|
||||
blog(LOG_ERROR, "xshm-input: XShm extension not found !");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
data->use_xinerama = xinerama_is_active(data->dpy) ? true : false;
|
||||
|
||||
obs_enter_graphics();
|
||||
data->cursor = xcursor_init(data->dpy);
|
||||
obs_leave_graphics();
|
||||
|
||||
xshm_update(data, settings);
|
||||
|
||||
return data;
|
||||
fail:
|
||||
xshm_destroy(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the capture data
|
||||
*/
|
||||
static void xshm_video_tick(void *vptr, float seconds)
|
||||
{
|
||||
UNUSED_PARAMETER(seconds);
|
||||
XSHM_DATA(vptr);
|
||||
|
||||
if (!data->xshm)
|
||||
return;
|
||||
|
||||
obs_enter_graphics();
|
||||
|
||||
XShmGetImage(data->dpy, XRootWindowOfScreen(data->screen),
|
||||
data->xshm->image, data->x_org, data->y_org, AllPlanes);
|
||||
gs_texture_set_image(data->texture, (void *) data->xshm->image->data,
|
||||
data->width * 4, false);
|
||||
|
||||
xcursor_tick(data->cursor);
|
||||
|
||||
obs_leave_graphics();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the capture data
|
||||
*/
|
||||
static void xshm_video_render(void *vptr, gs_effect_t effect)
|
||||
{
|
||||
XSHM_DATA(vptr);
|
||||
|
||||
if (!data->xshm)
|
||||
return;
|
||||
|
||||
gs_eparam_t image = gs_effect_get_param_by_name(effect, "image");
|
||||
gs_effect_set_texture(image, data->texture);
|
||||
|
||||
gs_enable_blending(false);
|
||||
gs_draw_sprite(data->texture, 0, 0, 0);
|
||||
|
||||
if (data->show_cursor)
|
||||
xcursor_render(data->cursor);
|
||||
|
||||
gs_reset_blend_state();
|
||||
}
|
||||
|
||||
/**
|
||||
* Width of the captured data
|
||||
*/
|
||||
static uint32_t xshm_getwidth(void *vptr)
|
||||
{
|
||||
XSHM_DATA(vptr);
|
||||
return data->width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Height of the captured data
|
||||
*/
|
||||
static uint32_t xshm_getheight(void *vptr)
|
||||
{
|
||||
XSHM_DATA(vptr);
|
||||
return data->height;
|
||||
}
|
||||
|
||||
struct obs_source_info xshm_input = {
|
||||
.id = "xshm_input",
|
||||
.type = OBS_SOURCE_TYPE_INPUT,
|
||||
.output_flags = OBS_SOURCE_VIDEO,
|
||||
.get_name = xshm_getname,
|
||||
.create = xshm_create,
|
||||
.destroy = xshm_destroy,
|
||||
.update = xshm_update,
|
||||
.get_defaults = xshm_defaults,
|
||||
.get_properties = xshm_properties,
|
||||
.video_tick = xshm_video_tick,
|
||||
.video_render = xshm_video_render,
|
||||
.get_width = xshm_getwidth,
|
||||
.get_height = xshm_getheight
|
||||
};
|
Reference in New Issue
Block a user