Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Ensure video frames are stored in Rust allocated memory #131

Merged
merged 4 commits into from
Dec 19, 2017

Conversation

cpearce
Copy link
Contributor

@cpearce cpearce commented Dec 19, 2017

To resolve the problems in issue #112 and to remove the potential use-after-free which can happen if GeckoMedia shuts down and deallocates video frames before the compositor is finished painting video frames, switch to having the video frames stored in Rust allocated Vecs which are ref counted. This means we won't deallocate the memory until the last Rust or C++ user of the data is destroyed.

Chris Pearce added 4 commits December 19, 2017 16:19
This patch copies video frames coming out of Gecko/C++ and stores the
result in an Arc<Vec<u8>>. In a later commit, I'll make the pixel data
shared with C++, instead of being copied on every update_current_images()
call.
We create a VideoFrameAllocator that stores a list of refcounted Vec<u8>s
in which to store data. Each has a handle. When C++ wants to create a
new image, it calls into Rust, which creates a new Vec and copies the
image into it, and returns the handle to C++. The C++ code will associate
the handle with other frame metadata such as timestamp, and pass the
handle back to Rust code when the image is to be composited.

This should mean that Rust controls the lifetimes of images, as they're
stored in ref counted Rust memory.
})
.collect::<Vec<PlanarYCbCrImage>>()
let mut frames = vec![];
let video_frame_allocator = video_frame_allocator.lock().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: perhaps use try_unwrap() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't get this to work, looks like try_unwrap is on Rc only?

@cpearce
Copy link
Contributor Author

cpearce commented Dec 19, 2017

@bors-servo r=philn

@bors-servo
Copy link
Collaborator

📌 Commit 5ee2696 has been approved by philn

@bors-servo
Copy link
Collaborator

⌛ Testing commit 5ee2696 with merge d7dcfce...

bors-servo pushed a commit that referenced this pull request Dec 19, 2017
Ensure video frames are stored in Rust allocated memory

To resolve the problems in issue #112 and to remove the potential use-after-free which can happen if GeckoMedia shuts down and deallocates video frames before the compositor is finished painting video frames, switch to having the video frames stored in Rust allocated Vec<u8>s which are ref counted. This means we won't deallocate the memory until the last Rust or C++ user of the data is destroyed.
@bors-servo
Copy link
Collaborator

☀️ Test successful - status-travis
Approved by: philn
Pushing d7dcfce to master...

@bors-servo bors-servo merged commit 5ee2696 into master Dec 19, 2017
@cpearce cpearce deleted the planar-cleanup branch December 19, 2017 21:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants