add TSWriterDelegate
This commit is contained in:
parent
fa877229ab
commit
d25f233bcc
|
@ -8,7 +8,7 @@ protocol AudioEncoderDelegate: class {
|
||||||
// MARK: -
|
// MARK: -
|
||||||
/**
|
/**
|
||||||
- seealse:
|
- seealse:
|
||||||
- https: //developer.apple.com/library/ios/technotes/tn2236/_index.html
|
- https://developer.apple.com/library/ios/technotes/tn2236/_index.html
|
||||||
*/
|
*/
|
||||||
final class AACEncoder: NSObject {
|
final class AACEncoder: NSObject {
|
||||||
enum Error: Swift.Error {
|
enum Error: Swift.Error {
|
||||||
|
|
|
@ -154,7 +154,7 @@ final class H264Encoder: NSObject {
|
||||||
private var invalidateSession: Bool = true
|
private var invalidateSession: Bool = true
|
||||||
private var lastImageBuffer: CVImageBuffer?
|
private var lastImageBuffer: CVImageBuffer?
|
||||||
|
|
||||||
// @see: https: //developer.apple.com/library/mac/releasenotes/General/APIDiffsMacOSX10_8/VideoToolbox.html
|
// @see: https://developer.apple.com/library/mac/releasenotes/General/APIDiffsMacOSX10_8/VideoToolbox.html
|
||||||
private var properties: [NSString: NSObject] {
|
private var properties: [NSString: NSObject] {
|
||||||
let isBaseline: Bool = profileLevel.contains("Baseline")
|
let isBaseline: Bool = profileLevel.contains("Baseline")
|
||||||
var properties: [NSString: NSObject] = [
|
var properties: [NSString: NSObject] = [
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
- seealso: https: //tools.ietf.org/html/draft-pantos-http-live-streaming-19
|
- seealso: https://tools.ietf.org/html/draft-pantos-http-live-streaming-19
|
||||||
*/
|
*/
|
||||||
struct M3U {
|
struct M3U {
|
||||||
static let header: String = "#EXTM3U"
|
static let header: String = "#EXTM3U"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/**
|
/**
|
||||||
- seealso: https: //en.wikipedia.org/wiki/Program-specific_information
|
- seealso: https://en.wikipedia.org/wiki/Program-specific_information
|
||||||
*/
|
*/
|
||||||
protocol PSIPointer {
|
protocol PSIPointer {
|
||||||
var pointerField: UInt8 { get set }
|
var pointerField: UInt8 { get set }
|
||||||
|
|
|
@ -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)")
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import AVFoundation
|
import AVFoundation
|
||||||
/**
|
/**
|
||||||
- seealso: https: //en.wikipedia.org/wiki/MPEG_transport_stream#Packet
|
- seealso: https://en.wikipedia.org/wiki/MPEG_transport_stream#Packet
|
||||||
*/
|
*/
|
||||||
struct TSPacket {
|
struct TSPacket {
|
||||||
static let size: Int = 188
|
static let size: Int = 188
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ import Foundation
|
||||||
Message Digest Algorithm 5
|
Message Digest Algorithm 5
|
||||||
|
|
||||||
- seealso:
|
- seealso:
|
||||||
- https: //ja.wikipedia.org/wiki/MD5
|
- https://ja.wikipedia.org/wiki/MD5
|
||||||
- https: //www.ietf.org/rfc/rfc1321.txt
|
- https://www.ietf.org/rfc/rfc1321.txt
|
||||||
*/
|
*/
|
||||||
final class MD5 {
|
final class MD5 {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue