Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

fix(player): harden stream buffering, proxy io, and details footer

Samir Hossainse32647d14051
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 10088b4..9ea1ee5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,19 @@
- Dimmed favorites/continue-watching card items and the search bar provider pill when modal popups (such as the provider picker) are active in `src/tui/screens/home.rs`, ensuring background elements properly recede visually.
- **Update Check In-Flight Notification Replacement**:
- Replaced the in-flight `"Checking for updates"` notification toast with the final outcome toast (`Up to date` or `Update check failed`) upon completion in `src/tui/app/system.rs`, avoiding duplicate stacked update notifications.
+- **Media Player Stream Buffering & Readahead Tuning**:
+ - Configured high-throughput buffering in `src/player.rs` for `mpv` and `IINA` (`--cache=yes`, `--cache-pause=yes`, `--cache-pause-wait=8`, `--cache-pause-initial=yes`, `--demuxer-max-bytes=256M`, `--demuxer-max-back-bytes=100M`, `--demuxer-readahead-secs=120`, `--demuxer-lavf-buffersize=1048576`, `--stream-buffer-size=512k`, `--force-seekable=yes`, and `--stream-lavf-o=reconnect=1,reconnect_streamed=1,reconnect_delay_max=5`), eliminating the 1-second re-buffering loop by enforcing an 8-second playback cushion, prefetching up to 2 minutes of stream data, and expanding memory cache size to 256MB.
+ - Configured network caching and adaptive streaming in `src/player.rs` for `VLC` (`--network-caching=10000` and `--adaptive-logic=nearoptimal`), aligning the network buffer floor with the 10.3s MPEG-DASH `minBufferTime` specification and preventing playback stalls when CDN chunk delivery encounters transient packet jitter.
+- **IINA Playback History & Progress Tracking**:
+ - Corrected playback tracker dispatch in `src/tui/app/playback.rs` to route `IINA` through wall-clock elapsed progress recording rather than mpv Lua IPC reconciliation, ensuring watch progress and continue-watching state are recorded upon closing IINA.
+- **Loopback Stream Proxy Buffer Throughput & Non-Timed Streaming**:
+ - Switched loopback reverse proxy upstream client in `src/proxy.rs` to `crate::net::streaming_client_builder()`, removing the 60-second total request deadline from media segment downloads and enabling persistent TCP keep-alive socket reuse across DASH chunk requests.
+ - Buffered TCP loopback chunk forwarding in `src/proxy.rs` using a 128KB `tokio::io::BufWriter`, reducing context-switch syscall overhead when streaming CloudFront DASH and MP4 media to VLC and mobile players.
+- **Details Screen Footer Action Hierarchy & Layout Streamlining**:
+ - Removed redundant `[^P] Provider` and `[Esc] Back` hints from the Details screen footer in `src/tui/screens/details.rs`.
+ - Reorganized footer action items into a clean, intuitive hierarchy: primary playback (`[Enter] Play`), download action (`[d] Download` / `Save`), pane navigation (`[Tab] Streams` on series), library action (`[f] Favorite`), and synopsis overview (`[i] Info`).
+ - Lowered `DETAILS_FOOTER_SPLIT_THRESHOLD` to 80 columns so standard terminals ($\ge 80$ cols) display a single horizontal line, while compact or mobile viewports ($< 80$ cols) split into two balanced lines.
+ - Synchronized mouse click hitboxes in `src/tui/app/mouse.rs` to match the exact updated footer layout.
- **Details Pane Season & Episode Mouse Hitbox Scrolling Offsets**:
- Factored `ListState::offset()` into row hitbox calculations in `src/tui/app/mouse.rs`, ensuring mouse clicks accurately select the intended season or episode row in scrolled lists.
- **Dynamic Application User-Agent Header**:
diff --git a/src/player.rs b/src/player.rs
index 5d6c3b3..a2ded21 100644
--- a/src/player.rs
+++ b/src/player.rs
@@ -419,6 +419,25 @@ fn mpv_command(
command.arg(format!("{prefix}autofit={width}x{height}"));
}
command.arg(format!("{prefix}geometry=50%:50%"));
+ command.arg(format!("{prefix}cache=yes"));
+ command.arg(format!("{prefix}cache-pause=yes"));
+ command.arg(format!("{prefix}cache-pause-wait=8"));
+ command.arg(format!("{prefix}cache-pause-initial=yes"));
+ let (max_bytes, back_bytes) =
+ if cfg!(target_os = "android") || crate::updater::artifact::is_termux_environment() {
+ ("128M", "50M")
+ } else {
+ ("256M", "100M")
+ };
+ command.arg(format!("{prefix}demuxer-max-bytes={max_bytes}"));
+ command.arg(format!("{prefix}demuxer-max-back-bytes={back_bytes}"));
+ command.arg(format!("{prefix}demuxer-readahead-secs=120"));
+ command.arg(format!("{prefix}demuxer-lavf-buffersize=1048576"));
+ command.arg(format!("{prefix}stream-buffer-size=512k"));
+ command.arg(format!("{prefix}force-seekable=yes"));
+ command.arg(format!(
+ "{prefix}stream-lavf-o=reconnect=1,reconnect_streamed=1,reconnect_delay_max=5"
+ ));
if !iina {
command.arg("--idle=no").arg("--keep-open=no");
}
@@ -657,7 +676,8 @@ fn vlc_command(
.arg(format!("--height={height}"));
}
command.arg("--play-and-exit");
- command.arg("--adaptive-logic=highest");
+ command.arg("--network-caching=10000");
+ command.arg("--adaptive-logic=nearoptimal");
if let Some(height) = max_height.filter(|&h| h > 0) {
command.arg(format!("--adaptive-maxheight={height}"));
}
@@ -1865,6 +1885,18 @@ mod tests {
assert!(args.contains(&"--sub-file=/tmp/test.srt".to_string()));
assert!(args.contains(&"--start=120".to_string()));
assert!(args.contains(&"--autofit=1920x1080".to_string()));
+ assert!(args.contains(&"--cache=yes".to_string()));
+ assert!(args.contains(&"--cache-pause=yes".to_string()));
+ assert!(args.contains(&"--cache-pause-wait=8".to_string()));
+ assert!(args.contains(&"--cache-pause-initial=yes".to_string()));
+ assert!(args.contains(&"--demuxer-max-bytes=256M".to_string()));
+ assert!(args.contains(&"--demuxer-readahead-secs=120".to_string()));
+ assert!(args.contains(&"--demuxer-lavf-buffersize=1048576".to_string()));
+ assert!(args.contains(&"--stream-buffer-size=512k".to_string()));
+ assert!(args.contains(&"--force-seekable=yes".to_string()));
+ assert!(args.contains(
+ &"--stream-lavf-o=reconnect=1,reconnect_streamed=1,reconnect_delay_max=5".to_string()
+ ));
assert!(
args.iter().any(|a| a.starts_with("--http-header-fields="))
|| args
@@ -1897,6 +1929,8 @@ mod tests {
.map(|a| a.to_string_lossy().into_owned())
.collect();
+ assert!(args.contains(&"--network-caching=10000".to_string()));
+ assert!(args.contains(&"--adaptive-logic=nearoptimal".to_string()));
assert!(args.contains(&"--http-user-agent=VLC-Agent".to_string()));
assert!(args.contains(&"--http-referrer=https://cdn.example.com".to_string()));
assert!(!args.iter().any(|a| a.contains("CloudFront-Signature")));
diff --git a/src/proxy.rs b/src/proxy.rs
index ee1a52a..3a33855 100644
--- a/src/proxy.rs
+++ b/src/proxy.rs
@@ -111,7 +111,7 @@ pub async fn run_sidecar(
headers: Vec<(String, String)>,
subtitle_url: Option<String>,
) {
- let client = crate::net::http_client_builder()
+ let client = crate::net::streaming_client_builder()
.connect_timeout(Duration::from_secs(15))
.build()
.unwrap_or_default();
@@ -212,8 +212,9 @@ async fn handle_connection(
target_host: Option<&str>,
subtitle_url: Option<&str>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
- let (reader, mut writer) = stream.into_split();
+ let (reader, writer) = stream.into_split();
let mut buf_reader = BufReader::new(reader);
+ let mut writer = tokio::io::BufWriter::with_capacity(128 * 1024, writer);
let mut request_line = String::new();
let n = buf_reader.read_line(&mut request_line).await?;
@@ -224,6 +225,7 @@ async fn handle_connection(
writer
.write_all(b"HTTP/1.1 431 Request Header Fields Too Large\r\nContent-Length: 0\r\nConnection: close\r\n\r\n")
.await?;
+ writer.flush().await?;
return Ok(());
}
@@ -262,6 +264,7 @@ async fn handle_connection(
let response =
"HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\nConnection: close\r\n\r\n";
writer.write_all(response.as_bytes()).await?;
+ writer.flush().await?;
return Ok(());
}
};
@@ -274,6 +277,7 @@ async fn handle_connection(
let response =
"HTTP/1.1 403 Forbidden\r\nContent-Length: 0\r\nConnection: close\r\n\r\n";
writer.write_all(response.as_bytes()).await?;
+ writer.flush().await?;
return Ok(());
}
}
@@ -307,6 +311,7 @@ async fn handle_connection(
body.len()
);
writer.write_all(response.as_bytes()).await?;
+ writer.flush().await?;
return Ok(());
}
};
@@ -342,6 +347,7 @@ async fn handle_connection(
.as_bytes(),
)
.await?;
+ writer.flush().await?;
return Ok(());
}
let manifest_str = String::from_utf8_lossy(&manifest_bytes);
@@ -367,6 +373,7 @@ async fn handle_connection(
let headers_bytes = format_proxy_response_headers(upstream_res.headers(), &target_url);
writer.write_all(&headers_bytes).await?;
+ writer.flush().await?;
let mut stream = upstream_res.bytes_stream();
loop {
diff --git a/src/tui/app/mouse.rs b/src/tui/app/mouse.rs
index e91042b..d3a2e91 100644
--- a/src/tui/app/mouse.rs
+++ b/src/tui/app/mouse.rs
@@ -1205,7 +1205,6 @@ impl App {
let is_streams = self.state.details_pane == DetailsPane::Streams;
let is_seasons = self.state.details_pane == DetailsPane::Seasons;
let is_episodes = self.state.details_pane == DetailsPane::Episodes;
- let is_languages = self.state.details_pane == DetailsPane::Languages;
let compact = width < crate::tui::screens::details::DETAILS_FOOTER_SPLIT_THRESHOLD;
let is_favorited = self.state.is_selected_details_favorited();
@@ -1214,51 +1213,32 @@ impl App {
enum FooterAction {
PlaySelect,
Download,
- Favorite,
StreamsTab,
- Back,
+ Favorite,
Info,
}
- let mut primary: Vec<(FooterAction, u16)> = Vec::new();
- let mut secondary: Vec<(FooterAction, u16)> = Vec::new();
-
- if is_streams {
- primary.push((FooterAction::PlaySelect, 7 + 1 + 4));
- let d_label_len = if compact { 4 } else { 8 };
- primary.push((FooterAction::Download, 3 + 1 + d_label_len));
- primary.push((FooterAction::Info, 3 + 1 + 4));
- secondary.push((FooterAction::Favorite, 3 + 1 + fav_label_len));
- secondary.push((FooterAction::Back, 5 + 1 + 4));
- } else if is_languages {
- primary.push((FooterAction::PlaySelect, 7 + 1 + 6));
- primary.push((FooterAction::Favorite, 3 + 1 + fav_label_len));
- primary.push((FooterAction::Info, 3 + 1 + 4));
- secondary.push((FooterAction::StreamsTab, 5 + 1 + 7));
- secondary.push((FooterAction::Back, 5 + 1 + 4));
+ let (enter_len, d_label_len) = if is_streams {
+ (4, Some(if compact { 4 } else { 8 }))
} else if is_seasons {
- primary.push((FooterAction::PlaySelect, 7 + 1 + 6));
- let d_label_len = if compact { 8 } else { 15 };
- primary.push((FooterAction::Download, 3 + 1 + d_label_len));
- primary.push((FooterAction::Favorite, 3 + 1 + fav_label_len));
- primary.push((FooterAction::Info, 3 + 1 + 4));
- secondary.push((FooterAction::StreamsTab, 5 + 1 + 7));
- secondary.push((FooterAction::Back, 5 + 1 + 4));
+ (6, Some(if compact { 8 } else { 15 }))
} else if is_episodes {
- primary.push((FooterAction::PlaySelect, 7 + 1 + 6));
- let d_label_len = if compact { 8 } else { 16 };
- primary.push((FooterAction::Download, 3 + 1 + d_label_len));
- primary.push((FooterAction::Favorite, 3 + 1 + fav_label_len));
- primary.push((FooterAction::Info, 3 + 1 + 4));
- secondary.push((FooterAction::StreamsTab, 5 + 1 + 7));
- secondary.push((FooterAction::Back, 5 + 1 + 4));
+ (6, Some(if compact { 8 } else { 16 }))
} else {
- primary.push((FooterAction::PlaySelect, 7 + 1 + 6));
- primary.push((FooterAction::Favorite, 3 + 1 + fav_label_len));
+ (6, None)
+ };
+
+ let mut primary = vec![(FooterAction::PlaySelect, 7 + 1 + enter_len)];
+ if let Some(d_len) = d_label_len {
+ primary.push((FooterAction::Download, 3 + 1 + d_len));
+ }
+
+ let mut secondary = Vec::new();
+ if !is_streams {
secondary.push((FooterAction::StreamsTab, 5 + 1 + 7));
- primary.push((FooterAction::Info, 3 + 1 + 4));
- secondary.push((FooterAction::Back, 5 + 1 + 4));
}
+ secondary.push((FooterAction::Favorite, 3 + 1 + fav_label_len));
+ secondary.push((FooterAction::Info, 3 + 1 + 4));
let active_buttons =
if width >= crate::tui::screens::details::DETAILS_FOOTER_SPLIT_THRESHOLD {
if line_idx > 0 {
@@ -1308,9 +1288,6 @@ impl App {
FooterAction::StreamsTab => {
self.action_sender.send(Action::TabPane).ok();
}
- FooterAction::Back => {
- self.action_sender.send(Action::GoBack).ok();
- }
}
return;
}
diff --git a/src/tui/app/playback.rs b/src/tui/app/playback.rs
index e5841fc..0b1e779 100644
--- a/src/tui/app/playback.rs
+++ b/src/tui/app/playback.rs
@@ -536,11 +536,7 @@ impl App {
start_time.elapsed().as_secs()
);
let has_tracker = tracker_opts.is_some()
- && matches!(
- kind,
- crate::tui::state::PlayerKind::Mpv
- | crate::tui::state::PlayerKind::Iina
- );
+ && matches!(kind, crate::tui::state::PlayerKind::Mpv);
if has_tracker {
sender.send(Action::ReconcileHistory).ok();
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index 24df18c..f416589 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -95,7 +95,7 @@ impl DetailsLayoutTier {
}
}
-pub const DETAILS_FOOTER_SPLIT_THRESHOLD: u16 = 106;
+pub const DETAILS_FOOTER_SPLIT_THRESHOLD: u16 = 80;
pub(crate) fn visible_selector_panes(
available_panes: &[crate::tui::state::DetailsPane],
@@ -2090,11 +2090,6 @@ fn details_footer(
} else {
"Favorite"
};
- let show_provider = state.active_provider != crate::providers::ProviderKind::Addons
- && !state
- .selected_details
- .as_ref()
- .is_some_and(|d| d.id.provider == crate::providers::ProviderKind::Addons);
let (enter_label, d_label) = if is_streams {
("Play", Some(if compact { "Save" } else { "Download" }))
@@ -2124,22 +2119,13 @@ fn details_footer(
if let Some(d) = d_label {
primary.extend(footer_group("d", d, false, theme, modal_active));
}
- primary.extend(footer_group("i", "Info", false, theme, modal_active));
- let mut secondary = footer_group("f", fav_label, false, theme, modal_active);
- if show_provider {
- secondary.extend(footer_group(
- crate::tui::text::CTRL_P_STR,
- "Provider",
- false,
- theme,
- modal_active,
- ));
- }
+ let mut secondary = Vec::new();
if !is_streams {
secondary.extend(footer_group("Tab", "Streams", false, theme, modal_active));
}
- secondary.extend(footer_group("Esc", "Back", false, theme, modal_active));
+ secondary.extend(footer_group("f", fav_label, false, theme, modal_active));
+ secondary.extend(footer_group("i", "Info", false, theme, modal_active));
if let Some(last) = secondary.last_mut() {
*last = Span::raw("");
}
@@ -2651,22 +2637,17 @@ mod tests {
assert!(!footer_text.contains("[o] Open With"));
assert!(footer_text.contains("[d] Download"));
assert!(footer_text.contains("[f] Favorite"));
- assert!(footer_text.contains("Provider"));
- assert!(footer_text.contains("[Esc] Back"));
+ assert!(footer_text.contains("[i] Info"));
+ assert!(!footer_text.contains("Provider"));
+ assert!(!footer_text.contains("[Esc] Back"));
- let (compact_primary, compact_secondary) = details_footer(&state, &theme, 90, false);
+ let (compact_primary, compact_secondary) = details_footer(&state, &theme, 70, false);
let mut compact_spans = compact_primary;
compact_spans.extend(compact_secondary);
let compact_text: String = compact_spans.iter().map(|s| s.content.as_ref()).collect();
assert!(compact_text.contains("[d] Save"));
-
- state.active_provider = crate::providers::ProviderKind::Addons;
- let (addon_primary, addon_secondary) = details_footer(&state, &theme, 120, false);
- let mut addon_spans = addon_primary;
- addon_spans.extend(addon_secondary);
- let addon_text: String = addon_spans.iter().map(|s| s.content.as_ref()).collect();
- assert!(!addon_text.contains("Provider"));
- state.active_provider = crate::providers::ProviderKind::MovieBox;
+ assert!(!compact_text.contains("Provider"));
+ assert!(!compact_text.contains("[Esc] Back"));
state.details_pane = crate::tui::state::DetailsPane::Seasons;
let (primary, secondary) = details_footer(&state, &theme, 120, false);
@@ -2675,9 +2656,10 @@ mod tests {
let footer_text: String = all_spans.iter().map(|s| s.content.as_ref()).collect();
assert!(footer_text.contains("[Enter] Select"));
assert!(footer_text.contains("[d] Download Season"));
- assert!(footer_text.contains("[f] Favorite"));
assert!(footer_text.contains("[Tab] Streams"));
- assert!(footer_text.contains("[Esc] Back"));
+ assert!(footer_text.contains("[f] Favorite"));
+ assert!(footer_text.contains("[i] Info"));
+ assert!(!footer_text.contains("[Esc] Back"));
state.details_pane = crate::tui::state::DetailsPane::Episodes;
let (primary, secondary) = details_footer(&state, &theme, 120, false);
@@ -2686,9 +2668,10 @@ mod tests {
let footer_text: String = all_spans.iter().map(|s| s.content.as_ref()).collect();
assert!(footer_text.contains("[Enter] Select"));
assert!(footer_text.contains("[d] Download Episode"));
- assert!(footer_text.contains("[f] Favorite"));
assert!(footer_text.contains("[Tab] Streams"));
- assert!(footer_text.contains("[Esc] Back"));
+ assert!(footer_text.contains("[f] Favorite"));
+ assert!(footer_text.contains("[i] Info"));
+ assert!(!footer_text.contains("[Esc] Back"));
}
#[test]
diff --git a/tests/tui_acceptance.rs b/tests/tui_acceptance.rs
index c3bcfc5..c629b2c 100644
--- a/tests/tui_acceptance.rs
+++ b/tests/tui_acceptance.rs
@@ -910,9 +910,9 @@ async fn test_tui_layout_truncation_and_bounds() {
}
let tier = moviebox_tui::tui::screens::details::DetailsLayoutTier::Narrow;
- assert_eq!(tier.footer_height(80), 2);
- assert_eq!(tier.footer_height(105), 2);
- assert_eq!(tier.footer_height(106), 1);
+ assert_eq!(tier.footer_height(70), 2);
+ assert_eq!(tier.footer_height(79), 2);
+ assert_eq!(tier.footer_height(80), 1);
assert_eq!(tier.footer_height(120), 1);
}