Skip to content

Commit 460c31e

Browse files
committed
Upload Input Inspection and Standardization 1 (#17)
Add scaffolding Add initializers Add internal and external state mapping Remove duplicate status enum and add inline docs to external status Add inline API docs to PHAsset-based MuxUpload constructor Consolidate all `MuxUpload` options into a single struct `UploadOptions` Declare asynchronous MuxUpload constructor in PHAsset extension Place extension methods into dedicated directories Polish inline API documentation Add option variants as static members: defaults, disabled inputStandardization Deprecate existing initializer, normally this API should be removed prior to GA, but since it was the only initializer exposed up to this point removing it would break everybody. Instead deprecate and remove at a later date. Store all upload-related options in UploadInfo Use correct starting byte parameter when restarting upload Hardcode request options when exporting AVAsset from PhotosKit Update API doc with lifecycle details and note the placeholder implementation Fix parameter name Start method fixes: remove force unwrap and add missing start calls chunkSize -> chunkSizeInBytes
1 parent 06e8e70 commit 460c31e

File tree

18 files changed

+874
-178
lines changed

18 files changed

+874
-178
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// UploadInputInspectionWorker.swift
3+
//
4+
5+
import AVFoundation
6+
import Foundation
7+
8+
class UploadInputInspectionWorker {
9+
10+
var sourceInput: AVAsset?
11+
12+
13+
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// UploadInputInspector.swift
3+
//
4+
5+
import AVFoundation
6+
import Foundation
7+
8+
class UploadInputInspector {
9+
10+
}
11+
12+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// UploadInputStandardizationWorker.swift
3+
//
4+
5+
import AVFoundation
6+
import Foundation
7+
8+
class UploadInputStandardizationWorker {
9+
10+
var sourceInput: AVAsset?
11+
12+
var standardizedInput: AVAsset?
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//
2+
// UploadInputStandardizer.swift
3+
//
4+
5+
import AVFoundation
6+
import Foundation
7+
8+
class UploadInputStandardizer {
9+
10+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//
2+
// UploadInput.swift
3+
//
4+
5+
import AVFoundation
6+
import Foundation
7+
8+
// Internal representation of the upload input as it is
9+
// undergoing non-standard
10+
struct UploadInput {
11+
12+
internal enum Status {
13+
case ready(AVAsset, UploadInfo)
14+
case started(AVAsset, UploadInfo)
15+
case underInspection(AVAsset, UploadInfo)
16+
case standardizing(AVAsset, UploadInfo)
17+
case standardizationSucceeded(AVAsset, UploadInfo)
18+
case standardizationFailed(AVAsset, UploadInfo)
19+
case awaitingUploadConfirmation(UploadInfo)
20+
case uploadInProgress(UploadInfo)
21+
case uploadPaused(UploadInfo)
22+
case uploadSucceeded(UploadInfo)
23+
case uploadFailed(UploadInfo)
24+
}
25+
26+
var status: Status
27+
28+
var sourceAsset: AVAsset {
29+
switch status {
30+
case .ready(let sourceAsset, _):
31+
return sourceAsset
32+
case .started(let sourceAsset, _):
33+
return sourceAsset
34+
case .underInspection(let sourceAsset, _):
35+
return sourceAsset
36+
case .standardizing(let sourceAsset, _):
37+
return sourceAsset
38+
case .standardizationSucceeded(let sourceAsset, _):
39+
return sourceAsset
40+
case .standardizationFailed(let sourceAsset, _):
41+
return sourceAsset
42+
case .awaitingUploadConfirmation(let uploadInfo):
43+
return uploadInfo.sourceAsset()
44+
case .uploadInProgress(let uploadInfo):
45+
return uploadInfo.sourceAsset()
46+
case .uploadSucceeded(let uploadInfo):
47+
return uploadInfo.sourceAsset()
48+
case .uploadFailed(let uploadInfo):
49+
return uploadInfo.sourceAsset()
50+
case .uploadPaused(let uploadInfo):
51+
return uploadInfo.sourceAsset()
52+
}
53+
}
54+
55+
var uploadInfo: UploadInfo {
56+
switch status {
57+
case .ready(_, let uploadInfo):
58+
return uploadInfo
59+
case .started(_, let uploadInfo):
60+
return uploadInfo
61+
case .underInspection(_, let uploadInfo):
62+
return uploadInfo
63+
case .standardizing(_, let uploadInfo):
64+
return uploadInfo
65+
case .standardizationSucceeded(_, let uploadInfo):
66+
return uploadInfo
67+
case .standardizationFailed(_, let uploadInfo):
68+
return uploadInfo
69+
case .awaitingUploadConfirmation(let uploadInfo):
70+
return uploadInfo
71+
case .uploadInProgress(let uploadInfo):
72+
return uploadInfo
73+
case .uploadPaused(let uploadInfo):
74+
return uploadInfo
75+
case .uploadSucceeded(let uploadInfo):
76+
return uploadInfo
77+
case .uploadFailed(let uploadInfo):
78+
return uploadInfo
79+
}
80+
}
81+
}
82+
83+
extension UploadInput.Status: Equatable {
84+
85+
}
86+
87+
extension UploadInput {
88+
init(
89+
asset: AVAsset,
90+
info: UploadInfo
91+
) {
92+
self.status = .ready(asset, info)
93+
}
94+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// MuxUpload+AVFoundation.swift
3+
//
4+
5+
import AVFoundation
6+
import Foundation
7+
8+
extension MuxUpload {
9+
10+
/// Initializes a MuxUpload from an ``AVAsset``
11+
///
12+
/// - Parameters:
13+
/// - uploadURL: the URL of your direct upload, see
14+
/// the [direct upload guide](https://docs.mux.com/api-reference#video/operation/create-direct-upload)
15+
/// - inputAsset: the asset containing audiovisual
16+
/// media to be used as the input for the direct
17+
/// upload
18+
/// - options: options used to control the direct
19+
/// upload of the input to Mux
20+
public convenience init(
21+
uploadURL: URL,
22+
inputAsset: AVAsset,
23+
options: UploadOptions
24+
) {
25+
self.init(
26+
input: UploadInput(
27+
asset: inputAsset,
28+
info: UploadInfo(
29+
uploadURL: uploadURL,
30+
options: options
31+
)
32+
),
33+
uploadManager: .shared
34+
)
35+
}
36+
37+
}

0 commit comments

Comments
 (0)