repackage

This commit is contained in:
shogo4405 2021-04-10 15:42:00 +09:00
parent 3d23eb9cfc
commit d9e3bc4797
9 changed files with 280 additions and 265 deletions

View File

@ -68,7 +68,7 @@ final class MainViewController: NSViewController {
// .width: 1920, // .width: 1920,
// .height: 1280, // .height: 1280,
// ] // ]
segmentedControl.isEnabled = false segmentedControl.isEnabled = false
switch segmentedControl.selectedSegment { switch segmentedControl.selectedSegment {
case 0: case 0:

View File

@ -397,6 +397,12 @@
BCB976DF26107B5600C9A649 /* TSAdaptationField.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB976DE26107B5600C9A649 /* TSAdaptationField.swift */; }; BCB976DF26107B5600C9A649 /* TSAdaptationField.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB976DE26107B5600C9A649 /* TSAdaptationField.swift */; };
BCB976E026107B5600C9A649 /* TSAdaptationField.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB976DE26107B5600C9A649 /* TSAdaptationField.swift */; }; BCB976E026107B5600C9A649 /* TSAdaptationField.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB976DE26107B5600C9A649 /* TSAdaptationField.swift */; };
BCB976E126107B5600C9A649 /* TSAdaptationField.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB976DE26107B5600C9A649 /* TSAdaptationField.swift */; }; BCB976E126107B5600C9A649 /* TSAdaptationField.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB976DE26107B5600C9A649 /* TSAdaptationField.swift */; };
BCB9772C26217F4F00C9A649 /* NetSocket.CycleBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB9772B26217F4F00C9A649 /* NetSocket.CycleBuffer.swift */; };
BCB9772D26217F4F00C9A649 /* NetSocket.CycleBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB9772B26217F4F00C9A649 /* NetSocket.CycleBuffer.swift */; };
BCB9772E26217F4F00C9A649 /* NetSocket.CycleBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB9772B26217F4F00C9A649 /* NetSocket.CycleBuffer.swift */; };
BCB9773F2621812800C9A649 /* AVCFormatStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB9773E2621812800C9A649 /* AVCFormatStream.swift */; };
BCB977402621812800C9A649 /* AVCFormatStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB9773E2621812800C9A649 /* AVCFormatStream.swift */; };
BCB977412621812800C9A649 /* AVCFormatStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCB9773E2621812800C9A649 /* AVCFormatStream.swift */; };
BCD1DC3A260627C300A1C593 /* Logboard.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC34DFD125EBB12C005F975A /* Logboard.xcframework */; }; BCD1DC3A260627C300A1C593 /* Logboard.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC34DFD125EBB12C005F975A /* Logboard.xcframework */; };
BCFB355524FA27EA00DC5108 /* PlaybackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFB355324FA275600DC5108 /* PlaybackViewController.swift */; }; BCFB355524FA27EA00DC5108 /* PlaybackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFB355324FA275600DC5108 /* PlaybackViewController.swift */; };
BCFB355A24FA40DD00DC5108 /* PlaybackContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFB355924FA40DD00DC5108 /* PlaybackContainerViewController.swift */; }; BCFB355A24FA40DD00DC5108 /* PlaybackContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFB355924FA40DD00DC5108 /* PlaybackContainerViewController.swift */; };
@ -689,6 +695,8 @@
BC9CFA9223BDE8B700917EEF /* NetStreamRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetStreamRenderer.swift; sourceTree = "<group>"; }; BC9CFA9223BDE8B700917EEF /* NetStreamRenderer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetStreamRenderer.swift; sourceTree = "<group>"; };
BCB976D026107B1200C9A649 /* TSAdaptationExtensionField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSAdaptationExtensionField.swift; sourceTree = "<group>"; }; BCB976D026107B1200C9A649 /* TSAdaptationExtensionField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSAdaptationExtensionField.swift; sourceTree = "<group>"; };
BCB976DE26107B5600C9A649 /* TSAdaptationField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSAdaptationField.swift; sourceTree = "<group>"; }; BCB976DE26107B5600C9A649 /* TSAdaptationField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSAdaptationField.swift; sourceTree = "<group>"; };
BCB9772B26217F4F00C9A649 /* NetSocket.CycleBuffer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetSocket.CycleBuffer.swift; sourceTree = "<group>"; };
BCB9773E2621812800C9A649 /* AVCFormatStream.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AVCFormatStream.swift; sourceTree = "<group>"; };
BCFB355324FA275600DC5108 /* PlaybackViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackViewController.swift; sourceTree = "<group>"; }; BCFB355324FA275600DC5108 /* PlaybackViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackViewController.swift; sourceTree = "<group>"; };
BCFB355624FA37F700DC5108 /* HKPictureInPicureController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HKPictureInPicureController.swift; sourceTree = "<group>"; }; BCFB355624FA37F700DC5108 /* HKPictureInPicureController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HKPictureInPicureController.swift; sourceTree = "<group>"; };
BCFB355924FA40DD00DC5108 /* PlaybackContainerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackContainerViewController.swift; sourceTree = "<group>"; }; BCFB355924FA40DD00DC5108 /* PlaybackContainerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackContainerViewController.swift; sourceTree = "<group>"; };
@ -965,8 +973,9 @@
children = ( children = (
29B8767D1CD70AE800FC07DA /* AudioSpecificConfig.swift */, 29B8767D1CD70AE800FC07DA /* AudioSpecificConfig.swift */,
29B8767E1CD70AE800FC07DA /* AVCConfigurationRecord.swift */, 29B8767E1CD70AE800FC07DA /* AVCConfigurationRecord.swift */,
292D8A321D8B293300DBECE2 /* MP4Sampler.swift */, BCB9773E2621812800C9A649 /* AVCFormatStream.swift */,
29798E511CE5DF1900F5CBD0 /* MP4Reader.swift */, 29798E511CE5DF1900F5CBD0 /* MP4Reader.swift */,
292D8A321D8B293300DBECE2 /* MP4Sampler.swift */,
29B8767F1CD70AE800FC07DA /* NALUnit.swift */, 29B8767F1CD70AE800FC07DA /* NALUnit.swift */,
29B876801CD70AE800FC07DA /* PacketizedElementaryStream.swift */, 29B876801CD70AE800FC07DA /* PacketizedElementaryStream.swift */,
29B876811CD70AE800FC07DA /* ProgramSpecific.swift */, 29B876811CD70AE800FC07DA /* ProgramSpecific.swift */,
@ -1068,6 +1077,7 @@
29B876971CD70B1100FC07DA /* MIME.swift */, 29B876971CD70B1100FC07DA /* MIME.swift */,
29B876981CD70B1100FC07DA /* NetClient.swift */, 29B876981CD70B1100FC07DA /* NetClient.swift */,
29B876991CD70B1100FC07DA /* NetService.swift */, 29B876991CD70B1100FC07DA /* NetService.swift */,
BCB9772B26217F4F00C9A649 /* NetSocket.CycleBuffer.swift */,
29B8769A1CD70B1100FC07DA /* NetSocket.swift */, 29B8769A1CD70B1100FC07DA /* NetSocket.swift */,
29AF3FCE1D7C744C00E41212 /* NetStream.swift */, 29AF3FCE1D7C744C00E41212 /* NetStream.swift */,
BC9CFA9223BDE8B700917EEF /* NetStreamRenderer.swift */, BC9CFA9223BDE8B700917EEF /* NetStreamRenderer.swift */,
@ -1617,6 +1627,7 @@
295891161EEB8DFC00CE51E1 /* FLVTagType.swift in Sources */, 295891161EEB8DFC00CE51E1 /* FLVTagType.swift in Sources */,
29B876B11CD70B2800FC07DA /* RTMPMessage.swift in Sources */, 29B876B11CD70B2800FC07DA /* RTMPMessage.swift in Sources */,
2941746B22D069B300A2944F /* AudioEffect.swift in Sources */, 2941746B22D069B300A2944F /* AudioEffect.swift in Sources */,
BCB9773F2621812800C9A649 /* AVCFormatStream.swift in Sources */,
295891011EEB7A8B00CE51E1 /* ScalingMode.swift in Sources */, 295891011EEB7A8B00CE51E1 /* ScalingMode.swift in Sources */,
BC83A4732403D83B006BDE06 /* VTCompressionSession+Extension.swift in Sources */, BC83A4732403D83B006BDE06 /* VTCompressionSession+Extension.swift in Sources */,
2943ED53232FCA7C00ED6301 /* Setting.swift in Sources */, 2943ED53232FCA7C00ED6301 /* Setting.swift in Sources */,
@ -1652,6 +1663,7 @@
BC9CFA9323BDE8B700917EEF /* NetStreamRenderer.swift in Sources */, BC9CFA9323BDE8B700917EEF /* NetStreamRenderer.swift in Sources */,
29B8769B1CD70B1100FC07DA /* MIME.swift in Sources */, 29B8769B1CD70B1100FC07DA /* MIME.swift in Sources */,
29B8769C1CD70B1100FC07DA /* NetClient.swift in Sources */, 29B8769C1CD70B1100FC07DA /* NetClient.swift in Sources */,
BCB9772C26217F4F00C9A649 /* NetSocket.CycleBuffer.swift in Sources */,
29B876871CD70AE800FC07DA /* ProgramSpecific.swift in Sources */, 29B876871CD70AE800FC07DA /* ProgramSpecific.swift in Sources */,
BC4C9EAF23F2E736004A14F2 /* AudioStreamBasicDescription+Extension.swift in Sources */, BC4C9EAF23F2E736004A14F2 /* AudioStreamBasicDescription+Extension.swift in Sources */,
BC558268240BB40E00011AC0 /* RTMPStreamInfo.swift in Sources */, BC558268240BB40E00011AC0 /* RTMPStreamInfo.swift in Sources */,
@ -1764,6 +1776,7 @@
29B876EC1CD70D5900FC07DA /* AudioCodec.swift in Sources */, 29B876EC1CD70D5900FC07DA /* AudioCodec.swift in Sources */,
29B876ED1CD70D5900FC07DA /* H264Decoder.swift in Sources */, 29B876ED1CD70D5900FC07DA /* H264Decoder.swift in Sources */,
BC8E32E42532F3700087DF49 /* GLHKView.swift in Sources */, BC8E32E42532F3700087DF49 /* GLHKView.swift in Sources */,
BCB977402621812800C9A649 /* AVCFormatStream.swift in Sources */,
29B876EE1CD70D5900FC07DA /* H264Encoder.swift in Sources */, 29B876EE1CD70D5900FC07DA /* H264Encoder.swift in Sources */,
29EA87EB1E79A3B70043A5F8 /* CMBlockBuffer+Extension.swift in Sources */, 29EA87EB1E79A3B70043A5F8 /* CMBlockBuffer+Extension.swift in Sources */,
29B876F01CD70D5900FC07DA /* Constants.swift in Sources */, 29B876F01CD70D5900FC07DA /* Constants.swift in Sources */,
@ -1799,6 +1812,7 @@
BC9CFA9423BDE8B700917EEF /* NetStreamRenderer.swift in Sources */, BC9CFA9423BDE8B700917EEF /* NetStreamRenderer.swift in Sources */,
BC20DF31250374A7007BC608 /* HKPictureInPicureController.swift in Sources */, BC20DF31250374A7007BC608 /* HKPictureInPicureController.swift in Sources */,
296242631D8DBA8C00C451A3 /* TSReader.swift in Sources */, 296242631D8DBA8C00C451A3 /* TSReader.swift in Sources */,
BCB9772D26217F4F00C9A649 /* NetSocket.CycleBuffer.swift in Sources */,
29B876FE1CD70D5A00FC07DA /* AVCConfigurationRecord.swift in Sources */, 29B876FE1CD70D5A00FC07DA /* AVCConfigurationRecord.swift in Sources */,
295891171EEB8DFC00CE51E1 /* FLVTagType.swift in Sources */, 295891171EEB8DFC00CE51E1 /* FLVTagType.swift in Sources */,
294852571D852499002DE492 /* RTMPTSocket.swift in Sources */, 294852571D852499002DE492 /* RTMPTSocket.swift in Sources */,
@ -1980,6 +1994,7 @@
29EB3E011ED05856001CAE8B /* HTTPStream.swift in Sources */, 29EB3E011ED05856001CAE8B /* HTTPStream.swift in Sources */,
29EB3E171ED05893001CAE8B /* NetClient.swift in Sources */, 29EB3E171ED05893001CAE8B /* NetClient.swift in Sources */,
BCB976D326107B1200C9A649 /* TSAdaptationExtensionField.swift in Sources */, BCB976D326107B1200C9A649 /* TSAdaptationExtensionField.swift in Sources */,
BCB977412621812800C9A649 /* AVCFormatStream.swift in Sources */,
BC4C9EB123F2E736004A14F2 /* AudioStreamBasicDescription+Extension.swift in Sources */, BC4C9EB123F2E736004A14F2 /* AudioStreamBasicDescription+Extension.swift in Sources */,
2958912C1EEB8F1D00CE51E1 /* FLVSoundSize.swift in Sources */, 2958912C1EEB8F1D00CE51E1 /* FLVSoundSize.swift in Sources */,
BC4DAEB32479851D005EFD57 /* FilenameUtil.swift in Sources */, BC4DAEB32479851D005EFD57 /* FilenameUtil.swift in Sources */,
@ -1995,6 +2010,7 @@
29EB3E361ED05A35001CAE8B /* EventDispatcher.swift in Sources */, 29EB3E361ED05A35001CAE8B /* EventDispatcher.swift in Sources */,
29EB3E341ED05A30001CAE8B /* CRC32.swift in Sources */, 29EB3E341ED05A30001CAE8B /* CRC32.swift in Sources */,
BC566F7025D2ECC500573C4C /* HLSService.swift in Sources */, BC566F7025D2ECC500573C4C /* HLSService.swift in Sources */,
BCB9772E26217F4F00C9A649 /* NetSocket.CycleBuffer.swift in Sources */,
29FD1B5222FF13190095A0BE /* VTSessionPropertyKey.swift in Sources */, 29FD1B5222FF13190095A0BE /* VTSessionPropertyKey.swift in Sources */,
29EB3E181ED05896001CAE8B /* NetService.swift in Sources */, 29EB3E181ED05896001CAE8B /* NetService.swift in Sources */,
295891281EEB8EF300CE51E1 /* FLVAACPacket.swift in Sources */, 295891281EEB8EF300CE51E1 /* FLVAACPacket.swift in Sources */,

View File

@ -45,7 +45,7 @@ public enum FLVAudioCodec: UInt8 {
var formatFlags: AudioFormatFlags { var formatFlags: AudioFormatFlags {
switch self { switch self {
case .aac: case .aac:
return AudioFormatFlags(AudioObjectType.aacMain.rawValue) return AudioFormatFlags(AudioSpecificConfig.AudioObjectType.aacMain.rawValue)
default: default:
return 0 return 0
} }

View File

@ -1,40 +1,6 @@
import AVFoundation import AVFoundation
import VideoToolbox import VideoToolbox
struct AVCFormatStream {
let data: Data
init(data: Data) {
self.data = data
}
init?(bytes: UnsafePointer<UInt8>, count: UInt32) {
self.init(data: Data(bytes: bytes, count: Int(count)))
}
init?(data: Data?) {
guard let data = data else {
return nil
}
self.init(data: data)
}
func toByteStream() -> Data {
let buffer = ByteArray(data: data)
var result = Data()
while 0 < buffer.bytesAvailable {
do {
let length: Int = try Int(buffer.readUInt32())
result.append(contentsOf: [0x00, 0x00, 0x00, 0x01])
result.append(try buffer.readBytes(length))
} catch {
logger.error("\(buffer)")
}
}
return result
}
}
// MARK: - // MARK: -
/* /*
- seealso: ISO/IEC 14496-15 2010 - seealso: ISO/IEC 14496-15 2010

View File

@ -0,0 +1,35 @@
import Foundation
struct AVCFormatStream {
let data: Data
init(data: Data) {
self.data = data
}
init?(bytes: UnsafePointer<UInt8>, count: UInt32) {
self.init(data: Data(bytes: bytes, count: Int(count)))
}
init?(data: Data?) {
guard let data = data else {
return nil
}
self.init(data: data)
}
func toByteStream() -> Data {
let buffer = ByteArray(data: data)
var result = Data()
while 0 < buffer.bytesAvailable {
do {
let length: Int = try Int(buffer.readUInt32())
result.append(contentsOf: [0x00, 0x00, 0x00, 0x01])
result.append(try buffer.readBytes(length))
} catch {
logger.error("\(buffer)")
}
}
return result
}
}

View File

@ -9,6 +9,135 @@ import AVFoundation
struct AudioSpecificConfig { struct AudioSpecificConfig {
static let ADTSHeaderSize: Int = 7 static let ADTSHeaderSize: Int = 7
enum AudioObjectType: UInt8 {
case unknown = 0
case aacMain = 1
case aaclc = 2
case aacssr = 3
case aacltp = 4
case aacsbr = 5
case aacScalable = 6
case twinqVQ = 7
case celp = 8
case hxvc = 9
init(objectID: MPEG4ObjectID) {
switch objectID {
case .aac_Main:
self = .aacMain
case .AAC_LC:
self = .aaclc
case .AAC_SSR:
self = .aacssr
case .AAC_LTP:
self = .aacltp
case .AAC_SBR:
self = .aacsbr
case .aac_Scalable:
self = .aacScalable
case .twinVQ:
self = .twinqVQ
case .CELP:
self = .celp
case .HVXC:
self = .hxvc
@unknown default:
self = .unknown
}
}
}
enum SamplingFrequency: UInt8 {
case hz96000 = 0
case hz88200 = 1
case hz64000 = 2
case hz48000 = 3
case hz44100 = 4
case hz32000 = 5
case hz24000 = 6
case hz22050 = 7
case hz16000 = 8
case hz12000 = 9
case hz11025 = 10
case hz8000 = 11
case hz7350 = 12
var sampleRate: Float64 {
switch self {
case .hz96000:
return 96000
case .hz88200:
return 88200
case .hz64000:
return 64000
case .hz48000:
return 48000
case .hz44100:
return 44100
case .hz32000:
return 32000
case .hz24000:
return 24000
case .hz22050:
return 22050
case .hz16000:
return 16000
case .hz12000:
return 12000
case .hz11025:
return 11025
case .hz8000:
return 8000
case .hz7350:
return 7350
}
}
init(sampleRate: Float64) {
switch Int(sampleRate) {
case 96000:
self = .hz96000
case 88200:
self = .hz88200
case 64000:
self = .hz64000
case 48000:
self = .hz48000
case 44100:
self = .hz44100
case 32000:
self = .hz32000
case 24000:
self = .hz24000
case 22050:
self = .hz22050
case 16000:
self = .hz16000
case 12000:
self = .hz12000
case 11025:
self = .hz11025
case 8000:
self = .hz8000
case 7350:
self = .hz7350
default:
self = .hz44100
}
}
}
enum ChannelConfiguration: UInt8 {
case definedInAOTSpecificConfig = 0
case frontCenter = 1
case frontLeftAndFrontRight = 2
case frontCenterAndFrontLeftAndFrontRight = 3
case frontCenterAndFrontLeftAndFrontRightAndBackCenter = 4
case frontCenterAndFrontLeftAndFrontRightAndBackLeftAndBackRight = 5
case frontCenterAndFrontLeftAndFrontRightAndBackLeftAndBackRightLFE = 6
case frontCenterAndFrontLeftAndFrontRightAndSideLeftAndSideRightAndBackLeftAndBackRightLFE = 7
}
let type: AudioObjectType let type: AudioObjectType
let frequency: SamplingFrequency let frequency: SamplingFrequency
let channel: ChannelConfiguration let channel: ChannelConfiguration
@ -81,135 +210,3 @@ extension AudioSpecificConfig: CustomDebugStringConvertible {
Mirror(reflecting: self).debugDescription Mirror(reflecting: self).debugDescription
} }
} }
// MARK: -
enum AudioObjectType: UInt8 {
case unknown = 0
case aacMain = 1
case aaclc = 2
case aacssr = 3
case aacltp = 4
case aacsbr = 5
case aacScalable = 6
case twinqVQ = 7
case celp = 8
case hxvc = 9
init(objectID: MPEG4ObjectID) {
switch objectID {
case .aac_Main:
self = .aacMain
case .AAC_LC:
self = .aaclc
case .AAC_SSR:
self = .aacssr
case .AAC_LTP:
self = .aacltp
case .AAC_SBR:
self = .aacsbr
case .aac_Scalable:
self = .aacScalable
case .twinVQ:
self = .twinqVQ
case .CELP:
self = .celp
case .HVXC:
self = .hxvc
@unknown default:
self = .unknown
}
}
}
// MARK: -
public enum SamplingFrequency: UInt8 {
case hz96000 = 0
case hz88200 = 1
case hz64000 = 2
case hz48000 = 3
case hz44100 = 4
case hz32000 = 5
case hz24000 = 6
case hz22050 = 7
case hz16000 = 8
case hz12000 = 9
case hz11025 = 10
case hz8000 = 11
case hz7350 = 12
public var sampleRate: Float64 {
switch self {
case .hz96000:
return 96000
case .hz88200:
return 88200
case .hz64000:
return 64000
case .hz48000:
return 48000
case .hz44100:
return 44100
case .hz32000:
return 32000
case .hz24000:
return 24000
case .hz22050:
return 22050
case .hz16000:
return 16000
case .hz12000:
return 12000
case .hz11025:
return 11025
case .hz8000:
return 8000
case .hz7350:
return 7350
}
}
public init(sampleRate: Float64) {
switch Int(sampleRate) {
case 96000:
self = .hz96000
case 88200:
self = .hz88200
case 64000:
self = .hz64000
case 48000:
self = .hz48000
case 44100:
self = .hz44100
case 32000:
self = .hz32000
case 24000:
self = .hz24000
case 22050:
self = .hz22050
case 16000:
self = .hz16000
case 12000:
self = .hz12000
case 11025:
self = .hz11025
case 8000:
self = .hz8000
case 7350:
self = .hz7350
default:
self = .hz44100
}
}
}
// MARK: -
enum ChannelConfiguration: UInt8 {
case definedInAOTSpecificConfig = 0
case frontCenter = 1
case frontLeftAndFrontRight = 2
case frontCenterAndFrontLeftAndFrontRight = 3
case frontCenterAndFrontLeftAndFrontRightAndBackCenter = 4
case frontCenterAndFrontLeftAndFrontRightAndBackLeftAndBackRight = 5
case frontCenterAndFrontLeftAndFrontRightAndBackLeftAndBackRightLFE = 6
case frontCenterAndFrontLeftAndFrontRightAndSideLeftAndSideRightAndBackLeftAndBackRightLFE = 7
}

View File

@ -0,0 +1,97 @@
import Foundation
extension NetSocket {
struct CycleBuffer: CustomDebugStringConvertible {
var bytes: UnsafePointer<UInt8>? {
data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> UnsafePointer<UInt8>? in
bytes.baseAddress?.assumingMemoryBound(to: UInt8.self).advanced(by: top)
}
}
var maxLength: Int {
min(count, capacity - top)
}
var debugDescription: String {
Mirror(reflecting: self).debugDescription
}
private var count: Int {
let value = bottom - top
return value < 0 ? value + capacity : value
}
private var data: Data
private var capacity: Int = 0 {
didSet {
logger.info("extends a buffer size from ", oldValue, " to ", capacity)
}
}
private var top: Int = 0
private var bottom: Int = 0
private var locked: UnsafeMutablePointer<UInt32>?
private var lockedBottom: Int = -1
init(capacity: Int) {
self.capacity = capacity
data = .init(repeating: 0, count: capacity)
}
mutating func append(_ data: Data, locked: UnsafeMutablePointer<UInt32>? = nil) {
guard data.count + count < capacity else {
extend(data)
return
}
let count = data.count
if self.locked == nil {
self.locked = locked
}
let length = min(count, capacity - bottom)
self.data.replaceSubrange(bottom..<bottom + length, with: data)
if length < count {
bottom = count - length
self.data.replaceSubrange(0..<bottom, with: data.advanced(by: length))
} else {
bottom += count
}
if capacity == bottom {
bottom = 0
}
if locked != nil {
lockedBottom = bottom
}
}
mutating func markAsRead(_ count: Int) {
let length = min(count, capacity - top)
if length < count {
top = count - length
} else {
top += count
}
if capacity == top {
top = 0
}
if let locked = locked, -1 < lockedBottom && lockedBottom <= top {
OSAtomicAnd32Barrier(0, locked)
lockedBottom = -1
}
}
mutating func clear() {
top = 0
bottom = 0
locked = nil
lockedBottom = 0
}
private mutating func extend(_ data: Data) {
if 0 < top {
let subdata = self.data.subdata(in: 0..<bottom)
self.data.replaceSubrange(0..<capacity - top, with: self.data.advanced(by: top))
self.data.replaceSubrange(capacity - top..<capacity - top + subdata.count, with: subdata)
bottom = capacity - top + subdata.count
}
self.data.append(.init(count: capacity))
top = 0
capacity = self.data.count
append(data)
}
}
}

View File

@ -2,100 +2,6 @@ import Foundation
/// The NetSocket class creates a two-way connection between a client and a server. This class is wrapper for a InputStream and an OutputStream. /// The NetSocket class creates a two-way connection between a client and a server. This class is wrapper for a InputStream and an OutputStream.
open class NetSocket: NSObject { open class NetSocket: NSObject {
struct CycleBuffer: CustomDebugStringConvertible {
var bytes: UnsafePointer<UInt8>? {
data.withUnsafeBytes { (bytes: UnsafeRawBufferPointer) -> UnsafePointer<UInt8>? in
bytes.baseAddress?.assumingMemoryBound(to: UInt8.self).advanced(by: top)
}
}
var maxLength: Int {
min(count, capacity - top)
}
var debugDescription: String {
Mirror(reflecting: self).debugDescription
}
private var count: Int {
let value = bottom - top
return value < 0 ? value + capacity : value
}
private var data: Data
private var capacity: Int = 0 {
didSet {
logger.info("extends a buffer size from ", oldValue, " to ", capacity)
}
}
private var top: Int = 0
private var bottom: Int = 0
private var locked: UnsafeMutablePointer<UInt32>?
private var lockedBottom: Int = -1
init(capacity: Int) {
self.capacity = capacity
data = .init(repeating: 0, count: capacity)
}
mutating func append(_ data: Data, locked: UnsafeMutablePointer<UInt32>? = nil) {
guard data.count + count < capacity else {
extend(data)
return
}
let count = data.count
if self.locked == nil {
self.locked = locked
}
let length = min(count, capacity - bottom)
self.data.replaceSubrange(bottom..<bottom + length, with: data)
if length < count {
bottom = count - length
self.data.replaceSubrange(0..<bottom, with: data.advanced(by: length))
} else {
bottom += count
}
if capacity == bottom {
bottom = 0
}
if locked != nil {
lockedBottom = bottom
}
}
mutating func markAsRead(_ count: Int) {
let length = min(count, capacity - top)
if length < count {
top = count - length
} else {
top += count
}
if capacity == top {
top = 0
}
if let locked = locked, -1 < lockedBottom && lockedBottom <= top {
OSAtomicAnd32Barrier(0, locked)
lockedBottom = -1
}
}
mutating func clear() {
top = 0
bottom = 0
locked = nil
lockedBottom = 0
}
private mutating func extend(_ data: Data) {
if 0 < top {
let subdata = self.data.subdata(in: 0..<bottom)
self.data.replaceSubrange(0..<capacity - top, with: self.data.advanced(by: top))
self.data.replaceSubrange(capacity - top..<capacity - top + subdata.count, with: subdata)
bottom = capacity - top + subdata.count
}
self.data.append(.init(count: capacity))
top = 0
capacity = self.data.count
append(data)
}
}
/// The default time to wait for TCP/IP Handshake done. /// The default time to wait for TCP/IP Handshake done.
public static let defaultTimeout: Int = 15 // sec public static let defaultTimeout: Int = 15 // sec
public static let defaultWindowSizeC = Int(UInt16.max) public static let defaultWindowSizeC = Int(UInt16.max)

View File

@ -121,7 +121,6 @@ extension TSPacket: CustomDebugStringConvertible {
} }
} }
// MARK: - // MARK: -
struct TSTimestamp { struct TSTimestamp {
static let resolution: Double = 90 * 1000 // 90kHz static let resolution: Double = 90 * 1000 // 90kHz
@ -186,4 +185,3 @@ struct TSProgramClockReference {
return data return data
} }
} }