#[non_exhaustive]pub struct Options { /* private fields */ }Expand description
The settings of a command: receivers, the stream’s shape, the browser receiver, storage and callbacks. Fields a command does not use are ignored. Cloning shares the callbacks.
use tvpipe::{Options, PixelFormat};
let options = Options::new()
.to("Living Room")
.video(1280, 720, 60, PixelFormat::Rgba)
.audio(48_000, 2);Implementations§
Source§impl Options
impl Options
Sourcepub fn new() -> Options
pub fn new() -> Options
No receivers yet, defaults everywhere.
Examples found in repository?
22fn main() -> tvpipe::Result<()> {
23 let mut targets: Vec<String> = std::env::args().skip(1).collect();
24 if targets.is_empty() {
25 targets.push("browser".into());
26 }
27 let mut options = Options::new()
28 .video(W as u32, H as u32, FPS as u32, PixelFormat::Rgba)
29 .audio(RATE, 2)
30 .player(PlayerOptions::new().port(0))
31 // Pairing with an Apple TV that needs it, on the terminal.
32 .on_pin(|req| {
33 eprint!("PIN shown on {}: ", req.name);
34 let mut line = String::new();
35 std::io::stdin().read_line(&mut line).ok()?;
36 Some(line.trim().to_owned())
37 });
38 for t in &targets {
39 options = options.to(t.as_str());
40 }
41 let mut s = tvpipe::stream(options)?;
42 if let Some(url) = s.player_url() {
43 println!("watch at {url}");
44 }
45
46 let mut frame = vec![0u8; W * H * 4];
47 let mut pcm = Vec::new();
48 let mut phase = 0.0f32;
49 let mut sent = 0u64;
50 for n in 0u64.. {
51 let pts = Duration::from_micros(n * 1_000_000 / FPS);
52 // Pace by the stream's clock: a game would render at its own rate.
53 if let Some(wait) = pts.checked_sub(s.elapsed()) {
54 std::thread::sleep(wait);
55 }
56 draw(&mut frame, n);
57 if s.write_video(&frame, pts)? == Written::Queued {
58 sent += 1;
59 }
60 tone(&mut pcm, &mut phase, (RATE as u64 / FPS) as usize);
61 s.write_audio(&pcm, pts)?;
62 for e in s.poll_events() {
63 match e {
64 Event::Receiver(r) => println!("{}: {}", r.name, r.state),
65 Event::Stats(st) if st.elapsed_ms / 1000 % 5 == 0 => {
66 println!("{} s, {sent} frames queued", st.elapsed_ms / 1000)
67 }
68 _ => {}
69 }
70 }
71 }
72 s.finish()?;
73 Ok(())
74}Sourcepub fn to(self, target: impl Into<String>) -> Self
pub fn to(self, target: impl Into<String>) -> Self
A receiver (repeatable): a name from discover
("Living Room"), forced to a protocol ("airplay:Living Room",
"cast:Office"), an address ("192.168.1.20", "cast:10.0.0.5"),
or "browser" for a browser tab (PlayerOptions).
Examples found in repository?
22fn main() -> tvpipe::Result<()> {
23 let mut targets: Vec<String> = std::env::args().skip(1).collect();
24 if targets.is_empty() {
25 targets.push("browser".into());
26 }
27 let mut options = Options::new()
28 .video(W as u32, H as u32, FPS as u32, PixelFormat::Rgba)
29 .audio(RATE, 2)
30 .player(PlayerOptions::new().port(0))
31 // Pairing with an Apple TV that needs it, on the terminal.
32 .on_pin(|req| {
33 eprint!("PIN shown on {}: ", req.name);
34 let mut line = String::new();
35 std::io::stdin().read_line(&mut line).ok()?;
36 Some(line.trim().to_owned())
37 });
38 for t in &targets {
39 options = options.to(t.as_str());
40 }
41 let mut s = tvpipe::stream(options)?;
42 if let Some(url) = s.player_url() {
43 println!("watch at {url}");
44 }
45
46 let mut frame = vec![0u8; W * H * 4];
47 let mut pcm = Vec::new();
48 let mut phase = 0.0f32;
49 let mut sent = 0u64;
50 for n in 0u64.. {
51 let pts = Duration::from_micros(n * 1_000_000 / FPS);
52 // Pace by the stream's clock: a game would render at its own rate.
53 if let Some(wait) = pts.checked_sub(s.elapsed()) {
54 std::thread::sleep(wait);
55 }
56 draw(&mut frame, n);
57 if s.write_video(&frame, pts)? == Written::Queued {
58 sent += 1;
59 }
60 tone(&mut pcm, &mut phase, (RATE as u64 / FPS) as usize);
61 s.write_audio(&pcm, pts)?;
62 for e in s.poll_events() {
63 match e {
64 Event::Receiver(r) => println!("{}: {}", r.name, r.state),
65 Event::Stats(st) if st.elapsed_ms / 1000 % 5 == 0 => {
66 println!("{} s, {sent} frames queued", st.elapsed_ms / 1000)
67 }
68 _ => {}
69 }
70 }
71 }
72 s.finish()?;
73 Ok(())
74}Sourcepub fn to_device(self, device: &DeviceInfo) -> Self
pub fn to_device(self, device: &DeviceInfo) -> Self
A receiver from discover: Cast when it plays
video over Cast, else AirPlay.
Sourcepub fn video(
self,
width: u32,
height: u32,
fps: u32,
format: PixelFormat,
) -> Self
pub fn video( self, width: u32, height: u32, fps: u32, format: PixelFormat, ) -> Self
Raw frames of this size, rate and layout go to the built-in H.264
encoder (Stream::write_video).
Examples found in repository?
22fn main() -> tvpipe::Result<()> {
23 let mut targets: Vec<String> = std::env::args().skip(1).collect();
24 if targets.is_empty() {
25 targets.push("browser".into());
26 }
27 let mut options = Options::new()
28 .video(W as u32, H as u32, FPS as u32, PixelFormat::Rgba)
29 .audio(RATE, 2)
30 .player(PlayerOptions::new().port(0))
31 // Pairing with an Apple TV that needs it, on the terminal.
32 .on_pin(|req| {
33 eprint!("PIN shown on {}: ", req.name);
34 let mut line = String::new();
35 std::io::stdin().read_line(&mut line).ok()?;
36 Some(line.trim().to_owned())
37 });
38 for t in &targets {
39 options = options.to(t.as_str());
40 }
41 let mut s = tvpipe::stream(options)?;
42 if let Some(url) = s.player_url() {
43 println!("watch at {url}");
44 }
45
46 let mut frame = vec![0u8; W * H * 4];
47 let mut pcm = Vec::new();
48 let mut phase = 0.0f32;
49 let mut sent = 0u64;
50 for n in 0u64.. {
51 let pts = Duration::from_micros(n * 1_000_000 / FPS);
52 // Pace by the stream's clock: a game would render at its own rate.
53 if let Some(wait) = pts.checked_sub(s.elapsed()) {
54 std::thread::sleep(wait);
55 }
56 draw(&mut frame, n);
57 if s.write_video(&frame, pts)? == Written::Queued {
58 sent += 1;
59 }
60 tone(&mut pcm, &mut phase, (RATE as u64 / FPS) as usize);
61 s.write_audio(&pcm, pts)?;
62 for e in s.poll_events() {
63 match e {
64 Event::Receiver(r) => println!("{}: {}", r.name, r.state),
65 Event::Stats(st) if st.elapsed_ms / 1000 % 5 == 0 => {
66 println!("{} s, {sent} frames queued", st.elapsed_ms / 1000)
67 }
68 _ => {}
69 }
70 }
71 }
72 s.finish()?;
73 Ok(())
74}Sourcepub fn h264(self, width: u32, height: u32, fps: u32) -> Self
pub fn h264(self, width: u32, height: u32, fps: u32) -> Self
The program’s own H.264 of this size and rate
(Stream::write_h264).
Sourcepub fn audio(self, sample_rate: u32, channels: u8) -> Self
pub fn audio(self, sample_rate: u32, channels: u8) -> Self
Interleaved PCM at this rate and channel count
(Stream::write_audio).
Examples found in repository?
22fn main() -> tvpipe::Result<()> {
23 let mut targets: Vec<String> = std::env::args().skip(1).collect();
24 if targets.is_empty() {
25 targets.push("browser".into());
26 }
27 let mut options = Options::new()
28 .video(W as u32, H as u32, FPS as u32, PixelFormat::Rgba)
29 .audio(RATE, 2)
30 .player(PlayerOptions::new().port(0))
31 // Pairing with an Apple TV that needs it, on the terminal.
32 .on_pin(|req| {
33 eprint!("PIN shown on {}: ", req.name);
34 let mut line = String::new();
35 std::io::stdin().read_line(&mut line).ok()?;
36 Some(line.trim().to_owned())
37 });
38 for t in &targets {
39 options = options.to(t.as_str());
40 }
41 let mut s = tvpipe::stream(options)?;
42 if let Some(url) = s.player_url() {
43 println!("watch at {url}");
44 }
45
46 let mut frame = vec![0u8; W * H * 4];
47 let mut pcm = Vec::new();
48 let mut phase = 0.0f32;
49 let mut sent = 0u64;
50 for n in 0u64.. {
51 let pts = Duration::from_micros(n * 1_000_000 / FPS);
52 // Pace by the stream's clock: a game would render at its own rate.
53 if let Some(wait) = pts.checked_sub(s.elapsed()) {
54 std::thread::sleep(wait);
55 }
56 draw(&mut frame, n);
57 if s.write_video(&frame, pts)? == Written::Queued {
58 sent += 1;
59 }
60 tone(&mut pcm, &mut phase, (RATE as u64 / FPS) as usize);
61 s.write_audio(&pcm, pts)?;
62 for e in s.poll_events() {
63 match e {
64 Event::Receiver(r) => println!("{}: {}", r.name, r.state),
65 Event::Stats(st) if st.elapsed_ms / 1000 % 5 == 0 => {
66 println!("{} s, {sent} frames queued", st.elapsed_ms / 1000)
67 }
68 _ => {}
69 }
70 }
71 }
72 s.finish()?;
73 Ok(())
74}Sourcepub fn size(self, width: u32, height: u32) -> Self
pub fn size(self, width: u32, height: u32) -> Self
Caps the output size (default: the input’s, at most 1920x1080).
Sourcepub fn bitrate_kbps(self, kbps: u32) -> Self
pub fn bitrate_kbps(self, kbps: u32) -> Self
The video bitrate (default: from the size and rate).
Sourcepub fn latency(self, latency: Duration) -> Self
pub fn latency(self, latency: Duration) -> Self
The playout delay every receiver presents frames with (5–2000 ms; default: 300 ms with Cast, AirPlay’s automatic leads, 100 ms for browser tabs).
Sourcepub fn reconnect(self, window: Duration) -> Self
pub fn reconnect(self, window: Duration) -> Self
How long a receiver whose connection was lost is reconnected (default 120 s; zero: never).
Sourcepub fn encoder_threads(self, threads: usize) -> Self
pub fn encoder_threads(self, threads: usize) -> Self
Threads of the built-in encoder (0, the default: one per core, up to its slice limit).
Sourcepub fn encoder(self, encoder: Encoder) -> Self
pub fn encoder(self, encoder: Encoder) -> Self
Which encoder makes the video for play (default:
the best ffmpeg has).
Sourcepub fn ffmpeg_path(self, path: impl Into<PathBuf>) -> Self
pub fn ffmpeg_path(self, path: impl Into<PathBuf>) -> Self
The ffmpeg to use (default: PATH, or next to the program).
Sourcepub fn realtime(self, realtime: bool) -> Self
pub fn realtime(self, realtime: bool) -> Self
Paces a file at its timestamps (default for files) or reads it as fast as it comes (default for live inputs).
Sourcepub fn player(self, player: PlayerOptions) -> Self
pub fn player(self, player: PlayerOptions) -> Self
The browser receiver’s settings.
Examples found in repository?
22fn main() -> tvpipe::Result<()> {
23 let mut targets: Vec<String> = std::env::args().skip(1).collect();
24 if targets.is_empty() {
25 targets.push("browser".into());
26 }
27 let mut options = Options::new()
28 .video(W as u32, H as u32, FPS as u32, PixelFormat::Rgba)
29 .audio(RATE, 2)
30 .player(PlayerOptions::new().port(0))
31 // Pairing with an Apple TV that needs it, on the terminal.
32 .on_pin(|req| {
33 eprint!("PIN shown on {}: ", req.name);
34 let mut line = String::new();
35 std::io::stdin().read_line(&mut line).ok()?;
36 Some(line.trim().to_owned())
37 });
38 for t in &targets {
39 options = options.to(t.as_str());
40 }
41 let mut s = tvpipe::stream(options)?;
42 if let Some(url) = s.player_url() {
43 println!("watch at {url}");
44 }
45
46 let mut frame = vec![0u8; W * H * 4];
47 let mut pcm = Vec::new();
48 let mut phase = 0.0f32;
49 let mut sent = 0u64;
50 for n in 0u64.. {
51 let pts = Duration::from_micros(n * 1_000_000 / FPS);
52 // Pace by the stream's clock: a game would render at its own rate.
53 if let Some(wait) = pts.checked_sub(s.elapsed()) {
54 std::thread::sleep(wait);
55 }
56 draw(&mut frame, n);
57 if s.write_video(&frame, pts)? == Written::Queued {
58 sent += 1;
59 }
60 tone(&mut pcm, &mut phase, (RATE as u64 / FPS) as usize);
61 s.write_audio(&pcm, pts)?;
62 for e in s.poll_events() {
63 match e {
64 Event::Receiver(r) => println!("{}: {}", r.name, r.state),
65 Event::Stats(st) if st.elapsed_ms / 1000 % 5 == 0 => {
66 println!("{} s, {sent} frames queued", st.elapsed_ms / 1000)
67 }
68 _ => {}
69 }
70 }
71 }
72 s.finish()?;
73 Ok(())
74}Sourcepub fn storage(self, storage: Storage) -> Self
pub fn storage(self, storage: Storage) -> Self
Where pairings and the player token are kept (default:
Storage::default_app).
Sourcepub fn on_pin(
self,
f: impl FnMut(&PinRequest) -> Option<String> + Send + 'static,
) -> Self
pub fn on_pin( self, f: impl FnMut(&PinRequest) -> Option<String> + Send + 'static, ) -> Self
Pairs an AirPlay receiver that needs it during
stream/play: f gets the
request and returns the PIN the TV shows (None: give up).
Examples found in repository?
22fn main() -> tvpipe::Result<()> {
23 let mut targets: Vec<String> = std::env::args().skip(1).collect();
24 if targets.is_empty() {
25 targets.push("browser".into());
26 }
27 let mut options = Options::new()
28 .video(W as u32, H as u32, FPS as u32, PixelFormat::Rgba)
29 .audio(RATE, 2)
30 .player(PlayerOptions::new().port(0))
31 // Pairing with an Apple TV that needs it, on the terminal.
32 .on_pin(|req| {
33 eprint!("PIN shown on {}: ", req.name);
34 let mut line = String::new();
35 std::io::stdin().read_line(&mut line).ok()?;
36 Some(line.trim().to_owned())
37 });
38 for t in &targets {
39 options = options.to(t.as_str());
40 }
41 let mut s = tvpipe::stream(options)?;
42 if let Some(url) = s.player_url() {
43 println!("watch at {url}");
44 }
45
46 let mut frame = vec![0u8; W * H * 4];
47 let mut pcm = Vec::new();
48 let mut phase = 0.0f32;
49 let mut sent = 0u64;
50 for n in 0u64.. {
51 let pts = Duration::from_micros(n * 1_000_000 / FPS);
52 // Pace by the stream's clock: a game would render at its own rate.
53 if let Some(wait) = pts.checked_sub(s.elapsed()) {
54 std::thread::sleep(wait);
55 }
56 draw(&mut frame, n);
57 if s.write_video(&frame, pts)? == Written::Queued {
58 sent += 1;
59 }
60 tone(&mut pcm, &mut phase, (RATE as u64 / FPS) as usize);
61 s.write_audio(&pcm, pts)?;
62 for e in s.poll_events() {
63 match e {
64 Event::Receiver(r) => println!("{}: {}", r.name, r.state),
65 Event::Stats(st) if st.elapsed_ms / 1000 % 5 == 0 => {
66 println!("{} s, {sent} frames queued", st.elapsed_ms / 1000)
67 }
68 _ => {}
69 }
70 }
71 }
72 s.finish()?;
73 Ok(())
74}Sourcepub fn on_event(self, f: impl FnMut(&Event) + Send + 'static) -> Self
pub fn on_event(self, f: impl FnMut(&Event) + Send + 'static) -> Self
Calls f for every event, on a thread of the session’s own (so a
slow callback never stalls the media threads).
Sourcepub fn approve_remote(
self,
f: impl Fn(&str, &dyn Fn() -> bool) -> bool + Send + Sync + 'static,
) -> Self
pub fn approve_remote( self, f: impl Fn(&str, &dyn Fn() -> bool) -> bool + Send + Sync + 'static, ) -> Self
share with a public link: decides whether a capture from over
the tunnel may reach the receivers, given its description; the
second argument says the question is moot. Without it, remote
shares are refused.
share without a URL: also serves the share page on a public link
(tunnel), so someone elsewhere can share to the receivers.
share without a URL: opens the share page with the OS’s opener.
Sourcepub fn visible_browser(self, visible: bool) -> Self
pub fn visible_browser(self, visible: bool) -> Self
share URL (headless): show tvpipe’s browser window instead of
running it headless.
Sourcepub fn browser_path(self, path: impl Into<PathBuf>) -> Self
pub fn browser_path(self, path: impl Into<PathBuf>) -> Self
share URL: the browser to start (default: the installed one).