Skip to content

fixed an issue where the frame rate could not be configured when attaching a video using attachVideo.#1824

Merged
shogo4405 merged 2 commits intomainfrom
feature/video-attach-timing
Oct 26, 2025
Merged

fixed an issue where the frame rate could not be configured when attaching a video using attachVideo.#1824
shogo4405 merged 2 commits intomainfrom
feature/video-attach-timing

Conversation

@shogo4405
Copy link
Copy Markdown
Collaborator

Description & motivation

  • fixed memory-leak MediaMixer.
  • fixed an issue where the frame rate could not be configured when attaching a video using attachVideo.
try await mixer.attachVideo(AVCaptureDevice.default(for: .video), track: 0) { unit in
  try unit.setFrameRate(60)
}

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots:

@shogo4405 shogo4405 added this to the 2.2.1 milestone Oct 26, 2025
@shogo4405 shogo4405 force-pushed the feature/video-attach-timing branch from ead5974 to 2f13802 Compare October 26, 2025 14:37
@shogo4405 shogo4405 requested a review from Copilot October 26, 2025 14:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes two issues: a memory leak in MediaMixer and the inability to configure frame rate when attaching video devices. The key changes refactor device initialization to occur at attachment time rather than lazily, allowing configuration blocks to execute before devices are added to the capture session.

Key Changes:

  • Moved device initialization from lazy creation to attachment time, enabling proper configuration
  • Changed isMultiTrackAudioMixingEnabled from computed to stored property to fix memory leak
  • Added test coverage for memory leak fixes and video configuration functionality

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
HaishinKit/Sources/Mixer/MediaMixer.swift Removed initialization task and changed isMultiTrackAudioMixingEnabled to stored property; simplified attachVideo to delegate configuration to VideoCaptureUnit
HaishinKit/Sources/Mixer/VideoCaptureUnit.swift Refactored attachVideo to create VideoDeviceUnit instances at attachment time and apply configuration before session attachment
HaishinKit/Sources/Mixer/VideoDeviceUnit.swift Changed initialization to require device parameter; moved device setup from attachDevice to initializer; renamed data output class
HaishinKit/Sources/Mixer/AudioCaptureUnit.swift Refactored attachAudio to create AudioDeviceUnit at attachment time; added isMultiTrackAudioMixingEnabled parameter to initializer
HaishinKit/Sources/Mixer/AudioDeviceUnit.swift Changed initializer to require device parameter and perform full initialization; removed attachDevice method
HaishinKit/Sources/Mixer/DeviceUnit.swift Updated protocol to require device parameter in initializer
HaishinKit/Tests/Mixer/MediaMixerTests.swift Added test for video configuration and uncommented memory leak test
HaishinKit/Tests/Mixer/VideoDeviceUnitTests.swift Added new test file for VideoDeviceUnit memory leak verification
HaishinKit/Tests/Mixer/AudioDeviceUnitTests.swift Added new test file for AudioDeviceUnit memory leak verification

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return
}
try? configuration?(capture)
session.detachCapture(self.devices[track])
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

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

Potential crash when detaching a nil device. If devices[track] is nil (e.g., on first attachment), calling detachCapture with nil may cause issues depending on the implementation. Consider checking if the device exists before detaching: if let device = self.devices[track] { session.detachCapture(device) }

Suggested change
session.detachCapture(self.devices[track])
if let device = self.devices[track] {
session.detachCapture(device)
}

Copilot uses AI. Check for mistakes.
try session.configuration { _ in
for capture in devices.values where capture.device == device {
try? capture.attachDevice(nil, session: session, audioUnit: self)
session.detachCapture(self.devices[track])
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

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

Potential crash when detaching a nil device. If devices[track] is nil (e.g., on first attachment), calling detachCapture with nil may cause issues depending on the implementation. Consider checking if the device exists before detaching: if let device = self.devices[track] { session.detachCapture(device) }

Suggested change
session.detachCapture(self.devices[track])
if let device = self.devices[track] {
session.detachCapture(device)
}

Copilot uses AI. Check for mistakes.
@shogo4405 shogo4405 merged commit 1ddee19 into main Oct 26, 2025
1 check failed
@shogo4405 shogo4405 deleted the feature/video-attach-timing branch October 26, 2025 14:44
shogo4405 added a commit that referenced this pull request Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants