Removes unneeded stuff
This commit is contained in:
@@ -35,12 +35,10 @@
|
||||
B5667B3E249BC43100D93F85 /* AudioPlayerRenderProcessor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5667B3D249BC43000D93F85 /* AudioPlayerRenderProcessor.swift */; };
|
||||
B59DF10424916FD50043C498 /* DispatchQueue+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59DF10324916FD50043C498 /* DispatchQueue+Helpers.swift */; };
|
||||
B59DF1A32493E90C0043C498 /* AudioFileStream+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = B59DF1A22493E90C0043C498 /* AudioFileStream+Helpers.swift */; };
|
||||
B5A1254C24DD92C600862F64 /* OutputStreamWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A1254B24DD92C600862F64 /* OutputStreamWriter.swift */; };
|
||||
B5AEDBB824744153007D8101 /* AudioStreaming.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B5AEDBAE24744153007D8101 /* AudioStreaming.framework */; };
|
||||
B5AEDBBF24744153007D8101 /* AudioStreaming.h in Headers */ = {isa = PBXBuildFile; fileRef = B5AEDBB124744153007D8101 /* AudioStreaming.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
B5B3B7CC248647ED00656828 /* AudioPlayerState.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5B3B7CB248647ED00656828 /* AudioPlayerState.swift */; };
|
||||
B5B3B7D72486993B00656828 /* AudioStreamingMac.h in Headers */ = {isa = PBXBuildFile; fileRef = B5B3B7D52486993B00656828 /* AudioStreamingMac.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
B5E1DE2324B706A500955BFB /* Stream+DispatchQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E1DE2224B706A500955BFB /* Stream+DispatchQueue.swift */; };
|
||||
B5E1DE2524B70B4200955BFB /* AudioPlayerConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5E1DE2424B70B4200955BFB /* AudioPlayerConfiguration.swift */; };
|
||||
B5EF954E247DA5AC003E8FF8 /* NetworkingClientTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5EF954D247DA5AC003E8FF8 /* NetworkingClientTests.swift */; };
|
||||
B5EF9555247E9393003E8FF8 /* AudioEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5EF9554247E9393003E8FF8 /* AudioEntry.swift */; };
|
||||
@@ -104,7 +102,6 @@
|
||||
B5667B3D249BC43000D93F85 /* AudioPlayerRenderProcessor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayerRenderProcessor.swift; sourceTree = "<group>"; };
|
||||
B59DF10324916FD50043C498 /* DispatchQueue+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DispatchQueue+Helpers.swift"; sourceTree = "<group>"; };
|
||||
B59DF1A22493E90C0043C498 /* AudioFileStream+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AudioFileStream+Helpers.swift"; sourceTree = "<group>"; };
|
||||
B5A1254B24DD92C600862F64 /* OutputStreamWriter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OutputStreamWriter.swift; sourceTree = "<group>"; };
|
||||
B5AEDBAE24744153007D8101 /* AudioStreaming.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AudioStreaming.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B5AEDBB124744153007D8101 /* AudioStreaming.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AudioStreaming.h; sourceTree = "<group>"; };
|
||||
B5AEDBB224744153007D8101 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
@@ -114,7 +111,6 @@
|
||||
B5B3B7D32486993B00656828 /* AudioStreamingMac.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AudioStreamingMac.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
B5B3B7D52486993B00656828 /* AudioStreamingMac.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AudioStreamingMac.h; sourceTree = "<group>"; };
|
||||
B5B3B7D62486993B00656828 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
B5E1DE2224B706A500955BFB /* Stream+DispatchQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Stream+DispatchQueue.swift"; sourceTree = "<group>"; };
|
||||
B5E1DE2424B70B4200955BFB /* AudioPlayerConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioPlayerConfiguration.swift; sourceTree = "<group>"; };
|
||||
B5EF954D247DA5AC003E8FF8 /* NetworkingClientTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkingClientTests.swift; sourceTree = "<group>"; };
|
||||
B5EF9554247E9393003E8FF8 /* AudioEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioEntry.swift; sourceTree = "<group>"; };
|
||||
@@ -159,7 +155,6 @@
|
||||
B5276B73247D4D9F00D2F56A /* NetworkSessionDelegate.swift */,
|
||||
B5F883C22477DC4400D277C1 /* NetworkDataStream.swift */,
|
||||
B5276B71247D4D5B00D2F56A /* NetworkTasksMap.swift */,
|
||||
B5A1254B24DD92C600862F64 /* OutputStreamWriter.swift */,
|
||||
);
|
||||
path = Network;
|
||||
sourceTree = "<group>";
|
||||
@@ -189,7 +184,6 @@
|
||||
children = (
|
||||
B55CE97724813BCA0001C498 /* UnsafeMutablePointer+Helpers.swift */,
|
||||
B59DF10324916FD50043C498 /* DispatchQueue+Helpers.swift */,
|
||||
B5E1DE2224B706A500955BFB /* Stream+DispatchQueue.swift */,
|
||||
B55F77D024D82CD50057F431 /* AVAudioUnit+Convenience.swift */,
|
||||
B51B9F9924DBE5BF00BDEAA2 /* AVAudioFormat+Convenience.swift */,
|
||||
);
|
||||
@@ -504,7 +498,6 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
B5EF955D247ECBB1003E8FF8 /* RemoteAudioSource.swift in Sources */,
|
||||
B5E1DE2324B706A500955BFB /* Stream+DispatchQueue.swift in Sources */,
|
||||
B59DF10424916FD50043C498 /* DispatchQueue+Helpers.swift in Sources */,
|
||||
B5B3B7CC248647ED00656828 /* AudioPlayerState.swift in Sources */,
|
||||
B51B9F9A24DBE5BF00BDEAA2 /* AVAudioFormat+Convenience.swift in Sources */,
|
||||
@@ -535,7 +528,6 @@
|
||||
B5276B74247D4D9F00D2F56A /* NetworkSessionDelegate.swift in Sources */,
|
||||
B55F77D624DACE140057F431 /* BufferContext.swift in Sources */,
|
||||
B55CE97824813BCA0001C498 /* UnsafeMutablePointer+Helpers.swift in Sources */,
|
||||
B5A1254C24DD92C600862F64 /* OutputStreamWriter.swift in Sources */,
|
||||
B5F883B62476DADB00D277C1 /* Protected.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
//
|
||||
// Created by Dimitrios Chatzieleftheriou on 09/07/2020.
|
||||
// Copyright © 2020 Decimal. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension InputStream {
|
||||
/// Sets the InputStream to the specified DispatchQueue
|
||||
///
|
||||
/// - parameter queue: A `DispatchQueue` object the `InputStream` is attached to.
|
||||
func set(on queue: DispatchQueue) {
|
||||
CFReadStreamSetDispatchQueue(self, queue)
|
||||
}
|
||||
|
||||
/// Unsets the InputStream from the attached DispatchQueue
|
||||
///
|
||||
/// This sets the `DispatchQueue` to `nil`
|
||||
func unsetFromQueue() {
|
||||
CFReadStreamSetDispatchQueue(self, nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension OutputStream {
|
||||
/// Sets the OutputStream to the specified DispatchQueue
|
||||
///
|
||||
/// - parameter queue: A `DispatchQueue` object the `OutputStream` is attached to.
|
||||
func set(on queue: DispatchQueue) {
|
||||
CFWriteStreamSetDispatchQueue(self, queue)
|
||||
}
|
||||
|
||||
/// Unsets the OutputStream from the attached DispatchQueue
|
||||
///
|
||||
/// This sets the `DispatchQueue` to `nil`
|
||||
func unsetFromQueue() {
|
||||
CFWriteStreamSetDispatchQueue(self, nil)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
//
|
||||
// Created by Dimitrios Chatzieleftheriou on 07/08/2020.
|
||||
// Copyright © 2020 Decimal. All rights reserved.
|
||||
//
|
||||
|
||||
/// An object that writes the received data from a network request to a specified `OutputStream`
|
||||
final class OutputStreamWriter {
|
||||
/// The accumulated data received from the URLSession
|
||||
private var dataReceived = Data()
|
||||
/// Keeps track of the total written bytes in the output stream
|
||||
private var totalBytesWritten: Int = 0
|
||||
|
||||
/// Write the data on the `OutputStream`
|
||||
///
|
||||
/// - parameter stream: An `OutputStream` for the data to be written in.
|
||||
/// - parameter bufferSize: A `Int` value indicating the max buffer size to be written at a given time.
|
||||
///
|
||||
/// - returns: An `Int` value indicating the accumulated written bytes.
|
||||
func writeData(on stream: OutputStream, bufferSize: Int) -> Int {
|
||||
guard !dataReceived.isEmpty else { return 0 }
|
||||
|
||||
// gets the underlying byte buffer and writes to the stream
|
||||
let sliceCount = min(bufferSize, dataReceived.count)
|
||||
let slice = dataReceived[..<sliceCount]
|
||||
let written = slice.withUnsafeBytes { buffer -> Int in
|
||||
guard slice.count > 0 else { return 0 }
|
||||
// "safe" to force unwrap here as we check if the count is not 0
|
||||
let base = buffer.baseAddress!.assumingMemoryBound(to: UInt8.self)
|
||||
return stream.write(base, maxLength: buffer.count)
|
||||
}
|
||||
// check if `stream.write` returns an error and return
|
||||
guard written > 0 else { return -1 }
|
||||
|
||||
if dataReceived.count >= written {
|
||||
dataReceived.removeSubrange(..<written)
|
||||
}
|
||||
|
||||
totalBytesWritten += written
|
||||
return totalBytesWritten
|
||||
}
|
||||
|
||||
/// Stores the given data
|
||||
///
|
||||
/// - parameter data: A `Data` object as received from a network request.
|
||||
func storeReceived(data: Data) {
|
||||
self.dataReceived.append(data)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -131,7 +131,6 @@ public final class AudioPlayer {
|
||||
let audioSource = RemoteAudioSource(networking: self.networking,
|
||||
url: url,
|
||||
sourceQueue: sourceQueue,
|
||||
readBufferSize: configuration.readBufferSize,
|
||||
httpHeaders: headers)
|
||||
let entry = AudioEntry(source: audioSource,
|
||||
entryId: AudioEntryId(id: url.absoluteString))
|
||||
@@ -163,7 +162,6 @@ public final class AudioPlayer {
|
||||
sourceQueue.async { [weak self] in
|
||||
guard let self = self else { return }
|
||||
self.playerContext.audioReadingEntry?.source.delegate = nil
|
||||
self.playerContext.audioReadingEntry?.source.removeFromQueue()
|
||||
self.playerContext.audioReadingEntry?.source.close()
|
||||
if let playingEntry = self.playerContext.audioPlayingEntry {
|
||||
self.processFinishPlaying(entry: playingEntry, with: nil)
|
||||
@@ -427,7 +425,6 @@ public final class AudioPlayer {
|
||||
|
||||
if let readingEntry = playerContext.audioReadingEntry {
|
||||
readingEntry.source.delegate = nil
|
||||
readingEntry.source.removeFromQueue()
|
||||
readingEntry.source.close()
|
||||
}
|
||||
|
||||
@@ -435,7 +432,6 @@ public final class AudioPlayer {
|
||||
playerContext.audioReadingEntry = entry
|
||||
}
|
||||
playerContext.audioReadingEntry?.source.delegate = self
|
||||
playerContext.audioReadingEntry?.source.setup()
|
||||
playerContext.audioReadingEntry?.source.seek(at: 0)
|
||||
|
||||
if startPlaying {
|
||||
@@ -555,7 +551,6 @@ extension AudioPlayer: AudioStreamSourceDelegate {
|
||||
|
||||
playerContext.entriesLock.lock()
|
||||
if playerContext.audioReadingEntry === nil {
|
||||
source.removeFromQueue()
|
||||
source.close()
|
||||
}
|
||||
playerContext.entriesLock.unlock()
|
||||
@@ -570,7 +565,6 @@ extension AudioPlayer: AudioStreamSourceDelegate {
|
||||
func endOfFileOccured(source: AudioStreamSource) {
|
||||
if playerContext.audioReadingEntry == nil || playerContext.audioReadingEntry?.source !== source {
|
||||
source.delegate = nil
|
||||
source.removeFromQueue()
|
||||
source.close()
|
||||
return
|
||||
}
|
||||
@@ -583,7 +577,6 @@ extension AudioPlayer: AudioStreamSourceDelegate {
|
||||
|
||||
guard let readingEntry = playerContext.audioReadingEntry else {
|
||||
source.delegate = nil
|
||||
source.removeFromQueue()
|
||||
source.close()
|
||||
return
|
||||
}
|
||||
@@ -591,7 +584,6 @@ extension AudioPlayer: AudioStreamSourceDelegate {
|
||||
readingEntry.framesState.lastFrameQueued = readingEntry.framesState.queued
|
||||
|
||||
readingEntry.source.delegate = nil
|
||||
readingEntry.source.removeFromQueue()
|
||||
readingEntry.source.close()
|
||||
|
||||
playerContext.entriesLock.lock()
|
||||
|
||||
@@ -8,8 +8,6 @@ import Foundation
|
||||
public struct AudioPlayerConfiguration: Equatable {
|
||||
/// All pending items will be flushed when seeking a track if this is set to `true`
|
||||
let flushQueueOnSeek: Bool
|
||||
/// The size of the I/O read buffer.
|
||||
let readBufferSize: Int
|
||||
/// The size of the decompressed buffer.
|
||||
let bufferSizeInSeconds: Double
|
||||
/// Number of seconds of audio required to before playback first starts.
|
||||
@@ -25,7 +23,6 @@ public struct AudioPlayerConfiguration: Equatable {
|
||||
let enableLogs: Bool
|
||||
|
||||
static public let `default` = AudioPlayerConfiguration(flushQueueOnSeek: true,
|
||||
readBufferSize: 64 * 1024,
|
||||
bufferSizeInSeconds: 10,
|
||||
secondsRequiredToStartPlaying: 1,
|
||||
gracePeriodAfterSeekInSeconds: 0.5,
|
||||
@@ -36,7 +33,6 @@ public struct AudioPlayerConfiguration: Equatable {
|
||||
/// Parameters are pre set for convenience
|
||||
///
|
||||
/// - parameter flushQueueOnSeek: All pending items will be flushed when seeking a track if this is set to `true`
|
||||
/// - parameter readBufferSize: The size of the I/O read buffer.
|
||||
/// - parameter bufferSizeInSeconds: The size of the decompressed buffer.
|
||||
/// - parameter secondsRequiredToStartPlaying: Number of seconds of audio required to before playback first starts.
|
||||
/// - parameter gracePeriodAfterSeekInSeconds: Number of seconds of audio required after seek occcurs.
|
||||
@@ -44,14 +40,12 @@ public struct AudioPlayerConfiguration: Equatable {
|
||||
/// - parameter enableLogs: Enables the internal logs
|
||||
///
|
||||
public init(flushQueueOnSeek: Bool = true,
|
||||
readBufferSize: Int = 64 * 1024,
|
||||
bufferSizeInSeconds: Double = 10,
|
||||
secondsRequiredToStartPlaying: Double = 1,
|
||||
gracePeriodAfterSeekInSeconds: Double = 0.5,
|
||||
secondsRequiredToStartPlayingAfterBufferUnderun: Int = 1,
|
||||
enableLogs: Bool = false) {
|
||||
self.flushQueueOnSeek = flushQueueOnSeek
|
||||
self.readBufferSize = readBufferSize
|
||||
self.bufferSizeInSeconds = bufferSizeInSeconds
|
||||
self.secondsRequiredToStartPlaying = secondsRequiredToStartPlaying
|
||||
self.gracePeriodAfterSeekInSeconds = gracePeriodAfterSeekInSeconds
|
||||
@@ -61,7 +55,6 @@ public struct AudioPlayerConfiguration: Equatable {
|
||||
/// Normalize values on any zero values passed
|
||||
func normalizeValues() -> AudioPlayerConfiguration {
|
||||
let defaultValues = AudioPlayerConfiguration.default
|
||||
let readBufferSize = self.readBufferSize == 0 ? defaultValues.readBufferSize : self.readBufferSize
|
||||
let bufferSizeInSeconds = self.bufferSizeInSeconds == 0 ? defaultValues.bufferSizeInSeconds : self.bufferSizeInSeconds
|
||||
let secondsRequiredToStartPlaying = self.secondsRequiredToStartPlaying == 0 ? defaultValues.secondsRequiredToStartPlaying : self.secondsRequiredToStartPlaying
|
||||
let gracePeriodAfterSeekInSeconds = self.gracePeriodAfterSeekInSeconds == 0 ? defaultValues.gracePeriodAfterSeekInSeconds : self.gracePeriodAfterSeekInSeconds
|
||||
@@ -70,7 +63,6 @@ public struct AudioPlayerConfiguration: Equatable {
|
||||
defaultValues.secondsRequiredToStartPlayingAfterBufferUnderun : self.secondsRequiredToStartPlayingAfterBufferUnderun
|
||||
|
||||
return AudioPlayerConfiguration(flushQueueOnSeek: self.flushQueueOnSeek,
|
||||
readBufferSize: readBufferSize,
|
||||
bufferSizeInSeconds: bufferSizeInSeconds,
|
||||
secondsRequiredToStartPlaying: secondsRequiredToStartPlaying,
|
||||
gracePeriodAfterSeekInSeconds: gracePeriodAfterSeekInSeconds,
|
||||
|
||||
@@ -18,9 +18,6 @@ final class AudioRendererContext {
|
||||
|
||||
let lock = UnfairLock()
|
||||
|
||||
let readBufferSize: Int
|
||||
let readBuffer: UnsafeMutablePointer<UInt8>
|
||||
|
||||
let bufferContext: BufferContext
|
||||
|
||||
let seekRequest: SeekRequest
|
||||
@@ -41,8 +38,6 @@ final class AudioRendererContext {
|
||||
let configuration: AudioPlayerConfiguration
|
||||
init(configuration: AudioPlayerConfiguration, outputAudioFormat: AVAudioFormat) {
|
||||
self.configuration = configuration
|
||||
self.readBufferSize = configuration.readBufferSize
|
||||
self.readBuffer = UnsafeMutablePointer<UInt8>.uint8pointer(of: readBufferSize)
|
||||
self.seekRequest = SeekRequest()
|
||||
|
||||
let canonicalStream = outputAudioFormat.basicStreamDescription
|
||||
@@ -64,7 +59,6 @@ final class AudioRendererContext {
|
||||
|
||||
/// Deallocates buffer resources
|
||||
public func clean() {
|
||||
readBuffer.deallocate()
|
||||
inOutAudioBufferList.deallocate()
|
||||
audioBuffer.mData?.deallocate()
|
||||
}
|
||||
|
||||
@@ -26,19 +26,6 @@ protocol CoreAudioStreamSource: class {
|
||||
/// An `AudioStreamSourceDelegate` object to listen for events from the source
|
||||
var delegate: AudioStreamSourceDelegate? { get set }
|
||||
|
||||
/// Reads up to a given number of bytes into a given buffer.
|
||||
/// - parameter buffer: A mutable pointer of `UInt8` to hold the current buffer of stream
|
||||
/// - parameter size: The maximum length for the buffer to read
|
||||
/// - returns: As per `InputStream` documentation
|
||||
/// - A positive number indicates the number of bytes read.
|
||||
/// - 0 indicates that the end of the buffer was reached.
|
||||
/// - -1 means that the operation failed; more information about the error can be obtained with streamError.
|
||||
func read(into buffer: UnsafeMutablePointer<UInt8>, size: Int) -> Int
|
||||
|
||||
func setup()
|
||||
|
||||
func removeFromQueue()
|
||||
|
||||
/// Closes the underlying stream
|
||||
func close()
|
||||
|
||||
@@ -51,30 +38,10 @@ protocol CoreAudioStreamSource: class {
|
||||
|
||||
protocol AudioStreamSource: CoreAudioStreamSource {
|
||||
|
||||
var inputStream: InputStream? { get }
|
||||
|
||||
/// The `DispatchQueue` network object will receive data
|
||||
var sourceQueue: DispatchQueue { get }
|
||||
|
||||
/// A `MetadataStreamSource` object that handles the metadata parsing
|
||||
var metadataStreamProccessor: MetadataStreamSource { get }
|
||||
|
||||
/// Returns `true` if the source has bytes available to be processed
|
||||
var hasBytesAvailable: Bool { get }
|
||||
|
||||
/// The status of the stream
|
||||
var streamStatus: InputStream.Status { get }
|
||||
|
||||
}
|
||||
|
||||
extension AudioStreamSource {
|
||||
var hasBytesAvailable: Bool {
|
||||
guard let stream = inputStream else { return false }
|
||||
return stream.hasBytesAvailable
|
||||
}
|
||||
|
||||
var streamStatus: InputStream.Status {
|
||||
guard let stream = inputStream else { return .error }
|
||||
return stream.streamStatus
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,10 +6,7 @@
|
||||
import Foundation
|
||||
import AudioToolbox
|
||||
|
||||
public class RemoteAudioSource: NSObject, AudioStreamSource {
|
||||
|
||||
var inputStream: InputStream?
|
||||
var readBufferSize: Int = 0
|
||||
public class RemoteAudioSource: AudioStreamSource {
|
||||
|
||||
weak var delegate: AudioStreamSourceDelegate?
|
||||
|
||||
@@ -50,7 +47,6 @@ public class RemoteAudioSource: NSObject, AudioStreamSource {
|
||||
metadataStreamSource: MetadataStreamSource,
|
||||
url: URL,
|
||||
sourceQueue: DispatchQueue,
|
||||
readBufferSize: Int,
|
||||
httpHeaders: [String: String]) {
|
||||
self.networking = networking
|
||||
self.metadataStreamProccessor = metadataStreamSource
|
||||
@@ -60,13 +56,11 @@ public class RemoteAudioSource: NSObject, AudioStreamSource {
|
||||
self.httpStatusCode = 0
|
||||
self.relativePosition = 0
|
||||
self.seekOffset = 0
|
||||
self.readBufferSize = readBufferSize
|
||||
}
|
||||
|
||||
convenience init(networking: NetworkingClient,
|
||||
url: URL,
|
||||
sourceQueue: DispatchQueue,
|
||||
readBufferSize: Int,
|
||||
httpHeaders: [String: String]) {
|
||||
let metadataParser = MetadataParser()
|
||||
let metadataProccessor = MetadataStreamProcessor(parser: metadataParser.eraseToAnyParser())
|
||||
@@ -74,38 +68,19 @@ public class RemoteAudioSource: NSObject, AudioStreamSource {
|
||||
metadataStreamSource: metadataProccessor,
|
||||
url: url,
|
||||
sourceQueue: sourceQueue,
|
||||
readBufferSize: readBufferSize,
|
||||
httpHeaders: httpHeaders)
|
||||
}
|
||||
|
||||
convenience init(networking: NetworkingClient,
|
||||
url: URL,
|
||||
sourceQueue: DispatchQueue,
|
||||
readBufferSize: Int) {
|
||||
sourceQueue: DispatchQueue) {
|
||||
self.init(networking: networking,
|
||||
url: url,
|
||||
sourceQueue: sourceQueue,
|
||||
readBufferSize: readBufferSize,
|
||||
httpHeaders: [:])
|
||||
}
|
||||
|
||||
func setup() {
|
||||
guard let stream = inputStream else {
|
||||
return
|
||||
}
|
||||
// stream.delegate = self
|
||||
// stream.set(on: sourceQueue)
|
||||
}
|
||||
|
||||
func removeFromQueue() {
|
||||
guard let stream = inputStream else { return }
|
||||
stream.delegate = nil
|
||||
stream.unsetFromQueue()
|
||||
}
|
||||
|
||||
func close() {
|
||||
inputStream?.close()
|
||||
inputStream = nil
|
||||
streamRequest?.cancel()
|
||||
if let streamTask = streamRequest {
|
||||
networking.remove(task: streamTask)
|
||||
@@ -114,8 +89,6 @@ public class RemoteAudioSource: NSObject, AudioStreamSource {
|
||||
}
|
||||
|
||||
func seek(at offset: Int) {
|
||||
// dispatchPrecondition(condition: .onQueue(sourceQueue))
|
||||
|
||||
close()
|
||||
|
||||
relativePosition = 0
|
||||
@@ -129,31 +102,8 @@ public class RemoteAudioSource: NSObject, AudioStreamSource {
|
||||
performOpen(seek: offset)
|
||||
}
|
||||
|
||||
func read(into buffer: UnsafeMutablePointer<UInt8>, size: Int) -> Int {
|
||||
performRead(into: buffer, size: size)
|
||||
}
|
||||
|
||||
|
||||
// MARK: Private
|
||||
|
||||
private func performRead(into buffer: UnsafeMutablePointer<UInt8>, size: Int) -> Int {
|
||||
guard size != 0 else { return 0 }
|
||||
guard let stream = inputStream else { return 0 }
|
||||
|
||||
var read: Int = 0
|
||||
// Metadata parsing
|
||||
if metadataStreamProccessor.canProccessMetadata {
|
||||
read = metadataStreamProccessor.proccessFromRead(into: buffer, size: size, using: stream)
|
||||
} else {
|
||||
read = stream.read(buffer, maxLength: size)
|
||||
}
|
||||
|
||||
guard read > 0 else { return read }
|
||||
relativePosition += read
|
||||
|
||||
return read
|
||||
}
|
||||
|
||||
private func performOpen(seek seekOffset: Int) {
|
||||
let urlRequest = buildUrlRequest(with: url, seekIfNeeded: seekOffset)
|
||||
|
||||
@@ -197,13 +147,6 @@ public class RemoteAudioSource: NSObject, AudioStreamSource {
|
||||
}
|
||||
}
|
||||
|
||||
private func performSoftSetup() {
|
||||
guard let stream = inputStream else {
|
||||
return
|
||||
}
|
||||
stream.set(on: sourceQueue)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
private func parseResponseHeader(response: HTTPURLResponse?) -> Bool {
|
||||
guard let response = response else { return false }
|
||||
|
||||
Reference in New Issue
Block a user