Skip to content

Commit

Permalink
rename AVAssetEditContext to AVComposeContext
Browse files Browse the repository at this point in the history
  • Loading branch information
skyfe79 committed Apr 8, 2024
1 parent b535f7f commit 8a10bea
Show file tree
Hide file tree
Showing 15 changed files with 43 additions and 43 deletions.
6 changes: 3 additions & 3 deletions Sources/core/AVEditContext.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import AVFoundation

/// A context for editing `AVAsset` instances, encapsulating composition, video composition, and audio mix.
/// A context for composing `AVAsset` instances, encapsulating composition, video composition, and audio mix.
///
/// This class provides a structured way to manage the components required for editing an `AVAsset`, such as combining multiple assets, applying video and audio effects, and exporting the final composition.
class AVAssetEditContext {
class AVComposeContext {
/// The composition of assets.
///
/// This property holds the `AVComposition` object that represents the combined assets used in the editing context.
Expand All @@ -19,7 +19,7 @@ class AVAssetEditContext {
/// This optional property holds an `AVAudioMix` object, which defines how audio tracks are mixed and processed. It can include parameters for applying audio effects, volume adjustments, and other audio manipulations.
let audioMix: AVAudioMix?

/// Initializes a new `AVAssetEditContext`.
/// Initializes a new `AVComposeContext`.
///
/// - Parameters:
/// - composition: An `AVComposition` object representing the combined assets.
Expand Down
4 changes: 2 additions & 2 deletions Sources/core/AVExporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import AVFoundation
/// A class responsible for exporting AV assets.
class AVExporter {
/// The editing context containing the asset to be exported.
private let editContext: AVAssetEditContext
private let editContext: AVComposeContext

/// Initializes a new exporter with the given editing context.
/// - Parameter editContext: The context containing the asset to be exported.
init(editContext: AVAssetEditContext) {
init(editContext: AVComposeContext) {
self.editContext = editContext
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/operations/AVOperation.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// A protocol that defines an asynchronous operation on an audiovisual asset.
///
/// Conforming types to `AVOperation` are responsible for performing operations that may include editing, processing, or analyzing audiovisual content. The result of the operation is an optional `AVAssetEditContext` which encapsulates the changes made to the asset.
/// Conforming types to `AVOperation` are responsible for performing operations that may include editing, processing, or analyzing audiovisual content. The result of the operation is an optional `AVComposeContext` which encapsulates the changes made to the asset.
///
/// - Throws: An error if the operation cannot be completed.
/// - Returns: An optional `AVAssetEditContext` object representing the result of the operation.
/// - Returns: An optional `AVComposeContext` object representing the result of the operation.
protocol AVOperation {
func run() async throws -> AVAssetEditContext?
func run() async throws -> AVComposeContext?
}
8 changes: 4 additions & 4 deletions Sources/operations/CropOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class CropOperation: AVOperation {

/// Runs the crop operation asynchronously.
///
/// This method creates a composition and a video composition, then returns an `AVAssetEditContext` containing these compositions.
/// This method creates a composition and a video composition, then returns an `AVComposeContext` containing these compositions.
///
/// - Throws: An error if the operation cannot be completed.
/// - Returns: An optional `AVAssetEditContext` object representing the result of the operation.
func run() async throws -> AVAssetEditContext? {
/// - Returns: An optional `AVComposeContext` object representing the result of the operation.
func run() async throws -> AVComposeContext? {
let composition = await createComposition()
let videoComposition = await createVideoComposition()
return AVAssetEditContext(composition: composition, videoComposition: videoComposition)
return AVComposeContext(composition: composition, videoComposition: videoComposition)
}

/// Creates an `AVComposition` from the asset source.
Expand Down
6 changes: 3 additions & 3 deletions Sources/operations/ExtractAudioOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class ExtractAudioOperation: AVOperation {
/// This method creates an `AVComposition` containing only the audio track of the source asset.
///
/// - Throws: An error if the operation cannot be completed.
/// - Returns: An optional `AVAssetEditContext` object representing the result of the operation.
func run() async throws -> AVAssetEditContext? {
/// - Returns: An optional `AVComposeContext` object representing the result of the operation.
func run() async throws -> AVComposeContext? {
let composition = await createComposition()
return AVAssetEditContext(composition: composition)
return AVComposeContext(composition: composition)
}

/// Asynchronously creates an `AVComposition` with the audio track of the source asset.
Expand Down
8 changes: 4 additions & 4 deletions Sources/operations/ExtractVideoOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class ExtractVideoOperation: AVOperation {

/// Runs the video extraction operation asynchronously.
///
/// This method creates an `AVComposition` and an `AVVideoComposition`, then returns an `AVAssetEditContext` containing these compositions.
/// This method creates an `AVComposition` and an `AVVideoComposition`, then returns an `AVComposeContext` containing these compositions.
///
/// - Throws: An error if the operation cannot be completed.
/// - Returns: An optional `AVAssetEditContext` object representing the result of the operation.
func run() async throws -> AVAssetEditContext? {
/// - Returns: An optional `AVComposeContext` object representing the result of the operation.
func run() async throws -> AVComposeContext? {
let composition = await createComposition()
let videoComposition = await createVideoComposition()
return AVAssetEditContext(composition: composition, videoComposition: videoComposition)
return AVComposeContext(composition: composition, videoComposition: videoComposition)
}

/// Asynchronously creates an `AVComposition` with the video track of the source asset.
Expand Down
4 changes: 2 additions & 2 deletions Sources/operations/GenerateImagesOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class GenerateImagesOperation: AVOperation {
/// This method generates images from the source asset at the specified times or at intervals defined by `stride`. The generated images are saved to the folder specified by `outputURL`.
///
/// - Throws: An error if neither times nor stride are provided.
/// - Returns: An optional `AVAssetEditContext` object representing the result of the operation. Currently, this method always returns `nil`.
/// - Returns: An optional `AVComposeContext` object representing the result of the operation. Currently, this method always returns `nil`.
@discardableResult
func run() async throws -> AVAssetEditContext? {
func run() async throws -> AVComposeContext? {
guard times.isEmpty == false || stride > 0 else {
throw "Either times or stride must be provided"
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/operations/ImagesToVideoOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class ImagesToVideoOperation: AVOperation {

/// Executes the operation to generate a video from the images.
///
/// - Returns: An optional `AVAssetEditContext` object representing the result of the operation. Currently, this method always returns `nil`.
/// - Returns: An optional `AVComposeContext` object representing the result of the operation. Currently, this method always returns `nil`.
/// - Throws: An error if the image size cannot be determined or the video cannot be written.
@discardableResult
func run() async throws -> AVAssetEditContext? {
func run() async throws -> AVComposeContext? {
try figureoutImageSize()
guard imageSize != .zero else {
throw NSError(domain: "ImagesToVideoOperation", code: 0, userInfo: [NSLocalizedDescriptionKey: "Failed to determine image size."])
Expand Down
6 changes: 3 additions & 3 deletions Sources/operations/MergeOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class MergeOperation: AVOperation {
/// This method reads all files from the input directory, sorts them, and merges their audio and video tracks into a single composition. It also creates a video composition to ensure consistent frame rate across the merged video.
///
/// - Throws: An error if the files cannot be read or the merge operation fails.
/// - Returns: An optional `AVAssetEditContext` object representing the result of the merge operation.
func run() async throws -> AVAssetEditContext? {
/// - Returns: An optional `AVComposeContext` object representing the result of the merge operation.
func run() async throws -> AVComposeContext? {
// Retrieve and sort files from the input directory.
let files = try FileManager.default.contentsOfDirectory(at: inputURL, includingPropertiesForKeys: nil)
let sortedFiles = files.sorted { $0.lastPathComponent < $1.lastPathComponent }
Expand Down Expand Up @@ -57,6 +57,6 @@ class MergeOperation: AVOperation {
videoComposition.frameDuration = CMTime(value: 1, timescale: 30)

// Return the editing context containing the merged composition and video composition.
return AVAssetEditContext(composition: composition, videoComposition: videoComposition)
return AVComposeContext(composition: composition, videoComposition: videoComposition)
}
}
6 changes: 3 additions & 3 deletions Sources/operations/OverlayImageOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class OverlayImageOperation: AVOperation {
/// This method creates a composition and a video composition, then overlays the specified image onto the video track of the asset source.
///
/// - Throws: An error if the operation cannot be completed.
/// - Returns: An optional `AVAssetEditContext` object representing the result of the operation.
func run() async throws -> AVAssetEditContext? {
/// - Returns: An optional `AVComposeContext` object representing the result of the operation.
func run() async throws -> AVComposeContext? {
let (composition, videoComposition) = await createComposition()
return AVAssetEditContext(composition: composition, videoComposition: videoComposition)
return AVComposeContext(composition: composition, videoComposition: videoComposition)
}

/// Creates a composition and a video composition for the overlay operation.
Expand Down
6 changes: 3 additions & 3 deletions Sources/operations/OverlaySoundOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class OverlaySoundOperation: AVOperation {
/// Executes the overlay operation asynchronously.
///
/// - Throws: An error if the operation cannot be completed.
/// - Returns: An optional `AVAssetEditContext` object representing the result of the operation.
func run() async throws -> AVAssetEditContext? {
/// - Returns: An optional `AVComposeContext` object representing the result of the operation.
func run() async throws -> AVComposeContext? {
let (composition, videoComposition, audioMix) = await createComposition()
return AVAssetEditContext(composition: composition, videoComposition: videoComposition, audioMix: audioMix)
return AVComposeContext(composition: composition, videoComposition: videoComposition, audioMix: audioMix)
}

/// Creates a composition and optionally an audio mix for the overlay operation.
Expand Down
6 changes: 3 additions & 3 deletions Sources/operations/OverlayTextOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ class OverlayTextOperation: AVOperation {
/// Executes the overlay operation asynchronously.
///
/// - Throws: An error if the operation cannot be completed.
/// - Returns: An optional `AVAssetEditContext` object representing the result of the operation.
func run() async throws -> AVAssetEditContext? {
/// - Returns: An optional `AVComposeContext` object representing the result of the operation.
func run() async throws -> AVComposeContext? {
let (composition, videoComposition) = await createComposition()
return AVAssetEditContext(composition: composition, videoComposition: videoComposition)
return AVComposeContext(composition: composition, videoComposition: videoComposition)
}

/// Creates a composition and a video composition for the overlay operation.
Expand Down
6 changes: 3 additions & 3 deletions Sources/operations/RotateOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class RotateOperation: AVOperation {
/// Executes the rotation operation asynchronously.
///
/// - Throws: An error if the operation cannot be completed.
/// - Returns: An optional `AVAssetEditContext` object representing the result of the rotation operation.
func run() async throws -> AVAssetEditContext? {
/// - Returns: An optional `AVComposeContext` object representing the result of the rotation operation.
func run() async throws -> AVComposeContext? {
let composition = await createComposition()
let videoComposition = await createVideoComposition()
return AVAssetEditContext(composition: composition, videoComposition: videoComposition)
return AVComposeContext(composition: composition, videoComposition: videoComposition)
}

/// Creates a composition for the rotation operation.
Expand Down
6 changes: 3 additions & 3 deletions Sources/operations/SpeedOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class SpeedOperation: AVOperation {
/// Executes the speed adjustment operation asynchronously.
///
/// - Throws: An error if the operation cannot be completed.
/// - Returns: An optional `AVAssetEditContext` object representing the result of the operation.
func run() async throws -> AVAssetEditContext? {
/// - Returns: An optional `AVComposeContext` object representing the result of the operation.
func run() async throws -> AVComposeContext? {
let (composition, videoCompositon) = await createComposition()
return AVAssetEditContext(composition: composition, videoComposition: videoCompositon)
return AVComposeContext(composition: composition, videoComposition: videoCompositon)
}

/// Creates a composition and a video composition for the speed adjustment operation.
Expand Down
4 changes: 2 additions & 2 deletions Sources/operations/SplitOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class SplitOperation: AVOperation {
/// This method creates a directory at the output URL (if it doesn't already exist), calculates the time ranges for each segment based on the specified duration, and exports each segment to the output URL.
///
/// - Throws: An error if the operation cannot be completed.
/// - Returns: An optional `AVAssetEditContext` object representing the result of the operation, which is `nil` in this case as the operation does not modify the asset context.
func run() async throws -> AVAssetEditContext? {
/// - Returns: An optional `AVComposeContext` object representing the result of the operation, which is `nil` in this case as the operation does not modify the asset context.
func run() async throws -> AVComposeContext? {
do {
try FileManager.default.createDirectory(at: outputURL, withIntermediateDirectories: true, attributes: nil)
let ranges = CMTimeRange.stride(range: assetSource.duration.range, by: CMTimeValue(duration))
Expand Down

0 comments on commit 8a10bea

Please sign in to comment.