Skip to content

Commit c79a4e5

Browse files
authored
Releases/v0.6.0 (#97)
* Remove UIKit dependency (#90) * Replace use of UIDevice and use a different non-UIKit source * Version updates (#91) * docs: backfill missing inline API docs (#92) * feat: Foundation Measurement API for chunk size (#94) * refactor: Respell Version to SemanticVersion for explicitness in API (#95) * Rename revision to patch as in SemVer 2.0.0 * Rename Version to SemanticVersion for explicitness * Inline API docs and adjust indentation to match rest of the package * Lowercase to avoid casing issues (#98)
1 parent 27d9c64 commit c79a4e5

File tree

6 files changed

+189
-79
lines changed

6 files changed

+189
-79
lines changed

Mux-Upload-SDK.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22
s.name = 'Mux-Upload-SDK'
33
s.module_name = 'MuxUploadSDK'
4-
s.version = '0.3.1'
4+
s.version = '0.6.0'
55
s.summary = 'Upload video to Mux.'
66
s.description = 'A library for uploading video to Mux. Similar to UpChunk, but for iOS.'
77

Sources/MuxUploadSDK/InternalUtilities/Reporting/Reporter.swift

+55-20
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,36 @@
66
//
77

88
import Foundation
9-
import UIKit
9+
10+
fileprivate func processInfoOperationSystemVersion() -> String {
11+
let version = ProcessInfo().operatingSystemVersion
12+
return "\(version.majorVersion).\(version.minorVersion).\(version.patchVersion)"
13+
}
14+
15+
fileprivate func posixModelName() -> String {
16+
var systemName = utsname()
17+
uname(&systemName)
18+
return withUnsafePointer(to: &systemName.machine) {
19+
$0.withMemoryRebound(to: CChar.self, capacity: 1) {
20+
ptr in String.init(validatingUTF8: ptr)
21+
}
22+
} ?? "Unknown"
23+
}
24+
25+
fileprivate func inferredPlatformName() -> String {
26+
let modelName = posixModelName().lowercased()
27+
if modelName.contains("ipad") {
28+
return "iPadOS"
29+
} else if modelName.contains("iphone") {
30+
return "iOS"
31+
} else {
32+
#if targetEnvironment(simulator)
33+
return "Simulator"
34+
#else
35+
return "Unknown"
36+
#endif
37+
}
38+
}
1039

1140
class Reporter: NSObject {
1241

@@ -28,9 +57,11 @@ class Reporter: NSObject {
2857
var locale: Locale {
2958
Locale.current
3059
}
31-
var device: UIDevice {
32-
UIDevice.current
33-
}
60+
61+
let model: String
62+
let platformName: String
63+
let platformVersion: String
64+
3465
var regionCode: String? {
3566
if #available(iOS 16, *) {
3667
return locale.language.region?.identifier
@@ -52,6 +83,10 @@ class Reporter: NSObject {
5283
string: "https://mobile.muxanalytics.com"
5384
)!
5485

86+
self.model = posixModelName()
87+
self.platformName = inferredPlatformName()
88+
self.platformVersion = processInfoOperationSystemVersion()
89+
5590
super.init()
5691

5792
let sessionConfig: URLSessionConfiguration = URLSessionConfiguration.default
@@ -105,14 +140,14 @@ extension Reporter {
105140
let data = UploadSucceededEvent.Data(
106141
appName: Bundle.main.appName,
107142
appVersion: Bundle.main.appVersion,
108-
deviceModel: device.model,
143+
deviceModel: model,
109144
inputDuration: inputDuration,
110145
inputSize: inputSize,
111146
inputStandardizationRequested: options.inputStandardization.isRequested,
112-
platformName: device.systemName,
113-
platformVersion: device.systemVersion,
147+
platformName: platformName,
148+
platformVersion: platformVersion,
114149
regionCode: regionCode,
115-
sdkVersion: Version.versionString,
150+
sdkVersion: SemanticVersion.versionString,
116151
uploadStartTime: uploadStartTime,
117152
uploadEndTime: uploadEndTime,
118153
uploadURL: uploadURL
@@ -145,15 +180,15 @@ extension Reporter {
145180
let data = UploadFailedEvent.Data(
146181
appName: Bundle.main.appName,
147182
appVersion: Bundle.main.appVersion,
148-
deviceModel: device.model,
183+
deviceModel: model,
149184
errorDescription: errorDescription,
150185
inputDuration: inputDuration,
151186
inputSize: inputSize,
152187
inputStandardizationRequested: options.inputStandardization.isRequested,
153-
platformName: device.systemName,
154-
platformVersion: device.systemVersion,
188+
platformName: platformName,
189+
platformVersion: platformVersion,
155190
regionCode: regionCode,
156-
sdkVersion: Version.versionString,
191+
sdkVersion: SemanticVersion.versionString,
157192
uploadStartTime: uploadStartTime,
158193
uploadEndTime: uploadEndTime,
159194
uploadURL: url
@@ -186,15 +221,15 @@ extension Reporter {
186221
let data = InputStandardizationSucceededEvent.Data(
187222
appName: Bundle.main.appName,
188223
appVersion: Bundle.main.appVersion,
189-
deviceModel: device.model,
224+
deviceModel: model,
190225
inputDuration: inputDuration,
191226
inputSize: inputSize,
192227
maximumResolution: options.inputStandardization.maximumResolution.description,
193228
nonStandardInputReasons: nonStandardInputReasons.map(\.description),
194-
platformName: device.systemName,
195-
platformVersion: device.systemVersion,
229+
platformName: platformName,
230+
platformVersion: platformVersion,
196231
regionCode: regionCode,
197-
sdkVersion: Version.versionString,
232+
sdkVersion: SemanticVersion.versionString,
198233
standardizationStartTime: standardizationStartTime,
199234
standardizationEndTime: standardizationEndTime,
200235
uploadURL: uploadURL
@@ -229,16 +264,16 @@ extension Reporter {
229264
let data = InputStandardizationFailedEvent.Data(
230265
appName: Bundle.main.appName,
231266
appVersion: Bundle.main.appVersion,
232-
deviceModel: device.model,
267+
deviceModel: model,
233268
errorDescription: errorDescription,
234269
inputDuration: inputDuration,
235270
inputSize: inputSize,
236271
maximumResolution: options.inputStandardization.maximumResolution.description,
237272
nonStandardInputReasons: nonStandardInputReasons.map(\.description),
238-
platformName: device.systemName,
239-
platformVersion: device.systemVersion,
273+
platformName: platformName,
274+
platformVersion: platformVersion,
240275
regionCode: regionCode,
241-
sdkVersion: Version.versionString,
276+
sdkVersion: SemanticVersion.versionString,
242277
standardizationStartTime: standardizationStartTime,
243278
standardizationEndTime: standardizationEndTime,
244279
uploadCanceled: uploadCanceled,

Sources/MuxUploadSDK/PublicAPI/DirectUpload.swift

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import AVFoundation
99
import Foundation
1010

11+
/// Indicates whether a finished upload failed due to an error
12+
/// or succeeded along with details
1113
public typealias DirectUploadResult = Result<DirectUpload.SuccessDetails, DirectUploadError>
1214

1315
///
@@ -341,6 +343,9 @@ public final class DirectUpload {
341343
*/
342344
public var progressHandler: StateHandler?
343345

346+
/**
347+
Details about a ``DirectUpload`` after it successfully finished
348+
*/
344349
public struct SuccessDetails : Sendable, Hashable {
345350
public let finalState: TransportStatus
346351
}

Sources/MuxUploadSDK/PublicAPI/Options/DirectUploadOptions.swift

+105-38
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,65 @@
44

55
import Foundation
66

7+
// MARK: - Direct Upload Options
8+
79
/// Options for the direct upload
810
public struct DirectUploadOptions {
911

1012
// MARK: - Transport Options
1113

12-
/// Options to control the SDK network operations to
13-
/// transport the direct upload input to Mux
14+
/// Options for tuning network transport of direct upload
15+
/// chunks to Mux. Using the ``default`` is recommended
16+
/// for most applications.
1417
public struct Transport {
1518

16-
/// At least 8M is recommended
19+
/// The size of each file chunk in bytes sent by the
20+
/// SDK during an upload. At least 8MB is recommended.
1721
public var chunkSizeInBytes: Int
1822

19-
/// Number of retry attempts per chunk if the
20-
/// associated request fails
23+
/// Number of retry attempts per chunk if its upload
24+
/// request is unsuccessful
2125
public var retryLimitPerChunk: Int
2226

23-
/// A default set of transport options: 8MB chunk
24-
/// size and chunk request retry limit of 3
27+
/// Default options for ``DirectUpload`` chunk transport
28+
/// over the network. The chunk size is 8MB and the
29+
/// per-chunk retry limit is 3.
2530
public static var `default`: Transport {
2631
Transport(
2732
chunkSizeInBytes: 8 * 1024 * 1024,
2833
retryLimitPerChunk: 3
2934
)
3035
}
3136

32-
/// Initializes options that govern network transport
33-
/// by the SDK
34-
///
37+
/// Initializes options for transport of upload chunks
38+
/// over the network
3539
/// - Parameters:
36-
/// - chunkSize: the size of each file chunk in
37-
/// bytes the SDK sends when uploading, default
38-
/// value is 8MB
39-
/// - retriesPerChunk: number of retry attempts
40-
/// if the chunk request fails, default value is 3
40+
/// - chunkSize: the size of each file chunk sent
41+
/// by the SDK during an upload.
42+
/// Defaults to 8MB.
43+
/// - retryLimitPerChunk: number of times a failed
44+
/// chunk request is retried. Default limit is
45+
/// 3 retries.
46+
public init(
47+
chunkSize: Measurement<UnitInformationStorage> = .defaultDirectUploadChunkSize,
48+
retryLimitPerChunk: Int = 3
49+
) {
50+
self.chunkSizeInBytes = Int(
51+
abs(chunkSize.converted(to: .bytes).value)
52+
.rounded(.down)
53+
)
54+
self.retryLimitPerChunk = retryLimitPerChunk
55+
}
56+
57+
/// Initializes options for transport of upload chunks
58+
/// over the network
59+
/// - Parameters:
60+
/// - chunkSizeInBytes: the size of each file
61+
/// chunk in bytes the SDK uploads in a single
62+
/// request. Default chunk size is 8MB.
63+
/// - retryLimitPerChunk: number of times a failed
64+
/// chunk request is retried. Default limit is
65+
/// 3 retries.
4166
public init(
4267
chunkSizeInBytes: Int = 8 * 1024 * 1024,
4368
retryLimitPerChunk: Int = 3
@@ -47,12 +72,14 @@ public struct DirectUploadOptions {
4772
}
4873
}
4974

50-
/// Transport options for the direct upload
75+
/// Network transport options for direct upload chunks
5176
public var transport: Transport
5277

5378
// MARK: - Input Standardization Options
5479

55-
/// Options controlling direct upload input standardization
80+
/// Options for adjusments made by ``DirectUpload``
81+
/// to some inputs to minimize processing time during
82+
/// ingestion
5683
public struct InputStandardization {
5784

5885
/// If requested the SDK will attempt to detect
@@ -124,8 +151,8 @@ public struct DirectUploadOptions {
124151
maximumResolution: .default
125152
)
126153

127-
// Kept private to an invalid combination of parameters
128-
// being used for initialization
154+
// Kept private to avoid an invalid combination of
155+
// parameters being used for initialization
129156
private init(
130157
isRequested: Bool,
131158
maximumResolution: MaximumResolution
@@ -134,10 +161,8 @@ public struct DirectUploadOptions {
134161
self.maximumResolution = maximumResolution
135162
}
136163

137-
/// Used to initialize ``DirectUploadOptions.InputStandardization``
138-
/// with that enables input standardization with
139-
/// a maximum resolution
140-
///
164+
/// Initializes options that request input
165+
/// standardization with a custom maximum resolution
141166
/// - Parameters:
142167
/// - maximumResolution: the maximum resolution
143168
/// of the standardized input
@@ -186,12 +211,14 @@ public struct DirectUploadOptions {
186211

187212
// MARK: Direct Upload Options Initializers
188213

214+
/// Initializes options that dictate how the direct upload
215+
/// is carried out by the SDK
189216
/// - Parameters:
190-
/// - inputStandardization: options to enable or
191-
/// disable standardizing the format of the direct
192-
/// upload inputs, it is requested by default. To
193-
/// prevent the SDK from making any changes to the
194-
/// format of the input use ``DirectUploadOptions.InputStandardization.skipped``
217+
/// - inputStandardization: options related to input
218+
/// standardization. Input standardization is requested
219+
/// by default.
220+
/// To skip input standardization pass in
221+
/// ``DirectUploadOptions.InputStandardization.skipped``.
195222
/// - transport: options for transporting the
196223
/// direct upload input to Mux
197224
/// - eventTracking: event tracking options for the
@@ -206,19 +233,49 @@ public struct DirectUploadOptions {
206233
self.eventTracking = eventTracking
207234
}
208235

236+
/// Initializes options that dictate how the direct upload
237+
/// is carried out by the SDK
238+
/// - Parameters:
239+
/// - eventTracking: event tracking options for the
240+
/// direct upload
241+
/// - inputStandardization: options related to input
242+
/// standardization. Input standardization is requested
243+
/// by default.
244+
/// To skip input standardization pass in
245+
/// ``DirectUploadOptions.InputStandardization.skipped``.
246+
/// - chunkSize: The size of each file chunk sent by
247+
/// the SDK during an upload. Defaults to 8MB.
248+
/// - retryLimitPerChunk: number of retry attempts
249+
/// if the chunk request fails. Defaults to 3.
250+
public init(
251+
eventTracking: EventTracking = .default,
252+
inputStandardization: InputStandardization = .default,
253+
chunkSize: Measurement<UnitInformationStorage> = .defaultDirectUploadChunkSize,
254+
retryLimitPerChunk: Int = 3
255+
) {
256+
self.eventTracking = eventTracking
257+
self.inputStandardization = inputStandardization
258+
self.transport = Transport(
259+
chunkSize: chunkSize,
260+
retryLimitPerChunk: retryLimitPerChunk
261+
)
262+
}
263+
264+
/// Initializes options that dictate how the direct upload
265+
/// is carried out by the SDK
209266
/// - Parameters:
210267
/// - eventTracking: event tracking options for the
211268
/// direct upload
212-
/// - inputStandardization: options to enable or
213-
/// disable standardizing the format of the direct
214-
/// upload inputs, it is requested by default. To
215-
/// prevent the SDK from making any changes to the
216-
/// format of the input use ``DirectUploadOptions.InputStandardization.skipped``
217-
/// - chunkSize: the size of each file chunk in
218-
/// bytes the SDK sends when uploading, default
219-
/// value is 8MB
220-
/// - retriesPerChunk: number of retry attempts
221-
/// if the chunk request fails, default value is 3
269+
/// - inputStandardization: options related to input
270+
/// standardization. Input standardization is requested
271+
/// by default.
272+
/// To skip input standardization pass in
273+
/// ``DirectUploadOptions.InputStandardization.skipped``.
274+
/// - chunkSizeInBytes: The size of each file chunk
275+
/// in bytes sent by the SDK during an upload.
276+
/// Defaults to 8MB.
277+
/// - retryLimitPerChunk: number of retry attempts
278+
/// if the chunk request fails. Defaults to 3.
222279
public init(
223280
eventTracking: EventTracking = .default,
224281
inputStandardization: InputStandardization = .default,
@@ -237,6 +294,16 @@ public struct DirectUploadOptions {
237294

238295
// MARK: - Extensions
239296

297+
extension Measurement where UnitType == UnitInformationStorage {
298+
/// Default direct upload chunk size
299+
public static var defaultDirectUploadChunkSize: Self {
300+
Measurement(
301+
value: 8,
302+
unit: .megabytes
303+
)
304+
}
305+
}
306+
240307
extension DirectUploadOptions.InputStandardization.MaximumResolution: CustomStringConvertible {
241308
public var description: String {
242309
switch self {

0 commit comments

Comments
 (0)