Skip to content

Commit

Permalink
Merge pull request #11 from noppefoxwolf/hotfix/FatalWhenPlaybackFailure
Browse files Browse the repository at this point in the history
assetのreset失敗時にpauseなどを呼ぶとfatalErrorになる問題
  • Loading branch information
noppefoxwolf authored Nov 13, 2020
2 parents 78f5e1c + 487d06d commit 00b4810
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 43 deletions.
191 changes: 190 additions & 1 deletion Example/Kitsunebi.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "Kitsunebi_Example.app"
BlueprintName = "Kitsunebi_Example"
ReferencedContainer = "container:Kitsunebi.xcodeproj">
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -52,18 +61,17 @@
ReferencedContainer = "container:Kitsunebi.xcodeproj">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "D74145BC255E72CD00B2AECA"
BuildableName = "Tests.xctest"
BlueprintName = "Tests"
ReferencedContainer = "container:Kitsunebi.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "607FACCF1AFB9204008FA782"
BuildableName = "Kitsunebi_Example.app"
BlueprintName = "Kitsunebi_Example"
ReferencedContainer = "container:Kitsunebi.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
Expand All @@ -85,8 +93,6 @@
ReferencedContainer = "container:Kitsunebi.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
Expand Down
4 changes: 4 additions & 0 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ platform :ios, '12.0'
target 'Kitsunebi_Example' do
pod 'Kitsunebi', :path => '../'
end

target 'Tests' do
pod 'Kitsunebi', :path => '../'
end
5 changes: 3 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Kitsunebi: 728531ae3060c166376b1a118c9a22b0f01e9d90

PODFILE CHECKSUM: fd524ebd71fba6c1aaaa283f1d3b32f80fd19cda
PODFILE CHECKSUM: 76ed2f2b7a60b498883386901c667ffa48dbcb69

COCOAPODS: 1.10.0

COCOAPODS: 1.9.3
19 changes: 19 additions & 0 deletions Example/Tests/AssetTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// AssetTests.swift
// Kitsunebi
//
// Created by Tomoya Hirano on 2020/11/13.
// Copyright © 2020 CocoaPods. All rights reserved.
//

@testable import Kitsunebi
import XCTest

class AssetTests: XCTestCase {
func testNotFatalBeforeReset() {
let asset = Asset(url: URL(fileURLWithPath: ""))
_ = asset.status
XCTAssert(true, "Pass")
}
}

6 changes: 2 additions & 4 deletions Example/Tests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand All @@ -13,11 +13,9 @@
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
Expand Down
33 changes: 19 additions & 14 deletions Example/Tests/Tests.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
//
// Tests.swift
// Tests
//
// Created by Tomoya Hirano on 2020/11/13.
// Copyright © 2020 CocoaPods. All rights reserved.
//

import XCTest
import Kitsunebi

class Tests: XCTestCase {

override func setUp() {
super.setUp()

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {

func testExample() throws {
// This is an example of a functional test case.
XCTAssert(true, "Pass")
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testPerformanceExample() {

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure() {
measure {
// Put the code you want to measure the time of here.
}
}

}
20 changes: 11 additions & 9 deletions Kitsunebi/Classes/Asset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,41 @@ final class Asset {
kCVPixelBufferMetalCompatibilityKey as String : true,
]
let asset: AVURLAsset
lazy var reader: AVAssetReader = { preconditionFailure() }()
lazy var output: AVAssetReaderTrackOutput = { preconditionFailure() }()
var status: AVAssetReader.Status { return reader.status }
var isRunning: Bool { return reader.status != .completed && reader.status != .cancelled }
private var reader: AVAssetReader? = nil
private var output: AVAssetReaderTrackOutput? = nil
var status: AVAssetReader.Status? { reader?.status }

init(url: URL) {
asset = AVURLAsset(url: url)
}

func reset() throws {
reader = try AVAssetReader(asset: asset)
output = AVAssetReaderTrackOutput(track: asset.tracks(withMediaType: AVMediaType.video)[0], outputSettings: outputSettings)
let reader = try AVAssetReader(asset: asset)
let output = AVAssetReaderTrackOutput(track: asset.tracks(withMediaType: AVMediaType.video)[0], outputSettings: outputSettings)
if reader.canAdd(output) {
reader.add(output)
} else {
throw Error.cannotAddOutput
}
output.alwaysCopiesSampleData = false
reader.startReading()

self.reader = reader
self.output = output
}

func cancelReading() {
reader.cancelReading()
reader?.cancelReading()
}

func copyNextImageBuffer() throws -> CVImageBuffer {
if let error = reader.error {
if let error = reader?.error {
throw error
}
if status != .reading {
throw AssetError.readerWasStopped
}
if let sampleBuffer = output.copyNextSampleBuffer(), let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) {
if let sampleBuffer = output?.copyNextSampleBuffer(), let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) {
return imageBuffer
} else {
throw AssetError.readerNotReturnedImage
Expand Down

0 comments on commit 00b4810

Please sign in to comment.