Skip to content

Add device server#4

Merged
varsill merged 9 commits into
single_niffrom
device_server
Dec 23, 2025
Merged

Add device server#4
varsill merged 9 commits into
single_niffrom
device_server

Conversation

@varsill
Copy link
Copy Markdown
Collaborator

@varsill varsill commented Dec 22, 2025

This PR:

  • adds DeviceServer
  • adds destroy function so that NIF resource can be explicitly freed before GC decides to free it (a workaround to solve a problem with too many encoders spawned at once in test)

@varsill varsill marked this pull request as ready for review December 22, 2025 11:55
@varsill varsill requested a review from mat-hek December 22, 2025 13:19
@varsill varsill mentioned this pull request Dec 22, 2025
Comment thread lib/vk_video.ex Outdated
Comment on lines +4 to +7

@impl true
def start(_start_type, _start_args) do
GenServer.start_link(Membrane.VKVideo.DeviceServer, nil, name: DeviceServer)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
@impl true
def start(_start_type, _start_args) do
GenServer.start_link(Membrane.VKVideo.DeviceServer, nil, name: DeviceServer)
alias Membrane.VKVideo.DeviceServer
@impl true
def start(_start_type, _start_args) do
GenServer.start_link(DeviceServer, [], name: DeviceServer)

Comment thread lib/device_server.ex Outdated

@spec get_device() :: {:ok, Native.t()} | no_return()
def get_device() do
GenServer.call(DeviceServer, :get_device)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
GenServer.call(DeviceServer, :get_device)
GenServer.call(__MODULE__, :get_device)

Comment thread native/vkvideo/src/lib.rs
.map_err(|err| Error::RaiseTerm(Box::new(err.to_string())))?;

let device_resource = ResourceArc::new(Resource::Device(DeviceResource { device }));
Ok((ok(), device_resource))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the point of wrapping the device in the ok tuple?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

it's just for the sake of convention, all the resources are returned in an ok tuple

@varsill varsill merged commit 8c15bfa into single_nif Dec 23, 2025
3 checks passed
varsill added a commit that referenced this pull request Dec 23, 2025
* Puts encoder and decoder into a single NIF

* Make Resource an Enum

* Fix function names

* Add device server (#4)

* Add create_device

* Fix the resource

* Add Device server and destroy function

--- 
Co-authored-by: Jerzy Wilczek <jerzy.wilczek@swmansion.com>
varsill added a commit that referenced this pull request Jan 9, 2026
* Return error message from all vk-video errors. Update typespecs. Add handling of tune in the encoder

* Add RateControl option

* Add test checking different configuration of the encoder. Raise errors instead of returning the error tuple

* Use DirtyIo scheduler for all NIF functions. Adjust tests to new filename

* Add :requires_gpu tag to encoder tests

* Add encoder element

* Update typespecs. Add tests for encoder. Add support for RateControl

* Add more tests for encoder

* Add docs for rate control structs

* Put encoder and decoder into a single NIF.  (#3)

* Make Resource an Enum

* Add device server (#4)

* Add create_device

* Add Device server and destroy function

* Fallback to 30 and warn if the framerate is needed but not provided via stream format nor options

---------
Co-authored-by: Jerzy Wilczek <jerzy.wilczek@swmansion.com>
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.

3 participants