Skip to content

Commit

Permalink
Merge branch 'master' into Remove-Video-Device
Browse files Browse the repository at this point in the history
  • Loading branch information
YuAo authored Mar 15, 2022
2 parents e55424f + 1623b3d commit 109320e
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 27 deletions.
79 changes: 77 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,88 @@ name: Swift
on: [push, pull_request]

jobs:
build:
target_macOS:

runs-on: macOS-latest
name: Smoke Test (macOS)

runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: Select Xcode
run: sudo xcode-select --switch "$(find /Applications -mindepth 1 -maxdepth 1 ! -type l | grep "Xcode_[\.0-9]*app" | sort -V | tail -1)/Contents/Developer"
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v

target_iOS_simulator:

name: Smoke Test (iOS Simulator)

runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: Select Xcode
run: sudo xcode-select --switch "$(find /Applications -mindepth 1 -maxdepth 1 ! -type l | grep "Xcode_[\.0-9]*app" | sort -V | tail -1)/Contents/Developer"
- name: Build
run: xcodebuild build -scheme VideoIO -destination 'platform=iOS Simulator,name=iPhone 11' -workspace .
- name: Run tests
run: xcodebuild test -scheme VideoIO -destination 'platform=iOS Simulator,name=iPhone 11' -workspace .

target_tvOS_simulator:

name: Smoke Test (tvOS Simulator)

runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: Select Xcode
run: sudo xcode-select --switch "$(find /Applications -mindepth 1 -maxdepth 1 ! -type l | grep "Xcode_[\.0-9]*app" | sort -V | tail -1)/Contents/Developer"
- name: Build
run: xcodebuild build -scheme VideoIO -destination 'platform=tvOS Simulator,name=Apple TV' -workspace .
- name: Run tests
run: xcodebuild test -scheme VideoIO -destination 'platform=tvOS Simulator,name=Apple TV' -workspace .

target_iOS_device:

name: Build (iOS Device)

runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: Select Xcode
run: sudo xcode-select --switch "$(find /Applications -mindepth 1 -maxdepth 1 ! -type l | grep "Xcode_[\.0-9]*app" | sort -V | tail -1)/Contents/Developer"
- name: Build
run: xcodebuild build -scheme VideoIO -destination generic/platform=iOS -workspace .

target_tvOS_device:

name: Build (tvOS Device)

runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: Select Xcode
run: sudo xcode-select --switch "$(find /Applications -mindepth 1 -maxdepth 1 ! -type l | grep "Xcode_[\.0-9]*app" | sort -V | tail -1)/Contents/Developer"
- name: Build
run: xcodebuild build -scheme VideoIO -destination generic/platform=tvOS -workspace .

target_macCatalyst:

name: Smoke Test (macCatalyst)

runs-on: macos-latest

steps:
- uses: actions/checkout@v2
- name: Select Xcode
run: sudo xcode-select --switch "$(find /Applications -mindepth 1 -maxdepth 1 ! -type l | grep "Xcode_[\.0-9]*app" | sort -V | tail -1)/Contents/Developer"
- name: Build
run: xcodebuild build -scheme VideoIO -destination 'platform=macOS,variant=Mac Catalyst' -workspace .
- name: Run tests
run: xcodebuild test -scheme VideoIO -destination 'platform=macOS,variant=Mac Catalyst' -workspace .
23 changes: 2 additions & 21 deletions Sources/VideoIO/Camera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class Camera {
case cannotAddInput
case cannotAddOutput
case metadataObjectTypeNotAvailable
case noRequiredMediaTypeFoundOnDevice
}

public struct Configurator {
Expand Down Expand Up @@ -125,27 +126,7 @@ public class Camera {
}
let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: deviceTypes, mediaType: .video, position: position)
if let device = discoverySession.devices.first {
let newVideoDeviceInput = try AVCaptureDeviceInput(device: device)
self.captureSession.beginConfiguration()
if let currentVideoDeviceInput = self.videoDeviceInput {
self.captureSession.removeInput(currentVideoDeviceInput)
}
if self.captureSession.canAddInput(newVideoDeviceInput) {
self.captureSession.addInput(newVideoDeviceInput)
self.videoDeviceInput = newVideoDeviceInput
} else {
self.captureSession.commitConfiguration()
throw Error.cannotAddInput
}

if let connection = self.videoCaptureConnection {
self.configurator.videoConnectionConfigurator(self, connection)
}
self.captureSession.commitConfiguration()

try device.lockForConfiguration()
self.configurator.videoDeviceConfigurator(self, device)
device.unlockForConfiguration()
try self.switchToVideoCaptureDevice(device)
} else {
throw Error.noDeviceFound
}
Expand Down
22 changes: 18 additions & 4 deletions Sources/VideoIO/MultitrackMovieRecorder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,19 @@ public final class MultitrackMovieRecorder {

public var numberOfAudioTracks: Int

public init(videoTrackCount: Int, audioTrackCount: Int) {
public var shouldOptimizeForNetworkUse: Bool

@available(*, deprecated, renamed: "init(numberOfVideoTracks:numberOfAudioTracks:shouldOptimizeForNetworkUse:)")
public init(videoTrackCount: Int, audioTrackCount: Int, optimizeForNetworkUse: Bool = true) {
numberOfVideoTracks = videoTrackCount
numberOfAudioTracks = audioTrackCount
shouldOptimizeForNetworkUse = optimizeForNetworkUse
}

public init(numberOfVideoTracks: Int, numberOfAudioTracks: Int, shouldOptimizeForNetworkUse: Bool = true) {
self.numberOfAudioTracks = numberOfAudioTracks
self.numberOfVideoTracks = numberOfVideoTracks
self.shouldOptimizeForNetworkUse = shouldOptimizeForNetworkUse
}
}

Expand Down Expand Up @@ -135,7 +145,7 @@ public final class MultitrackMovieRecorder {
try? fileManager.removeItem(at: url)
self.assetWriter = try AVAssetWriter(url: url, fileType: fileType)
self.assetWriter.metadata = self.configuration.metadata
self.assetWriter.shouldOptimizeForNetworkUse = true
self.assetWriter.shouldOptimizeForNetworkUse = configuration.shouldOptimizeForNetworkUse
}

private func checkError() throws {
Expand Down Expand Up @@ -519,16 +529,20 @@ public final class MovieRecorder {
/// Set to `true` to record both video and audio.
public var hasAudio: Bool

public init(hasAudio: Bool) {
/// Set to `true` to write the file in a way that is more suitable for playback over a network.
public var shouldOptimizeForNetworkUse: Bool

public init(hasAudio: Bool, shouldOptimizeForNetworkUse: Bool = true) {
self.hasAudio = hasAudio
self.shouldOptimizeForNetworkUse = shouldOptimizeForNetworkUse
}
}

public let configuration: Configuration

public init(url: URL, configuration: Configuration) throws {
self.configuration = configuration
var internalConfiguration = MultitrackMovieRecorder.Configuration(videoTrackCount: 1, audioTrackCount: configuration.hasAudio ? 1 : 0)
var internalConfiguration = MultitrackMovieRecorder.Configuration(numberOfVideoTracks: 1, numberOfAudioTracks: configuration.hasAudio ? 1 : 0, shouldOptimizeForNetworkUse: configuration.shouldOptimizeForNetworkUse)
internalConfiguration.metadata = configuration.metadata
internalConfiguration.videoOrientation = configuration.videoOrientation
internalConfiguration.videoSettings = configuration.videoSettings
Expand Down

0 comments on commit 109320e

Please sign in to comment.