Evita patch recording ripetute che distruggevano i muxer HLS (500 ops) e fa encoderare 1080p/720p con codec e bitrate coerenti al wizard. Co-authored-by: Cursor <cursoragent@cursor.com>
32 lines
983 B
Ruby
32 lines
983 B
Ruby
module Sessions
|
|
# Sceglie il preset più alto supportato dall'upload misurato (test rete).
|
|
class SelectQuality
|
|
UPLOAD_HEADROOM = 0.8
|
|
UPLOAD_HEADROOM_1080P = 1.0
|
|
|
|
PRESETS = [
|
|
{ id: "1080p_30_4.5mbps", target_bitrate: 4_500_000, target_fps: 30 },
|
|
{ id: "720p_30_4mbps", target_bitrate: 4_000_000, target_fps: 30 },
|
|
{ id: "720p_30_2.5mbps", target_bitrate: 2_500_000, target_fps: 30 },
|
|
{ id: "720p_30_1.5mbps", target_bitrate: 1_500_000, target_fps: 30 }
|
|
].freeze
|
|
|
|
def self.call(upload_mbps:)
|
|
new(upload_mbps: upload_mbps).call
|
|
end
|
|
|
|
def initialize(upload_mbps:)
|
|
@upload_mbps = upload_mbps.to_f
|
|
end
|
|
|
|
def call
|
|
PRESETS.find { |preset| upload_sufficient?(preset) } || PRESETS.last
|
|
end
|
|
|
|
def upload_sufficient?(preset)
|
|
headroom = preset[:id].start_with?("1080p") ? UPLOAD_HEADROOM_1080P : UPLOAD_HEADROOM
|
|
@upload_mbps >= (preset[:target_bitrate] / 1_000_000.0 * headroom)
|
|
end
|
|
end
|
|
end
|