Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 调整并重构视频音频流的选择逻辑,应该可以提升些许性能 #212

Merged
merged 2 commits into from
Jan 13, 2025

Conversation

amtoaer
Copy link
Owner

@amtoaer amtoaer commented Jan 12, 2025

大部分是写法的重构,如:

  1. 重构初学 rust 时写的笨比代码 .is_xxx && .as_xxx.unwrap
  2. 避免对常量数组使用 vec! 导致的堆分配,.to_string() 调用移动至过滤后
  3. 程序仅需要获取 best_stream,使用 max_by() 代替 order_by().first() 以提升性能

此外,该 PR 还调整了流的排序逻辑,修复了两个问题:

  1. hdr、dolby、hires 的流不受 min max quality 约束
  2. 仅依赖 quality 枚举值大小导致的音频流排序错误

合并该 PR 后,应该能确保视频优先级顺序为:

// 没有特殊处理,按照优先级从低到高
pub enum VideoQuality {
    Quality360p = 16,
    Quality480p = 32,
    Quality720p = 64,
    Quality1080p = 80,
    Quality1080pPLUS = 112,
    Quality1080p60 = 116,
    Quality4k = 120,
    QualityHdr = 125,
    QualityDolby = 126,
    Quality8k = 127,
}

音频优先级顺序为:

// 排序时为 Dolby 和 HiRes 增加权重,实现 64k < 132k < 192k < Dolby < HiRes
pub enum AudioQuality {
    Quality64k = 30216,
    Quality132k = 30232,
    QualityDolby = 30250,
    QualityHiRES = 30251,
    Quality192k = 30280,
}

待补充单元测试。

@amtoaer amtoaer merged commit 7d9999d into main Jan 13, 2025
1 check passed
@amtoaer amtoaer deleted the feat_best_stream branch January 13, 2025 05:53
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.

1 participant