formats.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * formats.c
  3. *
  4. * Copyright 2023 Georges Basile Stavracas Neto <[email protected]>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * SPDX-License-Identifier: GPL-2.0-or-later
  20. */
  21. #include "formats.h"
  22. #include <libdrm/drm_fourcc.h>
  23. #include <pipewire/pipewire.h>
  24. static const struct obs_pw_video_format supported_formats[] = {
  25. {
  26. SPA_VIDEO_FORMAT_BGRA,
  27. DRM_FORMAT_ARGB8888,
  28. GS_BGRA,
  29. VIDEO_FORMAT_BGRA,
  30. false,
  31. 4,
  32. "ARGB8888",
  33. },
  34. {
  35. SPA_VIDEO_FORMAT_RGBA,
  36. DRM_FORMAT_ABGR8888,
  37. GS_RGBA,
  38. VIDEO_FORMAT_RGBA,
  39. false,
  40. 4,
  41. "ABGR8888",
  42. },
  43. {
  44. SPA_VIDEO_FORMAT_BGRx,
  45. DRM_FORMAT_XRGB8888,
  46. GS_BGRX,
  47. VIDEO_FORMAT_BGRX,
  48. false,
  49. 4,
  50. "XRGB8888",
  51. },
  52. {
  53. SPA_VIDEO_FORMAT_RGBx,
  54. DRM_FORMAT_XBGR8888,
  55. GS_BGRX,
  56. VIDEO_FORMAT_NONE,
  57. true,
  58. 4,
  59. "XBGR8888",
  60. },
  61. {
  62. SPA_VIDEO_FORMAT_YUY2,
  63. DRM_FORMAT_YUYV,
  64. GS_UNKNOWN,
  65. VIDEO_FORMAT_YUY2,
  66. false,
  67. 2,
  68. "YUYV422",
  69. },
  70. {
  71. SPA_VIDEO_FORMAT_NV12,
  72. DRM_FORMAT_NV12,
  73. GS_UNKNOWN,
  74. VIDEO_FORMAT_NV12,
  75. false,
  76. 2,
  77. "NV12",
  78. },
  79. #if PW_CHECK_VERSION(0, 3, 41)
  80. {
  81. SPA_VIDEO_FORMAT_ABGR_210LE,
  82. DRM_FORMAT_ABGR2101010,
  83. GS_R10G10B10A2,
  84. VIDEO_FORMAT_NONE,
  85. false,
  86. 10,
  87. "ABGR2101010",
  88. },
  89. {
  90. SPA_VIDEO_FORMAT_xBGR_210LE,
  91. DRM_FORMAT_XBGR2101010,
  92. GS_R10G10B10A2,
  93. VIDEO_FORMAT_NONE,
  94. false,
  95. 10,
  96. "XBGR2101010",
  97. },
  98. #endif
  99. };
  100. #define N_SUPPORTED_FORMATS (sizeof(supported_formats) / sizeof(supported_formats[0]))
  101. bool obs_pw_video_format_from_spa_format(uint32_t spa_format, struct obs_pw_video_format *out_video_format)
  102. {
  103. for (size_t i = 0; i < N_SUPPORTED_FORMATS; i++) {
  104. if (supported_formats[i].spa_format != spa_format)
  105. continue;
  106. if (out_video_format)
  107. *out_video_format = supported_formats[i];
  108. return true;
  109. }
  110. return false;
  111. }