Skip to content

Commit

Permalink
Refactor TypedBlockQueue.
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Jul 28, 2024
1 parent 0a319d7 commit 8dd8abd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/Screen/ScreenObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public final class VideoTrackScreenObject: ScreenObject {
super.init()
horizontalAlignment = .center
do {
queue = TypedBlockQueue(try CMBufferQueue(capacity: 1, handlers: .outputPTSSortedSampleBuffers))
queue = try TypedBlockQueue(capacity: 1, handlers: .outputPTSSortedSampleBuffers)
} catch {
logger.error(error)
}
Expand Down
6 changes: 4 additions & 2 deletions Sources/Util/TypedBlockQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Foundation

final class TypedBlockQueue<T: AnyObject> {
private let queue: CMBufferQueue
private let capacity: CMItemCount

@inlinable @inline(__always) var head: T? {
guard let head = queue.head else {
Expand All @@ -19,8 +20,9 @@ final class TypedBlockQueue<T: AnyObject> {
queue.duration
}

init(_ queue: CMBufferQueue) {
self.queue = queue
init(capacity: CMItemCount, handlers: CMBufferQueue.Handlers) throws {
self.capacity = capacity
self.queue = try CMBufferQueue(capacity: capacity, handlers: handlers)
}

@inlinable
Expand Down

0 comments on commit 8dd8abd

Please sign in to comment.