tiny-pilot / tinypilot

Use your Raspberry Pi as a browser-based KVM.
https://tinypilotkvm.com
MIT License
3.05k stars 255 forks source link

Refactor code around video settings to avoid duplications #1156

Closed jotaen4tinypilot closed 1 year ago

jotaen4tinypilot commented 2 years ago

⚠️ Note: this refactoring is blocked on https://github.com/tiny-pilot/tinypilot/issues/1114 (i.e., after the eventual H264 release). This is to avoid significant delays in the H264 roll-out.


Currently, we have two video settings: jpegQuality and videoFps. In order for us to get and set the value, and to retrieve the default value, we need (per setting):

That totals at almost 200 LOC per setting, so 400 LOC for both. The code is practically identical.

I assume we have intentionally opted for duplication and fine-granularity when originally implementing this, because back then it probably wasn’t as clear how the video settings feature would evolve over time.

I think the situation is much clearer now. We are also about to bring in a third parameter h264Bitrate, which will work in the exact same way as the existing two – adding another 200 LOC.

So I think it should be safe for us to invest into a clean-up at this point.

Refactoring goals

Tasks / PRs

(Prioritised)

jotaen4tinypilot commented 2 years ago

@mtlynch I slotted this ticket for 2.5.1 as suggestion, because I thought it would make sense to get it done timely (though after all other H264 work in any event). Please feel free to defer. My estimate would be “medium”.

jotaen4tinypilot commented 1 year ago

I’ve updated the issue description with an actionable task list. I’d see most value in the first two items, because they will eliminate a lot of code repetitions; the last two (revising the naming) would be nice for code hygiene, but optional or at least deferable in my eyes.

mtlynch commented 1 year ago

Thanks, @jotaen4tinypilot. I think we should just do all of them this sprint. The last two are deferable, but they also seem like only a straightforward couple hours of work, if that.