Hi everybody, I'm trying to use the multi input of an usb device using the AVAudioEngine.
My aim is to connect different inputNode channels to 2 or more different audionode (f.e. mixer).
I'm able to get a spefic input channel from the engine inputNode with
OSStatus err = AudioUnitSetProperty(avEngine.inputNode.audioUnit, kAudioOutputUnitProperty_ChannelMap, kAudioUnitScope_Output, 1, outputChannelMap, propSize);
but this will change the routing to all the input node and to all the destination mixer nodes.
How to send channel 1 of inputNode to a mixerNode1 and channel 2 to another mixerNode2?
Explore the integration of media technologies within your app. Discuss working with audio, video, camera, and other media functionalities.
Post
Replies
Boosts
Views
Activity
Hi everyone, I need to add spatial video maker in my app which was wrote in objective-c. I found some reference code by swift, can you help me with converting the code to objective -c?
let left = CMTaggedBuffer(
tags: [.stereoView(.leftEye), .videoLayerID(leftEyeLayerIndex)], pixelBuffer: leftEyeBuffer)
let right = CMTaggedBuffer(
tags: [.stereoView(.rightEye), .videoLayerID(rightEyeLayerIndex)],
pixelBuffer: rightEyeBuffer)
let result = adaptor.appendTaggedBuffers(
[left, right], withPresentationTime: leftPresentationTs)
I need to capture 4k photos with 4:3 ratio from the camera. I can do this, but i want to disable video stabilization. I can disable video stabilization using the AVCaptureSessionPresetHigh preset. But AVCaptureSessionPresetHigh gives me a 16:9 photo with the surroundings cropped. Unfortunately, the 16:9 ratio does not solve my needs.
When I run the session using the AVCaptureSessionPresetPhoto preset and adding AVCapturePhotoOutput, I cannot turn off image stabilization.
self.capturePhotoOutput = AVCapturePhotoOutput.init()
self.captureDevice = AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera
, for: AVMediaType.video, position: .back)
do {
let input = try AVCaptureDeviceInput(device: self.captureDevice!)
self.captureSession = AVCaptureSession()
self.captureSession?.beginConfiguration()
self.captureSession?.sessionPreset = .photo
self.captureSession?.addInput(input)
if ((captureSession?.canAddOutput(capturePhotoOutput!)) != nil) {
captureSession?.addOutput(capturePhotoOutput!)
}
if let connection = capturePhotoOutput?.connection(with: .video) {
if connection.isVideoStabilizationSupported {
connection.preferredVideoStabilizationMode = .off
}
}
DispatchQueue.main.async { [self] in
self.capturePhotoOutput?.isHighResolutionCaptureEnabled = true
self.videoPreviewLayer = AVCaptureVideoPreviewLayer(session: self.captureSession!)
self.videoPreviewLayer?.videoGravity = .resizeAspectFill
self.videoPreviewLayer?.connection?.videoOrientation = .portrait
self.videoPreviewLayer?.frame = self.previewView.layer.frame
self.previewView.layer.insertSublayer(self.videoPreviewLayer!, at: 0)
}
self.captureSession?.commitConfiguration()
self.captureSession?.startRunning()
}
}
@objc private func handleTakePhoto(){
let photoSettings = AVCapturePhotoSettings()
if let photoPreviewType = photoSettings.availablePreviewPhotoPixelFormatTypes.first {
photoSettings.previewPhotoFormat = [kCVPixelBufferPixelFormatTypeKey as String:photoPreviewType]
photoSettings.isAutoStillImageStabilizationEnabled = false
capturePhotoOutput?.capturePhoto(with: photoSettings, delegate: self)
}
}
func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
if let dataImage = photo.fileDataRepresentation() {
print(UIImage(data: dataImage)?.size as Any)
let dataProvider = CGDataProvider(data: dataImage as CFData)
let cgImageRef: CGImage! = CGImage(jpegDataProviderSource: dataProvider!, decode: nil, shouldInterpolate: true, intent: .defaultIntent)
let image = UIImage(cgImage: cgImageRef, scale: 1.0, orientation: rotateImage(orientation: currentOrientation))
} else {
print("some error here")
}
}
As a temporary solution, I added only AVCaptureVideoDataOutput to the session without adding AVCapturePhotoOutput, and I can capture in 4:3 format with the captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) function. However, this time I cannot get a 4K image.
In short, I need to turn off video stabilization in a session with AVCapturePhotoOutput added.
self.captureDevice = AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera
, for: AVMediaType.video, position: .back)
do {
let input = try AVCaptureDeviceInput(device: self.captureDevice!)
self.captureSession = AVCaptureSession()
self.captureSession?.beginConfiguration()
self.captureSession?.sessionPreset = .photo
self.captureSession?.addInput(input)
videoDataOutput = AVCaptureVideoDataOutput()
videoDataOutput?.videoSettings = [
kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)
]
videoDataOutput?.setSampleBufferDelegate(self, queue: DispatchQueue(label: "videoQueue"))
if ((captureSession?.canAddOutput(videoDataOutput!)) != nil) {
captureSession?.addOutput(videoDataOutput!)
}
/* If I cancel the comment line, video stabilization is enabled.
if ((captureSession?.canAddOutput(capturePhotoOutput!)) != nil) {
captureSession?.addOutput(capturePhotoOutput!)
}
*/
DispatchQueue.main.async { [self] in
self.videoPreviewLayer = AVCaptureVideoPreviewLayer(session: self.captureSession!)
self.videoPreviewLayer?.videoGravity = .resizeAspectFill
self.videoPreviewLayer?.connection?.videoOrientation = .portrait
self.videoPreviewLayer?.frame = self.previewView.layer.frame
self.previewView.layer.insertSublayer(self.videoPreviewLayer!, at: 0)
}
self.captureSession?.commitConfiguration()
self.captureSession?.startRunning()
}
}
@objc private func handleTakePhoto(){
takePicture = true
}
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
if !takePicture {
return //we have nothing to do with the image buffer
}
//try and get a CVImageBuffer out of the sample buffer
guard let cvBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
return
}
let rect = CGRect(x: 0, y: 0, width: CVPixelBufferGetWidth(cvBuffer), height: CVPixelBufferGetHeight(cvBuffer))
let ciImage = CIImage.init(cvImageBuffer: cvBuffer)
let ciContext = CIContext()
let cgImage = ciContext.createCGImage(ciImage, from: rect)
guard cgImage != nil else {return }
let uiImage = UIImage(cgImage: cgImage!)
}
I'm trying to integrate Callkit into a Flutter app that uses webRTC for calls and I have an issue with taking calls on locked screen. CXAnswerCallAction requires to have the action.fulfill() method called after the connection is established. Here is a pice of code without waiting for establishment of the connection:
guard let call = self.callManager?.callWithUUID(uuid: action.callUUID) else{
action.fail()
return
}
call.data.isAccepted = true
self.answerCall = call
self.callManager?.updateCall(call)
sendEvent(SwiftCallKeepPlugin.ACTION_CALL_ACCEPT, call.data.toJSON())
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1200)) {
self.configureAudioSession()
}
action.fulfill()
}
This causes the connection time counter to be immediately visible on the screen, but the user still has to wait for connection establishment and can't hear anything.
Here is the code that waits for the establishment of the connection before calling action.fulfill():
if(self.awaitedConnection.uuid != uuid) {
action.fail()
} else if(self.awaitedConnection.isConnected) {
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1200)) {
self.configureAudioSession()
}
action.fulfill()
} else {
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(1000)) {
self.waitForConnection(uuid: uuid, action: action)
}
}
}
public func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
guard let call = self.callManager?.callWithUUID(uuid: action.callUUID) else{
action.fail()
return
}
call.data.isAccepted = true
self.answerCall = call
self.callManager?.updateCall(call)
self.awaitedConnection.uuid = action.callUUID
self.awaitedConnection.isConnected = false
sendEvent(wiftCallKeepPlugin.ACTION_CALL_ACCEPT, call.data.toJSON())
waitForConnection(uuid: action.callUUID, action: action)
}
Unfortunately, though it works great on iOS 15.7, on 17.3 it causes lack of audio, no sound and no recording. I also can't enable it later when the call is ongoing. For reference:
let session = AVAudioSession.sharedInstance()
do{
try session.setCategory(AVAudioSession.Category.playAndRecord, options: AVAudioSession.CategoryOptions.allowBluetooth)
try session.setMode(self.getAudioSessionMode(data?.audioSessionMode ?? "voiceChat"))
try session.setActive(data?.audioSessionActive ?? true)
try session.setPreferredSampleRate(data?.audioSessionPreferredSampleRate ?? 44100.0)
try session.setPreferredIOBufferDuration(data?.audioSessionPreferredIOBufferDuration ?? 0.005)
}catch{
print(error)
}
}
I can see in the docs of action.fulfill() that "You should only call this method from the implementation of a CXProviderDelegate method". I this the reason for the issue? But how can I do it if I need to wait for the connection asynchronously and the provider method is synchronous?
Hello everyone,
I'm relatively new to iOS development, and I'm currently working on a Flutter plugin package. I want to use the AVFAudio package to load instrument sounds from an SF2 file into different channels. Specifically, I'd like to load individual instruments from the SF2 file onto separate channels.
However, I've been struggling to find a way to achieve this. Could someone guide me on how to load SF2 instrument sounds into different channels using AVFAudio? I've tried various combinations of parameters (program number, soundbank MSB, and soundbank LSB), but none seem to work.
If anyone has experience with AVFAudio and SF2 files, I'd greatly appreciate your help. Perhaps there's a proven approach or a way to determine the correct values for these parameters? Should I use a soundfont editor to inspect specific values within the SF2 file?
Thank you in advance for any assistance!
Best regards,
Melih
Hello,
I am working on the Musickit web browser application. I have created my developer token as mentioned in the documentation.
When I call the authorize() method to authenticate, I get the Apple Music pop up as expected. However, after entering the user credentials and "allowing" access, I get the following error:
POST https://play.itunes.apple.com/WebObjects/MZPlay.woa/wa/webPlayerLogout 403 (Forbidden)
musickit.js:28 Uncaught (in promise) AUTHORIZATION_ERROR: Unauthorized
at https://js-cdn.music.apple.com/musickit/v3/musickit.js:28:269512
at Generator.next ()
at asyncGeneratorStep$u (https://js-cdn.music.apple.com/musickit/v3/musickit.js:28:266594)
at _next (https://js-cdn.music.apple.com/musickit/v3/musickit.js:28:266821)
I am using an user account with paid subscription to Apple Music.
With the JWT created, I am able to make API calls and receive the response for requests that do that need the userToken.
I am currently stuck at this step and would like some help to root cause this issue.
I’ve noticed that audio is locked into position with builds. It sometimes comes out the left ear, other times the right. I occasionally get it working with both, but the audio isn’t moving with head tracking.
I've seen other reports of this issue in the Unity support forums too.
Any ideas on how to fix this? Its being reported in my app reviews as a negative.
I can't seem to find an album using MusicKit containing RecordLabel. I am using album.with([..., .recordLabels, ...] but I only see an empty recordLabels collection returned for every album I am trying...
Is this actually available / populated through MusicKit?
Hi,
This Apple provided program “SideBySideToMVHEVC” removes the audio track from our videos resulting in useless content.
Advise for:
code changes required permitting keeping the audio track
Or
advise for Apple tools permitting re-inserting the audio track after “SideBySideToMVHEVC”
Sincerely,
Olaf
Hello everyone,
I was playing a livestream when I received the error -16831/START-TIME is too close to live returned from the AVPlayerItemNewErrorLogEntry function. I don't know why the error is returned.Can you explain to me the reason for this error?
I play livestream thì bị lỗi : -12888 -"Playlist File unchanged for longer than 1.5 * target duration" , I also read error -12888 in the documentation page 170: https://docs.huihoo.com/apple/wwdc/ 2018/502_measuring_and_optimizing_hls_performance.pdf but still don't understand the reason. Please explain to me the reason for the error?
How Can I update the cookies of the previously set m3u8 video in AVPlayer without creating the new AVURLAsset and replacing the AVPlayer current Item with it
Dear Team,
I am trying to add contact from QRCode. But it seems that the built-in QR code reader of
iphone camera isn't able to decode the FullName with space containing in last name correctly
ex:-Collin A. Al Miller.
I have attached all the screenshot for your reference.
Here are the examples:
When I am trying to focus iphone camera on QRCode the fullname (Collin A. Al Miller). scan the
The full name its giving the empty result without the fullname.
The attached screenshot details a)CameraQRNotWorking b)NotWorkingQRCOde
2)When i try to removed the blank space and tried to add comma or - in the full name its getting
recognised and its working perfectly.
The attached screenshot name a)CameraQRCodeWorking b)workingQRCODE
3)Both the full name are working perfectly in QR camera scanner of android
Collin A. Al-Miller or Collin A, Al Miller.
The attached screenshot name AndroidQRCODE
Hope this issue will get resolved in upcoming release. Kindly provide the feedback relatedto this
issue
Code to generate vcard
var str = "BEGIN:VCARD \n" +
"VERSION:2.1 \n" +
"FN:\("Collin A. Al Miller") \n" +
"TITLE:\("") \n"
if options.showPersonalPhone {
str.append(contentsOf: "item1.TEL;CELL:\("+91987654320") \n")
str.append(contentsOf: "item1.X-ABLabel:Mobile\n")
}
if options.showWorkPhone {
str.append(contentsOf: "item2.TEL;WORK;VOICE:\("+91987654320") \n")
str.append(contentsOf: "item2.X-ABLabel:Work Phone\n")
}
if options.showEmail {
str.append(contentsOf: "item3.EMAIL;WORK;INTERNET:\("test@gmail.com") \n")
str.append(contentsOf: "item3.X-ABLabel:Work Email\n")
}
if options.showWebsite {
str.append(contentsOf: "URL:www.test.com \n")
}
if options.showLocation {
str.append(contentsOf: "ADR;WORK:;;\("Bangalore") \n")
}
str.append(contentsOf: "END:VCARD")
We develop virtual instruments for Mac/AU and are trying to get our AU-Plugins and our Standalone player to work with Audio Workgroups.
When the Standalone App or Logic Pro is in the foreground and active all is well and as expected.
However when the App or Logic Pro is not in focus all my auxiliary threads are running on E-Cores. Even though they are properly joined to the processing thread's workgroup. This leads to a lot of audible drop outs because deadlines are not met anymore.
The processing thread itself stays on a p-core. But has to wait for the other threads to finish.
How can I opt out of this behaviour? Our users certainly have use cases where they expect the Player to run smoothly even though they currently have a different App in focus.
Dear Apple Engineers,
I have downloaded the FairPlay Streaming SDK 4.4 - In which i could able to make use of the fps_safari_hls_example.html file to make a successful playback of fairplay protected content in safari, by pointing our fairplay license server, .m3u8 file & certificate.
Now that, i'm trying to achieve the renewal concept, so i tried to use the fps_safari_hls_key_renewal.html file also setting up the ContentKeyDuration to 20sec in FP license server backend. But client didn't make any subsequent FP license request around when nearing 20th sec or post 20th sec. I wonder if this use case be achieved in safari,
the only extra functionality i could see in renewal html file is below piece of code
await runAndWaitForLicenseRequest(session, keyURI, () => {
session.update(stringToUInt8Array("renew"))
});
Based on the above piece, i assume that we are making sure that client to aware the when to renew the license. But in my case, there were no FP request is made , in-fact, this piece of code got executed immediate after the 1st FP license request call & protected media continues to play despite setting the ContentKeyDuration to 20sec with LIMITED as contentkeyType .
Could you please suggest on how to achieve the subsequent renewal request from client based on the ContentKeyDuration send in the CKC response using this sample renewal html file..? Is there any tewaks to be made in html file, kindly suggest.
I know there have been a lot of questions about playing back spatial/immersive/MV-HEVC video content on the Vision Pro. Today, I released an example player on GitHub that might answer some questions. Of course, without official documentation on some of these formats, it could be that Apple will eventually do something a little different. We'll just have to wait.
In the meantime: https://github.com/mikeswanson/SpatialPlayer
I am developing an app using a data cable to link a camera. When I enter the page for the first time, I can detect the camera device, and then when I exit the page and enter again, I cannot detect the linked camera.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
[self addImageCaptureCore];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self checkCameraConnection];
});
}
- (void)checkCameraConnection {
if (@available(iOS 13.0, *)) {
NSArray<ICDevice *> *connectedDevices = self.browser.devices;
if (connectedDevices.count > 0) {
NSLog(@"Camera is connected");
} else {
NSLog(@"Camera is not connected");
}
}
else {
// Fallback on earlier versions
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
if (@available(iOS 13.0, *)) {
if (self.cameraDevice) {
if (self.cameraDevice.hasOpenSession) {
[self.cameraDevice requestCloseSession];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.browser stop];
self.browser.delegate = nil;
self.browser = nil;
});
}
else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.browser stop];
self.browser.delegate = nil;
self.browser = nil;
});
}
}
} else {
// Fallback on earlier versions
}
}
- (void)addImageCaptureCore {
if (@available(iOS 13.0, *)) {
ICDeviceBrowser *browser = [[ICDeviceBrowser alloc] init];
browser.delegate = self;
[browser start];
self.browser = browser;
}
else {
}
}
#pragma mark - ICDeviceBrowserDelegate
- (void)deviceBrowser:(ICDeviceBrowser*)browser didAddDevice:(ICDevice*)device moreComing:(BOOL) moreComing API_AVAILABLE(ios(13.0)){
NSLog(@"Device name = %@",device.name);
if ([device isKindOfClass:[ICCameraDevice class]]) {
if ([device.capabilities containsObject:ICCameraDeviceCanAcceptPTPCommands]) {
ICCameraDevice *cameraDevice = (ICCameraDevice *)device;
cameraDevice.delegate = self;
[cameraDevice requestOpenSession];
self.cameraDevice = cameraDevice;
}
}
}
- (void)deviceBrowser:(ICDeviceBrowser*)browser didRemoveDevice:(ICDevice*)device moreGoing:(BOOL) moreGoing API_AVAILABLE(ios(13.0)){
if (self.cameraDevice) {
if (self.cameraDevice.hasOpenSession) {
[self.cameraDevice requestCloseSession];
self.cameraDevice.delegate = nil;
self.cameraDevice = nil;
}
else {
self.cameraDevice.delegate = nil;
self.cameraDevice = nil;
}
}
}
#pragma mark - ICCameraDeviceDelegate
- (void)cameraDevice:(ICCameraDevice*)camera didAddItems:(NSArray<ICCameraItem*>*) items API_AVAILABLE(ios(13.0)){
if (items.count > 0) {
ICCameraItem *latestItem = items.lastObject;
NSLog(@"name = %@",latestItem.name);
}
}
#pragma mark - ICDeviceDelegate
- (void)device:(ICDevice*)device didOpenSessionWithError:(NSError* _Nullable) error API_AVAILABLE(ios(13.0)){
if (error) {
NSLog(@"Failed to open session %@",error.localizedDescription);
}
else {
NSLog(@"open session success");
}
}
- (void)device:(ICDevice*)device didCloseSessionWithError:(NSError* _Nullable)error API_AVAILABLE(ios(13.0)){
if (error) {
NSLog(@"close session error = %@",error.localizedDescription);
}
else {
NSLog(@"didCloseSession");
}
}
- (void)didRemoveDevice:(ICDevice*)device {
}
Mediastreamvalidiator error:
all .m3u8 files relevant have already the REQ-VIDEO-LAYOUT="CH-STEREO" parameter set.
Nevertheless mediastreamvalidator check/reports for HLS Authoring Specification for Apple Devices states:
General requirements
Must Fix Issues
You MUST declare REQ-VIDEO-LAYOUT for variants containing other then standard monoscopic video
Variant #1
Hi hope all are well!
We've been working on a live streaming app and it's going quite well!
Just got the aspect ratio locked as desired.
Now the audio, its volume is extremely low. It sounds like it's using the headset mic instead of the bottom mic that's used on Facetime or on speakerphone calls.
We tried flipping cameras and specifying sample rates, almost every constraint in MediaConstraints - no go!
Is there any way to specify this?
Thanks in advance!
I'm currently working on an iPad application that uses a third party sdk to scan a drivers license, and then allows the user to take a picture of themselves. However, when the user is directed to the self photo view, the AVCaptureSession preview will freeze. The app as a whole does not freeze. Only the view preview. I believe this is an issue with the OS, because this only happens on iPad 9s. All the other iPads work fine. Has anyone else seen this issue? Also, is there anyway to see logs from the AVCaptureSession so I can see what is happening? Maybe there is a way I can see when it freezes and then restart it.