Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit 00b4810

Browse files
authored
Merge pull request #11 from noppefoxwolf/hotfix/FatalWhenPlaybackFailure
assetのreset失敗時にpauseなどを呼ぶとfatalErrorになる問題
2 parents 78f5e1c + 487d06d commit 00b4810

File tree

8 files changed

+267
-43
lines changed

8 files changed

+267
-43
lines changed

Example/Kitsunebi.xcodeproj/project.pbxproj

Lines changed: 190 additions & 1 deletion
Large diffs are not rendered by default.

Example/Kitsunebi.xcodeproj/xcshareddata/xcschemes/Kitsunebi-Example.xcscheme

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@
4141
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4242
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
4343
shouldUseLaunchSchemeArgsEnv = "YES">
44+
<MacroExpansion>
45+
<BuildableReference
46+
BuildableIdentifier = "primary"
47+
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
48+
BuildableName = "Kitsunebi_Example.app"
49+
BlueprintName = "Kitsunebi_Example"
50+
ReferencedContainer = "container:Kitsunebi.xcodeproj">
51+
</BuildableReference>
52+
</MacroExpansion>
4453
<Testables>
4554
<TestableReference
4655
skipped = "NO">
@@ -52,18 +61,17 @@
5261
ReferencedContainer = "container:Kitsunebi.xcodeproj">
5362
</BuildableReference>
5463
</TestableReference>
64+
<TestableReference
65+
skipped = "NO">
66+
<BuildableReference
67+
BuildableIdentifier = "primary"
68+
BlueprintIdentifier = "D74145BC255E72CD00B2AECA"
69+
BuildableName = "Tests.xctest"
70+
BlueprintName = "Tests"
71+
ReferencedContainer = "container:Kitsunebi.xcodeproj">
72+
</BuildableReference>
73+
</TestableReference>
5574
</Testables>
56-
<MacroExpansion>
57-
<BuildableReference
58-
BuildableIdentifier = "primary"
59-
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
60-
BuildableName = "Kitsunebi_Example.app"
61-
BlueprintName = "Kitsunebi_Example"
62-
ReferencedContainer = "container:Kitsunebi.xcodeproj">
63-
</BuildableReference>
64-
</MacroExpansion>
65-
<AdditionalOptions>
66-
</AdditionalOptions>
6775
</TestAction>
6876
<LaunchAction
6977
buildConfiguration = "Debug"
@@ -85,8 +93,6 @@
8593
ReferencedContainer = "container:Kitsunebi.xcodeproj">
8694
</BuildableReference>
8795
</BuildableProductRunnable>
88-
<AdditionalOptions>
89-
</AdditionalOptions>
9096
</LaunchAction>
9197
<ProfileAction
9298
buildConfiguration = "Release"

Example/Podfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ platform :ios, '12.0'
55
target 'Kitsunebi_Example' do
66
pod 'Kitsunebi', :path => '../'
77
end
8+
9+
target 'Tests' do
10+
pod 'Kitsunebi', :path => '../'
11+
end

Example/Podfile.lock

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ EXTERNAL SOURCES:
1111
SPEC CHECKSUMS:
1212
Kitsunebi: 728531ae3060c166376b1a118c9a22b0f01e9d90
1313

14-
PODFILE CHECKSUM: fd524ebd71fba6c1aaaa283f1d3b32f80fd19cda
14+
PODFILE CHECKSUM: 76ed2f2b7a60b498883386901c667ffa48dbcb69
15+
16+
COCOAPODS: 1.10.0
1517

16-
COCOAPODS: 1.9.3

Example/Tests/AssetTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// AssetTests.swift
3+
// Kitsunebi
4+
//
5+
// Created by Tomoya Hirano on 2020/11/13.
6+
// Copyright © 2020 CocoaPods. All rights reserved.
7+
//
8+
9+
@testable import Kitsunebi
10+
import XCTest
11+
12+
class AssetTests: XCTestCase {
13+
func testNotFatalBeforeReset() {
14+
let asset = Asset(url: URL(fileURLWithPath: ""))
15+
_ = asset.status
16+
XCTAssert(true, "Pass")
17+
}
18+
}
19+

Example/Tests/Info.plist

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<plist version="1.0">
44
<dict>
55
<key>CFBundleDevelopmentRegion</key>
6-
<string>en</string>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
77
<key>CFBundleExecutable</key>
88
<string>$(EXECUTABLE_NAME)</string>
99
<key>CFBundleIdentifier</key>
@@ -13,11 +13,9 @@
1313
<key>CFBundleName</key>
1414
<string>$(PRODUCT_NAME)</string>
1515
<key>CFBundlePackageType</key>
16-
<string>BNDL</string>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
1717
<key>CFBundleShortVersionString</key>
1818
<string>1.0</string>
19-
<key>CFBundleSignature</key>
20-
<string>????</string>
2119
<key>CFBundleVersion</key>
2220
<string>1</string>
2321
</dict>

Example/Tests/Tests.swift

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1+
//
2+
// Tests.swift
3+
// Tests
4+
//
5+
// Created by Tomoya Hirano on 2020/11/13.
6+
// Copyright © 2020 CocoaPods. All rights reserved.
7+
//
8+
19
import XCTest
2-
import Kitsunebi
310

411
class Tests: XCTestCase {
5-
6-
override func setUp() {
7-
super.setUp()
12+
13+
override func setUpWithError() throws {
814
// Put setup code here. This method is called before the invocation of each test method in the class.
915
}
10-
11-
override func tearDown() {
16+
17+
override func tearDownWithError() throws {
1218
// Put teardown code here. This method is called after the invocation of each test method in the class.
13-
super.tearDown()
1419
}
15-
16-
func testExample() {
20+
21+
func testExample() throws {
1722
// This is an example of a functional test case.
18-
XCTAssert(true, "Pass")
23+
// Use XCTAssert and related functions to verify your tests produce the correct results.
1924
}
20-
21-
func testPerformanceExample() {
25+
26+
func testPerformanceExample() throws {
2227
// This is an example of a performance test case.
23-
self.measure() {
28+
measure {
2429
// Put the code you want to measure the time of here.
2530
}
2631
}
27-
32+
2833
}

Kitsunebi/Classes/Asset.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,41 @@ final class Asset {
1212
kCVPixelBufferMetalCompatibilityKey as String : true,
1313
]
1414
let asset: AVURLAsset
15-
lazy var reader: AVAssetReader = { preconditionFailure() }()
16-
lazy var output: AVAssetReaderTrackOutput = { preconditionFailure() }()
17-
var status: AVAssetReader.Status { return reader.status }
18-
var isRunning: Bool { return reader.status != .completed && reader.status != .cancelled }
15+
private var reader: AVAssetReader? = nil
16+
private var output: AVAssetReaderTrackOutput? = nil
17+
var status: AVAssetReader.Status? { reader?.status }
1918

2019
init(url: URL) {
2120
asset = AVURLAsset(url: url)
2221
}
2322

2423
func reset() throws {
25-
reader = try AVAssetReader(asset: asset)
26-
output = AVAssetReaderTrackOutput(track: asset.tracks(withMediaType: AVMediaType.video)[0], outputSettings: outputSettings)
24+
let reader = try AVAssetReader(asset: asset)
25+
let output = AVAssetReaderTrackOutput(track: asset.tracks(withMediaType: AVMediaType.video)[0], outputSettings: outputSettings)
2726
if reader.canAdd(output) {
2827
reader.add(output)
2928
} else {
3029
throw Error.cannotAddOutput
3130
}
3231
output.alwaysCopiesSampleData = false
3332
reader.startReading()
33+
34+
self.reader = reader
35+
self.output = output
3436
}
3537

3638
func cancelReading() {
37-
reader.cancelReading()
39+
reader?.cancelReading()
3840
}
3941

4042
func copyNextImageBuffer() throws -> CVImageBuffer {
41-
if let error = reader.error {
43+
if let error = reader?.error {
4244
throw error
4345
}
4446
if status != .reading {
4547
throw AssetError.readerWasStopped
4648
}
47-
if let sampleBuffer = output.copyNextSampleBuffer(), let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) {
49+
if let sampleBuffer = output?.copyNextSampleBuffer(), let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) {
4850
return imageBuffer
4951
} else {
5052
throw AssetError.readerNotReturnedImage

0 commit comments

Comments
 (0)