Skip to content

Commit 827b5f6

Browse files
authored
Revert "revert linux use cpal (rustdesk#10260)" (rustdesk#10262)
This reverts commit b0791ba.
1 parent b0791ba commit 827b5f6

File tree

2 files changed

+0
-60
lines changed

2 files changed

+0
-60
lines changed

Cargo.toml

-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ fon = "0.6"
7878
zip = "0.6"
7979
shutdown_hooks = "0.1"
8080
totp-rs = { version = "5.4", default-features = false, features = ["gen_secret", "otpauth"] }
81-
82-
[target.'cfg(not(target_os = "linux"))'.dependencies]
83-
# https://github.com/rustdesk/rustdesk/discussions/10197, not use cpal on linux
8481
cpal = { git = "https://github.com/rustdesk-org/cpal", branch = "osx-screencapturekit" }
8582
ringbuf = "0.3"
8683

src/client.rs

-57
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@ use async_trait::async_trait;
22
use bytes::Bytes;
33
#[cfg(not(any(target_os = "android", target_os = "ios")))]
44
use clipboard_master::{CallbackResult, ClipboardHandler};
5-
#[cfg(not(target_os = "linux"))]
65
use cpal::{
76
traits::{DeviceTrait, HostTrait, StreamTrait},
87
Device, Host, StreamConfig,
98
};
109
use crossbeam_queue::ArrayQueue;
1110
use magnum_opus::{Channels::*, Decoder as AudioDecoder};
12-
#[cfg(not(target_os = "linux"))]
1311
use ringbuf::{ring_buffer::RbBase, Rb};
1412
use serde::{Deserialize, Serialize};
1513
use sha2::{Digest, Sha256};
@@ -119,7 +117,6 @@ pub const SCRAP_OTHER_VERSION_OR_X11_REQUIRED: &str =
119117
pub const SCRAP_X11_REQUIRED: &str = "x11 expected";
120118
pub const SCRAP_X11_REF_URL: &str = "https://rustdesk.com/docs/en/manual/linux/#x11-required";
121119

122-
#[cfg(not(target_os = "linux"))]
123120
pub const AUDIO_BUFFER_MS: usize = 3000;
124121

125122
#[cfg(feature = "flutter")]
@@ -142,7 +139,6 @@ struct TextClipboardState {
142139
running: bool,
143140
}
144141

145-
#[cfg(not(target_os = "linux"))]
146142
lazy_static::lazy_static! {
147143
static ref AUDIO_HOST: Host = cpal::default_host();
148144
}
@@ -865,28 +861,20 @@ impl ClipboardHandler for ClientClipboardHandler {
865861
#[derive(Default)]
866862
pub struct AudioHandler {
867863
audio_decoder: Option<(AudioDecoder, Vec<f32>)>,
868-
#[cfg(target_os = "linux")]
869-
simple: Option<psimple::Simple>,
870-
#[cfg(not(target_os = "linux"))]
871864
audio_buffer: AudioBuffer,
872865
sample_rate: (u32, u32),
873-
#[cfg(not(target_os = "linux"))]
874866
audio_stream: Option<Box<dyn StreamTrait>>,
875867
channels: u16,
876-
#[cfg(not(target_os = "linux"))]
877868
device_channel: u16,
878-
#[cfg(not(target_os = "linux"))]
879869
ready: Arc<std::sync::Mutex<bool>>,
880870
}
881871

882-
#[cfg(not(target_os = "linux"))]
883872
struct AudioBuffer(
884873
pub Arc<std::sync::Mutex<ringbuf::HeapRb<f32>>>,
885874
usize,
886875
[usize; 30],
887876
);
888877

889-
#[cfg(not(target_os = "linux"))]
890878
impl Default for AudioBuffer {
891879
fn default() -> Self {
892880
Self(
@@ -899,7 +887,6 @@ impl Default for AudioBuffer {
899887
}
900888
}
901889

902-
#[cfg(not(target_os = "linux"))]
903890
impl AudioBuffer {
904891
pub fn resize(&mut self, sample_rate: usize, channels: usize) {
905892
let capacity = sample_rate * channels * AUDIO_BUFFER_MS / 1000;
@@ -1002,37 +989,7 @@ impl AudioBuffer {
1002989
}
1003990

1004991
impl AudioHandler {
1005-
#[cfg(target_os = "linux")]
1006-
fn start_audio(&mut self, format0: AudioFormat) -> ResultType<()> {
1007-
use psimple::Simple;
1008-
use pulse::sample::{Format, Spec};
1009-
use pulse::stream::Direction;
1010-
1011-
let spec = Spec {
1012-
format: Format::F32le,
1013-
channels: format0.channels as _,
1014-
rate: format0.sample_rate as _,
1015-
};
1016-
if !spec.is_valid() {
1017-
bail!("Invalid audio format");
1018-
}
1019-
1020-
self.simple = Some(Simple::new(
1021-
None, // Use the default server
1022-
&crate::get_app_name(), // Our application’s name
1023-
Direction::Playback, // We want a playback stream
1024-
None, // Use the default device
1025-
"playback", // Description of our stream
1026-
&spec, // Our sample format
1027-
None, // Use default channel map
1028-
None, // Use default buffering attributes
1029-
)?);
1030-
self.sample_rate = (format0.sample_rate, format0.sample_rate);
1031-
Ok(())
1032-
}
1033-
1034992
/// Start the audio playback.
1035-
#[cfg(not(target_os = "linux"))]
1036993
fn start_audio(&mut self, format0: AudioFormat) -> ResultType<()> {
1037994
let device = AUDIO_HOST
1038995
.default_output_device()
@@ -1100,20 +1057,13 @@ impl AudioHandler {
11001057
/// Handle audio frame and play it.
11011058
#[inline]
11021059
pub fn handle_frame(&mut self, frame: AudioFrame) {
1103-
#[cfg(not(target_os = "linux"))]
11041060
if self.audio_stream.is_none() || !self.ready.lock().unwrap().clone() {
11051061
return;
11061062
}
1107-
#[cfg(target_os = "linux")]
1108-
if self.simple.is_none() {
1109-
log::debug!("PulseAudio simple binding does not exists");
1110-
return;
1111-
}
11121063
self.audio_decoder.as_mut().map(|(d, buffer)| {
11131064
if let Ok(n) = d.decode_float(&frame.data, buffer, false) {
11141065
let channels = self.channels;
11151066
let n = n * (channels as usize);
1116-
#[cfg(not(target_os = "linux"))]
11171067
{
11181068
let sample_rate0 = self.sample_rate.0;
11191069
let sample_rate = self.sample_rate.1;
@@ -1137,18 +1087,11 @@ impl AudioHandler {
11371087
}
11381088
self.audio_buffer.append_pcm(&buffer);
11391089
}
1140-
#[cfg(target_os = "linux")]
1141-
{
1142-
let data_u8 =
1143-
unsafe { std::slice::from_raw_parts::<u8>(buffer.as_ptr() as _, n * 4) };
1144-
self.simple.as_mut().map(|x| x.write(data_u8));
1145-
}
11461090
}
11471091
});
11481092
}
11491093

11501094
/// Build audio output stream for current device.
1151-
#[cfg(not(target_os = "linux"))]
11521095
fn build_output_stream<T: cpal::Sample + cpal::SizedSample + cpal::FromSample<f32>>(
11531096
&mut self,
11541097
config: &StreamConfig,

0 commit comments

Comments
 (0)