fix: stabilize seek slider and clean backend lint issues
Some checks failed
Build for Windows / build-windows (push) Has been cancelled
Some checks failed
Build for Windows / build-windows (push) Has been cancelled
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
//! qobuz-backend: C-ABI library consumed by the Qt frontend.
|
||||
#![allow(clippy::missing_safety_doc)]
|
||||
|
||||
mod api;
|
||||
mod player;
|
||||
|
||||
@@ -157,7 +157,7 @@ impl MediaSource for SegmentStreamSource {
|
||||
|
||||
fn http_client() -> &'static reqwest::blocking::Client {
|
||||
static CLIENT: OnceLock<reqwest::blocking::Client> = OnceLock::new();
|
||||
CLIENT.get_or_init(|| reqwest::blocking::Client::new())
|
||||
CLIENT.get_or_init(reqwest::blocking::Client::new)
|
||||
}
|
||||
|
||||
fn fetch_segment(url: &str, cancel: &Arc<AtomicBool>) -> Option<Vec<u8>> {
|
||||
@@ -260,40 +260,43 @@ fn decrypt_and_extract_frames(data: &mut [u8], key: Option<&[u8; 16]>) -> Vec<u8
|
||||
break;
|
||||
}
|
||||
|
||||
if &data[pos + 4..pos + 8] == b"uuid" && box_size >= 36 {
|
||||
if &data[pos + 8..pos + 24] == QBZ1_UUID {
|
||||
let body = pos + 24;
|
||||
if body + 12 > data.len() {
|
||||
pos += box_size;
|
||||
continue;
|
||||
if data[pos + 4..pos + 8] == *b"uuid"
|
||||
&& box_size >= 36
|
||||
&& data[pos + 8..pos + 24] == QBZ1_UUID
|
||||
{
|
||||
let body = pos + 24;
|
||||
if body + 12 > data.len() {
|
||||
pos += box_size;
|
||||
continue;
|
||||
}
|
||||
|
||||
let raw_offset = read_u32_be(data, body + 4) as usize;
|
||||
let num_samples = read_u24_be(data, body + 9) as usize;
|
||||
let sample_data_start = pos + raw_offset;
|
||||
let table_start = body + 12;
|
||||
|
||||
let mut offset = sample_data_start;
|
||||
for i in 0..num_samples {
|
||||
let e = table_start + i * 16;
|
||||
if e + 16 > data.len() {
|
||||
break;
|
||||
}
|
||||
let size = read_u32_be(data, e) as usize;
|
||||
let enc = u16::from_be_bytes([data[e + 6], data[e + 7]]) != 0;
|
||||
|
||||
let raw_offset = read_u32_be(data, body + 4) as usize;
|
||||
let num_samples = read_u24_be(data, body + 9) as usize;
|
||||
let sample_data_start = pos + raw_offset;
|
||||
let table_start = body + 12;
|
||||
|
||||
let mut offset = sample_data_start;
|
||||
for i in 0..num_samples {
|
||||
let e = table_start + i * 16;
|
||||
if e + 16 > data.len() {
|
||||
break;
|
||||
}
|
||||
let size = read_u32_be(data, e) as usize;
|
||||
let enc = u16::from_be_bytes([data[e + 6], data[e + 7]]) != 0;
|
||||
|
||||
let end = offset + size;
|
||||
if end <= data.len() {
|
||||
if enc && key.is_some() {
|
||||
let end = offset + size;
|
||||
if end <= data.len() {
|
||||
if enc {
|
||||
if let Some(k) = key {
|
||||
let mut iv = [0u8; 16];
|
||||
iv[..8].copy_from_slice(&data[e + 8..e + 16]);
|
||||
Ctr128BE::<Aes128>::new(key.unwrap().into(), (&iv).into())
|
||||
Ctr128BE::<Aes128>::new(k.into(), (&iv).into())
|
||||
.apply_keystream(&mut data[offset..end]);
|
||||
}
|
||||
frames.extend_from_slice(&data[offset..end]);
|
||||
}
|
||||
offset += size;
|
||||
frames.extend_from_slice(&data[offset..end]);
|
||||
}
|
||||
offset += size;
|
||||
}
|
||||
}
|
||||
pos += box_size;
|
||||
@@ -845,7 +848,7 @@ impl Seek for HttpStreamSource {
|
||||
.send()
|
||||
{
|
||||
Ok(r) => r,
|
||||
Err(e) => return Err(io::Error::new(io::ErrorKind::Other, e.to_string())),
|
||||
Err(e) => return Err(io::Error::other(e.to_string())),
|
||||
};
|
||||
|
||||
if resp.status() == reqwest::StatusCode::PARTIAL_CONTENT {
|
||||
@@ -881,10 +884,7 @@ impl Seek for HttpStreamSource {
|
||||
self.pos = self.reader_pos;
|
||||
Ok(self.pos)
|
||||
} else {
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("HTTP Error {}", resp.status()),
|
||||
))
|
||||
Err(io::Error::other(format!("HTTP Error {}", resp.status())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ impl AudioOutput {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn flush(&self) {
|
||||
// Wait until the ring buffer is fully emptied by cpal
|
||||
while !self._ring.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user