Repo created
This commit is contained in:
parent
81b91f4139
commit
f8c34fa5ee
22732 changed files with 4815320 additions and 2 deletions
2
TMessagesProj/jni/voip/webrtc/modules/portal/OWNERS
Normal file
2
TMessagesProj/jni/voip/webrtc/modules/portal/OWNERS
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
alcooper@chromium.org
|
||||
mfoltz@chromium.org
|
||||
56
TMessagesProj/jni/voip/webrtc/modules/portal/pipewire.sigs
Normal file
56
TMessagesProj/jni/voip/webrtc/modules/portal/pipewire.sigs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2018 The WebRTC project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
//------------------------------------------------
|
||||
// Functions from PipeWire used in capturer code.
|
||||
//------------------------------------------------
|
||||
|
||||
// core.h
|
||||
int pw_core_disconnect(pw_core *core);
|
||||
|
||||
// loop.h
|
||||
void pw_loop_destroy(pw_loop *loop);
|
||||
pw_loop * pw_loop_new(const spa_dict *props);
|
||||
|
||||
|
||||
// pipewire.h
|
||||
void pw_init(int *argc, char **argv[]);
|
||||
const char* pw_get_library_version();
|
||||
|
||||
// properties.h
|
||||
pw_properties * pw_properties_new_string(const char *args);
|
||||
|
||||
// stream.h
|
||||
void pw_stream_add_listener(pw_stream *stream, spa_hook *listener, const pw_stream_events *events, void *data);
|
||||
int pw_stream_connect(pw_stream *stream, enum pw_direction direction, uint32_t target_id, enum pw_stream_flags flags, const spa_pod **params, uint32_t n_params);
|
||||
int pw_stream_disconnect(pw_stream *stream);
|
||||
pw_buffer *pw_stream_dequeue_buffer(pw_stream *stream);
|
||||
void pw_stream_destroy(pw_stream *stream);
|
||||
pw_stream * pw_stream_new(pw_core *core, const char *name, pw_properties *props);
|
||||
int pw_stream_queue_buffer(pw_stream *stream, pw_buffer *buffer);
|
||||
int pw_stream_set_active(pw_stream *stream, bool active);
|
||||
int pw_stream_update_params(pw_stream *stream, const spa_pod **params, uint32_t n_params);
|
||||
uint32_t pw_stream_get_node_id(pw_stream *stream);
|
||||
pw_stream_state pw_stream_get_state(pw_stream *stream, const char **error);
|
||||
const char * pw_stream_state_as_string(enum pw_stream_state state);
|
||||
|
||||
// thread-loop.h
|
||||
void pw_thread_loop_destroy(pw_thread_loop *loop);
|
||||
pw_thread_loop * pw_thread_loop_new(const char *name, const spa_dict *props);
|
||||
int pw_thread_loop_start(pw_thread_loop *loop);
|
||||
void pw_thread_loop_stop(pw_thread_loop *loop);
|
||||
void pw_thread_loop_lock(pw_thread_loop *loop);
|
||||
void pw_thread_loop_unlock(pw_thread_loop *loop);
|
||||
pw_loop * pw_thread_loop_get_loop(pw_thread_loop *loop);
|
||||
void pw_thread_loop_signal(pw_thread_loop *loop, bool wait_for_accept);
|
||||
void pw_thread_loop_wait(pw_thread_loop *loop);
|
||||
|
||||
// context.h
|
||||
void pw_context_destroy(pw_context *context);
|
||||
pw_context *pw_context_new(pw_loop *main_loop, pw_properties *props, size_t user_data_size);
|
||||
pw_core * pw_context_connect(pw_context *context, pw_properties *properties, size_t user_data_size);
|
||||
pw_core * pw_context_connect_fd(pw_context *context, int fd, pw_properties *properties, size_t user_data_size);
|
||||
|
||||
// proxy.h
|
||||
void pw_proxy_destroy(struct pw_proxy *proxy);
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// The extra include header needed in the generated stub file for defining
|
||||
// various PipeWire types.
|
||||
|
||||
extern "C" {
|
||||
|
||||
#include <pipewire/pipewire.h>
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright 2022 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "modules/portal/pipewire_utils.h"
|
||||
|
||||
#include <pipewire/pipewire.h>
|
||||
|
||||
#include "rtc_base/sanitizer.h"
|
||||
|
||||
#if defined(WEBRTC_DLOPEN_PIPEWIRE)
|
||||
#include "modules/portal/pipewire_stubs.h"
|
||||
#endif // defined(WEBRTC_DLOPEN_PIPEWIRE)
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
RTC_NO_SANITIZE("cfi-icall")
|
||||
bool InitializePipeWire() {
|
||||
#if defined(WEBRTC_DLOPEN_PIPEWIRE)
|
||||
static constexpr char kPipeWireLib[] = "libpipewire-0.3.so.0";
|
||||
|
||||
using modules_portal::InitializeStubs;
|
||||
using modules_portal::kModulePipewire;
|
||||
|
||||
modules_portal::StubPathMap paths;
|
||||
|
||||
// Check if the PipeWire library is available.
|
||||
paths[kModulePipewire].push_back(kPipeWireLib);
|
||||
|
||||
static bool result = InitializeStubs(paths);
|
||||
|
||||
return result;
|
||||
#else
|
||||
return true;
|
||||
#endif // defined(WEBRTC_DLOPEN_PIPEWIRE)
|
||||
}
|
||||
|
||||
PipeWireThreadLoopLock::PipeWireThreadLoopLock(pw_thread_loop* loop)
|
||||
: loop_(loop) {
|
||||
pw_thread_loop_lock(loop_);
|
||||
}
|
||||
|
||||
PipeWireThreadLoopLock::~PipeWireThreadLoopLock() {
|
||||
pw_thread_loop_unlock(loop_);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright 2022 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_PORTAL_PIPEWIRE_UTILS_H_
|
||||
#define MODULES_PORTAL_PIPEWIRE_UTILS_H_
|
||||
|
||||
struct pw_thread_loop;
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
constexpr int kInvalidPipeWireFd = -1;
|
||||
|
||||
// Prepare PipeWire so that it is ready to be used. If it needs to be dlopen'd
|
||||
// this will do so. Note that this does not guarantee a PipeWire server is
|
||||
// running nor does it establish a connection to one.
|
||||
bool InitializePipeWire();
|
||||
|
||||
// Locks pw_thread_loop in the current scope
|
||||
class PipeWireThreadLoopLock {
|
||||
public:
|
||||
explicit PipeWireThreadLoopLock(pw_thread_loop* loop);
|
||||
~PipeWireThreadLoopLock();
|
||||
|
||||
private:
|
||||
pw_thread_loop* const loop_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_PORTAL_PIPEWIRE_UTILS_H_
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2022 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_PORTAL_PORTAL_REQUEST_RESPONSE_H_
|
||||
#define MODULES_PORTAL_PORTAL_REQUEST_RESPONSE_H_
|
||||
|
||||
namespace webrtc {
|
||||
namespace xdg_portal {
|
||||
|
||||
// Contains type of responses that can be observed when making a request to
|
||||
// a desktop portal interface.
|
||||
enum class RequestResponse {
|
||||
// Unknown, the initialized status.
|
||||
kUnknown,
|
||||
// Success, the request is carried out.
|
||||
kSuccess,
|
||||
// The user cancelled the interaction.
|
||||
kUserCancelled,
|
||||
// The user interaction was ended in some other way.
|
||||
kError,
|
||||
|
||||
kMaxValue = kError,
|
||||
};
|
||||
|
||||
} // namespace xdg_portal
|
||||
} // namespace webrtc
|
||||
#endif // MODULES_PORTAL_PORTAL_REQUEST_RESPONSE_H_
|
||||
64
TMessagesProj/jni/voip/webrtc/modules/portal/scoped_glib.cc
Normal file
64
TMessagesProj/jni/voip/webrtc/modules/portal/scoped_glib.cc
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* Copyright 2022 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "modules/portal/scoped_glib.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT) Scoped<GError>;
|
||||
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT) Scoped<char>;
|
||||
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT) Scoped<GVariant>;
|
||||
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT) Scoped<GVariantIter>;
|
||||
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT) Scoped<GDBusMessage>;
|
||||
template class RTC_EXPORT_TEMPLATE_DEFINE(RTC_EXPORT) Scoped<GUnixFDList>;
|
||||
|
||||
template <>
|
||||
Scoped<GError>::~Scoped() {
|
||||
if (ptr_) {
|
||||
g_error_free(ptr_);
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
Scoped<char>::~Scoped() {
|
||||
if (ptr_) {
|
||||
g_free(ptr_);
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
Scoped<GVariant>::~Scoped() {
|
||||
if (ptr_) {
|
||||
g_variant_unref(ptr_);
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
Scoped<GVariantIter>::~Scoped() {
|
||||
if (ptr_) {
|
||||
g_variant_iter_free(ptr_);
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
Scoped<GDBusMessage>::~Scoped() {
|
||||
if (ptr_) {
|
||||
g_object_unref(ptr_);
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
Scoped<GUnixFDList>::~Scoped() {
|
||||
if (ptr_) {
|
||||
g_object_unref(ptr_);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
76
TMessagesProj/jni/voip/webrtc/modules/portal/scoped_glib.h
Normal file
76
TMessagesProj/jni/voip/webrtc/modules/portal/scoped_glib.h
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright 2022 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_PORTAL_SCOPED_GLIB_H_
|
||||
#define MODULES_PORTAL_SCOPED_GLIB_H_
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/system/rtc_export_template.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
template <class T>
|
||||
class Scoped {
|
||||
public:
|
||||
Scoped() {}
|
||||
explicit Scoped(T* val) { ptr_ = val; }
|
||||
~Scoped() { RTC_DCHECK_NOTREACHED(); }
|
||||
|
||||
T* operator->() const { return ptr_; }
|
||||
|
||||
explicit operator bool() const { return ptr_ != nullptr; }
|
||||
|
||||
bool operator!() const { return ptr_ == nullptr; }
|
||||
|
||||
T* get() const { return ptr_; }
|
||||
|
||||
T** receive() {
|
||||
RTC_CHECK(!ptr_);
|
||||
return &ptr_;
|
||||
}
|
||||
|
||||
Scoped& operator=(T* val) {
|
||||
RTC_DCHECK(val);
|
||||
ptr_ = val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
T* ptr_ = nullptr;
|
||||
};
|
||||
|
||||
template <>
|
||||
Scoped<GError>::~Scoped();
|
||||
template <>
|
||||
Scoped<char>::~Scoped();
|
||||
template <>
|
||||
Scoped<GVariant>::~Scoped();
|
||||
template <>
|
||||
Scoped<GVariantIter>::~Scoped();
|
||||
template <>
|
||||
Scoped<GDBusMessage>::~Scoped();
|
||||
template <>
|
||||
Scoped<GUnixFDList>::~Scoped();
|
||||
|
||||
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT) Scoped<GError>;
|
||||
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT) Scoped<char>;
|
||||
extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT) Scoped<GVariant>;
|
||||
extern template class RTC_EXPORT_TEMPLATE_DECLARE(
|
||||
RTC_EXPORT) Scoped<GVariantIter>;
|
||||
extern template class RTC_EXPORT_TEMPLATE_DECLARE(
|
||||
RTC_EXPORT) Scoped<GDBusMessage>;
|
||||
extern template class RTC_EXPORT_TEMPLATE_DECLARE(
|
||||
RTC_EXPORT) Scoped<GUnixFDList>;
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_PORTAL_SCOPED_GLIB_H_
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
/*
|
||||
* Copyright 2022 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "modules/portal/xdg_desktop_portal_utils.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "modules/portal/scoped_glib.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace xdg_portal {
|
||||
|
||||
std::string RequestResponseToString(RequestResponse request) {
|
||||
switch (request) {
|
||||
case RequestResponse::kUnknown:
|
||||
return "kUnknown";
|
||||
case RequestResponse::kSuccess:
|
||||
return "kSuccess";
|
||||
case RequestResponse::kUserCancelled:
|
||||
return "kUserCancelled";
|
||||
case RequestResponse::kError:
|
||||
return "kError";
|
||||
default:
|
||||
return "Uknown";
|
||||
}
|
||||
}
|
||||
|
||||
RequestResponse RequestResponseFromPortalResponse(uint32_t portal_response) {
|
||||
// See:
|
||||
// https://docs.flatpak.org/en/latest/portal-api-reference.html#gdbus-signal-org-freedesktop-portal-Request.Response
|
||||
switch (portal_response) {
|
||||
case 0:
|
||||
return RequestResponse::kSuccess;
|
||||
case 1:
|
||||
return RequestResponse::kUserCancelled;
|
||||
case 2:
|
||||
return RequestResponse::kError;
|
||||
default:
|
||||
return RequestResponse::kUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
std::string PrepareSignalHandle(absl::string_view token,
|
||||
GDBusConnection* connection) {
|
||||
Scoped<char> sender(
|
||||
g_strdup(g_dbus_connection_get_unique_name(connection) + 1));
|
||||
for (int i = 0; sender.get()[i]; ++i) {
|
||||
if (sender.get()[i] == '.') {
|
||||
sender.get()[i] = '_';
|
||||
}
|
||||
}
|
||||
const char* handle =
|
||||
g_strconcat(kDesktopRequestObjectPath, "/", sender.get(), "/",
|
||||
std::string(token).c_str(), /*end of varargs*/ nullptr);
|
||||
return handle;
|
||||
}
|
||||
|
||||
uint32_t SetupRequestResponseSignal(absl::string_view object_path,
|
||||
const GDBusSignalCallback callback,
|
||||
gpointer user_data,
|
||||
GDBusConnection* connection) {
|
||||
return g_dbus_connection_signal_subscribe(
|
||||
connection, kDesktopBusName, kRequestInterfaceName, "Response",
|
||||
std::string(object_path).c_str(), /*arg0=*/nullptr,
|
||||
G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE, callback, user_data,
|
||||
/*user_data_free_func=*/nullptr);
|
||||
}
|
||||
|
||||
void RequestSessionProxy(absl::string_view interface_name,
|
||||
const ProxyRequestCallback proxy_request_callback,
|
||||
GCancellable* cancellable,
|
||||
gpointer user_data) {
|
||||
g_dbus_proxy_new_for_bus(
|
||||
G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, /*info=*/nullptr,
|
||||
kDesktopBusName, kDesktopObjectPath, std::string(interface_name).c_str(),
|
||||
cancellable,
|
||||
reinterpret_cast<GAsyncReadyCallback>(proxy_request_callback), user_data);
|
||||
}
|
||||
|
||||
void SetupSessionRequestHandlers(
|
||||
absl::string_view portal_prefix,
|
||||
const SessionRequestCallback session_request_callback,
|
||||
const SessionRequestResponseSignalHandler request_response_signale_handler,
|
||||
GDBusConnection* connection,
|
||||
GDBusProxy* proxy,
|
||||
GCancellable* cancellable,
|
||||
std::string& portal_handle,
|
||||
guint& session_request_signal_id,
|
||||
gpointer user_data) {
|
||||
GVariantBuilder builder;
|
||||
Scoped<char> variant_string;
|
||||
|
||||
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
|
||||
variant_string =
|
||||
g_strdup_printf("%.*s_session%d", static_cast<int>(portal_prefix.size()),
|
||||
portal_prefix.data(), g_random_int_range(0, G_MAXINT));
|
||||
g_variant_builder_add(&builder, "{sv}", "session_handle_token",
|
||||
g_variant_new_string(variant_string.get()));
|
||||
|
||||
variant_string =
|
||||
g_strdup_printf("%.*s_%d", static_cast<int>(portal_prefix.size()),
|
||||
portal_prefix.data(), g_random_int_range(0, G_MAXINT));
|
||||
g_variant_builder_add(&builder, "{sv}", "handle_token",
|
||||
g_variant_new_string(variant_string.get()));
|
||||
|
||||
portal_handle = PrepareSignalHandle(variant_string.get(), connection);
|
||||
session_request_signal_id = SetupRequestResponseSignal(
|
||||
portal_handle.c_str(), request_response_signale_handler, user_data,
|
||||
connection);
|
||||
|
||||
RTC_LOG(LS_INFO) << "Desktop session requested.";
|
||||
g_dbus_proxy_call(
|
||||
proxy, "CreateSession", g_variant_new("(a{sv})", &builder),
|
||||
G_DBUS_CALL_FLAGS_NONE, /*timeout=*/-1, cancellable,
|
||||
reinterpret_cast<GAsyncReadyCallback>(session_request_callback),
|
||||
user_data);
|
||||
}
|
||||
|
||||
void StartSessionRequest(
|
||||
absl::string_view prefix,
|
||||
absl::string_view session_handle,
|
||||
const StartRequestResponseSignalHandler signal_handler,
|
||||
const SessionStartRequestedHandler session_started_handler,
|
||||
GDBusProxy* proxy,
|
||||
GDBusConnection* connection,
|
||||
GCancellable* cancellable,
|
||||
guint& start_request_signal_id,
|
||||
std::string& start_handle,
|
||||
gpointer user_data) {
|
||||
GVariantBuilder builder;
|
||||
Scoped<char> variant_string;
|
||||
|
||||
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
|
||||
variant_string =
|
||||
g_strdup_printf("%.*s%d", static_cast<int>(prefix.size()), prefix.data(),
|
||||
g_random_int_range(0, G_MAXINT));
|
||||
g_variant_builder_add(&builder, "{sv}", "handle_token",
|
||||
g_variant_new_string(variant_string.get()));
|
||||
|
||||
start_handle = PrepareSignalHandle(variant_string.get(), connection);
|
||||
start_request_signal_id = SetupRequestResponseSignal(
|
||||
start_handle.c_str(), signal_handler, user_data, connection);
|
||||
|
||||
// "Identifier for the application window", this is Wayland, so not "x11:...".
|
||||
const char parent_window[] = "";
|
||||
|
||||
RTC_LOG(LS_INFO) << "Starting the portal session.";
|
||||
g_dbus_proxy_call(
|
||||
proxy, "Start",
|
||||
g_variant_new("(osa{sv})", std::string(session_handle).c_str(),
|
||||
parent_window, &builder),
|
||||
G_DBUS_CALL_FLAGS_NONE, /*timeout=*/-1, cancellable,
|
||||
reinterpret_cast<GAsyncReadyCallback>(session_started_handler),
|
||||
user_data);
|
||||
}
|
||||
|
||||
void TearDownSession(absl::string_view session_handle,
|
||||
GDBusProxy* proxy,
|
||||
GCancellable* cancellable,
|
||||
GDBusConnection* connection) {
|
||||
if (!session_handle.empty()) {
|
||||
Scoped<GDBusMessage> message(g_dbus_message_new_method_call(
|
||||
kDesktopBusName, std::string(session_handle).c_str(),
|
||||
kSessionInterfaceName, "Close"));
|
||||
if (message.get()) {
|
||||
Scoped<GError> error;
|
||||
g_dbus_connection_send_message(connection, message.get(),
|
||||
G_DBUS_SEND_MESSAGE_FLAGS_NONE,
|
||||
/*out_serial=*/nullptr, error.receive());
|
||||
if (error.get()) {
|
||||
RTC_LOG(LS_ERROR) << "Failed to close the session: " << error->message;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cancellable) {
|
||||
g_cancellable_cancel(cancellable);
|
||||
g_object_unref(cancellable);
|
||||
}
|
||||
|
||||
if (proxy) {
|
||||
g_object_unref(proxy);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace xdg_portal
|
||||
} // namespace webrtc
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright 2022 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_PORTAL_XDG_DESKTOP_PORTAL_UTILS_H_
|
||||
#define MODULES_PORTAL_XDG_DESKTOP_PORTAL_UTILS_H_
|
||||
|
||||
#include <gio/gio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "modules/portal/portal_request_response.h"
|
||||
#include "modules/portal/scoped_glib.h"
|
||||
#include "modules/portal/xdg_session_details.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
namespace webrtc {
|
||||
namespace xdg_portal {
|
||||
|
||||
constexpr char kDesktopBusName[] = "org.freedesktop.portal.Desktop";
|
||||
constexpr char kDesktopObjectPath[] = "/org/freedesktop/portal/desktop";
|
||||
constexpr char kDesktopRequestObjectPath[] =
|
||||
"/org/freedesktop/portal/desktop/request";
|
||||
constexpr char kSessionInterfaceName[] = "org.freedesktop.portal.Session";
|
||||
constexpr char kRequestInterfaceName[] = "org.freedesktop.portal.Request";
|
||||
constexpr char kScreenCastInterfaceName[] = "org.freedesktop.portal.ScreenCast";
|
||||
|
||||
using ProxyRequestCallback = void (*)(GObject*, GAsyncResult*, gpointer);
|
||||
using SessionRequestCallback = void (*)(GDBusProxy*, GAsyncResult*, gpointer);
|
||||
using SessionRequestResponseSignalHandler = void (*)(GDBusConnection*,
|
||||
const char*,
|
||||
const char*,
|
||||
const char*,
|
||||
const char*,
|
||||
GVariant*,
|
||||
gpointer);
|
||||
using StartRequestResponseSignalHandler = void (*)(GDBusConnection*,
|
||||
const char*,
|
||||
const char*,
|
||||
const char*,
|
||||
const char*,
|
||||
GVariant*,
|
||||
gpointer);
|
||||
using SessionStartRequestedHandler = void (*)(GDBusProxy*,
|
||||
GAsyncResult*,
|
||||
gpointer);
|
||||
|
||||
RTC_EXPORT std::string RequestResponseToString(RequestResponse request);
|
||||
|
||||
RequestResponse RequestResponseFromPortalResponse(uint32_t portal_response);
|
||||
|
||||
// Returns a string path for signal handle based on the provided connection and
|
||||
// token.
|
||||
RTC_EXPORT std::string PrepareSignalHandle(absl::string_view token,
|
||||
GDBusConnection* connection);
|
||||
|
||||
// Sets up the callback to execute when a response signal is received for the
|
||||
// given object.
|
||||
RTC_EXPORT uint32_t
|
||||
SetupRequestResponseSignal(absl::string_view object_path,
|
||||
const GDBusSignalCallback callback,
|
||||
gpointer user_data,
|
||||
GDBusConnection* connection);
|
||||
|
||||
RTC_EXPORT void RequestSessionProxy(
|
||||
absl::string_view interface_name,
|
||||
const ProxyRequestCallback proxy_request_callback,
|
||||
GCancellable* cancellable,
|
||||
gpointer user_data);
|
||||
|
||||
RTC_EXPORT void SetupSessionRequestHandlers(
|
||||
absl::string_view portal_prefix,
|
||||
const SessionRequestCallback session_request_callback,
|
||||
const SessionRequestResponseSignalHandler request_response_signale_handler,
|
||||
GDBusConnection* connection,
|
||||
GDBusProxy* proxy,
|
||||
GCancellable* cancellable,
|
||||
std::string& portal_handle,
|
||||
guint& session_request_signal_id,
|
||||
gpointer user_data);
|
||||
|
||||
RTC_EXPORT void StartSessionRequest(
|
||||
absl::string_view prefix,
|
||||
absl::string_view session_handle,
|
||||
const StartRequestResponseSignalHandler signal_handler,
|
||||
const SessionStartRequestedHandler session_started_handler,
|
||||
GDBusProxy* proxy,
|
||||
GDBusConnection* connection,
|
||||
GCancellable* cancellable,
|
||||
guint& start_request_signal_id,
|
||||
std::string& start_handle,
|
||||
gpointer user_data);
|
||||
|
||||
// Tears down the portal session and cleans up related objects.
|
||||
RTC_EXPORT void TearDownSession(absl::string_view session_handle,
|
||||
GDBusProxy* proxy,
|
||||
GCancellable* cancellable,
|
||||
GDBusConnection* connection);
|
||||
|
||||
} // namespace xdg_portal
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_PORTAL_XDG_DESKTOP_PORTAL_UTILS_H_
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright 2022 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef MODULES_PORTAL_XDG_SESSION_DETAILS_H_
|
||||
#define MODULES_PORTAL_XDG_SESSION_DETAILS_H_
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace webrtc {
|
||||
namespace xdg_portal {
|
||||
|
||||
// Details of the session associated with XDG desktop portal session. Portal API
|
||||
// calls can be invoked by utilizing the information here.
|
||||
struct SessionDetails {
|
||||
GDBusProxy* proxy = nullptr;
|
||||
GCancellable* cancellable = nullptr;
|
||||
std::string session_handle;
|
||||
uint32_t pipewire_stream_node_id = 0;
|
||||
};
|
||||
|
||||
} // namespace xdg_portal
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // MODULES_PORTAL_XDG_SESSION_DETAILS_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue