├── .gitignore ├── LICENSE ├── README.md ├── ScreenCasting.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist └── ScreenCasting ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── Base.lproj └── Main.storyboard ├── Info.plist ├── ScreenCasting.entitlements ├── ViewController.swift └── WindowController.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## User settings 6 | xcuserdata/ 7 | 8 | ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) 9 | *.xcscmblueprint 10 | *.xccheckout 11 | 12 | ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) 13 | build/ 14 | DerivedData/ 15 | *.moved-aside 16 | *.pbxuser 17 | !default.pbxuser 18 | *.mode1v3 19 | !default.mode1v3 20 | *.mode2v3 21 | !default.mode2v3 22 | *.perspectivev3 23 | !default.perspectivev3 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | 28 | ## App packaging 29 | *.ipa 30 | *.dSYM.zip 31 | *.dSYM 32 | 33 | ## Playgrounds 34 | timeline.xctimeline 35 | playground.xcworkspace 36 | 37 | # Swift Package Manager 38 | # 39 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 40 | # Packages/ 41 | # Package.pins 42 | # Package.resolved 43 | # *.xcodeproj 44 | # 45 | # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata 46 | # hence it is not needed unless you have added a package configuration file to your project 47 | # .swiftpm 48 | 49 | .build/ 50 | 51 | # CocoaPods 52 | # 53 | # We recommend against adding the Pods directory to your .gitignore. However 54 | # you should judge for yourself, the pros and cons are mentioned at: 55 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 56 | # 57 | # Pods/ 58 | # 59 | # Add this line if you want to avoid checking in source code from the Xcode workspace 60 | # *.xcworkspace 61 | 62 | # Carthage 63 | # 64 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 65 | # Carthage/Checkouts 66 | 67 | Carthage/Build/ 68 | 69 | # Accio dependency management 70 | Dependencies/ 71 | .accio/ 72 | 73 | # fastlane 74 | # 75 | # It is recommended to not store the screenshots in the git repo. 76 | # Instead, use fastlane to re-generate the screenshots whenever they are needed. 77 | # For more information about the recommended setup visit: 78 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 79 | 80 | fastlane/report.xml 81 | fastlane/Preview.html 82 | fastlane/screenshots/**/*.png 83 | fastlane/test_output 84 | 85 | # Code Injection 86 | # 87 | # After new code Injection tools there's a generated folder /iOSInjectionProject 88 | # https://github.com/johnno1962/injectionforxcode 89 | 90 | iOSInjectionProject/ 91 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ScreenCasting 2 | Minimal UI for Sharing iOS Device 3 | -------------------------------------------------------------------------------- /ScreenCasting.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | CC5AFDB022AA0AB1004E041A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC5AFDAF22AA0AB1004E041A /* AppDelegate.swift */; }; 11 | CC5AFDB222AA0AB2004E041A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CC5AFDB122AA0AB2004E041A /* Assets.xcassets */; }; 12 | CC5AFDB522AA0AB2004E041A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CC5AFDB322AA0AB2004E041A /* Main.storyboard */; }; 13 | CC9BDB7C22AA10C400C024E8 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC9BDB7B22AA10C400C024E8 /* ViewController.swift */; }; 14 | CC9BDB7E22AA189900C024E8 /* WindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC9BDB7D22AA189900C024E8 /* WindowController.swift */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXFileReference section */ 18 | CC5AFDAC22AA0AB1004E041A /* ScreenCasting.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ScreenCasting.app; sourceTree = BUILT_PRODUCTS_DIR; }; 19 | CC5AFDAF22AA0AB1004E041A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 20 | CC5AFDB122AA0AB2004E041A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 21 | CC5AFDB422AA0AB2004E041A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 22 | CC5AFDB622AA0AB2004E041A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 23 | CC5AFDB722AA0AB2004E041A /* ScreenCasting.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ScreenCasting.entitlements; sourceTree = ""; }; 24 | CC9BDB7B22AA10C400C024E8 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 25 | CC9BDB7D22AA189900C024E8 /* WindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowController.swift; sourceTree = ""; }; 26 | /* End PBXFileReference section */ 27 | 28 | /* Begin PBXFrameworksBuildPhase section */ 29 | CC5AFDA922AA0AB1004E041A /* Frameworks */ = { 30 | isa = PBXFrameworksBuildPhase; 31 | buildActionMask = 2147483647; 32 | files = ( 33 | ); 34 | runOnlyForDeploymentPostprocessing = 0; 35 | }; 36 | /* End PBXFrameworksBuildPhase section */ 37 | 38 | /* Begin PBXGroup section */ 39 | CC5AFDA322AA0AB1004E041A = { 40 | isa = PBXGroup; 41 | children = ( 42 | CC5AFDAE22AA0AB1004E041A /* ScreenCasting */, 43 | CC5AFDAD22AA0AB1004E041A /* Products */, 44 | ); 45 | sourceTree = ""; 46 | }; 47 | CC5AFDAD22AA0AB1004E041A /* Products */ = { 48 | isa = PBXGroup; 49 | children = ( 50 | CC5AFDAC22AA0AB1004E041A /* ScreenCasting.app */, 51 | ); 52 | name = Products; 53 | sourceTree = ""; 54 | }; 55 | CC5AFDAE22AA0AB1004E041A /* ScreenCasting */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | CC5AFDAF22AA0AB1004E041A /* AppDelegate.swift */, 59 | CC9BDB7D22AA189900C024E8 /* WindowController.swift */, 60 | CC9BDB7B22AA10C400C024E8 /* ViewController.swift */, 61 | CC5AFDB122AA0AB2004E041A /* Assets.xcassets */, 62 | CC5AFDB322AA0AB2004E041A /* Main.storyboard */, 63 | CC5AFDB622AA0AB2004E041A /* Info.plist */, 64 | CC5AFDB722AA0AB2004E041A /* ScreenCasting.entitlements */, 65 | ); 66 | path = ScreenCasting; 67 | sourceTree = ""; 68 | }; 69 | /* End PBXGroup section */ 70 | 71 | /* Begin PBXNativeTarget section */ 72 | CC5AFDAB22AA0AB1004E041A /* ScreenCasting */ = { 73 | isa = PBXNativeTarget; 74 | buildConfigurationList = CC5AFDBA22AA0AB2004E041A /* Build configuration list for PBXNativeTarget "ScreenCasting" */; 75 | buildPhases = ( 76 | CC5AFDA822AA0AB1004E041A /* Sources */, 77 | CC5AFDA922AA0AB1004E041A /* Frameworks */, 78 | CC5AFDAA22AA0AB1004E041A /* Resources */, 79 | ); 80 | buildRules = ( 81 | ); 82 | dependencies = ( 83 | ); 84 | name = ScreenCasting; 85 | productName = ScreenCasting; 86 | productReference = CC5AFDAC22AA0AB1004E041A /* ScreenCasting.app */; 87 | productType = "com.apple.product-type.application"; 88 | }; 89 | /* End PBXNativeTarget section */ 90 | 91 | /* Begin PBXProject section */ 92 | CC5AFDA422AA0AB1004E041A /* Project object */ = { 93 | isa = PBXProject; 94 | attributes = { 95 | LastSwiftUpdateCheck = 1100; 96 | LastUpgradeCheck = 1320; 97 | ORGANIZATIONNAME = Oltica; 98 | TargetAttributes = { 99 | CC5AFDAB22AA0AB1004E041A = { 100 | CreatedOnToolsVersion = 11.0; 101 | }; 102 | }; 103 | }; 104 | buildConfigurationList = CC5AFDA722AA0AB1004E041A /* Build configuration list for PBXProject "ScreenCasting" */; 105 | compatibilityVersion = "Xcode 9.3"; 106 | developmentRegion = en; 107 | hasScannedForEncodings = 0; 108 | knownRegions = ( 109 | en, 110 | Base, 111 | ); 112 | mainGroup = CC5AFDA322AA0AB1004E041A; 113 | productRefGroup = CC5AFDAD22AA0AB1004E041A /* Products */; 114 | projectDirPath = ""; 115 | projectRoot = ""; 116 | targets = ( 117 | CC5AFDAB22AA0AB1004E041A /* ScreenCasting */, 118 | ); 119 | }; 120 | /* End PBXProject section */ 121 | 122 | /* Begin PBXResourcesBuildPhase section */ 123 | CC5AFDAA22AA0AB1004E041A /* Resources */ = { 124 | isa = PBXResourcesBuildPhase; 125 | buildActionMask = 2147483647; 126 | files = ( 127 | CC5AFDB222AA0AB2004E041A /* Assets.xcassets in Resources */, 128 | CC5AFDB522AA0AB2004E041A /* Main.storyboard in Resources */, 129 | ); 130 | runOnlyForDeploymentPostprocessing = 0; 131 | }; 132 | /* End PBXResourcesBuildPhase section */ 133 | 134 | /* Begin PBXSourcesBuildPhase section */ 135 | CC5AFDA822AA0AB1004E041A /* Sources */ = { 136 | isa = PBXSourcesBuildPhase; 137 | buildActionMask = 2147483647; 138 | files = ( 139 | CC9BDB7C22AA10C400C024E8 /* ViewController.swift in Sources */, 140 | CC9BDB7E22AA189900C024E8 /* WindowController.swift in Sources */, 141 | CC5AFDB022AA0AB1004E041A /* AppDelegate.swift in Sources */, 142 | ); 143 | runOnlyForDeploymentPostprocessing = 0; 144 | }; 145 | /* End PBXSourcesBuildPhase section */ 146 | 147 | /* Begin PBXVariantGroup section */ 148 | CC5AFDB322AA0AB2004E041A /* Main.storyboard */ = { 149 | isa = PBXVariantGroup; 150 | children = ( 151 | CC5AFDB422AA0AB2004E041A /* Base */, 152 | ); 153 | name = Main.storyboard; 154 | sourceTree = ""; 155 | }; 156 | /* End PBXVariantGroup section */ 157 | 158 | /* Begin XCBuildConfiguration section */ 159 | CC5AFDB822AA0AB2004E041A /* Debug */ = { 160 | isa = XCBuildConfiguration; 161 | buildSettings = { 162 | ALWAYS_SEARCH_USER_PATHS = NO; 163 | CLANG_ANALYZER_NONNULL = YES; 164 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 165 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 166 | CLANG_CXX_LIBRARY = "libc++"; 167 | CLANG_ENABLE_MODULES = YES; 168 | CLANG_ENABLE_OBJC_ARC = YES; 169 | CLANG_ENABLE_OBJC_WEAK = YES; 170 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 171 | CLANG_WARN_BOOL_CONVERSION = YES; 172 | CLANG_WARN_COMMA = YES; 173 | CLANG_WARN_CONSTANT_CONVERSION = YES; 174 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 175 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 176 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 177 | CLANG_WARN_EMPTY_BODY = YES; 178 | CLANG_WARN_ENUM_CONVERSION = YES; 179 | CLANG_WARN_INFINITE_RECURSION = YES; 180 | CLANG_WARN_INT_CONVERSION = YES; 181 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 182 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 183 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 184 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 185 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 186 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 187 | CLANG_WARN_STRICT_PROTOTYPES = YES; 188 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 189 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 190 | CLANG_WARN_UNREACHABLE_CODE = YES; 191 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 192 | COPY_PHASE_STRIP = NO; 193 | DEBUG_INFORMATION_FORMAT = dwarf; 194 | ENABLE_STRICT_OBJC_MSGSEND = YES; 195 | ENABLE_TESTABILITY = YES; 196 | GCC_C_LANGUAGE_STANDARD = gnu11; 197 | GCC_DYNAMIC_NO_PIC = NO; 198 | GCC_NO_COMMON_BLOCKS = YES; 199 | GCC_OPTIMIZATION_LEVEL = 0; 200 | GCC_PREPROCESSOR_DEFINITIONS = ( 201 | "DEBUG=1", 202 | "$(inherited)", 203 | ); 204 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 205 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 206 | GCC_WARN_UNDECLARED_SELECTOR = YES; 207 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 208 | GCC_WARN_UNUSED_FUNCTION = YES; 209 | GCC_WARN_UNUSED_VARIABLE = YES; 210 | MACOSX_DEPLOYMENT_TARGET = 11.0; 211 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 212 | MTL_FAST_MATH = YES; 213 | ONLY_ACTIVE_ARCH = YES; 214 | SDKROOT = macosx; 215 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 216 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 217 | }; 218 | name = Debug; 219 | }; 220 | CC5AFDB922AA0AB2004E041A /* Release */ = { 221 | isa = XCBuildConfiguration; 222 | buildSettings = { 223 | ALWAYS_SEARCH_USER_PATHS = NO; 224 | CLANG_ANALYZER_NONNULL = YES; 225 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 226 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 227 | CLANG_CXX_LIBRARY = "libc++"; 228 | CLANG_ENABLE_MODULES = YES; 229 | CLANG_ENABLE_OBJC_ARC = YES; 230 | CLANG_ENABLE_OBJC_WEAK = YES; 231 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 232 | CLANG_WARN_BOOL_CONVERSION = YES; 233 | CLANG_WARN_COMMA = YES; 234 | CLANG_WARN_CONSTANT_CONVERSION = YES; 235 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 236 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 237 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 238 | CLANG_WARN_EMPTY_BODY = YES; 239 | CLANG_WARN_ENUM_CONVERSION = YES; 240 | CLANG_WARN_INFINITE_RECURSION = YES; 241 | CLANG_WARN_INT_CONVERSION = YES; 242 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 243 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 244 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 245 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 246 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 247 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 248 | CLANG_WARN_STRICT_PROTOTYPES = YES; 249 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 250 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 251 | CLANG_WARN_UNREACHABLE_CODE = YES; 252 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 253 | COPY_PHASE_STRIP = NO; 254 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 255 | ENABLE_NS_ASSERTIONS = NO; 256 | ENABLE_STRICT_OBJC_MSGSEND = YES; 257 | GCC_C_LANGUAGE_STANDARD = gnu11; 258 | GCC_NO_COMMON_BLOCKS = YES; 259 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 260 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 261 | GCC_WARN_UNDECLARED_SELECTOR = YES; 262 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 263 | GCC_WARN_UNUSED_FUNCTION = YES; 264 | GCC_WARN_UNUSED_VARIABLE = YES; 265 | MACOSX_DEPLOYMENT_TARGET = 11.0; 266 | MTL_ENABLE_DEBUG_INFO = NO; 267 | MTL_FAST_MATH = YES; 268 | SDKROOT = macosx; 269 | SWIFT_COMPILATION_MODE = wholemodule; 270 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 271 | }; 272 | name = Release; 273 | }; 274 | CC5AFDBB22AA0AB2004E041A /* Debug */ = { 275 | isa = XCBuildConfiguration; 276 | buildSettings = { 277 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 278 | CODE_SIGN_ENTITLEMENTS = ScreenCasting/ScreenCasting.entitlements; 279 | CODE_SIGN_IDENTITY = "-"; 280 | CODE_SIGN_STYLE = Automatic; 281 | COMBINE_HIDPI_IMAGES = YES; 282 | DEVELOPMENT_TEAM = ""; 283 | ENABLE_HARDENED_RUNTIME = YES; 284 | INFOPLIST_FILE = ScreenCasting/Info.plist; 285 | LD_RUNPATH_SEARCH_PATHS = ( 286 | "$(inherited)", 287 | "@executable_path/../Frameworks", 288 | ); 289 | PRODUCT_BUNDLE_IDENTIFIER = org.oltica.ScreenCasting; 290 | PRODUCT_NAME = "$(TARGET_NAME)"; 291 | PROVISIONING_PROFILE_SPECIFIER = ""; 292 | SWIFT_VERSION = 5.0; 293 | }; 294 | name = Debug; 295 | }; 296 | CC5AFDBC22AA0AB2004E041A /* Release */ = { 297 | isa = XCBuildConfiguration; 298 | buildSettings = { 299 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 300 | CODE_SIGN_ENTITLEMENTS = ScreenCasting/ScreenCasting.entitlements; 301 | CODE_SIGN_IDENTITY = "-"; 302 | CODE_SIGN_STYLE = Automatic; 303 | COMBINE_HIDPI_IMAGES = YES; 304 | DEVELOPMENT_TEAM = ""; 305 | ENABLE_HARDENED_RUNTIME = YES; 306 | INFOPLIST_FILE = ScreenCasting/Info.plist; 307 | LD_RUNPATH_SEARCH_PATHS = ( 308 | "$(inherited)", 309 | "@executable_path/../Frameworks", 310 | ); 311 | PRODUCT_BUNDLE_IDENTIFIER = org.oltica.ScreenCasting; 312 | PRODUCT_NAME = "$(TARGET_NAME)"; 313 | PROVISIONING_PROFILE_SPECIFIER = ""; 314 | SWIFT_VERSION = 5.0; 315 | }; 316 | name = Release; 317 | }; 318 | /* End XCBuildConfiguration section */ 319 | 320 | /* Begin XCConfigurationList section */ 321 | CC5AFDA722AA0AB1004E041A /* Build configuration list for PBXProject "ScreenCasting" */ = { 322 | isa = XCConfigurationList; 323 | buildConfigurations = ( 324 | CC5AFDB822AA0AB2004E041A /* Debug */, 325 | CC5AFDB922AA0AB2004E041A /* Release */, 326 | ); 327 | defaultConfigurationIsVisible = 0; 328 | defaultConfigurationName = Release; 329 | }; 330 | CC5AFDBA22AA0AB2004E041A /* Build configuration list for PBXNativeTarget "ScreenCasting" */ = { 331 | isa = XCConfigurationList; 332 | buildConfigurations = ( 333 | CC5AFDBB22AA0AB2004E041A /* Debug */, 334 | CC5AFDBC22AA0AB2004E041A /* Release */, 335 | ); 336 | defaultConfigurationIsVisible = 0; 337 | defaultConfigurationName = Release; 338 | }; 339 | /* End XCConfigurationList section */ 340 | }; 341 | rootObject = CC5AFDA422AA0AB1004E041A /* Project object */; 342 | } 343 | -------------------------------------------------------------------------------- /ScreenCasting.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ScreenCasting.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ScreenCasting/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ScreenCasting 4 | // 5 | // Created by Khaos Tian on 6/6/19. 6 | // Copyright © 2019 Oltica. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | @NSApplicationMain 12 | class AppDelegate: NSObject, NSApplicationDelegate { 13 | 14 | private var primaryWindow: NSWindow? 15 | 16 | func applicationDidFinishLaunching(_ aNotification: Notification) { 17 | primaryWindow = NSApplication.shared.windows.first 18 | } 19 | 20 | func applicationWillTerminate(_ aNotification: Notification) { 21 | } 22 | 23 | func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool { 24 | guard !flag else { 25 | return false 26 | } 27 | 28 | primaryWindow?.makeKeyAndOrderFront(self) 29 | return true 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /ScreenCasting/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /ScreenCasting/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ScreenCasting/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | -------------------------------------------------------------------------------- /ScreenCasting/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | Copyright © 2019 Oltica. All rights reserved. 27 | NSMainStoryboardFile 28 | Main 29 | NSPrincipalClass 30 | NSApplication 31 | NSSupportsAutomaticTermination 32 | 33 | NSSupportsSuddenTermination 34 | 35 | NSCameraUsageDescription 36 | Camera Access 37 | NSMicrophoneUsageDescription 38 | Microphone Access 39 | 40 | 41 | -------------------------------------------------------------------------------- /ScreenCasting/ScreenCasting.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.device.audio-input 8 | 9 | com.apple.security.device.camera 10 | 11 | com.apple.security.device.usb 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ScreenCasting/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ScreenCasting 4 | // 5 | // Created by Khaos Tian on 6/6/19. 6 | // Copyright © 2019 Oltica. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import CoreMediaIO 11 | import AVFoundation 12 | import IOKit.pwr_mgt 13 | 14 | class ViewController: NSViewController { 15 | 16 | private var previewLayer: AVCaptureVideoPreviewLayer? 17 | @IBOutlet weak var activityIndicator: NSProgressIndicator! 18 | @IBOutlet weak var labelEffectView: NSVisualEffectView! 19 | @IBOutlet weak var deviceLabel: NSTextField! 20 | 21 | private var captureSession: AVCaptureSession? 22 | 23 | private var activeDevice: AVCaptureDevice? 24 | private var activeAudioDevice: AVCaptureDevice? 25 | private var audioOutput: AVCaptureAudioPreviewOutput? 26 | 27 | private var isViewVisible = false 28 | 29 | private var isElementHidden = false 30 | 31 | private var sleepAssertionID: IOPMAssertionID? 32 | 33 | override func viewDidLoad() { 34 | super.viewDidLoad() 35 | 36 | let gesture = NSClickGestureRecognizer(target: self, action: #selector(didClickOnView)) 37 | view.addGestureRecognizer(gesture) 38 | 39 | labelEffectView.layer?.cornerRadius = 8 40 | AVCaptureDevice.requestAccess(for: .video) { result in 41 | guard result else { 42 | NSLog("Rejected.") 43 | return 44 | } 45 | self.setupAVStack() 46 | } 47 | 48 | NotificationCenter.default.addObserver( 49 | self, 50 | selector: #selector(handlePortFormatDescriptionDidChangeNotification(_:)), 51 | name: .AVCaptureInputPortFormatDescriptionDidChange, 52 | object: nil 53 | ) 54 | } 55 | 56 | @objc 57 | private func newDocument(_ sender: AnyObject) { 58 | if let windowController = self.storyboard?.instantiateInitialController() as? NSWindowController { 59 | windowController.showWindow(sender) 60 | } 61 | } 62 | 63 | @objc 64 | private func didClickOnView() { 65 | guard captureSession != nil else { 66 | return 67 | } 68 | 69 | isElementHidden.toggle() 70 | 71 | if isElementHidden { 72 | hideElements() 73 | } else { 74 | showElements() 75 | } 76 | } 77 | 78 | override func rightMouseDown(with event: NSEvent) { 79 | let cameraSession = AVCaptureDevice.DiscoverySession( 80 | deviceTypes: [ 81 | .builtInWideAngleCamera, 82 | .externalUnknown, 83 | ], 84 | mediaType: .video, 85 | position: .unspecified 86 | ) 87 | 88 | let screenCastSession = AVCaptureDevice.DiscoverySession( 89 | deviceTypes: [ 90 | .builtInWideAngleCamera, 91 | .externalUnknown, 92 | ], 93 | mediaType: .muxed, 94 | position: .unspecified 95 | ) 96 | 97 | let devices = screenCastSession.devices + cameraSession.devices 98 | 99 | let menu = NSMenu(title: "Settings") 100 | 101 | let deviceTitleItem = NSMenuItem(title: "Source", action: nil, keyEquivalent: "") 102 | menu.addItem(deviceTitleItem) 103 | 104 | for device in devices { 105 | let item = NSMenuItem(title: device.localizedName, action: #selector(handleVideoSourceSelect(_:)), keyEquivalent: "") 106 | item.indentationLevel = 1 107 | item.representedObject = device 108 | item.state = activeDevice == device ? .on : .off 109 | menu.addItem(item) 110 | } 111 | 112 | if devices.isEmpty { 113 | menu.addItem(withTitle: "No Available Source", action: nil, keyEquivalent: "") 114 | } 115 | 116 | if let activeDevice = activeDevice { 117 | menu.addItem(NSMenuItem.separator()) 118 | 119 | let audioDiscoverySession = AVCaptureDevice.DiscoverySession( 120 | deviceTypes: [ 121 | .builtInMicrophone, 122 | .externalUnknown 123 | ], 124 | mediaType: .audio, 125 | position: .unspecified 126 | ) 127 | 128 | let audioTitleItem = NSMenuItem(title: "Audio", action: nil, keyEquivalent: "") 129 | menu.addItem(audioTitleItem) 130 | 131 | if activeDevice.hasMediaType(.muxed) { 132 | let item = NSMenuItem(title: activeDevice.localizedName, action: nil, keyEquivalent: "") 133 | item.indentationLevel = 1 134 | item.representedObject = nil 135 | item.state = .on 136 | menu.addItem(item) 137 | } else { 138 | for audioDevice in audioDiscoverySession.devices { 139 | let item = NSMenuItem(title: audioDevice.localizedName, action: #selector(handleAudioDeviceSelect(_:)), keyEquivalent: "") 140 | item.indentationLevel = 1 141 | item.representedObject = audioDevice 142 | item.state = activeAudioDevice == audioDevice ? .on : .off 143 | menu.addItem(item) 144 | } 145 | } 146 | } 147 | 148 | let videoFormats = activeDevice?.formats.filter { $0.mediaType == .video } ?? [] 149 | if !videoFormats.isEmpty { 150 | menu.addItem(NSMenuItem.separator()) 151 | let formatTitleItem = NSMenuItem(title: "Format", action: nil, keyEquivalent: "") 152 | menu.addItem(formatTitleItem) 153 | 154 | for format in videoFormats { 155 | let frameRates = format.videoSupportedFrameRateRanges 156 | .map { String(format: "%.2f fps", $0.maxFrameRate) } 157 | .joined(separator: ",") 158 | 159 | let dimensions = format.formatDescription.dimensions 160 | let resolution = "\(dimensions.width)x\(dimensions.height)" 161 | 162 | let item = NSMenuItem( 163 | title: "\(resolution) (\(frameRates)) - \(format.formatDescription.mediaSubType)", 164 | action: #selector(handleVideoFormatSelect(_:)), 165 | keyEquivalent: "" 166 | ) 167 | item.indentationLevel = 1 168 | item.representedObject = format 169 | item.state = (activeDevice?.activeFormat == format) ? .on : .off 170 | menu.addItem(item) 171 | } 172 | } 173 | 174 | if let captureSession = captureSession { 175 | menu.addItem(NSMenuItem.separator()) 176 | 177 | var availablePresets: [AVCaptureSession.Preset] = [ 178 | .photo, 179 | .high, 180 | .medium, 181 | .low, 182 | ] 183 | 184 | if #available(macOS 10.15, *) { 185 | availablePresets.append( 186 | contentsOf: [ 187 | .hd4K3840x2160, 188 | .hd1920x1080, 189 | .hd1280x720, 190 | ] 191 | ) 192 | } 193 | 194 | let presetTitleItem = NSMenuItem(title: "Preset", action: nil, keyEquivalent: "") 195 | menu.addItem(presetTitleItem) 196 | 197 | for preset in availablePresets { 198 | if captureSession.canSetSessionPreset(preset) { 199 | let item = NSMenuItem(title: preset.rawValue, action: #selector(handleVideoPresetSelect(_:)), keyEquivalent: "") 200 | item.indentationLevel = 1 201 | item.representedObject = preset 202 | item.state = captureSession.sessionPreset == preset ? .on : .off 203 | menu.addItem(item) 204 | } 205 | } 206 | } 207 | 208 | NSMenu.popUpContextMenu(menu, with: event, for: self.view) 209 | } 210 | 211 | @objc 212 | private func handleVideoSourceSelect(_ sender: NSMenuItem) { 213 | guard let device = sender.representedObject as? AVCaptureDevice else { 214 | return 215 | } 216 | 217 | configureInput(device) 218 | } 219 | 220 | @objc 221 | private func handleAudioDeviceSelect(_ sender: NSMenuItem) { 222 | guard let device = sender.representedObject as? AVCaptureDevice, 223 | let activeDevice = activeDevice, 224 | activeAudioDevice != device else { 225 | return 226 | } 227 | 228 | configureInput(activeDevice, audioDevice: device) 229 | } 230 | 231 | @objc 232 | private func handleVideoPresetSelect(_ sender: NSMenuItem) { 233 | guard let preset = sender.representedObject as? AVCaptureSession.Preset else { 234 | return 235 | } 236 | 237 | captureSession?.sessionPreset = preset 238 | } 239 | 240 | @objc 241 | private func handleVideoFormatSelect(_ sender: NSMenuItem) { 242 | guard let activeDevice = activeDevice, 243 | let format = sender.representedObject as? AVCaptureDevice.Format else { 244 | return 245 | } 246 | 247 | do { 248 | try activeDevice.lockForConfiguration() 249 | 250 | activeDevice.activeFormat = format 251 | 252 | activeDevice.unlockForConfiguration() 253 | } catch { 254 | NSLog("Failed to update device, error: \(error)") 255 | } 256 | } 257 | 258 | @objc 259 | private func handlePortFormatDescriptionDidChangeNotification(_ notification: NSNotification) { 260 | if let captureSession = captureSession, let port = notification.object as? AVCaptureInput.Port { 261 | guard captureSession.inputs.contains(where: { $0.ports.contains(port) }), (port.mediaType == .video || port.mediaType == .muxed) else { 262 | return 263 | } 264 | 265 | if let formatDescription = port.formatDescription, 266 | let window = self.view.window, 267 | let screen = window.screen { 268 | 269 | let dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription) 270 | 271 | window.aspectRatio = NSSize( 272 | width: CGFloat(dimensions.width)/CGFloat(dimensions.height), 273 | height: 1 274 | ) 275 | 276 | window.setContentSize( 277 | NSSize( 278 | width: Int(CGFloat(dimensions.width) / screen.backingScaleFactor), 279 | height: Int(CGFloat(dimensions.height) / screen.backingScaleFactor) 280 | ) 281 | ) 282 | } 283 | } 284 | } 285 | 286 | private func setupAVStack() { 287 | var prop = CMIOObjectPropertyAddress( 288 | mSelector: CMIOObjectPropertySelector(kCMIOHardwarePropertyAllowScreenCaptureDevices), 289 | mScope: CMIOObjectPropertyScope(kCMIOObjectPropertyScopeGlobal), 290 | mElement: CMIOObjectPropertyElement(kCMIOObjectPropertyElementMaster) 291 | ) 292 | var allow: UInt32 = 1 293 | CMIOObjectSetPropertyData( 294 | CMIOObjectID(kCMIOObjectSystemObject), 295 | &prop, 296 | 0, 297 | nil, 298 | UInt32(MemoryLayout.size(ofValue: allow)), 299 | &allow 300 | ) 301 | 302 | NotificationCenter.default.addObserver( 303 | self, 304 | selector: #selector(handleDeviceConnected(_:)), 305 | name: .AVCaptureDeviceWasConnected, 306 | object: nil 307 | ) 308 | 309 | NotificationCenter.default.addObserver( 310 | self, 311 | selector: #selector(handleDeviceDisconnected(_:)), 312 | name: .AVCaptureDeviceWasDisconnected, 313 | object: nil 314 | ) 315 | } 316 | 317 | @objc 318 | private func handleDeviceConnected(_ notification: Notification) { 319 | guard isViewVisible else { 320 | return 321 | } 322 | 323 | if activeDevice == nil, 324 | let device = notification.object as? AVCaptureDevice, 325 | device.hasMediaType(.muxed) { 326 | self.configureInput(device) 327 | } 328 | } 329 | 330 | @objc 331 | private func handleDeviceDisconnected(_ notification: Notification) { 332 | guard let device = notification.object as? AVCaptureDevice else { 333 | return 334 | } 335 | 336 | if self.activeDevice == device { 337 | teardown() 338 | } 339 | } 340 | 341 | override func viewDidAppear() { 342 | super.viewDidAppear() 343 | isViewVisible = true 344 | activityIndicator.startAnimation(self) 345 | 346 | let screenCastSession = AVCaptureDevice.DiscoverySession( 347 | deviceTypes: [ 348 | .builtInWideAngleCamera, 349 | .externalUnknown, 350 | ], 351 | mediaType: .muxed, 352 | position: .unspecified 353 | ) 354 | 355 | if let device = screenCastSession.devices.first { 356 | self.configureInput(device) 357 | } 358 | } 359 | 360 | override func viewDidDisappear() { 361 | super.viewDidDisappear() 362 | isViewVisible = false 363 | teardown() 364 | } 365 | 366 | private func teardown() { 367 | self.activeDevice = nil 368 | self.activeAudioDevice = nil 369 | self.audioOutput = nil 370 | self.labelEffectView.isHidden = true 371 | self.captureSession?.stopRunning() 372 | self.captureSession = nil 373 | activityIndicator.startAnimation(self) 374 | 375 | if let sleepAssertionID = sleepAssertionID { 376 | IOPMAssertionRelease(sleepAssertionID) 377 | self.sleepAssertionID = nil 378 | } 379 | } 380 | 381 | private func showElements() { 382 | updateWindowButtonsVisibility(false) 383 | labelEffectView.isHidden = false 384 | } 385 | 386 | private func hideElements() { 387 | updateWindowButtonsVisibility(true) 388 | labelEffectView.isHidden = true 389 | } 390 | 391 | private func updateWindowButtonsVisibility(_ isHidden: Bool) { 392 | guard let window = view.window else { 393 | return 394 | } 395 | 396 | window.standardWindowButton(.closeButton)?.isHidden = isHidden 397 | window.standardWindowButton(.miniaturizeButton)?.isHidden = isHidden 398 | window.standardWindowButton(.zoomButton)?.isHidden = isHidden 399 | } 400 | 401 | private func configureInput(_ device: AVCaptureDevice, audioDevice: AVCaptureDevice? = nil) { 402 | if activeDevice != nil { 403 | captureSession?.stopRunning() 404 | } 405 | activeAudioDevice = nil 406 | 407 | if sleepAssertionID == nil { 408 | var assertionID = IOPMAssertionID() 409 | let res = IOPMAssertionCreateWithName( 410 | kIOPMAssertPreventUserIdleDisplaySleep as CFString, 411 | IOPMAssertionLevel(kIOPMAssertionLevelOn), 412 | "Content Streaming" as CFString, 413 | &assertionID 414 | ) 415 | if res == kIOReturnSuccess { 416 | sleepAssertionID = assertionID 417 | } 418 | } 419 | 420 | let captureSession = AVCaptureSession() 421 | activeDevice = device 422 | 423 | do { 424 | try device.lockForConfiguration() 425 | } catch { 426 | NSLog("Unable to lock device") 427 | } 428 | 429 | deviceLabel.stringValue = device.localizedName 430 | labelEffectView.isHidden = false 431 | 432 | let previewLayer = AVCaptureVideoPreviewLayer(sessionWithNoConnection: captureSession) 433 | view.layer = previewLayer 434 | self.previewLayer = previewLayer 435 | 436 | captureSession.beginConfiguration() 437 | guard let videoInputDevice = try? AVCaptureDeviceInput(device: device), 438 | captureSession.canAddInput(videoInputDevice) else { 439 | NSLog("Can't add it.") 440 | captureSession.commitConfiguration() 441 | return 442 | } 443 | 444 | captureSession.addInputWithNoConnections(videoInputDevice) 445 | if let videoPort = videoInputDevice.ports.first(where: { $0.mediaType == .video || $0.mediaType == .muxed }) { 446 | captureSession.addConnection(AVCaptureConnection(inputPort: videoPort, videoPreviewLayer: previewLayer)) 447 | } 448 | 449 | if let audioPort = videoInputDevice.ports.first(where: { $0.mediaType == .audio || $0.mediaType == .muxed }) { 450 | activeAudioDevice = nil 451 | 452 | let audioOutput = AVCaptureAudioPreviewOutput() 453 | audioOutput.outputDeviceUniqueID = defaultAudioDeviceUniqueID() 454 | audioOutput.volume = 1.0 455 | self.audioOutput = audioOutput 456 | 457 | captureSession.addOutputWithNoConnections(audioOutput) 458 | captureSession.addConnection(AVCaptureConnection(inputPorts: [audioPort], output: audioOutput)) 459 | } else { 460 | let recommendedAudioDevice: AVCaptureDevice? = { 461 | if let audioDevice = audioDevice { 462 | return audioDevice 463 | } 464 | 465 | let audioDiscoverySession = AVCaptureDevice.DiscoverySession( 466 | deviceTypes: [ 467 | .builtInMicrophone, 468 | .externalUnknown 469 | ], 470 | mediaType: .audio, 471 | position: .unspecified 472 | ) 473 | 474 | let possibleAudioDevices = audioDiscoverySession.devices.filter { $0.localizedName == device.localizedName } 475 | 476 | if possibleAudioDevices.count == 1 { 477 | return possibleAudioDevices.first 478 | } else { 479 | return nil 480 | } 481 | }() 482 | 483 | if let recommendedAudioDevice = recommendedAudioDevice, 484 | let audioInputDevice = try? AVCaptureDeviceInput(device: recommendedAudioDevice), 485 | captureSession.canAddInput(audioInputDevice) { 486 | activeAudioDevice = recommendedAudioDevice 487 | 488 | let audioOutput = AVCaptureAudioPreviewOutput() 489 | audioOutput.outputDeviceUniqueID = defaultAudioDeviceUniqueID() 490 | audioOutput.volume = 1.0 491 | self.audioOutput = audioOutput 492 | 493 | captureSession.addInputWithNoConnections(audioInputDevice) 494 | captureSession.addOutputWithNoConnections(audioOutput) 495 | 496 | captureSession.addConnection(AVCaptureConnection(inputPorts: audioInputDevice.ports, output: audioOutput)) 497 | } else { 498 | self.audioOutput = nil 499 | } 500 | } 501 | 502 | captureSession.commitConfiguration() 503 | 504 | captureSession.startRunning() 505 | device.unlockForConfiguration() 506 | activityIndicator.stopAnimation(self) 507 | self.captureSession = captureSession 508 | } 509 | } 510 | 511 | extension ViewController { 512 | 513 | private func defaultAudioDeviceUniqueID() -> String? { 514 | var propertyAddress = AudioObjectPropertyAddress( 515 | mSelector: kAudioHardwarePropertyDefaultOutputDevice, 516 | mScope: kAudioObjectPropertyScopeGlobal, 517 | mElement: kAudioObjectPropertyElementMain 518 | ) 519 | var deviceID = AudioObjectID() 520 | var dataSize = UInt32(MemoryLayout.size) 521 | 522 | var err = AudioObjectGetPropertyData( 523 | AudioObjectID(kAudioObjectSystemObject), 524 | &propertyAddress, 525 | 0, 526 | nil, 527 | &dataSize, 528 | &deviceID 529 | ) 530 | 531 | guard err == 0 else { 532 | return nil 533 | } 534 | 535 | var name: CFString? 536 | dataSize = UInt32(MemoryLayout.size) 537 | propertyAddress.mSelector = kAudioDevicePropertyDeviceUID 538 | 539 | err = withUnsafeMutablePointer(to: &name, { name in 540 | return AudioObjectGetPropertyData( 541 | deviceID, 542 | &propertyAddress, 543 | 0, 544 | nil, 545 | &dataSize, 546 | name 547 | ) 548 | }) 549 | 550 | guard err == 0 else { 551 | return nil 552 | } 553 | 554 | return name as String? 555 | } 556 | } 557 | -------------------------------------------------------------------------------- /ScreenCasting/WindowController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // WindowController.swift 3 | // ScreenCasting 4 | // 5 | // Created by Khaos Tian on 6/6/19. 6 | // Copyright © 2019 Oltica. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class WindowController: NSWindowController { 12 | 13 | override func windowDidLoad() { 14 | super.windowDidLoad() 15 | window?.appearance = NSAppearance(named: .darkAqua) 16 | window?.backgroundColor = .black 17 | window?.isMovableByWindowBackground = true 18 | } 19 | } 20 | --------------------------------------------------------------------------------