1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! Wrapper around [RTCRtpParameters].
//!
//! [RTCRtpParameters]: https://w3.org/TR/webrtc#dom-rtcrtpparameters
use dart_sys::Dart_Handle;
use futures::future::LocalBoxFuture;
use medea_macro::dart_bridge;
use crate::platform::{dart::utils::handle::DartHandle, Error};
use super::{
send_encoding_parameters::SendEncodingParameters,
utils::{dart_future::FutureFromDart, list::DartList},
};
#[dart_bridge("flutter/lib/src/native/platform/parameters.g.dart")]
mod parameters {
use dart_sys::Dart_Handle;
use crate::platform::Error;
extern "C" {
/// Returns [RTCRtpEncodingParameters][1] from the provided
/// [RTCRtpParameters].
///
/// [RTCRtpParameters]: https://w3.org/TR/webrtc#dom-rtcrtpparameters
/// [1]: https://w3.org/TR/webrtc#dom-rtcrtpencodingparameters
pub fn encodings(parameters: Dart_Handle)
-> Result<Dart_Handle, Error>;
/// Sets the provided [RTCRtpEncodingParameters][1] into the provided
/// [RTCRtpParameters].
///
/// [RTCRtpParameters]: https://w3.org/TR/webrtc#dom-rtcrtpparameters
/// [1]: https://w3.org/TR/webrtc#dom-rtcrtpencodingparameters
pub fn set_encoding(
parameters: Dart_Handle,
encoding: Dart_Handle,
) -> Result<Dart_Handle, Error>;
}
}
/// Representation of [RTCRtpParameters].
///
/// [RTCRtpParameters]: https://w3.org/TR/webrtc#dom-rtcrtpparameters
#[derive(Clone, Debug)]
pub struct Parameters(DartHandle);
impl From<DartHandle> for Parameters {
fn from(from: DartHandle) -> Self {
Self(from)
}
}
impl Parameters {
/// Returns [`SendEncodingParameters`] of these [`Parameters`].
#[must_use]
pub fn encodings(
&self,
) -> LocalBoxFuture<'static, Result<Vec<SendEncodingParameters>, Error>>
{
let handle = self.0.get();
Box::pin(async move {
let fut = unsafe { parameters::encodings(handle) }.unwrap();
let encodings =
unsafe { FutureFromDart::execute::<DartHandle>(fut) }.await?;
let encodings = Vec::from(DartList::from(encodings))
.into_iter()
.map(|encoding: DartHandle| {
SendEncodingParameters::from(encoding)
})
.collect();
Ok(encodings)
})
}
/// Sets the provided [`SendEncodingParameters`] into these [`Parameters`].
#[must_use]
pub fn set_encoding(
&self,
encoding: &SendEncodingParameters,
) -> LocalBoxFuture<'static, ()> {
let handle = self.0.get();
let enc_handle = encoding.handle();
Box::pin(async move {
let fut = unsafe { parameters::set_encoding(handle, enc_handle) }
.unwrap();
unsafe { FutureFromDart::execute::<()>(fut) }.await.unwrap();
})
}
/// Returns the underlying [`Dart_Handle`] of these [`Parameters`].
#[must_use]
pub fn handle(&self) -> Dart_Handle {
self.0.get()
}
}