-
Notifications
You must be signed in to change notification settings - Fork 2
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
Added method addMoreFrames #39
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need an addMoreFrames function? Is this because you don't know exactly how many frames the sequence will have in advance? Or is this because you want to preload additional frames later? Or is there any other reason?
In your current pull request, you recreate all frames and input sources without destructing the old ones. This could cause memory leaks but is also, as far as I can estimate, no faster than an entire destruct/re-init of the sequence renderer.
Here are the reasons for needing the addMoreFrames method:
Implementation method:
As you suggested, destructing/re-initializing the FastImageSequence from the usage part is also a method, but the usage code would become ugly and hard to understand. More importantly, the video played with the image sequence may not be smooth whenever new frames are added. As you can see below, in situations where frames are added, it is handled to play continuously and smoothly. Additionally, it branches to moreFrame to help with performance as much as possible. https://github.com/kimhongyeon/fast-image-sequence/blob/5eb35966d080c18bcb962c04aca7b3a97060cb35/src/lib/FastImageSequence.ts#L373-L377 On the other hand, if the new image sequences being received from the server in real-time keep coming in at intervals smaller than a second, the addMoreFrames method will be called repeatedly. Considering this, it might be a good idea to handle such situations using throttling or debouncing. |
5eb3596
to
dc5283a
Compare
When will this PR be merged? |
Issue: #38
Fast Image Sequence Renderer, as it stands, is difficult to add frames to once initialized. It requires reinitialization to add more frames, which is inefficient and complicates the code since new images keep coming in over a short period, characteristic of streaming.
So, I have added the
addMoreFrames
method.When
addMoreFrames
is called while the image sequence is running after the instance has been created, the frames and sources are restructured, allowing images to be added seamlessly.To implement this, I moved some of the initialization logic from the constructor into a
struct
method. By callingstruct
in theconstructor
, it retains the same logic as before.In
addMoreFrames
, after modifyingthis.options.frames
, thestruct
method is called, followed by thedestruct
method to temporarily release resources like the canvas. Then, the original logic is executed with a few branching points. For example, when callingdrawingLoop
, it resumes from the previous playback point.As a result, when the image sequence needs to grow continuously like streaming, calling the
addMoreFrames
method allows it to function like video streaming.