pipewire.c 33 KB

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