Skip to content

fix(windows): play audio-only media; re-extract native lib when its content changes - #255

Open
muthuraj57 wants to merge 1 commit into
kdroidFilter:masterfrom
muthuraj57:audio-only-windows
Open

muthuraj57 wants to merge 1 commit into
kdroidFilter:masterfrom
muthuraj57:audio-only-windows

Conversation

@muthuraj57

Copy link
Copy Markdown

Summary

On Windows, opening a file with no video track (MP3, WAV, Ogg Opus, ...) failed with MF_E_INVALIDSTREAMNUMBER (0xC00D36B3), because OpenMedia required a video stream. Media Foundation decodes these files fine, so this makes the video stream optional and fixes the end-of-media bugs this exposed:

  • Audio-only media opens: OpenMedia selects the video stream only if there is one (bHasVideo); a source with neither video nor audio is still rejected. ReadVideoFrame* return S_FALSE without video. On the Kotlin side a 0×0 size means audio-only instead of an error; the producer idles and the consumer reports position/progress from GetMediaPosition.
  • End of stream is detected by the audio thread: MF_SOURCE_READERF_ENDOFSTREAM was checked after the if (!mfSample) return 0; early return, so it was never seen. For audio-only media the audio thread now sets EOF.
  • Seek/play after the end works: seeking after the audio thread exited restarts it, and the producer keeps running after onPlaybackEnded (it used to break), so the next end is reported again.
  • Native library cache: NativeLibraryLoader reused the cached DLL when only the size matched, so an updated DLL of the same size kept running the old code (it did, while testing this). It now compares the content.

Test plan

Windows 11 x64:

  • MP3, WAV (12 min) and Ogg Opus files: duration, position, seek, onPlaybackEnded, seek + play after the end replays and fires the end again; CPU 0–1 %
  • HLS video (fMP4 with a separate audio rendition): plays and seeks as before
  • ktlintCheck adds no new findings, :mediaplayer:compileKotlinJvm passes
  • Windows arm64 (not tested)

…ontent changes

- OpenMedia no longer fails with MF_E_INVALIDSTREAMNUMBER when the source has
  no video stream: the video stream is optional, and media without both video
  and audio is still rejected.
- The audio thread now sees MF_SOURCE_READERF_ENDOFSTREAM (the flag was checked
  after the null-sample early return) and, for audio-only media, sets EOF.
- Seeking after the audio thread exited (end of media) restarts it.
- The producer keeps running after onPlaybackEnded, so seek + play after the
  end works and the next end is reported again.
- Audio-only position/progress come from GetMediaPosition.
- NativeLibraryLoader compared only the file size, so an updated DLL of the same
  size kept the stale cached copy; it now compares the content.

Tested on Windows 11 (x64) with MP3, WAV and Ogg Opus files (duration,
position, seek, end, replay) and an HLS video (unchanged).

This branch has not been deployed

No deployments
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.

2 participants