pipewire.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  1. /* pipewire.c
  2. *
  3. * Copyright 2020 Georges Basile Stavracas Neto <[email protected]>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * SPDX-License-Identifier: GPL-2.0-or-later
  19. */
  20. #include "pipewire.h"
  21. #include "portal.h"
  22. #include <util/dstr.h>
  23. #include <gio/gio.h>
  24. #include <gio/gunixfdlist.h>
  25. #include <fcntl.h>
  26. #include <glad/glad.h>
  27. #include <linux/dma-buf.h>
  28. #include <libdrm/drm_fourcc.h>
  29. #include <spa/param/video/format-utils.h>
  30. #include <spa/debug/format.h>
  31. #include <spa/debug/types.h>
  32. #include <spa/param/video/type-info.h>
  33. #define REQUEST_PATH "/org/freedesktop/portal/desktop/request/%s/obs%u"
  34. #define SESSION_PATH "/org/freedesktop/portal/desktop/session/%s/obs%u"
  35. #define CURSOR_META_SIZE(width, height) \
  36. (sizeof(struct spa_meta_cursor) + sizeof(struct spa_meta_bitmap) + \
  37. width * height * 4)
  38. #define fourcc_code(a, b, c, d) \
  39. ((__u32)(a) | ((__u32)(b) << 8) | ((__u32)(c) << 16) | \
  40. ((__u32)(d) << 24))
  41. #define DRM_FORMAT_XRGB8888 \
  42. fourcc_code('X', 'R', '2', \
  43. '4') /* [31:0] x:R:G:B 8:8:8:8 little endian */
  44. #define DRM_FORMAT_XBGR8888 \
  45. fourcc_code('X', 'B', '2', \
  46. '4') /* [31:0] x:B:G:R 8:8:8:8 little endian */
  47. #define DRM_FORMAT_ARGB8888 \
  48. fourcc_code('A', 'R', '2', \
  49. '4') /* [31:0] A:R:G:B 8:8:8:8 little endian */
  50. #define DRM_FORMAT_ABGR8888 \
  51. fourcc_code('A', 'B', '2', \
  52. '4') /* [31:0] A:B:G:R 8:8:8:8 little endian */
  53. struct _obs_pipewire_data {
  54. GCancellable *cancellable;
  55. char *sender_name;
  56. char *session_handle;
  57. uint32_t pipewire_node;
  58. int pipewire_fd;
  59. uint32_t available_cursor_modes;
  60. obs_source_t *source;
  61. obs_data_t *settings;
  62. gs_texture_t *texture;
  63. struct pw_thread_loop *thread_loop;
  64. struct pw_context *context;
  65. struct pw_core *core;
  66. struct spa_hook core_listener;
  67. struct pw_stream *stream;
  68. struct spa_hook stream_listener;
  69. struct spa_video_info format;
  70. struct {
  71. bool valid;
  72. int x, y;
  73. uint32_t width, height;
  74. } crop;
  75. struct {
  76. bool visible;
  77. bool valid;
  78. int x, y;
  79. int hotspot_x, hotspot_y;
  80. int width, height;
  81. gs_texture_t *texture;
  82. } cursor;
  83. enum obs_pw_capture_type capture_type;
  84. struct obs_video_info video_info;
  85. bool negotiated;
  86. };
  87. struct dbus_call_data {
  88. obs_pipewire_data *obs_pw;
  89. char *request_path;
  90. guint signal_id;
  91. gulong cancelled_id;
  92. };
  93. /* auxiliary methods */
  94. static const char *capture_type_to_string(enum obs_pw_capture_type capture_type)
  95. {
  96. switch (capture_type) {
  97. case DESKTOP_CAPTURE:
  98. return "desktop";
  99. case WINDOW_CAPTURE:
  100. return "window";
  101. }
  102. return "unknown";
  103. }
  104. static void new_request_path(obs_pipewire_data *data, char **out_path,
  105. char **out_token)
  106. {
  107. static uint32_t request_token_count = 0;
  108. request_token_count++;
  109. if (out_token) {
  110. struct dstr str;
  111. dstr_init(&str);
  112. dstr_printf(&str, "obs%u", request_token_count);
  113. *out_token = str.array;
  114. }
  115. if (out_path) {
  116. struct dstr str;
  117. dstr_init(&str);
  118. dstr_printf(&str, REQUEST_PATH, data->sender_name,
  119. request_token_count);
  120. *out_path = str.array;
  121. }
  122. }
  123. static void new_session_path(obs_pipewire_data *data, char **out_path,
  124. char **out_token)
  125. {
  126. static uint32_t session_token_count = 0;
  127. session_token_count++;
  128. if (out_token) {
  129. struct dstr str;
  130. dstr_init(&str);
  131. dstr_printf(&str, "obs%u", session_token_count);
  132. *out_token = str.array;
  133. }
  134. if (out_path) {
  135. struct dstr str;
  136. dstr_init(&str);
  137. dstr_printf(&str, SESSION_PATH, data->sender_name,
  138. session_token_count);
  139. *out_path = str.array;
  140. }
  141. }
  142. static void on_cancelled_cb(GCancellable *cancellable, void *data)
  143. {
  144. UNUSED_PARAMETER(cancellable);
  145. struct dbus_call_data *call = data;
  146. blog(LOG_INFO, "[pipewire] screencast session cancelled");
  147. g_dbus_connection_call(
  148. portal_get_dbus_connection(), "org.freedesktop.portal.Desktop",
  149. call->request_path, "org.freedesktop.portal.Request", "Close",
  150. NULL, NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
  151. }
  152. static struct dbus_call_data *subscribe_to_signal(obs_pipewire_data *obs_pw,
  153. const char *path,
  154. GDBusSignalCallback callback)
  155. {
  156. struct dbus_call_data *call;
  157. call = bzalloc(sizeof(struct dbus_call_data));
  158. call->obs_pw = obs_pw;
  159. call->request_path = bstrdup(path);
  160. call->cancelled_id = g_signal_connect(obs_pw->cancellable, "cancelled",
  161. G_CALLBACK(on_cancelled_cb),
  162. call);
  163. call->signal_id = g_dbus_connection_signal_subscribe(
  164. portal_get_dbus_connection(), "org.freedesktop.portal.Desktop",
  165. "org.freedesktop.portal.Request", "Response",
  166. call->request_path, NULL, G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,
  167. callback, call, NULL);
  168. return call;
  169. }
  170. static void dbus_call_data_free(struct dbus_call_data *call)
  171. {
  172. if (!call)
  173. return;
  174. if (call->signal_id)
  175. g_dbus_connection_signal_unsubscribe(
  176. portal_get_dbus_connection(), call->signal_id);
  177. if (call->cancelled_id > 0)
  178. g_signal_handler_disconnect(call->obs_pw->cancellable,
  179. call->cancelled_id);
  180. g_clear_pointer(&call->request_path, bfree);
  181. bfree(call);
  182. }
  183. static void teardown_pipewire(obs_pipewire_data *obs_pw)
  184. {
  185. if (obs_pw->thread_loop) {
  186. pw_thread_loop_wait(obs_pw->thread_loop);
  187. pw_thread_loop_stop(obs_pw->thread_loop);
  188. }
  189. if (obs_pw->stream)
  190. pw_stream_disconnect(obs_pw->stream);
  191. g_clear_pointer(&obs_pw->stream, pw_stream_destroy);
  192. g_clear_pointer(&obs_pw->context, pw_context_destroy);
  193. g_clear_pointer(&obs_pw->thread_loop, pw_thread_loop_destroy);
  194. if (obs_pw->pipewire_fd > 0) {
  195. close(obs_pw->pipewire_fd);
  196. obs_pw->pipewire_fd = 0;
  197. }
  198. obs_pw->negotiated = false;
  199. }
  200. static void destroy_session(obs_pipewire_data *obs_pw)
  201. {
  202. if (obs_pw->session_handle) {
  203. g_dbus_connection_call(portal_get_dbus_connection(),
  204. "org.freedesktop.portal.Desktop",
  205. obs_pw->session_handle,
  206. "org.freedesktop.portal.Session",
  207. "Close", NULL, NULL,
  208. G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL,
  209. NULL);
  210. g_clear_pointer(&obs_pw->session_handle, g_free);
  211. }
  212. g_clear_pointer(&obs_pw->sender_name, bfree);
  213. g_clear_pointer(&obs_pw->cursor.texture, gs_texture_destroy);
  214. g_clear_pointer(&obs_pw->texture, gs_texture_destroy);
  215. g_cancellable_cancel(obs_pw->cancellable);
  216. g_clear_object(&obs_pw->cancellable);
  217. }
  218. static inline bool has_effective_crop(obs_pipewire_data *obs_pw)
  219. {
  220. return obs_pw->crop.valid &&
  221. (obs_pw->crop.x != 0 || obs_pw->crop.y != 0 ||
  222. obs_pw->crop.width < obs_pw->format.info.raw.size.width ||
  223. obs_pw->crop.height < obs_pw->format.info.raw.size.height);
  224. }
  225. static bool spa_pixel_format_to_drm_format(uint32_t spa_format,
  226. uint32_t *out_format)
  227. {
  228. switch (spa_format) {
  229. case SPA_VIDEO_FORMAT_RGBA:
  230. *out_format = DRM_FORMAT_ABGR8888;
  231. break;
  232. case SPA_VIDEO_FORMAT_RGBx:
  233. *out_format = DRM_FORMAT_XBGR8888;
  234. break;
  235. case SPA_VIDEO_FORMAT_BGRA:
  236. *out_format = DRM_FORMAT_ARGB8888;
  237. break;
  238. case SPA_VIDEO_FORMAT_BGRx:
  239. *out_format = DRM_FORMAT_XRGB8888;
  240. break;
  241. default:
  242. return false;
  243. }
  244. return true;
  245. }
  246. static bool spa_pixel_format_to_obs_format(uint32_t spa_format,
  247. enum gs_color_format *out_format,
  248. bool *swap_red_blue)
  249. {
  250. switch (spa_format) {
  251. case SPA_VIDEO_FORMAT_RGBA:
  252. *out_format = GS_RGBA;
  253. *swap_red_blue = false;
  254. break;
  255. case SPA_VIDEO_FORMAT_RGBx:
  256. *out_format = GS_BGRX;
  257. *swap_red_blue = true;
  258. break;
  259. case SPA_VIDEO_FORMAT_BGRA:
  260. *out_format = GS_BGRA;
  261. *swap_red_blue = false;
  262. break;
  263. case SPA_VIDEO_FORMAT_BGRx:
  264. *out_format = GS_BGRX;
  265. *swap_red_blue = false;
  266. break;
  267. default:
  268. return false;
  269. }
  270. return true;
  271. }
  272. static void swap_texture_red_blue(gs_texture_t *texture)
  273. {
  274. GLuint gl_texure = *(GLuint *)gs_texture_get_obj(texture);
  275. glBindTexture(GL_TEXTURE_2D, gl_texure);
  276. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
  277. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
  278. glBindTexture(GL_TEXTURE_2D, 0);
  279. }
  280. /* ------------------------------------------------- */
  281. static void on_process_cb(void *user_data)
  282. {
  283. obs_pipewire_data *obs_pw = user_data;
  284. struct spa_meta_cursor *cursor;
  285. uint32_t drm_format;
  286. struct spa_meta_region *region;
  287. struct spa_buffer *buffer;
  288. struct pw_buffer *b;
  289. bool swap_red_blue = false;
  290. bool has_buffer;
  291. /* Find the most recent buffer */
  292. b = NULL;
  293. while (true) {
  294. struct pw_buffer *aux =
  295. pw_stream_dequeue_buffer(obs_pw->stream);
  296. if (!aux)
  297. break;
  298. if (b)
  299. pw_stream_queue_buffer(obs_pw->stream, b);
  300. b = aux;
  301. }
  302. if (!b) {
  303. blog(LOG_DEBUG, "[pipewire] Out of buffers!");
  304. return;
  305. }
  306. buffer = b->buffer;
  307. has_buffer = buffer->datas[0].chunk->size != 0;
  308. obs_enter_graphics();
  309. if (!has_buffer)
  310. goto read_metadata;
  311. if (buffer->datas[0].type == SPA_DATA_DmaBuf) {
  312. uint32_t planes = buffer->n_datas;
  313. uint32_t offsets[planes];
  314. uint32_t strides[planes];
  315. uint64_t modifiers[planes];
  316. int fds[planes];
  317. bool modifierless; // DMA-BUF without explicit modifier
  318. blog(LOG_DEBUG,
  319. "[pipewire] DMA-BUF info: fd:%ld, stride:%d, offset:%u, size:%dx%d",
  320. buffer->datas[0].fd, buffer->datas[0].chunk->stride,
  321. buffer->datas[0].chunk->offset,
  322. obs_pw->format.info.raw.size.width,
  323. obs_pw->format.info.raw.size.height);
  324. if (!spa_pixel_format_to_drm_format(
  325. obs_pw->format.info.raw.format, &drm_format)) {
  326. blog(LOG_ERROR,
  327. "[pipewire] unsupported DMA buffer format: %d",
  328. obs_pw->format.info.raw.format);
  329. goto read_metadata;
  330. }
  331. for (uint32_t plane = 0; plane < planes; plane++) {
  332. fds[plane] = buffer->datas[plane].fd;
  333. offsets[plane] = buffer->datas[plane].chunk->offset;
  334. strides[plane] = buffer->datas[plane].chunk->stride;
  335. modifiers[plane] = obs_pw->format.info.raw.modifier;
  336. }
  337. g_clear_pointer(&obs_pw->texture, gs_texture_destroy);
  338. modifierless = obs_pw->format.info.raw.modifier ==
  339. DRM_FORMAT_MOD_INVALID;
  340. obs_pw->texture = gs_texture_create_from_dmabuf(
  341. obs_pw->format.info.raw.size.width,
  342. obs_pw->format.info.raw.size.height, drm_format,
  343. GS_BGRX, planes, fds, strides, offsets,
  344. modifierless ? NULL : modifiers);
  345. } else {
  346. blog(LOG_DEBUG, "[pipewire] Buffer has memory texture");
  347. enum gs_color_format obs_format;
  348. if (!spa_pixel_format_to_obs_format(
  349. obs_pw->format.info.raw.format, &obs_format,
  350. &swap_red_blue)) {
  351. blog(LOG_ERROR,
  352. "[pipewire] unsupported DMA buffer format: %d",
  353. obs_pw->format.info.raw.format);
  354. goto read_metadata;
  355. }
  356. g_clear_pointer(&obs_pw->texture, gs_texture_destroy);
  357. obs_pw->texture = gs_texture_create(
  358. obs_pw->format.info.raw.size.width,
  359. obs_pw->format.info.raw.size.height, obs_format, 1,
  360. (const uint8_t **)&buffer->datas[0].data, GS_DYNAMIC);
  361. }
  362. if (swap_red_blue)
  363. swap_texture_red_blue(obs_pw->texture);
  364. /* Video Crop */
  365. region = spa_buffer_find_meta_data(buffer, SPA_META_VideoCrop,
  366. sizeof(*region));
  367. if (region && spa_meta_region_is_valid(region)) {
  368. blog(LOG_DEBUG,
  369. "[pipewire] Crop Region available (%dx%d+%d+%d)",
  370. region->region.position.x, region->region.position.y,
  371. region->region.size.width, region->region.size.height);
  372. obs_pw->crop.x = region->region.position.x;
  373. obs_pw->crop.y = region->region.position.y;
  374. obs_pw->crop.width = region->region.size.width;
  375. obs_pw->crop.height = region->region.size.height;
  376. obs_pw->crop.valid = true;
  377. } else {
  378. obs_pw->crop.valid = false;
  379. }
  380. read_metadata:
  381. /* Cursor */
  382. cursor = spa_buffer_find_meta_data(buffer, SPA_META_Cursor,
  383. sizeof(*cursor));
  384. obs_pw->cursor.valid = cursor && spa_meta_cursor_is_valid(cursor);
  385. if (obs_pw->cursor.visible && obs_pw->cursor.valid) {
  386. struct spa_meta_bitmap *bitmap = NULL;
  387. enum gs_color_format format;
  388. if (cursor->bitmap_offset)
  389. bitmap = SPA_MEMBER(cursor, cursor->bitmap_offset,
  390. struct spa_meta_bitmap);
  391. if (bitmap && bitmap->size.width > 0 &&
  392. bitmap->size.height > 0 &&
  393. spa_pixel_format_to_obs_format(bitmap->format, &format,
  394. &swap_red_blue)) {
  395. const uint8_t *bitmap_data;
  396. bitmap_data =
  397. SPA_MEMBER(bitmap, bitmap->offset, uint8_t);
  398. obs_pw->cursor.hotspot_x = cursor->hotspot.x;
  399. obs_pw->cursor.hotspot_y = cursor->hotspot.y;
  400. obs_pw->cursor.width = bitmap->size.width;
  401. obs_pw->cursor.height = bitmap->size.height;
  402. g_clear_pointer(&obs_pw->cursor.texture,
  403. gs_texture_destroy);
  404. obs_pw->cursor.texture = gs_texture_create(
  405. obs_pw->cursor.width, obs_pw->cursor.height,
  406. format, 1, &bitmap_data, GS_DYNAMIC);
  407. if (swap_red_blue)
  408. swap_texture_red_blue(obs_pw->cursor.texture);
  409. }
  410. obs_pw->cursor.x = cursor->position.x;
  411. obs_pw->cursor.y = cursor->position.y;
  412. }
  413. pw_stream_queue_buffer(obs_pw->stream, b);
  414. obs_leave_graphics();
  415. }
  416. static void on_param_changed_cb(void *user_data, uint32_t id,
  417. const struct spa_pod *param)
  418. {
  419. obs_pipewire_data *obs_pw = user_data;
  420. struct spa_pod_builder pod_builder;
  421. const struct spa_pod *params[3];
  422. uint8_t params_buffer[1024];
  423. int result;
  424. if (!param || id != SPA_PARAM_Format)
  425. return;
  426. result = spa_format_parse(param, &obs_pw->format.media_type,
  427. &obs_pw->format.media_subtype);
  428. if (result < 0)
  429. return;
  430. if (obs_pw->format.media_type != SPA_MEDIA_TYPE_video ||
  431. obs_pw->format.media_subtype != SPA_MEDIA_SUBTYPE_raw)
  432. return;
  433. spa_format_video_raw_parse(param, &obs_pw->format.info.raw);
  434. blog(LOG_DEBUG, "[pipewire] Negotiated format:");
  435. blog(LOG_DEBUG, "[pipewire] Format: %d (%s)",
  436. obs_pw->format.info.raw.format,
  437. spa_debug_type_find_name(spa_type_video_format,
  438. obs_pw->format.info.raw.format));
  439. blog(LOG_DEBUG, "[pipewire] Size: %dx%d",
  440. obs_pw->format.info.raw.size.width,
  441. obs_pw->format.info.raw.size.height);
  442. blog(LOG_DEBUG, "[pipewire] Framerate: %d/%d",
  443. obs_pw->format.info.raw.framerate.num,
  444. obs_pw->format.info.raw.framerate.denom);
  445. /* Video crop */
  446. pod_builder =
  447. SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer));
  448. params[0] = spa_pod_builder_add_object(
  449. &pod_builder, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
  450. SPA_PARAM_META_type, SPA_POD_Id(SPA_META_VideoCrop),
  451. SPA_PARAM_META_size,
  452. SPA_POD_Int(sizeof(struct spa_meta_region)));
  453. /* Cursor */
  454. params[1] = spa_pod_builder_add_object(
  455. &pod_builder, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
  456. SPA_PARAM_META_type, SPA_POD_Id(SPA_META_Cursor),
  457. SPA_PARAM_META_size,
  458. SPA_POD_CHOICE_RANGE_Int(CURSOR_META_SIZE(64, 64),
  459. CURSOR_META_SIZE(1, 1),
  460. CURSOR_META_SIZE(1024, 1024)));
  461. /* Buffer options */
  462. params[2] = spa_pod_builder_add_object(
  463. &pod_builder, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
  464. SPA_PARAM_BUFFERS_dataType,
  465. SPA_POD_Int((1 << SPA_DATA_MemPtr) | (1 << SPA_DATA_DmaBuf)));
  466. pw_stream_update_params(obs_pw->stream, params, 3);
  467. obs_pw->negotiated = true;
  468. }
  469. static void on_state_changed_cb(void *user_data, enum pw_stream_state old,
  470. enum pw_stream_state state, const char *error)
  471. {
  472. UNUSED_PARAMETER(old);
  473. UNUSED_PARAMETER(error);
  474. obs_pipewire_data *obs_pw = user_data;
  475. blog(LOG_DEBUG, "[pipewire] stream %p state: \"%s\" (error: %s)",
  476. obs_pw->stream, pw_stream_state_as_string(state),
  477. error ? error : "none");
  478. }
  479. static const struct pw_stream_events stream_events = {
  480. PW_VERSION_STREAM_EVENTS,
  481. .state_changed = on_state_changed_cb,
  482. .param_changed = on_param_changed_cb,
  483. .process = on_process_cb,
  484. };
  485. static void on_core_error_cb(void *user_data, uint32_t id, int seq, int res,
  486. const char *message)
  487. {
  488. UNUSED_PARAMETER(seq);
  489. obs_pipewire_data *obs_pw = user_data;
  490. blog(LOG_ERROR, "[pipewire] Error id:%u seq:%d res:%d (%s): %s", id,
  491. seq, res, g_strerror(res), message);
  492. pw_thread_loop_signal(obs_pw->thread_loop, FALSE);
  493. }
  494. static void on_core_done_cb(void *user_data, uint32_t id, int seq)
  495. {
  496. UNUSED_PARAMETER(seq);
  497. obs_pipewire_data *obs_pw = user_data;
  498. if (id == PW_ID_CORE)
  499. pw_thread_loop_signal(obs_pw->thread_loop, FALSE);
  500. }
  501. static const struct pw_core_events core_events = {
  502. PW_VERSION_CORE_EVENTS,
  503. .done = on_core_done_cb,
  504. .error = on_core_error_cb,
  505. };
  506. static void play_pipewire_stream(obs_pipewire_data *obs_pw)
  507. {
  508. struct spa_pod_builder pod_builder;
  509. const struct spa_pod *params[1];
  510. uint8_t params_buffer[1024];
  511. struct obs_video_info ovi;
  512. obs_pw->thread_loop = pw_thread_loop_new("PipeWire thread loop", NULL);
  513. obs_pw->context = pw_context_new(
  514. pw_thread_loop_get_loop(obs_pw->thread_loop), NULL, 0);
  515. if (pw_thread_loop_start(obs_pw->thread_loop) < 0) {
  516. blog(LOG_WARNING, "Error starting threaded mainloop");
  517. return;
  518. }
  519. pw_thread_loop_lock(obs_pw->thread_loop);
  520. /* Core */
  521. obs_pw->core = pw_context_connect_fd(
  522. obs_pw->context, fcntl(obs_pw->pipewire_fd, F_DUPFD_CLOEXEC, 5),
  523. NULL, 0);
  524. if (!obs_pw->core) {
  525. blog(LOG_WARNING, "Error creating PipeWire core: %m");
  526. pw_thread_loop_unlock(obs_pw->thread_loop);
  527. return;
  528. }
  529. pw_core_add_listener(obs_pw->core, &obs_pw->core_listener, &core_events,
  530. obs_pw);
  531. /* Stream */
  532. obs_pw->stream = pw_stream_new(
  533. obs_pw->core, "OBS Studio",
  534. pw_properties_new(PW_KEY_MEDIA_TYPE, "Video",
  535. PW_KEY_MEDIA_CATEGORY, "Capture",
  536. PW_KEY_MEDIA_ROLE, "Screen", NULL));
  537. pw_stream_add_listener(obs_pw->stream, &obs_pw->stream_listener,
  538. &stream_events, obs_pw);
  539. blog(LOG_INFO, "[pipewire] created stream %p", obs_pw->stream);
  540. /* Stream parameters */
  541. pod_builder =
  542. SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer));
  543. obs_get_video_info(&ovi);
  544. params[0] = spa_pod_builder_add_object(
  545. &pod_builder, SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
  546. SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
  547. SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
  548. SPA_FORMAT_VIDEO_format,
  549. SPA_POD_CHOICE_ENUM_Id(
  550. 4, SPA_VIDEO_FORMAT_BGRA, SPA_VIDEO_FORMAT_RGBA,
  551. SPA_VIDEO_FORMAT_BGRx, SPA_VIDEO_FORMAT_RGBx),
  552. SPA_FORMAT_VIDEO_size,
  553. SPA_POD_CHOICE_RANGE_Rectangle(
  554. &SPA_RECTANGLE(320, 240), // Arbitrary
  555. &SPA_RECTANGLE(1, 1), &SPA_RECTANGLE(8192, 4320)),
  556. SPA_FORMAT_VIDEO_framerate,
  557. SPA_POD_CHOICE_RANGE_Fraction(
  558. &SPA_FRACTION(ovi.fps_num, ovi.fps_den),
  559. &SPA_FRACTION(0, 1), &SPA_FRACTION(360, 1)));
  560. obs_pw->video_info = ovi;
  561. pw_stream_connect(
  562. obs_pw->stream, PW_DIRECTION_INPUT, obs_pw->pipewire_node,
  563. PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_MAP_BUFFERS, params,
  564. 1);
  565. blog(LOG_INFO, "[pipewire] playing stream…");
  566. pw_thread_loop_unlock(obs_pw->thread_loop);
  567. }
  568. /* ------------------------------------------------- */
  569. static void on_pipewire_remote_opened_cb(GObject *source, GAsyncResult *res,
  570. void *user_data)
  571. {
  572. g_autoptr(GUnixFDList) fd_list = NULL;
  573. g_autoptr(GVariant) result = NULL;
  574. g_autoptr(GError) error = NULL;
  575. obs_pipewire_data *obs_pw = user_data;
  576. int fd_index;
  577. result = g_dbus_proxy_call_with_unix_fd_list_finish(
  578. G_DBUS_PROXY(source), &fd_list, res, &error);
  579. if (error) {
  580. if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
  581. blog(LOG_ERROR,
  582. "[pipewire] Error retrieving pipewire fd: %s",
  583. error->message);
  584. return;
  585. }
  586. g_variant_get(result, "(h)", &fd_index, &error);
  587. obs_pw->pipewire_fd = g_unix_fd_list_get(fd_list, fd_index, &error);
  588. if (error) {
  589. if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
  590. blog(LOG_ERROR,
  591. "[pipewire] Error retrieving pipewire fd: %s",
  592. error->message);
  593. return;
  594. }
  595. play_pipewire_stream(obs_pw);
  596. }
  597. static void open_pipewire_remote(obs_pipewire_data *obs_pw)
  598. {
  599. GVariantBuilder builder;
  600. g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
  601. g_dbus_proxy_call_with_unix_fd_list(
  602. portal_get_dbus_proxy(), "OpenPipeWireRemote",
  603. g_variant_new("(oa{sv})", obs_pw->session_handle, &builder),
  604. G_DBUS_CALL_FLAGS_NONE, -1, NULL, obs_pw->cancellable,
  605. on_pipewire_remote_opened_cb, obs_pw);
  606. }
  607. /* ------------------------------------------------- */
  608. static void on_start_response_received_cb(GDBusConnection *connection,
  609. const char *sender_name,
  610. const char *object_path,
  611. const char *interface_name,
  612. const char *signal_name,
  613. GVariant *parameters, void *user_data)
  614. {
  615. UNUSED_PARAMETER(connection);
  616. UNUSED_PARAMETER(sender_name);
  617. UNUSED_PARAMETER(object_path);
  618. UNUSED_PARAMETER(interface_name);
  619. UNUSED_PARAMETER(signal_name);
  620. g_autoptr(GVariant) stream_properties = NULL;
  621. g_autoptr(GVariant) streams = NULL;
  622. g_autoptr(GVariant) result = NULL;
  623. struct dbus_call_data *call = user_data;
  624. obs_pipewire_data *obs_pw = call->obs_pw;
  625. GVariantIter iter;
  626. uint32_t response;
  627. size_t n_streams;
  628. g_clear_pointer(&call, dbus_call_data_free);
  629. g_variant_get(parameters, "(u@a{sv})", &response, &result);
  630. if (response != 0) {
  631. blog(LOG_WARNING,
  632. "[pipewire] Failed to start screencast, denied or cancelled by user");
  633. return;
  634. }
  635. streams =
  636. g_variant_lookup_value(result, "streams", G_VARIANT_TYPE_ARRAY);
  637. g_variant_iter_init(&iter, streams);
  638. n_streams = g_variant_iter_n_children(&iter);
  639. if (n_streams != 1) {
  640. blog(LOG_WARNING,
  641. "[pipewire] Received more than one stream when only one was expected. "
  642. "This is probably a bug in the desktop portal implementation you are "
  643. "using.");
  644. // The KDE Desktop portal implementation sometimes sends an invalid
  645. // response where more than one stream is attached, and only the
  646. // last one is the one we're looking for. This is the only known
  647. // buggy implementation, so let's at least try to make it work here.
  648. for (size_t i = 0; i < n_streams - 1; i++) {
  649. g_autoptr(GVariant) throwaway_properties = NULL;
  650. uint32_t throwaway_pipewire_node;
  651. g_variant_iter_loop(&iter, "(u@a{sv})",
  652. &throwaway_pipewire_node,
  653. &throwaway_properties);
  654. }
  655. }
  656. g_variant_iter_loop(&iter, "(u@a{sv})", &obs_pw->pipewire_node,
  657. &stream_properties);
  658. blog(LOG_INFO, "[pipewire] %s selected, setting up screencast",
  659. capture_type_to_string(obs_pw->capture_type));
  660. open_pipewire_remote(obs_pw);
  661. }
  662. static void on_started_cb(GObject *source, GAsyncResult *res, void *user_data)
  663. {
  664. UNUSED_PARAMETER(user_data);
  665. g_autoptr(GVariant) result = NULL;
  666. g_autoptr(GError) error = NULL;
  667. result = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error);
  668. if (error) {
  669. if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
  670. blog(LOG_ERROR,
  671. "[pipewire] Error selecting screencast source: %s",
  672. error->message);
  673. return;
  674. }
  675. }
  676. static void start(obs_pipewire_data *obs_pw)
  677. {
  678. GVariantBuilder builder;
  679. struct dbus_call_data *call;
  680. char *request_token;
  681. char *request_path;
  682. new_request_path(obs_pw, &request_path, &request_token);
  683. blog(LOG_INFO, "[pipewire] asking for %s…",
  684. capture_type_to_string(obs_pw->capture_type));
  685. call = subscribe_to_signal(obs_pw, request_path,
  686. on_start_response_received_cb);
  687. g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
  688. g_variant_builder_add(&builder, "{sv}", "handle_token",
  689. g_variant_new_string(request_token));
  690. g_dbus_proxy_call(portal_get_dbus_proxy(), "Start",
  691. g_variant_new("(osa{sv})", obs_pw->session_handle, "",
  692. &builder),
  693. G_DBUS_CALL_FLAGS_NONE, -1, obs_pw->cancellable,
  694. on_started_cb, call);
  695. bfree(request_token);
  696. bfree(request_path);
  697. }
  698. /* ------------------------------------------------- */
  699. static void on_select_source_response_received_cb(
  700. GDBusConnection *connection, const char *sender_name,
  701. const char *object_path, const char *interface_name,
  702. const char *signal_name, GVariant *parameters, void *user_data)
  703. {
  704. UNUSED_PARAMETER(connection);
  705. UNUSED_PARAMETER(sender_name);
  706. UNUSED_PARAMETER(object_path);
  707. UNUSED_PARAMETER(interface_name);
  708. UNUSED_PARAMETER(signal_name);
  709. g_autoptr(GVariant) ret = NULL;
  710. struct dbus_call_data *call = user_data;
  711. obs_pipewire_data *obs_pw = call->obs_pw;
  712. uint32_t response;
  713. blog(LOG_DEBUG, "[pipewire] Response to select source received");
  714. g_clear_pointer(&call, dbus_call_data_free);
  715. g_variant_get(parameters, "(u@a{sv})", &response, &ret);
  716. if (response != 0) {
  717. blog(LOG_WARNING,
  718. "[pipewire] Failed to select source, denied or cancelled by user");
  719. return;
  720. }
  721. start(obs_pw);
  722. }
  723. static void on_source_selected_cb(GObject *source, GAsyncResult *res,
  724. void *user_data)
  725. {
  726. UNUSED_PARAMETER(user_data);
  727. g_autoptr(GVariant) result = NULL;
  728. g_autoptr(GError) error = NULL;
  729. result = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error);
  730. if (error) {
  731. if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
  732. blog(LOG_ERROR,
  733. "[pipewire] Error selecting screencast source: %s",
  734. error->message);
  735. return;
  736. }
  737. }
  738. static void select_source(obs_pipewire_data *obs_pw)
  739. {
  740. struct dbus_call_data *call;
  741. GVariantBuilder builder;
  742. char *request_token;
  743. char *request_path;
  744. new_request_path(obs_pw, &request_path, &request_token);
  745. call = subscribe_to_signal(obs_pw, request_path,
  746. on_select_source_response_received_cb);
  747. g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
  748. g_variant_builder_add(&builder, "{sv}", "types",
  749. g_variant_new_uint32(obs_pw->capture_type));
  750. g_variant_builder_add(&builder, "{sv}", "multiple",
  751. g_variant_new_boolean(FALSE));
  752. g_variant_builder_add(&builder, "{sv}", "handle_token",
  753. g_variant_new_string(request_token));
  754. if (obs_pw->available_cursor_modes & 4)
  755. g_variant_builder_add(&builder, "{sv}", "cursor_mode",
  756. g_variant_new_uint32(4));
  757. else if ((obs_pw->available_cursor_modes & 2) && obs_pw->cursor.visible)
  758. g_variant_builder_add(&builder, "{sv}", "cursor_mode",
  759. g_variant_new_uint32(2));
  760. else
  761. g_variant_builder_add(&builder, "{sv}", "cursor_mode",
  762. g_variant_new_uint32(1));
  763. g_dbus_proxy_call(portal_get_dbus_proxy(), "SelectSources",
  764. g_variant_new("(oa{sv})", obs_pw->session_handle,
  765. &builder),
  766. G_DBUS_CALL_FLAGS_NONE, -1, obs_pw->cancellable,
  767. on_source_selected_cb, call);
  768. bfree(request_token);
  769. bfree(request_path);
  770. }
  771. /* ------------------------------------------------- */
  772. static void on_create_session_response_received_cb(
  773. GDBusConnection *connection, const char *sender_name,
  774. const char *object_path, const char *interface_name,
  775. const char *signal_name, GVariant *parameters, void *user_data)
  776. {
  777. UNUSED_PARAMETER(connection);
  778. UNUSED_PARAMETER(sender_name);
  779. UNUSED_PARAMETER(object_path);
  780. UNUSED_PARAMETER(interface_name);
  781. UNUSED_PARAMETER(signal_name);
  782. g_autoptr(GVariant) session_handle_variant = NULL;
  783. g_autoptr(GVariant) result = NULL;
  784. struct dbus_call_data *call = user_data;
  785. obs_pipewire_data *obs_pw = call->obs_pw;
  786. uint32_t response;
  787. g_clear_pointer(&call, dbus_call_data_free);
  788. g_variant_get(parameters, "(u@a{sv})", &response, &result);
  789. if (response != 0) {
  790. blog(LOG_WARNING,
  791. "[pipewire] Failed to create session, denied or cancelled by user");
  792. return;
  793. }
  794. blog(LOG_INFO, "[pipewire] screencast session created");
  795. session_handle_variant =
  796. g_variant_lookup_value(result, "session_handle", NULL);
  797. obs_pw->session_handle =
  798. g_variant_dup_string(session_handle_variant, NULL);
  799. select_source(obs_pw);
  800. }
  801. static void on_session_created_cb(GObject *source, GAsyncResult *res,
  802. void *user_data)
  803. {
  804. UNUSED_PARAMETER(user_data);
  805. g_autoptr(GVariant) result = NULL;
  806. g_autoptr(GError) error = NULL;
  807. result = g_dbus_proxy_call_finish(G_DBUS_PROXY(source), res, &error);
  808. if (error) {
  809. if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
  810. blog(LOG_ERROR,
  811. "[pipewire] Error creating screencast session: %s",
  812. error->message);
  813. return;
  814. }
  815. }
  816. static void create_session(obs_pipewire_data *obs_pw)
  817. {
  818. struct dbus_call_data *call;
  819. GVariantBuilder builder;
  820. char *session_token;
  821. char *request_token;
  822. char *request_path;
  823. new_request_path(obs_pw, &request_path, &request_token);
  824. new_session_path(obs_pw, NULL, &session_token);
  825. call = subscribe_to_signal(obs_pw, request_path,
  826. on_create_session_response_received_cb);
  827. g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
  828. g_variant_builder_add(&builder, "{sv}", "handle_token",
  829. g_variant_new_string(request_token));
  830. g_variant_builder_add(&builder, "{sv}", "session_handle_token",
  831. g_variant_new_string(session_token));
  832. g_dbus_proxy_call(portal_get_dbus_proxy(), "CreateSession",
  833. g_variant_new("(a{sv})", &builder),
  834. G_DBUS_CALL_FLAGS_NONE, -1, obs_pw->cancellable,
  835. on_session_created_cb, call);
  836. bfree(session_token);
  837. bfree(request_token);
  838. bfree(request_path);
  839. }
  840. /* ------------------------------------------------- */
  841. static void update_available_cursor_modes(obs_pipewire_data *obs_pw,
  842. GDBusProxy *proxy)
  843. {
  844. g_autoptr(GVariant) cached_cursor_modes = NULL;
  845. uint32_t available_cursor_modes;
  846. cached_cursor_modes =
  847. g_dbus_proxy_get_cached_property(proxy, "AvailableCursorModes");
  848. available_cursor_modes =
  849. cached_cursor_modes ? g_variant_get_uint32(cached_cursor_modes)
  850. : 0;
  851. obs_pw->available_cursor_modes = available_cursor_modes;
  852. blog(LOG_INFO, "[pipewire] available cursor modes:");
  853. if (available_cursor_modes & 4)
  854. blog(LOG_INFO, "[pipewire] - Metadata");
  855. if (available_cursor_modes & 2)
  856. blog(LOG_INFO, "[pipewire] - Always visible");
  857. if (available_cursor_modes & 1)
  858. blog(LOG_INFO, "[pipewire] - Hidden");
  859. }
  860. /* ------------------------------------------------- */
  861. static gboolean init_obs_pipewire(obs_pipewire_data *obs_pw)
  862. {
  863. GDBusConnection *connection;
  864. GDBusProxy *proxy;
  865. char *aux;
  866. obs_pw->cancellable = g_cancellable_new();
  867. connection = portal_get_dbus_connection();
  868. if (!connection)
  869. return FALSE;
  870. proxy = portal_get_dbus_proxy();
  871. if (!proxy)
  872. return FALSE;
  873. update_available_cursor_modes(obs_pw, proxy);
  874. obs_pw->sender_name =
  875. bstrdup(g_dbus_connection_get_unique_name(connection) + 1);
  876. /* Replace dots by underscores */
  877. while ((aux = strstr(obs_pw->sender_name, ".")) != NULL)
  878. *aux = '_';
  879. blog(LOG_INFO, "PipeWire initialized (sender name: %s)",
  880. obs_pw->sender_name);
  881. create_session(obs_pw);
  882. return TRUE;
  883. }
  884. static bool reload_session_cb(obs_properties_t *properties,
  885. obs_property_t *property, void *data)
  886. {
  887. UNUSED_PARAMETER(properties);
  888. UNUSED_PARAMETER(property);
  889. obs_pipewire_data *obs_pw = data;
  890. teardown_pipewire(obs_pw);
  891. destroy_session(obs_pw);
  892. init_obs_pipewire(obs_pw);
  893. return false;
  894. }
  895. /* obs_source_info methods */
  896. void *obs_pipewire_create(enum obs_pw_capture_type capture_type,
  897. obs_data_t *settings, obs_source_t *source)
  898. {
  899. obs_pipewire_data *obs_pw = bzalloc(sizeof(obs_pipewire_data));
  900. obs_pw->source = source;
  901. obs_pw->settings = settings;
  902. obs_pw->capture_type = capture_type;
  903. obs_pw->cursor.visible = obs_data_get_bool(settings, "ShowCursor");
  904. if (!init_obs_pipewire(obs_pw))
  905. g_clear_pointer(&obs_pw, bfree);
  906. return obs_pw;
  907. }
  908. void obs_pipewire_destroy(obs_pipewire_data *obs_pw)
  909. {
  910. if (!obs_pw)
  911. return;
  912. teardown_pipewire(obs_pw);
  913. destroy_session(obs_pw);
  914. bfree(obs_pw);
  915. }
  916. void obs_pipewire_get_defaults(obs_data_t *settings)
  917. {
  918. obs_data_set_default_bool(settings, "ShowCursor", true);
  919. }
  920. obs_properties_t *obs_pipewire_get_properties(obs_pipewire_data *obs_pw,
  921. const char *reload_string_id)
  922. {
  923. obs_properties_t *properties;
  924. properties = obs_properties_create();
  925. obs_properties_add_button2(properties, "Reload",
  926. obs_module_text(reload_string_id),
  927. reload_session_cb, obs_pw);
  928. obs_properties_add_bool(properties, "ShowCursor",
  929. obs_module_text("ShowCursor"));
  930. return properties;
  931. }
  932. void obs_pipewire_update(obs_pipewire_data *obs_pw, obs_data_t *settings)
  933. {
  934. obs_pw->cursor.visible = obs_data_get_bool(settings, "ShowCursor");
  935. }
  936. void obs_pipewire_show(obs_pipewire_data *obs_pw)
  937. {
  938. if (obs_pw->stream)
  939. pw_stream_set_active(obs_pw->stream, true);
  940. }
  941. void obs_pipewire_hide(obs_pipewire_data *obs_pw)
  942. {
  943. if (obs_pw->stream)
  944. pw_stream_set_active(obs_pw->stream, false);
  945. }
  946. uint32_t obs_pipewire_get_width(obs_pipewire_data *obs_pw)
  947. {
  948. if (!obs_pw->negotiated)
  949. return 0;
  950. if (obs_pw->crop.valid)
  951. return obs_pw->crop.width;
  952. else
  953. return obs_pw->format.info.raw.size.width;
  954. }
  955. uint32_t obs_pipewire_get_height(obs_pipewire_data *obs_pw)
  956. {
  957. if (!obs_pw->negotiated)
  958. return 0;
  959. if (obs_pw->crop.valid)
  960. return obs_pw->crop.height;
  961. else
  962. return obs_pw->format.info.raw.size.height;
  963. }
  964. void obs_pipewire_video_render(obs_pipewire_data *obs_pw, gs_effect_t *effect)
  965. {
  966. gs_eparam_t *image;
  967. if (!obs_pw->texture)
  968. return;
  969. image = gs_effect_get_param_by_name(effect, "image");
  970. gs_effect_set_texture(image, obs_pw->texture);
  971. if (has_effective_crop(obs_pw)) {
  972. gs_draw_sprite_subregion(obs_pw->texture, 0, obs_pw->crop.x,
  973. obs_pw->crop.y, obs_pw->crop.width,
  974. obs_pw->crop.height);
  975. } else {
  976. gs_draw_sprite(obs_pw->texture, 0, 0, 0);
  977. }
  978. if (obs_pw->cursor.visible && obs_pw->cursor.valid &&
  979. obs_pw->cursor.texture) {
  980. float cursor_x = obs_pw->cursor.x - obs_pw->cursor.hotspot_x;
  981. float cursor_y = obs_pw->cursor.y - obs_pw->cursor.hotspot_y;
  982. gs_matrix_push();
  983. gs_matrix_translate3f(cursor_x, cursor_y, 0.0f);
  984. gs_effect_set_texture(image, obs_pw->cursor.texture);
  985. gs_draw_sprite(obs_pw->texture, 0, obs_pw->cursor.width,
  986. obs_pw->cursor.height);
  987. gs_matrix_pop();
  988. }
  989. }
  990. enum obs_pw_capture_type
  991. obs_pipewire_get_capture_type(obs_pipewire_data *obs_pw)
  992. {
  993. return obs_pw->capture_type;
  994. }