Post

Replies

Boosts

Views

Activity

Swift 6 concurrency error of passing sending closure
I am getting this error in a couple of places in my code with Task closure after setting Swift 6 as Language version in XCode. Passing closure as a 'sending' parameter risks causing data races between code in the current task and concurrent execution of the closure Below is minimally reproducible sample code. import Foundation final class Recorder { var writer = Writer() func startRecording() { Task { await writer.startRecording() print("started recording") } } func stopRecording() { Task { await writer.stopRecording() print("stopped recording") } } } actor Writer { var isRecording = false func startRecording() { isRecording = true } func stopRecording() { isRecording = false } } While making the class Recorder as Actor would fix the problem, I fear I will have to make too many classes as Actors in the class and in my scenario, there could be performance implications where real time audio and video frames are being processed. Further, I don't see any race condition in the code above. Does the error talk about possible race conditions that could arise if I were to call other functions on the self in future, or the current code itself is not safe?
0
2
525
Jan ’25
AVCaptureSession playback audio through headphones
I am using a RemoteIO unit along with AVCaptureSession to playback samples received from builtin or external microphone. The problem is AVCaptureSession freezes for few seconds in the startup if RemoteIO is simultaneously initialised. I want to know if there is a better and faster way to loopback samples received through AVCaptureAudioDataOutput to headphones? There is one sample code by Apple called AVCaptureToAudioUnit that uses AUGraph but it's pretty old and does not build anymore.
1
0
1.1k
Mar ’21
AVFoundation variable frame rate output
Does AVFoundation exports only have fixed frame rate output in presets other than passthrough? In other words, do AVAssetExportSession & AVAssetWriter/Reader output/input ever output variable frame rate video? If input video was 29.43 fps, I see output video is always 30 fps when I render using the above two interfaces. Looks like AVF applies a default video composition while rendering.
2
0
1.6k
Dec ’20
AVFoundation variable to constant frame rate question
I want to know how AVFoundation handles variable frame rate compositions. I create an AVMutableComposition from a bunch of videos (most have variable frame rate as iPhone camera never shoots videos at constant frame rate), then assign an AVVideoComposition with a custom defined frameDuration. Then if I playback this composition or render it using AVAssetExportSession/AVAssetWriter, will the output always be a constant frame rate video and will AVPlayer play it as constant frame rate (perhaps by dropping frames)? Also how do I specify frame rates such as 29.97 or 23.98 for rendering and playback?
3
0
1.5k
Nov ’20
UICollectionView compositional layout with variable length items
Is it possible to have horizontal scrolling 2D UICollectionView with cells which are variable in width but same in height without subclassing UICollectionViewLayout? Some items may be even more than the size of collectionView frame and the size of any two items is not the same in general and the gap between successive items may also be variable. WWDC videos say compositional layout can achieve anything we can imagine, not sure how to do this.
2
0
1.4k
Oct ’20
AVFoundation methods for smooth playback
Dear Apple Engineers, There seems to incomplete documentation about new AVFoundation methods introduced in iOS 14  @available(iOS 13.0, *)   optional func anticipateRendering(using renderHint: AVVideoCompositionRenderHint) @available(iOS 13.0, *) optional func prerollForRendering(using renderHint: AVVideoCompositionRenderHint) How do we exactly use these methods, when are they exactly called, how much time can we take to load texture from memory in these methods, what is the correct usage...can anyone explain?
1
0
605
Oct ’20
PHPickerViewController super buggy UI in multi-select mode
When in multi-selction mode (selectionLimit = 0), the PHPickerViewController almost everytime detects a scroll or swipe gesture as touch and selects the entire row of photos. It is so buggy that the user does not know which photos he inadvertently selected! While it is easy to use third party frameworks for this job, the biggest advantage of this picker is it doesn't need complex Photo Library permissions that are confusing users on iOS 14. Are Apple Engineers even aware of this serious bug that makes the picker almost useless for multi-selection mode?
2
0
1.4k
Oct ’20
PHPickerViewController load videos via PHAsset without permission
PHPickerViewController allows access to copies of photo library assets as well as returning PHAssets in the results. To get PHAssets instead of file copies, I do: let photolibrary = PHPhotoLibrary.shared() var configuration = PHPickerConfiguration(photoLibrary: photolibrary) configuration.filter = .videos configuration.selectionLimit = 0 let picker = PHPickerViewController(configuration: configuration) picker.delegate = self self.present(picker, animated: true, completion: nil) And then, 			func picker(_ picker: PHPickerViewController,		 didFinishPicking results: [PHPickerResult]) { picker.dismiss(animated: true) { let identifiers:[String] = results.compactMap(\.assetIdentifier) let fetchResult = PHAsset.fetchAssets(withLocalIdentifiers: identifiers, options: nil) NSLog("\(identifiers), \(fetchResult)") } } But the problem is once the photo picker is dismissed, it prompts for Photo Library access which is confusing and since the user anyways implicitly gave access to the selected assets in PHPickerViewController, PHPhotoLibrary should load those assets directly. Is there anyway to avoid the Photo library permission? The other option to copy the assets in the app is a waste of space for editing applications.
0
0
1.2k
Oct ’20