Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@Brooooooklyn
Copy link
Owner

@Brooooooklyn Brooooooklyn commented Dec 25, 2025

Replace FFmpeg's internal reference counting (av_frame_clone) with Rust's Arc<RwLock> for sharing frame data. This eliminates dual reference counting and provides a single source of truth.

Key changes:

  • Add parking_lot dependency for better RwLock performance
  • Frame: remove try_clone(), add deep_clone() and into_shared()
  • Packet: remove try_clone() (0 callers)
  • VideoFrameInner/AudioDataInner: use Arc<RwLock>
  • VideoEncoder/AudioEncoder: share frames via Arc, deep_clone when mutation needed
  • ImageDecoder: cache frames as Arc for efficient multi-access

🤖 Generated with Claude Code


Note

Unifies frame ownership by replacing FFmpeg ref-counted clones with Rust Arc<RwLock<Frame>>, reducing copies and centralizing synchronization.

  • Add parking_lot and introduce Frame::deep_clone() and Frame::into_shared(); remove try_clone() usage throughout
  • Migrate AudioData/VideoFrame internals to Arc<RwLock<Frame>>; VideoFrame.clone() now shares backing data; expose frame_arc() and add from_internal_arc(_with_color_space)
  • Update VideoEncoder/AudioEncoder to accept/share frames via Arc and only deep_clone() when mutation or upload requires ownership; adjust scaling/copy paths to use read locks
  • ImageDecoder caches decoded frames as shared Arc frames and returns VideoFrame via shared constructors
  • Remove Packet::try_clone() and Clone impl (no callers)
  • Type definitions: document VideoFrame.clone() sharing semantics in index.d.ts

Written by Cursor Bugbot for commit 720f0c4. This will update automatically on new commits. Configure here.

Copilot AI review requested due to automatic review settings December 25, 2025 12:58
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors frame data sharing from FFmpeg's reference counting to Rust's Arc<RwLock<Frame>>, providing a unified approach to memory management and eliminating dual reference counting systems.

  • Replaces Frame::try_clone() with Frame::deep_clone() for full copies and Frame::into_shared() for Arc-based sharing
  • Updates VideoFrame, AudioData, encoders, and ImageDecoder to use Arc<RwLock<Frame>> internally
  • Removes unused Packet::try_clone() method and Clone trait implementation

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Cargo.toml Adds parking_lot dependency for non-poisoning RwLock with better performance
src/codec/frame.rs Replaces try_clone() with deep_clone() for full copies and adds into_shared() for Arc wrapping
src/codec/packet.rs Removes unused try_clone() method and Clone trait implementation
src/webcodecs/video_frame.rs Refactors to use Arc<RwLock> internally, adds from_internal_arc constructors, updates all frame access to use read locks
src/webcodecs/video_encoder.rs Updates to receive Arc<RwLock> from VideoFrame, uses deep_clone when mutation needed
src/webcodecs/audio_data.rs Refactors to use Arc<RwLock> internally, updates all frame access to use read locks
src/webcodecs/audio_encoder.rs Updates to use deep_clone() instead of try_clone()
src/webcodecs/image_decoder.rs Caches decoded frames as Arc<RwLock> for efficient multi-access
index.d.ts Updates documentation for VideoFrame.clone() method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Replace FFmpeg's internal reference counting (av_frame_clone) with
Rust's Arc<RwLock<Frame>> for sharing frame data. This eliminates
dual reference counting and provides a single source of truth.

Key changes:
- Add parking_lot dependency for better RwLock performance
- Frame: remove try_clone(), add deep_clone() and into_shared()
- Packet: remove try_clone() (0 callers)
- VideoFrameInner/AudioDataInner: use Arc<RwLock<Frame>>
- VideoEncoder/AudioEncoder: share frames via Arc, deep_clone when mutation needed
- ImageDecoder: cache frames as Arc for efficient multi-access

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@Brooooooklyn Brooooooklyn merged commit 733ba73 into main Dec 26, 2025
34 checks passed
@Brooooooklyn Brooooooklyn deleted the frame-lifetime branch December 26, 2025 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants