From 28284a969406494d78f5e16ad76cc7c4972abcf7 Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Thu, 3 Oct 2024 17:52:31 +0200 Subject: [PATCH] wivrn namespace: move all server classes --- server/accept_connection.cpp | 2 +- server/accept_connection.h | 3 +++ server/active_runtime.cpp | 4 ++++ server/active_runtime.h | 4 ++++ server/audio/audio_pipewire.cpp | 7 ++++++- server/audio/audio_pipewire.h | 4 ++++ server/audio/audio_pulse.cpp | 4 ++++ server/audio/audio_pulse.h | 4 ++++ server/audio/audio_setup.cpp | 2 +- server/audio/audio_setup.h | 2 +- server/avahi_publisher.cpp | 4 ++++ server/avahi_publisher.h | 4 ++++ server/driver/clock_offset.cpp | 4 ++++ server/driver/clock_offset.h | 4 ++++ server/driver/configuration.cpp | 2 +- server/driver/configuration.h | 4 ++++ server/driver/hand_joints_list.cpp | 14 ++++++------- server/driver/hand_joints_list.h | 4 ++++ server/driver/history.h | 4 ++++ server/driver/pose_list.cpp | 5 ++++- server/driver/pose_list.h | 4 ++++ server/driver/view_list.cpp | 4 ++++ server/driver/view_list.h | 4 ++++ server/driver/wivrn_comp_target.cpp | 4 +++- server/driver/wivrn_connection.cpp | 8 ++++---- server/driver/wivrn_connection.h | 4 +++- server/driver/wivrn_controller.cpp | 8 +++----- server/driver/wivrn_controller.h | 2 +- server/driver/wivrn_eye_tracker.cpp | 4 ++++ server/driver/wivrn_eye_tracker.h | 4 ++++ server/driver/wivrn_fb_face2_tracker.cpp | 4 ++++ server/driver/wivrn_fb_face2_tracker.h | 4 ++++ server/driver/wivrn_foveation.cpp | 4 ++++ server/driver/wivrn_foveation.h | 4 ++++ server/driver/wivrn_hmd.cpp | 20 +++---------------- server/driver/wivrn_hmd.h | 5 +++-- server/driver/wivrn_pacer.cpp | 8 ++++++-- server/driver/wivrn_pacer.h | 4 ++++ server/driver/wivrn_session.cpp | 4 ++++ server/driver/wivrn_session.h | 17 ++++++++-------- server/encoder/encoder_settings.cpp | 7 ++++--- server/encoder/encoder_settings.h | 7 +++---- .../encoder/ffmpeg/video_encoder_ffmpeg.cpp | 4 ++++ server/encoder/ffmpeg/video_encoder_ffmpeg.h | 4 ++++ server/encoder/ffmpeg/video_encoder_va.cpp | 4 ++++ server/encoder/ffmpeg/video_encoder_va.h | 2 +- server/encoder/video_encoder.h | 3 +-- server/hostname.cpp | 2 +- server/hostname.h | 3 +++ server/start_application.cpp | 8 ++++---- server/start_application.h | 5 +++++ server/target_instance_wivrn.cpp | 2 +- server/utils/scoped_lock.h | 4 ++++ server/utils/wivrn_vk_bundle.cpp | 4 ++-- server/utils/wivrn_vk_bundle.h | 4 ++++ 55 files changed, 195 insertions(+), 73 deletions(-) diff --git a/server/accept_connection.cpp b/server/accept_connection.cpp index 5c2e686e..29d3e96c 100644 --- a/server/accept_connection.cpp +++ b/server/accept_connection.cpp @@ -30,7 +30,7 @@ static void handle_event_from_main_loop(to_monado::disconnect) // Ignore disconnect request when no headset is connected } -std::unique_ptr accept_connection(int watch_fd, std::function quit) +std::unique_ptr wivrn::accept_connection(int watch_fd, std::function quit) { wivrn_ipc_socket_monado->send(from_monado::headsdet_disconnected{}); diff --git a/server/accept_connection.h b/server/accept_connection.h index 7b0c8ee5..ae372cf5 100644 --- a/server/accept_connection.h +++ b/server/accept_connection.h @@ -23,4 +23,7 @@ #include #include +namespace wivrn +{ std::unique_ptr accept_connection(int watch_fd, std::function quit = std::function()); +} diff --git a/server/active_runtime.cpp b/server/active_runtime.cpp index 12ef973c..c5b3bde7 100644 --- a/server/active_runtime.cpp +++ b/server/active_runtime.cpp @@ -24,6 +24,9 @@ #include #include +namespace wivrn +{ + std::filesystem::path active_runtime::manifest_path() { const std::filesystem::path install_location = "share/openxr/1/openxr_wivrn.json"; @@ -84,3 +87,4 @@ active_runtime::~active_runtime() std::cerr << "Cannot unset active OpenXR runtime: " << e.what() << std::endl; } } +} // namespace wivrn diff --git a/server/active_runtime.h b/server/active_runtime.h index 3d217c75..813557f1 100644 --- a/server/active_runtime.h +++ b/server/active_runtime.h @@ -21,6 +21,9 @@ #include #include +namespace wivrn +{ + class active_runtime { bool to_be_deleted = false; @@ -35,3 +38,4 @@ public: static std::filesystem::path manifest_path(); }; +} // namespace wivrn diff --git a/server/audio/audio_pipewire.cpp b/server/audio/audio_pipewire.cpp index 152b0c18..9303fdd2 100644 --- a/server/audio/audio_pipewire.cpp +++ b/server/audio/audio_pipewire.cpp @@ -26,8 +26,11 @@ #include #include -using namespace wivrn; +namespace wivrn +{ +namespace +{ struct deleter { void operator()(pw_main_loop * loop) @@ -189,6 +192,7 @@ struct pipewire_device : public audio_device [loop = pw_loop.get()]() { pw_main_loop_run(loop); }); } }; +} // namespace void pipewire_device::mic_process(void * self_v) { @@ -315,3 +319,4 @@ std::shared_ptr create_pipewire_handle( return nullptr; } } +} // namespace wivrn diff --git a/server/audio/audio_pipewire.h b/server/audio/audio_pipewire.h index 2e0d566f..2039a50d 100644 --- a/server/audio/audio_pipewire.h +++ b/server/audio/audio_pipewire.h @@ -20,6 +20,9 @@ #include "audio_setup.h" +namespace wivrn +{ + std::shared_ptr create_pipewire_handle( const std::string & source_name, const std::string & source_description, @@ -27,3 +30,4 @@ std::shared_ptr create_pipewire_handle( const std::string & sink_description, const wivrn::from_headset::headset_info_packet & info, wivrn::wivrn_session & session); +} diff --git a/server/audio/audio_pulse.cpp b/server/audio/audio_pulse.cpp index ef484255..352fe7ea 100644 --- a/server/audio/audio_pulse.cpp +++ b/server/audio/audio_pulse.cpp @@ -25,6 +25,9 @@ static const char * sink_name = "WiVRn"; static const char * source_pipe = "wivrn-source"; static const char * sink_pipe = "wivrn-sink"; +namespace wivrn +{ + struct module_entry { uint32_t module; @@ -466,3 +469,4 @@ void unload_module(uintptr_t id) pa_connection cnx("WiVRn"); unload_module(cnx, id); } +} // namespace wivrn diff --git a/server/audio/audio_pulse.h b/server/audio/audio_pulse.h index 41e24059..dd633d22 100644 --- a/server/audio/audio_pulse.h +++ b/server/audio/audio_pulse.h @@ -20,6 +20,9 @@ #include "audio_setup.h" +namespace wivrn +{ + std::shared_ptr create_pulse_handle( const std::string & source_name, const std::string & source_description, @@ -27,3 +30,4 @@ std::shared_ptr create_pulse_handle( const std::string & sink_description, const wivrn::from_headset::headset_info_packet & info, wivrn::wivrn_session & session); +} diff --git a/server/audio/audio_setup.cpp b/server/audio/audio_setup.cpp index 1d25addd..92f698ff 100644 --- a/server/audio/audio_setup.cpp +++ b/server/audio/audio_setup.cpp @@ -30,7 +30,7 @@ #include "audio_pipewire.h" #endif -std::shared_ptr audio_device::create( +std::shared_ptr wivrn::audio_device::create( const std::string & source_name, const std::string & source_description, const std::string & sink_name, diff --git a/server/audio/audio_setup.h b/server/audio/audio_setup.h index 4bc90cb6..1425fe7b 100644 --- a/server/audio/audio_setup.h +++ b/server/audio/audio_setup.h @@ -27,7 +27,6 @@ namespace wivrn { class wivrn_session; -} struct audio_device { @@ -46,3 +45,4 @@ struct audio_device const wivrn::from_headset::headset_info_packet & info, wivrn::wivrn_session & session); }; +} // namespace wivrn diff --git a/server/avahi_publisher.cpp b/server/avahi_publisher.cpp index 5979af45..df948d61 100644 --- a/server/avahi_publisher.cpp +++ b/server/avahi_publisher.cpp @@ -9,6 +9,9 @@ #include #include +namespace wivrn +{ + const std::error_category & avahi_error_category() { static struct : std::error_category @@ -173,3 +176,4 @@ void avahi_publisher::watch_free(AvahiWatch * watch) { poll_api->watch_free(watch); }*/ +} // namespace wivrn diff --git a/server/avahi_publisher.h b/server/avahi_publisher.h index 1fb5ca1b..05e97ddd 100644 --- a/server/avahi_publisher.h +++ b/server/avahi_publisher.h @@ -7,6 +7,9 @@ #include #include +namespace wivrn +{ + const std::error_category & avahi_error_category(); class avahi_publisher @@ -39,3 +42,4 @@ public: avahi_publisher & operator=(const avahi_publisher &) = delete; ~avahi_publisher(); }; +} // namespace wivrn diff --git a/server/driver/clock_offset.cpp b/server/driver/clock_offset.cpp index 7e1e6cfc..ecc41ca8 100644 --- a/server/driver/clock_offset.cpp +++ b/server/driver/clock_offset.cpp @@ -23,6 +23,9 @@ #include "os/os_time.h" #include "util/u_logging.h" +namespace wivrn +{ + static const size_t num_samples = 100; void clock_offset_estimator::reset() @@ -144,3 +147,4 @@ XrTime clock_offset::to_headset(XrTime timestamp_ns) const { return timestamp_ns + b; } +} // namespace wivrn diff --git a/server/driver/clock_offset.h b/server/driver/clock_offset.h index fa7f78ce..879a2c7c 100644 --- a/server/driver/clock_offset.h +++ b/server/driver/clock_offset.h @@ -26,6 +26,9 @@ #include #include +namespace wivrn +{ + class wivrn_connection; struct clock_offset @@ -68,3 +71,4 @@ public: clock_offset get_offset(); }; +} // namespace wivrn diff --git a/server/driver/configuration.cpp b/server/driver/configuration.cpp index b54d6d02..4abfbb52 100644 --- a/server/driver/configuration.cpp +++ b/server/driver/configuration.cpp @@ -49,7 +49,6 @@ NLOHMANN_JSON_SERIALIZE_ENUM( {av1, "av1"}, {av1, "AV1"}, }) -} void configuration::set_config_file(const std::filesystem::path & path) { @@ -176,3 +175,4 @@ std::string server_cookie() return buffer; } } +} // namespace wivrn diff --git a/server/driver/configuration.h b/server/driver/configuration.h index 9faa9bf2..057ad4c0 100644 --- a/server/driver/configuration.h +++ b/server/driver/configuration.h @@ -27,6 +27,9 @@ #include "wivrn_packets.h" +namespace wivrn +{ + struct configuration { struct encoder @@ -54,3 +57,4 @@ struct configuration }; std::string server_cookie(); +} // namespace wivrn diff --git a/server/driver/hand_joints_list.cpp b/server/driver/hand_joints_list.cpp index bf311427..a79453df 100644 --- a/server/driver/hand_joints_list.cpp +++ b/server/driver/hand_joints_list.cpp @@ -22,26 +22,25 @@ #include "pose_list.h" #include "xrt_cast.h" -using namespace wivrn; - static_assert(XRT_HAND_JOINT_COUNT == XR_HAND_JOINT_COUNT_EXT); -namespace +namespace wivrn { -xrt_hand_joint_value interpolate(const xrt_hand_joint_value & a, const xrt_hand_joint_value & b, float t) + +static xrt_hand_joint_value interpolate(const xrt_hand_joint_value & a, const xrt_hand_joint_value & b, float t) { return { .relation = pose_list::interpolate(a.relation, b.relation, t), - .radius = a.radius * (1 - t) + b.radius * t}; + .radius = a.radius * (1 - t) + b.radius * t, + }; } -} // namespace xrt_hand_joint_set hand_joints_list::interpolate(const xrt_hand_joint_set & a, const xrt_hand_joint_set & b, float t) { xrt_hand_joint_set j = a; for (int i = 0; i < XRT_HAND_JOINT_COUNT; i++) { - j.values.hand_joint_set_default[i] = ::interpolate(a.values.hand_joint_set_default[i], b.values.hand_joint_set_default[i], t); + j.values.hand_joint_set_default[i] = ::wivrn::interpolate(a.values.hand_joint_set_default[i], b.values.hand_joint_set_default[i], t); } return j; } @@ -128,3 +127,4 @@ bool hand_joints_list::update_tracking(const from_headset::hand_tracking & track offset); return true; } +} // namespace wivrn diff --git a/server/driver/hand_joints_list.h b/server/driver/hand_joints_list.h index b5b8d1b7..b740fa1d 100644 --- a/server/driver/hand_joints_list.h +++ b/server/driver/hand_joints_list.h @@ -22,6 +22,9 @@ #include "history.h" #include "xrt/xrt_defines.h" +namespace wivrn +{ + class hand_joints_list : public history { public: @@ -35,3 +38,4 @@ public: bool update_tracking(const wivrn::from_headset::hand_tracking & tracking, const clock_offset & offset); }; +} // namespace wivrn diff --git a/server/driver/history.h b/server/driver/history.h index f45bcc3e..5c184382 100644 --- a/server/driver/history.h +++ b/server/driver/history.h @@ -27,6 +27,9 @@ #include #include +namespace wivrn +{ + template class history { @@ -161,3 +164,4 @@ public: } } }; +} // namespace wivrn diff --git a/server/driver/pose_list.cpp b/server/driver/pose_list.cpp index 66c206fa..1e9435fe 100644 --- a/server/driver/pose_list.cpp +++ b/server/driver/pose_list.cpp @@ -24,9 +24,11 @@ #include "xrt/xrt_defines.h" #include "xrt_cast.h" -using namespace wivrn; using namespace xrt::auxiliary::math; +namespace wivrn +{ + xrt_space_relation pose_list::interpolate(const xrt_space_relation & a, const xrt_space_relation & b, float t) { xrt_space_relation result; @@ -103,3 +105,4 @@ xrt_space_relation pose_list::convert_pose(const from_headset::tracking::pose & return res; } +} // namespace wivrn diff --git a/server/driver/pose_list.h b/server/driver/pose_list.h index 10e962d9..08cdeb84 100644 --- a/server/driver/pose_list.h +++ b/server/driver/pose_list.h @@ -24,6 +24,9 @@ #include "wivrn_packets.h" #include "xrt/xrt_defines.h" +namespace wivrn +{ + class pose_list : public history { public: @@ -39,3 +42,4 @@ public: static xrt_space_relation convert_pose(const wivrn::from_headset::tracking::pose &); }; +} // namespace wivrn diff --git a/server/driver/view_list.cpp b/server/driver/view_list.cpp index 81f88561..bc1d2d56 100644 --- a/server/driver/view_list.cpp +++ b/server/driver/view_list.cpp @@ -21,6 +21,9 @@ #include "pose_list.h" #include "xrt_cast.h" +namespace wivrn +{ + tracked_views view_list::interpolate(const tracked_views & a, const tracked_views & b, float t) { tracked_views result = a; @@ -57,3 +60,4 @@ bool view_list::update_tracking(const from_headset::tracking & tracking, const c } return true; } +} // namespace wivrn diff --git a/server/driver/view_list.h b/server/driver/view_list.h index 82c5ee22..c2eff49f 100644 --- a/server/driver/view_list.h +++ b/server/driver/view_list.h @@ -22,6 +22,9 @@ #include "pose_list.h" #include "wivrn_connection.h" +namespace wivrn +{ + struct tracked_views { XrViewStateFlags flags; @@ -38,3 +41,4 @@ public: bool update_tracking(const from_headset::tracking & tracking, const clock_offset & offset); }; +} // namespace wivrn diff --git a/server/driver/wivrn_comp_target.cpp b/server/driver/wivrn_comp_target.cpp index 4812e199..029d59ec 100644 --- a/server/driver/wivrn_comp_target.cpp +++ b/server/driver/wivrn_comp_target.cpp @@ -29,7 +29,8 @@ #include #include -using namespace wivrn; +namespace wivrn +{ std::vector wivrn_comp_target::wanted_instance_extensions = {}; std::vector wivrn_comp_target::wanted_device_extensions = { @@ -673,3 +674,4 @@ wivrn_comp_target::wivrn_comp_target(std::shared_ptr cnx, desc.fps = fps; this->c = c; } +} // namespace wivrn diff --git a/server/driver/wivrn_connection.cpp b/server/driver/wivrn_connection.cpp index 95b02247..0079843d 100644 --- a/server/driver/wivrn_connection.cpp +++ b/server/driver/wivrn_connection.cpp @@ -31,13 +31,13 @@ static void handle_event_from_main_loop(to_monado::disconnect) // Ignore disconnect request when no headset is connected } -wivrn_connection::wivrn_connection(TCP && tcp) : +wivrn::wivrn_connection::wivrn_connection(TCP && tcp) : control(std::move(tcp)), stream(-1) { init(); } -void wivrn_connection::init() +void wivrn::wivrn_connection::init() { active = false; stream = -1; @@ -144,13 +144,13 @@ void wivrn_connection::init() active = true; } -void wivrn_connection::reset(TCP && tcp) +void wivrn::wivrn_connection::reset(TCP && tcp) { control = std::move(tcp); init(); } -std::optional wivrn_connection::poll_control(int timeout) +std::optional wivrn::wivrn_connection::poll_control(int timeout) { pollfd fds{}; fds.events = POLLIN; diff --git a/server/driver/wivrn_connection.h b/server/driver/wivrn_connection.h index ab7bea8c..ab1857d6 100644 --- a/server/driver/wivrn_connection.h +++ b/server/driver/wivrn_connection.h @@ -25,7 +25,8 @@ #include #include -using namespace wivrn; +namespace wivrn +{ class wivrn_connection { @@ -131,3 +132,4 @@ public: return r; } }; +} // namespace wivrn diff --git a/server/driver/wivrn_controller.cpp b/server/driver/wivrn_controller.cpp index 8b910449..2060bd37 100644 --- a/server/driver/wivrn_controller.cpp +++ b/server/driver/wivrn_controller.cpp @@ -25,11 +25,8 @@ #include "xrt/xrt_defines.h" -/* - * - * Defines & structs. - * - */ +namespace wivrn +{ enum wivrn_controller_input_index { @@ -418,3 +415,4 @@ static void wivrn_controller_set_output(struct xrt_device * xdev, enum xrt_outpu { static_cast(xdev)->set_output(name, value); } +} // namespace wivrn diff --git a/server/driver/wivrn_controller.h b/server/driver/wivrn_controller.h index f99a1f70..c01d50b1 100644 --- a/server/driver/wivrn_controller.h +++ b/server/driver/wivrn_controller.h @@ -32,7 +32,6 @@ namespace wivrn { class wivrn_session; -} class wivrn_controller : public xrt_device { @@ -70,3 +69,4 @@ public: private: void set_inputs(device_id input_id, float value, int64_t last_change_time); }; +} // namespace wivrn diff --git a/server/driver/wivrn_eye_tracker.cpp b/server/driver/wivrn_eye_tracker.cpp index 09285be8..9557c6f5 100644 --- a/server/driver/wivrn_eye_tracker.cpp +++ b/server/driver/wivrn_eye_tracker.cpp @@ -30,6 +30,9 @@ #include #include +namespace wivrn +{ + static void wivrn_eye_tracker_destroy(xrt_device * xdev); static void wivrn_eye_tracker_update_inputs(xrt_device * xdev); @@ -110,3 +113,4 @@ static void wivrn_eye_tracker_get_tracked_pose(xrt_device * xdev, { *out_relation = static_cast(xdev)->get_tracked_pose(name, at_timestamp_ns); } +} // namespace wivrn diff --git a/server/driver/wivrn_eye_tracker.h b/server/driver/wivrn_eye_tracker.h index 482d6dc3..7032e0e1 100644 --- a/server/driver/wivrn_eye_tracker.h +++ b/server/driver/wivrn_eye_tracker.h @@ -32,6 +32,9 @@ #include #include +namespace wivrn +{ + class wivrn_eye_tracker : public xrt_device { std::mutex mutex; @@ -51,3 +54,4 @@ public: void update_tracking(const from_headset::tracking &, const clock_offset &); xrt_space_relation get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns); }; +} // namespace wivrn diff --git a/server/driver/wivrn_fb_face2_tracker.cpp b/server/driver/wivrn_fb_face2_tracker.cpp index cf280a20..c1094fd3 100644 --- a/server/driver/wivrn_fb_face2_tracker.cpp +++ b/server/driver/wivrn_fb_face2_tracker.cpp @@ -32,6 +32,9 @@ #include #include +namespace wivrn +{ + static void wivrn_fb_face2_tracker_destroy(xrt_device * xdev); static void wivrn_fb_face2_tracker_update_inputs(xrt_device * xdev); @@ -135,3 +138,4 @@ static xrt_result_t wivrn_fb_face2_tracker_get_face_tracking(struct xrt_device * { return static_cast(xdev)->get_face_tracking(facial_expression_type, at_timestamp_ns, inout_value); } +} // namespace wivrn diff --git a/server/driver/wivrn_fb_face2_tracker.h b/server/driver/wivrn_fb_face2_tracker.h index 5f94ea0a..85e9392e 100644 --- a/server/driver/wivrn_fb_face2_tracker.h +++ b/server/driver/wivrn_fb_face2_tracker.h @@ -33,6 +33,9 @@ #include #include +namespace wivrn +{ + struct wivrn_fb_face2_data { std::array weights; @@ -99,3 +102,4 @@ public: void update_tracking(const from_headset::tracking &, const clock_offset &); xrt_result_t get_face_tracking(enum xrt_input_name facial_expression_type, int64_t at_timestamp_ns, struct xrt_facial_expression_set * out_value); }; +} // namespace wivrn diff --git a/server/driver/wivrn_foveation.cpp b/server/driver/wivrn_foveation.cpp index 1751534d..38e61dab 100644 --- a/server/driver/wivrn_foveation.cpp +++ b/server/driver/wivrn_foveation.cpp @@ -35,6 +35,9 @@ extern const std::map> shaders; +namespace wivrn +{ + const uint32_t dispatch_group_count = RENDER_DISTORTION_IMAGE_DIMENSIONS / 8; struct FoveationParamsPcs @@ -317,3 +320,4 @@ void wivrn_foveation::set_initial_parameters(std::array foveation_arr, const VkImage * images, const VkImageView * image_views); }; +} // namespace wivrn diff --git a/server/driver/wivrn_hmd.cpp b/server/driver/wivrn_hmd.cpp index e49a1111..4e665f2b 100644 --- a/server/driver/wivrn_hmd.cpp +++ b/server/driver/wivrn_hmd.cpp @@ -35,23 +35,8 @@ #include "configuration.h" -/* - * - * Structs and defines. - * - */ - -/*! - * A wivrn HMD device. - * - * @implements xrt_device - */ - -/* - * - * Functions - * - */ +namespace wivrn +{ static void wivrn_hmd_destroy(xrt_device * xdev); @@ -456,3 +441,4 @@ static xrt_result_t wivrn_hmd_get_battery_status(struct xrt_device * xdev, { return static_cast(xdev)->get_battery_status(xdev, out_present, out_charging, out_charge); } +} // namespace wivrn diff --git a/server/driver/wivrn_hmd.h b/server/driver/wivrn_hmd.h index c0c88cc0..2db23884 100644 --- a/server/driver/wivrn_hmd.h +++ b/server/driver/wivrn_hmd.h @@ -31,11 +31,11 @@ #include struct comp_target; +struct comp_compositor; namespace wivrn { class wivrn_session; -} class wivrn_hmd : public xrt_device { @@ -69,7 +69,7 @@ public: void update_inputs(); xrt_space_relation get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns); - comp_target * create_compositor_target(struct comp_compositor * comp); + comp_target * create_compositor_target(comp_compositor * comp); void get_view_poses(const xrt_vec3 * default_eye_relation, int64_t at_timestamp_ns, uint32_t view_count, @@ -92,3 +92,4 @@ public: return foveation_parameters; } }; +} // namespace wivrn diff --git a/server/driver/wivrn_pacer.cpp b/server/driver/wivrn_pacer.cpp index 71b9f456..b151dbf7 100644 --- a/server/driver/wivrn_pacer.cpp +++ b/server/driver/wivrn_pacer.cpp @@ -22,10 +22,13 @@ #include "os/os_time.h" #include +namespace wivrn +{ + // How many samples of wait time to store per decoder -const size_t num_wait_times = 100; +static const size_t num_wait_times = 100; // How many samples of wait time are required to use them -const size_t min_wait_times = 50; +static const size_t min_wait_times = 50; void wivrn_pacer::set_stream_count(size_t count) { @@ -171,3 +174,4 @@ void wivrn_pacer::reset() } in_flight_frames = {}; } +} // namespace wivrn diff --git a/server/driver/wivrn_pacer.h b/server/driver/wivrn_pacer.h index e478ec6e..99aa0c66 100644 --- a/server/driver/wivrn_pacer.h +++ b/server/driver/wivrn_pacer.h @@ -26,6 +26,9 @@ #include #include +namespace wivrn +{ + struct clock_offset; class wivrn_pacer @@ -89,3 +92,4 @@ public: void reset(); }; +} // namespace wivrn diff --git a/server/driver/wivrn_session.cpp b/server/driver/wivrn_session.cpp index c709069d..6e0b29f3 100644 --- a/server/driver/wivrn_session.cpp +++ b/server/driver/wivrn_session.cpp @@ -53,6 +53,9 @@ #include "solarxr_device.h" #endif +namespace wivrn +{ + struct wivrn_comp_target_factory : public comp_target_factory { std::shared_ptr session; @@ -545,3 +548,4 @@ void wivrn_session::reconnect() U_LOG_E("Reconnection failed: %s", e.what()); } } +} // namespace wivrn diff --git a/server/driver/wivrn_session.h b/server/driver/wivrn_session.h index 624c0adb..d9e59e1a 100644 --- a/server/driver/wivrn_session.h +++ b/server/driver/wivrn_session.h @@ -33,21 +33,20 @@ #include #include +struct u_system; +struct xrt_system_devices; +struct xrt_space_overseer; +struct xrt_system_compositor; + +namespace wivrn +{ class wivrn_eye_tracker; class wivrn_fb_face2_tracker; class wivrn_foveation; class wivrn_foveation_renderer; struct audio_device; - -struct u_system; -struct xrt_system_devices; -struct xrt_space_overseer; -struct xrt_system_compositor; -struct wivrn_comp_target_factory; - -namespace wivrn -{ struct wivrn_comp_target; +struct wivrn_comp_target_factory; class tracking_control_t { diff --git a/server/encoder/encoder_settings.cpp b/server/encoder/encoder_settings.cpp index 83e67ebc..dd25735e 100644 --- a/server/encoder/encoder_settings.cpp +++ b/server/encoder/encoder_settings.cpp @@ -37,8 +37,8 @@ #include "ffmpeg/video_encoder_va.h" #endif -using namespace wivrn; - +namespace wivrn +{ // TODO: size independent bitrate static const uint64_t default_bitrate = 50'000'000; @@ -258,7 +258,7 @@ static void make_even(uint16_t & value, uint16_t max) value = std::min(value, max); } -std::vector wivrn::get_encoder_settings(wivrn_vk_bundle & bundle, uint32_t & width, uint32_t & height, const from_headset::headset_info_packet & info) +std::vector get_encoder_settings(wivrn_vk_bundle & bundle, uint32_t & width, uint32_t & height, const from_headset::headset_info_packet & info) { configuration config; try @@ -316,3 +316,4 @@ std::vector wivrn::get_encoder_settings(wivrn_vk_bundle & bund split_bitrate(res, bitrate); return res; } +} // namespace wivrn diff --git a/server/encoder/encoder_settings.h b/server/encoder/encoder_settings.h index 85e61df6..06ce7f94 100644 --- a/server/encoder/encoder_settings.h +++ b/server/encoder/encoder_settings.h @@ -25,10 +25,9 @@ #include #include -struct wivrn_vk_bundle; - namespace wivrn { +struct wivrn_vk_bundle; struct encoder_settings : public to_headset::video_stream_description::item { @@ -43,6 +42,6 @@ struct encoder_settings : public to_headset::video_stream_description::item std::vector get_encoder_settings(wivrn_vk_bundle &, uint32_t & width, uint32_t & height, const from_headset::headset_info_packet & info); -} // namespace wivrn - void print_encoders(const std::vector & encoders); + +} // namespace wivrn diff --git a/server/encoder/ffmpeg/video_encoder_ffmpeg.cpp b/server/encoder/ffmpeg/video_encoder_ffmpeg.cpp index 189a6172..24bdac77 100644 --- a/server/encoder/ffmpeg/video_encoder_ffmpeg.cpp +++ b/server/encoder/ffmpeg/video_encoder_ffmpeg.cpp @@ -61,6 +61,9 @@ bool set_log_level() } // namespace +namespace wivrn +{ + bool VideoEncoderFFMPEG::once = set_log_level(); std::optional VideoEncoderFFMPEG::encode(bool idr, std::chrono::steady_clock::time_point target_timestamp, uint8_t slot) @@ -94,3 +97,4 @@ VideoEncoderFFMPEG::mute_logs::~mute_logs() { set_log_level(); } +} // namespace wivrn diff --git a/server/encoder/ffmpeg/video_encoder_ffmpeg.h b/server/encoder/ffmpeg/video_encoder_ffmpeg.h index 9b80d59a..4ec4d078 100644 --- a/server/encoder/ffmpeg/video_encoder_ffmpeg.h +++ b/server/encoder/ffmpeg/video_encoder_ffmpeg.h @@ -23,6 +23,9 @@ #include "ffmpeg_helper.h" #include +namespace wivrn +{ + class VideoEncoderFFMPEG : public wivrn::VideoEncoder { public: @@ -47,3 +50,4 @@ protected: private: static bool once; }; +} // namespace wivrn diff --git a/server/encoder/ffmpeg/video_encoder_va.cpp b/server/encoder/ffmpeg/video_encoder_va.cpp index 05efc9be..56cf9052 100644 --- a/server/encoder/ffmpeg/video_encoder_va.cpp +++ b/server/encoder/ffmpeg/video_encoder_va.cpp @@ -40,6 +40,9 @@ extern "C" #include } +namespace wivrn +{ + namespace { const char * @@ -475,3 +478,4 @@ void video_encoder_va::push_frame(bool idr, std::chrono::steady_clock::time_poin throw std::system_error(err, av_error_category(), "avcodec_send_frame failed"); } } +} // namespace wivrn diff --git a/server/encoder/ffmpeg/video_encoder_va.h b/server/encoder/ffmpeg/video_encoder_va.h index f1306fef..4931498a 100644 --- a/server/encoder/ffmpeg/video_encoder_va.h +++ b/server/encoder/ffmpeg/video_encoder_va.h @@ -27,7 +27,6 @@ namespace wivrn { struct encoder_settings; -} class video_encoder_va : public VideoEncoderFFMPEG { @@ -52,3 +51,4 @@ public: protected: void push_frame(bool idr, std::chrono::steady_clock::time_point pts, uint8_t slot) override; }; +} // namespace wivrn diff --git a/server/encoder/video_encoder.h b/server/encoder/video_encoder.h index b9b63194..f2ceb9c1 100644 --- a/server/encoder/video_encoder.h +++ b/server/encoder/video_encoder.h @@ -33,11 +33,10 @@ #include "encoder_settings.h" #include "wivrn_packets.h" -struct wivrn_vk_bundle; - namespace wivrn { +struct wivrn_vk_bundle; class wivrn_session; inline const char * encoder_nvenc = "nvenc"; diff --git a/server/hostname.cpp b/server/hostname.cpp index 951a5059..b3701120 100644 --- a/server/hostname.cpp +++ b/server/hostname.cpp @@ -63,7 +63,7 @@ static std::string _hostname() return "no-hostname"; } -std::string hostname() +std::string wivrn::hostname() { // Accessing hostname in child process fails with glib static std::string result = _hostname(); diff --git a/server/hostname.h b/server/hostname.h index 89143048..f59798aa 100644 --- a/server/hostname.h +++ b/server/hostname.h @@ -2,4 +2,7 @@ #include +namespace wivrn +{ std::string hostname(); +} diff --git a/server/start_application.cpp b/server/start_application.cpp index c819babe..a2b2af32 100644 --- a/server/start_application.cpp +++ b/server/start_application.cpp @@ -21,7 +21,7 @@ #include #include -int get_service_pid(const std::string & service_name, pid_t & pid) +static int get_service_pid(const std::string & service_name, pid_t & pid) { sd_bus * bus = nullptr; sd_bus_error error = SD_BUS_ERROR_NULL; @@ -165,7 +165,7 @@ finish: return is_active; } -pid_t start_unit_file() +pid_t wivrn::start_unit_file() { std::string service_name = "wivrn-application.service"; pid_t pid; @@ -200,7 +200,7 @@ pid_t start_unit_file() #endif -pid_t fork_application() +pid_t wivrn::fork_application() { auto config = configuration::read_user_configuration(); @@ -225,7 +225,7 @@ pid_t fork_application() return application_pid; } -int exec_application(configuration config) +int wivrn::exec_application(configuration config) { if (config.application.empty()) return 0; diff --git a/server/start_application.h b/server/start_application.h index b1cd57ee..fc09db30 100644 --- a/server/start_application.h +++ b/server/start_application.h @@ -4,10 +4,15 @@ #include +namespace wivrn +{ struct configuration; pid_t fork_application(); + #if WIVRN_USE_SYSTEMD pid_t start_unit_file(); #endif + int exec_application(configuration); +} // namespace wivrn diff --git a/server/target_instance_wivrn.cpp b/server/target_instance_wivrn.cpp index 81698de7..43c477ed 100644 --- a/server/target_instance_wivrn.cpp +++ b/server/target_instance_wivrn.cpp @@ -24,7 +24,7 @@ * */ -extern std::unique_ptr tcp; +extern std::unique_ptr tcp; static xrt_result_t wivrn_instance_create_system(struct xrt_instance * xinst, diff --git a/server/utils/scoped_lock.h b/server/utils/scoped_lock.h index 5a7963c6..bc235f1d 100644 --- a/server/utils/scoped_lock.h +++ b/server/utils/scoped_lock.h @@ -21,6 +21,9 @@ #include "os/os_threading.h" +namespace wivrn +{ + class scoped_lock { os_mutex & mutex; @@ -36,3 +39,4 @@ public: os_mutex_unlock(&mutex); } }; +} // namespace wivrn diff --git a/server/utils/wivrn_vk_bundle.cpp b/server/utils/wivrn_vk_bundle.cpp index ad2eeee6..a22f10cb 100644 --- a/server/utils/wivrn_vk_bundle.cpp +++ b/server/utils/wivrn_vk_bundle.cpp @@ -23,7 +23,7 @@ #include -wivrn_vk_bundle::wivrn_vk_bundle(vk_bundle & vk, std::span requested_instance_extensions, std::span requested_device_extensions) : +wivrn::wivrn_vk_bundle::wivrn_vk_bundle(vk_bundle & vk, std::span requested_instance_extensions, std::span requested_device_extensions) : vk(vk), instance(vk_ctx, vk.instance), physical_device(instance, vk.physical_device), @@ -147,7 +147,7 @@ wivrn_vk_bundle::wivrn_vk_bundle(vk_bundle & vk, std::span request } } -uint32_t wivrn_vk_bundle::get_memory_type(uint32_t type_bits, vk::MemoryPropertyFlags memory_props) +uint32_t wivrn::wivrn_vk_bundle::get_memory_type(uint32_t type_bits, vk::MemoryPropertyFlags memory_props) { auto mem_prop = physical_device.getMemoryProperties(); diff --git a/server/utils/wivrn_vk_bundle.h b/server/utils/wivrn_vk_bundle.h index 9093d972..cbad010b 100644 --- a/server/utils/wivrn_vk_bundle.h +++ b/server/utils/wivrn_vk_bundle.h @@ -27,6 +27,9 @@ struct vk_bundle; +namespace wivrn +{ + // to use vk::raii we need a vk::raii::{Instance,PhysicalDevice,Device} // however we don't own it, so deactivate the destructor struct raii_instance : public vk::raii::Instance @@ -68,3 +71,4 @@ struct wivrn_vk_bundle uint32_t get_memory_type(uint32_t type_bits, vk::MemoryPropertyFlags memory_props); }; +} // namespace wivrn