-
Notifications
You must be signed in to change notification settings - Fork 136
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
Fix: Create new texture when video frame size is changed. #137
Conversation
- To get callback ahead of buffer reallocation if the frame size is changed
- Now PlayerRegisterTexture & PlayerUnregisterTexture are renamed to PlayerCreateVideoOutlet & PlayerDeleteVideoOutlet. - Now method channel call no longer creates texture ahead of time, but when first frame of the video is received. - If a new media of different video dimensions is opened, the previous texture is deleted & new is created, whose ID is notified through the method channel. - Currently UnregisterTexture is causing exception. Not sure about the reason.
channel_->InvokeMethod( | ||
"PlayerTextureId", | ||
std::make_unique<flutter::EncodableValue>(flutter::EncodableMap( | ||
{{"playerId", player_id_}, {"textureId", nullptr}}))); |
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.
I decided to just change textureId
ValueNotifier<int?>
to null
before we unregister previous texture & register new one. I was hoping this could avoid the crash, atleast it would avoid "texture not registered."
Does the old texture get unregistered before you reallocate the pixel buffer here? dart_vlc/dartvlc/internal/events.h Line 146 in 09805e4
That's the critical part. If you reuse the same buffer with the new texture you gain nothing. Besides, the texture creation / deletion part in the video outlet might need synchronization. |
} | ||
|
||
void VideoOutlet::OnVideo(uint8_t* buffer, int32_t width, int32_t height) { | ||
if (width_ != width && height_ != height) { |
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.
You obviously want to recreate the texture if EITHER the width OR the height changes.
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.
silly mistake. 😅
I added dart_vlc/dartvlc/internal/events.h Lines 143 to 145 in 09805e4
dart_vlc/windows/dart_vlc_plugin.cc Lines 81 to 85 in 09805e4
VideoOutlet::DeleteTexture before video_frame_buffer_.reset(new uint8_t[size]); .
And I can confirm that a new
APOLOGIES picked the wrong thing. |
Where did you get this from? All texture operations in the texture registrar are thread safe: |
All I need to do is unmount |
In the unregistration path, the mutex only protects the map. The actual texture unregistration is performed asynchronously after the texture has been removed from the map. So even after |
Possibly the best would be to publish today's morning patch (that's critical, idk how old |
I wouldn't change anything on the Dart side. The buffer size doesn't need to match the visible video resolution. You can allocate a fixed buffer of 4096x4096 etc. and don't reallocate it. It shouldn't require any further changes. Having a larger buffer wouldn't even affect performance, as only the visible portion will get copied (both from VLC into the buffer and from the buffer to the GL_TEXTURE_2D used by Flutter). |
Changing C++ code (which will still need to be changed) vs temporarily adding a default argument in Dart.
Having high buffer size has actually caused CPU usage to be higher in my tests. And, I don't know but I actually tested out different frame sizes when adding dynamic buffer allocation. I'm just unaware how this is coming into sight now... Anyways, it's a problem for now. |
Exactly, because you've changed it for the You might want to take a look at your implementation 😄 dart_vlc/dartvlc/internal/events.h Lines 119 to 159 in bb55014
|
Literally only |
Hitesh. VLC doesn't know about your buffer size. Do you tell it the size somewhere? Nope. You tell it the |
I obviously meant the size that is being copied. The larger the dimensions, the larger the size being copied, and in our case that size is equal to the buffer itself. I didn't think about pre-defining a large buffer ahead of time & how I can avoid reinitialization. Apologies. I was possibly confused by all the stuff. |
It's ok. |
[WIP]
VideoResizeCallback
toPlayer::OnVideo
listener, to get callback ahead of buffer reallocation (if the frame size is changed).VideoOutlet::CreateNewTexture
), whose texture ID is notified through the method channel.UnregisterTexture
is causing exception (fromVideoOutlet::DeleteTexture
).