-
-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
413 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ analyzer_rules: | |
excluded: | ||
- Carthage | ||
- Pods | ||
- Tests | ||
- Vendor | ||
- .build | ||
opt_in_rules: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import CoreMedia | ||
import Foundation | ||
import Testing | ||
import CoreMedia | ||
|
||
@testable import HaishinKit | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import Foundation | ||
import AVFoundation | ||
import Foundation | ||
import Testing | ||
|
||
@testable import HaishinKit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import Foundation | ||
import CoreMedia | ||
import Foundation | ||
import Testing | ||
|
||
@testable import HaishinKit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import Foundation | ||
import AVFoundation | ||
import Foundation | ||
import Testing | ||
|
||
@testable import HaishinKit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import Foundation | ||
import CoreMedia | ||
import Foundation | ||
import Testing | ||
|
||
@testable import HaishinKit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import Foundation | ||
import CoreMedia | ||
import Foundation | ||
import Testing | ||
|
||
@testable import HaishinKit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,81 @@ | ||
import AVFAudio | ||
import Foundation | ||
import Testing | ||
import Logboard | ||
import AVFAudio | ||
import Testing | ||
|
||
@testable import HaishinKit | ||
|
||
/* | ||
|
||
final class TSReaderTests: XCTestCase { | ||
func testTSFileRead() { | ||
let bundle = Bundle(for: type(of: self)) | ||
let url = URL(fileURLWithPath: bundle.path(forResource: "SampleVideo_360x240_5mb_2ch", ofType: "ts")!) | ||
do { | ||
let readerDelegate = TSReaderTestsResult() | ||
let fileHandle = try FileHandle(forReadingFrom: url) | ||
let reader = TSReader<TSReaderTestsResult>() | ||
reader.delegate = readerDelegate | ||
_ = reader.read(fileHandle.readDataToEndOfFile()) | ||
} catch { | ||
} | ||
} | ||
final class TSReaderTests: XCTestCase { | ||
func testTSFileRead() { | ||
let bundle = Bundle(for: type(of: self)) | ||
let url = URL(fileURLWithPath: bundle.path(forResource: "SampleVideo_360x240_5mb_2ch", ofType: "ts")!) | ||
do { | ||
let readerDelegate = TSReaderTestsResult() | ||
let fileHandle = try FileHandle(forReadingFrom: url) | ||
let reader = TSReader<TSReaderTestsResult>() | ||
reader.delegate = readerDelegate | ||
_ = reader.read(fileHandle.readDataToEndOfFile()) | ||
} catch { | ||
} | ||
} | ||
|
||
func testTSFileRead_changeResolution() { | ||
let bundle = Bundle(for: type(of: self)) | ||
let url = URL(fileURLWithPath: bundle.path(forResource: "change_video_resolution", ofType: "ts")!) | ||
do { | ||
let readerDelegate = TSReaderTestsResult() | ||
let fileHandle = try FileHandle(forReadingFrom: url) | ||
let reader = TSReader<TSReaderTestsResult>() | ||
reader.delegate = readerDelegate | ||
_ = reader.read(fileHandle.readDataToEndOfFile()) | ||
XCTAssertEqual(readerDelegate.videoFormats[0].dimensions.width, 640) | ||
XCTAssertEqual(readerDelegate.videoFormats[0].dimensions.height, 360) | ||
XCTAssertEqual(readerDelegate.videoFormats[1].dimensions.width, 1280) | ||
XCTAssertEqual(readerDelegate.videoFormats[1].dimensions.height, 720) | ||
XCTAssertEqual(readerDelegate.videoFormats[2].dimensions.width, 1920) | ||
XCTAssertEqual(readerDelegate.videoFormats[2].dimensions.height, 1080) | ||
} catch { | ||
} | ||
} | ||
} | ||
|
||
func testTSFileRead_changeResolution() { | ||
let bundle = Bundle(for: type(of: self)) | ||
let url = URL(fileURLWithPath: bundle.path(forResource: "change_video_resolution", ofType: "ts")!) | ||
do { | ||
let readerDelegate = TSReaderTestsResult() | ||
let fileHandle = try FileHandle(forReadingFrom: url) | ||
let reader = TSReader<TSReaderTestsResult>() | ||
reader.delegate = readerDelegate | ||
_ = reader.read(fileHandle.readDataToEndOfFile()) | ||
XCTAssertEqual(readerDelegate.videoFormats[0].dimensions.width, 640) | ||
XCTAssertEqual(readerDelegate.videoFormats[0].dimensions.height, 360) | ||
XCTAssertEqual(readerDelegate.videoFormats[1].dimensions.width, 1280) | ||
XCTAssertEqual(readerDelegate.videoFormats[1].dimensions.height, 720) | ||
XCTAssertEqual(readerDelegate.videoFormats[2].dimensions.width, 1920) | ||
XCTAssertEqual(readerDelegate.videoFormats[2].dimensions.height, 1080) | ||
} catch { | ||
} | ||
} | ||
} | ||
private final class TSReaderTestsResult: TSReaderDelegate, AudioCodecDelegate { | ||
private var audioCodec: HaishinKit.AudioCodec<TSReaderTestsResult> = .init(lockQueue: DispatchQueue(label: "TSReaderAudioCodec")) | ||
|
||
private final class TSReaderTestsResult: TSReaderDelegate, AudioCodecDelegate { | ||
private var audioCodec: HaishinKit.AudioCodec<TSReaderTestsResult> = .init(lockQueue: DispatchQueue(label: "TSReaderAudioCodec")) | ||
|
||
var videoFormats: [CMFormatDescription] = [] | ||
var videoFormats: [CMFormatDescription] = [] | ||
|
||
init() { | ||
audioCodec.delegate = self | ||
audioCodec.settings.format = .pcm | ||
audioCodec.startRunning() | ||
} | ||
init() { | ||
audioCodec.delegate = self | ||
audioCodec.settings.format = .pcm | ||
audioCodec.startRunning() | ||
} | ||
|
||
func reader(_ reader: TSReader<TSReaderTestsResult>, id: UInt16, didRead formatDescription: CMFormatDescription) { | ||
switch formatDescription.mediaType { | ||
case .video: | ||
videoFormats.append(formatDescription) | ||
default: | ||
break | ||
} | ||
} | ||
func reader(_ reader: TSReader<TSReaderTestsResult>, id: UInt16, didRead formatDescription: CMFormatDescription) { | ||
switch formatDescription.mediaType { | ||
case .video: | ||
videoFormats.append(formatDescription) | ||
default: | ||
break | ||
} | ||
} | ||
|
||
func reader(_ reader: TSReader<TSReaderTestsResult>, id: UInt16, didRead sampleBuffer: CMSampleBuffer) { | ||
if sampleBuffer.formatDescription?.mediaType == .audio { | ||
audioCodec.append(sampleBuffer) | ||
} | ||
} | ||
func reader(_ reader: TSReader<TSReaderTestsResult>, id: UInt16, didRead sampleBuffer: CMSampleBuffer) { | ||
if sampleBuffer.formatDescription?.mediaType == .audio { | ||
audioCodec.append(sampleBuffer) | ||
} | ||
} | ||
|
||
func audioCodec(_ codec: HaishinKit.AudioCodec<TSReaderTestsResult>, didOutput outputFormat: AVAudioFormat?) { | ||
} | ||
func audioCodec(_ codec: HaishinKit.AudioCodec<TSReaderTestsResult>, didOutput outputFormat: AVAudioFormat?) { | ||
} | ||
|
||
func audioCodec(_ codec: HaishinKit.AudioCodec<TSReaderTestsResult>, errorOccurred error: HaishinKit.IOAudioUnitError) { | ||
// XCTFail() | ||
} | ||
func audioCodec(_ codec: HaishinKit.AudioCodec<TSReaderTestsResult>, errorOccurred error: HaishinKit.IOAudioUnitError) { | ||
// XCTFail() | ||
} | ||
|
||
func audioCodec(_ codec: HaishinKit.AudioCodec<TSReaderTestsResult>, didOutput audioBuffer: AVAudioBuffer, when: AVAudioTime) { | ||
} | ||
} | ||
func audioCodec(_ codec: HaishinKit.AudioCodec<TSReaderTestsResult>, didOutput audioBuffer: AVAudioBuffer, when: AVAudioTime) { | ||
} | ||
} | ||
|
||
*/ | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import Foundation | ||
import AVFoundation | ||
import Foundation | ||
import Testing | ||
|
||
@testable import HaishinKit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,58 @@ | ||
import Foundation | ||
import AVFoundation | ||
import Foundation | ||
import Testing | ||
|
||
@testable import HaishinKit | ||
|
||
@Suite struct AudioMixerTrackTests { | ||
/* | ||
@Test func pKeep16000() { | ||
let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 16000, channels: 1, interleaved: true)! | ||
let track = AudioMixerTrack<AudioMixerTrackTests>(id: 0, outputFormat: format) | ||
track.delegate = self | ||
track.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) | ||
#expect(track.outputFormat.sampleRate == 16000) | ||
track.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) | ||
#expect(track.outputFormat.sampleRate == 16000) | ||
} | ||
@Test func pKeep16000() { | ||
let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 16000, channels: 1, interleaved: true)! | ||
let track = AudioMixerTrack<AudioMixerTrackTests>(id: 0, outputFormat: format) | ||
track.delegate = self | ||
track.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) | ||
#expect(track.outputFormat.sampleRate == 16000) | ||
track.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) | ||
#expect(track.outputFormat.sampleRate == 16000) | ||
} | ||
|
||
@Test func pKeep44100() { | ||
let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 44100, channels: 1, interleaved: true)! | ||
let resampler = AudioMixerTrack<AudioMixerTrackTests>(id: 0, outputFormat: format) | ||
resampler.delegate = self | ||
resampler.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) | ||
#expect(resampler.outputFormat.sampleRate == 44100) | ||
resampler.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) | ||
#expect(resampler.outputFormat.sampleRate == 44100) | ||
resampler.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) | ||
#expect(resampler.outputFormat.sampleRate == 44100) | ||
resampler.append(CMAudioSampleBufferFactory.makeSinWave(16000, numSamples: 1024 * 20, channels: 1)!) | ||
#expect(resampler.outputFormat.sampleRate == 44100) | ||
} | ||
@Test func pKeep44100() { | ||
let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 44100, channels: 1, interleaved: true)! | ||
let resampler = AudioMixerTrack<AudioMixerTrackTests>(id: 0, outputFormat: format) | ||
resampler.delegate = self | ||
resampler.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) | ||
#expect(resampler.outputFormat.sampleRate == 44100) | ||
resampler.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) | ||
#expect(resampler.outputFormat.sampleRate == 44100) | ||
resampler.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) | ||
#expect(resampler.outputFormat.sampleRate == 44100) | ||
resampler.append(CMAudioSampleBufferFactory.makeSinWave(16000, numSamples: 1024 * 20, channels: 1)!) | ||
#expect(resampler.outputFormat.sampleRate == 44100) | ||
} | ||
|
||
@Test func pKeep48000() { | ||
let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 48000, channels: 1, interleaved: true)! | ||
let track = AudioMixerTrack<AudioMixerTrackTests>(id: 0, outputFormat: format) | ||
track.delegate = self | ||
track.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) | ||
track.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024 * 2, channels: 1)!) | ||
} | ||
@Test func pKeep48000() { | ||
let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 48000, channels: 1, interleaved: true)! | ||
let track = AudioMixerTrack<AudioMixerTrackTests>(id: 0, outputFormat: format) | ||
track.delegate = self | ||
track.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) | ||
track.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024 * 2, channels: 1)!) | ||
} | ||
|
||
@Test func pPassthrough48000_44100() { | ||
let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 44000, channels: 1, interleaved: true)! | ||
let resampler = AudioMixerTrack<AudioMixerTrackTests>(id: 0, outputFormat: format) | ||
resampler.delegate = self | ||
resampler.append(CMAudioSampleBufferFactory.makeSinWave(44000, numSamples: 1024, channels: 1)!) | ||
resampler.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) | ||
} | ||
@Test func pPassthrough48000_44100() { | ||
let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 44000, channels: 1, interleaved: true)! | ||
let resampler = AudioMixerTrack<AudioMixerTrackTests>(id: 0, outputFormat: format) | ||
resampler.delegate = self | ||
resampler.append(CMAudioSampleBufferFactory.makeSinWave(44000, numSamples: 1024, channels: 1)!) | ||
resampler.append(CMAudioSampleBufferFactory.makeSinWave(48000, numSamples: 1024, channels: 1)!) | ||
} | ||
|
||
@Test func pPassthrough16000_48000() { | ||
let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 48000, channels: 1, interleaved: true)! | ||
let track = AudioMixerTrack<AudioMixerTrackTests>(id: 0, outputFormat: format) | ||
track.delegate = self | ||
track.append(CMAudioSampleBufferFactory.makeSinWave(16000, numSamples: 1024, channels: 1)!) | ||
#expect(track.outputFormat.sampleRate == 48000) | ||
track.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) | ||
} | ||
@Test func pPassthrough16000_48000() { | ||
let format = AVAudioFormat(commonFormat: .pcmFormatInt16, sampleRate: 48000, channels: 1, interleaved: true)! | ||
let track = AudioMixerTrack<AudioMixerTrackTests>(id: 0, outputFormat: format) | ||
track.delegate = self | ||
track.append(CMAudioSampleBufferFactory.makeSinWave(16000, numSamples: 1024, channels: 1)!) | ||
#expect(track.outputFormat.sampleRate == 48000) | ||
track.append(CMAudioSampleBufferFactory.makeSinWave(44100, numSamples: 1024, channels: 1)!) | ||
} | ||
*/ | ||
} | ||
|
Oops, something went wrong.