Bug 1843786 - webrtc: Implement Pipewire camera rotation support, r=webrtc-reviewers,pehrsons,@webrtc-reviewers

Support the Pipewire videotransform meta via the already existing shared
infrastructure. This is needed for mobile devices which often have a 90
degree rotated camera - which is likely the reason there is already
support in the shared code paths.

Upstream commit: dc4c019c62abefc09e4903abea44bc36f3427452

Differential Revision: https://phabricator.services.mozilla.com/D183652
This commit is contained in:
Robert Mader 2023-09-06 16:37:55 +00:00
Родитель 0cfcaa31a6
Коммит 78a6ed6ce1
2 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -278,6 +278,10 @@ void VideoCaptureModulePipeWire::OnFormatChanged(const struct spa_pod* format) {
&builder, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, SPA_PARAM_META_type,
SPA_POD_Id(SPA_META_Header), SPA_PARAM_META_size,
SPA_POD_Int(sizeof(struct spa_meta_header)))));
params.push_back(reinterpret_cast<spa_pod*>(spa_pod_builder_add_object(
&builder, SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta, SPA_PARAM_META_type,
SPA_POD_Id(SPA_META_VideoTransform), SPA_PARAM_META_size,
SPA_POD_Int(sizeof(struct spa_meta_videotransform)))));
pw_stream_update_params(stream_, params.data(), params.size());
}
@ -315,12 +319,36 @@ void VideoCaptureModulePipeWire::OnStreamProcess(void* data) {
that->ProcessBuffers();
}
static VideoRotation VideorotationFromPipeWireTransform(uint32_t transform) {
switch (transform) {
case SPA_META_TRANSFORMATION_90:
return kVideoRotation_90;
case SPA_META_TRANSFORMATION_180:
return kVideoRotation_180;
case SPA_META_TRANSFORMATION_270:
return kVideoRotation_270;
default:
return kVideoRotation_0;
}
}
void VideoCaptureModulePipeWire::ProcessBuffers() {
while (pw_buffer* buffer = pw_stream_dequeue_buffer(stream_)) {
struct spa_meta_header* h;
h = static_cast<struct spa_meta_header*>(
spa_buffer_find_meta_data(buffer->buffer, SPA_META_Header, sizeof(*h)));
struct spa_meta_videotransform* videotransform;
videotransform =
static_cast<struct spa_meta_videotransform*>(spa_buffer_find_meta_data(
buffer->buffer, SPA_META_VideoTransform, sizeof(*videotransform)));
if (videotransform) {
VideoRotation rotation =
VideorotationFromPipeWireTransform(videotransform->transform);
SetCaptureRotation(rotation);
SetApplyRotation(rotation != kVideoRotation_0);
}
if (h->flags & SPA_META_HEADER_FLAG_CORRUPTED) {
RTC_LOG(LS_INFO) << "Dropping corruped frame.";
} else {

Просмотреть файл

@ -0,0 +1 @@
We cherry-picked this in bug 1843786