├── .travis.yml ├── LICENSE ├── README.md └── VTToolbox ├── VTToolbox.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── mganvi001c.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── mganvi001c.xcuserdatad │ └── xcschemes │ └── VTToolbox.xcscheme ├── VTToolbox ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── H264HwEncoderImpl.h ├── H264HwEncoderImpl.m ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m └── VTToolboxTests ├── Info.plist └── VTToolboxTests.m /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | xcode_project: VTToolbox/VTToolbox.xcodeproj # path to your xcodeproj folder 3 | xcode_scheme: VTToolbox 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2015 Manish Ganvir 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![alt text](https://travis-ci.org/manishganvir/iOS-h264Hw-Toolbox.svg?branch=master) 2 | 3 | # iOS-h264Hw-Toolbox 4 | Simple iOS8 app which uses new iOS8 based hardware acceleration for H264 (Using videotoolbox) 5 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 063190BB1ACCEB85002B5EAF /* H264HwEncoderImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = 063190BA1ACCEB85002B5EAF /* H264HwEncoderImpl.m */; }; 11 | 06ADA19B1ACCEB0B00106FA9 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 06ADA19A1ACCEB0B00106FA9 /* main.m */; }; 12 | 06ADA19E1ACCEB0B00106FA9 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 06ADA19D1ACCEB0B00106FA9 /* AppDelegate.m */; }; 13 | 06ADA1A11ACCEB0B00106FA9 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 06ADA1A01ACCEB0B00106FA9 /* ViewController.m */; }; 14 | 06ADA1A41ACCEB0B00106FA9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 06ADA1A21ACCEB0B00106FA9 /* Main.storyboard */; }; 15 | 06ADA1A61ACCEB0B00106FA9 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 06ADA1A51ACCEB0B00106FA9 /* Images.xcassets */; }; 16 | 06ADA1A91ACCEB0B00106FA9 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 06ADA1A71ACCEB0B00106FA9 /* LaunchScreen.xib */; }; 17 | 06ADA1B51ACCEB0B00106FA9 /* VTToolboxTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 06ADA1B41ACCEB0B00106FA9 /* VTToolboxTests.m */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | 06ADA1AF1ACCEB0B00106FA9 /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = 06ADA18D1ACCEB0B00106FA9 /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = 06ADA1941ACCEB0B00106FA9; 26 | remoteInfo = VTToolbox; 27 | }; 28 | /* End PBXContainerItemProxy section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | 063190B91ACCEB85002B5EAF /* H264HwEncoderImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = H264HwEncoderImpl.h; sourceTree = ""; }; 32 | 063190BA1ACCEB85002B5EAF /* H264HwEncoderImpl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = H264HwEncoderImpl.m; sourceTree = ""; }; 33 | 06ADA1951ACCEB0B00106FA9 /* VTToolbox.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VTToolbox.app; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | 06ADA1991ACCEB0B00106FA9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 06ADA19A1ACCEB0B00106FA9 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 36 | 06ADA19C1ACCEB0B00106FA9 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 37 | 06ADA19D1ACCEB0B00106FA9 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 38 | 06ADA19F1ACCEB0B00106FA9 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 39 | 06ADA1A01ACCEB0B00106FA9 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 40 | 06ADA1A31ACCEB0B00106FA9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 41 | 06ADA1A51ACCEB0B00106FA9 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 42 | 06ADA1A81ACCEB0B00106FA9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 43 | 06ADA1AE1ACCEB0B00106FA9 /* VTToolboxTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = VTToolboxTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | 06ADA1B31ACCEB0B00106FA9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | 06ADA1B41ACCEB0B00106FA9 /* VTToolboxTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = VTToolboxTests.m; sourceTree = ""; }; 46 | /* End PBXFileReference section */ 47 | 48 | /* Begin PBXFrameworksBuildPhase section */ 49 | 06ADA1921ACCEB0B00106FA9 /* Frameworks */ = { 50 | isa = PBXFrameworksBuildPhase; 51 | buildActionMask = 2147483647; 52 | files = ( 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | 06ADA1AB1ACCEB0B00106FA9 /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | ); 61 | runOnlyForDeploymentPostprocessing = 0; 62 | }; 63 | /* End PBXFrameworksBuildPhase section */ 64 | 65 | /* Begin PBXGroup section */ 66 | 06ADA18C1ACCEB0B00106FA9 = { 67 | isa = PBXGroup; 68 | children = ( 69 | 06ADA1971ACCEB0B00106FA9 /* VTToolbox */, 70 | 06ADA1B11ACCEB0B00106FA9 /* VTToolboxTests */, 71 | 06ADA1961ACCEB0B00106FA9 /* Products */, 72 | ); 73 | sourceTree = ""; 74 | }; 75 | 06ADA1961ACCEB0B00106FA9 /* Products */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | 06ADA1951ACCEB0B00106FA9 /* VTToolbox.app */, 79 | 06ADA1AE1ACCEB0B00106FA9 /* VTToolboxTests.xctest */, 80 | ); 81 | name = Products; 82 | sourceTree = ""; 83 | }; 84 | 06ADA1971ACCEB0B00106FA9 /* VTToolbox */ = { 85 | isa = PBXGroup; 86 | children = ( 87 | 063190B91ACCEB85002B5EAF /* H264HwEncoderImpl.h */, 88 | 063190BA1ACCEB85002B5EAF /* H264HwEncoderImpl.m */, 89 | 06ADA19C1ACCEB0B00106FA9 /* AppDelegate.h */, 90 | 06ADA19D1ACCEB0B00106FA9 /* AppDelegate.m */, 91 | 06ADA19F1ACCEB0B00106FA9 /* ViewController.h */, 92 | 06ADA1A01ACCEB0B00106FA9 /* ViewController.m */, 93 | 06ADA1A21ACCEB0B00106FA9 /* Main.storyboard */, 94 | 06ADA1A51ACCEB0B00106FA9 /* Images.xcassets */, 95 | 06ADA1A71ACCEB0B00106FA9 /* LaunchScreen.xib */, 96 | 06ADA1981ACCEB0B00106FA9 /* Supporting Files */, 97 | ); 98 | path = VTToolbox; 99 | sourceTree = ""; 100 | }; 101 | 06ADA1981ACCEB0B00106FA9 /* Supporting Files */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | 06ADA1991ACCEB0B00106FA9 /* Info.plist */, 105 | 06ADA19A1ACCEB0B00106FA9 /* main.m */, 106 | ); 107 | name = "Supporting Files"; 108 | sourceTree = ""; 109 | }; 110 | 06ADA1B11ACCEB0B00106FA9 /* VTToolboxTests */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 06ADA1B41ACCEB0B00106FA9 /* VTToolboxTests.m */, 114 | 06ADA1B21ACCEB0B00106FA9 /* Supporting Files */, 115 | ); 116 | path = VTToolboxTests; 117 | sourceTree = ""; 118 | }; 119 | 06ADA1B21ACCEB0B00106FA9 /* Supporting Files */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | 06ADA1B31ACCEB0B00106FA9 /* Info.plist */, 123 | ); 124 | name = "Supporting Files"; 125 | sourceTree = ""; 126 | }; 127 | /* End PBXGroup section */ 128 | 129 | /* Begin PBXNativeTarget section */ 130 | 06ADA1941ACCEB0B00106FA9 /* VTToolbox */ = { 131 | isa = PBXNativeTarget; 132 | buildConfigurationList = 06ADA1B81ACCEB0B00106FA9 /* Build configuration list for PBXNativeTarget "VTToolbox" */; 133 | buildPhases = ( 134 | 06ADA1911ACCEB0B00106FA9 /* Sources */, 135 | 06ADA1921ACCEB0B00106FA9 /* Frameworks */, 136 | 06ADA1931ACCEB0B00106FA9 /* Resources */, 137 | ); 138 | buildRules = ( 139 | ); 140 | dependencies = ( 141 | ); 142 | name = VTToolbox; 143 | productName = VTToolbox; 144 | productReference = 06ADA1951ACCEB0B00106FA9 /* VTToolbox.app */; 145 | productType = "com.apple.product-type.application"; 146 | }; 147 | 06ADA1AD1ACCEB0B00106FA9 /* VTToolboxTests */ = { 148 | isa = PBXNativeTarget; 149 | buildConfigurationList = 06ADA1BB1ACCEB0B00106FA9 /* Build configuration list for PBXNativeTarget "VTToolboxTests" */; 150 | buildPhases = ( 151 | 06ADA1AA1ACCEB0B00106FA9 /* Sources */, 152 | 06ADA1AB1ACCEB0B00106FA9 /* Frameworks */, 153 | 06ADA1AC1ACCEB0B00106FA9 /* Resources */, 154 | ); 155 | buildRules = ( 156 | ); 157 | dependencies = ( 158 | 06ADA1B01ACCEB0B00106FA9 /* PBXTargetDependency */, 159 | ); 160 | name = VTToolboxTests; 161 | productName = VTToolboxTests; 162 | productReference = 06ADA1AE1ACCEB0B00106FA9 /* VTToolboxTests.xctest */; 163 | productType = "com.apple.product-type.bundle.unit-test"; 164 | }; 165 | /* End PBXNativeTarget section */ 166 | 167 | /* Begin PBXProject section */ 168 | 06ADA18D1ACCEB0B00106FA9 /* Project object */ = { 169 | isa = PBXProject; 170 | attributes = { 171 | LastUpgradeCheck = 0620; 172 | ORGANIZATIONNAME = "Ganvir, Manish"; 173 | TargetAttributes = { 174 | 06ADA1941ACCEB0B00106FA9 = { 175 | CreatedOnToolsVersion = 6.2; 176 | }; 177 | 06ADA1AD1ACCEB0B00106FA9 = { 178 | CreatedOnToolsVersion = 6.2; 179 | TestTargetID = 06ADA1941ACCEB0B00106FA9; 180 | }; 181 | }; 182 | }; 183 | buildConfigurationList = 06ADA1901ACCEB0B00106FA9 /* Build configuration list for PBXProject "VTToolbox" */; 184 | compatibilityVersion = "Xcode 3.2"; 185 | developmentRegion = English; 186 | hasScannedForEncodings = 0; 187 | knownRegions = ( 188 | en, 189 | Base, 190 | ); 191 | mainGroup = 06ADA18C1ACCEB0B00106FA9; 192 | productRefGroup = 06ADA1961ACCEB0B00106FA9 /* Products */; 193 | projectDirPath = ""; 194 | projectRoot = ""; 195 | targets = ( 196 | 06ADA1941ACCEB0B00106FA9 /* VTToolbox */, 197 | 06ADA1AD1ACCEB0B00106FA9 /* VTToolboxTests */, 198 | ); 199 | }; 200 | /* End PBXProject section */ 201 | 202 | /* Begin PBXResourcesBuildPhase section */ 203 | 06ADA1931ACCEB0B00106FA9 /* Resources */ = { 204 | isa = PBXResourcesBuildPhase; 205 | buildActionMask = 2147483647; 206 | files = ( 207 | 06ADA1A41ACCEB0B00106FA9 /* Main.storyboard in Resources */, 208 | 06ADA1A91ACCEB0B00106FA9 /* LaunchScreen.xib in Resources */, 209 | 06ADA1A61ACCEB0B00106FA9 /* Images.xcassets in Resources */, 210 | ); 211 | runOnlyForDeploymentPostprocessing = 0; 212 | }; 213 | 06ADA1AC1ACCEB0B00106FA9 /* Resources */ = { 214 | isa = PBXResourcesBuildPhase; 215 | buildActionMask = 2147483647; 216 | files = ( 217 | ); 218 | runOnlyForDeploymentPostprocessing = 0; 219 | }; 220 | /* End PBXResourcesBuildPhase section */ 221 | 222 | /* Begin PBXSourcesBuildPhase section */ 223 | 06ADA1911ACCEB0B00106FA9 /* Sources */ = { 224 | isa = PBXSourcesBuildPhase; 225 | buildActionMask = 2147483647; 226 | files = ( 227 | 06ADA1A11ACCEB0B00106FA9 /* ViewController.m in Sources */, 228 | 06ADA19E1ACCEB0B00106FA9 /* AppDelegate.m in Sources */, 229 | 06ADA19B1ACCEB0B00106FA9 /* main.m in Sources */, 230 | 063190BB1ACCEB85002B5EAF /* H264HwEncoderImpl.m in Sources */, 231 | ); 232 | runOnlyForDeploymentPostprocessing = 0; 233 | }; 234 | 06ADA1AA1ACCEB0B00106FA9 /* Sources */ = { 235 | isa = PBXSourcesBuildPhase; 236 | buildActionMask = 2147483647; 237 | files = ( 238 | 06ADA1B51ACCEB0B00106FA9 /* VTToolboxTests.m in Sources */, 239 | ); 240 | runOnlyForDeploymentPostprocessing = 0; 241 | }; 242 | /* End PBXSourcesBuildPhase section */ 243 | 244 | /* Begin PBXTargetDependency section */ 245 | 06ADA1B01ACCEB0B00106FA9 /* PBXTargetDependency */ = { 246 | isa = PBXTargetDependency; 247 | target = 06ADA1941ACCEB0B00106FA9 /* VTToolbox */; 248 | targetProxy = 06ADA1AF1ACCEB0B00106FA9 /* PBXContainerItemProxy */; 249 | }; 250 | /* End PBXTargetDependency section */ 251 | 252 | /* Begin PBXVariantGroup section */ 253 | 06ADA1A21ACCEB0B00106FA9 /* Main.storyboard */ = { 254 | isa = PBXVariantGroup; 255 | children = ( 256 | 06ADA1A31ACCEB0B00106FA9 /* Base */, 257 | ); 258 | name = Main.storyboard; 259 | sourceTree = ""; 260 | }; 261 | 06ADA1A71ACCEB0B00106FA9 /* LaunchScreen.xib */ = { 262 | isa = PBXVariantGroup; 263 | children = ( 264 | 06ADA1A81ACCEB0B00106FA9 /* Base */, 265 | ); 266 | name = LaunchScreen.xib; 267 | sourceTree = ""; 268 | }; 269 | /* End PBXVariantGroup section */ 270 | 271 | /* Begin XCBuildConfiguration section */ 272 | 06ADA1B61ACCEB0B00106FA9 /* Debug */ = { 273 | isa = XCBuildConfiguration; 274 | buildSettings = { 275 | ALWAYS_SEARCH_USER_PATHS = NO; 276 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 277 | CLANG_CXX_LIBRARY = "libc++"; 278 | CLANG_ENABLE_MODULES = YES; 279 | CLANG_ENABLE_OBJC_ARC = YES; 280 | CLANG_WARN_BOOL_CONVERSION = YES; 281 | CLANG_WARN_CONSTANT_CONVERSION = YES; 282 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 283 | CLANG_WARN_EMPTY_BODY = YES; 284 | CLANG_WARN_ENUM_CONVERSION = YES; 285 | CLANG_WARN_INT_CONVERSION = YES; 286 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 287 | CLANG_WARN_UNREACHABLE_CODE = YES; 288 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 289 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 290 | COPY_PHASE_STRIP = NO; 291 | ENABLE_STRICT_OBJC_MSGSEND = YES; 292 | GCC_C_LANGUAGE_STANDARD = gnu99; 293 | GCC_DYNAMIC_NO_PIC = NO; 294 | GCC_OPTIMIZATION_LEVEL = 0; 295 | GCC_PREPROCESSOR_DEFINITIONS = ( 296 | "DEBUG=1", 297 | "$(inherited)", 298 | ); 299 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 300 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 301 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 302 | GCC_WARN_UNDECLARED_SELECTOR = YES; 303 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 304 | GCC_WARN_UNUSED_FUNCTION = YES; 305 | GCC_WARN_UNUSED_VARIABLE = YES; 306 | IPHONEOS_DEPLOYMENT_TARGET = 8.2; 307 | MTL_ENABLE_DEBUG_INFO = YES; 308 | ONLY_ACTIVE_ARCH = YES; 309 | SDKROOT = iphoneos; 310 | }; 311 | name = Debug; 312 | }; 313 | 06ADA1B71ACCEB0B00106FA9 /* Release */ = { 314 | isa = XCBuildConfiguration; 315 | buildSettings = { 316 | ALWAYS_SEARCH_USER_PATHS = NO; 317 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 318 | CLANG_CXX_LIBRARY = "libc++"; 319 | CLANG_ENABLE_MODULES = YES; 320 | CLANG_ENABLE_OBJC_ARC = YES; 321 | CLANG_WARN_BOOL_CONVERSION = YES; 322 | CLANG_WARN_CONSTANT_CONVERSION = YES; 323 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 324 | CLANG_WARN_EMPTY_BODY = YES; 325 | CLANG_WARN_ENUM_CONVERSION = YES; 326 | CLANG_WARN_INT_CONVERSION = YES; 327 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 328 | CLANG_WARN_UNREACHABLE_CODE = YES; 329 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 330 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 331 | COPY_PHASE_STRIP = NO; 332 | ENABLE_NS_ASSERTIONS = NO; 333 | ENABLE_STRICT_OBJC_MSGSEND = YES; 334 | GCC_C_LANGUAGE_STANDARD = gnu99; 335 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 336 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 337 | GCC_WARN_UNDECLARED_SELECTOR = YES; 338 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 339 | GCC_WARN_UNUSED_FUNCTION = YES; 340 | GCC_WARN_UNUSED_VARIABLE = YES; 341 | IPHONEOS_DEPLOYMENT_TARGET = 8.2; 342 | MTL_ENABLE_DEBUG_INFO = NO; 343 | SDKROOT = iphoneos; 344 | VALIDATE_PRODUCT = YES; 345 | }; 346 | name = Release; 347 | }; 348 | 06ADA1B91ACCEB0B00106FA9 /* Debug */ = { 349 | isa = XCBuildConfiguration; 350 | buildSettings = { 351 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 352 | INFOPLIST_FILE = VTToolbox/Info.plist; 353 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 354 | PRODUCT_NAME = "$(TARGET_NAME)"; 355 | }; 356 | name = Debug; 357 | }; 358 | 06ADA1BA1ACCEB0B00106FA9 /* Release */ = { 359 | isa = XCBuildConfiguration; 360 | buildSettings = { 361 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 362 | INFOPLIST_FILE = VTToolbox/Info.plist; 363 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 364 | PRODUCT_NAME = "$(TARGET_NAME)"; 365 | }; 366 | name = Release; 367 | }; 368 | 06ADA1BC1ACCEB0B00106FA9 /* Debug */ = { 369 | isa = XCBuildConfiguration; 370 | buildSettings = { 371 | BUNDLE_LOADER = "$(TEST_HOST)"; 372 | FRAMEWORK_SEARCH_PATHS = ( 373 | "$(SDKROOT)/Developer/Library/Frameworks", 374 | "$(inherited)", 375 | ); 376 | GCC_PREPROCESSOR_DEFINITIONS = ( 377 | "DEBUG=1", 378 | "$(inherited)", 379 | ); 380 | INFOPLIST_FILE = VTToolboxTests/Info.plist; 381 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 382 | PRODUCT_NAME = "$(TARGET_NAME)"; 383 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/VTToolbox.app/VTToolbox"; 384 | }; 385 | name = Debug; 386 | }; 387 | 06ADA1BD1ACCEB0B00106FA9 /* Release */ = { 388 | isa = XCBuildConfiguration; 389 | buildSettings = { 390 | BUNDLE_LOADER = "$(TEST_HOST)"; 391 | FRAMEWORK_SEARCH_PATHS = ( 392 | "$(SDKROOT)/Developer/Library/Frameworks", 393 | "$(inherited)", 394 | ); 395 | INFOPLIST_FILE = VTToolboxTests/Info.plist; 396 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 397 | PRODUCT_NAME = "$(TARGET_NAME)"; 398 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/VTToolbox.app/VTToolbox"; 399 | }; 400 | name = Release; 401 | }; 402 | /* End XCBuildConfiguration section */ 403 | 404 | /* Begin XCConfigurationList section */ 405 | 06ADA1901ACCEB0B00106FA9 /* Build configuration list for PBXProject "VTToolbox" */ = { 406 | isa = XCConfigurationList; 407 | buildConfigurations = ( 408 | 06ADA1B61ACCEB0B00106FA9 /* Debug */, 409 | 06ADA1B71ACCEB0B00106FA9 /* Release */, 410 | ); 411 | defaultConfigurationIsVisible = 0; 412 | defaultConfigurationName = Release; 413 | }; 414 | 06ADA1B81ACCEB0B00106FA9 /* Build configuration list for PBXNativeTarget "VTToolbox" */ = { 415 | isa = XCConfigurationList; 416 | buildConfigurations = ( 417 | 06ADA1B91ACCEB0B00106FA9 /* Debug */, 418 | 06ADA1BA1ACCEB0B00106FA9 /* Release */, 419 | ); 420 | defaultConfigurationIsVisible = 0; 421 | defaultConfigurationName = Release; 422 | }; 423 | 06ADA1BB1ACCEB0B00106FA9 /* Build configuration list for PBXNativeTarget "VTToolboxTests" */ = { 424 | isa = XCConfigurationList; 425 | buildConfigurations = ( 426 | 06ADA1BC1ACCEB0B00106FA9 /* Debug */, 427 | 06ADA1BD1ACCEB0B00106FA9 /* Release */, 428 | ); 429 | defaultConfigurationIsVisible = 0; 430 | defaultConfigurationName = Release; 431 | }; 432 | /* End XCConfigurationList section */ 433 | }; 434 | rootObject = 06ADA18D1ACCEB0B00106FA9 /* Project object */; 435 | } 436 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox.xcodeproj/project.xcworkspace/xcuserdata/mganvi001c.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/manishganvir/iOS-h264Hw-Toolbox/1074d67045da57c3b0c46f75a6bbaff5bc19160d/VTToolbox/VTToolbox.xcodeproj/project.xcworkspace/xcuserdata/mganvi001c.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /VTToolbox/VTToolbox.xcodeproj/xcuserdata/mganvi001c.xcuserdatad/xcschemes/VTToolbox.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // h264v1 4 | // 5 | // Created by Ganvir, Manish on 3/31/15. 6 | // Copyright (c) 2015 Ganvir, Manish. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // h264v1 4 | // 5 | // Created by Ganvir, Manish on 3/31/15. 6 | // Copyright (c) 2015 Ganvir, Manish. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 28 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox/H264HwEncoderImpl.h: -------------------------------------------------------------------------------- 1 | // 2 | // H264HwEncoderImpl.h 3 | // h264v1 4 | // 5 | // Created by Ganvir, Manish on 3/31/15. 6 | // Copyright (c) 2015 Ganvir, Manish. All rights reserved. 7 | // 8 | 9 | #import 10 | @import AVFoundation; 11 | @protocol H264HwEncoderImplDelegate 12 | 13 | - (void)gotSpsPps:(NSData*)sps pps:(NSData*)pps; 14 | - (void)gotEncodedData:(NSData*)data isKeyFrame:(BOOL)isKeyFrame; 15 | 16 | @end 17 | @interface H264HwEncoderImpl : NSObject 18 | 19 | - (void) initWithConfiguration; 20 | - (void) start:(int)width height:(int)height; 21 | - (void) initEncode:(int)width height:(int)height; 22 | - (void) changeResolution:(int)width height:(int)height; 23 | - (void) encode:(CMSampleBufferRef )sampleBuffer; 24 | - (void) End; 25 | 26 | 27 | @property (weak, nonatomic) NSString *error; 28 | @property (weak, nonatomic) id delegate; 29 | 30 | @end 31 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox/H264HwEncoderImpl.m: -------------------------------------------------------------------------------- 1 | // 2 | // H264HwEncoderImpl.m 3 | // h264v1 4 | // 5 | // Created by Ganvir, Manish on 3/31/15. 6 | // Copyright (c) 2015 Ganvir, Manish. All rights reserved. 7 | // 8 | 9 | #import "H264HwEncoderImpl.h" 10 | #define YUV_FRAME_SIZE 2000 11 | #define FRAME_WIDTH 12 | #define NUMBEROFRAMES 300 13 | #define DURATION 12 14 | 15 | @import VideoToolbox; 16 | @import AVFoundation; 17 | 18 | @implementation H264HwEncoderImpl 19 | { 20 | NSString * yuvFile; 21 | VTCompressionSessionRef EncodingSession; 22 | dispatch_queue_t aQueue; 23 | CMFormatDescriptionRef format; 24 | CMSampleTimingInfo * timingInfo; 25 | BOOL initialized; 26 | int frameCount; 27 | NSData *sps; 28 | NSData *pps; 29 | } 30 | @synthesize error; 31 | 32 | - (void) initWithConfiguration 33 | { 34 | NSFileManager *fileManager = [NSFileManager defaultManager]; 35 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 36 | NSString *documentsDirectory = [paths objectAtIndex:0]; 37 | 38 | /*yuvFile = [documentsDirectory stringByAppendingPathComponent:@"test.i420"]; 39 | 40 | if ([fileManager fileExistsAtPath:yuvFile] == NO) { 41 | NSLog(@"H264: File does not exist"); 42 | return; 43 | }*/ 44 | 45 | EncodingSession = nil; 46 | initialized = true; 47 | aQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 48 | frameCount = 0; 49 | sps = NULL; 50 | pps = NULL; 51 | 52 | } 53 | 54 | void didCompressH264(void *outputCallbackRefCon, void *sourceFrameRefCon, OSStatus status, VTEncodeInfoFlags infoFlags, 55 | CMSampleBufferRef sampleBuffer ) 56 | { 57 | NSLog(@"didCompressH264 called with status %d infoFlags %d", (int)status, (int)infoFlags); 58 | if (status != 0) return; 59 | 60 | if (!CMSampleBufferDataIsReady(sampleBuffer)) 61 | { 62 | NSLog(@"didCompressH264 data is not ready "); 63 | return; 64 | } 65 | H264HwEncoderImpl* encoder = (__bridge H264HwEncoderImpl*)outputCallbackRefCon; 66 | 67 | // Check if we have got a key frame first 68 | bool keyframe = !CFDictionaryContainsKey( (CFArrayGetValueAtIndex(CMSampleBufferGetSampleAttachmentsArray(sampleBuffer, true), 0)), kCMSampleAttachmentKey_NotSync); 69 | 70 | if (keyframe) 71 | { 72 | CMFormatDescriptionRef format = CMSampleBufferGetFormatDescription(sampleBuffer); 73 | // CFDictionaryRef extensionDict = CMFormatDescriptionGetExtensions(format); 74 | // Get the extensions 75 | // From the extensions get the dictionary with key "SampleDescriptionExtensionAtoms" 76 | // From the dict, get the value for the key "avcC" 77 | 78 | size_t sparameterSetSize, sparameterSetCount; 79 | const uint8_t *sparameterSet; 80 | OSStatus statusCode = CMVideoFormatDescriptionGetH264ParameterSetAtIndex(format, 0, &sparameterSet, &sparameterSetSize, &sparameterSetCount, 0 ); 81 | if (statusCode == noErr) 82 | { 83 | // Found sps and now check for pps 84 | size_t pparameterSetSize, pparameterSetCount; 85 | const uint8_t *pparameterSet; 86 | OSStatus statusCode = CMVideoFormatDescriptionGetH264ParameterSetAtIndex(format, 1, &pparameterSet, &pparameterSetSize, &pparameterSetCount, 0 ); 87 | if (statusCode == noErr) 88 | { 89 | // Found pps 90 | encoder->sps = [NSData dataWithBytes:sparameterSet length:sparameterSetSize]; 91 | encoder->pps = [NSData dataWithBytes:pparameterSet length:pparameterSetSize]; 92 | if (encoder->_delegate) 93 | { 94 | [encoder->_delegate gotSpsPps:encoder->sps pps:encoder->pps]; 95 | } 96 | } 97 | } 98 | } 99 | 100 | CMBlockBufferRef dataBuffer = CMSampleBufferGetDataBuffer(sampleBuffer); 101 | size_t length, totalLength; 102 | char *dataPointer; 103 | OSStatus statusCodeRet = CMBlockBufferGetDataPointer(dataBuffer, 0, &length, &totalLength, &dataPointer); 104 | if (statusCodeRet == noErr) { 105 | 106 | size_t bufferOffset = 0; 107 | static const int AVCCHeaderLength = 4; 108 | while (bufferOffset < totalLength - AVCCHeaderLength) { 109 | 110 | // Read the NAL unit length 111 | uint32_t NALUnitLength = 0; 112 | memcpy(&NALUnitLength, dataPointer + bufferOffset, AVCCHeaderLength); 113 | 114 | // Convert the length value from Big-endian to Little-endian 115 | NALUnitLength = CFSwapInt32BigToHost(NALUnitLength); 116 | 117 | NSData* data = [[NSData alloc] initWithBytes:(dataPointer + bufferOffset + AVCCHeaderLength) length:NALUnitLength]; 118 | [encoder->_delegate gotEncodedData:data isKeyFrame:keyframe]; 119 | 120 | // Move to the next NAL unit in the block buffer 121 | bufferOffset += AVCCHeaderLength + NALUnitLength; 122 | } 123 | 124 | } 125 | 126 | } 127 | 128 | - (void) start:(int)width height:(int)height 129 | { 130 | int frameSize = (width * height * 1.5); 131 | 132 | if (!initialized) 133 | { 134 | NSLog(@"H264: Not initialized"); 135 | error = @"H264: Not initialized"; 136 | return; 137 | } 138 | dispatch_sync(aQueue, ^{ 139 | 140 | // For testing out the logic, lets read from a file and then send it to encoder to create h264 stream 141 | 142 | // Create the compression session 143 | OSStatus status = VTCompressionSessionCreate(NULL, width, height, kCMVideoCodecType_H264, NULL, NULL, NULL, didCompressH264, (__bridge void *)(self), &EncodingSession); 144 | NSLog(@"H264: VTCompressionSessionCreate %d", (int)status); 145 | 146 | if (status != 0) 147 | { 148 | NSLog(@"H264: Unable to create a H264 session"); 149 | error = @"H264: Unable to create a H264 session"; 150 | 151 | return ; 152 | 153 | } 154 | 155 | // Set the properties 156 | VTSessionSetProperty(EncodingSession, kVTCompressionPropertyKey_RealTime, kCFBooleanTrue); 157 | VTSessionSetProperty(EncodingSession, kVTCompressionPropertyKey_AllowFrameReordering, kCFBooleanFalse); 158 | VTSessionSetProperty(EncodingSession, kVTCompressionPropertyKey_MaxKeyFrameInterval, 240); 159 | 160 | VTSessionSetProperty(EncodingSession, kVTCompressionPropertyKey_ProfileLevel, kVTProfileLevel_H264_High_AutoLevel); 161 | 162 | 163 | // Tell the encoder to start encoding 164 | VTCompressionSessionPrepareToEncodeFrames(EncodingSession); 165 | 166 | // Start reading from the file and copy it to the buffer 167 | 168 | // Open the file using POSIX as this is anyway a test application 169 | int fd = open([yuvFile UTF8String], O_RDONLY); 170 | if (fd == -1) 171 | { 172 | NSLog(@"H264: Unable to open the file"); 173 | error = @"H264: Unable to open the file"; 174 | 175 | return ; 176 | } 177 | 178 | NSMutableData* theData = [[NSMutableData alloc] initWithLength:frameSize] ; 179 | NSUInteger actualBytes = frameSize; 180 | while (actualBytes > 0) 181 | { 182 | void* buffer = [theData mutableBytes]; 183 | NSUInteger bufferSize = [theData length]; 184 | 185 | actualBytes = read(fd, buffer, bufferSize); 186 | if (actualBytes < frameSize) 187 | [theData setLength:actualBytes]; 188 | 189 | frameCount++; 190 | // Create a CM Block buffer out of this data 191 | CMBlockBufferRef BlockBuffer = NULL; 192 | OSStatus status = CMBlockBufferCreateWithMemoryBlock(NULL, buffer, actualBytes,kCFAllocatorNull, NULL, 0, actualBytes, kCMBlockBufferAlwaysCopyDataFlag, &BlockBuffer); 193 | 194 | // Check for error 195 | if (status != noErr) 196 | { 197 | NSLog(@"H264: CMBlockBufferCreateWithMemoryBlock failed with %d", (int)status); 198 | error = @"H264: CMBlockBufferCreateWithMemoryBlock failed "; 199 | 200 | return ; 201 | } 202 | 203 | // Create a CM Sample Buffer 204 | CMSampleBufferRef sampleBuffer = NULL; 205 | CMFormatDescriptionRef formatDescription; 206 | CMFormatDescriptionCreate ( kCFAllocatorDefault, // Allocator 207 | kCMMediaType_Video, 208 | 'I420', 209 | NULL, 210 | &formatDescription ); 211 | CMSampleTimingInfo sampleTimingInfo = {CMTimeMake(1, 300)}; 212 | 213 | OSStatus statusCode = CMSampleBufferCreate(kCFAllocatorDefault, BlockBuffer, YES, NULL, NULL, formatDescription, 1, 1, &sampleTimingInfo, 0, NULL, &sampleBuffer); 214 | 215 | // Check for error 216 | if (statusCode != noErr) { 217 | NSLog(@"H264: CMSampleBufferCreate failed with %d", (int)statusCode); 218 | error = @"H264: CMSampleBufferCreate failed "; 219 | 220 | return; 221 | } 222 | CFRelease(BlockBuffer); 223 | BlockBuffer = NULL; 224 | 225 | // Get the CV Image buffer 226 | CVImageBufferRef imageBuffer = (CVImageBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer); 227 | 228 | // Create properties 229 | CMTime presentationTimeStamp = CMTimeMake(frameCount, 300); 230 | //CMTime duration = CMTimeMake(1, DURATION); 231 | VTEncodeInfoFlags flags; 232 | 233 | // Pass it to the encoder 234 | statusCode = VTCompressionSessionEncodeFrame(EncodingSession, 235 | imageBuffer, 236 | presentationTimeStamp, 237 | kCMTimeInvalid, 238 | NULL, NULL, &flags); 239 | // Check for error 240 | if (statusCode != noErr) { 241 | NSLog(@"H264: VTCompressionSessionEncodeFrame failed with %d", (int)statusCode); 242 | error = @"H264: VTCompressionSessionEncodeFrame failed "; 243 | 244 | // End the session 245 | VTCompressionSessionInvalidate(EncodingSession); 246 | CFRelease(EncodingSession); 247 | EncodingSession = NULL; 248 | error = NULL; 249 | return; 250 | } 251 | NSLog(@"H264: VTCompressionSessionEncodeFrame Success"); 252 | 253 | } 254 | 255 | // Mark the completion 256 | VTCompressionSessionCompleteFrames(EncodingSession, kCMTimeInvalid); 257 | 258 | // End the session 259 | VTCompressionSessionInvalidate(EncodingSession); 260 | CFRelease(EncodingSession); 261 | EncodingSession = NULL; 262 | error = NULL; 263 | 264 | close(fd); 265 | }); 266 | 267 | 268 | } 269 | - (void) initEncode:(int)width height:(int)height 270 | { 271 | dispatch_sync(aQueue, ^{ 272 | 273 | // For testing out the logic, lets read from a file and then send it to encoder to create h264 stream 274 | 275 | // Create the compression session 276 | OSStatus status = VTCompressionSessionCreate(NULL, width, height, kCMVideoCodecType_H264, NULL, NULL, NULL, didCompressH264, (__bridge void *)(self), &EncodingSession); 277 | NSLog(@"H264: VTCompressionSessionCreate %d", (int)status); 278 | 279 | if (status != 0) 280 | { 281 | NSLog(@"H264: Unable to create a H264 session"); 282 | error = @"H264: Unable to create a H264 session"; 283 | 284 | return ; 285 | 286 | } 287 | 288 | // Set the properties 289 | VTSessionSetProperty(EncodingSession, kVTCompressionPropertyKey_RealTime, kCFBooleanTrue); 290 | VTSessionSetProperty(EncodingSession, kVTCompressionPropertyKey_ProfileLevel, kVTProfileLevel_H264_Main_AutoLevel); 291 | 292 | 293 | // Tell the encoder to start encoding 294 | VTCompressionSessionPrepareToEncodeFrames(EncodingSession); 295 | }); 296 | } 297 | - (void) encode:(CMSampleBufferRef )sampleBuffer 298 | { 299 | dispatch_sync(aQueue, ^{ 300 | 301 | frameCount++; 302 | // Get the CV Image buffer 303 | CVImageBufferRef imageBuffer = (CVImageBufferRef)CMSampleBufferGetImageBuffer(sampleBuffer); 304 | 305 | // Create properties 306 | CMTime presentationTimeStamp = CMTimeMake(frameCount, 1000); 307 | //CMTime duration = CMTimeMake(1, DURATION); 308 | VTEncodeInfoFlags flags; 309 | 310 | // Pass it to the encoder 311 | OSStatus statusCode = VTCompressionSessionEncodeFrame(EncodingSession, 312 | imageBuffer, 313 | presentationTimeStamp, 314 | kCMTimeInvalid, 315 | NULL, NULL, &flags); 316 | // Check for error 317 | if (statusCode != noErr) { 318 | NSLog(@"H264: VTCompressionSessionEncodeFrame failed with %d", (int)statusCode); 319 | error = @"H264: VTCompressionSessionEncodeFrame failed "; 320 | 321 | // End the session 322 | VTCompressionSessionInvalidate(EncodingSession); 323 | CFRelease(EncodingSession); 324 | EncodingSession = NULL; 325 | error = NULL; 326 | return; 327 | } 328 | NSLog(@"H264: VTCompressionSessionEncodeFrame Success"); 329 | }); 330 | 331 | 332 | } 333 | - (void) changeResolution:(int)width height:(int)height 334 | { 335 | } 336 | 337 | 338 | - (void) End 339 | { 340 | // Mark the completion 341 | VTCompressionSessionCompleteFrames(EncodingSession, kCMTimeInvalid); 342 | 343 | // End the session 344 | VTCompressionSessionInvalidate(EncodingSession); 345 | CFRelease(EncodingSession); 346 | EncodingSession = NULL; 347 | error = NULL; 348 | 349 | } 350 | 351 | @end 352 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /VTToolbox/VTToolbox/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | manish.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UIFileSharingEnabled 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // h264v1 4 | // 5 | // Created by Ganvir, Manish on 3/31/15. 6 | // Copyright (c) 2015 Ganvir, Manish. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "H264HwEncoderImpl.h" 11 | @import AVFoundation; 12 | 13 | @interface ViewController : UIViewController 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // h264v1 4 | // 5 | // Created by Ganvir, Manish on 3/31/15. 6 | // Copyright (c) 2015 Ganvir, Manish. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "H264HwEncoderImpl.h" 11 | 12 | @interface ViewController () 13 | { 14 | H264HwEncoderImpl *h264Encoder; 15 | AVCaptureSession *captureSession; 16 | bool startCalled; 17 | AVCaptureVideoPreviewLayer *previewLayer; 18 | NSString *h264File; 19 | int fd; 20 | NSFileHandle *fileHandle; 21 | AVCaptureConnection* connection; 22 | } 23 | @property (weak, nonatomic) IBOutlet UIButton *StartStopButton; 24 | 25 | @end 26 | 27 | @implementation ViewController 28 | 29 | - (void)viewDidLoad { 30 | [super viewDidLoad]; 31 | // Do any additional setup after loading the view, typically from a nib. 32 | h264Encoder = [H264HwEncoderImpl alloc]; 33 | [h264Encoder initWithConfiguration]; 34 | startCalled = true; 35 | 36 | 37 | 38 | 39 | } 40 | 41 | - (void)didReceiveMemoryWarning { 42 | [super didReceiveMemoryWarning]; 43 | // Dispose of any resources that can be recreated. 44 | } 45 | 46 | // Called when start/stop button is pressed 47 | - (IBAction)OnStartStop:(id)sender { 48 | 49 | if (startCalled) 50 | { 51 | [self startCamera]; 52 | startCalled = false; 53 | [_StartStopButton setTitle:@"Stop" forState:UIControlStateNormal]; 54 | } 55 | else 56 | { 57 | [_StartStopButton setTitle:@"Start" forState:UIControlStateNormal]; 58 | startCalled = true; 59 | [self stopCamera]; 60 | [h264Encoder End]; 61 | } 62 | 63 | } 64 | 65 | - (void) startCamera 66 | { 67 | // make input device 68 | 69 | NSError *deviceError; 70 | 71 | AVCaptureDevice *cameraDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 72 | 73 | AVCaptureDeviceInput *inputDevice = [AVCaptureDeviceInput deviceInputWithDevice:cameraDevice error:&deviceError]; 74 | 75 | // make output device 76 | 77 | AVCaptureVideoDataOutput *outputDevice = [[AVCaptureVideoDataOutput alloc] init]; 78 | 79 | NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey; 80 | 81 | NSNumber* val = [NSNumber 82 | numberWithUnsignedInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange]; 83 | NSDictionary* videoSettings = 84 | [NSDictionary dictionaryWithObject:val forKey:key]; 85 | outputDevice.videoSettings = videoSettings; 86 | 87 | [outputDevice setSampleBufferDelegate:self queue:dispatch_get_main_queue()]; 88 | 89 | // initialize capture session 90 | 91 | captureSession = [[AVCaptureSession alloc] init]; 92 | 93 | [captureSession addInput:inputDevice]; 94 | [captureSession addOutput:outputDevice]; 95 | 96 | // begin configuration for the AVCaptureSession 97 | [captureSession beginConfiguration]; 98 | 99 | // picture resolution 100 | [captureSession setSessionPreset:[NSString stringWithString:AVCaptureSessionPreset640x480]]; 101 | 102 | connection = [outputDevice connectionWithMediaType:AVMediaTypeVideo]; 103 | [self setRelativeVideoOrientation]; 104 | 105 | NSNotificationCenter* notify = [NSNotificationCenter defaultCenter]; 106 | 107 | [notify addObserver:self 108 | selector:@selector(statusBarOrientationDidChange:) 109 | name:@"StatusBarOrientationDidChange" 110 | object:nil]; 111 | 112 | 113 | [captureSession commitConfiguration]; 114 | 115 | // make preview layer and add so that camera's view is displayed on screen 116 | 117 | previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:captureSession]; 118 | [previewLayer setVideoGravity:AVLayerVideoGravityResizeAspect]; 119 | 120 | previewLayer.frame = self.view.bounds; 121 | [self.view.layer addSublayer:previewLayer]; 122 | 123 | // go! 124 | 125 | [captureSession startRunning]; 126 | 127 | NSFileManager *fileManager = [NSFileManager defaultManager]; 128 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 129 | NSString *documentsDirectory = [paths objectAtIndex:0]; 130 | 131 | h264File = [documentsDirectory stringByAppendingPathComponent:@"test.h264"]; 132 | [fileManager removeItemAtPath:h264File error:nil]; 133 | [fileManager createFileAtPath:h264File contents:nil attributes:nil]; 134 | 135 | // Open the file using POSIX as this is anyway a test application 136 | //fd = open([h264File UTF8String], O_RDWR); 137 | fileHandle = [NSFileHandle fileHandleForWritingAtPath:h264File]; 138 | 139 | [h264Encoder initEncode:480 height:640]; 140 | h264Encoder.delegate = self; 141 | 142 | 143 | 144 | } 145 | - (void)statusBarOrientationDidChange:(NSNotification*)notification { 146 | [self setRelativeVideoOrientation]; 147 | } 148 | 149 | - (void)setRelativeVideoOrientation { 150 | switch ([[UIDevice currentDevice] orientation]) { 151 | case UIInterfaceOrientationPortrait: 152 | #if defined(__IPHONE_8_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_8_0 153 | case UIInterfaceOrientationUnknown: 154 | #endif 155 | connection.videoOrientation = AVCaptureVideoOrientationPortrait; 156 | 157 | break; 158 | case UIInterfaceOrientationPortraitUpsideDown: 159 | connection.videoOrientation = 160 | AVCaptureVideoOrientationPortraitUpsideDown; 161 | break; 162 | case UIInterfaceOrientationLandscapeLeft: 163 | connection.videoOrientation = AVCaptureVideoOrientationLandscapeLeft; 164 | break; 165 | case UIInterfaceOrientationLandscapeRight: 166 | connection.videoOrientation = AVCaptureVideoOrientationLandscapeRight; 167 | break; 168 | default: 169 | break; 170 | } 171 | } 172 | - (void) stopCamera 173 | { 174 | [captureSession stopRunning]; 175 | [previewLayer removeFromSuperlayer]; 176 | //close(fd); 177 | [fileHandle closeFile]; 178 | fileHandle = NULL; 179 | } 180 | -(void) captureOutput:(AVCaptureOutput*)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection*)connection 181 | 182 | { 183 | //CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer( sampleBuffer ); 184 | 185 | //CGSize imageSize = CVImageBufferGetEncodedSize( imageBuffer ); 186 | 187 | // also in the 'mediaSpecific' dict of the sampleBuffer 188 | 189 | NSLog( @"frame captured at "); 190 | [h264Encoder encode:sampleBuffer]; 191 | 192 | } 193 | 194 | #pragma mark - H264HwEncoderImplDelegate delegare 195 | 196 | - (void)gotSpsPps:(NSData*)sps pps:(NSData*)pps 197 | { 198 | NSLog(@"gotSpsPps %d %d", (int)[sps length], (int)[pps length]); 199 | //[sps writeToFile:h264File atomically:YES]; 200 | //[pps writeToFile:h264File atomically:YES]; 201 | // write(fd, [sps bytes], [sps length]); 202 | //write(fd, [pps bytes], [pps length]); 203 | const char bytes[] = "\x00\x00\x00\x01"; 204 | size_t length = (sizeof bytes) - 1; //string literals have implicit trailing '\0' 205 | NSData *ByteHeader = [NSData dataWithBytes:bytes length:length]; 206 | [fileHandle writeData:ByteHeader]; 207 | [fileHandle writeData:sps]; 208 | [fileHandle writeData:ByteHeader]; 209 | [fileHandle writeData:pps]; 210 | 211 | } 212 | - (void)gotEncodedData:(NSData*)data isKeyFrame:(BOOL)isKeyFrame 213 | { 214 | NSLog(@"gotEncodedData %d", (int)[data length]); 215 | static int framecount = 1; 216 | 217 | // [data writeToFile:h264File atomically:YES]; 218 | //write(fd, [data bytes], [data length]); 219 | if (fileHandle != NULL) 220 | { 221 | const char bytes[] = "\x00\x00\x00\x01"; 222 | size_t length = (sizeof bytes) - 1; //string literals have implicit trailing '\0' 223 | NSData *ByteHeader = [NSData dataWithBytes:bytes length:length]; 224 | 225 | 226 | /*NSData *UnitHeader; 227 | if(isKeyFrame) 228 | { 229 | char header[2]; 230 | header[0] = '\x65'; 231 | UnitHeader = [NSData dataWithBytes:header length:1]; 232 | framecount = 1; 233 | } 234 | else 235 | { 236 | char header[4]; 237 | header[0] = '\x41'; 238 | //header[1] = '\x9A'; 239 | //header[2] = framecount; 240 | UnitHeader = [NSData dataWithBytes:header length:1]; 241 | framecount++; 242 | }*/ 243 | [fileHandle writeData:ByteHeader]; 244 | //[fileHandle writeData:UnitHeader]; 245 | [fileHandle writeData:data]; 246 | } 247 | } 248 | 249 | 250 | @end 251 | -------------------------------------------------------------------------------- /VTToolbox/VTToolbox/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // h264v1 4 | // 5 | // Created by Ganvir, Manish on 3/31/15. 6 | // Copyright (c) 2015 Ganvir, Manish. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /VTToolbox/VTToolboxTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | manish.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /VTToolbox/VTToolboxTests/VTToolboxTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // VTToolboxTests.m 3 | // VTToolboxTests 4 | // 5 | // Created by Ganvir, Manish (Contractor) on 4/1/15. 6 | // Copyright (c) 2015 Ganvir, Manish. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface VTToolboxTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation VTToolboxTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------