Skip to content

fix: harden track listeners and the media recorder - #536

Merged
devopvoid merged 5 commits into
mainfrom
fix/recorder-listener-hardening
Nov 4, 2026
Merged

devopvoid merged 5 commits into
mainfrom
fix/recorder-listener-hardening

Conversation

@devopvoid

Copy link
Copy Markdown
Owner

Fixes failure paths in track listeners, the recorder and the media reader, and makes recording losses measurable.

  • A track listener that cannot be stored leaves the track before its observer is freed.
  • A recorder start that fails halfway is undone, and the recorder can be started again. encoded_observer_add allocates its handle first and no longer throws through the C interface.
  • A source is not opened when the protocol whitelist cannot be set.
  • MediaRecorder.getStats() reports dropped frames per track by cause, and the peak of the writer's queue.

Behavior change: new MediaRecorder(path) now throws FileAlreadyExistsException if the file exists. MediaRecorder(path, true) replaces it through a temporary file, once the recording is finished, so a recording without media no longer costs an earlier one.

MediaReader opened the source even if av_dict_set failed, without the limit on what it may reach. It now returns the error before avformat_open_input and frees the context.
The track got a bare pointer to the observer before addNativeRef stored its shared_ptr, so a failure there freed an observer WebRTC still called. It now leaves the track first, and addNativeRef reports a global reference that could not be created instead of storing a null one.
The writer started before the tracks were attached, and a failed attach went unnoticed. Tracks are now attached first and the writer started last, so that a failure takes the observers off again and leaves the recorder idle and startable. encoded_observer_add allocates its handle first, and returns null instead of throwing through the C interface.
A recorder emptied an existing file, and deleted it when it got no media, so an aborted attempt could cost an earlier recording. This changes the documented behavior: the constructor now throws FileAlreadyExistsException, and MediaRecorder(Path, boolean) replaces the file through a temporary file that takes its place only once finished.
COMPLETE speaks of what the recorder took, so applications could not tell how much it dropped before. MediaRecorder.getStats() now gives per track how many frames were dropped by cause, and the peak of the writer's queue. The result values stay as they are.
@devopvoid
devopvoid merged commit 77ce8e7 into main Nov 4, 2026
26 checks passed
@devopvoid
devopvoid deleted the fix/recorder-listener-hardening branch November 4, 2026 23:36
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.

1 participant