Skip to content

Commit e213551

Browse files
committed
v2.0.2(118)
fix memory eating issue
1 parent bcccaae commit e213551

File tree

5 files changed

+98
-67
lines changed

5 files changed

+98
-67
lines changed

CryptCloudViewer/CryptCloudViewer.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@
325325
CLANG_ENABLE_MODULES = YES;
326326
CODE_SIGN_ENTITLEMENTS = CryptCloudViewer/CryptCloudViewer.entitlements;
327327
CODE_SIGN_STYLE = Automatic;
328-
CURRENT_PROJECT_VERSION = 117;
328+
CURRENT_PROJECT_VERSION = 118;
329329
DEAD_CODE_STRIPPING = YES;
330330
DEVELOPMENT_TEAM = 7A9X38B4YU;
331331
ENABLE_APP_SANDBOX = YES;
@@ -354,7 +354,7 @@
354354
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
355355
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
356356
MACOSX_DEPLOYMENT_TARGET = 26.0;
357-
MARKETING_VERSION = 2.0.1;
357+
MARKETING_VERSION = 2.0.2;
358358
PRODUCT_BUNDLE_IDENTIFIER = info.lithium03.ccViewer;
359359
PRODUCT_NAME = "$(TARGET_NAME)";
360360
REGISTER_APP_GROUPS = YES;
@@ -384,7 +384,7 @@
384384
CLANG_ENABLE_MODULES = YES;
385385
CODE_SIGN_ENTITLEMENTS = CryptCloudViewer/CryptCloudViewer.entitlements;
386386
CODE_SIGN_STYLE = Automatic;
387-
CURRENT_PROJECT_VERSION = 117;
387+
CURRENT_PROJECT_VERSION = 118;
388388
DEAD_CODE_STRIPPING = YES;
389389
DEVELOPMENT_TEAM = 7A9X38B4YU;
390390
ENABLE_APP_SANDBOX = YES;
@@ -413,7 +413,7 @@
413413
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
414414
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
415415
MACOSX_DEPLOYMENT_TARGET = 26.0;
416-
MARKETING_VERSION = 2.0.1;
416+
MARKETING_VERSION = 2.0.2;
417417
PRODUCT_BUNDLE_IDENTIFIER = info.lithium03.ccViewer;
418418
PRODUCT_NAME = "$(TARGET_NAME)";
419419
REGISTER_APP_GROUPS = YES;

CryptCloudViewer/CryptCloudViewer/CastPlay.swift

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ class CastConverter: NSObject, GCKRemoteMediaClientListener {
2525
UserDefaults.standard.bool(forKey: "shuffle")
2626
}
2727

28-
var items: [RemoteItem] = []
29-
var itemIDMap: [Int: String] = [:]
28+
var orgItems: [(String, String)] = []
29+
var itemMap: [Int: RemoteItem] = [:]
3030
var durations: [String: (Double, String, String, String)] = [:]
3131
var currentIdx = -1
3232
var currentItemID: Int = -1 {
@@ -37,20 +37,17 @@ class CastConverter: NSObject, GCKRemoteMediaClientListener {
3737
}
3838
if oldValue < 0 { return }
3939
for i in 0...oldValue {
40-
if let path = itemIDMap[i] {
40+
if let item = itemMap[i] {
4141
Task {
42-
print("Convert done", i, path)
43-
await Converter.Done(targetPath: path)
42+
print("Convert done", i, item.path)
43+
await Converter.Done(targetPath: item.path)
44+
await item.cancel()
45+
itemMap[i] = nil
4446
}
4547
}
4648
}
4749
}
4850
}
49-
50-
func setItemID(_ id: Int, path: String) {
51-
print("setItemID", id, path)
52-
itemIDMap[id] = path
53-
}
5451

5552
func setCurrentItemID(_ id: Int) {
5653
print("setCurrentItemID", id)
@@ -89,33 +86,44 @@ class CastConverter: NSObject, GCKRemoteMediaClientListener {
8986
}
9087

9188
func finish() async {
92-
for item in items {
89+
for item in itemMap.values {
9390
await Converter.Done(targetPath: item.path)
9491
}
95-
items.removeAll()
96-
itemIDMap.removeAll()
92+
itemMap.removeAll()
9793
}
9894

99-
func nextItem() -> (Int, RemoteItem)? {
100-
if currentIdx + 1 < items.count {
95+
func nextItem() async -> (Int, RemoteItem)? {
96+
if currentIdx + 1 < orgItems.count {
10197
currentIdx += 1
10298
}
10399
else {
104100
if loop {
105101
if shuffle {
106-
items.shuffle()
102+
orgItems.shuffle()
107103
}
108104
currentIdx = 0
109105
}
110106
else {
111107
return nil
112108
}
113109
}
114-
return (currentIdx, items[currentIdx])
110+
let (storage, fileid) = orgItems[currentIdx]
111+
if let remoteItem = await CloudFactory.shared.storageList.get(storage)?.get(fileId: fileid) {
112+
itemMap[currentIdx] = remoteItem
113+
return (currentIdx, remoteItem)
114+
}
115+
if currentIdx > 0 {
116+
return await nextItem()
117+
}
118+
return nil
115119
}
116120

117-
func setItems(_ items: [RemoteItem]) {
118-
self.items = items
121+
func setItems(_ items: [(String, String)]) async {
122+
await finish()
123+
orgItems = items
124+
if shuffle {
125+
orgItems.shuffle()
126+
}
119127
currentIdx = -1
120128
}
121129
}
@@ -246,7 +254,6 @@ class CastConverter: NSObject, GCKRemoteMediaClientListener {
246254
print(item.path)
247255
if let url = await Converter.Play(item: info) {
248256
let randID = url.deletingLastPathComponent().lastPathComponent
249-
await prop.setItemID(index, path: item.path)
250257
if await Converter.start_encode(randID: randID) {
251258
var sleepCount = 0
252259
while Converter.IsCasting(), await !Converter.fileReady(randID: randID), await Converter.runState(randID: randID) {
@@ -319,29 +326,32 @@ class CastConverter: NSObject, GCKRemoteMediaClientListener {
319326
}
320327

321328
func playConverter(storages: [String], fileids: [String], playlist: Bool = false) async {
322-
var shuffle: Bool {
323-
UserDefaults.standard.bool(forKey: "shuffle")
324-
}
325-
var items: [RemoteItem] = []
326-
for (storage, fileid) in zip(storages, fileids) {
327-
if let remoteItem = await CloudFactory.shared.storageList.get(storage)?.get(fileId: fileid) {
328-
if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .text) {
329-
}
330-
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .image) {
331-
}
332-
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .pdf) {
333-
}
334-
else if remoteItem.ext == "cue" {
329+
var items: [(String, String)] = []
330+
await withTaskGroup { group in
331+
for (storage, fileid) in zip(storages, fileids) {
332+
group.addTask { () -> (String, String)? in
333+
if let remoteItem = await CloudFactory.shared.storageList.get(storage)?.get(fileId: fileid) {
334+
if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .text) {
335+
}
336+
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .image) {
337+
}
338+
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .pdf) {
339+
}
340+
else if remoteItem.ext == "cue" {
341+
}
342+
else {
343+
return (storage, fileid)
344+
}
345+
}
346+
return nil
335347
}
336-
else {
337-
items.append(remoteItem)
348+
}
349+
for await item in group {
350+
if let item {
351+
items.append(item)
338352
}
339353
}
340354
}
341-
if items.isEmpty { return }
342-
if shuffle {
343-
items.shuffle()
344-
}
345355
CastConverter.shared.playlist = playlist
346356
let castContext = GCKCastContext.sharedInstance()
347357
if castContext.castState == .connected || castContext.castState == .connecting {

CryptCloudViewer/CryptCloudViewer/CryptCloudViewer.entitlements

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<string>CloudKit</string>
1818
<string>CloudDocuments</string>
1919
</array>
20+
<key>com.apple.developer.kernel.increased-memory-limit</key>
21+
<true/>
2022
<key>com.apple.developer.ubiquity-container-identifiers</key>
2123
<array>
2224
<string>iCloud.info.lithium03.ccViewer</string>

CryptCloudViewer/CryptCloudViewer/OpenfileUIView.swift

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,37 +62,56 @@ struct OpenfileUIView: View {
6262
if storages.count > 1 {
6363
var ffplay = false
6464
if UserDefaults.standard.bool(forKey: "FFplayer"), UserDefaults.standard.bool(forKey: "firstFFplayer") {
65-
for (storage, fileid) in zip(storages, fileids) {
66-
if let remoteItem = await CloudFactory.shared.storageList.get(storage)?.get(fileId: fileid) {
67-
if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .text) {
68-
}
69-
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .image) {
70-
}
71-
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .pdf) {
65+
await withTaskGroup { group in
66+
for (storage, fileid) in zip(storages, fileids) {
67+
group.addTask { ()->(String, String)? in
68+
if let remoteItem = await CloudFactory.shared.storageList.get(storage)?.get(fileId: fileid) {
69+
if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .text) {
70+
}
71+
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .image) {
72+
}
73+
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .pdf) {
74+
}
75+
else {
76+
ffplay = true
77+
return (storage, fileid)
78+
}
79+
}
80+
return nil
7281
}
73-
else {
74-
ffplay = true
82+
}
83+
for await item in group {
84+
if let (storage, fileid) = item {
7585
passStorages.append(storage)
7686
passFileids.append(fileid)
7787
}
7888
}
7989
}
8090
}
8191
else {
82-
for (storage, fileid) in zip(storages, fileids) {
83-
if let remoteItem = await CloudFactory.shared.storageList.get(storage)?.get(fileId: fileid) {
84-
if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .text) {
85-
}
86-
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .image) {
87-
}
88-
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .pdf) {
89-
}
90-
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .movie), UserDefaults.standard.bool(forKey: "MediaViewer") {
91-
passStorages.append(storage)
92-
passFileids.append(fileid)
92+
await withTaskGroup { group in
93+
for (storage, fileid) in zip(storages, fileids) {
94+
group.addTask { ()->(String, String)? in
95+
if let remoteItem = await CloudFactory.shared.storageList.get(storage)?.get(fileId: fileid) {
96+
if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .text) {
97+
}
98+
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .image) {
99+
}
100+
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .pdf) {
101+
}
102+
else if let uti = UTType(filenameExtension: remoteItem.ext), uti.conforms(to: .movie), UserDefaults.standard.bool(forKey: "MediaViewer") {
103+
return (storage, fileid)
104+
}
105+
else {
106+
ffplay = true
107+
return (storage, fileid)
108+
}
109+
}
110+
return nil
93111
}
94-
else {
95-
ffplay = true
112+
}
113+
for await item in group {
114+
if let (storage, fileid) = item {
96115
passStorages.append(storage)
97116
passFileids.append(fileid)
98117
}

RemoteCloud/RemoteCloud/NetworkStorage.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ public class NetworkRemoteItem: RemoteItem {
261261
}
262262

263263
public class SlotStream: RemoteStream {
264-
static let slotcount = 50
264+
static let slotcount = 10
265265
static let slotadvance: Int64 = 2
266-
static let bufSize:Int64 = 2*1024*1024
266+
static let bufSize:Int64 = 1*1024*1024
267267
var error = false {
268268
didSet {
269269
print(error)

0 commit comments

Comments
 (0)