PipeWire camera: add support for BGRA/RGBA formats

Adds support for 32 bits formats needed for libcamera software ISP. This
is needed, because libcamera enforces 8 byte alignment and we only
support 3 byte alignment for RGB. This will make it work with 32 bits
aligned output formats recently added to libcamera.

Relevant libcamera patch: https://patchwork.libcamera.org/patch/20253/

This has been verified on an snapdragon device using libcamera and software ISP and on my machine using "vivid" virtual camera from libcamera and enforcing specific format.

Bug: webrtc:346808586
Change-Id: I8d89120660b2304b880d952c5acd7f5cd09b611e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/354400
Commit-Queue: Jan Grulich <grulja@gmail.com>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42474}
This commit is contained in:
Jan Grulich 2024-06-12 21:30:02 +02:00 committed by WebRTC LUCI CQ
parent 94a6b92645
commit c3aeffd776
2 changed files with 12 additions and 0 deletions

View File

@ -37,6 +37,10 @@ VideoType PipeWireRawFormatToVideoType(uint32_t id) {
return VideoType::kUYVY;
case SPA_VIDEO_FORMAT_RGB:
return VideoType::kRGB24;
case SPA_VIDEO_FORMAT_BGRA:
return VideoType::kARGB;
case SPA_VIDEO_FORMAT_RGBA:
return VideoType::kABGR;
default:
return VideoType::kUnknown;
}

View File

@ -33,6 +33,10 @@ struct {
{SPA_VIDEO_FORMAT_NV12, VideoType::kNV12},
{SPA_VIDEO_FORMAT_YUY2, VideoType::kYUY2},
{SPA_VIDEO_FORMAT_UYVY, VideoType::kUYVY},
// PipeWire is big-endian for the formats, while libyuv is little-endian
// This means that BGRA == ARGB and RGBA == ABGR
{SPA_VIDEO_FORMAT_BGRA, VideoType::kARGB},
{SPA_VIDEO_FORMAT_RGBA, VideoType::kABGR},
{SPA_VIDEO_FORMAT_RGB, VideoType::kRGB24},
};
@ -303,6 +307,10 @@ void VideoCaptureModulePipeWire::OnFormatChanged(const struct spa_pod* format) {
case VideoType::kRGB24:
stride = configured_capability_.width * 3;
break;
case VideoType::kARGB:
case VideoType::kABGR:
stride = configured_capability_.width * 4;
break;
default:
RTC_LOG(LS_ERROR) << "Unsupported video format.";
return;