Conversation
native/vkvideo_decoder/src/lib.rs
Outdated
| let mut decoder = resource | ||
| .decoder_mutex | ||
| .try_lock() | ||
| .map_err(|_| Error::Term(Box::new(decoder_lock_failure())))?; |
There was a problem hiding this comment.
Do I understand correctly that we're ignoring the error here? If so, can we convert it to a string and raise instead?
There was a problem hiding this comment.
I've just realized that these errors are quite helpful when I started working on the encoder in #2 so I will return them as a String, along the error
There was a problem hiding this comment.
Then I'd just raise, at least if Rustler allows it
| - elixir/hex_publish: | ||
| requires: | ||
| - elixir/build_test | ||
| - elixir/test |
There was a problem hiding this comment.
instead of disabling tests here, I'd have a tag disable_on_ci added to each test and exclude it in test_helper
native/vkvideo_decoder/src/lib.rs
Outdated
| ) -> Result<(Atom, Vec<RawFrame<'a>>), Error> { | ||
| let mut decoder = resource | ||
| .decoder_mutex | ||
| .try_lock() |
There was a problem hiding this comment.
why try_lock here? In case another thread has locked the mutex we'll return error out of the function and (supposedly) never decode the frame, is this what you want?
There was a problem hiding this comment.
If I understand correctly, Rustler requires resource to be Sync+Send. Decoder is already Send but I needed to wrap it into Mutex to make it Sync.
At the same time, I don't expect the decoder to be used concurrently by different Erlang processes (and therfore different OS threads at the same time) - decode and flush are supposed to be called by a single Filter's process. If for whatever reason these NIFs are called from different Erlang processes and the lock attempt fails, it's fine that we return an error.
There was a problem hiding this comment.
if the nif will be dirtyio anyway why not just lock instead of try_lock?
There was a problem hiding this comment.
if the nif will be dirtyio anyway why not just lock instead of try_lock?
There was a problem hiding this comment.
if the nif will be dirtyio anyway why not just lock instead of try_lock?
There was a problem hiding this comment.
Oh, since it's just the matter of using lock vs try_lock I can surely make it lock.
I decided to use try_lock as the Mutex's purpose is solely to make Rustler happy about the resource being Sync so I felt it would be safer to fail immediately if the resource is used in a way it wasn't supposed to be used (i.e. concurrently).
If Rustler allowed for this, I would be happy with the resource being just Send as this is the only thing that I need to make the element work.
native/vkvideo_decoder/src/lib.rs
Outdated
| pub height: u32, | ||
| } | ||
|
|
||
| #[rustler::nif(schedule = "DirtyCpu")] |
There was a problem hiding this comment.
I don't know if DirtyCpu is correct here. Actual blocking in the decoder happens on waiting for the GPU to return the frames, and there shouldn't be much CPU processing, but I don't really understand the difference between dirty IO and CPU in NIFs
There was a problem hiding this comment.
Yeah, it sounds like DirtyIO then
lib/decoder.ex
Outdated
| %Membrane.RawVideo{ | ||
| height: frame.height, | ||
| width: frame.width, | ||
| pixel_format: :I420, |
There was a problem hiding this comment.
The frames are probably in NV12, not I420
|
One more thing I forgot about, Maybe creating multiple decoders with a separate instance and device for each one does work, but I dont think its the recommended way to do this. |
Hmm, it sounds as if we need some kind of a "Device server" which would obtain the |
Its fine to make multiple of them, I just think it's wasteful, since we don't need more than one. Definitely different os processes can have their own instances and it will be fine, we dont need to worry about that. I think a device server is the correct solution here. |
|
Hi @jerzywilczek - I've implemented some of the requested changes in #3 and #4, you can take a look there as well ;) |
jerzywilczek
left a comment
There was a problem hiding this comment.
looks good, hope to get these segfaults sorted soon
native/vkvideo/src/decoder.rs
Outdated
| let decoder_mutex = Mutex::new(decoder); | ||
| let decoder_resource = DecoderResource { decoder_mutex }; |
There was a problem hiding this comment.
| let decoder_mutex = Mutex::new(decoder); | |
| let decoder_resource = DecoderResource { decoder_mutex }; | |
| let decoder = Mutex::new(decoder); | |
| let decoder = DecoderResource { decoder_mutex }; |
(nit) shadowing is encouraged
native/vkvideo/src/encoder.rs
Outdated
| bytes: Binary, | ||
| pts_ns: Option<u64>, | ||
| ) -> Result<(Atom, EncodedFrame<'a>), Error> { | ||
| let encoder_resource = resource.encoder().ok_or_else(|| Error::BadArg)?; |
There was a problem hiding this comment.
| let encoder_resource = resource.encoder().ok_or_else(|| Error::BadArg)?; | |
| let Resource::Encoder(encoder_resource) = resource else { | |
| return Err(Error::BadArg); | |
| }; |
I dont know if you know you can do that.
I'm not saying you should change this, just wanted to make sure you know this exists
There was a problem hiding this comment.
Oh, that's nice, but I think I will leave it with ok_or_else for now
9d097e9 to
1fac062
Compare
|
closing in favour of #5 |
No description provided.