-
Notifications
You must be signed in to change notification settings - Fork 57
Add support for custom user-managed data using AVIOContextOpaque
#245
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
base: master
Are you sure you want to change the base?
Conversation
|
Could I create a application-like example, demonstrating the API usage of If can, I shall put them under |
AVIOContextAVIOContextOpaque
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.
Pull Request Overview
This PR adds support for custom user-managed data using AVIOContextOpaque, enabling more flexible integration with asynchronous and multi-threaded scenarios where custom data types can be passed through the AVIO context. The implementation allows users to provide their own data structures (wrapped in Arc<Mutex> or similar) alongside custom read/write/seek callbacks.
Key changes:
- Introduces
AVIOContextOpaquestruct with generic type support for custom data - Refactors existing callback infrastructure to support generic opaque data types
- Updates
AVIOContextContainerenum to include the new opaque variant
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/avformat/avio.rs | Adds AVIOContextOpaque implementation with generic type support and refactors callback infrastructure |
| src/avformat/avformat.rs | Updates AVIOContextContainer enum to include opaque variant and simplifies pointer access pattern |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } | ||
|
|
||
| #[cfg(not(feature = "ffmpeg7"))] | ||
| unsafe extern "C" fn write_c<T: Send + Sync>( |
Copilot
AI
Aug 19, 2025
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.
There are two write_c functions defined with conflicting configurations. The second function at line 124-132 should be pub to match the visibility of other functions in the module.
| unsafe extern "C" fn write_c<T: Send + Sync>( | |
| pub unsafe extern "C" fn write_c<T: Send + Sync>( |
| } | ||
| } | ||
|
|
||
| impl Drop for AVIOContextOpaque { |
Copilot
AI
Aug 19, 2025
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.
The Drop implementation for AVIOContextOpaque doesn't handle the opaque data cleanup. The opaque pointer passed to avio_alloc_context needs to be properly freed, but there's no mechanism to recover and drop the Box<Opaque> that was leaked in alloc_context.
|
|
||
| // pub type ReadPacketCallback = Box<dyn FnMut(&mut Vec<u8>, &mut [u8]) -> i32 + Send + 'static>; | ||
| // pub type WritePacketCallback = Box<dyn FnMut(&mut Vec<u8>, &[u8]) -> i32 + Send + 'static>; | ||
| // pub type SeekCallback = Box<dyn FnMut(&mut Vec<u8>, i64, i32) -> i64 + Send + 'static>; |
Copilot
AI
Aug 19, 2025
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.
Remove commented-out code. These type aliases are now defined in the opaque module and should not be left as dead comments.
| // pub type SeekCallback = Box<dyn FnMut(&mut Vec<u8>, i64, i32) -> i64 + Send + 'static>; |
| @@ -1,5 +1,6 @@ | |||
| use std::{ | |||
| ffi::{c_void, CStr}, | |||
| marker::PhantomData, | |||
Copilot
AI
Aug 19, 2025
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.
PhantomData is imported but never used in the code. Remove this unused import.
| marker::PhantomData, |
For asynchronous and integrated cases, the usage of
AVIOContextcould be awkward. Imagine that you have a stream data to sync across thread, which could be read and written continuously, then to link it toAVIOContext, we must work hard. With newly-addedAVIOContextOpaque, we could do that: