Schedule Buffered Video Playback
Learn this problemProblem statement
A video contains one ordered frame per entry in readDurations. Reading begins at time 0. Frame i takes readDurations[i] milliseconds to read, and the next read begins immediately after the previous one finishes.
Playback must render every frame in order at exactly 25 frames per second. Therefore, if playback starts at time start, frame i is rendered at time start + 40 * i. A frame may be rendered exactly when its read finishes, but never before it is ready.
Use one sequential reader and one sequential renderer: read calls never overlap other read calls, render calls never overlap other render calls, and the read and render sequences may overlap each other.
Choose the earliest nonnegative playback start that prevents buffer underflow for every frame. Return an array containing the render timestamp of each frame.
Function
scheduleVideoFrames(readDurations: long[]) → long[]Examples
Example 1
readDurations = [10,10,10]return = [10,50,90]The frames become ready at times 10, 20, and 30. Starting playback at time 10 is sufficient, so the render calls occur at 10, 50, and 90.
Example 2
readDurations = [70,70,10]return = [100,140,180]The first two frames become ready at times 70 and 140. A start before 100 would request the second frame before it is ready. Starting at 100 is the earliest underflow-free choice.
Example 3
readDurations = [0,100,0]return = [60,100,140]The second frame is not ready until time 100. A playback start of 60 schedules that frame at time 100 while retaining the exact 40-millisecond cadence.
Constraints
1 <= readDurations.length <= 100000.0 <= readDurations[i] <= 10^9.- Every cumulative read time and render timestamp fits in a signed 64-bit integer.