fix: Move Audio Input initialization shortly before startRecording
(#159)
* rename * Update AVAudioSession+updateCategory.swift * fix bootstrap script * Update CameraView+AVAudioSession.swift * move audio input adding lower * Activate AudioSession only when starting recording * format * Deactivate Audio Session * remove audio input before deactivating audio session * Update CameraView+AVAudioSession.swift * log time * Update CameraView+AVAudioSession.swift * measure time with `measureElapsedTime` * Update project.pbxproj * only log in debug builds * bootstrap with bridge (RNN new API) * Mark two funcs as `@inlinable` * format * Update ReactLogger.swift * Make audioWriter optional (allow videos without sound) * only log frame drop reason in DEBUG * Make audio writing entirely optional * format * Use function name as label for measureElapsedTime * Update MeasureElapsedTime.swift * Update MeasureElapsedTime.swift * Mark AudioWriter as finished * set `automaticallyConfiguresApplicationAudioSession` once * Add JS console logging * log to JS console for a few logs * Update AVAudioSession+updateCategory.swift * format * Update JSConsoleHelper.mm * catch log errors * Update ReactLogger.swift * fix docs * Update RecordingSession.swift * Immediatelly add audio input * Update CameraView+AVCaptureSession.swift * Update CameraView+AVCaptureSession.swift * Update ReactLogger.swift * immediatelly set audio session * extract * format * Update TROUBLESHOOTING.mdx * hmm * Update AVAudioSession+updateCategory.swift * Create secondary `AVCaptureSession` for audio * Configure once, start stop on demand * format * fix audio notification interruptions * docs
This commit is contained in:
20
ios/React Utils/JSConsoleHelper.h
Normal file
20
ios/React Utils/JSConsoleHelper.h
Normal file
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// JSConsoleHelper.h
|
||||
// VisionCamera
|
||||
//
|
||||
// Created by Marc Rousavy on 02.06.21.
|
||||
// Copyright © 2021 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <React/RCTBridge.h>
|
||||
#import <React/RCTLog.h>
|
||||
|
||||
@interface JSConsoleHelper : NSObject
|
||||
|
||||
typedef void (^ConsoleLogFunction) (RCTLogLevel level, NSString* message);
|
||||
|
||||
+ (ConsoleLogFunction) getLogFunctionForBridge:(RCTBridge*)bridge;
|
||||
|
||||
@end
|
60
ios/React Utils/JSConsoleHelper.mm
Normal file
60
ios/React Utils/JSConsoleHelper.mm
Normal file
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// JSConsoleHelper.mm
|
||||
// VisionCamera
|
||||
//
|
||||
// Created by Marc Rousavy on 02.06.21.
|
||||
// Copyright © 2021 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "JSConsoleHelper.h"
|
||||
|
||||
#import <React/RCTBridge.h>
|
||||
#import <ReactCommon/RCTTurboModule.h>
|
||||
#import <React/RCTBridge+Private.h>
|
||||
#import <jsi/jsi.h>
|
||||
#import "RCTBridge+runOnJS.h"
|
||||
|
||||
@implementation JSConsoleHelper
|
||||
|
||||
+ (const char *) getLogFunctionNameForLogLevel:(RCTLogLevel)level {
|
||||
switch (level) {
|
||||
case RCTLogLevelTrace:
|
||||
return "trace";
|
||||
case RCTLogLevelInfo:
|
||||
return "log";
|
||||
case RCTLogLevelWarning:
|
||||
return "warn";
|
||||
case RCTLogLevelError:
|
||||
case RCTLogLevelFatal:
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
+ (ConsoleLogFunction) getLogFunctionForBridge:(RCTBridge*)bridge {
|
||||
RCTCxxBridge *cxxBridge = (RCTCxxBridge *)bridge;
|
||||
if (!cxxBridge.runtime) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
jsi::Runtime* jsiRuntime = (jsi::Runtime*)cxxBridge.runtime;
|
||||
|
||||
return ^(RCTLogLevel level, NSString* message) {
|
||||
[bridge runOnJS:^{
|
||||
if (jsiRuntime != nullptr) {
|
||||
jsi::Runtime& runtime = *jsiRuntime;
|
||||
auto logFunctionName = [JSConsoleHelper getLogFunctionNameForLogLevel:level];
|
||||
try {
|
||||
auto console = runtime.global().getPropertyAsObject(runtime, "console");
|
||||
auto log = console.getPropertyAsFunction(runtime, logFunctionName);
|
||||
log.call(runtime, jsi::String::createFromAscii(runtime, [message UTF8String]));
|
||||
} catch (jsi::JSError& jsError) {
|
||||
NSLog(@"%@", message);
|
||||
NSLog(@"Failed to call `console.%s`: %s", logFunctionName, jsError.getMessage().c_str());
|
||||
}
|
||||
}
|
||||
}];
|
||||
};
|
||||
}
|
||||
|
||||
@end
|
@@ -8,16 +8,34 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
let context = "VisionCamera"
|
||||
|
||||
// MARK: - ReactLogger
|
||||
|
||||
enum ReactLogger {
|
||||
/**
|
||||
A function that logs to the JavaScript console.
|
||||
*/
|
||||
static var ConsoleLogFunction: ConsoleLogFunction?
|
||||
|
||||
/**
|
||||
Log a message to the console in the format of `VisionCamera.[caller-function-name]: [message]`
|
||||
|
||||
@discussion
|
||||
If the global ConsoleLogFunction is set, this function also logs to the JavaScript console (console.log, console.trace, console.warn or console.error)
|
||||
This function also always logs to [RCTDefaultLogFunction].
|
||||
In non-DEBUG builds, this function is no-op.
|
||||
*/
|
||||
@inlinable
|
||||
static func log(level: RCTLogLevel,
|
||||
message: String,
|
||||
alsoLogToJS: Bool = false,
|
||||
_ file: String = #file,
|
||||
_ lineNumber: Int = #line,
|
||||
_ function: String = #function) {
|
||||
RCTDefaultLogFunction(level, RCTLogSource.native, file, lineNumber as NSNumber, "\(context).\(function): \(message)")
|
||||
#if DEBUG
|
||||
if alsoLogToJS, let log = ConsoleLogFunction {
|
||||
log(level, "[native] VisionCamera.\(function): \(message)")
|
||||
}
|
||||
RCTDefaultLogFunction(level, RCTLogSource.native, file, lineNumber as NSNumber, "VisionCamera.\(function): \(message)")
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user