Skip to content

Commit 6876978

Browse files
committed
Consolidate settings into one struct
1 parent 94cb611 commit 6876978

File tree

9 files changed

+228
-88
lines changed

9 files changed

+228
-88
lines changed

Sources/MuxUploadSDK/PublicAPI/MuxUpload+AVFoundation.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@ extension MuxUpload {
1010
public convenience init(
1111
uploadURL: URL,
1212
inputAsset: AVAsset,
13-
transportSettings: TransportSettings = TransportSettings(),
14-
optOutOfEventTracking: Bool,
15-
standardizationSettings: StandardizationSettings = .enabled(resolution: .preset1920x1080)
13+
settings: UploadSettings
1614
) {
17-
1815
let input = UploadInput(status: .ready(inputAsset))
1916

2017
self.init(
2118
input: input,
22-
transportSettings: transportSettings,
23-
optOutOfEventTracking: optOutOfEventTracking,
24-
standardizationSettings: standardizationSettings,
19+
settings: settings,
2520
uploadManager: .shared
2621
)
2722
}

Sources/MuxUploadSDK/PublicAPI/MuxUpload+Photos.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ extension MuxUpload {
2626
using inputAsset: PHAsset,
2727
requestOptions: PHVideoRequestOptions,
2828
uploadURL: URL,
29-
transportsettings: TransportSettings = TransportSettings(),
30-
optOutOfEventTracking: Bool,
31-
standardizationSettings: StandardizationSettings = .enabled(resolution: .preset1920x1080),
29+
settings: UploadSettings,
3230
completion: @escaping (MuxUpload?) -> ()
3331
) {
3432

@@ -46,9 +44,7 @@ extension MuxUpload {
4644
MuxUpload(
4745
uploadURL: uploadURL,
4846
inputAsset: unwrappedAsset,
49-
transportSettings: transportsettings,
50-
optOutOfEventTracking: optOutOfEventTracking,
51-
standardizationSettings: standardizationSettings
47+
settings: settings
5248
)
5349
}
5450

Sources/MuxUploadSDK/PublicAPI/MuxUpload+Transport.swift

Lines changed: 0 additions & 24 deletions
This file was deleted.

Sources/MuxUploadSDK/PublicAPI/MuxUpload.swift

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public typealias UploadResult = Result<MuxUpload.Success, MuxUpload.UploadError>
1717
*/
1818
public final class MuxUpload: Hashable, Equatable {
1919

20+
private var settings: UploadSettings
2021
private var input: UploadInput
2122

2223
private var internalStatus: UploadInput.Status {
@@ -134,17 +135,37 @@ public final class MuxUpload: Hashable, Equatable {
134135

135136
}
136137

138+
/// Initializes a MuxUpload
139+
/// - Parameters:
140+
/// - uploadURL: the URL of the direct upload
141+
/// - videoFileURL: the file:// URL of the upload
142+
/// input
143+
/// - chunkSize: the size of chunks when uploading,
144+
/// at least 8M is recommended
145+
/// - retriesPerChunk: number of retry attempts for
146+
/// a failed chunk upload request
147+
/// - inputStandardization: enable or disable input
148+
/// standardization by the SDK locally
149+
/// - optOutOfEventTracking: opt out of event tracking
137150
public convenience init(
138151
uploadURL: URL,
139152
videoFileURL: URL,
140153
chunkSize: Int = 8 * 1024 * 1024, // Google recommends at least 8M
141154
retriesPerChunk: Int = 3,
142-
optOutOfEventTracking: Bool = false,
143-
standardizationSettings: StandardizationSettings = .enabled(resolution: .preset1920x1080)
155+
inputStandardization: UploadSettings.InputStandardization = .init(
156+
targetResolution: UploadSettings.InputStandardization.ResolutionPreset.default
157+
),
158+
optOutOfEventTracking: Bool = false
144159
) {
145-
let transportSettings = TransportSettings(
146-
chunkSize: chunkSize,
147-
retriesPerChunk: retriesPerChunk
160+
let uploadSettings = UploadSettings(
161+
inputStandardization: inputStandardization,
162+
transport: UploadSettings.Transport(
163+
chunkSize: chunkSize,
164+
retriesPerChunk: retriesPerChunk
165+
),
166+
eventTracking: UploadSettings.EventTracking(
167+
optedOut: optOutOfEventTracking
168+
)
148169
)
149170

150171
let inputSourceAsset = AVAsset(url: videoFileURL)
@@ -153,43 +174,37 @@ public final class MuxUpload: Hashable, Equatable {
153174

154175
self.init(
155176
input: input,
156-
optOutOfEventTracking: optOutOfEventTracking,
157-
standardizationSettings: standardizationSettings,
177+
settings: uploadSettings,
158178
uploadManager: .shared
159179
)
160180
}
161181

162182
public convenience init(
163183
uploadURL: URL,
164184
inputFileURL: URL,
165-
transportSettings: TransportSettings = TransportSettings(),
166-
optOutOfEventTracking: Bool,
167-
standardizationSettings: StandardizationSettings = .enabled(resolution: .preset1920x1080)
185+
settings: UploadSettings
168186
) {
169187
let inputSourceAsset = AVAsset(url: inputFileURL)
170188
let input = UploadInput(status: .ready(inputSourceAsset))
171189

172190
self.init(
173191
input: input,
174192
manage: true,
175-
transportSettings: transportSettings,
176-
optOutOfEventTracking: optOutOfEventTracking,
177-
standardizationSettings: standardizationSettings,
193+
settings: settings,
178194
uploadManager: .shared
179195
)
180196
}
181197

182198
init(
183199
input: UploadInput,
184200
manage: Bool = true,
185-
transportSettings: TransportSettings = TransportSettings(),
186-
optOutOfEventTracking: Bool,
187-
standardizationSettings: StandardizationSettings,
201+
settings: UploadSettings,
188202
uploadManager: UploadManager
189203
) {
190204
self.input = input
191205
self.manageBySDK = manage
192206
self.id = Int.random(in: Int.min...Int.max)
207+
self.settings = settings
193208
self.uploadManager = uploadManager
194209
}
195210

@@ -201,8 +216,7 @@ public final class MuxUpload: Hashable, Equatable {
201216

202217
self.init(
203218
input: input,
204-
optOutOfEventTracking: uploader.uploadInfo.optOutOfEventTracking,
205-
standardizationSettings: .disabled, // fix this
219+
settings: uploader.settings,
206220
uploadManager: .shared
207221
)
208222
self.fileWorker = uploader
@@ -282,7 +296,11 @@ public final class MuxUpload: Hashable, Equatable {
282296
cancel()
283297
}
284298
let completedUnitCount = UInt64({ self.lastSeenStatus.progress?.completedUnitCount ?? 0 }())
285-
let fileWorker = ChunkedFileUploader(uploadInfo: uploadInfo!, startingAtByte: completedUnitCount)
299+
let fileWorker = ChunkedFileUploader(
300+
uploadInfo: uploadInfo!,
301+
startingAtByte: completedUnitCount,
302+
settings: settings
303+
)
286304
fileWorker.addDelegate(
287305
withToken: id,
288306
InternalUploaderDelegate { [weak self] state in self?.handleStateUpdate(state) }
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
//
2+
// UploadSettings.swift
3+
//
4+
5+
import Foundation
6+
7+
public struct UploadSettings {
8+
9+
/// Settings to control the SDK network operations to
10+
/// transport the direct upload input to Mux
11+
public struct Transport {
12+
13+
/// At least 8M is recommended
14+
public var chunkSize: Int
15+
16+
/// Number of retry attempts per chunk if the
17+
/// associated request fails
18+
public var retriesPerChunk: Int
19+
20+
public init(
21+
chunkSize: Int = 8 * 1024 * 1024,
22+
retriesPerChunk: Int = 3
23+
) {
24+
self.chunkSize = chunkSize
25+
self.retriesPerChunk = retriesPerChunk
26+
}
27+
}
28+
29+
/// Transport settings for the direct upload
30+
public var transport: Transport
31+
32+
/// Settings controlling direct upload input standardization
33+
public struct InputStandardization {
34+
35+
/// If enabled the SDK will attempt to detect
36+
/// non-standard input formats and if so detected
37+
/// will attempt to standardize to a standard input
38+
/// format. ``true`` by default
39+
public var isEnabled: Bool = true
40+
41+
/// Preset to control the resolution of the standard
42+
/// input.
43+
///
44+
/// See ``UploadSettings.Standardization.targetResolution``
45+
/// for more details.
46+
public enum ResolutionPreset {
47+
/// Preset standardized upload input to the SDK
48+
/// default standard resolution of 1920x1080 (1080p).
49+
case `default`
50+
/// Preset standardized upload input to 1280x720
51+
/// (720p).
52+
case preset1280x720 // 720p
53+
/// Preset standardized upload input to 1920x1080
54+
/// (1080p).
55+
case preset1920x1080 // 1080p
56+
}
57+
58+
/// The preset resolution of the standardized upload
59+
/// input. If your input resolution is below 1920 by
60+
/// 1080 for the width and height, respectively, then
61+
/// the resolution will remain unchanged after input
62+
/// standardization.
63+
///
64+
/// Example 1: a direct upload input with 1440 x 1080
65+
/// resolution encoded using Apple ProRes and with
66+
/// no other non-standard input parameters with
67+
/// ``ResolutionPreset.default`` selected.
68+
///
69+
/// If input standardization is enabled, the SDK
70+
/// will attempt standardize the input into an H.264
71+
/// encoded output that will maintain its original
72+
/// 1440 x 1080 resolution.
73+
///
74+
/// Example 2: a direct upload input with 1440 x 1080
75+
/// resolution encoded using H.264 and with no other
76+
/// non-standard input format parameters with
77+
/// ``ResolutionPreset.preset1280x720`` selected.
78+
///
79+
/// If input standardization is enabled, the SDK will
80+
/// not make changes to the resolution of the input.
81+
/// The input will be uploaded to Mux as-is.
82+
///
83+
public var targetResolution: ResolutionPreset = .default
84+
85+
/// Disable all local input standardization by the SDK,
86+
/// any inputs provided to the `MuxUpload` instance
87+
/// along with this setting will be uploaded to Mux
88+
/// as they are with no local changes.
89+
public static let `disabled`: InputStandardization = InputStandardization(
90+
isEnabled: false,
91+
targetResolution: .default
92+
)
93+
94+
private init(
95+
isEnabled: Bool,
96+
targetResolution: ResolutionPreset
97+
) {
98+
self.isEnabled = isEnabled
99+
self.targetResolution = targetResolution
100+
}
101+
102+
///
103+
public init(
104+
targetResolution: ResolutionPreset
105+
) {
106+
self.isEnabled = true
107+
self.targetResolution = targetResolution
108+
}
109+
}
110+
111+
/// Input standardization settings for the direct upload
112+
public var inputStandardization: InputStandardization
113+
114+
///
115+
public struct EventTracking {
116+
117+
///
118+
public var optedOut: Bool
119+
120+
///
121+
public init(optedOut: Bool) {
122+
self.optedOut = optedOut
123+
}
124+
}
125+
126+
/// Event tracking settings for the direct upload
127+
public var eventTracking: EventTracking
128+
129+
/// - Parameters:
130+
/// - inputStandardization: settings to enable or
131+
/// disable standardizing the format of the direct
132+
/// upload inputs, enabled by default. To prevent the
133+
/// SDK from making any changes to the format of the
134+
/// input use ``UploadSettings.InputStandardization.disabled``
135+
/// - transport: settings for transporting the
136+
/// direct upload input to Mux
137+
/// - eventTracking: event tracking settings for the
138+
/// direct upload
139+
public init(
140+
inputStandardization: InputStandardization = InputStandardization(
141+
targetResolution: .default
142+
),
143+
transport: Transport = Transport(),
144+
eventTracking: EventTracking
145+
) {
146+
self.transport = transport
147+
self.inputStandardization = inputStandardization
148+
self.eventTracking = eventTracking
149+
}
150+
151+
}

Sources/MuxUploadSDK/PublicAPI/StandardizationSettings.swift

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)