Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More tests #37

Merged
merged 3 commits into from
Mar 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Example/DownloadToGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
CA0AA135222D198700FFF90F /* DownloadTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA0AA134222D198700FFF90F /* DownloadTest.swift */; };
CA0AA138223021D900FFF90F /* items.json in Resources */ = {isa = PBXBuildFile; fileRef = CA0AA137223021BE00FFF90F /* items.json */; };
CAB012E1206CCBC400EB3F69 /* Samples.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAB012E0206CCBC400EB3F69 /* Samples.swift */; };
CAD71F59223E99CC0074CBA4 /* TestTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAD71F58223E99CC0074CBA4 /* TestTools.swift */; };
CAD71F5A223E99CC0074CBA4 /* TestTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAD71F58223E99CC0074CBA4 /* TestTools.swift */; };
CAD71F5C223EDAA40074CBA4 /* XCTestTools.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAD71F5B223EDAA40074CBA4 /* XCTestTools.swift */; };
CAE8915B222BC015004ACD30 /* HLSLocalizerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = CAE8915A222BC015004ACD30 /* HLSLocalizerTest.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -55,6 +58,8 @@
CA0AA134222D198700FFF90F /* DownloadTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadTest.swift; sourceTree = "<group>"; };
CA0AA137223021BE00FFF90F /* items.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = items.json; sourceTree = "<group>"; };
CAB012E0206CCBC400EB3F69 /* Samples.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Samples.swift; sourceTree = "<group>"; };
CAD71F58223E99CC0074CBA4 /* TestTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestTools.swift; sourceTree = "<group>"; };
CAD71F5B223EDAA40074CBA4 /* XCTestTools.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = XCTestTools.swift; path = Tests/XCTestTools.swift; sourceTree = SOURCE_ROOT; };
CAE8915A222BC015004ACD30 /* HLSLocalizerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HLSLocalizerTest.swift; sourceTree = "<group>"; };
DC9E0E3C7F4B72EB61E261A5 /* Pods-DownloadToGo_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DownloadToGo_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-DownloadToGo_Example/Pods-DownloadToGo_Example.debug.xcconfig"; sourceTree = "<group>"; };
EBD962729B0E7C93B9B967A2 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -124,6 +129,7 @@
607FACDE1AFB9204008FA782 /* LaunchScreen.xib */,
607FACD31AFB9204008FA782 /* Supporting Files */,
CAB012E0206CCBC400EB3F69 /* Samples.swift */,
CAD71F58223E99CC0074CBA4 /* TestTools.swift */,
);
name = "Example for DownloadToGo";
path = DownloadToGo;
Expand All @@ -144,6 +150,7 @@
607FACE91AFB9204008FA782 /* Supporting Files */,
CAE8915A222BC015004ACD30 /* HLSLocalizerTest.swift */,
CA0AA134222D198700FFF90F /* DownloadTest.swift */,
CAD71F5B223EDAA40074CBA4 /* XCTestTools.swift */,
);
path = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -379,15 +386,18 @@
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
CAB012E1206CCBC400EB3F69 /* Samples.swift in Sources */,
20AD661C1F174B0900E8E6D7 /* VideoViewController.swift in Sources */,
CAD71F59223E99CC0074CBA4 /* TestTools.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
607FACE11AFB9204008FA782 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CAD71F5C223EDAA40074CBA4 /* XCTestTools.swift in Sources */,
CAE8915B222BC015004ACD30 /* HLSLocalizerTest.swift in Sources */,
CA0AA135222D198700FFF90F /* DownloadTest.swift in Sources */,
CAD71F5A223E99CC0074CBA4 /* TestTools.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AACDC3C8D5E284825E230D6F4339852F"
BlueprintIdentifier = "12239D17D4E719512B5D5E8C0390B6FC"
BuildableName = "DownloadToGo.framework"
BlueprintName = "DownloadToGo"
ReferencedContainer = "container:Pods/Pods.xcodeproj">
Expand All @@ -54,6 +54,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildSystemType</key>
<string>Original</string>
</dict>
<dict/>
</plist>
103 changes: 103 additions & 0 deletions Example/DownloadToGo/TestTools.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//
// TestTools.swift
// DownloadToGo
//
// Created by Noam Tamim on 17/03/2019.
// Copyright © 2019 CocoaPods. All rights reserved.
//

import PlayKit
import PlayKitProviders
import DownloadToGo

let setSmallerOfflineDRMExpirationMinutes: Int? = 5
//let setSmallerOfflineDRMExpirationMinutes: Int? = nil


let defaultEnv = "http://cdnapi.kaltura.com"

struct ItemJSON: Codable {
let id: String
let title: String?
let partnerId: Int?
let ks: String?
let env: String = defaultEnv

let url: String?

let options: OptionsJSON?

let expected: ExpectedValues?
}

struct ExpectedValues: Codable {
let estimatedSize: Int64?
let downloadedSize: Int64?
let audioLangs: [String]?
let textLangs: [String]?
}

struct OptionsJSON: Codable {
let audioLangs: [String]?
let allAudioLangs: Bool?
let textLangs: [String]?
let allTextLangs: Bool?
let videoCodecs: [String]?
let audioCodecs: [String]?
let videoWidth: Int?
let videoHeight: Int?
let videoBitrates: [String:Int]?
let allowInefficientCodecs: Bool?

func toOptions() -> DTGSelectionOptions {
let opts = DTGSelectionOptions()

opts.allAudioLanguages = allAudioLangs ?? false
opts.audioLanguages = audioLangs

opts.allTextLanguages = allTextLangs ?? false
opts.textLanguages = textLangs

opts.allowInefficientCodecs = allowInefficientCodecs ?? false

if let codecs = audioCodecs {
opts.audioCodecs = codecs.compactMap({ (tag) -> DTGSelectionOptions.AudioCodec? in
switch tag {
case "mp4a": return .mp4a
case "ac3": return .ac3
case "eac3", "ec3": return .eac3
default: return nil
}
})
}

if let codecs = videoCodecs {
opts.videoCodecs = codecs.compactMap({ (tag) -> DTGSelectionOptions.VideoCodec? in
switch tag {
case "avc1": return .avc1
case "hevc", "hvc1": return .hevc
default: return nil
}
})
}

opts.videoWidth = videoWidth
opts.videoHeight = videoHeight

if let bitrates = videoBitrates {
for (codecId, bitrate) in bitrates {
let codec: DTGSelectionOptions.VideoCodec
switch codecId {
case "avc1": codec = .avc1
case "hevc", "hvc1": codec = .hevc
default: continue
}

opts.setMinVideoBitrate(codec, bitrate)
}
}

return opts
}
}

114 changes: 17 additions & 97 deletions Example/DownloadToGo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,103 +12,8 @@ import Toast
import PlayKit
import PlayKitProviders

let setSmallerOfflineDRMExpirationMinutes: Int? = 5
//let setSmallerOfflineDRMExpirationMinutes: Int? = nil

let defaultAudioBitrateEstimation: Int = 64000


struct ItemJSON: Codable {
let id: String
let title: String?
let partnerId: Int?
let ks: String?
let env: String?

let url: String?

let options: OptionsJSON?

func toItem() -> Item {
let item: Item
let title = self.title ?? self.id
if let partnerId = self.partnerId {
item = Item(title, id: self.id, partnerId: partnerId, ks: self.ks, env: self.env)
} else if let url = self.url {
item = Item(title, id: self.id, url: url)
} else {
fatalError("Invalid item, missing `partnerId` and `url`")
}
item.options = options?.toOptions()

return item
}
}

struct OptionsJSON: Codable {
let audioLangs: [String]?
let allAudioLangs: Bool?
let textLangs: [String]?
let allTextLangs: Bool?
let videoCodecs: [String]?
let audioCodecs: [String]?
let videoWidth: Int?
let videoHeight: Int?
let videoBitrates: [String:Int]?
let allowInefficientCodecs: Bool?

func toOptions() -> DTGSelectionOptions {
let opts = DTGSelectionOptions()

opts.allAudioLanguages = allAudioLangs ?? false
opts.audioLanguages = audioLangs

opts.allTextLanguages = allTextLangs ?? false
opts.textLanguages = textLangs

opts.allowInefficientCodecs = allowInefficientCodecs ?? false

if let codecs = audioCodecs {
opts.audioCodecs = codecs.compactMap({ (tag) -> DTGSelectionOptions.AudioCodec? in
switch tag {
case "mp4a": return .mp4a
case "ac3": return .ac3
case "eac3", "ec3": return .eac3
default: return nil
}
})
}

if let codecs = videoCodecs {
opts.videoCodecs = codecs.compactMap({ (tag) -> DTGSelectionOptions.VideoCodec? in
switch tag {
case "avc1": return .avc1
case "hevc", "hvc1": return .hevc
default: return nil
}
})
}

opts.videoWidth = videoWidth
opts.videoHeight = videoHeight

if let bitrates = videoBitrates {
for (codecId, bitrate) in bitrates {
let codec: DTGSelectionOptions.VideoCodec
switch codecId {
case "avc1": codec = .avc1
case "hevc", "hvc1": codec = .hevc
default: continue
}

opts.setMinVideoBitrate(codec, bitrate)
}
}

return opts
}
}

class Item {
static let defaultEnv = "http://cdnapi.kaltura.com"
let id: String
Expand All @@ -119,7 +24,21 @@ class Item {
var entry: PKMediaEntry?

var options: DTGSelectionOptions?

var expected: ExpectedValues?

convenience init(json: ItemJSON) {
let title = json.title ?? json.id

if let partnerId = json.partnerId {
self.init(title, id: json.id, partnerId: partnerId, ks: json.ks, env: json.env)
} else if let url = json.url {
self.init(title, id: json.id, url: url)
} else {
fatalError("Invalid item, missing `partnerId` and `url`")
}
self.options = json.options?.toOptions()
}

init(_ title: String, id: String, url: String) {
self.id = id
self.title = title
Expand Down Expand Up @@ -157,6 +76,7 @@ class Item {
}
}


class ViewController: UIViewController {
let dummyFileName = "dummyfile"
let videoViewControllerSegueIdentifier = "videoViewController"
Expand Down Expand Up @@ -214,7 +134,7 @@ class ViewController: UIViewController {
let json = try! Data(contentsOf: jsonURL)
let loadedItems = try! JSONDecoder().decode([ItemJSON].self, from: json)

items = loadedItems.map{$0.toItem()}
items = loadedItems.map{Item(json: $0)}

let completedItems = try! self.cm.itemsByState(.completed)
for (index, item) in completedItems.enumerated() {
Expand Down
8 changes: 7 additions & 1 deletion Example/DownloadToGo/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
"options": {
"allAudioLangs": true,
"allTextLangs": true,
}
},
"expected": {
"estimatedSize": 0,
"downloadedSize": 0,
"audioLangs": ["en"],
"textLangs": [],
}
},
{
"title": "AES-128 multi-key",
Expand Down
Loading