Imported Upstream version 0.13.2+dsfg1

This commit is contained in:
Sebastian Ramacher 2016-02-24 00:16:51 +01:00
commit fb3990e9e5
2036 changed files with 287360 additions and 0 deletions

View file

@ -0,0 +1,51 @@
project(linux-capture)
find_package(X11 REQUIRED)
if(NOT X11_Xcomposite_FOUND)
message(STATUS "Xcomposite library not found, linux-capture plugin disabled")
return()
endif()
find_package(XCB COMPONENTS XCB SHM XFIXES XINERAMA REQUIRED)
find_package(X11_XCB REQUIRED)
include_directories(SYSTEM
"${CMAKE_SOURCE_DIR}/libobs"
${X11_Xcomposite_INCLUDE_PATH}
${X11_X11_INCLUDE_PATH}
${XCB_INCLUDE_DIRS}
)
set(linux-capture_SOURCES
linux-capture.c
xcursor.c
xcursor-xcb.c
xhelpers.c
xshm-input.c
xcomposite-main.cpp
xcompcap-main.cpp
xcompcap-helper.cpp
)
set(linux-capture_HEADERS
xcursor.h
xcursor-xcb.h
xhelpers.h
xcompcap-main.hpp
xcompcap-helper.hpp
)
add_library(linux-capture MODULE
${linux-capture_SOURCES}
${linux-capture_HEADERS}
)
target_link_libraries(linux-capture
libobs
glad
${X11_LIBRARIES}
${X11_Xfixes_LIB}
${X11_X11_LIB}
${X11_Xcomposite_LIB}
${XCB_LIBRARIES}
)
install_obs_plugin_with_data(linux-capture data)

View 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

View file

@ -0,0 +1,12 @@
X11SharedMemoryScreenInput="التقاط الشاشة (XSHM)"
Screen="الشاشة"
CaptureCursor="مؤشر الالتقاط"
XCCapture="التقاط النافذة (Xcomposite)"
Window="نافذة"
CropTop="الاقتطاع من الأعلى (بكسل)"
CropLeft="الاقتطاع من اليسار (بكسل)"
CropRight="الاقتطاع من اليمين (بكسل)"
CropBottom="الاقتطاع من الأسفل (بكسل)"
SwapRedBlue="مبادلة بين الأحمر و الأزرق"
LockX="قفل السيرفر X عند الالتقاط"

View file

@ -0,0 +1,7 @@
X11SharedMemoryScreenInput="Заснемане на екрана (XSHM)"
Screen="Екран"
CaptureCursor="Заснемане на курсора"
AdvancedSettings="Разширени настройки"
XServer="X сървър"
Window="Прозорец"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Captura la pantalla (XSHM)"
Screen="Pantalla"
CaptureCursor="Captura el cursor"
AdvancedSettings="Configuració avançada"
XServer="Servidor X"
XCCapture="Captura de finestra (Xcomposite)"
Window="Finestra"
CropTop="Escapçament superior (en píxels)"
CropLeft="Escapçament esquerre (en píxels)"
CropRight="Escapçament dret (en píxels)"
CropBottom="Escapçament inferior (en píxels)"
SwapRedBlue="Intercanvia els colors vermell i blau"
LockX="Bloca el servidor X quan s'estigui capturant"
IncludeXBorder="Inclou-hi la vora X"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Záznam obrazovky (XSHM)"
Screen="Obrazovka"
CaptureCursor="Snímat kurzor"
AdvancedSettings="Rozšířená nastavení"
XServer="Server X"
XCCapture="Záznam okna (Xcomposite)"
Window="Okno"
CropTop="Oříznout vršek (px)"
CropLeft="Oříznout vlevo (px)"
CropRight="Oříznout vpravo (px)"
CropBottom="Oříznout spodek (px)"
SwapRedBlue="Prohodit červenou a modrou"
LockX="Zamknout server X při záznamu"
IncludeXBorder="Zahrnout hranice X"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Indfang Skærm (XSHM)"
Screen="Skærm"
CaptureCursor="Indfang markøren"
AdvancedSettings="Avancerede indstillinger"
XServer="X Server"
XCCapture="Indfang Vindue (Xcomposite)"
Window="Vindue"
CropTop="Beskær Top (pixels)"
CropLeft="Beskær Venstre (pixels)"
CropRight="Beskær Højre (pixels)"
CropBottom="Beskær bund (pixels)"
SwapRedBlue="Swap rød og blå"
LockX="Lås X server ved optagelse"
IncludeXBorder="Inkluder X kant"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Bildschirmaufnahme (XSHM)"
Screen="Bildschirm"
CaptureCursor="Mauszeiger aufnehmen"
AdvancedSettings="Erweiterte Einstellungen"
XServer="X Server"
XCCapture="Fensteraufnahme (Xcomposite)"
Window="Fenster"
CropTop="Oben abschneiden (Pixel)"
CropLeft="Links abschneiden (Pixel)"
CropRight="Rechts abschneiden (Pixel)"
CropBottom="Unten abschneiden (Pixel)"
SwapRedBlue="Rot und Blau tauschen"
LockX="X Server sperren während der Aufnahme"
IncludeXBorder="X Rahmen anzeigen"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Σύλληψη Οθόνης (XSHM)"
Screen="Οθόνη"
CaptureCursor="Σύλληψη δρομέα"
AdvancedSettings="Ρυθμίσεις για Προχωρημένους"
XServer="X Server"
XCCapture="Σύλληψη Παραθύρου (XComposite)"
Window="Παράθυρο"
CropTop="Περικοπή Πάνω (pixels)"
CropLeft="Περικοπή Αριστερά (pixels)"
CropRight="Περικοπή Δεξιά (pixels)"
CropBottom="Περικοπή Κάτω (pixels)"
SwapRedBlue="Ανταλλαγή κόκκινου και μπλέ"
LockX="Κλείδωμα X server κατά την σύλληψη"
IncludeXBorder="Περίλαβε το περίγραμμα του X"

View file

@ -0,0 +1,14 @@
X11SharedMemoryScreenInput="Screen Capture (XSHM)"
Screen="Screen"
CaptureCursor="Capture Cursor"
AdvancedSettings="Advanced Settings"
XServer="X Server"
XCCapture="Window Capture (Xcomposite)"
Window="Window"
CropTop="Crop Top (pixels)"
CropLeft="Crop Left (pixels)"
CropRight="Crop Right (pixels)"
CropBottom="Crop Bottom (pixels)"
SwapRedBlue="Swap red and blue"
LockX="Lock X server when capturing"
IncludeXBorder="Include X Border"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Captura de pantalla (XSHM)"
Screen="Pantalla"
CaptureCursor="Captura de Cursor"
AdvancedSettings="Ajustes Avanzados"
XServer="X Server"
XCCapture="Captura de ventana (Xcomposite)"
Window="Ventana"
CropTop="Recortar arriba (píxeles)"
CropLeft="Recortar izquierda (pixeles)"
CropRight="Recortar derecha (píxeles)"
CropBottom="Recortar abajo (píxeles)"
SwapRedBlue="Intercambiar rojo y azúl"
LockX="Fijar X server mientras se captura"
IncludeXBorder="Incluir borde de ventana X"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Ikusleiho Harpena (XSHM)"
Screen="Ikusleihoa"
CaptureCursor="Hartu Kurtsorea"
AdvancedSettings="Ezarpen Aurreratuak"
XServer="X Zerbitzaria"
XCCapture="Leiho Harpena (Xcomposite)"
Window="Leihoa"
CropTop="Moztu Goitik (pixel)"
CropLeft="Moztu Ezkerretik (pixel)"
CropRight="Moztu Eskuinetik (pixel)"
CropBottom="Moztu Behetik (pixel)"
SwapRedBlue="Aldatu gorria eta urdina"
LockX="Blokeatu X zerbitzaria harpenean"
IncludeXBorder="Barneratu X Hertza"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Ruudunkaappaus (XSHM)"
Screen="Kuvaruutu"
CaptureCursor="Kaappaa kursori"
AdvancedSettings="Lisäasetukset"
XServer="X Server"
XCCapture="Ikkunakaappaus (Xcomposite)"
Window="Ikkuna"
CropTop="Rajaa ylhäältä (pikselit)"
CropLeft="Rajaa vasemmalta (pikselit)"
CropRight="Rajaa oikealta (pikselit)"
CropBottom="Rajaa alhaalta (pikselit)"
SwapRedBlue="Vaihda punainen ja sininen"
LockX="Lukitse X Server kaappauksen aikana"
IncludeXBorder="Sisällytä X-reunus"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Capture d'écran (XSHM)"
Screen="Écran"
CaptureCursor="Enregistrer le Curseur"
AdvancedSettings="Paramètres avancés"
XServer="Serveur X"
XCCapture="Capture de la fenêtre (Xcomposite)"
Window="Fenêtre"
CropTop="Rogner en Haut (pixels)"
CropLeft="Rogner à Gauche (pixels)"
CropRight="Rogner à Droite (pixels)"
CropBottom="Rogner en Bas (pixels)"
SwapRedBlue="Intervertir le rouge et le bleu"
LockX="Verrouiller le serveur X lors de la capture"
IncludeXBorder="Inclure la bordure de X"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Captura de pantalla (XSHM)"
Screen="Pantalla"
CaptureCursor="Captura de cursor"
AdvancedSettings="Axustes avanzados"
XServer="X Server"
XCCapture="Captura de xanela (Xcomposite)"
Window="Xanela"
CropTop="Recortar por arriba (píxeles)"
CropLeft="Recortar pola esquerda (píxeles)"
CropRight="Recortar pola dereita (píxeles)"
CropBottom="Recortar por abaixo (píxeles)"
SwapRedBlue="Trocar vermello e azul"
LockX="Bloquear o servidor X durante a captura"
IncludeXBorder="Incluír o bordo da xanela X"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Ekranski ulaz (XSHM)"
Screen="Ekran"
CaptureCursor="Snimaj kursor"
AdvancedSettings="Napredna podešavanja"
XServer="X server"
XCCapture="Ulaz sa prozora (Xcomposite)"
Window="Prozor"
CropTop="Odseci odozgo (pikseli)"
CropLeft="Odseci sa leva (pikseli)"
CropRight="Odseci sa desna (pikseli)"
CropBottom="Odseci odozdo (pikseli)"
SwapRedBlue="Zameni crvenu i plavu"
LockX="Zaključaj X server u toku snimanja"
IncludeXBorder="Uključujući i X okvir"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Képernyő Felvétel (XSHM)"
Screen="Képernyő"
CaptureCursor="Kurzor Rögztítése"
AdvancedSettings="Speciális Beállítások"
XServer="X Szerver"
XCCapture="Ablak Felvétel (Xcomposite)"
Window="Ablak"
CropTop="Felső Levágása (pixelek)"
CropLeft="Bal Levágása (pixelek)"
CropRight="Jobb Levágása (pixelek)"
CropBottom="Alsó Levágása (pixelek)"
SwapRedBlue="Piros és Kék Cseréje"
LockX="X Szerver Zárolása Rögzítéskor"
IncludeXBorder="X Kerettel"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Cattura schermo (XSHM)"
Screen="Schermo"
CaptureCursor="Cattura il cursore"
AdvancedSettings="Configurazioni Avanzate"
XServer="X Server"
XCCapture="Cattura la finestra (xcomposite)"
Window="Finestra"
CropTop="Crop Superiore (pixels)"
CropLeft="Crop Sinistro (pixels)"
CropRight="Crop Destro (pixels)"
CropBottom="Crop Inferiore (pixels)"
SwapRedBlue="Inverti rosso e blu"
LockX="Blocca l' X Server durante l'acquisizione"
IncludeXBorder="Includi X bordi"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="画面キャプチャ XSHM"
Screen="画面"
CaptureCursor="カーソルをキャプチャ"
AdvancedSettings="高度な設定"
XServer="X サーバ"
XCCapture="ウィンドウキャプチャ (Xcomposite)"
Window="ウィンドウ"
CropTop="上部クロップ(ピクセル)"
CropLeft="左側クロップ(ピクセル)"
CropRight="右側クロップ(ピクセル)"
CropBottom="下部クロップ(ピクセル)"
SwapRedBlue="赤と青を入れ替え"
LockX="キャプチャ時にXサーバをロック"
IncludeXBorder="Xウインドウの境界を含める"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="화면 캡쳐 (XSHM)"
Screen="화면"
CaptureCursor="커서 캡쳐"
AdvancedSettings="고급 설정"
XServer="X 서버"
XCCapture="윈도우 캡쳐(Xcomposite)"
Window="윈도우"
CropTop="위쪽 자르기 (픽셀)"
CropLeft="왼쪽 자르기 (픽셀)"
CropRight="오른쪽 자르기 (픽셀)"
CropBottom="아래 자르기 (픽셀)"
SwapRedBlue="적청 교환"
LockX="캡쳐 시 X 서버를 잠금"
IncludeXBorder="X 윈도우 경계를 포함"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Skjermopptak (XSHM)"
Screen="Skjerm"
CaptureCursor="Ta opp musepeker"
AdvancedSettings="Avanserte innstillinger"
XServer="X-tjener"
XCCapture="Vindusopptak (Xcomposite)"
Window="Vindu"
CropTop="Beskjær toppen (piksler)"
CropLeft="Beskjær venstre (piksler)"
CropRight="Beskjær høyre (piksler)"
CropBottom="Beskjær bunnen (piksler)"
SwapRedBlue="Bytt rød og blå"
LockX="Lås X-server under opptak"
IncludeXBorder="Inkludér X11-rammen"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Schermcapture (XSHM)"
Screen="Scherm"
CaptureCursor="Cursor Opnemen"
AdvancedSettings="Geavanceerde instellingen"
XServer="X Server"
XCCapture="Venstercapture (Xcomposite)"
Window="Venster"
CropTop="Boven Bijsnijden (pixels)"
CropLeft="Links Bijsnijden (pixels)"
CropRight="Rechts Bijsnijden (pixels)"
CropBottom="Onder Bijsnijden (pixels)"
SwapRedBlue="Rood en blauw omwisselen"
LockX="X server vergrendelen tijdens het opnemen"
IncludeXBorder="Inclusief X-schermranden"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Przechwytywanie ekranu (XSHM)"
Screen="Ekran"
CaptureCursor="Przechwytywanie kursora"
AdvancedSettings="Ustawienia zaawansowane"
XServer="X Server"
XCCapture="Przechwytywanie okna (XComposite)"
Window="Okno"
CropTop="Przytnij od góry (piksele)"
CropLeft="Przytnij z lewej (piksele)"
CropRight="Przytnij z prawej (piksele)"
CropBottom="Przytnij od spodu (piksele)"
SwapRedBlue="Zamień czerwony i niebieski"
LockX="Zablokuj serwer X podczas przechwytywania"
IncludeXBorder="Dołącz ramkę okna"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Captura de Tela (XSHM)"
Screen="Tela"
CaptureCursor="Capturar o Cursor"
AdvancedSettings="Configurações Avançadas"
XServer="Servidor x"
XCCapture="Captura de Janela (Xcomposite)"
Window="Janela"
CropTop="Cortar em Cima (Pixels)"
CropLeft="Cortar à Esquerda (Pixels)"
CropRight="Cortar à Direita (Pixels)"
CropBottom="Cortar em Baixo (Pixels)"
SwapRedBlue="Trocar Vermelho com Azul"
LockX="Bloquear servidor X durante a captura"
IncludeXBorder="Incluir X Borda"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Captura de tela (XSHM)"
Screen="Tela"
CaptureCursor="Capturar o Cursor"
AdvancedSettings="Definições avançadas"
XServer="X Server"
XCCapture="Captura de janela (Xcomposite)"
Window="Janela"
CropTop="Cortar em Cima (Pixels)"
CropLeft="Cortar à Esquerda (Pixels)"
CropRight="Cortar à direita (Pixels)"
CropBottom="Cortar em Baixo (Pixels)"
SwapRedBlue="Trocar vermelho e azul"
LockX="Bloquear servidor X durante a captura"
IncludeXBorder="Incluir X Border"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Captură de ecran (XSHM)"
Screen="Ecran"
CaptureCursor="Capturează cursorul"
AdvancedSettings="Setări Avansate"
XServer="X Server"
XCCapture="Captură Fereastră (Xcomposite)"
Window="Fereastră"
CropTop="Taie Sus (pixeli)"
CropLeft="Taie stânga (pixeli)"
CropRight="Taie Dreapta (pixeli)"
CropBottom="Taie jos (pixeli)"
SwapRedBlue="Schimbă Roșu cu Albastru"
LockX="Blochează server X atunci când se capturează"
IncludeXBorder="Include marginea cu X"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Захват экрана (XSHM)"
Screen="Экран"
CaptureCursor="Захват курсора"
AdvancedSettings="Дополнительные настройки"
XServer="X-сервер"
XCCapture="Захват окна (Xcomposite)"
Window="Окно"
CropTop="Обрезать сверху (пикселей)"
CropLeft="Обрезать слева (пикселей)"
CropRight="Обрезать справа (пикселей)"
CropBottom="Обрезать снизу (пикселей)"
SwapRedBlue="Поменять местами красный и синий"
LockX="Блокировать X-сервер при захвате"
IncludeXBorder="Включить захват границы"

View file

@ -0,0 +1,13 @@
X11SharedMemoryScreenInput="Zachytávanie monitora (XSHM)"
Screen="Monitor"
CaptureCursor="Zachytávať kurzor"
AdvancedSettings="Rozšírené nastavenia"
XCCapture="Zachytávanie okna (Xcomposite)"
Window="Okno"
CropTop="Orezanie hore (pixely)"
CropLeft="Orezanie vľavo (pixely)"
CropRight="Orezanie vpravo (pixely)"
CropBottom="Orezanie dole (pixely)"
SwapRedBlue="Vymeniť červenú a modrú"
LockX="Zamknúť X server počas snímania"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Zajemanje zaslona (XSHM)"
Screen="Zaslon"
CaptureCursor="Zajemaj kazalec"
AdvancedSettings="Napredne nastavitve"
XServer="X Server"
XCCapture="Zajemanje okna (Xcomposite)"
Window="Okno"
CropTop="Obreži zgoraj (pixels)"
CropLeft="Obreži levo (pixels)"
CropRight="Obreži desno (pixels)"
CropBottom="Obreži spodaj (pixels)"
SwapRedBlue="Zamenjaj modro in rdečo"
LockX="Zakleni X server med zajemanjem"
IncludeXBorder="Vključujejo X meje"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Ekranski ulaz (XSHM)"
Screen="Ekran"
CaptureCursor="Snimaj kursor"
AdvancedSettings="Napredna podešavanja"
XServer="X server"
XCCapture="Улаз са прозора (Xcomposite)"
Window="Прозор"
CropTop="Одсеци одозго (пиксели)"
CropLeft="Одсеци са лева (пиксели)"
CropRight="Одсеци са десна (пиксели)"
CropBottom="Одсеци одоздо (пиксели)"
SwapRedBlue="Замени црвену и плаву"
LockX="Закључај X сервер у току снимања"
IncludeXBorder="Uključujući i X okvir"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Екрански улаз (XSHM)"
Screen="Екран"
CaptureCursor="Снимај курсор"
AdvancedSettings="Напредна подешавања"
XServer="X сервер"
XCCapture="Ulaz sa prozora (Xcomposite)"
Window="Prozor"
CropTop="Odseci odozgo (pikseli)"
CropLeft="Odseci sa leva (pikseli)"
CropRight="Odseci sa desna (pikseli)"
CropBottom="Odseci odozdo (pikseli)"
SwapRedBlue="Zameni crvenu i plavu"
LockX="Zaključaj X server u toku snimanja"
IncludeXBorder="Укључујући и X оквир"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Bildskärmskälla (XSHM)"
Screen="Skärm"
CaptureCursor="Visa muspekare"
AdvancedSettings="Avancerade Inställningar"
XServer="X-servern"
XCCapture="Fönsterkälla (Xcomposite)"
Window="Fönster"
CropTop="Beskär övre kant (pixlar)"
CropLeft="Beskär vänster kant (pixlar)"
CropRight="Beskär höger kant (pixlar)"
CropBottom="Beskär nedre kant (pixlar)"
SwapRedBlue="Byt röd och blå"
LockX="Lås X-servern medan källan är aktiv"
IncludeXBorder="Inkludera X Border"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="Ekran Yakalama (XSHM)"
Screen="Ekran"
CaptureCursor="İmleci Yakala"
AdvancedSettings="Gelişmiş Ayarlar"
XServer="X Sunucusu"
XCCapture="Pencere Yakalama (Xcomposite)"
Window="Pencere"
CropTop="Üstten Kırp (piksel)"
CropLeft="Soldan Kırp (piksel)"
CropRight="Sağdan Kırp (piksel)"
CropBottom="Alttan Kırp (piksel)"
SwapRedBlue="Kırmızı ve maviyi değiştir"
LockX="Yakalama sırasında X sunucusunu kilitle"
IncludeXBorder="X Çerçevesini Dahil Et"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="屏幕捕获(XSHM)"
Screen="屏幕"
CaptureCursor="捕捉光标"
AdvancedSettings="高级设置"
XServer="X Server"
XCCapture="窗口捕获(Xcomposite)"
Window="窗口"
CropTop="裁剪顶部(像素)"
CropLeft="裁剪左侧(像素)"
CropRight="裁剪右部(像素)"
CropBottom="裁剪下部(像素)"
SwapRedBlue="交换红色和蓝色"
LockX="当捕获时锁定X server"
IncludeXBorder="包括 X 边框"

View file

@ -0,0 +1,15 @@
X11SharedMemoryScreenInput="截取螢幕XSHM"
Screen="螢幕"
CaptureCursor="捕捉游標"
AdvancedSettings="進階設定 "
XServer="X server"
XCCapture="截取視窗Xcomposite"
Window="視窗"
CropTop="剪裁頂部px"
CropLeft="剪裁左側px"
CropRight="剪裁右側px"
CropBottom="剪裁底部px"
SwapRedBlue="交換紅藍顏色"
LockX="截取時鎖定 X server"
IncludeXBorder="包含X邊框"

View file

@ -0,0 +1,37 @@
/*
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;
extern void xcomposite_load(void);
extern void xcomposite_unload(void);
bool obs_module_load(void)
{
obs_register_source(&xshm_input);
xcomposite_load();
return true;
}
void obs_module_unload(void)
{
xcomposite_unload();
}

View file

@ -0,0 +1,421 @@
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/extensions/Xcomposite.h>
#include <unordered_set>
#include <pthread.h>
#include <obs-module.h>
#include "xcompcap-helper.hpp"
namespace XCompcap
{
static Display* xdisplay = 0;
Display *disp()
{
if (!xdisplay)
xdisplay = XOpenDisplay(NULL);
return xdisplay;
}
void cleanupDisplay()
{
if (!xdisplay)
return;
XCloseDisplay(xdisplay);
xdisplay = 0;
}
static void getAllWindows(Window parent, std::list<Window>& windows)
{
UNUSED_PARAMETER(parent);
UNUSED_PARAMETER(windows);
}
std::list<Window> getAllWindows()
{
std::list<Window> res;
for (int i = 0; i < ScreenCount(disp()); ++i)
getAllWindows(RootWindow(disp(), i), res);
return res;
}
// Specification for checking for ewmh support at
// http://standards.freedesktop.org/wm-spec/wm-spec-latest.html#idm140200472693600
bool ewmhIsSupported()
{
Display *display = disp();
Atom netSupportingWmCheck = XInternAtom(display,
"_NET_SUPPORTING_WM_CHECK", true);
Atom actualType;
int format = 0;
unsigned long num = 0, bytes = 0;
unsigned char *data = NULL;
Window ewmh_window = 0;
int status = XGetWindowProperty(
display,
DefaultRootWindow(display),
netSupportingWmCheck,
0L,
1L,
false,
XA_WINDOW,
&actualType,
&format,
&num,
&bytes,
&data);
if (status == Success) {
if (num > 0) {
ewmh_window = ((Window*)data)[0];
}
if (data) {
XFree(data);
data = NULL;
}
}
if (ewmh_window) {
status = XGetWindowProperty(
display,
ewmh_window,
netSupportingWmCheck,
0L,
1L,
false,
XA_WINDOW,
&actualType,
&format,
&num,
&bytes,
&data);
if (status != Success || num == 0 ||
ewmh_window != ((Window*)data)[0]) {
ewmh_window = 0;
}
if (status == Success && data) {
XFree(data);
}
}
return ewmh_window != 0;
}
std::list<Window> getTopLevelWindows()
{
std::list<Window> res;
if (!ewmhIsSupported()) {
blog(LOG_WARNING, "Unable to query window list "
"because window manager "
"does not support extended "
"window manager Hints");
return res;
}
Atom netClList = XInternAtom(disp(), "_NET_CLIENT_LIST", true);
Atom actualType;
int format;
unsigned long num, bytes;
Window* data = 0;
for (int i = 0; i < ScreenCount(disp()); ++i) {
Window rootWin = RootWindow(disp(), i);
int status = XGetWindowProperty(
disp(),
rootWin,
netClList,
0L,
~0L,
false,
AnyPropertyType,
&actualType,
&format,
&num,
&bytes,
(uint8_t**)&data);
if (status != Success) {
blog(LOG_WARNING, "Failed getting root "
"window properties");
continue;
}
for (unsigned long i = 0; i < num; ++i)
res.push_back(data[i]);
XFree(data);
}
return res;
}
int getRootWindowScreen(Window root)
{
XWindowAttributes attr;
if (!XGetWindowAttributes(disp(), root, &attr))
return DefaultScreen(disp());
return XScreenNumberOfScreen(attr.screen);
}
std::string getWindowName(Window win)
{
Atom netWmName = XInternAtom(disp(), "_NET_WM_NAME", false);
int n;
char **list = 0;
XTextProperty tp;
std::string res = "unknown";
XGetTextProperty(disp(), win, &tp, netWmName);
if (!tp.nitems)
XGetWMName(disp(), win, &tp);
if (!tp.nitems)
return "error";
if (tp.encoding == XA_STRING) {
res = (char*)tp.value;
} else {
int ret = XmbTextPropertyToTextList(disp(), &tp, &list,
&n);
if (ret >= Success && n > 0 && *list) {
res = *list;
XFreeStringList(list);
}
}
XFree(tp.value);
return res;
}
std::string getWindowCommand(Window win)
{
Atom xi = XInternAtom(disp(), "WM_COMMAND", false);
int n;
char **list = 0;
XTextProperty tp;
std::string res = "error";
XGetTextProperty(disp(), win, &tp, xi);
if (!tp.nitems)
return std::string();
if (tp.encoding == XA_STRING) {
res = (char*)tp.value;
} else {
int ret = XmbTextPropertyToTextList(disp(), &tp, &list,
&n);
if (ret >= Success && n > 0 && *list) {
res = *list;
XFreeStringList(list);
}
}
XFree(tp.value);
return res;
}
int getWindowPid(Window win)
{
UNUSED_PARAMETER(win);
return 1234; //TODO
}
static std::unordered_set<Window> changedWindows;
static pthread_mutex_t changeLock = PTHREAD_MUTEX_INITIALIZER;
void processEvents()
{
PLock lock(&changeLock);
XLockDisplay(disp());
while (XEventsQueued(disp(), QueuedAfterReading) > 0) {
XEvent ev;
XNextEvent(disp(), &ev);
if (ev.type == ConfigureNotify)
changedWindows.insert(ev.xconfigure.event);
if (ev.type == MapNotify)
changedWindows.insert(ev.xmap.event);
if (ev.type == Expose)
changedWindows.insert(ev.xexpose.window);
if (ev.type == DestroyNotify)
changedWindows.insert(ev.xdestroywindow.event);
}
XUnlockDisplay(disp());
}
bool windowWasReconfigured(Window win)
{
PLock lock(&changeLock);
auto it = changedWindows.find(win);
if (it != changedWindows.end()) {
changedWindows.erase(it);
return true;
}
return false;
}
}
PLock::PLock(pthread_mutex_t* mtx, bool trylock)
:m(mtx)
{
if (trylock)
islock = mtx && pthread_mutex_trylock(mtx) == 0;
else
islock = mtx && pthread_mutex_lock(mtx) == 0;
}
PLock::~PLock()
{
if (islock) {
pthread_mutex_unlock(m);
}
}
bool PLock::isLocked()
{
return islock;
}
void PLock::unlock()
{
if (islock) {
pthread_mutex_unlock(m);
islock = false;
}
}
void PLock::lock()
{
if (!islock) {
pthread_mutex_lock(m);
islock = true;
}
}
static bool* curErrorTarget = 0;
static char curErrorText[200];
static int xerrorlock_handler(Display* disp, XErrorEvent* err)
{
if (curErrorTarget)
*curErrorTarget = true;
XGetErrorText(disp, err->error_code, curErrorText, 200);
return 0;
}
XErrorLock::XErrorLock()
{
goterr = false;
islock = false;
prevhandler = 0;
lock();
}
XErrorLock::~XErrorLock()
{
unlock();
}
bool XErrorLock::isLocked()
{
return islock;
}
void XErrorLock::lock()
{
if (!islock) {
XLockDisplay(XCompcap::disp());
XSync(XCompcap::disp(), 0);
curErrorTarget = &goterr;
curErrorText[0] = 0;
prevhandler = XSetErrorHandler(xerrorlock_handler);
islock = true;
}
}
void XErrorLock::unlock()
{
if (islock) {
XSync(XCompcap::disp(), 0);
curErrorTarget = 0;
XSetErrorHandler(prevhandler);
prevhandler = 0;
XUnlockDisplay(XCompcap::disp());
islock = false;
}
}
bool XErrorLock::gotError()
{
if (!islock)
return false;
XSync(XCompcap::disp(), 0);
bool res = goterr;
goterr = false;
return res;
}
std::string XErrorLock::getErrorText()
{
return curErrorText;
}
void XErrorLock::resetError()
{
if (islock)
XSync(XCompcap::disp(), 0);
goterr = false;
curErrorText[0] = 0;
}
ObsGsContextHolder::ObsGsContextHolder()
{
obs_enter_graphics();
}
ObsGsContextHolder::~ObsGsContextHolder()
{
obs_leave_graphics();
}

View file

@ -0,0 +1,76 @@
#pragma once
#include <string>
#include <list>
#define blog(level, msg, ...) blog(level, "xcompcap: " msg, ##__VA_ARGS__)
class PLock
{
pthread_mutex_t *m;
bool islock;
public:
PLock(const PLock&) = delete;
PLock& operator=(const PLock&) = delete;
PLock(pthread_mutex_t* mtx, bool trylock = false);
~PLock();
bool isLocked();
void unlock();
void lock();
};
class XErrorLock
{
bool islock;
bool goterr;
XErrorHandler prevhandler;
public:
XErrorLock(const XErrorLock&) = delete;
XErrorLock& operator=(const XErrorLock&) = delete;
XErrorLock();
~XErrorLock();
bool isLocked();
void unlock();
void lock();
bool gotError();
std::string getErrorText();
void resetError();
};
class ObsGsContextHolder
{
public:
ObsGsContextHolder(const ObsGsContextHolder&) = delete;
ObsGsContextHolder& operator=(const ObsGsContextHolder&) = delete;
ObsGsContextHolder();
~ObsGsContextHolder();
};
namespace XCompcap
{
Display* disp();
void cleanupDisplay();
std::string getWindowCommand(Window win);
int getRootWindowScreen(Window root);
std::string getWindowName(Window win);
int getWindowPid(Window win);
bool ewmhIsSupported();
std::list<Window> getTopLevelWindows();
std::list<Window> getAllWindows();
void processEvents();
bool windowWasReconfigured(Window win);
}

View file

@ -0,0 +1,551 @@
#include <glad/glad.h>
#include <glad/glad_glx.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xcomposite.h>
#include <pthread.h>
#include <vector>
#include <obs-module.h>
#include <graphics/vec4.h>
#include <util/platform.h>
#include "xcompcap-main.hpp"
#include "xcompcap-helper.hpp"
#include "xcursor.h"
#define xdisp (XCompcap::disp())
#define WIN_STRING_DIV "\r\n"
bool XCompcapMain::init()
{
if (!xdisp) {
blog(LOG_ERROR, "failed opening display");
return false;
}
int eventBase, errorBase;
if (!XCompositeQueryExtension(xdisp, &eventBase, &errorBase)) {
blog(LOG_ERROR, "Xcomposite extension not supported");
return false;
}
int major = 0, minor = 2;
XCompositeQueryVersion(xdisp, &major, &minor);
if (major == 0 && minor < 2) {
blog(LOG_ERROR, "Xcomposite extension is too old: %d.%d < 0.2",
major, minor);
return false;
}
return true;
}
void XCompcapMain::deinit()
{
XCompcap::cleanupDisplay();
}
obs_properties_t *XCompcapMain::properties()
{
obs_properties_t *props = obs_properties_create();
obs_property_t *wins = obs_properties_add_list(props, "capture_window",
obs_module_text("Window"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
for (Window win: XCompcap::getTopLevelWindows()) {
std::string wname = XCompcap::getWindowName(win);
std::string progpath = XCompcap::getWindowCommand(win);
std::string winid = std::to_string((long long)win);
std::string desc =
(winid + WIN_STRING_DIV + wname +
WIN_STRING_DIV + progpath);
obs_property_list_add_string(wins, wname.c_str(),
desc.c_str());
}
obs_properties_add_int(props, "cut_top", obs_module_text("CropTop"),
0, 4096, 1);
obs_properties_add_int(props, "cut_left", obs_module_text("CropLeft"),
0, 4096, 1);
obs_properties_add_int(props, "cut_right", obs_module_text("CropRight"),
0, 4096, 1);
obs_properties_add_int(props, "cut_bot", obs_module_text("CropBottom"),
0, 4096, 1);
obs_properties_add_bool(props, "swap_redblue",
obs_module_text("SwapRedBlue"));
obs_properties_add_bool(props, "lock_x", obs_module_text("LockX"));
obs_properties_add_bool(props, "show_cursor",
obs_module_text("CaptureCursor"));
obs_properties_add_bool(props, "include_border",
obs_module_text("IncludeXBorder"));
return props;
}
void XCompcapMain::defaults(obs_data_t *settings)
{
obs_data_set_default_string(settings, "capture_window", "");
obs_data_set_default_int(settings, "cut_top", 0);
obs_data_set_default_int(settings, "cut_left", 0);
obs_data_set_default_int(settings, "cut_right", 0);
obs_data_set_default_int(settings, "cut_bot", 0);
obs_data_set_default_bool(settings, "swap_redblue", false);
obs_data_set_default_bool(settings, "lock_x", false);
obs_data_set_default_bool(settings, "show_cursor", true);
obs_data_set_default_bool(settings, "include_border", false);
}
struct XCompcapMain_private
{
XCompcapMain_private()
:win(0)
,cut_top(0), cur_cut_top(0)
,cut_left(0), cur_cut_left(0)
,cut_right(0), cur_cut_right(0)
,cut_bot(0), cur_cut_bot(0)
,inverted(false)
,width(0),height(0)
,pixmap(0)
,glxpixmap(0)
,tex(0)
,gltex(0)
{
pthread_mutexattr_init(&lockattr);
pthread_mutexattr_settype(&lockattr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&lock, &lockattr);
}
~XCompcapMain_private()
{
pthread_mutex_destroy(&lock);
pthread_mutexattr_destroy(&lockattr);
}
obs_source_t *source;
std::string windowName;
Window win;
int cut_top, cur_cut_top;
int cut_left, cur_cut_left;
int cut_right, cur_cut_right;
int cut_bot, cur_cut_bot;
bool inverted;
bool swapRedBlue;
bool lockX;
bool include_border;
uint32_t width;
uint32_t height;
uint32_t border;
Pixmap pixmap;
GLXPixmap glxpixmap;
gs_texture_t *tex;
gs_texture_t *gltex;
pthread_mutex_t lock;
pthread_mutexattr_t lockattr;
bool show_cursor = true;
bool cursor_outside = false;
xcursor_t *cursor = nullptr;
};
XCompcapMain::XCompcapMain(obs_data_t *settings, obs_source_t *source)
{
p = new XCompcapMain_private;
p->source = source;
obs_enter_graphics();
p->cursor = xcursor_init(xdisp);
obs_leave_graphics();
updateSettings(settings);
}
static void xcc_cleanup(XCompcapMain_private *p);
XCompcapMain::~XCompcapMain()
{
ObsGsContextHolder obsctx;
if (p->tex) {
gs_texture_destroy(p->tex);
p->tex = 0;
}
xcc_cleanup(p);
if (p->cursor) {
xcursor_destroy(p->cursor);
p->cursor = nullptr;
}
delete p;
}
static Window getWindowFromString(std::string wstr)
{
if (wstr == "") {
return XCompcap::getTopLevelWindows().front();
}
if (wstr.substr(0, 4) == "root") {
int i = std::stoi("0" + wstr.substr(4));
return RootWindow(xdisp, i);
}
size_t firstMark = wstr.find(WIN_STRING_DIV);
if (firstMark == std::string::npos)
return (Window)std::stol(wstr);
std::string widstr = wstr.substr(0, firstMark);
Window wid = (Window)std::stol(widstr);
wstr = wstr.substr(firstMark + strlen(WIN_STRING_DIV));
size_t lastMark = wstr.rfind(WIN_STRING_DIV);
std::string wname = wstr.substr(0, lastMark);
Window matchedNameWin = wid;
for (Window cwin: XCompcap::getTopLevelWindows()) {
std::string cwinname = XCompcap::getWindowName(cwin);
if (cwin == wid && wname == cwinname)
return wid;
if (wname == cwinname)
matchedNameWin = cwin;
}
return matchedNameWin;
}
static void xcc_cleanup(XCompcapMain_private *p)
{
PLock lock(&p->lock);
XErrorLock xlock;
if (p->gltex) {
gs_texture_destroy(p->gltex);
p->gltex = 0;
}
if (p->glxpixmap) {
glXDestroyPixmap(xdisp, p->glxpixmap);
p->glxpixmap = 0;
}
if (p->pixmap) {
XFreePixmap(xdisp, p->pixmap);
p->pixmap = 0;
}
if (p->win) {
XCompositeUnredirectWindow(xdisp, p->win,
CompositeRedirectAutomatic);
XSelectInput(xdisp, p->win, 0);
p->win = 0;
}
}
void XCompcapMain::updateSettings(obs_data_t *settings)
{
PLock lock(&p->lock);
XErrorLock xlock;
ObsGsContextHolder obsctx;
blog(LOG_DEBUG, "Settings updating");
Window prevWin = p->win;
xcc_cleanup(p);
if (settings) {
const char *windowName = obs_data_get_string(settings,
"capture_window");
p->windowName = windowName;
p->win = getWindowFromString(windowName);
p->cut_top = obs_data_get_int(settings, "cut_top");
p->cut_left = obs_data_get_int(settings, "cut_left");
p->cut_right = obs_data_get_int(settings, "cut_right");
p->cut_bot = obs_data_get_int(settings, "cut_bot");
p->lockX = obs_data_get_bool(settings, "lock_x");
p->swapRedBlue = obs_data_get_bool(settings, "swap_redblue");
p->show_cursor = obs_data_get_bool(settings, "show_cursor");
p->include_border = obs_data_get_bool(settings, "include_border");
} else {
p->win = prevWin;
}
xlock.resetError();
XCompositeRedirectWindow(xdisp, p->win, CompositeRedirectAutomatic);
if (xlock.gotError()) {
blog(LOG_ERROR, "XCompositeRedirectWindow failed: %s",
xlock.getErrorText().c_str());
return;
}
XSelectInput(xdisp, p->win, StructureNotifyMask | ExposureMask);
XSync(xdisp, 0);
XWindowAttributes attr;
if (!XGetWindowAttributes(xdisp, p->win, &attr)) {
p->win = 0;
p->width = 0;
p->height = 0;
return;
}
if (p->cursor && p->show_cursor) {
Window child;
int x, y;
XTranslateCoordinates(xdisp, p->win, attr.root, 0, 0, &x, &y,
&child);
xcursor_offset(p->cursor, x, y);
}
gs_color_format cf = GS_RGBA;
p->border = attr.border_width;
if (p->include_border) {
p->width = attr.width + p->border * 2;
p->height = attr.height + p->border * 2;
} else {
p->width = attr.width;
p->height = attr.height;
}
if (p->cut_top + p->cut_bot < (int)p->height) {
p->cur_cut_top = p->cut_top;
p->cur_cut_bot = p->cut_bot;
} else {
p->cur_cut_top = 0;
p->cur_cut_bot = 0;
}
if (p->cut_left + p->cut_right < (int)p->width) {
p->cur_cut_left = p->cut_left;
p->cur_cut_right = p->cut_right;
} else {
p->cur_cut_left = 0;
p->cur_cut_right = 0;
}
if (p->tex)
gs_texture_destroy(p->tex);
uint8_t *texData = new uint8_t[width() * height() * 4];
memset(texData, 0, width() * height() * 4);
const uint8_t* texDataArr[] = { texData, 0 };
p->tex = gs_texture_create(width(), height(), cf, 1,
texDataArr, 0);
delete[] texData;
if (p->swapRedBlue) {
GLuint tex = *(GLuint*)gs_texture_get_obj(p->tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
glBindTexture(GL_TEXTURE_2D, 0);
}
const int attrs[] =
{
GLX_BIND_TO_TEXTURE_RGBA_EXT, GL_TRUE,
GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT,
GLX_DOUBLEBUFFER, GL_FALSE,
None
};
int nelem = 0;
GLXFBConfig* configs = glXChooseFBConfig(xdisp,
XCompcap::getRootWindowScreen(attr.root),
attrs, &nelem);
if (nelem <= 0) {
blog(LOG_ERROR, "no matching fb config found");
p->win = 0;
p->height = 0;
p->width = 0;
return;
}
glXGetFBConfigAttrib(xdisp, configs[0], GLX_Y_INVERTED_EXT, &nelem);
p->inverted = nelem != 0;
xlock.resetError();
p->pixmap = XCompositeNameWindowPixmap(xdisp, p->win);
if (xlock.gotError()) {
blog(LOG_ERROR, "XCompositeNameWindowPixmap failed: %s",
xlock.getErrorText().c_str());
p->pixmap = 0;
XFree(configs);
return;
}
const int attribs[] =
{
GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
None
};
p->glxpixmap = glXCreatePixmap(xdisp, configs[0], p->pixmap, attribs);
if (xlock.gotError()) {
blog(LOG_ERROR, "glXCreatePixmap failed: %s",
xlock.getErrorText().c_str());
XFreePixmap(xdisp, p->pixmap);
XFree(configs);
p->pixmap = 0;
p->glxpixmap = 0;
return;
}
XFree(configs);
p->gltex = gs_texture_create(p->width, p->height, cf, 1, 0,
GS_GL_DUMMYTEX);
GLuint gltex = *(GLuint*)gs_texture_get_obj(p->gltex);
glBindTexture(GL_TEXTURE_2D, gltex);
glXBindTexImageEXT(xdisp, p->glxpixmap, GLX_FRONT_LEFT_EXT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
void XCompcapMain::tick(float seconds)
{
UNUSED_PARAMETER(seconds);
if (!obs_source_showing(p->source))
return;
PLock lock(&p->lock, true);
if (!lock.isLocked())
return;
XCompcap::processEvents();
if (XCompcap::windowWasReconfigured(p->win))
updateSettings(0);
XErrorLock xlock;
xlock.resetError();
XWindowAttributes attr;
if (!XGetWindowAttributes(xdisp, p->win, &attr)) {
Window newWin = getWindowFromString(p->windowName);
if (XGetWindowAttributes(xdisp, newWin, &attr)) {
p->win = newWin;
updateSettings(0);
}
return;
}
if (!p->tex || !p->gltex)
return;
obs_enter_graphics();
if (p->lockX) {
XLockDisplay(xdisp);
XSync(xdisp, 0);
}
if (p->include_border) {
gs_copy_texture_region(
p->tex, 0, 0,
p->gltex,
p->cur_cut_left,
p->cur_cut_top,
width(), height());
} else {
gs_copy_texture_region(
p->tex, 0, 0,
p->gltex,
p->cur_cut_left + p->border,
p->cur_cut_top + p->border,
width(), height());
}
if (p->cursor && p->show_cursor) {
xcursor_tick(p->cursor);
p->cursor_outside =
p->cursor->x < p->cur_cut_left ||
p->cursor->y < p->cur_cut_top ||
p->cursor->x > int(p->width - p->cur_cut_right) ||
p->cursor->y > int(p->height - p->cur_cut_bot);
}
if (p->lockX)
XUnlockDisplay(xdisp);
obs_leave_graphics();
}
void XCompcapMain::render(gs_effect_t *effect)
{
PLock lock(&p->lock, true);
if (!p->win)
return;
effect = obs_get_base_effect(OBS_EFFECT_OPAQUE);
if (!lock.isLocked() || !p->tex)
return;
gs_eparam_t *image = gs_effect_get_param_by_name(effect, "image");
gs_effect_set_texture(image, p->tex);
while (gs_effect_loop(effect, "Draw")) {
gs_draw_sprite(p->tex, 0, 0, 0);
}
if (p->cursor && p->gltex && p->show_cursor && !p->cursor_outside) {
effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
while (gs_effect_loop(effect, "Draw")) {
xcursor_render(p->cursor);
}
}
}
uint32_t XCompcapMain::width()
{
return p->width - p->cur_cut_left - p->cur_cut_right;
}
uint32_t XCompcapMain::height()
{
return p->height - p->cur_cut_bot - p->cur_cut_top;
}

View file

@ -0,0 +1,27 @@
#pragma once
struct XCompcapMain_private;
class XCompcapMain
{
public:
static bool init();
static void deinit();
static obs_properties_t *properties();
static void defaults(obs_data_t *settings);
XCompcapMain(obs_data_t *settings, obs_source_t *source);
~XCompcapMain();
void updateSettings(obs_data_t *settings);
void tick(float seconds);
void render(gs_effect_t *effect);
uint32_t width();
uint32_t height();
private:
XCompcapMain_private *p;
};

View file

@ -0,0 +1,92 @@
#include <obs-module.h>
#include "xcompcap-main.hpp"
static void* xcompcap_create(obs_data_t *settings, obs_source_t *source)
{
return new XCompcapMain(settings, source);
}
static void xcompcap_destroy(void *data)
{
XCompcapMain* cc = (XCompcapMain*)data;
delete cc;
}
static void xcompcap_video_tick(void* data, float seconds)
{
XCompcapMain* cc = (XCompcapMain*)data;
cc->tick(seconds);
}
static void xcompcap_video_render(void* data, gs_effect_t *effect)
{
XCompcapMain* cc = (XCompcapMain*)data;
cc->render(effect);
}
static uint32_t xcompcap_getwidth(void* data)
{
XCompcapMain* cc = (XCompcapMain*)data;
return cc->width();
}
static uint32_t xcompcap_getheight(void* data)
{
XCompcapMain* cc = (XCompcapMain*)data;
return cc->height();
}
static obs_properties_t *xcompcap_props(void *unused)
{
UNUSED_PARAMETER(unused);
return XCompcapMain::properties();
}
void xcompcap_defaults(obs_data_t *settings)
{
XCompcapMain::defaults(settings);
}
void xcompcap_update(void *data, obs_data_t *settings)
{
XCompcapMain* cc = (XCompcapMain*)data;
cc->updateSettings(settings);
}
static const char* xcompcap_getname(void*)
{
return obs_module_text("XCCapture");
}
extern "C" void xcomposite_load(void)
{
if (!XCompcapMain::init())
return;
obs_source_info sinfo;
memset(&sinfo, 0, sizeof(obs_source_info));
sinfo.id = "xcomposite_input";
sinfo.output_flags = OBS_SOURCE_VIDEO |
OBS_SOURCE_CUSTOM_DRAW;
sinfo.get_name = xcompcap_getname;
sinfo.create = xcompcap_create;
sinfo.destroy = xcompcap_destroy;
sinfo.get_properties = xcompcap_props;
sinfo.get_defaults = xcompcap_defaults;
sinfo.update = xcompcap_update;
sinfo.video_tick = xcompcap_video_tick;
sinfo.video_render = xcompcap_video_render;
sinfo.get_width = xcompcap_getwidth;
sinfo.get_height = xcompcap_getheight;
obs_register_source(&sinfo);
}
extern "C" void xcomposite_unload(void)
{
XCompcapMain::deinit();
}

View file

@ -0,0 +1,117 @@
/*
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 <xcb/xfixes.h>
#include <util/bmem.h>
#include "xcursor-xcb.h"
/*
* 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 xcb_xcursor_create(xcb_xcursor_t *data,
xcb_xfixes_get_cursor_image_reply_t *xc)
{
uint32_t *pixels = xcb_xfixes_get_cursor_image_cursor_image(xc);
if (!pixels)
return;
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);
}
data->last_serial = xc->cursor_serial;
data->last_width = xc->width;
data->last_height = xc->height;
}
/**
* We need to check for the xfixes version in order to initialize it ?
*/
xcb_xcursor_t *xcb_xcursor_init(xcb_connection_t *xcb)
{
xcb_xcursor_t *data = bzalloc(sizeof(xcb_xcursor_t));
xcb_xfixes_query_version_cookie_t xfix_c;
xfix_c = xcb_xfixes_query_version_unchecked(xcb,
XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION);
free(xcb_xfixes_query_version_reply(xcb, xfix_c, NULL));
return data;
}
void xcb_xcursor_destroy(xcb_xcursor_t *data)
{
if (data->tex)
gs_texture_destroy(data->tex);
bfree(data);
}
void xcb_xcursor_update(xcb_xcursor_t *data,
xcb_xfixes_get_cursor_image_reply_t *xc)
{
if (!data || !xc)
return;
if (!data->tex || data->last_serial != xc->cursor_serial)
xcb_xcursor_create(data, xc);
data->x = xc->x - data->x_org;
data->y = xc->y - data->y_org;
data->x_render = data->x - xc->xhot;
data->y_render = data->y - xc->yhot;
}
void xcb_xcursor_render(xcb_xcursor_t *data)
{
if (!data->tex)
return;
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_blend_state_push();
gs_blend_function(GS_BLEND_SRCALPHA, GS_BLEND_INVSRCALPHA);
gs_enable_color(true, true, true, false);
gs_matrix_push();
gs_matrix_translate3f(data->x_render, data->y_render, 0.0f);
gs_draw_sprite(data->tex, 0, 0, 0);
gs_matrix_pop();
gs_enable_color(true, true, true, true);
gs_blend_state_pop();
}
void xcb_xcursor_offset(xcb_xcursor_t* data, const int x_org, const int y_org)
{
data->x_org = x_org;
data->y_org = y_org;
}

View file

@ -0,0 +1,79 @@
/*
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>
#include <xcb/xfixes.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
unsigned int last_serial;
unsigned int last_width;
unsigned int last_height;
gs_texture_t *tex;
int x;
int y;
int x_org;
int y_org;
float x_render;
float y_render;
} xcb_xcursor_t;
/**
* Initializes the xcursor object
*
* @return NULL on error
*/
xcb_xcursor_t *xcb_xcursor_init(xcb_connection_t *xcb);
/**
* Destroys the xcursor object
* @param data xcursor object
*/
void xcb_xcursor_destroy(xcb_xcursor_t *data);
/**
* Update the cursor data
* @param data xcursor object
* @param xc xcb cursor image reply
*
* @note This needs to be executed within a valid render context
*
*/
void xcb_xcursor_update(xcb_xcursor_t *data,
xcb_xfixes_get_cursor_image_reply_t *xc);
/**
* Draw the cursor
*
* This needs to be executed within a valid render context
*/
void xcb_xcursor_render(xcb_xcursor_t *data);
/**
* Specify offset for the cursor
*/
void xcb_xcursor_offset(xcb_xcursor_t *data, const int x_org, const int y_org);
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,127 @@
/*
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 (!pixels)
return;
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 (!xc)
return;
if (!data->tex || data->last_serial != xc->cursor_serial)
xcursor_create(data, xc);
data->x = (int_fast32_t)xc->x - (int_fast32_t)data->x_org;
data->y = (int_fast32_t)xc->y - (int_fast32_t)data->y_org;
data->render_x = xc->x - xc->xhot - data->x_org;
data->render_y = xc->y - xc->yhot - data->y_org;
XFree(xc);
}
void xcursor_render(xcursor_t *data) {
if (!data->tex)
return;
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_blend_state_push();
gs_blend_function(GS_BLEND_SRCALPHA, GS_BLEND_INVSRCALPHA);
gs_enable_color(true, true, true, false);
gs_matrix_push();
gs_matrix_translate3f(data->render_x, data->render_y, 0.0f);
gs_draw_sprite(data->tex, 0, 0, 0);
gs_matrix_pop();
gs_enable_color(true, true, true, true);
gs_blend_state_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;
}

View file

@ -0,0 +1,73 @@
/*
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 render_x;
float render_y;
unsigned long last_serial;
uint_fast32_t last_width;
uint_fast32_t last_height;
gs_texture_t *tex;
int_fast32_t x, y;
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

View file

@ -0,0 +1,174 @@
/*
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 <xcb/xcb.h>
#include <xcb/xinerama.h>
#include "xhelpers.h"
bool xinerama_is_active(xcb_connection_t *xcb)
{
if (!xcb || !xcb_get_extension_data(xcb, &xcb_xinerama_id)->present)
return false;
bool active = true;
xcb_xinerama_is_active_cookie_t xnr_c;
xcb_xinerama_is_active_reply_t *xnr_r;
xnr_c = xcb_xinerama_is_active_unchecked(xcb);
xnr_r = xcb_xinerama_is_active_reply(xcb, xnr_c, NULL);
if (!xnr_r || xnr_r->state == 0)
active = false;
free(xnr_r);
return active;
}
int xinerama_screen_count(xcb_connection_t *xcb)
{
if (!xcb)
return 0;
int screens = 0;
xcb_xinerama_query_screens_cookie_t scr_c;
xcb_xinerama_query_screens_reply_t *scr_r;
scr_c = xcb_xinerama_query_screens_unchecked(xcb);
scr_r = xcb_xinerama_query_screens_reply(xcb, scr_c, NULL);
if (scr_r)
screens = scr_r->number;
free(scr_r);
return screens;
}
int xinerama_screen_geo(xcb_connection_t *xcb, int_fast32_t screen,
int_fast32_t *x, int_fast32_t *y,
int_fast32_t *w, int_fast32_t *h)
{
if (!xcb)
goto fail;
bool success = false;
xcb_xinerama_query_screens_cookie_t scr_c;
xcb_xinerama_query_screens_reply_t *scr_r;
xcb_xinerama_screen_info_iterator_t iter;
scr_c = xcb_xinerama_query_screens_unchecked(xcb);
scr_r = xcb_xinerama_query_screens_reply(xcb, scr_c, NULL);
if (!scr_r)
goto fail;
iter = xcb_xinerama_query_screens_screen_info_iterator(scr_r);
for (; iter.rem; --screen, xcb_xinerama_screen_info_next(&iter)) {
if (!screen) {
*x = iter.data->x_org;
*y = iter.data->y_org;
*w = iter.data->width;
*h = iter.data->height;
success = true;
}
}
free(scr_r);
if (success)
return 0;
fail:
*x = *y = *w = *h = 0;
return -1;
}
int x11_screen_geo(xcb_connection_t *xcb, int_fast32_t screen,
int_fast32_t *w, int_fast32_t *h)
{
if (!xcb)
goto fail;
bool success = false;
xcb_screen_iterator_t iter;
iter = xcb_setup_roots_iterator(xcb_get_setup(xcb));
for (; iter.rem; --screen, xcb_screen_next(&iter)) {
if (!screen) {
*w = iter.data->width_in_pixels;
*h = iter.data->height_in_pixels;
success = true;
}
}
if (success)
return 0;
fail:
*w = *h = 0;
return -1;
}
xcb_shm_t* xshm_xcb_attach(xcb_connection_t *xcb, const int w, const int h)
{
if (!xcb)
return NULL;
xcb_shm_t *shm = bzalloc(sizeof(xcb_shm_t));
shm->xcb = xcb;
shm->seg = xcb_generate_id(shm->xcb);
shm->shmid = shmget(IPC_PRIVATE, w * h * 4, IPC_CREAT | 0777);
if (shm->shmid == -1)
goto fail;
xcb_shm_attach(shm->xcb, shm->seg, shm->shmid, false);
shm->data = shmat(shm->shmid, NULL, 0);
return shm;
fail:
xshm_xcb_detach(shm);
return NULL;
}
void xshm_xcb_detach(xcb_shm_t *shm)
{
if (!shm)
return;
xcb_shm_detach(shm->xcb, shm->seg);
if ((char *) shm->data != (char *) -1)
shmdt(shm->data);
if (shm->shmid != -1)
shmctl(shm->shmid, IPC_RMID, NULL);
bfree(shm);
}
xcb_screen_t *xcb_get_screen(xcb_connection_t *xcb, int screen)
{
xcb_screen_iterator_t iter;
iter = xcb_setup_roots_iterator(xcb_get_setup(xcb));
for (; iter.rem; --screen, xcb_screen_next(&iter)) {
if (screen == 0)
return iter.data;
}
return NULL;
}

View file

@ -0,0 +1,109 @@
/*
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 <xcb/shm.h>
#include <xcb/xproto.h>
#include <obs.h>
typedef struct {
xcb_connection_t *xcb;
xcb_shm_seg_t seg;
int shmid;
uint8_t *data;
} xcb_shm_t;
/**
* Check for Xinerama extension
*
* @return true if xinerama is available and active
*/
bool xinerama_is_active(xcb_connection_t *xcb);
/**
* Get the number of Xinerama screens
*
* @return number of screens
*/
int xinerama_screen_count(xcb_connection_t *xcb);
/**
* Get screen geometry for a Xinerama screen
*
* @note On error the passed coordinates/sizes will be set to 0.
*
* @param xcb xcb connection
* @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 xinerama_screen_geo(xcb_connection_t *xcb, 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 xcb xcb connection
* @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 x11_screen_geo(xcb_connection_t *xcb, int_fast32_t screen,
int_fast32_t *w, int_fast32_t *h);
/**
* Attach a shared memory segment to the X-Server
*
* @param xcb xcb connection
* @param w width of the captured screen
* @param h height of the captured screen
*
* @return NULL on error
*/
xcb_shm_t *xshm_xcb_attach(xcb_connection_t *xcb, const int w, const int h);
/**
* Detach a shared memory segment
*/
void xshm_xcb_detach(xcb_shm_t *shm);
/**
* Get screen by id for a xcb connection
*
* @param xcb xcb connection
* @param screen id of the screen
* @return screen info structure
*/
xcb_screen_t *xcb_get_screen(xcb_connection_t *xcb, int screen);
#ifdef __cplusplus
}
#endif

View file

@ -0,0 +1,490 @@
/*
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 <xcb/shm.h>
#include <xcb/xfixes.h>
#include <xcb/xinerama.h>
#include <obs-module.h>
#include <util/dstr.h>
#include "xcursor-xcb.h"
#include "xhelpers.h"
#define XSHM_DATA(voidptr) struct xshm_data *data = voidptr;
#define blog(level, msg, ...) blog(level, "xshm-input: " msg, ##__VA_ARGS__)
struct xshm_data {
obs_source_t *source;
xcb_connection_t *xcb;
xcb_screen_t *xcb_screen;
xcb_shm_t *xshm;
xcb_xcursor_t *cursor;
char *server;
uint_fast32_t screen_id;
int_fast32_t x_org;
int_fast32_t y_org;
int_fast32_t width;
int_fast32_t height;
gs_texture_t *texture;
bool show_cursor;
bool use_xinerama;
bool advanced;
};
/**
* Resize the texture
*
* This will automatically create the texture if it does not exist
*
* @note requires to be called within the obs graphics context
*/
static inline void xshm_resize_texture(struct xshm_data *data)
{
if (data->texture)
gs_texture_destroy(data->texture);
data->texture = gs_texture_create(data->width, data->height,
GS_BGRA, 1, NULL, GS_DYNAMIC);
}
/**
* Check if the xserver supports all the extensions we need
*/
static bool xshm_check_extensions(xcb_connection_t *xcb)
{
bool ok = true;
if (!xcb_get_extension_data(xcb, &xcb_shm_id)->present) {
blog(LOG_ERROR, "Missing SHM extension !");
ok = false;
}
if (!xcb_get_extension_data(xcb, &xcb_xinerama_id)->present)
blog(LOG_INFO, "Missing Xinerama extension !");
return ok;
}
/**
* 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)
{
int_fast32_t old_width = data->width;
int_fast32_t old_height = data->height;
if (data->use_xinerama) {
if (xinerama_screen_geo(data->xcb, data->screen_id,
&data->x_org, &data->y_org,
&data->width, &data->height) < 0) {
return -1;
}
data->xcb_screen = xcb_get_screen(data->xcb, 0);
}
else {
data->x_org = 0;
data->y_org = 0;
if (x11_screen_geo(data->xcb, data->screen_id,
&data->width, &data->height) < 0) {
return -1;
}
data->xcb_screen = xcb_get_screen(data->xcb, data->screen_id);
}
if (!data->width || !data->height) {
blog(LOG_ERROR, "Failed to get geometry");
return -1;
}
blog(LOG_INFO, "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 *unused)
{
UNUSED_PARAMETER(unused);
return obs_module_text("X11SharedMemoryScreenInput");
}
/**
* Stop the capture
*/
static void xshm_capture_stop(struct xshm_data *data)
{
obs_enter_graphics();
if (data->texture) {
gs_texture_destroy(data->texture);
data->texture = NULL;
}
if (data->cursor) {
xcb_xcursor_destroy(data->cursor);
data->cursor = NULL;
}
obs_leave_graphics();
if (data->xshm) {
xshm_xcb_detach(data->xshm);
data->xshm = NULL;
}
if (data->xcb) {
xcb_disconnect(data->xcb);
data->xcb = NULL;
}
if (data->server) {
bfree(data->server);
data->server = NULL;
}
}
/**
* Start the capture
*/
static void xshm_capture_start(struct xshm_data *data)
{
const char *server = (data->advanced && *data->server)
? data->server : NULL;
data->xcb = xcb_connect(server, NULL);
if (!data->xcb || xcb_connection_has_error(data->xcb)) {
blog(LOG_ERROR, "Unable to open X display !");
goto fail;
}
if (!xshm_check_extensions(data->xcb))
goto fail;
data->use_xinerama = xinerama_is_active(data->xcb) ? true : false;
if (xshm_update_geometry(data) < 0) {
blog(LOG_ERROR, "failed to update geometry !");
goto fail;
}
data->xshm = xshm_xcb_attach(data->xcb, data->width, data->height);
if (!data->xshm) {
blog(LOG_ERROR, "failed to attach shm !");
goto fail;
}
data->cursor = xcb_xcursor_init(data->xcb);
xcb_xcursor_offset(data->cursor, data->x_org, data->y_org);
obs_enter_graphics();
xshm_resize_texture(data);
obs_leave_graphics();
return;
fail:
xshm_capture_stop(data);
}
/**
* Update the capture with changed settings
*/
static void xshm_update(void *vptr, obs_data_t *settings)
{
XSHM_DATA(vptr);
xshm_capture_stop(data);
data->screen_id = obs_data_get_int(settings, "screen");
data->show_cursor = obs_data_get_bool(settings, "show_cursor");
data->advanced = obs_data_get_bool(settings, "advanced");
data->server = bstrdup(obs_data_get_string(settings, "server"));
xshm_capture_start(data);
}
/**
* 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);
obs_data_set_default_bool(defaults, "advanced", false);
}
/**
* Toggle visibility of advanced settings
*/
static bool xshm_toggle_advanced(obs_properties_t *props,
obs_property_t *p, obs_data_t *settings)
{
UNUSED_PARAMETER(p);
const bool visible = obs_data_get_bool(settings, "advanced");
obs_property_t *server = obs_properties_get(props, "server");
obs_property_set_visible(server, visible);
/* trigger server changed callback so the screen list is refreshed */
obs_property_modified(server, settings);
return true;
}
/**
* The x server was changed
*/
static bool xshm_server_changed(obs_properties_t *props,
obs_property_t *p, obs_data_t *settings)
{
UNUSED_PARAMETER(p);
bool advanced = obs_data_get_bool(settings, "advanced");
int_fast32_t old_screen = obs_data_get_int(settings, "screen");
const char *server = obs_data_get_string(settings, "server");
obs_property_t *screens = obs_properties_get(props, "screen");
/* we want a real NULL here in case there is no string here */
server = (advanced && *server) ? server : NULL;
obs_property_list_clear(screens);
xcb_connection_t *xcb = xcb_connect(server, NULL);
if (!xcb || xcb_connection_has_error(xcb)) {
obs_property_set_enabled(screens, false);
return true;
}
struct dstr screen_info;
dstr_init(&screen_info);
bool xinerama = xinerama_is_active(xcb);
int_fast32_t count = (xinerama) ?
xinerama_screen_count(xcb) :
xcb_setup_roots_length(xcb_get_setup(xcb));
for (int_fast32_t i = 0; i < count; ++i) {
int_fast32_t x, y, w, h;
x = y = w = h = 0;
if (xinerama)
xinerama_screen_geo(xcb, i, &x, &y, &w, &h);
else
x11_screen_geo(xcb, i, &w, &h);
dstr_printf(&screen_info, "Screen %"PRIuFAST32" (%"PRIuFAST32
"x%"PRIuFAST32" @ %"PRIuFAST32
",%"PRIuFAST32")", i, w, h, x, y);
obs_property_list_add_int(screens, screen_info.array, i);
}
/* handle missing screen */
if (old_screen + 1 > count) {
dstr_printf(&screen_info, "Screen %"PRIuFAST32" (not found)",
old_screen);
size_t index = obs_property_list_add_int(screens,
screen_info.array, old_screen);
obs_property_list_item_disable(screens, index, true);
}
dstr_free(&screen_info);
xcb_disconnect(xcb);
obs_property_set_enabled(screens, true);
return true;
}
/**
* Get the properties for the capture
*/
static obs_properties_t *xshm_properties(void *vptr)
{
XSHM_DATA(vptr);
obs_properties_t *props = obs_properties_create();
obs_properties_add_list(props, "screen", obs_module_text("Screen"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
obs_properties_add_bool(props, "show_cursor",
obs_module_text("CaptureCursor"));
obs_property_t *advanced = obs_properties_add_bool(props, "advanced",
obs_module_text("AdvancedSettings"));
obs_property_t *server = obs_properties_add_text(props, "server",
obs_module_text("XServer"), OBS_TEXT_DEFAULT);
obs_property_set_modified_callback(advanced, xshm_toggle_advanced);
obs_property_set_modified_callback(server, xshm_server_changed);
/* trigger server callback to get screen count ... */
obs_data_t *settings = obs_source_get_settings(data->source);
obs_property_modified(server, settings);
obs_data_release(settings);
return props;
}
/**
* Destroy the capture
*/
static void xshm_destroy(void *vptr)
{
XSHM_DATA(vptr);
if (!data)
return;
xshm_capture_stop(data);
bfree(data);
}
/**
* Create the capture
*/
static void *xshm_create(obs_data_t *settings, obs_source_t *source)
{
struct xshm_data *data = bzalloc(sizeof(struct xshm_data));
data->source = source;
xshm_update(data, settings);
return data;
}
/**
* Prepare the capture data
*/
static void xshm_video_tick(void *vptr, float seconds)
{
UNUSED_PARAMETER(seconds);
XSHM_DATA(vptr);
if (!data->texture)
return;
if (!obs_source_showing(data->source))
return;
xcb_shm_get_image_cookie_t img_c;
xcb_shm_get_image_reply_t *img_r;
xcb_xfixes_get_cursor_image_cookie_t cur_c;
xcb_xfixes_get_cursor_image_reply_t *cur_r;
img_c = xcb_shm_get_image_unchecked(data->xcb, data->xcb_screen->root,
data->x_org, data->y_org, data->width, data->height,
~0, XCB_IMAGE_FORMAT_Z_PIXMAP, data->xshm->seg, 0);
cur_c = xcb_xfixes_get_cursor_image_unchecked(data->xcb);
img_r = xcb_shm_get_image_reply(data->xcb, img_c, NULL);
cur_r = xcb_xfixes_get_cursor_image_reply(data->xcb, cur_c, NULL);
if (!img_r)
goto exit;
obs_enter_graphics();
gs_texture_set_image(data->texture, (void *) data->xshm->data,
data->width * 4, false);
xcb_xcursor_update(data->cursor, cur_r);
obs_leave_graphics();
exit:
free(img_r);
free(cur_r);
}
/**
* Render the capture data
*/
static void xshm_video_render(void *vptr, gs_effect_t *effect)
{
XSHM_DATA(vptr);
effect = obs_get_base_effect(OBS_EFFECT_OPAQUE);
if (!data->texture)
return;
gs_eparam_t *image = gs_effect_get_param_by_name(effect, "image");
gs_effect_set_texture(image, data->texture);
while (gs_effect_loop(effect, "Draw")) {
gs_draw_sprite(data->texture, 0, 0, 0);
}
if (data->show_cursor) {
effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
while (gs_effect_loop(effect, "Draw")) {
xcb_xcursor_render(data->cursor);
}
}
}
/**
* 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 |
OBS_SOURCE_CUSTOM_DRAW |
OBS_SOURCE_DO_NOT_DUPLICATE,
.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
};