mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Adopt absl::string_view in modules/desktop_capture/
Bug: webrtc:13579 Change-Id: I9fbc3d6df2dedb7eac908e1af38300d2b42142c8 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/272000 Commit-Queue: Ali Tofigh <alito@webrtc.org> Reviewed-by: Alexander Cooper <alcooper@chromium.org> Cr-Commit-Position: refs/heads/main@{#37817}
This commit is contained in:
parent
de7ae5755b
commit
dc0911bd37
8 changed files with 62 additions and 44 deletions
|
@ -209,6 +209,7 @@ if (rtc_include_tests) {
|
||||||
"../../rtc_base:logging",
|
"../../rtc_base:logging",
|
||||||
"../../system_wrappers",
|
"../../system_wrappers",
|
||||||
]
|
]
|
||||||
|
absl_deps = [ "//third_party/abseil-cpp/absl/strings" ]
|
||||||
|
|
||||||
if (is_posix || is_fuchsia) {
|
if (is_posix || is_fuchsia) {
|
||||||
sources += [
|
sources += [
|
||||||
|
|
|
@ -9,6 +9,9 @@
|
||||||
*/
|
*/
|
||||||
#include "modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.h"
|
#include "modules/desktop_capture/linux/wayland/xdg_desktop_portal_utils.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "modules/desktop_capture/linux/wayland/scoped_glib.h"
|
#include "modules/desktop_capture/linux/wayland/scoped_glib.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
|
|
||||||
|
@ -30,7 +33,7 @@ std::string RequestResponseToString(RequestResponse request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string PrepareSignalHandle(const char* token,
|
std::string PrepareSignalHandle(absl::string_view token,
|
||||||
GDBusConnection* connection) {
|
GDBusConnection* connection) {
|
||||||
Scoped<char> sender(
|
Scoped<char> sender(
|
||||||
g_strdup(g_dbus_connection_get_unique_name(connection) + 1));
|
g_strdup(g_dbus_connection_get_unique_name(connection) + 1));
|
||||||
|
@ -39,33 +42,36 @@ std::string PrepareSignalHandle(const char* token,
|
||||||
sender.get()[i] = '_';
|
sender.get()[i] = '_';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const char* handle = g_strconcat(kDesktopRequestObjectPath, "/", sender.get(),
|
const char* handle =
|
||||||
"/", token, /*end of varargs*/ nullptr);
|
g_strconcat(kDesktopRequestObjectPath, "/", sender.get(), "/",
|
||||||
|
std::string(token).c_str(), /*end of varargs*/ nullptr);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SetupRequestResponseSignal(const char* object_path,
|
uint32_t SetupRequestResponseSignal(absl::string_view object_path,
|
||||||
const GDBusSignalCallback callback,
|
const GDBusSignalCallback callback,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
GDBusConnection* connection) {
|
GDBusConnection* connection) {
|
||||||
return g_dbus_connection_signal_subscribe(
|
return g_dbus_connection_signal_subscribe(
|
||||||
connection, kDesktopBusName, kRequestInterfaceName, "Response",
|
connection, kDesktopBusName, kRequestInterfaceName, "Response",
|
||||||
object_path, /*arg0=*/nullptr, G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,
|
std::string(object_path).c_str(), /*arg0=*/nullptr,
|
||||||
callback, user_data, /*user_data_free_func=*/nullptr);
|
G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE, callback, user_data,
|
||||||
|
/*user_data_free_func=*/nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestSessionProxy(const char* interface_name,
|
void RequestSessionProxy(absl::string_view interface_name,
|
||||||
const ProxyRequestCallback proxy_request_callback,
|
const ProxyRequestCallback proxy_request_callback,
|
||||||
GCancellable* cancellable,
|
GCancellable* cancellable,
|
||||||
gpointer user_data) {
|
gpointer user_data) {
|
||||||
g_dbus_proxy_new_for_bus(
|
g_dbus_proxy_new_for_bus(
|
||||||
G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, /*info=*/nullptr,
|
G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, /*info=*/nullptr,
|
||||||
kDesktopBusName, kDesktopObjectPath, interface_name, cancellable,
|
kDesktopBusName, kDesktopObjectPath, std::string(interface_name).c_str(),
|
||||||
|
cancellable,
|
||||||
reinterpret_cast<GAsyncReadyCallback>(proxy_request_callback), user_data);
|
reinterpret_cast<GAsyncReadyCallback>(proxy_request_callback), user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupSessionRequestHandlers(
|
void SetupSessionRequestHandlers(
|
||||||
const std::string& portal_prefix,
|
absl::string_view portal_prefix,
|
||||||
const SessionRequestCallback session_request_callback,
|
const SessionRequestCallback session_request_callback,
|
||||||
const SessionRequestResponseSignalHandler request_response_signale_handler,
|
const SessionRequestResponseSignalHandler request_response_signale_handler,
|
||||||
GDBusConnection* connection,
|
GDBusConnection* connection,
|
||||||
|
@ -78,13 +84,15 @@ void SetupSessionRequestHandlers(
|
||||||
Scoped<char> variant_string;
|
Scoped<char> variant_string;
|
||||||
|
|
||||||
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
|
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
|
||||||
variant_string = g_strdup_printf("%s_session%d", portal_prefix.c_str(),
|
variant_string =
|
||||||
g_random_int_range(0, G_MAXINT));
|
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_builder_add(&builder, "{sv}", "session_handle_token",
|
||||||
g_variant_new_string(variant_string.get()));
|
g_variant_new_string(variant_string.get()));
|
||||||
|
|
||||||
variant_string = g_strdup_printf("%s_%d", portal_prefix.c_str(),
|
variant_string =
|
||||||
g_random_int_range(0, G_MAXINT));
|
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_builder_add(&builder, "{sv}", "handle_token",
|
||||||
g_variant_new_string(variant_string.get()));
|
g_variant_new_string(variant_string.get()));
|
||||||
|
|
||||||
|
@ -102,8 +110,8 @@ void SetupSessionRequestHandlers(
|
||||||
}
|
}
|
||||||
|
|
||||||
void StartSessionRequest(
|
void StartSessionRequest(
|
||||||
const std::string& prefix,
|
absl::string_view prefix,
|
||||||
const std::string session_handle,
|
absl::string_view session_handle,
|
||||||
const StartRequestResponseSignalHandler signal_handler,
|
const StartRequestResponseSignalHandler signal_handler,
|
||||||
const SessionStartRequestedHandler session_started_handler,
|
const SessionStartRequestedHandler session_started_handler,
|
||||||
GDBusProxy* proxy,
|
GDBusProxy* proxy,
|
||||||
|
@ -117,7 +125,8 @@ void StartSessionRequest(
|
||||||
|
|
||||||
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
|
g_variant_builder_init(&builder, G_VARIANT_TYPE_VARDICT);
|
||||||
variant_string =
|
variant_string =
|
||||||
g_strdup_printf("%s%d", prefix.c_str(), g_random_int_range(0, G_MAXINT));
|
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_builder_add(&builder, "{sv}", "handle_token",
|
||||||
g_variant_new_string(variant_string.get()));
|
g_variant_new_string(variant_string.get()));
|
||||||
|
|
||||||
|
@ -131,21 +140,21 @@ void StartSessionRequest(
|
||||||
RTC_LOG(LS_INFO) << "Starting the portal session.";
|
RTC_LOG(LS_INFO) << "Starting the portal session.";
|
||||||
g_dbus_proxy_call(
|
g_dbus_proxy_call(
|
||||||
proxy, "Start",
|
proxy, "Start",
|
||||||
g_variant_new("(osa{sv})", session_handle.c_str(), parent_window,
|
g_variant_new("(osa{sv})", std::string(session_handle).c_str(),
|
||||||
&builder),
|
parent_window, &builder),
|
||||||
G_DBUS_CALL_FLAGS_NONE, /*timeout=*/-1, cancellable,
|
G_DBUS_CALL_FLAGS_NONE, /*timeout=*/-1, cancellable,
|
||||||
reinterpret_cast<GAsyncReadyCallback>(session_started_handler),
|
reinterpret_cast<GAsyncReadyCallback>(session_started_handler),
|
||||||
user_data);
|
user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TearDownSession(std::string session_handle,
|
void TearDownSession(absl::string_view session_handle,
|
||||||
GDBusProxy* proxy,
|
GDBusProxy* proxy,
|
||||||
GCancellable* cancellable,
|
GCancellable* cancellable,
|
||||||
GDBusConnection* connection) {
|
GDBusConnection* connection) {
|
||||||
if (!session_handle.empty()) {
|
if (!session_handle.empty()) {
|
||||||
Scoped<GDBusMessage> message(
|
Scoped<GDBusMessage> message(g_dbus_message_new_method_call(
|
||||||
g_dbus_message_new_method_call(kDesktopBusName, session_handle.c_str(),
|
kDesktopBusName, std::string(session_handle).c_str(),
|
||||||
kSessionInterfaceName, "Close"));
|
kSessionInterfaceName, "Close"));
|
||||||
if (message.get()) {
|
if (message.get()) {
|
||||||
Scoped<GError> error;
|
Scoped<GError> error;
|
||||||
g_dbus_connection_send_message(connection, message.get(),
|
g_dbus_connection_send_message(connection, message.get(),
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "modules/desktop_capture/linux/wayland/portal_request_response.h"
|
#include "modules/desktop_capture/linux/wayland/portal_request_response.h"
|
||||||
#include "modules/desktop_capture/linux/wayland/scoped_glib.h"
|
#include "modules/desktop_capture/linux/wayland/scoped_glib.h"
|
||||||
#include "modules/desktop_capture/linux/wayland/xdg_session_details.h"
|
#include "modules/desktop_capture/linux/wayland/xdg_session_details.h"
|
||||||
|
@ -43,7 +44,6 @@ using SessionRequestResponseSignalHandler = void (*)(GDBusConnection*,
|
||||||
const char*,
|
const char*,
|
||||||
GVariant*,
|
GVariant*,
|
||||||
gpointer);
|
gpointer);
|
||||||
using SessionRequestResponseSignalCallback = void (*)(std::string);
|
|
||||||
using StartRequestResponseSignalHandler = void (*)(GDBusConnection*,
|
using StartRequestResponseSignalHandler = void (*)(GDBusConnection*,
|
||||||
const char*,
|
const char*,
|
||||||
const char*,
|
const char*,
|
||||||
|
@ -59,22 +59,23 @@ std::string RequestResponseToString(RequestResponse request);
|
||||||
|
|
||||||
// Returns a string path for signal handle based on the provided connection and
|
// Returns a string path for signal handle based on the provided connection and
|
||||||
// token.
|
// token.
|
||||||
std::string PrepareSignalHandle(const char* token, GDBusConnection* connection);
|
std::string PrepareSignalHandle(absl::string_view token,
|
||||||
|
GDBusConnection* connection);
|
||||||
|
|
||||||
// Sets up the callback to execute when a response signal is received for the
|
// Sets up the callback to execute when a response signal is received for the
|
||||||
// given object.
|
// given object.
|
||||||
uint32_t SetupRequestResponseSignal(const char* object_path,
|
uint32_t SetupRequestResponseSignal(absl::string_view object_path,
|
||||||
const GDBusSignalCallback callback,
|
const GDBusSignalCallback callback,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
GDBusConnection* connection);
|
GDBusConnection* connection);
|
||||||
|
|
||||||
void RequestSessionProxy(const char* interface_name,
|
void RequestSessionProxy(absl::string_view interface_name,
|
||||||
const ProxyRequestCallback proxy_request_callback,
|
const ProxyRequestCallback proxy_request_callback,
|
||||||
GCancellable* cancellable,
|
GCancellable* cancellable,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
void SetupSessionRequestHandlers(
|
void SetupSessionRequestHandlers(
|
||||||
const std::string& portal_prefix,
|
absl::string_view portal_prefix,
|
||||||
const SessionRequestCallback session_request_callback,
|
const SessionRequestCallback session_request_callback,
|
||||||
const SessionRequestResponseSignalHandler request_response_signale_handler,
|
const SessionRequestResponseSignalHandler request_response_signale_handler,
|
||||||
GDBusConnection* connection,
|
GDBusConnection* connection,
|
||||||
|
@ -85,8 +86,8 @@ void SetupSessionRequestHandlers(
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
void StartSessionRequest(
|
void StartSessionRequest(
|
||||||
const std::string& prefix,
|
absl::string_view prefix,
|
||||||
const std::string session_handle,
|
absl::string_view session_handle,
|
||||||
const StartRequestResponseSignalHandler signal_handler,
|
const StartRequestResponseSignalHandler signal_handler,
|
||||||
const SessionStartRequestedHandler session_started_handler,
|
const SessionStartRequestedHandler session_started_handler,
|
||||||
GDBusProxy* proxy,
|
GDBusProxy* proxy,
|
||||||
|
@ -97,7 +98,7 @@ void StartSessionRequest(
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
// Tears down the portal session and cleans up related objects.
|
// Tears down the portal session and cleans up related objects.
|
||||||
void TearDownSession(std::string session_handle,
|
void TearDownSession(absl::string_view session_handle,
|
||||||
GDBusProxy* proxy,
|
GDBusProxy* proxy,
|
||||||
GCancellable* cancellable,
|
GCancellable* cancellable,
|
||||||
GDBusConnection* connection);
|
GDBusConnection* connection);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
|
|
||||||
|
@ -31,9 +32,9 @@ SharedXDisplay::~SharedXDisplay() {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
rtc::scoped_refptr<SharedXDisplay> SharedXDisplay::Create(
|
rtc::scoped_refptr<SharedXDisplay> SharedXDisplay::Create(
|
||||||
const std::string& display_name) {
|
absl::string_view display_name) {
|
||||||
Display* display =
|
Display* display = XOpenDisplay(
|
||||||
XOpenDisplay(display_name.empty() ? NULL : display_name.c_str());
|
display_name.empty() ? NULL : std::string(display_name).c_str());
|
||||||
if (!display) {
|
if (!display) {
|
||||||
RTC_LOG(LS_ERROR) << "Unable to open display";
|
RTC_LOG(LS_ERROR) << "Unable to open display";
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
#define MODULES_DESKTOP_CAPTURE_LINUX_X11_SHARED_X_DISPLAY_H_
|
#define MODULES_DESKTOP_CAPTURE_LINUX_X11_SHARED_X_DISPLAY_H_
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "api/ref_counted_base.h"
|
#include "api/ref_counted_base.h"
|
||||||
#include "api/scoped_refptr.h"
|
#include "api/scoped_refptr.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
|
@ -42,7 +42,7 @@ class RTC_EXPORT SharedXDisplay
|
||||||
// connection failed. Equivalent to CreateDefault() when `display_name` is
|
// connection failed. Equivalent to CreateDefault() when `display_name` is
|
||||||
// empty.
|
// empty.
|
||||||
static rtc::scoped_refptr<SharedXDisplay> Create(
|
static rtc::scoped_refptr<SharedXDisplay> Create(
|
||||||
const std::string& display_name);
|
absl::string_view display_name);
|
||||||
|
|
||||||
// Creates X11 Display connection for the default display (e.g. specified in
|
// Creates X11 Display connection for the default display (e.g. specified in
|
||||||
// DISPLAY). NULL is returned if X11 connection failed.
|
// DISPLAY). NULL is returned if X11 connection failed.
|
||||||
|
|
|
@ -9,11 +9,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "modules/desktop_capture/mac/full_screen_mac_application_handler.h"
|
#include "modules/desktop_capture/mac/full_screen_mac_application_handler.h"
|
||||||
|
|
||||||
#include <libproc.h>
|
#include <libproc.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "absl/strings/match.h"
|
#include "absl/strings/match.h"
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "api/function_view.h"
|
#include "api/function_view.h"
|
||||||
#include "modules/desktop_capture/mac/window_list_utils.h"
|
#include "modules/desktop_capture/mac/window_list_utils.h"
|
||||||
|
|
||||||
|
@ -52,7 +56,7 @@ static constexpr const char* kPowerPointSlideShowTitles[] = {
|
||||||
class FullScreenMacApplicationHandler : public FullScreenApplicationHandler {
|
class FullScreenMacApplicationHandler : public FullScreenApplicationHandler {
|
||||||
public:
|
public:
|
||||||
using TitlePredicate =
|
using TitlePredicate =
|
||||||
std::function<bool(const std::string&, const std::string&)>;
|
std::function<bool(absl::string_view, absl::string_view)>;
|
||||||
|
|
||||||
FullScreenMacApplicationHandler(DesktopCapturer::SourceId sourceId,
|
FullScreenMacApplicationHandler(DesktopCapturer::SourceId sourceId,
|
||||||
TitlePredicate title_predicate,
|
TitlePredicate title_predicate,
|
||||||
|
@ -134,14 +138,14 @@ class FullScreenMacApplicationHandler : public FullScreenApplicationHandler {
|
||||||
mutable DesktopCapturer::SourceList cache_sources_;
|
mutable DesktopCapturer::SourceList cache_sources_;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool equal_title_predicate(const std::string& original_title,
|
bool equal_title_predicate(absl::string_view original_title,
|
||||||
const std::string& title) {
|
absl::string_view title) {
|
||||||
return original_title == title;
|
return original_title == title;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool slide_show_title_predicate(const std::string& original_title,
|
bool slide_show_title_predicate(absl::string_view original_title,
|
||||||
const std::string& title) {
|
absl::string_view title) {
|
||||||
if (title.find(original_title) == std::string::npos)
|
if (title.find(original_title) == absl::string_view::npos)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (const char* pp_slide_title : kPowerPointSlideShowTitles) {
|
for (const char* pp_slide_title : kPowerPointSlideShowTitles) {
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
#include "rtc_base/logging.h"
|
#include "rtc_base/logging.h"
|
||||||
|
|
||||||
|
@ -51,8 +52,8 @@ ScreenDrawerLockPosix::~ScreenDrawerLockPosix() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void ScreenDrawerLockPosix::Unlink(const char* name) {
|
void ScreenDrawerLockPosix::Unlink(absl::string_view name) {
|
||||||
sem_unlink(name);
|
sem_unlink(std::string(name).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
|
|
||||||
|
#include "absl/strings/string_view.h"
|
||||||
#include "modules/desktop_capture/screen_drawer.h"
|
#include "modules/desktop_capture/screen_drawer.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
@ -27,7 +28,7 @@ class ScreenDrawerLockPosix final : public ScreenDrawerLock {
|
||||||
// Unlinks the named semaphore actively. This will remove the sem_t object in
|
// Unlinks the named semaphore actively. This will remove the sem_t object in
|
||||||
// the system and allow others to create a different sem_t object with the
|
// the system and allow others to create a different sem_t object with the
|
||||||
// same/ name.
|
// same/ name.
|
||||||
static void Unlink(const char* name);
|
static void Unlink(absl::string_view name);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
sem_t* semaphore_;
|
sem_t* semaphore_;
|
||||||
|
|
Loading…
Reference in a new issue