Skip to content

Conversation

@azchohfi
Copy link
Contributor

@azchohfi azchohfi commented Jan 12, 2024

Creates a video_player_windows package that uses Windows' Media Foundation APIs to deliver a decent video player on windows.

Fixes: flutter/flutter#37673

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/packages repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

Very exciting!

I started to review but ran out of time for today after a few high level notes. Publishing those now so they don't have to wait for the rest of the review, but I'll try to do the real review ASAP since I'd love to see Windows support for video_player landed.

@azchohfi azchohfi force-pushed the video_player_windows branch from 0f6b79c to a2aa91b Compare January 13, 2024 03:01
@azchohfi
Copy link
Contributor Author

When I updated to 16.0.0 of Pigeon, found a bug: flutter/flutter#141499

@stuartmorgan-g
Copy link
Collaborator

When I updated to 16.0.0 of Pigeon, found a bug: flutter/flutter#141499

Thanks, that should probably be an easy fix.

FYI we're generally moving away from dartHostTestHandler in favor of just mocking/faking the host API itself, as we've generally found over time that it makes the tests simpler.

@azchohfi
Copy link
Contributor Author

@stuartmorgan I have no idea why the tests are timing out. They are working fine locally.

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

Just a little nit from me.

I think this generally looks great! I also don't have a lot of experience with c++ so I can't speak to best practices there.

@stuartmorgan-g
Copy link
Collaborator

@stuartmorgan I have no idea why the tests are timing out. They are working fine locally.

We have an ongoing problem in our Windows CI where some kinds of failures (even compile failures in at least some cases) somehow cause the CI to think something is still running and then they time out without much output, which unfortunately makes identifying the cause of a CI failure difficult. I'll try running the tests on my machine later today and see if I see any failures locally.

Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

I did a fairly high-level review, mostly about style guide notes, test structure, exceptions, Pigeon boundary. I haven't reviewed the specifics of the video implementation; I'll leave that to @cbracken since he'll most need to be familiar with it.

I haven't had a chance to play with it on my Windows machine yet, but I'm very much looking forward to seeing it in action :)

@azchohfi
Copy link
Contributor Author

Went through most of the comments and fixed most of the issues.

@stuartmorgan-g
Copy link
Collaborator

  • I'm getting logging from the engine about an event being sent from a non-platform thread. I'm going to see if I can quickly track that down.

Looks like this is the event_sink_ call in VideoPlayer::SendInitialized, which is coming from MFWorkItem::Invoke on a thread called (if I'm reading this VS UI correctly) ntdll.dll thread.

And then also VideoPlayer::SetBuffering on the same thread, from MediaEngineCallbackHelper::EventNotify

@stuartmorgan-g
Copy link
Collaborator

  • Resizing the window pretty reliably crashes

Running this under the debugger, in one case I saw an assertion failure in MediaEngineWrapper::EnsureTextureCreated; as with the earlier crash, it's texture_.put() being non-null.

But the actual crash seems to be an abort coming from deep in the Flutter engine on the raster thread. I don't have a debug engine on Windows so I don't have more detail. Given that it's resize, I'm guessing that the most likely situation is that a buffer is being destroyed while the engine is still using it.

@azchohfi
Copy link
Contributor Author

I created a generic RunOnMainThread method, that adds a delegate to a queue, registers a top-level Window Proc Delegate, which dequeues the delegate and run it. This solved these issues, but I think other plugins might benefit from this, as there is an equivalent in Android and iOS.

@stuartmorgan-g
Copy link
Collaborator

stuartmorgan-g commented Jan 23, 2024

This solved these issues, but I think other plugins might benefit from this, as there is an equivalent in Android and iOS.

flutter/flutter#134346 has some related discussion; we've considered, rejected, and now are reconsidering building that into the plugin APIs.

Your input there would be welcome as a significant stakeholder :)

@lucasjinreal

This comment was marked as off-topic.

@FZY456
Copy link

FZY456 commented Feb 22, 2024

Hello, I've found an issue with video_player_windows. It throws an error when playing a locally stored video file with a filename containing Chinese characters.

The error log is as follows:

 #0      WindowsVideoPlayerApi.create (package:video_player_windows/src/messages.g.dart:89:7)
 <asynchronous suspension>
 #1      WindowsVideoPlayer.create (package:video_player_windows/src/windows_video_player.dart:56:27)
 <asynchronous suspension>
 #2      VideoPlayerController.initialize (package:video_player/video_player.dart:434:19)

@stuartmorgan-g
Copy link
Collaborator

@FZY456 You've only included the stack there, not the actual error.

@FZY456
Copy link

FZY456 commented Feb 22, 2024

@FZY456 You've only included the stack there, not the actual error.

PlatformException(uri_load_failed, , null, null)

@stuartmorgan-g
Copy link
Collaborator

From triage: What's the current status of this PR? Is it just waiting for an updated review?

@azchohfi
Copy link
Contributor Author

azchohfi commented Apr 5, 2024

No, review is probably still updated, but there is work on my end. I just didn't have time to do yet. My bad.

@stuartmorgan-g stuartmorgan-g added the triage-windows Should be looked at in Windows triage label Jun 3, 2024
@Andrekarma

This comment was marked as off-topic.

@stuartmorgan-g
Copy link
Collaborator

From triage: @azchohfi Is this still something you're planning to come back to?

@azchohfi
Copy link
Contributor Author

azchohfi commented Aug 6, 2024

Unfortunately, I do not have time right now to look at this. I would say that most of the code works but it needs some tweaking to make it production ready. Feel free to work on top of this to get it merged.

@LeoSandbox

This comment was marked as off-topic.

@stuartmorgan-g
Copy link
Collaborator

As there isn't a planned timeline to finish this PR, I'm going to go ahead and close it to reflect the fact that it's not active. The issue has been marked as having a partial PR, and we encourage anyone in the community interested in this functionality to pick up the work from here.

@OutdatedGuy
Copy link
Contributor

For whoever willing to take the work from here, some observations on choppiness:

If you run the example app and switch to "Asset" tab, the butterfly video will start playing in a very choppy manner. Try making the window smaller by re-sizing it slowly and at some threshold the video starts playing smoothly.

On my machine, when the VideoPlayer size was 607.2 x 341.55 the video was playing smoothly and when the size was 608 x 342 the video became very choppy.

You can try it yourself by wrapping the VideoPlayer widget inside _ButterFlyAssetVideo with a LayoutBuilder:

LayoutBuilder(
  builder: (context, constraints) {
    print('VideoPlayer size: ${constraints.maxWidth} x ${constraints.maxHeight}');
    return VideoPlayer(_controller);
  },
),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: video_player platform-windows triage-windows Should be looked at in Windows triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[video_player] Add Windows support

9 participants