add TSWriterDelegate
This commit is contained in:
parent
fa877229ab
commit
d25f233bcc
|
@ -1,7 +1,8 @@
|
||||||
import CoreMedia
|
import CoreMedia
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
protocol TSWriterDelegate: class {
|
public protocol TSWriterDelegate: class {
|
||||||
|
func didOutput(_ data: Data)
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TSWriter {
|
public class TSWriter {
|
||||||
|
@ -36,6 +37,8 @@ public class TSWriter {
|
||||||
var segmentMaxCount: Int = TSWriter.defaultSegmentMaxCount
|
var segmentMaxCount: Int = TSWriter.defaultSegmentMaxCount
|
||||||
var segmentDuration: Double = TSWriter.defaultSegmentDuration
|
var segmentDuration: Double = TSWriter.defaultSegmentDuration
|
||||||
|
|
||||||
|
public weak var delegate: TSWriterDelegate?
|
||||||
|
|
||||||
private(set) var PAT: ProgramAssociationSpecific = {
|
private(set) var PAT: ProgramAssociationSpecific = {
|
||||||
let PAT: ProgramAssociationSpecific = ProgramAssociationSpecific()
|
let PAT: ProgramAssociationSpecific = ProgramAssociationSpecific()
|
||||||
PAT.programs = [1: TSWriter.defaultPMTPID]
|
PAT.programs = [1: TSWriter.defaultPMTPID]
|
||||||
|
@ -92,6 +95,7 @@ public class TSWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
nstry({
|
nstry({
|
||||||
|
self.delegate?.didOutput(bytes)
|
||||||
self.currentFileHandle?.write(bytes)
|
self.currentFileHandle?.write(bytes)
|
||||||
}, { exception in
|
}, { exception in
|
||||||
self.currentFileHandle?.write(bytes)
|
self.currentFileHandle?.write(bytes)
|
||||||
|
@ -139,6 +143,7 @@ public class TSWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
nstry({
|
nstry({
|
||||||
|
self.delegate?.didOutput(bytes)
|
||||||
self.currentFileHandle?.write(bytes)
|
self.currentFileHandle?.write(bytes)
|
||||||
}, { exception in
|
}, { exception in
|
||||||
self.currentFileHandle?.write(bytes)
|
self.currentFileHandle?.write(bytes)
|
||||||
|
@ -224,6 +229,7 @@ public class TSWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
nstry({
|
nstry({
|
||||||
|
self.delegate?.didOutput(bytes)
|
||||||
self.currentFileHandle?.write(bytes)
|
self.currentFileHandle?.write(bytes)
|
||||||
}, { exception in
|
}, { exception in
|
||||||
logger.warn("\(exception)")
|
logger.warn("\(exception)")
|
||||||
|
|
|
@ -160,7 +160,7 @@ open class NetStream: NSObject {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
open func appendSampleBuffer(_ sampleBuffer: CMSampleBuffer, withType: CMSampleBufferType, options: [NSObject: AnyObject]? = nil) {
|
open func appendSampleBuffer(_ sampleBuffer: CMSampleBuffer, withType: AVMediaType, options: [NSObject: AnyObject]? = nil) {
|
||||||
switch withType {
|
switch withType {
|
||||||
case .audio:
|
case .audio:
|
||||||
mixer.audioIO.lockQueue.async {
|
mixer.audioIO.lockQueue.async {
|
||||||
|
@ -170,6 +170,8 @@ open class NetStream: NSObject {
|
||||||
mixer.videoIO.lockQueue.async {
|
mixer.videoIO.lockQueue.async {
|
||||||
self.mixer.videoIO.appendSampleBuffer(sampleBuffer)
|
self.mixer.videoIO.appendSampleBuffer(sampleBuffer)
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,3 @@ import Logboard
|
||||||
|
|
||||||
let logger: Logboard = Logboard.with(HaishinKitIdentifier)
|
let logger: Logboard = Logboard.with(HaishinKitIdentifier)
|
||||||
|
|
||||||
public enum CMSampleBufferType: String {
|
|
||||||
case video
|
|
||||||
case audio
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue