Skip to content

Commit

Permalink
linux-pipewire: Factor out formats list into a file
Browse files Browse the repository at this point in the history
This will help share these formats with the upcoming Camera portal
code.
  • Loading branch information
GeorgesStavracas committed Jan 11, 2024
1 parent 7f765cd commit 364323e
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 146 deletions.
4 changes: 3 additions & 1 deletion plugins/linux-pipewire/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ add_library(OBS::pipewire ALIAS linux-pipewire)

target_sources(
linux-pipewire
PRIVATE linux-pipewire.c
PRIVATE formats.c
formats.h
linux-pipewire.c
pipewire.c
pipewire.h
portal.c
Expand Down
122 changes: 122 additions & 0 deletions plugins/linux-pipewire/formats.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* formats.c
*
* Copyright 2023 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* 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/>.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "formats.h"

#include <libdrm/drm_fourcc.h>
#include <pipewire/pipewire.h>

static const struct obs_pw_video_format supported_formats[] = {
{
SPA_VIDEO_FORMAT_BGRA,
DRM_FORMAT_ARGB8888,
GS_BGRA,
VIDEO_FORMAT_BGRA,
false,
4,
"ARGB8888",
},
{
SPA_VIDEO_FORMAT_RGBA,
DRM_FORMAT_ABGR8888,
GS_RGBA,
VIDEO_FORMAT_RGBA,
false,
4,
"ABGR8888",
},
{
SPA_VIDEO_FORMAT_BGRx,
DRM_FORMAT_XRGB8888,
GS_BGRX,
VIDEO_FORMAT_BGRX,
false,
4,
"XRGB8888",
},
{
SPA_VIDEO_FORMAT_RGBx,
DRM_FORMAT_XBGR8888,
GS_BGRX,
VIDEO_FORMAT_NONE,
true,
4,
"XBGR8888",
},
{
SPA_VIDEO_FORMAT_YUY2,
DRM_FORMAT_YUYV,
GS_UNKNOWN,
VIDEO_FORMAT_YUY2,
false,
2,
"YUYV422",
},
{
SPA_VIDEO_FORMAT_NV12,
DRM_FORMAT_NV12,
GS_UNKNOWN,
VIDEO_FORMAT_NV12,
false,
2,
"NV12",
},
#if PW_CHECK_VERSION(0, 3, 41)
{
SPA_VIDEO_FORMAT_ABGR_210LE,
DRM_FORMAT_ABGR2101010,
GS_R10G10B10A2,
VIDEO_FORMAT_NONE,
false,
10,
"ABGR2101010",

},
{
SPA_VIDEO_FORMAT_xBGR_210LE,
DRM_FORMAT_XBGR2101010,
GS_R10G10B10A2,
VIDEO_FORMAT_NONE,
false,
10,
"XBGR2101010",

},
#endif
};

#define N_SUPPORTED_FORMATS \
(sizeof(supported_formats) / sizeof(supported_formats[0]))

bool obs_pw_video_format_from_spa_format(
uint32_t spa_format, struct obs_pw_video_format *out_video_format)
{
for (size_t i = 0; i < N_SUPPORTED_FORMATS; i++) {
if (supported_formats[i].spa_format != spa_format)
continue;

if (out_video_format)
*out_video_format = supported_formats[i];

return true;
}
return false;
}
39 changes: 39 additions & 0 deletions plugins/linux-pipewire/formats.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* formats.h
*
* Copyright 2023 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* 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/>.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/

#pragma once

#include <obs-module.h>

#include <spa/param/video/format-utils.h>

struct obs_pw_video_format {
uint32_t spa_format;
uint32_t drm_format;
enum gs_color_format gs_format;
enum video_format video_format;
bool swap_red_blue;
uint32_t bpp;
const char *pretty_name;
};

bool obs_pw_video_format_from_spa_format(
uint32_t spa_format, struct obs_pw_video_format *out_format_info);

0 comments on commit 364323e

Please sign in to comment.