nandi/jolt-nativepublic Fork 0
cfd3e3677bed92e80cfe447469a249cfdc0b1401
Commits
Clone
git clone https://git.rickub.com/nandi/jolt-native.git
git clone ssh://git@rickub.com/nandi/jolt-native.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

convert.rs · 81 lines · 2.4 KBRust Blame HistoryRaw
Lift freeq's AV media plane out of sleek 90f8b89 nandi 19d ago1use std::convert::TryInto;
2use std::time::Duration;
3
4extern crate ndk;
5
6use crate::{
7 BackendSpecificError, BuildStreamError, PauseStreamError, PlayStreamError, StreamError,
8 StreamInstant,
9};
10
11pub fn to_stream_instant(duration: Duration) -> StreamInstant {
12 StreamInstant::new(
13 duration.as_secs().try_into().unwrap(),
14 duration.subsec_nanos(),
15 )
16}
17
18pub fn stream_instant(stream: &ndk::audio::AudioStream) -> StreamInstant {
19 let ts = stream
20 .timestamp(ndk::audio::Clockid::Monotonic)
21 .unwrap_or(ndk::audio::Timestamp {
22 frame_position: 0,
23 time_nanoseconds: 0,
24 });
25 to_stream_instant(Duration::from_nanos(ts.time_nanoseconds as u64))
26}
27
28impl From<ndk::audio::AudioError> for StreamError {
29 fn from(error: ndk::audio::AudioError) -> Self {
30 use self::ndk::audio::AudioError::*;
31 match error {
32 Disconnected | Unavailable => Self::DeviceNotAvailable,
33 e => (BackendSpecificError {
34 description: e.to_string(),
35 })
36 .into(),
37 }
38 }
39}
40
41impl From<ndk::audio::AudioError> for PlayStreamError {
42 fn from(error: ndk::audio::AudioError) -> Self {
43 use self::ndk::audio::AudioError::*;
44 match error {
45 Disconnected | Unavailable => Self::DeviceNotAvailable,
46 e => (BackendSpecificError {
47 description: e.to_string(),
48 })
49 .into(),
50 }
51 }
52}
53
54impl From<ndk::audio::AudioError> for PauseStreamError {
55 fn from(error: ndk::audio::AudioError) -> Self {
56 use self::ndk::audio::AudioError::*;
57 match error {
58 Disconnected | Unavailable => Self::DeviceNotAvailable,
59 e => (BackendSpecificError {
60 description: e.to_string(),
61 })
62 .into(),
63 }
64 }
65}
66
67impl From<ndk::audio::AudioError> for BuildStreamError {
68 fn from(error: ndk::audio::AudioError) -> Self {
69 use self::ndk::audio::AudioError::*;
70 match error {
71 Disconnected | Unavailable => Self::DeviceNotAvailable,
72 NoFreeHandles => Self::StreamIdOverflow,
73 InvalidFormat | InvalidRate => Self::StreamConfigNotSupported,
74 IllegalArgument => Self::InvalidArgument,
75 e => (BackendSpecificError {
76 description: e.to_string(),
77 })
78 .into(),
79 }
80 }
81}