Skip to content

Fast channel switch#11

Merged
lbb00 merged 26 commits into
mainfrom
cursor/-bc-b3e93374-5caf-4678-a0ae-ba2ebf70fd9b-3aa2
Mar 11, 2026
Merged

Fast channel switch#11
lbb00 merged 26 commits into
mainfrom
cursor/-bc-b3e93374-5caf-4678-a0ae-ba2ebf70fd9b-3aa2

Conversation

@lbb00
Copy link
Copy Markdown
Member

@lbb00 lbb00 commented Mar 11, 2026

No description provided.

cursoragent and others added 26 commits March 11, 2026 23:18
Co-authored-by: lbb <mr@lbb00.com>
Co-authored-by: lbb <mr@lbb00.com>
Co-authored-by: lbb <mr@lbb00.com>
Co-authored-by: lbb <mr@lbb00.com>
Co-authored-by: lbb <mr@lbb00.com>
Co-authored-by: lbb <mr@lbb00.com>
Co-authored-by: lbb <mr@lbb00.com>
Co-authored-by: lbb <mr@lbb00.com>
- fix(security): replace hardcoded /opt/cursor/logs with app_data_dir()
- fix(security): add SSRF validation for proxy /stream and /warm endpoints
- perf(logger): replace blocking sync Mutex+file I/O with async mpsc channel writer thread
- refactor: remove excessive runtime logging in orchestrator, proxy, and commands
- refactor: extract useDualPlaybackEngine hook from VideoPlayer (SRP)
- refactor: split loadChannelInSlot into loadHlsSlot/loadMpegtsSlot/loadNativeSlot
- refactor: replace magic numbers with named constants

Amp-Thread-ID: https://ampcode.com/threads/T-019cd3cb-257d-77fc-bda5-bbaf67c96654
Co-authored-by: Amp <amp@ampcode.com>
- Add player.standbyEnabled setting with default value false
- Add resolver function resolveStandbyEnabled()
- Add toggle control in playback settings
- Conditionally load standby slot based on setting
- Add translations: Fast Channel Change / 快速换台

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8cb-6f2f-711b-8f4d-146bdd937388
Co-authored-by: Amp <amp@ampcode.com>
- Log neighbor warm plan with predicted and warm target channels
- Log user channel switches with direction
- Log channel loading to standby slots with prewarm flag
- Log slot ready status when stream connects
- Log slot activation with channel info
- Log slot destruction
- Log reasons when preloading is skipped

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>
- Slot 0: prev channel (n-1)
- Slot 1: active channel (n) - always displayed
- Slot 2: next channel (n+1)

Benefits:
- Preload both adjacent channels for faster switching in both directions
- Auto-cleanup after 30s inactivity (user not switching channels)
- Single active slot simplifies playback logic
- Better console logging for 3-slot management

Changes:
- PlayerSlot type: 0 | 1 | 2 (prev/active/next)
- 3 video elements: prevVideoRef, activeVideoRef, nextVideoRef
- Separate prev/next slot helpers instead of toggle
- Inactivity timer clears unused slots after 30s
- Updated tests to match 3-slot architecture

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>
前端槽位清理时间(2500ms)现在与发送给后端的预热意图 TTL 保持一致。
确保前后端的资源管理同步:
- 后端 TTL 过期后停止预热
- 前端 TTL 过期后清理槽位
- 避免资源不同步或浪费

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>
- 槽位 TTL: 60s (1min) - 用户一分钟内的切台都能秒启动
- 后端预热 TTL: 2.5s - 后端及时释放用不到的预热资源

避免槽位占用过长时间,同时给用户充足的响应时间

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>
'Dual' 已过时 - 现在支持 3 个槽位 + 双向预加载:
- 槽位 0: 上一频道 (n-1)
- 槽位 1: 当前频道 (n)
- 槽位 2: 下一频道 (n+1)

更准确的命名反映了实际的架构

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>
强调行为而非数量:
- 预加载邻频道(prev/next)
- 无缝快速切台
- 1分钟内的任意切台都是秒启动

比 'TripleSlot' 更清晰地表达了核心能力

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>
删除后端预热决策层:
- ❌ prewarm_submit_intents
- ❌ prewarm_report_primary
- ❌ prewarm_clear_source

改为前端单独管理:
- 预加载完全由 standbyEnabled 设置控制
- 3 个槽位生命周期由前端管理
- 60秒 TTL 自动清理

简化了架构:只有一层预加载逻辑,避免前后端冗余

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>
完整的命名重构,强调行为而非实现细节:

前端:
- useStandbyPlayback → useInstantChannelSwitch
- StandbyPlaybackEngine → InstantChannelSwitchEngine
- [Standby] logs → [InstantSwitch] logs
- STANDBY_SLOT_TTL_MS → INSTANT_SWITCH_SLOT_TTL_MS

Settings:
- standbyEnabled → instantSwitchEnabled
- STANDBY_ENABLED_SETTING_KEY → INSTANT_SWITCH_ENABLED_SETTING_KEY
- player.standbyEnabled → player.instantSwitchEnabled

翻译:
- en-US: 'Fast Channel Change' → 'Instant Switch'
- zh-CN: '快速换台' → '即时切台'

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>
@lbb00 lbb00 force-pushed the cursor/-bc-b3e93374-5caf-4678-a0ae-ba2ebf70fd9b-3aa2 branch from 8309126 to f6b8879 Compare March 11, 2026 15:19
@lbb00 lbb00 merged commit 2b241d1 into main Mar 11, 2026
2 checks passed
@lbb00 lbb00 deleted the cursor/-bc-b3e93374-5caf-4678-a0ae-ba2ebf70fd9b-3aa2 branch March 11, 2026 15:19
lbb00 added a commit that referenced this pull request Mar 15, 2026
* perf: reduce channel switch latency

Co-authored-by: lbb <mr@lbb00.com>

* perf: preload channel switch and keep speed indicator visible

Co-authored-by: lbb <mr@lbb00.com>

* perf: add dual-player hot switch and proxy warm cache

Co-authored-by: lbb <mr@lbb00.com>

* perf: reuse standby slot on rapid channel toggles

Co-authored-by: lbb <mr@lbb00.com>

* perf: wait for standby readiness before swap

Co-authored-by: lbb <mr@lbb00.com>

* perf: prewarm standby slot for predicted next channel

Co-authored-by: lbb <mr@lbb00.com>

* perf: simplify channel prewarm switch flow

Co-authored-by: lbb <mr@lbb00.com>

* refactor: split player switch core and add unit tests

Co-authored-by: lbb <mr@lbb00.com>

* feat: add rust resource prewarm orchestrator

Co-authored-by: lbb <mr@lbb00.com>

* fix(player): keep bottom info visible after overlay hide

Co-authored-by: lbb <mr@lbb00.com>

* feat: add standby runtime logging and hit probes

Co-authored-by: lbb <mr@lbb00.com>

* feat(debug): add switch latency and hit rate panel

Co-authored-by: lbb <mr@lbb00.com>

* revert(debug): remove switch metrics panel

Co-authored-by: lbb <mr@lbb00.com>

* refactor: fix security, perf, and architecture issues

- fix(security): replace hardcoded /opt/cursor/logs with app_data_dir()
- fix(security): add SSRF validation for proxy /stream and /warm endpoints
- perf(logger): replace blocking sync Mutex+file I/O with async mpsc channel writer thread
- refactor: remove excessive runtime logging in orchestrator, proxy, and commands
- refactor: extract useDualPlaybackEngine hook from VideoPlayer (SRP)
- refactor: split loadChannelInSlot into loadHlsSlot/loadMpegtsSlot/loadNativeSlot
- refactor: replace magic numbers with named constants

Amp-Thread-ID: https://ampcode.com/threads/T-019cd3cb-257d-77fc-bda5-bbaf67c96654
Co-authored-by: Amp <amp@ampcode.com>

* feat: Add Fast Channel Change (FCC) configuration toggle

- Add player.standbyEnabled setting with default value false
- Add resolver function resolveStandbyEnabled()
- Add toggle control in playback settings
- Conditionally load standby slot based on setting
- Add translations: Fast Channel Change / 快速换台

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8cb-6f2f-711b-8f4d-146bdd937388
Co-authored-by: Amp <amp@ampcode.com>

* feat: add console logging for standby preloading details

- Log neighbor warm plan with predicted and warm target channels
- Log user channel switches with direction
- Log channel loading to standby slots with prewarm flag
- Log slot ready status when stream connects
- Log slot activation with channel info
- Log slot destruction
- Log reasons when preloading is skipped

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>

* feat: expand to 3-slot playback engine with auto-cleanup

- Slot 0: prev channel (n-1)
- Slot 1: active channel (n) - always displayed
- Slot 2: next channel (n+1)

Benefits:
- Preload both adjacent channels for faster switching in both directions
- Auto-cleanup after 30s inactivity (user not switching channels)
- Single active slot simplifies playback logic
- Better console logging for 3-slot management

Changes:
- PlayerSlot type: 0 | 1 | 2 (prev/active/next)
- 3 video elements: prevVideoRef, activeVideoRef, nextVideoRef
- Separate prev/next slot helpers instead of toggle
- Inactivity timer clears unused slots after 30s
- Updated tests to match 3-slot architecture

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>

* fix: sync standby slot TTL with backend prewarm TTL

前端槽位清理时间(2500ms)现在与发送给后端的预热意图 TTL 保持一致。
确保前后端的资源管理同步:
- 后端 TTL 过期后停止预热
- 前端 TTL 过期后清理槽位
- 避免资源不同步或浪费

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>

* fix: separate slot TTL and backend prewarm TTL

- 槽位 TTL: 60s (1min) - 用户一分钟内的切台都能秒启动
- 后端预热 TTL: 2.5s - 后端及时释放用不到的预热资源

避免槽位占用过长时间,同时给用户充足的响应时间

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>

* refactor: rename useDualPlaybackEngine to useTripleSlotPlaybackEngine

'Dual' 已过时 - 现在支持 3 个槽位 + 双向预加载:
- 槽位 0: 上一频道 (n-1)
- 槽位 1: 当前频道 (n)
- 槽位 2: 下一频道 (n+1)

更准确的命名反映了实际的架构

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>

* refactor: rename to useStandbyPlayback - behavior-driven naming

强调行为而非数量:
- 预加载邻频道(prev/next)
- 无缝快速切台
- 1分钟内的任意切台都是秒启动

比 'TripleSlot' 更清晰地表达了核心能力

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>

* refactor: remove backend prewarm API, all preloading now frontend-driven

删除后端预热决策层:
- ❌ prewarm_submit_intents
- ❌ prewarm_report_primary
- ❌ prewarm_clear_source

改为前端单独管理:
- 预加载完全由 standbyEnabled 设置控制
- 3 个槽位生命周期由前端管理
- 60秒 TTL 自动清理

简化了架构:只有一层预加载逻辑,避免前后端冗余

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>

* refactor: rename standby to instant switch - better naming

完整的命名重构,强调行为而非实现细节:

前端:
- useStandbyPlayback → useInstantChannelSwitch
- StandbyPlaybackEngine → InstantChannelSwitchEngine
- [Standby] logs → [InstantSwitch] logs
- STANDBY_SLOT_TTL_MS → INSTANT_SWITCH_SLOT_TTL_MS

Settings:
- standbyEnabled → instantSwitchEnabled
- STANDBY_ENABLED_SETTING_KEY → INSTANT_SWITCH_ENABLED_SETTING_KEY
- player.standbyEnabled → player.instantSwitchEnabled

翻译:
- en-US: 'Fast Channel Change' → 'Instant Switch'
- zh-CN: '快速换台' → '即时切台'

Amp-Thread-ID: https://ampcode.com/threads/T-019cd8d6-f00e-7148-a2e4-0d93420aa95e
Co-authored-by: Amp <amp@ampcode.com>

* Fix player slot switching and tests

* Fix player slot switch robustness and proxy safety

* Fix desktop nav state and startup view

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Amp <amp@ampcode.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants