Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(client): ♻️ Move platform to alvr_system_info; rename video decoder #2488

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ alvr_server_core = { path = "alvr/server_core"}
alvr_server_io = { path = "alvr/server_io" }
alvr_session = { path = "alvr/session" }
alvr_sockets = { path = "alvr/sockets" }
alvr_system_info = { path = "alvr/system_info" }

[profile.release]
debug = "limited"
Expand Down
1 change: 1 addition & 0 deletions alvr/client_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ alvr_common.workspace = true
alvr_packets.workspace = true
alvr_session.workspace = true
alvr_sockets.workspace = true
alvr_system_info.workspace = true

app_dirs2 = "2"
bincode = "1"
Expand Down
13 changes: 7 additions & 6 deletions alvr/client_core/src/c_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
decoder::{self, DecoderConfig, DecoderSource},
graphics::{GraphicsContext, LobbyRenderer, RenderViewInput, StreamRenderer},
storage, ClientCapabilities, ClientCoreContext, ClientCoreEvent,
storage,
video_decoder::{self, VideoDecoderConfig, VideoDecoderSource},
ClientCapabilities, ClientCoreContext, ClientCoreEvent,
};
use alvr_common::{
anyhow::Result,
Expand Down Expand Up @@ -255,7 +256,7 @@ pub extern "C" fn alvr_protocol_id(protocol_buffer: *mut c_char) -> u64 {
#[cfg(target_os = "android")]
#[no_mangle]
pub unsafe extern "C" fn alvr_try_get_permission(permission: *const c_char) {
crate::platform::try_get_permission(CStr::from_ptr(permission).to_str().unwrap());
alvr_system_info::try_get_permission(CStr::from_ptr(permission).to_str().unwrap());
}

/// NB: for android, `context` must be thread safe.
Expand Down Expand Up @@ -823,7 +824,7 @@ pub unsafe extern "C" fn alvr_render_stream_opengl(

// Decoder-related interface

static DECODER_SOURCE: OptLazy<DecoderSource> = alvr_common::lazy_mut_none();
static DECODER_SOURCE: OptLazy<VideoDecoderSource> = alvr_common::lazy_mut_none();

#[repr(u8)]
pub enum AlvrMediacodecPropType {
Expand Down Expand Up @@ -863,7 +864,7 @@ pub struct AlvrDecoderConfig {
/// alvr_initialize() must be called before alvr_create_decoder
#[no_mangle]
pub extern "C" fn alvr_create_decoder(config: AlvrDecoderConfig) {
let config = DecoderConfig {
let config = VideoDecoderConfig {
codec: match config.codec {
AlvrCodec::H264 => CodecType::H264,
AlvrCodec::Hevc => CodecType::Hevc,
Expand Down Expand Up @@ -909,7 +910,7 @@ pub extern "C" fn alvr_create_decoder(config: AlvrDecoderConfig) {
};

let (mut sink, source) =
decoder::create_decoder(config, |maybe_timestamp: Result<Duration>| {
video_decoder::create_decoder(config, |maybe_timestamp: Result<Duration>| {
if let Some(context) = &*CLIENT_CORE_CONTEXT.lock() {
match maybe_timestamp {
Ok(timestamp) => context.report_frame_decoded(timestamp),
Expand Down
7 changes: 3 additions & 4 deletions alvr/client_core/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use crate::{
logging_backend::{LogMirrorData, LOG_CHANNEL_SENDER},
platform,
sockets::AnnouncerSocket,
statistics::StatisticsManager,
storage::Config,
Expand Down Expand Up @@ -75,7 +74,7 @@ fn set_hud_message(event_queue: &Mutex<VecDeque<ClientCoreEvent>>, message: &str
"ALVR v{}\nhostname: {}\nIP: {}\n\n{message}",
*ALVR_VERSION,
Config::load().hostname,
platform::local_ip(),
alvr_system_info::local_ip(),
);

event_queue
Expand Down Expand Up @@ -167,7 +166,7 @@ fn connection_pipeline(
proto_control_socket
.send(&ClientConnectionResult::ConnectionAccepted {
client_protocol_id: alvr_common::protocol_id_u64(),
display_name: platform::platform().to_string(),
display_name: alvr_system_info::platform().to_string(),
server_ip,
streaming_capabilities: Some(
alvr_packets::encode_video_streaming_capabilities(&VideoStreamingCapabilities {
Expand Down Expand Up @@ -438,7 +437,7 @@ fn connection_pipeline(

#[cfg(target_os = "android")]
if Instant::now() > battery_deadline {
let (gauge_value, is_plugged) = platform::get_battery_status();
let (gauge_value, is_plugged) = alvr_system_info::get_battery_status();
if let Some(sender) = &mut *ctx.control_sender.lock() {
sender
.send(&ClientControlPacket::Battery(crate::BatteryInfo {
Expand Down
20 changes: 5 additions & 15 deletions alvr/client_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
mod c_api;
mod connection;
mod logging_backend;
mod platform;
mod sockets;
mod statistics;
mod storage;

#[cfg(target_os = "android")]
mod audio;

pub mod decoder;
pub mod graphics;
pub mod video_decoder;

use alvr_common::{
dbg_client_core, error,
Expand All @@ -32,7 +31,6 @@ use alvr_packets::{
};
use alvr_session::CodecType;
use connection::ConnectionContext;
use serde::{Deserialize, Serialize};
use std::{
collections::{HashSet, VecDeque},
sync::Arc,
Expand All @@ -41,17 +39,9 @@ use std::{
};
use storage::Config;

pub use alvr_system_info::Platform;
pub use logging_backend::init_logging;
pub use platform::Platform;

#[cfg(target_os = "android")]
pub use platform::try_get_permission;

pub fn platform() -> Platform {
platform::platform()
}

#[derive(Serialize, Deserialize)]
pub enum ClientCoreEvent {
UpdateHudMessage(String),
StreamingStarted(Box<StreamConfig>),
Expand Down Expand Up @@ -104,8 +94,8 @@ impl ClientCoreContext {
#[cfg(target_os = "android")]
{
dbg_client_core!("Getting permissions");
platform::try_get_permission(platform::MICROPHONE_PERMISSION);
platform::set_wifi_lock(true);
alvr_system_info::try_get_permission(alvr_system_info::MICROPHONE_PERMISSION);
alvr_system_info::set_wifi_lock(true);
}

let lifecycle_state = Arc::new(RwLock::new(LifecycleState::Idle));
Expand Down Expand Up @@ -402,7 +392,7 @@ impl Drop for ClientCoreContext {
}

#[cfg(target_os = "android")]
platform::set_wifi_lock(false);
alvr_system_info::set_wifi_lock(false);
}
}

Expand Down
3 changes: 1 addition & 2 deletions alvr/client_core/src/sockets.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::platform;
use alvr_common::anyhow::{bail, Result};
use mdns_sd::{ServiceDaemon, ServiceInfo};

Expand All @@ -18,7 +17,7 @@ impl AnnouncerSocket {
}

pub fn announce(&self) -> Result<()> {
let local_ip = platform::local_ip();
let local_ip = alvr_system_info::local_ip();
if local_ip.is_unspecified() {
bail!("IP is unspecified");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::VideoDecoderConfig;
use alvr_common::{
anyhow::{anyhow, bail, Context, Result},
error, info,
Expand Down Expand Up @@ -25,8 +26,6 @@ use std::{
time::Duration,
};

use crate::decoder::DecoderConfig;

struct FakeThreadSafe<T>(T);
unsafe impl<T> Send for FakeThreadSafe<T> {}
unsafe impl<T> Sync for FakeThreadSafe<T> {}
Expand Down Expand Up @@ -90,7 +89,7 @@ pub struct VideoDecoderSource {
running: Arc<RelaxedAtomic>,
dequeue_thread: Option<JoinHandle<()>>,
image_queue: Arc<Mutex<VecDeque<QueuedImage>>>,
config: DecoderConfig,
config: VideoDecoderConfig,
buffering_running_average: f32,
}

Expand Down Expand Up @@ -191,7 +190,7 @@ fn decoder_attempt_setup(
// Since we leak the ImageReader, and we pass frame_result_callback to it which contains a reference
// to ClientCoreContext, to avoid circular references we need to use a Weak reference.
fn decoder_lifecycle(
config: DecoderConfig,
config: VideoDecoderConfig,
csd_0: Vec<u8>,
frame_result_callback: Weak<impl Fn(Result<Duration>) + Send + Sync + 'static>,
running: Arc<RelaxedAtomic>,
Expand Down Expand Up @@ -334,7 +333,7 @@ fn decoder_lifecycle(

// Create a sink/source pair
pub fn video_decoder_split(
config: DecoderConfig,
config: VideoDecoderConfig,
csd_0: Vec<u8>,
frame_result_callback: impl Fn(Result<Duration>) + Send + Sync + 'static,
) -> Result<(VideoDecoderSink, VideoDecoderSource)> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#[cfg(target_os = "android")]
mod android;

use alvr_common::anyhow::Result;
use alvr_session::{CodecType, MediacodecDataType};
use std::time::Duration;

#[derive(Clone, Default, PartialEq)]
pub struct DecoderConfig {
pub struct VideoDecoderConfig {
pub codec: CodecType,
pub force_software_decoder: bool,
pub max_buffering_frames: f32,
Expand All @@ -12,12 +15,12 @@ pub struct DecoderConfig {
pub config_buffer: Vec<u8>,
}

pub struct DecoderSink {
pub struct VideoDecoderSink {
#[cfg(target_os = "android")]
inner: crate::platform::VideoDecoderSink,
inner: android::VideoDecoderSink,
}

impl DecoderSink {
impl VideoDecoderSink {
// returns true if frame has been successfully enqueued
#[allow(unused_variables)]
pub fn push_nal(&mut self, timestamp: Duration, nal: &[u8]) -> bool {
Expand All @@ -30,12 +33,12 @@ impl DecoderSink {
}
}

pub struct DecoderSource {
pub struct VideoDecoderSource {
#[cfg(target_os = "android")]
inner: crate::platform::VideoDecoderSource,
inner: android::VideoDecoderSource,
}

impl DecoderSource {
impl VideoDecoderSource {
/// If a frame is available, return the timestamp and the AHardwareBuffer.
pub fn get_frame(&mut self) -> Option<(Duration, *mut std::ffi::c_void)> {
#[cfg(target_os = "android")]
Expand All @@ -50,20 +53,23 @@ impl DecoderSource {
// report_frame_decoded: (target_timestamp: Duration) -> ()
#[allow(unused_variables)]
pub fn create_decoder(
config: DecoderConfig,
config: VideoDecoderConfig,
report_frame_decoded: impl Fn(Result<Duration>) + Send + Sync + 'static,
) -> (DecoderSink, DecoderSource) {
) -> (VideoDecoderSink, VideoDecoderSource) {
#[cfg(target_os = "android")]
{
let (sink, source) = crate::platform::video_decoder_split(
let (sink, source) = android::video_decoder_split(
config.clone(),
config.config_buffer,
report_frame_decoded,
)
.unwrap();

(DecoderSink { inner: sink }, DecoderSource { inner: source })
(
VideoDecoderSink { inner: sink },
VideoDecoderSource { inner: source },
)
}
#[cfg(not(target_os = "android"))]
(DecoderSink {}, DecoderSource {})
(VideoDecoderSink {}, VideoDecoderSource {})
}
1 change: 1 addition & 0 deletions alvr/client_openxr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ alvr_common.workspace = true
alvr_client_core.workspace = true
alvr_packets.workspace = true
alvr_session.workspace = true
alvr_system_info.workspace = true

openxr = { git = "https://github.com/Ralith/openxrs", rev = "9270509d23dc774b43a8b7289e8adf69fcac6828" }

Expand Down
10 changes: 5 additions & 5 deletions alvr/client_openxr/src/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ pub fn initialize_interaction(
if (config.combined_eye_gaze || config.eye_tracking_fb)
&& matches!(platform, Platform::QuestPro)
{
alvr_client_core::try_get_permission("com.oculus.permission.EYE_TRACKING")
alvr_system_info::try_get_permission("com.oculus.permission.EYE_TRACKING")
}
if config.combined_eye_gaze && platform.is_pico() {
alvr_client_core::try_get_permission("com.picovr.permission.EYE_TRACKING")
alvr_system_info::try_get_permission("com.picovr.permission.EYE_TRACKING")
}
if config.face_tracking_fb && matches!(platform, Platform::QuestPro) {
alvr_client_core::try_get_permission("android.permission.RECORD_AUDIO");
alvr_client_core::try_get_permission("com.oculus.permission.FACE_TRACKING")
alvr_system_info::try_get_permission("android.permission.RECORD_AUDIO");
alvr_system_info::try_get_permission("com.oculus.permission.FACE_TRACKING")
}
}

Expand All @@ -82,7 +82,7 @@ pub fn initialize_interaction(
&& platform.is_quest()
&& platform != Platform::Quest1
{
alvr_client_core::try_get_permission("com.oculus.permission.BODY_TRACKING")
alvr_system_info::try_get_permission("com.oculus.permission.BODY_TRACKING")
}
}

Expand Down
2 changes: 1 addition & 1 deletion alvr/client_openxr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn default_view() -> xr::View {
pub fn entry_point() {
alvr_client_core::init_logging();

let platform = alvr_client_core::platform();
let platform = alvr_system_info::platform();

let loader_suffix = match platform {
Platform::Quest1 => "_quest1",
Expand Down
Loading
Loading