-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fixed issue: player navigates to removed frames when playing #8747
base: develop
Are you sure you want to change the base?
Conversation
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis update addresses a bug in the playback feature, preventing navigation to non-existent frames. It also modifies the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant AnnotationTopBarContainer
participant PlaybackLogic
User->>AnnotationTopBarContainer: Start Playback
AnnotationTopBarContainer->>PlaybackLogic: Check Frame Validity
alt Frame Valid
PlaybackLogic->>AnnotationTopBarContainer: Update Frame
else Frame Invalid
PlaybackLogic->>AnnotationTopBarContainer: Stop Playback
end
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
cvat-ui/src/containers/annotation-page/top-bar/top-bar.tsx (1)
228-228
: Consider using a more descriptive property nameThe property name
lockedPlayTimeout
could be more descriptive of its purpose. Consider renaming it toisPlaybackInProgress
orisFrameTransitionLocked
to better convey its role in preventing concurrent frame transitions during playback.- private lockedPlayTimeout: boolean; + private isPlaybackInProgress: boolean; constructor(props: Props) { super(props); - this.lockedPlayTimeout = false; + this.isPlaybackInProgress = false;Also applies to: 233-233
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
changelog.d/20241127_145739_sekachev.bs_simplified_navigation.md
(1 hunks)cvat-ui/src/containers/annotation-page/top-bar/top-bar.tsx
(3 hunks)
✅ Files skipped from review due to trivial changes (1)
- changelog.d/20241127_145739_sekachev.bs_simplified_navigation.md
🔇 Additional comments (1)
cvat-ui/src/containers/annotation-page/top-bar/top-bar.tsx (1)
586-605
: Overall implementation effectively addresses the playback issue
The changes successfully prevent navigation to removed frames during playback by:
- Adding a lock mechanism to prevent concurrent frame transitions
- Using
frames.search
withnotDeleted: true
to find valid frames - Properly handling the case when no valid next frame is found
The implementation is sound and effectively fixes the reported issue.
if (playing && canvasIsReady && !frameFetching && !this.lockedPlayTimeout) { | ||
this.lockedPlayTimeout = true; | ||
setTimeout(async () => { | ||
const { playing: stillPlaying } = this.props; | ||
this.lockedPlayTimeout = false; | ||
|
||
if (stillPlaying) { | ||
const newFrame = await jobInstance.frames.search( | ||
{ notDeleted: true }, | ||
frameNumber + 1, | ||
jobInstance.stopFrame, | ||
); | ||
|
||
if (newFrame !== null && isAbleToChangeFrame(newFrame)) { | ||
onChangeFrame(newFrame, stillPlaying); | ||
} else { | ||
onSwitchPlay(false); | ||
} | ||
}, frameDelay); | ||
} else { | ||
onSwitchPlay(false); | ||
} | ||
} | ||
}, frameDelay); |
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.
🛠️ Refactor suggestion
Enhance error handling and maintainability of the play method
The play method implementation could be improved in several ways:
- Add error handling for the async frame search operation
- Extract frame search logic into a separate method
- Add TypeScript return type annotation
- Consider removing redundant playing check
Consider refactoring the method like this:
- private play(): void {
+ private async play(): Promise<void> {
const {
jobInstance,
frameNumber,
frameDelay,
frameFetching,
playing,
canvasIsReady,
onSwitchPlay,
onChangeFrame,
} = this.props;
- if (playing && canvasIsReady && !frameFetching && !this.lockedPlayTimeout) {
- this.lockedPlayTimeout = true;
- setTimeout(async () => {
- const { playing: stillPlaying } = this.props;
- this.lockedPlayTimeout = false;
+ if (playing && canvasIsReady && !frameFetching && !this.isPlaybackInProgress) {
+ this.isPlaybackInProgress = true;
+ try {
+ await new Promise((resolve) => setTimeout(resolve, frameDelay));
+ const newFrame = await this.findNextPlayableFrame(frameNumber);
+ if (newFrame !== null && isAbleToChangeFrame(newFrame)) {
+ onChangeFrame(newFrame, playing);
+ } else {
+ onSwitchPlay(false);
+ }
+ } catch (error) {
+ console.error('Failed to advance frame during playback:', error);
+ onSwitchPlay(false);
+ } finally {
+ this.isPlaybackInProgress = false;
+ }
+ }
+ }
- if (stillPlaying) {
- const newFrame = await jobInstance.frames.search(
- { notDeleted: true },
- frameNumber + 1,
- jobInstance.stopFrame,
- );
-
- if (newFrame !== null && isAbleToChangeFrame(newFrame)) {
- onChangeFrame(newFrame, stillPlaying);
- } else {
- onSwitchPlay(false);
- }
- }
- }, frameDelay);
- }
+ private async findNextPlayableFrame(currentFrame: number): Promise<number | null> {
+ const { jobInstance } = this.props;
+ return jobInstance.frames.search(
+ { notDeleted: true },
+ currentFrame + 1,
+ jobInstance.stopFrame,
+ );
}
This refactoring:
- Adds proper error handling with try/catch
- Extracts frame search logic into a separate method
- Uses async/await consistently
- Removes the redundant playing check
- Adds TypeScript return type annotations
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (playing && canvasIsReady && !frameFetching && !this.lockedPlayTimeout) { | |
this.lockedPlayTimeout = true; | |
setTimeout(async () => { | |
const { playing: stillPlaying } = this.props; | |
this.lockedPlayTimeout = false; | |
if (stillPlaying) { | |
const newFrame = await jobInstance.frames.search( | |
{ notDeleted: true }, | |
frameNumber + 1, | |
jobInstance.stopFrame, | |
); | |
if (newFrame !== null && isAbleToChangeFrame(newFrame)) { | |
onChangeFrame(newFrame, stillPlaying); | |
} else { | |
onSwitchPlay(false); | |
} | |
}, frameDelay); | |
} else { | |
onSwitchPlay(false); | |
} | |
} | |
}, frameDelay); | |
private async play(): Promise<void> { | |
const { | |
jobInstance, | |
frameNumber, | |
frameDelay, | |
frameFetching, | |
playing, | |
canvasIsReady, | |
onSwitchPlay, | |
onChangeFrame, | |
} = this.props; | |
if (playing && canvasIsReady && !frameFetching && !this.isPlaybackInProgress) { | |
this.isPlaybackInProgress = true; | |
try { | |
await new Promise((resolve) => setTimeout(resolve, frameDelay)); | |
const newFrame = await this.findNextPlayableFrame(frameNumber); | |
if (newFrame !== null && isAbleToChangeFrame(newFrame)) { | |
onChangeFrame(newFrame, playing); | |
} else { | |
onSwitchPlay(false); | |
} | |
} catch (error) { | |
console.error('Failed to advance frame during playback:', error); | |
onSwitchPlay(false); | |
} finally { | |
this.isPlaybackInProgress = false; | |
} | |
} | |
} | |
private async findNextPlayableFrame(currentFrame: number): Promise<number | null> { | |
const { jobInstance } = this.props; | |
return jobInstance.frames.search( | |
{ notDeleted: true }, | |
currentFrame + 1, | |
jobInstance.stopFrame, | |
); | |
} |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #8747 +/- ##
===========================================
+ Coverage 74.04% 74.05% +0.01%
===========================================
Files 409 409
Lines 43786 43784 -2
Branches 3984 3984
===========================================
+ Hits 32420 32423 +3
+ Misses 11366 11361 -5
|
Motivation and context
How has this been tested?
Checklist
develop
branch(cvat-canvas,
cvat-core,
cvat-data and
cvat-ui)
License
Feel free to contact the maintainers if that's a concern.
Summary by CodeRabbit
Bug Fixes
New Features