Skip to content

Commit 8948bda

Browse files
committed
Improvements and linux pre (#1)
* Implement getting sources from screencapture kit * Expose stream rect on linux in metadata
1 parent 26400c8 commit 8948bda

File tree

6 files changed

+89
-4
lines changed

6 files changed

+89
-4
lines changed

modules/desktop_capture/linux/wayland/base_capturer_pipewire.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,4 +243,7 @@ void BaseCapturerPipeWire::SendFramesImmediately(bool send_frames_immediately) {
243243
send_frames_immediately_ = send_frames_immediately;
244244
}
245245

246+
DesktopCaptureMetadata BaseCapturerPipeWire::GetMetadata() {
247+
return DesktopCaptureMetadata{GetSessionDetails()};
248+
}
246249
} // namespace webrtc

modules/desktop_capture/linux/wayland/base_capturer_pipewire.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class RTC_EXPORT BaseCapturerPipeWire
5050
bool SelectSource(SourceId id) override;
5151
DelegatedSourceListController* GetDelegatedSourceListController() override;
5252
void SetMaxFrameRate(uint32_t max_frame_rate) override;
53+
DesktopCaptureMetadata GetMetadata() override;
5354

5455
// DelegatedSourceListController
5556
void Observe(Observer* observer) override;

modules/desktop_capture/linux/wayland/screencast_portal.cc

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,18 @@ void ScreenCastPortal::SetSessionDetails(
118118
if (session_details.pipewire_stream_node_id) {
119119
pw_stream_node_id_ = session_details.pipewire_stream_node_id;
120120
}
121+
if (session_details.top) {
122+
top_ = session_details.top;
123+
}
124+
if (session_details.left) {
125+
left_ = session_details.left;
126+
}
127+
if (session_details.width) {
128+
width_ = session_details.width;
129+
}
130+
if (session_details.height) {
131+
height_ = session_details.height;
132+
}
121133
}
122134

123135
void ScreenCastPortal::Start() {
@@ -127,7 +139,16 @@ void ScreenCastPortal::Start() {
127139
}
128140

129141
xdg_portal::SessionDetails ScreenCastPortal::GetSessionDetails() {
130-
return {}; // No-op
142+
return xdg_portal::SessionDetails{
143+
proxy_,
144+
cancellable_,
145+
session_handle_,
146+
pw_stream_node_id_,
147+
width_,
148+
height_,
149+
top_,
150+
left_
151+
};
131152
}
132153

133154
void ScreenCastPortal::OnPortalDone(RequestResponse result) {
@@ -383,6 +404,12 @@ void ScreenCastPortal::OnStartRequestResponseSignal(GDBusConnection* connection,
383404

384405
that->pw_stream_node_id_ = stream_id;
385406

407+
int32_t width = 0, height = 0, top = 0, left = 0;
408+
g_variant_lookup(options.get(), "position", "(ii)", &left, &top);
409+
g_variant_lookup(options.get(), "size", "(ii)", &width, &height);
410+
xdg_portal::SessionDetails details{nullptr, nullptr, std::string{}, 0, width, height, top, left};
411+
that->SetSessionDetails(details);
412+
386413
break;
387414
}
388415
}

modules/desktop_capture/linux/wayland/screencast_portal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ class RTC_EXPORT ScreenCastPortal
165165
guint start_request_signal_id_ = 0;
166166
guint session_closed_signal_id_ = 0;
167167

168+
// Temporary solution for storing stream origin
169+
int32_t width_ = 0;
170+
int32_t height_ = 0;
171+
int32_t top_ = 0;
172+
int32_t left_ = 0;
173+
168174
void UnsubscribeSignalHandlers();
169175
static void OnProxyRequested(GObject* object,
170176
GAsyncResult* result,

modules/desktop_capture/mac/screen_capturer_sck.mm

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,54 @@ friend void AbslStringify(Sink& sink,
462462
bool ScreenCapturerSck::GetSourceList(SourceList* sources) {
463463
RTC_DCHECK_RUN_ON(&api_checker_);
464464
sources->clear();
465-
EnsurePickerHandle();
466-
if (picker_handle_) {
467-
sources->push_back({picker_handle_->Source(), std::string()});
465+
466+
if (capture_options_.allow_sck_system_picker()) {
467+
EnsurePickerHandle();
468+
if (picker_handle_) {
469+
sources->push_back({picker_handle_->Source(), std::string()});
470+
}
471+
return true;
472+
}
473+
474+
__block SCShareableContent* shareable_content = nil;
475+
__block NSError* fetch_error = nil;
476+
477+
// Use synchronous approach with semaphore to wait for async completion
478+
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
479+
480+
[SCShareableContent getShareableContentWithCompletionHandler:^(SCShareableContent* content, NSError* error) {
481+
shareable_content = content;
482+
fetch_error = error;
483+
dispatch_semaphore_signal(semaphore);
484+
}];
485+
486+
// Wait for the completion handler
487+
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
488+
489+
if (fetch_error || !shareable_content) {
490+
RTC_LOG(LS_ERROR) << "ScreenCapturerSck " << this
491+
<< " GetSourceList failed to get shareable content with error code "
492+
<< (fetch_error ? fetch_error.code : 0) << ".";
493+
return false;
494+
}
495+
496+
if (!shareable_content.displays.count) {
497+
RTC_LOG(LS_WARNING) << "ScreenCapturerSck " << this
498+
<< " GetSourceList returned no displays.";
499+
return true; // Return true but with empty list
468500
}
501+
502+
// Populate sources with available displays
503+
for (SCDisplay* display in shareable_content.displays) {
504+
DesktopCapturer::Source source;
505+
source.id = static_cast<SourceId>(display.displayID);
506+
507+
source.display_id = display.displayID;
508+
sources->push_back(source);
509+
}
510+
511+
RTC_LOG(LS_INFO) << "ScreenCapturerSck " << this
512+
<< " GetSourceList found " << sources->size() << " displays.";
469513
return true;
470514
}
471515

modules/portal/xdg_session_details.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ struct SessionDetails {
2525
GCancellable* cancellable = nullptr;
2626
std::string session_handle;
2727
uint32_t pipewire_stream_node_id = 0;
28+
int32_t width = 0;
29+
int32_t height = 0;
30+
int32_t top = 0;
31+
int32_t left = 0;
2832
};
2933

3034
} // namespace xdg_portal

0 commit comments

Comments
 (0)