From ea3cc7fd3b8a97043e60b27fc94a1e86e8e3e0d9 Mon Sep 17 00:00:00 2001 From: enm10k Date: Tue, 17 Oct 2023 13:02:40 +0900 Subject: [PATCH 1/3] =?UTF-8?q?AVCaptureDevice.Format=20=E3=81=AE=E9=81=B8?= =?UTF-8?q?=E6=8A=9E=E6=99=82=E3=81=AB=E3=83=95=E3=83=AC=E3=83=BC=E3=83=A0?= =?UTF-8?q?=E3=83=AC=E3=83=BC=E3=83=88=E3=82=92=E8=80=83=E6=85=AE=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 5 +++++ Sora/CameraVideoCapturer.swift | 13 +++++++++++-- Sora/PeerChannel.swift | 3 ++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 7af99951..fb023a68 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,11 @@ ## develop +- [FIX] AVCaptureDevice.Format の選択時にフレームレートを考慮するように修正する + - フレームレートに 60 を設定しても、 AVFrameRateRange が 1-30 の AVCaptureDevice.Format が選択されてしまうケースがあった + - 修正前は、カメラから同じ解像度の AVCaptureDevice.Format が複数取得された場合、最初に解像度が一致した AVCaptureDevice.Format を選択しており、フレームレートが考慮されていないという問題があった + - @enm10k + ## 2023.3.0 - [CHANGE] `@available(*, unavailable)` は廃止になるため削除する diff --git a/Sora/CameraVideoCapturer.swift b/Sora/CameraVideoCapturer.swift index 9a124a34..cad7e266 100644 --- a/Sora/CameraVideoCapturer.swift +++ b/Sora/CameraVideoCapturer.swift @@ -53,7 +53,7 @@ public final class CameraVideoCapturer { } /// 指定された設定に最も近い AVCaptureDevice.Format? を返します。 - public static func format(width: Int32, height: Int32, for device: AVCaptureDevice) -> AVCaptureDevice.Format? { + public static func format(width: Int32, height: Int32, for device: AVCaptureDevice, frameRate: Int? = nil) -> AVCaptureDevice.Format? { let formats = RTCCameraVideoCapturer.supportedFormats(for: device) var currentFormat: AVCaptureDevice.Format? var currentDiff = INT_MAX @@ -64,6 +64,14 @@ public final class CameraVideoCapturer { currentFormat = format currentDiff = diff } + + // 解像度が一致し、フレームレートもサポートされている場合はその format を返す + let fpsRanges = format.videoSupportedFrameRateRanges + if frameRate != nil && width == dimension.width && height == dimension.height && + fpsRanges.contains(where: { Int($0.minFrameRate) <= frameRate! && frameRate! <= Int($0.maxFrameRate) }) { + return format + } + } return currentFormat } @@ -98,7 +106,8 @@ public final class CameraVideoCapturer { let dimension = CMVideoFormatDescriptionGetDimensions(format.formatDescription) guard let format = CameraVideoCapturer.format(width: dimension.width, height: dimension.height, - for: flip.device) + for: flip.device, + frameRate: capturer.frameRate!) else { completionHandler(SoraError.cameraError(reason: "CameraVideoCapturer.format failed: suitable format is not found")) return diff --git a/Sora/PeerChannel.swift b/Sora/PeerChannel.swift index 6da114de..5ba14583 100644 --- a/Sora/PeerChannel.swift +++ b/Sora/PeerChannel.swift @@ -466,7 +466,8 @@ class PeerChannel: NSObject, RTCPeerConnectionDelegate { // デバイスに対応したフォーマットとフレームレートを取得する guard let format = CameraVideoCapturer.format(width: configuration.cameraSettings.resolution.width, height: configuration.cameraSettings.resolution.height, - for: capturer.device) + for: capturer.device, + frameRate: configuration.cameraSettings.frameRate) else { Logger.error(type: .peerChannel, message: "CameraVideoCapturer.suitableFormat failed: suitable format rate is not found") return From af15b61c011fb93c500844f3df98ba0a2813daf5 Mon Sep 17 00:00:00 2001 From: enm10k Date: Tue, 17 Oct 2023 15:17:28 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=E3=83=AD=E3=82=B8=E3=83=83=E3=82=AF?= =?UTF-8?q?=E3=82=92=E5=86=8D=E5=BA=A6=E8=A6=8B=E7=9B=B4=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sora/CameraVideoCapturer.swift | 37 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/Sora/CameraVideoCapturer.swift b/Sora/CameraVideoCapturer.swift index cad7e266..3cec4064 100644 --- a/Sora/CameraVideoCapturer.swift +++ b/Sora/CameraVideoCapturer.swift @@ -54,26 +54,31 @@ public final class CameraVideoCapturer { /// 指定された設定に最も近い AVCaptureDevice.Format? を返します。 public static func format(width: Int32, height: Int32, for device: AVCaptureDevice, frameRate: Int? = nil) -> AVCaptureDevice.Format? { - let formats = RTCCameraVideoCapturer.supportedFormats(for: device) - var currentFormat: AVCaptureDevice.Format? - var currentDiff = INT_MAX - for format in formats { + func calcDiff(_ targetWidth: Int32, _ targetHeight: Int32, _ format: AVCaptureDevice.Format) -> Int32 { let dimension = CMVideoFormatDescriptionGetDimensions(format.formatDescription) - let diff = abs(width - dimension.width) + abs(height - dimension.height) - if diff < currentDiff { - currentFormat = format - currentDiff = diff - } + return abs(targetWidth - dimension.width) + abs(targetHeight - dimension.height) + } - // 解像度が一致し、フレームレートもサポートされている場合はその format を返す - let fpsRanges = format.videoSupportedFrameRateRanges - if frameRate != nil && width == dimension.width && height == dimension.height && - fpsRanges.contains(where: { Int($0.minFrameRate) <= frameRate! && frameRate! <= Int($0.maxFrameRate) }) { - return format - } + let supportedFormats = RTCCameraVideoCapturer.supportedFormats(for: device) + // 指定された解像度に近いフォーマットを絞り込む + guard let diff = supportedFormats.map({ calcDiff(width, height, $0) }).min() else { + return nil + } + let formats = supportedFormats.filter { calcDiff(width, height, $0) == diff } + guard !formats.isEmpty else { + return nil + } + + // この関数の引数に frameRate が指定された場合、フレームレートも考慮する + guard let frameRate else { + return formats.first } - return currentFormat + return formats.filter { + $0.videoSupportedFrameRateRanges.contains(where: { + Int($0.minFrameRate) <= frameRate && frameRate <= Int($0.maxFrameRate) + }) + }.first ?? formats.first } /// 指定された FPS 値をサポートしているレンジが存在すれば、その値を返します。 From 0ab4d24475bbb12905e0fc3551813c73b1f6dc98 Mon Sep 17 00:00:00 2001 From: miosakuma Date: Tue, 24 Oct 2023 15:17:38 +0900 Subject: [PATCH 3/3] =?UTF-8?q?2023.3.1=20=E3=83=AA=E3=83=AA=E3=83=BC?= =?UTF-8?q?=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jazzy.yaml | 2 +- CHANGES.md | 3 +++ Sora.podspec | 2 +- Sora.xcodeproj/project.pbxproj | 4 ++-- Sora/PackageInfo.swift | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.jazzy.yaml b/.jazzy.yaml index 894b753e..b4df7114 100644 --- a/.jazzy.yaml +++ b/.jazzy.yaml @@ -8,7 +8,7 @@ theme: apple min_acl: public sdk: iphoneos module: Sora -module_version: 2023.3.0 +module_version: 2023.3.1 swift_version: 5.8.1 xcodebuild_arguments: - -parallelizeTargets diff --git a/CHANGES.md b/CHANGES.md index fb023a68..4c19ec52 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,9 @@ ## develop + +## 2023.3.1 + - [FIX] AVCaptureDevice.Format の選択時にフレームレートを考慮するように修正する - フレームレートに 60 を設定しても、 AVFrameRateRange が 1-30 の AVCaptureDevice.Format が選択されてしまうケースがあった - 修正前は、カメラから同じ解像度の AVCaptureDevice.Format が複数取得された場合、最初に解像度が一致した AVCaptureDevice.Format を選択しており、フレームレートが考慮されていないという問題があった diff --git a/Sora.podspec b/Sora.podspec index d0585d4f..968429b2 100644 --- a/Sora.podspec +++ b/Sora.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Sora" - s.version = "2023.3.0" + s.version = "2023.3.1" s.summary = "Sora iOS SDK" s.description = <<-DESC A library to develop Sora client applications. diff --git a/Sora.xcodeproj/project.pbxproj b/Sora.xcodeproj/project.pbxproj index ed95dbb1..fd05fe4b 100644 --- a/Sora.xcodeproj/project.pbxproj +++ b/Sora.xcodeproj/project.pbxproj @@ -586,7 +586,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 2023.3.0; + MARKETING_VERSION = 2023.3.1; PRODUCT_BUNDLE_IDENTIFIER = jp.shiguredo.sora.ios.sdk.Sora; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; @@ -620,7 +620,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - MARKETING_VERSION = 2023.3.0; + MARKETING_VERSION = 2023.3.1; PRODUCT_BUNDLE_IDENTIFIER = jp.shiguredo.sora.ios.sdk.Sora; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE = ""; diff --git a/Sora/PackageInfo.swift b/Sora/PackageInfo.swift index cae431b8..42f41c56 100644 --- a/Sora/PackageInfo.swift +++ b/Sora/PackageInfo.swift @@ -1,7 +1,7 @@ /// :nodoc: public enum SDKInfo { // Sora iOS SDK のバージョンを定義する - public static let version = "2023.3.0" + public static let version = "2023.3.1" } /**