diff --git a/.gitignore b/.gitignore index 382f8343..3a6477f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,25 @@ +# infer +infer-out/ -#CocoaPods +# Xcode +.DS_Store +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +*.xcworkspace +!default.xcworkspace +xcuserdata +profile +*.moved-aside +DerivedData +.idea/ + +# CocoaPods Pods/ Podfile.lock \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 1dd25288..fdd2dc20 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: objective-c osx_image: xcode7 -xcode_workspace: LFLiveKit.xcworkspace +xcode_project: LFLiveKit.xcodeproj xcode_scheme: LFLiveKit script: -- xctool -workspace LFLiveKit.xcworkspace -scheme 'LFLiveKit' -configuration Release -sdk iphonesimulator -arch i386 build \ No newline at end of file +- xctool -project LFLiveKit.xcodeproj -scheme 'LFLiveKit' -configuration Release -sdk iphonesimulator -arch i386 build \ No newline at end of file diff --git a/LFLiveKit.podspec b/LFLiveKit.podspec index 08a38377..553b6a30 100644 --- a/LFLiveKit.podspec +++ b/LFLiveKit.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = "LFLiveKit" - s.version = "1.9.0" + s.version = "2.0" s.summary = "LaiFeng ios Live. LFLiveKit." s.homepage = "https://github.com/chenliming777" s.license = { :type => "MIT", :file => "LICENSE" } @@ -10,15 +10,13 @@ Pod::Spec.new do |s| s.platform = :ios, "7.0" s.ios.deployment_target = "7.0" s.source = { :git => "https://github.com/LaiFengiOS/LFLiveKit.git", :tag => "#{s.version}" } - s.source_files = "LFLiveKit/**/*.{h,m,mm,cpp}" - s.public_header_files = "LFLiveKit/**/*.h" + s.source_files = "LFLiveKit/**/*.{h,m,mm,cpp,c}" + #s.public_header_files = "LFLiveKit/**/*.h" + s.public_header_files = ['LFLiveKit/*.h', 'LFLiveKit/objects/*.h', 'LFLiveKit/configuration/*.h'] s.frameworks = "VideoToolbox", "AudioToolbox","AVFoundation","Foundation","UIKit" s.libraries = "c++", "z" s.requires_arc = true - s.dependency 'LMGPUImage', '~> 0.1.9' - s.dependency "YYDispatchQueuePool" - s.dependency "pili-librtmp", '1.0.3' end diff --git a/LFLiveKit.xcodeproj/project.pbxproj b/LFLiveKit.xcodeproj/project.pbxproj index d4e0c4b7..a8043724 100644 --- a/LFLiveKit.xcodeproj/project.pbxproj +++ b/LFLiveKit.xcodeproj/project.pbxproj @@ -30,15 +30,15 @@ 84001FE21D0016380026C63F /* LFGPUImageEmptyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FB91D0016380026C63F /* LFGPUImageEmptyFilter.m */; }; 84001FE31D0016380026C63F /* LFLiveSession.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FBA1D0016380026C63F /* LFLiveSession.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84001FE41D0016380026C63F /* LFLiveSession.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FBB1D0016380026C63F /* LFLiveSession.m */; }; - 84001FE51D0016380026C63F /* LFAudioFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FBD1D0016380026C63F /* LFAudioFrame.h */; }; + 84001FE51D0016380026C63F /* LFAudioFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FBD1D0016380026C63F /* LFAudioFrame.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84001FE61D0016380026C63F /* LFAudioFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FBE1D0016380026C63F /* LFAudioFrame.m */; }; - 84001FE71D0016380026C63F /* LFFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FBF1D0016380026C63F /* LFFrame.h */; }; + 84001FE71D0016380026C63F /* LFFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FBF1D0016380026C63F /* LFFrame.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84001FE81D0016380026C63F /* LFFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FC01D0016380026C63F /* LFFrame.m */; }; 84001FE91D0016380026C63F /* LFLiveDebug.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FC11D0016380026C63F /* LFLiveDebug.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84001FEA1D0016380026C63F /* LFLiveDebug.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FC21D0016380026C63F /* LFLiveDebug.m */; }; 84001FEB1D0016380026C63F /* LFLiveStreamInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FC31D0016380026C63F /* LFLiveStreamInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84001FEC1D0016380026C63F /* LFLiveStreamInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FC41D0016380026C63F /* LFLiveStreamInfo.m */; }; - 84001FED1D0016380026C63F /* LFVideoFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FC51D0016380026C63F /* LFVideoFrame.h */; }; + 84001FED1D0016380026C63F /* LFVideoFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = 84001FC51D0016380026C63F /* LFVideoFrame.h */; settings = {ATTRIBUTES = (Public, ); }; }; 84001FEE1D0016380026C63F /* LFVideoFrame.m in Sources */ = {isa = PBXBuildFile; fileRef = 84001FC61D0016380026C63F /* LFVideoFrame.m */; }; 84001FF71D0017590026C63F /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84001FF61D0017590026C63F /* AVFoundation.framework */; }; 84001FF91D00175D0026C63F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84001FF81D00175D0026C63F /* Foundation.framework */; }; @@ -46,7 +46,368 @@ 84001FFD1D0017680026C63F /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84001FFC1D0017680026C63F /* AudioToolbox.framework */; }; 84001FFF1D00176C0026C63F /* VideoToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84001FFE1D00176C0026C63F /* VideoToolbox.framework */; }; 840020011D0017850026C63F /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 840020001D0017850026C63F /* libz.tbd */; }; - AD7F89B4621A7EFEBEA72D49 /* libPods-LFLiveKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B8CB02D2A92EA1F5A262F154 /* libPods-LFLiveKit.a */; }; + 8437239A1D4F260A002B398B /* GLProgram.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437222D1D4F260A002B398B /* GLProgram.h */; }; + 8437239B1D4F260A002B398B /* GLProgram.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437222E1D4F260A002B398B /* GLProgram.m */; }; + 8437239C1D4F260A002B398B /* GPUImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437222F1D4F260A002B398B /* GPUImage.h */; }; + 8437239D1D4F260A002B398B /* GPUImage3x3ConvolutionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722301D4F260A002B398B /* GPUImage3x3ConvolutionFilter.h */; }; + 8437239E1D4F260A002B398B /* GPUImage3x3ConvolutionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722311D4F260A002B398B /* GPUImage3x3ConvolutionFilter.m */; }; + 8437239F1D4F260A002B398B /* GPUImage3x3TextureSamplingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722321D4F260A002B398B /* GPUImage3x3TextureSamplingFilter.h */; }; + 843723A01D4F260A002B398B /* GPUImage3x3TextureSamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722331D4F260A002B398B /* GPUImage3x3TextureSamplingFilter.m */; }; + 843723A11D4F260A002B398B /* GPUImageAdaptiveThresholdFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722341D4F260A002B398B /* GPUImageAdaptiveThresholdFilter.h */; }; + 843723A21D4F260A002B398B /* GPUImageAdaptiveThresholdFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722351D4F260A002B398B /* GPUImageAdaptiveThresholdFilter.m */; }; + 843723A31D4F260A002B398B /* GPUImageAddBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722361D4F260A002B398B /* GPUImageAddBlendFilter.h */; }; + 843723A41D4F260A002B398B /* GPUImageAddBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722371D4F260A002B398B /* GPUImageAddBlendFilter.m */; }; + 843723A51D4F260A002B398B /* GPUImageAlphaBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722381D4F260A002B398B /* GPUImageAlphaBlendFilter.h */; }; + 843723A61D4F260A002B398B /* GPUImageAlphaBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722391D4F260A002B398B /* GPUImageAlphaBlendFilter.m */; }; + 843723A71D4F260A002B398B /* GPUImageAmatorkaFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437223A1D4F260A002B398B /* GPUImageAmatorkaFilter.h */; }; + 843723A81D4F260A002B398B /* GPUImageAmatorkaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437223B1D4F260A002B398B /* GPUImageAmatorkaFilter.m */; }; + 843723A91D4F260A002B398B /* GPUImageAverageColor.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437223C1D4F260A002B398B /* GPUImageAverageColor.h */; }; + 843723AA1D4F260A002B398B /* GPUImageAverageColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437223D1D4F260A002B398B /* GPUImageAverageColor.m */; }; + 843723AB1D4F260A002B398B /* GPUImageAverageLuminanceThresholdFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437223E1D4F260A002B398B /* GPUImageAverageLuminanceThresholdFilter.h */; }; + 843723AC1D4F260A002B398B /* GPUImageAverageLuminanceThresholdFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437223F1D4F260A002B398B /* GPUImageAverageLuminanceThresholdFilter.m */; }; + 843723AD1D4F260A002B398B /* GPUImageBilateralFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722401D4F260A002B398B /* GPUImageBilateralFilter.h */; }; + 843723AE1D4F260A002B398B /* GPUImageBilateralFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722411D4F260A002B398B /* GPUImageBilateralFilter.m */; }; + 843723AF1D4F260A002B398B /* GPUImageBoxBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722421D4F260A002B398B /* GPUImageBoxBlurFilter.h */; }; + 843723B01D4F260A002B398B /* GPUImageBoxBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722431D4F260A002B398B /* GPUImageBoxBlurFilter.m */; }; + 843723B11D4F260A002B398B /* GPUImageBrightnessFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722441D4F260A002B398B /* GPUImageBrightnessFilter.h */; }; + 843723B21D4F260A002B398B /* GPUImageBrightnessFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722451D4F260A002B398B /* GPUImageBrightnessFilter.m */; }; + 843723B31D4F260A002B398B /* GPUImageBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722461D4F260A002B398B /* GPUImageBuffer.h */; }; + 843723B41D4F260A002B398B /* GPUImageBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722471D4F260A002B398B /* GPUImageBuffer.m */; }; + 843723B51D4F260A002B398B /* GPUImageBulgeDistortionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722481D4F260A002B398B /* GPUImageBulgeDistortionFilter.h */; }; + 843723B61D4F260A002B398B /* GPUImageBulgeDistortionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722491D4F260A002B398B /* GPUImageBulgeDistortionFilter.m */; }; + 843723B71D4F260A002B398B /* GPUImageCannyEdgeDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437224A1D4F260A002B398B /* GPUImageCannyEdgeDetectionFilter.h */; }; + 843723B81D4F260A002B398B /* GPUImageCannyEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437224B1D4F260A002B398B /* GPUImageCannyEdgeDetectionFilter.m */; }; + 843723B91D4F260A002B398B /* GPUImageCGAColorspaceFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437224C1D4F260A002B398B /* GPUImageCGAColorspaceFilter.h */; }; + 843723BA1D4F260A002B398B /* GPUImageCGAColorspaceFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437224D1D4F260A002B398B /* GPUImageCGAColorspaceFilter.m */; }; + 843723BB1D4F260A002B398B /* GPUImageChromaKeyBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437224E1D4F260A002B398B /* GPUImageChromaKeyBlendFilter.h */; }; + 843723BC1D4F260A002B398B /* GPUImageChromaKeyBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437224F1D4F260A002B398B /* GPUImageChromaKeyBlendFilter.m */; }; + 843723BD1D4F260A002B398B /* GPUImageChromaKeyFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722501D4F260A002B398B /* GPUImageChromaKeyFilter.h */; }; + 843723BE1D4F260A002B398B /* GPUImageChromaKeyFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722511D4F260A002B398B /* GPUImageChromaKeyFilter.m */; }; + 843723BF1D4F260A002B398B /* GPUImageClosingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722521D4F260A002B398B /* GPUImageClosingFilter.h */; }; + 843723C01D4F260A002B398B /* GPUImageClosingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722531D4F260A002B398B /* GPUImageClosingFilter.m */; }; + 843723C11D4F260A002B398B /* GPUImageColorBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722541D4F260A002B398B /* GPUImageColorBlendFilter.h */; }; + 843723C21D4F260A002B398B /* GPUImageColorBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722551D4F260A002B398B /* GPUImageColorBlendFilter.m */; }; + 843723C31D4F260A002B398B /* GPUImageColorBurnBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722561D4F260A002B398B /* GPUImageColorBurnBlendFilter.h */; }; + 843723C41D4F260A002B398B /* GPUImageColorBurnBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722571D4F260A002B398B /* GPUImageColorBurnBlendFilter.m */; }; + 843723C51D4F260A002B398B /* GPUImageColorConversion.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722581D4F260A002B398B /* GPUImageColorConversion.h */; }; + 843723C61D4F260A002B398B /* GPUImageColorConversion.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722591D4F260A002B398B /* GPUImageColorConversion.m */; }; + 843723C71D4F260A002B398B /* GPUImageColorDodgeBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437225A1D4F260A002B398B /* GPUImageColorDodgeBlendFilter.h */; }; + 843723C81D4F260A002B398B /* GPUImageColorDodgeBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437225B1D4F260A002B398B /* GPUImageColorDodgeBlendFilter.m */; }; + 843723C91D4F260A002B398B /* GPUImageColorInvertFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437225C1D4F260A002B398B /* GPUImageColorInvertFilter.h */; }; + 843723CA1D4F260A002B398B /* GPUImageColorInvertFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437225D1D4F260A002B398B /* GPUImageColorInvertFilter.m */; }; + 843723CB1D4F260A002B398B /* GPUImageColorLocalBinaryPatternFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437225E1D4F260A002B398B /* GPUImageColorLocalBinaryPatternFilter.h */; }; + 843723CC1D4F260A002B398B /* GPUImageColorLocalBinaryPatternFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437225F1D4F260A002B398B /* GPUImageColorLocalBinaryPatternFilter.m */; }; + 843723CD1D4F260A002B398B /* GPUImageColorMatrixFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722601D4F260A002B398B /* GPUImageColorMatrixFilter.h */; }; + 843723CE1D4F260A002B398B /* GPUImageColorMatrixFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722611D4F260A002B398B /* GPUImageColorMatrixFilter.m */; }; + 843723CF1D4F260A002B398B /* GPUImageColorPackingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722621D4F260A002B398B /* GPUImageColorPackingFilter.h */; }; + 843723D01D4F260A002B398B /* GPUImageColorPackingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722631D4F260A002B398B /* GPUImageColorPackingFilter.m */; }; + 843723D11D4F260A002B398B /* GPUImageColourFASTFeatureDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722641D4F260A002B398B /* GPUImageColourFASTFeatureDetector.h */; }; + 843723D21D4F260A002B398B /* GPUImageColourFASTFeatureDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722651D4F260A002B398B /* GPUImageColourFASTFeatureDetector.m */; }; + 843723D31D4F260A002B398B /* GPUImageColourFASTSamplingOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722661D4F260A002B398B /* GPUImageColourFASTSamplingOperation.h */; }; + 843723D41D4F260A002B398B /* GPUImageColourFASTSamplingOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722671D4F260A002B398B /* GPUImageColourFASTSamplingOperation.m */; }; + 843723D51D4F260A002B398B /* GPUImageContrastFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722681D4F260A002B398B /* GPUImageContrastFilter.h */; }; + 843723D61D4F260A002B398B /* GPUImageContrastFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722691D4F260A002B398B /* GPUImageContrastFilter.m */; }; + 843723D71D4F260A002B398B /* GPUImageCropFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437226A1D4F260A002B398B /* GPUImageCropFilter.h */; }; + 843723D81D4F260A002B398B /* GPUImageCropFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437226B1D4F260A002B398B /* GPUImageCropFilter.m */; }; + 843723D91D4F260A002B398B /* GPUImageCrosshairGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437226C1D4F260A002B398B /* GPUImageCrosshairGenerator.h */; }; + 843723DA1D4F260A002B398B /* GPUImageCrosshairGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437226D1D4F260A002B398B /* GPUImageCrosshairGenerator.m */; }; + 843723DB1D4F260A002B398B /* GPUImageCrosshatchFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437226E1D4F260A002B398B /* GPUImageCrosshatchFilter.h */; }; + 843723DC1D4F260A002B398B /* GPUImageCrosshatchFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437226F1D4F260A002B398B /* GPUImageCrosshatchFilter.m */; }; + 843723DD1D4F260A002B398B /* GPUImageDarkenBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722701D4F260A002B398B /* GPUImageDarkenBlendFilter.h */; }; + 843723DE1D4F260A002B398B /* GPUImageDarkenBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722711D4F260A002B398B /* GPUImageDarkenBlendFilter.m */; }; + 843723DF1D4F260A002B398B /* GPUImageDifferenceBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722721D4F260A002B398B /* GPUImageDifferenceBlendFilter.h */; }; + 843723E01D4F260A002B398B /* GPUImageDifferenceBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722731D4F260A002B398B /* GPUImageDifferenceBlendFilter.m */; }; + 843723E11D4F260A002B398B /* GPUImageDilationFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722741D4F260A002B398B /* GPUImageDilationFilter.h */; }; + 843723E21D4F260A002B398B /* GPUImageDilationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722751D4F260A002B398B /* GPUImageDilationFilter.m */; }; + 843723E31D4F260A002B398B /* GPUImageDirectionalNonMaximumSuppressionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722761D4F260A002B398B /* GPUImageDirectionalNonMaximumSuppressionFilter.h */; }; + 843723E41D4F260A002B398B /* GPUImageDirectionalNonMaximumSuppressionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722771D4F260A002B398B /* GPUImageDirectionalNonMaximumSuppressionFilter.m */; }; + 843723E51D4F260A002B398B /* GPUImageDirectionalSobelEdgeDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722781D4F260A002B398B /* GPUImageDirectionalSobelEdgeDetectionFilter.h */; }; + 843723E61D4F260A002B398B /* GPUImageDirectionalSobelEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722791D4F260A002B398B /* GPUImageDirectionalSobelEdgeDetectionFilter.m */; }; + 843723E71D4F260A002B398B /* GPUImageDissolveBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437227A1D4F260A002B398B /* GPUImageDissolveBlendFilter.h */; }; + 843723E81D4F260A002B398B /* GPUImageDissolveBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437227B1D4F260A002B398B /* GPUImageDissolveBlendFilter.m */; }; + 843723E91D4F260A002B398B /* GPUImageDivideBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437227C1D4F260A002B398B /* GPUImageDivideBlendFilter.h */; }; + 843723EA1D4F260A002B398B /* GPUImageDivideBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437227D1D4F260A002B398B /* GPUImageDivideBlendFilter.m */; }; + 843723EB1D4F260A002B398B /* GPUImageEmbossFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437227E1D4F260A002B398B /* GPUImageEmbossFilter.h */; }; + 843723EC1D4F260A002B398B /* GPUImageEmbossFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437227F1D4F260A002B398B /* GPUImageEmbossFilter.m */; }; + 843723ED1D4F260A002B398B /* GPUImageErosionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722801D4F260A002B398B /* GPUImageErosionFilter.h */; }; + 843723EE1D4F260A002B398B /* GPUImageErosionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722811D4F260A002B398B /* GPUImageErosionFilter.m */; }; + 843723EF1D4F260A002B398B /* GPUImageExclusionBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722821D4F260A002B398B /* GPUImageExclusionBlendFilter.h */; }; + 843723F01D4F260A002B398B /* GPUImageExclusionBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722831D4F260A002B398B /* GPUImageExclusionBlendFilter.m */; }; + 843723F11D4F260A002B398B /* GPUImageExposureFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722841D4F260A002B398B /* GPUImageExposureFilter.h */; }; + 843723F21D4F260A002B398B /* GPUImageExposureFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722851D4F260A002B398B /* GPUImageExposureFilter.m */; }; + 843723F31D4F260A002B398B /* GPUImageFalseColorFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722861D4F260A002B398B /* GPUImageFalseColorFilter.h */; }; + 843723F41D4F260A002B398B /* GPUImageFalseColorFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722871D4F260A002B398B /* GPUImageFalseColorFilter.m */; }; + 843723F51D4F260A002B398B /* GPUImageFASTCornerDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722881D4F260A002B398B /* GPUImageFASTCornerDetectionFilter.h */; }; + 843723F61D4F260A002B398B /* GPUImageFASTCornerDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722891D4F260A002B398B /* GPUImageFASTCornerDetectionFilter.m */; }; + 843723F71D4F260A002B398B /* GPUImageFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437228A1D4F260A002B398B /* GPUImageFilter.h */; }; + 843723F81D4F260A002B398B /* GPUImageFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437228B1D4F260A002B398B /* GPUImageFilter.m */; }; + 843723F91D4F260A002B398B /* GPUImageFilterGroup.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437228C1D4F260A002B398B /* GPUImageFilterGroup.h */; }; + 843723FA1D4F260A002B398B /* GPUImageFilterGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437228D1D4F260A002B398B /* GPUImageFilterGroup.m */; }; + 843723FB1D4F260A002B398B /* GPUImageFilterPipeline.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437228E1D4F260A002B398B /* GPUImageFilterPipeline.h */; }; + 843723FC1D4F260A002B398B /* GPUImageFilterPipeline.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437228F1D4F260A002B398B /* GPUImageFilterPipeline.m */; }; + 843723FD1D4F260A002B398B /* GPUImageFourInputFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722901D4F260A002B398B /* GPUImageFourInputFilter.h */; }; + 843723FE1D4F260A002B398B /* GPUImageFourInputFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722911D4F260A002B398B /* GPUImageFourInputFilter.m */; }; + 843723FF1D4F260A002B398B /* GPUImageFramebuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722921D4F260A002B398B /* GPUImageFramebuffer.h */; }; + 843724001D4F260A002B398B /* GPUImageFramebuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722931D4F260A002B398B /* GPUImageFramebuffer.m */; }; + 843724011D4F260A002B398B /* GPUImageFramebufferCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722941D4F260A002B398B /* GPUImageFramebufferCache.h */; }; + 843724021D4F260A002B398B /* GPUImageFramebufferCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722951D4F260A002B398B /* GPUImageFramebufferCache.m */; }; + 843724031D4F260A002B398B /* GPUImageGammaFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722961D4F260A002B398B /* GPUImageGammaFilter.h */; }; + 843724041D4F260A002B398B /* GPUImageGammaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722971D4F260A002B398B /* GPUImageGammaFilter.m */; }; + 843724051D4F260A002B398B /* GPUImageGaussianBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722981D4F260A002B398B /* GPUImageGaussianBlurFilter.h */; }; + 843724061D4F260A002B398B /* GPUImageGaussianBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722991D4F260A002B398B /* GPUImageGaussianBlurFilter.m */; }; + 843724071D4F260A002B398B /* GPUImageGaussianBlurPositionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437229A1D4F260A002B398B /* GPUImageGaussianBlurPositionFilter.h */; }; + 843724081D4F260A002B398B /* GPUImageGaussianBlurPositionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437229B1D4F260A002B398B /* GPUImageGaussianBlurPositionFilter.m */; }; + 843724091D4F260A002B398B /* GPUImageGaussianSelectiveBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437229C1D4F260A002B398B /* GPUImageGaussianSelectiveBlurFilter.h */; }; + 8437240A1D4F260A002B398B /* GPUImageGaussianSelectiveBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437229D1D4F260A002B398B /* GPUImageGaussianSelectiveBlurFilter.m */; }; + 8437240B1D4F260A002B398B /* GPUImageGlassSphereFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437229E1D4F260A002B398B /* GPUImageGlassSphereFilter.h */; }; + 8437240C1D4F260A002B398B /* GPUImageGlassSphereFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437229F1D4F260A002B398B /* GPUImageGlassSphereFilter.m */; }; + 8437240D1D4F260A002B398B /* GPUImageGrayscaleFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722A01D4F260A002B398B /* GPUImageGrayscaleFilter.h */; }; + 8437240E1D4F260A002B398B /* GPUImageGrayscaleFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722A11D4F260A002B398B /* GPUImageGrayscaleFilter.m */; }; + 8437240F1D4F260A002B398B /* GPUImageHalftoneFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722A21D4F260A002B398B /* GPUImageHalftoneFilter.h */; }; + 843724101D4F260A002B398B /* GPUImageHalftoneFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722A31D4F260A002B398B /* GPUImageHalftoneFilter.m */; }; + 843724111D4F260A002B398B /* GPUImageHardLightBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722A41D4F260A002B398B /* GPUImageHardLightBlendFilter.h */; }; + 843724121D4F260A002B398B /* GPUImageHardLightBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722A51D4F260A002B398B /* GPUImageHardLightBlendFilter.m */; }; + 843724131D4F260A002B398B /* GPUImageHarrisCornerDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722A61D4F260A002B398B /* GPUImageHarrisCornerDetectionFilter.h */; }; + 843724141D4F260A002B398B /* GPUImageHarrisCornerDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722A71D4F260A002B398B /* GPUImageHarrisCornerDetectionFilter.m */; }; + 843724151D4F260A002B398B /* GPUImageHazeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722A81D4F260A002B398B /* GPUImageHazeFilter.h */; }; + 843724161D4F260A002B398B /* GPUImageHazeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722A91D4F260A002B398B /* GPUImageHazeFilter.m */; }; + 843724171D4F260A002B398B /* GPUImageHighlightShadowFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722AA1D4F260A002B398B /* GPUImageHighlightShadowFilter.h */; }; + 843724181D4F260A002B398B /* GPUImageHighlightShadowFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722AB1D4F260A002B398B /* GPUImageHighlightShadowFilter.m */; }; + 843724191D4F260A002B398B /* GPUImageHighlightShadowTintFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722AC1D4F260A002B398B /* GPUImageHighlightShadowTintFilter.h */; }; + 8437241A1D4F260A002B398B /* GPUImageHighlightShadowTintFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722AD1D4F260A002B398B /* GPUImageHighlightShadowTintFilter.m */; }; + 8437241B1D4F260A002B398B /* GPUImageHighPassFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722AE1D4F260A002B398B /* GPUImageHighPassFilter.h */; }; + 8437241C1D4F260A002B398B /* GPUImageHighPassFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722AF1D4F260A002B398B /* GPUImageHighPassFilter.m */; }; + 8437241D1D4F260A002B398B /* GPUImageHistogramEqualizationFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722B01D4F260A002B398B /* GPUImageHistogramEqualizationFilter.h */; }; + 8437241E1D4F260A002B398B /* GPUImageHistogramEqualizationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722B11D4F260A002B398B /* GPUImageHistogramEqualizationFilter.m */; }; + 8437241F1D4F260A002B398B /* GPUImageHistogramFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722B21D4F260A002B398B /* GPUImageHistogramFilter.h */; }; + 843724201D4F260A002B398B /* GPUImageHistogramFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722B31D4F260A002B398B /* GPUImageHistogramFilter.m */; }; + 843724211D4F260A002B398B /* GPUImageHistogramGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722B41D4F260A002B398B /* GPUImageHistogramGenerator.h */; }; + 843724221D4F260A002B398B /* GPUImageHistogramGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722B51D4F260A002B398B /* GPUImageHistogramGenerator.m */; }; + 843724231D4F260A002B398B /* GPUImageHoughTransformLineDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722B61D4F260A002B398B /* GPUImageHoughTransformLineDetector.h */; }; + 843724241D4F260A002B398B /* GPUImageHoughTransformLineDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722B71D4F260A002B398B /* GPUImageHoughTransformLineDetector.m */; }; + 843724251D4F260A002B398B /* GPUImageHSBFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722B81D4F260A002B398B /* GPUImageHSBFilter.h */; }; + 843724261D4F260A002B398B /* GPUImageHSBFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722B91D4F260A002B398B /* GPUImageHSBFilter.m */; }; + 843724271D4F260A002B398B /* GPUImageHueBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722BA1D4F260A002B398B /* GPUImageHueBlendFilter.h */; }; + 843724281D4F260A002B398B /* GPUImageHueBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722BB1D4F260A002B398B /* GPUImageHueBlendFilter.m */; }; + 843724291D4F260A002B398B /* GPUImageHueFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722BC1D4F260A002B398B /* GPUImageHueFilter.h */; }; + 8437242A1D4F260A002B398B /* GPUImageHueFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722BD1D4F260A002B398B /* GPUImageHueFilter.m */; }; + 8437242B1D4F260A002B398B /* GPUImageiOSBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722BE1D4F260A002B398B /* GPUImageiOSBlurFilter.h */; }; + 8437242C1D4F260A002B398B /* GPUImageiOSBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722BF1D4F260A002B398B /* GPUImageiOSBlurFilter.m */; }; + 8437242D1D4F260A002B398B /* GPUImageJFAVoronoiFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722C01D4F260A002B398B /* GPUImageJFAVoronoiFilter.h */; }; + 8437242E1D4F260A002B398B /* GPUImageJFAVoronoiFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722C11D4F260A002B398B /* GPUImageJFAVoronoiFilter.m */; }; + 8437242F1D4F260A002B398B /* GPUImageKuwaharaFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722C21D4F260A002B398B /* GPUImageKuwaharaFilter.h */; }; + 843724301D4F260A002B398B /* GPUImageKuwaharaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722C31D4F260A002B398B /* GPUImageKuwaharaFilter.m */; }; + 843724311D4F260A002B398B /* GPUImageKuwaharaRadius3Filter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722C41D4F260A002B398B /* GPUImageKuwaharaRadius3Filter.h */; }; + 843724321D4F260A002B398B /* GPUImageKuwaharaRadius3Filter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722C51D4F260A002B398B /* GPUImageKuwaharaRadius3Filter.m */; }; + 843724331D4F260A002B398B /* GPUImageLanczosResamplingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722C61D4F260A002B398B /* GPUImageLanczosResamplingFilter.h */; }; + 843724341D4F260A002B398B /* GPUImageLanczosResamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722C71D4F260A002B398B /* GPUImageLanczosResamplingFilter.m */; }; + 843724351D4F260A002B398B /* GPUImageLaplacianFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722C81D4F260A002B398B /* GPUImageLaplacianFilter.h */; }; + 843724361D4F260A002B398B /* GPUImageLaplacianFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722C91D4F260A002B398B /* GPUImageLaplacianFilter.m */; }; + 843724371D4F260A002B398B /* GPUImageLevelsFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722CA1D4F260A002B398B /* GPUImageLevelsFilter.h */; }; + 843724381D4F260A002B398B /* GPUImageLevelsFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722CB1D4F260A002B398B /* GPUImageLevelsFilter.m */; }; + 843724391D4F260A002B398B /* GPUImageLightenBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722CC1D4F260A002B398B /* GPUImageLightenBlendFilter.h */; }; + 8437243A1D4F260A002B398B /* GPUImageLightenBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722CD1D4F260A002B398B /* GPUImageLightenBlendFilter.m */; }; + 8437243B1D4F260A002B398B /* GPUImageLinearBurnBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722CE1D4F260A002B398B /* GPUImageLinearBurnBlendFilter.h */; }; + 8437243C1D4F260A002B398B /* GPUImageLinearBurnBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722CF1D4F260A002B398B /* GPUImageLinearBurnBlendFilter.m */; }; + 8437243D1D4F260A002B398B /* GPUImageLineGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722D01D4F260A002B398B /* GPUImageLineGenerator.h */; }; + 8437243E1D4F260A002B398B /* GPUImageLineGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722D11D4F260A002B398B /* GPUImageLineGenerator.m */; }; + 8437243F1D4F260A002B398B /* GPUImageLocalBinaryPatternFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722D21D4F260A002B398B /* GPUImageLocalBinaryPatternFilter.h */; }; + 843724401D4F260A002B398B /* GPUImageLocalBinaryPatternFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722D31D4F260A002B398B /* GPUImageLocalBinaryPatternFilter.m */; }; + 843724411D4F260A002B398B /* GPUImageLookupFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722D41D4F260A002B398B /* GPUImageLookupFilter.h */; }; + 843724421D4F260A002B398B /* GPUImageLookupFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722D51D4F260A002B398B /* GPUImageLookupFilter.m */; }; + 843724431D4F260A002B398B /* GPUImageLowPassFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722D61D4F260A002B398B /* GPUImageLowPassFilter.h */; }; + 843724441D4F260A002B398B /* GPUImageLowPassFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722D71D4F260A002B398B /* GPUImageLowPassFilter.m */; }; + 843724451D4F260A002B398B /* GPUImageLuminanceRangeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722D81D4F260A002B398B /* GPUImageLuminanceRangeFilter.h */; }; + 843724461D4F260A002B398B /* GPUImageLuminanceRangeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722D91D4F260A002B398B /* GPUImageLuminanceRangeFilter.m */; }; + 843724471D4F260A002B398B /* GPUImageLuminanceThresholdFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722DA1D4F260A002B398B /* GPUImageLuminanceThresholdFilter.h */; }; + 843724481D4F260A002B398B /* GPUImageLuminanceThresholdFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722DB1D4F260A002B398B /* GPUImageLuminanceThresholdFilter.m */; }; + 843724491D4F260A002B398B /* GPUImageLuminosity.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722DC1D4F260A002B398B /* GPUImageLuminosity.h */; }; + 8437244A1D4F260A002B398B /* GPUImageLuminosity.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722DD1D4F260A002B398B /* GPUImageLuminosity.m */; }; + 8437244B1D4F260A002B398B /* GPUImageLuminosityBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722DE1D4F260A002B398B /* GPUImageLuminosityBlendFilter.h */; }; + 8437244C1D4F260A002B398B /* GPUImageLuminosityBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722DF1D4F260A002B398B /* GPUImageLuminosityBlendFilter.m */; }; + 8437244D1D4F260A002B398B /* GPUImageMaskFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722E01D4F260A002B398B /* GPUImageMaskFilter.h */; }; + 8437244E1D4F260A002B398B /* GPUImageMaskFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722E11D4F260A002B398B /* GPUImageMaskFilter.m */; }; + 8437244F1D4F260A002B398B /* GPUImageMedianFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722E21D4F260A002B398B /* GPUImageMedianFilter.h */; }; + 843724501D4F260A002B398B /* GPUImageMedianFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722E31D4F260A002B398B /* GPUImageMedianFilter.m */; }; + 843724511D4F260A002B398B /* GPUImageMissEtikateFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722E41D4F260A002B398B /* GPUImageMissEtikateFilter.h */; }; + 843724521D4F260A002B398B /* GPUImageMissEtikateFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722E51D4F260A002B398B /* GPUImageMissEtikateFilter.m */; }; + 843724531D4F260A002B398B /* GPUImageMonochromeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722E61D4F260A002B398B /* GPUImageMonochromeFilter.h */; }; + 843724541D4F260A002B398B /* GPUImageMonochromeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722E71D4F260A002B398B /* GPUImageMonochromeFilter.m */; }; + 843724551D4F260A002B398B /* GPUImageMosaicFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722E81D4F260A002B398B /* GPUImageMosaicFilter.h */; }; + 843724561D4F260A002B398B /* GPUImageMosaicFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722E91D4F260A002B398B /* GPUImageMosaicFilter.m */; }; + 843724571D4F260A002B398B /* GPUImageMotionBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722EA1D4F260A002B398B /* GPUImageMotionBlurFilter.h */; }; + 843724581D4F260A002B398B /* GPUImageMotionBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722EB1D4F260A002B398B /* GPUImageMotionBlurFilter.m */; }; + 843724591D4F260A002B398B /* GPUImageMotionDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722EC1D4F260A002B398B /* GPUImageMotionDetector.h */; }; + 8437245A1D4F260A002B398B /* GPUImageMotionDetector.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722ED1D4F260A002B398B /* GPUImageMotionDetector.m */; }; + 8437245B1D4F260A002B398B /* GPUImageMovie.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722EE1D4F260A002B398B /* GPUImageMovie.h */; }; + 8437245C1D4F260A002B398B /* GPUImageMovie.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722EF1D4F260A002B398B /* GPUImageMovie.m */; }; + 8437245D1D4F260A002B398B /* GPUImageMovieComposition.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722F01D4F260A002B398B /* GPUImageMovieComposition.h */; }; + 8437245E1D4F260A002B398B /* GPUImageMovieComposition.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722F11D4F260A002B398B /* GPUImageMovieComposition.m */; }; + 8437245F1D4F260A002B398B /* GPUImageMultiplyBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722F21D4F260A002B398B /* GPUImageMultiplyBlendFilter.h */; }; + 843724601D4F260A002B398B /* GPUImageMultiplyBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722F31D4F260A002B398B /* GPUImageMultiplyBlendFilter.m */; }; + 843724611D4F260A002B398B /* GPUImageNobleCornerDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722F41D4F260A002B398B /* GPUImageNobleCornerDetectionFilter.h */; }; + 843724621D4F260A002B398B /* GPUImageNobleCornerDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722F51D4F260A002B398B /* GPUImageNobleCornerDetectionFilter.m */; }; + 843724631D4F260A002B398B /* GPUImageNonMaximumSuppressionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722F61D4F260A002B398B /* GPUImageNonMaximumSuppressionFilter.h */; }; + 843724641D4F260A002B398B /* GPUImageNonMaximumSuppressionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722F71D4F260A002B398B /* GPUImageNonMaximumSuppressionFilter.m */; }; + 843724651D4F260A002B398B /* GPUImageNormalBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722F81D4F260A002B398B /* GPUImageNormalBlendFilter.h */; }; + 843724661D4F260A002B398B /* GPUImageNormalBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722F91D4F260A002B398B /* GPUImageNormalBlendFilter.m */; }; + 843724671D4F260A002B398B /* GPUImageOpacityFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722FA1D4F260A002B398B /* GPUImageOpacityFilter.h */; }; + 843724681D4F260A002B398B /* GPUImageOpacityFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722FB1D4F260A002B398B /* GPUImageOpacityFilter.m */; }; + 843724691D4F260A002B398B /* GPUImageOpeningFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722FC1D4F260A002B398B /* GPUImageOpeningFilter.h */; }; + 8437246A1D4F260A002B398B /* GPUImageOpeningFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722FD1D4F260A002B398B /* GPUImageOpeningFilter.m */; }; + 8437246B1D4F260A002B398B /* GPUImageOutput.h in Headers */ = {isa = PBXBuildFile; fileRef = 843722FE1D4F260A002B398B /* GPUImageOutput.h */; }; + 8437246C1D4F260A002B398B /* GPUImageOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = 843722FF1D4F260A002B398B /* GPUImageOutput.m */; }; + 8437246D1D4F260A002B398B /* GPUImageOverlayBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723001D4F260A002B398B /* GPUImageOverlayBlendFilter.h */; }; + 8437246E1D4F260A002B398B /* GPUImageOverlayBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723011D4F260A002B398B /* GPUImageOverlayBlendFilter.m */; }; + 8437246F1D4F260A002B398B /* GPUImageParallelCoordinateLineTransformFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723021D4F260A002B398B /* GPUImageParallelCoordinateLineTransformFilter.h */; }; + 843724701D4F260A002B398B /* GPUImageParallelCoordinateLineTransformFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723031D4F260A002B398B /* GPUImageParallelCoordinateLineTransformFilter.m */; }; + 843724711D4F260A002B398B /* GPUImagePerlinNoiseFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723041D4F260A002B398B /* GPUImagePerlinNoiseFilter.h */; }; + 843724721D4F260A002B398B /* GPUImagePerlinNoiseFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723051D4F260A002B398B /* GPUImagePerlinNoiseFilter.m */; }; + 843724731D4F260A002B398B /* GPUImagePinchDistortionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723061D4F260A002B398B /* GPUImagePinchDistortionFilter.h */; }; + 843724741D4F260A002B398B /* GPUImagePinchDistortionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723071D4F260A002B398B /* GPUImagePinchDistortionFilter.m */; }; + 843724751D4F260A002B398B /* GPUImagePixellateFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723081D4F260A002B398B /* GPUImagePixellateFilter.h */; }; + 843724761D4F260A002B398B /* GPUImagePixellateFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723091D4F260A002B398B /* GPUImagePixellateFilter.m */; }; + 843724771D4F260A002B398B /* GPUImagePixellatePositionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437230A1D4F260A002B398B /* GPUImagePixellatePositionFilter.h */; }; + 843724781D4F260A002B398B /* GPUImagePixellatePositionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437230B1D4F260A002B398B /* GPUImagePixellatePositionFilter.m */; }; + 843724791D4F260A002B398B /* GPUImagePoissonBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437230C1D4F260A002B398B /* GPUImagePoissonBlendFilter.h */; }; + 8437247A1D4F260A002B398B /* GPUImagePoissonBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437230D1D4F260A002B398B /* GPUImagePoissonBlendFilter.m */; }; + 8437247B1D4F260A002B398B /* GPUImagePolarPixellateFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437230E1D4F260A002B398B /* GPUImagePolarPixellateFilter.h */; }; + 8437247C1D4F260A002B398B /* GPUImagePolarPixellateFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437230F1D4F260A002B398B /* GPUImagePolarPixellateFilter.m */; }; + 8437247D1D4F260A002B398B /* GPUImagePolkaDotFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723101D4F260A002B398B /* GPUImagePolkaDotFilter.h */; }; + 8437247E1D4F260A002B398B /* GPUImagePolkaDotFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723111D4F260A002B398B /* GPUImagePolkaDotFilter.m */; }; + 8437247F1D4F260A002B398B /* GPUImagePosterizeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723121D4F260A002B398B /* GPUImagePosterizeFilter.h */; }; + 843724801D4F260A002B398B /* GPUImagePosterizeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723131D4F260A002B398B /* GPUImagePosterizeFilter.m */; }; + 843724811D4F260A002B398B /* GPUImagePrewittEdgeDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723141D4F260A002B398B /* GPUImagePrewittEdgeDetectionFilter.h */; }; + 843724821D4F260A002B398B /* GPUImagePrewittEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723151D4F260A002B398B /* GPUImagePrewittEdgeDetectionFilter.m */; }; + 843724831D4F260A002B398B /* GPUImageRawDataInput.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723161D4F260A002B398B /* GPUImageRawDataInput.h */; }; + 843724841D4F260A002B398B /* GPUImageRawDataInput.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723171D4F260A002B398B /* GPUImageRawDataInput.m */; }; + 843724851D4F260A002B398B /* GPUImageRawDataOutput.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723181D4F260A002B398B /* GPUImageRawDataOutput.h */; }; + 843724861D4F260A002B398B /* GPUImageRawDataOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723191D4F260A002B398B /* GPUImageRawDataOutput.m */; }; + 843724871D4F260A002B398B /* GPUImageRGBClosingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437231A1D4F260A002B398B /* GPUImageRGBClosingFilter.h */; }; + 843724881D4F260A002B398B /* GPUImageRGBClosingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437231B1D4F260A002B398B /* GPUImageRGBClosingFilter.m */; }; + 843724891D4F260A002B398B /* GPUImageRGBDilationFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437231C1D4F260A002B398B /* GPUImageRGBDilationFilter.h */; }; + 8437248A1D4F260A002B398B /* GPUImageRGBDilationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437231D1D4F260A002B398B /* GPUImageRGBDilationFilter.m */; }; + 8437248B1D4F260A002B398B /* GPUImageRGBErosionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437231E1D4F260A002B398B /* GPUImageRGBErosionFilter.h */; }; + 8437248C1D4F260A002B398B /* GPUImageRGBErosionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437231F1D4F260A002B398B /* GPUImageRGBErosionFilter.m */; }; + 8437248D1D4F260A002B398B /* GPUImageRGBFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723201D4F260A002B398B /* GPUImageRGBFilter.h */; }; + 8437248E1D4F260A002B398B /* GPUImageRGBFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723211D4F260A002B398B /* GPUImageRGBFilter.m */; }; + 8437248F1D4F260A002B398B /* GPUImageRGBOpeningFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723221D4F260A002B398B /* GPUImageRGBOpeningFilter.h */; }; + 843724901D4F260A002B398B /* GPUImageRGBOpeningFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723231D4F260A002B398B /* GPUImageRGBOpeningFilter.m */; }; + 843724911D4F260A002B398B /* GPUImageSaturationBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723241D4F260A002B398B /* GPUImageSaturationBlendFilter.h */; }; + 843724921D4F260A002B398B /* GPUImageSaturationBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723251D4F260A002B398B /* GPUImageSaturationBlendFilter.m */; }; + 843724931D4F260A002B398B /* GPUImageSaturationFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723261D4F260A002B398B /* GPUImageSaturationFilter.h */; }; + 843724941D4F260A002B398B /* GPUImageSaturationFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723271D4F260A002B398B /* GPUImageSaturationFilter.m */; }; + 843724951D4F260A002B398B /* GPUImageScreenBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723281D4F260A002B398B /* GPUImageScreenBlendFilter.h */; }; + 843724961D4F260A002B398B /* GPUImageScreenBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723291D4F260A002B398B /* GPUImageScreenBlendFilter.m */; }; + 843724971D4F260A002B398B /* GPUImageSepiaFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437232A1D4F260A002B398B /* GPUImageSepiaFilter.h */; }; + 843724981D4F260A002B398B /* GPUImageSepiaFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437232B1D4F260A002B398B /* GPUImageSepiaFilter.m */; }; + 843724991D4F260A002B398B /* GPUImageSharpenFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437232C1D4F260A002B398B /* GPUImageSharpenFilter.h */; }; + 8437249A1D4F260A002B398B /* GPUImageSharpenFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437232D1D4F260A002B398B /* GPUImageSharpenFilter.m */; }; + 8437249B1D4F260A002B398B /* GPUImageShiTomasiFeatureDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437232E1D4F260A002B398B /* GPUImageShiTomasiFeatureDetectionFilter.h */; }; + 8437249C1D4F260A002B398B /* GPUImageShiTomasiFeatureDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437232F1D4F260A002B398B /* GPUImageShiTomasiFeatureDetectionFilter.m */; }; + 8437249D1D4F260A002B398B /* GPUImageSingleComponentGaussianBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723301D4F260A002B398B /* GPUImageSingleComponentGaussianBlurFilter.h */; }; + 8437249E1D4F260A002B398B /* GPUImageSingleComponentGaussianBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723311D4F260A002B398B /* GPUImageSingleComponentGaussianBlurFilter.m */; }; + 8437249F1D4F260A002B398B /* GPUImageSketchFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723321D4F260A002B398B /* GPUImageSketchFilter.h */; }; + 843724A01D4F260A002B398B /* GPUImageSketchFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723331D4F260A002B398B /* GPUImageSketchFilter.m */; }; + 843724A11D4F260A002B398B /* GPUImageSkinToneFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723341D4F260A002B398B /* GPUImageSkinToneFilter.h */; }; + 843724A21D4F260A002B398B /* GPUImageSkinToneFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723351D4F260A002B398B /* GPUImageSkinToneFilter.m */; }; + 843724A31D4F260A002B398B /* GPUImageSmoothToonFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723361D4F260A002B398B /* GPUImageSmoothToonFilter.h */; }; + 843724A41D4F260A002B398B /* GPUImageSmoothToonFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723371D4F260A002B398B /* GPUImageSmoothToonFilter.m */; }; + 843724A51D4F260A002B398B /* GPUImageSobelEdgeDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723381D4F260A002B398B /* GPUImageSobelEdgeDetectionFilter.h */; }; + 843724A61D4F260A002B398B /* GPUImageSobelEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723391D4F260A002B398B /* GPUImageSobelEdgeDetectionFilter.m */; }; + 843724A71D4F260A002B398B /* GPUImageSoftEleganceFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437233A1D4F260A002B398B /* GPUImageSoftEleganceFilter.h */; }; + 843724A81D4F260A002B398B /* GPUImageSoftEleganceFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437233B1D4F260A002B398B /* GPUImageSoftEleganceFilter.m */; }; + 843724A91D4F260A002B398B /* GPUImageSoftLightBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437233C1D4F260A002B398B /* GPUImageSoftLightBlendFilter.h */; }; + 843724AA1D4F260A002B398B /* GPUImageSoftLightBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437233D1D4F260A002B398B /* GPUImageSoftLightBlendFilter.m */; }; + 843724AB1D4F260A002B398B /* GPUImageSolarizeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437233E1D4F260A002B398B /* GPUImageSolarizeFilter.h */; }; + 843724AC1D4F260A002B398B /* GPUImageSolarizeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437233F1D4F260A002B398B /* GPUImageSolarizeFilter.m */; }; + 843724AD1D4F260A002B398B /* GPUImageSolidColorGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723401D4F260A002B398B /* GPUImageSolidColorGenerator.h */; }; + 843724AE1D4F260A002B398B /* GPUImageSolidColorGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723411D4F260A002B398B /* GPUImageSolidColorGenerator.m */; }; + 843724AF1D4F260A002B398B /* GPUImageSourceOverBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723421D4F260A002B398B /* GPUImageSourceOverBlendFilter.h */; }; + 843724B01D4F260A002B398B /* GPUImageSourceOverBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723431D4F260A002B398B /* GPUImageSourceOverBlendFilter.m */; }; + 843724B11D4F260A002B398B /* GPUImageSphereRefractionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723441D4F260A002B398B /* GPUImageSphereRefractionFilter.h */; }; + 843724B21D4F260A002B398B /* GPUImageSphereRefractionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723451D4F260A002B398B /* GPUImageSphereRefractionFilter.m */; }; + 843724B31D4F260A002B398B /* GPUImageStillCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723461D4F260A002B398B /* GPUImageStillCamera.h */; }; + 843724B41D4F260A002B398B /* GPUImageStillCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723471D4F260A002B398B /* GPUImageStillCamera.m */; }; + 843724B51D4F260A002B398B /* GPUImageStretchDistortionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723481D4F260A002B398B /* GPUImageStretchDistortionFilter.h */; }; + 843724B61D4F260A002B398B /* GPUImageStretchDistortionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723491D4F260A002B398B /* GPUImageStretchDistortionFilter.m */; }; + 843724B71D4F260A002B398B /* GPUImageSubtractBlendFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437234A1D4F260A002B398B /* GPUImageSubtractBlendFilter.h */; }; + 843724B81D4F260A002B398B /* GPUImageSubtractBlendFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437234B1D4F260A002B398B /* GPUImageSubtractBlendFilter.m */; }; + 843724B91D4F260A002B398B /* GPUImageSwirlFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437234C1D4F260A002B398B /* GPUImageSwirlFilter.h */; }; + 843724BA1D4F260A002B398B /* GPUImageSwirlFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437234D1D4F260A002B398B /* GPUImageSwirlFilter.m */; }; + 843724BB1D4F260A002B398B /* GPUImageTextureInput.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437234E1D4F260A002B398B /* GPUImageTextureInput.h */; }; + 843724BC1D4F260A002B398B /* GPUImageTextureInput.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437234F1D4F260A002B398B /* GPUImageTextureInput.m */; }; + 843724BD1D4F260A002B398B /* GPUImageTextureOutput.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723501D4F260A002B398B /* GPUImageTextureOutput.h */; }; + 843724BE1D4F260A002B398B /* GPUImageTextureOutput.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723511D4F260A002B398B /* GPUImageTextureOutput.m */; }; + 843724BF1D4F260A002B398B /* GPUImageThreeInputFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723521D4F260A002B398B /* GPUImageThreeInputFilter.h */; }; + 843724C01D4F260A002B398B /* GPUImageThreeInputFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723531D4F260A002B398B /* GPUImageThreeInputFilter.m */; }; + 843724C11D4F260A002B398B /* GPUImageThresholdEdgeDetectionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723541D4F260A002B398B /* GPUImageThresholdEdgeDetectionFilter.h */; }; + 843724C21D4F260A002B398B /* GPUImageThresholdEdgeDetectionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723551D4F260A002B398B /* GPUImageThresholdEdgeDetectionFilter.m */; }; + 843724C31D4F260A002B398B /* GPUImageThresholdedNonMaximumSuppressionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723561D4F260A002B398B /* GPUImageThresholdedNonMaximumSuppressionFilter.h */; }; + 843724C41D4F260A002B398B /* GPUImageThresholdedNonMaximumSuppressionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723571D4F260A002B398B /* GPUImageThresholdedNonMaximumSuppressionFilter.m */; }; + 843724C51D4F260A002B398B /* GPUImageThresholdSketchFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723581D4F260A002B398B /* GPUImageThresholdSketchFilter.h */; }; + 843724C61D4F260A002B398B /* GPUImageThresholdSketchFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723591D4F260A002B398B /* GPUImageThresholdSketchFilter.m */; }; + 843724C71D4F260A002B398B /* GPUImageTiltShiftFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437235A1D4F260A002B398B /* GPUImageTiltShiftFilter.h */; }; + 843724C81D4F260A002B398B /* GPUImageTiltShiftFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437235B1D4F260A002B398B /* GPUImageTiltShiftFilter.m */; }; + 843724C91D4F260A002B398B /* GPUImageToneCurveFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437235C1D4F260A002B398B /* GPUImageToneCurveFilter.h */; }; + 843724CA1D4F260A002B398B /* GPUImageToneCurveFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437235D1D4F260A002B398B /* GPUImageToneCurveFilter.m */; }; + 843724CB1D4F260A002B398B /* GPUImageToonFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437235E1D4F260A002B398B /* GPUImageToonFilter.h */; }; + 843724CC1D4F260A002B398B /* GPUImageToonFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437235F1D4F260A002B398B /* GPUImageToonFilter.m */; }; + 843724CD1D4F260A002B398B /* GPUImageTransformFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723601D4F260A002B398B /* GPUImageTransformFilter.h */; }; + 843724CE1D4F260A002B398B /* GPUImageTransformFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723611D4F260A002B398B /* GPUImageTransformFilter.m */; }; + 843724CF1D4F260A002B398B /* GPUImageTwoInputCrossTextureSamplingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723621D4F260A002B398B /* GPUImageTwoInputCrossTextureSamplingFilter.h */; }; + 843724D01D4F260A002B398B /* GPUImageTwoInputCrossTextureSamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723631D4F260A002B398B /* GPUImageTwoInputCrossTextureSamplingFilter.m */; }; + 843724D11D4F260A002B398B /* GPUImageTwoInputFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723641D4F260A002B398B /* GPUImageTwoInputFilter.h */; }; + 843724D21D4F260A002B398B /* GPUImageTwoInputFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723651D4F260A002B398B /* GPUImageTwoInputFilter.m */; }; + 843724D31D4F260A002B398B /* GPUImageTwoPassFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723661D4F260A002B398B /* GPUImageTwoPassFilter.h */; }; + 843724D41D4F260A002B398B /* GPUImageTwoPassFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723671D4F260A002B398B /* GPUImageTwoPassFilter.m */; }; + 843724D51D4F260A002B398B /* GPUImageTwoPassTextureSamplingFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723681D4F260A002B398B /* GPUImageTwoPassTextureSamplingFilter.h */; }; + 843724D61D4F260A002B398B /* GPUImageTwoPassTextureSamplingFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723691D4F260A002B398B /* GPUImageTwoPassTextureSamplingFilter.m */; }; + 843724D71D4F260A002B398B /* GPUImageUIElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437236A1D4F260A002B398B /* GPUImageUIElement.h */; }; + 843724D81D4F260A002B398B /* GPUImageUIElement.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437236B1D4F260A002B398B /* GPUImageUIElement.m */; }; + 843724D91D4F260A002B398B /* GPUImageUnsharpMaskFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437236C1D4F260A002B398B /* GPUImageUnsharpMaskFilter.h */; }; + 843724DA1D4F260A002B398B /* GPUImageUnsharpMaskFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437236D1D4F260A002B398B /* GPUImageUnsharpMaskFilter.m */; }; + 843724DB1D4F260A002B398B /* GPUImageVideoCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437236E1D4F260A002B398B /* GPUImageVideoCamera.h */; }; + 843724DC1D4F260A002B398B /* GPUImageVideoCamera.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437236F1D4F260A002B398B /* GPUImageVideoCamera.m */; }; + 843724DD1D4F260A002B398B /* GPUImageVignetteFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723701D4F260A002B398B /* GPUImageVignetteFilter.h */; }; + 843724DE1D4F260A002B398B /* GPUImageVignetteFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723711D4F260A002B398B /* GPUImageVignetteFilter.m */; }; + 843724DF1D4F260A002B398B /* GPUImageVoronoiConsumerFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723721D4F260A002B398B /* GPUImageVoronoiConsumerFilter.h */; }; + 843724E01D4F260A002B398B /* GPUImageVoronoiConsumerFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723731D4F260A002B398B /* GPUImageVoronoiConsumerFilter.m */; }; + 843724E11D4F260A002B398B /* GPUImageWeakPixelInclusionFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723741D4F260A002B398B /* GPUImageWeakPixelInclusionFilter.h */; }; + 843724E21D4F260A002B398B /* GPUImageWeakPixelInclusionFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723751D4F260A002B398B /* GPUImageWeakPixelInclusionFilter.m */; }; + 843724E31D4F260A002B398B /* GPUImageWhiteBalanceFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723761D4F260A002B398B /* GPUImageWhiteBalanceFilter.h */; }; + 843724E41D4F260A002B398B /* GPUImageWhiteBalanceFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723771D4F260A002B398B /* GPUImageWhiteBalanceFilter.m */; }; + 843724E51D4F260A002B398B /* GPUImageXYDerivativeFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723781D4F260A002B398B /* GPUImageXYDerivativeFilter.h */; }; + 843724E61D4F260A002B398B /* GPUImageXYDerivativeFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723791D4F260A002B398B /* GPUImageXYDerivativeFilter.m */; }; + 843724E71D4F260A002B398B /* GPUImageZoomBlurFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437237A1D4F260A002B398B /* GPUImageZoomBlurFilter.h */; }; + 843724E81D4F260A002B398B /* GPUImageZoomBlurFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = 8437237B1D4F260A002B398B /* GPUImageZoomBlurFilter.m */; }; + 843724E91D4F260A002B398B /* GPUImageFramework.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437237E1D4F260A002B398B /* GPUImageFramework.h */; }; + 843724EA1D4F260A002B398B /* GPUImageContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437237F1D4F260A002B398B /* GPUImageContext.h */; }; + 843724EB1D4F260A002B398B /* GPUImageContext.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723801D4F260A002B398B /* GPUImageContext.m */; }; + 843724EC1D4F260A002B398B /* GPUImageMovieWriter.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723811D4F260A002B398B /* GPUImageMovieWriter.h */; }; + 843724ED1D4F260A002B398B /* GPUImageMovieWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723821D4F260A002B398B /* GPUImageMovieWriter.m */; }; + 843724EE1D4F260A002B398B /* GPUImagePicture+TextureSubimage.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723831D4F260A002B398B /* GPUImagePicture+TextureSubimage.h */; }; + 843724EF1D4F260A002B398B /* GPUImagePicture+TextureSubimage.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723841D4F260A002B398B /* GPUImagePicture+TextureSubimage.m */; }; + 843724F01D4F260A002B398B /* GPUImagePicture.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723851D4F260A002B398B /* GPUImagePicture.h */; }; + 843724F11D4F260A002B398B /* GPUImagePicture.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723861D4F260A002B398B /* GPUImagePicture.m */; }; + 843724F21D4F260A002B398B /* GPUImageView.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723871D4F260A002B398B /* GPUImageView.h */; }; + 843724F31D4F260A002B398B /* GPUImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 843723881D4F260A002B398B /* GPUImageView.m */; }; + 843724F41D4F260A002B398B /* amf.c in Sources */ = {isa = PBXBuildFile; fileRef = 8437238A1D4F260A002B398B /* amf.c */; }; + 843724F51D4F260A002B398B /* amf.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437238B1D4F260A002B398B /* amf.h */; }; + 843724F61D4F260A002B398B /* bytes.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437238C1D4F260A002B398B /* bytes.h */; }; + 843724F71D4F260A002B398B /* dh.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437238D1D4F260A002B398B /* dh.h */; }; + 843724F81D4F260A002B398B /* dhgroups.h in Headers */ = {isa = PBXBuildFile; fileRef = 8437238E1D4F260A002B398B /* dhgroups.h */; }; + 843724F91D4F260A002B398B /* error.c in Sources */ = {isa = PBXBuildFile; fileRef = 8437238F1D4F260A002B398B /* error.c */; }; + 843724FA1D4F260A002B398B /* error.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723901D4F260A002B398B /* error.h */; }; + 843724FB1D4F260A002B398B /* handshake.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723911D4F260A002B398B /* handshake.h */; }; + 843724FC1D4F260A002B398B /* hashswf.c in Sources */ = {isa = PBXBuildFile; fileRef = 843723921D4F260A002B398B /* hashswf.c */; }; + 843724FD1D4F260A002B398B /* http.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723931D4F260A002B398B /* http.h */; }; + 843724FE1D4F260A002B398B /* log.c in Sources */ = {isa = PBXBuildFile; fileRef = 843723941D4F260A002B398B /* log.c */; }; + 843724FF1D4F260A002B398B /* log.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723951D4F260A002B398B /* log.h */; }; + 843725001D4F260A002B398B /* parseurl.c in Sources */ = {isa = PBXBuildFile; fileRef = 843723961D4F260A002B398B /* parseurl.c */; }; + 843725011D4F260A002B398B /* rtmp.c in Sources */ = {isa = PBXBuildFile; fileRef = 843723971D4F260A002B398B /* rtmp.c */; }; + 843725021D4F260A002B398B /* rtmp.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723981D4F260A002B398B /* rtmp.h */; }; + 843725031D4F260A002B398B /* rtmp_sys.h in Headers */ = {isa = PBXBuildFile; fileRef = 843723991D4F260A002B398B /* rtmp_sys.h */; }; B289F1DB1D3DE77F00D9C7A5 /* LFStreamingBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = B289F1D41D3DE77F00D9C7A5 /* LFStreamingBuffer.h */; }; B289F1DC1D3DE77F00D9C7A5 /* LFStreamingBuffer.m in Sources */ = {isa = PBXBuildFile; fileRef = B289F1D51D3DE77F00D9C7A5 /* LFStreamingBuffer.m */; }; B289F1DD1D3DE77F00D9C7A5 /* LFStreamRtmpSocket.h in Headers */ = {isa = PBXBuildFile; fileRef = B289F1D61D3DE77F00D9C7A5 /* LFStreamRtmpSocket.h */; }; @@ -65,7 +426,6 @@ B2CD14751D45F18B008082E8 /* LFVideoEncoder.m in Sources */ = {isa = PBXBuildFile; fileRef = B2CD146A1D45F18B008082E8 /* LFVideoEncoder.m */; }; B2CD14761D45F18B008082E8 /* LFH264VideoEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = B2CD146B1D45F18B008082E8 /* LFH264VideoEncoder.h */; }; B2CD14771D45F18B008082E8 /* LFH264VideoEncoder.mm in Sources */ = {isa = PBXBuildFile; fileRef = B2CD146C1D45F18B008082E8 /* LFH264VideoEncoder.mm */; }; - BE55DA79155500CDEF87FB5C /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = B5758EB2A15DAA132D8BF380 /* libPods.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -79,6 +439,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 0BA5A0CE1F07E1D707F69735 /* Pods-LFLiveKit.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKit.release.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKit/Pods-LFLiveKit.release.xcconfig"; sourceTree = ""; }; 84001F8A1D0015D10026C63F /* LFLiveKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = LFLiveKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 84001F8D1D0015D10026C63F /* LFLiveKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LFLiveKit.h; sourceTree = ""; }; 84001F8F1D0015D10026C63F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -121,7 +482,368 @@ 84001FFC1D0017680026C63F /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 84001FFE1D00176C0026C63F /* VideoToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = VideoToolbox.framework; path = System/Library/Frameworks/VideoToolbox.framework; sourceTree = SDKROOT; }; 840020001D0017850026C63F /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; - A17586B27CD6843997425CCF /* Pods-LFLiveKit.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKit.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKit/Pods-LFLiveKit.debug.xcconfig"; sourceTree = ""; }; + 8437222D1D4F260A002B398B /* GLProgram.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GLProgram.h; sourceTree = ""; }; + 8437222E1D4F260A002B398B /* GLProgram.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GLProgram.m; sourceTree = ""; }; + 8437222F1D4F260A002B398B /* GPUImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImage.h; sourceTree = ""; }; + 843722301D4F260A002B398B /* GPUImage3x3ConvolutionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImage3x3ConvolutionFilter.h; sourceTree = ""; }; + 843722311D4F260A002B398B /* GPUImage3x3ConvolutionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImage3x3ConvolutionFilter.m; sourceTree = ""; }; + 843722321D4F260A002B398B /* GPUImage3x3TextureSamplingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImage3x3TextureSamplingFilter.h; sourceTree = ""; }; + 843722331D4F260A002B398B /* GPUImage3x3TextureSamplingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImage3x3TextureSamplingFilter.m; sourceTree = ""; }; + 843722341D4F260A002B398B /* GPUImageAdaptiveThresholdFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageAdaptiveThresholdFilter.h; sourceTree = ""; }; + 843722351D4F260A002B398B /* GPUImageAdaptiveThresholdFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageAdaptiveThresholdFilter.m; sourceTree = ""; }; + 843722361D4F260A002B398B /* GPUImageAddBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageAddBlendFilter.h; sourceTree = ""; }; + 843722371D4F260A002B398B /* GPUImageAddBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageAddBlendFilter.m; sourceTree = ""; }; + 843722381D4F260A002B398B /* GPUImageAlphaBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageAlphaBlendFilter.h; sourceTree = ""; }; + 843722391D4F260A002B398B /* GPUImageAlphaBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageAlphaBlendFilter.m; sourceTree = ""; }; + 8437223A1D4F260A002B398B /* GPUImageAmatorkaFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageAmatorkaFilter.h; sourceTree = ""; }; + 8437223B1D4F260A002B398B /* GPUImageAmatorkaFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageAmatorkaFilter.m; sourceTree = ""; }; + 8437223C1D4F260A002B398B /* GPUImageAverageColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageAverageColor.h; sourceTree = ""; }; + 8437223D1D4F260A002B398B /* GPUImageAverageColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageAverageColor.m; sourceTree = ""; }; + 8437223E1D4F260A002B398B /* GPUImageAverageLuminanceThresholdFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageAverageLuminanceThresholdFilter.h; sourceTree = ""; }; + 8437223F1D4F260A002B398B /* GPUImageAverageLuminanceThresholdFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageAverageLuminanceThresholdFilter.m; sourceTree = ""; }; + 843722401D4F260A002B398B /* GPUImageBilateralFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageBilateralFilter.h; sourceTree = ""; }; + 843722411D4F260A002B398B /* GPUImageBilateralFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageBilateralFilter.m; sourceTree = ""; }; + 843722421D4F260A002B398B /* GPUImageBoxBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageBoxBlurFilter.h; sourceTree = ""; }; + 843722431D4F260A002B398B /* GPUImageBoxBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageBoxBlurFilter.m; sourceTree = ""; }; + 843722441D4F260A002B398B /* GPUImageBrightnessFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageBrightnessFilter.h; sourceTree = ""; }; + 843722451D4F260A002B398B /* GPUImageBrightnessFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageBrightnessFilter.m; sourceTree = ""; }; + 843722461D4F260A002B398B /* GPUImageBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageBuffer.h; sourceTree = ""; }; + 843722471D4F260A002B398B /* GPUImageBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageBuffer.m; sourceTree = ""; }; + 843722481D4F260A002B398B /* GPUImageBulgeDistortionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageBulgeDistortionFilter.h; sourceTree = ""; }; + 843722491D4F260A002B398B /* GPUImageBulgeDistortionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageBulgeDistortionFilter.m; sourceTree = ""; }; + 8437224A1D4F260A002B398B /* GPUImageCannyEdgeDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageCannyEdgeDetectionFilter.h; sourceTree = ""; }; + 8437224B1D4F260A002B398B /* GPUImageCannyEdgeDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageCannyEdgeDetectionFilter.m; sourceTree = ""; }; + 8437224C1D4F260A002B398B /* GPUImageCGAColorspaceFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageCGAColorspaceFilter.h; sourceTree = ""; }; + 8437224D1D4F260A002B398B /* GPUImageCGAColorspaceFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageCGAColorspaceFilter.m; sourceTree = ""; }; + 8437224E1D4F260A002B398B /* GPUImageChromaKeyBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageChromaKeyBlendFilter.h; sourceTree = ""; }; + 8437224F1D4F260A002B398B /* GPUImageChromaKeyBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageChromaKeyBlendFilter.m; sourceTree = ""; }; + 843722501D4F260A002B398B /* GPUImageChromaKeyFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageChromaKeyFilter.h; sourceTree = ""; }; + 843722511D4F260A002B398B /* GPUImageChromaKeyFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageChromaKeyFilter.m; sourceTree = ""; }; + 843722521D4F260A002B398B /* GPUImageClosingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageClosingFilter.h; sourceTree = ""; }; + 843722531D4F260A002B398B /* GPUImageClosingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageClosingFilter.m; sourceTree = ""; }; + 843722541D4F260A002B398B /* GPUImageColorBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorBlendFilter.h; sourceTree = ""; }; + 843722551D4F260A002B398B /* GPUImageColorBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorBlendFilter.m; sourceTree = ""; }; + 843722561D4F260A002B398B /* GPUImageColorBurnBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorBurnBlendFilter.h; sourceTree = ""; }; + 843722571D4F260A002B398B /* GPUImageColorBurnBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorBurnBlendFilter.m; sourceTree = ""; }; + 843722581D4F260A002B398B /* GPUImageColorConversion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorConversion.h; sourceTree = ""; }; + 843722591D4F260A002B398B /* GPUImageColorConversion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorConversion.m; sourceTree = ""; }; + 8437225A1D4F260A002B398B /* GPUImageColorDodgeBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorDodgeBlendFilter.h; sourceTree = ""; }; + 8437225B1D4F260A002B398B /* GPUImageColorDodgeBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorDodgeBlendFilter.m; sourceTree = ""; }; + 8437225C1D4F260A002B398B /* GPUImageColorInvertFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorInvertFilter.h; sourceTree = ""; }; + 8437225D1D4F260A002B398B /* GPUImageColorInvertFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorInvertFilter.m; sourceTree = ""; }; + 8437225E1D4F260A002B398B /* GPUImageColorLocalBinaryPatternFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorLocalBinaryPatternFilter.h; sourceTree = ""; }; + 8437225F1D4F260A002B398B /* GPUImageColorLocalBinaryPatternFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorLocalBinaryPatternFilter.m; sourceTree = ""; }; + 843722601D4F260A002B398B /* GPUImageColorMatrixFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorMatrixFilter.h; sourceTree = ""; }; + 843722611D4F260A002B398B /* GPUImageColorMatrixFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorMatrixFilter.m; sourceTree = ""; }; + 843722621D4F260A002B398B /* GPUImageColorPackingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColorPackingFilter.h; sourceTree = ""; }; + 843722631D4F260A002B398B /* GPUImageColorPackingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColorPackingFilter.m; sourceTree = ""; }; + 843722641D4F260A002B398B /* GPUImageColourFASTFeatureDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColourFASTFeatureDetector.h; sourceTree = ""; }; + 843722651D4F260A002B398B /* GPUImageColourFASTFeatureDetector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColourFASTFeatureDetector.m; sourceTree = ""; }; + 843722661D4F260A002B398B /* GPUImageColourFASTSamplingOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageColourFASTSamplingOperation.h; sourceTree = ""; }; + 843722671D4F260A002B398B /* GPUImageColourFASTSamplingOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageColourFASTSamplingOperation.m; sourceTree = ""; }; + 843722681D4F260A002B398B /* GPUImageContrastFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageContrastFilter.h; sourceTree = ""; }; + 843722691D4F260A002B398B /* GPUImageContrastFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageContrastFilter.m; sourceTree = ""; }; + 8437226A1D4F260A002B398B /* GPUImageCropFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageCropFilter.h; sourceTree = ""; }; + 8437226B1D4F260A002B398B /* GPUImageCropFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageCropFilter.m; sourceTree = ""; }; + 8437226C1D4F260A002B398B /* GPUImageCrosshairGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageCrosshairGenerator.h; sourceTree = ""; }; + 8437226D1D4F260A002B398B /* GPUImageCrosshairGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageCrosshairGenerator.m; sourceTree = ""; }; + 8437226E1D4F260A002B398B /* GPUImageCrosshatchFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageCrosshatchFilter.h; sourceTree = ""; }; + 8437226F1D4F260A002B398B /* GPUImageCrosshatchFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageCrosshatchFilter.m; sourceTree = ""; }; + 843722701D4F260A002B398B /* GPUImageDarkenBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDarkenBlendFilter.h; sourceTree = ""; }; + 843722711D4F260A002B398B /* GPUImageDarkenBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDarkenBlendFilter.m; sourceTree = ""; }; + 843722721D4F260A002B398B /* GPUImageDifferenceBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDifferenceBlendFilter.h; sourceTree = ""; }; + 843722731D4F260A002B398B /* GPUImageDifferenceBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDifferenceBlendFilter.m; sourceTree = ""; }; + 843722741D4F260A002B398B /* GPUImageDilationFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDilationFilter.h; sourceTree = ""; }; + 843722751D4F260A002B398B /* GPUImageDilationFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDilationFilter.m; sourceTree = ""; }; + 843722761D4F260A002B398B /* GPUImageDirectionalNonMaximumSuppressionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDirectionalNonMaximumSuppressionFilter.h; sourceTree = ""; }; + 843722771D4F260A002B398B /* GPUImageDirectionalNonMaximumSuppressionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDirectionalNonMaximumSuppressionFilter.m; sourceTree = ""; }; + 843722781D4F260A002B398B /* GPUImageDirectionalSobelEdgeDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDirectionalSobelEdgeDetectionFilter.h; sourceTree = ""; }; + 843722791D4F260A002B398B /* GPUImageDirectionalSobelEdgeDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDirectionalSobelEdgeDetectionFilter.m; sourceTree = ""; }; + 8437227A1D4F260A002B398B /* GPUImageDissolveBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDissolveBlendFilter.h; sourceTree = ""; }; + 8437227B1D4F260A002B398B /* GPUImageDissolveBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDissolveBlendFilter.m; sourceTree = ""; }; + 8437227C1D4F260A002B398B /* GPUImageDivideBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageDivideBlendFilter.h; sourceTree = ""; }; + 8437227D1D4F260A002B398B /* GPUImageDivideBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageDivideBlendFilter.m; sourceTree = ""; }; + 8437227E1D4F260A002B398B /* GPUImageEmbossFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageEmbossFilter.h; sourceTree = ""; }; + 8437227F1D4F260A002B398B /* GPUImageEmbossFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageEmbossFilter.m; sourceTree = ""; }; + 843722801D4F260A002B398B /* GPUImageErosionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageErosionFilter.h; sourceTree = ""; }; + 843722811D4F260A002B398B /* GPUImageErosionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageErosionFilter.m; sourceTree = ""; }; + 843722821D4F260A002B398B /* GPUImageExclusionBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageExclusionBlendFilter.h; sourceTree = ""; }; + 843722831D4F260A002B398B /* GPUImageExclusionBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageExclusionBlendFilter.m; sourceTree = ""; }; + 843722841D4F260A002B398B /* GPUImageExposureFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageExposureFilter.h; sourceTree = ""; }; + 843722851D4F260A002B398B /* GPUImageExposureFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageExposureFilter.m; sourceTree = ""; }; + 843722861D4F260A002B398B /* GPUImageFalseColorFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFalseColorFilter.h; sourceTree = ""; }; + 843722871D4F260A002B398B /* GPUImageFalseColorFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFalseColorFilter.m; sourceTree = ""; }; + 843722881D4F260A002B398B /* GPUImageFASTCornerDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFASTCornerDetectionFilter.h; sourceTree = ""; }; + 843722891D4F260A002B398B /* GPUImageFASTCornerDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFASTCornerDetectionFilter.m; sourceTree = ""; }; + 8437228A1D4F260A002B398B /* GPUImageFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFilter.h; sourceTree = ""; }; + 8437228B1D4F260A002B398B /* GPUImageFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFilter.m; sourceTree = ""; }; + 8437228C1D4F260A002B398B /* GPUImageFilterGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFilterGroup.h; sourceTree = ""; }; + 8437228D1D4F260A002B398B /* GPUImageFilterGroup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFilterGroup.m; sourceTree = ""; }; + 8437228E1D4F260A002B398B /* GPUImageFilterPipeline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFilterPipeline.h; sourceTree = ""; }; + 8437228F1D4F260A002B398B /* GPUImageFilterPipeline.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFilterPipeline.m; sourceTree = ""; }; + 843722901D4F260A002B398B /* GPUImageFourInputFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFourInputFilter.h; sourceTree = ""; }; + 843722911D4F260A002B398B /* GPUImageFourInputFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFourInputFilter.m; sourceTree = ""; }; + 843722921D4F260A002B398B /* GPUImageFramebuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFramebuffer.h; sourceTree = ""; }; + 843722931D4F260A002B398B /* GPUImageFramebuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFramebuffer.m; sourceTree = ""; }; + 843722941D4F260A002B398B /* GPUImageFramebufferCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFramebufferCache.h; sourceTree = ""; }; + 843722951D4F260A002B398B /* GPUImageFramebufferCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageFramebufferCache.m; sourceTree = ""; }; + 843722961D4F260A002B398B /* GPUImageGammaFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageGammaFilter.h; sourceTree = ""; }; + 843722971D4F260A002B398B /* GPUImageGammaFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageGammaFilter.m; sourceTree = ""; }; + 843722981D4F260A002B398B /* GPUImageGaussianBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageGaussianBlurFilter.h; sourceTree = ""; }; + 843722991D4F260A002B398B /* GPUImageGaussianBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageGaussianBlurFilter.m; sourceTree = ""; }; + 8437229A1D4F260A002B398B /* GPUImageGaussianBlurPositionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageGaussianBlurPositionFilter.h; sourceTree = ""; }; + 8437229B1D4F260A002B398B /* GPUImageGaussianBlurPositionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageGaussianBlurPositionFilter.m; sourceTree = ""; }; + 8437229C1D4F260A002B398B /* GPUImageGaussianSelectiveBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageGaussianSelectiveBlurFilter.h; sourceTree = ""; }; + 8437229D1D4F260A002B398B /* GPUImageGaussianSelectiveBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageGaussianSelectiveBlurFilter.m; sourceTree = ""; }; + 8437229E1D4F260A002B398B /* GPUImageGlassSphereFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageGlassSphereFilter.h; sourceTree = ""; }; + 8437229F1D4F260A002B398B /* GPUImageGlassSphereFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageGlassSphereFilter.m; sourceTree = ""; }; + 843722A01D4F260A002B398B /* GPUImageGrayscaleFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageGrayscaleFilter.h; sourceTree = ""; }; + 843722A11D4F260A002B398B /* GPUImageGrayscaleFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageGrayscaleFilter.m; sourceTree = ""; }; + 843722A21D4F260A002B398B /* GPUImageHalftoneFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHalftoneFilter.h; sourceTree = ""; }; + 843722A31D4F260A002B398B /* GPUImageHalftoneFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHalftoneFilter.m; sourceTree = ""; }; + 843722A41D4F260A002B398B /* GPUImageHardLightBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHardLightBlendFilter.h; sourceTree = ""; }; + 843722A51D4F260A002B398B /* GPUImageHardLightBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHardLightBlendFilter.m; sourceTree = ""; }; + 843722A61D4F260A002B398B /* GPUImageHarrisCornerDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHarrisCornerDetectionFilter.h; sourceTree = ""; }; + 843722A71D4F260A002B398B /* GPUImageHarrisCornerDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHarrisCornerDetectionFilter.m; sourceTree = ""; }; + 843722A81D4F260A002B398B /* GPUImageHazeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHazeFilter.h; sourceTree = ""; }; + 843722A91D4F260A002B398B /* GPUImageHazeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHazeFilter.m; sourceTree = ""; }; + 843722AA1D4F260A002B398B /* GPUImageHighlightShadowFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHighlightShadowFilter.h; sourceTree = ""; }; + 843722AB1D4F260A002B398B /* GPUImageHighlightShadowFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHighlightShadowFilter.m; sourceTree = ""; }; + 843722AC1D4F260A002B398B /* GPUImageHighlightShadowTintFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHighlightShadowTintFilter.h; sourceTree = ""; }; + 843722AD1D4F260A002B398B /* GPUImageHighlightShadowTintFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHighlightShadowTintFilter.m; sourceTree = ""; }; + 843722AE1D4F260A002B398B /* GPUImageHighPassFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHighPassFilter.h; sourceTree = ""; }; + 843722AF1D4F260A002B398B /* GPUImageHighPassFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHighPassFilter.m; sourceTree = ""; }; + 843722B01D4F260A002B398B /* GPUImageHistogramEqualizationFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHistogramEqualizationFilter.h; sourceTree = ""; }; + 843722B11D4F260A002B398B /* GPUImageHistogramEqualizationFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHistogramEqualizationFilter.m; sourceTree = ""; }; + 843722B21D4F260A002B398B /* GPUImageHistogramFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHistogramFilter.h; sourceTree = ""; }; + 843722B31D4F260A002B398B /* GPUImageHistogramFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHistogramFilter.m; sourceTree = ""; }; + 843722B41D4F260A002B398B /* GPUImageHistogramGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHistogramGenerator.h; sourceTree = ""; }; + 843722B51D4F260A002B398B /* GPUImageHistogramGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHistogramGenerator.m; sourceTree = ""; }; + 843722B61D4F260A002B398B /* GPUImageHoughTransformLineDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHoughTransformLineDetector.h; sourceTree = ""; }; + 843722B71D4F260A002B398B /* GPUImageHoughTransformLineDetector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHoughTransformLineDetector.m; sourceTree = ""; }; + 843722B81D4F260A002B398B /* GPUImageHSBFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHSBFilter.h; sourceTree = ""; }; + 843722B91D4F260A002B398B /* GPUImageHSBFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHSBFilter.m; sourceTree = ""; }; + 843722BA1D4F260A002B398B /* GPUImageHueBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHueBlendFilter.h; sourceTree = ""; }; + 843722BB1D4F260A002B398B /* GPUImageHueBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHueBlendFilter.m; sourceTree = ""; }; + 843722BC1D4F260A002B398B /* GPUImageHueFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageHueFilter.h; sourceTree = ""; }; + 843722BD1D4F260A002B398B /* GPUImageHueFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageHueFilter.m; sourceTree = ""; }; + 843722BE1D4F260A002B398B /* GPUImageiOSBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageiOSBlurFilter.h; sourceTree = ""; }; + 843722BF1D4F260A002B398B /* GPUImageiOSBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageiOSBlurFilter.m; sourceTree = ""; }; + 843722C01D4F260A002B398B /* GPUImageJFAVoronoiFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageJFAVoronoiFilter.h; sourceTree = ""; }; + 843722C11D4F260A002B398B /* GPUImageJFAVoronoiFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageJFAVoronoiFilter.m; sourceTree = ""; }; + 843722C21D4F260A002B398B /* GPUImageKuwaharaFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageKuwaharaFilter.h; sourceTree = ""; }; + 843722C31D4F260A002B398B /* GPUImageKuwaharaFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageKuwaharaFilter.m; sourceTree = ""; }; + 843722C41D4F260A002B398B /* GPUImageKuwaharaRadius3Filter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageKuwaharaRadius3Filter.h; sourceTree = ""; }; + 843722C51D4F260A002B398B /* GPUImageKuwaharaRadius3Filter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageKuwaharaRadius3Filter.m; sourceTree = ""; }; + 843722C61D4F260A002B398B /* GPUImageLanczosResamplingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLanczosResamplingFilter.h; sourceTree = ""; }; + 843722C71D4F260A002B398B /* GPUImageLanczosResamplingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLanczosResamplingFilter.m; sourceTree = ""; }; + 843722C81D4F260A002B398B /* GPUImageLaplacianFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLaplacianFilter.h; sourceTree = ""; }; + 843722C91D4F260A002B398B /* GPUImageLaplacianFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLaplacianFilter.m; sourceTree = ""; }; + 843722CA1D4F260A002B398B /* GPUImageLevelsFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLevelsFilter.h; sourceTree = ""; }; + 843722CB1D4F260A002B398B /* GPUImageLevelsFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLevelsFilter.m; sourceTree = ""; }; + 843722CC1D4F260A002B398B /* GPUImageLightenBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLightenBlendFilter.h; sourceTree = ""; }; + 843722CD1D4F260A002B398B /* GPUImageLightenBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLightenBlendFilter.m; sourceTree = ""; }; + 843722CE1D4F260A002B398B /* GPUImageLinearBurnBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLinearBurnBlendFilter.h; sourceTree = ""; }; + 843722CF1D4F260A002B398B /* GPUImageLinearBurnBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLinearBurnBlendFilter.m; sourceTree = ""; }; + 843722D01D4F260A002B398B /* GPUImageLineGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLineGenerator.h; sourceTree = ""; }; + 843722D11D4F260A002B398B /* GPUImageLineGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLineGenerator.m; sourceTree = ""; }; + 843722D21D4F260A002B398B /* GPUImageLocalBinaryPatternFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLocalBinaryPatternFilter.h; sourceTree = ""; }; + 843722D31D4F260A002B398B /* GPUImageLocalBinaryPatternFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLocalBinaryPatternFilter.m; sourceTree = ""; }; + 843722D41D4F260A002B398B /* GPUImageLookupFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLookupFilter.h; sourceTree = ""; }; + 843722D51D4F260A002B398B /* GPUImageLookupFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLookupFilter.m; sourceTree = ""; }; + 843722D61D4F260A002B398B /* GPUImageLowPassFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLowPassFilter.h; sourceTree = ""; }; + 843722D71D4F260A002B398B /* GPUImageLowPassFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLowPassFilter.m; sourceTree = ""; }; + 843722D81D4F260A002B398B /* GPUImageLuminanceRangeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLuminanceRangeFilter.h; sourceTree = ""; }; + 843722D91D4F260A002B398B /* GPUImageLuminanceRangeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLuminanceRangeFilter.m; sourceTree = ""; }; + 843722DA1D4F260A002B398B /* GPUImageLuminanceThresholdFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLuminanceThresholdFilter.h; sourceTree = ""; }; + 843722DB1D4F260A002B398B /* GPUImageLuminanceThresholdFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLuminanceThresholdFilter.m; sourceTree = ""; }; + 843722DC1D4F260A002B398B /* GPUImageLuminosity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLuminosity.h; sourceTree = ""; }; + 843722DD1D4F260A002B398B /* GPUImageLuminosity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLuminosity.m; sourceTree = ""; }; + 843722DE1D4F260A002B398B /* GPUImageLuminosityBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageLuminosityBlendFilter.h; sourceTree = ""; }; + 843722DF1D4F260A002B398B /* GPUImageLuminosityBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageLuminosityBlendFilter.m; sourceTree = ""; }; + 843722E01D4F260A002B398B /* GPUImageMaskFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMaskFilter.h; sourceTree = ""; }; + 843722E11D4F260A002B398B /* GPUImageMaskFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMaskFilter.m; sourceTree = ""; }; + 843722E21D4F260A002B398B /* GPUImageMedianFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMedianFilter.h; sourceTree = ""; }; + 843722E31D4F260A002B398B /* GPUImageMedianFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMedianFilter.m; sourceTree = ""; }; + 843722E41D4F260A002B398B /* GPUImageMissEtikateFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMissEtikateFilter.h; sourceTree = ""; }; + 843722E51D4F260A002B398B /* GPUImageMissEtikateFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMissEtikateFilter.m; sourceTree = ""; }; + 843722E61D4F260A002B398B /* GPUImageMonochromeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMonochromeFilter.h; sourceTree = ""; }; + 843722E71D4F260A002B398B /* GPUImageMonochromeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMonochromeFilter.m; sourceTree = ""; }; + 843722E81D4F260A002B398B /* GPUImageMosaicFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMosaicFilter.h; sourceTree = ""; }; + 843722E91D4F260A002B398B /* GPUImageMosaicFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMosaicFilter.m; sourceTree = ""; }; + 843722EA1D4F260A002B398B /* GPUImageMotionBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMotionBlurFilter.h; sourceTree = ""; }; + 843722EB1D4F260A002B398B /* GPUImageMotionBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMotionBlurFilter.m; sourceTree = ""; }; + 843722EC1D4F260A002B398B /* GPUImageMotionDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMotionDetector.h; sourceTree = ""; }; + 843722ED1D4F260A002B398B /* GPUImageMotionDetector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMotionDetector.m; sourceTree = ""; }; + 843722EE1D4F260A002B398B /* GPUImageMovie.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMovie.h; sourceTree = ""; }; + 843722EF1D4F260A002B398B /* GPUImageMovie.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMovie.m; sourceTree = ""; }; + 843722F01D4F260A002B398B /* GPUImageMovieComposition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMovieComposition.h; sourceTree = ""; }; + 843722F11D4F260A002B398B /* GPUImageMovieComposition.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMovieComposition.m; sourceTree = ""; }; + 843722F21D4F260A002B398B /* GPUImageMultiplyBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMultiplyBlendFilter.h; sourceTree = ""; }; + 843722F31D4F260A002B398B /* GPUImageMultiplyBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMultiplyBlendFilter.m; sourceTree = ""; }; + 843722F41D4F260A002B398B /* GPUImageNobleCornerDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageNobleCornerDetectionFilter.h; sourceTree = ""; }; + 843722F51D4F260A002B398B /* GPUImageNobleCornerDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageNobleCornerDetectionFilter.m; sourceTree = ""; }; + 843722F61D4F260A002B398B /* GPUImageNonMaximumSuppressionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageNonMaximumSuppressionFilter.h; sourceTree = ""; }; + 843722F71D4F260A002B398B /* GPUImageNonMaximumSuppressionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageNonMaximumSuppressionFilter.m; sourceTree = ""; }; + 843722F81D4F260A002B398B /* GPUImageNormalBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageNormalBlendFilter.h; sourceTree = ""; }; + 843722F91D4F260A002B398B /* GPUImageNormalBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageNormalBlendFilter.m; sourceTree = ""; }; + 843722FA1D4F260A002B398B /* GPUImageOpacityFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageOpacityFilter.h; sourceTree = ""; }; + 843722FB1D4F260A002B398B /* GPUImageOpacityFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageOpacityFilter.m; sourceTree = ""; }; + 843722FC1D4F260A002B398B /* GPUImageOpeningFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageOpeningFilter.h; sourceTree = ""; }; + 843722FD1D4F260A002B398B /* GPUImageOpeningFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageOpeningFilter.m; sourceTree = ""; }; + 843722FE1D4F260A002B398B /* GPUImageOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageOutput.h; sourceTree = ""; }; + 843722FF1D4F260A002B398B /* GPUImageOutput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageOutput.m; sourceTree = ""; }; + 843723001D4F260A002B398B /* GPUImageOverlayBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageOverlayBlendFilter.h; sourceTree = ""; }; + 843723011D4F260A002B398B /* GPUImageOverlayBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageOverlayBlendFilter.m; sourceTree = ""; }; + 843723021D4F260A002B398B /* GPUImageParallelCoordinateLineTransformFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageParallelCoordinateLineTransformFilter.h; sourceTree = ""; }; + 843723031D4F260A002B398B /* GPUImageParallelCoordinateLineTransformFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageParallelCoordinateLineTransformFilter.m; sourceTree = ""; }; + 843723041D4F260A002B398B /* GPUImagePerlinNoiseFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePerlinNoiseFilter.h; sourceTree = ""; }; + 843723051D4F260A002B398B /* GPUImagePerlinNoiseFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePerlinNoiseFilter.m; sourceTree = ""; }; + 843723061D4F260A002B398B /* GPUImagePinchDistortionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePinchDistortionFilter.h; sourceTree = ""; }; + 843723071D4F260A002B398B /* GPUImagePinchDistortionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePinchDistortionFilter.m; sourceTree = ""; }; + 843723081D4F260A002B398B /* GPUImagePixellateFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePixellateFilter.h; sourceTree = ""; }; + 843723091D4F260A002B398B /* GPUImagePixellateFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePixellateFilter.m; sourceTree = ""; }; + 8437230A1D4F260A002B398B /* GPUImagePixellatePositionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePixellatePositionFilter.h; sourceTree = ""; }; + 8437230B1D4F260A002B398B /* GPUImagePixellatePositionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePixellatePositionFilter.m; sourceTree = ""; }; + 8437230C1D4F260A002B398B /* GPUImagePoissonBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePoissonBlendFilter.h; sourceTree = ""; }; + 8437230D1D4F260A002B398B /* GPUImagePoissonBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePoissonBlendFilter.m; sourceTree = ""; }; + 8437230E1D4F260A002B398B /* GPUImagePolarPixellateFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePolarPixellateFilter.h; sourceTree = ""; }; + 8437230F1D4F260A002B398B /* GPUImagePolarPixellateFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePolarPixellateFilter.m; sourceTree = ""; }; + 843723101D4F260A002B398B /* GPUImagePolkaDotFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePolkaDotFilter.h; sourceTree = ""; }; + 843723111D4F260A002B398B /* GPUImagePolkaDotFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePolkaDotFilter.m; sourceTree = ""; }; + 843723121D4F260A002B398B /* GPUImagePosterizeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePosterizeFilter.h; sourceTree = ""; }; + 843723131D4F260A002B398B /* GPUImagePosterizeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePosterizeFilter.m; sourceTree = ""; }; + 843723141D4F260A002B398B /* GPUImagePrewittEdgeDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePrewittEdgeDetectionFilter.h; sourceTree = ""; }; + 843723151D4F260A002B398B /* GPUImagePrewittEdgeDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePrewittEdgeDetectionFilter.m; sourceTree = ""; }; + 843723161D4F260A002B398B /* GPUImageRawDataInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRawDataInput.h; sourceTree = ""; }; + 843723171D4F260A002B398B /* GPUImageRawDataInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRawDataInput.m; sourceTree = ""; }; + 843723181D4F260A002B398B /* GPUImageRawDataOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRawDataOutput.h; sourceTree = ""; }; + 843723191D4F260A002B398B /* GPUImageRawDataOutput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRawDataOutput.m; sourceTree = ""; }; + 8437231A1D4F260A002B398B /* GPUImageRGBClosingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRGBClosingFilter.h; sourceTree = ""; }; + 8437231B1D4F260A002B398B /* GPUImageRGBClosingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRGBClosingFilter.m; sourceTree = ""; }; + 8437231C1D4F260A002B398B /* GPUImageRGBDilationFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRGBDilationFilter.h; sourceTree = ""; }; + 8437231D1D4F260A002B398B /* GPUImageRGBDilationFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRGBDilationFilter.m; sourceTree = ""; }; + 8437231E1D4F260A002B398B /* GPUImageRGBErosionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRGBErosionFilter.h; sourceTree = ""; }; + 8437231F1D4F260A002B398B /* GPUImageRGBErosionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRGBErosionFilter.m; sourceTree = ""; }; + 843723201D4F260A002B398B /* GPUImageRGBFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRGBFilter.h; sourceTree = ""; }; + 843723211D4F260A002B398B /* GPUImageRGBFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRGBFilter.m; sourceTree = ""; }; + 843723221D4F260A002B398B /* GPUImageRGBOpeningFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageRGBOpeningFilter.h; sourceTree = ""; }; + 843723231D4F260A002B398B /* GPUImageRGBOpeningFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageRGBOpeningFilter.m; sourceTree = ""; }; + 843723241D4F260A002B398B /* GPUImageSaturationBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSaturationBlendFilter.h; sourceTree = ""; }; + 843723251D4F260A002B398B /* GPUImageSaturationBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSaturationBlendFilter.m; sourceTree = ""; }; + 843723261D4F260A002B398B /* GPUImageSaturationFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSaturationFilter.h; sourceTree = ""; }; + 843723271D4F260A002B398B /* GPUImageSaturationFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSaturationFilter.m; sourceTree = ""; }; + 843723281D4F260A002B398B /* GPUImageScreenBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageScreenBlendFilter.h; sourceTree = ""; }; + 843723291D4F260A002B398B /* GPUImageScreenBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageScreenBlendFilter.m; sourceTree = ""; }; + 8437232A1D4F260A002B398B /* GPUImageSepiaFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSepiaFilter.h; sourceTree = ""; }; + 8437232B1D4F260A002B398B /* GPUImageSepiaFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSepiaFilter.m; sourceTree = ""; }; + 8437232C1D4F260A002B398B /* GPUImageSharpenFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSharpenFilter.h; sourceTree = ""; }; + 8437232D1D4F260A002B398B /* GPUImageSharpenFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSharpenFilter.m; sourceTree = ""; }; + 8437232E1D4F260A002B398B /* GPUImageShiTomasiFeatureDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageShiTomasiFeatureDetectionFilter.h; sourceTree = ""; }; + 8437232F1D4F260A002B398B /* GPUImageShiTomasiFeatureDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageShiTomasiFeatureDetectionFilter.m; sourceTree = ""; }; + 843723301D4F260A002B398B /* GPUImageSingleComponentGaussianBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSingleComponentGaussianBlurFilter.h; sourceTree = ""; }; + 843723311D4F260A002B398B /* GPUImageSingleComponentGaussianBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSingleComponentGaussianBlurFilter.m; sourceTree = ""; }; + 843723321D4F260A002B398B /* GPUImageSketchFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSketchFilter.h; sourceTree = ""; }; + 843723331D4F260A002B398B /* GPUImageSketchFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSketchFilter.m; sourceTree = ""; }; + 843723341D4F260A002B398B /* GPUImageSkinToneFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSkinToneFilter.h; sourceTree = ""; }; + 843723351D4F260A002B398B /* GPUImageSkinToneFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSkinToneFilter.m; sourceTree = ""; }; + 843723361D4F260A002B398B /* GPUImageSmoothToonFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSmoothToonFilter.h; sourceTree = ""; }; + 843723371D4F260A002B398B /* GPUImageSmoothToonFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSmoothToonFilter.m; sourceTree = ""; }; + 843723381D4F260A002B398B /* GPUImageSobelEdgeDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSobelEdgeDetectionFilter.h; sourceTree = ""; }; + 843723391D4F260A002B398B /* GPUImageSobelEdgeDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSobelEdgeDetectionFilter.m; sourceTree = ""; }; + 8437233A1D4F260A002B398B /* GPUImageSoftEleganceFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSoftEleganceFilter.h; sourceTree = ""; }; + 8437233B1D4F260A002B398B /* GPUImageSoftEleganceFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSoftEleganceFilter.m; sourceTree = ""; }; + 8437233C1D4F260A002B398B /* GPUImageSoftLightBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSoftLightBlendFilter.h; sourceTree = ""; }; + 8437233D1D4F260A002B398B /* GPUImageSoftLightBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSoftLightBlendFilter.m; sourceTree = ""; }; + 8437233E1D4F260A002B398B /* GPUImageSolarizeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSolarizeFilter.h; sourceTree = ""; }; + 8437233F1D4F260A002B398B /* GPUImageSolarizeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSolarizeFilter.m; sourceTree = ""; }; + 843723401D4F260A002B398B /* GPUImageSolidColorGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSolidColorGenerator.h; sourceTree = ""; }; + 843723411D4F260A002B398B /* GPUImageSolidColorGenerator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSolidColorGenerator.m; sourceTree = ""; }; + 843723421D4F260A002B398B /* GPUImageSourceOverBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSourceOverBlendFilter.h; sourceTree = ""; }; + 843723431D4F260A002B398B /* GPUImageSourceOverBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSourceOverBlendFilter.m; sourceTree = ""; }; + 843723441D4F260A002B398B /* GPUImageSphereRefractionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSphereRefractionFilter.h; sourceTree = ""; }; + 843723451D4F260A002B398B /* GPUImageSphereRefractionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSphereRefractionFilter.m; sourceTree = ""; }; + 843723461D4F260A002B398B /* GPUImageStillCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageStillCamera.h; sourceTree = ""; }; + 843723471D4F260A002B398B /* GPUImageStillCamera.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageStillCamera.m; sourceTree = ""; }; + 843723481D4F260A002B398B /* GPUImageStretchDistortionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageStretchDistortionFilter.h; sourceTree = ""; }; + 843723491D4F260A002B398B /* GPUImageStretchDistortionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageStretchDistortionFilter.m; sourceTree = ""; }; + 8437234A1D4F260A002B398B /* GPUImageSubtractBlendFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSubtractBlendFilter.h; sourceTree = ""; }; + 8437234B1D4F260A002B398B /* GPUImageSubtractBlendFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSubtractBlendFilter.m; sourceTree = ""; }; + 8437234C1D4F260A002B398B /* GPUImageSwirlFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageSwirlFilter.h; sourceTree = ""; }; + 8437234D1D4F260A002B398B /* GPUImageSwirlFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageSwirlFilter.m; sourceTree = ""; }; + 8437234E1D4F260A002B398B /* GPUImageTextureInput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTextureInput.h; sourceTree = ""; }; + 8437234F1D4F260A002B398B /* GPUImageTextureInput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTextureInput.m; sourceTree = ""; }; + 843723501D4F260A002B398B /* GPUImageTextureOutput.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTextureOutput.h; sourceTree = ""; }; + 843723511D4F260A002B398B /* GPUImageTextureOutput.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTextureOutput.m; sourceTree = ""; }; + 843723521D4F260A002B398B /* GPUImageThreeInputFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageThreeInputFilter.h; sourceTree = ""; }; + 843723531D4F260A002B398B /* GPUImageThreeInputFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageThreeInputFilter.m; sourceTree = ""; }; + 843723541D4F260A002B398B /* GPUImageThresholdEdgeDetectionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageThresholdEdgeDetectionFilter.h; sourceTree = ""; }; + 843723551D4F260A002B398B /* GPUImageThresholdEdgeDetectionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageThresholdEdgeDetectionFilter.m; sourceTree = ""; }; + 843723561D4F260A002B398B /* GPUImageThresholdedNonMaximumSuppressionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageThresholdedNonMaximumSuppressionFilter.h; sourceTree = ""; }; + 843723571D4F260A002B398B /* GPUImageThresholdedNonMaximumSuppressionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageThresholdedNonMaximumSuppressionFilter.m; sourceTree = ""; }; + 843723581D4F260A002B398B /* GPUImageThresholdSketchFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageThresholdSketchFilter.h; sourceTree = ""; }; + 843723591D4F260A002B398B /* GPUImageThresholdSketchFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageThresholdSketchFilter.m; sourceTree = ""; }; + 8437235A1D4F260A002B398B /* GPUImageTiltShiftFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTiltShiftFilter.h; sourceTree = ""; }; + 8437235B1D4F260A002B398B /* GPUImageTiltShiftFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTiltShiftFilter.m; sourceTree = ""; }; + 8437235C1D4F260A002B398B /* GPUImageToneCurveFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageToneCurveFilter.h; sourceTree = ""; }; + 8437235D1D4F260A002B398B /* GPUImageToneCurveFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageToneCurveFilter.m; sourceTree = ""; }; + 8437235E1D4F260A002B398B /* GPUImageToonFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageToonFilter.h; sourceTree = ""; }; + 8437235F1D4F260A002B398B /* GPUImageToonFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageToonFilter.m; sourceTree = ""; }; + 843723601D4F260A002B398B /* GPUImageTransformFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTransformFilter.h; sourceTree = ""; }; + 843723611D4F260A002B398B /* GPUImageTransformFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTransformFilter.m; sourceTree = ""; }; + 843723621D4F260A002B398B /* GPUImageTwoInputCrossTextureSamplingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTwoInputCrossTextureSamplingFilter.h; sourceTree = ""; }; + 843723631D4F260A002B398B /* GPUImageTwoInputCrossTextureSamplingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTwoInputCrossTextureSamplingFilter.m; sourceTree = ""; }; + 843723641D4F260A002B398B /* GPUImageTwoInputFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTwoInputFilter.h; sourceTree = ""; }; + 843723651D4F260A002B398B /* GPUImageTwoInputFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTwoInputFilter.m; sourceTree = ""; }; + 843723661D4F260A002B398B /* GPUImageTwoPassFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTwoPassFilter.h; sourceTree = ""; }; + 843723671D4F260A002B398B /* GPUImageTwoPassFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTwoPassFilter.m; sourceTree = ""; }; + 843723681D4F260A002B398B /* GPUImageTwoPassTextureSamplingFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageTwoPassTextureSamplingFilter.h; sourceTree = ""; }; + 843723691D4F260A002B398B /* GPUImageTwoPassTextureSamplingFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageTwoPassTextureSamplingFilter.m; sourceTree = ""; }; + 8437236A1D4F260A002B398B /* GPUImageUIElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageUIElement.h; sourceTree = ""; }; + 8437236B1D4F260A002B398B /* GPUImageUIElement.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageUIElement.m; sourceTree = ""; }; + 8437236C1D4F260A002B398B /* GPUImageUnsharpMaskFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageUnsharpMaskFilter.h; sourceTree = ""; }; + 8437236D1D4F260A002B398B /* GPUImageUnsharpMaskFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageUnsharpMaskFilter.m; sourceTree = ""; }; + 8437236E1D4F260A002B398B /* GPUImageVideoCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageVideoCamera.h; sourceTree = ""; }; + 8437236F1D4F260A002B398B /* GPUImageVideoCamera.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageVideoCamera.m; sourceTree = ""; }; + 843723701D4F260A002B398B /* GPUImageVignetteFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageVignetteFilter.h; sourceTree = ""; }; + 843723711D4F260A002B398B /* GPUImageVignetteFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageVignetteFilter.m; sourceTree = ""; }; + 843723721D4F260A002B398B /* GPUImageVoronoiConsumerFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageVoronoiConsumerFilter.h; sourceTree = ""; }; + 843723731D4F260A002B398B /* GPUImageVoronoiConsumerFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageVoronoiConsumerFilter.m; sourceTree = ""; }; + 843723741D4F260A002B398B /* GPUImageWeakPixelInclusionFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageWeakPixelInclusionFilter.h; sourceTree = ""; }; + 843723751D4F260A002B398B /* GPUImageWeakPixelInclusionFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageWeakPixelInclusionFilter.m; sourceTree = ""; }; + 843723761D4F260A002B398B /* GPUImageWhiteBalanceFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageWhiteBalanceFilter.h; sourceTree = ""; }; + 843723771D4F260A002B398B /* GPUImageWhiteBalanceFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageWhiteBalanceFilter.m; sourceTree = ""; }; + 843723781D4F260A002B398B /* GPUImageXYDerivativeFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageXYDerivativeFilter.h; sourceTree = ""; }; + 843723791D4F260A002B398B /* GPUImageXYDerivativeFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageXYDerivativeFilter.m; sourceTree = ""; }; + 8437237A1D4F260A002B398B /* GPUImageZoomBlurFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageZoomBlurFilter.h; sourceTree = ""; }; + 8437237B1D4F260A002B398B /* GPUImageZoomBlurFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageZoomBlurFilter.m; sourceTree = ""; }; + 8437237E1D4F260A002B398B /* GPUImageFramework.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageFramework.h; sourceTree = ""; }; + 8437237F1D4F260A002B398B /* GPUImageContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageContext.h; sourceTree = ""; }; + 843723801D4F260A002B398B /* GPUImageContext.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageContext.m; sourceTree = ""; }; + 843723811D4F260A002B398B /* GPUImageMovieWriter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageMovieWriter.h; sourceTree = ""; }; + 843723821D4F260A002B398B /* GPUImageMovieWriter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageMovieWriter.m; sourceTree = ""; }; + 843723831D4F260A002B398B /* GPUImagePicture+TextureSubimage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "GPUImagePicture+TextureSubimage.h"; sourceTree = ""; }; + 843723841D4F260A002B398B /* GPUImagePicture+TextureSubimage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "GPUImagePicture+TextureSubimage.m"; sourceTree = ""; }; + 843723851D4F260A002B398B /* GPUImagePicture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImagePicture.h; sourceTree = ""; }; + 843723861D4F260A002B398B /* GPUImagePicture.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImagePicture.m; sourceTree = ""; }; + 843723871D4F260A002B398B /* GPUImageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GPUImageView.h; sourceTree = ""; }; + 843723881D4F260A002B398B /* GPUImageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GPUImageView.m; sourceTree = ""; }; + 8437238A1D4F260A002B398B /* amf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = amf.c; sourceTree = ""; }; + 8437238B1D4F260A002B398B /* amf.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = amf.h; sourceTree = ""; }; + 8437238C1D4F260A002B398B /* bytes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bytes.h; sourceTree = ""; }; + 8437238D1D4F260A002B398B /* dh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dh.h; sourceTree = ""; }; + 8437238E1D4F260A002B398B /* dhgroups.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dhgroups.h; sourceTree = ""; }; + 8437238F1D4F260A002B398B /* error.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = error.c; sourceTree = ""; }; + 843723901D4F260A002B398B /* error.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = error.h; sourceTree = ""; }; + 843723911D4F260A002B398B /* handshake.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = handshake.h; sourceTree = ""; }; + 843723921D4F260A002B398B /* hashswf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hashswf.c; sourceTree = ""; }; + 843723931D4F260A002B398B /* http.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = http.h; sourceTree = ""; }; + 843723941D4F260A002B398B /* log.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = log.c; sourceTree = ""; }; + 843723951D4F260A002B398B /* log.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = log.h; sourceTree = ""; }; + 843723961D4F260A002B398B /* parseurl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = parseurl.c; sourceTree = ""; }; + 843723971D4F260A002B398B /* rtmp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = rtmp.c; sourceTree = ""; }; + 843723981D4F260A002B398B /* rtmp.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rtmp.h; sourceTree = ""; }; + 843723991D4F260A002B398B /* rtmp_sys.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = rtmp_sys.h; sourceTree = ""; }; B289F1D41D3DE77F00D9C7A5 /* LFStreamingBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LFStreamingBuffer.h; path = LFLiveKit/publish/LFStreamingBuffer.h; sourceTree = SOURCE_ROOT; }; B289F1D51D3DE77F00D9C7A5 /* LFStreamingBuffer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = LFStreamingBuffer.m; path = LFLiveKit/publish/LFStreamingBuffer.m; sourceTree = SOURCE_ROOT; }; B289F1D61D3DE77F00D9C7A5 /* LFStreamRtmpSocket.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LFStreamRtmpSocket.h; path = LFLiveKit/publish/LFStreamRtmpSocket.h; sourceTree = SOURCE_ROOT; }; @@ -140,9 +862,7 @@ B2CD146A1D45F18B008082E8 /* LFVideoEncoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LFVideoEncoder.m; sourceTree = ""; }; B2CD146B1D45F18B008082E8 /* LFH264VideoEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LFH264VideoEncoder.h; sourceTree = ""; }; B2CD146C1D45F18B008082E8 /* LFH264VideoEncoder.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LFH264VideoEncoder.mm; sourceTree = ""; }; - B5758EB2A15DAA132D8BF380 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; - B75B965E6B94DE4CBCC82EA7 /* Pods-LFLiveKit.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKit.release.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKit/Pods-LFLiveKit.release.xcconfig"; sourceTree = ""; }; - B8CB02D2A92EA1F5A262F154 /* libPods-LFLiveKit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LFLiveKit.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + D0BB7E7CE5403C4911E026B9 /* Pods-LFLiveKit.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKit.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKit/Pods-LFLiveKit.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -156,8 +876,6 @@ 84001FFB1D0017630026C63F /* UIKit.framework in Frameworks */, 84001FF91D00175D0026C63F /* Foundation.framework in Frameworks */, 84001FF71D0017590026C63F /* AVFoundation.framework in Frameworks */, - AD7F89B4621A7EFEBEA72D49 /* libPods-LFLiveKit.a in Frameworks */, - BE55DA79155500CDEF87FB5C /* libPods.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -181,20 +899,27 @@ 84001FFA1D0017630026C63F /* UIKit.framework */, 84001FF81D00175D0026C63F /* Foundation.framework */, 84001FF61D0017590026C63F /* AVFoundation.framework */, - B8CB02D2A92EA1F5A262F154 /* libPods-LFLiveKit.a */, - B5758EB2A15DAA132D8BF380 /* libPods.a */, ); name = Frameworks; sourceTree = ""; }; + 4FDA0F424950EEA14E09E312 /* Pods */ = { + isa = PBXGroup; + children = ( + D0BB7E7CE5403C4911E026B9 /* Pods-LFLiveKit.debug.xcconfig */, + 0BA5A0CE1F07E1D707F69735 /* Pods-LFLiveKit.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; 84001F801D0015D10026C63F = { isa = PBXGroup; children = ( 84001F8C1D0015D10026C63F /* LFLiveKit */, 84001F981D0015D10026C63F /* LFLiveKitTests */, 84001F8B1D0015D10026C63F /* Products */, - EDD4B76A07A6817C79BB4E5C /* Pods */, 0C07D14560B9E91EA1B59306 /* Frameworks */, + 4FDA0F424950EEA14E09E312 /* Pods */, ); sourceTree = ""; }; @@ -219,6 +944,7 @@ 84001FA91D0016380026C63F /* coder */, 84001FB51D0016380026C63F /* filter */, 84001FC91D0016380026C63F /* publish */, + 8437222B1D4F260A002B398B /* Vendor */, 84001F8F1D0015D10026C63F /* Info.plist */, ); path = LFLiveKit; @@ -314,6 +1040,407 @@ path = upload; sourceTree = ""; }; + 8437222B1D4F260A002B398B /* Vendor */ = { + isa = PBXGroup; + children = ( + 8437222C1D4F260A002B398B /* GPUImage */, + 843723891D4F260A002B398B /* pili-librtmp */, + ); + path = Vendor; + sourceTree = ""; + }; + 8437222C1D4F260A002B398B /* GPUImage */ = { + isa = PBXGroup; + children = ( + 8437222D1D4F260A002B398B /* GLProgram.h */, + 8437222E1D4F260A002B398B /* GLProgram.m */, + 8437222F1D4F260A002B398B /* GPUImage.h */, + 843722301D4F260A002B398B /* GPUImage3x3ConvolutionFilter.h */, + 843722311D4F260A002B398B /* GPUImage3x3ConvolutionFilter.m */, + 843722321D4F260A002B398B /* GPUImage3x3TextureSamplingFilter.h */, + 843722331D4F260A002B398B /* GPUImage3x3TextureSamplingFilter.m */, + 843722341D4F260A002B398B /* GPUImageAdaptiveThresholdFilter.h */, + 843722351D4F260A002B398B /* GPUImageAdaptiveThresholdFilter.m */, + 843722361D4F260A002B398B /* GPUImageAddBlendFilter.h */, + 843722371D4F260A002B398B /* GPUImageAddBlendFilter.m */, + 843722381D4F260A002B398B /* GPUImageAlphaBlendFilter.h */, + 843722391D4F260A002B398B /* GPUImageAlphaBlendFilter.m */, + 8437223A1D4F260A002B398B /* GPUImageAmatorkaFilter.h */, + 8437223B1D4F260A002B398B /* GPUImageAmatorkaFilter.m */, + 8437223C1D4F260A002B398B /* GPUImageAverageColor.h */, + 8437223D1D4F260A002B398B /* GPUImageAverageColor.m */, + 8437223E1D4F260A002B398B /* GPUImageAverageLuminanceThresholdFilter.h */, + 8437223F1D4F260A002B398B /* GPUImageAverageLuminanceThresholdFilter.m */, + 843722401D4F260A002B398B /* GPUImageBilateralFilter.h */, + 843722411D4F260A002B398B /* GPUImageBilateralFilter.m */, + 843722421D4F260A002B398B /* GPUImageBoxBlurFilter.h */, + 843722431D4F260A002B398B /* GPUImageBoxBlurFilter.m */, + 843722441D4F260A002B398B /* GPUImageBrightnessFilter.h */, + 843722451D4F260A002B398B /* GPUImageBrightnessFilter.m */, + 843722461D4F260A002B398B /* GPUImageBuffer.h */, + 843722471D4F260A002B398B /* GPUImageBuffer.m */, + 843722481D4F260A002B398B /* GPUImageBulgeDistortionFilter.h */, + 843722491D4F260A002B398B /* GPUImageBulgeDistortionFilter.m */, + 8437224A1D4F260A002B398B /* GPUImageCannyEdgeDetectionFilter.h */, + 8437224B1D4F260A002B398B /* GPUImageCannyEdgeDetectionFilter.m */, + 8437224C1D4F260A002B398B /* GPUImageCGAColorspaceFilter.h */, + 8437224D1D4F260A002B398B /* GPUImageCGAColorspaceFilter.m */, + 8437224E1D4F260A002B398B /* GPUImageChromaKeyBlendFilter.h */, + 8437224F1D4F260A002B398B /* GPUImageChromaKeyBlendFilter.m */, + 843722501D4F260A002B398B /* GPUImageChromaKeyFilter.h */, + 843722511D4F260A002B398B /* GPUImageChromaKeyFilter.m */, + 843722521D4F260A002B398B /* GPUImageClosingFilter.h */, + 843722531D4F260A002B398B /* GPUImageClosingFilter.m */, + 843722541D4F260A002B398B /* GPUImageColorBlendFilter.h */, + 843722551D4F260A002B398B /* GPUImageColorBlendFilter.m */, + 843722561D4F260A002B398B /* GPUImageColorBurnBlendFilter.h */, + 843722571D4F260A002B398B /* GPUImageColorBurnBlendFilter.m */, + 843722581D4F260A002B398B /* GPUImageColorConversion.h */, + 843722591D4F260A002B398B /* GPUImageColorConversion.m */, + 8437225A1D4F260A002B398B /* GPUImageColorDodgeBlendFilter.h */, + 8437225B1D4F260A002B398B /* GPUImageColorDodgeBlendFilter.m */, + 8437225C1D4F260A002B398B /* GPUImageColorInvertFilter.h */, + 8437225D1D4F260A002B398B /* GPUImageColorInvertFilter.m */, + 8437225E1D4F260A002B398B /* GPUImageColorLocalBinaryPatternFilter.h */, + 8437225F1D4F260A002B398B /* GPUImageColorLocalBinaryPatternFilter.m */, + 843722601D4F260A002B398B /* GPUImageColorMatrixFilter.h */, + 843722611D4F260A002B398B /* GPUImageColorMatrixFilter.m */, + 843722621D4F260A002B398B /* GPUImageColorPackingFilter.h */, + 843722631D4F260A002B398B /* GPUImageColorPackingFilter.m */, + 843722641D4F260A002B398B /* GPUImageColourFASTFeatureDetector.h */, + 843722651D4F260A002B398B /* GPUImageColourFASTFeatureDetector.m */, + 843722661D4F260A002B398B /* GPUImageColourFASTSamplingOperation.h */, + 843722671D4F260A002B398B /* GPUImageColourFASTSamplingOperation.m */, + 843722681D4F260A002B398B /* GPUImageContrastFilter.h */, + 843722691D4F260A002B398B /* GPUImageContrastFilter.m */, + 8437226A1D4F260A002B398B /* GPUImageCropFilter.h */, + 8437226B1D4F260A002B398B /* GPUImageCropFilter.m */, + 8437226C1D4F260A002B398B /* GPUImageCrosshairGenerator.h */, + 8437226D1D4F260A002B398B /* GPUImageCrosshairGenerator.m */, + 8437226E1D4F260A002B398B /* GPUImageCrosshatchFilter.h */, + 8437226F1D4F260A002B398B /* GPUImageCrosshatchFilter.m */, + 843722701D4F260A002B398B /* GPUImageDarkenBlendFilter.h */, + 843722711D4F260A002B398B /* GPUImageDarkenBlendFilter.m */, + 843722721D4F260A002B398B /* GPUImageDifferenceBlendFilter.h */, + 843722731D4F260A002B398B /* GPUImageDifferenceBlendFilter.m */, + 843722741D4F260A002B398B /* GPUImageDilationFilter.h */, + 843722751D4F260A002B398B /* GPUImageDilationFilter.m */, + 843722761D4F260A002B398B /* GPUImageDirectionalNonMaximumSuppressionFilter.h */, + 843722771D4F260A002B398B /* GPUImageDirectionalNonMaximumSuppressionFilter.m */, + 843722781D4F260A002B398B /* GPUImageDirectionalSobelEdgeDetectionFilter.h */, + 843722791D4F260A002B398B /* GPUImageDirectionalSobelEdgeDetectionFilter.m */, + 8437227A1D4F260A002B398B /* GPUImageDissolveBlendFilter.h */, + 8437227B1D4F260A002B398B /* GPUImageDissolveBlendFilter.m */, + 8437227C1D4F260A002B398B /* GPUImageDivideBlendFilter.h */, + 8437227D1D4F260A002B398B /* GPUImageDivideBlendFilter.m */, + 8437227E1D4F260A002B398B /* GPUImageEmbossFilter.h */, + 8437227F1D4F260A002B398B /* GPUImageEmbossFilter.m */, + 843722801D4F260A002B398B /* GPUImageErosionFilter.h */, + 843722811D4F260A002B398B /* GPUImageErosionFilter.m */, + 843722821D4F260A002B398B /* GPUImageExclusionBlendFilter.h */, + 843722831D4F260A002B398B /* GPUImageExclusionBlendFilter.m */, + 843722841D4F260A002B398B /* GPUImageExposureFilter.h */, + 843722851D4F260A002B398B /* GPUImageExposureFilter.m */, + 843722861D4F260A002B398B /* GPUImageFalseColorFilter.h */, + 843722871D4F260A002B398B /* GPUImageFalseColorFilter.m */, + 843722881D4F260A002B398B /* GPUImageFASTCornerDetectionFilter.h */, + 843722891D4F260A002B398B /* GPUImageFASTCornerDetectionFilter.m */, + 8437228A1D4F260A002B398B /* GPUImageFilter.h */, + 8437228B1D4F260A002B398B /* GPUImageFilter.m */, + 8437228C1D4F260A002B398B /* GPUImageFilterGroup.h */, + 8437228D1D4F260A002B398B /* GPUImageFilterGroup.m */, + 8437228E1D4F260A002B398B /* GPUImageFilterPipeline.h */, + 8437228F1D4F260A002B398B /* GPUImageFilterPipeline.m */, + 843722901D4F260A002B398B /* GPUImageFourInputFilter.h */, + 843722911D4F260A002B398B /* GPUImageFourInputFilter.m */, + 843722921D4F260A002B398B /* GPUImageFramebuffer.h */, + 843722931D4F260A002B398B /* GPUImageFramebuffer.m */, + 843722941D4F260A002B398B /* GPUImageFramebufferCache.h */, + 843722951D4F260A002B398B /* GPUImageFramebufferCache.m */, + 843722961D4F260A002B398B /* GPUImageGammaFilter.h */, + 843722971D4F260A002B398B /* GPUImageGammaFilter.m */, + 843722981D4F260A002B398B /* GPUImageGaussianBlurFilter.h */, + 843722991D4F260A002B398B /* GPUImageGaussianBlurFilter.m */, + 8437229A1D4F260A002B398B /* GPUImageGaussianBlurPositionFilter.h */, + 8437229B1D4F260A002B398B /* GPUImageGaussianBlurPositionFilter.m */, + 8437229C1D4F260A002B398B /* GPUImageGaussianSelectiveBlurFilter.h */, + 8437229D1D4F260A002B398B /* GPUImageGaussianSelectiveBlurFilter.m */, + 8437229E1D4F260A002B398B /* GPUImageGlassSphereFilter.h */, + 8437229F1D4F260A002B398B /* GPUImageGlassSphereFilter.m */, + 843722A01D4F260A002B398B /* GPUImageGrayscaleFilter.h */, + 843722A11D4F260A002B398B /* GPUImageGrayscaleFilter.m */, + 843722A21D4F260A002B398B /* GPUImageHalftoneFilter.h */, + 843722A31D4F260A002B398B /* GPUImageHalftoneFilter.m */, + 843722A41D4F260A002B398B /* GPUImageHardLightBlendFilter.h */, + 843722A51D4F260A002B398B /* GPUImageHardLightBlendFilter.m */, + 843722A61D4F260A002B398B /* GPUImageHarrisCornerDetectionFilter.h */, + 843722A71D4F260A002B398B /* GPUImageHarrisCornerDetectionFilter.m */, + 843722A81D4F260A002B398B /* GPUImageHazeFilter.h */, + 843722A91D4F260A002B398B /* GPUImageHazeFilter.m */, + 843722AA1D4F260A002B398B /* GPUImageHighlightShadowFilter.h */, + 843722AB1D4F260A002B398B /* GPUImageHighlightShadowFilter.m */, + 843722AC1D4F260A002B398B /* GPUImageHighlightShadowTintFilter.h */, + 843722AD1D4F260A002B398B /* GPUImageHighlightShadowTintFilter.m */, + 843722AE1D4F260A002B398B /* GPUImageHighPassFilter.h */, + 843722AF1D4F260A002B398B /* GPUImageHighPassFilter.m */, + 843722B01D4F260A002B398B /* GPUImageHistogramEqualizationFilter.h */, + 843722B11D4F260A002B398B /* GPUImageHistogramEqualizationFilter.m */, + 843722B21D4F260A002B398B /* GPUImageHistogramFilter.h */, + 843722B31D4F260A002B398B /* GPUImageHistogramFilter.m */, + 843722B41D4F260A002B398B /* GPUImageHistogramGenerator.h */, + 843722B51D4F260A002B398B /* GPUImageHistogramGenerator.m */, + 843722B61D4F260A002B398B /* GPUImageHoughTransformLineDetector.h */, + 843722B71D4F260A002B398B /* GPUImageHoughTransformLineDetector.m */, + 843722B81D4F260A002B398B /* GPUImageHSBFilter.h */, + 843722B91D4F260A002B398B /* GPUImageHSBFilter.m */, + 843722BA1D4F260A002B398B /* GPUImageHueBlendFilter.h */, + 843722BB1D4F260A002B398B /* GPUImageHueBlendFilter.m */, + 843722BC1D4F260A002B398B /* GPUImageHueFilter.h */, + 843722BD1D4F260A002B398B /* GPUImageHueFilter.m */, + 843722BE1D4F260A002B398B /* GPUImageiOSBlurFilter.h */, + 843722BF1D4F260A002B398B /* GPUImageiOSBlurFilter.m */, + 843722C01D4F260A002B398B /* GPUImageJFAVoronoiFilter.h */, + 843722C11D4F260A002B398B /* GPUImageJFAVoronoiFilter.m */, + 843722C21D4F260A002B398B /* GPUImageKuwaharaFilter.h */, + 843722C31D4F260A002B398B /* GPUImageKuwaharaFilter.m */, + 843722C41D4F260A002B398B /* GPUImageKuwaharaRadius3Filter.h */, + 843722C51D4F260A002B398B /* GPUImageKuwaharaRadius3Filter.m */, + 843722C61D4F260A002B398B /* GPUImageLanczosResamplingFilter.h */, + 843722C71D4F260A002B398B /* GPUImageLanczosResamplingFilter.m */, + 843722C81D4F260A002B398B /* GPUImageLaplacianFilter.h */, + 843722C91D4F260A002B398B /* GPUImageLaplacianFilter.m */, + 843722CA1D4F260A002B398B /* GPUImageLevelsFilter.h */, + 843722CB1D4F260A002B398B /* GPUImageLevelsFilter.m */, + 843722CC1D4F260A002B398B /* GPUImageLightenBlendFilter.h */, + 843722CD1D4F260A002B398B /* GPUImageLightenBlendFilter.m */, + 843722CE1D4F260A002B398B /* GPUImageLinearBurnBlendFilter.h */, + 843722CF1D4F260A002B398B /* GPUImageLinearBurnBlendFilter.m */, + 843722D01D4F260A002B398B /* GPUImageLineGenerator.h */, + 843722D11D4F260A002B398B /* GPUImageLineGenerator.m */, + 843722D21D4F260A002B398B /* GPUImageLocalBinaryPatternFilter.h */, + 843722D31D4F260A002B398B /* GPUImageLocalBinaryPatternFilter.m */, + 843722D41D4F260A002B398B /* GPUImageLookupFilter.h */, + 843722D51D4F260A002B398B /* GPUImageLookupFilter.m */, + 843722D61D4F260A002B398B /* GPUImageLowPassFilter.h */, + 843722D71D4F260A002B398B /* GPUImageLowPassFilter.m */, + 843722D81D4F260A002B398B /* GPUImageLuminanceRangeFilter.h */, + 843722D91D4F260A002B398B /* GPUImageLuminanceRangeFilter.m */, + 843722DA1D4F260A002B398B /* GPUImageLuminanceThresholdFilter.h */, + 843722DB1D4F260A002B398B /* GPUImageLuminanceThresholdFilter.m */, + 843722DC1D4F260A002B398B /* GPUImageLuminosity.h */, + 843722DD1D4F260A002B398B /* GPUImageLuminosity.m */, + 843722DE1D4F260A002B398B /* GPUImageLuminosityBlendFilter.h */, + 843722DF1D4F260A002B398B /* GPUImageLuminosityBlendFilter.m */, + 843722E01D4F260A002B398B /* GPUImageMaskFilter.h */, + 843722E11D4F260A002B398B /* GPUImageMaskFilter.m */, + 843722E21D4F260A002B398B /* GPUImageMedianFilter.h */, + 843722E31D4F260A002B398B /* GPUImageMedianFilter.m */, + 843722E41D4F260A002B398B /* GPUImageMissEtikateFilter.h */, + 843722E51D4F260A002B398B /* GPUImageMissEtikateFilter.m */, + 843722E61D4F260A002B398B /* GPUImageMonochromeFilter.h */, + 843722E71D4F260A002B398B /* GPUImageMonochromeFilter.m */, + 843722E81D4F260A002B398B /* GPUImageMosaicFilter.h */, + 843722E91D4F260A002B398B /* GPUImageMosaicFilter.m */, + 843722EA1D4F260A002B398B /* GPUImageMotionBlurFilter.h */, + 843722EB1D4F260A002B398B /* GPUImageMotionBlurFilter.m */, + 843722EC1D4F260A002B398B /* GPUImageMotionDetector.h */, + 843722ED1D4F260A002B398B /* GPUImageMotionDetector.m */, + 843722EE1D4F260A002B398B /* GPUImageMovie.h */, + 843722EF1D4F260A002B398B /* GPUImageMovie.m */, + 843722F01D4F260A002B398B /* GPUImageMovieComposition.h */, + 843722F11D4F260A002B398B /* GPUImageMovieComposition.m */, + 843722F21D4F260A002B398B /* GPUImageMultiplyBlendFilter.h */, + 843722F31D4F260A002B398B /* GPUImageMultiplyBlendFilter.m */, + 843722F41D4F260A002B398B /* GPUImageNobleCornerDetectionFilter.h */, + 843722F51D4F260A002B398B /* GPUImageNobleCornerDetectionFilter.m */, + 843722F61D4F260A002B398B /* GPUImageNonMaximumSuppressionFilter.h */, + 843722F71D4F260A002B398B /* GPUImageNonMaximumSuppressionFilter.m */, + 843722F81D4F260A002B398B /* GPUImageNormalBlendFilter.h */, + 843722F91D4F260A002B398B /* GPUImageNormalBlendFilter.m */, + 843722FA1D4F260A002B398B /* GPUImageOpacityFilter.h */, + 843722FB1D4F260A002B398B /* GPUImageOpacityFilter.m */, + 843722FC1D4F260A002B398B /* GPUImageOpeningFilter.h */, + 843722FD1D4F260A002B398B /* GPUImageOpeningFilter.m */, + 843722FE1D4F260A002B398B /* GPUImageOutput.h */, + 843722FF1D4F260A002B398B /* GPUImageOutput.m */, + 843723001D4F260A002B398B /* GPUImageOverlayBlendFilter.h */, + 843723011D4F260A002B398B /* GPUImageOverlayBlendFilter.m */, + 843723021D4F260A002B398B /* GPUImageParallelCoordinateLineTransformFilter.h */, + 843723031D4F260A002B398B /* GPUImageParallelCoordinateLineTransformFilter.m */, + 843723041D4F260A002B398B /* GPUImagePerlinNoiseFilter.h */, + 843723051D4F260A002B398B /* GPUImagePerlinNoiseFilter.m */, + 843723061D4F260A002B398B /* GPUImagePinchDistortionFilter.h */, + 843723071D4F260A002B398B /* GPUImagePinchDistortionFilter.m */, + 843723081D4F260A002B398B /* GPUImagePixellateFilter.h */, + 843723091D4F260A002B398B /* GPUImagePixellateFilter.m */, + 8437230A1D4F260A002B398B /* GPUImagePixellatePositionFilter.h */, + 8437230B1D4F260A002B398B /* GPUImagePixellatePositionFilter.m */, + 8437230C1D4F260A002B398B /* GPUImagePoissonBlendFilter.h */, + 8437230D1D4F260A002B398B /* GPUImagePoissonBlendFilter.m */, + 8437230E1D4F260A002B398B /* GPUImagePolarPixellateFilter.h */, + 8437230F1D4F260A002B398B /* GPUImagePolarPixellateFilter.m */, + 843723101D4F260A002B398B /* GPUImagePolkaDotFilter.h */, + 843723111D4F260A002B398B /* GPUImagePolkaDotFilter.m */, + 843723121D4F260A002B398B /* GPUImagePosterizeFilter.h */, + 843723131D4F260A002B398B /* GPUImagePosterizeFilter.m */, + 843723141D4F260A002B398B /* GPUImagePrewittEdgeDetectionFilter.h */, + 843723151D4F260A002B398B /* GPUImagePrewittEdgeDetectionFilter.m */, + 843723161D4F260A002B398B /* GPUImageRawDataInput.h */, + 843723171D4F260A002B398B /* GPUImageRawDataInput.m */, + 843723181D4F260A002B398B /* GPUImageRawDataOutput.h */, + 843723191D4F260A002B398B /* GPUImageRawDataOutput.m */, + 8437231A1D4F260A002B398B /* GPUImageRGBClosingFilter.h */, + 8437231B1D4F260A002B398B /* GPUImageRGBClosingFilter.m */, + 8437231C1D4F260A002B398B /* GPUImageRGBDilationFilter.h */, + 8437231D1D4F260A002B398B /* GPUImageRGBDilationFilter.m */, + 8437231E1D4F260A002B398B /* GPUImageRGBErosionFilter.h */, + 8437231F1D4F260A002B398B /* GPUImageRGBErosionFilter.m */, + 843723201D4F260A002B398B /* GPUImageRGBFilter.h */, + 843723211D4F260A002B398B /* GPUImageRGBFilter.m */, + 843723221D4F260A002B398B /* GPUImageRGBOpeningFilter.h */, + 843723231D4F260A002B398B /* GPUImageRGBOpeningFilter.m */, + 843723241D4F260A002B398B /* GPUImageSaturationBlendFilter.h */, + 843723251D4F260A002B398B /* GPUImageSaturationBlendFilter.m */, + 843723261D4F260A002B398B /* GPUImageSaturationFilter.h */, + 843723271D4F260A002B398B /* GPUImageSaturationFilter.m */, + 843723281D4F260A002B398B /* GPUImageScreenBlendFilter.h */, + 843723291D4F260A002B398B /* GPUImageScreenBlendFilter.m */, + 8437232A1D4F260A002B398B /* GPUImageSepiaFilter.h */, + 8437232B1D4F260A002B398B /* GPUImageSepiaFilter.m */, + 8437232C1D4F260A002B398B /* GPUImageSharpenFilter.h */, + 8437232D1D4F260A002B398B /* GPUImageSharpenFilter.m */, + 8437232E1D4F260A002B398B /* GPUImageShiTomasiFeatureDetectionFilter.h */, + 8437232F1D4F260A002B398B /* GPUImageShiTomasiFeatureDetectionFilter.m */, + 843723301D4F260A002B398B /* GPUImageSingleComponentGaussianBlurFilter.h */, + 843723311D4F260A002B398B /* GPUImageSingleComponentGaussianBlurFilter.m */, + 843723321D4F260A002B398B /* GPUImageSketchFilter.h */, + 843723331D4F260A002B398B /* GPUImageSketchFilter.m */, + 843723341D4F260A002B398B /* GPUImageSkinToneFilter.h */, + 843723351D4F260A002B398B /* GPUImageSkinToneFilter.m */, + 843723361D4F260A002B398B /* GPUImageSmoothToonFilter.h */, + 843723371D4F260A002B398B /* GPUImageSmoothToonFilter.m */, + 843723381D4F260A002B398B /* GPUImageSobelEdgeDetectionFilter.h */, + 843723391D4F260A002B398B /* GPUImageSobelEdgeDetectionFilter.m */, + 8437233A1D4F260A002B398B /* GPUImageSoftEleganceFilter.h */, + 8437233B1D4F260A002B398B /* GPUImageSoftEleganceFilter.m */, + 8437233C1D4F260A002B398B /* GPUImageSoftLightBlendFilter.h */, + 8437233D1D4F260A002B398B /* GPUImageSoftLightBlendFilter.m */, + 8437233E1D4F260A002B398B /* GPUImageSolarizeFilter.h */, + 8437233F1D4F260A002B398B /* GPUImageSolarizeFilter.m */, + 843723401D4F260A002B398B /* GPUImageSolidColorGenerator.h */, + 843723411D4F260A002B398B /* GPUImageSolidColorGenerator.m */, + 843723421D4F260A002B398B /* GPUImageSourceOverBlendFilter.h */, + 843723431D4F260A002B398B /* GPUImageSourceOverBlendFilter.m */, + 843723441D4F260A002B398B /* GPUImageSphereRefractionFilter.h */, + 843723451D4F260A002B398B /* GPUImageSphereRefractionFilter.m */, + 843723461D4F260A002B398B /* GPUImageStillCamera.h */, + 843723471D4F260A002B398B /* GPUImageStillCamera.m */, + 843723481D4F260A002B398B /* GPUImageStretchDistortionFilter.h */, + 843723491D4F260A002B398B /* GPUImageStretchDistortionFilter.m */, + 8437234A1D4F260A002B398B /* GPUImageSubtractBlendFilter.h */, + 8437234B1D4F260A002B398B /* GPUImageSubtractBlendFilter.m */, + 8437234C1D4F260A002B398B /* GPUImageSwirlFilter.h */, + 8437234D1D4F260A002B398B /* GPUImageSwirlFilter.m */, + 8437234E1D4F260A002B398B /* GPUImageTextureInput.h */, + 8437234F1D4F260A002B398B /* GPUImageTextureInput.m */, + 843723501D4F260A002B398B /* GPUImageTextureOutput.h */, + 843723511D4F260A002B398B /* GPUImageTextureOutput.m */, + 843723521D4F260A002B398B /* GPUImageThreeInputFilter.h */, + 843723531D4F260A002B398B /* GPUImageThreeInputFilter.m */, + 843723541D4F260A002B398B /* GPUImageThresholdEdgeDetectionFilter.h */, + 843723551D4F260A002B398B /* GPUImageThresholdEdgeDetectionFilter.m */, + 843723561D4F260A002B398B /* GPUImageThresholdedNonMaximumSuppressionFilter.h */, + 843723571D4F260A002B398B /* GPUImageThresholdedNonMaximumSuppressionFilter.m */, + 843723581D4F260A002B398B /* GPUImageThresholdSketchFilter.h */, + 843723591D4F260A002B398B /* GPUImageThresholdSketchFilter.m */, + 8437235A1D4F260A002B398B /* GPUImageTiltShiftFilter.h */, + 8437235B1D4F260A002B398B /* GPUImageTiltShiftFilter.m */, + 8437235C1D4F260A002B398B /* GPUImageToneCurveFilter.h */, + 8437235D1D4F260A002B398B /* GPUImageToneCurveFilter.m */, + 8437235E1D4F260A002B398B /* GPUImageToonFilter.h */, + 8437235F1D4F260A002B398B /* GPUImageToonFilter.m */, + 843723601D4F260A002B398B /* GPUImageTransformFilter.h */, + 843723611D4F260A002B398B /* GPUImageTransformFilter.m */, + 843723621D4F260A002B398B /* GPUImageTwoInputCrossTextureSamplingFilter.h */, + 843723631D4F260A002B398B /* GPUImageTwoInputCrossTextureSamplingFilter.m */, + 843723641D4F260A002B398B /* GPUImageTwoInputFilter.h */, + 843723651D4F260A002B398B /* GPUImageTwoInputFilter.m */, + 843723661D4F260A002B398B /* GPUImageTwoPassFilter.h */, + 843723671D4F260A002B398B /* GPUImageTwoPassFilter.m */, + 843723681D4F260A002B398B /* GPUImageTwoPassTextureSamplingFilter.h */, + 843723691D4F260A002B398B /* GPUImageTwoPassTextureSamplingFilter.m */, + 8437236A1D4F260A002B398B /* GPUImageUIElement.h */, + 8437236B1D4F260A002B398B /* GPUImageUIElement.m */, + 8437236C1D4F260A002B398B /* GPUImageUnsharpMaskFilter.h */, + 8437236D1D4F260A002B398B /* GPUImageUnsharpMaskFilter.m */, + 8437236E1D4F260A002B398B /* GPUImageVideoCamera.h */, + 8437236F1D4F260A002B398B /* GPUImageVideoCamera.m */, + 843723701D4F260A002B398B /* GPUImageVignetteFilter.h */, + 843723711D4F260A002B398B /* GPUImageVignetteFilter.m */, + 843723721D4F260A002B398B /* GPUImageVoronoiConsumerFilter.h */, + 843723731D4F260A002B398B /* GPUImageVoronoiConsumerFilter.m */, + 843723741D4F260A002B398B /* GPUImageWeakPixelInclusionFilter.h */, + 843723751D4F260A002B398B /* GPUImageWeakPixelInclusionFilter.m */, + 843723761D4F260A002B398B /* GPUImageWhiteBalanceFilter.h */, + 843723771D4F260A002B398B /* GPUImageWhiteBalanceFilter.m */, + 843723781D4F260A002B398B /* GPUImageXYDerivativeFilter.h */, + 843723791D4F260A002B398B /* GPUImageXYDerivativeFilter.m */, + 8437237A1D4F260A002B398B /* GPUImageZoomBlurFilter.h */, + 8437237B1D4F260A002B398B /* GPUImageZoomBlurFilter.m */, + 8437237C1D4F260A002B398B /* iOS */, + ); + path = GPUImage; + sourceTree = ""; + }; + 8437237C1D4F260A002B398B /* iOS */ = { + isa = PBXGroup; + children = ( + 8437237D1D4F260A002B398B /* Framework */, + 8437237F1D4F260A002B398B /* GPUImageContext.h */, + 843723801D4F260A002B398B /* GPUImageContext.m */, + 843723811D4F260A002B398B /* GPUImageMovieWriter.h */, + 843723821D4F260A002B398B /* GPUImageMovieWriter.m */, + 843723831D4F260A002B398B /* GPUImagePicture+TextureSubimage.h */, + 843723841D4F260A002B398B /* GPUImagePicture+TextureSubimage.m */, + 843723851D4F260A002B398B /* GPUImagePicture.h */, + 843723861D4F260A002B398B /* GPUImagePicture.m */, + 843723871D4F260A002B398B /* GPUImageView.h */, + 843723881D4F260A002B398B /* GPUImageView.m */, + ); + path = iOS; + sourceTree = ""; + }; + 8437237D1D4F260A002B398B /* Framework */ = { + isa = PBXGroup; + children = ( + 8437237E1D4F260A002B398B /* GPUImageFramework.h */, + ); + path = Framework; + sourceTree = ""; + }; + 843723891D4F260A002B398B /* pili-librtmp */ = { + isa = PBXGroup; + children = ( + 8437238A1D4F260A002B398B /* amf.c */, + 8437238B1D4F260A002B398B /* amf.h */, + 8437238C1D4F260A002B398B /* bytes.h */, + 8437238D1D4F260A002B398B /* dh.h */, + 8437238E1D4F260A002B398B /* dhgroups.h */, + 8437238F1D4F260A002B398B /* error.c */, + 843723901D4F260A002B398B /* error.h */, + 843723911D4F260A002B398B /* handshake.h */, + 843723921D4F260A002B398B /* hashswf.c */, + 843723931D4F260A002B398B /* http.h */, + 843723941D4F260A002B398B /* log.c */, + 843723951D4F260A002B398B /* log.h */, + 843723961D4F260A002B398B /* parseurl.c */, + 843723971D4F260A002B398B /* rtmp.c */, + 843723981D4F260A002B398B /* rtmp.h */, + 843723991D4F260A002B398B /* rtmp_sys.h */, + ); + path = "pili-librtmp"; + sourceTree = ""; + }; B2CD14611D45F18B008082E8 /* H264 */ = { isa = PBXGroup; children = ( @@ -330,15 +1457,6 @@ path = H264; sourceTree = ""; }; - EDD4B76A07A6817C79BB4E5C /* Pods */ = { - isa = PBXGroup; - children = ( - A17586B27CD6843997425CCF /* Pods-LFLiveKit.debug.xcconfig */, - B75B965E6B94DE4CBCC82EA7 /* Pods-LFLiveKit.release.xcconfig */, - ); - name = Pods; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -346,32 +1464,228 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 84001FE51D0016380026C63F /* LFAudioFrame.h in Headers */, + 843724711D4F260A002B398B /* GPUImagePerlinNoiseFilter.h in Headers */, + 843724F61D4F260A002B398B /* bytes.h in Headers */, + 84001FED1D0016380026C63F /* LFVideoFrame.h in Headers */, + 843724A51D4F260A002B398B /* GPUImageSobelEdgeDetectionFilter.h in Headers */, + 843724231D4F260A002B398B /* GPUImageHoughTransformLineDetector.h in Headers */, + 8437246D1D4F260A002B398B /* GPUImageOverlayBlendFilter.h in Headers */, + 84001FE71D0016380026C63F /* LFFrame.h in Headers */, + 843724C11D4F260A002B398B /* GPUImageThresholdEdgeDetectionFilter.h in Headers */, + 843724B71D4F260A002B398B /* GPUImageSubtractBlendFilter.h in Headers */, + 8437245B1D4F260A002B398B /* GPUImageMovie.h in Headers */, + 843724191D4F260A002B398B /* GPUImageHighlightShadowTintFilter.h in Headers */, + 843724291D4F260A002B398B /* GPUImageHueFilter.h in Headers */, + 843724FF1D4F260A002B398B /* log.h in Headers */, + 843724AF1D4F260A002B398B /* GPUImageSourceOverBlendFilter.h in Headers */, + 843723CB1D4F260A002B398B /* GPUImageColorLocalBinaryPatternFilter.h in Headers */, + 843723DF1D4F260A002B398B /* GPUImageDifferenceBlendFilter.h in Headers */, + 843724EA1D4F260A002B398B /* GPUImageContext.h in Headers */, + 843723D91D4F260A002B398B /* GPUImageCrosshairGenerator.h in Headers */, 84001FDB1D0016380026C63F /* LFLiveAudioConfiguration.h in Headers */, + 843723ED1D4F260A002B398B /* GPUImageErosionFilter.h in Headers */, B289F1DD1D3DE77F00D9C7A5 /* LFStreamRtmpSocket.h in Headers */, + 843724211D4F260A002B398B /* GPUImageHistogramGenerator.h in Headers */, + 843723C51D4F260A002B398B /* GPUImageColorConversion.h in Headers */, + 8437239D1D4F260A002B398B /* GPUImage3x3ConvolutionFilter.h in Headers */, + 843724971D4F260A002B398B /* GPUImageSepiaFilter.h in Headers */, + 843723AF1D4F260A002B398B /* GPUImageBoxBlurFilter.h in Headers */, + 8437248B1D4F260A002B398B /* GPUImageRGBErosionFilter.h in Headers */, + 843724D11D4F260A002B398B /* GPUImageTwoInputFilter.h in Headers */, + 843723B31D4F260A002B398B /* GPUImageBuffer.h in Headers */, + 843724D31D4F260A002B398B /* GPUImageTwoPassFilter.h in Headers */, + 843724311D4F260A002B398B /* GPUImageKuwaharaRadius3Filter.h in Headers */, + 843724F21D4F260A002B398B /* GPUImageView.h in Headers */, + 843724991D4F260A002B398B /* GPUImageSharpenFilter.h in Headers */, 84001FDD1D0016380026C63F /* LFLiveVideoConfiguration.h in Headers */, B2CD14701D45F18B008082E8 /* LFMP4Atom.h in Headers */, + 849005B61D4B5C8400D2A3D5 /* error.h in Headers */, + 843724FB1D4F260A002B398B /* handshake.h in Headers */, + 843723F31D4F260A002B398B /* GPUImageFalseColorFilter.h in Headers */, + 843723B71D4F260A002B398B /* GPUImageCannyEdgeDetectionFilter.h in Headers */, + 843724151D4F260A002B398B /* GPUImageHazeFilter.h in Headers */, + 843723E51D4F260A002B398B /* GPUImageDirectionalSobelEdgeDetectionFilter.h in Headers */, + 843724091D4F260A002B398B /* GPUImageGaussianSelectiveBlurFilter.h in Headers */, + 843724DD1D4F260A002B398B /* GPUImageVignetteFilter.h in Headers */, + 843724AD1D4F260A002B398B /* GPUImageSolidColorGenerator.h in Headers */, + 8437244D1D4F260A002B398B /* GPUImageMaskFilter.h in Headers */, + 843723E91D4F260A002B398B /* GPUImageDivideBlendFilter.h in Headers */, + B2CD14701D45F18B008082E8 /* LFMP4Atom.h in Headers */, 84001FE31D0016380026C63F /* LFLiveSession.h in Headers */, + 843724411D4F260A002B398B /* GPUImageLookupFilter.h in Headers */, + 843724E91D4F260A002B398B /* GPUImageFramework.h in Headers */, + 8437244B1D4F260A002B398B /* GPUImageLuminosityBlendFilter.h in Headers */, + 8437247D1D4F260A002B398B /* GPUImagePolkaDotFilter.h in Headers */, + 843724571D4F260A002B398B /* GPUImageMotionBlurFilter.h in Headers */, + 843724BD1D4F260A002B398B /* GPUImageTextureOutput.h in Headers */, + 843724DB1D4F260A002B398B /* GPUImageVideoCamera.h in Headers */, + 843724791D4F260A002B398B /* GPUImagePoissonBlendFilter.h in Headers */, B289F1DB1D3DE77F00D9C7A5 /* LFStreamingBuffer.h in Headers */, + 843724771D4F260A002B398B /* GPUImagePixellatePositionFilter.h in Headers */, + 843724911D4F260A002B398B /* GPUImageSaturationBlendFilter.h in Headers */, + 8437240D1D4F260A002B398B /* GPUImageGrayscaleFilter.h in Headers */, + 8437249D1D4F260A002B398B /* GPUImageSingleComponentGaussianBlurFilter.h in Headers */, + 843724751D4F260A002B398B /* GPUImagePixellateFilter.h in Headers */, + 843724E71D4F260A002B398B /* GPUImageZoomBlurFilter.h in Headers */, + 843723FF1D4F260A002B398B /* GPUImageFramebuffer.h in Headers */, + 8437244F1D4F260A002B398B /* GPUImageMedianFilter.h in Headers */, + 843724B11D4F260A002B398B /* GPUImageSphereRefractionFilter.h in Headers */, + 843724631D4F260A002B398B /* GPUImageNonMaximumSuppressionFilter.h in Headers */, + 843724591D4F260A002B398B /* GPUImageMotionDetector.h in Headers */, + 8437246F1D4F260A002B398B /* GPUImageParallelCoordinateLineTransformFilter.h in Headers */, + 843724931D4F260A002B398B /* GPUImageSaturationFilter.h in Headers */, + 843723EF1D4F260A002B398B /* GPUImageExclusionBlendFilter.h in Headers */, + 843724811D4F260A002B398B /* GPUImagePrewittEdgeDetectionFilter.h in Headers */, + 843724C91D4F260A002B398B /* GPUImageToneCurveFilter.h in Headers */, + 843724CF1D4F260A002B398B /* GPUImageTwoInputCrossTextureSamplingFilter.h in Headers */, + 843723AD1D4F260A002B398B /* GPUImageBilateralFilter.h in Headers */, + 843724F81D4F260A002B398B /* dhgroups.h in Headers */, + 843724731D4F260A002B398B /* GPUImagePinchDistortionFilter.h in Headers */, + 843724D71D4F260A002B398B /* GPUImageUIElement.h in Headers */, + 843724BB1D4F260A002B398B /* GPUImageTextureInput.h in Headers */, + 843724871D4F260A002B398B /* GPUImageRGBClosingFilter.h in Headers */, + 843724371D4F260A002B398B /* GPUImageLevelsFilter.h in Headers */, + 843724951D4F260A002B398B /* GPUImageScreenBlendFilter.h in Headers */, 84001FEB1D0016380026C63F /* LFLiveStreamInfo.h in Headers */, + 843724251D4F260A002B398B /* GPUImageHSBFilter.h in Headers */, + 843724891D4F260A002B398B /* GPUImageRGBDilationFilter.h in Headers */, + 843724C31D4F260A002B398B /* GPUImageThresholdedNonMaximumSuppressionFilter.h in Headers */, + 843723A71D4F260A002B398B /* GPUImageAmatorkaFilter.h in Headers */, + 8437245F1D4F260A002B398B /* GPUImageMultiplyBlendFilter.h in Headers */, 84001FE91D0016380026C63F /* LFLiveDebug.h in Headers */, - 84001FE71D0016380026C63F /* LFFrame.h in Headers */, + 843723BB1D4F260A002B398B /* GPUImageChromaKeyBlendFilter.h in Headers */, + 8437239A1D4F260A002B398B /* GLProgram.h in Headers */, + 843723E71D4F260A002B398B /* GPUImageDissolveBlendFilter.h in Headers */, + 843723B51D4F260A002B398B /* GPUImageBulgeDistortionFilter.h in Headers */, + 843724331D4F260A002B398B /* GPUImageLanczosResamplingFilter.h in Headers */, + 843724131D4F260A002B398B /* GPUImageHarrisCornerDetectionFilter.h in Headers */, + 843724C71D4F260A002B398B /* GPUImageTiltShiftFilter.h in Headers */, + 843723F91D4F260A002B398B /* GPUImageFilterGroup.h in Headers */, + 843723C31D4F260A002B398B /* GPUImageColorBurnBlendFilter.h in Headers */, + 8437243B1D4F260A002B398B /* GPUImageLinearBurnBlendFilter.h in Headers */, + 843724011D4F260A002B398B /* GPUImageFramebufferCache.h in Headers */, + 8437247B1D4F260A002B398B /* GPUImagePolarPixellateFilter.h in Headers */, + 843724AB1D4F260A002B398B /* GPUImageSolarizeFilter.h in Headers */, + 843724071D4F260A002B398B /* GPUImageGaussianBlurPositionFilter.h in Headers */, + 843723D71D4F260A002B398B /* GPUImageCropFilter.h in Headers */, + 8437249B1D4F260A002B398B /* GPUImageShiTomasiFeatureDetectionFilter.h in Headers */, + 843724031D4F260A002B398B /* GPUImageGammaFilter.h in Headers */, + 8437242B1D4F260A002B398B /* GPUImageiOSBlurFilter.h in Headers */, + 843724EE1D4F260A002B398B /* GPUImagePicture+TextureSubimage.h in Headers */, + 843724111D4F260A002B398B /* GPUImageHardLightBlendFilter.h in Headers */, + 843723A51D4F260A002B398B /* GPUImageAlphaBlendFilter.h in Headers */, + 843724E11D4F260A002B398B /* GPUImageWeakPixelInclusionFilter.h in Headers */, + 843723EB1D4F260A002B398B /* GPUImageEmbossFilter.h in Headers */, + 843724EC1D4F260A002B398B /* GPUImageMovieWriter.h in Headers */, + 843724451D4F260A002B398B /* GPUImageLuminanceRangeFilter.h in Headers */, + 843723D31D4F260A002B398B /* GPUImageColourFASTSamplingOperation.h in Headers */, + 8437243F1D4F260A002B398B /* GPUImageLocalBinaryPatternFilter.h in Headers */, + 843725021D4F260A002B398B /* rtmp.h in Headers */, B2CD14761D45F18B008082E8 /* LFH264VideoEncoder.h in Headers */, + 843724FA1D4F260A002B398B /* error.h in Headers */, + 843723E31D4F260A002B398B /* GPUImageDirectionalNonMaximumSuppressionFilter.h in Headers */, + 843724351D4F260A002B398B /* GPUImageLaplacianFilter.h in Headers */, + 843724511D4F260A002B398B /* GPUImageMissEtikateFilter.h in Headers */, + 843724D91D4F260A002B398B /* GPUImageUnsharpMaskFilter.h in Headers */, + 843724A71D4F260A002B398B /* GPUImageSoftEleganceFilter.h in Headers */, + 843724CB1D4F260A002B398B /* GPUImageToonFilter.h in Headers */, + 843723DD1D4F260A002B398B /* GPUImageDarkenBlendFilter.h in Headers */, 84001FD61D0016380026C63F /* LFHardwareAudioEncoder.h in Headers */, B289F1E01D3DE77F00D9C7A5 /* NSMutableArray+LFAdd.h in Headers */, + 8437242D1D4F260A002B398B /* GPUImageJFAVoronoiFilter.h in Headers */, + 843723D11D4F260A002B398B /* GPUImageColourFASTFeatureDetector.h in Headers */, + 843723F51D4F260A002B398B /* GPUImageFASTCornerDetectionFilter.h in Headers */, 84001FDF1D0016380026C63F /* LFGPUImageBeautyFilter.h in Headers */, + 843723BF1D4F260A002B398B /* GPUImageClosingFilter.h in Headers */, + 843723FB1D4F260A002B398B /* GPUImageFilterPipeline.h in Headers */, + 843724E51D4F260A002B398B /* GPUImageXYDerivativeFilter.h in Headers */, + 8437241F1D4F260A002B398B /* GPUImageHistogramFilter.h in Headers */, + 8437248D1D4F260A002B398B /* GPUImageRGBFilter.h in Headers */, + 843723E11D4F260A002B398B /* GPUImageDilationFilter.h in Headers */, + 843724531D4F260A002B398B /* GPUImageMonochromeFilter.h in Headers */, + 843724391D4F260A002B398B /* GPUImageLightenBlendFilter.h in Headers */, + 843723CD1D4F260A002B398B /* GPUImageColorMatrixFilter.h in Headers */, + 843724DF1D4F260A002B398B /* GPUImageVoronoiConsumerFilter.h in Headers */, + 8437241B1D4F260A002B398B /* GPUImageHighPassFilter.h in Headers */, + 843724CD1D4F260A002B398B /* GPUImageTransformFilter.h in Headers */, + 843724831D4F260A002B398B /* GPUImageRawDataInput.h in Headers */, + 843724F51D4F260A002B398B /* amf.h in Headers */, + 843723A31D4F260A002B398B /* GPUImageAddBlendFilter.h in Headers */, + 843724B91D4F260A002B398B /* GPUImageSwirlFilter.h in Headers */, + 8437246B1D4F260A002B398B /* GPUImageOutput.h in Headers */, + 843724851D4F260A002B398B /* GPUImageRawDataOutput.h in Headers */, + 843723DB1D4F260A002B398B /* GPUImageCrosshatchFilter.h in Headers */, + 843724491D4F260A002B398B /* GPUImageLuminosity.h in Headers */, 84001FD31D0016380026C63F /* LFVideoCapture.h in Headers */, 84001FD11D0016380026C63F /* LFAudioCapture.h in Headers */, + 843723C71D4F260A002B398B /* GPUImageColorDodgeBlendFilter.h in Headers */, + 8437241D1D4F260A002B398B /* GPUImageHistogramEqualizationFilter.h in Headers */, + 843723C91D4F260A002B398B /* GPUImageColorInvertFilter.h in Headers */, + 843724E31D4F260A002B398B /* GPUImageWhiteBalanceFilter.h in Headers */, + 843724C51D4F260A002B398B /* GPUImageThresholdSketchFilter.h in Headers */, + 8437248F1D4F260A002B398B /* GPUImageRGBOpeningFilter.h in Headers */, + 8437240B1D4F260A002B398B /* GPUImageGlassSphereFilter.h in Headers */, + 8437239F1D4F260A002B398B /* GPUImage3x3TextureSamplingFilter.h in Headers */, + 843724651D4F260A002B398B /* GPUImageNormalBlendFilter.h in Headers */, + 8437245D1D4F260A002B398B /* GPUImageMovieComposition.h in Headers */, 84001FE11D0016380026C63F /* LFGPUImageEmptyFilter.h in Headers */, + 843724B51D4F260A002B398B /* GPUImageStretchDistortionFilter.h in Headers */, 84001FDA1D0016380026C63F /* LFVideoEncoding.h in Headers */, 84001FE51D0016380026C63F /* LFAudioFrame.h in Headers */, 84001FED1D0016380026C63F /* LFVideoFrame.h in Headers */, B2CD14741D45F18B008082E8 /* LFVideoEncoder.h in Headers */, B2CD14731D45F18B008082E8 /* LFNALUnit.h in Headers */, + 849005BF1D4B5C8400D2A3D5 /* rtmp_sys.h in Headers */, + 849005BE1D4B5C8400D2A3D5 /* rtmp.h in Headers */, + 843724BF1D4F260A002B398B /* GPUImageThreeInputFilter.h in Headers */, + 843724F71D4F260A002B398B /* dh.h in Headers */, + 843725031D4F260A002B398B /* rtmp_sys.h in Headers */, + 843724691D4F260A002B398B /* GPUImageOpeningFilter.h in Headers */, + 843723C11D4F260A002B398B /* GPUImageColorBlendFilter.h in Headers */, + 8437249F1D4F260A002B398B /* GPUImageSketchFilter.h in Headers */, + 84001FE51D0016380026C63F /* LFAudioFrame.h in Headers */, + 84001FED1D0016380026C63F /* LFVideoFrame.h in Headers */, + B2CD14741D45F18B008082E8 /* LFVideoEncoder.h in Headers */, + B2CD14731D45F18B008082E8 /* LFNALUnit.h in Headers */, 84001FD81D0016380026C63F /* LFHardwareVideoEncoder.h in Headers */, + 843724A91D4F260A002B398B /* GPUImageSoftLightBlendFilter.h in Headers */, + 843723A91D4F260A002B398B /* GPUImageAverageColor.h in Headers */, + 843723FD1D4F260A002B398B /* GPUImageFourInputFilter.h in Headers */, + 843724431D4F260A002B398B /* GPUImageLowPassFilter.h in Headers */, + 8437239C1D4F260A002B398B /* GPUImage.h in Headers */, B289F1DF1D3DE77F00D9C7A5 /* LFStreamSocket.h in Headers */, + 8437242F1D4F260A002B398B /* GPUImageKuwaharaFilter.h in Headers */, + 843723B11D4F260A002B398B /* GPUImageBrightnessFilter.h in Headers */, + 843724FD1D4F260A002B398B /* http.h in Headers */, + 843724611D4F260A002B398B /* GPUImageNobleCornerDetectionFilter.h in Headers */, + 8437243D1D4F260A002B398B /* GPUImageLineGenerator.h in Headers */, 84001FD51D0016380026C63F /* LFAudioEncoding.h in Headers */, B2CD146D1D45F18B008082E8 /* LFAVEncoder.h in Headers */, + 849005B11D4B5C8400D2A3D5 /* amf.h in Headers */, + 843723AB1D4F260A002B398B /* GPUImageAverageLuminanceThresholdFilter.h in Headers */, + 843723F71D4F260A002B398B /* GPUImageFilter.h in Headers */, + 8437240F1D4F260A002B398B /* GPUImageHalftoneFilter.h in Headers */, + 843723A11D4F260A002B398B /* GPUImageAdaptiveThresholdFilter.h in Headers */, + 843723CF1D4F260A002B398B /* GPUImageColorPackingFilter.h in Headers */, + 843723B91D4F260A002B398B /* GPUImageCGAColorspaceFilter.h in Headers */, + 843724051D4F260A002B398B /* GPUImageGaussianBlurFilter.h in Headers */, + 843724B31D4F260A002B398B /* GPUImageStillCamera.h in Headers */, + 843724D51D4F260A002B398B /* GPUImageTwoPassTextureSamplingFilter.h in Headers */, + 843723F11D4F260A002B398B /* GPUImageExposureFilter.h in Headers */, + 843723D51D4F260A002B398B /* GPUImageContrastFilter.h in Headers */, + 843724A11D4F260A002B398B /* GPUImageSkinToneFilter.h in Headers */, + 843724271D4F260A002B398B /* GPUImageHueBlendFilter.h in Headers */, + 843724471D4F260A002B398B /* GPUImageLuminanceThresholdFilter.h in Headers */, + 843724551D4F260A002B398B /* GPUImageMosaicFilter.h in Headers */, + 843723BD1D4F260A002B398B /* GPUImageChromaKeyFilter.h in Headers */, + 843724171D4F260A002B398B /* GPUImageHighlightShadowFilter.h in Headers */, + B2CD146D1D45F18B008082E8 /* LFAVEncoder.h in Headers */, 84001F8E1D0015D10026C63F /* LFLiveKit.h in Headers */, + 843724671D4F260A002B398B /* GPUImageOpacityFilter.h in Headers */, + 8437247F1D4F260A002B398B /* GPUImagePosterizeFilter.h in Headers */, + 843724A31D4F260A002B398B /* GPUImageSmoothToonFilter.h in Headers */, + 843724F01D4F260A002B398B /* GPUImagePicture.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -382,14 +1696,10 @@ isa = PBXNativeTarget; buildConfigurationList = 84001F9E1D0015D10026C63F /* Build configuration list for PBXNativeTarget "LFLiveKit" */; buildPhases = ( - 8EE9401DCA9508E918B7FB68 /* 📦 Check Pods Manifest.lock */, - 98F2C3F394BD79A6D6B8424F /* Check Pods Manifest.lock */, 84001F851D0015D10026C63F /* Sources */, 84001F861D0015D10026C63F /* Frameworks */, 84001F871D0015D10026C63F /* Headers */, 84001F881D0015D10026C63F /* Resources */, - 817C22141AD3F2EB34365AA3 /* 📦 Copy Pods Resources */, - 8A5D8B623E50AAC1575D1741 /* Copy Pods Resources */, ); buildRules = ( ); @@ -470,97 +1780,220 @@ }; /* End PBXResourcesBuildPhase section */ -/* Begin PBXShellScriptBuildPhase section */ - 817C22141AD3F2EB34365AA3 /* 📦 Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "📦 Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LFLiveKit/Pods-LFLiveKit-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - 8A5D8B623E50AAC1575D1741 /* Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - 8EE9401DCA9508E918B7FB68 /* 📦 Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "📦 Check Pods Manifest.lock"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; - showEnvVarsInLog = 0; - }; - 98F2C3F394BD79A6D6B8424F /* Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Check Pods Manifest.lock"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; - showEnvVarsInLog = 0; - }; -/* End PBXShellScriptBuildPhase section */ - /* Begin PBXSourcesBuildPhase section */ 84001F851D0015D10026C63F /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( 84001FE21D0016380026C63F /* LFGPUImageEmptyFilter.m in Sources */, + 843724C21D4F260A002B398B /* GPUImageThresholdEdgeDetectionFilter.m in Sources */, 84001FE41D0016380026C63F /* LFLiveSession.m in Sources */, B2CD14711D45F18B008082E8 /* LFMP4Atom.m in Sources */, + 849005B81D4B5C8400D2A3D5 /* hashswf.c in Sources */, + 843724BA1D4F260A002B398B /* GPUImageSwirlFilter.m in Sources */, + 843723A41D4F260A002B398B /* GPUImageAddBlendFilter.m in Sources */, + 843723B01D4F260A002B398B /* GPUImageBoxBlurFilter.m in Sources */, + 843723DC1D4F260A002B398B /* GPUImageCrosshatchFilter.m in Sources */, + 843724E41D4F260A002B398B /* GPUImageWhiteBalanceFilter.m in Sources */, + 843724101D4F260A002B398B /* GPUImageHalftoneFilter.m in Sources */, + 843724301D4F260A002B398B /* GPUImageKuwaharaFilter.m in Sources */, + 843724201D4F260A002B398B /* GPUImageHistogramFilter.m in Sources */, + 8437246E1D4F260A002B398B /* GPUImageOverlayBlendFilter.m in Sources */, + 843723A81D4F260A002B398B /* GPUImageAmatorkaFilter.m in Sources */, + B2CD14711D45F18B008082E8 /* LFMP4Atom.m in Sources */, 84001FE61D0016380026C63F /* LFAudioFrame.m in Sources */, + 843724C41D4F260A002B398B /* GPUImageThresholdedNonMaximumSuppressionFilter.m in Sources */, + 843724F91D4F260A002B398B /* error.c in Sources */, + 843724DC1D4F260A002B398B /* GPUImageVideoCamera.m in Sources */, + 8437246C1D4F260A002B398B /* GPUImageOutput.m in Sources */, + 843724B01D4F260A002B398B /* GPUImageSourceOverBlendFilter.m in Sources */, + 843724581D4F260A002B398B /* GPUImageMotionBlurFilter.m in Sources */, 84001FDC1D0016380026C63F /* LFLiveAudioConfiguration.m in Sources */, 84001FD41D0016380026C63F /* LFVideoCapture.m in Sources */, + 843723B81D4F260A002B398B /* GPUImageCannyEdgeDetectionFilter.m in Sources */, 84001FE81D0016380026C63F /* LFFrame.m in Sources */, +<<<<<<< HEAD + B2CD14721D45F18B008082E8 /* LFNALUnit.cpp in Sources */, +======= +>>>>>>> rename h264 encode lib to avoid duplicate symbol error + 843724CE1D4F260A002B398B /* GPUImageTransformFilter.m in Sources */, + 843723E81D4F260A002B398B /* GPUImageDissolveBlendFilter.m in Sources */, + 843723D81D4F260A002B398B /* GPUImageCropFilter.m in Sources */, + 843723EC1D4F260A002B398B /* GPUImageEmbossFilter.m in Sources */, + 843724AA1D4F260A002B398B /* GPUImageSoftLightBlendFilter.m in Sources */, + 843723F21D4F260A002B398B /* GPUImageExposureFilter.m in Sources */, + 8437244E1D4F260A002B398B /* GPUImageMaskFilter.m in Sources */, + 843724841D4F260A002B398B /* GPUImageRawDataInput.m in Sources */, B2CD14721D45F18B008082E8 /* LFNALUnit.cpp in Sources */, B289F1DC1D3DE77F00D9C7A5 /* LFStreamingBuffer.m in Sources */, + 843723F01D4F260A002B398B /* GPUImageExclusionBlendFilter.m in Sources */, + 843724F31D4F260A002B398B /* GPUImageView.m in Sources */, + 843724081D4F260A002B398B /* GPUImageGaussianBlurPositionFilter.m in Sources */, + 843724A41D4F260A002B398B /* GPUImageSmoothToonFilter.m in Sources */, + 8437241A1D4F260A002B398B /* GPUImageHighlightShadowTintFilter.m in Sources */, + 843724821D4F260A002B398B /* GPUImagePrewittEdgeDetectionFilter.m in Sources */, + 843724CC1D4F260A002B398B /* GPUImageToonFilter.m in Sources */, + 843724801D4F260A002B398B /* GPUImagePosterizeFilter.m in Sources */, B289F1E11D3DE77F00D9C7A5 /* NSMutableArray+LFAdd.m in Sources */, + 843724041D4F260A002B398B /* GPUImageGammaFilter.m in Sources */, + 843724B21D4F260A002B398B /* GPUImageSphereRefractionFilter.m in Sources */, + 8437248E1D4F260A002B398B /* GPUImageRGBFilter.m in Sources */, + 843724161D4F260A002B398B /* GPUImageHazeFilter.m in Sources */, + 843723BC1D4F260A002B398B /* GPUImageChromaKeyBlendFilter.m in Sources */, + 8437247A1D4F260A002B398B /* GPUImagePoissonBlendFilter.m in Sources */, + 843723E01D4F260A002B398B /* GPUImageDifferenceBlendFilter.m in Sources */, + 843723EA1D4F260A002B398B /* GPUImageDivideBlendFilter.m in Sources */, + 8437243E1D4F260A002B398B /* GPUImageLineGenerator.m in Sources */, + 843723B21D4F260A002B398B /* GPUImageBrightnessFilter.m in Sources */, + 843723C21D4F260A002B398B /* GPUImageColorBlendFilter.m in Sources */, + 843724241D4F260A002B398B /* GPUImageHoughTransformLineDetector.m in Sources */, + 843723A21D4F260A002B398B /* GPUImageAdaptiveThresholdFilter.m in Sources */, + 843724BE1D4F260A002B398B /* GPUImageTextureOutput.m in Sources */, + 8437241C1D4F260A002B398B /* GPUImageHighPassFilter.m in Sources */, B2CD14771D45F18B008082E8 /* LFH264VideoEncoder.mm in Sources */, + 843723C01D4F260A002B398B /* GPUImageClosingFilter.m in Sources */, + 843724AE1D4F260A002B398B /* GPUImageSolidColorGenerator.m in Sources */, + 843724ED1D4F260A002B398B /* GPUImageMovieWriter.m in Sources */, + 843723AA1D4F260A002B398B /* GPUImageAverageColor.m in Sources */, 84001FDE1D0016380026C63F /* LFLiveVideoConfiguration.m in Sources */, + 8437247E1D4F260A002B398B /* GPUImagePolkaDotFilter.m in Sources */, + 843723D01D4F260A002B398B /* GPUImageColorPackingFilter.m in Sources */, + 843724F41D4F260A002B398B /* amf.c in Sources */, + 8437242C1D4F260A002B398B /* GPUImageiOSBlurFilter.m in Sources */, + 843724941D4F260A002B398B /* GPUImageSaturationFilter.m in Sources */, + 8437248A1D4F260A002B398B /* GPUImageRGBDilationFilter.m in Sources */, + 843724781D4F260A002B398B /* GPUImagePixellatePositionFilter.m in Sources */, + 8437245A1D4F260A002B398B /* GPUImageMotionDetector.m in Sources */, 84001FD21D0016380026C63F /* LFAudioCapture.m in Sources */, B2CD14751D45F18B008082E8 /* LFVideoEncoder.m in Sources */, + 843724B81D4F260A002B398B /* GPUImageSubtractBlendFilter.m in Sources */, + 843724741D4F260A002B398B /* GPUImagePinchDistortionFilter.m in Sources */, + 843724D61D4F260A002B398B /* GPUImageTwoPassTextureSamplingFilter.m in Sources */, + 843723DA1D4F260A002B398B /* GPUImageCrosshairGenerator.m in Sources */, + 843724A01D4F260A002B398B /* GPUImageSketchFilter.m in Sources */, + 843723A01D4F260A002B398B /* GPUImage3x3TextureSamplingFilter.m in Sources */, + 8437249A1D4F260A002B398B /* GPUImageSharpenFilter.m in Sources */, + 843723C41D4F260A002B398B /* GPUImageColorBurnBlendFilter.m in Sources */, + 843724121D4F260A002B398B /* GPUImageHardLightBlendFilter.m in Sources */, + 843723D61D4F260A002B398B /* GPUImageContrastFilter.m in Sources */, + 843724BC1D4F260A002B398B /* GPUImageTextureInput.m in Sources */, + 843724521D4F260A002B398B /* GPUImageMissEtikateFilter.m in Sources */, + B2CD14751D45F18B008082E8 /* LFVideoEncoder.m in Sources */, B2CD146F1D45F18B008082E8 /* LICENSE.markdown in Sources */, B289F1DE1D3DE77F00D9C7A5 /* LFStreamRtmpSocket.m in Sources */, + 843724CA1D4F260A002B398B /* GPUImageToneCurveFilter.m in Sources */, + 843724D21D4F260A002B398B /* GPUImageTwoInputFilter.m in Sources */, + 843723F61D4F260A002B398B /* GPUImageFASTCornerDetectionFilter.m in Sources */, + 843724901D4F260A002B398B /* GPUImageRGBOpeningFilter.m in Sources */, + 843724861D4F260A002B398B /* GPUImageRawDataOutput.m in Sources */, + 843724F11D4F260A002B398B /* GPUImagePicture.m in Sources */, + 843723E41D4F260A002B398B /* GPUImageDirectionalNonMaximumSuppressionFilter.m in Sources */, + 843724DE1D4F260A002B398B /* GPUImageVignetteFilter.m in Sources */, + 8437245C1D4F260A002B398B /* GPUImageMovie.m in Sources */, 84001FD91D0016380026C63F /* LFHardwareVideoEncoder.m in Sources */, + 843724A61D4F260A002B398B /* GPUImageSobelEdgeDetectionFilter.m in Sources */, + 843724281D4F260A002B398B /* GPUImageHueBlendFilter.m in Sources */, + 843723B61D4F260A002B398B /* GPUImageBulgeDistortionFilter.m in Sources */, + 8437243A1D4F260A002B398B /* GPUImageLightenBlendFilter.m in Sources */, + 843724AC1D4F260A002B398B /* GPUImageSolarizeFilter.m in Sources */, + 843724481D4F260A002B398B /* GPUImageLuminanceThresholdFilter.m in Sources */, + 843723C61D4F260A002B398B /* GPUImageColorConversion.m in Sources */, + 843724561D4F260A002B398B /* GPUImageMosaicFilter.m in Sources */, + 8437245E1D4F260A002B398B /* GPUImageMovieComposition.m in Sources */, + 843724A81D4F260A002B398B /* GPUImageSoftEleganceFilter.m in Sources */, + 843724961D4F260A002B398B /* GPUImageScreenBlendFilter.m in Sources */, + 843724541D4F260A002B398B /* GPUImageMonochromeFilter.m in Sources */, + 843723B41D4F260A002B398B /* GPUImageBuffer.m in Sources */, + 8437239B1D4F260A002B398B /* GLProgram.m in Sources */, + 843724E81D4F260A002B398B /* GPUImageZoomBlurFilter.m in Sources */, 84001FEC1D0016380026C63F /* LFLiveStreamInfo.m in Sources */, + 8437244A1D4F260A002B398B /* GPUImageLuminosity.m in Sources */, + 843724FC1D4F260A002B398B /* hashswf.c in Sources */, + 843724321D4F260A002B398B /* GPUImageKuwaharaRadius3Filter.m in Sources */, + 843724E21D4F260A002B398B /* GPUImageWeakPixelInclusionFilter.m in Sources */, 84001FEA1D0016380026C63F /* LFLiveDebug.m in Sources */, + 8437244C1D4F260A002B398B /* GPUImageLuminosityBlendFilter.m in Sources */, + 843724FE1D4F260A002B398B /* log.c in Sources */, + 8437241E1D4F260A002B398B /* GPUImageHistogramEqualizationFilter.m in Sources */, 84001FEE1D0016380026C63F /* LFVideoFrame.m in Sources */, + 843723DE1D4F260A002B398B /* GPUImageDarkenBlendFilter.m in Sources */, + 843723D41D4F260A002B398B /* GPUImageColourFASTSamplingOperation.m in Sources */, + 843724921D4F260A002B398B /* GPUImageSaturationBlendFilter.m in Sources */, + 843724261D4F260A002B398B /* GPUImageHSBFilter.m in Sources */, + 843724E61D4F260A002B398B /* GPUImageXYDerivativeFilter.m in Sources */, + 843724401D4F260A002B398B /* GPUImageLocalBinaryPatternFilter.m in Sources */, + 8437240E1D4F260A002B398B /* GPUImageGrayscaleFilter.m in Sources */, + 843724361D4F260A002B398B /* GPUImageLaplacianFilter.m in Sources */, + 843723FE1D4F260A002B398B /* GPUImageFourInputFilter.m in Sources */, + 843724061D4F260A002B398B /* GPUImageGaussianBlurFilter.m in Sources */, + 843724A21D4F260A002B398B /* GPUImageSkinToneFilter.m in Sources */, + 8437249C1D4F260A002B398B /* GPUImageShiTomasiFeatureDetectionFilter.m in Sources */, + 843724601D4F260A002B398B /* GPUImageMultiplyBlendFilter.m in Sources */, + 843723E61D4F260A002B398B /* GPUImageDirectionalSobelEdgeDetectionFilter.m in Sources */, + 8437246A1D4F260A002B398B /* GPUImageOpeningFilter.m in Sources */, + 8437247C1D4F260A002B398B /* GPUImagePolarPixellateFilter.m in Sources */, + 843724381D4F260A002B398B /* GPUImageLevelsFilter.m in Sources */, + 8437248C1D4F260A002B398B /* GPUImageRGBErosionFilter.m in Sources */, + 843723CE1D4F260A002B398B /* GPUImageColorMatrixFilter.m in Sources */, + 8437242E1D4F260A002B398B /* GPUImageJFAVoronoiFilter.m in Sources */, + 843723CC1D4F260A002B398B /* GPUImageColorLocalBinaryPatternFilter.m in Sources */, + 8437239E1D4F260A002B398B /* GPUImage3x3ConvolutionFilter.m in Sources */, + 843724021D4F260A002B398B /* GPUImageFramebufferCache.m in Sources */, + 843724501D4F260A002B398B /* GPUImageMedianFilter.m in Sources */, + 8437240C1D4F260A002B398B /* GPUImageGlassSphereFilter.m in Sources */, + 843724DA1D4F260A002B398B /* GPUImageUnsharpMaskFilter.m in Sources */, + 8437240A1D4F260A002B398B /* GPUImageGaussianSelectiveBlurFilter.m in Sources */, + 843723AE1D4F260A002B398B /* GPUImageBilateralFilter.m in Sources */, + 843724141D4F260A002B398B /* GPUImageHarrisCornerDetectionFilter.m in Sources */, + 843724C01D4F260A002B398B /* GPUImageThreeInputFilter.m in Sources */, + 843724E01D4F260A002B398B /* GPUImageVoronoiConsumerFilter.m in Sources */, + 843724721D4F260A002B398B /* GPUImagePerlinNoiseFilter.m in Sources */, + 843724701D4F260A002B398B /* GPUImageParallelCoordinateLineTransformFilter.m in Sources */, + 843723F81D4F260A002B398B /* GPUImageFilter.m in Sources */, + 843724881D4F260A002B398B /* GPUImageRGBClosingFilter.m in Sources */, + 8437242A1D4F260A002B398B /* GPUImageHueFilter.m in Sources */, + 843724D41D4F260A002B398B /* GPUImageTwoPassFilter.m in Sources */, + 843723CA1D4F260A002B398B /* GPUImageColorInvertFilter.m in Sources */, + 843724D01D4F260A002B398B /* GPUImageTwoInputCrossTextureSamplingFilter.m in Sources */, + 843724421D4F260A002B398B /* GPUImageLookupFilter.m in Sources */, + 843723BA1D4F260A002B398B /* GPUImageCGAColorspaceFilter.m in Sources */, + 843724681D4F260A002B398B /* GPUImageOpacityFilter.m in Sources */, + 843724D81D4F260A002B398B /* GPUImageUIElement.m in Sources */, + 843724981D4F260A002B398B /* GPUImageSepiaFilter.m in Sources */, + 843724461D4F260A002B398B /* GPUImageLuminanceRangeFilter.m in Sources */, 84001FD71D0016380026C63F /* LFHardwareAudioEncoder.m in Sources */, + 843723BE1D4F260A002B398B /* GPUImageChromaKeyFilter.m in Sources */, + 843724761D4F260A002B398B /* GPUImagePixellateFilter.m in Sources */, + 843724641D4F260A002B398B /* GPUImageNonMaximumSuppressionFilter.m in Sources */, + 843724181D4F260A002B398B /* GPUImageHighlightShadowFilter.m in Sources */, + 843723EE1D4F260A002B398B /* GPUImageErosionFilter.m in Sources */, + 843723F41D4F260A002B398B /* GPUImageFalseColorFilter.m in Sources */, + 843723A61D4F260A002B398B /* GPUImageAlphaBlendFilter.m in Sources */, + 843723D21D4F260A002B398B /* GPUImageColourFASTFeatureDetector.m in Sources */, + 843724B41D4F260A002B398B /* GPUImageStillCamera.m in Sources */, + 843724B61D4F260A002B398B /* GPUImageStretchDistortionFilter.m in Sources */, + 843724001D4F260A002B398B /* GPUImageFramebuffer.m in Sources */, + 843724C61D4F260A002B398B /* GPUImageThresholdSketchFilter.m in Sources */, + 8437243C1D4F260A002B398B /* GPUImageLinearBurnBlendFilter.m in Sources */, + 843724EB1D4F260A002B398B /* GPUImageContext.m in Sources */, + 843724C81D4F260A002B398B /* GPUImageTiltShiftFilter.m in Sources */, + 843725001D4F260A002B398B /* parseurl.c in Sources */, + 843724EF1D4F260A002B398B /* GPUImagePicture+TextureSubimage.m in Sources */, + 843723C81D4F260A002B398B /* GPUImageColorDodgeBlendFilter.m in Sources */, + 8437249E1D4F260A002B398B /* GPUImageSingleComponentGaussianBlurFilter.m in Sources */, + 843723E21D4F260A002B398B /* GPUImageDilationFilter.m in Sources */, + 843724661D4F260A002B398B /* GPUImageNormalBlendFilter.m in Sources */, + 843723AC1D4F260A002B398B /* GPUImageAverageLuminanceThresholdFilter.m in Sources */, + 843723FA1D4F260A002B398B /* GPUImageFilterGroup.m in Sources */, 84001FE01D0016380026C63F /* LFGPUImageBeautyFilter.m in Sources */, B2CD146E1D45F18B008082E8 /* LFAVEncoder.mm in Sources */, + 843723FC1D4F260A002B398B /* GPUImageFilterPipeline.m in Sources */, + 843724441D4F260A002B398B /* GPUImageLowPassFilter.m in Sources */, + 843725011D4F260A002B398B /* rtmp.c in Sources */, + 843724221D4F260A002B398B /* GPUImageHistogramGenerator.m in Sources */, + 843724621D4F260A002B398B /* GPUImageNobleCornerDetectionFilter.m in Sources */, + 843724341D4F260A002B398B /* GPUImageLanczosResamplingFilter.m in Sources */, + B2CD146E1D45F18B008082E8 /* LFAVEncoder.mm in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -675,39 +2108,69 @@ }; 84001F9F1D0015D10026C63F /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = A17586B27CD6843997425CCF /* Pods-LFLiveKit.debug.xcconfig */; + baseConfigurationReference = D0BB7E7CE5403C4911E026B9 /* Pods-LFLiveKit.debug.xcconfig */; buildSettings = { DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_BITCODE = NO; + ENABLE_BITCODE = YES; INFOPLIST_FILE = LFLiveKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/LFLiveKit/publish/libpili-librtmp", + ); + OTHER_CFLAGS = ( + "$(inherited)", + "-isystem", + "\"${PODS_ROOT}/Headers/Public\"", + "-isystem", + "\"${PODS_ROOT}/Headers/Public/LMGPUImage\"", + "-isystem", + "\"${PODS_ROOT}/Headers/Public/pili-librtmp\"", + "-fembed-bitcode", + ); PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKit.LFLiveKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + USER_HEADER_SEARCH_PATHS = "$(BUILT_PRODUCTS_DIR)/**"; }; name = Debug; }; 84001FA01D0015D10026C63F /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = B75B965E6B94DE4CBCC82EA7 /* Pods-LFLiveKit.release.xcconfig */; + baseConfigurationReference = 0BA5A0CE1F07E1D707F69735 /* Pods-LFLiveKit.release.xcconfig */; buildSettings = { DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - ENABLE_BITCODE = NO; + ENABLE_BITCODE = YES; INFOPLIST_FILE = LFLiveKit/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/LFLiveKit/publish/libpili-librtmp", + ); + OTHER_CFLAGS = ( + "$(inherited)", + "-isystem", + "\"${PODS_ROOT}/Headers/Public\"", + "-isystem", + "\"${PODS_ROOT}/Headers/Public/LMGPUImage\"", + "-isystem", + "\"${PODS_ROOT}/Headers/Public/pili-librtmp\"", + "-fembed-bitcode", + ); PRODUCT_BUNDLE_IDENTIFIER = com.youku.LFLiveKit.LFLiveKit; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + USER_HEADER_SEARCH_PATHS = "$(BUILT_PRODUCTS_DIR)/**"; }; name = Release; }; diff --git a/LFLiveKit.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate b/LFLiveKit.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate index 769c914b..14912fab 100644 Binary files a/LFLiveKit.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate and b/LFLiveKit.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/LFLiveKit.xcworkspace/contents.xcworkspacedata b/LFLiveKit.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 7e1121d5..00000000 --- a/LFLiveKit.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - diff --git a/LFLiveKit.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate b/LFLiveKit.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100644 index 90ff3d38..00000000 Binary files a/LFLiveKit.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/LFLiveKit/Info.plist b/LFLiveKit/Info.plist index 6e2e047f..dfb64922 100644 --- a/LFLiveKit/Info.plist +++ b/LFLiveKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.9.0 + 2.0 CFBundleSignature ???? CFBundleVersion diff --git a/LFLiveKit/LFLiveSession.m b/LFLiveKit/LFLiveSession.m index a06dc306..a3a27abf 100755 --- a/LFLiveKit/LFLiveSession.m +++ b/LFLiveKit/LFLiveSession.m @@ -15,6 +15,7 @@ #import "LFStreamRTMPSocket.h" #import "LFLiveStreamInfo.h" #import "LFGPUImageBeautyFilter.h" +#import "LFH264VideoEncoder.h" #define LFLiveReportKey @"com.youku.liveSessionReport" @@ -95,6 +96,7 @@ - (void)startLive:(LFLiveStreamInfo *)streamInfo { - (void)stopLive { self.uploading = NO; [self.socket stop]; + self.socket = nil; } #pragma mark -- CaptureDelegate diff --git a/LFLiveKit/Vendor/GPUImage/GLProgram.h b/LFLiveKit/Vendor/GPUImage/GLProgram.h new file mode 100755 index 00000000..cd455e71 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GLProgram.h @@ -0,0 +1,42 @@ +// This is Jeff LaMarche's GLProgram OpenGL shader wrapper class from his OpenGL ES 2.0 book. +// A description of this can be found at his page on the topic: +// http://iphonedevelopment.blogspot.com/2010/11/opengl-es-20-for-ios-chapter-4.html +// I've extended this to be able to take programs as NSStrings in addition to files, for baked-in shaders + +#import + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +#import +#import +#else +#import +#import +#endif + +@interface GLProgram : NSObject +{ + NSMutableArray *attributes; + NSMutableArray *uniforms; + GLuint program, + vertShader, + fragShader; +} + +@property(readwrite, nonatomic) BOOL initialized; +@property(readwrite, copy, nonatomic) NSString *vertexShaderLog; +@property(readwrite, copy, nonatomic) NSString *fragmentShaderLog; +@property(readwrite, copy, nonatomic) NSString *programLog; + +- (id)initWithVertexShaderString:(NSString *)vShaderString + fragmentShaderString:(NSString *)fShaderString; +- (id)initWithVertexShaderString:(NSString *)vShaderString + fragmentShaderFilename:(NSString *)fShaderFilename; +- (id)initWithVertexShaderFilename:(NSString *)vShaderFilename + fragmentShaderFilename:(NSString *)fShaderFilename; +- (void)addAttribute:(NSString *)attributeName; +- (GLuint)attributeIndex:(NSString *)attributeName; +- (GLuint)uniformIndex:(NSString *)uniformName; +- (BOOL)link; +- (void)use; +- (void)validate; +@end diff --git a/LFLiveKit/Vendor/GPUImage/GLProgram.m b/LFLiveKit/Vendor/GPUImage/GLProgram.m new file mode 100755 index 00000000..105d75fe --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GLProgram.m @@ -0,0 +1,236 @@ +// This is Jeff LaMarche's GLProgram OpenGL shader wrapper class from his OpenGL ES 2.0 book. +// A description of this can be found at his page on the topic: +// http://iphonedevelopment.blogspot.com/2010/11/opengl-es-20-for-ios-chapter-4.html + + +#import "GLProgram.h" +// START:typedefs +#pragma mark Function Pointer Definitions +typedef void (*GLInfoFunction)(GLuint program, GLenum pname, GLint* params); +typedef void (*GLLogFunction) (GLuint program, GLsizei bufsize, GLsizei* length, GLchar* infolog); +// END:typedefs +#pragma mark - +#pragma mark Private Extension Method Declaration +// START:extension +@interface GLProgram() + +- (BOOL)compileShader:(GLuint *)shader + type:(GLenum)type + string:(NSString *)shaderString; +@end +// END:extension +#pragma mark - + +@implementation GLProgram +// START:init + +@synthesize initialized = _initialized; + +- (id)initWithVertexShaderString:(NSString *)vShaderString + fragmentShaderString:(NSString *)fShaderString; +{ + if ((self = [super init])) + { + _initialized = NO; + + attributes = [[NSMutableArray alloc] init]; + uniforms = [[NSMutableArray alloc] init]; + program = glCreateProgram(); + + if (![self compileShader:&vertShader + type:GL_VERTEX_SHADER + string:vShaderString]) + { + NSLog(@"Failed to compile vertex shader"); + } + + // Create and compile fragment shader + if (![self compileShader:&fragShader + type:GL_FRAGMENT_SHADER + string:fShaderString]) + { + NSLog(@"Failed to compile fragment shader"); + } + + glAttachShader(program, vertShader); + glAttachShader(program, fragShader); + } + + return self; +} + +- (id)initWithVertexShaderString:(NSString *)vShaderString + fragmentShaderFilename:(NSString *)fShaderFilename; +{ + NSString *fragShaderPathname = [[NSBundle mainBundle] pathForResource:fShaderFilename ofType:@"fsh"]; + NSString *fragmentShaderString = [NSString stringWithContentsOfFile:fragShaderPathname encoding:NSUTF8StringEncoding error:nil]; + + if ((self = [self initWithVertexShaderString:vShaderString fragmentShaderString:fragmentShaderString])) + { + } + + return self; +} + +- (id)initWithVertexShaderFilename:(NSString *)vShaderFilename + fragmentShaderFilename:(NSString *)fShaderFilename; +{ + NSString *vertShaderPathname = [[NSBundle mainBundle] pathForResource:vShaderFilename ofType:@"vsh"]; + NSString *vertexShaderString = [NSString stringWithContentsOfFile:vertShaderPathname encoding:NSUTF8StringEncoding error:nil]; + + NSString *fragShaderPathname = [[NSBundle mainBundle] pathForResource:fShaderFilename ofType:@"fsh"]; + NSString *fragmentShaderString = [NSString stringWithContentsOfFile:fragShaderPathname encoding:NSUTF8StringEncoding error:nil]; + + if ((self = [self initWithVertexShaderString:vertexShaderString fragmentShaderString:fragmentShaderString])) + { + } + + return self; +} +// END:init +// START:compile +- (BOOL)compileShader:(GLuint *)shader + type:(GLenum)type + string:(NSString *)shaderString +{ +// CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); + + GLint status; + const GLchar *source; + + source = + (GLchar *)[shaderString UTF8String]; + if (!source) + { + NSLog(@"Failed to load vertex shader"); + return NO; + } + + *shader = glCreateShader(type); + glShaderSource(*shader, 1, &source, NULL); + glCompileShader(*shader); + + glGetShaderiv(*shader, GL_COMPILE_STATUS, &status); + + if (status != GL_TRUE) + { + GLint logLength; + glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) + { + GLchar *log = (GLchar *)malloc(logLength); + glGetShaderInfoLog(*shader, logLength, &logLength, log); + if (shader == &vertShader) + { + self.vertexShaderLog = [NSString stringWithFormat:@"%s", log]; + } + else + { + self.fragmentShaderLog = [NSString stringWithFormat:@"%s", log]; + } + + free(log); + } + } + +// CFAbsoluteTime linkTime = (CFAbsoluteTimeGetCurrent() - startTime); +// NSLog(@"Compiled in %f ms", linkTime * 1000.0); + + return status == GL_TRUE; +} +// END:compile +#pragma mark - +// START:addattribute +- (void)addAttribute:(NSString *)attributeName +{ + if (![attributes containsObject:attributeName]) + { + [attributes addObject:attributeName]; + glBindAttribLocation(program, + (GLuint)[attributes indexOfObject:attributeName], + [attributeName UTF8String]); + } +} +// END:addattribute +// START:indexmethods +- (GLuint)attributeIndex:(NSString *)attributeName +{ + return (GLuint)[attributes indexOfObject:attributeName]; +} +- (GLuint)uniformIndex:(NSString *)uniformName +{ + return glGetUniformLocation(program, [uniformName UTF8String]); +} +// END:indexmethods +#pragma mark - +// START:link +- (BOOL)link +{ +// CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); + + GLint status; + + glLinkProgram(program); + + glGetProgramiv(program, GL_LINK_STATUS, &status); + if (status == GL_FALSE) + return NO; + + if (vertShader) + { + glDeleteShader(vertShader); + vertShader = 0; + } + if (fragShader) + { + glDeleteShader(fragShader); + fragShader = 0; + } + + self.initialized = YES; + +// CFAbsoluteTime linkTime = (CFAbsoluteTimeGetCurrent() - startTime); +// NSLog(@"Linked in %f ms", linkTime * 1000.0); + + return YES; +} +// END:link +// START:use +- (void)use +{ + glUseProgram(program); +} +// END:use +#pragma mark - + +- (void)validate; +{ + GLint logLength; + + glValidateProgram(program); + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &logLength); + if (logLength > 0) + { + GLchar *log = (GLchar *)malloc(logLength); + glGetProgramInfoLog(program, logLength, &logLength, log); + self.programLog = [NSString stringWithFormat:@"%s", log]; + free(log); + } +} + +#pragma mark - +// START:dealloc +- (void)dealloc +{ + if (vertShader) + glDeleteShader(vertShader); + + if (fragShader) + glDeleteShader(fragShader); + + if (program) + glDeleteProgram(program); + +} +// END:dealloc +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImage.h b/LFLiveKit/Vendor/GPUImage/GPUImage.h new file mode 100755 index 00000000..3e91c29c --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImage.h @@ -0,0 +1,170 @@ +#import "GLProgram.h" + +// Base classes +#import "GPUImageContext.h" +#import "GPUImageOutput.h" +#import "GPUImageView.h" +#import "GPUImageVideoCamera.h" +#import "GPUImageStillCamera.h" +#import "GPUImageMovie.h" +#import "GPUImagePicture.h" +#import "GPUImageRawDataInput.h" +#import "GPUImageRawDataOutput.h" +#import "GPUImageMovieWriter.h" +#import "GPUImageFilterPipeline.h" +#import "GPUImageTextureOutput.h" +#import "GPUImageFilterGroup.h" +#import "GPUImageTextureInput.h" +#import "GPUImageUIElement.h" +#import "GPUImageBuffer.h" +#import "GPUImageFramebuffer.h" +#import "GPUImageFramebufferCache.h" + +// Filters +#import "GPUImageFilter.h" +#import "GPUImageTwoInputFilter.h" +#import "GPUImagePixellateFilter.h" +#import "GPUImagePixellatePositionFilter.h" +#import "GPUImageSepiaFilter.h" +#import "GPUImageColorInvertFilter.h" +#import "GPUImageSaturationFilter.h" +#import "GPUImageContrastFilter.h" +#import "GPUImageExposureFilter.h" +#import "GPUImageBrightnessFilter.h" +#import "GPUImageLevelsFilter.h" +#import "GPUImageSharpenFilter.h" +#import "GPUImageGammaFilter.h" +#import "GPUImageSobelEdgeDetectionFilter.h" +#import "GPUImageSketchFilter.h" +#import "GPUImageToonFilter.h" +#import "GPUImageSmoothToonFilter.h" +#import "GPUImageMultiplyBlendFilter.h" +#import "GPUImageDissolveBlendFilter.h" +#import "GPUImageKuwaharaFilter.h" +#import "GPUImageKuwaharaRadius3Filter.h" +#import "GPUImageVignetteFilter.h" +#import "GPUImageGaussianBlurFilter.h" +#import "GPUImageGaussianBlurPositionFilter.h" +#import "GPUImageGaussianSelectiveBlurFilter.h" +#import "GPUImageOverlayBlendFilter.h" +#import "GPUImageDarkenBlendFilter.h" +#import "GPUImageLightenBlendFilter.h" +#import "GPUImageSwirlFilter.h" +#import "GPUImageSourceOverBlendFilter.h" +#import "GPUImageColorBurnBlendFilter.h" +#import "GPUImageColorDodgeBlendFilter.h" +#import "GPUImageScreenBlendFilter.h" +#import "GPUImageExclusionBlendFilter.h" +#import "GPUImageDifferenceBlendFilter.h" +#import "GPUImageSubtractBlendFilter.h" +#import "GPUImageHardLightBlendFilter.h" +#import "GPUImageSoftLightBlendFilter.h" +#import "GPUImageColorBlendFilter.h" +#import "GPUImageHueBlendFilter.h" +#import "GPUImageSaturationBlendFilter.h" +#import "GPUImageLuminosityBlendFilter.h" +#import "GPUImageCropFilter.h" +#import "GPUImageGrayscaleFilter.h" +#import "GPUImageTransformFilter.h" +#import "GPUImageChromaKeyBlendFilter.h" +#import "GPUImageHazeFilter.h" +#import "GPUImageLuminanceThresholdFilter.h" +#import "GPUImagePosterizeFilter.h" +#import "GPUImageBoxBlurFilter.h" +#import "GPUImageAdaptiveThresholdFilter.h" +#import "GPUImageSolarizeFilter.h" +#import "GPUImageUnsharpMaskFilter.h" +#import "GPUImageBulgeDistortionFilter.h" +#import "GPUImagePinchDistortionFilter.h" +#import "GPUImageCrosshatchFilter.h" +#import "GPUImageCGAColorspaceFilter.h" +#import "GPUImagePolarPixellateFilter.h" +#import "GPUImageStretchDistortionFilter.h" +#import "GPUImagePerlinNoiseFilter.h" +#import "GPUImageJFAVoronoiFilter.h" +#import "GPUImageVoronoiConsumerFilter.h" +#import "GPUImageMosaicFilter.h" +#import "GPUImageTiltShiftFilter.h" +#import "GPUImage3x3ConvolutionFilter.h" +#import "GPUImageEmbossFilter.h" +#import "GPUImageCannyEdgeDetectionFilter.h" +#import "GPUImageThresholdEdgeDetectionFilter.h" +#import "GPUImageMaskFilter.h" +#import "GPUImageHistogramFilter.h" +#import "GPUImageHistogramGenerator.h" +#import "GPUImageHistogramEqualizationFilter.h" +#import "GPUImagePrewittEdgeDetectionFilter.h" +#import "GPUImageXYDerivativeFilter.h" +#import "GPUImageHarrisCornerDetectionFilter.h" +#import "GPUImageAlphaBlendFilter.h" +#import "GPUImageNormalBlendFilter.h" +#import "GPUImageNonMaximumSuppressionFilter.h" +#import "GPUImageRGBFilter.h" +#import "GPUImageMedianFilter.h" +#import "GPUImageBilateralFilter.h" +#import "GPUImageCrosshairGenerator.h" +#import "GPUImageToneCurveFilter.h" +#import "GPUImageNobleCornerDetectionFilter.h" +#import "GPUImageShiTomasiFeatureDetectionFilter.h" +#import "GPUImageErosionFilter.h" +#import "GPUImageRGBErosionFilter.h" +#import "GPUImageDilationFilter.h" +#import "GPUImageRGBDilationFilter.h" +#import "GPUImageOpeningFilter.h" +#import "GPUImageRGBOpeningFilter.h" +#import "GPUImageClosingFilter.h" +#import "GPUImageRGBClosingFilter.h" +#import "GPUImageColorPackingFilter.h" +#import "GPUImageSphereRefractionFilter.h" +#import "GPUImageMonochromeFilter.h" +#import "GPUImageOpacityFilter.h" +#import "GPUImageHighlightShadowFilter.h" +#import "GPUImageFalseColorFilter.h" +#import "GPUImageHSBFilter.h" +#import "GPUImageHueFilter.h" +#import "GPUImageGlassSphereFilter.h" +#import "GPUImageLookupFilter.h" +#import "GPUImageAmatorkaFilter.h" +#import "GPUImageMissEtikateFilter.h" +#import "GPUImageSoftEleganceFilter.h" +#import "GPUImageAddBlendFilter.h" +#import "GPUImageDivideBlendFilter.h" +#import "GPUImagePolkaDotFilter.h" +#import "GPUImageLocalBinaryPatternFilter.h" +#import "GPUImageColorLocalBinaryPatternFilter.h" +#import "GPUImageLanczosResamplingFilter.h" +#import "GPUImageAverageColor.h" +#import "GPUImageSolidColorGenerator.h" +#import "GPUImageLuminosity.h" +#import "GPUImageAverageLuminanceThresholdFilter.h" +#import "GPUImageWhiteBalanceFilter.h" +#import "GPUImageChromaKeyFilter.h" +#import "GPUImageLowPassFilter.h" +#import "GPUImageHighPassFilter.h" +#import "GPUImageMotionDetector.h" +#import "GPUImageHalftoneFilter.h" +#import "GPUImageThresholdedNonMaximumSuppressionFilter.h" +#import "GPUImageHoughTransformLineDetector.h" +#import "GPUImageParallelCoordinateLineTransformFilter.h" +#import "GPUImageThresholdSketchFilter.h" +#import "GPUImageLineGenerator.h" +#import "GPUImageLinearBurnBlendFilter.h" +#import "GPUImageGaussianBlurPositionFilter.h" +#import "GPUImagePixellatePositionFilter.h" +#import "GPUImageTwoInputCrossTextureSamplingFilter.h" +#import "GPUImagePoissonBlendFilter.h" +#import "GPUImageMotionBlurFilter.h" +#import "GPUImageZoomBlurFilter.h" +#import "GPUImageLaplacianFilter.h" +#import "GPUImageiOSBlurFilter.h" +#import "GPUImageLuminanceRangeFilter.h" +#import "GPUImageDirectionalNonMaximumSuppressionFilter.h" +#import "GPUImageDirectionalSobelEdgeDetectionFilter.h" +#import "GPUImageSingleComponentGaussianBlurFilter.h" +#import "GPUImageThreeInputFilter.h" +#import "GPUImageFourInputFilter.h" +#import "GPUImageWeakPixelInclusionFilter.h" +#import "GPUImageColorConversion.h" +#import "GPUImageColourFASTFeatureDetector.h" +#import "GPUImageColourFASTSamplingOperation.h" + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImage3x3ConvolutionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImage3x3ConvolutionFilter.h new file mode 100755 index 00000000..67e68def --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImage3x3ConvolutionFilter.h @@ -0,0 +1,18 @@ +#import "GPUImage3x3TextureSamplingFilter.h" + +/** Runs a 3x3 convolution kernel against the image + */ +@interface GPUImage3x3ConvolutionFilter : GPUImage3x3TextureSamplingFilter +{ + GLint convolutionMatrixUniform; +} + +/** Convolution kernel to run against the image + + The convolution kernel is a 3x3 matrix of values to apply to the pixel and its 8 surrounding pixels. + The matrix is specified in row-major order, with the top left pixel being one.one and the bottom right three.three + If the values in the matrix don't add up to 1.0, the image could be brightened or darkened. + */ +@property(readwrite, nonatomic) GPUMatrix3x3 convolutionKernel; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImage3x3ConvolutionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImage3x3ConvolutionFilter.m new file mode 100755 index 00000000..c623ac67 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImage3x3ConvolutionFilter.m @@ -0,0 +1,128 @@ +#import "GPUImage3x3ConvolutionFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImage3x3ConvolutionFragmentShaderString = SHADER_STRING +( + precision highp float; + + uniform sampler2D inputImageTexture; + + uniform mediump mat3 convolutionMatrix; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + void main() + { + mediump vec3 bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + mediump vec3 bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb; + mediump vec3 bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb; + mediump vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); + mediump vec3 leftColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + mediump vec3 rightColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; + mediump vec3 topColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; + mediump vec3 topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).rgb; + mediump vec3 topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).rgb; + + mediump vec3 resultColor = topLeftColor * convolutionMatrix[0][0] + topColor * convolutionMatrix[0][1] + topRightColor * convolutionMatrix[0][2]; + resultColor += leftColor * convolutionMatrix[1][0] + centerColor.rgb * convolutionMatrix[1][1] + rightColor * convolutionMatrix[1][2]; + resultColor += bottomLeftColor * convolutionMatrix[2][0] + bottomColor * convolutionMatrix[2][1] + bottomRightColor * convolutionMatrix[2][2]; + + gl_FragColor = vec4(resultColor, centerColor.a); + } +); +#else +NSString *const kGPUImage3x3ConvolutionFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + uniform mat3 convolutionMatrix; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + void main() + { + vec3 bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + vec3 bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb; + vec3 bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb; + vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); + vec3 leftColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + vec3 rightColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; + vec3 topColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; + vec3 topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).rgb; + vec3 topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).rgb; + + vec3 resultColor = topLeftColor * convolutionMatrix[0][0] + topColor * convolutionMatrix[0][1] + topRightColor * convolutionMatrix[0][2]; + resultColor += leftColor * convolutionMatrix[1][0] + centerColor.rgb * convolutionMatrix[1][1] + rightColor * convolutionMatrix[1][2]; + resultColor += bottomLeftColor * convolutionMatrix[2][0] + bottomColor * convolutionMatrix[2][1] + bottomRightColor * convolutionMatrix[2][2]; + + gl_FragColor = vec4(resultColor, centerColor.a); + } +); +#endif + +@implementation GPUImage3x3ConvolutionFilter + +@synthesize convolutionKernel = _convolutionKernel; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImage3x3ConvolutionFragmentShaderString])) + { + return nil; + } + + self.convolutionKernel = (GPUMatrix3x3){ + {0.f, 0.f, 0.f}, + {0.f, 1.f, 0.f}, + {0.f, 0.f, 0.f} + }; + + return self; +} + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [super initWithFragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + convolutionMatrixUniform = [filterProgram uniformIndex:@"convolutionMatrix"]; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setConvolutionKernel:(GPUMatrix3x3)newValue; +{ + _convolutionKernel = newValue; + + [self setMatrix3f:_convolutionKernel forUniform:convolutionMatrixUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImage3x3TextureSamplingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImage3x3TextureSamplingFilter.h new file mode 100644 index 00000000..5599e156 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImage3x3TextureSamplingFilter.h @@ -0,0 +1,18 @@ +#import "GPUImageFilter.h" + +extern NSString *const kGPUImageNearbyTexelSamplingVertexShaderString; + +@interface GPUImage3x3TextureSamplingFilter : GPUImageFilter +{ + GLint texelWidthUniform, texelHeightUniform; + + CGFloat texelWidth, texelHeight; + BOOL hasOverriddenImageSizeFactor; +} + +// The texel width and height determines how far out to sample from this texel. By default, this is the normalized width of a pixel, but this can be overridden for different effects. +@property(readwrite, nonatomic) CGFloat texelWidth; +@property(readwrite, nonatomic) CGFloat texelHeight; + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImage3x3TextureSamplingFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImage3x3TextureSamplingFilter.m new file mode 100644 index 00000000..05c4d50c --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImage3x3TextureSamplingFilter.m @@ -0,0 +1,121 @@ +#import "GPUImage3x3TextureSamplingFilter.h" + +// Override vertex shader to remove dependent texture reads +NSString *const kGPUImageNearbyTexelSamplingVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + + uniform float texelWidth; + uniform float texelHeight; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + void main() + { + gl_Position = position; + + vec2 widthStep = vec2(texelWidth, 0.0); + vec2 heightStep = vec2(0.0, texelHeight); + vec2 widthHeightStep = vec2(texelWidth, texelHeight); + vec2 widthNegativeHeightStep = vec2(texelWidth, -texelHeight); + + textureCoordinate = inputTextureCoordinate.xy; + leftTextureCoordinate = inputTextureCoordinate.xy - widthStep; + rightTextureCoordinate = inputTextureCoordinate.xy + widthStep; + + topTextureCoordinate = inputTextureCoordinate.xy - heightStep; + topLeftTextureCoordinate = inputTextureCoordinate.xy - widthHeightStep; + topRightTextureCoordinate = inputTextureCoordinate.xy + widthNegativeHeightStep; + + bottomTextureCoordinate = inputTextureCoordinate.xy + heightStep; + bottomLeftTextureCoordinate = inputTextureCoordinate.xy - widthNegativeHeightStep; + bottomRightTextureCoordinate = inputTextureCoordinate.xy + widthHeightStep; + } +); + + +@implementation GPUImage3x3TextureSamplingFilter + +@synthesize texelWidth = _texelWidth; +@synthesize texelHeight = _texelHeight; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithVertexShaderFromString:(NSString *)vertexShaderString fragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [super initWithVertexShaderFromString:vertexShaderString fragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + texelWidthUniform = [filterProgram uniformIndex:@"texelWidth"]; + texelHeightUniform = [filterProgram uniformIndex:@"texelHeight"]; + + return self; +} + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [self initWithVertexShaderFromString:kGPUImageNearbyTexelSamplingVertexShaderString fragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + return self; +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + if (!hasOverriddenImageSizeFactor) + { + _texelWidth = 1.0 / filterFrameSize.width; + _texelHeight = 1.0 / filterFrameSize.height; + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:filterProgram]; + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + glUniform1f(texelWidthUniform, _texelHeight); + glUniform1f(texelHeightUniform, _texelWidth); + } + else + { + glUniform1f(texelWidthUniform, _texelWidth); + glUniform1f(texelHeightUniform, _texelHeight); + } + }); + } +} + +#pragma mark - +#pragma mark Accessors + +- (void)setTexelWidth:(CGFloat)newValue; +{ + hasOverriddenImageSizeFactor = YES; + _texelWidth = newValue; + + [self setFloat:_texelWidth forUniform:texelWidthUniform program:filterProgram]; +} + +- (void)setTexelHeight:(CGFloat)newValue; +{ + hasOverriddenImageSizeFactor = YES; + _texelHeight = newValue; + + [self setFloat:_texelHeight forUniform:texelHeightUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageAdaptiveThresholdFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageAdaptiveThresholdFilter.h new file mode 100755 index 00000000..32785560 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageAdaptiveThresholdFilter.h @@ -0,0 +1,9 @@ +#import "GPUImageFilterGroup.h" + +@interface GPUImageAdaptiveThresholdFilter : GPUImageFilterGroup + +/** A multiplier for the background averaging blur radius in pixels, with a default of 4 + */ +@property(readwrite, nonatomic) CGFloat blurRadiusInPixels; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageAdaptiveThresholdFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageAdaptiveThresholdFilter.m new file mode 100755 index 00000000..71fa6abf --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageAdaptiveThresholdFilter.m @@ -0,0 +1,100 @@ +#import "GPUImageAdaptiveThresholdFilter.h" +#import "GPUImageFilter.h" +#import "GPUImageTwoInputFilter.h" +#import "GPUImageGrayscaleFilter.h" +#import "GPUImageBoxBlurFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageAdaptiveThresholdFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + highp float blurredInput = texture2D(inputImageTexture, textureCoordinate).r; + highp float localLuminance = texture2D(inputImageTexture2, textureCoordinate2).r; + highp float thresholdResult = step(blurredInput - 0.05, localLuminance); + + gl_FragColor = vec4(vec3(thresholdResult), 1.0); + } +); +#else +NSString *const kGPUImageAdaptiveThresholdFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + float blurredInput = texture2D(inputImageTexture, textureCoordinate).r; + float localLuminance = texture2D(inputImageTexture2, textureCoordinate2).r; + float thresholdResult = step(blurredInput - 0.05, localLuminance); + + gl_FragColor = vec4(vec3(thresholdResult), 1.0); + } +); +#endif + +@interface GPUImageAdaptiveThresholdFilter() +{ + GPUImageBoxBlurFilter *boxBlurFilter; +} +@end + +@implementation GPUImageAdaptiveThresholdFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + // First pass: reduce to luminance + GPUImageGrayscaleFilter *luminanceFilter = [[GPUImageGrayscaleFilter alloc] init]; + [self addFilter:luminanceFilter]; + + // Second pass: perform a box blur + boxBlurFilter = [[GPUImageBoxBlurFilter alloc] init]; + [self addFilter:boxBlurFilter]; + + // Third pass: compare the blurred background luminance to the local value + GPUImageFilter *adaptiveThresholdFilter = [[GPUImageTwoInputFilter alloc] initWithFragmentShaderFromString:kGPUImageAdaptiveThresholdFragmentShaderString]; + [self addFilter:adaptiveThresholdFilter]; + + [luminanceFilter addTarget:boxBlurFilter]; + + [boxBlurFilter addTarget:adaptiveThresholdFilter]; + // To prevent double updating of this filter, disable updates from the sharp luminance image side + [luminanceFilter addTarget:adaptiveThresholdFilter]; + + self.initialFilters = [NSArray arrayWithObject:luminanceFilter]; + self.terminalFilter = adaptiveThresholdFilter; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBlurRadiusInPixels:(CGFloat)newValue; +{ + boxBlurFilter.blurRadiusInPixels = newValue; +} + +- (CGFloat)blurRadiusInPixels; +{ + return boxBlurFilter.blurRadiusInPixels; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageAddBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageAddBlendFilter.h new file mode 100644 index 00000000..b14c60c6 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageAddBlendFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageAddBlendFilter : GPUImageTwoInputFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageAddBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageAddBlendFilter.m new file mode 100644 index 00000000..c89054a8 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageAddBlendFilter.m @@ -0,0 +1,100 @@ +#import "GPUImageAddBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageAddBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + lowp vec4 base = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + mediump float r; + if (overlay.r * base.a + base.r * overlay.a >= overlay.a * base.a) { + r = overlay.a * base.a + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + } else { + r = overlay.r + base.r; + } + + mediump float g; + if (overlay.g * base.a + base.g * overlay.a >= overlay.a * base.a) { + g = overlay.a * base.a + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + } else { + g = overlay.g + base.g; + } + + mediump float b; + if (overlay.b * base.a + base.b * overlay.a >= overlay.a * base.a) { + b = overlay.a * base.a + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + } else { + b = overlay.b + base.b; + } + + mediump float a = overlay.a + base.a - overlay.a * base.a; + + gl_FragColor = vec4(r, g, b, a); + } +); +#else +NSString *const kGPUImageAddBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 base = texture2D(inputImageTexture, textureCoordinate); + vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + float r; + if (overlay.r * base.a + base.r * overlay.a >= overlay.a * base.a) { + r = overlay.a * base.a + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + } else { + r = overlay.r + base.r; + } + + float g; + if (overlay.g * base.a + base.g * overlay.a >= overlay.a * base.a) { + g = overlay.a * base.a + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + } else { + g = overlay.g + base.g; + } + + float b; + if (overlay.b * base.a + base.b * overlay.a >= overlay.a * base.a) { + b = overlay.a * base.a + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + } else { + b = overlay.b + base.b; + } + + float a = overlay.a + base.a - overlay.a * base.a; + + gl_FragColor = vec4(r, g, b, a); + } +); +#endif + + + +@implementation GPUImageAddBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageAddBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageAlphaBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageAlphaBlendFilter.h new file mode 100755 index 00000000..c4d75759 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageAlphaBlendFilter.h @@ -0,0 +1,11 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageAlphaBlendFilter : GPUImageTwoInputFilter +{ + GLint mixUniform; +} + +// Mix ranges from 0.0 (only image 1) to 1.0 (only image 2), with 1.0 as the normal level +@property(readwrite, nonatomic) CGFloat mix; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageAlphaBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageAlphaBlendFilter.m new file mode 100755 index 00000000..077df790 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageAlphaBlendFilter.m @@ -0,0 +1,72 @@ +#import "GPUImageAlphaBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageAlphaBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform lowp float mixturePercent; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(mix(textureColor.rgb, textureColor2.rgb, textureColor2.a * mixturePercent), textureColor.a); + } +); +#else +NSString *const kGPUImageAlphaBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform float mixturePercent; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(mix(textureColor.rgb, textureColor2.rgb, textureColor2.a * mixturePercent), textureColor.a); + } +); +#endif + +@implementation GPUImageAlphaBlendFilter + +@synthesize mix = _mix; + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageAlphaBlendFragmentShaderString])) + { + return nil; + } + + mixUniform = [filterProgram uniformIndex:@"mixturePercent"]; + self.mix = 0.5; + + return self; +} + + +#pragma mark - +#pragma mark Accessors + +- (void)setMix:(CGFloat)newValue; +{ + _mix = newValue; + + [self setFloat:_mix forUniform:mixUniform program:filterProgram]; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageAmatorkaFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageAmatorkaFilter.h new file mode 100755 index 00000000..1dbe096d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageAmatorkaFilter.h @@ -0,0 +1,17 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImagePicture; + +/** A photo filter based on Photoshop action by Amatorka + http://amatorka.deviantart.com/art/Amatorka-Action-2-121069631 + */ + +// Note: If you want to use this effect you have to add lookup_amatorka.png +// from Resources folder to your application bundle. + +@interface GPUImageAmatorkaFilter : GPUImageFilterGroup +{ + GPUImagePicture *lookupImageSource; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageAmatorkaFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageAmatorkaFilter.m new file mode 100755 index 00000000..1ab3ec4e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageAmatorkaFilter.m @@ -0,0 +1,38 @@ +#import "GPUImageAmatorkaFilter.h" +#import "GPUImagePicture.h" +#import "GPUImageLookupFilter.h" + +@implementation GPUImageAmatorkaFilter + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + UIImage *image = [UIImage imageNamed:@"lookup_amatorka.png"]; +#else + NSImage *image = [NSImage imageNamed:@"lookup_amatorka.png"]; +#endif + + NSAssert(image, @"To use GPUImageAmatorkaFilter you need to add lookup_amatorka.png from GPUImage/framework/Resources to your application bundle."); + + lookupImageSource = [[GPUImagePicture alloc] initWithImage:image]; + GPUImageLookupFilter *lookupFilter = [[GPUImageLookupFilter alloc] init]; + [self addFilter:lookupFilter]; + + [lookupImageSource addTarget:lookupFilter atTextureLocation:1]; + [lookupImageSource processImage]; + + self.initialFilters = [NSArray arrayWithObjects:lookupFilter, nil]; + self.terminalFilter = lookupFilter; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageAverageColor.h b/LFLiveKit/Vendor/GPUImage/GPUImageAverageColor.h new file mode 100644 index 00000000..e3d957d0 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageAverageColor.h @@ -0,0 +1,20 @@ +#import "GPUImageFilter.h" + +extern NSString *const kGPUImageColorAveragingVertexShaderString; + +@interface GPUImageAverageColor : GPUImageFilter +{ + GLint texelWidthUniform, texelHeightUniform; + + NSUInteger numberOfStages; + + GLubyte *rawImagePixels; + CGSize finalStageSize; +} + +// This block is called on the completion of color averaging for a frame +@property(nonatomic, copy) void(^colorAverageProcessingFinishedBlock)(CGFloat redComponent, CGFloat greenComponent, CGFloat blueComponent, CGFloat alphaComponent, CMTime frameTime); + +- (void)extractAverageColorAtFrameTime:(CMTime)frameTime; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageAverageColor.m b/LFLiveKit/Vendor/GPUImage/GPUImageAverageColor.m new file mode 100644 index 00000000..e2dd7e73 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageAverageColor.m @@ -0,0 +1,204 @@ +#import "GPUImageAverageColor.h" + +NSString *const kGPUImageColorAveragingVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + + uniform float texelWidth; + uniform float texelHeight; + + varying vec2 upperLeftInputTextureCoordinate; + varying vec2 upperRightInputTextureCoordinate; + varying vec2 lowerLeftInputTextureCoordinate; + varying vec2 lowerRightInputTextureCoordinate; + + void main() + { + gl_Position = position; + + upperLeftInputTextureCoordinate = inputTextureCoordinate.xy + vec2(-texelWidth, -texelHeight); + upperRightInputTextureCoordinate = inputTextureCoordinate.xy + vec2(texelWidth, -texelHeight); + lowerLeftInputTextureCoordinate = inputTextureCoordinate.xy + vec2(-texelWidth, texelHeight); + lowerRightInputTextureCoordinate = inputTextureCoordinate.xy + vec2(texelWidth, texelHeight); + } + ); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageColorAveragingFragmentShaderString = SHADER_STRING +( + precision highp float; + + uniform sampler2D inputImageTexture; + + varying highp vec2 outputTextureCoordinate; + + varying highp vec2 upperLeftInputTextureCoordinate; + varying highp vec2 upperRightInputTextureCoordinate; + varying highp vec2 lowerLeftInputTextureCoordinate; + varying highp vec2 lowerRightInputTextureCoordinate; + + void main() + { + highp vec4 upperLeftColor = texture2D(inputImageTexture, upperLeftInputTextureCoordinate); + highp vec4 upperRightColor = texture2D(inputImageTexture, upperRightInputTextureCoordinate); + highp vec4 lowerLeftColor = texture2D(inputImageTexture, lowerLeftInputTextureCoordinate); + highp vec4 lowerRightColor = texture2D(inputImageTexture, lowerRightInputTextureCoordinate); + + gl_FragColor = 0.25 * (upperLeftColor + upperRightColor + lowerLeftColor + lowerRightColor); + } +); +#else +NSString *const kGPUImageColorAveragingFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + varying vec2 outputTextureCoordinate; + + varying vec2 upperLeftInputTextureCoordinate; + varying vec2 upperRightInputTextureCoordinate; + varying vec2 lowerLeftInputTextureCoordinate; + varying vec2 lowerRightInputTextureCoordinate; + + void main() + { + vec4 upperLeftColor = texture2D(inputImageTexture, upperLeftInputTextureCoordinate); + vec4 upperRightColor = texture2D(inputImageTexture, upperRightInputTextureCoordinate); + vec4 lowerLeftColor = texture2D(inputImageTexture, lowerLeftInputTextureCoordinate); + vec4 lowerRightColor = texture2D(inputImageTexture, lowerRightInputTextureCoordinate); + + gl_FragColor = 0.25 * (upperLeftColor + upperRightColor + lowerLeftColor + lowerRightColor); + } +); +#endif + +@implementation GPUImageAverageColor + +@synthesize colorAverageProcessingFinishedBlock = _colorAverageProcessingFinishedBlock; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithVertexShaderFromString:kGPUImageColorAveragingVertexShaderString fragmentShaderFromString:kGPUImageColorAveragingFragmentShaderString])) + { + return nil; + } + + texelWidthUniform = [filterProgram uniformIndex:@"texelWidth"]; + texelHeightUniform = [filterProgram uniformIndex:@"texelHeight"]; + finalStageSize = CGSizeMake(1.0, 1.0); + + __unsafe_unretained GPUImageAverageColor *weakSelf = self; + [self setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime) { + [weakSelf extractAverageColorAtFrameTime:frameTime]; + }]; + + return self; +} + +- (void)dealloc; +{ + if (rawImagePixels != NULL) + { + free(rawImagePixels); + } +} + +#pragma mark - +#pragma mark Managing the display FBOs + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + if (self.preventRendering) + { + [firstInputFramebuffer unlock]; + return; + } + + outputFramebuffer = nil; + [GPUImageContext setActiveShaderProgram:filterProgram]; + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + + GLuint currentTexture = [firstInputFramebuffer texture]; + + NSUInteger numberOfReductionsInX = floor(log(inputTextureSize.width) / log(4.0)); + NSUInteger numberOfReductionsInY = floor(log(inputTextureSize.height) / log(4.0)); + NSUInteger reductionsToHitSideLimit = MIN(numberOfReductionsInX, numberOfReductionsInY); + for (NSUInteger currentReduction = 0; currentReduction < reductionsToHitSideLimit; currentReduction++) + { + CGSize currentStageSize = CGSizeMake(floor(inputTextureSize.width / pow(4.0, currentReduction + 1.0)), floor(inputTextureSize.height / pow(4.0, currentReduction + 1.0))); + + [outputFramebuffer unlock]; + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:currentStageSize textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, currentTexture); + + glUniform1i(filterInputTextureUniform, 2); + + glUniform1f(texelWidthUniform, 0.25 / currentStageSize.width); + glUniform1f(texelHeightUniform, 0.25 / currentStageSize.height); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + currentTexture = [outputFramebuffer texture]; + finalStageSize = currentStageSize; + } + + [firstInputFramebuffer unlock]; +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + inputRotation = kGPUImageNoRotation; +} + +- (void)extractAverageColorAtFrameTime:(CMTime)frameTime; +{ + runSynchronouslyOnVideoProcessingQueue(^{ + // we need a normal color texture for averaging the color values + NSAssert(self.outputTextureOptions.internalFormat == GL_RGBA, @"The output texture internal format for this filter must be GL_RGBA."); + NSAssert(self.outputTextureOptions.type == GL_UNSIGNED_BYTE, @"The type of the output texture of this filter must be GL_UNSIGNED_BYTE."); + + NSUInteger totalNumberOfPixels = round(finalStageSize.width * finalStageSize.height); + + if (rawImagePixels == NULL) + { + rawImagePixels = (GLubyte *)malloc(totalNumberOfPixels * 4); + } + + [GPUImageContext useImageProcessingContext]; + [outputFramebuffer activateFramebuffer]; + glReadPixels(0, 0, (int)finalStageSize.width, (int)finalStageSize.height, GL_RGBA, GL_UNSIGNED_BYTE, rawImagePixels); + + NSUInteger redTotal = 0, greenTotal = 0, blueTotal = 0, alphaTotal = 0; + NSUInteger byteIndex = 0; + for (NSUInteger currentPixel = 0; currentPixel < totalNumberOfPixels; currentPixel++) + { + redTotal += rawImagePixels[byteIndex++]; + greenTotal += rawImagePixels[byteIndex++]; + blueTotal += rawImagePixels[byteIndex++]; + alphaTotal += rawImagePixels[byteIndex++]; + } + + CGFloat normalizedRedTotal = (CGFloat)redTotal / (CGFloat)totalNumberOfPixels / 255.0; + CGFloat normalizedGreenTotal = (CGFloat)greenTotal / (CGFloat)totalNumberOfPixels / 255.0; + CGFloat normalizedBlueTotal = (CGFloat)blueTotal / (CGFloat)totalNumberOfPixels / 255.0; + CGFloat normalizedAlphaTotal = (CGFloat)alphaTotal / (CGFloat)totalNumberOfPixels / 255.0; + + if (_colorAverageProcessingFinishedBlock != NULL) + { + _colorAverageProcessingFinishedBlock(normalizedRedTotal, normalizedGreenTotal, normalizedBlueTotal, normalizedAlphaTotal, frameTime); + } + }); +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageAverageLuminanceThresholdFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageAverageLuminanceThresholdFilter.h new file mode 100644 index 00000000..7f1ae464 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageAverageLuminanceThresholdFilter.h @@ -0,0 +1,8 @@ +#import "GPUImageFilterGroup.h" + +@interface GPUImageAverageLuminanceThresholdFilter : GPUImageFilterGroup + +// This is multiplied by the continually calculated average image luminosity to arrive at the final threshold. Default is 1.0. +@property(readwrite, nonatomic) CGFloat thresholdMultiplier; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageAverageLuminanceThresholdFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageAverageLuminanceThresholdFilter.m new file mode 100644 index 00000000..eb2796f4 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageAverageLuminanceThresholdFilter.m @@ -0,0 +1,47 @@ +#import "GPUImageAverageLuminanceThresholdFilter.h" +#import "GPUImageLuminosity.h" +#import "GPUImageLuminanceThresholdFilter.h" + +@interface GPUImageAverageLuminanceThresholdFilter() +{ + GPUImageLuminosity *luminosityFilter; + GPUImageLuminanceThresholdFilter *luminanceThresholdFilter; +} +@end + +@implementation GPUImageAverageLuminanceThresholdFilter + +@synthesize thresholdMultiplier = _thresholdMultiplier; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + self.thresholdMultiplier = 1.0; + + luminosityFilter = [[GPUImageLuminosity alloc] init]; + [self addFilter:luminosityFilter]; + + luminanceThresholdFilter = [[GPUImageLuminanceThresholdFilter alloc] init]; + [self addFilter:luminanceThresholdFilter]; + + __unsafe_unretained GPUImageAverageLuminanceThresholdFilter *weakSelf = self; + __unsafe_unretained GPUImageLuminanceThresholdFilter *weakThreshold = luminanceThresholdFilter; + + [luminosityFilter setLuminosityProcessingFinishedBlock:^(CGFloat luminosity, CMTime frameTime) { + weakThreshold.threshold = luminosity * weakSelf.thresholdMultiplier; + }]; + + self.initialFilters = [NSArray arrayWithObjects:luminosityFilter, luminanceThresholdFilter, nil]; + self.terminalFilter = luminanceThresholdFilter; + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageBilateralFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageBilateralFilter.h new file mode 100644 index 00000000..6b736ccf --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageBilateralFilter.h @@ -0,0 +1,10 @@ +#import "GPUImageGaussianBlurFilter.h" + +@interface GPUImageBilateralFilter : GPUImageGaussianBlurFilter +{ + CGFloat firstDistanceNormalizationFactorUniform; + CGFloat secondDistanceNormalizationFactorUniform; +} +// A normalization factor for the distance between central color and sample color. +@property(nonatomic, readwrite) CGFloat distanceNormalizationFactor; +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageBilateralFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageBilateralFilter.m new file mode 100644 index 00000000..c2a8c867 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageBilateralFilter.m @@ -0,0 +1,231 @@ +#import "GPUImageBilateralFilter.h" + +NSString *const kGPUImageBilateralBlurVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + + const int GAUSSIAN_SAMPLES = 9; + + uniform float texelWidthOffset; + uniform float texelHeightOffset; + + varying vec2 textureCoordinate; + varying vec2 blurCoordinates[GAUSSIAN_SAMPLES]; + + void main() + { + gl_Position = position; + textureCoordinate = inputTextureCoordinate.xy; + + // Calculate the positions for the blur + int multiplier = 0; + vec2 blurStep; + vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset); + + for (int i = 0; i < GAUSSIAN_SAMPLES; i++) + { + multiplier = (i - ((GAUSSIAN_SAMPLES - 1) / 2)); + // Blur in x (horizontal) + blurStep = float(multiplier) * singleStepOffset; + blurCoordinates[i] = inputTextureCoordinate.xy + blurStep; + } + } +); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageBilateralFilterFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + const lowp int GAUSSIAN_SAMPLES = 9; + + varying highp vec2 textureCoordinate; + varying highp vec2 blurCoordinates[GAUSSIAN_SAMPLES]; + + uniform mediump float distanceNormalizationFactor; + + void main() + { + lowp vec4 centralColor; + lowp float gaussianWeightTotal; + lowp vec4 sum; + lowp vec4 sampleColor; + lowp float distanceFromCentralColor; + lowp float gaussianWeight; + + centralColor = texture2D(inputImageTexture, blurCoordinates[4]); + gaussianWeightTotal = 0.18; + sum = centralColor * 0.18; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[0]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.05 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[1]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.09 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[2]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.12 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[3]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.15 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[5]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.15 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[6]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.12 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[7]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.09 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[8]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.05 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + gl_FragColor = sum / gaussianWeightTotal; + } +); +#else +NSString *const kGPUImageBilateralFilterFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + const int GAUSSIAN_SAMPLES = 9; + + varying vec2 textureCoordinate; + varying vec2 blurCoordinates[GAUSSIAN_SAMPLES]; + + uniform float distanceNormalizationFactor; + + void main() + { + vec4 centralColor; + float gaussianWeightTotal; + vec4 sum; + vec4 sampleColor; + float distanceFromCentralColor; + float gaussianWeight; + + centralColor = texture2D(inputImageTexture, blurCoordinates[4]); + gaussianWeightTotal = 0.18; + sum = centralColor * 0.18; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[0]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.05 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[1]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.09 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[2]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.12 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[3]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.15 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[5]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.15 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[6]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.12 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[7]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.09 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + sampleColor = texture2D(inputImageTexture, blurCoordinates[8]); + distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); + gaussianWeight = 0.05 * (1.0 - distanceFromCentralColor); + gaussianWeightTotal += gaussianWeight; + sum += sampleColor * gaussianWeight; + + gl_FragColor = sum / gaussianWeightTotal; + } +); +#endif + +@implementation GPUImageBilateralFilter + +@synthesize distanceNormalizationFactor = _distanceNormalizationFactor; + +- (id)init; +{ + + if (!(self = [super initWithFirstStageVertexShaderFromString:kGPUImageBilateralBlurVertexShaderString + firstStageFragmentShaderFromString:kGPUImageBilateralFilterFragmentShaderString + secondStageVertexShaderFromString:kGPUImageBilateralBlurVertexShaderString + secondStageFragmentShaderFromString:kGPUImageBilateralFilterFragmentShaderString])) { + return nil; + } + + firstDistanceNormalizationFactorUniform = [filterProgram uniformIndex:@"distanceNormalizationFactor"]; + secondDistanceNormalizationFactorUniform = [filterProgram uniformIndex:@"distanceNormalizationFactor"]; + + self.texelSpacingMultiplier = 4.0; + self.distanceNormalizationFactor = 8.0; + + + return self; +} + + +#pragma mark - +#pragma mark Accessors + +- (void)setDistanceNormalizationFactor:(CGFloat)newValue +{ + _distanceNormalizationFactor = newValue; + + [self setFloat:newValue + forUniform:firstDistanceNormalizationFactorUniform + program:filterProgram]; + + [self setFloat:newValue + forUniform:secondDistanceNormalizationFactorUniform + program:secondFilterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageBoxBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageBoxBlurFilter.h new file mode 100755 index 00000000..3fd880bf --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageBoxBlurFilter.h @@ -0,0 +1,7 @@ +#import "GPUImageGaussianBlurFilter.h" + +/** A hardware-accelerated box blur of an image + */ +@interface GPUImageBoxBlurFilter : GPUImageGaussianBlurFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageBoxBlurFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageBoxBlurFilter.m new file mode 100755 index 00000000..5a49385b --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageBoxBlurFilter.m @@ -0,0 +1,178 @@ +#import "GPUImageBoxBlurFilter.h" + + +@implementation GPUImageBoxBlurFilter + ++ (NSString *)vertexShaderForOptimizedBlurOfRadius:(NSUInteger)blurRadius sigma:(CGFloat)sigma; +{ + if (blurRadius < 1) + { + return kGPUImageVertexShaderString; + } + + // From these weights we calculate the offsets to read interpolated values from + NSUInteger numberOfOptimizedOffsets = MIN(blurRadius / 2 + (blurRadius % 2), 7); + + NSMutableString *shaderString = [[NSMutableString alloc] init]; + // Header + [shaderString appendFormat:@"\ + attribute vec4 position;\n\ + attribute vec4 inputTextureCoordinate;\n\ + \n\ + uniform float texelWidthOffset;\n\ + uniform float texelHeightOffset;\n\ + \n\ + varying vec2 blurCoordinates[%lu];\n\ + \n\ + void main()\n\ + {\n\ + gl_Position = position;\n\ + \n\ + vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset);\n", (unsigned long)(1 + (numberOfOptimizedOffsets * 2))]; + + // Inner offset loop + [shaderString appendString:@"blurCoordinates[0] = inputTextureCoordinate.xy;\n"]; + for (NSUInteger currentOptimizedOffset = 0; currentOptimizedOffset < numberOfOptimizedOffsets; currentOptimizedOffset++) + { + GLfloat optimizedOffset = (GLfloat)(currentOptimizedOffset * 2) + 1.5; + + [shaderString appendFormat:@"\ + blurCoordinates[%lu] = inputTextureCoordinate.xy + singleStepOffset * %f;\n\ + blurCoordinates[%lu] = inputTextureCoordinate.xy - singleStepOffset * %f;\n", (unsigned long)((currentOptimizedOffset * 2) + 1), optimizedOffset, (unsigned long)((currentOptimizedOffset * 2) + 2), optimizedOffset]; + } + + // Footer + [shaderString appendString:@"}\n"]; + + return shaderString; +} + ++ (NSString *)fragmentShaderForOptimizedBlurOfRadius:(NSUInteger)blurRadius sigma:(CGFloat)sigma; +{ + if (blurRadius < 1) + { + return kGPUImagePassthroughFragmentShaderString; + } + + NSUInteger numberOfOptimizedOffsets = MIN(blurRadius / 2 + (blurRadius % 2), 7); + NSUInteger trueNumberOfOptimizedOffsets = blurRadius / 2 + (blurRadius % 2); + + NSMutableString *shaderString = [[NSMutableString alloc] init]; + + // Header +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [shaderString appendFormat:@"\ + uniform sampler2D inputImageTexture;\n\ + uniform highp float texelWidthOffset;\n\ + uniform highp float texelHeightOffset;\n\ + \n\ + varying highp vec2 blurCoordinates[%lu];\n\ + \n\ + void main()\n\ + {\n\ + lowp vec4 sum = vec4(0.0);\n", (unsigned long)(1 + (numberOfOptimizedOffsets * 2)) ]; +#else + [shaderString appendFormat:@"\ + uniform sampler2D inputImageTexture;\n\ + uniform float texelWidthOffset;\n\ + uniform float texelHeightOffset;\n\ + \n\ + varying vec2 blurCoordinates[%lu];\n\ + \n\ + void main()\n\ + {\n\ + vec4 sum = vec4(0.0);\n", 1 + (numberOfOptimizedOffsets * 2) ]; +#endif + + GLfloat boxWeight = 1.0 / (GLfloat)((blurRadius * 2) + 1); + + // Inner texture loop + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[0]) * %f;\n", boxWeight]; + + for (NSUInteger currentBlurCoordinateIndex = 0; currentBlurCoordinateIndex < numberOfOptimizedOffsets; currentBlurCoordinateIndex++) + { + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[%lu]) * %f;\n", (unsigned long)((currentBlurCoordinateIndex * 2) + 1), boxWeight * 2.0]; + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[%lu]) * %f;\n", (unsigned long)((currentBlurCoordinateIndex * 2) + 2), boxWeight * 2.0]; + } + + // If the number of required samples exceeds the amount we can pass in via varyings, we have to do dependent texture reads in the fragment shader + if (trueNumberOfOptimizedOffsets > numberOfOptimizedOffsets) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [shaderString appendString:@"highp vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset);\n"]; +#else + [shaderString appendString:@"vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset);\n"]; +#endif + + for (NSUInteger currentOverlowTextureRead = numberOfOptimizedOffsets; currentOverlowTextureRead < trueNumberOfOptimizedOffsets; currentOverlowTextureRead++) + { + GLfloat optimizedOffset = (GLfloat)(currentOverlowTextureRead * 2) + 1.5; + + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[0] + singleStepOffset * %f) * %f;\n", optimizedOffset, boxWeight * 2.0]; + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[0] - singleStepOffset * %f) * %f;\n", optimizedOffset, boxWeight * 2.0]; + } + } + + // Footer + [shaderString appendString:@"\ + gl_FragColor = sum;\n\ + }\n"]; + + return shaderString; +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + [super setupFilterForSize:filterFrameSize]; + + if (shouldResizeBlurRadiusWithImageSize == YES) + { + + } +} + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + // NSString *currentGaussianBlurVertexShader = [GPUImageGaussianBlurFilter vertexShaderForStandardGaussianOfRadius:4 sigma:2.0]; + // NSString *currentGaussianBlurFragmentShader = [GPUImageGaussianBlurFilter fragmentShaderForStandardGaussianOfRadius:4 sigma:2.0]; + + NSString *currentBoxBlurVertexShader = [[self class] vertexShaderForOptimizedBlurOfRadius:4 sigma:0.0]; + NSString *currentBoxBlurFragmentShader = [[self class] fragmentShaderForOptimizedBlurOfRadius:4 sigma:0.0]; + + if (!(self = [super initWithFirstStageVertexShaderFromString:currentBoxBlurVertexShader firstStageFragmentShaderFromString:currentBoxBlurFragmentShader secondStageVertexShaderFromString:currentBoxBlurVertexShader secondStageFragmentShaderFromString:currentBoxBlurFragmentShader])) + { + return nil; + } + + _blurRadiusInPixels = 4.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBlurRadiusInPixels:(CGFloat)newValue; +{ + CGFloat newBlurRadius = round(round(newValue / 2.0) * 2.0); // For now, only do even radii + + if (newBlurRadius != _blurRadiusInPixels) + { + _blurRadiusInPixels = newBlurRadius; + + NSString *newGaussianBlurVertexShader = [[self class] vertexShaderForOptimizedBlurOfRadius:_blurRadiusInPixels sigma:0.0]; + NSString *newGaussianBlurFragmentShader = [[self class] fragmentShaderForOptimizedBlurOfRadius:_blurRadiusInPixels sigma:0.0]; + + // NSLog(@"Optimized vertex shader: \n%@", newGaussianBlurVertexShader); + // NSLog(@"Optimized fragment shader: \n%@", newGaussianBlurFragmentShader); + // + [self switchToVertexShader:newGaussianBlurVertexShader fragmentShader:newGaussianBlurFragmentShader]; + } + shouldResizeBlurRadiusWithImageSize = NO; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageBrightnessFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageBrightnessFilter.h new file mode 100755 index 00000000..046473b9 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageBrightnessFilter.h @@ -0,0 +1,11 @@ +#import "GPUImageFilter.h" + +@interface GPUImageBrightnessFilter : GPUImageFilter +{ + GLint brightnessUniform; +} + +// Brightness ranges from -1.0 to 1.0, with 0.0 as the normal level +@property(readwrite, nonatomic) CGFloat brightness; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageBrightnessFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageBrightnessFilter.m new file mode 100755 index 00000000..7e526d85 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageBrightnessFilter.m @@ -0,0 +1,66 @@ +#import "GPUImageBrightnessFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageBrightnessFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform lowp float brightness; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w); + } +); +#else +NSString *const kGPUImageBrightnessFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float brightness; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w); + } + ); +#endif + +@implementation GPUImageBrightnessFilter + +@synthesize brightness = _brightness; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageBrightnessFragmentShaderString])) + { + return nil; + } + + brightnessUniform = [filterProgram uniformIndex:@"brightness"]; + self.brightness = 0.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBrightness:(CGFloat)newValue; +{ + _brightness = newValue; + + [self setFloat:_brightness forUniform:brightnessUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageBuffer.h b/LFLiveKit/Vendor/GPUImage/GPUImageBuffer.h new file mode 100644 index 00000000..caf09c8d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageBuffer.h @@ -0,0 +1,10 @@ +#import "GPUImageFilter.h" + +@interface GPUImageBuffer : GPUImageFilter +{ + NSMutableArray *bufferedFramebuffers; +} + +@property(readwrite, nonatomic) NSUInteger bufferSize; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageBuffer.m b/LFLiveKit/Vendor/GPUImage/GPUImageBuffer.m new file mode 100644 index 00000000..c90d020a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageBuffer.m @@ -0,0 +1,112 @@ +#import "GPUImageBuffer.h" + +@interface GPUImageBuffer() + +@end + +@implementation GPUImageBuffer + +@synthesize bufferSize = _bufferSize; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImagePassthroughFragmentShaderString])) + { + return nil; + } + + bufferedFramebuffers = [[NSMutableArray alloc] init]; +// [bufferedTextures addObject:[NSNumber numberWithInt:outputTexture]]; + _bufferSize = 1; + + return self; +} + +- (void)dealloc +{ + for (GPUImageFramebuffer *currentFramebuffer in bufferedFramebuffers) + { + [currentFramebuffer unlock]; + } +} + +#pragma mark - +#pragma mark GPUImageInput + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + if ([bufferedFramebuffers count] >= _bufferSize) + { + outputFramebuffer = [bufferedFramebuffers objectAtIndex:0]; + [bufferedFramebuffers removeObjectAtIndex:0]; + } + else + { + // Nothing yet in the buffer, so don't process further until the buffer is full + outputFramebuffer = firstInputFramebuffer; + [firstInputFramebuffer lock]; + } + + [bufferedFramebuffers addObject:firstInputFramebuffer]; + + // Need to pass along rotation information, as we're just holding on to buffered framebuffers and not rotating them ourselves + for (id currentTarget in targets) + { + if (currentTarget != self.targetToIgnoreForUpdates) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger textureIndex = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + [currentTarget setInputRotation:inputRotation atIndex:textureIndex]; + } + } + + // Let the downstream video elements see the previous frame from the buffer before rendering a new one into place + [self informTargetsAboutNewFrameAtTime:frameTime]; + +// [self renderToTextureWithVertices:imageVertices textureCoordinates:[[self class] textureCoordinatesForRotation:inputRotation]]; +} + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + // No need to render to another texture anymore, since we'll be hanging on to the textures in our buffer +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBufferSize:(NSUInteger)newValue; +{ + if ( (newValue == _bufferSize) || (newValue < 1) ) + { + return; + } + + if (newValue > _bufferSize) + { + NSUInteger texturesToAdd = newValue - _bufferSize; + for (NSUInteger currentTextureIndex = 0; currentTextureIndex < texturesToAdd; currentTextureIndex++) + { + // TODO: Deal with the growth of the size of the buffer by rotating framebuffers, no textures + } + } + else + { + NSUInteger texturesToRemove = _bufferSize - newValue; + for (NSUInteger currentTextureIndex = 0; currentTextureIndex < texturesToRemove; currentTextureIndex++) + { + GPUImageFramebuffer *lastFramebuffer = [bufferedFramebuffers lastObject]; + [bufferedFramebuffers removeObjectAtIndex:([bufferedFramebuffers count] - 1)]; + + [lastFramebuffer unlock]; + lastFramebuffer = nil; + } + } + + _bufferSize = newValue; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageBulgeDistortionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageBulgeDistortionFilter.h new file mode 100755 index 00000000..d416e536 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageBulgeDistortionFilter.h @@ -0,0 +1,16 @@ +#import "GPUImageFilter.h" + +/// Creates a bulge distortion on the image +@interface GPUImageBulgeDistortionFilter : GPUImageFilter +{ + GLint aspectRatioUniform, radiusUniform, centerUniform, scaleUniform; +} + +/// The center about which to apply the distortion, with a default of (0.5, 0.5) +@property(readwrite, nonatomic) CGPoint center; +/// The radius of the distortion, ranging from 0.0 to 1.0, with a default of 0.25 +@property(readwrite, nonatomic) CGFloat radius; +/// The amount of distortion to apply, from -1.0 to 1.0, with a default of 0.5 +@property(readwrite, nonatomic) CGFloat scale; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageBulgeDistortionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageBulgeDistortionFilter.m new file mode 100755 index 00000000..ad002678 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageBulgeDistortionFilter.m @@ -0,0 +1,174 @@ +#import "GPUImageBulgeDistortionFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageBulgeDistortionFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp float aspectRatio; + uniform highp vec2 center; + uniform highp float radius; + uniform highp float scale; + + void main() + { + highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, ((textureCoordinate.y - center.y) * aspectRatio) + center.y); + highp float dist = distance(center, textureCoordinateToUse); + textureCoordinateToUse = textureCoordinate; + + if (dist < radius) + { + textureCoordinateToUse -= center; + highp float percent = 1.0 - ((radius - dist) / radius) * scale; + percent = percent * percent; + + textureCoordinateToUse = textureCoordinateToUse * percent; + textureCoordinateToUse += center; + } + + gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse ); + } +); +#else +NSString *const kGPUImageBulgeDistortionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform float aspectRatio; + uniform vec2 center; + uniform float radius; + uniform float scale; + + void main() + { + vec2 textureCoordinateToUse = vec2(textureCoordinate.x, ((textureCoordinate.y - center.y) * aspectRatio) + center.y); + float dist = distance(center, textureCoordinateToUse); + textureCoordinateToUse = textureCoordinate; + + if (dist < radius) + { + textureCoordinateToUse -= center; + float percent = 1.0 - ((radius - dist) / radius) * scale; + percent = percent * percent; + + textureCoordinateToUse = textureCoordinateToUse * percent; + textureCoordinateToUse += center; + } + + gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse ); + } +); +#endif + + +@interface GPUImageBulgeDistortionFilter () + +- (void)adjustAspectRatio; + +@property (readwrite, nonatomic) CGFloat aspectRatio; + +@end + +@implementation GPUImageBulgeDistortionFilter + +@synthesize aspectRatio = _aspectRatio; +@synthesize center = _center; +@synthesize radius = _radius; +@synthesize scale = _scale; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageBulgeDistortionFragmentShaderString])) + { + return nil; + } + + aspectRatioUniform = [filterProgram uniformIndex:@"aspectRatio"]; + radiusUniform = [filterProgram uniformIndex:@"radius"]; + scaleUniform = [filterProgram uniformIndex:@"scale"]; + centerUniform = [filterProgram uniformIndex:@"center"]; + + self.radius = 0.25; + self.scale = 0.5; + self.center = CGPointMake(0.5, 0.5); + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)adjustAspectRatio; +{ + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + [self setAspectRatio:(inputTextureSize.width / inputTextureSize.height)]; + } + else + { + [self setAspectRatio:(inputTextureSize.height / inputTextureSize.width)]; + } +} + +- (void)forceProcessingAtSize:(CGSize)frameSize; +{ + [super forceProcessingAtSize:frameSize]; + [self adjustAspectRatio]; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + CGSize oldInputSize = inputTextureSize; + [super setInputSize:newSize atIndex:textureIndex]; + + if ( (!CGSizeEqualToSize(oldInputSize, inputTextureSize)) && (!CGSizeEqualToSize(newSize, CGSizeZero)) ) + { + [self adjustAspectRatio]; + } +} + +- (void)setAspectRatio:(CGFloat)newValue; +{ + _aspectRatio = newValue; + + [self setFloat:_aspectRatio forUniform:aspectRatioUniform program:filterProgram]; +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + [super setInputRotation:newInputRotation atIndex:textureIndex]; + [self setCenter:self.center]; + [self adjustAspectRatio]; +} + +- (void)setRadius:(CGFloat)newValue; +{ + _radius = newValue; + + [self setFloat:_radius forUniform:radiusUniform program:filterProgram]; +} + +- (void)setScale:(CGFloat)newValue; +{ + _scale = newValue; + + [self setFloat:_scale forUniform:scaleUniform program:filterProgram]; +} + +- (void)setCenter:(CGPoint)newValue; +{ + _center = newValue; + + CGPoint rotatedPoint = [self rotatedPoint:_center forRotation:inputRotation]; + + [self setPoint:rotatedPoint forUniform:centerUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageCGAColorspaceFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageCGAColorspaceFilter.h new file mode 100755 index 00000000..4f97804b --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageCGAColorspaceFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageFilter.h" + +@interface GPUImageCGAColorspaceFilter : GPUImageFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageCGAColorspaceFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageCGAColorspaceFilter.m new file mode 100755 index 00000000..eee939a0 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageCGAColorspaceFilter.m @@ -0,0 +1,113 @@ +// +// GPUImageCGAColorspaceFilter.m +// + +#import "GPUImageCGAColorspaceFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageCGAColorspaceFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + highp vec2 sampleDivisor = vec2(1.0 / 200.0, 1.0 / 320.0); + //highp vec4 colorDivisor = vec4(colorDepth); + + highp vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor); + highp vec4 color = texture2D(inputImageTexture, samplePos ); + + //gl_FragColor = texture2D(inputImageTexture, samplePos ); + mediump vec4 colorCyan = vec4(85.0 / 255.0, 1.0, 1.0, 1.0); + mediump vec4 colorMagenta = vec4(1.0, 85.0 / 255.0, 1.0, 1.0); + mediump vec4 colorWhite = vec4(1.0, 1.0, 1.0, 1.0); + mediump vec4 colorBlack = vec4(0.0, 0.0, 0.0, 1.0); + + mediump vec4 endColor; + highp float blackDistance = distance(color, colorBlack); + highp float whiteDistance = distance(color, colorWhite); + highp float magentaDistance = distance(color, colorMagenta); + highp float cyanDistance = distance(color, colorCyan); + + mediump vec4 finalColor; + + highp float colorDistance = min(magentaDistance, cyanDistance); + colorDistance = min(colorDistance, whiteDistance); + colorDistance = min(colorDistance, blackDistance); + + if (colorDistance == blackDistance) { + finalColor = colorBlack; + } else if (colorDistance == whiteDistance) { + finalColor = colorWhite; + } else if (colorDistance == cyanDistance) { + finalColor = colorCyan; + } else { + finalColor = colorMagenta; + } + + gl_FragColor = finalColor; + } +); +#else +NSString *const kGPUImageCGAColorspaceFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + vec2 sampleDivisor = vec2(1.0 / 200.0, 1.0 / 320.0); + //highp vec4 colorDivisor = vec4(colorDepth); + + vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor); + vec4 color = texture2D(inputImageTexture, samplePos ); + + //gl_FragColor = texture2D(inputImageTexture, samplePos ); + vec4 colorCyan = vec4(85.0 / 255.0, 1.0, 1.0, 1.0); + vec4 colorMagenta = vec4(1.0, 85.0 / 255.0, 1.0, 1.0); + vec4 colorWhite = vec4(1.0, 1.0, 1.0, 1.0); + vec4 colorBlack = vec4(0.0, 0.0, 0.0, 1.0); + + vec4 endColor; + float blackDistance = distance(color, colorBlack); + float whiteDistance = distance(color, colorWhite); + float magentaDistance = distance(color, colorMagenta); + float cyanDistance = distance(color, colorCyan); + + vec4 finalColor; + + float colorDistance = min(magentaDistance, cyanDistance); + colorDistance = min(colorDistance, whiteDistance); + colorDistance = min(colorDistance, blackDistance); + + if (colorDistance == blackDistance) { + finalColor = colorBlack; + } else if (colorDistance == whiteDistance) { + finalColor = colorWhite; + } else if (colorDistance == cyanDistance) { + finalColor = colorCyan; + } else { + finalColor = colorMagenta; + } + + gl_FragColor = finalColor; + } +); +#endif + +@implementation GPUImageCGAColorspaceFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageCGAColorspaceFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageCannyEdgeDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageCannyEdgeDetectionFilter.h new file mode 100755 index 00000000..53c58502 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageCannyEdgeDetectionFilter.h @@ -0,0 +1,62 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImageGrayscaleFilter; +@class GPUImageSingleComponentGaussianBlurFilter; +@class GPUImageDirectionalSobelEdgeDetectionFilter; +@class GPUImageDirectionalNonMaximumSuppressionFilter; +@class GPUImageWeakPixelInclusionFilter; + +/** This applies the edge detection process described by John Canny in + + Canny, J., A Computational Approach To Edge Detection, IEEE Trans. Pattern Analysis and Machine Intelligence, 8(6):679–698, 1986. + + and implemented in OpenGL ES by + + A. Ensor, S. Hall. GPU-based Image Analysis on Mobile Devices. Proceedings of Image and Vision Computing New Zealand 2011. + + It starts with a conversion to luminance, followed by an accelerated 9-hit Gaussian blur. A Sobel operator is applied to obtain the overall + gradient strength in the blurred image, as well as the direction (in texture sampling steps) of the gradient. A non-maximum suppression filter + acts along the direction of the gradient, highlighting strong edges that pass the threshold and completely removing those that fail the lower + threshold. Finally, pixels from in-between these thresholds are either included in edges or rejected based on neighboring pixels. + */ +@interface GPUImageCannyEdgeDetectionFilter : GPUImageFilterGroup +{ + GPUImageGrayscaleFilter *luminanceFilter; + GPUImageSingleComponentGaussianBlurFilter *blurFilter; + GPUImageDirectionalSobelEdgeDetectionFilter *edgeDetectionFilter; + GPUImageDirectionalNonMaximumSuppressionFilter *nonMaximumSuppressionFilter; + GPUImageWeakPixelInclusionFilter *weakPixelInclusionFilter; +} + +/** The image width and height factors tweak the appearance of the edges. + + These parameters affect the visibility of the detected edges + + By default, they match the inverse of the filter size in pixels + */ +@property(readwrite, nonatomic) CGFloat texelWidth; +/** The image width and height factors tweak the appearance of the edges. + + These parameters affect the visibility of the detected edges + + By default, they match the inverse of the filter size in pixels + */ +@property(readwrite, nonatomic) CGFloat texelHeight; + +/** The underlying blur radius for the Gaussian blur. Default is 2.0. + */ +@property (readwrite, nonatomic) CGFloat blurRadiusInPixels; + +/** The underlying blur texel spacing multiplier. Default is 1.0. + */ +@property (readwrite, nonatomic) CGFloat blurTexelSpacingMultiplier; + +/** Any edge with a gradient magnitude above this threshold will pass and show up in the final result. + */ +@property(readwrite, nonatomic) CGFloat upperThreshold; + +/** Any edge with a gradient magnitude below this threshold will fail and be removed from the final result. + */ +@property(readwrite, nonatomic) CGFloat lowerThreshold; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageCannyEdgeDetectionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageCannyEdgeDetectionFilter.m new file mode 100755 index 00000000..7327d532 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageCannyEdgeDetectionFilter.m @@ -0,0 +1,125 @@ +#import "GPUImageCannyEdgeDetectionFilter.h" + +#import "GPUImageGrayscaleFilter.h" +#import "GPUImageDirectionalSobelEdgeDetectionFilter.h" +#import "GPUImageDirectionalNonMaximumSuppressionFilter.h" +#import "GPUImageWeakPixelInclusionFilter.h" +#import "GPUImageSingleComponentGaussianBlurFilter.h" + +@implementation GPUImageCannyEdgeDetectionFilter + +@synthesize upperThreshold; +@synthesize lowerThreshold; +@synthesize blurRadiusInPixels; +@synthesize blurTexelSpacingMultiplier; +@synthesize texelWidth; +@synthesize texelHeight; + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + // First pass: convert image to luminance + luminanceFilter = [[GPUImageGrayscaleFilter alloc] init]; + [self addFilter:luminanceFilter]; + + // Second pass: apply a variable Gaussian blur + blurFilter = [[GPUImageSingleComponentGaussianBlurFilter alloc] init]; + [self addFilter:blurFilter]; + + // Third pass: run the Sobel edge detection, with calculated gradient directions, on this blurred image + edgeDetectionFilter = [[GPUImageDirectionalSobelEdgeDetectionFilter alloc] init]; + [self addFilter:edgeDetectionFilter]; + + // Fourth pass: apply non-maximum suppression + nonMaximumSuppressionFilter = [[GPUImageDirectionalNonMaximumSuppressionFilter alloc] init]; + [self addFilter:nonMaximumSuppressionFilter]; + + // Fifth pass: include weak pixels to complete edges + weakPixelInclusionFilter = [[GPUImageWeakPixelInclusionFilter alloc] init]; + [self addFilter:weakPixelInclusionFilter]; + + [luminanceFilter addTarget:blurFilter]; + [blurFilter addTarget:edgeDetectionFilter]; + [edgeDetectionFilter addTarget:nonMaximumSuppressionFilter]; + [nonMaximumSuppressionFilter addTarget:weakPixelInclusionFilter]; + + self.initialFilters = [NSArray arrayWithObject:luminanceFilter]; +// self.terminalFilter = nonMaximumSuppressionFilter; + self.terminalFilter = weakPixelInclusionFilter; + + self.blurRadiusInPixels = 2.0; + self.blurTexelSpacingMultiplier = 1.0; + self.upperThreshold = 0.4; + self.lowerThreshold = 0.1; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBlurRadiusInPixels:(CGFloat)newValue; +{ + blurFilter.blurRadiusInPixels = newValue; +} + +- (CGFloat)blurRadiusInPixels; +{ + return blurFilter.blurRadiusInPixels; +} + +- (void)setBlurTexelSpacingMultiplier:(CGFloat)newValue; +{ + blurFilter.texelSpacingMultiplier = newValue; +} + +- (CGFloat)blurTexelSpacingMultiplier; +{ + return blurFilter.texelSpacingMultiplier; +} + +- (void)setTexelWidth:(CGFloat)newValue; +{ + edgeDetectionFilter.texelWidth = newValue; +} + +- (CGFloat)texelWidth; +{ + return edgeDetectionFilter.texelWidth; +} + +- (void)setTexelHeight:(CGFloat)newValue; +{ + edgeDetectionFilter.texelHeight = newValue; +} + +- (CGFloat)texelHeight; +{ + return edgeDetectionFilter.texelHeight; +} + +- (void)setUpperThreshold:(CGFloat)newValue; +{ + nonMaximumSuppressionFilter.upperThreshold = newValue; +} + +- (CGFloat)upperThreshold; +{ + return nonMaximumSuppressionFilter.upperThreshold; +} + +- (void)setLowerThreshold:(CGFloat)newValue; +{ + nonMaximumSuppressionFilter.lowerThreshold = newValue; +} + +- (CGFloat)lowerThreshold; +{ + return nonMaximumSuppressionFilter.lowerThreshold; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyBlendFilter.h new file mode 100755 index 00000000..00a5aed7 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyBlendFilter.h @@ -0,0 +1,32 @@ +#import "GPUImageTwoInputFilter.h" + +/** Selectively replaces a color in the first image with the second image + */ +@interface GPUImageChromaKeyBlendFilter : GPUImageTwoInputFilter +{ + GLint colorToReplaceUniform, thresholdSensitivityUniform, smoothingUniform; +} + +/** The threshold sensitivity controls how similar pixels need to be colored to be replaced + + The default value is 0.3 + */ +@property(readwrite, nonatomic) CGFloat thresholdSensitivity; + +/** The degree of smoothing controls how gradually similar colors are replaced in the image + + The default value is 0.1 + */ +@property(readwrite, nonatomic) CGFloat smoothing; + +/** The color to be replaced is specified using individual red, green, and blue components (normalized to 1.0). + + The default is green: (0.0, 1.0, 0.0). + + @param redComponent Red component of color to be replaced + @param greenComponent Green component of color to be replaced + @param blueComponent Blue component of color to be replaced + */ +- (void)setColorToReplaceRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyBlendFilter.m new file mode 100755 index 00000000..4e6b4661 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyBlendFilter.m @@ -0,0 +1,117 @@ +#import "GPUImageChromaKeyBlendFilter.h" + +// Shader code based on Apple's CIChromaKeyFilter example: https://developer.apple.com/library/mac/#samplecode/CIChromaKeyFilter/Introduction/Intro.html + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageChromaKeyBlendFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform float thresholdSensitivity; + uniform float smoothing; + uniform vec3 colorToReplace; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + float maskY = 0.2989 * colorToReplace.r + 0.5866 * colorToReplace.g + 0.1145 * colorToReplace.b; + float maskCr = 0.7132 * (colorToReplace.r - maskY); + float maskCb = 0.5647 * (colorToReplace.b - maskY); + + float Y = 0.2989 * textureColor.r + 0.5866 * textureColor.g + 0.1145 * textureColor.b; + float Cr = 0.7132 * (textureColor.r - Y); + float Cb = 0.5647 * (textureColor.b - Y); + +// float blendValue = 1.0 - smoothstep(thresholdSensitivity - smoothing, thresholdSensitivity , abs(Cr - maskCr) + abs(Cb - maskCb)); + float blendValue = 1.0 - smoothstep(thresholdSensitivity, thresholdSensitivity + smoothing, distance(vec2(Cr, Cb), vec2(maskCr, maskCb))); + gl_FragColor = mix(textureColor, textureColor2, blendValue); + } +); +#else +NSString *const kGPUImageChromaKeyBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform float thresholdSensitivity; + uniform float smoothing; + uniform vec3 colorToReplace; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + float maskY = 0.2989 * colorToReplace.r + 0.5866 * colorToReplace.g + 0.1145 * colorToReplace.b; + float maskCr = 0.7132 * (colorToReplace.r - maskY); + float maskCb = 0.5647 * (colorToReplace.b - maskY); + + float Y = 0.2989 * textureColor.r + 0.5866 * textureColor.g + 0.1145 * textureColor.b; + float Cr = 0.7132 * (textureColor.r - Y); + float Cb = 0.5647 * (textureColor.b - Y); + + // float blendValue = 1.0 - smoothstep(thresholdSensitivity - smoothing, thresholdSensitivity , abs(Cr - maskCr) + abs(Cb - maskCb)); + float blendValue = 1.0 - smoothstep(thresholdSensitivity, thresholdSensitivity + smoothing, distance(vec2(Cr, Cb), vec2(maskCr, maskCb))); + gl_FragColor = mix(textureColor, textureColor2, blendValue); + } +); +#endif + +@implementation GPUImageChromaKeyBlendFilter + +@synthesize thresholdSensitivity = _thresholdSensitivity; +@synthesize smoothing = _smoothing; + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageChromaKeyBlendFragmentShaderString])) + { + return nil; + } + + thresholdSensitivityUniform = [filterProgram uniformIndex:@"thresholdSensitivity"]; + smoothingUniform = [filterProgram uniformIndex:@"smoothing"]; + colorToReplaceUniform = [filterProgram uniformIndex:@"colorToReplace"]; + + self.thresholdSensitivity = 0.4; + self.smoothing = 0.1; + [self setColorToReplaceRed:0.0 green:1.0 blue:0.0]; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setColorToReplaceRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; +{ + GPUVector3 colorToReplace = {redComponent, greenComponent, blueComponent}; + + [self setVec3:colorToReplace forUniform:colorToReplaceUniform program:filterProgram]; +} + +- (void)setThresholdSensitivity:(CGFloat)newValue; +{ + _thresholdSensitivity = newValue; + + [self setFloat:(GLfloat)_thresholdSensitivity forUniform:thresholdSensitivityUniform program:filterProgram]; +} + +- (void)setSmoothing:(CGFloat)newValue; +{ + _smoothing = newValue; + + [self setFloat:(GLfloat)_smoothing forUniform:smoothingUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyFilter.h new file mode 100644 index 00000000..5ee7e498 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyFilter.h @@ -0,0 +1,30 @@ +#import "GPUImageFilter.h" + +@interface GPUImageChromaKeyFilter : GPUImageFilter +{ + GLint colorToReplaceUniform, thresholdSensitivityUniform, smoothingUniform; +} + +/** The threshold sensitivity controls how similar pixels need to be colored to be replaced + + The default value is 0.3 + */ +@property(readwrite, nonatomic) CGFloat thresholdSensitivity; + +/** The degree of smoothing controls how gradually similar colors are replaced in the image + + The default value is 0.1 + */ +@property(readwrite, nonatomic) CGFloat smoothing; + +/** The color to be replaced is specified using individual red, green, and blue components (normalized to 1.0). + + The default is green: (0.0, 1.0, 0.0). + + @param redComponent Red component of color to be replaced + @param greenComponent Green component of color to be replaced + @param blueComponent Blue component of color to be replaced + */ +- (void)setColorToReplaceRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyFilter.m new file mode 100644 index 00000000..c70ef61d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageChromaKeyFilter.m @@ -0,0 +1,113 @@ +#import "GPUImageChromaKeyFilter.h" + +// Shader code based on Apple's CIChromaKeyFilter example: https://developer.apple.com/library/mac/#samplecode/CIChromaKeyFilter/Introduction/Intro.html + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageChromaKeyFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying highp vec2 textureCoordinate; + + uniform float thresholdSensitivity; + uniform float smoothing; + uniform vec3 colorToReplace; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + float maskY = 0.2989 * colorToReplace.r + 0.5866 * colorToReplace.g + 0.1145 * colorToReplace.b; + float maskCr = 0.7132 * (colorToReplace.r - maskY); + float maskCb = 0.5647 * (colorToReplace.b - maskY); + + float Y = 0.2989 * textureColor.r + 0.5866 * textureColor.g + 0.1145 * textureColor.b; + float Cr = 0.7132 * (textureColor.r - Y); + float Cb = 0.5647 * (textureColor.b - Y); + + // float blendValue = 1.0 - smoothstep(thresholdSensitivity - smoothing, thresholdSensitivity , abs(Cr - maskCr) + abs(Cb - maskCb)); + float blendValue = smoothstep(thresholdSensitivity, thresholdSensitivity + smoothing, distance(vec2(Cr, Cb), vec2(maskCr, maskCb))); + gl_FragColor = vec4(textureColor.rgb, textureColor.a * blendValue); + } +); +#else +NSString *const kGPUImageChromaKeyFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform float thresholdSensitivity; + uniform float smoothing; + uniform vec3 colorToReplace; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + float maskY = 0.2989 * colorToReplace.r + 0.5866 * colorToReplace.g + 0.1145 * colorToReplace.b; + float maskCr = 0.7132 * (colorToReplace.r - maskY); + float maskCb = 0.5647 * (colorToReplace.b - maskY); + + float Y = 0.2989 * textureColor.r + 0.5866 * textureColor.g + 0.1145 * textureColor.b; + float Cr = 0.7132 * (textureColor.r - Y); + float Cb = 0.5647 * (textureColor.b - Y); + + // float blendValue = 1.0 - smoothstep(thresholdSensitivity - smoothing, thresholdSensitivity , abs(Cr - maskCr) + abs(Cb - maskCb)); + float blendValue = smoothstep(thresholdSensitivity, thresholdSensitivity + smoothing, distance(vec2(Cr, Cb), vec2(maskCr, maskCb))); + gl_FragColor = vec4(textureColor.rgb, textureColor.a * blendValue); + } + ); +#endif + +@implementation GPUImageChromaKeyFilter + +@synthesize thresholdSensitivity = _thresholdSensitivity; +@synthesize smoothing = _smoothing; + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageChromaKeyFragmentShaderString])) + { + return nil; + } + + thresholdSensitivityUniform = [filterProgram uniformIndex:@"thresholdSensitivity"]; + smoothingUniform = [filterProgram uniformIndex:@"smoothing"]; + colorToReplaceUniform = [filterProgram uniformIndex:@"colorToReplace"]; + + self.thresholdSensitivity = 0.4; + self.smoothing = 0.1; + [self setColorToReplaceRed:0.0 green:1.0 blue:0.0]; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setColorToReplaceRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; +{ + GPUVector3 colorToReplace = {redComponent, greenComponent, blueComponent}; + + [self setVec3:colorToReplace forUniform:colorToReplaceUniform program:filterProgram]; +} + +- (void)setThresholdSensitivity:(CGFloat)newValue; +{ + _thresholdSensitivity = newValue; + + [self setFloat:(GLfloat)_thresholdSensitivity forUniform:thresholdSensitivityUniform program:filterProgram]; +} + +- (void)setSmoothing:(CGFloat)newValue; +{ + _smoothing = newValue; + + [self setFloat:(GLfloat)_smoothing forUniform:smoothingUniform program:filterProgram]; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageClosingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageClosingFilter.h new file mode 100644 index 00000000..61e34c41 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageClosingFilter.h @@ -0,0 +1,19 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImageErosionFilter; +@class GPUImageDilationFilter; + +// A filter that first performs a dilation on the red channel of an image, followed by an erosion of the same radius. +// This helps to filter out smaller dark elements. + +@interface GPUImageClosingFilter : GPUImageFilterGroup +{ + GPUImageErosionFilter *erosionFilter; + GPUImageDilationFilter *dilationFilter; +} + +@property(readwrite, nonatomic) CGFloat verticalTexelSpacing, horizontalTexelSpacing; + +- (id)initWithRadius:(NSUInteger)radius; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageClosingFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageClosingFilter.m new file mode 100644 index 00000000..01e9b29b --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageClosingFilter.m @@ -0,0 +1,57 @@ +#import "GPUImageClosingFilter.h" +#import "GPUImageErosionFilter.h" +#import "GPUImageDilationFilter.h" + +@implementation GPUImageClosingFilter + +@synthesize verticalTexelSpacing = _verticalTexelSpacing; +@synthesize horizontalTexelSpacing = _horizontalTexelSpacing; + +- (id)init; +{ + if (!(self = [self initWithRadius:1])) + { + return nil; + } + + return self; +} + +- (id)initWithRadius:(NSUInteger)radius; +{ + if (!(self = [super init])) + { + return nil; + } + + // First pass: dilation + dilationFilter = [[GPUImageDilationFilter alloc] initWithRadius:radius]; + [self addFilter:dilationFilter]; + + // Second pass: erosion + erosionFilter = [[GPUImageErosionFilter alloc] initWithRadius:radius]; + [self addFilter:erosionFilter]; + + [dilationFilter addTarget:erosionFilter]; + + self.initialFilters = [NSArray arrayWithObjects:dilationFilter, nil]; + self.terminalFilter = erosionFilter; + + return self; +} + +- (void)setVerticalTexelSpacing:(CGFloat)newValue; +{ + _verticalTexelSpacing = newValue; + erosionFilter.verticalTexelSpacing = newValue; + dilationFilter.verticalTexelSpacing = newValue; +} + +- (void)setHorizontalTexelSpacing:(CGFloat)newValue; +{ + _horizontalTexelSpacing = newValue; + erosionFilter.horizontalTexelSpacing = newValue; + dilationFilter.horizontalTexelSpacing = newValue; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorBlendFilter.h new file mode 100644 index 00000000..302a16c6 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorBlendFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageColorBlendFilter : GPUImageTwoInputFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageColorBlendFilter.m new file mode 100644 index 00000000..ced1cb8e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorBlendFilter.m @@ -0,0 +1,113 @@ +#import "GPUImageColorBlendFilter.h" + +/** + * Color blend mode based upon pseudo code from the PDF specification. + */ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageColorBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + highp float lum(lowp vec3 c) { + return dot(c, vec3(0.3, 0.59, 0.11)); + } + + lowp vec3 clipcolor(lowp vec3 c) { + highp float l = lum(c); + lowp float n = min(min(c.r, c.g), c.b); + lowp float x = max(max(c.r, c.g), c.b); + + if (n < 0.0) { + c.r = l + ((c.r - l) * l) / (l - n); + c.g = l + ((c.g - l) * l) / (l - n); + c.b = l + ((c.b - l) * l) / (l - n); + } + if (x > 1.0) { + c.r = l + ((c.r - l) * (1.0 - l)) / (x - l); + c.g = l + ((c.g - l) * (1.0 - l)) / (x - l); + c.b = l + ((c.b - l) * (1.0 - l)) / (x - l); + } + + return c; + } + + lowp vec3 setlum(lowp vec3 c, highp float l) { + highp float d = l - lum(c); + c = c + vec3(d); + return clipcolor(c); + } + + void main() + { + highp vec4 baseColor = texture2D(inputImageTexture, textureCoordinate); + highp vec4 overlayColor = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(baseColor.rgb * (1.0 - overlayColor.a) + setlum(overlayColor.rgb, lum(baseColor.rgb)) * overlayColor.a, baseColor.a); + } +); +#else +NSString *const kGPUImageColorBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + float lum(vec3 c) { + return dot(c, vec3(0.3, 0.59, 0.11)); + } + + vec3 clipcolor(vec3 c) { + float l = lum(c); + float n = min(min(c.r, c.g), c.b); + float x = max(max(c.r, c.g), c.b); + + if (n < 0.0) { + c.r = l + ((c.r - l) * l) / (l - n); + c.g = l + ((c.g - l) * l) / (l - n); + c.b = l + ((c.b - l) * l) / (l - n); + } + if (x > 1.0) { + c.r = l + ((c.r - l) * (1.0 - l)) / (x - l); + c.g = l + ((c.g - l) * (1.0 - l)) / (x - l); + c.b = l + ((c.b - l) * (1.0 - l)) / (x - l); + } + + return c; + } + + vec3 setlum(vec3 c, float l) { + float d = l - lum(c); + c = c + vec3(d); + return clipcolor(c); + } + + void main() + { + vec4 baseColor = texture2D(inputImageTexture, textureCoordinate); + vec4 overlayColor = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(baseColor.rgb * (1.0 - overlayColor.a) + setlum(overlayColor.rgb, lum(baseColor.rgb)) * overlayColor.a, baseColor.a); + } +); +#endif + + +@implementation GPUImageColorBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageColorBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorBurnBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorBurnBlendFilter.h new file mode 100755 index 00000000..50ebb3f4 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorBurnBlendFilter.h @@ -0,0 +1,9 @@ +#import "GPUImageTwoInputFilter.h" + +/** Applies a color burn blend of two images + */ +@interface GPUImageColorBurnBlendFilter : GPUImageTwoInputFilter +{ +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorBurnBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageColorBurnBlendFilter.m new file mode 100755 index 00000000..5d6ff60d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorBurnBlendFilter.m @@ -0,0 +1,52 @@ +#import "GPUImageColorBurnBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageColorBurnBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + mediump vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + mediump vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + mediump vec4 whiteColor = vec4(1.0); + gl_FragColor = whiteColor - (whiteColor - textureColor) / textureColor2; + } +); +#else +NSString *const kGPUImageColorBurnBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + vec4 whiteColor = vec4(1.0); + gl_FragColor = whiteColor - (whiteColor - textureColor) / textureColor2; + } +); +#endif + +@implementation GPUImageColorBurnBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageColorBurnBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorConversion.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorConversion.h new file mode 100644 index 00000000..02f82bf8 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorConversion.h @@ -0,0 +1,12 @@ +#ifndef GPUImageColorConversion_h +#define GPUImageColorConversion_h + +extern GLfloat *kColorConversion601; +extern GLfloat *kColorConversion601FullRange; +extern GLfloat *kColorConversion709; +extern NSString *const kGPUImageYUVVideoRangeConversionForRGFragmentShaderString; +extern NSString *const kGPUImageYUVFullRangeConversionForLAFragmentShaderString; +extern NSString *const kGPUImageYUVVideoRangeConversionForLAFragmentShaderString; + + +#endif /* GPUImageColorConversion_h */ diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorConversion.m b/LFLiveKit/Vendor/GPUImage/GPUImageColorConversion.m new file mode 100644 index 00000000..35534c20 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorConversion.m @@ -0,0 +1,159 @@ +#import "GPUImageFilter.h" + +// Color Conversion Constants (YUV to RGB) including adjustment from 16-235/16-240 (video range) + +// BT.601, which is the standard for SDTV. +GLfloat kColorConversion601Default[] = { + 1.164, 1.164, 1.164, + 0.0, -0.392, 2.017, + 1.596, -0.813, 0.0, +}; + +// BT.601 full range (ref: http://www.equasys.de/colorconversion.html) +GLfloat kColorConversion601FullRangeDefault[] = { + 1.0, 1.0, 1.0, + 0.0, -0.343, 1.765, + 1.4, -0.711, 0.0, +}; + +// BT.709, which is the standard for HDTV. +GLfloat kColorConversion709Default[] = { + 1.164, 1.164, 1.164, + 0.0, -0.213, 2.112, + 1.793, -0.533, 0.0, +}; + + +GLfloat *kColorConversion601 = kColorConversion601Default; +GLfloat *kColorConversion601FullRange = kColorConversion601FullRangeDefault; +GLfloat *kColorConversion709 = kColorConversion709Default; + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageYUVVideoRangeConversionForRGFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D luminanceTexture; + uniform sampler2D chrominanceTexture; + uniform mediump mat3 colorConversionMatrix; + + void main() + { + mediump vec3 yuv; + lowp vec3 rgb; + + yuv.x = texture2D(luminanceTexture, textureCoordinate).r; + yuv.yz = texture2D(chrominanceTexture, textureCoordinate).rg - vec2(0.5, 0.5); + rgb = colorConversionMatrix * yuv; + + gl_FragColor = vec4(rgb, 1); + } + ); +#else +NSString *const kGPUImageYUVVideoRangeConversionForRGFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D luminanceTexture; + uniform sampler2D chrominanceTexture; + + void main() + { + vec3 yuv; + vec3 rgb; + + yuv.x = texture2D(luminanceTexture, textureCoordinate).r; + yuv.yz = texture2D(chrominanceTexture, textureCoordinate).rg - vec2(0.5, 0.5); + + // BT.601, which is the standard for SDTV is provided as a reference + /* + rgb = mat3( 1, 1, 1, + 0, -.39465, 2.03211, + 1.13983, -.58060, 0) * yuv; + */ + + // Using BT.709 which is the standard for HDTV + rgb = mat3( 1, 1, 1, + 0, -.21482, 2.12798, + 1.28033, -.38059, 0) * yuv; + + gl_FragColor = vec4(rgb, 1); + } + ); +#endif + +NSString *const kGPUImageYUVFullRangeConversionForLAFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D luminanceTexture; + uniform sampler2D chrominanceTexture; + uniform mediump mat3 colorConversionMatrix; + + void main() + { + mediump vec3 yuv; + lowp vec3 rgb; + + yuv.x = texture2D(luminanceTexture, textureCoordinate).r; + yuv.yz = texture2D(chrominanceTexture, textureCoordinate).ra - vec2(0.5, 0.5); + rgb = colorConversionMatrix * yuv; + + gl_FragColor = vec4(rgb, 1); + } + ); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageYUVVideoRangeConversionForLAFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D luminanceTexture; + uniform sampler2D chrominanceTexture; + uniform mediump mat3 colorConversionMatrix; + + void main() + { + mediump vec3 yuv; + lowp vec3 rgb; + + yuv.x = texture2D(luminanceTexture, textureCoordinate).r - (16.0/255.0); + yuv.yz = texture2D(chrominanceTexture, textureCoordinate).ra - vec2(0.5, 0.5); + rgb = colorConversionMatrix * yuv; + + gl_FragColor = vec4(rgb, 1); + } + ); +#else +NSString *const kGPUImageYUVVideoRangeConversionForLAFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D luminanceTexture; + uniform sampler2D chrominanceTexture; + + void main() + { + vec3 yuv; + vec3 rgb; + + yuv.x = texture2D(luminanceTexture, textureCoordinate).r; + yuv.yz = texture2D(chrominanceTexture, textureCoordinate).ra - vec2(0.5, 0.5); + + // BT.601, which is the standard for SDTV is provided as a reference + /* + rgb = mat3( 1, 1, 1, + 0, -.39465, 2.03211, + 1.13983, -.58060, 0) * yuv; + */ + + // Using BT.709 which is the standard for HDTV + rgb = mat3( 1, 1, 1, + 0, -.21482, 2.12798, + 1.28033, -.38059, 0) * yuv; + + gl_FragColor = vec4(rgb, 1); + } + ); +#endif + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorDodgeBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorDodgeBlendFilter.h new file mode 100755 index 00000000..0f541c42 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorDodgeBlendFilter.h @@ -0,0 +1,9 @@ +#import "GPUImageTwoInputFilter.h" + +/** Applies a color dodge blend of two images + */ +@interface GPUImageColorDodgeBlendFilter : GPUImageTwoInputFilter +{ +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorDodgeBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageColorDodgeBlendFilter.m new file mode 100755 index 00000000..6a38827c --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorDodgeBlendFilter.m @@ -0,0 +1,75 @@ +#import "GPUImageColorDodgeBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageColorDodgeBlendFragmentShaderString = SHADER_STRING +( + + precision mediump float; + + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 base = texture2D(inputImageTexture, textureCoordinate); + vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + vec3 baseOverlayAlphaProduct = vec3(overlay.a * base.a); + vec3 rightHandProduct = overlay.rgb * (1.0 - base.a) + base.rgb * (1.0 - overlay.a); + + vec3 firstBlendColor = baseOverlayAlphaProduct + rightHandProduct; + vec3 overlayRGB = clamp((overlay.rgb / clamp(overlay.a, 0.01, 1.0)) * step(0.0, overlay.a), 0.0, 0.99); + + vec3 secondBlendColor = (base.rgb * overlay.a) / (1.0 - overlayRGB) + rightHandProduct; + + vec3 colorChoice = step((overlay.rgb * base.a + base.rgb * overlay.a), baseOverlayAlphaProduct); + + gl_FragColor = vec4(mix(firstBlendColor, secondBlendColor, colorChoice), 1.0); + } +); +#else +NSString *const kGPUImageColorDodgeBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 base = texture2D(inputImageTexture, textureCoordinate); + vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + vec3 baseOverlayAlphaProduct = vec3(overlay.a * base.a); + vec3 rightHandProduct = overlay.rgb * (1.0 - base.a) + base.rgb * (1.0 - overlay.a); + + vec3 firstBlendColor = baseOverlayAlphaProduct + rightHandProduct; + vec3 overlayRGB = clamp((overlay.rgb / clamp(overlay.a, 0.01, 1.0)) * step(0.0, overlay.a), 0.0, 0.99); + + vec3 secondBlendColor = (base.rgb * overlay.a) / (1.0 - overlayRGB) + rightHandProduct; + + vec3 colorChoice = step((overlay.rgb * base.a + base.rgb * overlay.a), baseOverlayAlphaProduct); + + gl_FragColor = vec4(mix(firstBlendColor, secondBlendColor, colorChoice), 1.0); + } +); +#endif + +@implementation GPUImageColorDodgeBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageColorDodgeBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorInvertFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorInvertFilter.h new file mode 100755 index 00000000..aaeec438 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorInvertFilter.h @@ -0,0 +1,7 @@ +#import "GPUImageFilter.h" + +@interface GPUImageColorInvertFilter : GPUImageFilter +{ +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorInvertFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageColorInvertFilter.m new file mode 100755 index 00000000..0a8798b1 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorInvertFilter.m @@ -0,0 +1,46 @@ +#import "GPUImageColorInvertFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageInvertFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4((1.0 - textureColor.rgb), textureColor.w); + } +); +#else +NSString *const kGPUImageInvertFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4((1.0 - textureColor.rgb), textureColor.w); + } + ); +#endif + +@implementation GPUImageColorInvertFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageInvertFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorLocalBinaryPatternFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorLocalBinaryPatternFilter.h new file mode 100644 index 00000000..8b57cd7c --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorLocalBinaryPatternFilter.h @@ -0,0 +1,5 @@ +#import "GPUImage3x3TextureSamplingFilter.h" + +@interface GPUImageColorLocalBinaryPatternFilter : GPUImage3x3TextureSamplingFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorLocalBinaryPatternFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageColorLocalBinaryPatternFilter.m new file mode 100644 index 00000000..d51aedf6 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorLocalBinaryPatternFilter.m @@ -0,0 +1,159 @@ +#import "GPUImageColorLocalBinaryPatternFilter.h" + +// This is based on "Accelerating image recognition on mobile devices using GPGPU" by Miguel Bordallo Lopez, Henri Nykanen, Jari Hannuksela, Olli Silven and Markku Vehvilainen +// http://www.ee.oulu.fi/~jhannuks/publications/SPIE2011a.pdf + +// Right pixel is the most significant bit, traveling clockwise to get to the upper right, which is the least significant +// If the external pixel is greater than or equal to the center, set to 1, otherwise 0 +// +// 2 1 0 +// 3 7 +// 4 5 6 + +// 01101101 +// 76543210 + +@implementation GPUImageColorLocalBinaryPatternFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageColorLocalBinaryPatternFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + lowp vec3 centerColor = texture2D(inputImageTexture, textureCoordinate).rgb; + lowp vec3 bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb; + lowp vec3 topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).rgb; + lowp vec3 topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).rgb; + lowp vec3 bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb; + lowp vec3 leftColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + lowp vec3 rightColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; + lowp vec3 bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + lowp vec3 topColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; + + lowp float redByteTally = 1.0 / 255.0 * step(centerColor.r, topRightColor.r); + redByteTally += 2.0 / 255.0 * step(centerColor.r, topColor.r); + redByteTally += 4.0 / 255.0 * step(centerColor.r, topLeftColor.r); + redByteTally += 8.0 / 255.0 * step(centerColor.r, leftColor.r); + redByteTally += 16.0 / 255.0 * step(centerColor.r, bottomLeftColor.r); + redByteTally += 32.0 / 255.0 * step(centerColor.r, bottomColor.r); + redByteTally += 64.0 / 255.0 * step(centerColor.r, bottomRightColor.r); + redByteTally += 128.0 / 255.0 * step(centerColor.r, rightColor.r); + + lowp float blueByteTally = 1.0 / 255.0 * step(centerColor.b, topRightColor.b); + blueByteTally += 2.0 / 255.0 * step(centerColor.b, topColor.b); + blueByteTally += 4.0 / 255.0 * step(centerColor.b, topLeftColor.b); + blueByteTally += 8.0 / 255.0 * step(centerColor.b, leftColor.b); + blueByteTally += 16.0 / 255.0 * step(centerColor.b, bottomLeftColor.b); + blueByteTally += 32.0 / 255.0 * step(centerColor.b, bottomColor.b); + blueByteTally += 64.0 / 255.0 * step(centerColor.b, bottomRightColor.b); + blueByteTally += 128.0 / 255.0 * step(centerColor.b, rightColor.b); + + lowp float greenByteTally = 1.0 / 255.0 * step(centerColor.g, topRightColor.g); + greenByteTally += 2.0 / 255.0 * step(centerColor.g, topColor.g); + greenByteTally += 4.0 / 255.0 * step(centerColor.g, topLeftColor.g); + greenByteTally += 8.0 / 255.0 * step(centerColor.g, leftColor.g); + greenByteTally += 16.0 / 255.0 * step(centerColor.g, bottomLeftColor.g); + greenByteTally += 32.0 / 255.0 * step(centerColor.g, bottomColor.g); + greenByteTally += 64.0 / 255.0 * step(centerColor.g, bottomRightColor.g); + greenByteTally += 128.0 / 255.0 * step(centerColor.g, rightColor.g); + + // TODO: Replace the above with a dot product and two vec4s + // TODO: Apply step to a matrix, rather than individually + + gl_FragColor = vec4(redByteTally, blueByteTally, greenByteTally, 1.0); + } +); +#else +NSString *const kGPUImageColorLocalBinaryPatternFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + vec3 centerColor = texture2D(inputImageTexture, textureCoordinate).rgb; + vec3 bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb; + vec3 topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).rgb; + vec3 topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).rgb; + vec3 bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb; + vec3 leftColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + vec3 rightColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; + vec3 bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + vec3 topColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; + + float redByteTally = 1.0 / 255.0 * step(centerColor.r, topRightColor.r); + redByteTally += 2.0 / 255.0 * step(centerColor.r, topColor.r); + redByteTally += 4.0 / 255.0 * step(centerColor.r, topLeftColor.r); + redByteTally += 8.0 / 255.0 * step(centerColor.r, leftColor.r); + redByteTally += 16.0 / 255.0 * step(centerColor.r, bottomLeftColor.r); + redByteTally += 32.0 / 255.0 * step(centerColor.r, bottomColor.r); + redByteTally += 64.0 / 255.0 * step(centerColor.r, bottomRightColor.r); + redByteTally += 128.0 / 255.0 * step(centerColor.r, rightColor.r); + + float blueByteTally = 1.0 / 255.0 * step(centerColor.b, topRightColor.b); + blueByteTally += 2.0 / 255.0 * step(centerColor.b, topColor.b); + blueByteTally += 4.0 / 255.0 * step(centerColor.b, topLeftColor.b); + blueByteTally += 8.0 / 255.0 * step(centerColor.b, leftColor.b); + blueByteTally += 16.0 / 255.0 * step(centerColor.b, bottomLeftColor.b); + blueByteTally += 32.0 / 255.0 * step(centerColor.b, bottomColor.b); + blueByteTally += 64.0 / 255.0 * step(centerColor.b, bottomRightColor.b); + blueByteTally += 128.0 / 255.0 * step(centerColor.b, rightColor.b); + + float greenByteTally = 1.0 / 255.0 * step(centerColor.g, topRightColor.g); + greenByteTally += 2.0 / 255.0 * step(centerColor.g, topColor.g); + greenByteTally += 4.0 / 255.0 * step(centerColor.g, topLeftColor.g); + greenByteTally += 8.0 / 255.0 * step(centerColor.g, leftColor.g); + greenByteTally += 16.0 / 255.0 * step(centerColor.g, bottomLeftColor.g); + greenByteTally += 32.0 / 255.0 * step(centerColor.g, bottomColor.g); + greenByteTally += 64.0 / 255.0 * step(centerColor.g, bottomRightColor.g); + greenByteTally += 128.0 / 255.0 * step(centerColor.g, rightColor.g); + + // TODO: Replace the above with a dot product and two vec4s + // TODO: Apply step to a matrix, rather than individually + + gl_FragColor = vec4(redByteTally, blueByteTally, greenByteTally, 1.0); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageColorLocalBinaryPatternFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorMatrixFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorMatrixFilter.h new file mode 100755 index 00000000..75887276 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorMatrixFilter.h @@ -0,0 +1,19 @@ +#import "GPUImageFilter.h" + +/** Transforms the colors of an image by applying a matrix to them + */ +@interface GPUImageColorMatrixFilter : GPUImageFilter +{ + GLint colorMatrixUniform; + GLint intensityUniform; +} + +/** A 4x4 matrix used to transform each color in an image + */ +@property(readwrite, nonatomic) GPUMatrix4x4 colorMatrix; + +/** The degree to which the new transformed color replaces the original color for each pixel + */ +@property(readwrite, nonatomic) CGFloat intensity; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorMatrixFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageColorMatrixFilter.m new file mode 100755 index 00000000..0e21c7e8 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorMatrixFilter.m @@ -0,0 +1,87 @@ +#import "GPUImageColorMatrixFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageColorMatrixFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform lowp mat4 colorMatrix; + uniform lowp float intensity; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 outputColor = textureColor * colorMatrix; + + gl_FragColor = (intensity * outputColor) + ((1.0 - intensity) * textureColor); + } +); +#else +NSString *const kGPUImageColorMatrixFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform mat4 colorMatrix; + uniform float intensity; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 outputColor = textureColor * colorMatrix; + + gl_FragColor = (intensity * outputColor) + ((1.0 - intensity) * textureColor); + } +); +#endif + +@implementation GPUImageColorMatrixFilter + +@synthesize intensity = _intensity; +@synthesize colorMatrix = _colorMatrix; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageColorMatrixFragmentShaderString])) + { + return nil; + } + + colorMatrixUniform = [filterProgram uniformIndex:@"colorMatrix"]; + intensityUniform = [filterProgram uniformIndex:@"intensity"]; + + self.intensity = 1.f; + self.colorMatrix = (GPUMatrix4x4){ + {1.f, 0.f, 0.f, 0.f}, + {0.f, 1.f, 0.f, 0.f}, + {0.f, 0.f, 1.f, 0.f}, + {0.f, 0.f, 0.f, 1.f} + }; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setIntensity:(CGFloat)newIntensity; +{ + _intensity = newIntensity; + + [self setFloat:_intensity forUniform:intensityUniform program:filterProgram]; +} + +- (void)setColorMatrix:(GPUMatrix4x4)newColorMatrix; +{ + _colorMatrix = newColorMatrix; + + [self setMatrix4f:_colorMatrix forUniform:colorMatrixUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorPackingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageColorPackingFilter.h new file mode 100644 index 00000000..c2edca51 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorPackingFilter.h @@ -0,0 +1,10 @@ +#import "GPUImageFilter.h" + +@interface GPUImageColorPackingFilter : GPUImageFilter +{ + GLint texelWidthUniform, texelHeightUniform; + + CGFloat texelWidth, texelHeight; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColorPackingFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageColorPackingFilter.m new file mode 100644 index 00000000..1a087ca8 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColorPackingFilter.m @@ -0,0 +1,139 @@ +#import "GPUImageColorPackingFilter.h" + +NSString *const kGPUImageColorPackingVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + + uniform float texelWidth; + uniform float texelHeight; + + varying vec2 upperLeftInputTextureCoordinate; + varying vec2 upperRightInputTextureCoordinate; + varying vec2 lowerLeftInputTextureCoordinate; + varying vec2 lowerRightInputTextureCoordinate; + + void main() + { + gl_Position = position; + + upperLeftInputTextureCoordinate = inputTextureCoordinate.xy + vec2(-texelWidth, -texelHeight); + upperRightInputTextureCoordinate = inputTextureCoordinate.xy + vec2(texelWidth, -texelHeight); + lowerLeftInputTextureCoordinate = inputTextureCoordinate.xy + vec2(-texelWidth, texelHeight); + lowerRightInputTextureCoordinate = inputTextureCoordinate.xy + vec2(texelWidth, texelHeight); + } +); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageColorPackingFragmentShaderString = SHADER_STRING +( + precision lowp float; + + uniform sampler2D inputImageTexture; + + uniform mediump mat3 convolutionMatrix; + + varying highp vec2 outputTextureCoordinate; + + varying highp vec2 upperLeftInputTextureCoordinate; + varying highp vec2 upperRightInputTextureCoordinate; + varying highp vec2 lowerLeftInputTextureCoordinate; + varying highp vec2 lowerRightInputTextureCoordinate; + + void main() + { + float upperLeftIntensity = texture2D(inputImageTexture, upperLeftInputTextureCoordinate).r; + float upperRightIntensity = texture2D(inputImageTexture, upperRightInputTextureCoordinate).r; + float lowerLeftIntensity = texture2D(inputImageTexture, lowerLeftInputTextureCoordinate).r; + float lowerRightIntensity = texture2D(inputImageTexture, lowerRightInputTextureCoordinate).r; + + gl_FragColor = vec4(upperLeftIntensity, upperRightIntensity, lowerLeftIntensity, lowerRightIntensity); + } +); +#else +NSString *const kGPUImageColorPackingFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + uniform mat3 convolutionMatrix; + + varying vec2 outputTextureCoordinate; + + varying vec2 upperLeftInputTextureCoordinate; + varying vec2 upperRightInputTextureCoordinate; + varying vec2 lowerLeftInputTextureCoordinate; + varying vec2 lowerRightInputTextureCoordinate; + + void main() + { + float upperLeftIntensity = texture2D(inputImageTexture, upperLeftInputTextureCoordinate).r; + float upperRightIntensity = texture2D(inputImageTexture, upperRightInputTextureCoordinate).r; + float lowerLeftIntensity = texture2D(inputImageTexture, lowerLeftInputTextureCoordinate).r; + float lowerRightIntensity = texture2D(inputImageTexture, lowerRightInputTextureCoordinate).r; + + gl_FragColor = vec4(upperLeftIntensity, upperRightIntensity, lowerLeftIntensity, lowerRightIntensity); + } +); +#endif + +@implementation GPUImageColorPackingFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithVertexShaderFromString:kGPUImageColorPackingVertexShaderString fragmentShaderFromString:kGPUImageColorPackingFragmentShaderString])) + { + return nil; + } + + texelWidthUniform = [filterProgram uniformIndex:@"texelWidth"]; + texelHeightUniform = [filterProgram uniformIndex:@"texelHeight"]; + + return self; +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + texelWidth = 0.5 / inputTextureSize.width; + texelHeight = 0.5 / inputTextureSize.height; + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:filterProgram]; + glUniform1f(texelWidthUniform, texelWidth); + glUniform1f(texelHeightUniform, texelHeight); + }); +} + +#pragma mark - +#pragma mark Managing the display FBOs + +- (CGSize)sizeOfFBO; +{ + CGSize outputSize = [self maximumOutputSize]; + if ( (CGSizeEqualToSize(outputSize, CGSizeZero)) || (inputTextureSize.width < outputSize.width) ) + { + CGSize quarterSize; + quarterSize.width = inputTextureSize.width / 2.0; + quarterSize.height = inputTextureSize.height / 2.0; + return quarterSize; + } + else + { + return outputSize; + } +} + +#pragma mark - +#pragma mark Rendering + +- (CGSize)outputFrameSize; +{ + CGSize quarterSize; + quarterSize.width = inputTextureSize.width / 2.0; + quarterSize.height = inputTextureSize.height / 2.0; + return quarterSize; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTFeatureDetector.h b/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTFeatureDetector.h new file mode 100755 index 00000000..3d51ed17 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTFeatureDetector.h @@ -0,0 +1,21 @@ +#import "GPUImageFilterGroup.h" + +// This generates image-wide feature descriptors using the ColourFAST process, as developed and described in +// +// A. Ensor and S. Hall. ColourFAST: GPU-based feature point detection and tracking on mobile devices. 28th International Conference of Image and Vision Computing, New Zealand, 2013, p. 124-129. +// +// Seth Hall, "GPU accelerated feature algorithms for mobile devices", PhD thesis, School of Computing and Mathematical Sciences, Auckland University of Technology 2014. +// http://aut.researchgateway.ac.nz/handle/10292/7991 + +@class GPUImageColourFASTSamplingOperation; +@class GPUImageBoxBlurFilter; + +@interface GPUImageColourFASTFeatureDetector : GPUImageFilterGroup +{ + GPUImageBoxBlurFilter *blurFilter; + GPUImageColourFASTSamplingOperation *colourFASTSamplingOperation; +} +// The blur radius of the underlying box blur. The default is 3.0. +@property (readwrite, nonatomic) CGFloat blurRadiusInPixels; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTFeatureDetector.m b/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTFeatureDetector.m new file mode 100755 index 00000000..f4e3684c --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTFeatureDetector.m @@ -0,0 +1,48 @@ +#import "GPUImageColourFASTFeatureDetector.h" +#import "GPUImageColourFASTSamplingOperation.h" +#import "GPUImageBoxBlurFilter.h" + +@implementation GPUImageColourFASTFeatureDetector + +@synthesize blurRadiusInPixels; + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + // First pass: apply a variable Gaussian blur + blurFilter = [[GPUImageBoxBlurFilter alloc] init]; + [self addFilter:blurFilter]; + + // Second pass: combine the blurred image with the original sharp one + colourFASTSamplingOperation = [[GPUImageColourFASTSamplingOperation alloc] init]; + [self addFilter:colourFASTSamplingOperation]; + + // Texture location 0 needs to be the sharp image for both the blur and the second stage processing + [blurFilter addTarget:colourFASTSamplingOperation atTextureLocation:1]; + + self.initialFilters = [NSArray arrayWithObjects:blurFilter, colourFASTSamplingOperation, nil]; + self.terminalFilter = colourFASTSamplingOperation; + + self.blurRadiusInPixels = 3.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBlurRadiusInPixels:(CGFloat)newValue; +{ + blurFilter.blurRadiusInPixels = newValue; +} + +- (CGFloat)blurRadiusInPixels; +{ + return blurFilter.blurRadiusInPixels; +} + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTSamplingOperation.h b/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTSamplingOperation.h new file mode 100755 index 00000000..78e6ede9 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTSamplingOperation.h @@ -0,0 +1,22 @@ +#import "GPUImageTwoInputFilter.h" + +// This is the feature extraction phase of the ColourFAST feature detector, as described in: +// +// A. Ensor and S. Hall. ColourFAST: GPU-based feature point detection and tracking on mobile devices. 28th International Conference of Image and Vision Computing, New Zealand, 2013, p. 124-129. +// +// Seth Hall, "GPU accelerated feature algorithms for mobile devices", PhD thesis, School of Computing and Mathematical Sciences, Auckland University of Technology 2014. +// http://aut.researchgateway.ac.nz/handle/10292/7991 + +@interface GPUImageColourFASTSamplingOperation : GPUImageTwoInputFilter +{ + GLint texelWidthUniform, texelHeightUniform; + + CGFloat texelWidth, texelHeight; + BOOL hasOverriddenImageSizeFactor; +} + +// The texel width and height determines how far out to sample from this texel. By default, this is the normalized width of a pixel, but this can be overridden for different effects. +@property(readwrite, nonatomic) CGFloat texelWidth; +@property(readwrite, nonatomic) CGFloat texelHeight; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTSamplingOperation.m b/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTSamplingOperation.m new file mode 100755 index 00000000..fc67f470 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageColourFASTSamplingOperation.m @@ -0,0 +1,204 @@ +#import "GPUImageColourFASTSamplingOperation.h" + +NSString *const kGPUImageColourFASTSamplingVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + attribute vec4 inputTextureCoordinate2; + + uniform float texelWidth; + uniform float texelHeight; + + varying vec2 textureCoordinate; + varying vec2 pointATextureCoordinate; + varying vec2 pointBTextureCoordinate; + varying vec2 pointCTextureCoordinate; + varying vec2 pointDTextureCoordinate; + varying vec2 pointETextureCoordinate; + varying vec2 pointFTextureCoordinate; + varying vec2 pointGTextureCoordinate; + varying vec2 pointHTextureCoordinate; + + void main() + { + gl_Position = position; + + float tripleTexelWidth = 3.0 * texelWidth; + float tripleTexelHeight = 3.0 * texelHeight; + + textureCoordinate = inputTextureCoordinate.xy; + + pointATextureCoordinate = vec2(textureCoordinate.x + tripleTexelWidth, textureCoordinate.y + texelHeight); + pointBTextureCoordinate = vec2(textureCoordinate.x + texelWidth, textureCoordinate.y + tripleTexelHeight); + pointCTextureCoordinate = vec2(textureCoordinate.x - texelWidth, textureCoordinate.y + tripleTexelHeight); + pointDTextureCoordinate = vec2(textureCoordinate.x - tripleTexelWidth, textureCoordinate.y + texelHeight); + pointETextureCoordinate = vec2(textureCoordinate.x - tripleTexelWidth, textureCoordinate.y - texelHeight); + pointFTextureCoordinate = vec2(textureCoordinate.x - texelWidth, textureCoordinate.y - tripleTexelHeight); + pointGTextureCoordinate = vec2(textureCoordinate.x + texelWidth, textureCoordinate.y - tripleTexelHeight); + pointHTextureCoordinate = vec2(textureCoordinate.x + tripleTexelWidth, textureCoordinate.y - texelHeight); + } +); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageColourFASTSamplingFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 textureCoordinate; + varying vec2 pointATextureCoordinate; + varying vec2 pointBTextureCoordinate; + varying vec2 pointCTextureCoordinate; + varying vec2 pointDTextureCoordinate; + varying vec2 pointETextureCoordinate; + varying vec2 pointFTextureCoordinate; + varying vec2 pointGTextureCoordinate; + varying vec2 pointHTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + const float PITwo = 6.2832; + const float PI = 3.1416; + void main() + { + vec3 centerColor = texture2D(inputImageTexture, textureCoordinate).rgb; + + vec3 pointAColor = texture2D(inputImageTexture, pointATextureCoordinate).rgb; + vec3 pointBColor = texture2D(inputImageTexture, pointBTextureCoordinate).rgb; + vec3 pointCColor = texture2D(inputImageTexture, pointCTextureCoordinate).rgb; + vec3 pointDColor = texture2D(inputImageTexture, pointDTextureCoordinate).rgb; + vec3 pointEColor = texture2D(inputImageTexture, pointETextureCoordinate).rgb; + vec3 pointFColor = texture2D(inputImageTexture, pointFTextureCoordinate).rgb; + vec3 pointGColor = texture2D(inputImageTexture, pointGTextureCoordinate).rgb; + vec3 pointHColor = texture2D(inputImageTexture, pointHTextureCoordinate).rgb; + + vec3 colorComparison = ((pointAColor + pointBColor + pointCColor + pointDColor + pointEColor + pointFColor + pointGColor + pointHColor) * 0.125) - centerColor; + + // Direction calculation drawn from Appendix B of Seth Hall's Ph.D. thesis + + vec3 dirX = (pointAColor*0.94868) + (pointBColor*0.316227) - (pointCColor*0.316227) - (pointDColor*0.94868) - (pointEColor*0.94868) - (pointFColor*0.316227) + (pointGColor*0.316227) + (pointHColor*0.94868); + vec3 dirY = (pointAColor*0.316227) + (pointBColor*0.94868) + (pointCColor*0.94868) + (pointDColor*0.316227) - (pointEColor*0.316227) - (pointFColor*0.94868) - (pointGColor*0.94868) - (pointHColor*0.316227); + vec3 absoluteDifference = abs(colorComparison); + float componentLength = length(colorComparison); + float avgX = dot(absoluteDifference, dirX) / componentLength; + float avgY = dot(absoluteDifference, dirY) / componentLength; + float angle = atan(avgY, avgX); + + vec3 normalizedColorComparison = (colorComparison + 1.0) * 0.5; + + gl_FragColor = vec4(normalizedColorComparison, (angle+PI)/PITwo); + } +); +#else +NSString *const kGPUImageColourFASTSamplingFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 pointATextureCoordinate; + varying vec2 pointBTextureCoordinate; + varying vec2 pointCTextureCoordinate; + varying vec2 pointDTextureCoordinate; + varying vec2 pointETextureCoordinate; + varying vec2 pointFTextureCoordinate; + varying vec2 pointGTextureCoordinate; + varying vec2 pointHTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + const float PITwo = 6.2832; + const float PI = 3.1416; + void main() + { + vec3 centerColor = texture2D(inputImageTexture, textureCoordinate).rgb; + + vec3 pointAColor = texture2D(inputImageTexture, pointATextureCoordinate).rgb; + vec3 pointBColor = texture2D(inputImageTexture, pointBTextureCoordinate).rgb; + vec3 pointCColor = texture2D(inputImageTexture, pointCTextureCoordinate).rgb; + vec3 pointDColor = texture2D(inputImageTexture, pointDTextureCoordinate).rgb; + vec3 pointEColor = texture2D(inputImageTexture, pointETextureCoordinate).rgb; + vec3 pointFColor = texture2D(inputImageTexture, pointFTextureCoordinate).rgb; + vec3 pointGColor = texture2D(inputImageTexture, pointGTextureCoordinate).rgb; + vec3 pointHColor = texture2D(inputImageTexture, pointHTextureCoordinate).rgb; + + vec3 colorComparison = ((pointAColor + pointBColor + pointCColor + pointDColor + pointEColor + pointFColor + pointGColor + pointHColor) * 0.125) - centerColor; + + // Direction calculation drawn from Appendix B of Seth Hall's Ph.D. thesis + + vec3 dirX = (pointAColor*0.94868) + (pointBColor*0.316227) - (pointCColor*0.316227) - (pointDColor*0.94868) - (pointEColor*0.94868) - (pointFColor*0.316227) + (pointGColor*0.316227) + (pointHColor*0.94868); + vec3 dirY = (pointAColor*0.316227) + (pointBColor*0.94868) + (pointCColor*0.94868) + (pointDColor*0.316227) - (pointEColor*0.316227) - (pointFColor*0.94868) - (pointGColor*0.94868) - (pointHColor*0.316227); + vec3 absoluteDifference = abs(colorComparison); + float componentLength = length(colorComparison); + float avgX = dot(absoluteDifference, dirX) / componentLength; + float avgY = dot(absoluteDifference, dirY) / componentLength; + float angle = atan(avgY, avgX); + + vec3 normalizedColorComparison = (colorComparison + 1.0) * 0.5; + + gl_FragColor = vec4(normalizedColorComparison, (angle+PI)/PITwo); + } +); +#endif + + +@implementation GPUImageColourFASTSamplingOperation + +@synthesize texelWidth = _texelWidth; +@synthesize texelHeight = _texelHeight; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [super initWithVertexShaderFromString:kGPUImageColourFASTSamplingVertexShaderString fragmentShaderFromString:kGPUImageColourFASTSamplingFragmentShaderString])) + { + return nil; + } + + texelWidthUniform = [filterProgram uniformIndex:@"texelWidth"]; + texelHeightUniform = [filterProgram uniformIndex:@"texelHeight"]; + + return self; +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + if (!hasOverriddenImageSizeFactor) + { + _texelWidth = 1.0 / filterFrameSize.width; + _texelHeight = 1.0 / filterFrameSize.height; + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:filterProgram]; + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + glUniform1f(texelWidthUniform, _texelHeight); + glUniform1f(texelHeightUniform, _texelWidth); + } + else + { + glUniform1f(texelWidthUniform, _texelWidth); + glUniform1f(texelHeightUniform, _texelHeight); + } + }); + } +} + +#pragma mark - +#pragma mark Accessors + +- (void)setTexelWidth:(CGFloat)newValue; +{ + hasOverriddenImageSizeFactor = YES; + _texelWidth = newValue; + + [self setFloat:_texelWidth forUniform:texelWidthUniform program:filterProgram]; +} + +- (void)setTexelHeight:(CGFloat)newValue; +{ + hasOverriddenImageSizeFactor = YES; + _texelHeight = newValue; + + [self setFloat:_texelHeight forUniform:texelHeightUniform program:filterProgram]; +} + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageContrastFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageContrastFilter.h new file mode 100755 index 00000000..e09e6dc4 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageContrastFilter.h @@ -0,0 +1,14 @@ +#import "GPUImageFilter.h" + +/** Adjusts the contrast of the image + */ +@interface GPUImageContrastFilter : GPUImageFilter +{ + GLint contrastUniform; +} + +/** Contrast ranges from 0.0 to 4.0 (max contrast), with 1.0 as the normal level + */ +@property(readwrite, nonatomic) CGFloat contrast; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageContrastFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageContrastFilter.m new file mode 100755 index 00000000..5ed1e22f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageContrastFilter.m @@ -0,0 +1,66 @@ +#import "GPUImageContrastFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageContrastFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform lowp float contrast; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w); + } +); +#else +NSString *const kGPUImageContrastFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float contrast; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w); + } + ); +#endif + +@implementation GPUImageContrastFilter + +@synthesize contrast = _contrast; + +#pragma mark - +#pragma mark Initialization + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageContrastFragmentShaderString])) + { + return nil; + } + + contrastUniform = [filterProgram uniformIndex:@"contrast"]; + self.contrast = 1.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setContrast:(CGFloat)newValue; +{ + _contrast = newValue; + + [self setFloat:_contrast forUniform:contrastUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageCropFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageCropFilter.h new file mode 100755 index 00000000..641fb7bf --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageCropFilter.h @@ -0,0 +1,14 @@ +#import "GPUImageFilter.h" + +@interface GPUImageCropFilter : GPUImageFilter +{ + GLfloat cropTextureCoordinates[8]; +} + +// The crop region is the rectangle within the image to crop. It is normalized to a coordinate space from 0.0 to 1.0, with 0.0, 0.0 being the upper left corner of the image +@property(readwrite, nonatomic) CGRect cropRegion; + +// Initialization and teardown +- (id)initWithCropRegion:(CGRect)newCropRegion; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageCropFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageCropFilter.m new file mode 100755 index 00000000..22e33c17 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageCropFilter.m @@ -0,0 +1,274 @@ +#import "GPUImageCropFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageCropFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate); + } +); +#else +NSString *const kGPUImageCropFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate); + } +); +#endif + +@interface GPUImageCropFilter () + +- (void)calculateCropTextureCoordinates; + +@end + +@interface GPUImageCropFilter() +{ + CGSize originallySuppliedInputSize; +} + +@end + +@implementation GPUImageCropFilter + +@synthesize cropRegion = _cropRegion; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithCropRegion:(CGRect)newCropRegion; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageCropFragmentShaderString])) + { + return nil; + } + + self.cropRegion = newCropRegion; + + return self; +} + +- (id)init; +{ + if (!(self = [self initWithCropRegion:CGRectMake(0.0, 0.0, 1.0, 1.0)])) + { + return nil; + } + + return self; +} + +#pragma mark - +#pragma mark Rendering + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + if (self.preventRendering) + { + return; + } + +// if (overrideInputSize) +// { +// if (CGSizeEqualToSize(forcedMaximumSize, CGSizeZero)) +// { +// return; +// } +// else +// { +// CGRect insetRect = AVMakeRectWithAspectRatioInsideRect(newSize, CGRectMake(0.0, 0.0, forcedMaximumSize.width, forcedMaximumSize.height)); +// inputTextureSize = insetRect.size; +// return; +// } +// } + + CGSize rotatedSize = [self rotatedSize:newSize forIndex:textureIndex]; + originallySuppliedInputSize = rotatedSize; + + CGSize scaledSize; + scaledSize.width = rotatedSize.width * _cropRegion.size.width; + scaledSize.height = rotatedSize.height * _cropRegion.size.height; + + + if (CGSizeEqualToSize(scaledSize, CGSizeZero)) + { + inputTextureSize = scaledSize; + } + else if (!CGSizeEqualToSize(inputTextureSize, scaledSize)) + { + inputTextureSize = scaledSize; + } +} + +#pragma mark - +#pragma mark GPUImageInput + +- (void)calculateCropTextureCoordinates; +{ + CGFloat minX = _cropRegion.origin.x; + CGFloat minY = _cropRegion.origin.y; + CGFloat maxX = CGRectGetMaxX(_cropRegion); + CGFloat maxY = CGRectGetMaxY(_cropRegion); + + switch(inputRotation) + { + case kGPUImageNoRotation: // Works + { + cropTextureCoordinates[0] = minX; // 0,0 + cropTextureCoordinates[1] = minY; + + cropTextureCoordinates[2] = maxX; // 1,0 + cropTextureCoordinates[3] = minY; + + cropTextureCoordinates[4] = minX; // 0,1 + cropTextureCoordinates[5] = maxY; + + cropTextureCoordinates[6] = maxX; // 1,1 + cropTextureCoordinates[7] = maxY; + }; break; + case kGPUImageRotateLeft: // Fixed + { + cropTextureCoordinates[0] = maxY; // 1,0 + cropTextureCoordinates[1] = 1.0 - maxX; + + cropTextureCoordinates[2] = maxY; // 1,1 + cropTextureCoordinates[3] = 1.0 - minX; + + cropTextureCoordinates[4] = minY; // 0,0 + cropTextureCoordinates[5] = 1.0 - maxX; + + cropTextureCoordinates[6] = minY; // 0,1 + cropTextureCoordinates[7] = 1.0 - minX; + }; break; + case kGPUImageRotateRight: // Fixed + { + cropTextureCoordinates[0] = minY; // 0,1 + cropTextureCoordinates[1] = 1.0 - minX; + + cropTextureCoordinates[2] = minY; // 0,0 + cropTextureCoordinates[3] = 1.0 - maxX; + + cropTextureCoordinates[4] = maxY; // 1,1 + cropTextureCoordinates[5] = 1.0 - minX; + + cropTextureCoordinates[6] = maxY; // 1,0 + cropTextureCoordinates[7] = 1.0 - maxX; + }; break; + case kGPUImageFlipVertical: // Works for me + { + cropTextureCoordinates[0] = minX; // 0,1 + cropTextureCoordinates[1] = maxY; + + cropTextureCoordinates[2] = maxX; // 1,1 + cropTextureCoordinates[3] = maxY; + + cropTextureCoordinates[4] = minX; // 0,0 + cropTextureCoordinates[5] = minY; + + cropTextureCoordinates[6] = maxX; // 1,0 + cropTextureCoordinates[7] = minY; + }; break; + case kGPUImageFlipHorizonal: // Works for me + { + cropTextureCoordinates[0] = maxX; // 1,0 + cropTextureCoordinates[1] = minY; + + cropTextureCoordinates[2] = minX; // 0,0 + cropTextureCoordinates[3] = minY; + + cropTextureCoordinates[4] = maxX; // 1,1 + cropTextureCoordinates[5] = maxY; + + cropTextureCoordinates[6] = minX; // 0,1 + cropTextureCoordinates[7] = maxY; + }; break; + case kGPUImageRotate180: // Fixed + { + cropTextureCoordinates[0] = maxX; // 1,1 + cropTextureCoordinates[1] = maxY; + + cropTextureCoordinates[2] = minX; // 0,1 + cropTextureCoordinates[3] = maxY; + + cropTextureCoordinates[4] = maxX; // 1,0 + cropTextureCoordinates[5] = minY; + + cropTextureCoordinates[6] = minX; // 0,0 + cropTextureCoordinates[7] = minY; + }; break; + case kGPUImageRotateRightFlipVertical: // Fixed + { + cropTextureCoordinates[0] = minY; // 0,0 + cropTextureCoordinates[1] = 1.0 - maxX; + + cropTextureCoordinates[2] = minY; // 0,1 + cropTextureCoordinates[3] = 1.0 - minX; + + cropTextureCoordinates[4] = maxY; // 1,0 + cropTextureCoordinates[5] = 1.0 - maxX; + + cropTextureCoordinates[6] = maxY; // 1,1 + cropTextureCoordinates[7] = 1.0 - minX; + }; break; + case kGPUImageRotateRightFlipHorizontal: // Fixed + { + cropTextureCoordinates[0] = maxY; // 1,1 + cropTextureCoordinates[1] = 1.0 - minX; + + cropTextureCoordinates[2] = maxY; // 1,0 + cropTextureCoordinates[3] = 1.0 - maxX; + + cropTextureCoordinates[4] = minY; // 0,1 + cropTextureCoordinates[5] = 1.0 - minX; + + cropTextureCoordinates[6] = minY; // 0,0 + cropTextureCoordinates[7] = 1.0 - maxX; + }; break; + } +} + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + static const GLfloat cropSquareVertices[] = { + -1.0f, -1.0f, + 1.0f, -1.0f, + -1.0f, 1.0f, + 1.0f, 1.0f, + }; + + [self renderToTextureWithVertices:cropSquareVertices textureCoordinates:cropTextureCoordinates]; + + [self informTargetsAboutNewFrameAtTime:frameTime]; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setCropRegion:(CGRect)newValue; +{ + NSParameterAssert(newValue.origin.x >= 0 && newValue.origin.x <= 1 && + newValue.origin.y >= 0 && newValue.origin.y <= 1 && + newValue.size.width >= 0 && newValue.size.width <= 1 && + newValue.size.height >= 0 && newValue.size.height <= 1); + + _cropRegion = newValue; + [self calculateCropTextureCoordinates]; +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + [super setInputRotation:newInputRotation atIndex:textureIndex]; + [self calculateCropTextureCoordinates]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageCrosshairGenerator.h b/LFLiveKit/Vendor/GPUImage/GPUImageCrosshairGenerator.h new file mode 100644 index 00000000..569774f5 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageCrosshairGenerator.h @@ -0,0 +1,17 @@ +#import "GPUImageFilter.h" + +@interface GPUImageCrosshairGenerator : GPUImageFilter +{ + GLint crosshairWidthUniform, crosshairColorUniform; +} + +// The width of the displayed crosshairs, in pixels. Currently this only works well for odd widths. The default is 5. +@property(readwrite, nonatomic) CGFloat crosshairWidth; + +// The color of the crosshairs is specified using individual red, green, and blue components (normalized to 1.0). The default is green: (0.0, 1.0, 0.0). +- (void)setCrosshairColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; + +// Rendering +- (void)renderCrosshairsFromArray:(GLfloat *)crosshairCoordinates count:(NSUInteger)numberOfCrosshairs frameTime:(CMTime)frameTime; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageCrosshairGenerator.m b/LFLiveKit/Vendor/GPUImage/GPUImageCrosshairGenerator.m new file mode 100644 index 00000000..9e2a29a2 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageCrosshairGenerator.m @@ -0,0 +1,139 @@ +#import "GPUImageCrosshairGenerator.h" + +NSString *const kGPUImageCrosshairVertexShaderString = SHADER_STRING +( + attribute vec4 position; + + uniform float crosshairWidth; + + varying vec2 centerLocation; + varying float pointSpacing; + + void main() + { + gl_Position = vec4(((position.xy * 2.0) - 1.0), 0.0, 1.0); + gl_PointSize = crosshairWidth + 1.0; + pointSpacing = 1.0 / crosshairWidth; + centerLocation = vec2(pointSpacing * ceil(crosshairWidth / 2.0), pointSpacing * ceil(crosshairWidth / 2.0)); + } +); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageCrosshairFragmentShaderString = SHADER_STRING +( + uniform lowp vec3 crosshairColor; + + varying highp vec2 centerLocation; + varying highp float pointSpacing; + + void main() + { + lowp vec2 distanceFromCenter = abs(centerLocation - gl_PointCoord.xy); + lowp float axisTest = step(pointSpacing, gl_PointCoord.y) * step(distanceFromCenter.x, 0.09) + step(pointSpacing, gl_PointCoord.x) * step(distanceFromCenter.y, 0.09); + + gl_FragColor = vec4(crosshairColor * axisTest, axisTest); +// gl_FragColor = vec4(distanceFromCenterInX, distanceFromCenterInY, 0.0, 1.0); + } +); +#else +NSString *const kGPUImageCrosshairFragmentShaderString = SHADER_STRING +( + GPUImageEscapedHashIdentifier(version 120)\n + + uniform vec3 crosshairColor; + + varying vec2 centerLocation; + varying float pointSpacing; + + void main() + { + vec2 distanceFromCenter = abs(centerLocation - gl_PointCoord.xy); + float axisTest = step(pointSpacing, gl_PointCoord.y) * step(distanceFromCenter.x, 0.09) + step(pointSpacing, gl_PointCoord.x) * step(distanceFromCenter.y, 0.09); + + gl_FragColor = vec4(crosshairColor * axisTest, axisTest); + // gl_FragColor = vec4(distanceFromCenterInX, distanceFromCenterInY, 0.0, 1.0); + } +); +#endif + +@implementation GPUImageCrosshairGenerator + +@synthesize crosshairWidth = _crosshairWidth; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithVertexShaderFromString:kGPUImageCrosshairVertexShaderString fragmentShaderFromString:kGPUImageCrosshairFragmentShaderString])) + { + return nil; + } + + runSynchronouslyOnVideoProcessingQueue(^{ + crosshairWidthUniform = [filterProgram uniformIndex:@"crosshairWidth"]; + crosshairColorUniform = [filterProgram uniformIndex:@"crosshairColor"]; + + self.crosshairWidth = 5.0; + [self setCrosshairColorRed:0.0 green:1.0 blue:0.0]; + }); + + return self; +} + +#pragma mark - +#pragma mark Rendering + +- (void)renderCrosshairsFromArray:(GLfloat *)crosshairCoordinates count:(NSUInteger)numberOfCrosshairs frameTime:(CMTime)frameTime; +{ + if (self.preventRendering) + { + return; + } + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:filterProgram]; + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +#else + glEnable(GL_POINT_SPRITE); + glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); +#endif + + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, crosshairCoordinates); + + glDrawArrays(GL_POINTS, 0, (GLsizei)numberOfCrosshairs); + + [self informTargetsAboutNewFrameAtTime:frameTime]; + }); +} + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + // Prevent rendering of the frame by normal means +} + +#pragma mark - +#pragma mark Accessors + +- (void)setCrosshairWidth:(CGFloat)newValue; +{ + _crosshairWidth = newValue; + + [self setFloat:_crosshairWidth forUniform:crosshairWidthUniform program:filterProgram]; +} + +- (void)setCrosshairColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; +{ + GPUVector3 crosshairColor = {redComponent, greenComponent, blueComponent}; + + [self setVec3:crosshairColor forUniform:crosshairColorUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageCrosshatchFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageCrosshatchFilter.h new file mode 100755 index 00000000..dab18967 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageCrosshatchFilter.h @@ -0,0 +1,13 @@ +#import "GPUImageFilter.h" + +@interface GPUImageCrosshatchFilter : GPUImageFilter +{ + GLint crossHatchSpacingUniform, lineWidthUniform; +} +// The fractional width of the image to use as the spacing for the crosshatch. The default is 0.03. +@property(readwrite, nonatomic) CGFloat crossHatchSpacing; + +// A relative width for the crosshatch lines. The default is 0.003. +@property(readwrite, nonatomic) CGFloat lineWidth; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageCrosshatchFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageCrosshatchFilter.m new file mode 100755 index 00000000..51dbd592 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageCrosshatchFilter.m @@ -0,0 +1,163 @@ +#import "GPUImageCrosshatchFilter.h" + +// Shader code based on http://machinesdontcare.wordpress.com/ + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageCrosshatchFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp float crossHatchSpacing; + uniform highp float lineWidth; + + const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + highp float luminance = dot(texture2D(inputImageTexture, textureCoordinate).rgb, W); + + lowp vec4 colorToDisplay = vec4(1.0, 1.0, 1.0, 1.0); + if (luminance < 1.00) + { + if (mod(textureCoordinate.x + textureCoordinate.y, crossHatchSpacing) <= lineWidth) + { + colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); + } + } + if (luminance < 0.75) + { + if (mod(textureCoordinate.x - textureCoordinate.y, crossHatchSpacing) <= lineWidth) + { + colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); + } + } + if (luminance < 0.50) + { + if (mod(textureCoordinate.x + textureCoordinate.y - (crossHatchSpacing / 2.0), crossHatchSpacing) <= lineWidth) + { + colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); + } + } + if (luminance < 0.3) + { + if (mod(textureCoordinate.x - textureCoordinate.y - (crossHatchSpacing / 2.0), crossHatchSpacing) <= lineWidth) + { + colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); + } + } + + gl_FragColor = colorToDisplay; + } +); +#else +NSString *const kGPUImageCrosshatchFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform float crossHatchSpacing; + uniform float lineWidth; + + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + float luminance = dot(texture2D(inputImageTexture, textureCoordinate).rgb, W); + + vec4 colorToDisplay = vec4(1.0, 1.0, 1.0, 1.0); + if (luminance < 1.00) + { + if (mod(textureCoordinate.x + textureCoordinate.y, crossHatchSpacing) <= lineWidth) + { + colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); + } + } + if (luminance < 0.75) + { + if (mod(textureCoordinate.x - textureCoordinate.y, crossHatchSpacing) <= lineWidth) + { + colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); + } + } + if (luminance < 0.50) + { + if (mod(textureCoordinate.x + textureCoordinate.y - (crossHatchSpacing / 2.0), crossHatchSpacing) <= lineWidth) + { + colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); + } + } + if (luminance < 0.3) + { + if (mod(textureCoordinate.x - textureCoordinate.y - (crossHatchSpacing / 2.0), crossHatchSpacing) <= lineWidth) + { + colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); + } + } + + gl_FragColor = colorToDisplay; + } +); +#endif + +@implementation GPUImageCrosshatchFilter + +@synthesize crossHatchSpacing = _crossHatchSpacing; +@synthesize lineWidth = _lineWidth; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageCrosshatchFragmentShaderString])) + { + return nil; + } + + crossHatchSpacingUniform = [filterProgram uniformIndex:@"crossHatchSpacing"]; + lineWidthUniform = [filterProgram uniformIndex:@"lineWidth"]; + + self.crossHatchSpacing = 0.03; + self.lineWidth = 0.003; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setCrossHatchSpacing:(CGFloat)newValue; +{ + CGFloat singlePixelSpacing; + if (inputTextureSize.width != 0.0) + { + singlePixelSpacing = 1.0 / inputTextureSize.width; + } + else + { + singlePixelSpacing = 1.0 / 2048.0; + } + + if (newValue < singlePixelSpacing) + { + _crossHatchSpacing = singlePixelSpacing; + } + else + { + _crossHatchSpacing = newValue; + } + + [self setFloat:_crossHatchSpacing forUniform:crossHatchSpacingUniform program:filterProgram]; +} + +- (void)setLineWidth:(CGFloat)newValue; +{ + _lineWidth = newValue; + + [self setFloat:_lineWidth forUniform:lineWidthUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDarkenBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDarkenBlendFilter.h new file mode 100755 index 00000000..5dfe3405 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDarkenBlendFilter.h @@ -0,0 +1,7 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageDarkenBlendFilter : GPUImageTwoInputFilter +{ +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDarkenBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageDarkenBlendFilter.m new file mode 100644 index 00000000..85ec9e8a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDarkenBlendFilter.m @@ -0,0 +1,52 @@ +#import "GPUImageDarkenBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageDarkenBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + lowp vec4 base = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 overlayer = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(min(overlayer.rgb * base.a, base.rgb * overlayer.a) + overlayer.rgb * (1.0 - base.a) + base.rgb * (1.0 - overlayer.a), 1.0); + } +); +#else +NSString *const kGPUImageDarkenBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 base = texture2D(inputImageTexture, textureCoordinate); + vec4 overlayer = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(min(overlayer.rgb * base.a, base.rgb * overlayer.a) + overlayer.rgb * (1.0 - base.a) + base.rgb * (1.0 - overlayer.a), 1.0); + } + ); +#endif + +@implementation GPUImageDarkenBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageDarkenBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDifferenceBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDifferenceBlendFilter.h new file mode 100755 index 00000000..7c7dfc23 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDifferenceBlendFilter.h @@ -0,0 +1,7 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageDifferenceBlendFilter : GPUImageTwoInputFilter +{ +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDifferenceBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageDifferenceBlendFilter.m new file mode 100755 index 00000000..01bf09b2 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDifferenceBlendFilter.m @@ -0,0 +1,50 @@ +#import "GPUImageDifferenceBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageDifferenceBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + mediump vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + mediump vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + gl_FragColor = vec4(abs(textureColor2.rgb - textureColor.rgb), textureColor.a); + } +); +#else +NSString *const kGPUImageDifferenceBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + gl_FragColor = vec4(abs(textureColor2.rgb - textureColor.rgb), textureColor.a); + } +); +#endif + +@implementation GPUImageDifferenceBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageDifferenceBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDilationFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDilationFilter.h new file mode 100644 index 00000000..59423a37 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDilationFilter.h @@ -0,0 +1,16 @@ +#import "GPUImageTwoPassTextureSamplingFilter.h" + +// For each pixel, this sets it to the maximum value of the red channel in a rectangular neighborhood extending out dilationRadius pixels from the center. +// This extends out bright features, and is most commonly used with black-and-white thresholded images. + +extern NSString *const kGPUImageDilationRadiusOneVertexShaderString; +extern NSString *const kGPUImageDilationRadiusTwoVertexShaderString; +extern NSString *const kGPUImageDilationRadiusThreeVertexShaderString; +extern NSString *const kGPUImageDilationRadiusFourVertexShaderString; + +@interface GPUImageDilationFilter : GPUImageTwoPassTextureSamplingFilter + +// Acceptable values for dilationRadius, which sets the distance in pixels to sample out from the center, are 1, 2, 3, and 4. +- (id)initWithRadius:(NSUInteger)dilationRadius; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDilationFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageDilationFilter.m new file mode 100644 index 00000000..df065185 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDilationFilter.m @@ -0,0 +1,431 @@ +#import "GPUImageDilationFilter.h" + +@implementation GPUImageDilationFilter + +NSString *const kGPUImageDilationRadiusOneVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec2 inputTextureCoordinate; + + uniform float texelWidthOffset; + uniform float texelHeightOffset; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + + void main() + { + gl_Position = position; + + vec2 offset = vec2(texelWidthOffset, texelHeightOffset); + + centerTextureCoordinate = inputTextureCoordinate; + oneStepNegativeTextureCoordinate = inputTextureCoordinate - offset; + oneStepPositiveTextureCoordinate = inputTextureCoordinate + offset; + } +); + +NSString *const kGPUImageDilationRadiusTwoVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec2 inputTextureCoordinate; + + uniform float texelWidthOffset; + uniform float texelHeightOffset; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + + void main() + { + gl_Position = position; + + vec2 offset = vec2(texelWidthOffset, texelHeightOffset); + + centerTextureCoordinate = inputTextureCoordinate; + oneStepNegativeTextureCoordinate = inputTextureCoordinate - offset; + oneStepPositiveTextureCoordinate = inputTextureCoordinate + offset; + twoStepsNegativeTextureCoordinate = inputTextureCoordinate - (offset * 2.0); + twoStepsPositiveTextureCoordinate = inputTextureCoordinate + (offset * 2.0); + } +); + +NSString *const kGPUImageDilationRadiusThreeVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec2 inputTextureCoordinate; + + uniform float texelWidthOffset; + uniform float texelHeightOffset; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + + void main() + { + gl_Position = position; + + vec2 offset = vec2(texelWidthOffset, texelHeightOffset); + + centerTextureCoordinate = inputTextureCoordinate; + oneStepNegativeTextureCoordinate = inputTextureCoordinate - offset; + oneStepPositiveTextureCoordinate = inputTextureCoordinate + offset; + twoStepsNegativeTextureCoordinate = inputTextureCoordinate - (offset * 2.0); + twoStepsPositiveTextureCoordinate = inputTextureCoordinate + (offset * 2.0); + threeStepsNegativeTextureCoordinate = inputTextureCoordinate - (offset * 3.0); + threeStepsPositiveTextureCoordinate = inputTextureCoordinate + (offset * 3.0); + } +); + +NSString *const kGPUImageDilationRadiusFourVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec2 inputTextureCoordinate; + + uniform float texelWidthOffset; + uniform float texelHeightOffset; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + varying vec2 fourStepsPositiveTextureCoordinate; + varying vec2 fourStepsNegativeTextureCoordinate; + + void main() + { + gl_Position = position; + + vec2 offset = vec2(texelWidthOffset, texelHeightOffset); + + centerTextureCoordinate = inputTextureCoordinate; + oneStepNegativeTextureCoordinate = inputTextureCoordinate - offset; + oneStepPositiveTextureCoordinate = inputTextureCoordinate + offset; + twoStepsNegativeTextureCoordinate = inputTextureCoordinate - (offset * 2.0); + twoStepsPositiveTextureCoordinate = inputTextureCoordinate + (offset * 2.0); + threeStepsNegativeTextureCoordinate = inputTextureCoordinate - (offset * 3.0); + threeStepsPositiveTextureCoordinate = inputTextureCoordinate + (offset * 3.0); + fourStepsNegativeTextureCoordinate = inputTextureCoordinate - (offset * 4.0); + fourStepsPositiveTextureCoordinate = inputTextureCoordinate + (offset * 4.0); + } +); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageDilationRadiusOneFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + + lowp float maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + + gl_FragColor = vec4(vec3(maxValue), 1.0); + } +); + +NSString *const kGPUImageDilationRadiusTwoFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + float twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate).r; + float twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate).r; + + lowp float maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + maxValue = max(maxValue, twoStepsPositiveIntensity); + maxValue = max(maxValue, twoStepsNegativeIntensity); + + gl_FragColor = vec4(vec3(maxValue), 1.0); + } +); + +NSString *const kGPUImageDilationRadiusThreeFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + float twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate).r; + float twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate).r; + float threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate).r; + float threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate).r; + + lowp float maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + maxValue = max(maxValue, twoStepsPositiveIntensity); + maxValue = max(maxValue, twoStepsNegativeIntensity); + maxValue = max(maxValue, threeStepsPositiveIntensity); + maxValue = max(maxValue, threeStepsNegativeIntensity); + + gl_FragColor = vec4(vec3(maxValue), 1.0); + } +); + +NSString *const kGPUImageDilationRadiusFourFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + varying vec2 fourStepsPositiveTextureCoordinate; + varying vec2 fourStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + float twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate).r; + float twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate).r; + float threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate).r; + float threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate).r; + float fourStepsPositiveIntensity = texture2D(inputImageTexture, fourStepsPositiveTextureCoordinate).r; + float fourStepsNegativeIntensity = texture2D(inputImageTexture, fourStepsNegativeTextureCoordinate).r; + + lowp float maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + maxValue = max(maxValue, twoStepsPositiveIntensity); + maxValue = max(maxValue, twoStepsNegativeIntensity); + maxValue = max(maxValue, threeStepsPositiveIntensity); + maxValue = max(maxValue, threeStepsNegativeIntensity); + maxValue = max(maxValue, fourStepsPositiveIntensity); + maxValue = max(maxValue, fourStepsNegativeIntensity); + + gl_FragColor = vec4(vec3(maxValue), 1.0); + } +); +#else +NSString *const kGPUImageDilationRadiusOneFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + + float maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + + gl_FragColor = vec4(vec3(maxValue), 1.0); + } +); + +NSString *const kGPUImageDilationRadiusTwoFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + float twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate).r; + float twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate).r; + + float maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + maxValue = max(maxValue, twoStepsPositiveIntensity); + maxValue = max(maxValue, twoStepsNegativeIntensity); + + gl_FragColor = vec4(vec3(maxValue), 1.0); + } +); + +NSString *const kGPUImageDilationRadiusThreeFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + float twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate).r; + float twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate).r; + float threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate).r; + float threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate).r; + + float maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + maxValue = max(maxValue, twoStepsPositiveIntensity); + maxValue = max(maxValue, twoStepsNegativeIntensity); + maxValue = max(maxValue, threeStepsPositiveIntensity); + maxValue = max(maxValue, threeStepsNegativeIntensity); + + gl_FragColor = vec4(vec3(maxValue), 1.0); + } +); + +NSString *const kGPUImageDilationRadiusFourFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + varying vec2 fourStepsPositiveTextureCoordinate; + varying vec2 fourStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + float twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate).r; + float twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate).r; + float threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate).r; + float threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate).r; + float fourStepsPositiveIntensity = texture2D(inputImageTexture, fourStepsPositiveTextureCoordinate).r; + float fourStepsNegativeIntensity = texture2D(inputImageTexture, fourStepsNegativeTextureCoordinate).r; + + float maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + maxValue = max(maxValue, twoStepsPositiveIntensity); + maxValue = max(maxValue, twoStepsNegativeIntensity); + maxValue = max(maxValue, threeStepsPositiveIntensity); + maxValue = max(maxValue, threeStepsNegativeIntensity); + maxValue = max(maxValue, fourStepsPositiveIntensity); + maxValue = max(maxValue, fourStepsNegativeIntensity); + + gl_FragColor = vec4(vec3(maxValue), 1.0); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithRadius:(NSUInteger)dilationRadius; +{ + NSString *fragmentShaderForThisRadius = nil; + NSString *vertexShaderForThisRadius = nil; + + switch (dilationRadius) + { + case 0: + case 1: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusOneVertexShaderString; + fragmentShaderForThisRadius = kGPUImageDilationRadiusOneFragmentShaderString; + }; break; + case 2: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusTwoVertexShaderString; + fragmentShaderForThisRadius = kGPUImageDilationRadiusTwoFragmentShaderString; + }; break; + case 3: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusThreeVertexShaderString; + fragmentShaderForThisRadius = kGPUImageDilationRadiusThreeFragmentShaderString; + }; break; + case 4: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusFourVertexShaderString; + fragmentShaderForThisRadius = kGPUImageDilationRadiusFourFragmentShaderString; + }; break; + default: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusFourVertexShaderString; + fragmentShaderForThisRadius = kGPUImageDilationRadiusFourFragmentShaderString; + }; break; + } + + if (!(self = [super initWithFirstStageVertexShaderFromString:vertexShaderForThisRadius firstStageFragmentShaderFromString:fragmentShaderForThisRadius secondStageVertexShaderFromString:vertexShaderForThisRadius secondStageFragmentShaderFromString:fragmentShaderForThisRadius])) + { + return nil; + } + + return self; +} + +- (id)init; +{ + if (!(self = [self initWithRadius:1])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalNonMaximumSuppressionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalNonMaximumSuppressionFilter.h new file mode 100644 index 00000000..fdffb9fb --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalNonMaximumSuppressionFilter.h @@ -0,0 +1,19 @@ +#import "GPUImageFilter.h" + +@interface GPUImageDirectionalNonMaximumSuppressionFilter : GPUImageFilter +{ + GLint texelWidthUniform, texelHeightUniform; + GLint upperThresholdUniform, lowerThresholdUniform; + + BOOL hasOverriddenImageSizeFactor; +} + +// The texel width and height determines how far out to sample from this texel. By default, this is the normalized width of a pixel, but this can be overridden for different effects. +@property(readwrite, nonatomic) CGFloat texelWidth; +@property(readwrite, nonatomic) CGFloat texelHeight; + +// These thresholds set cutoffs for the intensities that definitely get registered (upper threshold) and those that definitely don't (lower threshold) +@property(readwrite, nonatomic) CGFloat upperThreshold; +@property(readwrite, nonatomic) CGFloat lowerThreshold; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalNonMaximumSuppressionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalNonMaximumSuppressionFilter.m new file mode 100644 index 00000000..b442f3aa --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalNonMaximumSuppressionFilter.m @@ -0,0 +1,141 @@ +#import "GPUImageDirectionalNonMaximumSuppressionFilter.h" + +@implementation GPUImageDirectionalNonMaximumSuppressionFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageDirectionalNonmaximumSuppressionFragmentShaderString = SHADER_STRING +( + precision mediump float; + + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform highp float texelWidth; + uniform highp float texelHeight; + uniform mediump float upperThreshold; + uniform mediump float lowerThreshold; + + void main() + { + vec3 currentGradientAndDirection = texture2D(inputImageTexture, textureCoordinate).rgb; + vec2 gradientDirection = ((currentGradientAndDirection.gb * 2.0) - 1.0) * vec2(texelWidth, texelHeight); + + float firstSampledGradientMagnitude = texture2D(inputImageTexture, textureCoordinate + gradientDirection).r; + float secondSampledGradientMagnitude = texture2D(inputImageTexture, textureCoordinate - gradientDirection).r; + + float multiplier = step(firstSampledGradientMagnitude, currentGradientAndDirection.r); + multiplier = multiplier * step(secondSampledGradientMagnitude, currentGradientAndDirection.r); + + float thresholdCompliance = smoothstep(lowerThreshold, upperThreshold, currentGradientAndDirection.r); + multiplier = multiplier * thresholdCompliance; + + gl_FragColor = vec4(multiplier, multiplier, multiplier, 1.0); + } +); +#else +NSString *const kGPUImageDirectionalNonmaximumSuppressionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float texelWidth; + uniform float texelHeight; + uniform float upperThreshold; + uniform float lowerThreshold; + + void main() + { + vec3 currentGradientAndDirection = texture2D(inputImageTexture, textureCoordinate).rgb; + vec2 gradientDirection = ((currentGradientAndDirection.gb * 2.0) - 1.0) * vec2(texelWidth, texelHeight); + + float firstSampledGradientMagnitude = texture2D(inputImageTexture, textureCoordinate + gradientDirection).r; + float secondSampledGradientMagnitude = texture2D(inputImageTexture, textureCoordinate - gradientDirection).r; + + float multiplier = step(firstSampledGradientMagnitude, currentGradientAndDirection.r); + multiplier = multiplier * step(secondSampledGradientMagnitude, currentGradientAndDirection.r); + + float thresholdCompliance = smoothstep(lowerThreshold, upperThreshold, currentGradientAndDirection.r); + multiplier = multiplier * thresholdCompliance; + + gl_FragColor = vec4(multiplier, multiplier, multiplier, 1.0); + } +); +#endif + +@synthesize texelWidth = _texelWidth; +@synthesize texelHeight = _texelHeight; +@synthesize upperThreshold = _upperThreshold; +@synthesize lowerThreshold = _lowerThreshold; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageDirectionalNonmaximumSuppressionFragmentShaderString])) + { + return nil; + } + + texelWidthUniform = [filterProgram uniformIndex:@"texelWidth"]; + texelHeightUniform = [filterProgram uniformIndex:@"texelHeight"]; + upperThresholdUniform = [filterProgram uniformIndex:@"upperThreshold"]; + lowerThresholdUniform = [filterProgram uniformIndex:@"lowerThreshold"]; + + self.upperThreshold = 0.5; + self.lowerThreshold = 0.1; + + return self; +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + if (!hasOverriddenImageSizeFactor) + { + _texelWidth = 1.0 / filterFrameSize.width; + _texelHeight = 1.0 / filterFrameSize.height; + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:filterProgram]; + glUniform1f(texelWidthUniform, _texelWidth); + glUniform1f(texelHeightUniform, _texelHeight); + }); + } +} + +#pragma mark - +#pragma mark Accessors + +- (void)setTexelWidth:(CGFloat)newValue; +{ + hasOverriddenImageSizeFactor = YES; + _texelWidth = newValue; + + [self setFloat:_texelWidth forUniform:texelWidthUniform program:filterProgram]; +} + +- (void)setTexelHeight:(CGFloat)newValue; +{ + hasOverriddenImageSizeFactor = YES; + _texelHeight = newValue; + + [self setFloat:_texelHeight forUniform:texelHeightUniform program:filterProgram]; +} + +- (void)setLowerThreshold:(CGFloat)newValue; +{ + _lowerThreshold = newValue; + + [self setFloat:_lowerThreshold forUniform:lowerThresholdUniform program:filterProgram]; +} + +- (void)setUpperThreshold:(CGFloat)newValue; +{ + _upperThreshold = newValue; + + [self setFloat:_upperThreshold forUniform:upperThresholdUniform program:filterProgram]; +} + + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalSobelEdgeDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalSobelEdgeDetectionFilter.h new file mode 100644 index 00000000..cfccc897 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalSobelEdgeDetectionFilter.h @@ -0,0 +1,5 @@ +#import "GPUImage3x3TextureSamplingFilter.h" + +@interface GPUImageDirectionalSobelEdgeDetectionFilter : GPUImage3x3TextureSamplingFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalSobelEdgeDetectionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalSobelEdgeDetectionFilter.m new file mode 100644 index 00000000..a3575e3a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDirectionalSobelEdgeDetectionFilter.m @@ -0,0 +1,103 @@ +#import "GPUImageDirectionalSobelEdgeDetectionFilter.h" + +@implementation GPUImageDirectionalSobelEdgeDetectionFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageDirectionalSobelEdgeDetectionFragmentShaderString = SHADER_STRING +( + precision mediump float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + + vec2 gradientDirection; + gradientDirection.x = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; + gradientDirection.y = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; + + float gradientMagnitude = length(gradientDirection); + vec2 normalizedDirection = normalize(gradientDirection); + normalizedDirection = sign(normalizedDirection) * floor(abs(normalizedDirection) + 0.617316); // Offset by 1-sin(pi/8) to set to 0 if near axis, 1 if away + normalizedDirection = (normalizedDirection + 1.0) * 0.5; // Place -1.0 - 1.0 within 0 - 1.0 + + gl_FragColor = vec4(gradientMagnitude, normalizedDirection.x, normalizedDirection.y, 1.0); + } +); +#else +NSString *const kGPUImageDirectionalSobelEdgeDetectionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + + vec2 gradientDirection; + gradientDirection.x = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; + gradientDirection.y = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; + + float gradientMagnitude = length(gradientDirection); + vec2 normalizedDirection = normalize(gradientDirection); + normalizedDirection = sign(normalizedDirection) * floor(abs(normalizedDirection) + 0.617316); // Offset by 1-sin(pi/8) to set to 0 if near axis, 1 if away + normalizedDirection = (normalizedDirection + 1.0) * 0.5; // Place -1.0 - 1.0 within 0 - 1.0 + + gl_FragColor = vec4(gradientMagnitude, normalizedDirection.x, normalizedDirection.y, 1.0); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageDirectionalSobelEdgeDetectionFragmentShaderString])) + { + return nil; + } + + return self; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDissolveBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDissolveBlendFilter.h new file mode 100755 index 00000000..b4e5720a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDissolveBlendFilter.h @@ -0,0 +1,11 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageDissolveBlendFilter : GPUImageTwoInputFilter +{ + GLint mixUniform; +} + +// Mix ranges from 0.0 (only image 1) to 1.0 (only image 2), with 0.5 (half of either) as the normal level +@property(readwrite, nonatomic) CGFloat mix; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDissolveBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageDissolveBlendFilter.m new file mode 100755 index 00000000..b4a5609f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDissolveBlendFilter.m @@ -0,0 +1,72 @@ +#import "GPUImageDissolveBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageDissolveBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + uniform lowp float mixturePercent; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = mix(textureColor, textureColor2, mixturePercent); + } +); +#else +NSString *const kGPUImageDissolveBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + uniform float mixturePercent; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = mix(textureColor, textureColor2, mixturePercent); + } +); +#endif + +@implementation GPUImageDissolveBlendFilter + +@synthesize mix = _mix; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageDissolveBlendFragmentShaderString])) + { + return nil; + } + + mixUniform = [filterProgram uniformIndex:@"mixturePercent"]; + self.mix = 0.5; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setMix:(CGFloat)newValue; +{ + _mix = newValue; + + [self setFloat:_mix forUniform:mixUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDivideBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageDivideBlendFilter.h new file mode 100644 index 00000000..ad798e29 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDivideBlendFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageDivideBlendFilter : GPUImageTwoInputFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageDivideBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageDivideBlendFilter.m new file mode 100644 index 00000000..63ee071e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageDivideBlendFilter.m @@ -0,0 +1,96 @@ +#import "GPUImageDivideBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageDivideBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + mediump vec4 base = texture2D(inputImageTexture, textureCoordinate); + mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + mediump float ra; + if (overlay.a == 0.0 || ((base.r / overlay.r) > (base.a / overlay.a))) + ra = overlay.a * base.a + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + else + ra = (base.r * overlay.a * overlay.a) / overlay.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + + + mediump float ga; + if (overlay.a == 0.0 || ((base.g / overlay.g) > (base.a / overlay.a))) + ga = overlay.a * base.a + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + else + ga = (base.g * overlay.a * overlay.a) / overlay.g + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + + + mediump float ba; + if (overlay.a == 0.0 || ((base.b / overlay.b) > (base.a / overlay.a))) + ba = overlay.a * base.a + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + else + ba = (base.b * overlay.a * overlay.a) / overlay.b + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + + mediump float a = overlay.a + base.a - overlay.a * base.a; + + gl_FragColor = vec4(ra, ga, ba, a); + } +); +#else +NSString *const kGPUImageDivideBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 base = texture2D(inputImageTexture, textureCoordinate); + vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + float ra; + if (overlay.a == 0.0 || ((base.r / overlay.r) > (base.a / overlay.a))) + ra = overlay.a * base.a + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + else + ra = (base.r * overlay.a * overlay.a) / overlay.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + + + float ga; + if (overlay.a == 0.0 || ((base.g / overlay.g) > (base.a / overlay.a))) + ga = overlay.a * base.a + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + else + ga = (base.g * overlay.a * overlay.a) / overlay.g + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + + + float ba; + if (overlay.a == 0.0 || ((base.b / overlay.b) > (base.a / overlay.a))) + ba = overlay.a * base.a + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + else + ba = (base.b * overlay.a * overlay.a) / overlay.b + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + + float a = overlay.a + base.a - overlay.a * base.a; + + gl_FragColor = vec4(ra, ga, ba, a); + } + ); +#endif + +@implementation GPUImageDivideBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageDivideBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageEmbossFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageEmbossFilter.h new file mode 100755 index 00000000..dbd21e82 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageEmbossFilter.h @@ -0,0 +1,8 @@ +#import "GPUImage3x3ConvolutionFilter.h" + +@interface GPUImageEmbossFilter : GPUImage3x3ConvolutionFilter + +// The strength of the embossing, from 0.0 to 4.0, with 1.0 as the normal level +@property(readwrite, nonatomic) CGFloat intensity; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageEmbossFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageEmbossFilter.m new file mode 100755 index 00000000..6ba48cd4 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageEmbossFilter.m @@ -0,0 +1,49 @@ +#import "GPUImageEmbossFilter.h" + +@implementation GPUImageEmbossFilter + +@synthesize intensity = _intensity; + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + self.intensity = 1.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setIntensity:(CGFloat)newValue; +{ +// [(GPUImage3x3ConvolutionFilter *)filter setConvolutionMatrix:(GPUMatrix3x3){ +// {-2.0f, -1.0f, 0.0f}, +// {-1.0f, 1.0f, 1.0f}, +// { 0.0f, 1.0f, 2.0f} +// }]; + + _intensity = newValue; + + GPUMatrix3x3 newConvolutionMatrix; + newConvolutionMatrix.one.one = _intensity * (-2.0); + newConvolutionMatrix.one.two = -_intensity; + newConvolutionMatrix.one.three = 0.0f; + + newConvolutionMatrix.two.one = -_intensity; + newConvolutionMatrix.two.two = 1.0; + newConvolutionMatrix.two.three = _intensity; + + newConvolutionMatrix.three.one = 0.0f; + newConvolutionMatrix.three.two = _intensity; + newConvolutionMatrix.three.three = _intensity * 2.0; + + self.convolutionKernel = newConvolutionMatrix; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageErosionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageErosionFilter.h new file mode 100644 index 00000000..b311a265 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageErosionFilter.h @@ -0,0 +1,11 @@ +#import "GPUImageTwoPassTextureSamplingFilter.h" + +// For each pixel, this sets it to the minimum value of the red channel in a rectangular neighborhood extending out dilationRadius pixels from the center. +// This extends out dark features, and is most commonly used with black-and-white thresholded images. + +@interface GPUImageErosionFilter : GPUImageTwoPassTextureSamplingFilter + +// Acceptable values for erosionRadius, which sets the distance in pixels to sample out from the center, are 1, 2, 3, and 4. +- (id)initWithRadius:(NSUInteger)erosionRadius; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageErosionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageErosionFilter.m new file mode 100644 index 00000000..05f4f28d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageErosionFilter.m @@ -0,0 +1,312 @@ +#import "GPUImageErosionFilter.h" +#import "GPUImageDilationFilter.h" + +@implementation GPUImageErosionFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageErosionRadiusOneFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + + lowp float minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + + gl_FragColor = vec4(vec3(minValue), 1.0); + } +); + +NSString *const kGPUImageErosionRadiusTwoFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + float twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate).r; + float twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate).r; + + lowp float minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + minValue = min(minValue, twoStepsPositiveIntensity); + minValue = min(minValue, twoStepsNegativeIntensity); + + gl_FragColor = vec4(vec3(minValue), 1.0); + } +); + +NSString *const kGPUImageErosionRadiusThreeFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + float twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate).r; + float twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate).r; + float threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate).r; + float threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate).r; + + lowp float minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + minValue = min(minValue, twoStepsPositiveIntensity); + minValue = min(minValue, twoStepsNegativeIntensity); + minValue = min(minValue, threeStepsPositiveIntensity); + minValue = min(minValue, threeStepsNegativeIntensity); + + gl_FragColor = vec4(vec3(minValue), 1.0); + } +); + +NSString *const kGPUImageErosionRadiusFourFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + varying vec2 fourStepsPositiveTextureCoordinate; + varying vec2 fourStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + float twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate).r; + float twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate).r; + float threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate).r; + float threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate).r; + float fourStepsPositiveIntensity = texture2D(inputImageTexture, fourStepsPositiveTextureCoordinate).r; + float fourStepsNegativeIntensity = texture2D(inputImageTexture, fourStepsNegativeTextureCoordinate).r; + + lowp float minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + minValue = min(minValue, twoStepsPositiveIntensity); + minValue = min(minValue, twoStepsNegativeIntensity); + minValue = min(minValue, threeStepsPositiveIntensity); + minValue = min(minValue, threeStepsNegativeIntensity); + minValue = min(minValue, fourStepsPositiveIntensity); + minValue = min(minValue, fourStepsNegativeIntensity); + + gl_FragColor = vec4(vec3(minValue), 1.0); + } +); +#else +NSString *const kGPUImageErosionRadiusOneFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + + float minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + + gl_FragColor = vec4(vec3(minValue), 1.0); + } +); + +NSString *const kGPUImageErosionRadiusTwoFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + float twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate).r; + float twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate).r; + + float minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + minValue = min(minValue, twoStepsPositiveIntensity); + minValue = min(minValue, twoStepsNegativeIntensity); + + gl_FragColor = vec4(vec3(minValue), 1.0); + } +); + +NSString *const kGPUImageErosionRadiusThreeFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + float twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate).r; + float twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate).r; + float threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate).r; + float threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate).r; + + float minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + minValue = min(minValue, twoStepsPositiveIntensity); + minValue = min(minValue, twoStepsNegativeIntensity); + minValue = min(minValue, threeStepsPositiveIntensity); + minValue = min(minValue, threeStepsNegativeIntensity); + + gl_FragColor = vec4(vec3(minValue), 1.0); + } +); + +NSString *const kGPUImageErosionRadiusFourFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + varying vec2 fourStepsPositiveTextureCoordinate; + varying vec2 fourStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate).r; + float oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate).r; + float oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate).r; + float twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate).r; + float twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate).r; + float threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate).r; + float threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate).r; + float fourStepsPositiveIntensity = texture2D(inputImageTexture, fourStepsPositiveTextureCoordinate).r; + float fourStepsNegativeIntensity = texture2D(inputImageTexture, fourStepsNegativeTextureCoordinate).r; + + float minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + minValue = min(minValue, twoStepsPositiveIntensity); + minValue = min(minValue, twoStepsNegativeIntensity); + minValue = min(minValue, threeStepsPositiveIntensity); + minValue = min(minValue, threeStepsNegativeIntensity); + minValue = min(minValue, fourStepsPositiveIntensity); + minValue = min(minValue, fourStepsNegativeIntensity); + + gl_FragColor = vec4(vec3(minValue), 1.0); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithRadius:(NSUInteger)dilationRadius; +{ + NSString *fragmentShaderForThisRadius = nil; + NSString *vertexShaderForThisRadius = nil; + + switch (dilationRadius) + { + case 0: + case 1: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusOneVertexShaderString; + fragmentShaderForThisRadius = kGPUImageErosionRadiusOneFragmentShaderString; + }; break; + case 2: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusTwoVertexShaderString; + fragmentShaderForThisRadius = kGPUImageErosionRadiusTwoFragmentShaderString; + }; break; + case 3: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusThreeVertexShaderString; + fragmentShaderForThisRadius = kGPUImageErosionRadiusThreeFragmentShaderString; + }; break; + case 4: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusFourVertexShaderString; + fragmentShaderForThisRadius = kGPUImageErosionRadiusFourFragmentShaderString; + }; break; + default: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusFourVertexShaderString; + fragmentShaderForThisRadius = kGPUImageErosionRadiusFourFragmentShaderString; + }; break; + } + + if (!(self = [super initWithFirstStageVertexShaderFromString:vertexShaderForThisRadius firstStageFragmentShaderFromString:fragmentShaderForThisRadius secondStageVertexShaderFromString:vertexShaderForThisRadius secondStageFragmentShaderFromString:fragmentShaderForThisRadius])) + { + return nil; + } + + return self; +} + +- (id)init; +{ + if (!(self = [self initWithRadius:1])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageExclusionBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageExclusionBlendFilter.h new file mode 100755 index 00000000..f7c83f57 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageExclusionBlendFilter.h @@ -0,0 +1,7 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageExclusionBlendFilter : GPUImageTwoInputFilter +{ +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageExclusionBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageExclusionBlendFilter.m new file mode 100755 index 00000000..c364159f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageExclusionBlendFilter.m @@ -0,0 +1,56 @@ +#import "GPUImageExclusionBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageExclusionBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + mediump vec4 base = texture2D(inputImageTexture, textureCoordinate); + mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + // Dca = (Sca.Da + Dca.Sa - 2.Sca.Dca) + Sca.(1 - Da) + Dca.(1 - Sa) + + gl_FragColor = vec4((overlay.rgb * base.a + base.rgb * overlay.a - 2.0 * overlay.rgb * base.rgb) + overlay.rgb * (1.0 - base.a) + base.rgb * (1.0 - overlay.a), base.a); + } +); +#else +NSString *const kGPUImageExclusionBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 base = texture2D(inputImageTexture, textureCoordinate); + vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + // Dca = (Sca.Da + Dca.Sa - 2.Sca.Dca) + Sca.(1 - Da) + Dca.(1 - Sa) + + gl_FragColor = vec4((overlay.rgb * base.a + base.rgb * overlay.a - 2.0 * overlay.rgb * base.rgb) + overlay.rgb * (1.0 - base.a) + base.rgb * (1.0 - overlay.a), base.a); + } + ); +#endif + +@implementation GPUImageExclusionBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageExclusionBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageExposureFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageExposureFilter.h new file mode 100755 index 00000000..886a052f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageExposureFilter.h @@ -0,0 +1,11 @@ +#import "GPUImageFilter.h" + +@interface GPUImageExposureFilter : GPUImageFilter +{ + GLint exposureUniform; +} + +// Exposure ranges from -10.0 to 10.0, with 0.0 as the normal level +@property(readwrite, nonatomic) CGFloat exposure; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageExposureFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageExposureFilter.m new file mode 100755 index 00000000..d5ee2c9f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageExposureFilter.m @@ -0,0 +1,66 @@ +#import "GPUImageExposureFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageExposureFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform highp float exposure; + + void main() + { + highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4(textureColor.rgb * pow(2.0, exposure), textureColor.w); + } +); +#else +NSString *const kGPUImageExposureFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float exposure; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4(textureColor.rgb * pow(2.0, exposure), textureColor.w); + } +); +#endif + +@implementation GPUImageExposureFilter + +@synthesize exposure = _exposure; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageExposureFragmentShaderString])) + { + return nil; + } + + exposureUniform = [filterProgram uniformIndex:@"exposure"]; + self.exposure = 0.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setExposure:(CGFloat)newValue; +{ + _exposure = newValue; + + [self setFloat:_exposure forUniform:exposureUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFASTCornerDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageFASTCornerDetectionFilter.h new file mode 100644 index 00000000..86e7cf42 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFASTCornerDetectionFilter.h @@ -0,0 +1,33 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImageGrayscaleFilter; +@class GPUImage3x3TextureSamplingFilter; +@class GPUImageNonMaximumSuppressionFilter; + +/* + An implementation of the Features from Accelerated Segment Test (FAST) feature detector as described in the following publications: + + E. Rosten and T. Drummond. Fusing points and lines for high performance tracking. IEEE International Conference on Computer Vision, 2005. + E. Rosten and T. Drummond. Machine learning for high-speed corner detection. European Conference on Computer Vision, 2006. + + For more about the FAST feature detector, see the resources here: + http://www.edwardrosten.com/work/fast.html + */ + +typedef enum { kGPUImageFAST12Contiguous, kGPUImageFAST12ContiguousNonMaximumSuppressed} GPUImageFASTDetectorType; + +@interface GPUImageFASTCornerDetectionFilter : GPUImageFilterGroup +{ + GPUImageGrayscaleFilter *luminanceReductionFilter; + GPUImage3x3TextureSamplingFilter *featureDetectionFilter; + GPUImageNonMaximumSuppressionFilter *nonMaximumSuppressionFilter; +// Generate a lookup texture based on the bit patterns + +// Step 1: convert to monochrome if necessary +// Step 2: do a lookup at each pixel based on the Bresenham circle, encode comparison in two color components +// Step 3: do non-maximum suppression of close corner points +} + +- (id)initWithFASTDetectorVariant:(GPUImageFASTDetectorType)detectorType; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFASTCornerDetectionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageFASTCornerDetectionFilter.m new file mode 100644 index 00000000..b04a24aa --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFASTCornerDetectionFilter.m @@ -0,0 +1,89 @@ +#import "GPUImageFASTCornerDetectionFilter.h" + +#import "GPUImageGrayscaleFilter.h" +#import "GPUImage3x3TextureSamplingFilter.h" +#import "GPUImageNonMaximumSuppressionFilter.h" + +// 14 total texture coordinates from vertex shader for non-dependent reads +// 3 texture coordinates for dependent reads, then + +NSString *const kGPUImageFASTDetectorFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform sampler2D lookupTable; + + void main() + { + lowp float centerIntensity = texture2D(inputImageTexture, textureCoordinate).r; + lowp float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + lowp float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + lowp float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + lowp float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + lowp float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + lowp float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + lowp float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + lowp float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + + lowp float byteTally = 1.0 / 255.0 * step(centerIntensity, topRightIntensity); + byteTally += 2.0 / 255.0 * step(centerIntensity, topIntensity); + byteTally += 4.0 / 255.0 * step(centerIntensity, topLeftIntensity); + byteTally += 8.0 / 255.0 * step(centerIntensity, leftIntensity); + byteTally += 16.0 / 255.0 * step(centerIntensity, bottomLeftIntensity); + byteTally += 32.0 / 255.0 * step(centerIntensity, bottomIntensity); + byteTally += 64.0 / 255.0 * step(centerIntensity, bottomRightIntensity); + byteTally += 128.0 / 255.0 * step(centerIntensity, rightIntensity); + + // TODO: Replace the above with a dot product and two vec4s + // TODO: Apply step to a matrix, rather than individually + + gl_FragColor = vec4(byteTally, byteTally, byteTally, 1.0); + } + ); + + +@implementation GPUImageFASTCornerDetectionFilter + +- (id)init; +{ + if (!(self = [self initWithFASTDetectorVariant:kGPUImageFAST12ContiguousNonMaximumSuppressed])) + { + return nil; + } + + return self; +} + +- (id)initWithFASTDetectorVariant:(GPUImageFASTDetectorType)detectorType; +{ + if (!(self = [super init])) + { + return nil; + } + +// [derivativeFilter addTarget:blurFilter]; +// [blurFilter addTarget:harrisCornerDetectionFilter]; +// [harrisCornerDetectionFilter addTarget:nonMaximumSuppressionFilter]; + // [simpleThresholdFilter addTarget:colorPackingFilter]; + +// self.initialFilters = [NSArray arrayWithObjects:derivativeFilter, nil]; + // self.terminalFilter = colorPackingFilter; +// self.terminalFilter = nonMaximumSuppressionFilter; + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFalseColorFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageFalseColorFilter.h new file mode 100644 index 00000000..cb0b82f7 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFalseColorFilter.h @@ -0,0 +1,15 @@ +#import "GPUImageFilter.h" + +@interface GPUImageFalseColorFilter : GPUImageFilter +{ + GLint firstColorUniform, secondColorUniform; +} + +// The first and second colors specify what colors replace the dark and light areas of the image, respectively. The defaults are (0.0, 0.0, 0.5) amd (1.0, 0.0, 0.0). +@property(readwrite, nonatomic) GPUVector4 firstColor; +@property(readwrite, nonatomic) GPUVector4 secondColor; + +- (void)setFirstColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; +- (void)setSecondColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFalseColorFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageFalseColorFilter.m new file mode 100644 index 00000000..f514dbab --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFalseColorFilter.m @@ -0,0 +1,101 @@ +#import "GPUImageFalseColorFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUFalseColorFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float intensity; + uniform vec3 firstColor; + uniform vec3 secondColor; + + const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, luminanceWeighting); + + gl_FragColor = vec4( mix(firstColor.rgb, secondColor.rgb, luminance), textureColor.a); + } +); +#else +NSString *const kGPUFalseColorFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float intensity; + uniform vec3 firstColor; + uniform vec3 secondColor; + + const vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, luminanceWeighting); + + gl_FragColor = vec4( mix(firstColor.rgb, secondColor.rgb, luminance), textureColor.a); + } +); +#endif + + +@implementation GPUImageFalseColorFilter + +@synthesize secondColor = _secondColor; +@synthesize firstColor = _firstColor; + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUFalseColorFragmentShaderString])) + { + return nil; + } + + firstColorUniform = [filterProgram uniformIndex:@"firstColor"]; + secondColorUniform = [filterProgram uniformIndex:@"secondColor"]; + + self.firstColor = (GPUVector4){0.0f, 0.0f, 0.5f, 1.0f}; + self.secondColor = (GPUVector4){1.0f, 0.0f, 0.0f, 1.0f}; + + return self; +} + + +#pragma mark - +#pragma mark Accessors + +- (void)setFirstColor:(GPUVector4)newValue; +{ + _firstColor = newValue; + + [self setFirstColorRed:_firstColor.one green:_firstColor.two blue:_firstColor.three]; +} + +- (void)setSecondColor:(GPUVector4)newValue; +{ + _secondColor = newValue; + + [self setSecondColorRed:_secondColor.one green:_secondColor.two blue:_secondColor.three]; +} + +- (void)setFirstColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; +{ + GPUVector3 firstColor = {redComponent, greenComponent, blueComponent}; + + [self setVec3:firstColor forUniform:firstColorUniform program:filterProgram]; +} + +- (void)setSecondColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; +{ + GPUVector3 secondColor = {redComponent, greenComponent, blueComponent}; + + [self setVec3:secondColor forUniform:secondColorUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageFilter.h new file mode 100755 index 00000000..0171aa80 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFilter.h @@ -0,0 +1,134 @@ +#import "GPUImageOutput.h" + +#define STRINGIZE(x) #x +#define STRINGIZE2(x) STRINGIZE(x) +#define SHADER_STRING(text) @ STRINGIZE2(text) + +#define GPUImageHashIdentifier # +#define GPUImageWrappedLabel(x) x +#define GPUImageEscapedHashIdentifier(a) GPUImageWrappedLabel(GPUImageHashIdentifier)a + +extern NSString *const kGPUImageVertexShaderString; +extern NSString *const kGPUImagePassthroughFragmentShaderString; + +struct GPUVector4 { + GLfloat one; + GLfloat two; + GLfloat three; + GLfloat four; +}; +typedef struct GPUVector4 GPUVector4; + +struct GPUVector3 { + GLfloat one; + GLfloat two; + GLfloat three; +}; +typedef struct GPUVector3 GPUVector3; + +struct GPUMatrix4x4 { + GPUVector4 one; + GPUVector4 two; + GPUVector4 three; + GPUVector4 four; +}; +typedef struct GPUMatrix4x4 GPUMatrix4x4; + +struct GPUMatrix3x3 { + GPUVector3 one; + GPUVector3 two; + GPUVector3 three; +}; +typedef struct GPUMatrix3x3 GPUMatrix3x3; + +/** GPUImage's base filter class + + Filters and other subsequent elements in the chain conform to the GPUImageInput protocol, which lets them take in the supplied or processed texture from the previous link in the chain and do something with it. Objects one step further down the chain are considered targets, and processing can be branched by adding multiple targets to a single output or filter. + */ +@interface GPUImageFilter : GPUImageOutput +{ + GPUImageFramebuffer *firstInputFramebuffer; + + GLProgram *filterProgram; + GLint filterPositionAttribute, filterTextureCoordinateAttribute; + GLint filterInputTextureUniform; + GLfloat backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha; + + BOOL isEndProcessing; + + CGSize currentFilterSize; + GPUImageRotationMode inputRotation; + + BOOL currentlyReceivingMonochromeInput; + + NSMutableDictionary *uniformStateRestorationBlocks; + dispatch_semaphore_t imageCaptureSemaphore; +} + +@property(readonly) CVPixelBufferRef renderTarget; +@property(readwrite, nonatomic) BOOL preventRendering; +@property(readwrite, nonatomic) BOOL currentlyReceivingMonochromeInput; + +/// @name Initialization and teardown + +/** + Initialize with vertex and fragment shaders + + You make take advantage of the SHADER_STRING macro to write your shaders in-line. + @param vertexShaderString Source code of the vertex shader to use + @param fragmentShaderString Source code of the fragment shader to use + */ +- (id)initWithVertexShaderFromString:(NSString *)vertexShaderString fragmentShaderFromString:(NSString *)fragmentShaderString; + +/** + Initialize with a fragment shader + + You may take advantage of the SHADER_STRING macro to write your shader in-line. + @param fragmentShaderString Source code of fragment shader to use + */ +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +/** + Initialize with a fragment shader + @param fragmentShaderFilename Filename of fragment shader to load + */ +- (id)initWithFragmentShaderFromFile:(NSString *)fragmentShaderFilename; +- (void)initializeAttributes; +- (void)setupFilterForSize:(CGSize)filterFrameSize; +- (CGSize)rotatedSize:(CGSize)sizeToRotate forIndex:(NSInteger)textureIndex; +- (CGPoint)rotatedPoint:(CGPoint)pointToRotate forRotation:(GPUImageRotationMode)rotation; + +/// @name Managing the display FBOs +/** Size of the frame buffer object + */ +- (CGSize)sizeOfFBO; + +/// @name Rendering ++ (const GLfloat *)textureCoordinatesForRotation:(GPUImageRotationMode)rotationMode; +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +- (void)informTargetsAboutNewFrameAtTime:(CMTime)frameTime; +- (CGSize)outputFrameSize; + +/// @name Input parameters +- (void)setBackgroundColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; +- (void)setInteger:(GLint)newInteger forUniformName:(NSString *)uniformName; +- (void)setFloat:(GLfloat)newFloat forUniformName:(NSString *)uniformName; +- (void)setSize:(CGSize)newSize forUniformName:(NSString *)uniformName; +- (void)setPoint:(CGPoint)newPoint forUniformName:(NSString *)uniformName; +- (void)setFloatVec3:(GPUVector3)newVec3 forUniformName:(NSString *)uniformName; +- (void)setFloatVec4:(GPUVector4)newVec4 forUniform:(NSString *)uniformName; +- (void)setFloatArray:(GLfloat *)array length:(GLsizei)count forUniform:(NSString*)uniformName; + +- (void)setMatrix3f:(GPUMatrix3x3)matrix forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +- (void)setMatrix4f:(GPUMatrix4x4)matrix forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +- (void)setFloat:(GLfloat)floatValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +- (void)setPoint:(CGPoint)pointValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +- (void)setSize:(CGSize)sizeValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +- (void)setVec3:(GPUVector3)vectorValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +- (void)setVec4:(GPUVector4)vectorValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +- (void)setFloatArray:(GLfloat *)arrayValue length:(GLsizei)arrayLength forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +- (void)setInteger:(GLint)intValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; + +- (void)setAndExecuteUniformStateCallbackAtIndex:(GLint)uniform forProgram:(GLProgram *)shaderProgram toBlock:(dispatch_block_t)uniformStateBlock; +- (void)setUniformsForProgramAtIndex:(NSUInteger)programIndex; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageFilter.m new file mode 100755 index 00000000..406d707a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFilter.m @@ -0,0 +1,753 @@ +#import "GPUImageFilter.h" +#import "GPUImagePicture.h" +#import + +// Hardcode the vertex shader for standard filters, but this can be overridden +NSString *const kGPUImageVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + + varying vec2 textureCoordinate; + + void main() + { + gl_Position = position; + textureCoordinate = inputTextureCoordinate.xy; + } + ); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + +NSString *const kGPUImagePassthroughFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate); + } +); + +#else + +NSString *const kGPUImagePassthroughFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate); + } +); +#endif + + +@implementation GPUImageFilter + +@synthesize preventRendering = _preventRendering; +@synthesize currentlyReceivingMonochromeInput; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithVertexShaderFromString:(NSString *)vertexShaderString fragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [super init])) + { + return nil; + } + + uniformStateRestorationBlocks = [NSMutableDictionary dictionaryWithCapacity:10]; + _preventRendering = NO; + currentlyReceivingMonochromeInput = NO; + inputRotation = kGPUImageNoRotation; + backgroundColorRed = 0.0; + backgroundColorGreen = 0.0; + backgroundColorBlue = 0.0; + backgroundColorAlpha = 0.0; + imageCaptureSemaphore = dispatch_semaphore_create(0); + dispatch_semaphore_signal(imageCaptureSemaphore); + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + + filterProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:vertexShaderString fragmentShaderString:fragmentShaderString]; + + if (!filterProgram.initialized) + { + [self initializeAttributes]; + + if (![filterProgram link]) + { + NSString *progLog = [filterProgram programLog]; + NSLog(@"Program link log: %@", progLog); + NSString *fragLog = [filterProgram fragmentShaderLog]; + NSLog(@"Fragment shader compile log: %@", fragLog); + NSString *vertLog = [filterProgram vertexShaderLog]; + NSLog(@"Vertex shader compile log: %@", vertLog); + filterProgram = nil; + NSAssert(NO, @"Filter shader link failed"); + } + } + + filterPositionAttribute = [filterProgram attributeIndex:@"position"]; + filterTextureCoordinateAttribute = [filterProgram attributeIndex:@"inputTextureCoordinate"]; + filterInputTextureUniform = [filterProgram uniformIndex:@"inputImageTexture"]; // This does assume a name of "inputImageTexture" for the fragment shader + + [GPUImageContext setActiveShaderProgram:filterProgram]; + + glEnableVertexAttribArray(filterPositionAttribute); + glEnableVertexAttribArray(filterTextureCoordinateAttribute); + }); + + return self; +} + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [self initWithVertexShaderFromString:kGPUImageVertexShaderString fragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + return self; +} + +- (id)initWithFragmentShaderFromFile:(NSString *)fragmentShaderFilename; +{ + NSString *fragmentShaderPathname = [[NSBundle mainBundle] pathForResource:fragmentShaderFilename ofType:@"fsh"]; + NSString *fragmentShaderString = [NSString stringWithContentsOfFile:fragmentShaderPathname encoding:NSUTF8StringEncoding error:nil]; + + if (!(self = [self initWithFragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + return self; +} + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImagePassthroughFragmentShaderString])) + { + return nil; + } + + return self; +} + +- (void)initializeAttributes; +{ + [filterProgram addAttribute:@"position"]; + [filterProgram addAttribute:@"inputTextureCoordinate"]; + + // Override this, calling back to this super method, in order to add new attributes to your vertex shader +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + // This is where you can override to provide some custom setup, if your filter has a size-dependent element +} + +- (void)dealloc +{ +#if !OS_OBJECT_USE_OBJC + if (imageCaptureSemaphore != NULL) + { + dispatch_release(imageCaptureSemaphore); + } +#endif + +} + +#pragma mark - +#pragma mark Still image processing + +- (void)useNextFrameForImageCapture; +{ + usingNextFrameForImageCapture = YES; + + // Set the semaphore high, if it isn't already + if (dispatch_semaphore_wait(imageCaptureSemaphore, DISPATCH_TIME_NOW) != 0) + { + return; + } +} + +- (CGImageRef)newCGImageFromCurrentlyProcessedOutput +{ + // Give it three seconds to process, then abort if they forgot to set up the image capture properly + double timeoutForImageCapture = 3.0; + dispatch_time_t convertedTimeout = dispatch_time(DISPATCH_TIME_NOW, timeoutForImageCapture * NSEC_PER_SEC); + + if (dispatch_semaphore_wait(imageCaptureSemaphore, convertedTimeout) != 0) + { + return NULL; + } + + GPUImageFramebuffer* framebuffer = [self framebufferForOutput]; + + usingNextFrameForImageCapture = NO; + dispatch_semaphore_signal(imageCaptureSemaphore); + + CGImageRef image = [framebuffer newCGImageFromFramebufferContents]; + return image; +} + +#pragma mark - +#pragma mark Managing the display FBOs + +- (CGSize)sizeOfFBO; +{ + CGSize outputSize = [self maximumOutputSize]; + if ( (CGSizeEqualToSize(outputSize, CGSizeZero)) || (inputTextureSize.width < outputSize.width) ) + { + return inputTextureSize; + } + else + { + return outputSize; + } +} + +#pragma mark - +#pragma mark Rendering + ++ (const GLfloat *)textureCoordinatesForRotation:(GPUImageRotationMode)rotationMode; +{ + static const GLfloat noRotationTextureCoordinates[] = { + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + }; + + static const GLfloat rotateLeftTextureCoordinates[] = { + 1.0f, 0.0f, + 1.0f, 1.0f, + 0.0f, 0.0f, + 0.0f, 1.0f, + }; + + static const GLfloat rotateRightTextureCoordinates[] = { + 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 1.0f, + 1.0f, 0.0f, + }; + + static const GLfloat verticalFlipTextureCoordinates[] = { + 0.0f, 1.0f, + 1.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 0.0f, + }; + + static const GLfloat horizontalFlipTextureCoordinates[] = { + 1.0f, 0.0f, + 0.0f, 0.0f, + 1.0f, 1.0f, + 0.0f, 1.0f, + }; + + static const GLfloat rotateRightVerticalFlipTextureCoordinates[] = { + 0.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 0.0f, + 1.0f, 1.0f, + }; + + static const GLfloat rotateRightHorizontalFlipTextureCoordinates[] = { + 1.0f, 1.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 0.0f, 0.0f, + }; + + static const GLfloat rotate180TextureCoordinates[] = { + 1.0f, 1.0f, + 0.0f, 1.0f, + 1.0f, 0.0f, + 0.0f, 0.0f, + }; + + switch(rotationMode) + { + case kGPUImageNoRotation: return noRotationTextureCoordinates; + case kGPUImageRotateLeft: return rotateLeftTextureCoordinates; + case kGPUImageRotateRight: return rotateRightTextureCoordinates; + case kGPUImageFlipVertical: return verticalFlipTextureCoordinates; + case kGPUImageFlipHorizonal: return horizontalFlipTextureCoordinates; + case kGPUImageRotateRightFlipVertical: return rotateRightVerticalFlipTextureCoordinates; + case kGPUImageRotateRightFlipHorizontal: return rotateRightHorizontalFlipTextureCoordinates; + case kGPUImageRotate180: return rotate180TextureCoordinates; + } +} + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + if (self.preventRendering) + { + [firstInputFramebuffer unlock]; + return; + } + + [GPUImageContext setActiveShaderProgram:filterProgram]; + + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + if (usingNextFrameForImageCapture) + { + [outputFramebuffer lock]; + } + + [self setUniformsForProgramAtIndex:0]; + + glClearColor(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha); + glClear(GL_COLOR_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, [firstInputFramebuffer texture]); + + glUniform1i(filterInputTextureUniform, 2); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + [firstInputFramebuffer unlock]; + + if (usingNextFrameForImageCapture) + { + dispatch_semaphore_signal(imageCaptureSemaphore); + } +} + +- (void)informTargetsAboutNewFrameAtTime:(CMTime)frameTime; +{ + if (self.frameProcessingCompletionBlock != NULL) + { + self.frameProcessingCompletionBlock(self, frameTime); + } + + // Get all targets the framebuffer so they can grab a lock on it + for (id currentTarget in targets) + { + if (currentTarget != self.targetToIgnoreForUpdates) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger textureIndex = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + [self setInputFramebufferForTarget:currentTarget atIndex:textureIndex]; + [currentTarget setInputSize:[self outputFrameSize] atIndex:textureIndex]; + } + } + + // Release our hold so it can return to the cache immediately upon processing + [[self framebufferForOutput] unlock]; + + if (usingNextFrameForImageCapture) + { +// usingNextFrameForImageCapture = NO; + } + else + { + [self removeOutputFramebuffer]; + } + + // Trigger processing last, so that our unlock comes first in serial execution, avoiding the need for a callback + for (id currentTarget in targets) + { + if (currentTarget != self.targetToIgnoreForUpdates) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger textureIndex = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + [currentTarget newFrameReadyAtTime:frameTime atIndex:textureIndex]; + } + } +} + +- (CGSize)outputFrameSize; +{ + return inputTextureSize; +} + +#pragma mark - +#pragma mark Input parameters + +- (void)setBackgroundColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; +{ + backgroundColorRed = redComponent; + backgroundColorGreen = greenComponent; + backgroundColorBlue = blueComponent; + backgroundColorAlpha = alphaComponent; +} + +- (void)setInteger:(GLint)newInteger forUniformName:(NSString *)uniformName; +{ + GLint uniformIndex = [filterProgram uniformIndex:uniformName]; + [self setInteger:newInteger forUniform:uniformIndex program:filterProgram]; +} + +- (void)setFloat:(GLfloat)newFloat forUniformName:(NSString *)uniformName; +{ + GLint uniformIndex = [filterProgram uniformIndex:uniformName]; + [self setFloat:newFloat forUniform:uniformIndex program:filterProgram]; +} + +- (void)setSize:(CGSize)newSize forUniformName:(NSString *)uniformName; +{ + GLint uniformIndex = [filterProgram uniformIndex:uniformName]; + [self setSize:newSize forUniform:uniformIndex program:filterProgram]; +} + +- (void)setPoint:(CGPoint)newPoint forUniformName:(NSString *)uniformName; +{ + GLint uniformIndex = [filterProgram uniformIndex:uniformName]; + [self setPoint:newPoint forUniform:uniformIndex program:filterProgram]; +} + +- (void)setFloatVec3:(GPUVector3)newVec3 forUniformName:(NSString *)uniformName; +{ + GLint uniformIndex = [filterProgram uniformIndex:uniformName]; + [self setVec3:newVec3 forUniform:uniformIndex program:filterProgram]; +} + +- (void)setFloatVec4:(GPUVector4)newVec4 forUniform:(NSString *)uniformName; +{ + GLint uniformIndex = [filterProgram uniformIndex:uniformName]; + [self setVec4:newVec4 forUniform:uniformIndex program:filterProgram]; +} + +- (void)setFloatArray:(GLfloat *)array length:(GLsizei)count forUniform:(NSString*)uniformName +{ + GLint uniformIndex = [filterProgram uniformIndex:uniformName]; + + [self setFloatArray:array length:count forUniform:uniformIndex program:filterProgram]; +} + +- (void)setMatrix3f:(GPUMatrix3x3)matrix forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +{ + runAsynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:shaderProgram]; + [self setAndExecuteUniformStateCallbackAtIndex:uniform forProgram:shaderProgram toBlock:^{ + glUniformMatrix3fv(uniform, 1, GL_FALSE, (GLfloat *)&matrix); + }]; + }); +} + +- (void)setMatrix4f:(GPUMatrix4x4)matrix forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +{ + runAsynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:shaderProgram]; + [self setAndExecuteUniformStateCallbackAtIndex:uniform forProgram:shaderProgram toBlock:^{ + glUniformMatrix4fv(uniform, 1, GL_FALSE, (GLfloat *)&matrix); + }]; + }); +} + +- (void)setFloat:(GLfloat)floatValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +{ + runAsynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:shaderProgram]; + [self setAndExecuteUniformStateCallbackAtIndex:uniform forProgram:shaderProgram toBlock:^{ + glUniform1f(uniform, floatValue); + }]; + }); +} + +- (void)setPoint:(CGPoint)pointValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +{ + runAsynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:shaderProgram]; + [self setAndExecuteUniformStateCallbackAtIndex:uniform forProgram:shaderProgram toBlock:^{ + GLfloat positionArray[2]; + positionArray[0] = pointValue.x; + positionArray[1] = pointValue.y; + + glUniform2fv(uniform, 1, positionArray); + }]; + }); +} + +- (void)setSize:(CGSize)sizeValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +{ + runAsynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:shaderProgram]; + + [self setAndExecuteUniformStateCallbackAtIndex:uniform forProgram:shaderProgram toBlock:^{ + GLfloat sizeArray[2]; + sizeArray[0] = sizeValue.width; + sizeArray[1] = sizeValue.height; + + glUniform2fv(uniform, 1, sizeArray); + }]; + }); +} + +- (void)setVec3:(GPUVector3)vectorValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +{ + runAsynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:shaderProgram]; + + [self setAndExecuteUniformStateCallbackAtIndex:uniform forProgram:shaderProgram toBlock:^{ + glUniform3fv(uniform, 1, (GLfloat *)&vectorValue); + }]; + }); +} + +- (void)setVec4:(GPUVector4)vectorValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +{ + runAsynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:shaderProgram]; + + [self setAndExecuteUniformStateCallbackAtIndex:uniform forProgram:shaderProgram toBlock:^{ + glUniform4fv(uniform, 1, (GLfloat *)&vectorValue); + }]; + }); +} + +- (void)setFloatArray:(GLfloat *)arrayValue length:(GLsizei)arrayLength forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +{ + // Make a copy of the data, so it doesn't get overwritten before async call executes + NSData* arrayData = [NSData dataWithBytes:arrayValue length:arrayLength * sizeof(arrayValue[0])]; + + runAsynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:shaderProgram]; + + [self setAndExecuteUniformStateCallbackAtIndex:uniform forProgram:shaderProgram toBlock:^{ + glUniform1fv(uniform, arrayLength, [arrayData bytes]); + }]; + }); +} + +- (void)setInteger:(GLint)intValue forUniform:(GLint)uniform program:(GLProgram *)shaderProgram; +{ + runAsynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:shaderProgram]; + + [self setAndExecuteUniformStateCallbackAtIndex:uniform forProgram:shaderProgram toBlock:^{ + glUniform1i(uniform, intValue); + }]; + }); +} + +- (void)setAndExecuteUniformStateCallbackAtIndex:(GLint)uniform forProgram:(GLProgram *)shaderProgram toBlock:(dispatch_block_t)uniformStateBlock; +{ + [uniformStateRestorationBlocks setObject:[uniformStateBlock copy] forKey:[NSNumber numberWithInt:uniform]]; + uniformStateBlock(); +} + +- (void)setUniformsForProgramAtIndex:(NSUInteger)programIndex; +{ + [uniformStateRestorationBlocks enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop){ + dispatch_block_t currentBlock = obj; + currentBlock(); + }]; +} + +#pragma mark - +#pragma mark GPUImageInput + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + static const GLfloat imageVertices[] = { + -1.0f, -1.0f, + 1.0f, -1.0f, + -1.0f, 1.0f, + 1.0f, 1.0f, + }; + + [self renderToTextureWithVertices:imageVertices textureCoordinates:[[self class] textureCoordinatesForRotation:inputRotation]]; + + [self informTargetsAboutNewFrameAtTime:frameTime]; +} + +- (NSInteger)nextAvailableTextureIndex; +{ + return 0; +} + +- (void)setInputFramebuffer:(GPUImageFramebuffer *)newInputFramebuffer atIndex:(NSInteger)textureIndex; +{ + firstInputFramebuffer = newInputFramebuffer; + [firstInputFramebuffer lock]; +} + +- (CGSize)rotatedSize:(CGSize)sizeToRotate forIndex:(NSInteger)textureIndex; +{ + CGSize rotatedSize = sizeToRotate; + + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + rotatedSize.width = sizeToRotate.height; + rotatedSize.height = sizeToRotate.width; + } + + return rotatedSize; +} + +- (CGPoint)rotatedPoint:(CGPoint)pointToRotate forRotation:(GPUImageRotationMode)rotation; +{ + CGPoint rotatedPoint; + switch(rotation) + { + case kGPUImageNoRotation: return pointToRotate; break; + case kGPUImageFlipHorizonal: + { + rotatedPoint.x = 1.0 - pointToRotate.x; + rotatedPoint.y = pointToRotate.y; + }; break; + case kGPUImageFlipVertical: + { + rotatedPoint.x = pointToRotate.x; + rotatedPoint.y = 1.0 - pointToRotate.y; + }; break; + case kGPUImageRotateLeft: + { + rotatedPoint.x = 1.0 - pointToRotate.y; + rotatedPoint.y = pointToRotate.x; + }; break; + case kGPUImageRotateRight: + { + rotatedPoint.x = pointToRotate.y; + rotatedPoint.y = 1.0 - pointToRotate.x; + }; break; + case kGPUImageRotateRightFlipVertical: + { + rotatedPoint.x = pointToRotate.y; + rotatedPoint.y = pointToRotate.x; + }; break; + case kGPUImageRotateRightFlipHorizontal: + { + rotatedPoint.x = 1.0 - pointToRotate.y; + rotatedPoint.y = 1.0 - pointToRotate.x; + }; break; + case kGPUImageRotate180: + { + rotatedPoint.x = 1.0 - pointToRotate.x; + rotatedPoint.y = 1.0 - pointToRotate.y; + }; break; + } + + return rotatedPoint; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + if (self.preventRendering) + { + return; + } + + if (overrideInputSize) + { + if (CGSizeEqualToSize(forcedMaximumSize, CGSizeZero)) + { + } + else + { + CGRect insetRect = AVMakeRectWithAspectRatioInsideRect(newSize, CGRectMake(0.0, 0.0, forcedMaximumSize.width, forcedMaximumSize.height)); + inputTextureSize = insetRect.size; + } + } + else + { + CGSize rotatedSize = [self rotatedSize:newSize forIndex:textureIndex]; + + if (CGSizeEqualToSize(rotatedSize, CGSizeZero)) + { + inputTextureSize = rotatedSize; + } + else if (!CGSizeEqualToSize(inputTextureSize, rotatedSize)) + { + inputTextureSize = rotatedSize; + } + } + + [self setupFilterForSize:[self sizeOfFBO]]; +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + inputRotation = newInputRotation; +} + +- (void)forceProcessingAtSize:(CGSize)frameSize; +{ + if (CGSizeEqualToSize(frameSize, CGSizeZero)) + { + overrideInputSize = NO; + } + else + { + overrideInputSize = YES; + inputTextureSize = frameSize; + forcedMaximumSize = CGSizeZero; + } +} + +- (void)forceProcessingAtSizeRespectingAspectRatio:(CGSize)frameSize; +{ + if (CGSizeEqualToSize(frameSize, CGSizeZero)) + { + overrideInputSize = NO; + inputTextureSize = CGSizeZero; + forcedMaximumSize = CGSizeZero; + } + else + { + overrideInputSize = YES; + forcedMaximumSize = frameSize; + } +} + +- (CGSize)maximumOutputSize; +{ + // I'm temporarily disabling adjustments for smaller output sizes until I figure out how to make this work better + return CGSizeZero; + + /* + if (CGSizeEqualToSize(cachedMaximumOutputSize, CGSizeZero)) + { + for (id currentTarget in targets) + { + if ([currentTarget maximumOutputSize].width > cachedMaximumOutputSize.width) + { + cachedMaximumOutputSize = [currentTarget maximumOutputSize]; + } + } + } + + return cachedMaximumOutputSize; + */ +} + +- (void)endProcessing +{ + if (!isEndProcessing) + { + isEndProcessing = YES; + + for (id currentTarget in targets) + { + [currentTarget endProcessing]; + } + } +} + +- (BOOL)wantsMonochromeInput; +{ + return NO; +} + +#pragma mark - +#pragma mark Accessors + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFilterGroup.h b/LFLiveKit/Vendor/GPUImage/GPUImageFilterGroup.h new file mode 100755 index 00000000..6817cdf0 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFilterGroup.h @@ -0,0 +1,19 @@ +#import "GPUImageOutput.h" +#import "GPUImageFilter.h" + +@interface GPUImageFilterGroup : GPUImageOutput +{ + NSMutableArray *filters; + BOOL isEndProcessing; +} + +@property(readwrite, nonatomic, strong) GPUImageOutput *terminalFilter; +@property(readwrite, nonatomic, strong) NSArray *initialFilters; +@property(readwrite, nonatomic, strong) GPUImageOutput *inputFilterToIgnoreForUpdates; + +// Filter management +- (void)addFilter:(GPUImageOutput *)newFilter; +- (GPUImageOutput *)filterAtIndex:(NSUInteger)filterIndex; +- (NSUInteger)filterCount; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFilterGroup.m b/LFLiveKit/Vendor/GPUImage/GPUImageFilterGroup.m new file mode 100755 index 00000000..72cfe5e7 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFilterGroup.m @@ -0,0 +1,208 @@ +#import "GPUImageFilterGroup.h" +#import "GPUImagePicture.h" + +@implementation GPUImageFilterGroup + +@synthesize terminalFilter = _terminalFilter; +@synthesize initialFilters = _initialFilters; +@synthesize inputFilterToIgnoreForUpdates = _inputFilterToIgnoreForUpdates; + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + filters = [[NSMutableArray alloc] init]; + + return self; +} + +#pragma mark - +#pragma mark Filter management + +- (void)addFilter:(GPUImageOutput *)newFilter; +{ + [filters addObject:newFilter]; +} + +- (GPUImageOutput *)filterAtIndex:(NSUInteger)filterIndex; +{ + return [filters objectAtIndex:filterIndex]; +} + +- (NSUInteger)filterCount; +{ + return [filters count]; +} + +#pragma mark - +#pragma mark Still image processing + +- (void)useNextFrameForImageCapture; +{ + [self.terminalFilter useNextFrameForImageCapture]; +} + +- (CGImageRef)newCGImageFromCurrentlyProcessedOutput; +{ + return [self.terminalFilter newCGImageFromCurrentlyProcessedOutput]; +} + +#pragma mark - +#pragma mark GPUImageOutput overrides + +- (void)setTargetToIgnoreForUpdates:(id)targetToIgnoreForUpdates; +{ + [_terminalFilter setTargetToIgnoreForUpdates:targetToIgnoreForUpdates]; +} + +- (void)addTarget:(id)newTarget atTextureLocation:(NSInteger)textureLocation; +{ + [_terminalFilter addTarget:newTarget atTextureLocation:textureLocation]; +} + +- (void)removeTarget:(id)targetToRemove; +{ + [_terminalFilter removeTarget:targetToRemove]; +} + +- (void)removeAllTargets; +{ + [_terminalFilter removeAllTargets]; +} + +- (NSArray *)targets; +{ + return [_terminalFilter targets]; +} + +- (void)setFrameProcessingCompletionBlock:(void (^)(GPUImageOutput *, CMTime))frameProcessingCompletionBlock; +{ + [_terminalFilter setFrameProcessingCompletionBlock:frameProcessingCompletionBlock]; +} + +- (void (^)(GPUImageOutput *, CMTime))frameProcessingCompletionBlock; +{ + return [_terminalFilter frameProcessingCompletionBlock]; +} + +#pragma mark - +#pragma mark GPUImageInput protocol + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + for (GPUImageOutput *currentFilter in _initialFilters) + { + if (currentFilter != self.inputFilterToIgnoreForUpdates) + { + [currentFilter newFrameReadyAtTime:frameTime atIndex:textureIndex]; + } + } +} + +- (void)setInputFramebuffer:(GPUImageFramebuffer *)newInputFramebuffer atIndex:(NSInteger)textureIndex; +{ + for (GPUImageOutput *currentFilter in _initialFilters) + { + [currentFilter setInputFramebuffer:newInputFramebuffer atIndex:textureIndex]; + } +} + +- (NSInteger)nextAvailableTextureIndex; +{ +// if ([_initialFilters count] > 0) +// { +// return [[_initialFilters objectAtIndex:0] nextAvailableTextureIndex]; +// } + + return 0; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + for (GPUImageOutput *currentFilter in _initialFilters) + { + [currentFilter setInputSize:newSize atIndex:textureIndex]; + } +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + for (GPUImageOutput *currentFilter in _initialFilters) + { + [currentFilter setInputRotation:newInputRotation atIndex:(NSInteger)textureIndex]; + } +} + +- (void)forceProcessingAtSize:(CGSize)frameSize; +{ + for (GPUImageOutput *currentFilter in filters) + { + [currentFilter forceProcessingAtSize:frameSize]; + } +} + +- (void)forceProcessingAtSizeRespectingAspectRatio:(CGSize)frameSize; +{ + for (GPUImageOutput *currentFilter in filters) + { + [currentFilter forceProcessingAtSizeRespectingAspectRatio:frameSize]; + } +} + +- (CGSize)maximumOutputSize; +{ + // I'm temporarily disabling adjustments for smaller output sizes until I figure out how to make this work better + return CGSizeZero; + + /* + if (CGSizeEqualToSize(cachedMaximumOutputSize, CGSizeZero)) + { + for (id currentTarget in _initialFilters) + { + if ([currentTarget maximumOutputSize].width > cachedMaximumOutputSize.width) + { + cachedMaximumOutputSize = [currentTarget maximumOutputSize]; + } + } + } + + return cachedMaximumOutputSize; + */ +} + +- (void)endProcessing; +{ + if (!isEndProcessing) + { + isEndProcessing = YES; + + for (id currentTarget in _initialFilters) + { + [currentTarget endProcessing]; + } + } +} + +- (BOOL)wantsMonochromeInput; +{ + BOOL allInputsWantMonochromeInput = YES; + for (GPUImageOutput *currentFilter in _initialFilters) + { + allInputsWantMonochromeInput = allInputsWantMonochromeInput && [currentFilter wantsMonochromeInput]; + } + + return allInputsWantMonochromeInput; +} + +- (void)setCurrentlyReceivingMonochromeInput:(BOOL)newValue; +{ + for (GPUImageOutput *currentFilter in _initialFilters) + { + [currentFilter setCurrentlyReceivingMonochromeInput:newValue]; + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFilterPipeline.h b/LFLiveKit/Vendor/GPUImage/GPUImageFilterPipeline.h new file mode 100755 index 00000000..dc2baeac --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFilterPipeline.h @@ -0,0 +1,30 @@ +#import +#import "GPUImageOutput.h" + +@interface GPUImageFilterPipeline : NSObject +{ + NSString *stringValue; +} + +@property (strong) NSMutableArray *filters; + +@property (strong) GPUImageOutput *input; +@property (strong) id output; + +- (id) initWithOrderedFilters:(NSArray*) filters input:(GPUImageOutput*)input output:(id )output; +- (id) initWithConfiguration:(NSDictionary*) configuration input:(GPUImageOutput*)input output:(id )output; +- (id) initWithConfigurationFile:(NSURL*) configuration input:(GPUImageOutput*)input output:(id )output; + +- (void) addFilter:(GPUImageOutput *)filter; +- (void) addFilter:(GPUImageOutput *)filter atIndex:(NSUInteger)insertIndex; +- (void) replaceFilterAtIndex:(NSUInteger)index withFilter:(GPUImageOutput *)filter; +- (void) replaceAllFilters:(NSArray *) newFilters; +- (void) removeFilter:(GPUImageOutput *)filter; +- (void) removeFilterAtIndex:(NSUInteger)index; +- (void) removeAllFilters; + +- (UIImage *) currentFilteredFrame; +- (UIImage *) currentFilteredFrameWithOrientation:(UIImageOrientation)imageOrientation; +- (CGImageRef) newCGImageFromCurrentFilteredFrame; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFilterPipeline.m b/LFLiveKit/Vendor/GPUImage/GPUImageFilterPipeline.m new file mode 100755 index 00000000..4fbe5ebb --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFilterPipeline.m @@ -0,0 +1,218 @@ +#import "GPUImageFilterPipeline.h" + +@interface GPUImageFilterPipeline () + +- (BOOL)_parseConfiguration:(NSDictionary *)configuration; + +- (void)_refreshFilters; + +@end + +@implementation GPUImageFilterPipeline + +@synthesize filters = _filters, input = _input, output = _output; + +#pragma mark Config file init + +- (id)initWithConfiguration:(NSDictionary *)configuration input:(GPUImageOutput *)input output:(id )output { + self = [super init]; + if (self) { + self.input = input; + self.output = output; + if (![self _parseConfiguration:configuration]) { + NSLog(@"Sorry, a parsing error occurred."); + abort(); + } + [self _refreshFilters]; + } + return self; +} + +- (id)initWithConfigurationFile:(NSURL *)configuration input:(GPUImageOutput *)input output:(id )output { + return [self initWithConfiguration:[NSDictionary dictionaryWithContentsOfURL:configuration] input:input output:output]; +} + +- (BOOL)_parseConfiguration:(NSDictionary *)configuration { + NSArray *filters = [configuration objectForKey:@"Filters"]; + if (!filters) { + return NO; + } + + NSError *regexError = nil; + NSRegularExpression *parsingRegex = [NSRegularExpression regularExpressionWithPattern:@"(float|CGPoint|NSString)\\((.*?)(?:,\\s*(.*?))*\\)" + options:0 + error:®exError]; + + // It's faster to put them into an array and then pass it to the filters property than it is to call [self addFilter:] every time + NSMutableArray *orderedFilters = [NSMutableArray arrayWithCapacity:[filters count]]; + for (NSDictionary *filter in filters) { + NSString *filterName = [filter objectForKey:@"FilterName"]; + Class theClass = NSClassFromString(filterName); + GPUImageOutput *genericFilter = [[theClass alloc] init]; + // Set up the properties + NSDictionary *filterAttributes; + if ((filterAttributes = [filter objectForKey:@"Attributes"])) { + for (NSString *propertyKey in filterAttributes) { + // Set up the selector + SEL theSelector = NSSelectorFromString(propertyKey); + NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[theClass instanceMethodSignatureForSelector:theSelector]]; + [inv setSelector:theSelector]; + [inv setTarget:genericFilter]; + + // check selector given with parameter + if ([propertyKey hasSuffix:@":"]) { + + stringValue = nil; + + // Then parse the arguments + NSMutableArray *parsedArray; + if ([[filterAttributes objectForKey:propertyKey] isKindOfClass:[NSArray class]]) { + NSArray *array = [filterAttributes objectForKey:propertyKey]; + parsedArray = [NSMutableArray arrayWithCapacity:[array count]]; + for (NSString *string in array) { + NSTextCheckingResult *parse = [parsingRegex firstMatchInString:string + options:0 + range:NSMakeRange(0, [string length])]; + + NSString *modifier = [string substringWithRange:[parse rangeAtIndex:1]]; + if ([modifier isEqualToString:@"float"]) { + // Float modifier, one argument + CGFloat value = [[string substringWithRange:[parse rangeAtIndex:2]] floatValue]; + [parsedArray addObject:[NSNumber numberWithFloat:value]]; + [inv setArgument:&value atIndex:2]; + } else if ([modifier isEqualToString:@"CGPoint"]) { + // CGPoint modifier, two float arguments + CGFloat x = [[string substringWithRange:[parse rangeAtIndex:2]] floatValue]; + CGFloat y = [[string substringWithRange:[parse rangeAtIndex:3]] floatValue]; + CGPoint value = CGPointMake(x, y); + [parsedArray addObject:[NSValue valueWithCGPoint:value]]; + } else if ([modifier isEqualToString:@"NSString"]) { + // NSString modifier, one string argument + stringValue = [[string substringWithRange:[parse rangeAtIndex:2]] copy]; + [inv setArgument:&stringValue atIndex:2]; + + } else { + return NO; + } + } + [inv setArgument:&parsedArray atIndex:2]; + } else { + NSString *string = [filterAttributes objectForKey:propertyKey]; + NSTextCheckingResult *parse = [parsingRegex firstMatchInString:string + options:0 + range:NSMakeRange(0, [string length])]; + + NSString *modifier = [string substringWithRange:[parse rangeAtIndex:1]]; + if ([modifier isEqualToString:@"float"]) { + // Float modifier, one argument + CGFloat value = [[string substringWithRange:[parse rangeAtIndex:2]] floatValue]; + [inv setArgument:&value atIndex:2]; + } else if ([modifier isEqualToString:@"CGPoint"]) { + // CGPoint modifier, two float arguments + CGFloat x = [[string substringWithRange:[parse rangeAtIndex:2]] floatValue]; + CGFloat y = [[string substringWithRange:[parse rangeAtIndex:3]] floatValue]; + CGPoint value = CGPointMake(x, y); + [inv setArgument:&value atIndex:2]; + } else if ([modifier isEqualToString:@"NSString"]) { + // NSString modifier, one string argument + stringValue = [[string substringWithRange:[parse rangeAtIndex:2]] copy]; + [inv setArgument:&stringValue atIndex:2]; + + } else { + return NO; + } + } + } + + + [inv invoke]; + } + } + [orderedFilters addObject:genericFilter]; + } + self.filters = orderedFilters; + + return YES; +} + +#pragma mark Regular init + +- (id)initWithOrderedFilters:(NSArray *)filters input:(GPUImageOutput *)input output:(id )output { + self = [super init]; + if (self) { + self.input = input; + self.output = output; + self.filters = [NSMutableArray arrayWithArray:filters]; + [self _refreshFilters]; + } + return self; +} + +- (void)addFilter:(GPUImageOutput *)filter atIndex:(NSUInteger)insertIndex { + [self.filters insertObject:filter atIndex:insertIndex]; + [self _refreshFilters]; +} + +- (void)addFilter:(GPUImageOutput *)filter { + [self.filters addObject:filter]; + [self _refreshFilters]; +} + +- (void)replaceFilterAtIndex:(NSUInteger)index withFilter:(GPUImageOutput *)filter { + [self.filters replaceObjectAtIndex:index withObject:filter]; + [self _refreshFilters]; +} + +- (void) removeFilter:(GPUImageOutput *)filter; +{ + [self.filters removeObject:filter]; + [self _refreshFilters]; +} + +- (void)removeFilterAtIndex:(NSUInteger)index { + [self.filters removeObjectAtIndex:index]; + [self _refreshFilters]; +} + +- (void)removeAllFilters { + [self.filters removeAllObjects]; + [self _refreshFilters]; +} + +- (void)replaceAllFilters:(NSArray *)newFilters { + self.filters = [NSMutableArray arrayWithArray:newFilters]; + [self _refreshFilters]; +} + +- (void)_refreshFilters { + + id prevFilter = self.input; + GPUImageOutput *theFilter = nil; + + for (int i = 0; i < [self.filters count]; i++) { + theFilter = [self.filters objectAtIndex:i]; + [prevFilter removeAllTargets]; + [prevFilter addTarget:theFilter]; + prevFilter = theFilter; + } + + [prevFilter removeAllTargets]; + + if (self.output != nil) { + [prevFilter addTarget:self.output]; + } +} + +- (UIImage *)currentFilteredFrame { + return [(GPUImageOutput *)[_filters lastObject] imageFromCurrentFramebuffer]; +} + +- (UIImage *)currentFilteredFrameWithOrientation:(UIImageOrientation)imageOrientation { + return [(GPUImageOutput *)[_filters lastObject] imageFromCurrentFramebufferWithOrientation:imageOrientation]; +} + +- (CGImageRef)newCGImageFromCurrentFilteredFrame { + return [(GPUImageOutput *)[_filters lastObject] newCGImageFromCurrentlyProcessedOutput]; +} + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFourInputFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageFourInputFilter.h new file mode 100644 index 00000000..3beab2df --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFourInputFilter.h @@ -0,0 +1,21 @@ +#import "GPUImageThreeInputFilter.h" + +extern NSString *const kGPUImageFourInputTextureVertexShaderString; + +@interface GPUImageFourInputFilter : GPUImageThreeInputFilter +{ + GPUImageFramebuffer *fourthInputFramebuffer; + + GLint filterFourthTextureCoordinateAttribute; + GLint filterInputTextureUniform4; + GPUImageRotationMode inputRotation4; + GLuint filterSourceTexture4; + CMTime fourthFrameTime; + + BOOL hasSetThirdTexture, hasReceivedFourthFrame, fourthFrameWasVideo; + BOOL fourthFrameCheckDisabled; +} + +- (void)disableFourthFrameCheck; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFourInputFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageFourInputFilter.m new file mode 100644 index 00000000..bc660a3d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFourInputFilter.m @@ -0,0 +1,401 @@ +#import "GPUImageFourInputFilter.h" + + +NSString *const kGPUImageFourInputTextureVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + attribute vec4 inputTextureCoordinate2; + attribute vec4 inputTextureCoordinate3; + attribute vec4 inputTextureCoordinate4; + + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + varying vec2 textureCoordinate3; + varying vec2 textureCoordinate4; + + void main() + { + gl_Position = position; + textureCoordinate = inputTextureCoordinate.xy; + textureCoordinate2 = inputTextureCoordinate2.xy; + textureCoordinate3 = inputTextureCoordinate3.xy; + textureCoordinate4 = inputTextureCoordinate4.xy; + } +); + +@implementation GPUImageFourInputFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [self initWithVertexShaderFromString:kGPUImageFourInputTextureVertexShaderString fragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + return self; +} + +- (id)initWithVertexShaderFromString:(NSString *)vertexShaderString fragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [super initWithVertexShaderFromString:vertexShaderString fragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + inputRotation4 = kGPUImageNoRotation; + + hasSetThirdTexture = NO; + + hasReceivedFourthFrame = NO; + fourthFrameWasVideo = NO; + fourthFrameCheckDisabled = NO; + + fourthFrameTime = kCMTimeInvalid; + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + filterFourthTextureCoordinateAttribute = [filterProgram attributeIndex:@"inputTextureCoordinate4"]; + + filterInputTextureUniform4 = [filterProgram uniformIndex:@"inputImageTexture4"]; // This does assume a name of "inputImageTexture3" for the third input texture in the fragment shader + glEnableVertexAttribArray(filterFourthTextureCoordinateAttribute); + }); + + return self; +} + +- (void)initializeAttributes; +{ + [super initializeAttributes]; + [filterProgram addAttribute:@"inputTextureCoordinate4"]; +} + +- (void)disableFourthFrameCheck; +{ + fourthFrameCheckDisabled = YES; +} + +#pragma mark - +#pragma mark Rendering + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + if (self.preventRendering) + { + [firstInputFramebuffer unlock]; + [secondInputFramebuffer unlock]; + [thirdInputFramebuffer unlock]; + [fourthInputFramebuffer unlock]; + return; + } + + [GPUImageContext setActiveShaderProgram:filterProgram]; + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + if (usingNextFrameForImageCapture) + { + [outputFramebuffer lock]; + } + + [self setUniformsForProgramAtIndex:0]; + + glClearColor(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha); + glClear(GL_COLOR_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, [firstInputFramebuffer texture]); + glUniform1i(filterInputTextureUniform, 2); + + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, [secondInputFramebuffer texture]); + glUniform1i(filterInputTextureUniform2, 3); + + glActiveTexture(GL_TEXTURE4); + glBindTexture(GL_TEXTURE_2D, [thirdInputFramebuffer texture]); + glUniform1i(filterInputTextureUniform3, 4); + + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_2D, [fourthInputFramebuffer texture]); + glUniform1i(filterInputTextureUniform4, 5); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + glVertexAttribPointer(filterSecondTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [[self class] textureCoordinatesForRotation:inputRotation2]); + glVertexAttribPointer(filterThirdTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [[self class] textureCoordinatesForRotation:inputRotation3]); + glVertexAttribPointer(filterFourthTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [[self class] textureCoordinatesForRotation:inputRotation4]); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + [firstInputFramebuffer unlock]; + [secondInputFramebuffer unlock]; + [thirdInputFramebuffer unlock]; + [fourthInputFramebuffer unlock]; + if (usingNextFrameForImageCapture) + { + dispatch_semaphore_signal(imageCaptureSemaphore); + } +} + +#pragma mark - +#pragma mark GPUImageInput + +- (NSInteger)nextAvailableTextureIndex; +{ + if (hasSetThirdTexture) + { + return 3; + } + else if (hasSetSecondTexture) + { + return 2; + } + else if (hasSetFirstTexture) + { + return 1; + } + else + { + return 0; + } +} + +- (void)setInputFramebuffer:(GPUImageFramebuffer *)newInputFramebuffer atIndex:(NSInteger)textureIndex; +{ + if (textureIndex == 0) + { + firstInputFramebuffer = newInputFramebuffer; + hasSetFirstTexture = YES; + [firstInputFramebuffer lock]; + } + else if (textureIndex == 1) + { + secondInputFramebuffer = newInputFramebuffer; + hasSetSecondTexture = YES; + [secondInputFramebuffer lock]; + } + else if (textureIndex == 2) + { + thirdInputFramebuffer = newInputFramebuffer; + hasSetThirdTexture = YES; + [thirdInputFramebuffer lock]; + } + else + { + fourthInputFramebuffer = newInputFramebuffer; + [fourthInputFramebuffer lock]; + } +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + if (textureIndex == 0) + { + [super setInputSize:newSize atIndex:textureIndex]; + + if (CGSizeEqualToSize(newSize, CGSizeZero)) + { + hasSetFirstTexture = NO; + } + } + else if (textureIndex == 1) + { + if (CGSizeEqualToSize(newSize, CGSizeZero)) + { + hasSetSecondTexture = NO; + } + } + else if (textureIndex == 2) + { + if (CGSizeEqualToSize(newSize, CGSizeZero)) + { + hasSetThirdTexture = NO; + } + } +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + if (textureIndex == 0) + { + inputRotation = newInputRotation; + } + else if (textureIndex == 1) + { + inputRotation2 = newInputRotation; + } + else if (textureIndex == 2) + { + inputRotation3 = newInputRotation; + } + else + { + inputRotation4 = newInputRotation; + } +} + +- (CGSize)rotatedSize:(CGSize)sizeToRotate forIndex:(NSInteger)textureIndex; +{ + CGSize rotatedSize = sizeToRotate; + + GPUImageRotationMode rotationToCheck; + if (textureIndex == 0) + { + rotationToCheck = inputRotation; + } + else if (textureIndex == 1) + { + rotationToCheck = inputRotation2; + } + else if (textureIndex == 2) + { + rotationToCheck = inputRotation3; + } + else + { + rotationToCheck = inputRotation4; + } + + if (GPUImageRotationSwapsWidthAndHeight(rotationToCheck)) + { + rotatedSize.width = sizeToRotate.height; + rotatedSize.height = sizeToRotate.width; + } + + return rotatedSize; +} + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + // You can set up infinite update loops, so this helps to short circuit them + if (hasReceivedFirstFrame && hasReceivedSecondFrame && hasReceivedThirdFrame) + { + return; + } + + BOOL updatedMovieFrameOppositeStillImage = NO; + + if (textureIndex == 0) + { + hasReceivedFirstFrame = YES; + firstFrameTime = frameTime; + if (secondFrameCheckDisabled) + { + hasReceivedSecondFrame = YES; + } + if (thirdFrameCheckDisabled) + { + hasReceivedThirdFrame = YES; + } + if (fourthFrameCheckDisabled) + { + hasReceivedThirdFrame = YES; + } + + if (!CMTIME_IS_INDEFINITE(frameTime)) + { + if CMTIME_IS_INDEFINITE(secondFrameTime) + { + updatedMovieFrameOppositeStillImage = YES; + } + } + } + else if (textureIndex == 1) + { + hasReceivedSecondFrame = YES; + secondFrameTime = frameTime; + if (firstFrameCheckDisabled) + { + hasReceivedFirstFrame = YES; + } + if (thirdFrameCheckDisabled) + { + hasReceivedThirdFrame = YES; + } + if (fourthFrameCheckDisabled) + { + hasReceivedFourthFrame = YES; + } + + if (!CMTIME_IS_INDEFINITE(frameTime)) + { + if CMTIME_IS_INDEFINITE(firstFrameTime) + { + updatedMovieFrameOppositeStillImage = YES; + } + } + } + else if (textureIndex == 2) + { + hasReceivedThirdFrame = YES; + thirdFrameTime = frameTime; + if (firstFrameCheckDisabled) + { + hasReceivedFirstFrame = YES; + } + if (secondFrameCheckDisabled) + { + hasReceivedSecondFrame = YES; + } + if (fourthFrameCheckDisabled) + { + hasReceivedFourthFrame = YES; + } + + if (!CMTIME_IS_INDEFINITE(frameTime)) + { + if CMTIME_IS_INDEFINITE(firstFrameTime) + { + updatedMovieFrameOppositeStillImage = YES; + } + } + } + else + { + hasReceivedFourthFrame = YES; + fourthFrameTime = frameTime; + if (firstFrameCheckDisabled) + { + hasReceivedFirstFrame = YES; + } + if (secondFrameCheckDisabled) + { + hasReceivedSecondFrame = YES; + } + if (thirdFrameCheckDisabled) + { + hasReceivedThirdFrame = YES; + } + + if (!CMTIME_IS_INDEFINITE(frameTime)) + { + if CMTIME_IS_INDEFINITE(firstFrameTime) + { + updatedMovieFrameOppositeStillImage = YES; + } + } + } + + // || (hasReceivedFirstFrame && secondFrameCheckDisabled) || (hasReceivedSecondFrame && firstFrameCheckDisabled) + if ((hasReceivedFirstFrame && hasReceivedSecondFrame && hasReceivedThirdFrame && hasReceivedFourthFrame) || updatedMovieFrameOppositeStillImage) + { + static const GLfloat imageVertices[] = { + -1.0f, -1.0f, + 1.0f, -1.0f, + -1.0f, 1.0f, + 1.0f, 1.0f, + }; + + [self renderToTextureWithVertices:imageVertices textureCoordinates:[[self class] textureCoordinatesForRotation:inputRotation]]; + + [self informTargetsAboutNewFrameAtTime:frameTime]; + + hasReceivedFirstFrame = NO; + hasReceivedSecondFrame = NO; + hasReceivedThirdFrame = NO; + hasReceivedFourthFrame = NO; + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFramebuffer.h b/LFLiveKit/Vendor/GPUImage/GPUImageFramebuffer.h new file mode 100644 index 00000000..bdb6a1f1 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFramebuffer.h @@ -0,0 +1,59 @@ +#import + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +#import +#import +#import +#else +#import +#import +#endif + +#import +#import + + +typedef struct GPUTextureOptions { + GLenum minFilter; + GLenum magFilter; + GLenum wrapS; + GLenum wrapT; + GLenum internalFormat; + GLenum format; + GLenum type; +} GPUTextureOptions; + +@interface GPUImageFramebuffer : NSObject + +@property(readonly) CGSize size; +@property(readonly) GPUTextureOptions textureOptions; +@property(readonly) GLuint texture; +@property(readonly) BOOL missingFramebuffer; + +// Initialization and teardown +- (id)initWithSize:(CGSize)framebufferSize; +- (id)initWithSize:(CGSize)framebufferSize textureOptions:(GPUTextureOptions)fboTextureOptions onlyTexture:(BOOL)onlyGenerateTexture; +- (id)initWithSize:(CGSize)framebufferSize overriddenTexture:(GLuint)inputTexture; + +// Usage +- (void)activateFramebuffer; + +// Reference counting +- (void)lock; +- (void)unlock; +- (void)clearAllLocks; +- (void)disableReferenceCounting; +- (void)enableReferenceCounting; + +// Image capture +- (CGImageRef)newCGImageFromFramebufferContents; +- (void)restoreRenderTarget; + +// Raw data bytes +- (void)lockForReading; +- (void)unlockAfterReading; +- (NSUInteger)bytesPerRow; +- (GLubyte *)byteBuffer; +- (CVPixelBufferRef)pixelBuffer; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFramebuffer.m b/LFLiveKit/Vendor/GPUImage/GPUImageFramebuffer.m new file mode 100644 index 00000000..ea55c266 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFramebuffer.m @@ -0,0 +1,457 @@ +#import "GPUImageFramebuffer.h" +#import "GPUImageOutput.h" + +@interface GPUImageFramebuffer() +{ + GLuint framebuffer; +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + CVPixelBufferRef renderTarget; + CVOpenGLESTextureRef renderTexture; + NSUInteger readLockCount; +#else +#endif + NSUInteger framebufferReferenceCount; + BOOL referenceCountingDisabled; +} + +- (void)generateFramebuffer; +- (void)generateTexture; +- (void)destroyFramebuffer; + +@end + +void dataProviderReleaseCallback (void *info, const void *data, size_t size); +void dataProviderUnlockCallback (void *info, const void *data, size_t size); + +@implementation GPUImageFramebuffer + +@synthesize size = _size; +@synthesize textureOptions = _textureOptions; +@synthesize texture = _texture; +@synthesize missingFramebuffer = _missingFramebuffer; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithSize:(CGSize)framebufferSize textureOptions:(GPUTextureOptions)fboTextureOptions onlyTexture:(BOOL)onlyGenerateTexture; +{ + if (!(self = [super init])) + { + return nil; + } + + _textureOptions = fboTextureOptions; + _size = framebufferSize; + framebufferReferenceCount = 0; + referenceCountingDisabled = NO; + _missingFramebuffer = onlyGenerateTexture; + + if (_missingFramebuffer) + { + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + [self generateTexture]; + framebuffer = 0; + }); + } + else + { + [self generateFramebuffer]; + } + return self; +} + +- (id)initWithSize:(CGSize)framebufferSize overriddenTexture:(GLuint)inputTexture; +{ + if (!(self = [super init])) + { + return nil; + } + + GPUTextureOptions defaultTextureOptions; + defaultTextureOptions.minFilter = GL_LINEAR; + defaultTextureOptions.magFilter = GL_LINEAR; + defaultTextureOptions.wrapS = GL_CLAMP_TO_EDGE; + defaultTextureOptions.wrapT = GL_CLAMP_TO_EDGE; + defaultTextureOptions.internalFormat = GL_RGBA; + defaultTextureOptions.format = GL_BGRA; + defaultTextureOptions.type = GL_UNSIGNED_BYTE; + + _textureOptions = defaultTextureOptions; + _size = framebufferSize; + framebufferReferenceCount = 0; + referenceCountingDisabled = YES; + + _texture = inputTexture; + + return self; +} + +- (id)initWithSize:(CGSize)framebufferSize; +{ + GPUTextureOptions defaultTextureOptions; + defaultTextureOptions.minFilter = GL_LINEAR; + defaultTextureOptions.magFilter = GL_LINEAR; + defaultTextureOptions.wrapS = GL_CLAMP_TO_EDGE; + defaultTextureOptions.wrapT = GL_CLAMP_TO_EDGE; + defaultTextureOptions.internalFormat = GL_RGBA; + defaultTextureOptions.format = GL_BGRA; + defaultTextureOptions.type = GL_UNSIGNED_BYTE; + + if (!(self = [self initWithSize:framebufferSize textureOptions:defaultTextureOptions onlyTexture:NO])) + { + return nil; + } + + return self; +} + +- (void)dealloc +{ + [self destroyFramebuffer]; +} + +#pragma mark - +#pragma mark Internal + +- (void)generateTexture; +{ + glActiveTexture(GL_TEXTURE1); + glGenTextures(1, &_texture); + glBindTexture(GL_TEXTURE_2D, _texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _textureOptions.minFilter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _textureOptions.magFilter); + // This is necessary for non-power-of-two textures + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, _textureOptions.wrapS); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, _textureOptions.wrapT); + + // TODO: Handle mipmaps +} + +- (void)generateFramebuffer; +{ + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + + glGenFramebuffers(1, &framebuffer); + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); + + // By default, all framebuffers on iOS 5.0+ devices are backed by texture caches, using one shared cache + if ([GPUImageContext supportsFastTextureUpload]) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + CVOpenGLESTextureCacheRef coreVideoTextureCache = [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache]; + // Code originally sourced from http://allmybrain.com/2011/12/08/rendering-to-a-texture-with-ios-5-texture-cache-api/ + + CFDictionaryRef empty; // empty value for attr value. + CFMutableDictionaryRef attrs; + empty = CFDictionaryCreate(kCFAllocatorDefault, NULL, NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); // our empty IOSurface properties dictionary + attrs = CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + CFDictionarySetValue(attrs, kCVPixelBufferIOSurfacePropertiesKey, empty); + + CVReturn err = CVPixelBufferCreate(kCFAllocatorDefault, (int)_size.width, (int)_size.height, kCVPixelFormatType_32BGRA, attrs, &renderTarget); + if (err) + { + NSLog(@"FBO size: %f, %f", _size.width, _size.height); + NSAssert(NO, @"Error at CVPixelBufferCreate %d", err); + } + + err = CVOpenGLESTextureCacheCreateTextureFromImage (kCFAllocatorDefault, coreVideoTextureCache, renderTarget, + NULL, // texture attributes + GL_TEXTURE_2D, + _textureOptions.internalFormat, // opengl format + (int)_size.width, + (int)_size.height, + _textureOptions.format, // native iOS format + _textureOptions.type, + 0, + &renderTexture); + if (err) + { + NSAssert(NO, @"Error at CVOpenGLESTextureCacheCreateTextureFromImage %d", err); + } + + CFRelease(attrs); + CFRelease(empty); + + glBindTexture(CVOpenGLESTextureGetTarget(renderTexture), CVOpenGLESTextureGetName(renderTexture)); + _texture = CVOpenGLESTextureGetName(renderTexture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, _textureOptions.wrapS); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, _textureOptions.wrapT); + + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, CVOpenGLESTextureGetName(renderTexture), 0); +#endif + } + else + { + [self generateTexture]; + + glBindTexture(GL_TEXTURE_2D, _texture); + + glTexImage2D(GL_TEXTURE_2D, 0, _textureOptions.internalFormat, (int)_size.width, (int)_size.height, 0, _textureOptions.format, _textureOptions.type, 0); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0); + } + + #ifndef NS_BLOCK_ASSERTIONS + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + NSAssert(status == GL_FRAMEBUFFER_COMPLETE, @"Incomplete filter FBO: %d", status); + #endif + + glBindTexture(GL_TEXTURE_2D, 0); + }); +} + +- (void)destroyFramebuffer; +{ + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + + if (framebuffer) + { + glDeleteFramebuffers(1, &framebuffer); + framebuffer = 0; + } + + + if ([GPUImageContext supportsFastTextureUpload] && (!_missingFramebuffer)) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + if (renderTarget) + { + CFRelease(renderTarget); + renderTarget = NULL; + } + + if (renderTexture) + { + CFRelease(renderTexture); + renderTexture = NULL; + } +#endif + } + else + { + glDeleteTextures(1, &_texture); + } + + }); +} + +#pragma mark - +#pragma mark Usage + +- (void)activateFramebuffer; +{ + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); + glViewport(0, 0, (int)_size.width, (int)_size.height); +} + +#pragma mark - +#pragma mark Reference counting + +- (void)lock; +{ + if (referenceCountingDisabled) + { + return; + } + + framebufferReferenceCount++; +} + +- (void)unlock; +{ + if (referenceCountingDisabled) + { + return; + } + + NSAssert(framebufferReferenceCount > 0, @"Tried to overrelease a framebuffer, did you forget to call -useNextFrameForImageCapture before using -imageFromCurrentFramebuffer?"); + framebufferReferenceCount--; + if (framebufferReferenceCount < 1) + { + [[GPUImageContext sharedFramebufferCache] returnFramebufferToCache:self]; + } +} + +- (void)clearAllLocks; +{ + framebufferReferenceCount = 0; +} + +- (void)disableReferenceCounting; +{ + referenceCountingDisabled = YES; +} + +- (void)enableReferenceCounting; +{ + referenceCountingDisabled = NO; +} + +#pragma mark - +#pragma mark Image capture + +void dataProviderReleaseCallback (void *info, const void *data, size_t size) +{ + free((void *)data); +} + +void dataProviderUnlockCallback (void *info, const void *data, size_t size) +{ + GPUImageFramebuffer *framebuffer = (__bridge_transfer GPUImageFramebuffer*)info; + + [framebuffer restoreRenderTarget]; + [framebuffer unlock]; + [[GPUImageContext sharedFramebufferCache] removeFramebufferFromActiveImageCaptureList:framebuffer]; +} + +- (CGImageRef)newCGImageFromFramebufferContents; +{ + // a CGImage can only be created from a 'normal' color texture + NSAssert(self.textureOptions.internalFormat == GL_RGBA, @"For conversion to a CGImage the output texture format for this filter must be GL_RGBA."); + NSAssert(self.textureOptions.type == GL_UNSIGNED_BYTE, @"For conversion to a CGImage the type of the output texture of this filter must be GL_UNSIGNED_BYTE."); + + __block CGImageRef cgImageFromBytes; + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + + NSUInteger totalBytesForImage = (int)_size.width * (int)_size.height * 4; + // It appears that the width of a texture must be padded out to be a multiple of 8 (32 bytes) if reading from it using a texture cache + + GLubyte *rawImagePixels; + + CGDataProviderRef dataProvider = NULL; + if ([GPUImageContext supportsFastTextureUpload]) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + NSUInteger paddedWidthOfImage = CVPixelBufferGetBytesPerRow(renderTarget) / 4.0; + NSUInteger paddedBytesForImage = paddedWidthOfImage * (int)_size.height * 4; + + glFinish(); + CFRetain(renderTarget); // I need to retain the pixel buffer here and release in the data source callback to prevent its bytes from being prematurely deallocated during a photo write operation + [self lockForReading]; + rawImagePixels = (GLubyte *)CVPixelBufferGetBaseAddress(renderTarget); + dataProvider = CGDataProviderCreateWithData((__bridge_retained void*)self, rawImagePixels, paddedBytesForImage, dataProviderUnlockCallback); + [[GPUImageContext sharedFramebufferCache] addFramebufferToActiveImageCaptureList:self]; // In case the framebuffer is swapped out on the filter, need to have a strong reference to it somewhere for it to hang on while the image is in existence +#else +#endif + } + else + { + [self activateFramebuffer]; + rawImagePixels = (GLubyte *)malloc(totalBytesForImage); + glReadPixels(0, 0, (int)_size.width, (int)_size.height, GL_RGBA, GL_UNSIGNED_BYTE, rawImagePixels); + dataProvider = CGDataProviderCreateWithData(NULL, rawImagePixels, totalBytesForImage, dataProviderReleaseCallback); + [self unlock]; // Don't need to keep this around anymore + } + + CGColorSpaceRef defaultRGBColorSpace = CGColorSpaceCreateDeviceRGB(); + + if ([GPUImageContext supportsFastTextureUpload]) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + cgImageFromBytes = CGImageCreate((int)_size.width, (int)_size.height, 8, 32, CVPixelBufferGetBytesPerRow(renderTarget), defaultRGBColorSpace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst, dataProvider, NULL, NO, kCGRenderingIntentDefault); +#else +#endif + } + else + { + cgImageFromBytes = CGImageCreate((int)_size.width, (int)_size.height, 8, 32, 4 * (int)_size.width, defaultRGBColorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaLast, dataProvider, NULL, NO, kCGRenderingIntentDefault); + } + + // Capture image with current device orientation + CGDataProviderRelease(dataProvider); + CGColorSpaceRelease(defaultRGBColorSpace); + + }); + + return cgImageFromBytes; +} + +- (void)restoreRenderTarget; +{ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [self unlockAfterReading]; + CFRelease(renderTarget); +#else +#endif +} + +#pragma mark - +#pragma mark Raw data bytes + +- (void)lockForReading +{ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + if ([GPUImageContext supportsFastTextureUpload]) + { + if (readLockCount == 0) + { + CVPixelBufferLockBaseAddress(renderTarget, 0); + } + readLockCount++; + } +#endif +} + +- (void)unlockAfterReading +{ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + if ([GPUImageContext supportsFastTextureUpload]) + { + NSAssert(readLockCount > 0, @"Unbalanced call to -[GPUImageFramebuffer unlockAfterReading]"); + readLockCount--; + if (readLockCount == 0) + { + CVPixelBufferUnlockBaseAddress(renderTarget, 0); + } + } +#endif +} + +- (NSUInteger)bytesPerRow; +{ + if ([GPUImageContext supportsFastTextureUpload]) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + return CVPixelBufferGetBytesPerRow(renderTarget); +#else + return _size.width * 4; // TODO: do more with this on the non-texture-cache side +#endif + } + else + { + return _size.width * 4; + } +} + +- (GLubyte *)byteBuffer; +{ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [self lockForReading]; + GLubyte * bufferBytes = CVPixelBufferGetBaseAddress(renderTarget); + [self unlockAfterReading]; + return bufferBytes; +#else + return NULL; // TODO: do more with this on the non-texture-cache side +#endif +} + +- (CVPixelBufferRef )pixelBuffer; +{ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + return renderTarget; +#else + return NULL; // TODO: do more with this on the non-texture-cache side +#endif +} + +- (GLuint)texture; +{ +// NSLog(@"Accessing texture: %d from FB: %@", _texture, self); + return _texture; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFramebufferCache.h b/LFLiveKit/Vendor/GPUImage/GPUImageFramebufferCache.h new file mode 100644 index 00000000..e56a3456 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFramebufferCache.h @@ -0,0 +1,15 @@ +#import +#import +#import "GPUImageFramebuffer.h" + +@interface GPUImageFramebufferCache : NSObject + +// Framebuffer management +- (GPUImageFramebuffer *)fetchFramebufferForSize:(CGSize)framebufferSize textureOptions:(GPUTextureOptions)textureOptions onlyTexture:(BOOL)onlyTexture; +- (GPUImageFramebuffer *)fetchFramebufferForSize:(CGSize)framebufferSize onlyTexture:(BOOL)onlyTexture; +- (void)returnFramebufferToCache:(GPUImageFramebuffer *)framebuffer; +- (void)purgeAllUnassignedFramebuffers; +- (void)addFramebufferToActiveImageCaptureList:(GPUImageFramebuffer *)framebuffer; +- (void)removeFramebufferFromActiveImageCaptureList:(GPUImageFramebuffer *)framebuffer; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageFramebufferCache.m b/LFLiveKit/Vendor/GPUImage/GPUImageFramebufferCache.m new file mode 100644 index 00000000..53faf2c3 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageFramebufferCache.m @@ -0,0 +1,190 @@ +#import "GPUImageFramebufferCache.h" +#import "GPUImageContext.h" +#import "GPUImageOutput.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +#import +#else +#endif + +@interface GPUImageFramebufferCache() +{ +// NSCache *framebufferCache; + NSMutableDictionary *framebufferCache; + NSMutableDictionary *framebufferTypeCounts; + NSMutableArray *activeImageCaptureList; // Where framebuffers that may be lost by a filter, but which are still needed for a UIImage, etc., are stored + id memoryWarningObserver; + + dispatch_queue_t framebufferCacheQueue; +} + +- (NSString *)hashForSize:(CGSize)size textureOptions:(GPUTextureOptions)textureOptions onlyTexture:(BOOL)onlyTexture; + +@end + + +@implementation GPUImageFramebufferCache + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + __unsafe_unretained __typeof__ (self) weakSelf = self; + memoryWarningObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidReceiveMemoryWarningNotification object:nil queue:nil usingBlock:^(NSNotification *note) { + __typeof__ (self) strongSelf = weakSelf; + if (strongSelf) { + [strongSelf purgeAllUnassignedFramebuffers]; + } + }]; +#else +#endif + +// framebufferCache = [[NSCache alloc] init]; + framebufferCache = [[NSMutableDictionary alloc] init]; + framebufferTypeCounts = [[NSMutableDictionary alloc] init]; + activeImageCaptureList = [[NSMutableArray alloc] init]; + framebufferCacheQueue = dispatch_queue_create("com.sunsetlakesoftware.GPUImage.framebufferCacheQueue", GPUImageDefaultQueueAttribute()); + + return self; +} + +- (void)dealloc; +{ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [[NSNotificationCenter defaultCenter] removeObserver:self]; +#else +#endif +} + +#pragma mark - +#pragma mark Framebuffer management + +- (NSString *)hashForSize:(CGSize)size textureOptions:(GPUTextureOptions)textureOptions onlyTexture:(BOOL)onlyTexture; +{ + if (onlyTexture) + { + return [NSString stringWithFormat:@"%.1fx%.1f-%d:%d:%d:%d:%d:%d:%d-NOFB", size.width, size.height, textureOptions.minFilter, textureOptions.magFilter, textureOptions.wrapS, textureOptions.wrapT, textureOptions.internalFormat, textureOptions.format, textureOptions.type]; + } + else + { + return [NSString stringWithFormat:@"%.1fx%.1f-%d:%d:%d:%d:%d:%d:%d", size.width, size.height, textureOptions.minFilter, textureOptions.magFilter, textureOptions.wrapS, textureOptions.wrapT, textureOptions.internalFormat, textureOptions.format, textureOptions.type]; + } +} + +- (GPUImageFramebuffer *)fetchFramebufferForSize:(CGSize)framebufferSize textureOptions:(GPUTextureOptions)textureOptions onlyTexture:(BOOL)onlyTexture; +{ + __block GPUImageFramebuffer *framebufferFromCache = nil; +// dispatch_sync(framebufferCacheQueue, ^{ + runSynchronouslyOnVideoProcessingQueue(^{ + NSString *lookupHash = [self hashForSize:framebufferSize textureOptions:textureOptions onlyTexture:onlyTexture]; + NSNumber *numberOfMatchingTexturesInCache = [framebufferTypeCounts objectForKey:lookupHash]; + NSInteger numberOfMatchingTextures = [numberOfMatchingTexturesInCache integerValue]; + + if ([numberOfMatchingTexturesInCache integerValue] < 1) + { + // Nothing in the cache, create a new framebuffer to use + framebufferFromCache = [[GPUImageFramebuffer alloc] initWithSize:framebufferSize textureOptions:textureOptions onlyTexture:onlyTexture]; + } + else + { + // Something found, pull the old framebuffer and decrement the count + NSInteger currentTextureID = (numberOfMatchingTextures - 1); + while ((framebufferFromCache == nil) && (currentTextureID >= 0)) + { + NSString *textureHash = [NSString stringWithFormat:@"%@-%ld", lookupHash, (long)currentTextureID]; + framebufferFromCache = [framebufferCache objectForKey:textureHash]; + // Test the values in the cache first, to see if they got invalidated behind our back + if (framebufferFromCache != nil) + { + // Withdraw this from the cache while it's in use + [framebufferCache removeObjectForKey:textureHash]; + } + currentTextureID--; + } + + currentTextureID++; + + [framebufferTypeCounts setObject:[NSNumber numberWithInteger:currentTextureID] forKey:lookupHash]; + + if (framebufferFromCache == nil) + { + framebufferFromCache = [[GPUImageFramebuffer alloc] initWithSize:framebufferSize textureOptions:textureOptions onlyTexture:onlyTexture]; + } + } + }); + + [framebufferFromCache lock]; + return framebufferFromCache; +} + +- (GPUImageFramebuffer *)fetchFramebufferForSize:(CGSize)framebufferSize onlyTexture:(BOOL)onlyTexture; +{ + GPUTextureOptions defaultTextureOptions; + defaultTextureOptions.minFilter = GL_LINEAR; + defaultTextureOptions.magFilter = GL_LINEAR; + defaultTextureOptions.wrapS = GL_CLAMP_TO_EDGE; + defaultTextureOptions.wrapT = GL_CLAMP_TO_EDGE; + defaultTextureOptions.internalFormat = GL_RGBA; + defaultTextureOptions.format = GL_BGRA; + defaultTextureOptions.type = GL_UNSIGNED_BYTE; + + return [self fetchFramebufferForSize:framebufferSize textureOptions:defaultTextureOptions onlyTexture:onlyTexture]; +} + +- (void)returnFramebufferToCache:(GPUImageFramebuffer *)framebuffer; +{ + [framebuffer clearAllLocks]; + +// dispatch_async(framebufferCacheQueue, ^{ + runAsynchronouslyOnVideoProcessingQueue(^{ + CGSize framebufferSize = framebuffer.size; + GPUTextureOptions framebufferTextureOptions = framebuffer.textureOptions; + NSString *lookupHash = [self hashForSize:framebufferSize textureOptions:framebufferTextureOptions onlyTexture:framebuffer.missingFramebuffer]; + NSNumber *numberOfMatchingTexturesInCache = [framebufferTypeCounts objectForKey:lookupHash]; + NSInteger numberOfMatchingTextures = [numberOfMatchingTexturesInCache integerValue]; + + NSString *textureHash = [NSString stringWithFormat:@"%@-%ld", lookupHash, (long)numberOfMatchingTextures]; + +// [framebufferCache setObject:framebuffer forKey:textureHash cost:round(framebufferSize.width * framebufferSize.height * 4.0)]; + [framebufferCache setObject:framebuffer forKey:textureHash]; + [framebufferTypeCounts setObject:[NSNumber numberWithInteger:(numberOfMatchingTextures + 1)] forKey:lookupHash]; + }); +} + +- (void)purgeAllUnassignedFramebuffers; +{ + runAsynchronouslyOnVideoProcessingQueue(^{ +// dispatch_async(framebufferCacheQueue, ^{ + [framebufferCache removeAllObjects]; + [framebufferTypeCounts removeAllObjects]; +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + CVOpenGLESTextureCacheFlush([[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], 0); +#else +#endif + }); +} + +- (void)addFramebufferToActiveImageCaptureList:(GPUImageFramebuffer *)framebuffer; +{ + runAsynchronouslyOnVideoProcessingQueue(^{ +// dispatch_async(framebufferCacheQueue, ^{ + [activeImageCaptureList addObject:framebuffer]; + }); +} + +- (void)removeFramebufferFromActiveImageCaptureList:(GPUImageFramebuffer *)framebuffer; +{ + runAsynchronouslyOnVideoProcessingQueue(^{ +// dispatch_async(framebufferCacheQueue, ^{ + [activeImageCaptureList removeObject:framebuffer]; + }); +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageGammaFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageGammaFilter.h new file mode 100755 index 00000000..0521d089 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageGammaFilter.h @@ -0,0 +1,11 @@ +#import "GPUImageFilter.h" + +@interface GPUImageGammaFilter : GPUImageFilter +{ + GLint gammaUniform; +} + +// Gamma ranges from 0.0 to 3.0, with 1.0 as the normal level +@property(readwrite, nonatomic) CGFloat gamma; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageGammaFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageGammaFilter.m new file mode 100755 index 00000000..35adaba2 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageGammaFilter.m @@ -0,0 +1,66 @@ +#import "GPUImageGammaFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageGammaFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform lowp float gamma; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4(pow(textureColor.rgb, vec3(gamma)), textureColor.w); + } +); +#else +NSString *const kGPUImageGammaFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float gamma; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4(pow(textureColor.rgb, vec3(gamma)), textureColor.w); + } +); +#endif + +@implementation GPUImageGammaFilter + +@synthesize gamma = _gamma; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageGammaFragmentShaderString])) + { + return nil; + } + + gammaUniform = [filterProgram uniformIndex:@"gamma"]; + self.gamma = 1.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setGamma:(CGFloat)newValue; +{ + _gamma = newValue; + + [self setFloat:_gamma forUniform:gammaUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurFilter.h new file mode 100755 index 00000000..1fb7a137 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurFilter.h @@ -0,0 +1,36 @@ +#import "GPUImageTwoPassTextureSamplingFilter.h" + +/** A Gaussian blur filter + Interpolated optimization based on Daniel Rákos' work at http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/ + */ + +@interface GPUImageGaussianBlurFilter : GPUImageTwoPassTextureSamplingFilter +{ + BOOL shouldResizeBlurRadiusWithImageSize; + CGFloat _blurRadiusInPixels; +} + +/** A multiplier for the spacing between texels, ranging from 0.0 on up, with a default of 1.0. Adjusting this may slightly increase the blur strength, but will introduce artifacts in the result. + */ +@property (readwrite, nonatomic) CGFloat texelSpacingMultiplier; + +/** A radius in pixels to use for the blur, with a default of 2.0. This adjusts the sigma variable in the Gaussian distribution function. + */ +@property (readwrite, nonatomic) CGFloat blurRadiusInPixels; + +/** Setting these properties will allow the blur radius to scale with the size of the image. These properties are mutually exclusive; setting either will set the other to 0. + */ +@property (readwrite, nonatomic) CGFloat blurRadiusAsFractionOfImageWidth; +@property (readwrite, nonatomic) CGFloat blurRadiusAsFractionOfImageHeight; + +/// The number of times to sequentially blur the incoming image. The more passes, the slower the filter. +@property(readwrite, nonatomic) NSUInteger blurPasses; + ++ (NSString *)vertexShaderForStandardBlurOfRadius:(NSUInteger)blurRadius sigma:(CGFloat)sigma; ++ (NSString *)fragmentShaderForStandardBlurOfRadius:(NSUInteger)blurRadius sigma:(CGFloat)sigma; ++ (NSString *)vertexShaderForOptimizedBlurOfRadius:(NSUInteger)blurRadius sigma:(CGFloat)sigma; ++ (NSString *)fragmentShaderForOptimizedBlurOfRadius:(NSUInteger)blurRadius sigma:(CGFloat)sigma; + +- (void)switchToVertexShader:(NSString *)newVertexShader fragmentShader:(NSString *)newFragmentShader; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurFilter.m new file mode 100755 index 00000000..ec99352a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurFilter.m @@ -0,0 +1,513 @@ +#import "GPUImageGaussianBlurFilter.h" + +@implementation GPUImageGaussianBlurFilter + +@synthesize texelSpacingMultiplier = _texelSpacingMultiplier; +@synthesize blurRadiusInPixels = _blurRadiusInPixels; +@synthesize blurRadiusAsFractionOfImageWidth = _blurRadiusAsFractionOfImageWidth; +@synthesize blurRadiusAsFractionOfImageHeight = _blurRadiusAsFractionOfImageHeight; +@synthesize blurPasses = _blurPasses; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithFirstStageVertexShaderFromString:(NSString *)firstStageVertexShaderString firstStageFragmentShaderFromString:(NSString *)firstStageFragmentShaderString secondStageVertexShaderFromString:(NSString *)secondStageVertexShaderString secondStageFragmentShaderFromString:(NSString *)secondStageFragmentShaderString +{ + if (!(self = [super initWithFirstStageVertexShaderFromString:firstStageVertexShaderString firstStageFragmentShaderFromString:firstStageFragmentShaderString secondStageVertexShaderFromString:secondStageVertexShaderString secondStageFragmentShaderFromString:secondStageFragmentShaderString])) + { + return nil; + } + + self.texelSpacingMultiplier = 1.0; + _blurRadiusInPixels = 2.0; + shouldResizeBlurRadiusWithImageSize = NO; + + return self; +} + +- (id)init; +{ + NSString *currentGaussianBlurVertexShader = [[self class] vertexShaderForOptimizedBlurOfRadius:4 sigma:2.0]; + NSString *currentGaussianBlurFragmentShader = [[self class] fragmentShaderForOptimizedBlurOfRadius:4 sigma:2.0]; + + return [self initWithFirstStageVertexShaderFromString:currentGaussianBlurVertexShader firstStageFragmentShaderFromString:currentGaussianBlurFragmentShader secondStageVertexShaderFromString:currentGaussianBlurVertexShader secondStageFragmentShaderFromString:currentGaussianBlurFragmentShader]; +} + +#pragma mark - +#pragma mark Auto-generation of optimized Gaussian shaders + +// "Implementation limit of 32 varying components exceeded" - Max number of varyings for these GPUs + ++ (NSString *)vertexShaderForStandardBlurOfRadius:(NSUInteger)blurRadius sigma:(CGFloat)sigma; +{ + if (blurRadius < 1) + { + return kGPUImageVertexShaderString; + } + +// NSLog(@"Max varyings: %d", [GPUImageContext maximumVaryingVectorsForThisDevice]); + NSMutableString *shaderString = [[NSMutableString alloc] init]; + + // Header + [shaderString appendFormat:@"\ + attribute vec4 position;\n\ + attribute vec4 inputTextureCoordinate;\n\ + \n\ + uniform float texelWidthOffset;\n\ + uniform float texelHeightOffset;\n\ + \n\ + varying vec2 blurCoordinates[%lu];\n\ + \n\ + void main()\n\ + {\n\ + gl_Position = position;\n\ + \n\ + vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset);\n", (unsigned long)(blurRadius * 2 + 1) ]; + + // Inner offset loop + for (NSUInteger currentBlurCoordinateIndex = 0; currentBlurCoordinateIndex < (blurRadius * 2 + 1); currentBlurCoordinateIndex++) + { + NSInteger offsetFromCenter = currentBlurCoordinateIndex - blurRadius; + if (offsetFromCenter < 0) + { + [shaderString appendFormat:@"blurCoordinates[%ld] = inputTextureCoordinate.xy - singleStepOffset * %f;\n", (unsigned long)currentBlurCoordinateIndex, (GLfloat)(-offsetFromCenter)]; + } + else if (offsetFromCenter > 0) + { + [shaderString appendFormat:@"blurCoordinates[%ld] = inputTextureCoordinate.xy + singleStepOffset * %f;\n", (unsigned long)currentBlurCoordinateIndex, (GLfloat)(offsetFromCenter)]; + } + else + { + [shaderString appendFormat:@"blurCoordinates[%ld] = inputTextureCoordinate.xy;\n", (unsigned long)currentBlurCoordinateIndex]; + } + } + + // Footer + [shaderString appendString:@"}\n"]; + + return shaderString; +} + ++ (NSString *)fragmentShaderForStandardBlurOfRadius:(NSUInteger)blurRadius sigma:(CGFloat)sigma; +{ + if (blurRadius < 1) + { + return kGPUImagePassthroughFragmentShaderString; + } + + // First, generate the normal Gaussian weights for a given sigma + GLfloat *standardGaussianWeights = calloc(blurRadius + 1, sizeof(GLfloat)); + GLfloat sumOfWeights = 0.0; + for (NSUInteger currentGaussianWeightIndex = 0; currentGaussianWeightIndex < blurRadius + 1; currentGaussianWeightIndex++) + { + standardGaussianWeights[currentGaussianWeightIndex] = (1.0 / sqrt(2.0 * M_PI * pow(sigma, 2.0))) * exp(-pow(currentGaussianWeightIndex, 2.0) / (2.0 * pow(sigma, 2.0))); + + if (currentGaussianWeightIndex == 0) + { + sumOfWeights += standardGaussianWeights[currentGaussianWeightIndex]; + } + else + { + sumOfWeights += 2.0 * standardGaussianWeights[currentGaussianWeightIndex]; + } + } + + // Next, normalize these weights to prevent the clipping of the Gaussian curve at the end of the discrete samples from reducing luminance + for (NSUInteger currentGaussianWeightIndex = 0; currentGaussianWeightIndex < blurRadius + 1; currentGaussianWeightIndex++) + { + standardGaussianWeights[currentGaussianWeightIndex] = standardGaussianWeights[currentGaussianWeightIndex] / sumOfWeights; + } + + // Finally, generate the shader from these weights + NSMutableString *shaderString = [[NSMutableString alloc] init]; + + // Header +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [shaderString appendFormat:@"\ + uniform sampler2D inputImageTexture;\n\ + \n\ + varying highp vec2 blurCoordinates[%lu];\n\ + \n\ + void main()\n\ + {\n\ + lowp vec4 sum = vec4(0.0);\n", (unsigned long)(blurRadius * 2 + 1) ]; +#else + [shaderString appendFormat:@"\ + uniform sampler2D inputImageTexture;\n\ + \n\ + varying vec2 blurCoordinates[%lu];\n\ + \n\ + void main()\n\ + {\n\ + vec4 sum = vec4(0.0);\n", (blurRadius * 2 + 1) ]; +#endif + + // Inner texture loop + for (NSUInteger currentBlurCoordinateIndex = 0; currentBlurCoordinateIndex < (blurRadius * 2 + 1); currentBlurCoordinateIndex++) + { + NSInteger offsetFromCenter = currentBlurCoordinateIndex - blurRadius; + if (offsetFromCenter < 0) + { + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[%lu]) * %f;\n", (unsigned long)currentBlurCoordinateIndex, standardGaussianWeights[-offsetFromCenter]]; + } + else + { + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[%lu]) * %f;\n", (unsigned long)currentBlurCoordinateIndex, standardGaussianWeights[offsetFromCenter]]; + } + } + + // Footer + [shaderString appendString:@"\ + gl_FragColor = sum;\n\ + }\n"]; + + free(standardGaussianWeights); + return shaderString; +} + ++ (NSString *)vertexShaderForOptimizedBlurOfRadius:(NSUInteger)blurRadius sigma:(CGFloat)sigma; +{ + if (blurRadius < 1) + { + return kGPUImageVertexShaderString; + } + + // First, generate the normal Gaussian weights for a given sigma + GLfloat *standardGaussianWeights = calloc(blurRadius + 1, sizeof(GLfloat)); + GLfloat sumOfWeights = 0.0; + for (NSUInteger currentGaussianWeightIndex = 0; currentGaussianWeightIndex < blurRadius + 1; currentGaussianWeightIndex++) + { + standardGaussianWeights[currentGaussianWeightIndex] = (1.0 / sqrt(2.0 * M_PI * pow(sigma, 2.0))) * exp(-pow(currentGaussianWeightIndex, 2.0) / (2.0 * pow(sigma, 2.0))); + + if (currentGaussianWeightIndex == 0) + { + sumOfWeights += standardGaussianWeights[currentGaussianWeightIndex]; + } + else + { + sumOfWeights += 2.0 * standardGaussianWeights[currentGaussianWeightIndex]; + } + } + + // Next, normalize these weights to prevent the clipping of the Gaussian curve at the end of the discrete samples from reducing luminance + for (NSUInteger currentGaussianWeightIndex = 0; currentGaussianWeightIndex < blurRadius + 1; currentGaussianWeightIndex++) + { + standardGaussianWeights[currentGaussianWeightIndex] = standardGaussianWeights[currentGaussianWeightIndex] / sumOfWeights; + } + + // From these weights we calculate the offsets to read interpolated values from + NSUInteger numberOfOptimizedOffsets = MIN(blurRadius / 2 + (blurRadius % 2), 7); + GLfloat *optimizedGaussianOffsets = calloc(numberOfOptimizedOffsets, sizeof(GLfloat)); + + for (NSUInteger currentOptimizedOffset = 0; currentOptimizedOffset < numberOfOptimizedOffsets; currentOptimizedOffset++) + { + GLfloat firstWeight = standardGaussianWeights[currentOptimizedOffset*2 + 1]; + GLfloat secondWeight = standardGaussianWeights[currentOptimizedOffset*2 + 2]; + + GLfloat optimizedWeight = firstWeight + secondWeight; + + optimizedGaussianOffsets[currentOptimizedOffset] = (firstWeight * (currentOptimizedOffset*2 + 1) + secondWeight * (currentOptimizedOffset*2 + 2)) / optimizedWeight; + } + + NSMutableString *shaderString = [[NSMutableString alloc] init]; + // Header + [shaderString appendFormat:@"\ + attribute vec4 position;\n\ + attribute vec4 inputTextureCoordinate;\n\ + \n\ + uniform float texelWidthOffset;\n\ + uniform float texelHeightOffset;\n\ + \n\ + varying vec2 blurCoordinates[%lu];\n\ + \n\ + void main()\n\ + {\n\ + gl_Position = position;\n\ + \n\ + vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset);\n", (unsigned long)(1 + (numberOfOptimizedOffsets * 2))]; + + // Inner offset loop + [shaderString appendString:@"blurCoordinates[0] = inputTextureCoordinate.xy;\n"]; + for (NSUInteger currentOptimizedOffset = 0; currentOptimizedOffset < numberOfOptimizedOffsets; currentOptimizedOffset++) + { + [shaderString appendFormat:@"\ + blurCoordinates[%lu] = inputTextureCoordinate.xy + singleStepOffset * %f;\n\ + blurCoordinates[%lu] = inputTextureCoordinate.xy - singleStepOffset * %f;\n", (unsigned long)((currentOptimizedOffset * 2) + 1), optimizedGaussianOffsets[currentOptimizedOffset], (unsigned long)((currentOptimizedOffset * 2) + 2), optimizedGaussianOffsets[currentOptimizedOffset]]; + } + + // Footer + [shaderString appendString:@"}\n"]; + + free(optimizedGaussianOffsets); + free(standardGaussianWeights); + return shaderString; +} + ++ (NSString *)fragmentShaderForOptimizedBlurOfRadius:(NSUInteger)blurRadius sigma:(CGFloat)sigma; +{ + if (blurRadius < 1) + { + return kGPUImagePassthroughFragmentShaderString; + } + + // First, generate the normal Gaussian weights for a given sigma + GLfloat *standardGaussianWeights = calloc(blurRadius + 1, sizeof(GLfloat)); + GLfloat sumOfWeights = 0.0; + for (NSUInteger currentGaussianWeightIndex = 0; currentGaussianWeightIndex < blurRadius + 1; currentGaussianWeightIndex++) + { + standardGaussianWeights[currentGaussianWeightIndex] = (1.0 / sqrt(2.0 * M_PI * pow(sigma, 2.0))) * exp(-pow(currentGaussianWeightIndex, 2.0) / (2.0 * pow(sigma, 2.0))); + + if (currentGaussianWeightIndex == 0) + { + sumOfWeights += standardGaussianWeights[currentGaussianWeightIndex]; + } + else + { + sumOfWeights += 2.0 * standardGaussianWeights[currentGaussianWeightIndex]; + } + } + + // Next, normalize these weights to prevent the clipping of the Gaussian curve at the end of the discrete samples from reducing luminance + for (NSUInteger currentGaussianWeightIndex = 0; currentGaussianWeightIndex < blurRadius + 1; currentGaussianWeightIndex++) + { + standardGaussianWeights[currentGaussianWeightIndex] = standardGaussianWeights[currentGaussianWeightIndex] / sumOfWeights; + } + + // From these weights we calculate the offsets to read interpolated values from + NSUInteger numberOfOptimizedOffsets = MIN(blurRadius / 2 + (blurRadius % 2), 7); + NSUInteger trueNumberOfOptimizedOffsets = blurRadius / 2 + (blurRadius % 2); + + NSMutableString *shaderString = [[NSMutableString alloc] init]; + + // Header +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [shaderString appendFormat:@"\ + uniform sampler2D inputImageTexture;\n\ + uniform highp float texelWidthOffset;\n\ + uniform highp float texelHeightOffset;\n\ + \n\ + varying highp vec2 blurCoordinates[%lu];\n\ + \n\ + void main()\n\ + {\n\ + lowp vec4 sum = vec4(0.0);\n", (unsigned long)(1 + (numberOfOptimizedOffsets * 2)) ]; +#else + [shaderString appendFormat:@"\ + uniform sampler2D inputImageTexture;\n\ + uniform float texelWidthOffset;\n\ + uniform float texelHeightOffset;\n\ + \n\ + varying vec2 blurCoordinates[%lu];\n\ + \n\ + void main()\n\ + {\n\ + vec4 sum = vec4(0.0);\n", 1 + (numberOfOptimizedOffsets * 2) ]; +#endif + + // Inner texture loop + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[0]) * %f;\n", standardGaussianWeights[0]]; + + for (NSUInteger currentBlurCoordinateIndex = 0; currentBlurCoordinateIndex < numberOfOptimizedOffsets; currentBlurCoordinateIndex++) + { + GLfloat firstWeight = standardGaussianWeights[currentBlurCoordinateIndex * 2 + 1]; + GLfloat secondWeight = standardGaussianWeights[currentBlurCoordinateIndex * 2 + 2]; + GLfloat optimizedWeight = firstWeight + secondWeight; + + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[%lu]) * %f;\n", (unsigned long)((currentBlurCoordinateIndex * 2) + 1), optimizedWeight]; + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[%lu]) * %f;\n", (unsigned long)((currentBlurCoordinateIndex * 2) + 2), optimizedWeight]; + } + + // If the number of required samples exceeds the amount we can pass in via varyings, we have to do dependent texture reads in the fragment shader + if (trueNumberOfOptimizedOffsets > numberOfOptimizedOffsets) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [shaderString appendString:@"highp vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset);\n"]; +#else + [shaderString appendString:@"vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset);\n"]; +#endif + + for (NSUInteger currentOverlowTextureRead = numberOfOptimizedOffsets; currentOverlowTextureRead < trueNumberOfOptimizedOffsets; currentOverlowTextureRead++) + { + GLfloat firstWeight = standardGaussianWeights[currentOverlowTextureRead * 2 + 1]; + GLfloat secondWeight = standardGaussianWeights[currentOverlowTextureRead * 2 + 2]; + + GLfloat optimizedWeight = firstWeight + secondWeight; + GLfloat optimizedOffset = (firstWeight * (currentOverlowTextureRead * 2 + 1) + secondWeight * (currentOverlowTextureRead * 2 + 2)) / optimizedWeight; + + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[0] + singleStepOffset * %f) * %f;\n", optimizedOffset, optimizedWeight]; + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[0] - singleStepOffset * %f) * %f;\n", optimizedOffset, optimizedWeight]; + } + } + + // Footer + [shaderString appendString:@"\ + gl_FragColor = sum;\n\ + }\n"]; + + free(standardGaussianWeights); + return shaderString; +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + [super setupFilterForSize:filterFrameSize]; + + if (shouldResizeBlurRadiusWithImageSize) + { + if (self.blurRadiusAsFractionOfImageWidth > 0) + { + self.blurRadiusInPixels = filterFrameSize.width * self.blurRadiusAsFractionOfImageWidth; + } + else + { + self.blurRadiusInPixels = filterFrameSize.height * self.blurRadiusAsFractionOfImageHeight; + } + } +} + +#pragma mark - +#pragma mark Rendering + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + [super renderToTextureWithVertices:vertices textureCoordinates:textureCoordinates]; + + for (NSUInteger currentAdditionalBlurPass = 1; currentAdditionalBlurPass < _blurPasses; currentAdditionalBlurPass++) + { + [super renderToTextureWithVertices:vertices textureCoordinates:[[self class] textureCoordinatesForRotation:kGPUImageNoRotation]]; + } +} + +- (void)switchToVertexShader:(NSString *)newVertexShader fragmentShader:(NSString *)newFragmentShader; +{ + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + + filterProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:newVertexShader fragmentShaderString:newFragmentShader]; + + if (!filterProgram.initialized) + { + [self initializeAttributes]; + + if (![filterProgram link]) + { + NSString *progLog = [filterProgram programLog]; + NSLog(@"Program link log: %@", progLog); + NSString *fragLog = [filterProgram fragmentShaderLog]; + NSLog(@"Fragment shader compile log: %@", fragLog); + NSString *vertLog = [filterProgram vertexShaderLog]; + NSLog(@"Vertex shader compile log: %@", vertLog); + filterProgram = nil; + NSAssert(NO, @"Filter shader link failed"); + } + } + + filterPositionAttribute = [filterProgram attributeIndex:@"position"]; + filterTextureCoordinateAttribute = [filterProgram attributeIndex:@"inputTextureCoordinate"]; + filterInputTextureUniform = [filterProgram uniformIndex:@"inputImageTexture"]; // This does assume a name of "inputImageTexture" for the fragment shader + verticalPassTexelWidthOffsetUniform = [filterProgram uniformIndex:@"texelWidthOffset"]; + verticalPassTexelHeightOffsetUniform = [filterProgram uniformIndex:@"texelHeightOffset"]; + [GPUImageContext setActiveShaderProgram:filterProgram]; + + glEnableVertexAttribArray(filterPositionAttribute); + glEnableVertexAttribArray(filterTextureCoordinateAttribute); + + secondFilterProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:newVertexShader fragmentShaderString:newFragmentShader]; + + if (!secondFilterProgram.initialized) + { + [self initializeSecondaryAttributes]; + + if (![secondFilterProgram link]) + { + NSString *progLog = [secondFilterProgram programLog]; + NSLog(@"Program link log: %@", progLog); + NSString *fragLog = [secondFilterProgram fragmentShaderLog]; + NSLog(@"Fragment shader compile log: %@", fragLog); + NSString *vertLog = [secondFilterProgram vertexShaderLog]; + NSLog(@"Vertex shader compile log: %@", vertLog); + secondFilterProgram = nil; + NSAssert(NO, @"Filter shader link failed"); + } + } + + secondFilterPositionAttribute = [secondFilterProgram attributeIndex:@"position"]; + secondFilterTextureCoordinateAttribute = [secondFilterProgram attributeIndex:@"inputTextureCoordinate"]; + secondFilterInputTextureUniform = [secondFilterProgram uniformIndex:@"inputImageTexture"]; // This does assume a name of "inputImageTexture" for the fragment shader + secondFilterInputTextureUniform2 = [secondFilterProgram uniformIndex:@"inputImageTexture2"]; // This does assume a name of "inputImageTexture2" for second input texture in the fragment shader + horizontalPassTexelWidthOffsetUniform = [secondFilterProgram uniformIndex:@"texelWidthOffset"]; + horizontalPassTexelHeightOffsetUniform = [secondFilterProgram uniformIndex:@"texelHeightOffset"]; + [GPUImageContext setActiveShaderProgram:secondFilterProgram]; + + glEnableVertexAttribArray(secondFilterPositionAttribute); + glEnableVertexAttribArray(secondFilterTextureCoordinateAttribute); + + [self setupFilterForSize:[self sizeOfFBO]]; + glFinish(); + }); + +} + +#pragma mark - +#pragma mark Accessors + +- (void)setTexelSpacingMultiplier:(CGFloat)newValue; +{ + _texelSpacingMultiplier = newValue; + + _verticalTexelSpacing = _texelSpacingMultiplier; + _horizontalTexelSpacing = _texelSpacingMultiplier; + + [self setupFilterForSize:[self sizeOfFBO]]; +} + +// inputRadius for Core Image's CIGaussianBlur is really sigma in the Gaussian equation, so I'm using that for my blur radius, to be consistent +- (void)setBlurRadiusInPixels:(CGFloat)newValue; +{ + // 7.0 is the limit for blur size for hardcoded varying offsets + + if (round(newValue) != _blurRadiusInPixels) + { + _blurRadiusInPixels = round(newValue); // For now, only do integral sigmas + + NSUInteger calculatedSampleRadius = 0; + if (_blurRadiusInPixels >= 1) // Avoid a divide-by-zero error here + { + // Calculate the number of pixels to sample from by setting a bottom limit for the contribution of the outermost pixel + CGFloat minimumWeightToFindEdgeOfSamplingArea = 1.0/256.0; + calculatedSampleRadius = floor(sqrt(-2.0 * pow(_blurRadiusInPixels, 2.0) * log(minimumWeightToFindEdgeOfSamplingArea * sqrt(2.0 * M_PI * pow(_blurRadiusInPixels, 2.0))) )); + calculatedSampleRadius += calculatedSampleRadius % 2; // There's nothing to gain from handling odd radius sizes, due to the optimizations I use + } + +// NSLog(@"Blur radius: %f, calculated sample radius: %d", _blurRadiusInPixels, calculatedSampleRadius); +// + NSString *newGaussianBlurVertexShader = [[self class] vertexShaderForOptimizedBlurOfRadius:calculatedSampleRadius sigma:_blurRadiusInPixels]; + NSString *newGaussianBlurFragmentShader = [[self class] fragmentShaderForOptimizedBlurOfRadius:calculatedSampleRadius sigma:_blurRadiusInPixels]; + +// NSLog(@"Optimized vertex shader: \n%@", newGaussianBlurVertexShader); +// NSLog(@"Optimized fragment shader: \n%@", newGaussianBlurFragmentShader); +// + [self switchToVertexShader:newGaussianBlurVertexShader fragmentShader:newGaussianBlurFragmentShader]; + } + shouldResizeBlurRadiusWithImageSize = NO; +} + +- (void)setBlurRadiusAsFractionOfImageWidth:(CGFloat)blurRadiusAsFractionOfImageWidth +{ + if (blurRadiusAsFractionOfImageWidth < 0) return; + + shouldResizeBlurRadiusWithImageSize = _blurRadiusAsFractionOfImageWidth != blurRadiusAsFractionOfImageWidth && blurRadiusAsFractionOfImageWidth > 0; + _blurRadiusAsFractionOfImageWidth = blurRadiusAsFractionOfImageWidth; + _blurRadiusAsFractionOfImageHeight = 0; +} + +- (void)setBlurRadiusAsFractionOfImageHeight:(CGFloat)blurRadiusAsFractionOfImageHeight +{ + if (blurRadiusAsFractionOfImageHeight < 0) return; + + shouldResizeBlurRadiusWithImageSize = _blurRadiusAsFractionOfImageHeight != blurRadiusAsFractionOfImageHeight && blurRadiusAsFractionOfImageHeight > 0; + _blurRadiusAsFractionOfImageHeight = blurRadiusAsFractionOfImageHeight; + _blurRadiusAsFractionOfImageWidth = 0; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurPositionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurPositionFilter.h new file mode 100755 index 00000000..dc88a563 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurPositionFilter.h @@ -0,0 +1,22 @@ +#import "GPUImageTwoPassTextureSamplingFilter.h" + +/** A more generalized 9x9 Gaussian blur filter + */ +@interface GPUImageGaussianBlurPositionFilter : GPUImageTwoPassTextureSamplingFilter +{ + GLint blurCenterUniform, blurRadiusUniform, aspectRatioUniform; +} + +/** A multiplier for the blur size, ranging from 0.0 on up, with a default of 1.0 + */ +@property (readwrite, nonatomic) CGFloat blurSize; + +/** Center for the blur, defaults to 0.5, 0.5 + */ +@property (readwrite, nonatomic) CGPoint blurCenter; + +/** Radius for the blur, defaults to 1.0 + */ +@property (readwrite, nonatomic) CGFloat blurRadius; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurPositionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurPositionFilter.m new file mode 100755 index 00000000..8ecd9246 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianBlurPositionFilter.m @@ -0,0 +1,232 @@ +#import "GPUImageGaussianBlurPositionFilter.h" + +NSString *const kGPUImageGaussianBlurPositionVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + + const int GAUSSIAN_SAMPLES = 9; + + uniform float texelWidthOffset; + uniform float texelHeightOffset; + varying vec2 textureCoordinate; + varying vec2 blurCoordinates[GAUSSIAN_SAMPLES]; + + void main() + { + gl_Position = position; + textureCoordinate = inputTextureCoordinate.xy; + + // Calculate the positions for the blur + int multiplier = 0; + vec2 blurStep; + vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset); + + for (int i = 0; i < GAUSSIAN_SAMPLES; i++) { + multiplier = (i - ((GAUSSIAN_SAMPLES - 1) / 2)); + // Blur in x (horizontal) + blurStep = float(multiplier) * singleStepOffset; + blurCoordinates[i] = inputTextureCoordinate.xy + blurStep; + } + } +); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageGaussianBlurPositionFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + const lowp int GAUSSIAN_SAMPLES = 9; + + varying highp vec2 textureCoordinate; + varying highp vec2 blurCoordinates[GAUSSIAN_SAMPLES]; + + uniform highp float aspectRatio; + uniform lowp vec2 blurCenter; + uniform highp float blurRadius; + + void main() { + highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + highp float dist = distance(blurCenter, textureCoordinateToUse); + + if (dist < blurRadius) + { + lowp vec4 sum = vec4(0.0); + + sum += texture2D(inputImageTexture, blurCoordinates[0]) * 0.05; + sum += texture2D(inputImageTexture, blurCoordinates[1]) * 0.09; + sum += texture2D(inputImageTexture, blurCoordinates[2]) * 0.12; + sum += texture2D(inputImageTexture, blurCoordinates[3]) * 0.15; + sum += texture2D(inputImageTexture, blurCoordinates[4]) * 0.18; + sum += texture2D(inputImageTexture, blurCoordinates[5]) * 0.15; + sum += texture2D(inputImageTexture, blurCoordinates[6]) * 0.12; + sum += texture2D(inputImageTexture, blurCoordinates[7]) * 0.09; + sum += texture2D(inputImageTexture, blurCoordinates[8]) * 0.05; + + gl_FragColor = sum; + } + else + { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate); + } + } +); +#else +NSString *const kGPUImageGaussianBlurPositionFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + const int GAUSSIAN_SAMPLES = 9; + + varying vec2 textureCoordinate; + varying vec2 blurCoordinates[GAUSSIAN_SAMPLES]; + + uniform float aspectRatio; + uniform vec2 blurCenter; + uniform float blurRadius; + + void main() + { + vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + float dist = distance(blurCenter, textureCoordinateToUse); + + if (dist < blurRadius) + { + vec4 sum = vec4(0.0); + + sum += texture2D(inputImageTexture, blurCoordinates[0]) * 0.05; + sum += texture2D(inputImageTexture, blurCoordinates[1]) * 0.09; + sum += texture2D(inputImageTexture, blurCoordinates[2]) * 0.12; + sum += texture2D(inputImageTexture, blurCoordinates[3]) * 0.15; + sum += texture2D(inputImageTexture, blurCoordinates[4]) * 0.18; + sum += texture2D(inputImageTexture, blurCoordinates[5]) * 0.15; + sum += texture2D(inputImageTexture, blurCoordinates[6]) * 0.12; + sum += texture2D(inputImageTexture, blurCoordinates[7]) * 0.09; + sum += texture2D(inputImageTexture, blurCoordinates[8]) * 0.05; + + gl_FragColor = sum; + } + else + { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate); + } + } +); +#endif + +@interface GPUImageGaussianBlurPositionFilter () + +- (void)adjustAspectRatio; + +@property (readwrite, nonatomic) CGFloat aspectRatio; + +@end + +@implementation GPUImageGaussianBlurPositionFilter + +@synthesize blurSize = _blurSize; +@synthesize blurCenter = _blurCenter; +@synthesize aspectRatio = _aspectRatio; + +- (id) initWithFirstStageVertexShaderFromString:(NSString *)firstStageVertexShaderString + firstStageFragmentShaderFromString:(NSString *)firstStageFragmentShaderString + secondStageVertexShaderFromString:(NSString *)secondStageVertexShaderString + secondStageFragmentShaderFromString:(NSString *)secondStageFragmentShaderString { + + if (!(self = [super initWithFirstStageVertexShaderFromString:firstStageVertexShaderString ? firstStageVertexShaderString : kGPUImageGaussianBlurPositionVertexShaderString + firstStageFragmentShaderFromString:firstStageFragmentShaderString ? firstStageFragmentShaderString : kGPUImageGaussianBlurPositionFragmentShaderString + secondStageVertexShaderFromString:secondStageVertexShaderString ? secondStageVertexShaderString : kGPUImageGaussianBlurPositionVertexShaderString + secondStageFragmentShaderFromString:secondStageFragmentShaderString ? secondStageFragmentShaderString : kGPUImageGaussianBlurPositionFragmentShaderString])) { + return nil; + } + + aspectRatioUniform = [secondFilterProgram uniformIndex:@"aspectRatio"]; + blurCenterUniform = [secondFilterProgram uniformIndex:@"blurCenter"]; + blurRadiusUniform = [secondFilterProgram uniformIndex:@"blurRadius"]; + + self.blurSize = 1.0; + self.blurRadius = 1.0; + self.blurCenter = CGPointMake(0.5, 0.5); + + return self; +} + +- (id)init; +{ + return [self initWithFirstStageVertexShaderFromString:nil + firstStageFragmentShaderFromString:nil + secondStageVertexShaderFromString:nil + secondStageFragmentShaderFromString:nil]; +} + +- (void)adjustAspectRatio; +{ + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + [self setAspectRatio:(inputTextureSize.width / inputTextureSize.height)]; + } + else + { + [self setAspectRatio:(inputTextureSize.height / inputTextureSize.width)]; + } +} + +- (void)forceProcessingAtSize:(CGSize)frameSize; +{ + [super forceProcessingAtSize:frameSize]; + [self adjustAspectRatio]; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + CGSize oldInputSize = inputTextureSize; + [super setInputSize:newSize atIndex:textureIndex]; + + if ( (!CGSizeEqualToSize(oldInputSize, inputTextureSize)) && (!CGSizeEqualToSize(newSize, CGSizeZero)) ) + { + [self adjustAspectRatio]; + } +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + [super setInputRotation:newInputRotation atIndex:textureIndex]; + [self setBlurCenter:self.blurCenter]; + [self adjustAspectRatio]; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBlurSize:(CGFloat)newValue; +{ + _blurSize = newValue; + + _verticalTexelSpacing = _blurSize; + _horizontalTexelSpacing = _blurSize; + + [self setupFilterForSize:[self sizeOfFBO]]; +} + +- (void) setBlurCenter:(CGPoint)blurCenter; +{ + _blurCenter = blurCenter; + CGPoint rotatedPoint = [self rotatedPoint:blurCenter forRotation:inputRotation]; + [self setPoint:rotatedPoint forUniform:blurCenterUniform program:secondFilterProgram]; +} + +- (void) setBlurRadius:(CGFloat)blurRadius; +{ + _blurRadius = blurRadius; + + [self setFloat:_blurRadius forUniform:blurRadiusUniform program:secondFilterProgram]; +} + +- (void) setAspectRatio:(CGFloat)newValue; +{ + _aspectRatio = newValue; + + [self setFloat:_aspectRatio forUniform:aspectRatioUniform program:secondFilterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageGaussianSelectiveBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianSelectiveBlurFilter.h new file mode 100755 index 00000000..02324566 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianSelectiveBlurFilter.h @@ -0,0 +1,30 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImageGaussianBlurFilter; + +/** A Gaussian blur that preserves focus within a circular region + */ +@interface GPUImageGaussianSelectiveBlurFilter : GPUImageFilterGroup +{ + GPUImageGaussianBlurFilter *blurFilter; + GPUImageFilter *selectiveFocusFilter; + BOOL hasOverriddenAspectRatio; +} + +/** The radius of the circular area being excluded from the blur + */ +@property (readwrite, nonatomic) CGFloat excludeCircleRadius; +/** The center of the circular area being excluded from the blur + */ +@property (readwrite, nonatomic) CGPoint excludeCirclePoint; +/** The size of the area between the blurred portion and the clear circle + */ +@property (readwrite, nonatomic) CGFloat excludeBlurSize; +/** A radius in pixels to use for the blur, with a default of 5.0. This adjusts the sigma variable in the Gaussian distribution function. + */ +@property (readwrite, nonatomic) CGFloat blurRadiusInPixels; +/** The aspect ratio of the image, used to adjust the circularity of the in-focus region. By default, this matches the image aspect ratio, but you can override this value. + */ +@property (readwrite, nonatomic) CGFloat aspectRatio; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageGaussianSelectiveBlurFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianSelectiveBlurFilter.m new file mode 100755 index 00000000..7ebc9e19 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageGaussianSelectiveBlurFilter.m @@ -0,0 +1,147 @@ +#import "GPUImageGaussianSelectiveBlurFilter.h" +#import "GPUImageGaussianBlurFilter.h" +#import "GPUImageTwoInputFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageGaussianSelectiveBlurFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform lowp float excludeCircleRadius; + uniform lowp vec2 excludeCirclePoint; + uniform lowp float excludeBlurSize; + uniform highp float aspectRatio; + + void main() + { + lowp vec4 sharpImageColor = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 blurredImageColor = texture2D(inputImageTexture2, textureCoordinate2); + + highp vec2 textureCoordinateToUse = vec2(textureCoordinate2.x, (textureCoordinate2.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + highp float distanceFromCenter = distance(excludeCirclePoint, textureCoordinateToUse); + + gl_FragColor = mix(sharpImageColor, blurredImageColor, smoothstep(excludeCircleRadius - excludeBlurSize, excludeCircleRadius, distanceFromCenter)); + } +); +#else +NSString *const kGPUImageGaussianSelectiveBlurFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform float excludeCircleRadius; + uniform vec2 excludeCirclePoint; + uniform float excludeBlurSize; + uniform float aspectRatio; + + void main() + { + vec4 sharpImageColor = texture2D(inputImageTexture, textureCoordinate); + vec4 blurredImageColor = texture2D(inputImageTexture2, textureCoordinate2); + + vec2 textureCoordinateToUse = vec2(textureCoordinate2.x, (textureCoordinate2.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + float distanceFromCenter = distance(excludeCirclePoint, textureCoordinateToUse); + + gl_FragColor = mix(sharpImageColor, blurredImageColor, smoothstep(excludeCircleRadius - excludeBlurSize, excludeCircleRadius, distanceFromCenter)); + } +); +#endif + +@implementation GPUImageGaussianSelectiveBlurFilter + +@synthesize excludeCirclePoint = _excludeCirclePoint, excludeCircleRadius = _excludeCircleRadius, excludeBlurSize = _excludeBlurSize; +@synthesize blurRadiusInPixels = _blurRadiusInPixels; +@synthesize aspectRatio = _aspectRatio; + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + hasOverriddenAspectRatio = NO; + + // First pass: apply a variable Gaussian blur + blurFilter = [[GPUImageGaussianBlurFilter alloc] init]; + [self addFilter:blurFilter]; + + // Second pass: combine the blurred image with the original sharp one + selectiveFocusFilter = [[GPUImageTwoInputFilter alloc] initWithFragmentShaderFromString:kGPUImageGaussianSelectiveBlurFragmentShaderString]; + [self addFilter:selectiveFocusFilter]; + + // Texture location 0 needs to be the sharp image for both the blur and the second stage processing + [blurFilter addTarget:selectiveFocusFilter atTextureLocation:1]; + + // To prevent double updating of this filter, disable updates from the sharp image side + self.initialFilters = [NSArray arrayWithObjects:blurFilter, selectiveFocusFilter, nil]; + self.terminalFilter = selectiveFocusFilter; + + self.blurRadiusInPixels = 5.0; + + self.excludeCircleRadius = 60.0/320.0; + self.excludeCirclePoint = CGPointMake(0.5f, 0.5f); + self.excludeBlurSize = 30.0/320.0; + + return self; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + CGSize oldInputSize = inputTextureSize; + [super setInputSize:newSize atIndex:textureIndex]; + inputTextureSize = newSize; + + if ( (!CGSizeEqualToSize(oldInputSize, inputTextureSize)) && (!hasOverriddenAspectRatio) && (!CGSizeEqualToSize(newSize, CGSizeZero)) ) + { + _aspectRatio = (inputTextureSize.width / inputTextureSize.height); + [selectiveFocusFilter setFloat:_aspectRatio forUniformName:@"aspectRatio"]; + } +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBlurRadiusInPixels:(CGFloat)newValue; +{ + blurFilter.blurRadiusInPixels = newValue; +} + +- (CGFloat)blurRadiusInPixels; +{ + return blurFilter.blurRadiusInPixels; +} + +- (void)setExcludeCirclePoint:(CGPoint)newValue; +{ + _excludeCirclePoint = newValue; + [selectiveFocusFilter setPoint:newValue forUniformName:@"excludeCirclePoint"]; +} + +- (void)setExcludeCircleRadius:(CGFloat)newValue; +{ + _excludeCircleRadius = newValue; + [selectiveFocusFilter setFloat:newValue forUniformName:@"excludeCircleRadius"]; +} + +- (void)setExcludeBlurSize:(CGFloat)newValue; +{ + _excludeBlurSize = newValue; + [selectiveFocusFilter setFloat:newValue forUniformName:@"excludeBlurSize"]; +} + +- (void)setAspectRatio:(CGFloat)newValue; +{ + hasOverriddenAspectRatio = YES; + _aspectRatio = newValue; + [selectiveFocusFilter setFloat:_aspectRatio forUniformName:@"aspectRatio"]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageGlassSphereFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageGlassSphereFilter.h new file mode 100644 index 00000000..809a4ee8 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageGlassSphereFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageSphereRefractionFilter.h" + +@interface GPUImageGlassSphereFilter : GPUImageSphereRefractionFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageGlassSphereFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageGlassSphereFilter.m new file mode 100644 index 00000000..18662916 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageGlassSphereFilter.m @@ -0,0 +1,106 @@ +#import "GPUImageGlassSphereFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageGlassSphereFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp vec2 center; + uniform highp float radius; + uniform highp float aspectRatio; + uniform highp float refractiveIndex; +// uniform vec3 lightPosition; + const highp vec3 lightPosition = vec3(-0.5, 0.5, 1.0); + const highp vec3 ambientLightPosition = vec3(0.0, 0.0, 1.0); + + void main() + { + highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + highp float distanceFromCenter = distance(center, textureCoordinateToUse); + lowp float checkForPresenceWithinSphere = step(distanceFromCenter, radius); + + distanceFromCenter = distanceFromCenter / radius; + + highp float normalizedDepth = radius * sqrt(1.0 - distanceFromCenter * distanceFromCenter); + highp vec3 sphereNormal = normalize(vec3(textureCoordinateToUse - center, normalizedDepth)); + + highp vec3 refractedVector = 2.0 * refract(vec3(0.0, 0.0, -1.0), sphereNormal, refractiveIndex); + refractedVector.xy = -refractedVector.xy; + + highp vec3 finalSphereColor = texture2D(inputImageTexture, (refractedVector.xy + 1.0) * 0.5).rgb; + + // Grazing angle lighting + highp float lightingIntensity = 2.5 * (1.0 - pow(clamp(dot(ambientLightPosition, sphereNormal), 0.0, 1.0), 0.25)); + finalSphereColor += lightingIntensity; + + // Specular lighting + lightingIntensity = clamp(dot(normalize(lightPosition), sphereNormal), 0.0, 1.0); + lightingIntensity = pow(lightingIntensity, 15.0); + finalSphereColor += vec3(0.8, 0.8, 0.8) * lightingIntensity; + + gl_FragColor = vec4(finalSphereColor, 1.0) * checkForPresenceWithinSphere; + } +); +#else +NSString *const kGPUImageGlassSphereFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform vec2 center; + uniform float radius; + uniform float aspectRatio; + uniform float refractiveIndex; + // uniform vec3 lightPosition; + const vec3 lightPosition = vec3(-0.5, 0.5, 1.0); + const vec3 ambientLightPosition = vec3(0.0, 0.0, 1.0); + + void main() + { + vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + float distanceFromCenter = distance(center, textureCoordinateToUse); + float checkForPresenceWithinSphere = step(distanceFromCenter, radius); + + distanceFromCenter = distanceFromCenter / radius; + + float normalizedDepth = radius * sqrt(1.0 - distanceFromCenter * distanceFromCenter); + vec3 sphereNormal = normalize(vec3(textureCoordinateToUse - center, normalizedDepth)); + + vec3 refractedVector = 2.0 * refract(vec3(0.0, 0.0, -1.0), sphereNormal, refractiveIndex); + refractedVector.xy = -refractedVector.xy; + + vec3 finalSphereColor = texture2D(inputImageTexture, (refractedVector.xy + 1.0) * 0.5).rgb; + + // Grazing angle lighting + float lightingIntensity = 2.5 * (1.0 - pow(clamp(dot(ambientLightPosition, sphereNormal), 0.0, 1.0), 0.25)); + finalSphereColor += lightingIntensity; + + // Specular lighting + lightingIntensity = clamp(dot(normalize(lightPosition), sphereNormal), 0.0, 1.0); + lightingIntensity = pow(lightingIntensity, 15.0); + finalSphereColor += vec3(0.8, 0.8, 0.8) * lightingIntensity; + + gl_FragColor = vec4(finalSphereColor, 1.0) * checkForPresenceWithinSphere; + } +); +#endif + +@implementation GPUImageGlassSphereFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageGlassSphereFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageGrayscaleFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageGrayscaleFilter.h new file mode 100755 index 00000000..2d97f8c3 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageGrayscaleFilter.h @@ -0,0 +1,9 @@ +#import "GPUImageFilter.h" + +extern NSString *const kGPUImageLuminanceFragmentShaderString; + +/** Converts an image to grayscale (a slightly faster implementation of the saturation filter, without the ability to vary the color contribution) + */ +@interface GPUImageGrayscaleFilter : GPUImageFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageGrayscaleFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageGrayscaleFilter.m new file mode 100755 index 00000000..0066ca87 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageGrayscaleFilter.m @@ -0,0 +1,141 @@ +#import "GPUImageGrayscaleFilter.h" + +@implementation GPUImageGrayscaleFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLuminanceFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, W); + + gl_FragColor = vec4(vec3(luminance), textureColor.a); + } +); +#else +NSString *const kGPUImageLuminanceFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, W); + + gl_FragColor = vec4(vec3(luminance), textureColor.a); + } +); +#endif + + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + if (!currentlyReceivingMonochromeInput) + { + [super renderToTextureWithVertices:vertices textureCoordinates:textureCoordinates]; + } +} + +//- (void)setInputTexture:(GLuint)newInputTexture atIndex:(NSInteger)textureIndex; +//{ +// [super setInputTexture:newInputTexture atIndex:textureIndex]; +// if (currentlyReceivingMonochromeInput) +// { +// [self notifyTargetsAboutNewOutputTexture]; +// } +//} + +//- (GLuint)textureForOutput; +//{ +// if (currentlyReceivingMonochromeInput) +// { +// return filterSourceTexture; +// } +// else +// { +// return outputTexture; +// } +//} + +- (BOOL)wantsMonochromeInput; +{ +// return YES; + return NO; +} + +- (BOOL)providesMonochromeOutput; +{ +// return YES; + return NO; +} + +// TODO: Rewrite this based on the new GPUImageFilter implementation +//- (void)informTargetsAboutNewFrameAtTime:(CMTime)frameTime; +//{ +// if (self.frameProcessingCompletionBlock != NULL) +// { +// self.frameProcessingCompletionBlock(self, frameTime); +// } +// +// for (id currentTarget in targets) +// { +// if (currentTarget != self.targetToIgnoreForUpdates) +// { +// NSInteger indexOfObject = [targets indexOfObject:currentTarget]; +// NSInteger textureIndex = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; +// +// if ([GPUImageContext supportsFastTextureUpload] && preparedToCaptureImage) +// { +// [self setInputTextureForTarget:currentTarget atIndex:textureIndex]; +// } +// +// if (currentlyReceivingMonochromeInput) +// { +// [currentTarget setInputRotation:inputRotation atIndex:textureIndex]; +// +// CGSize sizeToRotate = [self outputFrameSize]; +// CGSize rotatedSize = sizeToRotate; +// if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) +// { +// rotatedSize.width = sizeToRotate.height; +// rotatedSize.height = sizeToRotate.width; +// } +// [currentTarget setInputSize:rotatedSize atIndex:textureIndex]; +// } +// else +// { +// [currentTarget setInputSize:[self outputFrameSize] atIndex:textureIndex]; +// } +// [currentTarget newFrameReadyAtTime:frameTime atIndex:textureIndex]; +// } +// } +//} + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageLuminanceFragmentShaderString])) + { + return nil; + } + + return self; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHSBFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHSBFilter.h new file mode 100644 index 00000000..65a9e1de --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHSBFilter.h @@ -0,0 +1,27 @@ +#import "GPUImageColorMatrixFilter.h" + +@interface GPUImageHSBFilter : GPUImageColorMatrixFilter + +/** Reset the filter to have no transformations. + */ +- (void)reset; + +/** Add a hue rotation to the filter. + The hue rotation is in the range [-360, 360] with 0 being no-change. + Note that this adjustment is additive, so use the reset method if you need to. + */ +- (void)rotateHue:(float)h; + +/** Add a saturation adjustment to the filter. + The saturation adjustment is in the range [0.0, 2.0] with 1.0 being no-change. + Note that this adjustment is additive, so use the reset method if you need to. + */ +- (void)adjustSaturation:(float)s; + +/** Add a brightness adjustment to the filter. + The brightness adjustment is in the range [0.0, 2.0] with 1.0 being no-change. + Note that this adjustment is additive, so use the reset method if you need to. + */ +- (void)adjustBrightness:(float)b; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHSBFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageHSBFilter.m new file mode 100644 index 00000000..eb668f7d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHSBFilter.m @@ -0,0 +1,414 @@ +#import "GPUImageHSBFilter.h" + +@implementation GPUImageHSBFilter { + float matrix[4][4]; +} + +- (id)init +{ + self = [super init]; + if (self) { + [self reset]; + } + return self; +} + +- (void)reset { + identmat(matrix); + [self _updateColorMatrix]; +} + +- (void)rotateHue:(float)h { + huerotatemat(matrix, h); + [self _updateColorMatrix]; +} + +- (void)adjustSaturation:(float)s { + saturatemat(matrix, s); + [self _updateColorMatrix]; +} + +- (void)adjustBrightness:(float)b { + cscalemat(matrix, b, b, b); + [self _updateColorMatrix]; +} + +- (void)_updateColorMatrix { + GPUMatrix4x4 gpuMatrix; + gpuMatrix.one.one = matrix[0][0]; + gpuMatrix.one.two = matrix[1][0]; + gpuMatrix.one.three = matrix[2][0]; + gpuMatrix.one.four = matrix[3][0]; + gpuMatrix.two.one = matrix[0][1]; + gpuMatrix.two.two = matrix[1][1]; + gpuMatrix.two.three = matrix[2][1]; + gpuMatrix.two.four = matrix[3][1]; + gpuMatrix.three.one = matrix[0][2]; + gpuMatrix.three.two = matrix[1][2]; + gpuMatrix.three.three = matrix[2][2]; + gpuMatrix.three.four = matrix[3][2]; + gpuMatrix.four.one = matrix[0][3]; + gpuMatrix.four.two = matrix[1][3]; + gpuMatrix.four.three = matrix[2][3]; + gpuMatrix.four.four = matrix[3][3]; + self.colorMatrix = gpuMatrix; +} + +#pragma mark - Matrix algorithms + +/* Matrix algorithms adapted from http://www.graficaobscura.com/matrix/index.html + + Note about luminance vector values below from that page: + Where rwgt is 0.3086, gwgt is 0.6094, and bwgt is 0.0820. This is the luminance vector. Notice here that we do not use the standard NTSC weights of 0.299, 0.587, and 0.114. The NTSC weights are only applicable to RGB colors in a gamma 2.2 color space. For linear RGB colors the values above are better. + */ +//#define RLUM (0.3086f) +//#define GLUM (0.6094f) +//#define BLUM (0.0820f) + +/* This is the vector value from the PDF specification, and may be closer to what Photoshop uses */ +#define RLUM (0.3f) +#define GLUM (0.59f) +#define BLUM (0.11f) + +/* + * matrixmult - + * multiply two matricies + */ +static void matrixmult(a,b,c) +float a[4][4], b[4][4], c[4][4]; +{ + int x, y; + float temp[4][4]; + + for(y=0; y<4 ; y++) + for(x=0 ; x<4 ; x++) { + temp[y][x] = b[y][0] * a[0][x] + + b[y][1] * a[1][x] + + b[y][2] * a[2][x] + + b[y][3] * a[3][x]; + } + for(y=0; y<4; y++) + for(x=0; x<4; x++) + c[y][x] = temp[y][x]; +} + +/* + * identmat - + * make an identity matrix + */ +static void identmat(matrix) +float matrix[4][4]; +{ + memset(matrix, 0, sizeof(float[4][4])); + matrix[0][0] = 1.0f; + matrix[1][1] = 1.0f; + matrix[2][2] = 1.0f; + matrix[3][3] = 1.0f; +} + +/* + * xformpnt - + * transform a 3D point using a matrix + */ +static void xformpnt(matrix,x,y,z,tx,ty,tz) +float matrix[4][4]; +float x,y,z; +float *tx,*ty,*tz; +{ + *tx = x*matrix[0][0] + y*matrix[1][0] + z*matrix[2][0] + matrix[3][0]; + *ty = x*matrix[0][1] + y*matrix[1][1] + z*matrix[2][1] + matrix[3][1]; + *tz = x*matrix[0][2] + y*matrix[1][2] + z*matrix[2][2] + matrix[3][2]; +} + +/* + * cscalemat - + * make a color scale marix + */ +static void cscalemat(mat,rscale,gscale,bscale) +float mat[4][4]; +float rscale, gscale, bscale; +{ + float mmat[4][4]; + + mmat[0][0] = rscale; + mmat[0][1] = 0.0; + mmat[0][2] = 0.0; + mmat[0][3] = 0.0; + + mmat[1][0] = 0.0; + mmat[1][1] = gscale; + mmat[1][2] = 0.0; + mmat[1][3] = 0.0; + + + mmat[2][0] = 0.0; + mmat[2][1] = 0.0; + mmat[2][2] = bscale; + mmat[2][3] = 0.0; + + mmat[3][0] = 0.0; + mmat[3][1] = 0.0; + mmat[3][2] = 0.0; + mmat[3][3] = 1.0; + matrixmult(mmat,mat,mat); +} + +/* + * saturatemat - + * make a saturation marix + */ +static void saturatemat(mat,sat) +float mat[4][4]; +float sat; +{ + float mmat[4][4]; + float a, b, c, d, e, f, g, h, i; + float rwgt, gwgt, bwgt; + + rwgt = RLUM; + gwgt = GLUM; + bwgt = BLUM; + + a = (1.0-sat)*rwgt + sat; + b = (1.0-sat)*rwgt; + c = (1.0-sat)*rwgt; + d = (1.0-sat)*gwgt; + e = (1.0-sat)*gwgt + sat; + f = (1.0-sat)*gwgt; + g = (1.0-sat)*bwgt; + h = (1.0-sat)*bwgt; + i = (1.0-sat)*bwgt + sat; + mmat[0][0] = a; + mmat[0][1] = b; + mmat[0][2] = c; + mmat[0][3] = 0.0; + + mmat[1][0] = d; + mmat[1][1] = e; + mmat[1][2] = f; + mmat[1][3] = 0.0; + + mmat[2][0] = g; + mmat[2][1] = h; + mmat[2][2] = i; + mmat[2][3] = 0.0; + + mmat[3][0] = 0.0; + mmat[3][1] = 0.0; + mmat[3][2] = 0.0; + mmat[3][3] = 1.0; + matrixmult(mmat,mat,mat); +} + +/* + * xrotate - + * rotate about the x (red) axis + */ +static void xrotatemat(mat,rs,rc) +float mat[4][4]; +float rs, rc; +{ + float mmat[4][4]; + + mmat[0][0] = 1.0; + mmat[0][1] = 0.0; + mmat[0][2] = 0.0; + mmat[0][3] = 0.0; + + mmat[1][0] = 0.0; + mmat[1][1] = rc; + mmat[1][2] = rs; + mmat[1][3] = 0.0; + + mmat[2][0] = 0.0; + mmat[2][1] = -rs; + mmat[2][2] = rc; + mmat[2][3] = 0.0; + + mmat[3][0] = 0.0; + mmat[3][1] = 0.0; + mmat[3][2] = 0.0; + mmat[3][3] = 1.0; + matrixmult(mmat,mat,mat); +} + +/* + * yrotate - + * rotate about the y (green) axis + */ +static void yrotatemat(mat,rs,rc) +float mat[4][4]; +float rs, rc; +{ + float mmat[4][4]; + + mmat[0][0] = rc; + mmat[0][1] = 0.0; + mmat[0][2] = -rs; + mmat[0][3] = 0.0; + + mmat[1][0] = 0.0; + mmat[1][1] = 1.0; + mmat[1][2] = 0.0; + mmat[1][3] = 0.0; + + mmat[2][0] = rs; + mmat[2][1] = 0.0; + mmat[2][2] = rc; + mmat[2][3] = 0.0; + + mmat[3][0] = 0.0; + mmat[3][1] = 0.0; + mmat[3][2] = 0.0; + mmat[3][3] = 1.0; + matrixmult(mmat,mat,mat); +} + +/* + * zrotate - + * rotate about the z (blue) axis + */ +static void zrotatemat(mat,rs,rc) +float mat[4][4]; +float rs, rc; +{ + float mmat[4][4]; + + mmat[0][0] = rc; + mmat[0][1] = rs; + mmat[0][2] = 0.0; + mmat[0][3] = 0.0; + + mmat[1][0] = -rs; + mmat[1][1] = rc; + mmat[1][2] = 0.0; + mmat[1][3] = 0.0; + + mmat[2][0] = 0.0; + mmat[2][1] = 0.0; + mmat[2][2] = 1.0; + mmat[2][3] = 0.0; + + mmat[3][0] = 0.0; + mmat[3][1] = 0.0; + mmat[3][2] = 0.0; + mmat[3][3] = 1.0; + matrixmult(mmat,mat,mat); +} + +/* + * zshear - + * shear z using x and y. + */ +static void zshearmat(mat,dx,dy) +float mat[4][4]; +float dx, dy; +{ + float mmat[4][4]; + + mmat[0][0] = 1.0; + mmat[0][1] = 0.0; + mmat[0][2] = dx; + mmat[0][3] = 0.0; + + mmat[1][0] = 0.0; + mmat[1][1] = 1.0; + mmat[1][2] = dy; + mmat[1][3] = 0.0; + + mmat[2][0] = 0.0; + mmat[2][1] = 0.0; + mmat[2][2] = 1.0; + mmat[2][3] = 0.0; + + mmat[3][0] = 0.0; + mmat[3][1] = 0.0; + mmat[3][2] = 0.0; + mmat[3][3] = 1.0; + matrixmult(mmat,mat,mat); +} + +/* + * simplehuerotatemat - + * simple hue rotation. This changes luminance + */ +//static void simplehuerotatemat(mat,rot) +//float mat[4][4]; +//float rot; +//{ +// float mag; +// float xrs, xrc; +// float yrs, yrc; +// float zrs, zrc; +// +// /* rotate the grey vector into positive Z */ +// mag = sqrt(2.0); +// xrs = 1.0/mag; +// xrc = 1.0/mag; +// xrotatemat(mat,xrs,xrc); +// +// mag = sqrt(3.0); +// yrs = -1.0/mag; +// yrc = sqrt(2.0)/mag; +// yrotatemat(mat,yrs,yrc); +// +// /* rotate the hue */ +// zrs = sin(rot*M_PI/180.0); +// zrc = cos(rot*M_PI/180.0); +// zrotatemat(mat,zrs,zrc); +// +// /* rotate the grey vector back into place */ +// yrotatemat(mat,-yrs,yrc); +// xrotatemat(mat,-xrs,xrc); +//} + +/* + * huerotatemat - + * rotate the hue, while maintaining luminance. + */ +static void huerotatemat(mat,rot) +float mat[4][4]; +float rot; +{ + float mmat[4][4]; + float mag; + float lx, ly, lz; + float xrs, xrc; + float yrs, yrc; + float zrs, zrc; + float zsx, zsy; + + identmat(mmat); + + /* rotate the grey vector into positive Z */ + mag = sqrt(2.0); + xrs = 1.0/mag; + xrc = 1.0/mag; + xrotatemat(mmat,xrs,xrc); + mag = sqrt(3.0); + yrs = -1.0/mag; + yrc = sqrt(2.0)/mag; + yrotatemat(mmat,yrs,yrc); + + /* shear the space to make the luminance plane horizontal */ + xformpnt(mmat,RLUM,GLUM,BLUM,&lx,&ly,&lz); + zsx = lx/lz; + zsy = ly/lz; + zshearmat(mmat,zsx,zsy); + + /* rotate the hue */ + zrs = sin(rot*M_PI/180.0); + zrc = cos(rot*M_PI/180.0); + zrotatemat(mmat,zrs,zrc); + + /* unshear the space to put the luminance plane back */ + zshearmat(mmat,-zsx,-zsy); + + /* rotate the grey vector back into place */ + yrotatemat(mmat,-yrs,yrc); + xrotatemat(mmat,-xrs,xrc); + + matrixmult(mmat,mat,mat); +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHalftoneFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHalftoneFilter.h new file mode 100644 index 00000000..1860bc97 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHalftoneFilter.h @@ -0,0 +1,5 @@ +#import "GPUImagePixellateFilter.h" + +@interface GPUImageHalftoneFilter : GPUImagePixellateFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHalftoneFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageHalftoneFilter.m new file mode 100644 index 00000000..1b621c6a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHalftoneFilter.m @@ -0,0 +1,79 @@ +#import "GPUImageHalftoneFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageHalftoneFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp float fractionalWidthOfPixel; + uniform highp float aspectRatio; + uniform highp float dotScaling; + + const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + highp vec2 sampleDivisor = vec2(fractionalWidthOfPixel, fractionalWidthOfPixel / aspectRatio); + + highp vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor) + 0.5 * sampleDivisor; + highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + highp vec2 adjustedSamplePos = vec2(samplePos.x, (samplePos.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + highp float distanceFromSamplePoint = distance(adjustedSamplePos, textureCoordinateToUse); + + lowp vec3 sampledColor = texture2D(inputImageTexture, samplePos ).rgb; + highp float dotScaling = 1.0 - dot(sampledColor, W); + + lowp float checkForPresenceWithinDot = 1.0 - step(distanceFromSamplePoint, (fractionalWidthOfPixel * 0.5) * dotScaling); + + gl_FragColor = vec4(vec3(checkForPresenceWithinDot), 1.0); + } +); +#else +NSString *const kGPUImageHalftoneFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform float fractionalWidthOfPixel; + uniform float aspectRatio; + uniform float dotScaling; + + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec2 sampleDivisor = vec2(fractionalWidthOfPixel, fractionalWidthOfPixel / aspectRatio); + + vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor) + 0.5 * sampleDivisor; + vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + vec2 adjustedSamplePos = vec2(samplePos.x, (samplePos.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + float distanceFromSamplePoint = distance(adjustedSamplePos, textureCoordinateToUse); + + vec3 sampledColor = texture2D(inputImageTexture, samplePos ).rgb; + float dotScaling = 1.0 - dot(sampledColor, W); + + float checkForPresenceWithinDot = 1.0 - step(distanceFromSamplePoint, (fractionalWidthOfPixel * 0.5) * dotScaling); + + gl_FragColor = vec4(vec3(checkForPresenceWithinDot), 1.0); + } +); +#endif + +@implementation GPUImageHalftoneFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageHalftoneFragmentShaderString])) + { + return nil; + } + + self.fractionalWidthOfAPixel = 0.01; + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHardLightBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHardLightBlendFilter.h new file mode 100755 index 00000000..47d62609 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHardLightBlendFilter.h @@ -0,0 +1,7 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageHardLightBlendFilter : GPUImageTwoInputFilter +{ +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHardLightBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageHardLightBlendFilter.m new file mode 100755 index 00000000..2896ce82 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHardLightBlendFilter.m @@ -0,0 +1,99 @@ +#import "GPUImageHardLightBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageHardLightBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + mediump vec4 base = texture2D(inputImageTexture, textureCoordinate); + mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + highp float ra; + if (2.0 * overlay.r < overlay.a) { + ra = 2.0 * overlay.r * base.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + } else { + ra = overlay.a * base.a - 2.0 * (base.a - base.r) * (overlay.a - overlay.r) + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + } + + highp float ga; + if (2.0 * overlay.g < overlay.a) { + ga = 2.0 * overlay.g * base.g + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + } else { + ga = overlay.a * base.a - 2.0 * (base.a - base.g) * (overlay.a - overlay.g) + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + } + + highp float ba; + if (2.0 * overlay.b < overlay.a) { + ba = 2.0 * overlay.b * base.b + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + } else { + ba = overlay.a * base.a - 2.0 * (base.a - base.b) * (overlay.a - overlay.b) + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + } + + gl_FragColor = vec4(ra, ga, ba, 1.0); + } +); +#else +NSString *const kGPUImageHardLightBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec4 base = texture2D(inputImageTexture, textureCoordinate); + vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + float ra; + if (2.0 * overlay.r < overlay.a) { + ra = 2.0 * overlay.r * base.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + } else { + ra = overlay.a * base.a - 2.0 * (base.a - base.r) * (overlay.a - overlay.r) + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + } + + float ga; + if (2.0 * overlay.g < overlay.a) { + ga = 2.0 * overlay.g * base.g + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + } else { + ga = overlay.a * base.a - 2.0 * (base.a - base.g) * (overlay.a - overlay.g) + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + } + + float ba; + if (2.0 * overlay.b < overlay.a) { + ba = 2.0 * overlay.b * base.b + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + } else { + ba = overlay.a * base.a - 2.0 * (base.a - base.b) * (overlay.a - overlay.b) + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + } + + gl_FragColor = vec4(ra, ga, ba, 1.0); + } +); +#endif + + +@implementation GPUImageHardLightBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageHardLightBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHarrisCornerDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHarrisCornerDetectionFilter.h new file mode 100755 index 00000000..1492b8b8 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHarrisCornerDetectionFilter.h @@ -0,0 +1,53 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImageGaussianBlurFilter; +@class GPUImageXYDerivativeFilter; +@class GPUImageGrayscaleFilter; +@class GPUImageGaussianBlurFilter; +@class GPUImageThresholdedNonMaximumSuppressionFilter; +@class GPUImageColorPackingFilter; + +//#define DEBUGFEATUREDETECTION + +/** Harris corner detector + + First pass: reduce to luminance and take the derivative of the luminance texture (GPUImageXYDerivativeFilter) + + Second pass: blur the derivative (GPUImageGaussianBlurFilter) + + Third pass: apply the Harris corner detection calculation + + This is the Harris corner detector, as described in + C. Harris and M. Stephens. A Combined Corner and Edge Detector. Proc. Alvey Vision Conf., Univ. Manchester, pp. 147-151, 1988. + */ +@interface GPUImageHarrisCornerDetectionFilter : GPUImageFilterGroup +{ + GPUImageXYDerivativeFilter *derivativeFilter; + GPUImageGaussianBlurFilter *blurFilter; + GPUImageFilter *harrisCornerDetectionFilter; + GPUImageThresholdedNonMaximumSuppressionFilter *nonMaximumSuppressionFilter; + GPUImageColorPackingFilter *colorPackingFilter; + GLfloat *cornersArray; + GLubyte *rawImagePixels; +} + +/** The radius of the underlying Gaussian blur. The default is 2.0. + */ +@property(readwrite, nonatomic) CGFloat blurRadiusInPixels; + +// This changes the dynamic range of the Harris corner detector by amplifying small cornerness values. Default is 5.0. +@property(readwrite, nonatomic) CGFloat sensitivity; + +// A threshold value at which a point is recognized as being a corner after the non-maximum suppression. Default is 0.20. +@property(readwrite, nonatomic) CGFloat threshold; + +// This block is called on the detection of new corner points, usually on every processed frame. A C array containing normalized coordinates in X, Y pairs is passed in, along with a count of the number of corners detected and the current timestamp of the video frame +@property(nonatomic, copy) void(^cornersDetectedBlock)(GLfloat* cornerArray, NSUInteger cornersDetected, CMTime frameTime); + +// These images are only enabled when built with DEBUGFEATUREDETECTION defined, and are used to examine the intermediate states of the feature detector +@property(nonatomic, readonly, strong) NSMutableArray *intermediateImages; + +// Initialization and teardown +- (id)initWithCornerDetectionFragmentShader:(NSString *)cornerDetectionFragmentShader; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHarrisCornerDetectionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageHarrisCornerDetectionFilter.m new file mode 100755 index 00000000..999748dd --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHarrisCornerDetectionFilter.m @@ -0,0 +1,292 @@ +#import "GPUImageHarrisCornerDetectionFilter.h" +#import "GPUImageGaussianBlurFilter.h" +#import "GPUImageXYDerivativeFilter.h" +#import "GPUImageGrayscaleFilter.h" +#import "GPUImageThresholdedNonMaximumSuppressionFilter.h" +#import "GPUImageColorPackingFilter.h" +#import "GPUImageGaussianBlurFilter.h" + +@interface GPUImageHarrisCornerDetectionFilter() + +- (void)extractCornerLocationsFromImageAtFrameTime:(CMTime)frameTime; + +@end + +// This is the Harris corner detector, as described in +// C. Harris and M. Stephens. A Combined Corner and Edge Detector. Proc. Alvey Vision Conf., Univ. Manchester, pp. 147-151, 1988. + +@implementation GPUImageHarrisCornerDetectionFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageHarrisCornerDetectionFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform lowp float sensitivity; + + const mediump float harrisConstant = 0.04; + + void main() + { + mediump vec3 derivativeElements = texture2D(inputImageTexture, textureCoordinate).rgb; + + mediump float derivativeSum = derivativeElements.x + derivativeElements.y; + + mediump float zElement = (derivativeElements.z * 2.0) - 1.0; + + // R = Ix^2 * Iy^2 - Ixy * Ixy - k * (Ix^2 + Iy^2)^2 + mediump float cornerness = derivativeElements.x * derivativeElements.y - (zElement * zElement) - harrisConstant * derivativeSum * derivativeSum; + + gl_FragColor = vec4(vec3(cornerness * sensitivity), 1.0); + } +); +#else +NSString *const kGPUImageHarrisCornerDetectionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float sensitivity; + + const float harrisConstant = 0.04; + + void main() + { + vec3 derivativeElements = texture2D(inputImageTexture, textureCoordinate).rgb; + + float derivativeSum = derivativeElements.x + derivativeElements.y; + + float zElement = (derivativeElements.z * 2.0) - 1.0; + + // R = Ix^2 * Iy^2 - Ixy * Ixy - k * (Ix^2 + Iy^2)^2 + float cornerness = derivativeElements.x * derivativeElements.y - (zElement * zElement) - harrisConstant * derivativeSum * derivativeSum; + + gl_FragColor = vec4(vec3(cornerness * sensitivity), 1.0); + } +); +#endif + +@synthesize blurRadiusInPixels; +@synthesize cornersDetectedBlock; +@synthesize sensitivity = _sensitivity; +@synthesize threshold = _threshold; +@synthesize intermediateImages = _intermediateImages; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithCornerDetectionFragmentShader:kGPUImageHarrisCornerDetectionFragmentShaderString])) + { + return nil; + } + + return self; +} + +- (id)initWithCornerDetectionFragmentShader:(NSString *)cornerDetectionFragmentShader; +{ + if (!(self = [super init])) + { + return nil; + } + +#ifdef DEBUGFEATUREDETECTION + _intermediateImages = [[NSMutableArray alloc] init]; +#endif + + // First pass: reduce to luminance and take the derivative of the luminance texture + derivativeFilter = [[GPUImageXYDerivativeFilter alloc] init]; + [self addFilter:derivativeFilter]; + +#ifdef DEBUGFEATUREDETECTION + __unsafe_unretained NSMutableArray *weakIntermediateImages = _intermediateImages; + __unsafe_unretained GPUImageFilter *weakFilter = derivativeFilter; + [derivativeFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime){ + UIImage *intermediateImage = [weakFilter imageFromCurrentlyProcessedOutput]; + [weakIntermediateImages addObject:intermediateImage]; + }]; +#endif + + // Second pass: blur the derivative + blurFilter = [[GPUImageGaussianBlurFilter alloc] init]; + [self addFilter:blurFilter]; + +#ifdef DEBUGFEATUREDETECTION + weakFilter = blurFilter; + [blurFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime){ + UIImage *intermediateImage = [weakFilter imageFromCurrentlyProcessedOutput]; + [weakIntermediateImages addObject:intermediateImage]; + }]; +#endif + + // Third pass: apply the Harris corner detection calculation + harrisCornerDetectionFilter = [[GPUImageFilter alloc] initWithFragmentShaderFromString:cornerDetectionFragmentShader]; + [self addFilter:harrisCornerDetectionFilter]; + +#ifdef DEBUGFEATUREDETECTION + weakFilter = harrisCornerDetectionFilter; + [harrisCornerDetectionFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime){ + UIImage *intermediateImage = [weakFilter imageFromCurrentlyProcessedOutput]; + [weakIntermediateImages addObject:intermediateImage]; + }]; +#endif + + // Fourth pass: apply non-maximum suppression and thresholding to find the local maxima + nonMaximumSuppressionFilter = [[GPUImageThresholdedNonMaximumSuppressionFilter alloc] init]; + [self addFilter:nonMaximumSuppressionFilter]; + + __unsafe_unretained GPUImageHarrisCornerDetectionFilter *weakSelf = self; +#ifdef DEBUGFEATUREDETECTION + weakFilter = nonMaximumSuppressionFilter; + [nonMaximumSuppressionFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime){ + UIImage *intermediateImage = [weakFilter imageFromCurrentlyProcessedOutput]; + [weakIntermediateImages addObject:intermediateImage]; + + [weakSelf extractCornerLocationsFromImageAtFrameTime:frameTime]; + }]; +#else + [nonMaximumSuppressionFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime) { + [weakSelf extractCornerLocationsFromImageAtFrameTime:frameTime]; + }]; +#endif + +// Sixth pass: compress the thresholded points into the RGBA channels +// colorPackingFilter = [[GPUImageColorPackingFilter alloc] init]; +// [self addFilter:colorPackingFilter]; +// +// +//#ifdef DEBUGFEATUREDETECTION +// __unsafe_unretained GPUImageHarrisCornerDetectionFilter *weakSelf = self; +// weakFilter = colorPackingFilter; +// [colorPackingFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime){ +// NSLog(@"Triggered response from compaction filter"); +// +// UIImage *intermediateImage = [weakFilter imageFromCurrentlyProcessedOutput]; +// [weakIntermediateImages addObject:intermediateImage]; +// +// [weakSelf extractCornerLocationsFromImageAtFrameTime:frameTime]; +// }]; +//#else +// __unsafe_unretained GPUImageHarrisCornerDetectionFilter *weakSelf = self; +// [colorPackingFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime) { +// [weakSelf extractCornerLocationsFromImageAtFrameTime:frameTime]; +// }]; +//#endif + + [derivativeFilter addTarget:blurFilter]; + [blurFilter addTarget:harrisCornerDetectionFilter]; + [harrisCornerDetectionFilter addTarget:nonMaximumSuppressionFilter]; +// [simpleThresholdFilter addTarget:colorPackingFilter]; + + self.initialFilters = [NSArray arrayWithObjects:derivativeFilter, nil]; +// self.terminalFilter = colorPackingFilter; + self.terminalFilter = nonMaximumSuppressionFilter; + + self.blurRadiusInPixels = 2.0; + self.sensitivity = 5.0; + self.threshold = 0.20; + + return self; +} + +- (void)dealloc; +{ + free(rawImagePixels); + free(cornersArray); +} + +#pragma mark - +#pragma mark Corner extraction + +- (void)extractCornerLocationsFromImageAtFrameTime:(CMTime)frameTime; +{ + // we need a normal color texture for this filter + NSAssert(self.outputTextureOptions.internalFormat == GL_RGBA, @"The output texture format for this filter must be GL_RGBA."); + NSAssert(self.outputTextureOptions.type == GL_UNSIGNED_BYTE, @"The type of the output texture of this filter must be GL_UNSIGNED_BYTE."); + + NSUInteger numberOfCorners = 0; + CGSize imageSize = nonMaximumSuppressionFilter.outputFrameSize; + + unsigned int imageByteSize = imageSize.width * imageSize.height * 4; + + if (rawImagePixels == NULL) + { + rawImagePixels = (GLubyte *)malloc(imageByteSize); + cornersArray = calloc(512 * 2, sizeof(GLfloat)); + } + + glReadPixels(0, 0, (int)imageSize.width, (int)imageSize.height, GL_RGBA, GL_UNSIGNED_BYTE, rawImagePixels); + + CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); + + unsigned int imageWidth = imageSize.width * 4; + + unsigned int currentByte = 0; + unsigned int cornerStorageIndex = 0; + while (currentByte < imageByteSize) + { + GLubyte colorByte = rawImagePixels[currentByte]; + + if (colorByte > 0) + { + unsigned int xCoordinate = currentByte % imageWidth; + unsigned int yCoordinate = currentByte / imageWidth; + + cornersArray[cornerStorageIndex++] = (CGFloat)(xCoordinate / 4) / imageSize.width; + cornersArray[cornerStorageIndex++] = (CGFloat)(yCoordinate) / imageSize.height; + numberOfCorners++; + + numberOfCorners = MIN(numberOfCorners, 511); + cornerStorageIndex = MIN(cornerStorageIndex, 1021); + } + currentByte +=4; + } + + CFAbsoluteTime currentFrameTime = (CFAbsoluteTimeGetCurrent() - startTime); + NSLog(@"Processing time : %f ms", 1000.0 * currentFrameTime); + + if (cornersDetectedBlock != NULL) + { + cornersDetectedBlock(cornersArray, numberOfCorners, frameTime); + } +} + +- (BOOL)wantsMonochromeInput; +{ +// return YES; + return NO; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBlurRadiusInPixels:(CGFloat)newValue; +{ + blurFilter.blurRadiusInPixels = newValue; +} + +- (CGFloat)blurRadiusInPixels; +{ + return blurFilter.blurRadiusInPixels; +} + +- (void)setSensitivity:(CGFloat)newValue; +{ + _sensitivity = newValue; + [harrisCornerDetectionFilter setFloat:newValue forUniformName:@"sensitivity"]; +} + +- (void)setThreshold:(CGFloat)newValue; +{ + nonMaximumSuppressionFilter.threshold = newValue; +} + +- (CGFloat)threshold; +{ + return nonMaximumSuppressionFilter.threshold; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHazeFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHazeFilter.h new file mode 100755 index 00000000..eb3fbca6 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHazeFilter.h @@ -0,0 +1,29 @@ +#import "GPUImageFilter.h" + +/* + * The haze filter can be used to add or remove haze (similar to a UV filter) + * + * @author Alaric Cole + * @creationDate 03/10/12 + * + */ + +/** The haze filter can be used to add or remove haze + + This is similar to a UV filter + */ +@interface GPUImageHazeFilter : GPUImageFilter +{ + GLint distanceUniform; + GLint slopeUniform; +} + +/** Strength of the color applied. Default 0. Values between -.3 and .3 are best + */ +@property(readwrite, nonatomic) CGFloat distance; + +/** Amount of color change. Default 0. Values between -.3 and .3 are best + */ +@property(readwrite, nonatomic) CGFloat slope; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHazeFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageHazeFilter.m new file mode 100755 index 00000000..f90fc22f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHazeFilter.m @@ -0,0 +1,96 @@ +#import "GPUImageHazeFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageHazeFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform lowp float hazeDistance; + uniform highp float slope; + + void main() + { + //todo reconsider precision modifiers + highp vec4 color = vec4(1.0);//todo reimplement as a parameter + + highp float d = textureCoordinate.y * slope + hazeDistance; + + highp vec4 c = texture2D(inputImageTexture, textureCoordinate) ; // consider using unpremultiply + + c = (c - d * color) / (1.0 -d); + + gl_FragColor = c; //consider using premultiply(c); + } +); +#else +NSString *const kGPUImageHazeFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform float hazeDistance; + uniform float slope; + + void main() + { + //todo reconsider precision modifiers + vec4 color = vec4(1.0);//todo reimplement as a parameter + + float d = textureCoordinate.y * slope + hazeDistance; + + vec4 c = texture2D(inputImageTexture, textureCoordinate) ; // consider using unpremultiply + + c = (c - d * color) / (1.0 -d); + + gl_FragColor = c; //consider using premultiply(c); + } +); +#endif + + + + +@implementation GPUImageHazeFilter + +@synthesize distance = _distance; +@synthesize slope = _slope; +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageHazeFragmentShaderString])) + { + return nil; + } + + distanceUniform = [filterProgram uniformIndex:@"hazeDistance"]; + slopeUniform = [filterProgram uniformIndex:@"slope"]; + + self.distance = 0.2; + self.slope = 0.0; + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setDistance:(CGFloat)newValue; +{ + _distance = newValue; + + [self setFloat:_distance forUniform:distanceUniform program:filterProgram]; +} + +- (void)setSlope:(CGFloat)newValue; +{ + _slope = newValue; + + [self setFloat:_slope forUniform:slopeUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHighPassFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHighPassFilter.h new file mode 100644 index 00000000..263d8df1 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHighPassFilter.h @@ -0,0 +1,14 @@ +#import "GPUImageFilterGroup.h" +#import "GPUImageLowPassFilter.h" +#import "GPUImageDifferenceBlendFilter.h" + +@interface GPUImageHighPassFilter : GPUImageFilterGroup +{ + GPUImageLowPassFilter *lowPassFilter; + GPUImageDifferenceBlendFilter *differenceBlendFilter; +} + +// This controls the degree by which the previous accumulated frames are blended and then subtracted from the current one. This ranges from 0.0 to 1.0, with a default of 0.5. +@property(readwrite, nonatomic) CGFloat filterStrength; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHighPassFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageHighPassFilter.m new file mode 100644 index 00000000..511240d8 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHighPassFilter.m @@ -0,0 +1,46 @@ +#import "GPUImageHighPassFilter.h" + +@implementation GPUImageHighPassFilter + +@synthesize filterStrength; + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + // Start with a low pass filter to define the component to be removed + lowPassFilter = [[GPUImageLowPassFilter alloc] init]; + [self addFilter:lowPassFilter]; + + // Take the difference of the current frame from the low pass filtered result to get the high pass + differenceBlendFilter = [[GPUImageDifferenceBlendFilter alloc] init]; + [self addFilter:differenceBlendFilter]; + + // Texture location 0 needs to be the original image for the difference blend + [lowPassFilter addTarget:differenceBlendFilter atTextureLocation:1]; + + self.initialFilters = [NSArray arrayWithObjects:lowPassFilter, differenceBlendFilter, nil]; + self.terminalFilter = differenceBlendFilter; + + self.filterStrength = 0.5; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setFilterStrength:(CGFloat)newValue; +{ + lowPassFilter.filterStrength = newValue; +} + +- (CGFloat)filterStrength; +{ + return lowPassFilter.filterStrength; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowFilter.h new file mode 100644 index 00000000..35791298 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowFilter.h @@ -0,0 +1,20 @@ +#import "GPUImageFilter.h" + +@interface GPUImageHighlightShadowFilter : GPUImageFilter +{ + GLint shadowsUniform, highlightsUniform; +} + +/** + * 0 - 1, increase to lighten shadows. + * @default 0 + */ +@property(readwrite, nonatomic) CGFloat shadows; + +/** + * 0 - 1, decrease to darken highlights. + * @default 1 + */ +@property(readwrite, nonatomic) CGFloat highlights; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowFilter.m new file mode 100644 index 00000000..aa92b740 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowFilter.m @@ -0,0 +1,93 @@ +#import "GPUImageHighlightShadowFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageHighlightShadowFragmentShaderString = SHADER_STRING +( +uniform sampler2D inputImageTexture; +varying highp vec2 textureCoordinate; + +uniform lowp float shadows; +uniform lowp float highlights; + +const mediump vec3 luminanceWeighting = vec3(0.3, 0.3, 0.3); + +void main() +{ + lowp vec4 source = texture2D(inputImageTexture, textureCoordinate); + mediump float luminance = dot(source.rgb, luminanceWeighting); + + mediump float shadow = clamp((pow(luminance, 1.0/(shadows+1.0)) + (-0.76)*pow(luminance, 2.0/(shadows+1.0))) - luminance, 0.0, 1.0); + mediump float highlight = clamp((1.0 - (pow(1.0-luminance, 1.0/(2.0-highlights)) + (-0.8)*pow(1.0-luminance, 2.0/(2.0-highlights)))) - luminance, -1.0, 0.0); + lowp vec3 result = vec3(0.0, 0.0, 0.0) + ((luminance + shadow + highlight) - 0.0) * ((source.rgb - vec3(0.0, 0.0, 0.0))/(luminance - 0.0)); + + gl_FragColor = vec4(result.rgb, source.a); +} +); +#else +NSString *const kGPUImageHighlightShadowFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + varying vec2 textureCoordinate; + + uniform float shadows; + uniform float highlights; + + const vec3 luminanceWeighting = vec3(0.3, 0.3, 0.3); + + void main() + { + vec4 source = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(source.rgb, luminanceWeighting); + + float shadow = clamp((pow(luminance, 1.0/(shadows+1.0)) + (-0.76)*pow(luminance, 2.0/(shadows+1.0))) - luminance, 0.0, 1.0); + float highlight = clamp((1.0 - (pow(1.0-luminance, 1.0/(2.0-highlights)) + (-0.8)*pow(1.0-luminance, 2.0/(2.0-highlights)))) - luminance, -1.0, 0.0); + vec3 result = vec3(0.0, 0.0, 0.0) + ((luminance + shadow + highlight) - 0.0) * ((source.rgb - vec3(0.0, 0.0, 0.0))/(luminance - 0.0)); + + gl_FragColor = vec4(result.rgb, source.a); + } +); +#endif + +@implementation GPUImageHighlightShadowFilter + +@synthesize shadows = _shadows; +@synthesize highlights = _highlights; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageHighlightShadowFragmentShaderString])) + { + return nil; + } + + shadowsUniform = [filterProgram uniformIndex:@"shadows"]; + highlightsUniform = [filterProgram uniformIndex:@"highlights"]; + + self.shadows = 0.0; + self.highlights = 1.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setShadows:(CGFloat)newValue; +{ + _shadows = newValue; + + [self setFloat:_shadows forUniform:shadowsUniform program:filterProgram]; +} + +- (void)setHighlights:(CGFloat)newValue; +{ + _highlights = newValue; + + [self setFloat:_highlights forUniform:highlightsUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowTintFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowTintFilter.h new file mode 100644 index 00000000..166c5c8c --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowTintFilter.h @@ -0,0 +1,25 @@ +// +// GPUImageHighlightShadowTintFilter.h +// +// +// Created by github.com/r3mus on 8/14/15. +// +// + +#import "GPUImageFilter.h" + +@interface GPUImageHighlightShadowTintFilter : GPUImageFilter +{ + GLint shadowTintIntensityUniform, highlightTintIntensityUniform, shadowTintColorUniform, highlightTintColorUniform; +} + +// The shadowTint and highlightTint colors specify what colors replace the dark and light areas of the image, respectively. The defaults for shadows are black, highlighs white. +@property(readwrite, nonatomic) GLfloat shadowTintIntensity; +@property(readwrite, nonatomic) GPUVector4 shadowTintColor; +@property(readwrite, nonatomic) GLfloat highlightTintIntensity; +@property(readwrite, nonatomic) GPUVector4 highlightTintColor; + +- (void)setShadowTintColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; +- (void)setHighlightTintColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowTintFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowTintFilter.m new file mode 100644 index 00000000..54bc0850 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHighlightShadowTintFilter.m @@ -0,0 +1,136 @@ +// +// GPUImageHighlightShadowTintFilter.m +// +// Created by github.com/r3mus on 8/14/15. +// +// + +#import "GPUImageHighlightShadowTintFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUHighlightShadowTintFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform lowp float shadowTintIntensity; + uniform lowp float highlightTintIntensity; + uniform highp vec4 shadowTintColor; + uniform highp vec4 highlightTintColor; + + const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + highp float luminance = dot(textureColor.rgb, luminanceWeighting); + + highp vec4 shadowResult = mix(textureColor, max(textureColor, vec4( mix(shadowTintColor.rgb, textureColor.rgb, luminance), textureColor.a)), shadowTintIntensity); + highp vec4 highlightResult = mix(textureColor, min(shadowResult, vec4( mix(shadowResult.rgb, highlightTintColor.rgb, luminance), textureColor.a)), highlightTintIntensity); + + gl_FragColor = vec4( mix(shadowResult.rgb, highlightResult.rgb, luminance), textureColor.a); + } + ); +#else +NSString *const kGPUHighlightShadowTintFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float shadowTintIntensity; + uniform float highlightTintIntensity; + uniform vec3 shadowTintColor; + uniform vec3 highlightTintColor; + + const vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, luminanceWeighting); + + vec4 shadowResult = mix(textureColor, max(textureColor, vec4( mix(shadowTintColor.rgb, textureColor.rgb, luminance), textureColor.a)), shadowTintIntensity); + vec4 highlightResult = mix(textureColor, min(shadowResult, vec4( mix(shadowResult.rgb, highlightTintColor.rgb, luminance), textureColor.a)), highlightTintIntensity); + + gl_FragColor = vec4( mix(shadowResult.rgb, highlightResult.rgb, luminance), textureColor.a); + } + ); +#endif + + +@implementation GPUImageHighlightShadowTintFilter + +@synthesize shadowTintIntensity = _shadowTintIntensity; +@synthesize highlightTintIntensity = _highlightTintIntensity; +@synthesize shadowTintColor = _shadowTintColor; +@synthesize highlightTintColor = _highlightTintColor; + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUHighlightShadowTintFragmentShaderString])) + { + return nil; + } + + shadowTintIntensityUniform = [filterProgram uniformIndex:@"shadowTintIntensity"]; + highlightTintIntensityUniform = [filterProgram uniformIndex:@"highlightTintIntensity"]; + shadowTintColorUniform = [filterProgram uniformIndex:@"shadowTintColor"]; + highlightTintColorUniform = [filterProgram uniformIndex:@"highlightTintColor"]; + + self.shadowTintIntensity = 0.0f; + self.highlightTintIntensity = 0.0f; + self.shadowTintColor = (GPUVector4){1.0f, 0.0f, 0.0f, 1.0f}; + self.highlightTintColor = (GPUVector4){0.0f, 0.0f, 1.0f, 1.0f}; + + return self; +} + + +#pragma mark - +#pragma mark Accessors + +- (void)setShadowTintIntensity:(GLfloat)newValue +{ + _shadowTintIntensity = newValue; + + [self setFloat:_shadowTintIntensity forUniform:shadowTintIntensityUniform program:filterProgram]; +} + +- (void)setHighlightTintIntensity:(GLfloat)newValue +{ + _highlightTintIntensity = newValue; + + [self setFloat:_highlightTintIntensity forUniform:highlightTintIntensityUniform program:filterProgram]; +} + +- (void)setShadowTintColor:(GPUVector4)newValue; +{ + _shadowTintColor = newValue; + + [self setShadowTintColorRed:_shadowTintColor.one green:_shadowTintColor.two blue:_shadowTintColor.three alpha:_shadowTintColor.four]; +} + +- (void)setHighlightTintColor:(GPUVector4)newValue; +{ + _highlightTintColor = newValue; + + [self setHighlightTintColorRed:_highlightTintColor.one green:_highlightTintColor.two blue:_highlightTintColor.three alpha:_highlightTintColor.four]; +} + +- (void)setShadowTintColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; +{ + GPUVector4 shadowTintColor = {redComponent, greenComponent, blueComponent, alphaComponent}; + + [self setVec4:shadowTintColor forUniform:shadowTintColorUniform program:filterProgram]; +} + +- (void)setHighlightTintColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; +{ + GPUVector4 highlightTintColor = {redComponent, greenComponent, blueComponent, alphaComponent}; + + [self setVec4:highlightTintColor forUniform:highlightTintColorUniform program:filterProgram]; +} + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHistogramEqualizationFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramEqualizationFilter.h new file mode 100644 index 00000000..2b71cda0 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramEqualizationFilter.h @@ -0,0 +1,26 @@ +// +// GPUImageHistogramEqualizationFilter.h +// FilterShowcase +// +// Created by Adam Marcus on 19/08/2014. +// Copyright (c) 2014 Sunset Lake Software LLC. All rights reserved. +// + +#import "GPUImageFilterGroup.h" +#import "GPUImageHistogramFilter.h" +#import "GPUImageRawDataOutput.h" +#import "GPUImageRawDataInput.h" +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageHistogramEqualizationFilter : GPUImageFilterGroup +{ + GPUImageHistogramFilter *histogramFilter; + GPUImageRawDataOutput *rawDataOutputFilter; + GPUImageRawDataInput *rawDataInputFilter; +} + +@property(readwrite, nonatomic) NSUInteger downsamplingFactor; + +- (id)initWithHistogramType:(GPUImageHistogramType)newHistogramType; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHistogramEqualizationFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramEqualizationFilter.m new file mode 100644 index 00000000..7d6b9a2d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramEqualizationFilter.m @@ -0,0 +1,307 @@ +// +// GPUImageHistogramEqualizationFilter.m +// FilterShowcase +// +// Created by Adam Marcus on 19/08/2014. +// Copyright (c) 2014 Sunset Lake Software LLC. All rights reserved. +// + +#import "GPUImageHistogramEqualizationFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageRedHistogramEqualizationFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp float redCurveValue = texture2D(inputImageTexture2, vec2(textureColor.r, 0.0)).r; + + gl_FragColor = vec4(redCurveValue, textureColor.g, textureColor.b, textureColor.a); + } + ); +#else +NSString *const kGPUImageRedHistogramEqualizationFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float redCurveValue = texture2D(inputImageTexture2, vec2(textureColor.r, 0.0)).r; + + gl_FragColor = vec4(redCurveValue, textureColor.g, textureColor.b, textureColor.a); + } + ); +#endif + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageGreenHistogramEqualizationFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp float greenCurveValue = texture2D(inputImageTexture2, vec2(textureColor.g, 0.0)).g; + + gl_FragColor = vec4(textureColor.r, greenCurveValue, textureColor.b, textureColor.a); + } + ); +#else +NSString *const kGPUImageGreenHistogramEqualizationFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float greenCurveValue = texture2D(inputImageTexture2, vec2(textureColor.g, 0.0)).g; + + gl_FragColor = vec4(textureColor.r, greenCurveValue, textureColor.b, textureColor.a); + } + ); +#endif + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageBlueHistogramEqualizationFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp float blueCurveValue = texture2D(inputImageTexture2, vec2(textureColor.b, 0.0)).b; + + gl_FragColor = vec4(textureColor.r, textureColor.g, blueCurveValue, textureColor.a); + } + ); +#else +NSString *const kGPUImageBlueHistogramEqualizationFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float blueCurveValue = texture2D(inputImageTexture2, vec2(textureColor.b, 0.0)).b; + + gl_FragColor = vec4(textureColor.r, textureColor.g, blueCurveValue, textureColor.a); + } + ); +#endif + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageRGBHistogramEqualizationFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp float redCurveValue = texture2D(inputImageTexture2, vec2(textureColor.r, 0.0)).r; + lowp float greenCurveValue = texture2D(inputImageTexture2, vec2(textureColor.g, 0.0)).g; + lowp float blueCurveValue = texture2D(inputImageTexture2, vec2(textureColor.b, 0.0)).b; + + gl_FragColor = vec4(redCurveValue, greenCurveValue, blueCurveValue, textureColor.a); + } + ); +#else +NSString *const kGPUImageRGBHistogramEqualizationFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float redCurveValue = texture2D(inputImageTexture2, vec2(textureColor.r, 0.0)).r; + float greenCurveValue = texture2D(inputImageTexture2, vec2(textureColor.g, 0.0)).g; + float blueCurveValue = texture2D(inputImageTexture2, vec2(textureColor.b, 0.0)).b; + + gl_FragColor = vec4(redCurveValue, greenCurveValue, blueCurveValue, textureColor.a); + } + ); +#endif + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLuminanceHistogramEqualizationFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + const lowp vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp float luminance = dot(textureColor.rgb, W); + lowp float newLuminance = texture2D(inputImageTexture2, vec2(luminance, 0.0)).r; + lowp float deltaLuminance = newLuminance - luminance; + + lowp float red = clamp(textureColor.r + deltaLuminance, 0.0, 1.0); + lowp float green = clamp(textureColor.g + deltaLuminance, 0.0, 1.0); + lowp float blue = clamp(textureColor.b + deltaLuminance, 0.0, 1.0); + + gl_FragColor = vec4(red, green, blue, textureColor.a); + } + ); +#else +NSString *const kGPUImageLuminanceHistogramEqualizationFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, W); + float newLuminance = texture2D(inputImageTexture2, vec2(luminance, 0.0)).r; + float deltaLuminance = newLuminance - luminance; + + float red = clamp(textureColor.r + deltaLuminance, 0.0, 1.0); + float green = clamp(textureColor.g + deltaLuminance, 0.0, 1.0); + float blue = clamp(textureColor.b + deltaLuminance, 0.0, 1.0); + + gl_FragColor = vec4(red, green, blue, textureColor.a); + } + ); +#endif + +@implementation GPUImageHistogramEqualizationFilter + +@synthesize downsamplingFactor = _downsamplingFactor; + +#pragma mark - +#pragma mark Initialization + +- (id)init; +{ + if (!(self = [self initWithHistogramType:kGPUImageHistogramRGB])) + { + return nil; + } + + return self; +} + +- (id)initWithHistogramType:(GPUImageHistogramType)newHistogramType +{ + if (!(self = [super init])) + { + return nil; + } + + histogramFilter = [[GPUImageHistogramFilter alloc] initWithHistogramType:newHistogramType]; + [self addFilter:histogramFilter]; + + GLubyte dummyInput[4 * 256]; // NB: No way to initialise GPUImageRawDataInput without providing bytes + rawDataInputFilter = [[GPUImageRawDataInput alloc] initWithBytes:dummyInput size:CGSizeMake(256.0, 1.0) pixelFormat:GPUPixelFormatBGRA type:GPUPixelTypeUByte]; + rawDataOutputFilter = [[GPUImageRawDataOutput alloc] initWithImageSize:CGSizeMake(256.0, 3.0) resultsInBGRAFormat:YES]; + + __unsafe_unretained GPUImageRawDataOutput *_rawDataOutputFilter = rawDataOutputFilter; + __unsafe_unretained GPUImageRawDataInput *_rawDataInputFilter = rawDataInputFilter; + [rawDataOutputFilter setNewFrameAvailableBlock:^{ + + unsigned int histogramBins[3][256]; + + [_rawDataOutputFilter lockFramebufferForReading]; + + GLubyte *data = [_rawDataOutputFilter rawBytesForImage]; + data += [_rawDataOutputFilter bytesPerRowInOutput]; + + histogramBins[0][0] = *data++; + histogramBins[1][0] = *data++; + histogramBins[2][0] = *data++; + data++; + + for (unsigned int x = 1; x < 256; x++) { + histogramBins[0][x] = histogramBins[0][x-1] + *data++; + histogramBins[1][x] = histogramBins[1][x-1] + *data++; + histogramBins[2][x] = histogramBins[2][x-1] + *data++; + data++; + } + + [_rawDataOutputFilter unlockFramebufferAfterReading]; + + GLubyte colorMapping[4 * 256]; + GLubyte *_colorMapping = colorMapping; + + for (unsigned int x = 0; x < 256; x++) { + *_colorMapping++ = (GLubyte) (((histogramBins[0][x] - histogramBins[0][0]) * 255) / histogramBins[0][255]); + *_colorMapping++ = (GLubyte) (((histogramBins[1][x] - histogramBins[1][0]) * 255) / histogramBins[1][255]); + *_colorMapping++ = (GLubyte) (((histogramBins[2][x] - histogramBins[2][0]) * 255) / histogramBins[2][255]); + *_colorMapping++ = 255; + } + + _colorMapping = colorMapping; + [_rawDataInputFilter updateDataFromBytes:_colorMapping size:CGSizeMake(256.0, 1.0)]; + [_rawDataInputFilter processData]; + }]; + [histogramFilter addTarget:rawDataOutputFilter]; + + NSString *fragmentShader = nil; + switch (newHistogramType) { + case kGPUImageHistogramRed: + fragmentShader = kGPUImageRedHistogramEqualizationFragmentShaderString; + break; + case kGPUImageHistogramGreen: + fragmentShader = kGPUImageGreenHistogramEqualizationFragmentShaderString; + break; + case kGPUImageHistogramBlue: + fragmentShader = kGPUImageBlueHistogramEqualizationFragmentShaderString; + break; + default: + case kGPUImageHistogramRGB: + fragmentShader = kGPUImageRGBHistogramEqualizationFragmentShaderString; + break; + case kGPUImageHistogramLuminance: + fragmentShader = kGPUImageLuminanceHistogramEqualizationFragmentShaderString; + break; + } + GPUImageFilter *equalizationFilter = [[GPUImageTwoInputFilter alloc] initWithFragmentShaderFromString:fragmentShader]; + [rawDataInputFilter addTarget:equalizationFilter atTextureLocation:1]; + + [self addFilter:equalizationFilter]; + + self.initialFilters = [NSArray arrayWithObjects:histogramFilter, equalizationFilter, nil]; + self.terminalFilter = equalizationFilter; + + self.downsamplingFactor = 16; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setDownsamplingFactor:(NSUInteger)newValue; +{ + if (_downsamplingFactor != newValue) + { + _downsamplingFactor = newValue; + histogramFilter.downsamplingFactor = newValue; + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHistogramFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramFilter.h new file mode 100755 index 00000000..32004bf7 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramFilter.h @@ -0,0 +1,22 @@ +#import "GPUImageFilter.h" + +typedef enum { kGPUImageHistogramRed, kGPUImageHistogramGreen, kGPUImageHistogramBlue, kGPUImageHistogramRGB, kGPUImageHistogramLuminance} GPUImageHistogramType; + +@interface GPUImageHistogramFilter : GPUImageFilter +{ + GPUImageHistogramType histogramType; + + GLubyte *vertexSamplingCoordinates; + + GLProgram *secondFilterProgram, *thirdFilterProgram; + GLint secondFilterPositionAttribute, thirdFilterPositionAttribute; +} + +// Rather than sampling every pixel, this dictates what fraction of the image is sampled. By default, this is 16 with a minimum of 1. +@property(readwrite, nonatomic) NSUInteger downsamplingFactor; + +// Initialization and teardown +- (id)initWithHistogramType:(GPUImageHistogramType)newHistogramType; +- (void)initializeSecondaryAttributes; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHistogramFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramFilter.m new file mode 100755 index 00000000..bb7acce7 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramFilter.m @@ -0,0 +1,341 @@ +#import "GPUImageHistogramFilter.h" + +// Unlike other filters, this one uses a grid of GL_POINTs to sample the incoming image in a grid. A custom vertex shader reads the color in the texture at its position +// and outputs a bin position in the final histogram as the vertex position. That point is then written into the image of the histogram using translucent pixels. +// The degree of translucency is controlled by the scalingFactor, which lets you adjust the dynamic range of the histogram. The histogram can only be generated for one +// color channel or luminance value at a time. +// +// This is based on this implementation: http://www.shaderwrangler.com/publications/histogram/histogram_cameraready.pdf +// +// Or at least that's how it would work if iOS could read from textures in a vertex shader, which it can't. Therefore, I read the texture data down from the +// incoming frame and process the texture colors as vertices. + +NSString *const kGPUImageRedHistogramSamplingVertexShaderString = SHADER_STRING +( + attribute vec4 position; + + varying vec3 colorFactor; + + void main() + { + colorFactor = vec3(1.0, 0.0, 0.0); + gl_Position = vec4(-1.0 + (position.x * 0.0078125), 0.0, 0.0, 1.0); + gl_PointSize = 1.0; + } +); + +NSString *const kGPUImageGreenHistogramSamplingVertexShaderString = SHADER_STRING +( + attribute vec4 position; + + varying vec3 colorFactor; + + void main() + { + colorFactor = vec3(0.0, 1.0, 0.0); + gl_Position = vec4(-1.0 + (position.y * 0.0078125), 0.0, 0.0, 1.0); + gl_PointSize = 1.0; + } +); + +NSString *const kGPUImageBlueHistogramSamplingVertexShaderString = SHADER_STRING +( + attribute vec4 position; + + varying vec3 colorFactor; + + void main() + { + colorFactor = vec3(0.0, 0.0, 1.0); + gl_Position = vec4(-1.0 + (position.z * 0.0078125), 0.0, 0.0, 1.0); + gl_PointSize = 1.0; + } +); + +NSString *const kGPUImageLuminanceHistogramSamplingVertexShaderString = SHADER_STRING +( + attribute vec4 position; + + varying vec3 colorFactor; + + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + float luminance = dot(position.xyz, W); + + colorFactor = vec3(1.0, 1.0, 1.0); + gl_Position = vec4(-1.0 + (luminance * 0.0078125), 0.0, 0.0, 1.0); + gl_PointSize = 1.0; + } +); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageHistogramAccumulationFragmentShaderString = SHADER_STRING +( + const lowp float scalingFactor = 1.0 / 256.0; + + varying lowp vec3 colorFactor; + + void main() + { + gl_FragColor = vec4(colorFactor * scalingFactor , 1.0); + } +); +#else +NSString *const kGPUImageHistogramAccumulationFragmentShaderString = SHADER_STRING +( + const float scalingFactor = 1.0 / 256.0; + + varying vec3 colorFactor; + + void main() + { + gl_FragColor = vec4(colorFactor * scalingFactor , 1.0); + } +); +#endif + +@implementation GPUImageHistogramFilter + +@synthesize downsamplingFactor = _downsamplingFactor; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithHistogramType:(GPUImageHistogramType)newHistogramType; +{ + switch (newHistogramType) + { + case kGPUImageHistogramRed: + { + if (!(self = [super initWithVertexShaderFromString:kGPUImageRedHistogramSamplingVertexShaderString fragmentShaderFromString:kGPUImageHistogramAccumulationFragmentShaderString])) + { + return nil; + } + }; break; + case kGPUImageHistogramGreen: + { + if (!(self = [super initWithVertexShaderFromString:kGPUImageGreenHistogramSamplingVertexShaderString fragmentShaderFromString:kGPUImageHistogramAccumulationFragmentShaderString])) + { + return nil; + } + }; break; + case kGPUImageHistogramBlue: + { + if (!(self = [super initWithVertexShaderFromString:kGPUImageBlueHistogramSamplingVertexShaderString fragmentShaderFromString:kGPUImageHistogramAccumulationFragmentShaderString])) + { + return nil; + } + }; break; + case kGPUImageHistogramLuminance: + { + if (!(self = [super initWithVertexShaderFromString:kGPUImageLuminanceHistogramSamplingVertexShaderString fragmentShaderFromString:kGPUImageHistogramAccumulationFragmentShaderString])) + { + return nil; + } + }; break; + case kGPUImageHistogramRGB: + { + if (!(self = [super initWithVertexShaderFromString:kGPUImageRedHistogramSamplingVertexShaderString fragmentShaderFromString:kGPUImageHistogramAccumulationFragmentShaderString])) + { + return nil; + } + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + + secondFilterProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:kGPUImageGreenHistogramSamplingVertexShaderString fragmentShaderString:kGPUImageHistogramAccumulationFragmentShaderString]; + thirdFilterProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:kGPUImageBlueHistogramSamplingVertexShaderString fragmentShaderString:kGPUImageHistogramAccumulationFragmentShaderString]; + + if (!secondFilterProgram.initialized) + { + [self initializeSecondaryAttributes]; + + if (![secondFilterProgram link]) + { + NSString *progLog = [secondFilterProgram programLog]; + NSLog(@"Program link log: %@", progLog); + NSString *fragLog = [secondFilterProgram fragmentShaderLog]; + NSLog(@"Fragment shader compile log: %@", fragLog); + NSString *vertLog = [secondFilterProgram vertexShaderLog]; + NSLog(@"Vertex shader compile log: %@", vertLog); + filterProgram = nil; + NSAssert(NO, @"Filter shader link failed"); + + } + + [GPUImageContext setActiveShaderProgram:secondFilterProgram]; + + glEnableVertexAttribArray(secondFilterPositionAttribute); + + if (![thirdFilterProgram link]) + { + NSString *progLog = [secondFilterProgram programLog]; + NSLog(@"Program link log: %@", progLog); + NSString *fragLog = [secondFilterProgram fragmentShaderLog]; + NSLog(@"Fragment shader compile log: %@", fragLog); + NSString *vertLog = [secondFilterProgram vertexShaderLog]; + NSLog(@"Vertex shader compile log: %@", vertLog); + filterProgram = nil; + NSAssert(NO, @"Filter shader link failed"); + } + } + + secondFilterPositionAttribute = [secondFilterProgram attributeIndex:@"position"]; + + + thirdFilterPositionAttribute = [thirdFilterProgram attributeIndex:@"position"]; + [GPUImageContext setActiveShaderProgram:thirdFilterProgram]; + + glEnableVertexAttribArray(thirdFilterPositionAttribute); + }); + }; break; + } + + histogramType = newHistogramType; + + self.downsamplingFactor = 16; + + return self; +} + +- (id)init; +{ + if (!(self = [self initWithHistogramType:kGPUImageHistogramRGB])) + { + return nil; + } + + return self; +} + +- (void)initializeSecondaryAttributes; +{ + [secondFilterProgram addAttribute:@"position"]; + [thirdFilterProgram addAttribute:@"position"]; +} + +- (void)dealloc; +{ + if (vertexSamplingCoordinates != NULL && ![GPUImageContext supportsFastTextureUpload]) + { + free(vertexSamplingCoordinates); + } +} + +#pragma mark - +#pragma mark Rendering + +- (CGSize)sizeOfFBO; +{ + return CGSizeMake(256.0, 3.0); +} + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + [self renderToTextureWithVertices:NULL textureCoordinates:NULL]; + + [self informTargetsAboutNewFrameAtTime:frameTime]; +} + +- (CGSize)outputFrameSize; +{ + return [self sizeOfFBO]; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + if (self.preventRendering) + { + return; + } + + inputTextureSize = newSize; +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + inputRotation = kGPUImageNoRotation; +} + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + // we need a normal color texture for this filter + NSAssert(self.outputTextureOptions.internalFormat == GL_RGBA, @"The output texture format for this filter must be GL_RGBA."); + NSAssert(self.outputTextureOptions.type == GL_UNSIGNED_BYTE, @"The type of the output texture of this filter must be GL_UNSIGNED_BYTE."); + + if (self.preventRendering) + { + [firstInputFramebuffer unlock]; + return; + } + + [GPUImageContext useImageProcessingContext]; + + if ([GPUImageContext supportsFastTextureUpload]) + { + glFinish(); + vertexSamplingCoordinates = [firstInputFramebuffer byteBuffer]; + } else { + if (vertexSamplingCoordinates == NULL) + { + vertexSamplingCoordinates = calloc(inputTextureSize.width * inputTextureSize.height * 4, sizeof(GLubyte)); + } + glReadPixels(0, 0, inputTextureSize.width, inputTextureSize.height, GL_RGBA, GL_UNSIGNED_BYTE, vertexSamplingCoordinates); + } + + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + if (usingNextFrameForImageCapture) + { + [outputFramebuffer lock]; + } + + [GPUImageContext setActiveShaderProgram:filterProgram]; + + glClearColor(0.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_ONE, GL_ONE); + glEnable(GL_BLEND); + + glVertexAttribPointer(filterPositionAttribute, 4, GL_UNSIGNED_BYTE, 0, ((unsigned int)_downsamplingFactor - 1) * 4, vertexSamplingCoordinates); + glDrawArrays(GL_POINTS, 0, inputTextureSize.width * inputTextureSize.height / (CGFloat)_downsamplingFactor); + + if (histogramType == kGPUImageHistogramRGB) + { + [GPUImageContext setActiveShaderProgram:secondFilterProgram]; + + glVertexAttribPointer(secondFilterPositionAttribute, 4, GL_UNSIGNED_BYTE, 0, ((unsigned int)_downsamplingFactor - 1) * 4, vertexSamplingCoordinates); + glDrawArrays(GL_POINTS, 0, inputTextureSize.width * inputTextureSize.height / (CGFloat)_downsamplingFactor); + + [GPUImageContext setActiveShaderProgram:thirdFilterProgram]; + + glVertexAttribPointer(thirdFilterPositionAttribute, 4, GL_UNSIGNED_BYTE, 0, ((unsigned int)_downsamplingFactor - 1) * 4, vertexSamplingCoordinates); + glDrawArrays(GL_POINTS, 0, inputTextureSize.width * inputTextureSize.height / (CGFloat)_downsamplingFactor); + } + + glDisable(GL_BLEND); + [firstInputFramebuffer unlock]; + + if (usingNextFrameForImageCapture) + { + dispatch_semaphore_signal(imageCaptureSemaphore); + } +} + +#pragma mark - +#pragma mark Accessors + +//- (void)setScalingFactor:(CGFloat)newValue; +//{ +// _scalingFactor = newValue; +// +// [GPUImageContext useImageProcessingContext]; +// [filterProgram use]; +// glUniform1f(scalingFactorUniform, _scalingFactor); +//} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHistogramGenerator.h b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramGenerator.h new file mode 100755 index 00000000..f80c50f3 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramGenerator.h @@ -0,0 +1,8 @@ +#import "GPUImageFilter.h" + +@interface GPUImageHistogramGenerator : GPUImageFilter +{ + GLint backgroundColorUniform; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHistogramGenerator.m b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramGenerator.m new file mode 100755 index 00000000..703795df --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHistogramGenerator.m @@ -0,0 +1,87 @@ +#import "GPUImageHistogramGenerator.h" + +NSString *const kGPUImageHistogramGeneratorVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + + varying vec2 textureCoordinate; + varying float height; + + void main() + { + gl_Position = position; + textureCoordinate = vec2(inputTextureCoordinate.x, 0.5); + height = 1.0 - inputTextureCoordinate.y; + } +); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageHistogramGeneratorFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp float height; + + uniform sampler2D inputImageTexture; + uniform lowp vec4 backgroundColor; + + void main() + { + lowp vec3 colorChannels = texture2D(inputImageTexture, textureCoordinate).rgb; + lowp vec4 heightTest = vec4(step(height, colorChannels), 1.0); + gl_FragColor = mix(backgroundColor, heightTest, heightTest.r + heightTest.g + heightTest.b); + } +); +#else +NSString *const kGPUImageHistogramGeneratorFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying float height; + + uniform sampler2D inputImageTexture; + uniform vec4 backgroundColor; + + void main() + { + vec3 colorChannels = texture2D(inputImageTexture, textureCoordinate).rgb; + vec4 heightTest = vec4(step(height, colorChannels), 1.0); + gl_FragColor = mix(backgroundColor, heightTest, heightTest.r + heightTest.g + heightTest.b); + } +); +#endif + +@implementation GPUImageHistogramGenerator + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithVertexShaderFromString:kGPUImageHistogramGeneratorVertexShaderString fragmentShaderFromString:kGPUImageHistogramGeneratorFragmentShaderString])) + { + return nil; + } + + backgroundColorUniform = [filterProgram uniformIndex:@"backgroundColor"]; + + [self setBackgroundColorRed:0.0 green:0.0 blue:0.0 alpha:0.0]; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBackgroundColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; +{ +// GLfloat backgroundColor[4]; +// backgroundColor[0] = redComponent; +// backgroundColor[1] = greenComponent; +// backgroundColor[2] = blueComponent; +// backgroundColor[3] = alphaComponent; + GPUVector4 backgroundColor = {redComponent, greenComponent, blueComponent, alphaComponent}; + + [self setVec4:backgroundColor forUniform:backgroundColorUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHoughTransformLineDetector.h b/LFLiveKit/Vendor/GPUImage/GPUImageHoughTransformLineDetector.h new file mode 100644 index 00000000..3ab6977f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHoughTransformLineDetector.h @@ -0,0 +1,49 @@ +#import "GPUImageFilterGroup.h" +#import "GPUImageThresholdEdgeDetectionFilter.h" +#import "GPUImageParallelCoordinateLineTransformFilter.h" +#import "GPUImageThresholdedNonMaximumSuppressionFilter.h" +#import "GPUImageCannyEdgeDetectionFilter.h" + +// This applies a Hough transform to detect lines in a scene. It starts with a thresholded Sobel edge detection pass, +// then takes those edge points in and applies a Hough transform to convert them to lines. The intersection of these lines +// is then determined via blending and accumulation, and a non-maximum suppression filter is applied to find local maxima. +// These local maxima are then converted back into lines in normal space and returned via a callback block. +// +// Rather than using one of the standard Hough transform types, this filter uses parallel coordinate space which is far more efficient +// to rasterize on a GPU. +// +// This approach is based entirely on the PC lines process developed by the Graph@FIT research group at the Brno University of Technology +// and described in their publications: +// +// M. Dubská, J. Havel, and A. Herout. Real-Time Detection of Lines using Parallel Coordinates and OpenGL. Proceedings of SCCG 2011, Bratislava, SK, p. 7. +// http://medusa.fit.vutbr.cz/public/data/papers/2011-SCCG-Dubska-Real-Time-Line-Detection-Using-PC-and-OpenGL.pdf +// M. Dubská, J. Havel, and A. Herout. PClines — Line detection using parallel coordinates. 2011 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), p. 1489- 1494. +// http://medusa.fit.vutbr.cz/public/data/papers/2011-CVPR-Dubska-PClines.pdf + +//#define DEBUGLINEDETECTION + +@interface GPUImageHoughTransformLineDetector : GPUImageFilterGroup +{ + GPUImageOutput *thresholdEdgeDetectionFilter; + +// GPUImageThresholdEdgeDetectionFilter *thresholdEdgeDetectionFilter; + GPUImageParallelCoordinateLineTransformFilter *parallelCoordinateLineTransformFilter; + GPUImageThresholdedNonMaximumSuppressionFilter *nonMaximumSuppressionFilter; + + GLfloat *linesArray; + GLubyte *rawImagePixels; +} + +// A threshold value for which a point is detected as belonging to an edge for determining lines. Default is 0.9. +@property(readwrite, nonatomic) CGFloat edgeThreshold; + +// A threshold value for which a local maximum is detected as belonging to a line in parallel coordinate space. Default is 0.20. +@property(readwrite, nonatomic) CGFloat lineDetectionThreshold; + +// This block is called on the detection of lines, usually on every processed frame. A C array containing normalized slopes and intercepts in m, b pairs (y=mx+b) is passed in, along with a count of the number of lines detected and the current timestamp of the video frame +@property(nonatomic, copy) void(^linesDetectedBlock)(GLfloat* lineArray, NSUInteger linesDetected, CMTime frameTime); + +// These images are only enabled when built with DEBUGLINEDETECTION defined, and are used to examine the intermediate states of the Hough transform +@property(nonatomic, readonly, strong) NSMutableArray *intermediateImages; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHoughTransformLineDetector.m b/LFLiveKit/Vendor/GPUImage/GPUImageHoughTransformLineDetector.m new file mode 100644 index 00000000..8289eb80 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHoughTransformLineDetector.m @@ -0,0 +1,241 @@ +#import "GPUImageHoughTransformLineDetector.h" + +@interface GPUImageHoughTransformLineDetector() + +- (void)extractLineParametersFromImageAtFrameTime:(CMTime)frameTime; + +@end + +@implementation GPUImageHoughTransformLineDetector + +@synthesize linesDetectedBlock; +@synthesize edgeThreshold; +@synthesize lineDetectionThreshold; +@synthesize intermediateImages = _intermediateImages; + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + // First pass: do edge detection and threshold that to just have white pixels for edges +// if ([GPUImageContext deviceSupportsFramebufferReads]) +// if ([GPUImageContext deviceSupportsFramebufferReads]) +// { +// thresholdEdgeDetectionFilter = [[GPUImageThresholdEdgeDetectionFilter alloc] init]; +// thresholdEdgeDetectionFilter = [[GPUImageSobelEdgeDetectionFilter alloc] init]; +// [(GPUImageThresholdEdgeDetectionFilter *)thresholdEdgeDetectionFilter setThreshold:0.07]; +// [(GPUImageThresholdEdgeDetectionFilter *)thresholdEdgeDetectionFilter setEdgeStrength:0.25]; +// [(GPUImageThresholdEdgeDetectionFilter *)thresholdEdgeDetectionFilter setEdgeStrength:1.0]; +// thresholdEdgeDetectionFilter = [[GPUImageCannyEdgeDetectionFilter alloc] init]; +// } +// else +// { + thresholdEdgeDetectionFilter = [[GPUImageCannyEdgeDetectionFilter alloc] init]; +// } + [self addFilter:thresholdEdgeDetectionFilter]; + + // Second pass: extract the white points and draw representative lines in parallel coordinate space + parallelCoordinateLineTransformFilter = [[GPUImageParallelCoordinateLineTransformFilter alloc] init]; + [self addFilter:parallelCoordinateLineTransformFilter]; + + // Third pass: apply non-maximum suppression + if ([GPUImageContext deviceSupportsFramebufferReads]) + { + nonMaximumSuppressionFilter = [[GPUImageThresholdedNonMaximumSuppressionFilter alloc] initWithPackedColorspace:YES]; + } + else + { + nonMaximumSuppressionFilter = [[GPUImageThresholdedNonMaximumSuppressionFilter alloc] initWithPackedColorspace:NO]; + } + [self addFilter:nonMaximumSuppressionFilter]; + + __unsafe_unretained GPUImageHoughTransformLineDetector *weakSelf = self; +#ifdef DEBUGLINEDETECTION + _intermediateImages = [[NSMutableArray alloc] init]; + __unsafe_unretained NSMutableArray *weakIntermediateImages = _intermediateImages; + +// __unsafe_unretained GPUImageOutput *weakEdgeDetectionFilter = thresholdEdgeDetectionFilter; +// [thresholdEdgeDetectionFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime){ +// [weakIntermediateImages removeAllObjects]; +// UIImage *intermediateImage = [weakEdgeDetectionFilter imageFromCurrentFramebuffer]; +// [weakIntermediateImages addObject:intermediateImage]; +// }]; +// +// __unsafe_unretained GPUImageOutput *weakParallelCoordinateLineTransformFilter = parallelCoordinateLineTransformFilter; +// [parallelCoordinateLineTransformFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime){ +// UIImage *intermediateImage = [weakParallelCoordinateLineTransformFilter imageFromCurrentFramebuffer]; +// [weakIntermediateImages addObject:intermediateImage]; +// }]; + + __unsafe_unretained GPUImageOutput *weakNonMaximumSuppressionFilter = nonMaximumSuppressionFilter; + [nonMaximumSuppressionFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime){ + UIImage *intermediateImage = [weakNonMaximumSuppressionFilter imageFromCurrentFramebuffer]; + [weakIntermediateImages addObject:intermediateImage]; + + [weakSelf extractLineParametersFromImageAtFrameTime:frameTime]; + }]; +#else + [nonMaximumSuppressionFilter setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime) { + [weakSelf extractLineParametersFromImageAtFrameTime:frameTime]; + }]; +#endif + + [thresholdEdgeDetectionFilter addTarget:parallelCoordinateLineTransformFilter]; + [parallelCoordinateLineTransformFilter addTarget:nonMaximumSuppressionFilter]; + + self.initialFilters = [NSArray arrayWithObjects:thresholdEdgeDetectionFilter, nil]; + // self.terminalFilter = colorPackingFilter; + self.terminalFilter = nonMaximumSuppressionFilter; + +// self.edgeThreshold = 0.95; + self.lineDetectionThreshold = 0.12; + + return self; +} + +- (void)dealloc; +{ + free(rawImagePixels); + free(linesArray); +} + +#pragma mark - +#pragma mark Corner extraction + +- (void)extractLineParametersFromImageAtFrameTime:(CMTime)frameTime; +{ + // we need a normal color texture for this filter + NSAssert(self.outputTextureOptions.internalFormat == GL_RGBA, @"The output texture format for this filter must be GL_RGBA."); + NSAssert(self.outputTextureOptions.type == GL_UNSIGNED_BYTE, @"The type of the output texture of this filter must be GL_UNSIGNED_BYTE."); + + NSUInteger numberOfLines = 0; + CGSize imageSize = nonMaximumSuppressionFilter.outputFrameSize; + + unsigned int imageByteSize = imageSize.width * imageSize.height * 4; + + if (rawImagePixels == NULL) + { + rawImagePixels = (GLubyte *)malloc(imageByteSize); + linesArray = calloc(1024 * 2, sizeof(GLfloat)); + } + + glReadPixels(0, 0, (int)imageSize.width, (int)imageSize.height, GL_RGBA, GL_UNSIGNED_BYTE, rawImagePixels); + +// CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); + + unsigned int imageWidth = imageSize.width * 4; + + unsigned int currentByte = 0; + unsigned int cornerStorageIndex = 0; + unsigned long lineStrengthCounter = 0; + while (currentByte < imageByteSize) + { + GLubyte colorByte = rawImagePixels[currentByte]; +// NSLog(@"(%d,%d): [%d,%d,%d,%d]", xCoordinate, yCoordinate, rawImagePixels[currentByte], rawImagePixels[currentByte+1], rawImagePixels[currentByte+2], rawImagePixels[currentByte+3]); +// NSLog(@"[%d,%d,%d,%d]", rawImagePixels[currentByte], rawImagePixels[currentByte+1], rawImagePixels[currentByte+2], rawImagePixels[currentByte+3]); + + if (colorByte > 0) + { + unsigned int xCoordinate = currentByte % imageWidth; + unsigned int yCoordinate = currentByte / imageWidth; + + lineStrengthCounter += colorByte; +// NSLog(@"(%d,%d): [%d,%d,%d,%d]", xCoordinate, yCoordinate, rawImagePixels[currentByte], rawImagePixels[currentByte+1], rawImagePixels[currentByte+2], rawImagePixels[currentByte+3]); + + CGFloat normalizedXCoordinate = -1.0 + 2.0 * (CGFloat)(xCoordinate / 4) / imageSize.width; + CGFloat normalizedYCoordinate = -1.0 + 2.0 * (CGFloat)(yCoordinate) / imageSize.height; + + if (normalizedXCoordinate < 0.0) + { + // T space + // m = -1 - d/u + // b = d * v/u + if (normalizedXCoordinate > -0.05) // Test for the case right near the X axis, stamp the X intercept instead of the Y + { + linesArray[cornerStorageIndex++] = 100000.0; + linesArray[cornerStorageIndex++] = normalizedYCoordinate; + } + else + { + linesArray[cornerStorageIndex++] = -1.0 - 1.0 / normalizedXCoordinate; + linesArray[cornerStorageIndex++] = 1.0 * normalizedYCoordinate / normalizedXCoordinate; + } + } + else + { + // S space + // m = 1 - d/u + // b = d * v/u + if (normalizedXCoordinate < 0.05) // Test for the case right near the X axis, stamp the X intercept instead of the Y + { + linesArray[cornerStorageIndex++] = 100000.0; + linesArray[cornerStorageIndex++] = normalizedYCoordinate; + } + else + { + linesArray[cornerStorageIndex++] = 1.0 - 1.0 / normalizedXCoordinate; + linesArray[cornerStorageIndex++] = 1.0 * normalizedYCoordinate / normalizedXCoordinate; + } + } + + numberOfLines++; + + numberOfLines = MIN(numberOfLines, 1023); + cornerStorageIndex = MIN(cornerStorageIndex, 2040); + } + currentByte +=4; + } + +// CFAbsoluteTime currentFrameTime = (CFAbsoluteTimeGetCurrent() - startTime); +// NSLog(@"Processing time : %f ms", 1000.0 * currentFrameTime); + + if (linesDetectedBlock != NULL) + { + linesDetectedBlock(linesArray, numberOfLines, frameTime); + } +} + +- (BOOL)wantsMonochromeInput; +{ +// return YES; + return NO; +} + +#pragma mark - +#pragma mark Accessors + +//- (void)setEdgeThreshold:(CGFloat)newValue; +//{ +// [(GPUImageCannyEdgeDetectionFilter *)thresholdEdgeDetectionFilter setThreshold:newValue]; +//} +// +//- (CGFloat)edgeThreshold; +//{ +// return [(GPUImageCannyEdgeDetectionFilter *)thresholdEdgeDetectionFilter threshold]; +//} + +- (void)setLineDetectionThreshold:(CGFloat)newValue; +{ + nonMaximumSuppressionFilter.threshold = newValue; +} + +- (CGFloat)lineDetectionThreshold; +{ + return nonMaximumSuppressionFilter.threshold; +} + +#ifdef DEBUGLINEDETECTION +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ +// [thresholdEdgeDetectionFilter useNextFrameForImageCapture]; +// [parallelCoordinateLineTransformFilter useNextFrameForImageCapture]; + [nonMaximumSuppressionFilter useNextFrameForImageCapture]; + + [super newFrameReadyAtTime:frameTime atIndex:textureIndex]; +} +#endif + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHueBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHueBlendFilter.h new file mode 100644 index 00000000..4399ffcf --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHueBlendFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageHueBlendFilter : GPUImageTwoInputFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHueBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageHueBlendFilter.m new file mode 100644 index 00000000..f9dfbbb8 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHueBlendFilter.m @@ -0,0 +1,212 @@ +#import "GPUImageHueBlendFilter.h" + +/** + * Hue blend mode based upon pseudo code from the PDF specification. + */ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageHueBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + highp float lum(lowp vec3 c) { + return dot(c, vec3(0.3, 0.59, 0.11)); + } + + lowp vec3 clipcolor(lowp vec3 c) { + highp float l = lum(c); + lowp float n = min(min(c.r, c.g), c.b); + lowp float x = max(max(c.r, c.g), c.b); + + if (n < 0.0) { + c.r = l + ((c.r - l) * l) / (l - n); + c.g = l + ((c.g - l) * l) / (l - n); + c.b = l + ((c.b - l) * l) / (l - n); + } + if (x > 1.0) { + c.r = l + ((c.r - l) * (1.0 - l)) / (x - l); + c.g = l + ((c.g - l) * (1.0 - l)) / (x - l); + c.b = l + ((c.b - l) * (1.0 - l)) / (x - l); + } + + return c; + } + + lowp vec3 setlum(lowp vec3 c, highp float l) { + highp float d = l - lum(c); + c = c + vec3(d); + return clipcolor(c); + } + + highp float sat(lowp vec3 c) { + lowp float n = min(min(c.r, c.g), c.b); + lowp float x = max(max(c.r, c.g), c.b); + return x - n; + } + + lowp float mid(lowp float cmin, lowp float cmid, lowp float cmax, highp float s) { + return ((cmid - cmin) * s) / (cmax - cmin); + } + + lowp vec3 setsat(lowp vec3 c, highp float s) { + if (c.r > c.g) { + if (c.r > c.b) { + if (c.g > c.b) { + /* g is mid, b is min */ + c.g = mid(c.b, c.g, c.r, s); + c.b = 0.0; + } else { + /* b is mid, g is min */ + c.b = mid(c.g, c.b, c.r, s); + c.g = 0.0; + } + c.r = s; + } else { + /* b is max, r is mid, g is min */ + c.r = mid(c.g, c.r, c.b, s); + c.b = s; + c.r = 0.0; + } + } else if (c.r > c.b) { + /* g is max, r is mid, b is min */ + c.r = mid(c.b, c.r, c.g, s); + c.g = s; + c.b = 0.0; + } else if (c.g > c.b) { + /* g is max, b is mid, r is min */ + c.b = mid(c.r, c.b, c.g, s); + c.g = s; + c.r = 0.0; + } else if (c.b > c.g) { + /* b is max, g is mid, r is min */ + c.g = mid(c.r, c.g, c.b, s); + c.b = s; + c.r = 0.0; + } else { + c = vec3(0.0); + } + return c; + } + + void main() + { + highp vec4 baseColor = texture2D(inputImageTexture, textureCoordinate); + highp vec4 overlayColor = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(baseColor.rgb * (1.0 - overlayColor.a) + setlum(setsat(overlayColor.rgb, sat(baseColor.rgb)), lum(baseColor.rgb)) * overlayColor.a, baseColor.a); + } +); +#else +NSString *const kGPUImageHueBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + float lum(vec3 c) { + return dot(c, vec3(0.3, 0.59, 0.11)); + } + + vec3 clipcolor(vec3 c) { + float l = lum(c); + float n = min(min(c.r, c.g), c.b); + float x = max(max(c.r, c.g), c.b); + + if (n < 0.0) { + c.r = l + ((c.r - l) * l) / (l - n); + c.g = l + ((c.g - l) * l) / (l - n); + c.b = l + ((c.b - l) * l) / (l - n); + } + if (x > 1.0) { + c.r = l + ((c.r - l) * (1.0 - l)) / (x - l); + c.g = l + ((c.g - l) * (1.0 - l)) / (x - l); + c.b = l + ((c.b - l) * (1.0 - l)) / (x - l); + } + + return c; + } + + vec3 setlum(vec3 c, float l) { + float d = l - lum(c); + c = c + vec3(d); + return clipcolor(c); + } + + float sat(vec3 c) { + float n = min(min(c.r, c.g), c.b); + float x = max(max(c.r, c.g), c.b); + return x - n; + } + + float mid(float cmin, float cmid, float cmax, float s) { + return ((cmid - cmin) * s) / (cmax - cmin); + } + + vec3 setsat(vec3 c, float s) { + if (c.r > c.g) { + if (c.r > c.b) { + if (c.g > c.b) { + /* g is mid, b is min */ + c.g = mid(c.b, c.g, c.r, s); + c.b = 0.0; + } else { + /* b is mid, g is min */ + c.b = mid(c.g, c.b, c.r, s); + c.g = 0.0; + } + c.r = s; + } else { + /* b is max, r is mid, g is min */ + c.r = mid(c.g, c.r, c.b, s); + c.b = s; + c.r = 0.0; + } + } else if (c.r > c.b) { + /* g is max, r is mid, b is min */ + c.r = mid(c.b, c.r, c.g, s); + c.g = s; + c.b = 0.0; + } else if (c.g > c.b) { + /* g is max, b is mid, r is min */ + c.b = mid(c.r, c.b, c.g, s); + c.g = s; + c.r = 0.0; + } else if (c.b > c.g) { + /* b is max, g is mid, r is min */ + c.g = mid(c.r, c.g, c.b, s); + c.b = s; + c.r = 0.0; + } else { + c = vec3(0.0); + } + return c; + } + + void main() + { + vec4 baseColor = texture2D(inputImageTexture, textureCoordinate); + vec4 overlayColor = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(baseColor.rgb * (1.0 - overlayColor.a) + setlum(setsat(overlayColor.rgb, sat(baseColor.rgb)), lum(baseColor.rgb)) * overlayColor.a, baseColor.a); + } +); +#endif + +@implementation GPUImageHueBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageHueBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHueFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageHueFilter.h new file mode 100644 index 00000000..eef24651 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHueFilter.h @@ -0,0 +1,11 @@ + +#import "GPUImageFilter.h" + +@interface GPUImageHueFilter : GPUImageFilter +{ + GLint hueAdjustUniform; + +} +@property (nonatomic, readwrite) CGFloat hue; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageHueFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageHueFilter.m new file mode 100644 index 00000000..5b42c86d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageHueFilter.m @@ -0,0 +1,123 @@ + +#import "GPUImageHueFilter.h" + +// Adapted from http://stackoverflow.com/questions/9234724/how-to-change-hue-of-a-texture-with-glsl - see for code and discussion +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageHueFragmentShaderString = SHADER_STRING +( + precision highp float; + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform mediump float hueAdjust; + const highp vec4 kRGBToYPrime = vec4 (0.299, 0.587, 0.114, 0.0); + const highp vec4 kRGBToI = vec4 (0.595716, -0.274453, -0.321263, 0.0); + const highp vec4 kRGBToQ = vec4 (0.211456, -0.522591, 0.31135, 0.0); + + const highp vec4 kYIQToR = vec4 (1.0, 0.9563, 0.6210, 0.0); + const highp vec4 kYIQToG = vec4 (1.0, -0.2721, -0.6474, 0.0); + const highp vec4 kYIQToB = vec4 (1.0, -1.1070, 1.7046, 0.0); + + void main () + { + // Sample the input pixel + highp vec4 color = texture2D(inputImageTexture, textureCoordinate); + + // Convert to YIQ + highp float YPrime = dot (color, kRGBToYPrime); + highp float I = dot (color, kRGBToI); + highp float Q = dot (color, kRGBToQ); + + // Calculate the hue and chroma + highp float hue = atan (Q, I); + highp float chroma = sqrt (I * I + Q * Q); + + // Make the user's adjustments + hue += (-hueAdjust); //why negative rotation? + + // Convert back to YIQ + Q = chroma * sin (hue); + I = chroma * cos (hue); + + // Convert back to RGB + highp vec4 yIQ = vec4 (YPrime, I, Q, 0.0); + color.r = dot (yIQ, kYIQToR); + color.g = dot (yIQ, kYIQToG); + color.b = dot (yIQ, kYIQToB); + + // Save the result + gl_FragColor = color; + } +); +#else +NSString *const kGPUImageHueFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float hueAdjust; + const vec4 kRGBToYPrime = vec4 (0.299, 0.587, 0.114, 0.0); + const vec4 kRGBToI = vec4 (0.595716, -0.274453, -0.321263, 0.0); + const vec4 kRGBToQ = vec4 (0.211456, -0.522591, 0.31135, 0.0); + + const vec4 kYIQToR = vec4 (1.0, 0.9563, 0.6210, 0.0); + const vec4 kYIQToG = vec4 (1.0, -0.2721, -0.6474, 0.0); + const vec4 kYIQToB = vec4 (1.0, -1.1070, 1.7046, 0.0); + + void main () + { + // Sample the input pixel + vec4 color = texture2D(inputImageTexture, textureCoordinate); + + // Convert to YIQ + float YPrime = dot (color, kRGBToYPrime); + float I = dot (color, kRGBToI); + float Q = dot (color, kRGBToQ); + + // Calculate the hue and chroma + float hue = atan (Q, I); + float chroma = sqrt (I * I + Q * Q); + + // Make the user's adjustments + hue += (-hueAdjust); //why negative rotation? + + // Convert back to YIQ + Q = chroma * sin (hue); + I = chroma * cos (hue); + + // Convert back to RGB + vec4 yIQ = vec4 (YPrime, I, Q, 0.0); + color.r = dot (yIQ, kYIQToR); + color.g = dot (yIQ, kYIQToG); + color.b = dot (yIQ, kYIQToB); + + // Save the result + gl_FragColor = color; + } +); +#endif + +@implementation GPUImageHueFilter +@synthesize hue; + +- (id)init +{ + if(! (self = [super initWithFragmentShaderFromString:kGPUImageHueFragmentShaderString]) ) + { + return nil; + } + + hueAdjustUniform = [filterProgram uniformIndex:@"hueAdjust"]; + self.hue = 90; + + return self; +} + +- (void)setHue:(CGFloat)newHue +{ + // Convert degrees to radians for hue rotation + hue = fmodf(newHue, 360.0) * M_PI/180; + [self setFloat:hue forUniform:hueAdjustUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageJFAVoronoiFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageJFAVoronoiFilter.h new file mode 100644 index 00000000..4c50cc37 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageJFAVoronoiFilter.h @@ -0,0 +1,17 @@ +#import "GPUImageFilter.h" + +@interface GPUImageJFAVoronoiFilter : GPUImageFilter +{ + GLuint secondFilterOutputTexture; + GLuint secondFilterFramebuffer; + + + GLint sampleStepUniform; + GLint sizeUniform; + NSUInteger numPasses; + +} + +@property (nonatomic, readwrite) CGSize sizeInPixels; + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageJFAVoronoiFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageJFAVoronoiFilter.m new file mode 100644 index 00000000..15835917 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageJFAVoronoiFilter.m @@ -0,0 +1,446 @@ +// adapted from unitzeroone - http://unitzeroone.com/labs/jfavoronoi/ + +#import "GPUImageJFAVoronoiFilter.h" + +// The shaders are mostly taken from UnitZeroOne's WebGL example here: +// http://unitzeroone.com/blog/2011/03/22/jump-flood-voronoi-for-webgl/ + +NSString *const kGPUImageJFAVoronoiVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + + uniform float sampleStep; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + void main() + { + gl_Position = position; + + vec2 widthStep = vec2(sampleStep, 0.0); + vec2 heightStep = vec2(0.0, sampleStep); + vec2 widthHeightStep = vec2(sampleStep); + vec2 widthNegativeHeightStep = vec2(sampleStep, -sampleStep); + + textureCoordinate = inputTextureCoordinate.xy; + leftTextureCoordinate = inputTextureCoordinate.xy - widthStep; + rightTextureCoordinate = inputTextureCoordinate.xy + widthStep; + + topTextureCoordinate = inputTextureCoordinate.xy - heightStep; + topLeftTextureCoordinate = inputTextureCoordinate.xy - widthHeightStep; + topRightTextureCoordinate = inputTextureCoordinate.xy + widthNegativeHeightStep; + + bottomTextureCoordinate = inputTextureCoordinate.xy + heightStep; + bottomLeftTextureCoordinate = inputTextureCoordinate.xy - widthNegativeHeightStep; + bottomRightTextureCoordinate = inputTextureCoordinate.xy + widthHeightStep; + } + ); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageJFAVoronoiFragmentShaderString = SHADER_STRING +( + + precision highp float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform vec2 size; + //varying vec2 textureCoordinate; + //uniform float sampleStep; + + vec2 getCoordFromColor(vec4 color) +{ + float z = color.z * 256.0; + float yoff = floor(z / 8.0); + float xoff = mod(z, 8.0); + float x = color.x*256.0 + xoff*256.0; + float y = color.y*256.0 + yoff*256.0; + return vec2(x,y) / size; +} + + void main(void) { + + vec2 sub; + vec4 dst; + vec4 local = texture2D(inputImageTexture, textureCoordinate); + vec4 sam; + float l; + float smallestDist; + if(local.a == 0.0){ + + smallestDist = dot(1.0,1.0); + }else{ + sub = getCoordFromColor(local)-textureCoordinate; + smallestDist = dot(sub,sub); + } + dst = local; + + + sam = texture2D(inputImageTexture, topRightTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, topTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, topLeftTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, bottomRightTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, bottomTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, bottomLeftTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, leftTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, rightTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + gl_FragColor = dst; + } +); +#else +NSString *const kGPUImageJFAVoronoiFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform vec2 size; + //varying vec2 textureCoordinate; + //uniform float sampleStep; + + vec2 getCoordFromColor(vec4 color) +{ + float z = color.z * 256.0; + float yoff = floor(z / 8.0); + float xoff = mod(z, 8.0); + float x = color.x*256.0 + xoff*256.0; + float y = color.y*256.0 + yoff*256.0; + return vec2(x,y) / size; +} + + void main(void) { + + vec2 sub; + vec4 dst; + vec4 local = texture2D(inputImageTexture, textureCoordinate); + vec4 sam; + float l; + float smallestDist; + if(local.a == 0.0){ + + smallestDist = dot(1.0,1.0); + }else{ + sub = getCoordFromColor(local)-textureCoordinate; + smallestDist = dot(sub,sub); + } + dst = local; + + + sam = texture2D(inputImageTexture, topRightTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, topTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, topLeftTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, bottomRightTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, bottomTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, bottomLeftTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, leftTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + + sam = texture2D(inputImageTexture, rightTextureCoordinate); + if(sam.a == 1.0){ + sub = (getCoordFromColor(sam)-textureCoordinate); + l = dot(sub,sub); + if(l < smallestDist){ + smallestDist = l; + dst = sam; + } + } + gl_FragColor = dst; + } +); +#endif + +@interface GPUImageJFAVoronoiFilter() { + int currentPass; +} + + +@end + +@implementation GPUImageJFAVoronoiFilter + +@synthesize sizeInPixels = _sizeInPixels; + +- (id)init; +{ + if (!(self = [super initWithVertexShaderFromString:kGPUImageJFAVoronoiVertexShaderString fragmentShaderFromString:kGPUImageJFAVoronoiFragmentShaderString])) + { + + NSLog(@"nil returned"); + return nil; + + } + + sampleStepUniform = [filterProgram uniformIndex:@"sampleStep"]; + sizeUniform = [filterProgram uniformIndex:@"size"]; + //[self disableSecondFrameCheck]; + + return self; +} + +-(void)setSizeInPixels:(CGSize)sizeInPixels { + _sizeInPixels = sizeInPixels; + + //validate that it's a power of 2 + + float width = log2(sizeInPixels.width); + float height = log2(sizeInPixels.height); + + if (width != height) { + NSLog(@"Voronoi point texture must be square"); + return; + } + if (width != floor(width) || height != floor(height)) { + NSLog(@"Voronoi point texture must be a power of 2. Texture size: %f, %f", sizeInPixels.width, sizeInPixels.height); + return; + } + glUniform2f(sizeUniform, _sizeInPixels.width, _sizeInPixels.height); +} + +#pragma mark - +#pragma mark Managing the display FBOs + +-(NSUInteger)nextPowerOfTwo:(CGPoint)input { + NSUInteger val; + if (input.x > input.y) { + val = (NSUInteger)input.x; + } else { + val = (NSUInteger)input.y; + } + + val--; + val = (val >> 1) | val; + val = (val >> 2) | val; + val = (val >> 4) | val; + val = (val >> 8) | val; + val = (val >> 16) | val; + val++; + return val; +} + +//- (void)setOutputFBO; +//{ +// if (currentPass % 2 == 1) { +// [self setSecondFilterFBO]; +// } else { +// [self setFilterFBO]; +// } +// +//} + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + // Run the first stage of the two-pass filter + [GPUImageContext setActiveShaderProgram:filterProgram]; + currentPass = 0; + + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + + glActiveTexture(GL_TEXTURE2); + + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glUniform1f(sampleStepUniform, 0.5); + + glUniform2f(sizeUniform, _sizeInPixels.width, _sizeInPixels.height); + + glBindTexture(GL_TEXTURE_2D, [firstInputFramebuffer texture]); + + glUniform1i(filterInputTextureUniform, 2); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + for (int pass = 1; pass <= numPasses + 1; pass++) { + currentPass = pass; +// [self setOutputFBO]; + + //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE2); + if (pass % 2 == 0) { + glBindTexture(GL_TEXTURE_2D, secondFilterOutputTexture); + } else { + glBindTexture(GL_TEXTURE_2D, [outputFramebuffer texture]); + } + glUniform1i(filterInputTextureUniform, 2); + + float step = pow(2.0, numPasses - pass) / pow(2.0, numPasses); + glUniform1f(sampleStepUniform, step); + glUniform2f(sizeUniform, _sizeInPixels.width, _sizeInPixels.height); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaFilter.h new file mode 100755 index 00000000..4fb0bce8 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaFilter.h @@ -0,0 +1,13 @@ +#import "GPUImageFilter.h" + +/** Kuwahara image abstraction, drawn from the work of Kyprianidis, et. al. in their publication "Anisotropic Kuwahara Filtering on the GPU" within the GPU Pro collection. This produces an oil-painting-like image, but it is extremely computationally expensive, so it can take seconds to render a frame on an iPad 2. This might be best used for still images. + */ +@interface GPUImageKuwaharaFilter : GPUImageFilter +{ + GLint radiusUniform; +} + +/// The radius to sample from when creating the brush-stroke effect, with a default of 3. The larger the radius, the slower the filter. +@property(readwrite, nonatomic) NSUInteger radius; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaFilter.m new file mode 100755 index 00000000..9061dbf3 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaFilter.m @@ -0,0 +1,223 @@ +#import "GPUImageKuwaharaFilter.h" + +// Sourced from Kyprianidis, J. E., Kang, H., and Doellner, J. "Anisotropic Kuwahara Filtering on the GPU," GPU Pro p.247 (2010). +// +// Original header: +// +// Anisotropic Kuwahara Filtering on the GPU +// by Jan Eric Kyprianidis + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageKuwaharaFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform int radius; + + precision highp float; + + const vec2 src_size = vec2 (1.0 / 768.0, 1.0 / 1024.0); + + void main (void) + { + vec2 uv = textureCoordinate; + float n = float((radius + 1) * (radius + 1)); + int i; int j; + vec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0); + vec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0); + vec3 c; + + for (j = -radius; j <= 0; ++j) { + for (i = -radius; i <= 0; ++i) { + c = texture2D(inputImageTexture, uv + vec2(i,j) * src_size).rgb; + m0 += c; + s0 += c * c; + } + } + + for (j = -radius; j <= 0; ++j) { + for (i = 0; i <= radius; ++i) { + c = texture2D(inputImageTexture, uv + vec2(i,j) * src_size).rgb; + m1 += c; + s1 += c * c; + } + } + + for (j = 0; j <= radius; ++j) { + for (i = 0; i <= radius; ++i) { + c = texture2D(inputImageTexture, uv + vec2(i,j) * src_size).rgb; + m2 += c; + s2 += c * c; + } + } + + for (j = 0; j <= radius; ++j) { + for (i = -radius; i <= 0; ++i) { + c = texture2D(inputImageTexture, uv + vec2(i,j) * src_size).rgb; + m3 += c; + s3 += c * c; + } + } + + + float min_sigma2 = 1e+2; + m0 /= n; + s0 = abs(s0 / n - m0 * m0); + + float sigma2 = s0.r + s0.g + s0.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m0, 1.0); + } + + m1 /= n; + s1 = abs(s1 / n - m1 * m1); + + sigma2 = s1.r + s1.g + s1.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m1, 1.0); + } + + m2 /= n; + s2 = abs(s2 / n - m2 * m2); + + sigma2 = s2.r + s2.g + s2.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m2, 1.0); + } + + m3 /= n; + s3 = abs(s3 / n - m3 * m3); + + sigma2 = s3.r + s3.g + s3.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m3, 1.0); + } + } +); +#else +NSString *const kGPUImageKuwaharaFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform int radius; + + const vec2 src_size = vec2 (1.0 / 768.0, 1.0 / 1024.0); + + void main (void) + { + vec2 uv = textureCoordinate; + float n = float((radius + 1) * (radius + 1)); + int i; int j; + vec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0); + vec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0); + vec3 c; + + for (j = -radius; j <= 0; ++j) { + for (i = -radius; i <= 0; ++i) { + c = texture2D(inputImageTexture, uv + vec2(i,j) * src_size).rgb; + m0 += c; + s0 += c * c; + } + } + + for (j = -radius; j <= 0; ++j) { + for (i = 0; i <= radius; ++i) { + c = texture2D(inputImageTexture, uv + vec2(i,j) * src_size).rgb; + m1 += c; + s1 += c * c; + } + } + + for (j = 0; j <= radius; ++j) { + for (i = 0; i <= radius; ++i) { + c = texture2D(inputImageTexture, uv + vec2(i,j) * src_size).rgb; + m2 += c; + s2 += c * c; + } + } + + for (j = 0; j <= radius; ++j) { + for (i = -radius; i <= 0; ++i) { + c = texture2D(inputImageTexture, uv + vec2(i,j) * src_size).rgb; + m3 += c; + s3 += c * c; + } + } + + + float min_sigma2 = 1e+2; + m0 /= n; + s0 = abs(s0 / n - m0 * m0); + + float sigma2 = s0.r + s0.g + s0.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m0, 1.0); + } + + m1 /= n; + s1 = abs(s1 / n - m1 * m1); + + sigma2 = s1.r + s1.g + s1.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m1, 1.0); + } + + m2 /= n; + s2 = abs(s2 / n - m2 * m2); + + sigma2 = s2.r + s2.g + s2.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m2, 1.0); + } + + m3 /= n; + s3 = abs(s3 / n - m3 * m3); + + sigma2 = s3.r + s3.g + s3.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m3, 1.0); + } + } +); +#endif + +@implementation GPUImageKuwaharaFilter + +@synthesize radius = _radius; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageKuwaharaFragmentShaderString])) + { + return nil; + } + + radiusUniform = [filterProgram uniformIndex:@"radius"]; + + self.radius = 3; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setRadius:(NSUInteger)newValue; +{ + _radius = newValue; + + [self setInteger:(GLint)_radius forUniform:radiusUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaRadius3Filter.h b/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaRadius3Filter.h new file mode 100644 index 00000000..c4591b81 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaRadius3Filter.h @@ -0,0 +1,8 @@ +// +// GPUImageKuwaharaRadius3Filter.h + +#import "GPUImageFilter.h" + +@interface GPUImageKuwaharaRadius3Filter : GPUImageFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaRadius3Filter.m b/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaRadius3Filter.m new file mode 100644 index 00000000..98b092c6 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageKuwaharaRadius3Filter.m @@ -0,0 +1,547 @@ +#import "GPUImageKuwaharaRadius3Filter.h" + +// Sourced from Kyprianidis, J. E., Kang, H., and Doellner, J. "Anisotropic Kuwahara Filtering on the GPU," GPU Pro p.247 (2010). +// +// Original header: +// +// Anisotropic Kuwahara Filtering on the GPU +// by Jan Eric Kyprianidis + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageKuwaharaRadius3FragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + + precision highp float; + + const vec2 src_size = vec2 (1.0 / 768.0, 1.0 / 1024.0); + + void main (void) + { + vec2 uv = textureCoordinate; + float n = float(16); // radius is assumed to be 3 + vec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0); + vec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0); + vec3 c; + vec3 cSq; + + c = texture2D(inputImageTexture, uv + vec2(-3,-3) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-3,-2) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-3,-1) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-3,0) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m1 += c; + s1 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(-2,-3) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-2,-2) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-2,-1) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-2,0) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m1 += c; + s1 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(-1,-3) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-1,-2) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-1,-1) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-1,0) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m1 += c; + s1 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(0,-3) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m3 += c; + s3 += cSq; + c = texture2D(inputImageTexture, uv + vec2(0,-2) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m3 += c; + s3 += cSq; + c = texture2D(inputImageTexture, uv + vec2(0,-1) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m3 += c; + s3 += cSq; + c = texture2D(inputImageTexture, uv + vec2(0,0) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m1 += c; + s1 += cSq; + m2 += c; + s2 += cSq; + m3 += c; + s3 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(-3,3) * src_size).rgb; + m1 += c; + s1 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-3,2) * src_size).rgb; + m1 += c; + s1 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-3,1) * src_size).rgb; + m1 += c; + s1 += c * c; + + c = texture2D(inputImageTexture, uv + vec2(-2,3) * src_size).rgb; + m1 += c; + s1 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-2,2) * src_size).rgb; + m1 += c; + s1 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-2,1) * src_size).rgb; + m1 += c; + s1 += c * c; + + c = texture2D(inputImageTexture, uv + vec2(-1,3) * src_size).rgb; + m1 += c; + s1 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-1,2) * src_size).rgb; + m1 += c; + s1 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-1,1) * src_size).rgb; + m1 += c; + s1 += c * c; + + c = texture2D(inputImageTexture, uv + vec2(0,3) * src_size).rgb; + cSq = c * c; + m1 += c; + s1 += cSq; + m2 += c; + s2 += cSq; + c = texture2D(inputImageTexture, uv + vec2(0,2) * src_size).rgb; + cSq = c * c; + m1 += c; + s1 += cSq; + m2 += c; + s2 += cSq; + c = texture2D(inputImageTexture, uv + vec2(0,1) * src_size).rgb; + cSq = c * c; + m1 += c; + s1 += cSq; + m2 += c; + s2 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(3,3) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(3,2) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(3,1) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(3,0) * src_size).rgb; + cSq = c * c; + m2 += c; + s2 += cSq; + m3 += c; + s3 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(2,3) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(2,2) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(2,1) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(2,0) * src_size).rgb; + cSq = c * c; + m2 += c; + s2 += cSq; + m3 += c; + s3 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(1,3) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(1,2) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(1,1) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(1,0) * src_size).rgb; + cSq = c * c; + m2 += c; + s2 += cSq; + m3 += c; + s3 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(3,-3) * src_size).rgb; + m3 += c; + s3 += c * c; + c = texture2D(inputImageTexture, uv + vec2(3,-2) * src_size).rgb; + m3 += c; + s3 += c * c; + c = texture2D(inputImageTexture, uv + vec2(3,-1) * src_size).rgb; + m3 += c; + s3 += c * c; + + c = texture2D(inputImageTexture, uv + vec2(2,-3) * src_size).rgb; + m3 += c; + s3 += c * c; + c = texture2D(inputImageTexture, uv + vec2(2,-2) * src_size).rgb; + m3 += c; + s3 += c * c; + c = texture2D(inputImageTexture, uv + vec2(2,-1) * src_size).rgb; + m3 += c; + s3 += c * c; + + c = texture2D(inputImageTexture, uv + vec2(1,-3) * src_size).rgb; + m3 += c; + s3 += c * c; + c = texture2D(inputImageTexture, uv + vec2(1,-2) * src_size).rgb; + m3 += c; + s3 += c * c; + c = texture2D(inputImageTexture, uv + vec2(1,-1) * src_size).rgb; + m3 += c; + s3 += c * c; + + float min_sigma2 = 1e+2; + m0 /= n; + s0 = abs(s0 / n - m0 * m0); + + float sigma2 = s0.r + s0.g + s0.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m0, 1.0); + } + + m1 /= n; + s1 = abs(s1 / n - m1 * m1); + + sigma2 = s1.r + s1.g + s1.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m1, 1.0); + } + + m2 /= n; + s2 = abs(s2 / n - m2 * m2); + + sigma2 = s2.r + s2.g + s2.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m2, 1.0); + } + + m3 /= n; + s3 = abs(s3 / n - m3 * m3); + + sigma2 = s3.r + s3.g + s3.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m3, 1.0); + } + } +); +#else +NSString *const kGPUImageKuwaharaRadius3FragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + + const vec2 src_size = vec2 (1.0 / 768.0, 1.0 / 1024.0); + + void main (void) + { + vec2 uv = textureCoordinate; + float n = float(16); // radius is assumed to be 3 + vec3 m0 = vec3(0.0); vec3 m1 = vec3(0.0); vec3 m2 = vec3(0.0); vec3 m3 = vec3(0.0); + vec3 s0 = vec3(0.0); vec3 s1 = vec3(0.0); vec3 s2 = vec3(0.0); vec3 s3 = vec3(0.0); + vec3 c; + vec3 cSq; + + c = texture2D(inputImageTexture, uv + vec2(-3,-3) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-3,-2) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-3,-1) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-3,0) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m1 += c; + s1 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(-2,-3) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-2,-2) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-2,-1) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-2,0) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m1 += c; + s1 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(-1,-3) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-1,-2) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-1,-1) * src_size).rgb; + m0 += c; + s0 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-1,0) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m1 += c; + s1 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(0,-3) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m3 += c; + s3 += cSq; + c = texture2D(inputImageTexture, uv + vec2(0,-2) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m3 += c; + s3 += cSq; + c = texture2D(inputImageTexture, uv + vec2(0,-1) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m3 += c; + s3 += cSq; + c = texture2D(inputImageTexture, uv + vec2(0,0) * src_size).rgb; + cSq = c * c; + m0 += c; + s0 += cSq; + m1 += c; + s1 += cSq; + m2 += c; + s2 += cSq; + m3 += c; + s3 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(-3,3) * src_size).rgb; + m1 += c; + s1 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-3,2) * src_size).rgb; + m1 += c; + s1 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-3,1) * src_size).rgb; + m1 += c; + s1 += c * c; + + c = texture2D(inputImageTexture, uv + vec2(-2,3) * src_size).rgb; + m1 += c; + s1 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-2,2) * src_size).rgb; + m1 += c; + s1 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-2,1) * src_size).rgb; + m1 += c; + s1 += c * c; + + c = texture2D(inputImageTexture, uv + vec2(-1,3) * src_size).rgb; + m1 += c; + s1 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-1,2) * src_size).rgb; + m1 += c; + s1 += c * c; + c = texture2D(inputImageTexture, uv + vec2(-1,1) * src_size).rgb; + m1 += c; + s1 += c * c; + + c = texture2D(inputImageTexture, uv + vec2(0,3) * src_size).rgb; + cSq = c * c; + m1 += c; + s1 += cSq; + m2 += c; + s2 += cSq; + c = texture2D(inputImageTexture, uv + vec2(0,2) * src_size).rgb; + cSq = c * c; + m1 += c; + s1 += cSq; + m2 += c; + s2 += cSq; + c = texture2D(inputImageTexture, uv + vec2(0,1) * src_size).rgb; + cSq = c * c; + m1 += c; + s1 += cSq; + m2 += c; + s2 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(3,3) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(3,2) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(3,1) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(3,0) * src_size).rgb; + cSq = c * c; + m2 += c; + s2 += cSq; + m3 += c; + s3 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(2,3) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(2,2) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(2,1) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(2,0) * src_size).rgb; + cSq = c * c; + m2 += c; + s2 += cSq; + m3 += c; + s3 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(1,3) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(1,2) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(1,1) * src_size).rgb; + m2 += c; + s2 += c * c; + c = texture2D(inputImageTexture, uv + vec2(1,0) * src_size).rgb; + cSq = c * c; + m2 += c; + s2 += cSq; + m3 += c; + s3 += cSq; + + c = texture2D(inputImageTexture, uv + vec2(3,-3) * src_size).rgb; + m3 += c; + s3 += c * c; + c = texture2D(inputImageTexture, uv + vec2(3,-2) * src_size).rgb; + m3 += c; + s3 += c * c; + c = texture2D(inputImageTexture, uv + vec2(3,-1) * src_size).rgb; + m3 += c; + s3 += c * c; + + c = texture2D(inputImageTexture, uv + vec2(2,-3) * src_size).rgb; + m3 += c; + s3 += c * c; + c = texture2D(inputImageTexture, uv + vec2(2,-2) * src_size).rgb; + m3 += c; + s3 += c * c; + c = texture2D(inputImageTexture, uv + vec2(2,-1) * src_size).rgb; + m3 += c; + s3 += c * c; + + c = texture2D(inputImageTexture, uv + vec2(1,-3) * src_size).rgb; + m3 += c; + s3 += c * c; + c = texture2D(inputImageTexture, uv + vec2(1,-2) * src_size).rgb; + m3 += c; + s3 += c * c; + c = texture2D(inputImageTexture, uv + vec2(1,-1) * src_size).rgb; + m3 += c; + s3 += c * c; + + float min_sigma2 = 1e+2; + m0 /= n; + s0 = abs(s0 / n - m0 * m0); + + float sigma2 = s0.r + s0.g + s0.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m0, 1.0); + } + + m1 /= n; + s1 = abs(s1 / n - m1 * m1); + + sigma2 = s1.r + s1.g + s1.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m1, 1.0); + } + + m2 /= n; + s2 = abs(s2 / n - m2 * m2); + + sigma2 = s2.r + s2.g + s2.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m2, 1.0); + } + + m3 /= n; + s3 = abs(s3 / n - m3 * m3); + + sigma2 = s3.r + s3.g + s3.b; + if (sigma2 < min_sigma2) { + min_sigma2 = sigma2; + gl_FragColor = vec4(m3, 1.0); + } + } +); +#endif + +@implementation GPUImageKuwaharaRadius3Filter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageKuwaharaRadius3FragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLanczosResamplingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLanczosResamplingFilter.h new file mode 100644 index 00000000..5d7409f5 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLanczosResamplingFilter.h @@ -0,0 +1,7 @@ +#import "GPUImageTwoPassTextureSamplingFilter.h" + +@interface GPUImageLanczosResamplingFilter : GPUImageTwoPassTextureSamplingFilter + +@property(readwrite, nonatomic) CGSize originalImageSize; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLanczosResamplingFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageLanczosResamplingFilter.m new file mode 100644 index 00000000..a655f486 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLanczosResamplingFilter.m @@ -0,0 +1,239 @@ +#import "GPUImageLanczosResamplingFilter.h" + +NSString *const kGPUImageLanczosVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec2 inputTextureCoordinate; + + uniform float texelWidthOffset; + uniform float texelHeightOffset; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepLeftTextureCoordinate; + varying vec2 twoStepsLeftTextureCoordinate; + varying vec2 threeStepsLeftTextureCoordinate; + varying vec2 fourStepsLeftTextureCoordinate; + varying vec2 oneStepRightTextureCoordinate; + varying vec2 twoStepsRightTextureCoordinate; + varying vec2 threeStepsRightTextureCoordinate; + varying vec2 fourStepsRightTextureCoordinate; + + void main() + { + gl_Position = position; + + vec2 firstOffset = vec2(texelWidthOffset, texelHeightOffset); + vec2 secondOffset = vec2(2.0 * texelWidthOffset, 2.0 * texelHeightOffset); + vec2 thirdOffset = vec2(3.0 * texelWidthOffset, 3.0 * texelHeightOffset); + vec2 fourthOffset = vec2(4.0 * texelWidthOffset, 4.0 * texelHeightOffset); + + centerTextureCoordinate = inputTextureCoordinate; + oneStepLeftTextureCoordinate = inputTextureCoordinate - firstOffset; + twoStepsLeftTextureCoordinate = inputTextureCoordinate - secondOffset; + threeStepsLeftTextureCoordinate = inputTextureCoordinate - thirdOffset; + fourStepsLeftTextureCoordinate = inputTextureCoordinate - fourthOffset; + oneStepRightTextureCoordinate = inputTextureCoordinate + firstOffset; + twoStepsRightTextureCoordinate = inputTextureCoordinate + secondOffset; + threeStepsRightTextureCoordinate = inputTextureCoordinate + thirdOffset; + fourStepsRightTextureCoordinate = inputTextureCoordinate + fourthOffset; + } +); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLanczosFragmentShaderString = SHADER_STRING +( + precision highp float; + + uniform sampler2D inputImageTexture; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepLeftTextureCoordinate; + varying vec2 twoStepsLeftTextureCoordinate; + varying vec2 threeStepsLeftTextureCoordinate; + varying vec2 fourStepsLeftTextureCoordinate; + varying vec2 oneStepRightTextureCoordinate; + varying vec2 twoStepsRightTextureCoordinate; + varying vec2 threeStepsRightTextureCoordinate; + varying vec2 fourStepsRightTextureCoordinate; + + // sinc(x) * sinc(x/a) = (a * sin(pi * x) * sin(pi * x / a)) / (pi^2 * x^2) + // Assuming a Lanczos constant of 2.0, and scaling values to max out at x = +/- 1.5 + + void main() + { + lowp vec4 fragmentColor = texture2D(inputImageTexture, centerTextureCoordinate) * 0.38026; + + fragmentColor += texture2D(inputImageTexture, oneStepLeftTextureCoordinate) * 0.27667; + fragmentColor += texture2D(inputImageTexture, oneStepRightTextureCoordinate) * 0.27667; + + fragmentColor += texture2D(inputImageTexture, twoStepsLeftTextureCoordinate) * 0.08074; + fragmentColor += texture2D(inputImageTexture, twoStepsRightTextureCoordinate) * 0.08074; + + fragmentColor += texture2D(inputImageTexture, threeStepsLeftTextureCoordinate) * -0.02612; + fragmentColor += texture2D(inputImageTexture, threeStepsRightTextureCoordinate) * -0.02612; + + fragmentColor += texture2D(inputImageTexture, fourStepsLeftTextureCoordinate) * -0.02143; + fragmentColor += texture2D(inputImageTexture, fourStepsRightTextureCoordinate) * -0.02143; + + gl_FragColor = fragmentColor; + } +); +#else +NSString *const kGPUImageLanczosFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepLeftTextureCoordinate; + varying vec2 twoStepsLeftTextureCoordinate; + varying vec2 threeStepsLeftTextureCoordinate; + varying vec2 fourStepsLeftTextureCoordinate; + varying vec2 oneStepRightTextureCoordinate; + varying vec2 twoStepsRightTextureCoordinate; + varying vec2 threeStepsRightTextureCoordinate; + varying vec2 fourStepsRightTextureCoordinate; + + // sinc(x) * sinc(x/a) = (a * sin(pi * x) * sin(pi * x / a)) / (pi^2 * x^2) + // Assuming a Lanczos constant of 2.0, and scaling values to max out at x = +/- 1.5 + + void main() + { + vec4 fragmentColor = texture2D(inputImageTexture, centerTextureCoordinate) * 0.38026; + + fragmentColor += texture2D(inputImageTexture, oneStepLeftTextureCoordinate) * 0.27667; + fragmentColor += texture2D(inputImageTexture, oneStepRightTextureCoordinate) * 0.27667; + + fragmentColor += texture2D(inputImageTexture, twoStepsLeftTextureCoordinate) * 0.08074; + fragmentColor += texture2D(inputImageTexture, twoStepsRightTextureCoordinate) * 0.08074; + + fragmentColor += texture2D(inputImageTexture, threeStepsLeftTextureCoordinate) * -0.02612; + fragmentColor += texture2D(inputImageTexture, threeStepsRightTextureCoordinate) * -0.02612; + + fragmentColor += texture2D(inputImageTexture, fourStepsLeftTextureCoordinate) * -0.02143; + fragmentColor += texture2D(inputImageTexture, fourStepsRightTextureCoordinate) * -0.02143; + + gl_FragColor = fragmentColor; + } +); +#endif + +@implementation GPUImageLanczosResamplingFilter + +@synthesize originalImageSize = _originalImageSize; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFirstStageVertexShaderFromString:kGPUImageLanczosVertexShaderString firstStageFragmentShaderFromString:kGPUImageLanczosFragmentShaderString secondStageVertexShaderFromString:kGPUImageLanczosVertexShaderString secondStageFragmentShaderFromString:kGPUImageLanczosFragmentShaderString])) + { + return nil; + } + + return self; +} + +// Base texture sampling offset on the input image, not the final size +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + self.originalImageSize = newSize; + [super setInputSize:newSize atIndex:textureIndex]; +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + runSynchronouslyOnVideoProcessingQueue(^{ + // The first pass through the framebuffer may rotate the inbound image, so need to account for that by changing up the kernel ordering for that pass + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + verticalPassTexelWidthOffset = 1.0 / _originalImageSize.height; + verticalPassTexelHeightOffset = 0.0; + } + else + { + verticalPassTexelWidthOffset = 0.0; + verticalPassTexelHeightOffset = 1.0 / _originalImageSize.height; + } + + horizontalPassTexelWidthOffset = 1.0 / _originalImageSize.width; + horizontalPassTexelHeightOffset = 0.0; + }); +} + + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + if (self.preventRendering) + { + [firstInputFramebuffer unlock]; + return; + } + + [GPUImageContext setActiveShaderProgram:filterProgram]; + + CGSize currentFBOSize = [self sizeOfFBO]; + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + currentFBOSize.height = self.originalImageSize.height; + } + else + { + currentFBOSize.width = self.originalImageSize.width; + } + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:currentFBOSize textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + + [self setUniformsForProgramAtIndex:0]; + + glClearColor(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha); + glClear(GL_COLOR_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, [firstInputFramebuffer texture]); + + glUniform1i(filterInputTextureUniform, 2); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + [firstInputFramebuffer unlock]; + + // Run the second stage of the two-pass filter + [GPUImageContext setActiveShaderProgram:secondFilterProgram]; + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, 0); + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, 0); + secondOutputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [secondOutputFramebuffer activateFramebuffer]; + if (usingNextFrameForImageCapture) + { + [secondOutputFramebuffer lock]; + } + + [self setUniformsForProgramAtIndex:1]; + + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, [outputFramebuffer texture]); + glVertexAttribPointer(secondFilterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [[self class] textureCoordinatesForRotation:kGPUImageNoRotation]); + + glUniform1i(secondFilterInputTextureUniform, 3); + + glVertexAttribPointer(secondFilterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + [outputFramebuffer unlock]; + outputFramebuffer = nil; + if (usingNextFrameForImageCapture) + { + dispatch_semaphore_signal(imageCaptureSemaphore); + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLaplacianFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLaplacianFilter.h new file mode 100644 index 00000000..267c1bab --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLaplacianFilter.h @@ -0,0 +1,5 @@ +#import "GPUImage3x3ConvolutionFilter.h" + +@interface GPUImageLaplacianFilter : GPUImage3x3ConvolutionFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLaplacianFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageLaplacianFilter.m new file mode 100644 index 00000000..98b78509 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLaplacianFilter.m @@ -0,0 +1,115 @@ +#import "GPUImageLaplacianFilter.h" +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLaplacianFragmentShaderString = SHADER_STRING +( + precision highp float; + + uniform sampler2D inputImageTexture; + + uniform mediump mat3 convolutionMatrix; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + void main() + { + mediump vec3 bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + mediump vec3 bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb; + mediump vec3 bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb; + mediump vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); + mediump vec3 leftColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + mediump vec3 rightColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; + mediump vec3 topColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; + mediump vec3 topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).rgb; + mediump vec3 topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).rgb; + + mediump vec3 resultColor = topLeftColor * convolutionMatrix[0][0] + topColor * convolutionMatrix[0][1] + topRightColor * convolutionMatrix[0][2]; + resultColor += leftColor * convolutionMatrix[1][0] + centerColor.rgb * convolutionMatrix[1][1] + rightColor * convolutionMatrix[1][2]; + resultColor += bottomLeftColor * convolutionMatrix[2][0] + bottomColor * convolutionMatrix[2][1] + bottomRightColor * convolutionMatrix[2][2]; + + // Normalize the results to allow for negative gradients in the 0.0-1.0 colorspace + resultColor = resultColor + 0.5; + + gl_FragColor = vec4(resultColor, centerColor.a); + } +); +#else +NSString *const kGPUImageLaplacianFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + uniform mat3 convolutionMatrix; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + void main() + { + vec3 bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + vec3 bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb; + vec3 bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb; + vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); + vec3 leftColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + vec3 rightColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; + vec3 topColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; + vec3 topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).rgb; + vec3 topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).rgb; + + vec3 resultColor = topLeftColor * convolutionMatrix[0][0] + topColor * convolutionMatrix[0][1] + topRightColor * convolutionMatrix[0][2]; + resultColor += leftColor * convolutionMatrix[1][0] + centerColor.rgb * convolutionMatrix[1][1] + rightColor * convolutionMatrix[1][2]; + resultColor += bottomLeftColor * convolutionMatrix[2][0] + bottomColor * convolutionMatrix[2][1] + bottomRightColor * convolutionMatrix[2][2]; + + // Normalize the results to allow for negative gradients in the 0.0-1.0 colorspace + resultColor = resultColor + 0.5; + + gl_FragColor = vec4(resultColor, centerColor.a); + } +); +#endif + +@implementation GPUImageLaplacianFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageLaplacianFragmentShaderString])) + { + return nil; + } + + GPUMatrix3x3 newConvolutionMatrix; + newConvolutionMatrix.one.one = 0.5; + newConvolutionMatrix.one.two = 1.0; + newConvolutionMatrix.one.three = 0.5; + + newConvolutionMatrix.two.one = 1.0; + newConvolutionMatrix.two.two = -6.0; + newConvolutionMatrix.two.three = 1.0; + + newConvolutionMatrix.three.one = 0.5; + newConvolutionMatrix.three.two = 1.0; + newConvolutionMatrix.three.three = 0.5; + + self.convolutionKernel = newConvolutionMatrix; + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLevelsFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLevelsFilter.h new file mode 100644 index 00000000..d0948fbf --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLevelsFilter.h @@ -0,0 +1,45 @@ +#import "GPUImageFilter.h" + +/** + * Levels like Photoshop. + * + * The min, max, minOut and maxOut parameters are floats in the range [0, 1]. + * If you have parameters from Photoshop in the range [0, 255] you must first + * convert them to be [0, 1]. + * The gamma/mid parameter is a float >= 0. This matches the value from Photoshop. + * + * If you want to apply levels to RGB as well as individual channels you need to use + * this filter twice - first for the individual channels and then for all channels. + */ +@interface GPUImageLevelsFilter : GPUImageFilter +{ + GLint minUniform; + GLint midUniform; + GLint maxUniform; + GLint minOutputUniform; + GLint maxOutputUniform; + + GPUVector3 minVector, midVector, maxVector, minOutputVector, maxOutputVector; +} + +/** Set levels for the red channel */ +- (void)setRedMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max minOut:(CGFloat)minOut maxOut:(CGFloat)maxOut; + +- (void)setRedMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max; + +/** Set levels for the green channel */ +- (void)setGreenMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max minOut:(CGFloat)minOut maxOut:(CGFloat)maxOut; + +- (void)setGreenMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max; + +/** Set levels for the blue channel */ +- (void)setBlueMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max minOut:(CGFloat)minOut maxOut:(CGFloat)maxOut; + +- (void)setBlueMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max; + +/** Set levels for all channels at once */ +- (void)setMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max minOut:(CGFloat)minOut maxOut:(CGFloat)maxOut; +- (void)setMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max; + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLevelsFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageLevelsFilter.m new file mode 100644 index 00000000..158815fd --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLevelsFilter.m @@ -0,0 +1,152 @@ +#import "GPUImageLevelsFilter.h" + +/* + ** Gamma correction + ** Details: http://blog.mouaif.org/2009/01/22/photoshop-gamma-correction-shader/ + */ + +#define GammaCorrection(color, gamma) pow(color, 1.0 / gamma) + +/* + ** Levels control (input (+gamma), output) + ** Details: http://blog.mouaif.org/2009/01/28/levels-control-shader/ + */ + +#define LevelsControlInputRange(color, minInput, maxInput) min(max(color - minInput, vec3(0.0)) / (maxInput - minInput), vec3(1.0)) +#define LevelsControlInput(color, minInput, gamma, maxInput) GammaCorrection(LevelsControlInputRange(color, minInput, maxInput), gamma) +#define LevelsControlOutputRange(color, minOutput, maxOutput) mix(minOutput, maxOutput, color) +#define LevelsControl(color, minInput, gamma, maxInput, minOutput, maxOutput) LevelsControlOutputRange(LevelsControlInput(color, minInput, gamma, maxInput), minOutput, maxOutput) + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLevelsFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform mediump vec3 levelMinimum; + uniform mediump vec3 levelMiddle; + uniform mediump vec3 levelMaximum; + uniform mediump vec3 minOutput; + uniform mediump vec3 maxOutput; + + void main() + { + mediump vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4(LevelsControl(textureColor.rgb, levelMinimum, levelMiddle, levelMaximum, minOutput, maxOutput), textureColor.a); + } +); +#else +NSString *const kGPUImageLevelsFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform vec3 levelMinimum; + uniform vec3 levelMiddle; + uniform vec3 levelMaximum; + uniform vec3 minOutput; + uniform vec3 maxOutput; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4(LevelsControl(textureColor.rgb, levelMinimum, levelMiddle, levelMaximum, minOutput, maxOutput), textureColor.a); + } +); +#endif + +@implementation GPUImageLevelsFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageLevelsFragmentShaderString])) + { + return nil; + } + + minUniform = [filterProgram uniformIndex:@"levelMinimum"]; + midUniform = [filterProgram uniformIndex:@"levelMiddle"]; + maxUniform = [filterProgram uniformIndex:@"levelMaximum"]; + minOutputUniform = [filterProgram uniformIndex:@"minOutput"]; + maxOutputUniform = [filterProgram uniformIndex:@"maxOutput"]; + + [self setRedMin:0.0 gamma:1.0 max:1.0 minOut:0.0 maxOut:1.0]; + [self setGreenMin:0.0 gamma:1.0 max:1.0 minOut:0.0 maxOut:1.0]; + [self setBlueMin:0.0 gamma:1.0 max:1.0 minOut:0.0 maxOut:1.0]; + + return self; +} + +#pragma mark - +#pragma mark Helpers + +- (void)updateUniforms { + [self setVec3:minVector forUniform:minUniform program:filterProgram]; + [self setVec3:midVector forUniform:midUniform program:filterProgram]; + [self setVec3:maxVector forUniform:maxUniform program:filterProgram]; + [self setVec3:minOutputVector forUniform:minOutputUniform program:filterProgram]; + [self setVec3:maxOutputVector forUniform:maxOutputUniform program:filterProgram]; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max minOut:(CGFloat)minOut maxOut:(CGFloat)maxOut { + [self setRedMin:min gamma:mid max:max minOut:minOut maxOut:maxOut]; + [self setGreenMin:min gamma:mid max:max minOut:minOut maxOut:maxOut]; + [self setBlueMin:min gamma:mid max:max minOut:minOut maxOut:maxOut]; +} + +- (void)setMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max { + [self setMin:min gamma:mid max:max minOut:0.0 maxOut:1.0]; +} + +- (void)setRedMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max minOut:(CGFloat)minOut maxOut:(CGFloat)maxOut { + minVector.one = min; + midVector.one = mid; + maxVector.one = max; + minOutputVector.one = minOut; + maxOutputVector.one = maxOut; + + [self updateUniforms]; +} + +- (void)setRedMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max { + [self setRedMin:min gamma:mid max:max minOut:0.0 maxOut:1.0]; +} + +- (void)setGreenMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max minOut:(CGFloat)minOut maxOut:(CGFloat)maxOut { + minVector.two = min; + midVector.two = mid; + maxVector.two = max; + minOutputVector.two = minOut; + maxOutputVector.two = maxOut; + + [self updateUniforms]; +} + +- (void)setGreenMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max { + [self setGreenMin:min gamma:mid max:max minOut:0.0 maxOut:1.0]; +} + +- (void)setBlueMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max minOut:(CGFloat)minOut maxOut:(CGFloat)maxOut { + minVector.three = min; + midVector.three = mid; + maxVector.three = max; + minOutputVector.three = minOut; + maxOutputVector.three = maxOut; + + [self updateUniforms]; +} + +- (void)setBlueMin:(CGFloat)min gamma:(CGFloat)mid max:(CGFloat)max { + [self setBlueMin:min gamma:mid max:max minOut:0.0 maxOut:1.0]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLightenBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLightenBlendFilter.h new file mode 100755 index 00000000..b0287c13 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLightenBlendFilter.h @@ -0,0 +1,8 @@ +#import "GPUImageTwoInputFilter.h" + +/// Blends two images by taking the maximum value of each color component between the images +@interface GPUImageLightenBlendFilter : GPUImageTwoInputFilter +{ +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLightenBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageLightenBlendFilter.m new file mode 100755 index 00000000..2bbd4b20 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLightenBlendFilter.m @@ -0,0 +1,52 @@ +#import "GPUImageLightenBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLightenBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = max(textureColor, textureColor2); + } +); +#else +NSString *const kGPUImageLightenBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = max(textureColor, textureColor2); + } + ); +#endif + +@implementation GPUImageLightenBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageLightenBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLineGenerator.h b/LFLiveKit/Vendor/GPUImage/GPUImageLineGenerator.h new file mode 100644 index 00000000..4c467366 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLineGenerator.h @@ -0,0 +1,18 @@ +#import "GPUImageFilter.h" + +@interface GPUImageLineGenerator : GPUImageFilter +{ + GLint lineWidthUniform, lineColorUniform; + GLfloat *lineCoordinates; +} + +// The width of the displayed lines, in pixels. The default is 1. +@property(readwrite, nonatomic) CGFloat lineWidth; + +// The color of the lines is specified using individual red, green, and blue components (normalized to 1.0). The default is green: (0.0, 1.0, 0.0). +- (void)setLineColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; + +// Rendering +- (void)renderLinesFromArray:(GLfloat *)lineSlopeAndIntercepts count:(NSUInteger)numberOfLines frameTime:(CMTime)frameTime; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLineGenerator.m b/LFLiveKit/Vendor/GPUImage/GPUImageLineGenerator.m new file mode 100644 index 00000000..85d93bee --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLineGenerator.m @@ -0,0 +1,164 @@ +#import "GPUImageLineGenerator.h" + +NSString *const kGPUImageLineGeneratorVertexShaderString = SHADER_STRING +( + attribute vec4 position; + + void main() + { + gl_Position = position; + } +); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLineGeneratorFragmentShaderString = SHADER_STRING +( + uniform lowp vec3 lineColor; + + void main() + { + gl_FragColor = vec4(lineColor, 1.0); + } +); +#else +NSString *const kGPUImageLineGeneratorFragmentShaderString = SHADER_STRING +( + uniform vec3 lineColor; + + void main() + { + gl_FragColor = vec4(lineColor, 1.0); + } +); +#endif + +@interface GPUImageLineGenerator() + +- (void)generateLineCoordinates; + +@end + +@implementation GPUImageLineGenerator + +@synthesize lineWidth = _lineWidth; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithVertexShaderFromString:kGPUImageLineGeneratorVertexShaderString fragmentShaderFromString:kGPUImageLineGeneratorFragmentShaderString])) + { + return nil; + } + + runSynchronouslyOnVideoProcessingQueue(^{ + lineWidthUniform = [filterProgram uniformIndex:@"lineWidth"]; + lineColorUniform = [filterProgram uniformIndex:@"lineColor"]; + + self.lineWidth = 1.0; + [self setLineColorRed:0.0 green:1.0 blue:0.0]; + }); + + return self; +} + +- (void)dealloc +{ + if (lineCoordinates) + { + free(lineCoordinates); + } +} + +#pragma mark - +#pragma mark Rendering + +- (void)generateLineCoordinates; +{ + lineCoordinates = calloc(1024 * 4, sizeof(GLfloat)); +} + +- (void)renderLinesFromArray:(GLfloat *)lineSlopeAndIntercepts count:(NSUInteger)numberOfLines frameTime:(CMTime)frameTime; +{ + if (self.preventRendering) + { + return; + } + + if (lineCoordinates == NULL) + { + [self generateLineCoordinates]; + } + + // Iterate through and generate vertices from the slopes and intercepts + NSUInteger currentVertexIndex = 0; + NSUInteger currentLineIndex = 0; + NSUInteger maxLineIndex = numberOfLines *2; + while(currentLineIndex < maxLineIndex) + { + GLfloat slope = lineSlopeAndIntercepts[currentLineIndex++]; + GLfloat intercept = lineSlopeAndIntercepts[currentLineIndex++]; + + if (slope > 9000.0) // Vertical line + { + lineCoordinates[currentVertexIndex++] = intercept; + lineCoordinates[currentVertexIndex++] = -1.0; + lineCoordinates[currentVertexIndex++] = intercept; + lineCoordinates[currentVertexIndex++] = 1.0; + } + else + { + lineCoordinates[currentVertexIndex++] = -1.0; + lineCoordinates[currentVertexIndex++] = slope * -1.0 + intercept; + lineCoordinates[currentVertexIndex++] = 1.0; + lineCoordinates[currentVertexIndex++] = slope * 1.0 + intercept; + } + } + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:filterProgram]; + + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + + glClearColor(0.0, 0.0, 0.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_ONE, GL_ONE); + glEnable(GL_BLEND); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, lineCoordinates); + glDrawArrays(GL_LINES, 0, ((unsigned int)numberOfLines * 2)); + + glDisable(GL_BLEND); + + [self informTargetsAboutNewFrameAtTime:frameTime]; + }); +} + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + // Prevent rendering of the frame by normal means +} + +#pragma mark - +#pragma mark Accessors + +- (void)setLineWidth:(CGFloat)newValue; +{ + _lineWidth = newValue; + [GPUImageContext setActiveShaderProgram:filterProgram]; + glLineWidth(newValue); +} + +- (void)setLineColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; +{ + GPUVector3 lineColor = {redComponent, greenComponent, blueComponent}; + + [self setVec3:lineColor forUniform:lineColorUniform program:filterProgram]; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLinearBurnBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLinearBurnBlendFilter.h new file mode 100644 index 00000000..7e5e415c --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLinearBurnBlendFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageLinearBurnBlendFilter : GPUImageTwoInputFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLinearBurnBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageLinearBurnBlendFilter.m new file mode 100644 index 00000000..47031967 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLinearBurnBlendFilter.m @@ -0,0 +1,51 @@ +#import "GPUImageLinearBurnBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLinearBurnBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + mediump vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + mediump vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(clamp(textureColor.rgb + textureColor2.rgb - vec3(1.0), vec3(0.0), vec3(1.0)), textureColor.a); + } +); +#else +NSString *const kGPUImageLinearBurnBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(clamp(textureColor.rgb + textureColor2.rgb - vec3(1.0), vec3(0.0), vec3(1.0)), textureColor.a); + } +); +#endif + +@implementation GPUImageLinearBurnBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageLinearBurnBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLocalBinaryPatternFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLocalBinaryPatternFilter.h new file mode 100644 index 00000000..431dbbd4 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLocalBinaryPatternFilter.h @@ -0,0 +1,5 @@ +#import "GPUImage3x3TextureSamplingFilter.h" + +@interface GPUImageLocalBinaryPatternFilter : GPUImage3x3TextureSamplingFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLocalBinaryPatternFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageLocalBinaryPatternFilter.m new file mode 100644 index 00000000..1ee1f8d9 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLocalBinaryPatternFilter.m @@ -0,0 +1,123 @@ +#import "GPUImageLocalBinaryPatternFilter.h" + +// This is based on "Accelerating image recognition on mobile devices using GPGPU" by Miguel Bordallo Lopez, Henri Nykanen, Jari Hannuksela, Olli Silven and Markku Vehvilainen +// http://www.ee.oulu.fi/~jhannuks/publications/SPIE2011a.pdf + +// Right pixel is the most significant bit, traveling clockwise to get to the upper right, which is the least significant +// If the external pixel is greater than or equal to the center, set to 1, otherwise 0 +// +// 2 1 0 +// 3 7 +// 4 5 6 + +// 01101101 +// 76543210 + +@implementation GPUImageLocalBinaryPatternFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLocalBinaryPatternFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + lowp float centerIntensity = texture2D(inputImageTexture, textureCoordinate).r; + lowp float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + lowp float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + lowp float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + lowp float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + lowp float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + lowp float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + lowp float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + lowp float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + + lowp float byteTally = 1.0 / 255.0 * step(centerIntensity, topRightIntensity); + byteTally += 2.0 / 255.0 * step(centerIntensity, topIntensity); + byteTally += 4.0 / 255.0 * step(centerIntensity, topLeftIntensity); + byteTally += 8.0 / 255.0 * step(centerIntensity, leftIntensity); + byteTally += 16.0 / 255.0 * step(centerIntensity, bottomLeftIntensity); + byteTally += 32.0 / 255.0 * step(centerIntensity, bottomIntensity); + byteTally += 64.0 / 255.0 * step(centerIntensity, bottomRightIntensity); + byteTally += 128.0 / 255.0 * step(centerIntensity, rightIntensity); + + // TODO: Replace the above with a dot product and two vec4s + // TODO: Apply step to a matrix, rather than individually + + gl_FragColor = vec4(byteTally, byteTally, byteTally, 1.0); + } +); +#else +NSString *const kGPUImageLocalBinaryPatternFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float centerIntensity = texture2D(inputImageTexture, textureCoordinate).r; + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + + float byteTally = 1.0 / 255.0 * step(centerIntensity, topRightIntensity); + byteTally += 2.0 / 255.0 * step(centerIntensity, topIntensity); + byteTally += 4.0 / 255.0 * step(centerIntensity, topLeftIntensity); + byteTally += 8.0 / 255.0 * step(centerIntensity, leftIntensity); + byteTally += 16.0 / 255.0 * step(centerIntensity, bottomLeftIntensity); + byteTally += 32.0 / 255.0 * step(centerIntensity, bottomIntensity); + byteTally += 64.0 / 255.0 * step(centerIntensity, bottomRightIntensity); + byteTally += 128.0 / 255.0 * step(centerIntensity, rightIntensity); + + // TODO: Replace the above with a dot product and two vec4s + // TODO: Apply step to a matrix, rather than individually + + gl_FragColor = vec4(byteTally, byteTally, byteTally, 1.0); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageLocalBinaryPatternFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLookupFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLookupFilter.h new file mode 100644 index 00000000..23ebde2b --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLookupFilter.h @@ -0,0 +1,34 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageLookupFilter : GPUImageTwoInputFilter +{ + GLint intensityUniform; +} + +// How To Use: +// 1) Use your favourite photo editing application to apply a filter to lookup.png from GPUImage/framework/Resources. +// For this to work properly each pixel color must not depend on other pixels (e.g. blur will not work). +// If you need more complex filter you can create as many lookup tables as required. +// E.g. color_balance_lookup_1.png -> GPUImageGaussianBlurFilter -> color_balance_lookup_2.png +// 2) Use you new lookup.png file as a second input for GPUImageLookupFilter. + +// See GPUImageAmatorkaFilter, GPUImageMissEtikateFilter, and GPUImageSoftEleganceFilter for example. + +// Additional Info: +// Lookup texture is organised as 8x8 quads of 64x64 pixels representing all possible RGB colors: +//for (int by = 0; by < 8; by++) { +// for (int bx = 0; bx < 8; bx++) { +// for (int g = 0; g < 64; g++) { +// for (int r = 0; r < 64; r++) { +// image.setPixel(r + bx * 64, g + by * 64, qRgb((int)(r * 255.0 / 63.0 + 0.5), +// (int)(g * 255.0 / 63.0 + 0.5), +// (int)((bx + by * 8.0) * 255.0 / 63.0 + 0.5))); +// } +// } +// } +//} + +// Opacity/intensity of lookup filter ranges from 0.0 to 1.0, with 1.0 as the normal setting +@property(readwrite, nonatomic) CGFloat intensity; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLookupFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageLookupFilter.m new file mode 100644 index 00000000..1c3505eb --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLookupFilter.m @@ -0,0 +1,115 @@ +#import "GPUImageLookupFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLookupFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; // TODO: This is not used + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; // lookup texture + + uniform lowp float intensity; + + void main() + { + highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + highp float blueColor = textureColor.b * 63.0; + + highp vec2 quad1; + quad1.y = floor(floor(blueColor) / 8.0); + quad1.x = floor(blueColor) - (quad1.y * 8.0); + + highp vec2 quad2; + quad2.y = floor(ceil(blueColor) / 8.0); + quad2.x = ceil(blueColor) - (quad2.y * 8.0); + + highp vec2 texPos1; + texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r); + texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g); + + highp vec2 texPos2; + texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r); + texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g); + + lowp vec4 newColor1 = texture2D(inputImageTexture2, texPos1); + lowp vec4 newColor2 = texture2D(inputImageTexture2, texPos2); + + lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor)); + gl_FragColor = mix(textureColor, vec4(newColor.rgb, textureColor.w), intensity); + } +); +#else +NSString *const kGPUImageLookupFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; // TODO: This is not used + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; // lookup texture + + uniform float intensity; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + float blueColor = textureColor.b * 63.0; + + vec2 quad1; + quad1.y = floor(floor(blueColor) / 8.0); + quad1.x = floor(blueColor) - (quad1.y * 8.0); + + vec2 quad2; + quad2.y = floor(ceil(blueColor) / 8.0); + quad2.x = ceil(blueColor) - (quad2.y * 8.0); + + vec2 texPos1; + texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r); + texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g); + + vec2 texPos2; + texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r); + texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g); + + vec4 newColor1 = texture2D(inputImageTexture2, texPos1); + vec4 newColor2 = texture2D(inputImageTexture2, texPos2); + + vec4 newColor = mix(newColor1, newColor2, fract(blueColor)); + gl_FragColor = mix(textureColor, vec4(newColor.rgb, textureColor.w), intensity); + } +); +#endif + +@implementation GPUImageLookupFilter + +@synthesize intensity = _intensity; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageLookupFragmentShaderString])) + { + return nil; + } + + intensityUniform = [filterProgram uniformIndex:@"intensity"]; + self.intensity = 1.0f; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setIntensity:(CGFloat)intensity +{ + _intensity = intensity; + + [self setFloat:_intensity forUniform:intensityUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLowPassFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLowPassFilter.h new file mode 100644 index 00000000..be5c397e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLowPassFilter.h @@ -0,0 +1,14 @@ +#import "GPUImageFilterGroup.h" +#import "GPUImageBuffer.h" +#import "GPUImageDissolveBlendFilter.h" + +@interface GPUImageLowPassFilter : GPUImageFilterGroup +{ + GPUImageBuffer *bufferFilter; + GPUImageDissolveBlendFilter *dissolveBlendFilter; +} + +// This controls the degree by which the previous accumulated frames are blended with the current one. This ranges from 0.0 to 1.0, with a default of 0.5. +@property(readwrite, nonatomic) CGFloat filterStrength; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLowPassFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageLowPassFilter.m new file mode 100644 index 00000000..39ca08f6 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLowPassFilter.m @@ -0,0 +1,61 @@ +#import "GPUImageLowPassFilter.h" + +@implementation GPUImageLowPassFilter + +@synthesize filterStrength; + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + // Take in the frame and blend it with the previous one + dissolveBlendFilter = [[GPUImageDissolveBlendFilter alloc] init]; + [self addFilter:dissolveBlendFilter]; + + // Buffer the result to be fed back into the blend + bufferFilter = [[GPUImageBuffer alloc] init]; + [self addFilter:bufferFilter]; + + // Texture location 0 needs to be the original image for the dissolve blend + [bufferFilter addTarget:dissolveBlendFilter atTextureLocation:1]; + [dissolveBlendFilter addTarget:bufferFilter]; + + [dissolveBlendFilter disableSecondFrameCheck]; + + // To prevent double updating of this filter, disable updates from the sharp image side + // self.inputFilterToIgnoreForUpdates = unsharpMaskFilter; + + self.initialFilters = [NSArray arrayWithObject:dissolveBlendFilter]; + self.terminalFilter = dissolveBlendFilter; + + self.filterStrength = 0.5; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setFilterStrength:(CGFloat)newValue; +{ + dissolveBlendFilter.mix = newValue; +} + +- (CGFloat)filterStrength; +{ + return dissolveBlendFilter.mix; +} + +- (void)addTarget:(id)newTarget atTextureLocation:(NSInteger)textureLocation; +{ + [self.terminalFilter addTarget:newTarget atTextureLocation:textureLocation]; + //if use GPUImagePipline,will cause self.termainlFilter removeAllTargets,so need add bufferFilter back + if (self.terminalFilter == dissolveBlendFilter && ![self.terminalFilter.targets containsObject:bufferFilter]) { + [self.terminalFilter addTarget:bufferFilter atTextureLocation:1]; + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceRangeFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceRangeFilter.h new file mode 100644 index 00000000..5a310370 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceRangeFilter.h @@ -0,0 +1,12 @@ +#import "GPUImageFilter.h" + +@interface GPUImageLuminanceRangeFilter : GPUImageFilter +{ + GLint rangeReductionUniform; +} + +/** The degree to reduce the luminance range, from 0.0 to 1.0. Default is 0.6. + */ +@property(readwrite, nonatomic) CGFloat rangeReductionFactor; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceRangeFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceRangeFilter.m new file mode 100644 index 00000000..5122c958 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceRangeFilter.m @@ -0,0 +1,76 @@ +#import "GPUImageLuminanceRangeFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLuminanceRangeFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform lowp float rangeReduction; + + // Values from "Graphics Shaders: Theory and Practice" by Bailey and Cunningham + const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + mediump float luminance = dot(textureColor.rgb, luminanceWeighting); + mediump float luminanceRatio = ((0.5 - luminance) * rangeReduction); + + gl_FragColor = vec4((textureColor.rgb) + (luminanceRatio), textureColor.w); + } +); +#else +NSString *const kGPUImageLuminanceRangeFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float rangeReduction; + + // Values from "Graphics Shaders: Theory and Practice" by Bailey and Cunningham + const vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, luminanceWeighting); + float luminanceRatio = ((0.5 - luminance) * rangeReduction); + + gl_FragColor = vec4((textureColor.rgb) + (luminanceRatio), textureColor.w); + } +); +#endif + +@implementation GPUImageLuminanceRangeFilter + +@synthesize rangeReductionFactor = _rangeReductionFactor; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageLuminanceRangeFragmentShaderString])) + { + return nil; + } + + rangeReductionUniform = [filterProgram uniformIndex:@"rangeReduction"]; + self.rangeReductionFactor = 0.6; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setRangeReductionFactor:(CGFloat)newValue; +{ + _rangeReductionFactor = newValue; + + [self setFloat:_rangeReductionFactor forUniform:rangeReductionUniform program:filterProgram]; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceThresholdFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceThresholdFilter.h new file mode 100755 index 00000000..0abb9a1e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceThresholdFilter.h @@ -0,0 +1,14 @@ +#import "GPUImageFilter.h" + +/** Pixels with a luminance above the threshold will appear white, and those below will be black + */ +@interface GPUImageLuminanceThresholdFilter : GPUImageFilter +{ + GLint thresholdUniform; +} + +/** Anything above this luminance will be white, and anything below black. Ranges from 0.0 to 1.0, with 0.5 as the default + */ +@property(readwrite, nonatomic) CGFloat threshold; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceThresholdFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceThresholdFilter.m new file mode 100755 index 00000000..368b8fbe --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLuminanceThresholdFilter.m @@ -0,0 +1,74 @@ +#import "GPUImageLuminanceThresholdFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLuminanceThresholdFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform highp float threshold; + + const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + highp float luminance = dot(textureColor.rgb, W); + highp float thresholdResult = step(threshold, luminance); + + gl_FragColor = vec4(vec3(thresholdResult), textureColor.w); + } +); +#else +NSString *const kGPUImageLuminanceThresholdFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float threshold; + + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, W); + float thresholdResult = step(threshold, luminance); + + gl_FragColor = vec4(vec3(thresholdResult), textureColor.w); + } +); +#endif + +@implementation GPUImageLuminanceThresholdFilter + +@synthesize threshold = _threshold; + +#pragma mark - +#pragma mark Initialization + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageLuminanceThresholdFragmentShaderString])) + { + return nil; + } + + thresholdUniform = [filterProgram uniformIndex:@"threshold"]; + self.threshold = 0.5; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setThreshold:(CGFloat)newValue; +{ + _threshold = newValue; + + [self setFloat:_threshold forUniform:thresholdUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLuminosity.h b/LFLiveKit/Vendor/GPUImage/GPUImageLuminosity.h new file mode 100644 index 00000000..b2d2458f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLuminosity.h @@ -0,0 +1,17 @@ +#import "GPUImageAverageColor.h" + +@interface GPUImageLuminosity : GPUImageAverageColor +{ + GLProgram *secondFilterProgram; + GLint secondFilterPositionAttribute, secondFilterTextureCoordinateAttribute; + GLint secondFilterInputTextureUniform, secondFilterInputTextureUniform2; + GLint secondFilterTexelWidthUniform, secondFilterTexelHeightUniform; +} + +// This block is called on the completion of color averaging for a frame +@property(nonatomic, copy) void(^luminosityProcessingFinishedBlock)(CGFloat luminosity, CMTime frameTime); + +- (void)extractLuminosityAtFrameTime:(CMTime)frameTime; +- (void)initializeSecondaryAttributes; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLuminosity.m b/LFLiveKit/Vendor/GPUImage/GPUImageLuminosity.m new file mode 100644 index 00000000..37f374ab --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLuminosity.m @@ -0,0 +1,329 @@ +#import "GPUImageLuminosity.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageInitialLuminosityFragmentShaderString = SHADER_STRING +( + precision highp float; + + uniform sampler2D inputImageTexture; + + varying highp vec2 outputTextureCoordinate; + + varying highp vec2 upperLeftInputTextureCoordinate; + varying highp vec2 upperRightInputTextureCoordinate; + varying highp vec2 lowerLeftInputTextureCoordinate; + varying highp vec2 lowerRightInputTextureCoordinate; + + const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + highp float upperLeftLuminance = dot(texture2D(inputImageTexture, upperLeftInputTextureCoordinate).rgb, W); + highp float upperRightLuminance = dot(texture2D(inputImageTexture, upperRightInputTextureCoordinate).rgb, W); + highp float lowerLeftLuminance = dot(texture2D(inputImageTexture, lowerLeftInputTextureCoordinate).rgb, W); + highp float lowerRightLuminance = dot(texture2D(inputImageTexture, lowerRightInputTextureCoordinate).rgb, W); + + highp float luminosity = 0.25 * (upperLeftLuminance + upperRightLuminance + lowerLeftLuminance + lowerRightLuminance); + gl_FragColor = vec4(luminosity, luminosity, luminosity, 1.0); + } +); + +NSString *const kGPUImageLuminosityFragmentShaderString = SHADER_STRING +( + precision highp float; + + uniform sampler2D inputImageTexture; + + varying highp vec2 outputTextureCoordinate; + + varying highp vec2 upperLeftInputTextureCoordinate; + varying highp vec2 upperRightInputTextureCoordinate; + varying highp vec2 lowerLeftInputTextureCoordinate; + varying highp vec2 lowerRightInputTextureCoordinate; + + void main() + { + highp float upperLeftLuminance = texture2D(inputImageTexture, upperLeftInputTextureCoordinate).r; + highp float upperRightLuminance = texture2D(inputImageTexture, upperRightInputTextureCoordinate).r; + highp float lowerLeftLuminance = texture2D(inputImageTexture, lowerLeftInputTextureCoordinate).r; + highp float lowerRightLuminance = texture2D(inputImageTexture, lowerRightInputTextureCoordinate).r; + + highp float luminosity = 0.25 * (upperLeftLuminance + upperRightLuminance + lowerLeftLuminance + lowerRightLuminance); + gl_FragColor = vec4(luminosity, luminosity, luminosity, 1.0); + } +); +#else +NSString *const kGPUImageInitialLuminosityFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + varying vec2 outputTextureCoordinate; + + varying vec2 upperLeftInputTextureCoordinate; + varying vec2 upperRightInputTextureCoordinate; + varying vec2 lowerLeftInputTextureCoordinate; + varying vec2 lowerRightInputTextureCoordinate; + + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + float upperLeftLuminance = dot(texture2D(inputImageTexture, upperLeftInputTextureCoordinate).rgb, W); + float upperRightLuminance = dot(texture2D(inputImageTexture, upperRightInputTextureCoordinate).rgb, W); + float lowerLeftLuminance = dot(texture2D(inputImageTexture, lowerLeftInputTextureCoordinate).rgb, W); + float lowerRightLuminance = dot(texture2D(inputImageTexture, lowerRightInputTextureCoordinate).rgb, W); + + float luminosity = 0.25 * (upperLeftLuminance + upperRightLuminance + lowerLeftLuminance + lowerRightLuminance); + gl_FragColor = vec4(luminosity, luminosity, luminosity, 1.0); + } +); + +NSString *const kGPUImageLuminosityFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + varying vec2 outputTextureCoordinate; + + varying vec2 upperLeftInputTextureCoordinate; + varying vec2 upperRightInputTextureCoordinate; + varying vec2 lowerLeftInputTextureCoordinate; + varying vec2 lowerRightInputTextureCoordinate; + + void main() + { + float upperLeftLuminance = texture2D(inputImageTexture, upperLeftInputTextureCoordinate).r; + float upperRightLuminance = texture2D(inputImageTexture, upperRightInputTextureCoordinate).r; + float lowerLeftLuminance = texture2D(inputImageTexture, lowerLeftInputTextureCoordinate).r; + float lowerRightLuminance = texture2D(inputImageTexture, lowerRightInputTextureCoordinate).r; + + float luminosity = 0.25 * (upperLeftLuminance + upperRightLuminance + lowerLeftLuminance + lowerRightLuminance); + gl_FragColor = vec4(luminosity, luminosity, luminosity, 1.0); + } +); +#endif + +@implementation GPUImageLuminosity + +@synthesize luminosityProcessingFinishedBlock = _luminosityProcessingFinishedBlock; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithVertexShaderFromString:kGPUImageColorAveragingVertexShaderString fragmentShaderFromString:kGPUImageInitialLuminosityFragmentShaderString])) + { + return nil; + } + + texelWidthUniform = [filterProgram uniformIndex:@"texelWidth"]; + texelHeightUniform = [filterProgram uniformIndex:@"texelHeight"]; + + __unsafe_unretained GPUImageLuminosity *weakSelf = self; + [self setFrameProcessingCompletionBlock:^(GPUImageOutput *filter, CMTime frameTime) { + [weakSelf extractLuminosityAtFrameTime:frameTime]; + }]; + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + + secondFilterProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:kGPUImageColorAveragingVertexShaderString fragmentShaderString:kGPUImageLuminosityFragmentShaderString]; + + if (!secondFilterProgram.initialized) + { + [self initializeSecondaryAttributes]; + + if (![secondFilterProgram link]) + { + NSString *progLog = [secondFilterProgram programLog]; + NSLog(@"Program link log: %@", progLog); + NSString *fragLog = [secondFilterProgram fragmentShaderLog]; + NSLog(@"Fragment shader compile log: %@", fragLog); + NSString *vertLog = [secondFilterProgram vertexShaderLog]; + NSLog(@"Vertex shader compile log: %@", vertLog); + filterProgram = nil; + NSAssert(NO, @"Filter shader link failed"); + } + } + + secondFilterPositionAttribute = [secondFilterProgram attributeIndex:@"position"]; + secondFilterTextureCoordinateAttribute = [secondFilterProgram attributeIndex:@"inputTextureCoordinate"]; + secondFilterInputTextureUniform = [secondFilterProgram uniformIndex:@"inputImageTexture"]; // This does assume a name of "inputImageTexture" for the fragment shader + secondFilterInputTextureUniform2 = [secondFilterProgram uniformIndex:@"inputImageTexture2"]; // This does assume a name of "inputImageTexture2" for second input texture in the fragment shader + + secondFilterTexelWidthUniform = [secondFilterProgram uniformIndex:@"texelWidth"]; + secondFilterTexelHeightUniform = [secondFilterProgram uniformIndex:@"texelHeight"]; + + [GPUImageContext setActiveShaderProgram:secondFilterProgram]; + + glEnableVertexAttribArray(secondFilterPositionAttribute); + glEnableVertexAttribArray(secondFilterTextureCoordinateAttribute); + }); + + return self; +} + +- (void)initializeSecondaryAttributes; +{ + [secondFilterProgram addAttribute:@"position"]; + [secondFilterProgram addAttribute:@"inputTextureCoordinate"]; +} + +/* +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + if (self.preventRendering) + { + [firstInputFramebuffer unlock]; + return; + } + + // Do an initial render pass that both convert to luminance and reduces + [GPUImageContext setActiveShaderProgram:filterProgram]; + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + + GLuint currentFramebuffer = [[stageFramebuffers objectAtIndex:0] intValue]; + glBindFramebuffer(GL_FRAMEBUFFER, currentFramebuffer); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + CGSize currentStageSize = [[stageSizes objectAtIndex:0] CGSizeValue]; +#else + NSSize currentStageSize = [[stageSizes objectAtIndex:0] sizeValue]; +#endif + glViewport(0, 0, (int)currentStageSize.width, (int)currentStageSize.height); + + GLuint currentTexture = [firstInputFramebuffer texture]; + + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, currentTexture); + + glUniform1i(filterInputTextureUniform, 2); + + glUniform1f(texelWidthUniform, 0.5 / currentStageSize.width); + glUniform1f(texelHeightUniform, 0.5 / currentStageSize.height); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + currentTexture = [[stageTextures objectAtIndex:0] intValue]; + + // Just perform reductions from this point on + [GPUImageContext setActiveShaderProgram:secondFilterProgram]; + glVertexAttribPointer(secondFilterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(secondFilterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + + NSUInteger numberOfStageFramebuffers = [stageFramebuffers count]; + for (NSUInteger currentStage = 1; currentStage < numberOfStageFramebuffers; currentStage++) + { + currentFramebuffer = [[stageFramebuffers objectAtIndex:currentStage] intValue]; + glBindFramebuffer(GL_FRAMEBUFFER, currentFramebuffer); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + currentStageSize = [[stageSizes objectAtIndex:currentStage] CGSizeValue]; +#else + currentStageSize = [[stageSizes objectAtIndex:currentStage] sizeValue]; +#endif + glViewport(0, 0, (int)currentStageSize.width, (int)currentStageSize.height); + + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, currentTexture); + + glUniform1i(secondFilterInputTextureUniform, 2); + + glUniform1f(secondFilterTexelWidthUniform, 0.5 / currentStageSize.width); + glUniform1f(secondFilterTexelHeightUniform, 0.5 / currentStageSize.height); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + currentTexture = [[stageTextures objectAtIndex:currentStage] intValue]; + +// NSUInteger totalBytesForImage = (int)currentStageSize.width * (int)currentStageSize.height * 4; +// GLubyte *rawImagePixels2 = (GLubyte *)malloc(totalBytesForImage); +// glReadPixels(0, 0, (int)currentStageSize.width, (int)currentStageSize.height, GL_RGBA, GL_UNSIGNED_BYTE, rawImagePixels2); +// CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, rawImagePixels2, totalBytesForImage, NULL); +// CGColorSpaceRef defaultRGBColorSpace = CGColorSpaceCreateDeviceRGB(); +// +// CGFloat currentRedTotal = 0.0f, currentGreenTotal = 0.0f, currentBlueTotal = 0.0f, currentAlphaTotal = 0.0f; +// NSUInteger totalNumberOfPixels = totalBytesForImage / 4; +// +// for (NSUInteger currentPixel = 0; currentPixel < totalNumberOfPixels; currentPixel++) +// { +// currentRedTotal += (CGFloat)rawImagePixels2[(currentPixel * 4)] / 255.0f; +// currentGreenTotal += (CGFloat)rawImagePixels2[(currentPixel * 4) + 1] / 255.0f; +// currentBlueTotal += (CGFloat)rawImagePixels2[(currentPixel * 4 + 2)] / 255.0f; +// currentAlphaTotal += (CGFloat)rawImagePixels2[(currentPixel * 4) + 3] / 255.0f; +// } +// +// NSLog(@"Stage %d average image red: %f, green: %f, blue: %f, alpha: %f", currentStage, currentRedTotal / (CGFloat)totalNumberOfPixels, currentGreenTotal / (CGFloat)totalNumberOfPixels, currentBlueTotal / (CGFloat)totalNumberOfPixels, currentAlphaTotal / (CGFloat)totalNumberOfPixels); +// +// +// CGImageRef cgImageFromBytes = CGImageCreate((int)currentStageSize.width, (int)currentStageSize.height, 8, 32, 4 * (int)currentStageSize.width, defaultRGBColorSpace, kCGBitmapByteOrderDefault | kCGImageAlphaLast, dataProvider, NULL, NO, kCGRenderingIntentDefault); +// +// UIImage *imageToSave = [UIImage imageWithCGImage:cgImageFromBytes]; +// +// NSData *dataForPNGFile = UIImagePNGRepresentation(imageToSave); +// +// NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); +// NSString *documentsDirectory = [paths objectAtIndex:0]; +// +// NSString *imageName = [NSString stringWithFormat:@"AverageLevel%d.png", currentStage]; +// NSError *error = nil; +// if (![dataForPNGFile writeToFile:[documentsDirectory stringByAppendingPathComponent:imageName] options:NSAtomicWrite error:&error]) +// { +// return; +// } + } + + [firstInputFramebuffer unlock]; +} + */ + +#pragma mark - +#pragma mark Callbacks + +- (void)extractLuminosityAtFrameTime:(CMTime)frameTime; +{ + runSynchronouslyOnVideoProcessingQueue(^{ + + // we need a normal color texture for this filter + NSAssert(self.outputTextureOptions.internalFormat == GL_RGBA, @"The output texture format for this filter must be GL_RGBA."); + NSAssert(self.outputTextureOptions.type == GL_UNSIGNED_BYTE, @"The type of the output texture of this filter must be GL_UNSIGNED_BYTE."); + + NSUInteger totalNumberOfPixels = round(finalStageSize.width * finalStageSize.height); + + if (rawImagePixels == NULL) + { + rawImagePixels = (GLubyte *)malloc(totalNumberOfPixels * 4); + } + + [GPUImageContext useImageProcessingContext]; + [outputFramebuffer activateFramebuffer]; + + glReadPixels(0, 0, (int)finalStageSize.width, (int)finalStageSize.height, GL_RGBA, GL_UNSIGNED_BYTE, rawImagePixels); + + NSUInteger luminanceTotal = 0; + NSUInteger byteIndex = 0; + for (NSUInteger currentPixel = 0; currentPixel < totalNumberOfPixels; currentPixel++) + { + luminanceTotal += rawImagePixels[byteIndex]; + byteIndex += 4; + } + + CGFloat normalizedLuminosityTotal = (CGFloat)luminanceTotal / (CGFloat)totalNumberOfPixels / 255.0; + + if (_luminosityProcessingFinishedBlock != NULL) + { + _luminosityProcessingFinishedBlock(normalizedLuminosityTotal, frameTime); + } + }); +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLuminosityBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageLuminosityBlendFilter.h new file mode 100644 index 00000000..03b5e4c9 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLuminosityBlendFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageLuminosityBlendFilter : GPUImageTwoInputFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageLuminosityBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageLuminosityBlendFilter.m new file mode 100644 index 00000000..7e399746 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageLuminosityBlendFilter.m @@ -0,0 +1,113 @@ +#import "GPUImageLuminosityBlendFilter.h" + +/** + * Luminosity blend mode based upon pseudo code from the PDF specification. + */ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageLuminosityBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + highp float lum(lowp vec3 c) { + return dot(c, vec3(0.3, 0.59, 0.11)); + } + + lowp vec3 clipcolor(lowp vec3 c) { + highp float l = lum(c); + lowp float n = min(min(c.r, c.g), c.b); + lowp float x = max(max(c.r, c.g), c.b); + + if (n < 0.0) { + c.r = l + ((c.r - l) * l) / (l - n); + c.g = l + ((c.g - l) * l) / (l - n); + c.b = l + ((c.b - l) * l) / (l - n); + } + if (x > 1.0) { + c.r = l + ((c.r - l) * (1.0 - l)) / (x - l); + c.g = l + ((c.g - l) * (1.0 - l)) / (x - l); + c.b = l + ((c.b - l) * (1.0 - l)) / (x - l); + } + + return c; + } + + lowp vec3 setlum(lowp vec3 c, highp float l) { + highp float d = l - lum(c); + c = c + vec3(d); + return clipcolor(c); + } + + void main() + { + highp vec4 baseColor = texture2D(inputImageTexture, textureCoordinate); + highp vec4 overlayColor = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(baseColor.rgb * (1.0 - overlayColor.a) + setlum(baseColor.rgb, lum(overlayColor.rgb)) * overlayColor.a, baseColor.a); + } +); +#else +NSString *const kGPUImageLuminosityBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + float lum(vec3 c) { + return dot(c, vec3(0.3, 0.59, 0.11)); + } + + vec3 clipcolor(vec3 c) { + float l = lum(c); + float n = min(min(c.r, c.g), c.b); + float x = max(max(c.r, c.g), c.b); + + if (n < 0.0) { + c.r = l + ((c.r - l) * l) / (l - n); + c.g = l + ((c.g - l) * l) / (l - n); + c.b = l + ((c.b - l) * l) / (l - n); + } + if (x > 1.0) { + c.r = l + ((c.r - l) * (1.0 - l)) / (x - l); + c.g = l + ((c.g - l) * (1.0 - l)) / (x - l); + c.b = l + ((c.b - l) * (1.0 - l)) / (x - l); + } + + return c; + } + + vec3 setlum(vec3 c, float l) { + float d = l - lum(c); + c = c + vec3(d); + return clipcolor(c); + } + + void main() + { + vec4 baseColor = texture2D(inputImageTexture, textureCoordinate); + vec4 overlayColor = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(baseColor.rgb * (1.0 - overlayColor.a) + setlum(baseColor.rgb, lum(overlayColor.rgb)) * overlayColor.a, baseColor.a); + } +); +#endif + + +@implementation GPUImageLuminosityBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageLuminosityBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMaskFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMaskFilter.h new file mode 100755 index 00000000..94cf0648 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMaskFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageMaskFilter : GPUImageTwoInputFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMaskFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageMaskFilter.m new file mode 100755 index 00000000..24503b3b --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMaskFilter.m @@ -0,0 +1,76 @@ +#import "GPUImageMaskFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageMaskShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + //Averages mask's the RGB values, and scales that value by the mask's alpha + // + //The dot product should take fewer cycles than doing an average normally + // + //Typical/ideal case, R,G, and B will be the same, and Alpha will be 1.0 + lowp float newAlpha = dot(textureColor2.rgb, vec3(.33333334, .33333334, .33333334)) * textureColor2.a; + + gl_FragColor = vec4(textureColor.xyz, newAlpha); +// gl_FragColor = vec4(textureColor2); + } +); +#else +NSString *const kGPUImageMaskShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + //Averages mask's the RGB values, and scales that value by the mask's alpha + // + //The dot product should take fewer cycles than doing an average normally + // + //Typical/ideal case, R,G, and B will be the same, and Alpha will be 1.0 + float newAlpha = dot(textureColor2.rgb, vec3(.33333334, .33333334, .33333334)) * textureColor2.a; + + gl_FragColor = vec4(textureColor.xyz, newAlpha); + // gl_FragColor = vec4(textureColor2); + } +); +#endif + +@implementation GPUImageMaskFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageMaskShaderString])) + { + return nil; + } + + return self; +} + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + [super renderToTextureWithVertices:vertices textureCoordinates:textureCoordinates]; + glDisable(GL_BLEND); +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMedianFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMedianFilter.h new file mode 100644 index 00000000..80225789 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMedianFilter.h @@ -0,0 +1,5 @@ +#import "GPUImage3x3TextureSamplingFilter.h" + +@interface GPUImageMedianFilter : GPUImage3x3TextureSamplingFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMedianFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageMedianFilter.m new file mode 100644 index 00000000..78c11805 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMedianFilter.m @@ -0,0 +1,178 @@ +#import "GPUImageMedianFilter.h" + +/* + 3x3 median filter, adapted from "A Fast, Small-Radius GPU Median Filter" by Morgan McGuire in ShaderX6 + http://graphics.cs.williams.edu/papers/MedianShaderX6/ + + Morgan McGuire and Kyle Whitson + Williams College + + Register allocation tips by Victor Huang Xiaohuang + University of Illinois at Urbana-Champaign + + http://graphics.cs.williams.edu + + + Copyright (c) Morgan McGuire and Williams College, 2006 + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageMedianFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + +#define s2(a, b) temp = a; a = min(a, b); b = max(temp, b); +#define mn3(a, b, c) s2(a, b); s2(a, c); +#define mx3(a, b, c) s2(b, c); s2(a, c); + +#define mnmx3(a, b, c) mx3(a, b, c); s2(a, b); // 3 exchanges +#define mnmx4(a, b, c, d) s2(a, b); s2(c, d); s2(a, c); s2(b, d); // 4 exchanges +#define mnmx5(a, b, c, d, e) s2(a, b); s2(c, d); mn3(a, c, e); mx3(b, d, e); // 6 exchanges +#define mnmx6(a, b, c, d, e, f) s2(a, d); s2(b, e); s2(c, f); mn3(a, b, c); mx3(d, e, f); // 7 exchanges + + void main() + { + vec3 v[6]; + + v[0] = texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb; + v[1] = texture2D(inputImageTexture, topRightTextureCoordinate).rgb; + v[2] = texture2D(inputImageTexture, topLeftTextureCoordinate).rgb; + v[3] = texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb; + v[4] = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + v[5] = texture2D(inputImageTexture, rightTextureCoordinate).rgb; +// v[6] = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; +// v[7] = texture2D(inputImageTexture, topTextureCoordinate).rgb; + vec3 temp; + + mnmx6(v[0], v[1], v[2], v[3], v[4], v[5]); + + v[5] = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + + mnmx5(v[1], v[2], v[3], v[4], v[5]); + + v[5] = texture2D(inputImageTexture, topTextureCoordinate).rgb; + + mnmx4(v[2], v[3], v[4], v[5]); + + v[5] = texture2D(inputImageTexture, textureCoordinate).rgb; + + mnmx3(v[3], v[4], v[5]); + + gl_FragColor = vec4(v[4], 1.0); + } +); +#else +NSString *const kGPUImageMedianFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + +#define s2(a, b) temp = a; a = min(a, b); b = max(temp, b); +#define mn3(a, b, c) s2(a, b); s2(a, c); +#define mx3(a, b, c) s2(b, c); s2(a, c); + +#define mnmx3(a, b, c) mx3(a, b, c); s2(a, b); // 3 exchanges +#define mnmx4(a, b, c, d) s2(a, b); s2(c, d); s2(a, c); s2(b, d); // 4 exchanges +#define mnmx5(a, b, c, d, e) s2(a, b); s2(c, d); mn3(a, c, e); mx3(b, d, e); // 6 exchanges +#define mnmx6(a, b, c, d, e, f) s2(a, d); s2(b, e); s2(c, f); mn3(a, b, c); mx3(d, e, f); // 7 exchanges + + void main() + { + vec3 v[6]; + + v[0] = texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb; + v[1] = texture2D(inputImageTexture, topRightTextureCoordinate).rgb; + v[2] = texture2D(inputImageTexture, topLeftTextureCoordinate).rgb; + v[3] = texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb; + v[4] = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + v[5] = texture2D(inputImageTexture, rightTextureCoordinate).rgb; + // v[6] = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + // v[7] = texture2D(inputImageTexture, topTextureCoordinate).rgb; + vec3 temp; + + mnmx6(v[0], v[1], v[2], v[3], v[4], v[5]); + + v[5] = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + + mnmx5(v[1], v[2], v[3], v[4], v[5]); + + v[5] = texture2D(inputImageTexture, topTextureCoordinate).rgb; + + mnmx4(v[2], v[3], v[4], v[5]); + + v[5] = texture2D(inputImageTexture, textureCoordinate).rgb; + + mnmx3(v[3], v[4], v[5]); + + gl_FragColor = vec4(v[4], 1.0); + } +); +#endif + +@implementation GPUImageMedianFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageMedianFragmentShaderString])) + { + return nil; + } + + hasOverriddenImageSizeFactor = NO; + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMissEtikateFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMissEtikateFilter.h new file mode 100755 index 00000000..de170647 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMissEtikateFilter.h @@ -0,0 +1,17 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImagePicture; + +/** A photo filter based on Photoshop action by Miss Etikate: + http://miss-etikate.deviantart.com/art/Photoshop-Action-15-120151961 + */ + +// Note: If you want to use this effect you have to add lookup_miss_etikate.png +// from Resources folder to your application bundle. + +@interface GPUImageMissEtikateFilter : GPUImageFilterGroup +{ + GPUImagePicture *lookupImageSource; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMissEtikateFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageMissEtikateFilter.m new file mode 100755 index 00000000..1810b707 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMissEtikateFilter.m @@ -0,0 +1,38 @@ +#import "GPUImageMissEtikateFilter.h" +#import "GPUImagePicture.h" +#import "GPUImageLookupFilter.h" + +@implementation GPUImageMissEtikateFilter + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + UIImage *image = [UIImage imageNamed:@"lookup_miss_etikate.png"]; +#else + NSImage *image = [NSImage imageNamed:@"lookup_miss_etikate.png"]; +#endif + + NSAssert(image, @"To use GPUImageMissEtikateFilter you need to add lookup_miss_etikate.png from GPUImage/framework/Resources to your application bundle."); + + lookupImageSource = [[GPUImagePicture alloc] initWithImage:image]; + GPUImageLookupFilter *lookupFilter = [[GPUImageLookupFilter alloc] init]; + [self addFilter:lookupFilter]; + + [lookupImageSource addTarget:lookupFilter atTextureLocation:1]; + [lookupImageSource processImage]; + + self.initialFilters = [NSArray arrayWithObjects:lookupFilter, nil]; + self.terminalFilter = lookupFilter; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMonochromeFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMonochromeFilter.h new file mode 100644 index 00000000..66a0e773 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMonochromeFilter.h @@ -0,0 +1,13 @@ +#import "GPUImageFilter.h" + +@interface GPUImageMonochromeFilter : GPUImageFilter +{ + GLint intensityUniform, filterColorUniform; +} + +@property(readwrite, nonatomic) CGFloat intensity; +@property(readwrite, nonatomic) GPUVector4 color; + +- (void)setColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMonochromeFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageMonochromeFilter.m new file mode 100644 index 00000000..70cef872 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMonochromeFilter.m @@ -0,0 +1,115 @@ +#import "GPUImageMonochromeFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUMonochromeFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float intensity; + uniform vec3 filterColor; + + const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + //desat, then apply overlay blend + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, luminanceWeighting); + + lowp vec4 desat = vec4(vec3(luminance), 1.0); + + //overlay + lowp vec4 outputColor = vec4( + (desat.r < 0.5 ? (2.0 * desat.r * filterColor.r) : (1.0 - 2.0 * (1.0 - desat.r) * (1.0 - filterColor.r))), + (desat.g < 0.5 ? (2.0 * desat.g * filterColor.g) : (1.0 - 2.0 * (1.0 - desat.g) * (1.0 - filterColor.g))), + (desat.b < 0.5 ? (2.0 * desat.b * filterColor.b) : (1.0 - 2.0 * (1.0 - desat.b) * (1.0 - filterColor.b))), + 1.0 + ); + + //which is better, or are they equal? + gl_FragColor = vec4( mix(textureColor.rgb, outputColor.rgb, intensity), textureColor.a); + } +); +#else +NSString *const kGPUMonochromeFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float intensity; + uniform vec3 filterColor; + + const vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + //desat, then apply overlay blend + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, luminanceWeighting); + + vec4 desat = vec4(vec3(luminance), 1.0); + + //overlay + vec4 outputColor = vec4( + (desat.r < 0.5 ? (2.0 * desat.r * filterColor.r) : (1.0 - 2.0 * (1.0 - desat.r) * (1.0 - filterColor.r))), + (desat.g < 0.5 ? (2.0 * desat.g * filterColor.g) : (1.0 - 2.0 * (1.0 - desat.g) * (1.0 - filterColor.g))), + (desat.b < 0.5 ? (2.0 * desat.b * filterColor.b) : (1.0 - 2.0 * (1.0 - desat.b) * (1.0 - filterColor.b))), + 1.0 + ); + + //which is better, or are they equal? + gl_FragColor = vec4( mix(textureColor.rgb, outputColor.rgb, intensity), textureColor.a); + } +); +#endif + +@implementation GPUImageMonochromeFilter + +@synthesize intensity = _intensity; +@synthesize color = _color; + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUMonochromeFragmentShaderString])) + { + return nil; + } + + intensityUniform = [filterProgram uniformIndex:@"intensity"]; + filterColorUniform = [filterProgram uniformIndex:@"filterColor"]; + + self.intensity = 1.0; + self.color = (GPUVector4){0.6f, 0.45f, 0.3f, 1.f}; + //self.color = [CIColor colorWithRed:0.6 green:0.45 blue:0.3 alpha:1.]; + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setColor:(GPUVector4)color; +{ + + _color = color; + + [self setColorRed:color.one green:color.two blue:color.three]; +} + +- (void)setColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent; +{ + GPUVector3 filterColor = {redComponent, greenComponent, blueComponent}; + + [self setVec3:filterColor forUniform:filterColorUniform program:filterProgram]; +} + +- (void)setIntensity:(CGFloat)newValue; +{ + _intensity = newValue; + + [self setFloat:_intensity forUniform:intensityUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMosaicFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMosaicFilter.h new file mode 100644 index 00000000..5f72d3c9 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMosaicFilter.h @@ -0,0 +1,22 @@ + +// This needs a little more work, it's rotating the input tileset and there are some artifacts (I think from GL_LINEAR interpolation), but it's working + +#import "GPUImageTwoInputFilter.h" +#import "GPUImagePicture.h" + +@interface GPUImageMosaicFilter : GPUImageTwoInputFilter { + GLint inputTileSizeUniform, numTilesUniform, displayTileSizeUniform, colorOnUniform; + GPUImagePicture *pic; +} + +// This filter takes an input tileset, the tiles must ascend in luminance +// It looks at the input image and replaces each display tile with an input tile +// according to the luminance of that tile. The idea was to replicate the ASCII +// video filters seen in other apps, but the tileset can be anything. +@property(readwrite, nonatomic) CGSize inputTileSize; +@property(readwrite, nonatomic) float numTiles; +@property(readwrite, nonatomic) CGSize displayTileSize; +@property(readwrite, nonatomic) BOOL colorOn; +@property(readwrite, nonatomic, copy) NSString *tileSet; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMosaicFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageMosaicFilter.m new file mode 100644 index 00000000..b017ca97 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMosaicFilter.m @@ -0,0 +1,188 @@ +// +// GPUImageMosaicFilter.m + + +#import "GPUImageMosaicFilter.h" +#import "GPUImagePicture.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageMosaicFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform vec2 inputTileSize; + uniform vec2 displayTileSize; + uniform float numTiles; + uniform int colorOn; + + void main() + { + vec2 xy = textureCoordinate; + xy = xy - mod(xy, displayTileSize); + + vec4 lumcoeff = vec4(0.299,0.587,0.114,0.0); + + vec4 inputColor = texture2D(inputImageTexture2, xy); + float lum = dot(inputColor,lumcoeff); + lum = 1.0 - lum; + + float stepsize = 1.0 / numTiles; + float lumStep = (lum - mod(lum, stepsize)) / stepsize; + + float rowStep = 1.0 / inputTileSize.x; + float x = mod(lumStep, rowStep); + float y = floor(lumStep / rowStep); + + vec2 startCoord = vec2(float(x) * inputTileSize.x, float(y) * inputTileSize.y); + vec2 finalCoord = startCoord + ((textureCoordinate - xy) * (inputTileSize / displayTileSize)); + + vec4 color = texture2D(inputImageTexture, finalCoord); + if (colorOn == 1) { + color = color * inputColor; + } + gl_FragColor = color; + + } +); +#else +NSString *const kGPUImageMosaicFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform vec2 inputTileSize; + uniform vec2 displayTileSize; + uniform float numTiles; + uniform int colorOn; + + void main() + { + vec2 xy = textureCoordinate; + xy = xy - mod(xy, displayTileSize); + + vec4 lumcoeff = vec4(0.299,0.587,0.114,0.0); + + vec4 inputColor = texture2D(inputImageTexture2, xy); + float lum = dot(inputColor,lumcoeff); + lum = 1.0 - lum; + + float stepsize = 1.0 / numTiles; + float lumStep = (lum - mod(lum, stepsize)) / stepsize; + + float rowStep = 1.0 / inputTileSize.x; + float x = mod(lumStep, rowStep); + float y = floor(lumStep / rowStep); + + vec2 startCoord = vec2(float(x) * inputTileSize.x, float(y) * inputTileSize.y); + vec2 finalCoord = startCoord + ((textureCoordinate - xy) * (inputTileSize / displayTileSize)); + + vec4 color = texture2D(inputImageTexture, finalCoord); + if (colorOn == 1) { + color = color * inputColor; + } + gl_FragColor = color; + } +); +#endif + +@implementation GPUImageMosaicFilter + +@synthesize inputTileSize = _inputTileSize, numTiles = _numTiles, displayTileSize = _displayTileSize, colorOn = _colorOn; +@synthesize tileSet = _tileSet; + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageMosaicFragmentShaderString])) + { + return nil; + } + + inputTileSizeUniform = [filterProgram uniformIndex:@"inputTileSize"]; + displayTileSizeUniform = [filterProgram uniformIndex:@"displayTileSize"]; + numTilesUniform = [filterProgram uniformIndex:@"numTiles"]; + colorOnUniform = [filterProgram uniformIndex:@"colorOn"]; + + CGSize its = CGSizeMake(0.125, 0.125); + CGSize dts = CGSizeMake(0.025, 0.025); + [self setDisplayTileSize:dts]; + [self setInputTileSize:its]; + [self setNumTiles:64.0]; + [self setColorOn:YES]; + //[self setTileSet:@"squares.png"]; + return self; +} + +- (void)setColorOn:(BOOL)yes +{ + glUniform1i(colorOnUniform, yes); +} + +- (void)setNumTiles:(float)numTiles +{ + + _numTiles = numTiles; + [self setFloat:_numTiles forUniformName:@"numTiles"]; +} + +- (void)setInputTileSize:(CGSize)inputTileSize +{ + if (inputTileSize.width > 1.0) { + _inputTileSize.width = 1.0; + } + if (inputTileSize.height > 1.0) { + _inputTileSize.height = 1.0; + } + if (inputTileSize.width < 0.0) { + _inputTileSize.width = 0.0; + } + if (inputTileSize.height < 0.0) { + _inputTileSize.height = 0.0; + } + + + _inputTileSize = inputTileSize; + + [self setSize:_inputTileSize forUniform:inputTileSizeUniform program:filterProgram]; +} + +-(void)setDisplayTileSize:(CGSize)displayTileSize +{ + if (displayTileSize.width > 1.0) { + _displayTileSize.width = 1.0; + } + if (displayTileSize.height > 1.0) { + _displayTileSize.height = 1.0; + } + if (displayTileSize.width < 0.0) { + _displayTileSize.width = 0.0; + } + if (displayTileSize.height < 0.0) { + _displayTileSize.height = 0.0; + } + + + _displayTileSize = displayTileSize; + + [self setSize:_displayTileSize forUniform:displayTileSizeUniform program:filterProgram]; +} + +-(void)setTileSet:(NSString *)tileSet +{ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + UIImage *img = [UIImage imageNamed:tileSet]; +#else + NSImage *img = [NSImage imageNamed:tileSet]; +#endif + pic = [[GPUImagePicture alloc] initWithImage:img smoothlyScaleOutput:YES]; + [pic addTarget:self]; + [pic processImage]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMotionBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMotionBlurFilter.h new file mode 100644 index 00000000..dcca712f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMotionBlurFilter.h @@ -0,0 +1,13 @@ +#import "GPUImageFilter.h" + +@interface GPUImageMotionBlurFilter : GPUImageFilter + +/** A multiplier for the blur size, ranging from 0.0 on up, with a default of 1.0 + */ +@property (readwrite, nonatomic) CGFloat blurSize; + +/** The angular direction of the blur, in degrees. 0 degrees by default + */ +@property (readwrite, nonatomic) CGFloat blurAngle; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMotionBlurFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageMotionBlurFilter.m new file mode 100644 index 00000000..5a2c20b6 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMotionBlurFilter.m @@ -0,0 +1,209 @@ +#import "GPUImageMotionBlurFilter.h" + +// Override vertex shader to remove dependent texture reads +NSString *const kGPUImageTiltedTexelSamplingVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + + uniform vec2 directionalTexelStep; + + varying vec2 textureCoordinate; + varying vec2 oneStepBackTextureCoordinate; + varying vec2 twoStepsBackTextureCoordinate; + varying vec2 threeStepsBackTextureCoordinate; + varying vec2 fourStepsBackTextureCoordinate; + varying vec2 oneStepForwardTextureCoordinate; + varying vec2 twoStepsForwardTextureCoordinate; + varying vec2 threeStepsForwardTextureCoordinate; + varying vec2 fourStepsForwardTextureCoordinate; + + void main() + { + gl_Position = position; + + textureCoordinate = inputTextureCoordinate.xy; + oneStepBackTextureCoordinate = inputTextureCoordinate.xy - directionalTexelStep; + twoStepsBackTextureCoordinate = inputTextureCoordinate.xy - 2.0 * directionalTexelStep; + threeStepsBackTextureCoordinate = inputTextureCoordinate.xy - 3.0 * directionalTexelStep; + fourStepsBackTextureCoordinate = inputTextureCoordinate.xy - 4.0 * directionalTexelStep; + oneStepForwardTextureCoordinate = inputTextureCoordinate.xy + directionalTexelStep; + twoStepsForwardTextureCoordinate = inputTextureCoordinate.xy + 2.0 * directionalTexelStep; + threeStepsForwardTextureCoordinate = inputTextureCoordinate.xy + 3.0 * directionalTexelStep; + fourStepsForwardTextureCoordinate = inputTextureCoordinate.xy + 4.0 * directionalTexelStep; + } +); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageMotionBlurFragmentShaderString = SHADER_STRING +( + precision highp float; + + uniform sampler2D inputImageTexture; + + varying vec2 textureCoordinate; + varying vec2 oneStepBackTextureCoordinate; + varying vec2 twoStepsBackTextureCoordinate; + varying vec2 threeStepsBackTextureCoordinate; + varying vec2 fourStepsBackTextureCoordinate; + varying vec2 oneStepForwardTextureCoordinate; + varying vec2 twoStepsForwardTextureCoordinate; + varying vec2 threeStepsForwardTextureCoordinate; + varying vec2 fourStepsForwardTextureCoordinate; + + void main() + { + // Box weights +// lowp vec4 fragmentColor = texture2D(inputImageTexture, textureCoordinate) * 0.1111111; +// fragmentColor += texture2D(inputImageTexture, oneStepBackTextureCoordinate) * 0.1111111; +// fragmentColor += texture2D(inputImageTexture, twoStepsBackTextureCoordinate) * 0.1111111; +// fragmentColor += texture2D(inputImageTexture, threeStepsBackTextureCoordinate) * 0.1111111; +// fragmentColor += texture2D(inputImageTexture, fourStepsBackTextureCoordinate) * 0.1111111; +// fragmentColor += texture2D(inputImageTexture, oneStepForwardTextureCoordinate) * 0.1111111; +// fragmentColor += texture2D(inputImageTexture, twoStepsForwardTextureCoordinate) * 0.1111111; +// fragmentColor += texture2D(inputImageTexture, threeStepsForwardTextureCoordinate) * 0.1111111; +// fragmentColor += texture2D(inputImageTexture, fourStepsForwardTextureCoordinate) * 0.1111111; + + lowp vec4 fragmentColor = texture2D(inputImageTexture, textureCoordinate) * 0.18; + fragmentColor += texture2D(inputImageTexture, oneStepBackTextureCoordinate) * 0.15; + fragmentColor += texture2D(inputImageTexture, twoStepsBackTextureCoordinate) * 0.12; + fragmentColor += texture2D(inputImageTexture, threeStepsBackTextureCoordinate) * 0.09; + fragmentColor += texture2D(inputImageTexture, fourStepsBackTextureCoordinate) * 0.05; + fragmentColor += texture2D(inputImageTexture, oneStepForwardTextureCoordinate) * 0.15; + fragmentColor += texture2D(inputImageTexture, twoStepsForwardTextureCoordinate) * 0.12; + fragmentColor += texture2D(inputImageTexture, threeStepsForwardTextureCoordinate) * 0.09; + fragmentColor += texture2D(inputImageTexture, fourStepsForwardTextureCoordinate) * 0.05; + + gl_FragColor = fragmentColor; + } +); +#else +NSString *const kGPUImageMotionBlurFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + varying vec2 textureCoordinate; + varying vec2 oneStepBackTextureCoordinate; + varying vec2 twoStepsBackTextureCoordinate; + varying vec2 threeStepsBackTextureCoordinate; + varying vec2 fourStepsBackTextureCoordinate; + varying vec2 oneStepForwardTextureCoordinate; + varying vec2 twoStepsForwardTextureCoordinate; + varying vec2 threeStepsForwardTextureCoordinate; + varying vec2 fourStepsForwardTextureCoordinate; + + void main() + { + // Box weights + // vec4 fragmentColor = texture2D(inputImageTexture, textureCoordinate) * 0.1111111; + // fragmentColor += texture2D(inputImageTexture, oneStepBackTextureCoordinate) * 0.1111111; + // fragmentColor += texture2D(inputImageTexture, twoStepsBackTextureCoordinate) * 0.1111111; + // fragmentColor += texture2D(inputImageTexture, threeStepsBackTextureCoordinate) * 0.1111111; + // fragmentColor += texture2D(inputImageTexture, fourStepsBackTextureCoordinate) * 0.1111111; + // fragmentColor += texture2D(inputImageTexture, oneStepForwardTextureCoordinate) * 0.1111111; + // fragmentColor += texture2D(inputImageTexture, twoStepsForwardTextureCoordinate) * 0.1111111; + // fragmentColor += texture2D(inputImageTexture, threeStepsForwardTextureCoordinate) * 0.1111111; + // fragmentColor += texture2D(inputImageTexture, fourStepsForwardTextureCoordinate) * 0.1111111; + + vec4 fragmentColor = texture2D(inputImageTexture, textureCoordinate) * 0.18; + fragmentColor += texture2D(inputImageTexture, oneStepBackTextureCoordinate) * 0.15; + fragmentColor += texture2D(inputImageTexture, twoStepsBackTextureCoordinate) * 0.12; + fragmentColor += texture2D(inputImageTexture, threeStepsBackTextureCoordinate) * 0.09; + fragmentColor += texture2D(inputImageTexture, fourStepsBackTextureCoordinate) * 0.05; + fragmentColor += texture2D(inputImageTexture, oneStepForwardTextureCoordinate) * 0.15; + fragmentColor += texture2D(inputImageTexture, twoStepsForwardTextureCoordinate) * 0.12; + fragmentColor += texture2D(inputImageTexture, threeStepsForwardTextureCoordinate) * 0.09; + fragmentColor += texture2D(inputImageTexture, fourStepsForwardTextureCoordinate) * 0.05; + + gl_FragColor = fragmentColor; + } +); +#endif + +@interface GPUImageMotionBlurFilter() +{ + GLint directionalTexelStepUniform; +} + +- (void)recalculateTexelOffsets; + +@end + +@implementation GPUImageMotionBlurFilter + +@synthesize blurSize = _blurSize; +@synthesize blurAngle = _blurAngle; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithVertexShaderFromString:kGPUImageTiltedTexelSamplingVertexShaderString fragmentShaderFromString:kGPUImageMotionBlurFragmentShaderString])) + { + return nil; + } + + directionalTexelStepUniform = [filterProgram uniformIndex:@"directionalTexelStep"]; + + self.blurSize = 2.5; + self.blurAngle = 0.0; + + return self; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + CGSize oldInputSize = inputTextureSize; + [super setInputSize:newSize atIndex:textureIndex]; + + if (!CGSizeEqualToSize(oldInputSize, inputTextureSize) && (!CGSizeEqualToSize(newSize, CGSizeZero)) ) + { + [self recalculateTexelOffsets]; + } +} + +- (void)recalculateTexelOffsets; +{ + CGFloat aspectRatio = 1.0; + CGPoint texelOffsets; + + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + aspectRatio = (inputTextureSize.width / inputTextureSize.height); + texelOffsets.x = _blurSize * sin(_blurAngle * M_PI / 180.0) * aspectRatio / inputTextureSize.height; + texelOffsets.y = _blurSize * cos(_blurAngle * M_PI / 180.0) / inputTextureSize.height; + } + else + { + aspectRatio = (inputTextureSize.height / inputTextureSize.width); + texelOffsets.x = _blurSize * cos(_blurAngle * M_PI / 180.0) * aspectRatio / inputTextureSize.width; + texelOffsets.y = _blurSize * sin(_blurAngle * M_PI / 180.0) / inputTextureSize.width; + } + + [self setPoint:texelOffsets forUniform:directionalTexelStepUniform program:filterProgram]; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + [super setInputRotation:newInputRotation atIndex:textureIndex]; + [self recalculateTexelOffsets]; +} + +- (void)setBlurAngle:(CGFloat)newValue; +{ + _blurAngle = newValue; + [self recalculateTexelOffsets]; +} + +- (void)setBlurSize:(CGFloat)newValue; +{ + _blurSize = newValue; + [self recalculateTexelOffsets]; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMotionDetector.h b/LFLiveKit/Vendor/GPUImage/GPUImageMotionDetector.h new file mode 100644 index 00000000..01329145 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMotionDetector.h @@ -0,0 +1,18 @@ +#import "GPUImageFilterGroup.h" +#import "GPUImageLowPassFilter.h" +#import "GPUImageAverageColor.h" + +@interface GPUImageMotionDetector : GPUImageFilterGroup +{ + GPUImageLowPassFilter *lowPassFilter; + GPUImageTwoInputFilter *frameComparisonFilter; + GPUImageAverageColor *averageColor; +} + +// This controls the low pass filter strength used to compare the current frame with previous ones to detect motion. This ranges from 0.0 to 1.0, with a default of 0.5. +@property(readwrite, nonatomic) CGFloat lowPassFilterStrength; + +// For every frame, this will feed back the calculated centroid of the motion, as well as a relative intensity. +@property(nonatomic, copy) void(^motionDetectionBlock)(CGPoint motionCentroid, CGFloat motionIntensity, CMTime frameTime); + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMotionDetector.m b/LFLiveKit/Vendor/GPUImage/GPUImageMotionDetector.m new file mode 100644 index 00000000..0e204ad7 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMotionDetector.m @@ -0,0 +1,112 @@ +#import "GPUImageMotionDetector.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageMotionComparisonFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform highp float intensity; + + void main() + { + lowp vec3 currentImageColor = texture2D(inputImageTexture, textureCoordinate).rgb; + lowp vec3 lowPassImageColor = texture2D(inputImageTexture2, textureCoordinate2).rgb; + + mediump float colorDistance = distance(currentImageColor, lowPassImageColor); // * 0.57735 + lowp float movementThreshold = step(0.2, colorDistance); + + gl_FragColor = movementThreshold * vec4(textureCoordinate2.x, textureCoordinate2.y, 1.0, 1.0); + } +); +#else +NSString *const kGPUImageMotionComparisonFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform float intensity; + + void main() + { + vec3 currentImageColor = texture2D(inputImageTexture, textureCoordinate).rgb; + vec3 lowPassImageColor = texture2D(inputImageTexture2, textureCoordinate2).rgb; + + float colorDistance = distance(currentImageColor, lowPassImageColor); // * 0.57735 + float movementThreshold = step(0.2, colorDistance); + + gl_FragColor = movementThreshold * vec4(textureCoordinate2.x, textureCoordinate2.y, 1.0, 1.0); + } +); +#endif + + +@implementation GPUImageMotionDetector + +@synthesize lowPassFilterStrength, motionDetectionBlock; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + // Start with a low pass filter to define the component to be removed + lowPassFilter = [[GPUImageLowPassFilter alloc] init]; + [self addFilter:lowPassFilter]; + + // Take the difference of the current frame from the low pass filtered result to get the high pass + frameComparisonFilter = [[GPUImageTwoInputFilter alloc] initWithFragmentShaderFromString:kGPUImageMotionComparisonFragmentShaderString]; + [self addFilter:frameComparisonFilter]; + + // Texture location 0 needs to be the original image for the difference blend + [lowPassFilter addTarget:frameComparisonFilter atTextureLocation:1]; + + // End with the average color for the scene to determine the centroid + averageColor = [[GPUImageAverageColor alloc] init]; + + __unsafe_unretained GPUImageMotionDetector *weakSelf = self; + + [averageColor setColorAverageProcessingFinishedBlock:^(CGFloat redComponent, CGFloat greenComponent, CGFloat blueComponent, CGFloat alphaComponent, CMTime frameTime) { + if (weakSelf.motionDetectionBlock != NULL) + { + weakSelf.motionDetectionBlock(CGPointMake(redComponent / alphaComponent, greenComponent / alphaComponent), alphaComponent, frameTime); + } +// NSLog(@"Average X: %f, Y: %f total: %f", redComponent / alphaComponent, greenComponent / alphaComponent, alphaComponent); + }]; + + [frameComparisonFilter addTarget:averageColor]; + + self.initialFilters = [NSArray arrayWithObjects:lowPassFilter, frameComparisonFilter, nil]; + self.terminalFilter = frameComparisonFilter; + + self.lowPassFilterStrength = 0.5; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setLowPassFilterStrength:(CGFloat)newValue; +{ + lowPassFilter.filterStrength = newValue; +} + +- (CGFloat)lowPassFilterStrength; +{ + return lowPassFilter.filterStrength; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMovie.h b/LFLiveKit/Vendor/GPUImage/GPUImageMovie.h new file mode 100755 index 00000000..f61e56ef --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMovie.h @@ -0,0 +1,61 @@ +#import +#import +#import "GPUImageContext.h" +#import "GPUImageOutput.h" + +/** Protocol for getting Movie played callback. + */ +@protocol GPUImageMovieDelegate + +- (void)didCompletePlayingMovie; +@end + +/** Source object for filtering movies + */ +@interface GPUImageMovie : GPUImageOutput + +@property (readwrite, retain) AVAsset *asset; +@property (readwrite, retain) AVPlayerItem *playerItem; +@property(readwrite, retain) NSURL *url; + +/** This enables the benchmarking mode, which logs out instantaneous and average frame times to the console + */ +@property(readwrite, nonatomic) BOOL runBenchmark; + +/** This determines whether to play back a movie as fast as the frames can be processed, or if the original speed of the movie should be respected. Defaults to NO. + */ +@property(readwrite, nonatomic) BOOL playAtActualSpeed; + +/** This determines whether the video should repeat (loop) at the end and restart from the beginning. Defaults to NO. + */ +@property(readwrite, nonatomic) BOOL shouldRepeat; + +/** This specifies the progress of the process on a scale from 0 to 1.0. A value of 0 means the process has not yet begun, A value of 1.0 means the conversaion is complete. + This property is not key-value observable. + */ +@property(readonly, nonatomic) float progress; + +/** This is used to send the delete Movie did complete playing alert + */ +@property (readwrite, nonatomic, assign) id delegate; + +@property (readonly, nonatomic) AVAssetReader *assetReader; +@property (readonly, nonatomic) BOOL audioEncodingIsFinished; +@property (readonly, nonatomic) BOOL videoEncodingIsFinished; + +/// @name Initialization and teardown +- (id)initWithAsset:(AVAsset *)asset; +- (id)initWithPlayerItem:(AVPlayerItem *)playerItem; +- (id)initWithURL:(NSURL *)url; +- (void)yuvConversionSetup; + +/// @name Movie processing +- (void)enableSynchronizedEncodingUsingMovieWriter:(GPUImageMovieWriter *)movieWriter; +- (BOOL)readNextVideoFrameFromOutput:(AVAssetReaderOutput *)readerVideoTrackOutput; +- (BOOL)readNextAudioSampleFromOutput:(AVAssetReaderOutput *)readerAudioTrackOutput; +- (void)startProcessing; +- (void)endProcessing; +- (void)cancelProcessing; +- (void)processMovieFrame:(CMSampleBufferRef)movieSampleBuffer; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMovie.m b/LFLiveKit/Vendor/GPUImage/GPUImageMovie.m new file mode 100755 index 00000000..4da050f4 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMovie.m @@ -0,0 +1,876 @@ +#import "GPUImageMovie.h" +#import "GPUImageMovieWriter.h" +#import "GPUImageFilter.h" +#import "GPUImageColorConversion.h" + + +@interface GPUImageMovie () +{ + BOOL audioEncodingIsFinished, videoEncodingIsFinished; + GPUImageMovieWriter *synchronizedMovieWriter; + AVAssetReader *reader; + AVPlayerItemVideoOutput *playerItemOutput; +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + CADisplayLink *displayLink; +#else + CVDisplayLinkRef displayLink; +#endif + CMTime previousFrameTime, processingFrameTime; + CFAbsoluteTime previousActualFrameTime; + BOOL keepLooping; + + GLuint luminanceTexture, chrominanceTexture; + + GLProgram *yuvConversionProgram; + GLint yuvConversionPositionAttribute, yuvConversionTextureCoordinateAttribute; + GLint yuvConversionLuminanceTextureUniform, yuvConversionChrominanceTextureUniform; + GLint yuvConversionMatrixUniform; + const GLfloat *_preferredConversion; + + BOOL isFullYUVRange; + + int imageBufferWidth, imageBufferHeight; +} + +- (void)processAsset; + +@end + +@implementation GPUImageMovie + +@synthesize url = _url; +@synthesize asset = _asset; +@synthesize runBenchmark = _runBenchmark; +@synthesize playAtActualSpeed = _playAtActualSpeed; +@synthesize delegate = _delegate; +@synthesize shouldRepeat = _shouldRepeat; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithURL:(NSURL *)url; +{ + if (!(self = [super init])) + { + return nil; + } + + [self yuvConversionSetup]; + + self.url = url; + self.asset = nil; + + return self; +} + +- (id)initWithAsset:(AVAsset *)asset; +{ + if (!(self = [super init])) + { + return nil; + } + + [self yuvConversionSetup]; + + self.url = nil; + self.asset = asset; + + return self; +} + +- (id)initWithPlayerItem:(AVPlayerItem *)playerItem; +{ + if (!(self = [super init])) + { + return nil; + } + + [self yuvConversionSetup]; + + self.url = nil; + self.asset = nil; + self.playerItem = playerItem; + + return self; +} + +- (void)yuvConversionSetup; +{ + if ([GPUImageContext supportsFastTextureUpload]) + { + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + + _preferredConversion = kColorConversion709; + isFullYUVRange = YES; + yuvConversionProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:kGPUImageVertexShaderString fragmentShaderString:kGPUImageYUVFullRangeConversionForLAFragmentShaderString]; + + if (!yuvConversionProgram.initialized) + { + [yuvConversionProgram addAttribute:@"position"]; + [yuvConversionProgram addAttribute:@"inputTextureCoordinate"]; + + if (![yuvConversionProgram link]) + { + NSString *progLog = [yuvConversionProgram programLog]; + NSLog(@"Program link log: %@", progLog); + NSString *fragLog = [yuvConversionProgram fragmentShaderLog]; + NSLog(@"Fragment shader compile log: %@", fragLog); + NSString *vertLog = [yuvConversionProgram vertexShaderLog]; + NSLog(@"Vertex shader compile log: %@", vertLog); + yuvConversionProgram = nil; + NSAssert(NO, @"Filter shader link failed"); + } + } + + yuvConversionPositionAttribute = [yuvConversionProgram attributeIndex:@"position"]; + yuvConversionTextureCoordinateAttribute = [yuvConversionProgram attributeIndex:@"inputTextureCoordinate"]; + yuvConversionLuminanceTextureUniform = [yuvConversionProgram uniformIndex:@"luminanceTexture"]; + yuvConversionChrominanceTextureUniform = [yuvConversionProgram uniformIndex:@"chrominanceTexture"]; + yuvConversionMatrixUniform = [yuvConversionProgram uniformIndex:@"colorConversionMatrix"]; + + [GPUImageContext setActiveShaderProgram:yuvConversionProgram]; + + glEnableVertexAttribArray(yuvConversionPositionAttribute); + glEnableVertexAttribArray(yuvConversionTextureCoordinateAttribute); + }); + } +} + +- (void)dealloc +{ + [playerItemOutput setDelegate:nil queue:nil]; + + // Moved into endProcessing + //if (self.playerItem && (displayLink != nil)) + //{ + // [displayLink invalidate]; // remove from all run loops + // displayLink = nil; + //} +} + +#pragma mark - +#pragma mark Movie processing + +- (void)enableSynchronizedEncodingUsingMovieWriter:(GPUImageMovieWriter *)movieWriter; +{ + synchronizedMovieWriter = movieWriter; + movieWriter.encodingLiveVideo = NO; +} + +- (void)startProcessing +{ + if( self.playerItem ) { + [self processPlayerItem]; + return; + } + if(self.url == nil) + { + [self processAsset]; + return; + } + + if (_shouldRepeat) keepLooping = YES; + + previousFrameTime = kCMTimeZero; + previousActualFrameTime = CFAbsoluteTimeGetCurrent(); + + NSDictionary *inputOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:AVURLAssetPreferPreciseDurationAndTimingKey]; + AVURLAsset *inputAsset = [[AVURLAsset alloc] initWithURL:self.url options:inputOptions]; + + GPUImageMovie __block *blockSelf = self; + + [inputAsset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler: ^{ + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + NSError *error = nil; + AVKeyValueStatus tracksStatus = [inputAsset statusOfValueForKey:@"tracks" error:&error]; + if (tracksStatus != AVKeyValueStatusLoaded) + { + return; + } + blockSelf.asset = inputAsset; + [blockSelf processAsset]; + blockSelf = nil; + }); + }]; +} + +- (AVAssetReader*)createAssetReader +{ + NSError *error = nil; + AVAssetReader *assetReader = [AVAssetReader assetReaderWithAsset:self.asset error:&error]; + + NSMutableDictionary *outputSettings = [NSMutableDictionary dictionary]; + if ([GPUImageContext supportsFastTextureUpload]) { + [outputSettings setObject:@(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) forKey:(id)kCVPixelBufferPixelFormatTypeKey]; + isFullYUVRange = YES; + } + else { + [outputSettings setObject:@(kCVPixelFormatType_32BGRA) forKey:(id)kCVPixelBufferPixelFormatTypeKey]; + isFullYUVRange = NO; + } + + // Maybe set alwaysCopiesSampleData to NO on iOS 5.0 for faster video decoding + AVAssetReaderTrackOutput *readerVideoTrackOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:[[self.asset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] outputSettings:outputSettings]; + readerVideoTrackOutput.alwaysCopiesSampleData = NO; + [assetReader addOutput:readerVideoTrackOutput]; + + NSArray *audioTracks = [self.asset tracksWithMediaType:AVMediaTypeAudio]; + BOOL shouldRecordAudioTrack = (([audioTracks count] > 0) && (self.audioEncodingTarget != nil) ); + AVAssetReaderTrackOutput *readerAudioTrackOutput = nil; + + if (shouldRecordAudioTrack) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [self.audioEncodingTarget setShouldInvalidateAudioSampleWhenDone:YES]; +#else +#warning Missing OSX implementation +#endif + + // This might need to be extended to handle movies with more than one audio track + AVAssetTrack* audioTrack = [audioTracks objectAtIndex:0]; + readerAudioTrackOutput = [AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:audioTrack outputSettings:nil]; + readerAudioTrackOutput.alwaysCopiesSampleData = NO; + [assetReader addOutput:readerAudioTrackOutput]; + } + + return assetReader; +} + +- (void)processAsset +{ + reader = [self createAssetReader]; + + AVAssetReaderOutput *readerVideoTrackOutput = nil; + AVAssetReaderOutput *readerAudioTrackOutput = nil; + + audioEncodingIsFinished = YES; + for( AVAssetReaderOutput *output in reader.outputs ) { + if( [output.mediaType isEqualToString:AVMediaTypeAudio] ) { + audioEncodingIsFinished = NO; + readerAudioTrackOutput = output; + } + else if( [output.mediaType isEqualToString:AVMediaTypeVideo] ) { + readerVideoTrackOutput = output; + } + } + + if ([reader startReading] == NO) + { + NSLog(@"Error reading from file at URL: %@", self.url); + return; + } + + __unsafe_unretained GPUImageMovie *weakSelf = self; + + if (synchronizedMovieWriter != nil) + { + [synchronizedMovieWriter setVideoInputReadyCallback:^{ + BOOL success = [weakSelf readNextVideoFrameFromOutput:readerVideoTrackOutput]; +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + return success; +#endif + }]; + + [synchronizedMovieWriter setAudioInputReadyCallback:^{ + BOOL success = [weakSelf readNextAudioSampleFromOutput:readerAudioTrackOutput]; +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + return success; +#endif + }]; + + [synchronizedMovieWriter enableSynchronizationCallbacks]; + + } + else + { + while (reader.status == AVAssetReaderStatusReading && (!_shouldRepeat || keepLooping)) + { + [weakSelf readNextVideoFrameFromOutput:readerVideoTrackOutput]; + + if ( (readerAudioTrackOutput) && (!audioEncodingIsFinished) ) + { + [weakSelf readNextAudioSampleFromOutput:readerAudioTrackOutput]; + } + + } + + if (reader.status == AVAssetReaderStatusCompleted) { + + [reader cancelReading]; + + if (keepLooping) { + reader = nil; + dispatch_async(dispatch_get_main_queue(), ^{ + [self startProcessing]; + }); + } else { + [weakSelf endProcessing]; + } + + } + } +} + +- (void)processPlayerItem +{ + runSynchronouslyOnVideoProcessingQueue(^{ + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkCallback:)]; + [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes]; + [displayLink setPaused:YES]; +#else + // Suggested implementation: use CVDisplayLink http://stackoverflow.com/questions/14158743/alternative-of-cadisplaylink-for-mac-os-x + CGDirectDisplayID displayID = CGMainDisplayID(); + CVReturn error = kCVReturnSuccess; + error = CVDisplayLinkCreateWithCGDisplay(displayID, &displayLink); + if (error) + { + NSLog(@"DisplayLink created with error:%d", error); + displayLink = NULL; + } + CVDisplayLinkSetOutputCallback(displayLink, renderCallback, (__bridge void *)self); + CVDisplayLinkStop(displayLink); +#endif + + dispatch_queue_t videoProcessingQueue = [GPUImageContext sharedContextQueue]; + NSMutableDictionary *pixBuffAttributes = [NSMutableDictionary dictionary]; + if ([GPUImageContext supportsFastTextureUpload]) { + [pixBuffAttributes setObject:@(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) forKey:(id)kCVPixelBufferPixelFormatTypeKey]; + } + else { + [pixBuffAttributes setObject:@(kCVPixelFormatType_32BGRA) forKey:(id)kCVPixelBufferPixelFormatTypeKey]; + } + playerItemOutput = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:pixBuffAttributes]; + [playerItemOutput setDelegate:self queue:videoProcessingQueue]; + + [_playerItem addOutput:playerItemOutput]; + [playerItemOutput requestNotificationOfMediaDataChangeWithAdvanceInterval:0.1]; + }); +} + +- (void)outputMediaDataWillChange:(AVPlayerItemOutput *)sender +{ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + // Restart display link. + [displayLink setPaused:NO]; +#else + CVDisplayLinkStart(displayLink); +#endif +} + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +- (void)displayLinkCallback:(CADisplayLink *)sender +{ + /* + The callback gets called once every Vsync. + Using the display link's timestamp and duration we can compute the next time the screen will be refreshed, and copy the pixel buffer for that time + This pixel buffer can then be processed and later rendered on screen. + */ + // Calculate the nextVsync time which is when the screen will be refreshed next. + CFTimeInterval nextVSync = ([sender timestamp] + [sender duration]); + + CMTime outputItemTime = [playerItemOutput itemTimeForHostTime:nextVSync]; + + [self processPixelBufferAtTime:outputItemTime]; + +} +#else +static CVReturn renderCallback(CVDisplayLinkRef displayLink, + const CVTimeStamp *inNow, + const CVTimeStamp *inOutputTime, + CVOptionFlags flagsIn, + CVOptionFlags *flagsOut, + void *displayLinkContext) +{ + // Sample code taken from here https://developer.apple.com/library/mac/samplecode/AVGreenScreenPlayer/Listings/AVGreenScreenPlayer_GSPlayerView_m.html + + GPUImageMovie *self = (__bridge GPUImageMovie *)displayLinkContext; + AVPlayerItemVideoOutput *playerItemOutput = self->playerItemOutput; + + + // The displayLink calls back at every vsync (screen refresh) + // Compute itemTime for the next vsync + CMTime outputItemTime = [playerItemOutput itemTimeForCVTimeStamp:*inOutputTime]; + + [self processPixelBufferAtTime:outputItemTime]; + + return kCVReturnSuccess; +} +#endif + +- (void)processPixelBufferAtTime:(CMTime)outputItemTime { + if ([playerItemOutput hasNewPixelBufferForItemTime:outputItemTime]) { + __unsafe_unretained GPUImageMovie *weakSelf = self; + CVPixelBufferRef pixelBuffer = [playerItemOutput copyPixelBufferForItemTime:outputItemTime itemTimeForDisplay:NULL]; + if( pixelBuffer ) + runSynchronouslyOnVideoProcessingQueue(^{ + [weakSelf processMovieFrame:pixelBuffer withSampleTime:outputItemTime]; + CFRelease(pixelBuffer); + }); + } +} + +- (BOOL)readNextVideoFrameFromOutput:(AVAssetReaderOutput *)readerVideoTrackOutput; +{ + if (reader.status == AVAssetReaderStatusReading && ! videoEncodingIsFinished) + { + CMSampleBufferRef sampleBufferRef = [readerVideoTrackOutput copyNextSampleBuffer]; + if (sampleBufferRef) + { + //NSLog(@"read a video frame: %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, CMSampleBufferGetOutputPresentationTimeStamp(sampleBufferRef)))); + if (_playAtActualSpeed) + { + // Do this outside of the video processing queue to not slow that down while waiting + CMTime currentSampleTime = CMSampleBufferGetOutputPresentationTimeStamp(sampleBufferRef); + CMTime differenceFromLastFrame = CMTimeSubtract(currentSampleTime, previousFrameTime); + CFAbsoluteTime currentActualTime = CFAbsoluteTimeGetCurrent(); + + CGFloat frameTimeDifference = CMTimeGetSeconds(differenceFromLastFrame); + CGFloat actualTimeDifference = currentActualTime - previousActualFrameTime; + + if (frameTimeDifference > actualTimeDifference) + { + usleep(1000000.0 * (frameTimeDifference - actualTimeDifference)); + } + + previousFrameTime = currentSampleTime; + previousActualFrameTime = CFAbsoluteTimeGetCurrent(); + } + + __unsafe_unretained GPUImageMovie *weakSelf = self; + runSynchronouslyOnVideoProcessingQueue(^{ + [weakSelf processMovieFrame:sampleBufferRef]; + CMSampleBufferInvalidate(sampleBufferRef); + CFRelease(sampleBufferRef); + }); + + return YES; + } + else + { + if (!keepLooping) { + videoEncodingIsFinished = YES; + if( videoEncodingIsFinished && audioEncodingIsFinished ) + [self endProcessing]; + } + } + } + else if (synchronizedMovieWriter != nil) + { + if (reader.status == AVAssetReaderStatusCompleted) + { + [self endProcessing]; + } + } + return NO; +} + +- (BOOL)readNextAudioSampleFromOutput:(AVAssetReaderOutput *)readerAudioTrackOutput; +{ + if (reader.status == AVAssetReaderStatusReading && ! audioEncodingIsFinished) + { + CMSampleBufferRef audioSampleBufferRef = [readerAudioTrackOutput copyNextSampleBuffer]; + if (audioSampleBufferRef) + { + //NSLog(@"read an audio frame: %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, CMSampleBufferGetOutputPresentationTimeStamp(audioSampleBufferRef)))); + [self.audioEncodingTarget processAudioBuffer:audioSampleBufferRef]; + CFRelease(audioSampleBufferRef); + return YES; + } + else + { + if (!keepLooping) { + audioEncodingIsFinished = YES; + if( videoEncodingIsFinished && audioEncodingIsFinished ) + [self endProcessing]; + } + } + } + else if (synchronizedMovieWriter != nil) + { + if (reader.status == AVAssetReaderStatusCompleted || reader.status == AVAssetReaderStatusFailed || + reader.status == AVAssetReaderStatusCancelled) + { + [self endProcessing]; + } + } + return NO; +} + +- (void)processMovieFrame:(CMSampleBufferRef)movieSampleBuffer; +{ +// CMTimeGetSeconds +// CMTimeSubtract + + CMTime currentSampleTime = CMSampleBufferGetOutputPresentationTimeStamp(movieSampleBuffer); + CVImageBufferRef movieFrame = CMSampleBufferGetImageBuffer(movieSampleBuffer); + + processingFrameTime = currentSampleTime; + [self processMovieFrame:movieFrame withSampleTime:currentSampleTime]; +} + +- (float)progress +{ + if ( AVAssetReaderStatusReading == reader.status ) + { + float current = processingFrameTime.value * 1.0f / processingFrameTime.timescale; + float duration = self.asset.duration.value * 1.0f / self.asset.duration.timescale; + return current / duration; + } + else if ( AVAssetReaderStatusCompleted == reader.status ) + { + return 1.f; + } + else + { + return 0.f; + } +} + +- (void)processMovieFrame:(CVPixelBufferRef)movieFrame withSampleTime:(CMTime)currentSampleTime +{ + int bufferHeight = (int) CVPixelBufferGetHeight(movieFrame); + int bufferWidth = (int) CVPixelBufferGetWidth(movieFrame); + + CFTypeRef colorAttachments = CVBufferGetAttachment(movieFrame, kCVImageBufferYCbCrMatrixKey, NULL); + if (colorAttachments != NULL) + { + if(CFStringCompare(colorAttachments, kCVImageBufferYCbCrMatrix_ITU_R_601_4, 0) == kCFCompareEqualTo) + { + if (isFullYUVRange) + { + _preferredConversion = kColorConversion601FullRange; + } + else + { + _preferredConversion = kColorConversion601; + } + } + else + { + _preferredConversion = kColorConversion709; + } + } + else + { + if (isFullYUVRange) + { + _preferredConversion = kColorConversion601FullRange; + } + else + { + _preferredConversion = kColorConversion601; + } + + } + + CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); + + // Fix issue 1580 + [GPUImageContext useImageProcessingContext]; + + if ([GPUImageContext supportsFastTextureUpload]) + { + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + CVOpenGLESTextureRef luminanceTextureRef = NULL; + CVOpenGLESTextureRef chrominanceTextureRef = NULL; +#else + CVOpenGLTextureRef luminanceTextureRef = NULL; + CVOpenGLTextureRef chrominanceTextureRef = NULL; +#endif + + // if (captureAsYUV && [GPUImageContext deviceSupportsRedTextures]) + if (CVPixelBufferGetPlaneCount(movieFrame) > 0) // Check for YUV planar inputs to do RGB conversion + { + + // fix issue 2221 + CVPixelBufferLockBaseAddress(movieFrame,0); + + + if ( (imageBufferWidth != bufferWidth) && (imageBufferHeight != bufferHeight) ) + { + imageBufferWidth = bufferWidth; + imageBufferHeight = bufferHeight; + } + + CVReturn err; + // Y-plane + glActiveTexture(GL_TEXTURE4); + if ([GPUImageContext deviceSupportsRedTextures]) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], movieFrame, NULL, GL_TEXTURE_2D, GL_LUMINANCE, bufferWidth, bufferHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0, &luminanceTextureRef); +#else + err = CVOpenGLTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], movieFrame, NULL, &luminanceTextureRef); +#endif + } + else + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], movieFrame, NULL, GL_TEXTURE_2D, GL_LUMINANCE, bufferWidth, bufferHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0, &luminanceTextureRef); +#else + err = CVOpenGLTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], movieFrame, NULL, &luminanceTextureRef); +#endif + } + if (err) + { + NSLog(@"Error at CVOpenGLESTextureCacheCreateTextureFromImage %d", err); + } + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + luminanceTexture = CVOpenGLESTextureGetName(luminanceTextureRef); +#else + luminanceTexture = CVOpenGLTextureGetName(luminanceTextureRef); +#endif + glBindTexture(GL_TEXTURE_2D, luminanceTexture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + // UV-plane + glActiveTexture(GL_TEXTURE5); + if ([GPUImageContext deviceSupportsRedTextures]) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], movieFrame, NULL, GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, bufferWidth/2, bufferHeight/2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 1, &chrominanceTextureRef); +#else + err = CVOpenGLTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], movieFrame, NULL, &chrominanceTextureRef); +#endif + } + else + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], movieFrame, NULL, GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, bufferWidth/2, bufferHeight/2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 1, &chrominanceTextureRef); +#else + err = CVOpenGLTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], movieFrame, NULL, &chrominanceTextureRef); +#endif + } + if (err) + { + NSLog(@"Error at CVOpenGLESTextureCacheCreateTextureFromImage %d", err); + } + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + chrominanceTexture = CVOpenGLESTextureGetName(chrominanceTextureRef); +#else + chrominanceTexture = CVOpenGLTextureGetName(chrominanceTextureRef); +#endif + glBindTexture(GL_TEXTURE_2D, chrominanceTexture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + +// if (!allTargetsWantMonochromeData) +// { + [self convertYUVToRGBOutput]; +// } + + for (id currentTarget in targets) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger targetTextureIndex = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + [currentTarget setInputSize:CGSizeMake(bufferWidth, bufferHeight) atIndex:targetTextureIndex]; + [currentTarget setInputFramebuffer:outputFramebuffer atIndex:targetTextureIndex]; + } + + [outputFramebuffer unlock]; + + for (id currentTarget in targets) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger targetTextureIndex = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + [currentTarget newFrameReadyAtTime:currentSampleTime atIndex:targetTextureIndex]; + } + + CVPixelBufferUnlockBaseAddress(movieFrame, 0); + CFRelease(luminanceTextureRef); + CFRelease(chrominanceTextureRef); + } + else + { + // TODO: Mesh this with the new framebuffer cache +// CVPixelBufferLockBaseAddress(movieFrame, 0); +// +// CVReturn err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, coreVideoTextureCache, movieFrame, NULL, GL_TEXTURE_2D, GL_RGBA, bufferWidth, bufferHeight, GL_BGRA, GL_UNSIGNED_BYTE, 0, &texture); +// +// if (!texture || err) { +// NSLog(@"Movie CVOpenGLESTextureCacheCreateTextureFromImage failed (error: %d)", err); +// NSAssert(NO, @"Camera failure"); +// return; +// } +// +// outputTexture = CVOpenGLESTextureGetName(texture); +// // glBindTexture(CVOpenGLESTextureGetTarget(texture), outputTexture); +// glBindTexture(GL_TEXTURE_2D, outputTexture); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); +// +// for (id currentTarget in targets) +// { +// NSInteger indexOfObject = [targets indexOfObject:currentTarget]; +// NSInteger targetTextureIndex = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; +// +// [currentTarget setInputSize:CGSizeMake(bufferWidth, bufferHeight) atIndex:targetTextureIndex]; +// [currentTarget setInputTexture:outputTexture atIndex:targetTextureIndex]; +// +// [currentTarget newFrameReadyAtTime:currentSampleTime atIndex:targetTextureIndex]; +// } +// +// CVPixelBufferUnlockBaseAddress(movieFrame, 0); +// CVOpenGLESTextureCacheFlush(coreVideoTextureCache, 0); +// CFRelease(texture); +// +// outputTexture = 0; + } + } + else + { + // Upload to texture + CVPixelBufferLockBaseAddress(movieFrame, 0); + + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:CGSizeMake(bufferWidth, bufferHeight) textureOptions:self.outputTextureOptions onlyTexture:YES]; + + glBindTexture(GL_TEXTURE_2D, [outputFramebuffer texture]); + // Using BGRA extension to pull in video frame data directly + glTexImage2D(GL_TEXTURE_2D, + 0, + self.outputTextureOptions.internalFormat, + bufferWidth, + bufferHeight, + 0, + self.outputTextureOptions.format, + self.outputTextureOptions.type, + CVPixelBufferGetBaseAddress(movieFrame)); + + for (id currentTarget in targets) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger targetTextureIndex = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + [currentTarget setInputSize:CGSizeMake(bufferWidth, bufferHeight) atIndex:targetTextureIndex]; + [currentTarget setInputFramebuffer:outputFramebuffer atIndex:targetTextureIndex]; + } + + [outputFramebuffer unlock]; + + for (id currentTarget in targets) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger targetTextureIndex = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + [currentTarget newFrameReadyAtTime:currentSampleTime atIndex:targetTextureIndex]; + } + CVPixelBufferUnlockBaseAddress(movieFrame, 0); + } + + if (_runBenchmark) + { + CFAbsoluteTime currentFrameTime = (CFAbsoluteTimeGetCurrent() - startTime); + NSLog(@"Current frame time : %f ms", 1000.0 * currentFrameTime); + } +} + +- (void)endProcessing; +{ + keepLooping = NO; +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [displayLink setPaused:YES]; +#else + CVDisplayLinkStop(displayLink); +#endif + + for (id currentTarget in targets) + { + [currentTarget endProcessing]; + } + + if (synchronizedMovieWriter != nil) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [synchronizedMovieWriter setVideoInputReadyCallback:^{return NO;}]; + [synchronizedMovieWriter setAudioInputReadyCallback:^{return NO;}]; +#else + // I'm not sure about this, meybe setting a nil will be more appropriate then an empty block + [synchronizedMovieWriter setVideoInputReadyCallback:^{}]; + [synchronizedMovieWriter setAudioInputReadyCallback:^{}]; +#endif + } + + if (self.playerItem && (displayLink != nil)) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [displayLink invalidate]; // remove from all run loops + displayLink = nil; +#else + CVDisplayLinkStop(displayLink); + displayLink = NULL; +#endif + } + + if ([self.delegate respondsToSelector:@selector(didCompletePlayingMovie)]) { + [self.delegate didCompletePlayingMovie]; + } + self.delegate = nil; +} + +- (void)cancelProcessing +{ + if (reader) { + [reader cancelReading]; + } + [self endProcessing]; +} + +- (void)convertYUVToRGBOutput; +{ + [GPUImageContext setActiveShaderProgram:yuvConversionProgram]; + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:CGSizeMake(imageBufferWidth, imageBufferHeight) onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + static const GLfloat squareVertices[] = { + -1.0f, -1.0f, + 1.0f, -1.0f, + -1.0f, 1.0f, + 1.0f, 1.0f, + }; + + static const GLfloat textureCoordinates[] = { + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + }; + + glActiveTexture(GL_TEXTURE4); + glBindTexture(GL_TEXTURE_2D, luminanceTexture); + glUniform1i(yuvConversionLuminanceTextureUniform, 4); + + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_2D, chrominanceTexture); + glUniform1i(yuvConversionChrominanceTextureUniform, 5); + + glUniformMatrix3fv(yuvConversionMatrixUniform, 1, GL_FALSE, _preferredConversion); + + glVertexAttribPointer(yuvConversionPositionAttribute, 2, GL_FLOAT, 0, 0, squareVertices); + glVertexAttribPointer(yuvConversionTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); +} + +- (AVAssetReader*)assetReader { + return reader; +} + +- (BOOL)audioEncodingIsFinished { + return audioEncodingIsFinished; +} + +- (BOOL)videoEncodingIsFinished { + return videoEncodingIsFinished; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMovieComposition.h b/LFLiveKit/Vendor/GPUImage/GPUImageMovieComposition.h new file mode 100644 index 00000000..00e43814 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMovieComposition.h @@ -0,0 +1,21 @@ +// +// GPUImageMovieComposition.h +// Givit +// +// Created by Sean Meiners on 2013/01/25. +// +// + +#import "GPUImageMovie.h" + +@interface GPUImageMovieComposition : GPUImageMovie + +@property (readwrite, retain) AVComposition *compositon; +@property (readwrite, retain) AVVideoComposition *videoComposition; +@property (readwrite, retain) AVAudioMix *audioMix; + +- (id)initWithComposition:(AVComposition*)compositon + andVideoComposition:(AVVideoComposition*)videoComposition + andAudioMix:(AVAudioMix*)audioMix; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMovieComposition.m b/LFLiveKit/Vendor/GPUImage/GPUImageMovieComposition.m new file mode 100644 index 00000000..6138fffe --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMovieComposition.m @@ -0,0 +1,70 @@ +// +// GPUImageMovieComposition.m +// Givit +// +// Created by Sean Meiners on 2013/01/25. +// +// + +#import "GPUImageMovieComposition.h" +#import "GPUImageMovieWriter.h" + +@implementation GPUImageMovieComposition + +@synthesize compositon = _compositon; +@synthesize videoComposition = _videoComposition; +@synthesize audioMix = _audioMix; + +- (id)initWithComposition:(AVComposition*)compositon + andVideoComposition:(AVVideoComposition*)videoComposition + andAudioMix:(AVAudioMix*)audioMix { + if (!(self = [super init])) + { + return nil; + } + + [self yuvConversionSetup]; + + self.compositon = compositon; + self.videoComposition = videoComposition; + self.audioMix = audioMix; + + return self; +} + +- (AVAssetReader*)createAssetReader + { + //NSLog(@"creating reader from composition: %@, video: %@, audio: %@ with duration: %@", _compositon, _videoComposition, _audioMix, CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, _compositon.duration))); + + NSError *error = nil; + AVAssetReader *assetReader = [AVAssetReader assetReaderWithAsset:self.compositon error:&error]; + + NSDictionary *outputSettings = @{(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_420YpCbCr8BiPlanarFullRange)}; + AVAssetReaderVideoCompositionOutput *readerVideoOutput = [AVAssetReaderVideoCompositionOutput assetReaderVideoCompositionOutputWithVideoTracks:[_compositon tracksWithMediaType:AVMediaTypeVideo] + videoSettings:outputSettings]; +#if ! TARGET_IPHONE_SIMULATOR + if( [_videoComposition isKindOfClass:[AVMutableVideoComposition class]] ) + [(AVMutableVideoComposition*)_videoComposition setRenderScale:1.0]; +#endif + readerVideoOutput.videoComposition = self.videoComposition; + readerVideoOutput.alwaysCopiesSampleData = NO; + [assetReader addOutput:readerVideoOutput]; + + NSArray *audioTracks = [_compositon tracksWithMediaType:AVMediaTypeAudio]; + BOOL shouldRecordAudioTrack = (([audioTracks count] > 0) && (self.audioEncodingTarget != nil) ); + AVAssetReaderAudioMixOutput *readerAudioOutput = nil; + + if (shouldRecordAudioTrack) + { + [self.audioEncodingTarget setShouldInvalidateAudioSampleWhenDone:YES]; + + readerAudioOutput = [AVAssetReaderAudioMixOutput assetReaderAudioMixOutputWithAudioTracks:audioTracks audioSettings:nil]; + readerAudioOutput.audioMix = self.audioMix; + readerAudioOutput.alwaysCopiesSampleData = NO; + [assetReader addOutput:readerAudioOutput]; + } + + return assetReader; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMultiplyBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageMultiplyBlendFilter.h new file mode 100755 index 00000000..5ebc28bb --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMultiplyBlendFilter.h @@ -0,0 +1,7 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageMultiplyBlendFilter : GPUImageTwoInputFilter +{ +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageMultiplyBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageMultiplyBlendFilter.m new file mode 100755 index 00000000..ed647072 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageMultiplyBlendFilter.m @@ -0,0 +1,52 @@ +#import "GPUImageMultiplyBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageMultiplyBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + lowp vec4 base = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 overlayer = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = overlayer * base + overlayer * (1.0 - base.a) + base * (1.0 - overlayer.a); + } +); +#else +NSString *const kGPUImageMultiplyBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 base = texture2D(inputImageTexture, textureCoordinate); + vec4 overlayer = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = overlayer * base + overlayer * (1.0 - base.a) + base * (1.0 - overlayer.a); + } +); +#endif + +@implementation GPUImageMultiplyBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageMultiplyBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageNobleCornerDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageNobleCornerDetectionFilter.h new file mode 100644 index 00000000..963fd66a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageNobleCornerDetectionFilter.h @@ -0,0 +1,12 @@ +#import "GPUImageHarrisCornerDetectionFilter.h" + +/** Noble corner detector + + This is the Noble variant on the Harris detector, from + Alison Noble, "Descriptions of Image Surfaces", PhD thesis, Department of Engineering Science, Oxford University 1989, p45. +*/ + + +@interface GPUImageNobleCornerDetectionFilter : GPUImageHarrisCornerDetectionFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageNobleCornerDetectionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageNobleCornerDetectionFilter.m new file mode 100644 index 00000000..aa6b3041 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageNobleCornerDetectionFilter.m @@ -0,0 +1,74 @@ +#import "GPUImageNobleCornerDetectionFilter.h" + +@implementation GPUImageNobleCornerDetectionFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageNobleCornerDetectionFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform lowp float sensitivity; + + void main() + { + mediump vec3 derivativeElements = texture2D(inputImageTexture, textureCoordinate).rgb; + + mediump float derivativeSum = derivativeElements.x + derivativeElements.y; + + // R = (Ix^2 * Iy^2 - Ixy * Ixy) / (Ix^2 + Iy^2) + mediump float zElement = (derivativeElements.z * 2.0) - 1.0; + // mediump float harrisIntensity = (derivativeElements.x * derivativeElements.y - (derivativeElements.z * derivativeElements.z)) / (derivativeSum); + mediump float cornerness = (derivativeElements.x * derivativeElements.y - (zElement * zElement)) / (derivativeSum); + + // Original Harris detector + // R = Ix^2 * Iy^2 - Ixy * Ixy - k * (Ix^2 + Iy^2)^2 + // highp float harrisIntensity = derivativeElements.x * derivativeElements.y - (derivativeElements.z * derivativeElements.z) - harrisConstant * derivativeSum * derivativeSum; + + // gl_FragColor = vec4(vec3(harrisIntensity * 7.0), 1.0); + gl_FragColor = vec4(vec3(cornerness * sensitivity), 1.0); + } +); +#else +NSString *const kGPUImageNobleCornerDetectionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float sensitivity; + + void main() + { + vec3 derivativeElements = texture2D(inputImageTexture, textureCoordinate).rgb; + + float derivativeSum = derivativeElements.x + derivativeElements.y; + + // R = (Ix^2 * Iy^2 - Ixy * Ixy) / (Ix^2 + Iy^2) + float zElement = (derivativeElements.z * 2.0) - 1.0; + // mediump float harrisIntensity = (derivativeElements.x * derivativeElements.y - (derivativeElements.z * derivativeElements.z)) / (derivativeSum); + float cornerness = (derivativeElements.x * derivativeElements.y - (zElement * zElement)) / (derivativeSum); + + // Original Harris detector + // R = Ix^2 * Iy^2 - Ixy * Ixy - k * (Ix^2 + Iy^2)^2 + // highp float harrisIntensity = derivativeElements.x * derivativeElements.y - (derivativeElements.z * derivativeElements.z) - harrisConstant * derivativeSum * derivativeSum; + + // gl_FragColor = vec4(vec3(harrisIntensity * 7.0), 1.0); + gl_FragColor = vec4(vec3(cornerness * sensitivity), 1.0); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithCornerDetectionFragmentShader:kGPUImageNobleCornerDetectionFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageNonMaximumSuppressionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageNonMaximumSuppressionFilter.h new file mode 100644 index 00000000..fd8fe6d6 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageNonMaximumSuppressionFilter.h @@ -0,0 +1,5 @@ +#import "GPUImage3x3TextureSamplingFilter.h" + +@interface GPUImageNonMaximumSuppressionFilter : GPUImage3x3TextureSamplingFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageNonMaximumSuppressionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageNonMaximumSuppressionFilter.m new file mode 100644 index 00000000..eaf7ce56 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageNonMaximumSuppressionFilter.m @@ -0,0 +1,107 @@ +#import "GPUImageNonMaximumSuppressionFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageNonMaximumSuppressionFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + varying highp vec2 textureCoordinate; + varying highp vec2 leftTextureCoordinate; + varying highp vec2 rightTextureCoordinate; + + varying highp vec2 topTextureCoordinate; + varying highp vec2 topLeftTextureCoordinate; + varying highp vec2 topRightTextureCoordinate; + + varying highp vec2 bottomTextureCoordinate; + varying highp vec2 bottomLeftTextureCoordinate; + varying highp vec2 bottomRightTextureCoordinate; + + void main() + { + lowp float bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).r; + lowp float bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + lowp float bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + lowp vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); + lowp float leftColor = texture2D(inputImageTexture, leftTextureCoordinate).r; + lowp float rightColor = texture2D(inputImageTexture, rightTextureCoordinate).r; + lowp float topColor = texture2D(inputImageTexture, topTextureCoordinate).r; + lowp float topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).r; + lowp float topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + + // Use a tiebreaker for pixels to the left and immediately above this one + lowp float multiplier = 1.0 - step(centerColor.r, topColor); + multiplier = multiplier * (1.0 - step(centerColor.r, topLeftColor)); + multiplier = multiplier * (1.0 - step(centerColor.r, leftColor)); + multiplier = multiplier * (1.0 - step(centerColor.r, bottomLeftColor)); + + lowp float maxValue = max(centerColor.r, bottomColor); + maxValue = max(maxValue, bottomRightColor); + maxValue = max(maxValue, rightColor); + maxValue = max(maxValue, topRightColor); + + gl_FragColor = vec4((centerColor.rgb * step(maxValue, centerColor.r) * multiplier), 1.0); + } +); +#else +NSString *const kGPUImageNonMaximumSuppressionFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + void main() + { + float bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); + float leftColor = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightColor = texture2D(inputImageTexture, rightTextureCoordinate).r; + float topColor = texture2D(inputImageTexture, topTextureCoordinate).r; + float topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + + // Use a tiebreaker for pixels to the left and immediately above this one + float multiplier = 1.0 - step(centerColor.r, topColor); + multiplier = multiplier * (1.0 - step(centerColor.r, topLeftColor)); + multiplier = multiplier * (1.0 - step(centerColor.r, leftColor)); + multiplier = multiplier * (1.0 - step(centerColor.r, bottomLeftColor)); + + float maxValue = max(centerColor.r, bottomColor); + maxValue = max(maxValue, bottomRightColor); + maxValue = max(maxValue, rightColor); + maxValue = max(maxValue, topRightColor); + + gl_FragColor = vec4((centerColor.rgb * step(maxValue, centerColor.r) * multiplier), 1.0); + } +); +#endif + +@implementation GPUImageNonMaximumSuppressionFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageNonMaximumSuppressionFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageNormalBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageNormalBlendFilter.h new file mode 100644 index 00000000..ce5e22b4 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageNormalBlendFilter.h @@ -0,0 +1,8 @@ +// Created by Jorge Garcia on 9/5/12. +// + +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageNormalBlendFilter : GPUImageTwoInputFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageNormalBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageNormalBlendFilter.m new file mode 100644 index 00000000..f5b5069d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageNormalBlendFilter.m @@ -0,0 +1,96 @@ +// Created by Jorge Garcia on 9/5/12. + +#import "GPUImageNormalBlendFilter.h" +/* + This equation is a simplification of the general blending equation. It assumes the destination color is opaque, and therefore drops the destination color's alpha term. + + D = C1 * C1a + C2 * C2a * (1 - C1a) + where D is the resultant color, C1 is the color of the first element, C1a is the alpha of the first element, C2 is the second element color, C2a is the alpha of the second element. The destination alpha is calculated with: + + Da = C1a + C2a * (1 - C1a) + The resultant color is premultiplied with the alpha. To restore the color to the unmultiplied values, just divide by Da, the resultant alpha. + + http://stackoverflow.com/questions/1724946/blend-mode-on-a-transparent-and-semi-transparent-background + + For some reason Photoshop behaves + D = C1 + C2 * C2a * (1 - C1a) + */ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageNormalBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + lowp vec4 c2 = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 c1 = texture2D(inputImageTexture2, textureCoordinate2); + + lowp vec4 outputColor; + +// outputColor.r = c1.r + c2.r * c2.a * (1.0 - c1.a); +// outputColor.g = c1.g + c2.g * c2.a * (1.0 - c1.a); +// outputColor.b = c1.b + c2.b * c2.a * (1.0 - c1.a); +// outputColor.a = c1.a + c2.a * (1.0 - c1.a); + + lowp float a = c1.a + c2.a * (1.0 - c1.a); + lowp float alphaDivisor = a + step(a, 0.0); // Protect against a divide-by-zero blacking out things in the output + + outputColor.r = (c1.r * c1.a + c2.r * c2.a * (1.0 - c1.a))/alphaDivisor; + outputColor.g = (c1.g * c1.a + c2.g * c2.a * (1.0 - c1.a))/alphaDivisor; + outputColor.b = (c1.b * c1.a + c2.b * c2.a * (1.0 - c1.a))/alphaDivisor; + outputColor.a = a; + + gl_FragColor = outputColor; + } +); +#else +NSString *const kGPUImageNormalBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 c2 = texture2D(inputImageTexture, textureCoordinate); + vec4 c1 = texture2D(inputImageTexture2, textureCoordinate2); + + vec4 outputColor; + + // outputColor.r = c1.r + c2.r * c2.a * (1.0 - c1.a); + // outputColor.g = c1.g + c2.g * c2.a * (1.0 - c1.a); + // outputColor.b = c1.b + c2.b * c2.a * (1.0 - c1.a); + // outputColor.a = c1.a + c2.a * (1.0 - c1.a); + + float a = c1.a + c2.a * (1.0 - c1.a); + float alphaDivisor = a + step(a, 0.0); // Protect against a divide-by-zero blacking out things in the output + + outputColor.r = (c1.r * c1.a + c2.r * c2.a * (1.0 - c1.a))/alphaDivisor; + outputColor.g = (c1.g * c1.a + c2.g * c2.a * (1.0 - c1.a))/alphaDivisor; + outputColor.b = (c1.b * c1.a + c2.b * c2.a * (1.0 - c1.a))/alphaDivisor; + outputColor.a = a; + + gl_FragColor = outputColor; + } +); +#endif + +@implementation GPUImageNormalBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageNormalBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageOpacityFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageOpacityFilter.h new file mode 100644 index 00000000..826749fb --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageOpacityFilter.h @@ -0,0 +1,11 @@ +#import "GPUImageFilter.h" + +@interface GPUImageOpacityFilter : GPUImageFilter +{ + GLint opacityUniform; +} + +// Opacity ranges from 0.0 to 1.0, with 1.0 as the normal setting +@property(readwrite, nonatomic) CGFloat opacity; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageOpacityFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageOpacityFilter.m new file mode 100644 index 00000000..b74acb60 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageOpacityFilter.m @@ -0,0 +1,65 @@ +#import "GPUImageOpacityFilter.h" + +@implementation GPUImageOpacityFilter + +@synthesize opacity = _opacity; + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageOpacityFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform lowp float opacity; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4(textureColor.rgb, textureColor.a * opacity); + } +); +#else +NSString *const kGPUImageOpacityFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float opacity; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4(textureColor.rgb, textureColor.a * opacity); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageOpacityFragmentShaderString])) + { + return nil; + } + + opacityUniform = [filterProgram uniformIndex:@"opacity"]; + self.opacity = 1.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setOpacity:(CGFloat)newValue; +{ + _opacity = newValue; + + [self setFloat:_opacity forUniform:opacityUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageOpeningFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageOpeningFilter.h new file mode 100644 index 00000000..3e4f7545 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageOpeningFilter.h @@ -0,0 +1,19 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImageErosionFilter; +@class GPUImageDilationFilter; + +// A filter that first performs an erosion on the red channel of an image, followed by a dilation of the same radius. +// This helps to filter out smaller bright elements. + +@interface GPUImageOpeningFilter : GPUImageFilterGroup +{ + GPUImageErosionFilter *erosionFilter; + GPUImageDilationFilter *dilationFilter; +} + +@property(readwrite, nonatomic) CGFloat verticalTexelSpacing, horizontalTexelSpacing; + +- (id)initWithRadius:(NSUInteger)radius; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageOpeningFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageOpeningFilter.m new file mode 100644 index 00000000..4e7a5653 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageOpeningFilter.m @@ -0,0 +1,57 @@ +#import "GPUImageOpeningFilter.h" +#import "GPUImageErosionFilter.h" +#import "GPUImageDilationFilter.h" + +@implementation GPUImageOpeningFilter + +@synthesize verticalTexelSpacing = _verticalTexelSpacing; +@synthesize horizontalTexelSpacing = _horizontalTexelSpacing; + +- (id)init; +{ + if (!(self = [self initWithRadius:1])) + { + return nil; + } + + return self; +} + +- (id)initWithRadius:(NSUInteger)radius; +{ + if (!(self = [super init])) + { + return nil; + } + + // First pass: erosion + erosionFilter = [[GPUImageErosionFilter alloc] initWithRadius:radius]; + [self addFilter:erosionFilter]; + + // Second pass: dilation + dilationFilter = [[GPUImageDilationFilter alloc] initWithRadius:radius]; + [self addFilter:dilationFilter]; + + [erosionFilter addTarget:dilationFilter]; + + self.initialFilters = [NSArray arrayWithObjects:erosionFilter, nil]; + self.terminalFilter = dilationFilter; + + return self; +} + +- (void)setVerticalTexelSpacing:(CGFloat)newValue; +{ + _verticalTexelSpacing = newValue; + erosionFilter.verticalTexelSpacing = newValue; + dilationFilter.verticalTexelSpacing = newValue; +} + +- (void)setHorizontalTexelSpacing:(CGFloat)newValue; +{ + _horizontalTexelSpacing = newValue; + erosionFilter.horizontalTexelSpacing = newValue; + dilationFilter.horizontalTexelSpacing = newValue; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageOutput.h b/LFLiveKit/Vendor/GPUImage/GPUImageOutput.h new file mode 100755 index 00000000..c10121a9 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageOutput.h @@ -0,0 +1,128 @@ +#import "GPUImageContext.h" +#import "GPUImageFramebuffer.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +#import +#else +// For now, just redefine this on the Mac +typedef NS_ENUM(NSInteger, UIImageOrientation) { + UIImageOrientationUp, // default orientation + UIImageOrientationDown, // 180 deg rotation + UIImageOrientationLeft, // 90 deg CCW + UIImageOrientationRight, // 90 deg CW + UIImageOrientationUpMirrored, // as above but image mirrored along other axis. horizontal flip + UIImageOrientationDownMirrored, // horizontal flip + UIImageOrientationLeftMirrored, // vertical flip + UIImageOrientationRightMirrored, // vertical flip +}; +#endif + +dispatch_queue_attr_t GPUImageDefaultQueueAttribute(void); +void runOnMainQueueWithoutDeadlocking(void (^block)(void)); +void runSynchronouslyOnVideoProcessingQueue(void (^block)(void)); +void runAsynchronouslyOnVideoProcessingQueue(void (^block)(void)); +void runSynchronouslyOnContextQueue(GPUImageContext *context, void (^block)(void)); +void runAsynchronouslyOnContextQueue(GPUImageContext *context, void (^block)(void)); +void reportAvailableMemoryForGPUImage(NSString *tag); + +@class GPUImageMovieWriter; + +/** GPUImage's base source object + + Images or frames of video are uploaded from source objects, which are subclasses of GPUImageOutput. These include: + + - GPUImageVideoCamera (for live video from an iOS camera) + - GPUImageStillCamera (for taking photos with the camera) + - GPUImagePicture (for still images) + - GPUImageMovie (for movies) + + Source objects upload still image frames to OpenGL ES as textures, then hand those textures off to the next objects in the processing chain. + */ +@interface GPUImageOutput : NSObject +{ + GPUImageFramebuffer *outputFramebuffer; + + NSMutableArray *targets, *targetTextureIndices; + + CGSize inputTextureSize, cachedMaximumOutputSize, forcedMaximumSize; + + BOOL overrideInputSize; + + BOOL allTargetsWantMonochromeData; + BOOL usingNextFrameForImageCapture; +} + +@property(readwrite, nonatomic) BOOL shouldSmoothlyScaleOutput; +@property(readwrite, nonatomic) BOOL shouldIgnoreUpdatesToThisTarget; +@property(readwrite, nonatomic, retain) GPUImageMovieWriter *audioEncodingTarget; +@property(readwrite, nonatomic, unsafe_unretained) id targetToIgnoreForUpdates; +@property(nonatomic, copy) void(^frameProcessingCompletionBlock)(GPUImageOutput*, CMTime); +@property(nonatomic) BOOL enabled; +@property(readwrite, nonatomic) GPUTextureOptions outputTextureOptions; + +/// @name Managing targets +- (void)setInputFramebufferForTarget:(id)target atIndex:(NSInteger)inputTextureIndex; +- (GPUImageFramebuffer *)framebufferForOutput; +- (void)removeOutputFramebuffer; +- (void)notifyTargetsAboutNewOutputTexture; + +/** Returns an array of the current targets. + */ +- (NSArray*)targets; + +/** Adds a target to receive notifications when new frames are available. + + The target will be asked for its next available texture. + + See [GPUImageInput newFrameReadyAtTime:] + + @param newTarget Target to be added + */ +- (void)addTarget:(id)newTarget; + +/** Adds a target to receive notifications when new frames are available. + + See [GPUImageInput newFrameReadyAtTime:] + + @param newTarget Target to be added + */ +- (void)addTarget:(id)newTarget atTextureLocation:(NSInteger)textureLocation; + +/** Removes a target. The target will no longer receive notifications when new frames are available. + + @param targetToRemove Target to be removed + */ +- (void)removeTarget:(id)targetToRemove; + +/** Removes all targets. + */ +- (void)removeAllTargets; + +/// @name Manage the output texture + +- (void)forceProcessingAtSize:(CGSize)frameSize; +- (void)forceProcessingAtSizeRespectingAspectRatio:(CGSize)frameSize; + +/// @name Still image processing + +- (void)useNextFrameForImageCapture; +- (CGImageRef)newCGImageFromCurrentlyProcessedOutput; +- (CGImageRef)newCGImageByFilteringCGImage:(CGImageRef)imageToFilter; + +// Platform-specific image output methods +// If you're trying to use these methods, remember that you need to set -useNextFrameForImageCapture before running -processImage or running video and calling any of these methods, or you will get a nil image +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +- (UIImage *)imageFromCurrentFramebuffer; +- (UIImage *)imageFromCurrentFramebufferWithOrientation:(UIImageOrientation)imageOrientation; +- (UIImage *)imageByFilteringImage:(UIImage *)imageToFilter; +- (CGImageRef)newCGImageByFilteringImage:(UIImage *)imageToFilter; +#else +- (NSImage *)imageFromCurrentFramebuffer; +- (NSImage *)imageFromCurrentFramebufferWithOrientation:(UIImageOrientation)imageOrientation; +- (NSImage *)imageByFilteringImage:(NSImage *)imageToFilter; +- (CGImageRef)newCGImageByFilteringImage:(NSImage *)imageToFilter; +#endif + +- (BOOL)providesMonochromeOutput; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageOutput.m b/LFLiveKit/Vendor/GPUImage/GPUImageOutput.m new file mode 100755 index 00000000..d9bdaefa --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageOutput.m @@ -0,0 +1,439 @@ +#import "GPUImageOutput.h" +#import "GPUImageMovieWriter.h" +#import "GPUImagePicture.h" +#import + +dispatch_queue_attr_t GPUImageDefaultQueueAttribute(void) +{ +#if TARGET_OS_IPHONE + if ([[[UIDevice currentDevice] systemVersion] compare:@"9.0" options:NSNumericSearch] != NSOrderedAscending) + { + return dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0); + } +#endif + return nil; +} + +void runOnMainQueueWithoutDeadlocking(void (^block)(void)) +{ + if ([NSThread isMainThread]) + { + block(); + } + else + { + dispatch_sync(dispatch_get_main_queue(), block); + } +} + +void runSynchronouslyOnVideoProcessingQueue(void (^block)(void)) +{ + dispatch_queue_t videoProcessingQueue = [GPUImageContext sharedContextQueue]; +#if !OS_OBJECT_USE_OBJC +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + if (dispatch_get_current_queue() == videoProcessingQueue) +#pragma clang diagnostic pop +#else + if (dispatch_get_specific([GPUImageContext contextKey])) +#endif + { + block(); + }else + { + dispatch_sync(videoProcessingQueue, block); + } +} + +void runAsynchronouslyOnVideoProcessingQueue(void (^block)(void)) +{ + dispatch_queue_t videoProcessingQueue = [GPUImageContext sharedContextQueue]; + +#if !OS_OBJECT_USE_OBJC +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + if (dispatch_get_current_queue() == videoProcessingQueue) +#pragma clang diagnostic pop +#else + if (dispatch_get_specific([GPUImageContext contextKey])) +#endif + { + block(); + }else + { + dispatch_async(videoProcessingQueue, block); + } +} + +void runSynchronouslyOnContextQueue(GPUImageContext *context, void (^block)(void)) +{ + dispatch_queue_t videoProcessingQueue = [context contextQueue]; +#if !OS_OBJECT_USE_OBJC +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + if (dispatch_get_current_queue() == videoProcessingQueue) +#pragma clang diagnostic pop +#else + if (dispatch_get_specific([GPUImageContext contextKey])) +#endif + { + block(); + }else + { + dispatch_sync(videoProcessingQueue, block); + } +} + +void runAsynchronouslyOnContextQueue(GPUImageContext *context, void (^block)(void)) +{ + dispatch_queue_t videoProcessingQueue = [context contextQueue]; + +#if !OS_OBJECT_USE_OBJC +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + if (dispatch_get_current_queue() == videoProcessingQueue) +#pragma clang diagnostic pop +#else + if (dispatch_get_specific([GPUImageContext contextKey])) +#endif + { + block(); + }else + { + dispatch_async(videoProcessingQueue, block); + } +} + +void reportAvailableMemoryForGPUImage(NSString *tag) +{ + if (!tag) + tag = @"Default"; + + struct task_basic_info info; + + mach_msg_type_number_t size = sizeof(info); + + kern_return_t kerr = task_info(mach_task_self(), + + TASK_BASIC_INFO, + + (task_info_t)&info, + + &size); + if( kerr == KERN_SUCCESS ) { + NSLog(@"%@ - Memory used: %u", tag, (unsigned int)info.resident_size); //in bytes + } else { + NSLog(@"%@ - Error: %s", tag, mach_error_string(kerr)); + } +} + +@implementation GPUImageOutput + +@synthesize shouldSmoothlyScaleOutput = _shouldSmoothlyScaleOutput; +@synthesize shouldIgnoreUpdatesToThisTarget = _shouldIgnoreUpdatesToThisTarget; +@synthesize audioEncodingTarget = _audioEncodingTarget; +@synthesize targetToIgnoreForUpdates = _targetToIgnoreForUpdates; +@synthesize frameProcessingCompletionBlock = _frameProcessingCompletionBlock; +@synthesize enabled = _enabled; +@synthesize outputTextureOptions = _outputTextureOptions; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + targets = [[NSMutableArray alloc] init]; + targetTextureIndices = [[NSMutableArray alloc] init]; + _enabled = YES; + allTargetsWantMonochromeData = YES; + usingNextFrameForImageCapture = NO; + + // set default texture options + _outputTextureOptions.minFilter = GL_LINEAR; + _outputTextureOptions.magFilter = GL_LINEAR; + _outputTextureOptions.wrapS = GL_CLAMP_TO_EDGE; + _outputTextureOptions.wrapT = GL_CLAMP_TO_EDGE; + _outputTextureOptions.internalFormat = GL_RGBA; + _outputTextureOptions.format = GL_BGRA; + _outputTextureOptions.type = GL_UNSIGNED_BYTE; + + return self; +} + +- (void)dealloc +{ + [self removeAllTargets]; +} + +#pragma mark - +#pragma mark Managing targets + +- (void)setInputFramebufferForTarget:(id)target atIndex:(NSInteger)inputTextureIndex; +{ + [target setInputFramebuffer:[self framebufferForOutput] atIndex:inputTextureIndex]; +} + +- (GPUImageFramebuffer *)framebufferForOutput; +{ + return outputFramebuffer; +} + +- (void)removeOutputFramebuffer; +{ + outputFramebuffer = nil; +} + +- (void)notifyTargetsAboutNewOutputTexture; +{ + for (id currentTarget in targets) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger textureIndex = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + [self setInputFramebufferForTarget:currentTarget atIndex:textureIndex]; + } +} + +- (NSArray*)targets; +{ + return [NSArray arrayWithArray:targets]; +} + +- (void)addTarget:(id)newTarget; +{ + NSInteger nextAvailableTextureIndex = [newTarget nextAvailableTextureIndex]; + [self addTarget:newTarget atTextureLocation:nextAvailableTextureIndex]; + + if ([newTarget shouldIgnoreUpdatesToThisTarget]) + { + _targetToIgnoreForUpdates = newTarget; + } +} + +- (void)addTarget:(id)newTarget atTextureLocation:(NSInteger)textureLocation; +{ + if([targets containsObject:newTarget]) + { + return; + } + + cachedMaximumOutputSize = CGSizeZero; + runSynchronouslyOnVideoProcessingQueue(^{ + [self setInputFramebufferForTarget:newTarget atIndex:textureLocation]; + [targets addObject:newTarget]; + [targetTextureIndices addObject:[NSNumber numberWithInteger:textureLocation]]; + + allTargetsWantMonochromeData = allTargetsWantMonochromeData && [newTarget wantsMonochromeInput]; + }); +} + +- (void)removeTarget:(id)targetToRemove; +{ + if(![targets containsObject:targetToRemove]) + { + return; + } + + if (_targetToIgnoreForUpdates == targetToRemove) + { + _targetToIgnoreForUpdates = nil; + } + + cachedMaximumOutputSize = CGSizeZero; + + NSInteger indexOfObject = [targets indexOfObject:targetToRemove]; + NSInteger textureIndexOfTarget = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + runSynchronouslyOnVideoProcessingQueue(^{ + [targetToRemove setInputSize:CGSizeZero atIndex:textureIndexOfTarget]; + [targetToRemove setInputRotation:kGPUImageNoRotation atIndex:textureIndexOfTarget]; + + [targetTextureIndices removeObjectAtIndex:indexOfObject]; + [targets removeObject:targetToRemove]; + [targetToRemove endProcessing]; + }); +} + +- (void)removeAllTargets; +{ + cachedMaximumOutputSize = CGSizeZero; + runSynchronouslyOnVideoProcessingQueue(^{ + for (id targetToRemove in targets) + { + NSInteger indexOfObject = [targets indexOfObject:targetToRemove]; + NSInteger textureIndexOfTarget = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + [targetToRemove setInputSize:CGSizeZero atIndex:textureIndexOfTarget]; + [targetToRemove setInputRotation:kGPUImageNoRotation atIndex:textureIndexOfTarget]; + } + [targets removeAllObjects]; + [targetTextureIndices removeAllObjects]; + + allTargetsWantMonochromeData = YES; + }); +} + +#pragma mark - +#pragma mark Manage the output texture + +- (void)forceProcessingAtSize:(CGSize)frameSize; +{ + +} + +- (void)forceProcessingAtSizeRespectingAspectRatio:(CGSize)frameSize; +{ +} + +#pragma mark - +#pragma mark Still image processing + +- (void)useNextFrameForImageCapture; +{ + +} + +- (CGImageRef)newCGImageFromCurrentlyProcessedOutput; +{ + return nil; +} + +- (CGImageRef)newCGImageByFilteringCGImage:(CGImageRef)imageToFilter; +{ + GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithCGImage:imageToFilter]; + + [self useNextFrameForImageCapture]; + [stillImageSource addTarget:(id)self]; + [stillImageSource processImage]; + + CGImageRef processedImage = [self newCGImageFromCurrentlyProcessedOutput]; + + [stillImageSource removeTarget:(id)self]; + return processedImage; +} + +- (BOOL)providesMonochromeOutput; +{ + return NO; +} + +#pragma mark - +#pragma mark Platform-specific image output methods + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + +- (UIImage *)imageFromCurrentFramebuffer; +{ + UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation]; + UIImageOrientation imageOrientation = UIImageOrientationLeft; + switch (deviceOrientation) + { + case UIDeviceOrientationPortrait: + imageOrientation = UIImageOrientationUp; + break; + case UIDeviceOrientationPortraitUpsideDown: + imageOrientation = UIImageOrientationDown; + break; + case UIDeviceOrientationLandscapeLeft: + imageOrientation = UIImageOrientationLeft; + break; + case UIDeviceOrientationLandscapeRight: + imageOrientation = UIImageOrientationRight; + break; + default: + imageOrientation = UIImageOrientationUp; + break; + } + + return [self imageFromCurrentFramebufferWithOrientation:imageOrientation]; +} + +- (UIImage *)imageFromCurrentFramebufferWithOrientation:(UIImageOrientation)imageOrientation; +{ + CGImageRef cgImageFromBytes = [self newCGImageFromCurrentlyProcessedOutput]; + UIImage *finalImage = [UIImage imageWithCGImage:cgImageFromBytes scale:1.0 orientation:imageOrientation]; + CGImageRelease(cgImageFromBytes); + + return finalImage; +} + +- (UIImage *)imageByFilteringImage:(UIImage *)imageToFilter; +{ + CGImageRef image = [self newCGImageByFilteringCGImage:[imageToFilter CGImage]]; + UIImage *processedImage = [UIImage imageWithCGImage:image scale:[imageToFilter scale] orientation:[imageToFilter imageOrientation]]; + CGImageRelease(image); + return processedImage; +} + +- (CGImageRef)newCGImageByFilteringImage:(UIImage *)imageToFilter +{ + return [self newCGImageByFilteringCGImage:[imageToFilter CGImage]]; +} + +#else + +- (NSImage *)imageFromCurrentFramebuffer; +{ + return [self imageFromCurrentFramebufferWithOrientation:UIImageOrientationLeft]; +} + +- (NSImage *)imageFromCurrentFramebufferWithOrientation:(UIImageOrientation)imageOrientation; +{ + CGImageRef cgImageFromBytes = [self newCGImageFromCurrentlyProcessedOutput]; + NSImage *finalImage = [[NSImage alloc] initWithCGImage:cgImageFromBytes size:NSZeroSize]; + CGImageRelease(cgImageFromBytes); + + return finalImage; +} + +- (NSImage *)imageByFilteringImage:(NSImage *)imageToFilter; +{ + CGImageRef image = [self newCGImageByFilteringCGImage:[imageToFilter CGImageForProposedRect:NULL context:[NSGraphicsContext currentContext] hints:nil]]; + NSImage *processedImage = [[NSImage alloc] initWithCGImage:image size:NSZeroSize]; + CGImageRelease(image); + return processedImage; +} + +- (CGImageRef)newCGImageByFilteringImage:(NSImage *)imageToFilter +{ + return [self newCGImageByFilteringCGImage:[imageToFilter CGImageForProposedRect:NULL context:[NSGraphicsContext currentContext] hints:nil]]; +} + +#endif + +#pragma mark - +#pragma mark Accessors + +- (void)setAudioEncodingTarget:(GPUImageMovieWriter *)newValue; +{ + _audioEncodingTarget = newValue; + if( ! _audioEncodingTarget.hasAudioTrack ) + { + _audioEncodingTarget.hasAudioTrack = YES; + } +} + +-(void)setOutputTextureOptions:(GPUTextureOptions)outputTextureOptions +{ + _outputTextureOptions = outputTextureOptions; + + if( outputFramebuffer.texture ) + { + glBindTexture(GL_TEXTURE_2D, outputFramebuffer.texture); + //_outputTextureOptions.format + //_outputTextureOptions.internalFormat + //_outputTextureOptions.magFilter + //_outputTextureOptions.minFilter + //_outputTextureOptions.type + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, _outputTextureOptions.wrapS); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, _outputTextureOptions.wrapT); + glBindTexture(GL_TEXTURE_2D, 0); + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageOverlayBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageOverlayBlendFilter.h new file mode 100755 index 00000000..57eb8402 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageOverlayBlendFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageOverlayBlendFilter : GPUImageTwoInputFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageOverlayBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageOverlayBlendFilter.m new file mode 100755 index 00000000..c8c5185d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageOverlayBlendFilter.m @@ -0,0 +1,94 @@ +#import "GPUImageOverlayBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageOverlayBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + mediump vec4 base = texture2D(inputImageTexture, textureCoordinate); + mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + mediump float ra; + if (2.0 * base.r < base.a) { + ra = 2.0 * overlay.r * base.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + } else { + ra = overlay.a * base.a - 2.0 * (base.a - base.r) * (overlay.a - overlay.r) + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + } + + mediump float ga; + if (2.0 * base.g < base.a) { + ga = 2.0 * overlay.g * base.g + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + } else { + ga = overlay.a * base.a - 2.0 * (base.a - base.g) * (overlay.a - overlay.g) + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + } + + mediump float ba; + if (2.0 * base.b < base.a) { + ba = 2.0 * overlay.b * base.b + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + } else { + ba = overlay.a * base.a - 2.0 * (base.a - base.b) * (overlay.a - overlay.b) + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + } + + gl_FragColor = vec4(ra, ga, ba, 1.0); + } +); +#else +NSString *const kGPUImageOverlayBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 base = texture2D(inputImageTexture, textureCoordinate); + vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + float ra; + if (2.0 * base.r < base.a) { + ra = 2.0 * overlay.r * base.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + } else { + ra = overlay.a * base.a - 2.0 * (base.a - base.r) * (overlay.a - overlay.r) + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a); + } + + float ga; + if (2.0 * base.g < base.a) { + ga = 2.0 * overlay.g * base.g + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + } else { + ga = overlay.a * base.a - 2.0 * (base.a - base.g) * (overlay.a - overlay.g) + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a); + } + + float ba; + if (2.0 * base.b < base.a) { + ba = 2.0 * overlay.b * base.b + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + } else { + ba = overlay.a * base.a - 2.0 * (base.a - base.b) * (overlay.a - overlay.b) + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a); + } + + gl_FragColor = vec4(ra, ga, ba, 1.0); + } +); +#endif + +@implementation GPUImageOverlayBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageOverlayBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageParallelCoordinateLineTransformFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageParallelCoordinateLineTransformFilter.h new file mode 100644 index 00000000..aa8f3f47 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageParallelCoordinateLineTransformFilter.h @@ -0,0 +1,16 @@ +#import "GPUImageFilter.h" + +// This is an accumulator that uses a Hough transform in parallel coordinate space to identify probable lines in a scene. +// +// It is entirely based on the work of the Graph@FIT research group at the Brno University of Technology and their publications: +// M. Dubská, J. Havel, and A. Herout. Real-Time Detection of Lines using Parallel Coordinates and OpenGL. Proceedings of SCCG 2011, Bratislava, SK, p. 7. +// M. Dubská, J. Havel, and A. Herout. PClines — Line detection using parallel coordinates. 2011 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), p. 1489- 1494. + +@interface GPUImageParallelCoordinateLineTransformFilter : GPUImageFilter +{ + GLubyte *rawImagePixels; + GLfloat *lineCoordinates; + unsigned int maxLinePairsToRender, linePairsToRender; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageParallelCoordinateLineTransformFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageParallelCoordinateLineTransformFilter.m new file mode 100644 index 00000000..0a2f6e49 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageParallelCoordinateLineTransformFilter.m @@ -0,0 +1,266 @@ +#import "GPUImageParallelCoordinateLineTransformFilter.h" + +NSString *const kGPUImageHoughAccumulationVertexShaderString = SHADER_STRING +( + attribute vec4 position; + + void main() + { + gl_Position = position; + } +); + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageHoughAccumulationFragmentShaderString = SHADER_STRING +( + const lowp float scalingFactor = 1.0 / 256.0; + + void main() + { + gl_FragColor = vec4(0.004, 0.004, 0.004, 1.0); + } +); + +// highp - 16-bit, floating point range: -2^62 to 2^62, integer range: -2^16 to 2^16 +// NOTE: See below for where I'm tacking on the required extension as a prefix +NSString *const kGPUImageHoughAccumulationFBOReadFragmentShaderString = SHADER_STRING +( + const lowp float scalingFactor = 0.004; +// const lowp float scalingFactor = 0.1; + + void main() + { + mediump vec4 fragmentData = gl_LastFragData[0]; + + fragmentData.r = fragmentData.r + scalingFactor; + fragmentData.g = scalingFactor * floor(fragmentData.r) + fragmentData.g; + fragmentData.b = scalingFactor * floor(fragmentData.g) + fragmentData.b; + fragmentData.a = scalingFactor * floor(fragmentData.b) + fragmentData.a; + + fragmentData = fract(fragmentData); + + gl_FragColor = vec4(fragmentData.rgb, 1.0); + } +); + +#else +NSString *const kGPUImageHoughAccumulationFragmentShaderString = SHADER_STRING +( + const float scalingFactor = 1.0 / 256.0; + + void main() + { + gl_FragColor = vec4(0.004, 0.004, 0.004, 1.0); + } +); + +NSString *const kGPUImageHoughAccumulationFBOReadFragmentShaderString = SHADER_STRING +( + const float scalingFactor = 1.0 / 256.0; + + void main() + { + // gl_FragColor = vec4(scalingFactor, scalingFactor, scalingFactor, 1.0); + gl_FragColor = vec4(0.004, 0.004, 0.004, 1.0); + } +); +#endif + +@interface GPUImageParallelCoordinateLineTransformFilter() +// Rendering +- (void)generateLineCoordinates; + +@end + +@implementation GPUImageParallelCoordinateLineTransformFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + NSString *fragmentShaderToUse = nil; + + if ([GPUImageContext deviceSupportsFramebufferReads]) + { + fragmentShaderToUse = [NSString stringWithFormat:@"#extension GL_EXT_shader_framebuffer_fetch : require\n %@",kGPUImageHoughAccumulationFBOReadFragmentShaderString]; + } + else + { + fragmentShaderToUse = kGPUImageHoughAccumulationFragmentShaderString; + } + + if (!(self = [super initWithVertexShaderFromString:kGPUImageHoughAccumulationVertexShaderString fragmentShaderFromString:fragmentShaderToUse])) + { + return nil; + } + + + return self; +} + +// TODO: have this be regenerated on change of image size +- (void)dealloc; +{ + free(rawImagePixels); + free(lineCoordinates); +} + +- (void)initializeAttributes; +{ + [filterProgram addAttribute:@"position"]; +} + +#pragma mark - +#pragma mark Rendering + +#define MAXLINESCALINGFACTOR 4 + +- (void)generateLineCoordinates; +{ + unsigned int imageByteSize = inputTextureSize.width * inputTextureSize.height * 4; + rawImagePixels = (GLubyte *)malloc(imageByteSize); + + maxLinePairsToRender = (inputTextureSize.width * inputTextureSize.height) / MAXLINESCALINGFACTOR; + lineCoordinates = calloc(maxLinePairsToRender * 8, sizeof(GLfloat)); +} + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + if (lineCoordinates == NULL) + { + [self generateLineCoordinates]; + } + + [self renderToTextureWithVertices:NULL textureCoordinates:NULL]; + + [self informTargetsAboutNewFrameAtTime:frameTime]; +} + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + // we need a normal color texture for this filter + NSAssert(self.outputTextureOptions.internalFormat == GL_RGBA, @"The output texture format for this filter must be GL_RGBA."); + NSAssert(self.outputTextureOptions.type == GL_UNSIGNED_BYTE, @"The type of the output texture of this filter must be GL_UNSIGNED_BYTE."); + + if (self.preventRendering) + { + [firstInputFramebuffer unlock]; + return; + } + + // Grab the edge points from the previous frame and create the parallel coordinate lines for them + // This would be a great place to have a working histogram pyramid implementation + + [GPUImageContext useImageProcessingContext]; + [firstInputFramebuffer activateFramebuffer]; + + glFinish(); + glReadPixels(0, 0, inputTextureSize.width, inputTextureSize.height, GL_RGBA, GL_UNSIGNED_BYTE, rawImagePixels); + + CGFloat xAspectMultiplier = 1.0, yAspectMultiplier = 1.0; + +// if (inputTextureSize.width > inputTextureSize.height) +// { +// yAspectMultiplier = inputTextureSize.height / inputTextureSize.width; +// } +// else +// { +// xAspectMultiplier = inputTextureSize.width / inputTextureSize.height; +// } + +// CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); + + unsigned int imageByteSize = inputTextureSize.width * inputTextureSize.height * 4; + unsigned int imageWidth = inputTextureSize.width * 4; + + linePairsToRender = 0; + unsigned int currentByte = 0; + unsigned int lineStorageIndex = 0; + unsigned int maxLineStorageIndex = maxLinePairsToRender * 8 - 8; + + GLfloat minY = 100, maxY = -100, minX = 100, maxX = -100; + while (currentByte < imageByteSize) + { + GLubyte colorByte = rawImagePixels[currentByte]; + + if (colorByte > 0) + { + unsigned int xCoordinate = currentByte % imageWidth; + unsigned int yCoordinate = currentByte / imageWidth; + + CGFloat normalizedXCoordinate = (-1.0 + 2.0 * (CGFloat)(xCoordinate / 4) / inputTextureSize.width) * xAspectMultiplier; + CGFloat normalizedYCoordinate = (-1.0 + 2.0 * (CGFloat)(yCoordinate) / inputTextureSize.height) * yAspectMultiplier; + + minY = MIN(minY, normalizedYCoordinate); + maxY = MAX(maxY, normalizedYCoordinate); + minX = MIN(minX, normalizedXCoordinate); + maxX = MAX(maxX, normalizedXCoordinate); + +// NSLog(@"Parallel line coordinates: (%f, %f) - (%f, %f) - (%f, %f)", -1.0, -normalizedYCoordinate, 0.0, normalizedXCoordinate, 1.0, normalizedYCoordinate); + // T space coordinates, (-d, -y) to (0, x) + lineCoordinates[lineStorageIndex++] = -1.0; + lineCoordinates[lineStorageIndex++] = -normalizedYCoordinate; + lineCoordinates[lineStorageIndex++] = 0.0; + lineCoordinates[lineStorageIndex++] = normalizedXCoordinate; + + // S space coordinates, (0, x) to (d, y) + lineCoordinates[lineStorageIndex++] = 0.0; + lineCoordinates[lineStorageIndex++] = normalizedXCoordinate; + lineCoordinates[lineStorageIndex++] = 1.0; + lineCoordinates[lineStorageIndex++] = normalizedYCoordinate; + + linePairsToRender++; + + linePairsToRender = MIN(linePairsToRender, maxLinePairsToRender); + lineStorageIndex = MIN(lineStorageIndex, maxLineStorageIndex); + } + currentByte +=8; + } + +// NSLog(@"Line pairs to render: %d out of max: %d", linePairsToRender, maxLinePairsToRender); + +// CFAbsoluteTime currentFrameTime = (CFAbsoluteTimeGetCurrent() - startTime); +// NSLog(@"Line generation processing time : %f ms", 1000.0 * currentFrameTime); + + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + + if (usingNextFrameForImageCapture) + { + [outputFramebuffer lock]; + } + + [GPUImageContext setActiveShaderProgram:filterProgram]; + [self setUniformsForProgramAtIndex:0]; + + glClearColor(0.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + + if (![GPUImageContext deviceSupportsFramebufferReads]) + { + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_ONE, GL_ONE); + glEnable(GL_BLEND); + } + else + { + } + + glLineWidth(1); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, lineCoordinates); + glDrawArrays(GL_LINES, 0, (linePairsToRender * 4)); + + if (![GPUImageContext deviceSupportsFramebufferReads]) + { + glDisable(GL_BLEND); + } + [firstInputFramebuffer unlock]; + if (usingNextFrameForImageCapture) + { + dispatch_semaphore_signal(imageCaptureSemaphore); + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePerlinNoiseFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePerlinNoiseFilter.h new file mode 100644 index 00000000..922f4d30 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePerlinNoiseFilter.h @@ -0,0 +1,13 @@ +#import "GPUImageFilter.h" + +@interface GPUImagePerlinNoiseFilter : GPUImageFilter +{ + GLint scaleUniform, colorStartUniform, colorFinishUniform; +} + +@property (readwrite, nonatomic) GPUVector4 colorStart; +@property (readwrite, nonatomic) GPUVector4 colorFinish; + +@property (readwrite, nonatomic) float scale; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePerlinNoiseFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImagePerlinNoiseFilter.m new file mode 100644 index 00000000..9ca7cbad --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePerlinNoiseFilter.m @@ -0,0 +1,239 @@ +#import "GPUImagePerlinNoiseFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImagePerlinNoiseFragmentShaderString = SHADER_STRING +( + precision highp float; + varying highp vec2 textureCoordinate; + uniform float scale; + + uniform vec4 colorStart; + uniform vec4 colorFinish; + + // + // Description : Array and textureless GLSL 2D/3D/4D simplex + // noise functions. + // Author : Ian McEwan, Ashima Arts. + // Maintainer : ijm + // Lastmod : 20110822 (ijm) + // License : Copyright (C) 2011 Ashima Arts. All rights reserved. + // Distributed under the MIT License. See LICENSE file. + // https://github.com/ashima/webgl-noise + // + + vec4 mod289(vec4 x) +{ + return x - floor(x * (1.0 / 289.0)) * 289.0; +} + + vec4 permute(vec4 x) +{ + return mod289(((x*34.0)+1.0)*x); +} + + vec4 taylorInvSqrt(vec4 r) +{ + return 1.79284291400159 - 0.85373472095314 * r; +} + + vec2 fade(vec2 t) { + return t*t*t*(t*(t*6.0-15.0)+10.0); + } + + // Classic Perlin noise + float cnoise(vec2 P) +{ + vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0); + vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0); + Pi = mod289(Pi); // To avoid truncation effects in permutation + vec4 ix = Pi.xzxz; + vec4 iy = Pi.yyww; + vec4 fx = Pf.xzxz; + vec4 fy = Pf.yyww; + + vec4 i = permute(permute(ix) + iy); + + vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ; + vec4 gy = abs(gx) - 0.5 ; + vec4 tx = floor(gx + 0.5); + gx = gx - tx; + + vec2 g00 = vec2(gx.x,gy.x); + vec2 g10 = vec2(gx.y,gy.y); + vec2 g01 = vec2(gx.z,gy.z); + vec2 g11 = vec2(gx.w,gy.w); + + vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11))); + g00 *= norm.x; + g01 *= norm.y; + g10 *= norm.z; + g11 *= norm.w; + + float n00 = dot(g00, vec2(fx.x, fy.x)); + float n10 = dot(g10, vec2(fx.y, fy.y)); + float n01 = dot(g01, vec2(fx.z, fy.z)); + float n11 = dot(g11, vec2(fx.w, fy.w)); + + vec2 fade_xy = fade(Pf.xy); + vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x); + float n_xy = mix(n_x.x, n_x.y, fade_xy.y); + return 2.3 * n_xy; +} + + + void main() + { + + float n1 = (cnoise(textureCoordinate * scale) + 1.0) / 2.0; + + vec4 colorDiff = colorFinish - colorStart; + vec4 color = colorStart + colorDiff * n1; + + gl_FragColor = color; + } +); +#else +NSString *const kGPUImagePerlinNoiseFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + uniform float scale; + + uniform vec4 colorStart; + uniform vec4 colorFinish; + + // + // Description : Array and textureless GLSL 2D/3D/4D simplex + // noise functions. + // Author : Ian McEwan, Ashima Arts. + // Maintainer : ijm + // Lastmod : 20110822 (ijm) + // License : Copyright (C) 2011 Ashima Arts. All rights reserved. + // Distributed under the MIT License. See LICENSE file. + // https://github.com/ashima/webgl-noise + // + + vec4 mod289(vec4 x) +{ + return x - floor(x * (1.0 / 289.0)) * 289.0; +} + + vec4 permute(vec4 x) +{ + return mod289(((x*34.0)+1.0)*x); +} + + vec4 taylorInvSqrt(vec4 r) +{ + return 1.79284291400159 - 0.85373472095314 * r; +} + + vec2 fade(vec2 t) { + return t*t*t*(t*(t*6.0-15.0)+10.0); + } + + // Classic Perlin noise + float cnoise(vec2 P) +{ + vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0); + vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0); + Pi = mod289(Pi); // To avoid truncation effects in permutation + vec4 ix = Pi.xzxz; + vec4 iy = Pi.yyww; + vec4 fx = Pf.xzxz; + vec4 fy = Pf.yyww; + + vec4 i = permute(permute(ix) + iy); + + vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ; + vec4 gy = abs(gx) - 0.5 ; + vec4 tx = floor(gx + 0.5); + gx = gx - tx; + + vec2 g00 = vec2(gx.x,gy.x); + vec2 g10 = vec2(gx.y,gy.y); + vec2 g01 = vec2(gx.z,gy.z); + vec2 g11 = vec2(gx.w,gy.w); + + vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11))); + g00 *= norm.x; + g01 *= norm.y; + g10 *= norm.z; + g11 *= norm.w; + + float n00 = dot(g00, vec2(fx.x, fy.x)); + float n10 = dot(g10, vec2(fx.y, fy.y)); + float n01 = dot(g01, vec2(fx.z, fy.z)); + float n11 = dot(g11, vec2(fx.w, fy.w)); + + vec2 fade_xy = fade(Pf.xy); + vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x); + float n_xy = mix(n_x.x, n_x.y, fade_xy.y); + return 2.3 * n_xy; + } + + void main() + { + + float n1 = (cnoise(textureCoordinate * scale) + 1.0) / 2.0; + + vec4 colorDiff = colorFinish - colorStart; + vec4 color = colorStart + colorDiff * n1; + + gl_FragColor = color; + } +); +#endif + + +@implementation GPUImagePerlinNoiseFilter + +@synthesize scale = _scale, colorStart = _colorStart, colorFinish = _colorFinish; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImagePerlinNoiseFragmentShaderString])) + { + return nil; + } + + scaleUniform = [filterProgram uniformIndex:@"scale"]; + + colorStartUniform = [filterProgram uniformIndex:@"colorStart"]; + colorFinishUniform = [filterProgram uniformIndex:@"colorFinish"]; + + [self setScale:8.0]; + + [self setColorStart:(GPUVector4){0.0, 0.0, 0.0, 1.0}]; + [self setColorFinish:(GPUVector4){1.0, 1.0, 1.0, 1.0}]; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setScale:(float)scale +{ + _scale = scale; + + [self setFloat:_scale forUniform:scaleUniform program:filterProgram]; +} + +- (void)setColorStart:(GPUVector4)colorStart +{ + _colorStart = colorStart; + + [self setVec4:_colorStart forUniform:colorStartUniform program:filterProgram]; +} + +- (void)setColorFinish:(GPUVector4)colorFinish +{ + _colorFinish = colorFinish; + + [self setVec4:_colorFinish forUniform:colorFinishUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePinchDistortionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePinchDistortionFilter.h new file mode 100755 index 00000000..994774fd --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePinchDistortionFilter.h @@ -0,0 +1,20 @@ +#import "GPUImageFilter.h" + +/** Creates a pinch distortion of the image + */ +@interface GPUImagePinchDistortionFilter : GPUImageFilter +{ + GLint aspectRatioUniform, radiusUniform, centerUniform, scaleUniform; +} + +/** The center about which to apply the distortion, with a default of (0.5, 0.5) + */ +@property(readwrite, nonatomic) CGPoint center; +/** The radius of the distortion, ranging from 0.0 to 2.0, with a default of 1.0 + */ +@property(readwrite, nonatomic) CGFloat radius; +/** The amount of distortion to apply, from -2.0 to 2.0, with a default of 0.5 + */ +@property(readwrite, nonatomic) CGFloat scale; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePinchDistortionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImagePinchDistortionFilter.m new file mode 100755 index 00000000..76d79096 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePinchDistortionFilter.m @@ -0,0 +1,176 @@ +#import "GPUImagePinchDistortionFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImagePinchDistortionFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp float aspectRatio; + uniform highp vec2 center; + uniform highp float radius; + uniform highp float scale; + + void main() + { + highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + highp float dist = distance(center, textureCoordinateToUse); + textureCoordinateToUse = textureCoordinate; + + if (dist < radius) + { + textureCoordinateToUse -= center; + highp float percent = 1.0 + ((0.5 - dist) / 0.5) * scale; + textureCoordinateToUse = textureCoordinateToUse * percent; + textureCoordinateToUse += center; + + gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse ); + } + else + { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate ); + } + } +); +#else +NSString *const kGPUImagePinchDistortionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform float aspectRatio; + uniform vec2 center; + uniform float radius; + uniform float scale; + + void main() + { + vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + float dist = distance(center, textureCoordinateToUse); + textureCoordinateToUse = textureCoordinate; + + if (dist < radius) + { + textureCoordinateToUse -= center; + float percent = 1.0 + ((0.5 - dist) / 0.5) * scale; + textureCoordinateToUse = textureCoordinateToUse * percent; + textureCoordinateToUse += center; + + gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse ); + } + else + { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate ); + } + } +); +#endif + +@interface GPUImagePinchDistortionFilter () + +- (void)adjustAspectRatio; + +@property (readwrite, nonatomic) CGFloat aspectRatio; + +@end + +@implementation GPUImagePinchDistortionFilter + +@synthesize aspectRatio = _aspectRatio; +@synthesize center = _center; +@synthesize radius = _radius; +@synthesize scale = _scale; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImagePinchDistortionFragmentShaderString])) + { + return nil; + } + + aspectRatioUniform = [filterProgram uniformIndex:@"aspectRatio"]; + radiusUniform = [filterProgram uniformIndex:@"radius"]; + scaleUniform = [filterProgram uniformIndex:@"scale"]; + centerUniform = [filterProgram uniformIndex:@"center"]; + + self.radius = 1.0; + self.scale = 0.5; + self.center = CGPointMake(0.5, 0.5); + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)adjustAspectRatio; +{ + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + [self setAspectRatio:(inputTextureSize.width / inputTextureSize.height)]; + } + else + { + [self setAspectRatio:(inputTextureSize.height / inputTextureSize.width)]; + } +} + +- (void)forceProcessingAtSize:(CGSize)frameSize; +{ + [super forceProcessingAtSize:frameSize]; + [self adjustAspectRatio]; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + CGSize oldInputSize = inputTextureSize; + [super setInputSize:newSize atIndex:textureIndex]; + + if ( (!CGSizeEqualToSize(oldInputSize, inputTextureSize)) && (!CGSizeEqualToSize(newSize, CGSizeZero)) ) + { + [self adjustAspectRatio]; + } +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + [super setInputRotation:newInputRotation atIndex:textureIndex]; + [self setCenter:self.center]; + [self adjustAspectRatio]; +} + +- (void)setAspectRatio:(CGFloat)newValue; +{ + _aspectRatio = newValue; + + [self setFloat:_aspectRatio forUniform:aspectRatioUniform program:filterProgram]; +} + +- (void)setRadius:(CGFloat)newValue; +{ + _radius = newValue; + + [self setFloat:_radius forUniform:radiusUniform program:filterProgram]; +} + +- (void)setScale:(CGFloat)newValue; +{ + _scale = newValue; + + [self setFloat:_scale forUniform:scaleUniform program:filterProgram]; +} + +- (void)setCenter:(CGPoint)newValue; +{ + _center = newValue; + + CGPoint rotatedPoint = [self rotatedPoint:_center forRotation:inputRotation]; + [self setPoint:rotatedPoint forUniform:centerUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePixellateFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePixellateFilter.h new file mode 100755 index 00000000..d0f6ae04 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePixellateFilter.h @@ -0,0 +1,12 @@ +#import "GPUImageFilter.h" + +@interface GPUImagePixellateFilter : GPUImageFilter +{ + GLint fractionalWidthOfAPixelUniform, aspectRatioUniform; +} + +// The fractional width of the image to use as a size for the pixels in the resulting image. Values below one pixel width in the source image are ignored. +@property(readwrite, nonatomic) CGFloat fractionalWidthOfAPixel; + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePixellateFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImagePixellateFilter.m new file mode 100755 index 00000000..88430d09 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePixellateFilter.m @@ -0,0 +1,151 @@ +#import "GPUImagePixellateFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImagePixellationFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp float fractionalWidthOfPixel; + uniform highp float aspectRatio; + + void main() + { + highp vec2 sampleDivisor = vec2(fractionalWidthOfPixel, fractionalWidthOfPixel / aspectRatio); + + highp vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor) + 0.5 * sampleDivisor; + gl_FragColor = texture2D(inputImageTexture, samplePos ); + } +); +#else +NSString *const kGPUImagePixellationFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform float fractionalWidthOfPixel; + uniform float aspectRatio; + + void main() + { + vec2 sampleDivisor = vec2(fractionalWidthOfPixel, fractionalWidthOfPixel / aspectRatio); + + vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor) + 0.5 * sampleDivisor; + gl_FragColor = texture2D(inputImageTexture, samplePos ); + } +); +#endif + +@interface GPUImagePixellateFilter () + +@property (readwrite, nonatomic) CGFloat aspectRatio; + +- (void)adjustAspectRatio; + +@end + +@implementation GPUImagePixellateFilter + +@synthesize fractionalWidthOfAPixel = _fractionalWidthOfAPixel; +@synthesize aspectRatio = _aspectRatio; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImagePixellationFragmentShaderString])) + { + return nil; + } + + return self; +} + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [super initWithFragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + fractionalWidthOfAPixelUniform = [filterProgram uniformIndex:@"fractionalWidthOfPixel"]; + aspectRatioUniform = [filterProgram uniformIndex:@"aspectRatio"]; + + self.fractionalWidthOfAPixel = 0.05; + + return self; +} + +- (void)adjustAspectRatio; +{ + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + [self setAspectRatio:(inputTextureSize.width / inputTextureSize.height)]; + } + else + { + [self setAspectRatio:(inputTextureSize.height / inputTextureSize.width)]; + } +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + [super setInputRotation:newInputRotation atIndex:textureIndex]; + [self adjustAspectRatio]; +} + +- (void)forceProcessingAtSize:(CGSize)frameSize; +{ + [super forceProcessingAtSize:frameSize]; + [self adjustAspectRatio]; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + CGSize oldInputSize = inputTextureSize; + [super setInputSize:newSize atIndex:textureIndex]; + + if ( (!CGSizeEqualToSize(oldInputSize, inputTextureSize)) && (!CGSizeEqualToSize(newSize, CGSizeZero)) ) + { + [self adjustAspectRatio]; + } +} + +#pragma mark - +#pragma mark Accessors + +- (void)setFractionalWidthOfAPixel:(CGFloat)newValue; +{ + CGFloat singlePixelSpacing; + if (inputTextureSize.width != 0.0) + { + singlePixelSpacing = 1.0 / inputTextureSize.width; + } + else + { + singlePixelSpacing = 1.0 / 2048.0; + } + + if (newValue < singlePixelSpacing) + { + _fractionalWidthOfAPixel = singlePixelSpacing; + } + else + { + _fractionalWidthOfAPixel = newValue; + } + + [self setFloat:_fractionalWidthOfAPixel forUniform:fractionalWidthOfAPixelUniform program:filterProgram]; +} + +- (void)setAspectRatio:(CGFloat)newValue; +{ + _aspectRatio = newValue; + + [self setFloat:_aspectRatio forUniform:aspectRatioUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePixellatePositionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePixellatePositionFilter.h new file mode 100755 index 00000000..9d304c93 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePixellatePositionFilter.h @@ -0,0 +1,17 @@ +#import "GPUImageFilter.h" + +@interface GPUImagePixellatePositionFilter : GPUImageFilter +{ + GLint fractionalWidthOfAPixelUniform, aspectRatioUniform, centerUniform, radiusUniform; +} + +// The fractional width of the image to use as a size for the pixels in the resulting image. Values below one pixel width in the source image are ignored. +@property(readwrite, nonatomic) CGFloat fractionalWidthOfAPixel; + +// the center point to start pixelation in texture coordinates, default 0.5, 0.5 +@property(readwrite, nonatomic) CGPoint center; + +// the radius (0.0 - 1.0) in which to pixelate, default 1.0 +@property(readwrite, nonatomic) CGFloat radius; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePixellatePositionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImagePixellatePositionFilter.m new file mode 100755 index 00000000..f1bd09cc --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePixellatePositionFilter.m @@ -0,0 +1,194 @@ +#import "GPUImagePixellatePositionFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImagePixellationPositionFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp float fractionalWidthOfPixel; + uniform highp float aspectRatio; + uniform lowp vec2 pixelateCenter; + uniform highp float pixelateRadius; + + void main() + { + highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + highp float dist = distance(pixelateCenter, textureCoordinateToUse); + + if (dist < pixelateRadius) + { + highp vec2 sampleDivisor = vec2(fractionalWidthOfPixel, fractionalWidthOfPixel / aspectRatio); + highp vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor) + 0.5 * sampleDivisor; + gl_FragColor = texture2D(inputImageTexture, samplePos ); + } + else + { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate ); + } + } +); +#else +NSString *const kGPUImagePixellationPositionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform float fractionalWidthOfPixel; + uniform float aspectRatio; + uniform vec2 pixelateCenter; + uniform float pixelateRadius; + + void main() + { + vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + float dist = distance(pixelateCenter, textureCoordinateToUse); + + if (dist < pixelateRadius) + { + vec2 sampleDivisor = vec2(fractionalWidthOfPixel, fractionalWidthOfPixel / aspectRatio); + vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor) + 0.5 * sampleDivisor; + gl_FragColor = texture2D(inputImageTexture, samplePos ); + } + else + { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate ); + } + } +); +#endif + +@interface GPUImagePixellatePositionFilter () + +- (void)adjustAspectRatio; + +@property (readwrite, nonatomic) CGFloat aspectRatio; + +@end + +@implementation GPUImagePixellatePositionFilter + +@synthesize fractionalWidthOfAPixel = _fractionalWidthOfAPixel; +@synthesize aspectRatio = _aspectRatio; +@synthesize center = _center; +@synthesize radius = _radius; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImagePixellationPositionFragmentShaderString])) + { + return nil; + } + + return self; +} + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [super initWithFragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + fractionalWidthOfAPixelUniform = [filterProgram uniformIndex:@"fractionalWidthOfPixel"]; + aspectRatioUniform = [filterProgram uniformIndex:@"aspectRatio"]; + centerUniform = [filterProgram uniformIndex:@"pixelateCenter"]; + radiusUniform = [filterProgram uniformIndex:@"pixelateRadius"]; + + self.fractionalWidthOfAPixel = 0.05; + self.center = CGPointMake(0.5f, 0.5f); + self.radius = 0.25f; + + return self; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + CGSize oldInputSize = inputTextureSize; + [super setInputSize:newSize atIndex:textureIndex]; + + if ( (!CGSizeEqualToSize(oldInputSize, inputTextureSize)) && (!CGSizeEqualToSize(newSize, CGSizeZero)) ) + { + [self adjustAspectRatio]; + } +} + +#pragma mark - +#pragma mark Accessors + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + [super setInputRotation:newInputRotation atIndex:textureIndex]; + [self setCenter:self.center]; + [self adjustAspectRatio]; +} + +- (void)adjustAspectRatio; +{ + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + [self setAspectRatio:(inputTextureSize.width / inputTextureSize.height)]; + } + else + { + [self setAspectRatio:(inputTextureSize.height / inputTextureSize.width)]; + } +} + +- (void)forceProcessingAtSize:(CGSize)frameSize; +{ + [super forceProcessingAtSize:frameSize]; + [self adjustAspectRatio]; +} + +- (void)setFractionalWidthOfAPixel:(CGFloat)newValue; +{ + CGFloat singlePixelSpacing; + if (inputTextureSize.width != 0.0) + { + singlePixelSpacing = 1.0 / inputTextureSize.width; + } + else + { + singlePixelSpacing = 1.0 / 2048.0; + } + + if (newValue < singlePixelSpacing) + { + _fractionalWidthOfAPixel = singlePixelSpacing; + } + else + { + _fractionalWidthOfAPixel = newValue; + } + + [self setFloat:_fractionalWidthOfAPixel forUniform:fractionalWidthOfAPixelUniform program:filterProgram]; +} + +- (void)setAspectRatio:(CGFloat)newValue; +{ + _aspectRatio = newValue; + + [self setFloat:_aspectRatio forUniform:aspectRatioUniform program:filterProgram]; +} + +- (void)setCenter:(CGPoint)center +{ + _center = center; + CGPoint rotatedPoint = [self rotatedPoint:center forRotation:inputRotation]; + [self setPoint:rotatedPoint forUniform:centerUniform program:filterProgram]; +} + +- (void)setRadius:(CGFloat)radius +{ + _radius = radius; + + [self setFloat:_radius forUniform:radiusUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePoissonBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePoissonBlendFilter.h new file mode 100644 index 00000000..58eff225 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePoissonBlendFilter.h @@ -0,0 +1,18 @@ +#import "GPUImageTwoInputCrossTextureSamplingFilter.h" +#import "GPUImageFilterGroup.h" + +@interface GPUImagePoissonBlendFilter : GPUImageTwoInputCrossTextureSamplingFilter +{ + GLint mixUniform; + + GPUImageFramebuffer *secondOutputFramebuffer; +} + +// Mix ranges from 0.0 (only image 1) to 1.0 (only image 2 gradients), with 1.0 as the normal level +@property(readwrite, nonatomic) CGFloat mix; + +// The number of times to propagate the gradients. +// Crank this up to 100 or even 1000 if you want to get anywhere near convergence. Yes, this will be slow. +@property(readwrite, nonatomic) NSUInteger numIterations; + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePoissonBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImagePoissonBlendFilter.m new file mode 100644 index 00000000..0167e024 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePoissonBlendFilter.m @@ -0,0 +1,175 @@ +#import "GPUImagePoissonBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImagePoissonBlendFragmentShaderString = SHADER_STRING +( + precision mediump float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + varying vec2 topTextureCoordinate; + varying vec2 bottomTextureCoordinate; + + varying vec2 textureCoordinate2; + varying vec2 leftTextureCoordinate2; + varying vec2 rightTextureCoordinate2; + varying vec2 topTextureCoordinate2; + varying vec2 bottomTextureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform lowp float mixturePercent; + + void main() + { + vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); + vec3 bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + vec3 leftColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + vec3 rightColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; + vec3 topColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; + + vec4 centerColor2 = texture2D(inputImageTexture2, textureCoordinate2); + vec3 bottomColor2 = texture2D(inputImageTexture2, bottomTextureCoordinate2).rgb; + vec3 leftColor2 = texture2D(inputImageTexture2, leftTextureCoordinate2).rgb; + vec3 rightColor2 = texture2D(inputImageTexture2, rightTextureCoordinate2).rgb; + vec3 topColor2 = texture2D(inputImageTexture2, topTextureCoordinate2).rgb; + + vec3 meanColor = (bottomColor + leftColor + rightColor + topColor) / 4.0; + vec3 diffColor = centerColor.rgb - meanColor; + + vec3 meanColor2 = (bottomColor2 + leftColor2 + rightColor2 + topColor2) / 4.0; + vec3 diffColor2 = centerColor2.rgb - meanColor2; + + vec3 gradColor = (meanColor + diffColor2); + + gl_FragColor = vec4(mix(centerColor.rgb, gradColor, centerColor2.a * mixturePercent), centerColor.a); + } +); +#else +NSString *const kGPUImagePoissonBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + varying vec2 topTextureCoordinate; + varying vec2 bottomTextureCoordinate; + + varying vec2 textureCoordinate2; + varying vec2 leftTextureCoordinate2; + varying vec2 rightTextureCoordinate2; + varying vec2 topTextureCoordinate2; + varying vec2 bottomTextureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform float mixturePercent; + + void main() + { + vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); + vec3 bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + vec3 leftColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + vec3 rightColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; + vec3 topColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; + + vec4 centerColor2 = texture2D(inputImageTexture2, textureCoordinate2); + vec3 bottomColor2 = texture2D(inputImageTexture2, bottomTextureCoordinate2).rgb; + vec3 leftColor2 = texture2D(inputImageTexture2, leftTextureCoordinate2).rgb; + vec3 rightColor2 = texture2D(inputImageTexture2, rightTextureCoordinate2).rgb; + vec3 topColor2 = texture2D(inputImageTexture2, topTextureCoordinate2).rgb; + + vec3 meanColor = (bottomColor + leftColor + rightColor + topColor) / 4.0; + vec3 diffColor = centerColor.rgb - meanColor; + + vec3 meanColor2 = (bottomColor2 + leftColor2 + rightColor2 + topColor2) / 4.0; + vec3 diffColor2 = centerColor2.rgb - meanColor2; + + vec3 gradColor = (meanColor + diffColor2); + + gl_FragColor = vec4(mix(centerColor.rgb, gradColor, centerColor2.a * mixturePercent), centerColor.a); + } +); +#endif + +@implementation GPUImagePoissonBlendFilter + +@synthesize mix = _mix; +@synthesize numIterations = _numIterations; + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImagePoissonBlendFragmentShaderString])) + { + return nil; + } + + mixUniform = [filterProgram uniformIndex:@"mixturePercent"]; + self.mix = 0.5; + + self.numIterations = 10; + + return self; +} + +- (void)setMix:(CGFloat)newValue; +{ + _mix = newValue; + + [self setFloat:_mix forUniform:mixUniform program:filterProgram]; +} + +//- (void)setOutputFBO; +//{ +// if (self.numIterations % 2 == 1) { +// [self setSecondFilterFBO]; +// } else { +// [self setFilterFBO]; +// } +//} + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + // Run the first stage of the two-pass filter + [GPUImageContext setActiveShaderProgram:filterProgram]; + + [super renderToTextureWithVertices:vertices textureCoordinates:textureCoordinates]; + + for (int pass = 1; pass < self.numIterations; pass++) { + + if (pass % 2 == 0) { + + [GPUImageContext setActiveShaderProgram:filterProgram]; + + // TODO: This will over-unlock the incoming framebuffer + [super renderToTextureWithVertices:vertices textureCoordinates:[[self class] textureCoordinatesForRotation:kGPUImageNoRotation]]; + } else { + // Run the second stage of the two-pass filter + secondOutputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [secondOutputFramebuffer activateFramebuffer]; + + [GPUImageContext setActiveShaderProgram:filterProgram]; + + glClearColor(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha); + glClear(GL_COLOR_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, [outputFramebuffer texture]); + glUniform1i(filterInputTextureUniform, 2); + + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, [secondInputFramebuffer texture]); + glUniform1i(filterInputTextureUniform2, 3); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [[self class] textureCoordinatesForRotation:kGPUImageNoRotation]); + glVertexAttribPointer(filterSecondTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [[self class] textureCoordinatesForRotation:inputRotation2]); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } + } +} + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePolarPixellateFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePolarPixellateFilter.h new file mode 100755 index 00000000..3de6a4d3 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePolarPixellateFilter.h @@ -0,0 +1,13 @@ +#import "GPUImageFilter.h" + +@interface GPUImagePolarPixellateFilter : GPUImageFilter { + GLint centerUniform, pixelSizeUniform; +} + +// The center about which to apply the distortion, with a default of (0.5, 0.5) +@property(readwrite, nonatomic) CGPoint center; +// The amount of distortion to apply, from (-2.0, -2.0) to (2.0, 2.0), with a default of (0.05, 0.05) +@property(readwrite, nonatomic) CGSize pixelSize; + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePolarPixellateFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImagePolarPixellateFilter.m new file mode 100755 index 00000000..5677db48 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePolarPixellateFilter.m @@ -0,0 +1,128 @@ +#import "GPUImagePolarPixellateFilter.h" + +// @fattjake based on vid by toneburst + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImagePolarPixellateFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp vec2 center; + uniform highp vec2 pixelSize; + + + void main() + { + highp vec2 normCoord = 2.0 * textureCoordinate - 1.0; + highp vec2 normCenter = 2.0 * center - 1.0; + + normCoord -= normCenter; + + highp float r = length(normCoord); // to polar coords + highp float phi = atan(normCoord.y, normCoord.x); // to polar coords + + r = r - mod(r, pixelSize.x) + 0.03; + phi = phi - mod(phi, pixelSize.y); + + normCoord.x = r * cos(phi); + normCoord.y = r * sin(phi); + + normCoord += normCenter; + + mediump vec2 textureCoordinateToUse = normCoord / 2.0 + 0.5; + + gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse ); + + } +); +#else +NSString *const kGPUImagePolarPixellateFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform vec2 center; + uniform vec2 pixelSize; + + + void main() + { + vec2 normCoord = 2.0 * textureCoordinate - 1.0; + vec2 normCenter = 2.0 * center - 1.0; + + normCoord -= normCenter; + + float r = length(normCoord); // to polar coords + float phi = atan(normCoord.y, normCoord.x); // to polar coords + + r = r - mod(r, pixelSize.x) + 0.03; + phi = phi - mod(phi, pixelSize.y); + + normCoord.x = r * cos(phi); + normCoord.y = r * sin(phi); + + normCoord += normCenter; + + vec2 textureCoordinateToUse = normCoord / 2.0 + 0.5; + + gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse ); + + } +); +#endif + + +@implementation GPUImagePolarPixellateFilter + +@synthesize center = _center; + +@synthesize pixelSize = _pixelSize; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImagePolarPixellateFragmentShaderString])) + { + return nil; + } + + pixelSizeUniform = [filterProgram uniformIndex:@"pixelSize"]; + centerUniform = [filterProgram uniformIndex:@"center"]; + + + self.pixelSize = CGSizeMake(0.05, 0.05); + self.center = CGPointMake(0.5, 0.5); + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + [super setInputRotation:newInputRotation atIndex:textureIndex]; + [self setCenter:self.center]; +} + +- (void)setPixelSize:(CGSize)pixelSize +{ + _pixelSize = pixelSize; + + [self setSize:_pixelSize forUniform:pixelSizeUniform program:filterProgram]; +} + +- (void)setCenter:(CGPoint)newValue; +{ + _center = newValue; + + CGPoint rotatedPoint = [self rotatedPoint:_center forRotation:inputRotation]; + [self setPoint:rotatedPoint forUniform:centerUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePolkaDotFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePolkaDotFilter.h new file mode 100644 index 00000000..369b7737 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePolkaDotFilter.h @@ -0,0 +1,10 @@ +#import "GPUImagePixellateFilter.h" + +@interface GPUImagePolkaDotFilter : GPUImagePixellateFilter +{ + GLint dotScalingUniform; +} + +@property(readwrite, nonatomic) CGFloat dotScaling; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePolkaDotFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImagePolkaDotFilter.m new file mode 100644 index 00000000..a439a043 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePolkaDotFilter.m @@ -0,0 +1,85 @@ +#import "GPUImagePolkaDotFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImagePolkaDotFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp float fractionalWidthOfPixel; + uniform highp float aspectRatio; + uniform highp float dotScaling; + + void main() + { + highp vec2 sampleDivisor = vec2(fractionalWidthOfPixel, fractionalWidthOfPixel / aspectRatio); + + highp vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor) + 0.5 * sampleDivisor; + highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + highp vec2 adjustedSamplePos = vec2(samplePos.x, (samplePos.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + highp float distanceFromSamplePoint = distance(adjustedSamplePos, textureCoordinateToUse); + lowp float checkForPresenceWithinDot = step(distanceFromSamplePoint, (fractionalWidthOfPixel * 0.5) * dotScaling); + + lowp vec4 inputColor = texture2D(inputImageTexture, samplePos); + + gl_FragColor = vec4(inputColor.rgb * checkForPresenceWithinDot, inputColor.a); + } +); +#else +NSString *const kGPUImagePolkaDotFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform float fractionalWidthOfPixel; + uniform float aspectRatio; + uniform float dotScaling; + + void main() + { + vec2 sampleDivisor = vec2(fractionalWidthOfPixel, fractionalWidthOfPixel / aspectRatio); + + vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor) + 0.5 * sampleDivisor; + vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + vec2 adjustedSamplePos = vec2(samplePos.x, (samplePos.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + float distanceFromSamplePoint = distance(adjustedSamplePos, textureCoordinateToUse); + float checkForPresenceWithinDot = step(distanceFromSamplePoint, (fractionalWidthOfPixel * 0.5) * dotScaling); + + vec4 inputColor = texture2D(inputImageTexture, samplePos); + + gl_FragColor = vec4(inputColor.rgb * checkForPresenceWithinDot, inputColor.a); + } +); +#endif + +@implementation GPUImagePolkaDotFilter + +@synthesize dotScaling = _dotScaling; + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImagePolkaDotFragmentShaderString])) + { + return nil; + } + + dotScalingUniform = [filterProgram uniformIndex:@"dotScaling"]; + + self.dotScaling = 0.90; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setDotScaling:(CGFloat)newValue; +{ + _dotScaling = newValue; + + [self setFloat:_dotScaling forUniform:dotScalingUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePosterizeFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePosterizeFilter.h new file mode 100755 index 00000000..6f655b3e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePosterizeFilter.h @@ -0,0 +1,14 @@ +#import "GPUImageFilter.h" + +/** This reduces the color dynamic range into the number of steps specified, leading to a cartoon-like simple shading of the image. + */ +@interface GPUImagePosterizeFilter : GPUImageFilter +{ + GLint colorLevelsUniform; +} + +/** The number of color levels to reduce the image space to. This ranges from 1 to 256, with a default of 10. + */ +@property(readwrite, nonatomic) NSUInteger colorLevels; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePosterizeFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImagePosterizeFilter.m new file mode 100755 index 00000000..a438cea5 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePosterizeFilter.m @@ -0,0 +1,66 @@ +#import "GPUImagePosterizeFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImagePosterizeFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform highp float colorLevels; + + void main() + { + highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = floor((textureColor * colorLevels) + vec4(0.5)) / colorLevels; + } +); +#else +NSString *const kGPUImagePosterizeFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float colorLevels; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = floor((textureColor * colorLevels) + vec4(0.5)) / colorLevels; + } +); +#endif + +@implementation GPUImagePosterizeFilter + +@synthesize colorLevels = _colorLevels; + +#pragma mark - +#pragma mark Initialization + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImagePosterizeFragmentShaderString])) + { + return nil; + } + + colorLevelsUniform = [filterProgram uniformIndex:@"colorLevels"]; + self.colorLevels = 10; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setColorLevels:(NSUInteger)newValue; +{ + _colorLevels = newValue; + + [self setFloat:_colorLevels forUniform:colorLevelsUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePrewittEdgeDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImagePrewittEdgeDetectionFilter.h new file mode 100755 index 00000000..141f8c5f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePrewittEdgeDetectionFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageSobelEdgeDetectionFilter.h" + +@interface GPUImagePrewittEdgeDetectionFilter : GPUImageSobelEdgeDetectionFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImagePrewittEdgeDetectionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImagePrewittEdgeDetectionFilter.m new file mode 100755 index 00000000..a9906930 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImagePrewittEdgeDetectionFilter.m @@ -0,0 +1,97 @@ +#import "GPUImagePrewittEdgeDetectionFilter.h" + +@implementation GPUImagePrewittEdgeDetectionFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImagePrewittFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float edgeStrength; + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float h = -topLeftIntensity - topIntensity - topRightIntensity + bottomLeftIntensity + bottomIntensity + bottomRightIntensity; + float v = -bottomLeftIntensity - leftIntensity - topLeftIntensity + bottomRightIntensity + rightIntensity + topRightIntensity; + + float mag = length(vec2(h, v)) * edgeStrength; + + gl_FragColor = vec4(vec3(mag), 1.0); + } +); +#else +NSString *const kGPUImagePrewittFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float edgeStrength; + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float h = -topLeftIntensity - topIntensity - topRightIntensity + bottomLeftIntensity + bottomIntensity + bottomRightIntensity; + float v = -bottomLeftIntensity - leftIntensity - topLeftIntensity + bottomRightIntensity + rightIntensity + topRightIntensity; + + float mag = length(vec2(h, v)) * edgeStrength; + + gl_FragColor = vec4(vec3(mag), 1.0); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImagePrewittFragmentShaderString])) + { + return nil; + } + + self.edgeStrength = 1.0; + + return self; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRGBClosingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageRGBClosingFilter.h new file mode 100644 index 00000000..08d13f88 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRGBClosingFilter.h @@ -0,0 +1,18 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImageRGBErosionFilter; +@class GPUImageRGBDilationFilter; + +// A filter that first performs a dilation on each color channel of an image, followed by an erosion of the same radius. +// This helps to filter out smaller dark elements. + +@interface GPUImageRGBClosingFilter : GPUImageFilterGroup +{ + GPUImageRGBErosionFilter *erosionFilter; + GPUImageRGBDilationFilter *dilationFilter; +} + +- (id)initWithRadius:(NSUInteger)radius; + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRGBClosingFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageRGBClosingFilter.m new file mode 100644 index 00000000..c5bb1c8d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRGBClosingFilter.m @@ -0,0 +1,41 @@ +#import "GPUImageRGBClosingFilter.h" +#import "GPUImageRGBErosionFilter.h" +#import "GPUImageRGBDilationFilter.h" + +@implementation GPUImageRGBClosingFilter + +- (id)init; +{ + if (!(self = [self initWithRadius:1])) + { + return nil; + } + + return self; +} + +- (id)initWithRadius:(NSUInteger)radius; +{ + if (!(self = [super init])) + { + return nil; + } + + // First pass: dilation + dilationFilter = [[GPUImageRGBDilationFilter alloc] initWithRadius:radius]; + [self addFilter:dilationFilter]; + + // Second pass: erosion + erosionFilter = [[GPUImageRGBErosionFilter alloc] initWithRadius:radius]; + [self addFilter:erosionFilter]; + + [dilationFilter addTarget:erosionFilter]; + + self.initialFilters = [NSArray arrayWithObjects:dilationFilter, nil]; + self.terminalFilter = erosionFilter; + + return self; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRGBDilationFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageRGBDilationFilter.h new file mode 100644 index 00000000..68276f84 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRGBDilationFilter.h @@ -0,0 +1,11 @@ +#import "GPUImageTwoPassTextureSamplingFilter.h" + +// For each pixel, this sets it to the maximum value of each color channel in a rectangular neighborhood extending out dilationRadius pixels from the center. +// This extends out brighter colors, and can be used for abstraction of color images. + +@interface GPUImageRGBDilationFilter : GPUImageTwoPassTextureSamplingFilter + +// Acceptable values for dilationRadius, which sets the distance in pixels to sample out from the center, are 1, 2, 3, and 4. +- (id)initWithRadius:(NSUInteger)dilationRadius; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRGBDilationFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageRGBDilationFilter.m new file mode 100644 index 00000000..9702c783 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRGBDilationFilter.m @@ -0,0 +1,306 @@ +#import "GPUImageRGBDilationFilter.h" +#import "GPUImageDilationFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageRGBDilationRadiusOneFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + lowp vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + lowp vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + lowp vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + + lowp vec4 maxValue = max(centerIntensity, oneStepPositiveIntensity); + + gl_FragColor = max(maxValue, oneStepNegativeIntensity); + } +); + +NSString *const kGPUImageRGBDilationRadiusTwoFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + lowp vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + lowp vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + lowp vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + lowp vec4 twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate); + lowp vec4 twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate); + + lowp vec4 maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + maxValue = max(maxValue, twoStepsPositiveIntensity); + maxValue = max(maxValue, twoStepsNegativeIntensity); + + gl_FragColor = max(maxValue, twoStepsNegativeIntensity); + } +); + +NSString *const kGPUImageRGBDilationRadiusThreeFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + lowp vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + lowp vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + lowp vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + lowp vec4 twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate); + lowp vec4 twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate); + lowp vec4 threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate); + lowp vec4 threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate); + + lowp vec4 maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + maxValue = max(maxValue, twoStepsPositiveIntensity); + maxValue = max(maxValue, twoStepsNegativeIntensity); + maxValue = max(maxValue, threeStepsPositiveIntensity); + + gl_FragColor = max(maxValue, threeStepsNegativeIntensity); + } +); + +NSString *const kGPUImageRGBDilationRadiusFourFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + varying vec2 fourStepsPositiveTextureCoordinate; + varying vec2 fourStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + lowp vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + lowp vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + lowp vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + lowp vec4 twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate); + lowp vec4 twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate); + lowp vec4 threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate); + lowp vec4 threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate); + lowp vec4 fourStepsPositiveIntensity = texture2D(inputImageTexture, fourStepsPositiveTextureCoordinate); + lowp vec4 fourStepsNegativeIntensity = texture2D(inputImageTexture, fourStepsNegativeTextureCoordinate); + + lowp vec4 maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + maxValue = max(maxValue, twoStepsPositiveIntensity); + maxValue = max(maxValue, twoStepsNegativeIntensity); + maxValue = max(maxValue, threeStepsPositiveIntensity); + maxValue = max(maxValue, threeStepsNegativeIntensity); + maxValue = max(maxValue, fourStepsPositiveIntensity); + + gl_FragColor = max(maxValue, fourStepsNegativeIntensity); + } +); +#else +NSString *const kGPUImageRGBDilationRadiusOneFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + + vec4 maxValue = max(centerIntensity, oneStepPositiveIntensity); + + gl_FragColor = max(maxValue, oneStepNegativeIntensity); + } + ); + +NSString *const kGPUImageRGBDilationRadiusTwoFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + vec4 twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate); + vec4 twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate); + + vec4 maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + maxValue = max(maxValue, twoStepsPositiveIntensity); + maxValue = max(maxValue, twoStepsNegativeIntensity); + + gl_FragColor = max(maxValue, twoStepsNegativeIntensity); + } + ); + +NSString *const kGPUImageRGBDilationRadiusThreeFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + vec4 twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate); + vec4 twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate); + vec4 threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate); + vec4 threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate); + + vec4 maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + maxValue = max(maxValue, twoStepsPositiveIntensity); + maxValue = max(maxValue, twoStepsNegativeIntensity); + maxValue = max(maxValue, threeStepsPositiveIntensity); + + gl_FragColor = max(maxValue, threeStepsNegativeIntensity); + } +); + +NSString *const kGPUImageRGBDilationRadiusFourFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + varying vec2 fourStepsPositiveTextureCoordinate; + varying vec2 fourStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + vec4 twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate); + vec4 twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate); + vec4 threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate); + vec4 threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate); + vec4 fourStepsPositiveIntensity = texture2D(inputImageTexture, fourStepsPositiveTextureCoordinate); + vec4 fourStepsNegativeIntensity = texture2D(inputImageTexture, fourStepsNegativeTextureCoordinate); + + vec4 maxValue = max(centerIntensity, oneStepPositiveIntensity); + maxValue = max(maxValue, oneStepNegativeIntensity); + maxValue = max(maxValue, twoStepsPositiveIntensity); + maxValue = max(maxValue, twoStepsNegativeIntensity); + maxValue = max(maxValue, threeStepsPositiveIntensity); + maxValue = max(maxValue, threeStepsNegativeIntensity); + maxValue = max(maxValue, fourStepsPositiveIntensity); + + gl_FragColor = max(maxValue, fourStepsNegativeIntensity); + } +); +#endif + +@implementation GPUImageRGBDilationFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithRadius:(NSUInteger)dilationRadius; +{ + NSString *fragmentShaderForThisRadius = nil; + NSString *vertexShaderForThisRadius = nil; + + switch (dilationRadius) + { + case 0: + case 1: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusOneVertexShaderString; + fragmentShaderForThisRadius = kGPUImageRGBDilationRadiusOneFragmentShaderString; + }; break; + case 2: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusTwoVertexShaderString; + fragmentShaderForThisRadius = kGPUImageRGBDilationRadiusTwoFragmentShaderString; + }; break; + case 3: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusThreeVertexShaderString; + fragmentShaderForThisRadius = kGPUImageRGBDilationRadiusThreeFragmentShaderString; + }; break; + case 4: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusFourVertexShaderString; + fragmentShaderForThisRadius = kGPUImageRGBDilationRadiusFourFragmentShaderString; + }; break; + default: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusFourVertexShaderString; + fragmentShaderForThisRadius = kGPUImageRGBDilationRadiusFourFragmentShaderString; + }; break; + } + + if (!(self = [super initWithFirstStageVertexShaderFromString:vertexShaderForThisRadius firstStageFragmentShaderFromString:fragmentShaderForThisRadius secondStageVertexShaderFromString:vertexShaderForThisRadius secondStageFragmentShaderFromString:fragmentShaderForThisRadius])) + { + return nil; + } + + return self; +} + +- (id)init; +{ + if (!(self = [self initWithRadius:1])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRGBErosionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageRGBErosionFilter.h new file mode 100644 index 00000000..5979cb7e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRGBErosionFilter.h @@ -0,0 +1,11 @@ +#import "GPUImageTwoPassTextureSamplingFilter.h" + +// For each pixel, this sets it to the minimum value of each color channel in a rectangular neighborhood extending out dilationRadius pixels from the center. +// This extends out dark features, and can be used for abstraction of color images. + +@interface GPUImageRGBErosionFilter : GPUImageTwoPassTextureSamplingFilter + +// Acceptable values for erosionRadius, which sets the distance in pixels to sample out from the center, are 1, 2, 3, and 4. +- (id)initWithRadius:(NSUInteger)erosionRadius; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRGBErosionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageRGBErosionFilter.m new file mode 100644 index 00000000..91e5f33d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRGBErosionFilter.m @@ -0,0 +1,304 @@ +#import "GPUImageRGBErosionFilter.h" +#import "GPUImageDilationFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageRGBErosionRadiusOneFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + lowp vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + lowp vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + lowp vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + + lowp vec4 minValue = min(centerIntensity, oneStepPositiveIntensity); + + gl_FragColor = min(minValue, oneStepNegativeIntensity); + } +); + +NSString *const kGPUImageRGBErosionRadiusTwoFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + lowp vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + lowp vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + lowp vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + lowp vec4 twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate); + lowp vec4 twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate); + + lowp vec4 minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + minValue = min(minValue, twoStepsPositiveIntensity); + + gl_FragColor = min(minValue, twoStepsNegativeIntensity); + } + ); + +NSString *const kGPUImageRGBErosionRadiusThreeFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + lowp vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + lowp vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + lowp vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + lowp vec4 twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate); + lowp vec4 twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate); + lowp vec4 threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate); + lowp vec4 threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate); + + lowp vec4 minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + minValue = min(minValue, twoStepsPositiveIntensity); + minValue = min(minValue, twoStepsNegativeIntensity); + minValue = min(minValue, threeStepsPositiveIntensity); + + gl_FragColor = min(minValue, threeStepsNegativeIntensity); + } + ); + +NSString *const kGPUImageRGBErosionRadiusFourFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + varying vec2 fourStepsPositiveTextureCoordinate; + varying vec2 fourStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + lowp vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + lowp vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + lowp vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + lowp vec4 twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate); + lowp vec4 twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate); + lowp vec4 threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate); + lowp vec4 threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate); + lowp vec4 fourStepsPositiveIntensity = texture2D(inputImageTexture, fourStepsPositiveTextureCoordinate); + lowp vec4 fourStepsNegativeIntensity = texture2D(inputImageTexture, fourStepsNegativeTextureCoordinate); + + lowp vec4 minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + minValue = min(minValue, twoStepsPositiveIntensity); + minValue = min(minValue, twoStepsNegativeIntensity); + minValue = min(minValue, threeStepsPositiveIntensity); + minValue = min(minValue, threeStepsNegativeIntensity); + minValue = min(minValue, fourStepsPositiveIntensity); + + gl_FragColor = min(minValue, fourStepsNegativeIntensity); + } +); +#else +NSString *const kGPUImageRGBErosionRadiusOneFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + + vec4 minValue = min(centerIntensity, oneStepPositiveIntensity); + + gl_FragColor = min(minValue, oneStepNegativeIntensity); + } +); + +NSString *const kGPUImageRGBErosionRadiusTwoFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + vec4 twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate); + vec4 twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate); + + vec4 minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + minValue = min(minValue, twoStepsPositiveIntensity); + + gl_FragColor = min(minValue, twoStepsNegativeIntensity); + } +); + +NSString *const kGPUImageRGBErosionRadiusThreeFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + vec4 twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate); + vec4 twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate); + vec4 threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate); + vec4 threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate); + + vec4 minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + minValue = min(minValue, twoStepsPositiveIntensity); + minValue = min(minValue, twoStepsNegativeIntensity); + minValue = min(minValue, threeStepsPositiveIntensity); + + gl_FragColor = min(minValue, threeStepsNegativeIntensity); + } +); + +NSString *const kGPUImageRGBErosionRadiusFourFragmentShaderString = SHADER_STRING +( + varying vec2 centerTextureCoordinate; + varying vec2 oneStepPositiveTextureCoordinate; + varying vec2 oneStepNegativeTextureCoordinate; + varying vec2 twoStepsPositiveTextureCoordinate; + varying vec2 twoStepsNegativeTextureCoordinate; + varying vec2 threeStepsPositiveTextureCoordinate; + varying vec2 threeStepsNegativeTextureCoordinate; + varying vec2 fourStepsPositiveTextureCoordinate; + varying vec2 fourStepsNegativeTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + vec4 centerIntensity = texture2D(inputImageTexture, centerTextureCoordinate); + vec4 oneStepPositiveIntensity = texture2D(inputImageTexture, oneStepPositiveTextureCoordinate); + vec4 oneStepNegativeIntensity = texture2D(inputImageTexture, oneStepNegativeTextureCoordinate); + vec4 twoStepsPositiveIntensity = texture2D(inputImageTexture, twoStepsPositiveTextureCoordinate); + vec4 twoStepsNegativeIntensity = texture2D(inputImageTexture, twoStepsNegativeTextureCoordinate); + vec4 threeStepsPositiveIntensity = texture2D(inputImageTexture, threeStepsPositiveTextureCoordinate); + vec4 threeStepsNegativeIntensity = texture2D(inputImageTexture, threeStepsNegativeTextureCoordinate); + vec4 fourStepsPositiveIntensity = texture2D(inputImageTexture, fourStepsPositiveTextureCoordinate); + vec4 fourStepsNegativeIntensity = texture2D(inputImageTexture, fourStepsNegativeTextureCoordinate); + + vec4 minValue = min(centerIntensity, oneStepPositiveIntensity); + minValue = min(minValue, oneStepNegativeIntensity); + minValue = min(minValue, twoStepsPositiveIntensity); + minValue = min(minValue, twoStepsNegativeIntensity); + minValue = min(minValue, threeStepsPositiveIntensity); + minValue = min(minValue, threeStepsNegativeIntensity); + minValue = min(minValue, fourStepsPositiveIntensity); + + gl_FragColor = min(minValue, fourStepsNegativeIntensity); + } +); +#endif + +@implementation GPUImageRGBErosionFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithRadius:(NSUInteger)erosionRadius; +{ + NSString *fragmentShaderForThisRadius = nil; + NSString *vertexShaderForThisRadius = nil; + + switch (erosionRadius) + { + case 0: + case 1: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusOneVertexShaderString; + fragmentShaderForThisRadius = kGPUImageRGBErosionRadiusOneFragmentShaderString; + }; break; + case 2: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusTwoVertexShaderString; + fragmentShaderForThisRadius = kGPUImageRGBErosionRadiusTwoFragmentShaderString; + }; break; + case 3: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusThreeVertexShaderString; + fragmentShaderForThisRadius = kGPUImageRGBErosionRadiusThreeFragmentShaderString; + }; break; + case 4: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusFourVertexShaderString; + fragmentShaderForThisRadius = kGPUImageRGBErosionRadiusFourFragmentShaderString; + }; break; + default: + { + vertexShaderForThisRadius = kGPUImageDilationRadiusFourVertexShaderString; + fragmentShaderForThisRadius = kGPUImageRGBErosionRadiusFourFragmentShaderString; + }; break; + } + + if (!(self = [super initWithFirstStageVertexShaderFromString:vertexShaderForThisRadius firstStageFragmentShaderFromString:fragmentShaderForThisRadius secondStageVertexShaderFromString:vertexShaderForThisRadius secondStageFragmentShaderFromString:fragmentShaderForThisRadius])) + { + return nil; + } + + return self; +} + +- (id)init; +{ + if (!(self = [self initWithRadius:1])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRGBFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageRGBFilter.h new file mode 100755 index 00000000..18966b1b --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRGBFilter.h @@ -0,0 +1,15 @@ +#import "GPUImageFilter.h" + +@interface GPUImageRGBFilter : GPUImageFilter +{ + GLint redUniform; + GLint greenUniform; + GLint blueUniform; +} + +// Normalized values by which each color channel is multiplied. The range is from 0.0 up, with 1.0 as the default. +@property (readwrite, nonatomic) CGFloat red; +@property (readwrite, nonatomic) CGFloat green; +@property (readwrite, nonatomic) CGFloat blue; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRGBFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageRGBFilter.m new file mode 100755 index 00000000..7a2e5681 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRGBFilter.m @@ -0,0 +1,89 @@ +#import "GPUImageRGBFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageRGBFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform highp float redAdjustment; + uniform highp float greenAdjustment; + uniform highp float blueAdjustment; + + void main() + { + highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4(textureColor.r * redAdjustment, textureColor.g * greenAdjustment, textureColor.b * blueAdjustment, textureColor.a); + } +); +#else +NSString *const kGPUImageRGBFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float redAdjustment; + uniform float greenAdjustment; + uniform float blueAdjustment; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + gl_FragColor = vec4(textureColor.r * redAdjustment, textureColor.g * greenAdjustment, textureColor.b * blueAdjustment, textureColor.a); + } + ); +#endif + +@implementation GPUImageRGBFilter + +@synthesize red = _red, blue = _blue, green = _green; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageRGBFragmentShaderString])) + { + return nil; + } + + redUniform = [filterProgram uniformIndex:@"redAdjustment"]; + self.red = 1.0; + + greenUniform = [filterProgram uniformIndex:@"greenAdjustment"]; + self.green = 1.0; + + blueUniform = [filterProgram uniformIndex:@"blueAdjustment"]; + self.blue = 1.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setRed:(CGFloat)newValue; +{ + _red = newValue; + + [self setFloat:_red forUniform:redUniform program:filterProgram]; +} + +- (void)setGreen:(CGFloat)newValue; +{ + _green = newValue; + + [self setFloat:_green forUniform:greenUniform program:filterProgram]; +} + +- (void)setBlue:(CGFloat)newValue; +{ + _blue = newValue; + + [self setFloat:_blue forUniform:blueUniform program:filterProgram]; +} + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRGBOpeningFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageRGBOpeningFilter.h new file mode 100644 index 00000000..dbec75fb --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRGBOpeningFilter.h @@ -0,0 +1,17 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImageRGBErosionFilter; +@class GPUImageRGBDilationFilter; + +// A filter that first performs an erosion on each color channel of an image, followed by a dilation of the same radius. +// This helps to filter out smaller bright elements. + +@interface GPUImageRGBOpeningFilter : GPUImageFilterGroup +{ + GPUImageRGBErosionFilter *erosionFilter; + GPUImageRGBDilationFilter *dilationFilter; +} + +- (id)initWithRadius:(NSUInteger)radius; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRGBOpeningFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageRGBOpeningFilter.m new file mode 100644 index 00000000..9d53021e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRGBOpeningFilter.m @@ -0,0 +1,41 @@ +#import "GPUImageRGBOpeningFilter.h" +#import "GPUImageRGBErosionFilter.h" +#import "GPUImageRGBDilationFilter.h" + +@implementation GPUImageRGBOpeningFilter + +- (id)init; +{ + if (!(self = [self initWithRadius:1])) + { + return nil; + } + + return self; +} + +- (id)initWithRadius:(NSUInteger)radius; +{ + if (!(self = [super init])) + { + return nil; + } + + // First pass: erosion + erosionFilter = [[GPUImageRGBErosionFilter alloc] initWithRadius:radius]; + [self addFilter:erosionFilter]; + + // Second pass: dilation + dilationFilter = [[GPUImageRGBDilationFilter alloc] initWithRadius:radius]; + [self addFilter:dilationFilter]; + + [erosionFilter addTarget:dilationFilter]; + + self.initialFilters = [NSArray arrayWithObjects:erosionFilter, nil]; + self.terminalFilter = dilationFilter; + + return self; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRawDataInput.h b/LFLiveKit/Vendor/GPUImage/GPUImageRawDataInput.h new file mode 100644 index 00000000..6ec4720f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRawDataInput.h @@ -0,0 +1,43 @@ +#import "GPUImageOutput.h" + +// The bytes passed into this input are not copied or retained, but you are free to deallocate them after they are used by this filter. +// The bytes are uploaded and stored within a texture, so nothing is kept locally. +// The default format for input bytes is GPUPixelFormatBGRA, unless specified with pixelFormat: +// The default type for input bytes is GPUPixelTypeUByte, unless specified with pixelType: + +typedef enum { + GPUPixelFormatBGRA = GL_BGRA, + GPUPixelFormatRGBA = GL_RGBA, + GPUPixelFormatRGB = GL_RGB, + GPUPixelFormatLuminance = GL_LUMINANCE +} GPUPixelFormat; + +typedef enum { + GPUPixelTypeUByte = GL_UNSIGNED_BYTE, + GPUPixelTypeFloat = GL_FLOAT +} GPUPixelType; + +@interface GPUImageRawDataInput : GPUImageOutput +{ + CGSize uploadedImageSize; + + dispatch_semaphore_t dataUpdateSemaphore; +} + +// Initialization and teardown +- (id)initWithBytes:(GLubyte *)bytesToUpload size:(CGSize)imageSize; +- (id)initWithBytes:(GLubyte *)bytesToUpload size:(CGSize)imageSize pixelFormat:(GPUPixelFormat)pixelFormat; +- (id)initWithBytes:(GLubyte *)bytesToUpload size:(CGSize)imageSize pixelFormat:(GPUPixelFormat)pixelFormat type:(GPUPixelType)pixelType; + +/** Input data pixel format + */ +@property (readwrite, nonatomic) GPUPixelFormat pixelFormat; +@property (readwrite, nonatomic) GPUPixelType pixelType; + +// Image rendering +- (void)updateDataFromBytes:(GLubyte *)bytesToUpload size:(CGSize)imageSize; +- (void)processData; +- (void)processDataForTimestamp:(CMTime)frameTime; +- (CGSize)outputImageSize; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRawDataInput.m b/LFLiveKit/Vendor/GPUImage/GPUImageRawDataInput.m new file mode 100644 index 00000000..cfa3b128 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRawDataInput.m @@ -0,0 +1,139 @@ +#import "GPUImageRawDataInput.h" + +@interface GPUImageRawDataInput() +- (void)uploadBytes:(GLubyte *)bytesToUpload; +@end + +@implementation GPUImageRawDataInput + +@synthesize pixelFormat = _pixelFormat; +@synthesize pixelType = _pixelType; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithBytes:(GLubyte *)bytesToUpload size:(CGSize)imageSize; +{ + if (!(self = [self initWithBytes:bytesToUpload size:imageSize pixelFormat:GPUPixelFormatBGRA type:GPUPixelTypeUByte])) + { + return nil; + } + + return self; +} + +- (id)initWithBytes:(GLubyte *)bytesToUpload size:(CGSize)imageSize pixelFormat:(GPUPixelFormat)pixelFormat; +{ + if (!(self = [self initWithBytes:bytesToUpload size:imageSize pixelFormat:pixelFormat type:GPUPixelTypeUByte])) + { + return nil; + } + + return self; +} + +- (id)initWithBytes:(GLubyte *)bytesToUpload size:(CGSize)imageSize pixelFormat:(GPUPixelFormat)pixelFormat type:(GPUPixelType)pixelType; +{ + if (!(self = [super init])) + { + return nil; + } + + dataUpdateSemaphore = dispatch_semaphore_create(1); + + uploadedImageSize = imageSize; + self.pixelFormat = pixelFormat; + self.pixelType = pixelType; + + [self uploadBytes:bytesToUpload]; + + return self; +} + +// ARC forbids explicit message send of 'release'; since iOS 6 even for dispatch_release() calls: stripping it out in that case is required. +- (void)dealloc; +{ +#if !OS_OBJECT_USE_OBJC + if (dataUpdateSemaphore != NULL) + { + dispatch_release(dataUpdateSemaphore); + } +#endif +} + +#pragma mark - +#pragma mark Image rendering + +- (void)uploadBytes:(GLubyte *)bytesToUpload; +{ + [GPUImageContext useImageProcessingContext]; + + // TODO: This probably isn't right, and will need to be corrected + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:uploadedImageSize textureOptions:self.outputTextureOptions onlyTexture:YES]; + + glBindTexture(GL_TEXTURE_2D, [outputFramebuffer texture]); + glTexImage2D(GL_TEXTURE_2D, 0, _pixelFormat, (int)uploadedImageSize.width, (int)uploadedImageSize.height, 0, (GLint)_pixelFormat, (GLenum)_pixelType, bytesToUpload); +} + +- (void)updateDataFromBytes:(GLubyte *)bytesToUpload size:(CGSize)imageSize; +{ + uploadedImageSize = imageSize; + + [self uploadBytes:bytesToUpload]; +} + +- (void)processData; +{ + if (dispatch_semaphore_wait(dataUpdateSemaphore, DISPATCH_TIME_NOW) != 0) + { + return; + } + + runAsynchronouslyOnVideoProcessingQueue(^{ + + CGSize pixelSizeOfImage = [self outputImageSize]; + + for (id currentTarget in targets) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger textureIndexOfTarget = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + [currentTarget setInputSize:pixelSizeOfImage atIndex:textureIndexOfTarget]; + [currentTarget setInputFramebuffer:outputFramebuffer atIndex:textureIndexOfTarget]; + [currentTarget newFrameReadyAtTime:kCMTimeInvalid atIndex:textureIndexOfTarget]; + } + + dispatch_semaphore_signal(dataUpdateSemaphore); + }); +} + +- (void)processDataForTimestamp:(CMTime)frameTime; +{ + if (dispatch_semaphore_wait(dataUpdateSemaphore, DISPATCH_TIME_NOW) != 0) + { + return; + } + + runAsynchronouslyOnVideoProcessingQueue(^{ + + CGSize pixelSizeOfImage = [self outputImageSize]; + + for (id currentTarget in targets) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger textureIndexOfTarget = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + [currentTarget setInputSize:pixelSizeOfImage atIndex:textureIndexOfTarget]; + [currentTarget newFrameReadyAtTime:frameTime atIndex:textureIndexOfTarget]; + } + + dispatch_semaphore_signal(dataUpdateSemaphore); + }); +} + +- (CGSize)outputImageSize; +{ + return uploadedImageSize; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRawDataOutput.h b/LFLiveKit/Vendor/GPUImage/GPUImageRawDataOutput.h new file mode 100755 index 00000000..5a4538c1 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRawDataOutput.h @@ -0,0 +1,44 @@ +#import +#import "GPUImageContext.h" + +struct GPUByteColorVector { + GLubyte red; + GLubyte green; + GLubyte blue; + GLubyte alpha; +}; +typedef struct GPUByteColorVector GPUByteColorVector; + +@protocol GPUImageRawDataProcessor; + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +@interface GPUImageRawDataOutput : NSObject { + CGSize imageSize; + GPUImageRotationMode inputRotation; + BOOL outputBGRA; +} +#else +@interface GPUImageRawDataOutput : NSObject { + CGSize imageSize; + GPUImageRotationMode inputRotation; + BOOL outputBGRA; +} +#endif + +@property(readonly) GLubyte *rawBytesForImage; +@property(nonatomic, copy) void(^newFrameAvailableBlock)(void); +@property(nonatomic) BOOL enabled; + +// Initialization and teardown +- (id)initWithImageSize:(CGSize)newImageSize resultsInBGRAFormat:(BOOL)resultsInBGRAFormat; + +// Data access +- (GPUByteColorVector)colorAtLocation:(CGPoint)locationInImage; +- (NSUInteger)bytesPerRowInOutput; + +- (void)setImageSize:(CGSize)newImageSize; + +- (void)lockFramebufferForReading; +- (void)unlockFramebufferAfterReading; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageRawDataOutput.m b/LFLiveKit/Vendor/GPUImage/GPUImageRawDataOutput.m new file mode 100755 index 00000000..18101e2c --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageRawDataOutput.m @@ -0,0 +1,307 @@ +#import "GPUImageRawDataOutput.h" + +#import "GPUImageContext.h" +#import "GLProgram.h" +#import "GPUImageFilter.h" +#import "GPUImageMovieWriter.h" + +@interface GPUImageRawDataOutput () +{ + GPUImageFramebuffer *firstInputFramebuffer, *outputFramebuffer, *retainedFramebuffer; + + BOOL hasReadFromTheCurrentFrame; + + GLProgram *dataProgram; + GLint dataPositionAttribute, dataTextureCoordinateAttribute; + GLint dataInputTextureUniform; + + GLubyte *_rawBytesForImage; + + BOOL lockNextFramebuffer; +} + +// Frame rendering +- (void)renderAtInternalSize; + +@end + +@implementation GPUImageRawDataOutput + +@synthesize rawBytesForImage = _rawBytesForImage; +@synthesize newFrameAvailableBlock = _newFrameAvailableBlock; +@synthesize enabled; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithImageSize:(CGSize)newImageSize resultsInBGRAFormat:(BOOL)resultsInBGRAFormat; +{ + if (!(self = [super init])) + { + return nil; + } + + self.enabled = YES; + lockNextFramebuffer = NO; + outputBGRA = resultsInBGRAFormat; + imageSize = newImageSize; + hasReadFromTheCurrentFrame = NO; + _rawBytesForImage = NULL; + inputRotation = kGPUImageNoRotation; + + [GPUImageContext useImageProcessingContext]; + if ( (outputBGRA && ![GPUImageContext supportsFastTextureUpload]) || (!outputBGRA && [GPUImageContext supportsFastTextureUpload]) ) + { + dataProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:kGPUImageVertexShaderString fragmentShaderString:kGPUImageColorSwizzlingFragmentShaderString]; + } + else + { + dataProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:kGPUImageVertexShaderString fragmentShaderString:kGPUImagePassthroughFragmentShaderString]; + } + + if (!dataProgram.initialized) + { + [dataProgram addAttribute:@"position"]; + [dataProgram addAttribute:@"inputTextureCoordinate"]; + + if (![dataProgram link]) + { + NSString *progLog = [dataProgram programLog]; + NSLog(@"Program link log: %@", progLog); + NSString *fragLog = [dataProgram fragmentShaderLog]; + NSLog(@"Fragment shader compile log: %@", fragLog); + NSString *vertLog = [dataProgram vertexShaderLog]; + NSLog(@"Vertex shader compile log: %@", vertLog); + dataProgram = nil; + NSAssert(NO, @"Filter shader link failed"); + } + } + + dataPositionAttribute = [dataProgram attributeIndex:@"position"]; + dataTextureCoordinateAttribute = [dataProgram attributeIndex:@"inputTextureCoordinate"]; + dataInputTextureUniform = [dataProgram uniformIndex:@"inputImageTexture"]; + + return self; +} + +- (void)dealloc +{ + if (_rawBytesForImage != NULL && (![GPUImageContext supportsFastTextureUpload])) + { + free(_rawBytesForImage); + _rawBytesForImage = NULL; + } +} + +#pragma mark - +#pragma mark Data access + +- (void)renderAtInternalSize; +{ + [GPUImageContext setActiveShaderProgram:dataProgram]; + + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:imageSize onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + + if(lockNextFramebuffer) + { + retainedFramebuffer = outputFramebuffer; + [retainedFramebuffer lock]; + [retainedFramebuffer lockForReading]; + lockNextFramebuffer = NO; + } + + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + static const GLfloat squareVertices[] = { + -1.0f, -1.0f, + 1.0f, -1.0f, + -1.0f, 1.0f, + 1.0f, 1.0f, + }; + + static const GLfloat textureCoordinates[] = { + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + }; + + glActiveTexture(GL_TEXTURE4); + glBindTexture(GL_TEXTURE_2D, [firstInputFramebuffer texture]); + glUniform1i(dataInputTextureUniform, 4); + + glVertexAttribPointer(dataPositionAttribute, 2, GL_FLOAT, 0, 0, squareVertices); + glVertexAttribPointer(dataTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + + glEnableVertexAttribArray(dataPositionAttribute); + glEnableVertexAttribArray(dataTextureCoordinateAttribute); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + [firstInputFramebuffer unlock]; +} + +- (GPUByteColorVector)colorAtLocation:(CGPoint)locationInImage; +{ + GPUByteColorVector *imageColorBytes = (GPUByteColorVector *)self.rawBytesForImage; +// NSLog(@"Row start"); +// for (unsigned int currentXPosition = 0; currentXPosition < (imageSize.width * 2.0); currentXPosition++) +// { +// GPUByteColorVector byteAtPosition = imageColorBytes[currentXPosition]; +// NSLog(@"%d - %d, %d, %d", currentXPosition, byteAtPosition.red, byteAtPosition.green, byteAtPosition.blue); +// } +// NSLog(@"Row end"); + +// GPUByteColorVector byteAtOne = imageColorBytes[1]; +// GPUByteColorVector byteAtWidth = imageColorBytes[(int)imageSize.width - 3]; +// GPUByteColorVector byteAtHeight = imageColorBytes[(int)(imageSize.height - 1) * (int)imageSize.width]; +// NSLog(@"Byte 1: %d, %d, %d, byte 2: %d, %d, %d, byte 3: %d, %d, %d", byteAtOne.red, byteAtOne.green, byteAtOne.blue, byteAtWidth.red, byteAtWidth.green, byteAtWidth.blue, byteAtHeight.red, byteAtHeight.green, byteAtHeight.blue); + + CGPoint locationToPickFrom = CGPointZero; + locationToPickFrom.x = MIN(MAX(locationInImage.x, 0.0), (imageSize.width - 1.0)); + locationToPickFrom.y = MIN(MAX((imageSize.height - locationInImage.y), 0.0), (imageSize.height - 1.0)); + + if (outputBGRA) + { + GPUByteColorVector flippedColor = imageColorBytes[(int)(round((locationToPickFrom.y * imageSize.width) + locationToPickFrom.x))]; + GLubyte temporaryRed = flippedColor.red; + + flippedColor.red = flippedColor.blue; + flippedColor.blue = temporaryRed; + + return flippedColor; + } + else + { + return imageColorBytes[(int)(round((locationToPickFrom.y * imageSize.width) + locationToPickFrom.x))]; + } +} + +#pragma mark - +#pragma mark GPUImageInput protocol + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + hasReadFromTheCurrentFrame = NO; + + if (_newFrameAvailableBlock != NULL) + { + _newFrameAvailableBlock(); + } +} + +- (NSInteger)nextAvailableTextureIndex; +{ + return 0; +} + +- (void)setInputFramebuffer:(GPUImageFramebuffer *)newInputFramebuffer atIndex:(NSInteger)textureIndex; +{ + firstInputFramebuffer = newInputFramebuffer; + [firstInputFramebuffer lock]; +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + inputRotation = newInputRotation; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ +} + +- (CGSize)maximumOutputSize; +{ + return imageSize; +} + +- (void)endProcessing; +{ +} + +- (BOOL)shouldIgnoreUpdatesToThisTarget; +{ + return NO; +} + +- (BOOL)wantsMonochromeInput; +{ + return NO; +} + +- (void)setCurrentlyReceivingMonochromeInput:(BOOL)newValue; +{ + +} + +#pragma mark - +#pragma mark Accessors + +- (GLubyte *)rawBytesForImage; +{ + if ( (_rawBytesForImage == NULL) && (![GPUImageContext supportsFastTextureUpload]) ) + { + _rawBytesForImage = (GLubyte *) calloc(imageSize.width * imageSize.height * 4, sizeof(GLubyte)); + hasReadFromTheCurrentFrame = NO; + } + + if (hasReadFromTheCurrentFrame) + { + return _rawBytesForImage; + } + else + { + runSynchronouslyOnVideoProcessingQueue(^{ + // Note: the fast texture caches speed up 640x480 frame reads from 9.6 ms to 3.1 ms on iPhone 4S + + [GPUImageContext useImageProcessingContext]; + [self renderAtInternalSize]; + + if ([GPUImageContext supportsFastTextureUpload]) + { + glFinish(); + _rawBytesForImage = [outputFramebuffer byteBuffer]; + } + else + { + glReadPixels(0, 0, imageSize.width, imageSize.height, GL_RGBA, GL_UNSIGNED_BYTE, _rawBytesForImage); + // GL_EXT_read_format_bgra + // glReadPixels(0, 0, imageSize.width, imageSize.height, GL_BGRA_EXT, GL_UNSIGNED_BYTE, _rawBytesForImage); + } + + hasReadFromTheCurrentFrame = YES; + + }); + + return _rawBytesForImage; + } +} + +- (NSUInteger)bytesPerRowInOutput; +{ + return [retainedFramebuffer bytesPerRow]; +} + +- (void)setImageSize:(CGSize)newImageSize { + imageSize = newImageSize; + if (_rawBytesForImage != NULL && (![GPUImageContext supportsFastTextureUpload])) + { + free(_rawBytesForImage); + _rawBytesForImage = NULL; + } +} + +- (void)lockFramebufferForReading; +{ + lockNextFramebuffer = YES; +} + +- (void)unlockFramebufferAfterReading; +{ + [retainedFramebuffer unlockAfterReading]; + [retainedFramebuffer unlock]; + retainedFramebuffer = nil; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSaturationBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSaturationBlendFilter.h new file mode 100644 index 00000000..767892a5 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSaturationBlendFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageSaturationBlendFilter : GPUImageTwoInputFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSaturationBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSaturationBlendFilter.m new file mode 100644 index 00000000..da37f6aa --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSaturationBlendFilter.m @@ -0,0 +1,213 @@ +#import "GPUImageSaturationBlendFilter.h" + +/** + * Saturation blend mode based upon pseudo code from the PDF specification. + */ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSaturationBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + highp float lum(lowp vec3 c) { + return dot(c, vec3(0.3, 0.59, 0.11)); + } + + lowp vec3 clipcolor(lowp vec3 c) { + highp float l = lum(c); + lowp float n = min(min(c.r, c.g), c.b); + lowp float x = max(max(c.r, c.g), c.b); + + if (n < 0.0) { + c.r = l + ((c.r - l) * l) / (l - n); + c.g = l + ((c.g - l) * l) / (l - n); + c.b = l + ((c.b - l) * l) / (l - n); + } + if (x > 1.0) { + c.r = l + ((c.r - l) * (1.0 - l)) / (x - l); + c.g = l + ((c.g - l) * (1.0 - l)) / (x - l); + c.b = l + ((c.b - l) * (1.0 - l)) / (x - l); + } + + return c; + } + + lowp vec3 setlum(lowp vec3 c, highp float l) { + highp float d = l - lum(c); + c = c + vec3(d); + return clipcolor(c); + } + + highp float sat(lowp vec3 c) { + lowp float n = min(min(c.r, c.g), c.b); + lowp float x = max(max(c.r, c.g), c.b); + return x - n; + } + + lowp float mid(lowp float cmin, lowp float cmid, lowp float cmax, highp float s) { + return ((cmid - cmin) * s) / (cmax - cmin); + } + + lowp vec3 setsat(lowp vec3 c, highp float s) { + if (c.r > c.g) { + if (c.r > c.b) { + if (c.g > c.b) { + /* g is mid, b is min */ + c.g = mid(c.b, c.g, c.r, s); + c.b = 0.0; + } else { + /* b is mid, g is min */ + c.b = mid(c.g, c.b, c.r, s); + c.g = 0.0; + } + c.r = s; + } else { + /* b is max, r is mid, g is min */ + c.r = mid(c.g, c.r, c.b, s); + c.b = s; + c.r = 0.0; + } + } else if (c.r > c.b) { + /* g is max, r is mid, b is min */ + c.r = mid(c.b, c.r, c.g, s); + c.g = s; + c.b = 0.0; + } else if (c.g > c.b) { + /* g is max, b is mid, r is min */ + c.b = mid(c.r, c.b, c.g, s); + c.g = s; + c.r = 0.0; + } else if (c.b > c.g) { + /* b is max, g is mid, r is min */ + c.g = mid(c.r, c.g, c.b, s); + c.b = s; + c.r = 0.0; + } else { + c = vec3(0.0); + } + return c; + } + + void main() + { + highp vec4 baseColor = texture2D(inputImageTexture, textureCoordinate); + highp vec4 overlayColor = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(baseColor.rgb * (1.0 - overlayColor.a) + setlum(setsat(baseColor.rgb, sat(overlayColor.rgb)), lum(baseColor.rgb)) * overlayColor.a, baseColor.a); + } +); +#else +NSString *const kGPUImageSaturationBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + float lum(vec3 c) { + return dot(c, vec3(0.3, 0.59, 0.11)); + } + + vec3 clipcolor(vec3 c) { + float l = lum(c); + float n = min(min(c.r, c.g), c.b); + float x = max(max(c.r, c.g), c.b); + + if (n < 0.0) { + c.r = l + ((c.r - l) * l) / (l - n); + c.g = l + ((c.g - l) * l) / (l - n); + c.b = l + ((c.b - l) * l) / (l - n); + } + if (x > 1.0) { + c.r = l + ((c.r - l) * (1.0 - l)) / (x - l); + c.g = l + ((c.g - l) * (1.0 - l)) / (x - l); + c.b = l + ((c.b - l) * (1.0 - l)) / (x - l); + } + + return c; + } + + vec3 setlum(vec3 c, float l) { + float d = l - lum(c); + c = c + vec3(d); + return clipcolor(c); + } + + float sat(vec3 c) { + float n = min(min(c.r, c.g), c.b); + float x = max(max(c.r, c.g), c.b); + return x - n; + } + + float mid(float cmin, float cmid, float cmax, float s) { + return ((cmid - cmin) * s) / (cmax - cmin); + } + + vec3 setsat(vec3 c, float s) { + if (c.r > c.g) { + if (c.r > c.b) { + if (c.g > c.b) { + /* g is mid, b is min */ + c.g = mid(c.b, c.g, c.r, s); + c.b = 0.0; + } else { + /* b is mid, g is min */ + c.b = mid(c.g, c.b, c.r, s); + c.g = 0.0; + } + c.r = s; + } else { + /* b is max, r is mid, g is min */ + c.r = mid(c.g, c.r, c.b, s); + c.b = s; + c.r = 0.0; + } + } else if (c.r > c.b) { + /* g is max, r is mid, b is min */ + c.r = mid(c.b, c.r, c.g, s); + c.g = s; + c.b = 0.0; + } else if (c.g > c.b) { + /* g is max, b is mid, r is min */ + c.b = mid(c.r, c.b, c.g, s); + c.g = s; + c.r = 0.0; + } else if (c.b > c.g) { + /* b is max, g is mid, r is min */ + c.g = mid(c.r, c.g, c.b, s); + c.b = s; + c.r = 0.0; + } else { + c = vec3(0.0); + } + return c; + } + + void main() + { + vec4 baseColor = texture2D(inputImageTexture, textureCoordinate); + vec4 overlayColor = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(baseColor.rgb * (1.0 - overlayColor.a) + setlum(setsat(baseColor.rgb, sat(overlayColor.rgb)), lum(baseColor.rgb)) * overlayColor.a, baseColor.a); + } +); +#endif + + +@implementation GPUImageSaturationBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageSaturationBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSaturationFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSaturationFilter.h new file mode 100755 index 00000000..1c6ff5bd --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSaturationFilter.h @@ -0,0 +1,14 @@ +#import "GPUImageFilter.h" + +/** Adjusts the saturation of an image + */ +@interface GPUImageSaturationFilter : GPUImageFilter +{ + GLint saturationUniform; +} + +/** Saturation ranges from 0.0 (fully desaturated) to 2.0 (max saturation), with 1.0 as the normal level + */ +@property(readwrite, nonatomic) CGFloat saturation; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSaturationFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSaturationFilter.m new file mode 100755 index 00000000..fc373d4a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSaturationFilter.m @@ -0,0 +1,78 @@ +#import "GPUImageSaturationFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSaturationFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform lowp float saturation; + + // Values from "Graphics Shaders: Theory and Practice" by Bailey and Cunningham + const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp float luminance = dot(textureColor.rgb, luminanceWeighting); + lowp vec3 greyScaleColor = vec3(luminance); + + gl_FragColor = vec4(mix(greyScaleColor, textureColor.rgb, saturation), textureColor.w); + + } +); +#else +NSString *const kGPUImageSaturationFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float saturation; + + // Values from "Graphics Shaders: Theory and Practice" by Bailey and Cunningham + const vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, luminanceWeighting); + vec3 greyScaleColor = vec3(luminance); + + gl_FragColor = vec4(mix(greyScaleColor, textureColor.rgb, saturation), textureColor.w); + + } + ); +#endif + +@implementation GPUImageSaturationFilter + +@synthesize saturation = _saturation; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageSaturationFragmentShaderString])) + { + return nil; + } + + saturationUniform = [filterProgram uniformIndex:@"saturation"]; + self.saturation = 1.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setSaturation:(CGFloat)newValue; +{ + _saturation = newValue; + + [self setFloat:_saturation forUniform:saturationUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageScreenBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageScreenBlendFilter.h new file mode 100755 index 00000000..2df3abf3 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageScreenBlendFilter.h @@ -0,0 +1,7 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageScreenBlendFilter : GPUImageTwoInputFilter +{ +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageScreenBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageScreenBlendFilter.m new file mode 100755 index 00000000..d871e7db --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageScreenBlendFilter.m @@ -0,0 +1,52 @@ +#import "GPUImageScreenBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageScreenBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + mediump vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + mediump vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + mediump vec4 whiteColor = vec4(1.0); + gl_FragColor = whiteColor - ((whiteColor - textureColor2) * (whiteColor - textureColor)); + } +); +#else +NSString *const kGPUImageScreenBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + vec4 whiteColor = vec4(1.0); + gl_FragColor = whiteColor - ((whiteColor - textureColor2) * (whiteColor - textureColor)); + } +); +#endif + +@implementation GPUImageScreenBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageScreenBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSepiaFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSepiaFilter.h new file mode 100755 index 00000000..a45164fe --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSepiaFilter.h @@ -0,0 +1,6 @@ +#import "GPUImageColorMatrixFilter.h" + +/// Simple sepia tone filter +@interface GPUImageSepiaFilter : GPUImageColorMatrixFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSepiaFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSepiaFilter.m new file mode 100755 index 00000000..71668d63 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSepiaFilter.m @@ -0,0 +1,24 @@ +#import "GPUImageSepiaFilter.h" + +@implementation GPUImageSepiaFilter + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + self.intensity = 1.0; + self.colorMatrix = (GPUMatrix4x4){ + {0.3588, 0.7044, 0.1368, 0.0}, + {0.2990, 0.5870, 0.1140, 0.0}, + {0.2392, 0.4696, 0.0912 ,0.0}, + {0,0,0,1.0}, + }; + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSharpenFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSharpenFilter.h new file mode 100755 index 00000000..739df503 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSharpenFilter.h @@ -0,0 +1,12 @@ +#import "GPUImageFilter.h" + +@interface GPUImageSharpenFilter : GPUImageFilter +{ + GLint sharpnessUniform; + GLint imageWidthFactorUniform, imageHeightFactorUniform; +} + +// Sharpness ranges from -4.0 to 4.0, with 0.0 as the normal level +@property(readwrite, nonatomic) CGFloat sharpness; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSharpenFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSharpenFilter.m new file mode 100755 index 00000000..6d7367a9 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSharpenFilter.m @@ -0,0 +1,147 @@ +#import "GPUImageSharpenFilter.h" + +NSString *const kGPUImageSharpenVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + + uniform float imageWidthFactor; + uniform float imageHeightFactor; + uniform float sharpness; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + varying vec2 topTextureCoordinate; + varying vec2 bottomTextureCoordinate; + + varying float centerMultiplier; + varying float edgeMultiplier; + + void main() + { + gl_Position = position; + + vec2 widthStep = vec2(imageWidthFactor, 0.0); + vec2 heightStep = vec2(0.0, imageHeightFactor); + + textureCoordinate = inputTextureCoordinate.xy; + leftTextureCoordinate = inputTextureCoordinate.xy - widthStep; + rightTextureCoordinate = inputTextureCoordinate.xy + widthStep; + topTextureCoordinate = inputTextureCoordinate.xy + heightStep; + bottomTextureCoordinate = inputTextureCoordinate.xy - heightStep; + + centerMultiplier = 1.0 + 4.0 * sharpness; + edgeMultiplier = sharpness; + } +); + + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSharpenFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying highp vec2 textureCoordinate; + varying highp vec2 leftTextureCoordinate; + varying highp vec2 rightTextureCoordinate; + varying highp vec2 topTextureCoordinate; + varying highp vec2 bottomTextureCoordinate; + + varying highp float centerMultiplier; + varying highp float edgeMultiplier; + + uniform sampler2D inputImageTexture; + + void main() + { + mediump vec3 textureColor = texture2D(inputImageTexture, textureCoordinate).rgb; + mediump vec3 leftTextureColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + mediump vec3 rightTextureColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; + mediump vec3 topTextureColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; + mediump vec3 bottomTextureColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + + gl_FragColor = vec4((textureColor * centerMultiplier - (leftTextureColor * edgeMultiplier + rightTextureColor * edgeMultiplier + topTextureColor * edgeMultiplier + bottomTextureColor * edgeMultiplier)), texture2D(inputImageTexture, bottomTextureCoordinate).w); + } +); +#else +NSString *const kGPUImageSharpenFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + varying vec2 topTextureCoordinate; + varying vec2 bottomTextureCoordinate; + + varying float centerMultiplier; + varying float edgeMultiplier; + + uniform sampler2D inputImageTexture; + + void main() + { + vec3 textureColor = texture2D(inputImageTexture, textureCoordinate).rgb; + vec3 leftTextureColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + vec3 rightTextureColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; + vec3 topTextureColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; + vec3 bottomTextureColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + + gl_FragColor = vec4((textureColor * centerMultiplier - (leftTextureColor * edgeMultiplier + rightTextureColor * edgeMultiplier + topTextureColor * edgeMultiplier + bottomTextureColor * edgeMultiplier)), texture2D(inputImageTexture, bottomTextureCoordinate).w); + } +); +#endif + + +@implementation GPUImageSharpenFilter + +@synthesize sharpness = _sharpness; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithVertexShaderFromString:kGPUImageSharpenVertexShaderString fragmentShaderFromString:kGPUImageSharpenFragmentShaderString])) + { + return nil; + } + + sharpnessUniform = [filterProgram uniformIndex:@"sharpness"]; + self.sharpness = 0.0; + + imageWidthFactorUniform = [filterProgram uniformIndex:@"imageWidthFactor"]; + imageHeightFactorUniform = [filterProgram uniformIndex:@"imageHeightFactor"]; + + return self; +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:filterProgram]; + + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + glUniform1f(imageWidthFactorUniform, 1.0 / filterFrameSize.height); + glUniform1f(imageHeightFactorUniform, 1.0 / filterFrameSize.width); + } + else + { + glUniform1f(imageWidthFactorUniform, 1.0 / filterFrameSize.width); + glUniform1f(imageHeightFactorUniform, 1.0 / filterFrameSize.height); + } + }); +} + +#pragma mark - +#pragma mark Accessors + +- (void)setSharpness:(CGFloat)newValue; +{ + _sharpness = newValue; + + [self setFloat:_sharpness forUniform:sharpnessUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageShiTomasiFeatureDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageShiTomasiFeatureDetectionFilter.h new file mode 100644 index 00000000..b16ebc01 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageShiTomasiFeatureDetectionFilter.h @@ -0,0 +1,13 @@ +#import "GPUImageHarrisCornerDetectionFilter.h" + +/** Shi-Tomasi feature detector + + This is the Shi-Tomasi feature detector, as described in + J. Shi and C. Tomasi. Good features to track. Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 593-600, June 1994. + */ + +@interface GPUImageShiTomasiFeatureDetectionFilter : GPUImageHarrisCornerDetectionFilter + +// Compared to the Harris corner detector, the default sensitivity value for this detector is set to 1.5 + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageShiTomasiFeatureDetectionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageShiTomasiFeatureDetectionFilter.m new file mode 100644 index 00000000..e58cbb4f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageShiTomasiFeatureDetectionFilter.m @@ -0,0 +1,65 @@ +#import "GPUImageShiTomasiFeatureDetectionFilter.h" + +@implementation GPUImageShiTomasiFeatureDetectionFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageShiTomasiCornerDetectionFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform lowp float sensitivity; + + void main() + { + mediump vec3 derivativeElements = texture2D(inputImageTexture, textureCoordinate).rgb; + + mediump float derivativeDifference = derivativeElements.x - derivativeElements.y; + mediump float zElement = (derivativeElements.z * 2.0) - 1.0; + + // R = Ix^2 + Iy^2 - sqrt( (Ix^2 - Iy^2)^2 + 4 * Ixy * Ixy) + mediump float cornerness = derivativeElements.x + derivativeElements.y - sqrt(derivativeDifference * derivativeDifference + 4.0 * zElement * zElement); + + gl_FragColor = vec4(vec3(cornerness * sensitivity), 1.0); + } +); +#else +NSString *const kGPUImageShiTomasiCornerDetectionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float sensitivity; + + void main() + { + vec3 derivativeElements = texture2D(inputImageTexture, textureCoordinate).rgb; + + float derivativeDifference = derivativeElements.x - derivativeElements.y; + float zElement = (derivativeElements.z * 2.0) - 1.0; + + // R = Ix^2 + Iy^2 - sqrt( (Ix^2 - Iy^2)^2 + 4 * Ixy * Ixy) + float cornerness = derivativeElements.x + derivativeElements.y - sqrt(derivativeDifference * derivativeDifference + 4.0 * zElement * zElement); + + gl_FragColor = vec4(vec3(cornerness * sensitivity), 1.0); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithCornerDetectionFragmentShader:kGPUImageShiTomasiCornerDetectionFragmentShaderString])) + { + return nil; + } + + self.sensitivity = 1.5; + + return self; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSingleComponentGaussianBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSingleComponentGaussianBlurFilter.h new file mode 100644 index 00000000..934b1e3a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSingleComponentGaussianBlurFilter.h @@ -0,0 +1,7 @@ +#import "GPUImageGaussianBlurFilter.h" + +// This filter merely performs the standard Gaussian blur on the red color channel (assuming a luminance image) + +@interface GPUImageSingleComponentGaussianBlurFilter : GPUImageGaussianBlurFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSingleComponentGaussianBlurFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSingleComponentGaussianBlurFilter.m new file mode 100644 index 00000000..4ff0d91d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSingleComponentGaussianBlurFilter.m @@ -0,0 +1,189 @@ +#import "GPUImageSingleComponentGaussianBlurFilter.h" + +@implementation GPUImageSingleComponentGaussianBlurFilter + ++ (NSString *)vertexShaderForOptimizedBlurOfRadius:(NSUInteger)blurRadius sigma:(CGFloat)sigma; +{ + if (blurRadius < 1) + { + return kGPUImageVertexShaderString; + } + + // First, generate the normal Gaussian weights for a given sigma + GLfloat *standardGaussianWeights = calloc(blurRadius + 1, sizeof(GLfloat)); + GLfloat sumOfWeights = 0.0; + for (NSUInteger currentGaussianWeightIndex = 0; currentGaussianWeightIndex < blurRadius + 1; currentGaussianWeightIndex++) + { + standardGaussianWeights[currentGaussianWeightIndex] = (1.0 / sqrt(2.0 * M_PI * pow(sigma, 2.0))) * exp(-pow(currentGaussianWeightIndex, 2.0) / (2.0 * pow(sigma, 2.0))); + + if (currentGaussianWeightIndex == 0) + { + sumOfWeights += standardGaussianWeights[currentGaussianWeightIndex]; + } + else + { + sumOfWeights += 2.0 * standardGaussianWeights[currentGaussianWeightIndex]; + } + } + + // Next, normalize these weights to prevent the clipping of the Gaussian curve at the end of the discrete samples from reducing luminance + for (NSUInteger currentGaussianWeightIndex = 0; currentGaussianWeightIndex < blurRadius + 1; currentGaussianWeightIndex++) + { + standardGaussianWeights[currentGaussianWeightIndex] = standardGaussianWeights[currentGaussianWeightIndex] / sumOfWeights; + } + + // From these weights we calculate the offsets to read interpolated values from + NSUInteger numberOfOptimizedOffsets = MIN(blurRadius / 2 + (blurRadius % 2), 7); + GLfloat *optimizedGaussianOffsets = calloc(numberOfOptimizedOffsets, sizeof(GLfloat)); + + for (NSUInteger currentOptimizedOffset = 0; currentOptimizedOffset < numberOfOptimizedOffsets; currentOptimizedOffset++) + { + GLfloat firstWeight = standardGaussianWeights[currentOptimizedOffset*2 + 1]; + GLfloat secondWeight = standardGaussianWeights[currentOptimizedOffset*2 + 2]; + + GLfloat optimizedWeight = firstWeight + secondWeight; + + optimizedGaussianOffsets[currentOptimizedOffset] = (firstWeight * (currentOptimizedOffset*2 + 1) + secondWeight * (currentOptimizedOffset*2 + 2)) / optimizedWeight; + } + + NSMutableString *shaderString = [[NSMutableString alloc] init]; + // Header + [shaderString appendFormat:@"\ + attribute vec4 position;\n\ + attribute vec4 inputTextureCoordinate;\n\ + \n\ + uniform float texelWidthOffset;\n\ + uniform float texelHeightOffset;\n\ + \n\ + varying vec2 blurCoordinates[%lu];\n\ + \n\ + void main()\n\ + {\n\ + gl_Position = position;\n\ + \n\ + vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset);\n", (unsigned long)(1 + (numberOfOptimizedOffsets * 2))]; + + // Inner offset loop + [shaderString appendString:@"blurCoordinates[0] = inputTextureCoordinate.xy;\n"]; + for (NSUInteger currentOptimizedOffset = 0; currentOptimizedOffset < numberOfOptimizedOffsets; currentOptimizedOffset++) + { + [shaderString appendFormat:@"\ + blurCoordinates[%lu] = inputTextureCoordinate.xy + singleStepOffset * %f;\n\ + blurCoordinates[%lu] = inputTextureCoordinate.xy - singleStepOffset * %f;\n", (unsigned long)((currentOptimizedOffset * 2) + 1), optimizedGaussianOffsets[currentOptimizedOffset], (unsigned long)((currentOptimizedOffset * 2) + 2), optimizedGaussianOffsets[currentOptimizedOffset]]; + } + + // Footer + [shaderString appendString:@"}\n"]; + + free(optimizedGaussianOffsets); + free(standardGaussianWeights); + return shaderString; +} + ++ (NSString *)fragmentShaderForOptimizedBlurOfRadius:(NSUInteger)blurRadius sigma:(CGFloat)sigma; +{ + if (blurRadius < 1) + { + return kGPUImagePassthroughFragmentShaderString; + } + + // First, generate the normal Gaussian weights for a given sigma + GLfloat *standardGaussianWeights = calloc(blurRadius + 1, sizeof(GLfloat)); + GLfloat sumOfWeights = 0.0; + for (NSUInteger currentGaussianWeightIndex = 0; currentGaussianWeightIndex < blurRadius + 1; currentGaussianWeightIndex++) + { + standardGaussianWeights[currentGaussianWeightIndex] = (1.0 / sqrt(2.0 * M_PI * pow(sigma, 2.0))) * exp(-pow(currentGaussianWeightIndex, 2.0) / (2.0 * pow(sigma, 2.0))); + + if (currentGaussianWeightIndex == 0) + { + sumOfWeights += standardGaussianWeights[currentGaussianWeightIndex]; + } + else + { + sumOfWeights += 2.0 * standardGaussianWeights[currentGaussianWeightIndex]; + } + } + + // Next, normalize these weights to prevent the clipping of the Gaussian curve at the end of the discrete samples from reducing luminance + for (NSUInteger currentGaussianWeightIndex = 0; currentGaussianWeightIndex < blurRadius + 1; currentGaussianWeightIndex++) + { + standardGaussianWeights[currentGaussianWeightIndex] = standardGaussianWeights[currentGaussianWeightIndex] / sumOfWeights; + } + + // From these weights we calculate the offsets to read interpolated values from + NSUInteger numberOfOptimizedOffsets = MIN(blurRadius / 2 + (blurRadius % 2), 7); + NSUInteger trueNumberOfOptimizedOffsets = blurRadius / 2 + (blurRadius % 2); + + NSMutableString *shaderString = [[NSMutableString alloc] init]; + + // Header +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [shaderString appendFormat:@"\ + uniform sampler2D inputImageTexture;\n\ + uniform highp float texelWidthOffset;\n\ + uniform highp float texelHeightOffset;\n\ + \n\ + varying highp vec2 blurCoordinates[%lu];\n\ + \n\ + void main()\n\ + {\n\ + lowp float sum = 0.0;\n", (unsigned long)(1 + (numberOfOptimizedOffsets * 2)) ]; +#else + [shaderString appendFormat:@"\ + uniform sampler2D inputImageTexture;\n\ + uniform float texelWidthOffset;\n\ + uniform float texelHeightOffset;\n\ + \n\ + varying vec2 blurCoordinates[%lu];\n\ + \n\ + void main()\n\ + {\n\ + float sum = 0.0;\n", 1 + (numberOfOptimizedOffsets * 2) ]; +#endif + + // Inner texture loop + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[0]).r * %f;\n", standardGaussianWeights[0]]; + + for (NSUInteger currentBlurCoordinateIndex = 0; currentBlurCoordinateIndex < numberOfOptimizedOffsets; currentBlurCoordinateIndex++) + { + GLfloat firstWeight = standardGaussianWeights[currentBlurCoordinateIndex * 2 + 1]; + GLfloat secondWeight = standardGaussianWeights[currentBlurCoordinateIndex * 2 + 2]; + GLfloat optimizedWeight = firstWeight + secondWeight; + + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[%lu]).r * %f;\n", (unsigned long)((currentBlurCoordinateIndex * 2) + 1), optimizedWeight]; + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[%lu]).r * %f;\n", (unsigned long)((currentBlurCoordinateIndex * 2) + 2), optimizedWeight]; + } + + // If the number of required samples exceeds the amount we can pass in via varyings, we have to do dependent texture reads in the fragment shader + if (trueNumberOfOptimizedOffsets > numberOfOptimizedOffsets) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [shaderString appendString:@"highp vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset);\n"]; +#else + [shaderString appendString:@"highp vec2 singleStepOffset = vec2(texelWidthOffset, texelHeightOffset);\n"]; +#endif + + for (NSUInteger currentOverlowTextureRead = numberOfOptimizedOffsets; currentOverlowTextureRead < trueNumberOfOptimizedOffsets; currentOverlowTextureRead++) + { + GLfloat firstWeight = standardGaussianWeights[currentOverlowTextureRead * 2 + 1]; + GLfloat secondWeight = standardGaussianWeights[currentOverlowTextureRead * 2 + 2]; + + GLfloat optimizedWeight = firstWeight + secondWeight; + GLfloat optimizedOffset = (firstWeight * (currentOverlowTextureRead * 2 + 1) + secondWeight * (currentOverlowTextureRead * 2 + 2)) / optimizedWeight; + + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[0] + singleStepOffset * %f).r * %f;\n", optimizedOffset, optimizedWeight]; + [shaderString appendFormat:@"sum += texture2D(inputImageTexture, blurCoordinates[0] - singleStepOffset * %f).r * %f;\n", optimizedOffset, optimizedWeight]; + } + } + + // Footer + [shaderString appendString:@"\ + gl_FragColor = vec4(sum, sum, sum, 1.0);\n\ + }\n"]; + + free(standardGaussianWeights); + return shaderString; +} + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSketchFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSketchFilter.h new file mode 100755 index 00000000..598145ae --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSketchFilter.h @@ -0,0 +1,11 @@ +#import "GPUImageSobelEdgeDetectionFilter.h" + +/** Converts video to look like a sketch. + + This is just the Sobel edge detection filter with the colors inverted. + */ +@interface GPUImageSketchFilter : GPUImageSobelEdgeDetectionFilter +{ +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSketchFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSketchFilter.m new file mode 100755 index 00000000..3cda2203 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSketchFilter.m @@ -0,0 +1,98 @@ +#import "GPUImageSketchFilter.h" + +@implementation GPUImageSketchFilter + +// Invert the colorspace for a sketch +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSketchFragmentShaderString = SHADER_STRING +( + precision mediump float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform float edgeStrength; + + uniform sampler2D inputImageTexture; + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; + float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; + + float mag = 1.0 - (length(vec2(h, v)) * edgeStrength); + + gl_FragColor = vec4(vec3(mag), 1.0); + } +); +#else +NSString *const kGPUImageSketchFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform float edgeStrength; + + uniform sampler2D inputImageTexture; + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; + float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; + + float mag = 1.0 - (length(vec2(h, v)) * edgeStrength); + + gl_FragColor = vec4(vec3(mag), 1.0); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImageSketchFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSkinToneFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSkinToneFilter.h new file mode 100644 index 00000000..0dd6f866 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSkinToneFilter.h @@ -0,0 +1,47 @@ +// +// GPUImageSkinToneFilter.h +// +// +// Created by github.com/r3mus on 8/14/15. +// +// + +#import "GPUImageTwoInputFilter.h" + +typedef NS_ENUM(NSUInteger, GPUImageSkinToneUpperColor) { + GPUImageSkinToneUpperColorGreen, + GPUImageSkinToneUpperColorOrange +}; + +extern NSString *const kGPUImageSkinToneFragmentShaderString; + +@interface GPUImageSkinToneFilter : GPUImageFilter +{ + GLint skinToneAdjustUniform; + GLint skinHueUniform; + GLint skinHueThresholdUniform; + GLint maxHueShiftUniform; + GLint maxSaturationShiftUniform; + GLint upperSkinToneColorUniform; +} + +// The amount of effect to apply, between -1.0 (pink) and +1.0 (orange OR green). Default is 0.0. +@property (nonatomic, readwrite) CGFloat skinToneAdjust; + +// The initial hue of skin to adjust. Default is 0.05 (a common skin red). +@property (nonatomic, readwrite) CGFloat skinHue; + +// The bell curve "breadth" of the skin hue adjustment (i.e. how different from the original skinHue will the modifications effect). +// Default is 40.0 +@property (nonatomic, readwrite) CGFloat skinHueThreshold; + +// The maximum amount of hue shift allowed in the adjustments that affect hue (pink, green). Default = 0.25. +@property (nonatomic, readwrite) CGFloat maxHueShift; + +// The maximum amount of saturation shift allowed in the adjustments that affect saturation (orange). Default = 0.4. +@property (nonatomic, readwrite) CGFloat maxSaturationShift; + +// Defines whether the upper range (> 0.0) will change the skin tone to green (hue) or orange (saturation) +@property (nonatomic, readwrite) GPUImageSkinToneUpperColor upperSkinToneColor; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSkinToneFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSkinToneFilter.m new file mode 100644 index 00000000..0db9ac7c --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSkinToneFilter.m @@ -0,0 +1,246 @@ +// +// GPUImageSkinToneFilter.m +// +// +// Created by github.com/r3mus on 8/13/15. +// +// + +#import "GPUImageSkinToneFilter.h" + +@implementation GPUImageSkinToneFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSkinToneFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + // [-1;1] <=> [pink;orange] + uniform highp float skinToneAdjust; // will make reds more pink + + // Other parameters + uniform mediump float skinHue; + uniform mediump float skinHueThreshold; + uniform mediump float maxHueShift; + uniform mediump float maxSaturationShift; + uniform int upperSkinToneColor; + + // RGB <-> HSV conversion, thanks to http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl + highp vec3 rgb2hsv(highp vec3 c) +{ + highp vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + highp vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + highp vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + + highp float d = q.x - min(q.w, q.y); + highp float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + + // HSV <-> RGB conversion, thanks to http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl + highp vec3 hsv2rgb(highp vec3 c) +{ + highp vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + highp vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + + // Main + void main () +{ + + // Sample the input pixel + highp vec4 colorRGB = texture2D(inputImageTexture, textureCoordinate); + + // Convert color to HSV, extract hue + highp vec3 colorHSV = rgb2hsv(colorRGB.rgb); + highp float hue = colorHSV.x; + + // check how far from skin hue + highp float dist = hue - skinHue; + if (dist > 0.5) + dist -= 1.0; + if (dist < -0.5) + dist += 1.0; + dist = abs(dist)/0.5; // normalized to [0,1] + + // Apply Gaussian like filter + highp float weight = exp(-dist*dist*skinHueThreshold); + weight = clamp(weight, 0.0, 1.0); + + // Using pink/green, so only adjust hue + if (upperSkinToneColor == 0) { + colorHSV.x += skinToneAdjust * weight * maxHueShift; + // Using pink/orange, so adjust hue < 0 and saturation > 0 + } else if (upperSkinToneColor == 1) { + // We want more orange, so increase saturation + if (skinToneAdjust > 0.0) + colorHSV.y += skinToneAdjust * weight * maxSaturationShift; + // we want more pinks, so decrease hue + else + colorHSV.x += skinToneAdjust * weight * maxHueShift; + } + + // final color + highp vec3 finalColorRGB = hsv2rgb(colorHSV.rgb); + + // display + gl_FragColor = vec4(finalColorRGB, 1.0); +} +); +#else +NSString *const kGPUImageSkinToneFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + // [-1;1] <=> [pink;orange] + uniform float skinToneAdjust; // will make reds more pink + + // Other parameters + uniform float skinHue; + uniform float skinHueThreshold; + uniform float maxHueShift; + uniform float maxSaturationShift; + uniform int upperSkinToneColor; + + // RGB <-> HSV conversion, thanks to http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl + highp vec3 rgb2hsv(highp vec3 c) +{ + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + + // HSV <-> RGB conversion, thanks to http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl + highp vec3 hsv2rgb(highp vec3 c) +{ + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + + // Main + void main () +{ + + // Sample the input pixel + vec4 colorRGB = texture2D(inputImageTexture, textureCoordinate); + + // Convert color to HSV, extract hue + vec3 colorHSV = rgb2hsv(colorRGB.rgb); + float hue = colorHSV.x; + + // check how far from skin hue + float dist = hue - skinHue; + if (dist > 0.5) + dist -= 1.0; + if (dist < -0.5) + dist += 1.0; + dist = abs(dist)/0.5; // normalized to [0,1] + + // Apply Gaussian like filter + float weight = exp(-dist*dist*skinHueThreshold); + weight = clamp(weight, 0.0, 1.0); + + // Using pink/green, so only adjust hue + if (upperSkinToneColor == 0) { + colorHSV.x += skinToneAdjust * weight * maxHueShift; + // Using pink/orange, so adjust hue < 0 and saturation > 0 + } else if (upperSkinToneColor == 1) { + // We want more orange, so increase saturation + if (skinToneAdjust > 0.0) + colorHSV.y += skinToneAdjust * weight * maxSaturationShift; + // we want more pinks, so decrease hue + else + colorHSV.x += skinToneAdjust * weight * maxHueShift; + } + + // final color + vec3 finalColorRGB = hsv2rgb(colorHSV.rgb); + + // display + gl_FragColor = vec4(finalColorRGB, 1.0); +} + ); +#endif + +#pragma mark - +#pragma mark Initialization and teardown +@synthesize skinToneAdjust; +@synthesize skinHue; +@synthesize skinHueThreshold; +@synthesize maxHueShift; +@synthesize maxSaturationShift; +@synthesize upperSkinToneColor; + +- (id)init +{ + if(! (self = [super initWithFragmentShaderFromString:kGPUImageSkinToneFragmentShaderString]) ) + { + return nil; + } + + skinToneAdjustUniform = [filterProgram uniformIndex:@"skinToneAdjust"]; + skinHueUniform = [filterProgram uniformIndex:@"skinHue"]; + skinHueThresholdUniform = [filterProgram uniformIndex:@"skinHueThreshold"]; + maxHueShiftUniform = [filterProgram uniformIndex:@"maxHueShift"]; + maxSaturationShiftUniform = [filterProgram uniformIndex:@"maxSaturationShift"]; + upperSkinToneColorUniform = [filterProgram uniformIndex:@"upperSkinToneColor"]; + + self.skinHue = 0.05; + self.skinHueThreshold = 40.0; + self.maxHueShift = 0.25; + self.maxSaturationShift = 0.4; + self.upperSkinToneColor = GPUImageSkinToneUpperColorGreen; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setSkinToneAdjust:(CGFloat)newValue +{ + skinToneAdjust = newValue; + [self setFloat:newValue forUniform:skinToneAdjustUniform program:filterProgram]; +} + +- (void)setSkinHue:(CGFloat)newValue +{ + skinHue = newValue; + [self setFloat:newValue forUniform:skinHueUniform program:filterProgram]; +} + +- (void)setSkinHueThreshold:(CGFloat)newValue +{ + skinHueThreshold = newValue; + [self setFloat:newValue forUniform:skinHueThresholdUniform program:filterProgram]; +} + +- (void)setMaxHueShift:(CGFloat)newValue +{ + maxHueShift = newValue; + [self setFloat:newValue forUniform:maxHueShiftUniform program:filterProgram]; +} + +- (void)setMaxSaturationShift:(CGFloat)newValue +{ + maxSaturationShift = newValue; + [self setFloat:newValue forUniform:maxSaturationShiftUniform program:filterProgram]; +} + +- (void)setUpperSkinToneColor:(GPUImageSkinToneUpperColor)newValue +{ + upperSkinToneColor = newValue; + [self setInteger:newValue forUniform:upperSkinToneColorUniform program:filterProgram]; +} + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSmoothToonFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSmoothToonFilter.h new file mode 100755 index 00000000..f89caac5 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSmoothToonFilter.h @@ -0,0 +1,28 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImageGaussianBlurFilter; +@class GPUImageToonFilter; + +/** This uses a similar process as the GPUImageToonFilter, only it precedes the toon effect with a Gaussian blur to smooth out noise. + */ +@interface GPUImageSmoothToonFilter : GPUImageFilterGroup +{ + GPUImageGaussianBlurFilter *blurFilter; + GPUImageToonFilter *toonFilter; +} + +/// The image width and height factors tweak the appearance of the edges. By default, they match the filter size in pixels +@property(readwrite, nonatomic) CGFloat texelWidth; +/// The image width and height factors tweak the appearance of the edges. By default, they match the filter size in pixels +@property(readwrite, nonatomic) CGFloat texelHeight; + +/// The radius of the underlying Gaussian blur. The default is 2.0. +@property (readwrite, nonatomic) CGFloat blurRadiusInPixels; + +/// The threshold at which to apply the edges, default of 0.2 +@property(readwrite, nonatomic) CGFloat threshold; + +/// The levels of quantization for the posterization of colors within the scene, with a default of 10.0 +@property(readwrite, nonatomic) CGFloat quantizationLevels; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSmoothToonFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSmoothToonFilter.m new file mode 100755 index 00000000..03828f48 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSmoothToonFilter.m @@ -0,0 +1,94 @@ +#import "GPUImageSmoothToonFilter.h" +#import "GPUImageGaussianBlurFilter.h" +#import "GPUImageToonFilter.h" + +@implementation GPUImageSmoothToonFilter + +@synthesize threshold; +@synthesize blurRadiusInPixels; +@synthesize quantizationLevels; +@synthesize texelWidth; +@synthesize texelHeight; + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + // First pass: apply a variable Gaussian blur + blurFilter = [[GPUImageGaussianBlurFilter alloc] init]; + [self addFilter:blurFilter]; + + // Second pass: run the Sobel edge detection on this blurred image, along with a posterization effect + toonFilter = [[GPUImageToonFilter alloc] init]; + [self addFilter:toonFilter]; + + // Texture location 0 needs to be the sharp image for both the blur and the second stage processing + [blurFilter addTarget:toonFilter]; + + self.initialFilters = [NSArray arrayWithObject:blurFilter]; + self.terminalFilter = toonFilter; + + self.blurRadiusInPixels = 2.0; + self.threshold = 0.2; + self.quantizationLevels = 10.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBlurRadiusInPixels:(CGFloat)newValue; +{ + blurFilter.blurRadiusInPixels = newValue; +} + +- (CGFloat)blurRadiusInPixels; +{ + return blurFilter.blurRadiusInPixels; +} + +- (void)setTexelWidth:(CGFloat)newValue; +{ + toonFilter.texelWidth = newValue; +} + +- (CGFloat)texelWidth; +{ + return toonFilter.texelWidth; +} + +- (void)setTexelHeight:(CGFloat)newValue; +{ + toonFilter.texelHeight = newValue; +} + +- (CGFloat)texelHeight; +{ + return toonFilter.texelHeight; +} + +- (void)setThreshold:(CGFloat)newValue; +{ + toonFilter.threshold = newValue; +} + +- (CGFloat)threshold; +{ + return toonFilter.threshold; +} + +- (void)setQuantizationLevels:(CGFloat)newValue; +{ + toonFilter.quantizationLevels = newValue; +} + +- (CGFloat)quantizationLevels; +{ + return toonFilter.quantizationLevels; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSobelEdgeDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSobelEdgeDetectionFilter.h new file mode 100755 index 00000000..d6b2c13a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSobelEdgeDetectionFilter.h @@ -0,0 +1,16 @@ +#import "GPUImageTwoPassFilter.h" + +@interface GPUImageSobelEdgeDetectionFilter : GPUImageTwoPassFilter +{ + GLint texelWidthUniform, texelHeightUniform, edgeStrengthUniform; + BOOL hasOverriddenImageSizeFactor; +} + +// The texel width and height factors tweak the appearance of the edges. By default, they match the inverse of the filter size in pixels +@property(readwrite, nonatomic) CGFloat texelWidth; +@property(readwrite, nonatomic) CGFloat texelHeight; + +// The filter strength property affects the dynamic range of the filter. High values can make edges more visible, but can lead to saturation. Default of 1.0. +@property(readwrite, nonatomic) CGFloat edgeStrength; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSobelEdgeDetectionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSobelEdgeDetectionFilter.m new file mode 100755 index 00000000..e193f027 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSobelEdgeDetectionFilter.m @@ -0,0 +1,188 @@ +#import "GPUImageSobelEdgeDetectionFilter.h" +#import "GPUImageGrayscaleFilter.h" +#import "GPUImage3x3ConvolutionFilter.h" + +// Code from "Graphics Shaders: Theory and Practice" by M. Bailey and S. Cunningham +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSobelEdgeDetectionFragmentShaderString = SHADER_STRING +( + precision mediump float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float edgeStrength; + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; + float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; + + float mag = length(vec2(h, v)) * edgeStrength; + + gl_FragColor = vec4(vec3(mag), 1.0); + } +); +#else +NSString *const kGPUImageSobelEdgeDetectionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float edgeStrength; + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; + float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; + + float mag = length(vec2(h, v)) * edgeStrength; + + gl_FragColor = vec4(vec3(mag), 1.0); + } +); +#endif + +@implementation GPUImageSobelEdgeDetectionFilter + +@synthesize texelWidth = _texelWidth; +@synthesize texelHeight = _texelHeight; +@synthesize edgeStrength = _edgeStrength; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImageSobelEdgeDetectionFragmentShaderString])) + { + return nil; + } + + return self; +} + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + // Do a luminance pass first to reduce the calculations performed at each fragment in the edge detection phase + + if (!(self = [super initWithFirstStageVertexShaderFromString:kGPUImageVertexShaderString firstStageFragmentShaderFromString:kGPUImageLuminanceFragmentShaderString secondStageVertexShaderFromString:kGPUImageNearbyTexelSamplingVertexShaderString secondStageFragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + hasOverriddenImageSizeFactor = NO; + + texelWidthUniform = [secondFilterProgram uniformIndex:@"texelWidth"]; + texelHeightUniform = [secondFilterProgram uniformIndex:@"texelHeight"]; + edgeStrengthUniform = [secondFilterProgram uniformIndex:@"edgeStrength"]; + + self.edgeStrength = 1.0; + return self; +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + if (!hasOverriddenImageSizeFactor) + { + _texelWidth = 1.0 / filterFrameSize.width; + _texelHeight = 1.0 / filterFrameSize.height; + + runSynchronouslyOnVideoProcessingQueue(^{ + GLProgram *previousProgram = [GPUImageContext sharedImageProcessingContext].currentShaderProgram; + [GPUImageContext setActiveShaderProgram:secondFilterProgram]; + glUniform1f(texelWidthUniform, _texelWidth); + glUniform1f(texelHeightUniform, _texelHeight); + [GPUImageContext setActiveShaderProgram:previousProgram]; + }); + } +} + +- (void)setUniformsForProgramAtIndex:(NSUInteger)programIndex; +{ + [super setUniformsForProgramAtIndex:programIndex]; + + if (programIndex == 1) + { + glUniform1f(texelWidthUniform, _texelWidth); + glUniform1f(texelHeightUniform, _texelHeight); + } +} + +- (BOOL)wantsMonochromeInput; +{ +// return YES; + return NO; +} + +- (BOOL)providesMonochromeOutput; +{ +// return YES; + return NO; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setTexelWidth:(CGFloat)newValue; +{ + hasOverriddenImageSizeFactor = YES; + _texelWidth = newValue; + + [self setFloat:_texelWidth forUniform:texelWidthUniform program:secondFilterProgram]; +} + +- (void)setTexelHeight:(CGFloat)newValue; +{ + hasOverriddenImageSizeFactor = YES; + _texelHeight = newValue; + + [self setFloat:_texelHeight forUniform:texelHeightUniform program:secondFilterProgram]; +} + +- (void)setEdgeStrength:(CGFloat)newValue; +{ + _edgeStrength = newValue; + + [self setFloat:_edgeStrength forUniform:edgeStrengthUniform program:secondFilterProgram]; +} + + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSoftEleganceFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSoftEleganceFilter.h new file mode 100755 index 00000000..596e1567 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSoftEleganceFilter.h @@ -0,0 +1,19 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImagePicture; + +/** A photo filter based on Soft Elegance Photoshop action + http://h-d-stock.deviantart.com/art/H-D-A-soft-elegance-70107603 + */ + +// Note: If you want to use this effect you have to add +// lookup_soft_elegance_1.png and lookup_soft_elegance_2.png +// from Resources folder to your application bundle. + +@interface GPUImageSoftEleganceFilter : GPUImageFilterGroup +{ + GPUImagePicture *lookupImageSource1; + GPUImagePicture *lookupImageSource2; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSoftEleganceFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSoftEleganceFilter.m new file mode 100755 index 00000000..e1d4e02d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSoftEleganceFilter.m @@ -0,0 +1,62 @@ +#import "GPUImageSoftEleganceFilter.h" +#import "GPUImagePicture.h" +#import "GPUImageLookupFilter.h" +#import "GPUImageGaussianBlurFilter.h" +#import "GPUImageAlphaBlendFilter.h" + +@implementation GPUImageSoftEleganceFilter + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + UIImage *image1 = [UIImage imageNamed:@"lookup_soft_elegance_1.png"]; + UIImage *image2 = [UIImage imageNamed:@"lookup_soft_elegance_2.png"]; +#else + NSImage *image1 = [NSImage imageNamed:@"lookup_soft_elegance_1.png"]; + NSImage *image2 = [NSImage imageNamed:@"lookup_soft_elegance_2.png"]; +#endif + + NSAssert(image1 && image2, + @"To use GPUImageSoftEleganceFilter you need to add lookup_soft_elegance_1.png and lookup_soft_elegance_2.png from GPUImage/framework/Resources to your application bundle."); + + lookupImageSource1 = [[GPUImagePicture alloc] initWithImage:image1]; + GPUImageLookupFilter *lookupFilter1 = [[GPUImageLookupFilter alloc] init]; + [self addFilter:lookupFilter1]; + + [lookupImageSource1 addTarget:lookupFilter1 atTextureLocation:1]; + [lookupImageSource1 processImage]; + + GPUImageGaussianBlurFilter *gaussianBlur = [[GPUImageGaussianBlurFilter alloc] init]; + gaussianBlur.blurRadiusInPixels = 10.0; + [lookupFilter1 addTarget:gaussianBlur]; + [self addFilter:gaussianBlur]; + + GPUImageAlphaBlendFilter *alphaBlend = [[GPUImageAlphaBlendFilter alloc] init]; + alphaBlend.mix = 0.14; + [lookupFilter1 addTarget:alphaBlend]; + [gaussianBlur addTarget:alphaBlend]; + [self addFilter:alphaBlend]; + + lookupImageSource2 = [[GPUImagePicture alloc] initWithImage:image2]; + + GPUImageLookupFilter *lookupFilter2 = [[GPUImageLookupFilter alloc] init]; + [alphaBlend addTarget:lookupFilter2]; + [lookupImageSource2 addTarget:lookupFilter2]; + [lookupImageSource2 processImage]; + [self addFilter:lookupFilter2]; + + self.initialFilters = [NSArray arrayWithObjects:lookupFilter1, nil]; + self.terminalFilter = lookupFilter2; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSoftLightBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSoftLightBlendFilter.h new file mode 100755 index 00000000..13fc877c --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSoftLightBlendFilter.h @@ -0,0 +1,7 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageSoftLightBlendFilter : GPUImageTwoInputFilter +{ +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSoftLightBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSoftLightBlendFilter.m new file mode 100755 index 00000000..368bce0a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSoftLightBlendFilter.m @@ -0,0 +1,54 @@ +#import "GPUImageSoftLightBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSoftLightBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + mediump vec4 base = texture2D(inputImageTexture, textureCoordinate); + mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + lowp float alphaDivisor = base.a + step(base.a, 0.0); // Protect against a divide-by-zero blacking out things in the output + gl_FragColor = base * (overlay.a * (base / alphaDivisor) + (2.0 * overlay * (1.0 - (base / alphaDivisor)))) + overlay * (1.0 - base.a) + base * (1.0 - overlay.a); + } +); +#else +NSString *const kGPUImageSoftLightBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 base = texture2D(inputImageTexture, textureCoordinate); + vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2); + + float alphaDivisor = base.a + step(base.a, 0.0); // Protect against a divide-by-zero blacking out things in the output + gl_FragColor = base * (overlay.a * (base / alphaDivisor) + (2.0 * overlay * (1.0 - (base / alphaDivisor)))) + overlay * (1.0 - base.a) + base * (1.0 - overlay.a); + } +); +#endif + +@implementation GPUImageSoftLightBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageSoftLightBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSolarizeFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSolarizeFilter.h new file mode 100644 index 00000000..ba01c15a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSolarizeFilter.h @@ -0,0 +1,14 @@ +#import "GPUImageFilter.h" + +/** Pixels with a luminance above the threshold will invert their color + */ +@interface GPUImageSolarizeFilter : GPUImageFilter +{ + GLint thresholdUniform; +} + +/** Anything above this luminance will be inverted, and anything below normal. Ranges from 0.0 to 1.0, with 0.5 as the default + */ +@property(readwrite, nonatomic) CGFloat threshold; + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSolarizeFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSolarizeFilter.m new file mode 100644 index 00000000..616cb5b2 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSolarizeFilter.m @@ -0,0 +1,76 @@ +#import "GPUImageSolarizeFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSolarizeFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform highp float threshold; + + const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + highp float luminance = dot(textureColor.rgb, W); + highp float thresholdResult = step(luminance, threshold); + highp vec3 finalColor = abs(thresholdResult - textureColor.rgb); + + gl_FragColor = vec4(finalColor, textureColor.w); + } +); +#else +NSString *const kGPUImageSolarizeFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float threshold; + + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + float luminance = dot(textureColor.rgb, W); + float thresholdResult = step(luminance, threshold); + vec3 finalColor = abs(thresholdResult - textureColor.rgb); + + gl_FragColor = vec4(vec3(finalColor), textureColor.w); + } +); +#endif + +@implementation GPUImageSolarizeFilter; + +@synthesize threshold = _threshold; + +#pragma mark - +#pragma mark Initialization + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageSolarizeFragmentShaderString])) + { + return nil; + } + + thresholdUniform = [filterProgram uniformIndex:@"threshold"]; + self.threshold = 0.5; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setThreshold:(CGFloat)newValue; +{ + _threshold = newValue; + + [self setFloat:_threshold forUniform:thresholdUniform program:filterProgram]; +} + + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSolidColorGenerator.h b/LFLiveKit/Vendor/GPUImage/GPUImageSolidColorGenerator.h new file mode 100644 index 00000000..58b1383e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSolidColorGenerator.h @@ -0,0 +1,19 @@ +#import "GPUImageFilter.h" + +// This outputs an image with a constant color. You need to use -forceProcessingAtSize: in order to set the output image +// dimensions, or this won't work correctly + + +@interface GPUImageSolidColorGenerator : GPUImageFilter +{ + GLint colorUniform; + GLint useExistingAlphaUniform; +} + +// This color dictates what the output image will be filled with +@property(readwrite, nonatomic) GPUVector4 color; +@property(readwrite, nonatomic, assign) BOOL useExistingAlpha; // whether to use the alpha of the existing image or not, default is NO + +- (void)setColorRed:(CGFloat)redComponent green:(CGFloat)greenComponent blue:(CGFloat)blueComponent alpha:(CGFloat)alphaComponent; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSolidColorGenerator.m b/LFLiveKit/Vendor/GPUImage/GPUImageSolidColorGenerator.m new file mode 100644 index 00000000..9b555ce0 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSolidColorGenerator.m @@ -0,0 +1,123 @@ +#import "GPUImageSolidColorGenerator.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUSolidColorFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying highp vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform vec4 color; + uniform float useExistingAlpha; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + gl_FragColor = vec4(color.rgb, max(textureColor.a, 1.0 - useExistingAlpha)); + } + ); +#else +NSString *const kGPUSolidColorFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + uniform sampler2D inputImageTexture; + uniform vec4 color; + uniform float useExistingAlpha; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + gl_FragColor = vec4(color.rgb, max(textureColor.a, 1.0 - useExistingAlpha)); + } + ); +#endif + +@implementation GPUImageSolidColorGenerator + +@synthesize color = _color; + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUSolidColorFragmentShaderString])) + { + return nil; + } + + colorUniform = [filterProgram uniformIndex:@"color"]; + useExistingAlphaUniform = [filterProgram uniformIndex:@"useExistingAlpha"]; + + _color = (GPUVector4){0.0f, 0.0f, 0.5f, 1.0f}; + self.useExistingAlpha = NO; + + return self; +} + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + if (self.preventRendering) + { + return; + } + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:filterProgram]; + + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + + glClearColor(_color.one, _color.two, _color.three, _color.four); + glClear(GL_COLOR_BUFFER_BIT); + }); +} + + +#pragma mark - +#pragma mark Accessors + +- (void)forceProcessingAtSize:(CGSize)frameSize; +{ + [super forceProcessingAtSize:frameSize]; + + if (!CGSizeEqualToSize(inputTextureSize, CGSizeZero)) + { + [self newFrameReadyAtTime:kCMTimeIndefinite atIndex:0]; + } +} + +- (void)addTarget:(id)newTarget atTextureLocation:(NSInteger)textureLocation; +{ + [super addTarget:newTarget atTextureLocation:textureLocation]; + + if (!CGSizeEqualToSize(inputTextureSize, CGSizeZero)) + { + [newTarget setInputSize:inputTextureSize atIndex:textureLocation]; + [newTarget newFrameReadyAtTime:kCMTimeIndefinite atIndex:textureLocation]; + } +} + +- (void)setColor:(GPUVector4)newValue; +{ + [self setColorRed:newValue.one green:newValue.two blue:newValue.three alpha:newValue.four]; +} + +- (void)setColorRed:(CGFloat)redComponent green:(CGFloat)greenComponent blue:(CGFloat)blueComponent alpha:(CGFloat)alphaComponent; +{ + _color.one = (GLfloat)redComponent; + _color.two = (GLfloat)greenComponent; + _color.three = (GLfloat)blueComponent; + _color.four = (GLfloat)alphaComponent; + +// [self setVec4:_color forUniform:colorUniform program:filterProgram]; + runAsynchronouslyOnVideoProcessingQueue(^{ + [self newFrameReadyAtTime:kCMTimeIndefinite atIndex:0]; + }); +} + +- (void)setUseExistingAlpha:(BOOL)useExistingAlpha; +{ + _useExistingAlpha = useExistingAlpha; + + [self setInteger:(useExistingAlpha ? 1 : 0) forUniform:useExistingAlphaUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSourceOverBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSourceOverBlendFilter.h new file mode 100644 index 00000000..29e30635 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSourceOverBlendFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageSourceOverBlendFilter : GPUImageTwoInputFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSourceOverBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSourceOverBlendFilter.m new file mode 100644 index 00000000..432adc4b --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSourceOverBlendFilter.m @@ -0,0 +1,51 @@ +#import "GPUImageSourceOverBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSourceOverBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate); + + gl_FragColor = mix(textureColor, textureColor2, textureColor2.a); + } +); +#else +NSString *const kGPUImageSourceOverBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate); + + gl_FragColor = mix(textureColor, textureColor2, textureColor2.a); + } + ); +#endif + +@implementation GPUImageSourceOverBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageSourceOverBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSphereRefractionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSphereRefractionFilter.h new file mode 100644 index 00000000..cbbd2afa --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSphereRefractionFilter.h @@ -0,0 +1,15 @@ +#import "GPUImageFilter.h" + +@interface GPUImageSphereRefractionFilter : GPUImageFilter +{ + GLint radiusUniform, centerUniform, aspectRatioUniform, refractiveIndexUniform; +} + +/// The center about which to apply the distortion, with a default of (0.5, 0.5) +@property(readwrite, nonatomic) CGPoint center; +/// The radius of the distortion, ranging from 0.0 to 1.0, with a default of 0.25 +@property(readwrite, nonatomic) CGFloat radius; +/// The index of refraction for the sphere, with a default of 0.71 +@property(readwrite, nonatomic) CGFloat refractiveIndex; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSphereRefractionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSphereRefractionFilter.m new file mode 100644 index 00000000..b0f54042 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSphereRefractionFilter.m @@ -0,0 +1,179 @@ +#import "GPUImageSphereRefractionFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSphereRefractionFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp vec2 center; + uniform highp float radius; + uniform highp float aspectRatio; + uniform highp float refractiveIndex; + + void main() + { + highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + highp float distanceFromCenter = distance(center, textureCoordinateToUse); + lowp float checkForPresenceWithinSphere = step(distanceFromCenter, radius); + + distanceFromCenter = distanceFromCenter / radius; + + highp float normalizedDepth = radius * sqrt(1.0 - distanceFromCenter * distanceFromCenter); + highp vec3 sphereNormal = normalize(vec3(textureCoordinateToUse - center, normalizedDepth)); + + highp vec3 refractedVector = refract(vec3(0.0, 0.0, -1.0), sphereNormal, refractiveIndex); + + gl_FragColor = texture2D(inputImageTexture, (refractedVector.xy + 1.0) * 0.5) * checkForPresenceWithinSphere; + } +); +#else +NSString *const kGPUImageSphereRefractionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform vec2 center; + uniform float radius; + uniform float aspectRatio; + uniform float refractiveIndex; + + void main() + { + vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); + float distanceFromCenter = distance(center, textureCoordinateToUse); + float checkForPresenceWithinSphere = step(distanceFromCenter, radius); + + distanceFromCenter = distanceFromCenter / radius; + + float normalizedDepth = radius * sqrt(1.0 - distanceFromCenter * distanceFromCenter); + vec3 sphereNormal = normalize(vec3(textureCoordinateToUse - center, normalizedDepth)); + + vec3 refractedVector = refract(vec3(0.0, 0.0, -1.0), sphereNormal, refractiveIndex); + + gl_FragColor = texture2D(inputImageTexture, (refractedVector.xy + 1.0) * 0.5) * checkForPresenceWithinSphere; + } +); +#endif + +@interface GPUImageSphereRefractionFilter () + +- (void)adjustAspectRatio; + +@property (readwrite, nonatomic) CGFloat aspectRatio; + +@end + + +@implementation GPUImageSphereRefractionFilter + +@synthesize center = _center; +@synthesize radius = _radius; +@synthesize aspectRatio = _aspectRatio; +@synthesize refractiveIndex = _refractiveIndex; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImageSphereRefractionFragmentShaderString])) + { + return nil; + } + + return self; +} + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [super initWithFragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + radiusUniform = [filterProgram uniformIndex:@"radius"]; + aspectRatioUniform = [filterProgram uniformIndex:@"aspectRatio"]; + centerUniform = [filterProgram uniformIndex:@"center"]; + refractiveIndexUniform = [filterProgram uniformIndex:@"refractiveIndex"]; + + self.radius = 0.25; + self.center = CGPointMake(0.5, 0.5); + self.refractiveIndex = 0.71; + + [self setBackgroundColorRed:0.0 green:0.0 blue:0.0 alpha:0.0]; + + return self; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + CGSize oldInputSize = inputTextureSize; + [super setInputSize:newSize atIndex:textureIndex]; + + if (!CGSizeEqualToSize(oldInputSize, inputTextureSize) && (!CGSizeEqualToSize(newSize, CGSizeZero)) ) + { + [self adjustAspectRatio]; + } +} + +#pragma mark - +#pragma mark Accessors + +- (void)adjustAspectRatio; +{ + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + [self setAspectRatio:(inputTextureSize.width / inputTextureSize.height)]; + } + else + { + [self setAspectRatio:(inputTextureSize.height / inputTextureSize.width)]; + } +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + [super setInputRotation:newInputRotation atIndex:textureIndex]; + [self setCenter:self.center]; + [self adjustAspectRatio]; +} + +- (void)forceProcessingAtSize:(CGSize)frameSize; +{ + [super forceProcessingAtSize:frameSize]; + [self adjustAspectRatio]; +} + +- (void)setRadius:(CGFloat)newValue; +{ + _radius = newValue; + + [self setFloat:_radius forUniform:radiusUniform program:filterProgram]; +} + +- (void)setCenter:(CGPoint)newValue; +{ + _center = newValue; + + CGPoint rotatedPoint = [self rotatedPoint:_center forRotation:inputRotation]; + [self setPoint:rotatedPoint forUniform:centerUniform program:filterProgram]; +} + +- (void)setAspectRatio:(CGFloat)newValue; +{ + _aspectRatio = newValue; + + [self setFloat:_aspectRatio forUniform:aspectRatioUniform program:filterProgram]; +} + +- (void)setRefractiveIndex:(CGFloat)newValue; +{ + _refractiveIndex = newValue; + + [self setFloat:_refractiveIndex forUniform:refractiveIndexUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageStillCamera.h b/LFLiveKit/Vendor/GPUImage/GPUImageStillCamera.h new file mode 100755 index 00000000..e4db59b2 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageStillCamera.h @@ -0,0 +1,24 @@ +#import "GPUImageVideoCamera.h" + +void stillImageDataReleaseCallback(void *releaseRefCon, const void *baseAddress); +void GPUImageCreateResizedSampleBuffer(CVPixelBufferRef cameraFrame, CGSize finalSize, CMSampleBufferRef *sampleBuffer); + +@interface GPUImageStillCamera : GPUImageVideoCamera + +/** The JPEG compression quality to use when capturing a photo as a JPEG. + */ +@property CGFloat jpegCompressionQuality; + +// Only reliably set inside the context of the completion handler of one of the capture methods +@property (readonly) NSDictionary *currentCaptureMetadata; + +// Photography controls +- (void)capturePhotoAsSampleBufferWithCompletionHandler:(void (^)(CMSampleBufferRef imageSampleBuffer, NSError *error))block; +- (void)capturePhotoAsImageProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withCompletionHandler:(void (^)(UIImage *processedImage, NSError *error))block; +- (void)capturePhotoAsImageProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withOrientation:(UIImageOrientation)orientation withCompletionHandler:(void (^)(UIImage *processedImage, NSError *error))block; +- (void)capturePhotoAsJPEGProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withCompletionHandler:(void (^)(NSData *processedJPEG, NSError *error))block; +- (void)capturePhotoAsJPEGProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withOrientation:(UIImageOrientation)orientation withCompletionHandler:(void (^)(NSData *processedJPEG, NSError *error))block; +- (void)capturePhotoAsPNGProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withCompletionHandler:(void (^)(NSData *processedPNG, NSError *error))block; +- (void)capturePhotoAsPNGProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withOrientation:(UIImageOrientation)orientation withCompletionHandler:(void (^)(NSData *processedPNG, NSError *error))block; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageStillCamera.m b/LFLiveKit/Vendor/GPUImage/GPUImageStillCamera.m new file mode 100755 index 00000000..447f79f6 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageStillCamera.m @@ -0,0 +1,338 @@ +// 2448x3264 pixel image = 31,961,088 bytes for uncompressed RGBA + +#import "GPUImageStillCamera.h" + +void stillImageDataReleaseCallback(void *releaseRefCon, const void *baseAddress) +{ + free((void *)baseAddress); +} + +void GPUImageCreateResizedSampleBuffer(CVPixelBufferRef cameraFrame, CGSize finalSize, CMSampleBufferRef *sampleBuffer) +{ + // CVPixelBufferCreateWithPlanarBytes for YUV input + + CGSize originalSize = CGSizeMake(CVPixelBufferGetWidth(cameraFrame), CVPixelBufferGetHeight(cameraFrame)); + + CVPixelBufferLockBaseAddress(cameraFrame, 0); + GLubyte *sourceImageBytes = CVPixelBufferGetBaseAddress(cameraFrame); + CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, sourceImageBytes, CVPixelBufferGetBytesPerRow(cameraFrame) * originalSize.height, NULL); + CGColorSpaceRef genericRGBColorspace = CGColorSpaceCreateDeviceRGB(); + CGImageRef cgImageFromBytes = CGImageCreate((int)originalSize.width, (int)originalSize.height, 8, 32, CVPixelBufferGetBytesPerRow(cameraFrame), genericRGBColorspace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst, dataProvider, NULL, NO, kCGRenderingIntentDefault); + + GLubyte *imageData = (GLubyte *) calloc(1, (int)finalSize.width * (int)finalSize.height * 4); + + CGContextRef imageContext = CGBitmapContextCreate(imageData, (int)finalSize.width, (int)finalSize.height, 8, (int)finalSize.width * 4, genericRGBColorspace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst); + CGContextDrawImage(imageContext, CGRectMake(0.0, 0.0, finalSize.width, finalSize.height), cgImageFromBytes); + CGImageRelease(cgImageFromBytes); + CGContextRelease(imageContext); + CGColorSpaceRelease(genericRGBColorspace); + CGDataProviderRelease(dataProvider); + + CVPixelBufferRef pixel_buffer = NULL; + CVPixelBufferCreateWithBytes(kCFAllocatorDefault, finalSize.width, finalSize.height, kCVPixelFormatType_32BGRA, imageData, finalSize.width * 4, stillImageDataReleaseCallback, NULL, NULL, &pixel_buffer); + CMVideoFormatDescriptionRef videoInfo = NULL; + CMVideoFormatDescriptionCreateForImageBuffer(NULL, pixel_buffer, &videoInfo); + + CMTime frameTime = CMTimeMake(1, 30); + CMSampleTimingInfo timing = {frameTime, frameTime, kCMTimeInvalid}; + + CMSampleBufferCreateForImageBuffer(kCFAllocatorDefault, pixel_buffer, YES, NULL, NULL, videoInfo, &timing, sampleBuffer); + CVPixelBufferUnlockBaseAddress(cameraFrame, 0); + CFRelease(videoInfo); + CVPixelBufferRelease(pixel_buffer); +} + +@interface GPUImageStillCamera () +{ + AVCaptureStillImageOutput *photoOutput; +} + +// Methods calling this are responsible for calling dispatch_semaphore_signal(frameRenderingSemaphore) somewhere inside the block +- (void)capturePhotoProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withImageOnGPUHandler:(void (^)(NSError *error))block; + +@end + +@implementation GPUImageStillCamera { + BOOL requiresFrontCameraTextureCacheCorruptionWorkaround; +} + +@synthesize currentCaptureMetadata = _currentCaptureMetadata; +@synthesize jpegCompressionQuality = _jpegCompressionQuality; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithSessionPreset:(NSString *)sessionPreset cameraPosition:(AVCaptureDevicePosition)cameraPosition; +{ + if (!(self = [super initWithSessionPreset:sessionPreset cameraPosition:cameraPosition])) + { + return nil; + } + + /* Detect iOS version < 6 which require a texture cache corruption workaround */ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + requiresFrontCameraTextureCacheCorruptionWorkaround = [[[UIDevice currentDevice] systemVersion] compare:@"6.0" options:NSNumericSearch] == NSOrderedAscending; +#pragma clang diagnostic pop + + [self.captureSession beginConfiguration]; + + photoOutput = [[AVCaptureStillImageOutput alloc] init]; + + // Having a still photo input set to BGRA and video to YUV doesn't work well, so since I don't have YUV resizing for iPhone 4 yet, kick back to BGRA for that device +// if (captureAsYUV && [GPUImageContext supportsFastTextureUpload]) + if (captureAsYUV && [GPUImageContext deviceSupportsRedTextures]) + { + BOOL supportsFullYUVRange = NO; + NSArray *supportedPixelFormats = photoOutput.availableImageDataCVPixelFormatTypes; + for (NSNumber *currentPixelFormat in supportedPixelFormats) + { + if ([currentPixelFormat intValue] == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) + { + supportsFullYUVRange = YES; + } + } + + if (supportsFullYUVRange) + { + [photoOutput setOutputSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange] forKey:(id)kCVPixelBufferPixelFormatTypeKey]]; + } + else + { + [photoOutput setOutputSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] forKey:(id)kCVPixelBufferPixelFormatTypeKey]]; + } + } + else + { + captureAsYUV = NO; + [photoOutput setOutputSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]]; + [videoOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]]; + } + + [self.captureSession addOutput:photoOutput]; + + [self.captureSession commitConfiguration]; + + self.jpegCompressionQuality = 0.8; + + return self; +} + +- (id)init; +{ + if (!(self = [self initWithSessionPreset:AVCaptureSessionPresetPhoto cameraPosition:AVCaptureDevicePositionBack])) + { + return nil; + } + return self; +} + +- (void)removeInputsAndOutputs; +{ + [self.captureSession removeOutput:photoOutput]; + [super removeInputsAndOutputs]; +} + +#pragma mark - +#pragma mark Photography controls + +- (void)capturePhotoAsSampleBufferWithCompletionHandler:(void (^)(CMSampleBufferRef imageSampleBuffer, NSError *error))block +{ + NSLog(@"If you want to use the method capturePhotoAsSampleBufferWithCompletionHandler:, you must comment out the line in GPUImageStillCamera.m in the method initWithSessionPreset:cameraPosition: which sets the CVPixelBufferPixelFormatTypeKey, as well as uncomment the rest of the method capturePhotoAsSampleBufferWithCompletionHandler:. However, if you do this you cannot use any of the photo capture methods to take a photo if you also supply a filter."); + + /*dispatch_semaphore_wait(frameRenderingSemaphore, DISPATCH_TIME_FOREVER); + + [photoOutput captureStillImageAsynchronouslyFromConnection:[[photoOutput connections] objectAtIndex:0] completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) { + block(imageSampleBuffer, error); + }]; + + dispatch_semaphore_signal(frameRenderingSemaphore); + + */ + + return; +} + +- (void)capturePhotoAsImageProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withCompletionHandler:(void (^)(UIImage *processedImage, NSError *error))block; +{ + [self capturePhotoProcessedUpToFilter:finalFilterInChain withImageOnGPUHandler:^(NSError *error) { + UIImage *filteredPhoto = nil; + + if(!error){ + filteredPhoto = [finalFilterInChain imageFromCurrentFramebuffer]; + } + dispatch_semaphore_signal(frameRenderingSemaphore); + + block(filteredPhoto, error); + }]; +} + +- (void)capturePhotoAsImageProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withOrientation:(UIImageOrientation)orientation withCompletionHandler:(void (^)(UIImage *processedImage, NSError *error))block { + [self capturePhotoProcessedUpToFilter:finalFilterInChain withImageOnGPUHandler:^(NSError *error) { + UIImage *filteredPhoto = nil; + + if(!error) { + filteredPhoto = [finalFilterInChain imageFromCurrentFramebufferWithOrientation:orientation]; + } + dispatch_semaphore_signal(frameRenderingSemaphore); + + block(filteredPhoto, error); + }]; +} + +- (void)capturePhotoAsJPEGProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withCompletionHandler:(void (^)(NSData *processedJPEG, NSError *error))block; +{ +// reportAvailableMemoryForGPUImage(@"Before Capture"); + + [self capturePhotoProcessedUpToFilter:finalFilterInChain withImageOnGPUHandler:^(NSError *error) { + NSData *dataForJPEGFile = nil; + + if(!error){ + @autoreleasepool { + UIImage *filteredPhoto = [finalFilterInChain imageFromCurrentFramebuffer]; + dispatch_semaphore_signal(frameRenderingSemaphore); +// reportAvailableMemoryForGPUImage(@"After UIImage generation"); + + dataForJPEGFile = UIImageJPEGRepresentation(filteredPhoto,self.jpegCompressionQuality); +// reportAvailableMemoryForGPUImage(@"After JPEG generation"); + } + +// reportAvailableMemoryForGPUImage(@"After autorelease pool"); + }else{ + dispatch_semaphore_signal(frameRenderingSemaphore); + } + + block(dataForJPEGFile, error); + }]; +} + +- (void)capturePhotoAsJPEGProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withOrientation:(UIImageOrientation)orientation withCompletionHandler:(void (^)(NSData *processedImage, NSError *error))block { + [self capturePhotoProcessedUpToFilter:finalFilterInChain withImageOnGPUHandler:^(NSError *error) { + NSData *dataForJPEGFile = nil; + + if(!error) { + @autoreleasepool { + UIImage *filteredPhoto = [finalFilterInChain imageFromCurrentFramebufferWithOrientation:orientation]; + dispatch_semaphore_signal(frameRenderingSemaphore); + + dataForJPEGFile = UIImageJPEGRepresentation(filteredPhoto, self.jpegCompressionQuality); + } + } else { + dispatch_semaphore_signal(frameRenderingSemaphore); + } + + block(dataForJPEGFile, error); + }]; +} + +- (void)capturePhotoAsPNGProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withCompletionHandler:(void (^)(NSData *processedPNG, NSError *error))block; +{ + + [self capturePhotoProcessedUpToFilter:finalFilterInChain withImageOnGPUHandler:^(NSError *error) { + NSData *dataForPNGFile = nil; + + if(!error){ + @autoreleasepool { + UIImage *filteredPhoto = [finalFilterInChain imageFromCurrentFramebuffer]; + dispatch_semaphore_signal(frameRenderingSemaphore); + dataForPNGFile = UIImagePNGRepresentation(filteredPhoto); + } + }else{ + dispatch_semaphore_signal(frameRenderingSemaphore); + } + + block(dataForPNGFile, error); + }]; + + return; +} + +- (void)capturePhotoAsPNGProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withOrientation:(UIImageOrientation)orientation withCompletionHandler:(void (^)(NSData *processedPNG, NSError *error))block; +{ + + [self capturePhotoProcessedUpToFilter:finalFilterInChain withImageOnGPUHandler:^(NSError *error) { + NSData *dataForPNGFile = nil; + + if(!error){ + @autoreleasepool { + UIImage *filteredPhoto = [finalFilterInChain imageFromCurrentFramebufferWithOrientation:orientation]; + dispatch_semaphore_signal(frameRenderingSemaphore); + dataForPNGFile = UIImagePNGRepresentation(filteredPhoto); + } + }else{ + dispatch_semaphore_signal(frameRenderingSemaphore); + } + + block(dataForPNGFile, error); + }]; + + return; +} + +#pragma mark - Private Methods + +- (void)capturePhotoProcessedUpToFilter:(GPUImageOutput *)finalFilterInChain withImageOnGPUHandler:(void (^)(NSError *error))block +{ + dispatch_semaphore_wait(frameRenderingSemaphore, DISPATCH_TIME_FOREVER); + + if(photoOutput.isCapturingStillImage){ + block([NSError errorWithDomain:AVFoundationErrorDomain code:AVErrorMaximumStillImageCaptureRequestsExceeded userInfo:nil]); + return; + } + + [photoOutput captureStillImageAsynchronouslyFromConnection:[[photoOutput connections] objectAtIndex:0] completionHandler:^(CMSampleBufferRef imageSampleBuffer, NSError *error) { + if(imageSampleBuffer == NULL){ + block(error); + return; + } + + // For now, resize photos to fix within the max texture size of the GPU + CVImageBufferRef cameraFrame = CMSampleBufferGetImageBuffer(imageSampleBuffer); + + CGSize sizeOfPhoto = CGSizeMake(CVPixelBufferGetWidth(cameraFrame), CVPixelBufferGetHeight(cameraFrame)); + CGSize scaledImageSizeToFitOnGPU = [GPUImageContext sizeThatFitsWithinATextureForSize:sizeOfPhoto]; + if (!CGSizeEqualToSize(sizeOfPhoto, scaledImageSizeToFitOnGPU)) + { + CMSampleBufferRef sampleBuffer = NULL; + + if (CVPixelBufferGetPlaneCount(cameraFrame) > 0) + { + NSAssert(NO, @"Error: no downsampling for YUV input in the framework yet"); + } + else + { + GPUImageCreateResizedSampleBuffer(cameraFrame, scaledImageSizeToFitOnGPU, &sampleBuffer); + } + + dispatch_semaphore_signal(frameRenderingSemaphore); + [finalFilterInChain useNextFrameForImageCapture]; + [self captureOutput:photoOutput didOutputSampleBuffer:sampleBuffer fromConnection:[[photoOutput connections] objectAtIndex:0]]; + dispatch_semaphore_wait(frameRenderingSemaphore, DISPATCH_TIME_FOREVER); + if (sampleBuffer != NULL) + CFRelease(sampleBuffer); + } + else + { + // This is a workaround for the corrupt images that are sometimes returned when taking a photo with the front camera and using the iOS 5.0 texture caches + AVCaptureDevicePosition currentCameraPosition = [[videoInput device] position]; + if ( (currentCameraPosition != AVCaptureDevicePositionFront) || (![GPUImageContext supportsFastTextureUpload]) || !requiresFrontCameraTextureCacheCorruptionWorkaround) + { + dispatch_semaphore_signal(frameRenderingSemaphore); + [finalFilterInChain useNextFrameForImageCapture]; + [self captureOutput:photoOutput didOutputSampleBuffer:imageSampleBuffer fromConnection:[[photoOutput connections] objectAtIndex:0]]; + dispatch_semaphore_wait(frameRenderingSemaphore, DISPATCH_TIME_FOREVER); + } + } + + CFDictionaryRef metadata = CMCopyDictionaryOfAttachments(NULL, imageSampleBuffer, kCMAttachmentMode_ShouldPropagate); + _currentCaptureMetadata = (__bridge_transfer NSDictionary *)metadata; + + block(nil); + + _currentCaptureMetadata = nil; + }]; +} + + + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageStretchDistortionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageStretchDistortionFilter.h new file mode 100755 index 00000000..07803095 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageStretchDistortionFilter.h @@ -0,0 +1,13 @@ +#import "GPUImageFilter.h" + +/** Creates a stretch distortion of the image + */ +@interface GPUImageStretchDistortionFilter : GPUImageFilter { + GLint centerUniform; +} + +/** The center about which to apply the distortion, with a default of (0.5, 0.5) + */ +@property(readwrite, nonatomic) CGPoint center; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageStretchDistortionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageStretchDistortionFilter.m new file mode 100755 index 00000000..d38cac34 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageStretchDistortionFilter.m @@ -0,0 +1,99 @@ +#import "GPUImageStretchDistortionFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageStretchDistortionFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp vec2 center; + + void main() + { + highp vec2 normCoord = 2.0 * textureCoordinate - 1.0; + highp vec2 normCenter = 2.0 * center - 1.0; + + normCoord -= normCenter; + mediump vec2 s = sign(normCoord); + normCoord = abs(normCoord); + normCoord = 0.5 * normCoord + 0.5 * smoothstep(0.25, 0.5, normCoord) * normCoord; + normCoord = s * normCoord; + + normCoord += normCenter; + + mediump vec2 textureCoordinateToUse = normCoord / 2.0 + 0.5; + + + gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse ); + + } +); +#else +NSString *const kGPUImageStretchDistortionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform vec2 center; + + void main() + { + vec2 normCoord = 2.0 * textureCoordinate - 1.0; + vec2 normCenter = 2.0 * center - 1.0; + + normCoord -= normCenter; + vec2 s = sign(normCoord); + normCoord = abs(normCoord); + normCoord = 0.5 * normCoord + 0.5 * smoothstep(0.25, 0.5, normCoord) * normCoord; + normCoord = s * normCoord; + + normCoord += normCenter; + + vec2 textureCoordinateToUse = normCoord / 2.0 + 0.5; + + gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse); + } +); +#endif + +@implementation GPUImageStretchDistortionFilter + +@synthesize center = _center; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageStretchDistortionFragmentShaderString])) + { + return nil; + } + + centerUniform = [filterProgram uniformIndex:@"center"]; + + self.center = CGPointMake(0.5, 0.5); + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + [super setInputRotation:newInputRotation atIndex:textureIndex]; + [self setCenter:self.center]; +} + +- (void)setCenter:(CGPoint)newValue; +{ + _center = newValue; + + CGPoint rotatedPoint = [self rotatedPoint:_center forRotation:inputRotation]; + [self setPoint:rotatedPoint forUniform:centerUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSubtractBlendFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSubtractBlendFilter.h new file mode 100755 index 00000000..8dee8215 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSubtractBlendFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageSubtractBlendFilter : GPUImageTwoInputFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSubtractBlendFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSubtractBlendFilter.m new file mode 100755 index 00000000..8938baea --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSubtractBlendFilter.m @@ -0,0 +1,52 @@ +#import "GPUImageSubtractBlendFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSubtractBlendFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(textureColor.rgb - textureColor2.rgb, textureColor.a); + } +); +#else +NSString *const kGPUImageSubtractBlendFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2); + + gl_FragColor = vec4(textureColor.rgb - textureColor2.rgb, textureColor.a); + } +); +#endif + +@implementation GPUImageSubtractBlendFilter + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageSubtractBlendFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSwirlFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageSwirlFilter.h new file mode 100755 index 00000000..ed7d0122 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSwirlFilter.h @@ -0,0 +1,17 @@ +#import "GPUImageFilter.h" + +/** Creates a swirl distortion on the image + */ +@interface GPUImageSwirlFilter : GPUImageFilter +{ + GLint radiusUniform, centerUniform, angleUniform; +} + +/// The center about which to apply the distortion, with a default of (0.5, 0.5) +@property(readwrite, nonatomic) CGPoint center; +/// The radius of the distortion, ranging from 0.0 to 1.0, with a default of 0.5 +@property(readwrite, nonatomic) CGFloat radius; +/// The amount of distortion to apply, with a minimum of 0.0 and a default of 1.0 +@property(readwrite, nonatomic) CGFloat angle; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageSwirlFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageSwirlFilter.m new file mode 100755 index 00000000..5462bc65 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageSwirlFilter.m @@ -0,0 +1,123 @@ +#import "GPUImageSwirlFilter.h" + +// Adapted from the shader example here: http://www.geeks3d.com/20110428/shader-library-swirl-post-processing-filter-in-glsl/ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageSwirlFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp vec2 center; + uniform highp float radius; + uniform highp float angle; + + void main() + { + highp vec2 textureCoordinateToUse = textureCoordinate; + highp float dist = distance(center, textureCoordinate); + if (dist < radius) + { + textureCoordinateToUse -= center; + highp float percent = (radius - dist) / radius; + highp float theta = percent * percent * angle * 8.0; + highp float s = sin(theta); + highp float c = cos(theta); + textureCoordinateToUse = vec2(dot(textureCoordinateToUse, vec2(c, -s)), dot(textureCoordinateToUse, vec2(s, c))); + textureCoordinateToUse += center; + } + + gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse ); + + } +); +#else +NSString *const kGPUImageSwirlFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform vec2 center; + uniform float radius; + uniform float angle; + + void main() + { + vec2 textureCoordinateToUse = textureCoordinate; + float dist = distance(center, textureCoordinate); + if (dist < radius) + { + textureCoordinateToUse -= center; + float percent = (radius - dist) / radius; + float theta = percent * percent * angle * 8.0; + float s = sin(theta); + float c = cos(theta); + textureCoordinateToUse = vec2(dot(textureCoordinateToUse, vec2(c, -s)), dot(textureCoordinateToUse, vec2(s, c))); + textureCoordinateToUse += center; + } + + gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse ); + } +); +#endif + +@implementation GPUImageSwirlFilter + +@synthesize center = _center; +@synthesize radius = _radius; +@synthesize angle = _angle; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageSwirlFragmentShaderString])) + { + return nil; + } + + radiusUniform = [filterProgram uniformIndex:@"radius"]; + angleUniform = [filterProgram uniformIndex:@"angle"]; + centerUniform = [filterProgram uniformIndex:@"center"]; + + self.radius = 0.5; + self.angle = 1.0; + self.center = CGPointMake(0.5, 0.5); + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + [super setInputRotation:newInputRotation atIndex:textureIndex]; + [self setCenter:self.center]; +} + +- (void)setRadius:(CGFloat)newValue; +{ + _radius = newValue; + + [self setFloat:_radius forUniform:radiusUniform program:filterProgram]; +} + +- (void)setAngle:(CGFloat)newValue; +{ + _angle = newValue; + + [self setFloat:_angle forUniform:angleUniform program:filterProgram]; +} + +- (void)setCenter:(CGPoint)newValue; +{ + _center = newValue; + + CGPoint rotatedPoint = [self rotatedPoint:_center forRotation:inputRotation]; + [self setPoint:rotatedPoint forUniform:centerUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTextureInput.h b/LFLiveKit/Vendor/GPUImage/GPUImageTextureInput.h new file mode 100755 index 00000000..8190305d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTextureInput.h @@ -0,0 +1,14 @@ +#import "GPUImageOutput.h" + +@interface GPUImageTextureInput : GPUImageOutput +{ + CGSize textureSize; +} + +// Initialization and teardown +- (id)initWithTexture:(GLuint)newInputTexture size:(CGSize)newTextureSize; + +// Image rendering +- (void)processTextureWithFrameTime:(CMTime)frameTime; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTextureInput.m b/LFLiveKit/Vendor/GPUImage/GPUImageTextureInput.m new file mode 100755 index 00000000..ad3ca1d1 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTextureInput.m @@ -0,0 +1,46 @@ +#import "GPUImageTextureInput.h" + +@implementation GPUImageTextureInput + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithTexture:(GLuint)newInputTexture size:(CGSize)newTextureSize; +{ + if (!(self = [super init])) + { + return nil; + } + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + }); + + textureSize = newTextureSize; + + runSynchronouslyOnVideoProcessingQueue(^{ + outputFramebuffer = [[GPUImageFramebuffer alloc] initWithSize:newTextureSize overriddenTexture:newInputTexture]; + }); + + return self; +} + +#pragma mark - +#pragma mark Image rendering + +- (void)processTextureWithFrameTime:(CMTime)frameTime; +{ + runAsynchronouslyOnVideoProcessingQueue(^{ + for (id currentTarget in targets) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger targetTextureIndex = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + [currentTarget setInputSize:textureSize atIndex:targetTextureIndex]; + [currentTarget setInputFramebuffer:outputFramebuffer atIndex:targetTextureIndex]; + [currentTarget newFrameReadyAtTime:frameTime atIndex:targetTextureIndex]; + } + }); +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTextureOutput.h b/LFLiveKit/Vendor/GPUImage/GPUImageTextureOutput.h new file mode 100755 index 00000000..05e1f36e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTextureOutput.h @@ -0,0 +1,21 @@ +#import +#import "GPUImageContext.h" + +@protocol GPUImageTextureOutputDelegate; + +@interface GPUImageTextureOutput : NSObject +{ + GPUImageFramebuffer *firstInputFramebuffer; +} + +@property(readwrite, unsafe_unretained, nonatomic) id delegate; +@property(readonly) GLuint texture; +@property(nonatomic) BOOL enabled; + +- (void)doneWithTexture; + +@end + +@protocol GPUImageTextureOutputDelegate +- (void)newFrameReadyFromTextureOutput:(GPUImageTextureOutput *)callbackTextureOutput; +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTextureOutput.m b/LFLiveKit/Vendor/GPUImage/GPUImageTextureOutput.m new file mode 100755 index 00000000..1e1f24f2 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTextureOutput.m @@ -0,0 +1,83 @@ +#import "GPUImageTextureOutput.h" + +@implementation GPUImageTextureOutput + +@synthesize delegate = _delegate; +@synthesize texture = _texture; +@synthesize enabled; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + self.enabled = YES; + + return self; +} + +- (void)doneWithTexture; +{ + [firstInputFramebuffer unlock]; +} + +#pragma mark - +#pragma mark GPUImageInput protocol + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + [_delegate newFrameReadyFromTextureOutput:self]; +} + +- (NSInteger)nextAvailableTextureIndex; +{ + return 0; +} + +// TODO: Deal with the fact that the texture changes regularly as a result of the caching +- (void)setInputFramebuffer:(GPUImageFramebuffer *)newInputFramebuffer atIndex:(NSInteger)textureIndex; +{ + firstInputFramebuffer = newInputFramebuffer; + [firstInputFramebuffer lock]; + + _texture = [firstInputFramebuffer texture]; +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ +} + +- (CGSize)maximumOutputSize; +{ + return CGSizeZero; +} + +- (void)endProcessing +{ +} + +- (BOOL)shouldIgnoreUpdatesToThisTarget; +{ + return NO; +} + +- (BOOL)wantsMonochromeInput; +{ + return NO; +} + +- (void)setCurrentlyReceivingMonochromeInput:(BOOL)newValue; +{ + +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageThreeInputFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageThreeInputFilter.h new file mode 100644 index 00000000..5ecd53e0 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageThreeInputFilter.h @@ -0,0 +1,21 @@ +#import "GPUImageTwoInputFilter.h" + +extern NSString *const kGPUImageThreeInputTextureVertexShaderString; + +@interface GPUImageThreeInputFilter : GPUImageTwoInputFilter +{ + GPUImageFramebuffer *thirdInputFramebuffer; + + GLint filterThirdTextureCoordinateAttribute; + GLint filterInputTextureUniform3; + GPUImageRotationMode inputRotation3; + GLuint filterSourceTexture3; + CMTime thirdFrameTime; + + BOOL hasSetSecondTexture, hasReceivedThirdFrame, thirdFrameWasVideo; + BOOL thirdFrameCheckDisabled; +} + +- (void)disableThirdFrameCheck; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageThreeInputFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageThreeInputFilter.m new file mode 100644 index 00000000..2f4f113f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageThreeInputFilter.m @@ -0,0 +1,328 @@ +#import "GPUImageThreeInputFilter.h" + + +NSString *const kGPUImageThreeInputTextureVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + attribute vec4 inputTextureCoordinate2; + attribute vec4 inputTextureCoordinate3; + + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + varying vec2 textureCoordinate3; + + void main() + { + gl_Position = position; + textureCoordinate = inputTextureCoordinate.xy; + textureCoordinate2 = inputTextureCoordinate2.xy; + textureCoordinate3 = inputTextureCoordinate3.xy; + } +); + +@implementation GPUImageThreeInputFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [self initWithVertexShaderFromString:kGPUImageThreeInputTextureVertexShaderString fragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + return self; +} + +- (id)initWithVertexShaderFromString:(NSString *)vertexShaderString fragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [super initWithVertexShaderFromString:vertexShaderString fragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + inputRotation3 = kGPUImageNoRotation; + + hasSetSecondTexture = NO; + + hasReceivedThirdFrame = NO; + thirdFrameWasVideo = NO; + thirdFrameCheckDisabled = NO; + + thirdFrameTime = kCMTimeInvalid; + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + filterThirdTextureCoordinateAttribute = [filterProgram attributeIndex:@"inputTextureCoordinate3"]; + + filterInputTextureUniform3 = [filterProgram uniformIndex:@"inputImageTexture3"]; // This does assume a name of "inputImageTexture3" for the third input texture in the fragment shader + glEnableVertexAttribArray(filterThirdTextureCoordinateAttribute); + }); + + return self; +} + +- (void)initializeAttributes; +{ + [super initializeAttributes]; + [filterProgram addAttribute:@"inputTextureCoordinate3"]; +} + +- (void)disableThirdFrameCheck; +{ + thirdFrameCheckDisabled = YES; +} + +#pragma mark - +#pragma mark Rendering + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + if (self.preventRendering) + { + [firstInputFramebuffer unlock]; + [secondInputFramebuffer unlock]; + [thirdInputFramebuffer unlock]; + return; + } + + [GPUImageContext setActiveShaderProgram:filterProgram]; + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + if (usingNextFrameForImageCapture) + { + [outputFramebuffer lock]; + } + + [self setUniformsForProgramAtIndex:0]; + + glClearColor(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha); + glClear(GL_COLOR_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, [firstInputFramebuffer texture]); + glUniform1i(filterInputTextureUniform, 2); + + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, [secondInputFramebuffer texture]); + glUniform1i(filterInputTextureUniform2, 3); + + glActiveTexture(GL_TEXTURE4); + glBindTexture(GL_TEXTURE_2D, [thirdInputFramebuffer texture]); + glUniform1i(filterInputTextureUniform3, 4); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + glVertexAttribPointer(filterSecondTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [[self class] textureCoordinatesForRotation:inputRotation2]); + glVertexAttribPointer(filterThirdTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [[self class] textureCoordinatesForRotation:inputRotation3]); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + [firstInputFramebuffer unlock]; + [secondInputFramebuffer unlock]; + [thirdInputFramebuffer unlock]; + if (usingNextFrameForImageCapture) + { + dispatch_semaphore_signal(imageCaptureSemaphore); + } +} + +#pragma mark - +#pragma mark GPUImageInput + +- (NSInteger)nextAvailableTextureIndex; +{ + if (hasSetSecondTexture) + { + return 2; + } + else if (hasSetFirstTexture) + { + return 1; + } + else + { + return 0; + } +} + +- (void)setInputFramebuffer:(GPUImageFramebuffer *)newInputFramebuffer atIndex:(NSInteger)textureIndex; +{ + if (textureIndex == 0) + { + firstInputFramebuffer = newInputFramebuffer; + hasSetFirstTexture = YES; + [firstInputFramebuffer lock]; + } + else if (textureIndex == 1) + { + secondInputFramebuffer = newInputFramebuffer; + hasSetSecondTexture = YES; + [secondInputFramebuffer lock]; + } + else + { + thirdInputFramebuffer = newInputFramebuffer; + [thirdInputFramebuffer lock]; + } +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + if (textureIndex == 0) + { + [super setInputSize:newSize atIndex:textureIndex]; + + if (CGSizeEqualToSize(newSize, CGSizeZero)) + { + hasSetFirstTexture = NO; + } + } + else if (textureIndex == 1) + { + if (CGSizeEqualToSize(newSize, CGSizeZero)) + { + hasSetSecondTexture = NO; + } + } +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + if (textureIndex == 0) + { + inputRotation = newInputRotation; + } + else if (textureIndex == 1) + { + inputRotation2 = newInputRotation; + } + else + { + inputRotation3 = newInputRotation; + } +} + +- (CGSize)rotatedSize:(CGSize)sizeToRotate forIndex:(NSInteger)textureIndex; +{ + CGSize rotatedSize = sizeToRotate; + + GPUImageRotationMode rotationToCheck; + if (textureIndex == 0) + { + rotationToCheck = inputRotation; + } + else if (textureIndex == 1) + { + rotationToCheck = inputRotation2; + } + else + { + rotationToCheck = inputRotation3; + } + + if (GPUImageRotationSwapsWidthAndHeight(rotationToCheck)) + { + rotatedSize.width = sizeToRotate.height; + rotatedSize.height = sizeToRotate.width; + } + + return rotatedSize; +} + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + // You can set up infinite update loops, so this helps to short circuit them + if (hasReceivedFirstFrame && hasReceivedSecondFrame && hasReceivedThirdFrame) + { + return; + } + + BOOL updatedMovieFrameOppositeStillImage = NO; + + if (textureIndex == 0) + { + hasReceivedFirstFrame = YES; + firstFrameTime = frameTime; + if (secondFrameCheckDisabled) + { + hasReceivedSecondFrame = YES; + } + if (thirdFrameCheckDisabled) + { + hasReceivedThirdFrame = YES; + } + + if (!CMTIME_IS_INDEFINITE(frameTime)) + { + if CMTIME_IS_INDEFINITE(secondFrameTime) + { + updatedMovieFrameOppositeStillImage = YES; + } + } + } + else if (textureIndex == 1) + { + hasReceivedSecondFrame = YES; + secondFrameTime = frameTime; + if (firstFrameCheckDisabled) + { + hasReceivedFirstFrame = YES; + } + if (thirdFrameCheckDisabled) + { + hasReceivedThirdFrame = YES; + } + + if (!CMTIME_IS_INDEFINITE(frameTime)) + { + if CMTIME_IS_INDEFINITE(firstFrameTime) + { + updatedMovieFrameOppositeStillImage = YES; + } + } + } + else + { + hasReceivedThirdFrame = YES; + thirdFrameTime = frameTime; + if (firstFrameCheckDisabled) + { + hasReceivedFirstFrame = YES; + } + if (secondFrameCheckDisabled) + { + hasReceivedSecondFrame = YES; + } + + if (!CMTIME_IS_INDEFINITE(frameTime)) + { + if CMTIME_IS_INDEFINITE(firstFrameTime) + { + updatedMovieFrameOppositeStillImage = YES; + } + } + } + + // || (hasReceivedFirstFrame && secondFrameCheckDisabled) || (hasReceivedSecondFrame && firstFrameCheckDisabled) + if ((hasReceivedFirstFrame && hasReceivedSecondFrame && hasReceivedThirdFrame) || updatedMovieFrameOppositeStillImage) + { + static const GLfloat imageVertices[] = { + -1.0f, -1.0f, + 1.0f, -1.0f, + -1.0f, 1.0f, + 1.0f, 1.0f, + }; + + [self renderToTextureWithVertices:imageVertices textureCoordinates:[[self class] textureCoordinatesForRotation:inputRotation]]; + + [self informTargetsAboutNewFrameAtTime:frameTime]; + + hasReceivedFirstFrame = NO; + hasReceivedSecondFrame = NO; + hasReceivedThirdFrame = NO; + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageThresholdEdgeDetectionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdEdgeDetectionFilter.h new file mode 100755 index 00000000..2036030c --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdEdgeDetectionFilter.h @@ -0,0 +1,12 @@ +#import "GPUImageSobelEdgeDetectionFilter.h" + +@interface GPUImageThresholdEdgeDetectionFilter : GPUImageSobelEdgeDetectionFilter +{ + GLint thresholdUniform; +} + +/** Any edge above this threshold will be black, and anything below white. Ranges from 0.0 to 1.0, with 0.8 as the default + */ +@property(readwrite, nonatomic) CGFloat threshold; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageThresholdEdgeDetectionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdEdgeDetectionFilter.m new file mode 100755 index 00000000..553c600f --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdEdgeDetectionFilter.m @@ -0,0 +1,145 @@ +#import "GPUImageThresholdEdgeDetectionFilter.h" + +@implementation GPUImageThresholdEdgeDetectionFilter + +// Invert the colorspace for a sketch +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageThresholdEdgeDetectionFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform lowp float threshold; + + uniform float edgeStrength; + + void main() + { +// float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; +// float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; +// float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; +// float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float centerIntensity = texture2D(inputImageTexture, textureCoordinate).r; +// float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; +// float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; +// float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + leftIntensity + 2.0 * centerIntensity + rightIntensity; +// float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomIntensity + 2.0 * centerIntensity + topIntensity; + float h = (centerIntensity - topIntensity) + (bottomIntensity - centerIntensity); + float v = (centerIntensity - leftIntensity) + (rightIntensity - centerIntensity); +// float h = (centerIntensity - topIntensity); +// float j = (topIntensity - centerIntensity); +// h = max(h,j); +// j = abs(h); +// float v = (centerIntensity - leftIntensity); + + float mag = length(vec2(h, v)) * edgeStrength; + mag = step(threshold, mag); + +// float mag = abs(h); + +// gl_FragColor = vec4(h, h, h, 1.0); +// gl_FragColor = vec4(texture2D(inputImageTexture, textureCoordinate)); +// gl_FragColor = vec4(h, centerIntensity, j, 1.0); + gl_FragColor = vec4(mag, mag, mag, 1.0); + } +); +#else +NSString *const kGPUImageThresholdEdgeDetectionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float threshold; + + uniform float edgeStrength; + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; + h = max(0.0, h); + float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; + v = max(0.0, v); + + float mag = length(vec2(h, v)) * edgeStrength; + mag = step(threshold, mag); + + gl_FragColor = vec4(vec3(mag), 1.0); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +@synthesize threshold = _threshold; + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [super initWithFragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + thresholdUniform = [secondFilterProgram uniformIndex:@"threshold"]; + self.threshold = 0.25; + self.edgeStrength = 1.0; + + return self; +} + + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImageThresholdEdgeDetectionFragmentShaderString])) + { + return nil; + } + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setThreshold:(CGFloat)newValue; +{ + _threshold = newValue; + + [self setFloat:_threshold forUniform:thresholdUniform program:secondFilterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageThresholdSketchFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdSketchFilter.h new file mode 100644 index 00000000..fda58979 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdSketchFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageThresholdEdgeDetectionFilter.h" + +@interface GPUImageThresholdSketchFilter : GPUImageThresholdEdgeDetectionFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageThresholdSketchFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdSketchFilter.m new file mode 100644 index 00000000..d24e9dea --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdSketchFilter.m @@ -0,0 +1,103 @@ +#import "GPUImageThresholdSketchFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageThresholdSketchFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform lowp float threshold; + uniform float edgeStrength; + + const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; + float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; + + float mag = (length(vec2(h, v)) * edgeStrength); + mag = step(threshold, mag); + mag = 1.0 - mag; + + gl_FragColor = vec4(vec3(mag), 1.0); + } +); +#else +NSString *const kGPUImageThresholdSketchFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + uniform float threshold; + uniform float edgeStrength; + + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; + float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; + + float mag = 1.0 - length(vec2(h, v) * edgeStrength); + mag = step(threshold, mag); + + gl_FragColor = vec4(vec3(mag), 1.0); + } +); +#endif + +@implementation GPUImageThresholdSketchFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImageThresholdSketchFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageThresholdedNonMaximumSuppressionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdedNonMaximumSuppressionFilter.h new file mode 100644 index 00000000..9c6e5d72 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdedNonMaximumSuppressionFilter.h @@ -0,0 +1,14 @@ +#import "GPUImage3x3TextureSamplingFilter.h" + +@interface GPUImageThresholdedNonMaximumSuppressionFilter : GPUImage3x3TextureSamplingFilter +{ + GLint thresholdUniform; +} + +/** Any local maximum above this threshold will be white, and anything below black. Ranges from 0.0 to 1.0, with 0.8 as the default + */ +@property(readwrite, nonatomic) CGFloat threshold; + +- (id)initWithPackedColorspace:(BOOL)inputUsesPackedColorspace; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageThresholdedNonMaximumSuppressionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdedNonMaximumSuppressionFilter.m new file mode 100644 index 00000000..439d3119 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageThresholdedNonMaximumSuppressionFilter.m @@ -0,0 +1,297 @@ +#import "GPUImageThresholdedNonMaximumSuppressionFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageThresholdedNonMaximumSuppressionFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + varying highp vec2 textureCoordinate; + varying highp vec2 leftTextureCoordinate; + varying highp vec2 rightTextureCoordinate; + + varying highp vec2 topTextureCoordinate; + varying highp vec2 topLeftTextureCoordinate; + varying highp vec2 topRightTextureCoordinate; + + varying highp vec2 bottomTextureCoordinate; + varying highp vec2 bottomLeftTextureCoordinate; + varying highp vec2 bottomRightTextureCoordinate; + + uniform lowp float threshold; + + void main() + { + lowp float bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).r; + lowp float bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + lowp float bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + lowp vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); + lowp float leftColor = texture2D(inputImageTexture, leftTextureCoordinate).r; + lowp float rightColor = texture2D(inputImageTexture, rightTextureCoordinate).r; + lowp float topColor = texture2D(inputImageTexture, topTextureCoordinate).r; + lowp float topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).r; + lowp float topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + + // Use a tiebreaker for pixels to the left and immediately above this one + lowp float multiplier = 1.0 - step(centerColor.r, topColor); + multiplier = multiplier * (1.0 - step(centerColor.r, topLeftColor)); + multiplier = multiplier * (1.0 - step(centerColor.r, leftColor)); + multiplier = multiplier * (1.0 - step(centerColor.r, bottomLeftColor)); + + lowp float maxValue = max(centerColor.r, bottomColor); + maxValue = max(maxValue, bottomRightColor); + maxValue = max(maxValue, rightColor); + maxValue = max(maxValue, topRightColor); + + lowp float finalValue = centerColor.r * step(maxValue, centerColor.r) * multiplier; + finalValue = step(threshold, finalValue); + + gl_FragColor = vec4(finalValue, finalValue, finalValue, 1.0); +// +// gl_FragColor = vec4((centerColor.rgb * step(maxValue, step(threshold, centerColor.r)) * multiplier), 1.0); + } +); + +NSString *const kGPUImageThresholdedNonMaximumSuppressionPackedColorspaceFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + varying highp vec2 textureCoordinate; + varying highp vec2 leftTextureCoordinate; + varying highp vec2 rightTextureCoordinate; + + varying highp vec2 topTextureCoordinate; + varying highp vec2 topLeftTextureCoordinate; + varying highp vec2 topRightTextureCoordinate; + + varying highp vec2 bottomTextureCoordinate; + varying highp vec2 bottomLeftTextureCoordinate; + varying highp vec2 bottomRightTextureCoordinate; + + uniform lowp float threshold; + uniform highp float texelWidth; + uniform highp float texelHeight; + + highp float encodedIntensity(highp vec3 sourceColor) + { + return (sourceColor.b * 256.0 * 256.0 + sourceColor.g * 256.0 + sourceColor.r); + } + + void main() + { + highp float bottomColor = encodedIntensity(texture2D(inputImageTexture, bottomTextureCoordinate).rgb); + highp float bottomLeftColor = encodedIntensity(texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb); + highp float bottomRightColor = encodedIntensity(texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb); + highp float centerColor = encodedIntensity(texture2D(inputImageTexture, textureCoordinate).rgb); + highp float leftColor = encodedIntensity(texture2D(inputImageTexture, leftTextureCoordinate).rgb); + highp float rightColor = encodedIntensity(texture2D(inputImageTexture, rightTextureCoordinate).rgb); + highp float topColor = encodedIntensity(texture2D(inputImageTexture, topTextureCoordinate).rgb); + highp float topRightColor = encodedIntensity(texture2D(inputImageTexture, topRightTextureCoordinate).rgb); + highp float topLeftColor = encodedIntensity(texture2D(inputImageTexture, topLeftTextureCoordinate).rgb); + + highp float secondStageColor1 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-2.0 * texelWidth, -2.0 * texelHeight)).rgb); + highp float secondStageColor2 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-2.0 * texelWidth, -1.0 * texelHeight)).rgb); + highp float secondStageColor3 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-2.0 * texelWidth, 0.0)).rgb); + highp float secondStageColor4 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-2.0 * texelWidth, 1.0 * texelHeight)).rgb); + highp float secondStageColor5 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-2.0 * texelWidth, 2.0 * texelHeight)).rgb); + highp float secondStageColor6 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-1.0 * texelWidth, 2.0 * texelHeight)).rgb); + highp float secondStageColor7 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(0.0, 2.0 * texelHeight)).rgb); + highp float secondStageColor8 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(1.0 * texelWidth, 2.0 * texelHeight)).rgb); + + highp float thirdStageColor1 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(-1.0 * texelWidth, -2.0 * texelHeight)).rgb); + highp float thirdStageColor2 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(0.0, -2.0 * texelHeight)).rgb); + highp float thirdStageColor3 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(1.0 * texelWidth, -2.0 * texelHeight)).rgb); + highp float thirdStageColor4 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(2.0 * texelWidth, -2.0 * texelHeight)).rgb); + highp float thirdStageColor5 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(2.0 * texelWidth, -1.0 * texelHeight)).rgb); + highp float thirdStageColor6 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(2.0 * texelWidth, 0.0)).rgb); + highp float thirdStageColor7 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(2.0 * texelWidth, 1.0 * texelHeight)).rgb); + highp float thirdStageColor8 = encodedIntensity(texture2D(inputImageTexture, textureCoordinate + vec2(2.0 * texelWidth, 2.0 * texelHeight)).rgb); + + // Use a tiebreaker for pixels to the left and immediately above this one + highp float multiplier = 1.0 - step(centerColor, topColor); + multiplier = multiplier * (1.0 - step(centerColor, topLeftColor)); + multiplier = multiplier * (1.0 - step(centerColor, leftColor)); + multiplier = multiplier * (1.0 - step(centerColor, bottomLeftColor)); + + multiplier = multiplier * (1.0 - step(centerColor, secondStageColor1)); + multiplier = multiplier * (1.0 - step(centerColor, secondStageColor2)); + multiplier = multiplier * (1.0 - step(centerColor, secondStageColor3)); + multiplier = multiplier * (1.0 - step(centerColor, secondStageColor4)); + multiplier = multiplier * (1.0 - step(centerColor, secondStageColor5)); + multiplier = multiplier * (1.0 - step(centerColor, secondStageColor6)); + multiplier = multiplier * (1.0 - step(centerColor, secondStageColor7)); + multiplier = multiplier * (1.0 - step(centerColor, secondStageColor8)); + + highp float maxValue = max(centerColor, bottomColor); + maxValue = max(maxValue, bottomRightColor); + maxValue = max(maxValue, rightColor); + maxValue = max(maxValue, topRightColor); + + maxValue = max(maxValue, thirdStageColor1); + maxValue = max(maxValue, thirdStageColor2); + maxValue = max(maxValue, thirdStageColor3); + maxValue = max(maxValue, thirdStageColor4); + maxValue = max(maxValue, thirdStageColor5); + maxValue = max(maxValue, thirdStageColor6); + maxValue = max(maxValue, thirdStageColor7); + maxValue = max(maxValue, thirdStageColor8); + + highp float midValue = centerColor * step(maxValue, centerColor) * multiplier; + highp float finalValue = step(threshold, midValue); + + gl_FragColor = vec4(finalValue * centerColor, topLeftColor, topRightColor, topColor); + } +); +#else +NSString *const kGPUImageThresholdedNonMaximumSuppressionFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform float threshold; + + void main() + { + float bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); + float leftColor = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightColor = texture2D(inputImageTexture, rightTextureCoordinate).r; + float topColor = texture2D(inputImageTexture, topTextureCoordinate).r; + float topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + + // Use a tiebreaker for pixels to the left and immediately above this one + float multiplier = 1.0 - step(centerColor.r, topColor); + multiplier = multiplier * (1.0 - step(centerColor.r, topLeftColor)); + multiplier = multiplier * (1.0 - step(centerColor.r, leftColor)); + multiplier = multiplier * (1.0 - step(centerColor.r, bottomLeftColor)); + + float maxValue = max(centerColor.r, bottomColor); + maxValue = max(maxValue, bottomRightColor); + maxValue = max(maxValue, rightColor); + maxValue = max(maxValue, topRightColor); + + float finalValue = centerColor.r * step(maxValue, centerColor.r) * multiplier; + finalValue = step(threshold, finalValue); + + gl_FragColor = vec4(finalValue, finalValue, finalValue, 1.0); + // + // gl_FragColor = vec4((centerColor.rgb * step(maxValue, step(threshold, centerColor.r)) * multiplier), 1.0); + } +); + +NSString *const kGPUImageThresholdedNonMaximumSuppressionPackedColorspaceFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform float threshold; + + void main() + { + float bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + vec4 centerColor = texture2D(inputImageTexture, textureCoordinate); + float leftColor = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightColor = texture2D(inputImageTexture, rightTextureCoordinate).r; + float topColor = texture2D(inputImageTexture, topTextureCoordinate).r; + float topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + + // Use a tiebreaker for pixels to the left and immediately above this one + float multiplier = 1.0 - step(centerColor.r, topColor); + multiplier = multiplier * (1.0 - step(centerColor.r, topLeftColor)); + multiplier = multiplier * (1.0 - step(centerColor.r, leftColor)); + multiplier = multiplier * (1.0 - step(centerColor.r, bottomLeftColor)); + + float maxValue = max(centerColor.r, bottomColor); + maxValue = max(maxValue, bottomRightColor); + maxValue = max(maxValue, rightColor); + maxValue = max(maxValue, topRightColor); + + float finalValue = centerColor.r * step(maxValue, centerColor.r) * multiplier; + finalValue = step(threshold, finalValue); + + gl_FragColor = vec4(finalValue, finalValue, finalValue, 1.0); + // + // gl_FragColor = vec4((centerColor.rgb * step(maxValue, step(threshold, centerColor.r)) * multiplier), 1.0); + } + ); +#endif + +@implementation GPUImageThresholdedNonMaximumSuppressionFilter + +@synthesize threshold = _threshold; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithPackedColorspace:NO])) + { + return nil; + } + + return self; +} + +- (id)initWithPackedColorspace:(BOOL)inputUsesPackedColorspace; +{ + NSString *shaderString; + if (inputUsesPackedColorspace) + { + shaderString = kGPUImageThresholdedNonMaximumSuppressionPackedColorspaceFragmentShaderString; + } + else + { + shaderString = kGPUImageThresholdedNonMaximumSuppressionFragmentShaderString; + } + + + if (!(self = [super initWithFragmentShaderFromString:shaderString])) + { + return nil; + } + + thresholdUniform = [filterProgram uniformIndex:@"threshold"]; + self.threshold = 0.9; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setThreshold:(CGFloat)newValue; +{ + _threshold = newValue; + + [self setFloat:_threshold forUniform:thresholdUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTiltShiftFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageTiltShiftFilter.h new file mode 100755 index 00000000..e41adee7 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTiltShiftFilter.h @@ -0,0 +1,24 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImageGaussianBlurFilter; + +/// A simulated tilt shift lens effect +@interface GPUImageTiltShiftFilter : GPUImageFilterGroup +{ + GPUImageGaussianBlurFilter *blurFilter; + GPUImageFilter *tiltShiftFilter; +} + +/// The radius of the underlying blur, in pixels. This is 7.0 by default. +@property(readwrite, nonatomic) CGFloat blurRadiusInPixels; + +/// The normalized location of the top of the in-focus area in the image, this value should be lower than bottomFocusLevel, default 0.4 +@property(readwrite, nonatomic) CGFloat topFocusLevel; + +/// The normalized location of the bottom of the in-focus area in the image, this value should be higher than topFocusLevel, default 0.6 +@property(readwrite, nonatomic) CGFloat bottomFocusLevel; + +/// The rate at which the image gets blurry away from the in-focus region, default 0.2 +@property(readwrite, nonatomic) CGFloat focusFallOffRate; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTiltShiftFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageTiltShiftFilter.m new file mode 100755 index 00000000..e2f632b1 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTiltShiftFilter.m @@ -0,0 +1,126 @@ +#import "GPUImageTiltShiftFilter.h" +#import "GPUImageFilter.h" +#import "GPUImageTwoInputFilter.h" +#import "GPUImageGaussianBlurFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageTiltShiftFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform highp float topFocusLevel; + uniform highp float bottomFocusLevel; + uniform highp float focusFallOffRate; + + void main() + { + lowp vec4 sharpImageColor = texture2D(inputImageTexture, textureCoordinate); + lowp vec4 blurredImageColor = texture2D(inputImageTexture2, textureCoordinate2); + + lowp float blurIntensity = 1.0 - smoothstep(topFocusLevel - focusFallOffRate, topFocusLevel, textureCoordinate2.y); + blurIntensity += smoothstep(bottomFocusLevel, bottomFocusLevel + focusFallOffRate, textureCoordinate2.y); + + gl_FragColor = mix(sharpImageColor, blurredImageColor, blurIntensity); + } +); +#else +NSString *const kGPUImageTiltShiftFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform float topFocusLevel; + uniform float bottomFocusLevel; + uniform float focusFallOffRate; + + void main() + { + vec4 sharpImageColor = texture2D(inputImageTexture, textureCoordinate); + vec4 blurredImageColor = texture2D(inputImageTexture2, textureCoordinate2); + + float blurIntensity = 1.0 - smoothstep(topFocusLevel - focusFallOffRate, topFocusLevel, textureCoordinate2.y); + blurIntensity += smoothstep(bottomFocusLevel, bottomFocusLevel + focusFallOffRate, textureCoordinate2.y); + + gl_FragColor = mix(sharpImageColor, blurredImageColor, blurIntensity); + } +); +#endif + +@implementation GPUImageTiltShiftFilter + +@synthesize blurRadiusInPixels; +@synthesize topFocusLevel = _topFocusLevel; +@synthesize bottomFocusLevel = _bottomFocusLevel; +@synthesize focusFallOffRate = _focusFallOffRate; + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + // First pass: apply a variable Gaussian blur + blurFilter = [[GPUImageGaussianBlurFilter alloc] init]; + [self addFilter:blurFilter]; + + // Second pass: combine the blurred image with the original sharp one + tiltShiftFilter = [[GPUImageTwoInputFilter alloc] initWithFragmentShaderFromString:kGPUImageTiltShiftFragmentShaderString]; + [self addFilter:tiltShiftFilter]; + + // Texture location 0 needs to be the sharp image for both the blur and the second stage processing + [blurFilter addTarget:tiltShiftFilter atTextureLocation:1]; + + // To prevent double updating of this filter, disable updates from the sharp image side +// self.inputFilterToIgnoreForUpdates = tiltShiftFilter; + + self.initialFilters = [NSArray arrayWithObjects:blurFilter, tiltShiftFilter, nil]; + self.terminalFilter = tiltShiftFilter; + + self.topFocusLevel = 0.4; + self.bottomFocusLevel = 0.6; + self.focusFallOffRate = 0.2; + self.blurRadiusInPixels = 7.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBlurRadiusInPixels:(CGFloat)newValue; +{ + blurFilter.blurRadiusInPixels = newValue; +} + +- (CGFloat)blurRadiusInPixels; +{ + return blurFilter.blurRadiusInPixels; +} + +- (void)setTopFocusLevel:(CGFloat)newValue; +{ + _topFocusLevel = newValue; + [tiltShiftFilter setFloat:newValue forUniformName:@"topFocusLevel"]; +} + +- (void)setBottomFocusLevel:(CGFloat)newValue; +{ + _bottomFocusLevel = newValue; + [tiltShiftFilter setFloat:newValue forUniformName:@"bottomFocusLevel"]; +} + +- (void)setFocusFallOffRate:(CGFloat)newValue; +{ + _focusFallOffRate = newValue; + [tiltShiftFilter setFloat:newValue forUniformName:@"focusFallOffRate"]; +} + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageToneCurveFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageToneCurveFilter.h new file mode 100755 index 00000000..ff4ae92e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageToneCurveFilter.h @@ -0,0 +1,30 @@ +#import "GPUImageFilter.h" + +@interface GPUImageToneCurveFilter : GPUImageFilter + +@property(readwrite, nonatomic, copy) NSArray *redControlPoints; +@property(readwrite, nonatomic, copy) NSArray *greenControlPoints; +@property(readwrite, nonatomic, copy) NSArray *blueControlPoints; +@property(readwrite, nonatomic, copy) NSArray *rgbCompositeControlPoints; + +// Initialization and teardown +- (id)initWithACVData:(NSData*)data; + +- (id)initWithACV:(NSString*)curveFilename; +- (id)initWithACVURL:(NSURL*)curveFileURL; + +// This lets you set all three red, green, and blue tone curves at once. +// NOTE: Deprecated this function because this effect can be accomplished +// using the rgbComposite channel rather then setting all 3 R, G, and B channels. +- (void)setRGBControlPoints:(NSArray *)points DEPRECATED_ATTRIBUTE; + +- (void)setPointsWithACV:(NSString*)curveFilename; +- (void)setPointsWithACVURL:(NSURL*)curveFileURL; + +// Curve calculation +- (NSMutableArray *)getPreparedSplineCurve:(NSArray *)points; +- (NSMutableArray *)splineCurve:(NSArray *)points; +- (NSMutableArray *)secondDerivative:(NSArray *)cgPoints; +- (void)updateToneCurveTexture; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageToneCurveFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageToneCurveFilter.m new file mode 100644 index 00000000..18a717e0 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageToneCurveFilter.m @@ -0,0 +1,621 @@ +#import "GPUImageToneCurveFilter.h" + +#pragma mark - +#pragma mark GPUImageACVFile Helper + +// GPUImageACVFile +// +// ACV File format Parser +// Please refer to http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/PhotoshopFileFormats.htm#50577411_pgfId-1056330 +// + +@interface GPUImageACVFile : NSObject{ + short version; + short totalCurves; + + NSArray *rgbCompositeCurvePoints; + NSArray *redCurvePoints; + NSArray *greenCurvePoints; + NSArray *blueCurvePoints; +} + +@property(strong,nonatomic) NSArray *rgbCompositeCurvePoints; +@property(strong,nonatomic) NSArray *redCurvePoints; +@property(strong,nonatomic) NSArray *greenCurvePoints; +@property(strong,nonatomic) NSArray *blueCurvePoints; + +- (id) initWithACVFileData:(NSData*)data; + + +unsigned short int16WithBytes(Byte* bytes); +@end + +@implementation GPUImageACVFile + +@synthesize rgbCompositeCurvePoints, redCurvePoints, greenCurvePoints, blueCurvePoints; + +- (id) initWithACVFileData:(NSData *)data { + self = [super init]; + if (self != nil) + { + if (data.length == 0) + { + NSLog(@"failed to init ACVFile with data:%@", data); + + return self; + } + + Byte* rawBytes = (Byte*) [data bytes]; + version = int16WithBytes(rawBytes); + rawBytes+=2; + + totalCurves = int16WithBytes(rawBytes); + rawBytes+=2; + + NSMutableArray *curves = [NSMutableArray new]; + + float pointRate = (1.0 / 255); + // The following is the data for each curve specified by count above + for (NSInteger x = 0; x 0) + { + // Sort the array. + NSArray *sortedPoints = [points sortedArrayUsingComparator:^NSComparisonResult(id a, id b) { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + float x1 = [(NSValue *)a CGPointValue].x; + float x2 = [(NSValue *)b CGPointValue].x; +#else + float x1 = [(NSValue *)a pointValue].x; + float x2 = [(NSValue *)b pointValue].x; +#endif + return x1 > x2; + }]; + + // Convert from (0, 1) to (0, 255). + NSMutableArray *convertedPoints = [NSMutableArray arrayWithCapacity:[sortedPoints count]]; + for (int i=0; i<[points count]; i++){ +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + CGPoint point = [[sortedPoints objectAtIndex:i] CGPointValue]; +#else + NSPoint point = [[sortedPoints objectAtIndex:i] pointValue]; +#endif + point.x = point.x * 255; + point.y = point.y * 255; + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [convertedPoints addObject:[NSValue valueWithCGPoint:point]]; +#else + [convertedPoints addObject:[NSValue valueWithPoint:point]]; +#endif + } + + + NSMutableArray *splinePoints = [self splineCurve:convertedPoints]; + + // If we have a first point like (0.3, 0) we'll be missing some points at the beginning + // that should be 0. +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + CGPoint firstSplinePoint = [[splinePoints objectAtIndex:0] CGPointValue]; +#else + NSPoint firstSplinePoint = [[splinePoints objectAtIndex:0] pointValue]; +#endif + + if (firstSplinePoint.x > 0) { + for (int i=firstSplinePoint.x; i >= 0; i--) { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + CGPoint newCGPoint = CGPointMake(i, 0); + [splinePoints insertObject:[NSValue valueWithCGPoint:newCGPoint] atIndex:0]; +#else + NSPoint newNSPoint = NSMakePoint(i, 0); + [splinePoints insertObject:[NSValue valueWithPoint:newNSPoint] atIndex:0]; +#endif + } + } + + // Insert points similarly at the end, if necessary. +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + CGPoint lastSplinePoint = [[splinePoints lastObject] CGPointValue]; + + if (lastSplinePoint.x < 255) { + for (int i = lastSplinePoint.x + 1; i <= 255; i++) { + CGPoint newCGPoint = CGPointMake(i, 255); + [splinePoints addObject:[NSValue valueWithCGPoint:newCGPoint]]; + } + } +#else + NSPoint lastSplinePoint = [[splinePoints lastObject] pointValue]; + + if (lastSplinePoint.x < 255) { + for (int i = lastSplinePoint.x + 1; i <= 255; i++) { + NSPoint newNSPoint = NSMakePoint(i, 255); + [splinePoints addObject:[NSValue valueWithPoint:newNSPoint]]; + } + } +#endif + + // Prepare the spline points. + NSMutableArray *preparedSplinePoints = [NSMutableArray arrayWithCapacity:[splinePoints count]]; + for (int i=0; i<[splinePoints count]; i++) + { +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + CGPoint newPoint = [[splinePoints objectAtIndex:i] CGPointValue]; +#else + NSPoint newPoint = [[splinePoints objectAtIndex:i] pointValue]; +#endif + CGPoint origPoint = CGPointMake(newPoint.x, newPoint.x); + + float distance = sqrt(pow((origPoint.x - newPoint.x), 2.0) + pow((origPoint.y - newPoint.y), 2.0)); + + if (origPoint.y > newPoint.y) + { + distance = -distance; + } + + [preparedSplinePoints addObject:[NSNumber numberWithFloat:distance]]; + } + + return preparedSplinePoints; + } + + return nil; +} + + +- (NSMutableArray *)splineCurve:(NSArray *)points +{ + NSMutableArray *sdA = [self secondDerivative:points]; + + // [points count] is equal to [sdA count] + NSInteger n = [sdA count]; + if (n < 1) + { + return nil; + } + double sd[n]; + + // From NSMutableArray to sd[n]; + for (int i=0; i 255.0) + { + y = 255.0; + } + else if (y < 0.0) + { + y = 0.0; + } +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE + [output addObject:[NSValue valueWithCGPoint:CGPointMake(x, y)]]; +#else + [output addObject:[NSValue valueWithPoint:NSMakePoint(x, y)]]; +#endif + } + } + + // The above always misses the last point because the last point is the last next, so we approach but don't equal it. + [output addObject:[points lastObject]]; + return output; +} + +- (NSMutableArray *)secondDerivative:(NSArray *)points +{ + const NSInteger n = [points count]; + if ((n <= 0) || (n == 1)) + { + return nil; + } + + double matrix[n][3]; + double result[n]; + matrix[0][1]=1; + // What about matrix[0][1] and matrix[0][0]? Assuming 0 for now (Brad L.) + matrix[0][0]=0; + matrix[0][2]=0; + + for(int i=1;idown) + for(int i=1;iup) + for(NSInteger i=n-2;i>=0;i--) + { + double k = matrix[i][2]/matrix[i+1][1]; + matrix[i][1] -= k*matrix[i+1][0]; + matrix[i][2] = 0; + result[i] -= k*result[i+1]; + } + + double y2[n]; + for(int i=0;i= 256) && ([_greenCurve count] >= 256) && ([_blueCurve count] >= 256) && ([_rgbCompositeCurve count] >= 256)) + { + for (unsigned int currentCurveIndex = 0; currentCurveIndex < 256; currentCurveIndex++) + { + // BGRA for upload to texture + GLubyte b = fmin(fmax(currentCurveIndex + [[_blueCurve objectAtIndex:currentCurveIndex] floatValue], 0), 255); + toneCurveByteArray[currentCurveIndex * 4] = fmin(fmax(b + [[_rgbCompositeCurve objectAtIndex:b] floatValue], 0), 255); + GLubyte g = fmin(fmax(currentCurveIndex + [[_greenCurve objectAtIndex:currentCurveIndex] floatValue], 0), 255); + toneCurveByteArray[currentCurveIndex * 4 + 1] = fmin(fmax(g + [[_rgbCompositeCurve objectAtIndex:g] floatValue], 0), 255); + GLubyte r = fmin(fmax(currentCurveIndex + [[_redCurve objectAtIndex:currentCurveIndex] floatValue], 0), 255); + toneCurveByteArray[currentCurveIndex * 4 + 2] = fmin(fmax(r + [[_rgbCompositeCurve objectAtIndex:r] floatValue], 0), 255); + toneCurveByteArray[currentCurveIndex * 4 + 3] = 255; + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256 /*width*/, 1 /*height*/, 0, GL_BGRA, GL_UNSIGNED_BYTE, toneCurveByteArray); + } + }); +} + +#pragma mark - +#pragma mark Rendering + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + if (self.preventRendering) + { + [firstInputFramebuffer unlock]; + return; + } + + [GPUImageContext setActiveShaderProgram:filterProgram]; + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + if (usingNextFrameForImageCapture) + { + [outputFramebuffer lock]; + } + + glClearColor(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha); + glClear(GL_COLOR_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, [firstInputFramebuffer texture]); + glUniform1i(filterInputTextureUniform, 2); + + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, toneCurveTexture); + glUniform1i(toneCurveTextureUniform, 3); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + [firstInputFramebuffer unlock]; + if (usingNextFrameForImageCapture) + { + dispatch_semaphore_signal(imageCaptureSemaphore); + } +} + +#pragma mark - +#pragma mark Accessors + +- (void)setRGBControlPoints:(NSArray *)points +{ + _redControlPoints = [points copy]; + _redCurve = [self getPreparedSplineCurve:_redControlPoints]; + + _greenControlPoints = [points copy]; + _greenCurve = [self getPreparedSplineCurve:_greenControlPoints]; + + _blueControlPoints = [points copy]; + _blueCurve = [self getPreparedSplineCurve:_blueControlPoints]; + + [self updateToneCurveTexture]; +} + + +- (void)setRgbCompositeControlPoints:(NSArray *)newValue +{ + _rgbCompositeControlPoints = [newValue copy]; + _rgbCompositeCurve = [self getPreparedSplineCurve:_rgbCompositeControlPoints]; + + [self updateToneCurveTexture]; +} + + +- (void)setRedControlPoints:(NSArray *)newValue; +{ + _redControlPoints = [newValue copy]; + _redCurve = [self getPreparedSplineCurve:_redControlPoints]; + + [self updateToneCurveTexture]; +} + + +- (void)setGreenControlPoints:(NSArray *)newValue +{ + _greenControlPoints = [newValue copy]; + _greenCurve = [self getPreparedSplineCurve:_greenControlPoints]; + + [self updateToneCurveTexture]; +} + + +- (void)setBlueControlPoints:(NSArray *)newValue +{ + _blueControlPoints = [newValue copy]; + _blueCurve = [self getPreparedSplineCurve:_blueControlPoints]; + + [self updateToneCurveTexture]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageToonFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageToonFilter.h new file mode 100755 index 00000000..ef8e17c3 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageToonFilter.h @@ -0,0 +1,19 @@ +#import "GPUImage3x3TextureSamplingFilter.h" + +/** This uses Sobel edge detection to place a black border around objects, + and then it quantizes the colors present in the image to give a cartoon-like quality to the image. + */ +@interface GPUImageToonFilter : GPUImage3x3TextureSamplingFilter +{ + GLint thresholdUniform, quantizationLevelsUniform; +} + +/** The threshold at which to apply the edges, default of 0.2 + */ +@property(readwrite, nonatomic) CGFloat threshold; + +/** The levels of quantization for the posterization of colors within the scene, with a default of 10.0 + */ +@property(readwrite, nonatomic) CGFloat quantizationLevels; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageToonFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageToonFilter.m new file mode 100755 index 00000000..e8ff104e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageToonFilter.m @@ -0,0 +1,149 @@ +#import "GPUImageToonFilter.h" +#import "GPUImageSobelEdgeDetectionFilter.h" +#import "GPUImage3x3ConvolutionFilter.h" + +// Code from "Graphics Shaders: Theory and Practice" by M. Bailey and S. Cunningham +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageToonFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp float intensity; + uniform highp float threshold; + uniform highp float quantizationLevels; + + const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; + float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; + + float mag = length(vec2(h, v)); + + vec3 posterizedImageColor = floor((textureColor.rgb * quantizationLevels) + 0.5) / quantizationLevels; + + float thresholdTest = 1.0 - step(threshold, mag); + + gl_FragColor = vec4(posterizedImageColor * thresholdTest, textureColor.a); + } +); +#else +NSString *const kGPUImageToonFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform float intensity; + uniform float threshold; + uniform float quantizationLevels; + + const vec3 W = vec3(0.2125, 0.7154, 0.0721); + + void main() + { + vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; + float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; + + float mag = length(vec2(h, v)); + + vec3 posterizedImageColor = floor((textureColor.rgb * quantizationLevels) + 0.5) / quantizationLevels; + + float thresholdTest = 1.0 - step(threshold, mag); + + gl_FragColor = vec4(posterizedImageColor * thresholdTest, textureColor.a); + } +); +#endif + +@implementation GPUImageToonFilter + +@synthesize threshold = _threshold; +@synthesize quantizationLevels = _quantizationLevels; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageToonFragmentShaderString])) + { + return nil; + } + + hasOverriddenImageSizeFactor = NO; + + thresholdUniform = [filterProgram uniformIndex:@"threshold"]; + quantizationLevelsUniform = [filterProgram uniformIndex:@"quantizationLevels"]; + + self.threshold = 0.2; + self.quantizationLevels = 10.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setThreshold:(CGFloat)newValue; +{ + _threshold = newValue; + + [self setFloat:_threshold forUniform:thresholdUniform program:filterProgram]; +} + +- (void)setQuantizationLevels:(CGFloat)newValue; +{ + _quantizationLevels = newValue; + + [self setFloat:_quantizationLevels forUniform:quantizationLevelsUniform program:filterProgram]; +} + + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTransformFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageTransformFilter.h new file mode 100755 index 00000000..9865b853 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTransformFilter.h @@ -0,0 +1,19 @@ +#import "GPUImageFilter.h" + +@interface GPUImageTransformFilter : GPUImageFilter +{ + GLint transformMatrixUniform, orthographicMatrixUniform; + GPUMatrix4x4 orthographicMatrix; +} + +// You can either set the transform to apply to be a 2-D affine transform or a 3-D transform. The default is the identity transform (the output image is identical to the input). +@property(readwrite, nonatomic) CGAffineTransform affineTransform; +@property(readwrite, nonatomic) CATransform3D transform3D; + +// This applies the transform to the raw frame data if set to YES, the default of NO takes the aspect ratio of the image input into account when rotating +@property(readwrite, nonatomic) BOOL ignoreAspectRatio; + +// sets the anchor point to top left corner +@property(readwrite, nonatomic) BOOL anchorTopLeft; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTransformFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageTransformFilter.m new file mode 100755 index 00000000..17933092 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTransformFilter.m @@ -0,0 +1,260 @@ +#import "GPUImageTransformFilter.h" + +NSString *const kGPUImageTransformVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + + uniform mat4 transformMatrix; + uniform mat4 orthographicMatrix; + + varying vec2 textureCoordinate; + + void main() + { + gl_Position = transformMatrix * vec4(position.xyz, 1.0) * orthographicMatrix; + textureCoordinate = inputTextureCoordinate.xy; + } +); + +@implementation GPUImageTransformFilter + +@synthesize affineTransform; +@synthesize transform3D = _transform3D; +@synthesize ignoreAspectRatio = _ignoreAspectRatio; +@synthesize anchorTopLeft = _anchorTopLeft; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithVertexShaderFromString:kGPUImageTransformVertexShaderString fragmentShaderFromString:kGPUImagePassthroughFragmentShaderString])) + { + return nil; + } + + transformMatrixUniform = [filterProgram uniformIndex:@"transformMatrix"]; + orthographicMatrixUniform = [filterProgram uniformIndex:@"orthographicMatrix"]; + + self.transform3D = CATransform3DIdentity; + + return self; +} + +#pragma mark - +#pragma mark Conversion from matrix formats + +- (void)loadOrthoMatrix:(GLfloat *)matrix left:(GLfloat)left right:(GLfloat)right bottom:(GLfloat)bottom top:(GLfloat)top near:(GLfloat)near far:(GLfloat)far; +{ + GLfloat r_l = right - left; + GLfloat t_b = top - bottom; + GLfloat f_n = far - near; + GLfloat tx = - (right + left) / (right - left); + GLfloat ty = - (top + bottom) / (top - bottom); + GLfloat tz = - (far + near) / (far - near); + + float scale = 2.0f; + if (_anchorTopLeft) + { + scale = 4.0f; + tx=-1.0f; + ty=-1.0f; + } + + matrix[0] = scale / r_l; + matrix[1] = 0.0f; + matrix[2] = 0.0f; + matrix[3] = tx; + + matrix[4] = 0.0f; + matrix[5] = scale / t_b; + matrix[6] = 0.0f; + matrix[7] = ty; + + matrix[8] = 0.0f; + matrix[9] = 0.0f; + matrix[10] = scale / f_n; + matrix[11] = tz; + + matrix[12] = 0.0f; + matrix[13] = 0.0f; + matrix[14] = 0.0f; + matrix[15] = 1.0f; +} + +//- (void)convert3DTransform:(CATransform3D *)transform3D toMatrix:(GLfloat *)matrix; +//{ +// // struct CATransform3D +// // { +// // CGFloat m11, m12, m13, m14; +// // CGFloat m21, m22, m23, m24; +// // CGFloat m31, m32, m33, m34; +// // CGFloat m41, m42, m43, m44; +// // }; +// +// matrix[0] = (GLfloat)transform3D->m11; +// matrix[1] = (GLfloat)transform3D->m12; +// matrix[2] = (GLfloat)transform3D->m13; +// matrix[3] = (GLfloat)transform3D->m14; +// matrix[4] = (GLfloat)transform3D->m21; +// matrix[5] = (GLfloat)transform3D->m22; +// matrix[6] = (GLfloat)transform3D->m23; +// matrix[7] = (GLfloat)transform3D->m24; +// matrix[8] = (GLfloat)transform3D->m31; +// matrix[9] = (GLfloat)transform3D->m32; +// matrix[10] = (GLfloat)transform3D->m33; +// matrix[11] = (GLfloat)transform3D->m34; +// matrix[12] = (GLfloat)transform3D->m41; +// matrix[13] = (GLfloat)transform3D->m42; +// matrix[14] = (GLfloat)transform3D->m43; +// matrix[15] = (GLfloat)transform3D->m44; +//} + +- (void)convert3DTransform:(CATransform3D *)transform3D toMatrix:(GPUMatrix4x4 *)matrix; +{ + // struct CATransform3D + // { + // CGFloat m11, m12, m13, m14; + // CGFloat m21, m22, m23, m24; + // CGFloat m31, m32, m33, m34; + // CGFloat m41, m42, m43, m44; + // }; + + GLfloat *mappedMatrix = (GLfloat *)matrix; + + mappedMatrix[0] = (GLfloat)transform3D->m11; + mappedMatrix[1] = (GLfloat)transform3D->m12; + mappedMatrix[2] = (GLfloat)transform3D->m13; + mappedMatrix[3] = (GLfloat)transform3D->m14; + mappedMatrix[4] = (GLfloat)transform3D->m21; + mappedMatrix[5] = (GLfloat)transform3D->m22; + mappedMatrix[6] = (GLfloat)transform3D->m23; + mappedMatrix[7] = (GLfloat)transform3D->m24; + mappedMatrix[8] = (GLfloat)transform3D->m31; + mappedMatrix[9] = (GLfloat)transform3D->m32; + mappedMatrix[10] = (GLfloat)transform3D->m33; + mappedMatrix[11] = (GLfloat)transform3D->m34; + mappedMatrix[12] = (GLfloat)transform3D->m41; + mappedMatrix[13] = (GLfloat)transform3D->m42; + mappedMatrix[14] = (GLfloat)transform3D->m43; + mappedMatrix[15] = (GLfloat)transform3D->m44; +} + +#pragma mark - +#pragma mark GPUImageInput + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + CGSize currentFBOSize = [self sizeOfFBO]; + CGFloat normalizedHeight = currentFBOSize.height / currentFBOSize.width; + + GLfloat adjustedVertices[] = { + -1.0f, -normalizedHeight, + 1.0f, -normalizedHeight, + -1.0f, normalizedHeight, + 1.0f, normalizedHeight, + }; + static const GLfloat squareVertices[] = { + -1.0f, -1.0f, + 1.0f, -1.0f, + -1.0f, 1.0f, + 1.0f, 1.0f, + }; + + GLfloat adjustedVerticesAnchorTL[] = { + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, normalizedHeight, + 1.0f, normalizedHeight, + }; + + static const GLfloat squareVerticesAnchorTL[] = { + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + }; + + if (_ignoreAspectRatio) + { + if (_anchorTopLeft) + { + [self renderToTextureWithVertices:squareVerticesAnchorTL textureCoordinates:[[self class] textureCoordinatesForRotation:inputRotation]]; + } + else + { + [self renderToTextureWithVertices:squareVertices textureCoordinates:[[self class] textureCoordinatesForRotation:inputRotation]]; + } + } + else + { + if (_anchorTopLeft) + { + [self renderToTextureWithVertices:adjustedVerticesAnchorTL textureCoordinates:[[self class] textureCoordinatesForRotation:inputRotation]]; + } + else + { + [self renderToTextureWithVertices:adjustedVertices textureCoordinates:[[self class] textureCoordinatesForRotation:inputRotation]]; + } + } + + [self informTargetsAboutNewFrameAtTime:frameTime]; +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + if (!_ignoreAspectRatio) + { + [self loadOrthoMatrix:(GLfloat *)&orthographicMatrix left:-1.0 right:1.0 bottom:(-1.0 * filterFrameSize.height / filterFrameSize.width) top:(1.0 * filterFrameSize.height / filterFrameSize.width) near:-1.0 far:1.0]; + // [self loadOrthoMatrix:orthographicMatrix left:-1.0 right:1.0 bottom:(-1.0 * (GLfloat)backingHeight / (GLfloat)backingWidth) top:(1.0 * (GLfloat)backingHeight / (GLfloat)backingWidth) near:-2.0 far:2.0]; + + [self setMatrix4f:orthographicMatrix forUniform:orthographicMatrixUniform program:filterProgram]; + } +} + +#pragma mark - +#pragma mark Accessors + +- (void)setAffineTransform:(CGAffineTransform)newValue; +{ + self.transform3D = CATransform3DMakeAffineTransform(newValue); +} + +- (CGAffineTransform)affineTransform; +{ + return CATransform3DGetAffineTransform(self.transform3D); +} + +- (void)setTransform3D:(CATransform3D)newValue; +{ + _transform3D = newValue; + + GPUMatrix4x4 temporaryMatrix; + + [self convert3DTransform:&_transform3D toMatrix:&temporaryMatrix]; + [self setMatrix4f:temporaryMatrix forUniform:transformMatrixUniform program:filterProgram]; +} + +- (void)setIgnoreAspectRatio:(BOOL)newValue; +{ + _ignoreAspectRatio = newValue; + + if (_ignoreAspectRatio) + { + [self loadOrthoMatrix:(GLfloat *)&orthographicMatrix left:-1.0 right:1.0 bottom:-1.0 top:1.0 near:-1.0 far:1.0]; + [self setMatrix4f:orthographicMatrix forUniform:orthographicMatrixUniform program:filterProgram]; + } + else + { + [self setupFilterForSize:[self sizeOfFBO]]; + } +} + +- (void)setAnchorTopLeft:(BOOL)newValue +{ + _anchorTopLeft = newValue; + [self setIgnoreAspectRatio:_ignoreAspectRatio]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputCrossTextureSamplingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputCrossTextureSamplingFilter.h new file mode 100644 index 00000000..64eac9dc --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputCrossTextureSamplingFilter.h @@ -0,0 +1,15 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageTwoInputCrossTextureSamplingFilter : GPUImageTwoInputFilter +{ + GLint texelWidthUniform, texelHeightUniform; + + CGFloat texelWidth, texelHeight; + BOOL hasOverriddenImageSizeFactor; +} + +// The texel width and height determines how far out to sample from this texel. By default, this is the normalized width of a pixel, but this can be overridden for different effects. +@property(readwrite, nonatomic) CGFloat texelWidth; +@property(readwrite, nonatomic) CGFloat texelHeight; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputCrossTextureSamplingFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputCrossTextureSamplingFilter.m new file mode 100644 index 00000000..aa338f81 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputCrossTextureSamplingFilter.m @@ -0,0 +1,108 @@ +#import "GPUImageTwoInputCrossTextureSamplingFilter.h" + +NSString *const kGPUImageTwoInputNearbyTexelSamplingVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + attribute vec4 inputTextureCoordinate2; + + uniform float texelWidth; + uniform float texelHeight; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + varying vec2 topTextureCoordinate; + varying vec2 bottomTextureCoordinate; + + varying vec2 textureCoordinate2; + varying vec2 leftTextureCoordinate2; + varying vec2 rightTextureCoordinate2; + varying vec2 topTextureCoordinate2; + varying vec2 bottomTextureCoordinate2; + + void main() + { + gl_Position = position; + + vec2 widthStep = vec2(texelWidth, 0.0); + vec2 heightStep = vec2(0.0, texelHeight); + + textureCoordinate = inputTextureCoordinate.xy; + leftTextureCoordinate = inputTextureCoordinate.xy - widthStep; + rightTextureCoordinate = inputTextureCoordinate.xy + widthStep; + topTextureCoordinate = inputTextureCoordinate.xy - heightStep; + bottomTextureCoordinate = inputTextureCoordinate.xy + heightStep; + + textureCoordinate2 = inputTextureCoordinate2.xy; + leftTextureCoordinate2 = inputTextureCoordinate2.xy - widthStep; + rightTextureCoordinate2 = inputTextureCoordinate2.xy + widthStep; + topTextureCoordinate2 = inputTextureCoordinate2.xy - heightStep; + bottomTextureCoordinate2 = inputTextureCoordinate2.xy + heightStep; + } +); + +@implementation GPUImageTwoInputCrossTextureSamplingFilter + +@synthesize texelWidth = _texelWidth; +@synthesize texelHeight = _texelHeight; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [super initWithVertexShaderFromString:kGPUImageTwoInputNearbyTexelSamplingVertexShaderString fragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + texelWidthUniform = [filterProgram uniformIndex:@"texelWidth"]; + texelHeightUniform = [filterProgram uniformIndex:@"texelHeight"]; + + return self; +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + if (!hasOverriddenImageSizeFactor) + { + _texelWidth = 1.0 / filterFrameSize.width; + _texelHeight = 1.0 / filterFrameSize.height; + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:filterProgram]; + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + glUniform1f(texelWidthUniform, _texelHeight); + glUniform1f(texelHeightUniform, _texelWidth); + } + else + { + glUniform1f(texelWidthUniform, _texelWidth); + glUniform1f(texelHeightUniform, _texelHeight); + } + }); + } +} + +#pragma mark - +#pragma mark Accessors + +- (void)setTexelWidth:(CGFloat)newValue; +{ + hasOverriddenImageSizeFactor = YES; + _texelWidth = newValue; + + [self setFloat:_texelWidth forUniform:texelWidthUniform program:filterProgram]; +} + +- (void)setTexelHeight:(CGFloat)newValue; +{ + hasOverriddenImageSizeFactor = YES; + _texelHeight = newValue; + + [self setFloat:_texelHeight forUniform:texelHeightUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputFilter.h new file mode 100644 index 00000000..da3a1345 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputFilter.h @@ -0,0 +1,21 @@ +#import "GPUImageFilter.h" + +extern NSString *const kGPUImageTwoInputTextureVertexShaderString; + +@interface GPUImageTwoInputFilter : GPUImageFilter +{ + GPUImageFramebuffer *secondInputFramebuffer; + + GLint filterSecondTextureCoordinateAttribute; + GLint filterInputTextureUniform2; + GPUImageRotationMode inputRotation2; + CMTime firstFrameTime, secondFrameTime; + + BOOL hasSetFirstTexture, hasReceivedFirstFrame, hasReceivedSecondFrame, firstFrameWasVideo, secondFrameWasVideo; + BOOL firstFrameCheckDisabled, secondFrameCheckDisabled; +} + +- (void)disableFirstFrameCheck; +- (void)disableSecondFrameCheck; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputFilter.m new file mode 100644 index 00000000..cf318737 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTwoInputFilter.m @@ -0,0 +1,264 @@ +#import "GPUImageTwoInputFilter.h" + +NSString *const kGPUImageTwoInputTextureVertexShaderString = SHADER_STRING +( + attribute vec4 position; + attribute vec4 inputTextureCoordinate; + attribute vec4 inputTextureCoordinate2; + + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + void main() + { + gl_Position = position; + textureCoordinate = inputTextureCoordinate.xy; + textureCoordinate2 = inputTextureCoordinate2.xy; + } +); + + +@implementation GPUImageTwoInputFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithFragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [self initWithVertexShaderFromString:kGPUImageTwoInputTextureVertexShaderString fragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + return self; +} + +- (id)initWithVertexShaderFromString:(NSString *)vertexShaderString fragmentShaderFromString:(NSString *)fragmentShaderString; +{ + if (!(self = [super initWithVertexShaderFromString:vertexShaderString fragmentShaderFromString:fragmentShaderString])) + { + return nil; + } + + inputRotation2 = kGPUImageNoRotation; + + hasSetFirstTexture = NO; + + hasReceivedFirstFrame = NO; + hasReceivedSecondFrame = NO; + firstFrameWasVideo = NO; + secondFrameWasVideo = NO; + firstFrameCheckDisabled = NO; + secondFrameCheckDisabled = NO; + + firstFrameTime = kCMTimeInvalid; + secondFrameTime = kCMTimeInvalid; + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + filterSecondTextureCoordinateAttribute = [filterProgram attributeIndex:@"inputTextureCoordinate2"]; + + filterInputTextureUniform2 = [filterProgram uniformIndex:@"inputImageTexture2"]; // This does assume a name of "inputImageTexture2" for second input texture in the fragment shader + glEnableVertexAttribArray(filterSecondTextureCoordinateAttribute); + }); + + return self; +} + +- (void)initializeAttributes; +{ + [super initializeAttributes]; + [filterProgram addAttribute:@"inputTextureCoordinate2"]; +} + +- (void)disableFirstFrameCheck; +{ + firstFrameCheckDisabled = YES; +} + +- (void)disableSecondFrameCheck; +{ + secondFrameCheckDisabled = YES; +} + +#pragma mark - +#pragma mark Rendering + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + if (self.preventRendering) + { + [firstInputFramebuffer unlock]; + [secondInputFramebuffer unlock]; + return; + } + + [GPUImageContext setActiveShaderProgram:filterProgram]; + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + if (usingNextFrameForImageCapture) + { + [outputFramebuffer lock]; + } + + [self setUniformsForProgramAtIndex:0]; + + glClearColor(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha); + glClear(GL_COLOR_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, [firstInputFramebuffer texture]); + glUniform1i(filterInputTextureUniform, 2); + + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, [secondInputFramebuffer texture]); + glUniform1i(filterInputTextureUniform2, 3); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + glVertexAttribPointer(filterSecondTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [[self class] textureCoordinatesForRotation:inputRotation2]); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + [firstInputFramebuffer unlock]; + [secondInputFramebuffer unlock]; + if (usingNextFrameForImageCapture) + { + dispatch_semaphore_signal(imageCaptureSemaphore); + } +} + +#pragma mark - +#pragma mark GPUImageInput + +- (NSInteger)nextAvailableTextureIndex; +{ + if (hasSetFirstTexture) + { + return 1; + } + else + { + return 0; + } +} + +- (void)setInputFramebuffer:(GPUImageFramebuffer *)newInputFramebuffer atIndex:(NSInteger)textureIndex; +{ + if (textureIndex == 0) + { + firstInputFramebuffer = newInputFramebuffer; + hasSetFirstTexture = YES; + [firstInputFramebuffer lock]; + } + else + { + secondInputFramebuffer = newInputFramebuffer; + [secondInputFramebuffer lock]; + } +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + if (textureIndex == 0) + { + [super setInputSize:newSize atIndex:textureIndex]; + + if (CGSizeEqualToSize(newSize, CGSizeZero)) + { + hasSetFirstTexture = NO; + } + } +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + if (textureIndex == 0) + { + inputRotation = newInputRotation; + } + else + { + inputRotation2 = newInputRotation; + } +} + +- (CGSize)rotatedSize:(CGSize)sizeToRotate forIndex:(NSInteger)textureIndex; +{ + CGSize rotatedSize = sizeToRotate; + + GPUImageRotationMode rotationToCheck; + if (textureIndex == 0) + { + rotationToCheck = inputRotation; + } + else + { + rotationToCheck = inputRotation2; + } + + if (GPUImageRotationSwapsWidthAndHeight(rotationToCheck)) + { + rotatedSize.width = sizeToRotate.height; + rotatedSize.height = sizeToRotate.width; + } + + return rotatedSize; +} + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + // You can set up infinite update loops, so this helps to short circuit them + if (hasReceivedFirstFrame && hasReceivedSecondFrame) + { + return; + } + + BOOL updatedMovieFrameOppositeStillImage = NO; + + if (textureIndex == 0) + { + hasReceivedFirstFrame = YES; + firstFrameTime = frameTime; + if (secondFrameCheckDisabled) + { + hasReceivedSecondFrame = YES; + } + + if (!CMTIME_IS_INDEFINITE(frameTime)) + { + if CMTIME_IS_INDEFINITE(secondFrameTime) + { + updatedMovieFrameOppositeStillImage = YES; + } + } + } + else + { + hasReceivedSecondFrame = YES; + secondFrameTime = frameTime; + if (firstFrameCheckDisabled) + { + hasReceivedFirstFrame = YES; + } + + if (!CMTIME_IS_INDEFINITE(frameTime)) + { + if CMTIME_IS_INDEFINITE(firstFrameTime) + { + updatedMovieFrameOppositeStillImage = YES; + } + } + } + + // || (hasReceivedFirstFrame && secondFrameCheckDisabled) || (hasReceivedSecondFrame && firstFrameCheckDisabled) + if ((hasReceivedFirstFrame && hasReceivedSecondFrame) || updatedMovieFrameOppositeStillImage) + { + CMTime passOnFrameTime = (!CMTIME_IS_INDEFINITE(firstFrameTime)) ? firstFrameTime : secondFrameTime; + [super newFrameReadyAtTime:passOnFrameTime atIndex:0]; // Bugfix when trying to record: always use time from first input (unless indefinite, in which case use the second input) + hasReceivedFirstFrame = NO; + hasReceivedSecondFrame = NO; + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassFilter.h new file mode 100755 index 00000000..23087f35 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassFilter.h @@ -0,0 +1,19 @@ +#import "GPUImageFilter.h" + +@interface GPUImageTwoPassFilter : GPUImageFilter +{ + GPUImageFramebuffer *secondOutputFramebuffer; + + GLProgram *secondFilterProgram; + GLint secondFilterPositionAttribute, secondFilterTextureCoordinateAttribute; + GLint secondFilterInputTextureUniform, secondFilterInputTextureUniform2; + + NSMutableDictionary *secondProgramUniformStateRestorationBlocks; +} + +// Initialization and teardown +- (id)initWithFirstStageVertexShaderFromString:(NSString *)firstStageVertexShaderString firstStageFragmentShaderFromString:(NSString *)firstStageFragmentShaderString secondStageVertexShaderFromString:(NSString *)secondStageVertexShaderString secondStageFragmentShaderFromString:(NSString *)secondStageFragmentShaderString; +- (id)initWithFirstStageFragmentShaderFromString:(NSString *)firstStageFragmentShaderString secondStageFragmentShaderFromString:(NSString *)secondStageFragmentShaderString; +- (void)initializeSecondaryAttributes; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassFilter.m new file mode 100755 index 00000000..9eb292b4 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassFilter.m @@ -0,0 +1,201 @@ +#import "GPUImageTwoPassFilter.h" + +@implementation GPUImageTwoPassFilter + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithFirstStageVertexShaderFromString:(NSString *)firstStageVertexShaderString firstStageFragmentShaderFromString:(NSString *)firstStageFragmentShaderString secondStageVertexShaderFromString:(NSString *)secondStageVertexShaderString secondStageFragmentShaderFromString:(NSString *)secondStageFragmentShaderString; +{ + if (!(self = [super initWithVertexShaderFromString:firstStageVertexShaderString fragmentShaderFromString:firstStageFragmentShaderString])) + { + return nil; + } + + secondProgramUniformStateRestorationBlocks = [NSMutableDictionary dictionaryWithCapacity:10]; + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + + secondFilterProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:secondStageVertexShaderString fragmentShaderString:secondStageFragmentShaderString]; + + if (!secondFilterProgram.initialized) + { + [self initializeSecondaryAttributes]; + + if (![secondFilterProgram link]) + { + NSString *progLog = [secondFilterProgram programLog]; + NSLog(@"Program link log: %@", progLog); + NSString *fragLog = [secondFilterProgram fragmentShaderLog]; + NSLog(@"Fragment shader compile log: %@", fragLog); + NSString *vertLog = [secondFilterProgram vertexShaderLog]; + NSLog(@"Vertex shader compile log: %@", vertLog); + secondFilterProgram = nil; + NSAssert(NO, @"Filter shader link failed"); + } + } + + secondFilterPositionAttribute = [secondFilterProgram attributeIndex:@"position"]; + secondFilterTextureCoordinateAttribute = [secondFilterProgram attributeIndex:@"inputTextureCoordinate"]; + secondFilterInputTextureUniform = [secondFilterProgram uniformIndex:@"inputImageTexture"]; // This does assume a name of "inputImageTexture" for the fragment shader + secondFilterInputTextureUniform2 = [secondFilterProgram uniformIndex:@"inputImageTexture2"]; // This does assume a name of "inputImageTexture2" for second input texture in the fragment shader + + [GPUImageContext setActiveShaderProgram:secondFilterProgram]; + + glEnableVertexAttribArray(secondFilterPositionAttribute); + glEnableVertexAttribArray(secondFilterTextureCoordinateAttribute); + }); + + return self; +} + +- (id)initWithFirstStageFragmentShaderFromString:(NSString *)firstStageFragmentShaderString secondStageFragmentShaderFromString:(NSString *)secondStageFragmentShaderString; +{ + if (!(self = [self initWithFirstStageVertexShaderFromString:kGPUImageVertexShaderString firstStageFragmentShaderFromString:firstStageFragmentShaderString secondStageVertexShaderFromString:kGPUImageVertexShaderString secondStageFragmentShaderFromString:secondStageFragmentShaderString])) + { + return nil; + } + + return self; +} + +- (void)initializeSecondaryAttributes; +{ + [secondFilterProgram addAttribute:@"position"]; + [secondFilterProgram addAttribute:@"inputTextureCoordinate"]; +} + +#pragma mark - +#pragma mark Managing targets + +- (GPUImageFramebuffer *)framebufferForOutput; +{ + return secondOutputFramebuffer; +} + +- (void)removeOutputFramebuffer; +{ + secondOutputFramebuffer = nil; +} + +#pragma mark - +#pragma mark Rendering + +- (void)renderToTextureWithVertices:(const GLfloat *)vertices textureCoordinates:(const GLfloat *)textureCoordinates; +{ + if (self.preventRendering) + { + [firstInputFramebuffer unlock]; + return; + } + + [GPUImageContext setActiveShaderProgram:filterProgram]; + + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + + [self setUniformsForProgramAtIndex:0]; + + glClearColor(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha); + glClear(GL_COLOR_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE2); + glBindTexture(GL_TEXTURE_2D, [firstInputFramebuffer texture]); + + glUniform1i(filterInputTextureUniform, 2); + + glVertexAttribPointer(filterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + glVertexAttribPointer(filterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + [firstInputFramebuffer unlock]; + firstInputFramebuffer = nil; + + // This assumes that any two-pass filter that says it desires monochrome input is using the first pass for a luminance conversion, which can be dropped +// if (!currentlyReceivingMonochromeInput) +// { + // Run the first stage of the two-pass filter +// [super renderToTextureWithVertices:vertices textureCoordinates:textureCoordinates]; +// } + + // Run the second stage of the two-pass filter + secondOutputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:[self sizeOfFBO] textureOptions:self.outputTextureOptions onlyTexture:NO]; + [secondOutputFramebuffer activateFramebuffer]; + [GPUImageContext setActiveShaderProgram:secondFilterProgram]; + if (usingNextFrameForImageCapture) + { + [secondOutputFramebuffer lock]; + } + + [self setUniformsForProgramAtIndex:1]; + + glActiveTexture(GL_TEXTURE3); + glBindTexture(GL_TEXTURE_2D, [outputFramebuffer texture]); + glVertexAttribPointer(secondFilterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [[self class] textureCoordinatesForRotation:kGPUImageNoRotation]); + + // TODO: Re-enable this monochrome optimization +// if (!currentlyReceivingMonochromeInput) +// { +// glActiveTexture(GL_TEXTURE3); +// glBindTexture(GL_TEXTURE_2D, outputTexture); +// glVertexAttribPointer(secondFilterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [[self class] textureCoordinatesForRotation:kGPUImageNoRotation]); +// } +// else +// { +// glActiveTexture(GL_TEXTURE3); +// glBindTexture(GL_TEXTURE_2D, sourceTexture); +// glVertexAttribPointer(secondFilterTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); +// } + + glUniform1i(secondFilterInputTextureUniform, 3); + + glVertexAttribPointer(secondFilterPositionAttribute, 2, GL_FLOAT, 0, 0, vertices); + + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + [outputFramebuffer unlock]; + outputFramebuffer = nil; + + if (usingNextFrameForImageCapture) + { + dispatch_semaphore_signal(imageCaptureSemaphore); + } +} + +- (void)setAndExecuteUniformStateCallbackAtIndex:(GLint)uniform forProgram:(GLProgram *)shaderProgram toBlock:(dispatch_block_t)uniformStateBlock; +{ +// TODO: Deal with the fact that two-pass filters may have the same shader program identifier + if (shaderProgram == filterProgram) + { + [uniformStateRestorationBlocks setObject:[uniformStateBlock copy] forKey:[NSNumber numberWithInt:uniform]]; + } + else + { + [secondProgramUniformStateRestorationBlocks setObject:[uniformStateBlock copy] forKey:[NSNumber numberWithInt:uniform]]; + } + uniformStateBlock(); +} + +- (void)setUniformsForProgramAtIndex:(NSUInteger)programIndex; +{ + if (programIndex == 0) + { + [uniformStateRestorationBlocks enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop){ + dispatch_block_t currentBlock = obj; + currentBlock(); + }]; + } + else + { + [secondProgramUniformStateRestorationBlocks enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop){ + dispatch_block_t currentBlock = obj; + currentBlock(); + }]; + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassTextureSamplingFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassTextureSamplingFilter.h new file mode 100644 index 00000000..73ab79d3 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassTextureSamplingFilter.h @@ -0,0 +1,13 @@ +#import "GPUImageTwoPassFilter.h" + +@interface GPUImageTwoPassTextureSamplingFilter : GPUImageTwoPassFilter +{ + GLint verticalPassTexelWidthOffsetUniform, verticalPassTexelHeightOffsetUniform, horizontalPassTexelWidthOffsetUniform, horizontalPassTexelHeightOffsetUniform; + GLfloat verticalPassTexelWidthOffset, verticalPassTexelHeightOffset, horizontalPassTexelWidthOffset, horizontalPassTexelHeightOffset; + CGFloat _verticalTexelSpacing, _horizontalTexelSpacing; +} + +// This sets the spacing between texels (in pixels) when sampling for the first. By default, this is 1.0 +@property(readwrite, nonatomic) CGFloat verticalTexelSpacing, horizontalTexelSpacing; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassTextureSamplingFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassTextureSamplingFilter.m new file mode 100644 index 00000000..b6a2ec58 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageTwoPassTextureSamplingFilter.m @@ -0,0 +1,85 @@ +#import "GPUImageTwoPassTextureSamplingFilter.h" + +@implementation GPUImageTwoPassTextureSamplingFilter + +@synthesize verticalTexelSpacing = _verticalTexelSpacing; +@synthesize horizontalTexelSpacing = _horizontalTexelSpacing; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithFirstStageVertexShaderFromString:(NSString *)firstStageVertexShaderString firstStageFragmentShaderFromString:(NSString *)firstStageFragmentShaderString secondStageVertexShaderFromString:(NSString *)secondStageVertexShaderString secondStageFragmentShaderFromString:(NSString *)secondStageFragmentShaderString +{ + if (!(self = [super initWithFirstStageVertexShaderFromString:firstStageVertexShaderString firstStageFragmentShaderFromString:firstStageFragmentShaderString secondStageVertexShaderFromString:secondStageVertexShaderString secondStageFragmentShaderFromString:secondStageFragmentShaderString])) + { + return nil; + } + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + + verticalPassTexelWidthOffsetUniform = [filterProgram uniformIndex:@"texelWidthOffset"]; + verticalPassTexelHeightOffsetUniform = [filterProgram uniformIndex:@"texelHeightOffset"]; + + horizontalPassTexelWidthOffsetUniform = [secondFilterProgram uniformIndex:@"texelWidthOffset"]; + horizontalPassTexelHeightOffsetUniform = [secondFilterProgram uniformIndex:@"texelHeightOffset"]; + }); + + self.verticalTexelSpacing = 1.0; + self.horizontalTexelSpacing = 1.0; + + return self; +} + +- (void)setUniformsForProgramAtIndex:(NSUInteger)programIndex; +{ + [super setUniformsForProgramAtIndex:programIndex]; + + if (programIndex == 0) + { + glUniform1f(verticalPassTexelWidthOffsetUniform, verticalPassTexelWidthOffset); + glUniform1f(verticalPassTexelHeightOffsetUniform, verticalPassTexelHeightOffset); + } + else + { + glUniform1f(horizontalPassTexelWidthOffsetUniform, horizontalPassTexelWidthOffset); + glUniform1f(horizontalPassTexelHeightOffsetUniform, horizontalPassTexelHeightOffset); + } +} + +- (void)setupFilterForSize:(CGSize)filterFrameSize; +{ + runSynchronouslyOnVideoProcessingQueue(^{ + // The first pass through the framebuffer may rotate the inbound image, so need to account for that by changing up the kernel ordering for that pass + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + verticalPassTexelWidthOffset = _verticalTexelSpacing / filterFrameSize.height; + verticalPassTexelHeightOffset = 0.0; + } + else + { + verticalPassTexelWidthOffset = 0.0; + verticalPassTexelHeightOffset = _verticalTexelSpacing / filterFrameSize.height; + } + + horizontalPassTexelWidthOffset = _horizontalTexelSpacing / filterFrameSize.width; + horizontalPassTexelHeightOffset = 0.0; + }); +} + +#pragma mark - +#pragma mark Accessors + +- (void)setVerticalTexelSpacing:(CGFloat)newValue; +{ + _verticalTexelSpacing = newValue; + [self setupFilterForSize:[self sizeOfFBO]]; +} + +- (void)setHorizontalTexelSpacing:(CGFloat)newValue; +{ + _horizontalTexelSpacing = newValue; + [self setupFilterForSize:[self sizeOfFBO]]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageUIElement.h b/LFLiveKit/Vendor/GPUImage/GPUImageUIElement.h new file mode 100644 index 00000000..984ff2ad --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageUIElement.h @@ -0,0 +1,15 @@ +#import "GPUImageOutput.h" + +@interface GPUImageUIElement : GPUImageOutput + +// Initialization and teardown +- (id)initWithView:(UIView *)inputView; +- (id)initWithLayer:(CALayer *)inputLayer; + +// Layer management +- (CGSize)layerSizeInPixels; +- (void)update; +- (void)updateUsingCurrentTime; +- (void)updateWithTimestamp:(CMTime)frameTime; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageUIElement.m b/LFLiveKit/Vendor/GPUImage/GPUImageUIElement.m new file mode 100644 index 00000000..33208924 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageUIElement.m @@ -0,0 +1,123 @@ +#import "GPUImageUIElement.h" + +@interface GPUImageUIElement () +{ + UIView *view; + CALayer *layer; + + CGSize previousLayerSizeInPixels; + CMTime time; + NSTimeInterval actualTimeOfLastUpdate; +} + +@end + +@implementation GPUImageUIElement + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithView:(UIView *)inputView; +{ + if (!(self = [super init])) + { + return nil; + } + + view = inputView; + layer = inputView.layer; + + previousLayerSizeInPixels = CGSizeZero; + [self update]; + + return self; +} + +- (id)initWithLayer:(CALayer *)inputLayer; +{ + if (!(self = [super init])) + { + return nil; + } + + view = nil; + layer = inputLayer; + + previousLayerSizeInPixels = CGSizeZero; + [self update]; + + return self; +} + +#pragma mark - +#pragma mark Layer management + +- (CGSize)layerSizeInPixels; +{ + CGSize pointSize = layer.bounds.size; + return CGSizeMake(layer.contentsScale * pointSize.width, layer.contentsScale * pointSize.height); +} + +- (void)update; +{ + [self updateWithTimestamp:kCMTimeIndefinite]; +} + +- (void)updateUsingCurrentTime; +{ + if(CMTIME_IS_INVALID(time)) { + time = CMTimeMakeWithSeconds(0, 600); + actualTimeOfLastUpdate = [NSDate timeIntervalSinceReferenceDate]; + } else { + NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate]; + NSTimeInterval diff = now - actualTimeOfLastUpdate; + time = CMTimeAdd(time, CMTimeMakeWithSeconds(diff, 600)); + actualTimeOfLastUpdate = now; + } + + [self updateWithTimestamp:time]; +} + +- (void)updateWithTimestamp:(CMTime)frameTime; +{ + [GPUImageContext useImageProcessingContext]; + + CGSize layerPixelSize = [self layerSizeInPixels]; + + GLubyte *imageData = (GLubyte *) calloc(1, (int)layerPixelSize.width * (int)layerPixelSize.height * 4); + + CGColorSpaceRef genericRGBColorspace = CGColorSpaceCreateDeviceRGB(); + CGContextRef imageContext = CGBitmapContextCreate(imageData, (int)layerPixelSize.width, (int)layerPixelSize.height, 8, (int)layerPixelSize.width * 4, genericRGBColorspace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst); +// CGContextRotateCTM(imageContext, M_PI_2); + CGContextTranslateCTM(imageContext, 0.0f, layerPixelSize.height); + CGContextScaleCTM(imageContext, layer.contentsScale, -layer.contentsScale); + // CGContextSetBlendMode(imageContext, kCGBlendModeCopy); // From Technical Q&A QA1708: http://developer.apple.com/library/ios/#qa/qa1708/_index.html + + [layer renderInContext:imageContext]; + + CGContextRelease(imageContext); + CGColorSpaceRelease(genericRGBColorspace); + + // TODO: This may not work + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:layerPixelSize textureOptions:self.outputTextureOptions onlyTexture:YES]; + + glBindTexture(GL_TEXTURE_2D, [outputFramebuffer texture]); + // no need to use self.outputTextureOptions here, we always need these texture options + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (int)layerPixelSize.width, (int)layerPixelSize.height, 0, GL_BGRA, GL_UNSIGNED_BYTE, imageData); + + free(imageData); + + for (id currentTarget in targets) + { + if (currentTarget != self.targetToIgnoreForUpdates) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger textureIndexOfTarget = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + [currentTarget setInputSize:layerPixelSize atIndex:textureIndexOfTarget]; + [currentTarget newFrameReadyAtTime:frameTime atIndex:textureIndexOfTarget]; + } + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageUnsharpMaskFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageUnsharpMaskFilter.h new file mode 100755 index 00000000..9d8aff01 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageUnsharpMaskFilter.h @@ -0,0 +1,16 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImageGaussianBlurFilter; + +@interface GPUImageUnsharpMaskFilter : GPUImageFilterGroup +{ + GPUImageGaussianBlurFilter *blurFilter; + GPUImageFilter *unsharpMaskFilter; +} +// The blur radius of the underlying Gaussian blur. The default is 4.0. +@property (readwrite, nonatomic) CGFloat blurRadiusInPixels; + +// The strength of the sharpening, from 0.0 on up, with a default of 1.0 +@property(readwrite, nonatomic) CGFloat intensity; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageUnsharpMaskFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageUnsharpMaskFilter.m new file mode 100755 index 00000000..542c5ea3 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageUnsharpMaskFilter.m @@ -0,0 +1,101 @@ +#import "GPUImageUnsharpMaskFilter.h" +#import "GPUImageFilter.h" +#import "GPUImageTwoInputFilter.h" +#import "GPUImageGaussianBlurFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageUnsharpMaskFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + varying highp vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform highp float intensity; + + void main() + { + lowp vec4 sharpImageColor = texture2D(inputImageTexture, textureCoordinate); + lowp vec3 blurredImageColor = texture2D(inputImageTexture2, textureCoordinate2).rgb; + + gl_FragColor = vec4(sharpImageColor.rgb * intensity + blurredImageColor * (1.0 - intensity), sharpImageColor.a); +// gl_FragColor = mix(blurredImageColor, sharpImageColor, intensity); +// gl_FragColor = vec4(sharpImageColor.rgb - (blurredImageColor.rgb * intensity), 1.0); + } +); +#else +NSString *const kGPUImageUnsharpMaskFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 textureCoordinate2; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + + uniform float intensity; + + void main() + { + vec4 sharpImageColor = texture2D(inputImageTexture, textureCoordinate); + vec3 blurredImageColor = texture2D(inputImageTexture2, textureCoordinate2).rgb; + + gl_FragColor = vec4(sharpImageColor.rgb * intensity + blurredImageColor * (1.0 - intensity), sharpImageColor.a); + // gl_FragColor = mix(blurredImageColor, sharpImageColor, intensity); + // gl_FragColor = vec4(sharpImageColor.rgb - (blurredImageColor.rgb * intensity), 1.0); + } +); +#endif + +@implementation GPUImageUnsharpMaskFilter + +@synthesize blurRadiusInPixels; +@synthesize intensity = _intensity; + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + // First pass: apply a variable Gaussian blur + blurFilter = [[GPUImageGaussianBlurFilter alloc] init]; + [self addFilter:blurFilter]; + + // Second pass: combine the blurred image with the original sharp one + unsharpMaskFilter = [[GPUImageTwoInputFilter alloc] initWithFragmentShaderFromString:kGPUImageUnsharpMaskFragmentShaderString]; + [self addFilter:unsharpMaskFilter]; + + // Texture location 0 needs to be the sharp image for both the blur and the second stage processing + [blurFilter addTarget:unsharpMaskFilter atTextureLocation:1]; + + self.initialFilters = [NSArray arrayWithObjects:blurFilter, unsharpMaskFilter, nil]; + self.terminalFilter = unsharpMaskFilter; + + self.intensity = 1.0; + self.blurRadiusInPixels = 4.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setBlurRadiusInPixels:(CGFloat)newValue; +{ + blurFilter.blurRadiusInPixels = newValue; +} + +- (CGFloat)blurRadiusInPixels; +{ + return blurFilter.blurRadiusInPixels; +} + +- (void)setIntensity:(CGFloat)newValue; +{ + _intensity = newValue; + [unsharpMaskFilter setFloat:newValue forUniformName:@"intensity"]; +} + +@end \ No newline at end of file diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageVideoCamera.h b/LFLiveKit/Vendor/GPUImage/GPUImageVideoCamera.h new file mode 100755 index 00000000..458020cf --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageVideoCamera.h @@ -0,0 +1,156 @@ +#import +#import +#import +#import "GPUImageContext.h" +#import "GPUImageOutput.h" +#import "GPUImageColorConversion.h" + +//Optionally override the YUV to RGB matrices +void setColorConversion601( GLfloat conversionMatrix[9] ); +void setColorConversion601FullRange( GLfloat conversionMatrix[9] ); +void setColorConversion709( GLfloat conversionMatrix[9] ); + + +//Delegate Protocal for Face Detection. +@protocol GPUImageVideoCameraDelegate + +@optional +- (void)willOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer; +@end + + +/** + A GPUImageOutput that provides frames from either camera +*/ +@interface GPUImageVideoCamera : GPUImageOutput +{ + NSUInteger numberOfFramesCaptured; + CGFloat totalFrameTimeDuringCapture; + + AVCaptureSession *_captureSession; + AVCaptureDevice *_inputCamera; + AVCaptureDevice *_microphone; + AVCaptureDeviceInput *videoInput; + AVCaptureVideoDataOutput *videoOutput; + + BOOL capturePaused; + GPUImageRotationMode outputRotation, internalRotation; + dispatch_semaphore_t frameRenderingSemaphore; + + BOOL captureAsYUV; + GLuint luminanceTexture, chrominanceTexture; + + __unsafe_unretained id _delegate; +} + +/// Whether or not the underlying AVCaptureSession is running +@property(readonly, nonatomic) BOOL isRunning; + +/// The AVCaptureSession used to capture from the camera +@property(readonly, retain, nonatomic) AVCaptureSession *captureSession; + +/// This enables the capture session preset to be changed on the fly +@property (readwrite, nonatomic, copy) NSString *captureSessionPreset; + +/// This sets the frame rate of the camera (iOS 5 and above only) +/** + Setting this to 0 or below will set the frame rate back to the default setting for a particular preset. + */ +@property (readwrite) int32_t frameRate; + +/// Easy way to tell which cameras are present on device +@property (readonly, getter = isFrontFacingCameraPresent) BOOL frontFacingCameraPresent; +@property (readonly, getter = isBackFacingCameraPresent) BOOL backFacingCameraPresent; + +/// This enables the benchmarking mode, which logs out instantaneous and average frame times to the console +@property(readwrite, nonatomic) BOOL runBenchmark; + +/// Use this property to manage camera settings. Focus point, exposure point, etc. +@property(readonly) AVCaptureDevice *inputCamera; + +/// This determines the rotation applied to the output image, based on the source material +@property(readwrite, nonatomic) UIInterfaceOrientation outputImageOrientation; + +/// These properties determine whether or not the two camera orientations should be mirrored. By default, both are NO. +@property(readwrite, nonatomic) BOOL horizontallyMirrorFrontFacingCamera, horizontallyMirrorRearFacingCamera; + +@property(nonatomic, assign) id delegate; + +/// @name Initialization and teardown + +/** Begin a capture session + + See AVCaptureSession for acceptable values + + @param sessionPreset Session preset to use + @param cameraPosition Camera to capture from + */ +- (id)initWithSessionPreset:(NSString *)sessionPreset cameraPosition:(AVCaptureDevicePosition)cameraPosition; + +/** Add audio capture to the session. Adding inputs and outputs freezes the capture session momentarily, so you + can use this method to add the audio inputs and outputs early, if you're going to set the audioEncodingTarget + later. Returns YES is the audio inputs and outputs were added, or NO if they had already been added. + */ +- (BOOL)addAudioInputsAndOutputs; + +/** Remove the audio capture inputs and outputs from this session. Returns YES if the audio inputs and outputs + were removed, or NO is they hadn't already been added. + */ +- (BOOL)removeAudioInputsAndOutputs; + +/** Tear down the capture session + */ +- (void)removeInputsAndOutputs; + +/// @name Manage the camera video stream + +/** Start camera capturing + */ +- (void)startCameraCapture; + +/** Stop camera capturing + */ +- (void)stopCameraCapture; + +/** Pause camera capturing + */ +- (void)pauseCameraCapture; + +/** Resume camera capturing + */ +- (void)resumeCameraCapture; + +/** Process a video sample + @param sampleBuffer Buffer to process + */ +- (void)processVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer; + +/** Process an audio sample + @param sampleBuffer Buffer to process + */ +- (void)processAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer; + +/** Get the position (front, rear) of the source camera + */ +- (AVCaptureDevicePosition)cameraPosition; + +/** Get the AVCaptureConnection of the source camera + */ +- (AVCaptureConnection *)videoCaptureConnection; + +/** This flips between the front and rear cameras + */ +- (void)rotateCamera; + +/// @name Benchmarking + +/** When benchmarking is enabled, this will keep a running average of the time from uploading, processing, and final recording or display + */ +- (CGFloat)averageFrameDurationDuringCapture; + +- (void)resetBenchmarkAverage; + ++ (BOOL)isBackFacingCameraPresent; ++ (BOOL)isFrontFacingCameraPresent; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageVideoCamera.m b/LFLiveKit/Vendor/GPUImage/GPUImageVideoCamera.m new file mode 100644 index 00000000..18aa60c3 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageVideoCamera.m @@ -0,0 +1,1062 @@ +#import "GPUImageVideoCamera.h" +#import "GPUImageMovieWriter.h" +#import "GPUImageFilter.h" + +void setColorConversion601( GLfloat conversionMatrix[9] ) +{ + kColorConversion601 = conversionMatrix; +} + +void setColorConversion601FullRange( GLfloat conversionMatrix[9] ) +{ + kColorConversion601FullRange = conversionMatrix; +} + +void setColorConversion709( GLfloat conversionMatrix[9] ) +{ + kColorConversion709 = conversionMatrix; +} + +#pragma mark - +#pragma mark Private methods and instance variables + +@interface GPUImageVideoCamera () +{ + AVCaptureDeviceInput *audioInput; + AVCaptureAudioDataOutput *audioOutput; + NSDate *startingCaptureTime; + + dispatch_queue_t cameraProcessingQueue, audioProcessingQueue; + + GLProgram *yuvConversionProgram; + GLint yuvConversionPositionAttribute, yuvConversionTextureCoordinateAttribute; + GLint yuvConversionLuminanceTextureUniform, yuvConversionChrominanceTextureUniform; + GLint yuvConversionMatrixUniform; + const GLfloat *_preferredConversion; + + BOOL isFullYUVRange; + + int imageBufferWidth, imageBufferHeight; + + BOOL addedAudioInputsDueToEncodingTarget; +} + +- (void)updateOrientationSendToTargets; +- (void)convertYUVToRGBOutput; + +@end + +@implementation GPUImageVideoCamera + +@synthesize captureSessionPreset = _captureSessionPreset; +@synthesize captureSession = _captureSession; +@synthesize inputCamera = _inputCamera; +@synthesize runBenchmark = _runBenchmark; +@synthesize outputImageOrientation = _outputImageOrientation; +@synthesize delegate = _delegate; +@synthesize horizontallyMirrorFrontFacingCamera = _horizontallyMirrorFrontFacingCamera, horizontallyMirrorRearFacingCamera = _horizontallyMirrorRearFacingCamera; +@synthesize frameRate = _frameRate; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack])) + { + return nil; + } + + return self; +} + +- (id)initWithSessionPreset:(NSString *)sessionPreset cameraPosition:(AVCaptureDevicePosition)cameraPosition; +{ + if (!(self = [super init])) + { + return nil; + } + + cameraProcessingQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0); + audioProcessingQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,0); + + frameRenderingSemaphore = dispatch_semaphore_create(1); + + _frameRate = 0; // This will not set frame rate unless this value gets set to 1 or above + _runBenchmark = NO; + capturePaused = NO; + outputRotation = kGPUImageNoRotation; + internalRotation = kGPUImageNoRotation; + captureAsYUV = YES; + _preferredConversion = kColorConversion709; + + // Grab the back-facing or front-facing camera + _inputCamera = nil; + NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; + for (AVCaptureDevice *device in devices) + { + if ([device position] == cameraPosition) + { + _inputCamera = device; + } + } + + if (!_inputCamera) { + return nil; + } + + // Create the capture session + _captureSession = [[AVCaptureSession alloc] init]; + + [_captureSession beginConfiguration]; + + // Add the video input + NSError *error = nil; + videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:_inputCamera error:&error]; + if ([_captureSession canAddInput:videoInput]) + { + [_captureSession addInput:videoInput]; + } + + // Add the video frame output + videoOutput = [[AVCaptureVideoDataOutput alloc] init]; + [videoOutput setAlwaysDiscardsLateVideoFrames:NO]; + +// if (captureAsYUV && [GPUImageContext deviceSupportsRedTextures]) + if (captureAsYUV && [GPUImageContext supportsFastTextureUpload]) + { + BOOL supportsFullYUVRange = NO; + NSArray *supportedPixelFormats = videoOutput.availableVideoCVPixelFormatTypes; + for (NSNumber *currentPixelFormat in supportedPixelFormats) + { + if ([currentPixelFormat intValue] == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) + { + supportsFullYUVRange = YES; + } + } + + if (supportsFullYUVRange) + { + [videoOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarFullRange] forKey:(id)kCVPixelBufferPixelFormatTypeKey]]; + isFullYUVRange = YES; + } + else + { + [videoOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange] forKey:(id)kCVPixelBufferPixelFormatTypeKey]]; + isFullYUVRange = NO; + } + } + else + { + [videoOutput setVideoSettings:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]]; + } + + runSynchronouslyOnVideoProcessingQueue(^{ + + if (captureAsYUV) + { + [GPUImageContext useImageProcessingContext]; + // if ([GPUImageContext deviceSupportsRedTextures]) + // { + // yuvConversionProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:kGPUImageVertexShaderString fragmentShaderString:kGPUImageYUVVideoRangeConversionForRGFragmentShaderString]; + // } + // else + // { + if (isFullYUVRange) + { + yuvConversionProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:kGPUImageVertexShaderString fragmentShaderString:kGPUImageYUVFullRangeConversionForLAFragmentShaderString]; + } + else + { + yuvConversionProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:kGPUImageVertexShaderString fragmentShaderString:kGPUImageYUVVideoRangeConversionForLAFragmentShaderString]; + } + + // } + + if (!yuvConversionProgram.initialized) + { + [yuvConversionProgram addAttribute:@"position"]; + [yuvConversionProgram addAttribute:@"inputTextureCoordinate"]; + + if (![yuvConversionProgram link]) + { + NSString *progLog = [yuvConversionProgram programLog]; + NSLog(@"Program link log: %@", progLog); + NSString *fragLog = [yuvConversionProgram fragmentShaderLog]; + NSLog(@"Fragment shader compile log: %@", fragLog); + NSString *vertLog = [yuvConversionProgram vertexShaderLog]; + NSLog(@"Vertex shader compile log: %@", vertLog); + yuvConversionProgram = nil; + NSAssert(NO, @"Filter shader link failed"); + } + } + + yuvConversionPositionAttribute = [yuvConversionProgram attributeIndex:@"position"]; + yuvConversionTextureCoordinateAttribute = [yuvConversionProgram attributeIndex:@"inputTextureCoordinate"]; + yuvConversionLuminanceTextureUniform = [yuvConversionProgram uniformIndex:@"luminanceTexture"]; + yuvConversionChrominanceTextureUniform = [yuvConversionProgram uniformIndex:@"chrominanceTexture"]; + yuvConversionMatrixUniform = [yuvConversionProgram uniformIndex:@"colorConversionMatrix"]; + + [GPUImageContext setActiveShaderProgram:yuvConversionProgram]; + + glEnableVertexAttribArray(yuvConversionPositionAttribute); + glEnableVertexAttribArray(yuvConversionTextureCoordinateAttribute); + } + }); + + [videoOutput setSampleBufferDelegate:self queue:cameraProcessingQueue]; + if ([_captureSession canAddOutput:videoOutput]) + { + [_captureSession addOutput:videoOutput]; + } + else + { + NSLog(@"Couldn't add video output"); + return nil; + } + + _captureSessionPreset = sessionPreset; + [_captureSession setSessionPreset:_captureSessionPreset]; + +// This will let you get 60 FPS video from the 720p preset on an iPhone 4S, but only that device and that preset +// AVCaptureConnection *conn = [videoOutput connectionWithMediaType:AVMediaTypeVideo]; +// +// if (conn.supportsVideoMinFrameDuration) +// conn.videoMinFrameDuration = CMTimeMake(1,60); +// if (conn.supportsVideoMaxFrameDuration) +// conn.videoMaxFrameDuration = CMTimeMake(1,60); + + [_captureSession commitConfiguration]; + + return self; +} + +- (GPUImageFramebuffer *)framebufferForOutput; +{ + return outputFramebuffer; +} + +- (void)dealloc +{ + [self stopCameraCapture]; + [videoOutput setSampleBufferDelegate:nil queue:dispatch_get_main_queue()]; + [audioOutput setSampleBufferDelegate:nil queue:dispatch_get_main_queue()]; + + [self removeInputsAndOutputs]; + +// ARC forbids explicit message send of 'release'; since iOS 6 even for dispatch_release() calls: stripping it out in that case is required. +#if !OS_OBJECT_USE_OBJC + if (frameRenderingSemaphore != NULL) + { + dispatch_release(frameRenderingSemaphore); + } +#endif +} + +- (BOOL)addAudioInputsAndOutputs +{ + if (audioOutput) + return NO; + + [_captureSession beginConfiguration]; + + _microphone = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio]; + audioInput = [AVCaptureDeviceInput deviceInputWithDevice:_microphone error:nil]; + if ([_captureSession canAddInput:audioInput]) + { + [_captureSession addInput:audioInput]; + } + audioOutput = [[AVCaptureAudioDataOutput alloc] init]; + + if ([_captureSession canAddOutput:audioOutput]) + { + [_captureSession addOutput:audioOutput]; + } + else + { + NSLog(@"Couldn't add audio output"); + } + [audioOutput setSampleBufferDelegate:self queue:audioProcessingQueue]; + + [_captureSession commitConfiguration]; + return YES; +} + +- (BOOL)removeAudioInputsAndOutputs +{ + if (!audioOutput) + return NO; + + [_captureSession beginConfiguration]; + [_captureSession removeInput:audioInput]; + [_captureSession removeOutput:audioOutput]; + audioInput = nil; + audioOutput = nil; + _microphone = nil; + [_captureSession commitConfiguration]; + return YES; +} + +- (void)removeInputsAndOutputs; +{ + [_captureSession beginConfiguration]; + if (videoInput) { + [_captureSession removeInput:videoInput]; + [_captureSession removeOutput:videoOutput]; + videoInput = nil; + videoOutput = nil; + } + if (_microphone != nil) + { + [_captureSession removeInput:audioInput]; + [_captureSession removeOutput:audioOutput]; + audioInput = nil; + audioOutput = nil; + _microphone = nil; + } + [_captureSession commitConfiguration]; +} + +#pragma mark - +#pragma mark Managing targets + +- (void)addTarget:(id)newTarget atTextureLocation:(NSInteger)textureLocation; +{ + [super addTarget:newTarget atTextureLocation:textureLocation]; + + [newTarget setInputRotation:outputRotation atIndex:textureLocation]; +} + +#pragma mark - +#pragma mark Manage the camera video stream + +- (BOOL)isRunning; +{ + return [_captureSession isRunning]; +} + +- (void)startCameraCapture; +{ + if (![_captureSession isRunning]) + { + startingCaptureTime = [NSDate date]; + [_captureSession startRunning]; + }; +} + +- (void)stopCameraCapture; +{ + if ([_captureSession isRunning]) + { + [_captureSession stopRunning]; + } +} + +- (void)pauseCameraCapture; +{ + capturePaused = YES; +} + +- (void)resumeCameraCapture; +{ + capturePaused = NO; +} + +- (void)rotateCamera +{ + if (self.frontFacingCameraPresent == NO) + return; + + NSError *error; + AVCaptureDeviceInput *newVideoInput; + AVCaptureDevicePosition currentCameraPosition = [[videoInput device] position]; + + if (currentCameraPosition == AVCaptureDevicePositionBack) + { + currentCameraPosition = AVCaptureDevicePositionFront; + } + else + { + currentCameraPosition = AVCaptureDevicePositionBack; + } + + AVCaptureDevice *backFacingCamera = nil; + NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; + for (AVCaptureDevice *device in devices) + { + if ([device position] == currentCameraPosition) + { + backFacingCamera = device; + } + } + newVideoInput = [[AVCaptureDeviceInput alloc] initWithDevice:backFacingCamera error:&error]; + + if (newVideoInput != nil) + { + [_captureSession beginConfiguration]; + + [_captureSession removeInput:videoInput]; + if ([_captureSession canAddInput:newVideoInput]) + { + [_captureSession addInput:newVideoInput]; + videoInput = newVideoInput; + } + else + { + [_captureSession addInput:videoInput]; + } + //captureSession.sessionPreset = oriPreset; + [_captureSession commitConfiguration]; + } + + _inputCamera = backFacingCamera; + [self setOutputImageOrientation:_outputImageOrientation]; +} + +- (AVCaptureDevicePosition)cameraPosition +{ + return [[videoInput device] position]; +} + ++ (BOOL)isBackFacingCameraPresent; +{ + NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; + + for (AVCaptureDevice *device in devices) + { + if ([device position] == AVCaptureDevicePositionBack) + return YES; + } + + return NO; +} + +- (BOOL)isBackFacingCameraPresent +{ + return [GPUImageVideoCamera isBackFacingCameraPresent]; +} + ++ (BOOL)isFrontFacingCameraPresent; +{ + NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; + + for (AVCaptureDevice *device in devices) + { + if ([device position] == AVCaptureDevicePositionFront) + return YES; + } + + return NO; +} + +- (BOOL)isFrontFacingCameraPresent +{ + return [GPUImageVideoCamera isFrontFacingCameraPresent]; +} + +- (void)setCaptureSessionPreset:(NSString *)captureSessionPreset; +{ + [_captureSession beginConfiguration]; + + _captureSessionPreset = captureSessionPreset; + [_captureSession setSessionPreset:_captureSessionPreset]; + + [_captureSession commitConfiguration]; +} + +- (void)setFrameRate:(int32_t)frameRate; +{ + _frameRate = frameRate; + + if (_frameRate > 0) + { + if ([_inputCamera respondsToSelector:@selector(setActiveVideoMinFrameDuration:)] && + [_inputCamera respondsToSelector:@selector(setActiveVideoMaxFrameDuration:)]) { + + NSError *error; + [_inputCamera lockForConfiguration:&error]; + if (error == nil) { +#if defined(__IPHONE_7_0) + [_inputCamera setActiveVideoMinFrameDuration:CMTimeMake(1, _frameRate)]; + [_inputCamera setActiveVideoMaxFrameDuration:CMTimeMake(1, _frameRate)]; +#endif + } + [_inputCamera unlockForConfiguration]; + + } else { + + for (AVCaptureConnection *connection in videoOutput.connections) + { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + if ([connection respondsToSelector:@selector(setVideoMinFrameDuration:)]) + connection.videoMinFrameDuration = CMTimeMake(1, _frameRate); + + if ([connection respondsToSelector:@selector(setVideoMaxFrameDuration:)]) + connection.videoMaxFrameDuration = CMTimeMake(1, _frameRate); +#pragma clang diagnostic pop + } + } + + } + else + { + if ([_inputCamera respondsToSelector:@selector(setActiveVideoMinFrameDuration:)] && + [_inputCamera respondsToSelector:@selector(setActiveVideoMaxFrameDuration:)]) { + + NSError *error; + [_inputCamera lockForConfiguration:&error]; + if (error == nil) { +#if defined(__IPHONE_7_0) + [_inputCamera setActiveVideoMinFrameDuration:kCMTimeInvalid]; + [_inputCamera setActiveVideoMaxFrameDuration:kCMTimeInvalid]; +#endif + } + [_inputCamera unlockForConfiguration]; + + } else { + + for (AVCaptureConnection *connection in videoOutput.connections) + { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + if ([connection respondsToSelector:@selector(setVideoMinFrameDuration:)]) + connection.videoMinFrameDuration = kCMTimeInvalid; // This sets videoMinFrameDuration back to default + + if ([connection respondsToSelector:@selector(setVideoMaxFrameDuration:)]) + connection.videoMaxFrameDuration = kCMTimeInvalid; // This sets videoMaxFrameDuration back to default +#pragma clang diagnostic pop + } + } + + } +} + +- (int32_t)frameRate; +{ + return _frameRate; +} + +- (AVCaptureConnection *)videoCaptureConnection { + for (AVCaptureConnection *connection in [videoOutput connections] ) { + for ( AVCaptureInputPort *port in [connection inputPorts] ) { + if ( [[port mediaType] isEqual:AVMediaTypeVideo] ) { + return connection; + } + } + } + + return nil; +} + +#define INITIALFRAMESTOIGNOREFORBENCHMARK 5 + +- (void)updateTargetsForVideoCameraUsingCacheTextureAtWidth:(int)bufferWidth height:(int)bufferHeight time:(CMTime)currentTime; +{ + // First, update all the framebuffers in the targets + for (id currentTarget in targets) + { + if ([currentTarget enabled]) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger textureIndexOfTarget = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + if (currentTarget != self.targetToIgnoreForUpdates) + { + [currentTarget setInputRotation:outputRotation atIndex:textureIndexOfTarget]; + [currentTarget setInputSize:CGSizeMake(bufferWidth, bufferHeight) atIndex:textureIndexOfTarget]; + + if ([currentTarget wantsMonochromeInput] && captureAsYUV) + { + [currentTarget setCurrentlyReceivingMonochromeInput:YES]; + // TODO: Replace optimization for monochrome output + [currentTarget setInputFramebuffer:outputFramebuffer atIndex:textureIndexOfTarget]; + } + else + { + [currentTarget setCurrentlyReceivingMonochromeInput:NO]; + [currentTarget setInputFramebuffer:outputFramebuffer atIndex:textureIndexOfTarget]; + } + } + else + { + [currentTarget setInputRotation:outputRotation atIndex:textureIndexOfTarget]; + [currentTarget setInputFramebuffer:outputFramebuffer atIndex:textureIndexOfTarget]; + } + } + } + + // Then release our hold on the local framebuffer to send it back to the cache as soon as it's no longer needed + [outputFramebuffer unlock]; + outputFramebuffer = nil; + + // Finally, trigger rendering as needed + for (id currentTarget in targets) + { + if ([currentTarget enabled]) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger textureIndexOfTarget = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + if (currentTarget != self.targetToIgnoreForUpdates) + { + [currentTarget newFrameReadyAtTime:currentTime atIndex:textureIndexOfTarget]; + } + } + } +} + +- (void)processVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer; +{ + if (capturePaused) + { + return; + } + + CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent(); + CVImageBufferRef cameraFrame = CMSampleBufferGetImageBuffer(sampleBuffer); + int bufferWidth = (int) CVPixelBufferGetWidth(cameraFrame); + int bufferHeight = (int) CVPixelBufferGetHeight(cameraFrame); + CFTypeRef colorAttachments = CVBufferGetAttachment(cameraFrame, kCVImageBufferYCbCrMatrixKey, NULL); + if (colorAttachments != NULL) + { + if(CFStringCompare(colorAttachments, kCVImageBufferYCbCrMatrix_ITU_R_601_4, 0) == kCFCompareEqualTo) + { + if (isFullYUVRange) + { + _preferredConversion = kColorConversion601FullRange; + } + else + { + _preferredConversion = kColorConversion601; + } + } + else + { + _preferredConversion = kColorConversion709; + } + } + else + { + if (isFullYUVRange) + { + _preferredConversion = kColorConversion601FullRange; + } + else + { + _preferredConversion = kColorConversion601; + } + } + + CMTime currentTime = CMSampleBufferGetPresentationTimeStamp(sampleBuffer); + + [GPUImageContext useImageProcessingContext]; + + if ([GPUImageContext supportsFastTextureUpload] && captureAsYUV) + { + CVOpenGLESTextureRef luminanceTextureRef = NULL; + CVOpenGLESTextureRef chrominanceTextureRef = NULL; + +// if (captureAsYUV && [GPUImageContext deviceSupportsRedTextures]) + if (CVPixelBufferGetPlaneCount(cameraFrame) > 0) // Check for YUV planar inputs to do RGB conversion + { + CVPixelBufferLockBaseAddress(cameraFrame, 0); + + if ( (imageBufferWidth != bufferWidth) && (imageBufferHeight != bufferHeight) ) + { + imageBufferWidth = bufferWidth; + imageBufferHeight = bufferHeight; + } + + CVReturn err; + // Y-plane + glActiveTexture(GL_TEXTURE4); + if ([GPUImageContext deviceSupportsRedTextures]) + { +// err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, coreVideoTextureCache, cameraFrame, NULL, GL_TEXTURE_2D, GL_RED_EXT, bufferWidth, bufferHeight, GL_RED_EXT, GL_UNSIGNED_BYTE, 0, &luminanceTextureRef); + err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], cameraFrame, NULL, GL_TEXTURE_2D, GL_LUMINANCE, bufferWidth, bufferHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0, &luminanceTextureRef); + } + else + { + err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], cameraFrame, NULL, GL_TEXTURE_2D, GL_LUMINANCE, bufferWidth, bufferHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0, &luminanceTextureRef); + } + if (err) + { + NSLog(@"Error at CVOpenGLESTextureCacheCreateTextureFromImage %d", err); + } + + luminanceTexture = CVOpenGLESTextureGetName(luminanceTextureRef); + glBindTexture(GL_TEXTURE_2D, luminanceTexture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + // UV-plane + glActiveTexture(GL_TEXTURE5); + if ([GPUImageContext deviceSupportsRedTextures]) + { +// err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, coreVideoTextureCache, cameraFrame, NULL, GL_TEXTURE_2D, GL_RG_EXT, bufferWidth/2, bufferHeight/2, GL_RG_EXT, GL_UNSIGNED_BYTE, 1, &chrominanceTextureRef); + err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], cameraFrame, NULL, GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, bufferWidth/2, bufferHeight/2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 1, &chrominanceTextureRef); + } + else + { + err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], cameraFrame, NULL, GL_TEXTURE_2D, GL_LUMINANCE_ALPHA, bufferWidth/2, bufferHeight/2, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, 1, &chrominanceTextureRef); + } + if (err) + { + NSLog(@"Error at CVOpenGLESTextureCacheCreateTextureFromImage %d", err); + } + + chrominanceTexture = CVOpenGLESTextureGetName(chrominanceTextureRef); + glBindTexture(GL_TEXTURE_2D, chrominanceTexture); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + +// if (!allTargetsWantMonochromeData) +// { + [self convertYUVToRGBOutput]; +// } + + int rotatedImageBufferWidth = bufferWidth, rotatedImageBufferHeight = bufferHeight; + + if (GPUImageRotationSwapsWidthAndHeight(internalRotation)) + { + rotatedImageBufferWidth = bufferHeight; + rotatedImageBufferHeight = bufferWidth; + } + + [self updateTargetsForVideoCameraUsingCacheTextureAtWidth:rotatedImageBufferWidth height:rotatedImageBufferHeight time:currentTime]; + + CVPixelBufferUnlockBaseAddress(cameraFrame, 0); + CFRelease(luminanceTextureRef); + CFRelease(chrominanceTextureRef); + } + else + { + // TODO: Mesh this with the output framebuffer structure + +// CVPixelBufferLockBaseAddress(cameraFrame, 0); +// +// CVReturn err = CVOpenGLESTextureCacheCreateTextureFromImage(kCFAllocatorDefault, [[GPUImageContext sharedImageProcessingContext] coreVideoTextureCache], cameraFrame, NULL, GL_TEXTURE_2D, GL_RGBA, bufferWidth, bufferHeight, GL_BGRA, GL_UNSIGNED_BYTE, 0, &texture); +// +// if (!texture || err) { +// NSLog(@"Camera CVOpenGLESTextureCacheCreateTextureFromImage failed (error: %d)", err); +// NSAssert(NO, @"Camera failure"); +// return; +// } +// +// outputTexture = CVOpenGLESTextureGetName(texture); +// // glBindTexture(CVOpenGLESTextureGetTarget(texture), outputTexture); +// glBindTexture(GL_TEXTURE_2D, outputTexture); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); +// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); +// +// [self updateTargetsForVideoCameraUsingCacheTextureAtWidth:bufferWidth height:bufferHeight time:currentTime]; +// +// CVPixelBufferUnlockBaseAddress(cameraFrame, 0); +// CFRelease(texture); +// +// outputTexture = 0; + } + + + if (_runBenchmark) + { + numberOfFramesCaptured++; + if (numberOfFramesCaptured > INITIALFRAMESTOIGNOREFORBENCHMARK) + { + CFAbsoluteTime currentFrameTime = (CFAbsoluteTimeGetCurrent() - startTime); + totalFrameTimeDuringCapture += currentFrameTime; + NSLog(@"Average frame time : %f ms", [self averageFrameDurationDuringCapture]); + NSLog(@"Current frame time : %f ms", 1000.0 * currentFrameTime); + } + } + } + else + { + CVPixelBufferLockBaseAddress(cameraFrame, 0); + + int bytesPerRow = (int) CVPixelBufferGetBytesPerRow(cameraFrame); + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:CGSizeMake(bytesPerRow / 4, bufferHeight) onlyTexture:YES]; + [outputFramebuffer activateFramebuffer]; + + glBindTexture(GL_TEXTURE_2D, [outputFramebuffer texture]); + + // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bufferWidth, bufferHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, CVPixelBufferGetBaseAddress(cameraFrame)); + + // Using BGRA extension to pull in video frame data directly + // The use of bytesPerRow / 4 accounts for a display glitch present in preview video frames when using the photo preset on the camera + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bytesPerRow / 4, bufferHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, CVPixelBufferGetBaseAddress(cameraFrame)); + + [self updateTargetsForVideoCameraUsingCacheTextureAtWidth:bytesPerRow / 4 height:bufferHeight time:currentTime]; + + CVPixelBufferUnlockBaseAddress(cameraFrame, 0); + + if (_runBenchmark) + { + numberOfFramesCaptured++; + if (numberOfFramesCaptured > INITIALFRAMESTOIGNOREFORBENCHMARK) + { + CFAbsoluteTime currentFrameTime = (CFAbsoluteTimeGetCurrent() - startTime); + totalFrameTimeDuringCapture += currentFrameTime; + } + } + } +} + +- (void)processAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer; +{ + [self.audioEncodingTarget processAudioBuffer:sampleBuffer]; +} + +- (void)convertYUVToRGBOutput; +{ + [GPUImageContext setActiveShaderProgram:yuvConversionProgram]; + + int rotatedImageBufferWidth = imageBufferWidth, rotatedImageBufferHeight = imageBufferHeight; + + if (GPUImageRotationSwapsWidthAndHeight(internalRotation)) + { + rotatedImageBufferWidth = imageBufferHeight; + rotatedImageBufferHeight = imageBufferWidth; + } + + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:CGSizeMake(rotatedImageBufferWidth, rotatedImageBufferHeight) textureOptions:self.outputTextureOptions onlyTexture:NO]; + [outputFramebuffer activateFramebuffer]; + + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + static const GLfloat squareVertices[] = { + -1.0f, -1.0f, + 1.0f, -1.0f, + -1.0f, 1.0f, + 1.0f, 1.0f, + }; + + glActiveTexture(GL_TEXTURE4); + glBindTexture(GL_TEXTURE_2D, luminanceTexture); + glUniform1i(yuvConversionLuminanceTextureUniform, 4); + + glActiveTexture(GL_TEXTURE5); + glBindTexture(GL_TEXTURE_2D, chrominanceTexture); + glUniform1i(yuvConversionChrominanceTextureUniform, 5); + + glUniformMatrix3fv(yuvConversionMatrixUniform, 1, GL_FALSE, _preferredConversion); + + glVertexAttribPointer(yuvConversionPositionAttribute, 2, GL_FLOAT, 0, 0, squareVertices); + glVertexAttribPointer(yuvConversionTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [GPUImageFilter textureCoordinatesForRotation:internalRotation]); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); +} + +#pragma mark - +#pragma mark Benchmarking + +- (CGFloat)averageFrameDurationDuringCapture; +{ + return (totalFrameTimeDuringCapture / (CGFloat)(numberOfFramesCaptured - INITIALFRAMESTOIGNOREFORBENCHMARK)) * 1000.0; +} + +- (void)resetBenchmarkAverage; +{ + numberOfFramesCaptured = 0; + totalFrameTimeDuringCapture = 0.0; +} + +#pragma mark - +#pragma mark AVCaptureVideoDataOutputSampleBufferDelegate + +- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection +{ + if (!self.captureSession.isRunning) + { + return; + } + else if (captureOutput == audioOutput) + { + [self processAudioSampleBuffer:sampleBuffer]; + } + else + { + if (dispatch_semaphore_wait(frameRenderingSemaphore, DISPATCH_TIME_NOW) != 0) + { + return; + } + + CFRetain(sampleBuffer); + runAsynchronouslyOnVideoProcessingQueue(^{ + //Feature Detection Hook. + if (self.delegate) + { + [self.delegate willOutputSampleBuffer:sampleBuffer]; + } + + [self processVideoSampleBuffer:sampleBuffer]; + + CFRelease(sampleBuffer); + dispatch_semaphore_signal(frameRenderingSemaphore); + }); + } +} + +#pragma mark - +#pragma mark Accessors + +- (void)setAudioEncodingTarget:(GPUImageMovieWriter *)newValue; +{ + if (newValue) { + /* Add audio inputs and outputs, if necessary */ + addedAudioInputsDueToEncodingTarget |= [self addAudioInputsAndOutputs]; + } else if (addedAudioInputsDueToEncodingTarget) { + /* Remove audio inputs and outputs, if they were added by previously setting the audio encoding target */ + [self removeAudioInputsAndOutputs]; + addedAudioInputsDueToEncodingTarget = NO; + } + + [super setAudioEncodingTarget:newValue]; +} + +- (void)updateOrientationSendToTargets; +{ + runSynchronouslyOnVideoProcessingQueue(^{ + + // From the iOS 5.0 release notes: + // In previous iOS versions, the front-facing camera would always deliver buffers in AVCaptureVideoOrientationLandscapeLeft and the back-facing camera would always deliver buffers in AVCaptureVideoOrientationLandscapeRight. + + if (captureAsYUV && [GPUImageContext supportsFastTextureUpload]) + { + outputRotation = kGPUImageNoRotation; + if ([self cameraPosition] == AVCaptureDevicePositionBack) + { + if (_horizontallyMirrorRearFacingCamera) + { + switch(_outputImageOrientation) + { + case UIInterfaceOrientationPortrait:internalRotation = kGPUImageRotateRightFlipVertical; break; + case UIInterfaceOrientationPortraitUpsideDown:internalRotation = kGPUImageRotate180; break; + case UIInterfaceOrientationLandscapeLeft:internalRotation = kGPUImageFlipHorizonal; break; + case UIInterfaceOrientationLandscapeRight:internalRotation = kGPUImageFlipVertical; break; + default:internalRotation = kGPUImageNoRotation; + } + } + else + { + switch(_outputImageOrientation) + { + case UIInterfaceOrientationPortrait:internalRotation = kGPUImageRotateRight; break; + case UIInterfaceOrientationPortraitUpsideDown:internalRotation = kGPUImageRotateLeft; break; + case UIInterfaceOrientationLandscapeLeft:internalRotation = kGPUImageRotate180; break; + case UIInterfaceOrientationLandscapeRight:internalRotation = kGPUImageNoRotation; break; + default:internalRotation = kGPUImageNoRotation; + } + } + } + else + { + if (_horizontallyMirrorFrontFacingCamera) + { + switch(_outputImageOrientation) + { + case UIInterfaceOrientationPortrait:internalRotation = kGPUImageRotateRightFlipVertical; break; + case UIInterfaceOrientationPortraitUpsideDown:internalRotation = kGPUImageRotateRightFlipHorizontal; break; + case UIInterfaceOrientationLandscapeLeft:internalRotation = kGPUImageFlipHorizonal; break; + case UIInterfaceOrientationLandscapeRight:internalRotation = kGPUImageFlipVertical; break; + default:internalRotation = kGPUImageNoRotation; + } + } + else + { + switch(_outputImageOrientation) + { + case UIInterfaceOrientationPortrait:internalRotation = kGPUImageRotateRight; break; + case UIInterfaceOrientationPortraitUpsideDown:internalRotation = kGPUImageRotateLeft; break; + case UIInterfaceOrientationLandscapeLeft:internalRotation = kGPUImageNoRotation; break; + case UIInterfaceOrientationLandscapeRight:internalRotation = kGPUImageRotate180; break; + default:internalRotation = kGPUImageNoRotation; + } + } + } + } + else + { + if ([self cameraPosition] == AVCaptureDevicePositionBack) + { + if (_horizontallyMirrorRearFacingCamera) + { + switch(_outputImageOrientation) + { + case UIInterfaceOrientationPortrait:outputRotation = kGPUImageRotateRightFlipVertical; break; + case UIInterfaceOrientationPortraitUpsideDown:outputRotation = kGPUImageRotate180; break; + case UIInterfaceOrientationLandscapeLeft:outputRotation = kGPUImageFlipHorizonal; break; + case UIInterfaceOrientationLandscapeRight:outputRotation = kGPUImageFlipVertical; break; + default:outputRotation = kGPUImageNoRotation; + } + } + else + { + switch(_outputImageOrientation) + { + case UIInterfaceOrientationPortrait:outputRotation = kGPUImageRotateRight; break; + case UIInterfaceOrientationPortraitUpsideDown:outputRotation = kGPUImageRotateLeft; break; + case UIInterfaceOrientationLandscapeLeft:outputRotation = kGPUImageRotate180; break; + case UIInterfaceOrientationLandscapeRight:outputRotation = kGPUImageNoRotation; break; + default:outputRotation = kGPUImageNoRotation; + } + } + } + else + { + if (_horizontallyMirrorFrontFacingCamera) + { + switch(_outputImageOrientation) + { + case UIInterfaceOrientationPortrait:outputRotation = kGPUImageRotateRightFlipVertical; break; + case UIInterfaceOrientationPortraitUpsideDown:outputRotation = kGPUImageRotateRightFlipHorizontal; break; + case UIInterfaceOrientationLandscapeLeft:outputRotation = kGPUImageFlipHorizonal; break; + case UIInterfaceOrientationLandscapeRight:outputRotation = kGPUImageFlipVertical; break; + default:outputRotation = kGPUImageNoRotation; + } + } + else + { + switch(_outputImageOrientation) + { + case UIInterfaceOrientationPortrait:outputRotation = kGPUImageRotateRight; break; + case UIInterfaceOrientationPortraitUpsideDown:outputRotation = kGPUImageRotateLeft; break; + case UIInterfaceOrientationLandscapeLeft:outputRotation = kGPUImageNoRotation; break; + case UIInterfaceOrientationLandscapeRight:outputRotation = kGPUImageRotate180; break; + default:outputRotation = kGPUImageNoRotation; + } + } + } + } + + for (id currentTarget in targets) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + [currentTarget setInputRotation:outputRotation atIndex:[[targetTextureIndices objectAtIndex:indexOfObject] integerValue]]; + } + }); +} + +- (void)setOutputImageOrientation:(UIInterfaceOrientation)newValue; +{ + _outputImageOrientation = newValue; + [self updateOrientationSendToTargets]; +} + +- (void)setHorizontallyMirrorFrontFacingCamera:(BOOL)newValue +{ + _horizontallyMirrorFrontFacingCamera = newValue; + [self updateOrientationSendToTargets]; +} + +- (void)setHorizontallyMirrorRearFacingCamera:(BOOL)newValue +{ + _horizontallyMirrorRearFacingCamera = newValue; + [self updateOrientationSendToTargets]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageVignetteFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageVignetteFilter.h new file mode 100755 index 00000000..37be9449 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageVignetteFilter.h @@ -0,0 +1,22 @@ +#import "GPUImageFilter.h" + +/** Performs a vignetting effect, fading out the image at the edges + */ +@interface GPUImageVignetteFilter : GPUImageFilter +{ + GLint vignetteCenterUniform, vignetteColorUniform, vignetteStartUniform, vignetteEndUniform; +} + +// the center for the vignette in tex coords (defaults to 0.5, 0.5) +@property (nonatomic, readwrite) CGPoint vignetteCenter; + +// The color to use for the Vignette (defaults to black) +@property (nonatomic, readwrite) GPUVector3 vignetteColor; + +// The normalized distance from the center where the vignette effect starts. Default of 0.5. +@property (nonatomic, readwrite) CGFloat vignetteStart; + +// The normalized distance from the center where the vignette effect ends. Default of 0.75. +@property (nonatomic, readwrite) CGFloat vignetteEnd; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageVignetteFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageVignetteFilter.m new file mode 100755 index 00000000..6e1eadb2 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageVignetteFilter.m @@ -0,0 +1,104 @@ +#import "GPUImageVignetteFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageVignetteFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + varying highp vec2 textureCoordinate; + + uniform lowp vec2 vignetteCenter; + uniform lowp vec3 vignetteColor; + uniform highp float vignetteStart; + uniform highp float vignetteEnd; + + void main() + { + lowp vec4 sourceImageColor = texture2D(inputImageTexture, textureCoordinate); + lowp float d = distance(textureCoordinate, vec2(vignetteCenter.x, vignetteCenter.y)); + lowp float percent = smoothstep(vignetteStart, vignetteEnd, d); + gl_FragColor = vec4(mix(sourceImageColor.rgb, vignetteColor, percent), sourceImageColor.a); + } +); +#else +NSString *const kGPUImageVignetteFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + varying vec2 textureCoordinate; + + uniform vec2 vignetteCenter; + uniform vec3 vignetteColor; + uniform float vignetteStart; + uniform float vignetteEnd; + + void main() + { + vec4 sourceImageColor = texture2D(inputImageTexture, textureCoordinate); + float d = distance(textureCoordinate, vec2(vignetteCenter.x, vignetteCenter.y)); + float percent = smoothstep(vignetteStart, vignetteEnd, d); + gl_FragColor = vec4(mix(sourceImageColor.rgb, vignetteColor, percent), sourceImageColor.a); + } +); +#endif + +@implementation GPUImageVignetteFilter + +@synthesize vignetteCenter = _vignetteCenter; +@synthesize vignetteColor = _vignetteColor; +@synthesize vignetteStart =_vignetteStart; +@synthesize vignetteEnd = _vignetteEnd; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageVignetteFragmentShaderString])) + { + return nil; + } + + vignetteCenterUniform = [filterProgram uniformIndex:@"vignetteCenter"]; + vignetteColorUniform = [filterProgram uniformIndex:@"vignetteColor"]; + vignetteStartUniform = [filterProgram uniformIndex:@"vignetteStart"]; + vignetteEndUniform = [filterProgram uniformIndex:@"vignetteEnd"]; + + self.vignetteCenter = (CGPoint){ 0.5f, 0.5f }; + self.vignetteColor = (GPUVector3){ 0.0f, 0.0f, 0.0f }; + self.vignetteStart = 0.3; + self.vignetteEnd = 0.75; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setVignetteCenter:(CGPoint)newValue +{ + _vignetteCenter = newValue; + + [self setPoint:newValue forUniform:vignetteCenterUniform program:filterProgram]; +} + +- (void)setVignetteColor:(GPUVector3)newValue +{ + _vignetteColor = newValue; + + [self setVec3:newValue forUniform:vignetteColorUniform program:filterProgram]; +} + +- (void)setVignetteStart:(CGFloat)newValue; +{ + _vignetteStart = newValue; + + [self setFloat:_vignetteStart forUniform:vignetteStartUniform program:filterProgram]; +} + +- (void)setVignetteEnd:(CGFloat)newValue; +{ + _vignetteEnd = newValue; + + [self setFloat:_vignetteEnd forUniform:vignetteEndUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageVoronoiConsumerFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageVoronoiConsumerFilter.h new file mode 100644 index 00000000..659e39d5 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageVoronoiConsumerFilter.h @@ -0,0 +1,10 @@ +#import "GPUImageTwoInputFilter.h" + +@interface GPUImageVoronoiConsumerFilter : GPUImageTwoInputFilter +{ + GLint sizeUniform; +} + +@property (nonatomic, readwrite) CGSize sizeInPixels; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageVoronoiConsumerFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageVoronoiConsumerFilter.m new file mode 100644 index 00000000..c12c34f4 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageVoronoiConsumerFilter.m @@ -0,0 +1,94 @@ +#import "GPUImageVoronoiConsumerFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageVoronoiConsumerFragmentShaderString = SHADER_STRING +( + + precision highp float; + + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + uniform vec2 size; + varying vec2 textureCoordinate; + + vec2 getCoordFromColor(vec4 color) +{ + float z = color.z * 256.0; + float yoff = floor(z / 8.0); + float xoff = mod(z, 8.0); + float x = color.x*256.0 + xoff*256.0; + float y = color.y*256.0 + yoff*256.0; + return vec2(x,y) / size; +} + + void main(void) { + vec4 colorLoc = texture2D(inputImageTexture2, textureCoordinate); + vec4 color = texture2D(inputImageTexture, getCoordFromColor(colorLoc)); + + gl_FragColor = color; + } +); +#else +NSString *const kGPUImageVoronoiConsumerFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + uniform sampler2D inputImageTexture2; + uniform vec2 size; + varying vec2 textureCoordinate; + + vec2 getCoordFromColor(vec4 color) + { + float z = color.z * 256.0; + float yoff = floor(z / 8.0); + float xoff = mod(z, 8.0); + float x = color.x*256.0 + xoff*256.0; + float y = color.y*256.0 + yoff*256.0; + return vec2(x,y) / size; + } + + void main(void) + { + vec4 colorLoc = texture2D(inputImageTexture2, textureCoordinate); + vec4 color = texture2D(inputImageTexture, getCoordFromColor(colorLoc)); + + gl_FragColor = color; + } +); +#endif + +@implementation GPUImageVoronoiConsumerFilter + +@synthesize sizeInPixels = _sizeInPixels; + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageVoronoiConsumerFragmentShaderString])) + { + return nil; + } + + sizeUniform = [filterProgram uniformIndex:@"size"]; + + return self; +} + +-(void)setSizeInPixels:(CGSize)sizeInPixels { + _sizeInPixels = sizeInPixels; + + //validate that it's a power of 2 and square + + float width = log2(sizeInPixels.width); + float height = log2(sizeInPixels.height); + + if (width != height) { + NSLog(@"Voronoi point texture must be square"); + return; + } + if (width != floor(width) || height != floor(height)) { + NSLog(@"Voronoi point texture must be a power of 2. Texture size %f, %f", sizeInPixels.width, sizeInPixels.height); + return; + } + glUniform2f(sizeUniform, _sizeInPixels.width, _sizeInPixels.height); +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageWeakPixelInclusionFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageWeakPixelInclusionFilter.h new file mode 100644 index 00000000..44b76c6a --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageWeakPixelInclusionFilter.h @@ -0,0 +1,5 @@ +#import "GPUImage3x3TextureSamplingFilter.h" + +@interface GPUImageWeakPixelInclusionFilter : GPUImage3x3TextureSamplingFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageWeakPixelInclusionFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageWeakPixelInclusionFilter.m new file mode 100644 index 00000000..4e95ad5d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageWeakPixelInclusionFilter.m @@ -0,0 +1,94 @@ +#import "GPUImageWeakPixelInclusionFilter.h" + +@implementation GPUImageWeakPixelInclusionFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageWeakPixelInclusionFragmentShaderString = SHADER_STRING +( + precision lowp float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float centerIntensity = texture2D(inputImageTexture, textureCoordinate).r; + + float pixelIntensitySum = bottomLeftIntensity + topRightIntensity + topLeftIntensity + bottomRightIntensity + leftIntensity + rightIntensity + bottomIntensity + topIntensity + centerIntensity; + float sumTest = step(1.5, pixelIntensitySum); + float pixelTest = step(0.01, centerIntensity); + + gl_FragColor = vec4(vec3(sumTest * pixelTest), 1.0); + } +); +#else +NSString *const kGPUImageWeakPixelInclusionFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float centerIntensity = texture2D(inputImageTexture, textureCoordinate).r; + + float pixelIntensitySum = bottomLeftIntensity + topRightIntensity + topLeftIntensity + bottomRightIntensity + leftIntensity + rightIntensity + bottomIntensity + topIntensity + centerIntensity; + float sumTest = step(1.5, pixelIntensitySum); + float pixelTest = step(0.01, centerIntensity); + + gl_FragColor = vec4(vec3(sumTest * pixelTest), 1.0); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImageWeakPixelInclusionFragmentShaderString])) + { + return nil; + } + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageWhiteBalanceFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageWhiteBalanceFilter.h new file mode 100644 index 00000000..6b09c33d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageWhiteBalanceFilter.h @@ -0,0 +1,17 @@ +#import "GPUImageFilter.h" +/** + * Created by Alaric Cole + * Allows adjustment of color temperature in terms of what an image was effectively shot in. This means higher Kelvin values will warm the image, while lower values will cool it. + + */ +@interface GPUImageWhiteBalanceFilter : GPUImageFilter +{ + GLint temperatureUniform, tintUniform; +} +//choose color temperature, in degrees Kelvin +@property(readwrite, nonatomic) CGFloat temperature; + +//adjust tint to compensate +@property(readwrite, nonatomic) CGFloat tint; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageWhiteBalanceFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageWhiteBalanceFilter.m new file mode 100644 index 00000000..17c9bce9 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageWhiteBalanceFilter.m @@ -0,0 +1,107 @@ +#import "GPUImageWhiteBalanceFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageWhiteBalanceFragmentShaderString = SHADER_STRING +( +uniform sampler2D inputImageTexture; +varying highp vec2 textureCoordinate; + +uniform lowp float temperature; +uniform lowp float tint; + +const lowp vec3 warmFilter = vec3(0.93, 0.54, 0.0); + +const mediump mat3 RGBtoYIQ = mat3(0.299, 0.587, 0.114, 0.596, -0.274, -0.322, 0.212, -0.523, 0.311); +const mediump mat3 YIQtoRGB = mat3(1.0, 0.956, 0.621, 1.0, -0.272, -0.647, 1.0, -1.105, 1.702); + +void main() +{ + lowp vec4 source = texture2D(inputImageTexture, textureCoordinate); + + mediump vec3 yiq = RGBtoYIQ * source.rgb; //adjusting tint + yiq.b = clamp(yiq.b + tint*0.5226*0.1, -0.5226, 0.5226); + lowp vec3 rgb = YIQtoRGB * yiq; + + lowp vec3 processed = vec3( + (rgb.r < 0.5 ? (2.0 * rgb.r * warmFilter.r) : (1.0 - 2.0 * (1.0 - rgb.r) * (1.0 - warmFilter.r))), //adjusting temperature + (rgb.g < 0.5 ? (2.0 * rgb.g * warmFilter.g) : (1.0 - 2.0 * (1.0 - rgb.g) * (1.0 - warmFilter.g))), + (rgb.b < 0.5 ? (2.0 * rgb.b * warmFilter.b) : (1.0 - 2.0 * (1.0 - rgb.b) * (1.0 - warmFilter.b)))); + + gl_FragColor = vec4(mix(rgb, processed, temperature), source.a); +} +); +#else +NSString *const kGPUImageWhiteBalanceFragmentShaderString = SHADER_STRING +( + uniform sampler2D inputImageTexture; + varying vec2 textureCoordinate; + + uniform float temperature; + uniform float tint; + + const vec3 warmFilter = vec3(0.93, 0.54, 0.0); + + const mat3 RGBtoYIQ = mat3(0.299, 0.587, 0.114, 0.596, -0.274, -0.322, 0.212, -0.523, 0.311); + const mat3 YIQtoRGB = mat3(1.0, 0.956, 0.621, 1.0, -0.272, -0.647, 1.0, -1.105, 1.702); + + void main() +{ + vec4 source = texture2D(inputImageTexture, textureCoordinate); + + vec3 yiq = RGBtoYIQ * source.rgb; //adjusting tint + yiq.b = clamp(yiq.b + tint*0.5226*0.1, -0.5226, 0.5226); + vec3 rgb = YIQtoRGB * yiq; + + vec3 processed = vec3( + (rgb.r < 0.5 ? (2.0 * rgb.r * warmFilter.r) : (1.0 - 2.0 * (1.0 - rgb.r) * (1.0 - warmFilter.r))), //adjusting temperature + (rgb.g < 0.5 ? (2.0 * rgb.g * warmFilter.g) : (1.0 - 2.0 * (1.0 - rgb.g) * (1.0 - warmFilter.g))), + (rgb.b < 0.5 ? (2.0 * rgb.b * warmFilter.b) : (1.0 - 2.0 * (1.0 - rgb.b) * (1.0 - warmFilter.b)))); + + gl_FragColor = vec4(mix(rgb, processed, temperature), source.a); +} +); +#endif + +@implementation GPUImageWhiteBalanceFilter + +@synthesize temperature = _temperature; +@synthesize tint = _tint; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageWhiteBalanceFragmentShaderString])) + { + return nil; + } + + temperatureUniform = [filterProgram uniformIndex:@"temperature"]; + tintUniform = [filterProgram uniformIndex:@"tint"]; + + self.temperature = 5000.0; + self.tint = 0.0; + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setTemperature:(CGFloat)newValue; +{ + _temperature = newValue; + + [self setFloat:_temperature < 5000 ? 0.0004 * (_temperature-5000.0) : 0.00006 * (_temperature-5000.0) forUniform:temperatureUniform program:filterProgram]; +} + +- (void)setTint:(CGFloat)newValue; +{ + _tint = newValue; + + [self setFloat:_tint / 100.0 forUniform:tintUniform program:filterProgram]; +} + +@end + diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageXYDerivativeFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageXYDerivativeFilter.h new file mode 100755 index 00000000..8db57457 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageXYDerivativeFilter.h @@ -0,0 +1,5 @@ +#import "GPUImageSobelEdgeDetectionFilter.h" + +@interface GPUImageXYDerivativeFilter : GPUImageSobelEdgeDetectionFilter + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageXYDerivativeFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageXYDerivativeFilter.m new file mode 100755 index 00000000..7e19e9d4 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageXYDerivativeFilter.m @@ -0,0 +1,106 @@ +#import "GPUImageXYDerivativeFilter.h" + +// I'm using the Prewitt operator to obtain the derivative, then squaring the X and Y components and placing the product of the two in Z. +// In tests, Prewitt seemed to be tied with Sobel for the best, and it's just a little cheaper to compute. +// This is primarily intended to be used with corner detection filters. + +@implementation GPUImageXYDerivativeFilter + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageGradientFragmentShaderString = SHADER_STRING +( + precision highp float; + + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform float edgeStrength; + + void main() + { + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + + float verticalDerivative = -topLeftIntensity - topIntensity - topRightIntensity + bottomLeftIntensity + bottomIntensity + bottomRightIntensity; + float horizontalDerivative = -bottomLeftIntensity - leftIntensity - topLeftIntensity + bottomRightIntensity + rightIntensity + topRightIntensity; + verticalDerivative = verticalDerivative * edgeStrength; + horizontalDerivative = horizontalDerivative * edgeStrength; + + // Scaling the X * Y operation so that negative numbers are not clipped in the 0..1 range. This will be expanded in the corner detection filter + gl_FragColor = vec4(horizontalDerivative * horizontalDerivative, verticalDerivative * verticalDerivative, ((verticalDerivative * horizontalDerivative) + 1.0) / 2.0, 1.0); + } +); +#else +NSString *const kGPUImageGradientFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + varying vec2 leftTextureCoordinate; + varying vec2 rightTextureCoordinate; + + varying vec2 topTextureCoordinate; + varying vec2 topLeftTextureCoordinate; + varying vec2 topRightTextureCoordinate; + + varying vec2 bottomTextureCoordinate; + varying vec2 bottomLeftTextureCoordinate; + varying vec2 bottomRightTextureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform float edgeStrength; + + void main() + { + float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r; + float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r; + float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r; + float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r; + float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r; + float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r; + float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r; + float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r; + + float verticalDerivative = -topLeftIntensity - topIntensity - topRightIntensity + bottomLeftIntensity + bottomIntensity + bottomRightIntensity; + float horizontalDerivative = -bottomLeftIntensity - leftIntensity - topLeftIntensity + bottomRightIntensity + rightIntensity + topRightIntensity; + verticalDerivative = verticalDerivative * edgeStrength; + horizontalDerivative = horizontalDerivative * edgeStrength; + + // Scaling the X * Y operation so that negative numbers are not clipped in the 0..1 range. This will be expanded in the corner detection filter + gl_FragColor = vec4(horizontalDerivative * horizontalDerivative, verticalDerivative * verticalDerivative, ((verticalDerivative * horizontalDerivative) + 1.0) / 2.0, 1.0); + } +); +#endif + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [self initWithFragmentShaderFromString:kGPUImageGradientFragmentShaderString])) + { + return nil; + } + + self.edgeStrength = 1.0; + + return self; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageZoomBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageZoomBlurFilter.h new file mode 100644 index 00000000..744a72cb --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageZoomBlurFilter.h @@ -0,0 +1,13 @@ +#import "GPUImageFilter.h" + +@interface GPUImageZoomBlurFilter : GPUImageFilter + +/** A multiplier for the blur size, ranging from 0.0 on up, with a default of 1.0 + */ +@property (readwrite, nonatomic) CGFloat blurSize; + +/** The normalized center of the blur. (0.5, 0.5) by default + */ +@property (readwrite, nonatomic) CGPoint blurCenter; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageZoomBlurFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageZoomBlurFilter.m new file mode 100644 index 00000000..2ae84934 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageZoomBlurFilter.m @@ -0,0 +1,115 @@ +#import "GPUImageZoomBlurFilter.h" + +#if TARGET_IPHONE_SIMULATOR || TARGET_OS_IPHONE +NSString *const kGPUImageZoomBlurFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform highp vec2 blurCenter; + uniform highp float blurSize; + + void main() + { + // TODO: Do a more intelligent scaling based on resolution here + highp vec2 samplingOffset = 1.0/100.0 * (blurCenter - textureCoordinate) * blurSize; + + lowp vec4 fragmentColor = texture2D(inputImageTexture, textureCoordinate) * 0.18; + fragmentColor += texture2D(inputImageTexture, textureCoordinate + samplingOffset) * 0.15; + fragmentColor += texture2D(inputImageTexture, textureCoordinate + (2.0 * samplingOffset)) * 0.12; + fragmentColor += texture2D(inputImageTexture, textureCoordinate + (3.0 * samplingOffset)) * 0.09; + fragmentColor += texture2D(inputImageTexture, textureCoordinate + (4.0 * samplingOffset)) * 0.05; + fragmentColor += texture2D(inputImageTexture, textureCoordinate - samplingOffset) * 0.15; + fragmentColor += texture2D(inputImageTexture, textureCoordinate - (2.0 * samplingOffset)) * 0.12; + fragmentColor += texture2D(inputImageTexture, textureCoordinate - (3.0 * samplingOffset)) * 0.09; + fragmentColor += texture2D(inputImageTexture, textureCoordinate - (4.0 * samplingOffset)) * 0.05; + + gl_FragColor = fragmentColor; + } +); +#else +NSString *const kGPUImageZoomBlurFragmentShaderString = SHADER_STRING +( + varying vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + uniform vec2 blurCenter; + uniform float blurSize; + + void main() + { + // TODO: Do a more intelligent scaling based on resolution here + vec2 samplingOffset = 1.0/100.0 * (blurCenter - textureCoordinate) * blurSize; + + vec4 fragmentColor = texture2D(inputImageTexture, textureCoordinate) * 0.18; + fragmentColor += texture2D(inputImageTexture, textureCoordinate + samplingOffset) * 0.15; + fragmentColor += texture2D(inputImageTexture, textureCoordinate + (2.0 * samplingOffset)) * 0.12; + fragmentColor += texture2D(inputImageTexture, textureCoordinate + (3.0 * samplingOffset)) * 0.09; + fragmentColor += texture2D(inputImageTexture, textureCoordinate + (4.0 * samplingOffset)) * 0.05; + fragmentColor += texture2D(inputImageTexture, textureCoordinate - samplingOffset) * 0.15; + fragmentColor += texture2D(inputImageTexture, textureCoordinate - (2.0 * samplingOffset)) * 0.12; + fragmentColor += texture2D(inputImageTexture, textureCoordinate - (3.0 * samplingOffset)) * 0.09; + fragmentColor += texture2D(inputImageTexture, textureCoordinate - (4.0 * samplingOffset)) * 0.05; + + gl_FragColor = fragmentColor; + } +); +#endif + +@interface GPUImageZoomBlurFilter() +{ + GLint blurSizeUniform, blurCenterUniform; +} +@end + +@implementation GPUImageZoomBlurFilter + +@synthesize blurSize = _blurSize; +@synthesize blurCenter = _blurCenter; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super initWithFragmentShaderFromString:kGPUImageZoomBlurFragmentShaderString])) + { + return nil; + } + + blurSizeUniform = [filterProgram uniformIndex:@"blurSize"]; + blurCenterUniform = [filterProgram uniformIndex:@"blurCenter"]; + + self.blurSize = 1.0; + self.blurCenter = CGPointMake(0.5, 0.5); + + return self; +} + +#pragma mark - +#pragma mark Accessors + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + [super setInputRotation:newInputRotation atIndex:textureIndex]; + [self setBlurCenter:self.blurCenter]; +} + +- (void)setBlurSize:(CGFloat)newValue; +{ + _blurSize = newValue; + + [self setFloat:_blurSize forUniform:blurSizeUniform program:filterProgram]; +} + +- (void)setBlurCenter:(CGPoint)newValue; +{ + _blurCenter = newValue; + + CGPoint rotatedPoint = [self rotatedPoint:_blurCenter forRotation:inputRotation]; + [self setPoint:rotatedPoint forUniform:blurCenterUniform program:filterProgram]; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageiOSBlurFilter.h b/LFLiveKit/Vendor/GPUImage/GPUImageiOSBlurFilter.h new file mode 100644 index 00000000..261d0d7c --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageiOSBlurFilter.h @@ -0,0 +1,31 @@ +#import "GPUImageFilterGroup.h" + +@class GPUImageSaturationFilter; +@class GPUImageGaussianBlurFilter; +@class GPUImageLuminanceRangeFilter; + +@interface GPUImageiOSBlurFilter : GPUImageFilterGroup +{ + GPUImageSaturationFilter *saturationFilter; + GPUImageGaussianBlurFilter *blurFilter; + GPUImageLuminanceRangeFilter *luminanceRangeFilter; +} + +/** A radius in pixels to use for the blur, with a default of 12.0. This adjusts the sigma variable in the Gaussian distribution function. + */ +@property (readwrite, nonatomic) CGFloat blurRadiusInPixels; + +/** Saturation ranges from 0.0 (fully desaturated) to 2.0 (max saturation), with 0.8 as the normal level + */ +@property (readwrite, nonatomic) CGFloat saturation; + +/** The degree to which to downsample, then upsample the incoming image to minimize computations within the Gaussian blur, default of 4.0 + */ +@property (readwrite, nonatomic) CGFloat downsampling; + + +/** The degree to reduce the luminance range, from 0.0 to 1.0. Default is 0.6. + */ +@property (readwrite, nonatomic) CGFloat rangeReductionFactor; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/GPUImageiOSBlurFilter.m b/LFLiveKit/Vendor/GPUImage/GPUImageiOSBlurFilter.m new file mode 100644 index 00000000..18533213 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/GPUImageiOSBlurFilter.m @@ -0,0 +1,114 @@ +#import "GPUImageiOSBlurFilter.h" +#import "GPUImageSaturationFilter.h" +#import "GPUImageGaussianBlurFilter.h" +#import "GPUImageLuminanceRangeFilter.h" + +@implementation GPUImageiOSBlurFilter + +@synthesize blurRadiusInPixels; +@synthesize saturation; +@synthesize downsampling = _downsampling; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + // First pass: downsample and desaturate + saturationFilter = [[GPUImageSaturationFilter alloc] init]; + [self addFilter:saturationFilter]; + + // Second pass: apply a strong Gaussian blur + blurFilter = [[GPUImageGaussianBlurFilter alloc] init]; + [self addFilter:blurFilter]; + + // Third pass: upsample and adjust luminance range + luminanceRangeFilter = [[GPUImageLuminanceRangeFilter alloc] init]; + [self addFilter:luminanceRangeFilter]; + + [saturationFilter addTarget:blurFilter]; + [blurFilter addTarget:luminanceRangeFilter]; + + self.initialFilters = [NSArray arrayWithObject:saturationFilter]; + self.terminalFilter = luminanceRangeFilter; + + self.blurRadiusInPixels = 12.0; + self.saturation = 0.8; + self.downsampling = 4.0; + self.rangeReductionFactor = 0.6; + + return self; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + if (_downsampling > 1.0) + { + CGSize rotatedSize = [saturationFilter rotatedSize:newSize forIndex:textureIndex]; + + [saturationFilter forceProcessingAtSize:CGSizeMake(rotatedSize.width / _downsampling, rotatedSize.height / _downsampling)]; + [luminanceRangeFilter forceProcessingAtSize:rotatedSize]; + } + + [super setInputSize:newSize atIndex:textureIndex]; +} + +#pragma mark - +#pragma mark Accessors + +// From Apple's UIImage+ImageEffects category: + +// A description of how to compute the box kernel width from the Gaussian +// radius (aka standard deviation) appears in the SVG spec: +// http://www.w3.org/TR/SVG/filters.html#feGaussianBlurElement +// +// For larger values of 's' (s >= 2.0), an approximation can be used: Three +// successive box-blurs build a piece-wise quadratic convolution kernel, which +// approximates the Gaussian kernel to within roughly 3%. +// +// let d = floor(s * 3*sqrt(2*pi)/4 + 0.5) +// +// ... if d is odd, use three box-blurs of size 'd', centered on the output pixel. + + +- (void)setBlurRadiusInPixels:(CGFloat)newValue; +{ + blurFilter.blurRadiusInPixels = newValue; +} + +- (CGFloat)blurRadiusInPixels; +{ + return blurFilter.blurRadiusInPixels; +} + +- (void)setSaturation:(CGFloat)newValue; +{ + saturationFilter.saturation = newValue; +} + +- (CGFloat)saturation; +{ + return saturationFilter.saturation; +} + +- (void)setDownsampling:(CGFloat)newValue; +{ + _downsampling = newValue; +} + +- (void)setRangeReductionFactor:(CGFloat)rangeReductionFactor +{ + luminanceRangeFilter.rangeReductionFactor = rangeReductionFactor; +} + +- (CGFloat)rangeReductionFactor +{ + return luminanceRangeFilter.rangeReductionFactor; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/iOS/Framework/GPUImageFramework.h b/LFLiveKit/Vendor/GPUImage/iOS/Framework/GPUImageFramework.h new file mode 100644 index 00000000..3de78bf4 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/iOS/Framework/GPUImageFramework.h @@ -0,0 +1,177 @@ +#import + +//! Project version number for GPUImageFramework. +FOUNDATION_EXPORT double GPUImageFrameworkVersionNumber; + +//! Project version string for GPUImageFramework. +FOUNDATION_EXPORT const unsigned char GPUImageFrameworkVersionString[]; + +#import + +// Base classes +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import + +// Filters +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import diff --git a/LFLiveKit/Vendor/GPUImage/iOS/GPUImageContext.h b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageContext.h new file mode 100755 index 00000000..71142b88 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageContext.h @@ -0,0 +1,64 @@ +#import "GLProgram.h" +#import "GPUImageFramebuffer.h" +#import "GPUImageFramebufferCache.h" + +#define GPUImageRotationSwapsWidthAndHeight(rotation) ((rotation) == kGPUImageRotateLeft || (rotation) == kGPUImageRotateRight || (rotation) == kGPUImageRotateRightFlipVertical || (rotation) == kGPUImageRotateRightFlipHorizontal) + +typedef NS_ENUM(NSUInteger, GPUImageRotationMode) { + kGPUImageNoRotation, + kGPUImageRotateLeft, + kGPUImageRotateRight, + kGPUImageFlipVertical, + kGPUImageFlipHorizonal, + kGPUImageRotateRightFlipVertical, + kGPUImageRotateRightFlipHorizontal, + kGPUImageRotate180 +}; + +@interface GPUImageContext : NSObject + +@property(readonly, nonatomic) dispatch_queue_t contextQueue; +@property(readwrite, retain, nonatomic) GLProgram *currentShaderProgram; +@property(readonly, retain, nonatomic) EAGLContext *context; +@property(readonly) CVOpenGLESTextureCacheRef coreVideoTextureCache; +@property(readonly) GPUImageFramebufferCache *framebufferCache; + ++ (void *)contextKey; ++ (GPUImageContext *)sharedImageProcessingContext; ++ (dispatch_queue_t)sharedContextQueue; ++ (GPUImageFramebufferCache *)sharedFramebufferCache; ++ (void)useImageProcessingContext; +- (void)useAsCurrentContext; ++ (void)setActiveShaderProgram:(GLProgram *)shaderProgram; +- (void)setContextShaderProgram:(GLProgram *)shaderProgram; ++ (GLint)maximumTextureSizeForThisDevice; ++ (GLint)maximumTextureUnitsForThisDevice; ++ (GLint)maximumVaryingVectorsForThisDevice; ++ (BOOL)deviceSupportsOpenGLESExtension:(NSString *)extension; ++ (BOOL)deviceSupportsRedTextures; ++ (BOOL)deviceSupportsFramebufferReads; ++ (CGSize)sizeThatFitsWithinATextureForSize:(CGSize)inputSize; + +- (void)presentBufferForDisplay; +- (GLProgram *)programForVertexShaderString:(NSString *)vertexShaderString fragmentShaderString:(NSString *)fragmentShaderString; + +- (void)useSharegroup:(EAGLSharegroup *)sharegroup; + +// Manage fast texture upload ++ (BOOL)supportsFastTextureUpload; + +@end + +@protocol GPUImageInput +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +- (void)setInputFramebuffer:(GPUImageFramebuffer *)newInputFramebuffer atIndex:(NSInteger)textureIndex; +- (NSInteger)nextAvailableTextureIndex; +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +- (CGSize)maximumOutputSize; +- (void)endProcessing; +- (BOOL)shouldIgnoreUpdatesToThisTarget; +- (BOOL)enabled; +- (BOOL)wantsMonochromeInput; +- (void)setCurrentlyReceivingMonochromeInput:(BOOL)newValue; +@end diff --git a/LFLiveKit/Vendor/GPUImage/iOS/GPUImageContext.m b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageContext.m new file mode 100755 index 00000000..c167d15d --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageContext.m @@ -0,0 +1,320 @@ +#import "GPUImageContext.h" +#import +#import + +#define MAXSHADERPROGRAMSALLOWEDINCACHE 40 + +extern dispatch_queue_attr_t GPUImageDefaultQueueAttribute(void); + +@interface GPUImageContext() +{ + NSMutableDictionary *shaderProgramCache; + NSMutableArray *shaderProgramUsageHistory; + EAGLSharegroup *_sharegroup; +} + +@end + +@implementation GPUImageContext + +@synthesize context = _context; +@synthesize currentShaderProgram = _currentShaderProgram; +@synthesize contextQueue = _contextQueue; +@synthesize coreVideoTextureCache = _coreVideoTextureCache; +@synthesize framebufferCache = _framebufferCache; + +static void *openGLESContextQueueKey; + +- (id)init; +{ + if (!(self = [super init])) + { + return nil; + } + + openGLESContextQueueKey = &openGLESContextQueueKey; + _contextQueue = dispatch_queue_create("com.sunsetlakesoftware.GPUImage.openGLESContextQueue", GPUImageDefaultQueueAttribute()); + +#if OS_OBJECT_USE_OBJC + dispatch_queue_set_specific(_contextQueue, openGLESContextQueueKey, (__bridge void *)self, NULL); +#endif + shaderProgramCache = [[NSMutableDictionary alloc] init]; + shaderProgramUsageHistory = [[NSMutableArray alloc] init]; + + return self; +} + ++ (void *)contextKey { + return openGLESContextQueueKey; +} + +// Based on Colin Wheeler's example here: http://cocoasamurai.blogspot.com/2011/04/singletons-your-doing-them-wrong.html ++ (GPUImageContext *)sharedImageProcessingContext; +{ + static dispatch_once_t pred; + static GPUImageContext *sharedImageProcessingContext = nil; + + dispatch_once(&pred, ^{ + sharedImageProcessingContext = [[[self class] alloc] init]; + }); + return sharedImageProcessingContext; +} + ++ (dispatch_queue_t)sharedContextQueue; +{ + return [[self sharedImageProcessingContext] contextQueue]; +} + ++ (GPUImageFramebufferCache *)sharedFramebufferCache; +{ + return [[self sharedImageProcessingContext] framebufferCache]; +} + ++ (void)useImageProcessingContext; +{ + [[GPUImageContext sharedImageProcessingContext] useAsCurrentContext]; +} + +- (void)useAsCurrentContext; +{ + EAGLContext *imageProcessingContext = [self context]; + if ([EAGLContext currentContext] != imageProcessingContext) + { + [EAGLContext setCurrentContext:imageProcessingContext]; + } +} + ++ (void)setActiveShaderProgram:(GLProgram *)shaderProgram; +{ + GPUImageContext *sharedContext = [GPUImageContext sharedImageProcessingContext]; + [sharedContext setContextShaderProgram:shaderProgram]; +} + +- (void)setContextShaderProgram:(GLProgram *)shaderProgram; +{ + EAGLContext *imageProcessingContext = [self context]; + if ([EAGLContext currentContext] != imageProcessingContext) + { + [EAGLContext setCurrentContext:imageProcessingContext]; + } + + if (self.currentShaderProgram != shaderProgram) + { + self.currentShaderProgram = shaderProgram; + [shaderProgram use]; + } +} + ++ (GLint)maximumTextureSizeForThisDevice; +{ + static dispatch_once_t pred; + static GLint maxTextureSize = 0; + + dispatch_once(&pred, ^{ + [self useImageProcessingContext]; + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTextureSize); + }); + + return maxTextureSize; +} + ++ (GLint)maximumTextureUnitsForThisDevice; +{ + static dispatch_once_t pred; + static GLint maxTextureUnits = 0; + + dispatch_once(&pred, ^{ + [self useImageProcessingContext]; + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); + }); + + return maxTextureUnits; +} + ++ (GLint)maximumVaryingVectorsForThisDevice; +{ + static dispatch_once_t pred; + static GLint maxVaryingVectors = 0; + + dispatch_once(&pred, ^{ + [self useImageProcessingContext]; + glGetIntegerv(GL_MAX_VARYING_VECTORS, &maxVaryingVectors); + }); + + return maxVaryingVectors; +} + ++ (BOOL)deviceSupportsOpenGLESExtension:(NSString *)extension; +{ + static dispatch_once_t pred; + static NSArray *extensionNames = nil; + + // Cache extensions for later quick reference, since this won't change for a given device + dispatch_once(&pred, ^{ + [GPUImageContext useImageProcessingContext]; + NSString *extensionsString = [NSString stringWithCString:(const char *)glGetString(GL_EXTENSIONS) encoding:NSASCIIStringEncoding]; + extensionNames = [extensionsString componentsSeparatedByString:@" "]; + }); + + return [extensionNames containsObject:extension]; +} + + +// http://www.khronos.org/registry/gles/extensions/EXT/EXT_texture_rg.txt + ++ (BOOL)deviceSupportsRedTextures; +{ + static dispatch_once_t pred; + static BOOL supportsRedTextures = NO; + + dispatch_once(&pred, ^{ + supportsRedTextures = [GPUImageContext deviceSupportsOpenGLESExtension:@"GL_EXT_texture_rg"]; + }); + + return supportsRedTextures; +} + ++ (BOOL)deviceSupportsFramebufferReads; +{ + static dispatch_once_t pred; + static BOOL supportsFramebufferReads = NO; + + dispatch_once(&pred, ^{ + supportsFramebufferReads = [GPUImageContext deviceSupportsOpenGLESExtension:@"GL_EXT_shader_framebuffer_fetch"]; + }); + + return supportsFramebufferReads; +} + ++ (CGSize)sizeThatFitsWithinATextureForSize:(CGSize)inputSize; +{ + GLint maxTextureSize = [self maximumTextureSizeForThisDevice]; + if ( (inputSize.width < maxTextureSize) && (inputSize.height < maxTextureSize) ) + { + return inputSize; + } + + CGSize adjustedSize; + if (inputSize.width > inputSize.height) + { + adjustedSize.width = (CGFloat)maxTextureSize; + adjustedSize.height = ((CGFloat)maxTextureSize / inputSize.width) * inputSize.height; + } + else + { + adjustedSize.height = (CGFloat)maxTextureSize; + adjustedSize.width = ((CGFloat)maxTextureSize / inputSize.height) * inputSize.width; + } + + return adjustedSize; +} + +- (void)presentBufferForDisplay; +{ + [self.context presentRenderbuffer:GL_RENDERBUFFER]; +} + +- (GLProgram *)programForVertexShaderString:(NSString *)vertexShaderString fragmentShaderString:(NSString *)fragmentShaderString; +{ + NSString *lookupKeyForShaderProgram = [NSString stringWithFormat:@"V: %@ - F: %@", vertexShaderString, fragmentShaderString]; + GLProgram *programFromCache = [shaderProgramCache objectForKey:lookupKeyForShaderProgram]; + + if (programFromCache == nil) + { + programFromCache = [[GLProgram alloc] initWithVertexShaderString:vertexShaderString fragmentShaderString:fragmentShaderString]; + [shaderProgramCache setObject:programFromCache forKey:lookupKeyForShaderProgram]; +// [shaderProgramUsageHistory addObject:lookupKeyForShaderProgram]; +// if ([shaderProgramUsageHistory count] >= MAXSHADERPROGRAMSALLOWEDINCACHE) +// { +// for (NSUInteger currentShaderProgramRemovedFromCache = 0; currentShaderProgramRemovedFromCache < 10; currentShaderProgramRemovedFromCache++) +// { +// NSString *shaderProgramToRemoveFromCache = [shaderProgramUsageHistory objectAtIndex:0]; +// [shaderProgramUsageHistory removeObjectAtIndex:0]; +// [shaderProgramCache removeObjectForKey:shaderProgramToRemoveFromCache]; +// } +// } + } + + return programFromCache; +} + +- (void)useSharegroup:(EAGLSharegroup *)sharegroup; +{ + NSAssert(_context == nil, @"Unable to use a share group when the context has already been created. Call this method before you use the context for the first time."); + + _sharegroup = sharegroup; +} + +- (EAGLContext *)createContext; +{ + EAGLContext *context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2 sharegroup:_sharegroup]; + NSAssert(context != nil, @"Unable to create an OpenGL ES 2.0 context. The GPUImage framework requires OpenGL ES 2.0 support to work."); + return context; +} + + +#pragma mark - +#pragma mark Manage fast texture upload + ++ (BOOL)supportsFastTextureUpload; +{ +#if TARGET_IPHONE_SIMULATOR + return NO; +#else + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wtautological-pointer-compare" + return (CVOpenGLESTextureCacheCreate != NULL); +#pragma clang diagnostic pop + +#endif +} + +#pragma mark - +#pragma mark Accessors + +- (EAGLContext *)context; +{ + if (_context == nil) + { + _context = [self createContext]; + [EAGLContext setCurrentContext:_context]; + + // Set up a few global settings for the image processing pipeline + glDisable(GL_DEPTH_TEST); + } + + return _context; +} + +- (CVOpenGLESTextureCacheRef)coreVideoTextureCache; +{ + if (_coreVideoTextureCache == NULL) + { +#if defined(__IPHONE_6_0) + CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, [self context], NULL, &_coreVideoTextureCache); +#else + CVReturn err = CVOpenGLESTextureCacheCreate(kCFAllocatorDefault, NULL, (__bridge void *)[self context], NULL, &_coreVideoTextureCache); +#endif + + if (err) + { + NSAssert(NO, @"Error at CVOpenGLESTextureCacheCreate %d", err); + } + + } + + return _coreVideoTextureCache; +} + +- (GPUImageFramebufferCache *)framebufferCache; +{ + if (_framebufferCache == nil) + { + _framebufferCache = [[GPUImageFramebufferCache alloc] init]; + } + + return _framebufferCache; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/iOS/GPUImageMovieWriter.h b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageMovieWriter.h new file mode 100755 index 00000000..f0b2c6ad --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageMovieWriter.h @@ -0,0 +1,67 @@ +#import +#import +#import "GPUImageContext.h" + +extern NSString *const kGPUImageColorSwizzlingFragmentShaderString; + +@protocol GPUImageMovieWriterDelegate + +@optional +- (void)movieRecordingCompleted; +- (void)movieRecordingFailedWithError:(NSError*)error; + +@end + +@interface GPUImageMovieWriter : NSObject +{ + BOOL alreadyFinishedRecording; + + NSURL *movieURL; + NSString *fileType; + AVAssetWriter *assetWriter; + AVAssetWriterInput *assetWriterAudioInput; + AVAssetWriterInput *assetWriterVideoInput; + AVAssetWriterInputPixelBufferAdaptor *assetWriterPixelBufferInput; + + GPUImageContext *_movieWriterContext; + CVPixelBufferRef renderTarget; + CVOpenGLESTextureRef renderTexture; + + CGSize videoSize; + GPUImageRotationMode inputRotation; +} + +@property(readwrite, nonatomic) BOOL hasAudioTrack; +@property(readwrite, nonatomic) BOOL shouldPassthroughAudio; +@property(readwrite, nonatomic) BOOL shouldInvalidateAudioSampleWhenDone; +@property(nonatomic, copy) void(^completionBlock)(void); +@property(nonatomic, copy) void(^failureBlock)(NSError*); +@property(nonatomic, assign) id delegate; +@property(readwrite, nonatomic) BOOL encodingLiveVideo; +@property(nonatomic, copy) BOOL(^videoInputReadyCallback)(void); +@property(nonatomic, copy) BOOL(^audioInputReadyCallback)(void); +@property(nonatomic, copy) void(^audioProcessingCallback)(SInt16 **samplesRef, CMItemCount numSamplesInBuffer); +@property(nonatomic) BOOL enabled; +@property(nonatomic, readonly) AVAssetWriter *assetWriter; +@property(nonatomic, readonly) CMTime duration; +@property(nonatomic, assign) CGAffineTransform transform; +@property(nonatomic, copy) NSArray *metaData; +@property(nonatomic, assign, getter = isPaused) BOOL paused; +@property(nonatomic, retain) GPUImageContext *movieWriterContext; + +// Initialization and teardown +- (id)initWithMovieURL:(NSURL *)newMovieURL size:(CGSize)newSize; +- (id)initWithMovieURL:(NSURL *)newMovieURL size:(CGSize)newSize fileType:(NSString *)newFileType outputSettings:(NSDictionary *)outputSettings; + +- (void)setHasAudioTrack:(BOOL)hasAudioTrack audioSettings:(NSDictionary *)audioOutputSettings; + +// Movie recording +- (void)startRecording; +- (void)startRecordingInOrientation:(CGAffineTransform)orientationTransform; +- (void)finishRecording; +- (void)finishRecordingWithCompletionHandler:(void (^)(void))handler; +- (void)cancelRecording; +- (void)processAudioBuffer:(CMSampleBufferRef)audioBuffer; +- (void)enableSynchronizationCallbacks; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/iOS/GPUImageMovieWriter.m b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageMovieWriter.m new file mode 100755 index 00000000..addc0a79 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageMovieWriter.m @@ -0,0 +1,1016 @@ +#import "GPUImageMovieWriter.h" + +#import "GPUImageContext.h" +#import "GLProgram.h" +#import "GPUImageFilter.h" + +NSString *const kGPUImageColorSwizzlingFragmentShaderString = SHADER_STRING +( + varying highp vec2 textureCoordinate; + + uniform sampler2D inputImageTexture; + + void main() + { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate).bgra; + } +); + + +@interface GPUImageMovieWriter () +{ + GLuint movieFramebuffer, movieRenderbuffer; + + GLProgram *colorSwizzlingProgram; + GLint colorSwizzlingPositionAttribute, colorSwizzlingTextureCoordinateAttribute; + GLint colorSwizzlingInputTextureUniform; + + GPUImageFramebuffer *firstInputFramebuffer; + + BOOL discont; + CMTime startTime, previousFrameTime, previousAudioTime; + CMTime offsetTime; + + dispatch_queue_t audioQueue, videoQueue; + BOOL audioEncodingIsFinished, videoEncodingIsFinished; + + BOOL isRecording; +} + +// Movie recording +- (void)initializeMovieWithOutputSettings:(NSMutableDictionary *)outputSettings; + +// Frame rendering +- (void)createDataFBO; +- (void)destroyDataFBO; +- (void)setFilterFBO; + +- (void)renderAtInternalSizeUsingFramebuffer:(GPUImageFramebuffer *)inputFramebufferToUse; + +@end + +@implementation GPUImageMovieWriter + +@synthesize hasAudioTrack = _hasAudioTrack; +@synthesize encodingLiveVideo = _encodingLiveVideo; +@synthesize shouldPassthroughAudio = _shouldPassthroughAudio; +@synthesize completionBlock; +@synthesize failureBlock; +@synthesize videoInputReadyCallback; +@synthesize audioInputReadyCallback; +@synthesize enabled; +@synthesize shouldInvalidateAudioSampleWhenDone = _shouldInvalidateAudioSampleWhenDone; +@synthesize paused = _paused; +@synthesize movieWriterContext = _movieWriterContext; + +@synthesize delegate = _delegate; + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithMovieURL:(NSURL *)newMovieURL size:(CGSize)newSize; +{ + return [self initWithMovieURL:newMovieURL size:newSize fileType:AVFileTypeQuickTimeMovie outputSettings:nil]; +} + +- (id)initWithMovieURL:(NSURL *)newMovieURL size:(CGSize)newSize fileType:(NSString *)newFileType outputSettings:(NSMutableDictionary *)outputSettings; +{ + if (!(self = [super init])) + { + return nil; + } + + _shouldInvalidateAudioSampleWhenDone = NO; + + self.enabled = YES; + alreadyFinishedRecording = NO; + videoEncodingIsFinished = NO; + audioEncodingIsFinished = NO; + + discont = NO; + videoSize = newSize; + movieURL = newMovieURL; + fileType = newFileType; + startTime = kCMTimeInvalid; + _encodingLiveVideo = [[outputSettings objectForKey:@"EncodingLiveVideo"] isKindOfClass:[NSNumber class]] ? [[outputSettings objectForKey:@"EncodingLiveVideo"] boolValue] : YES; + previousFrameTime = kCMTimeNegativeInfinity; + previousAudioTime = kCMTimeNegativeInfinity; + inputRotation = kGPUImageNoRotation; + + _movieWriterContext = [[GPUImageContext alloc] init]; + [_movieWriterContext useSharegroup:[[[GPUImageContext sharedImageProcessingContext] context] sharegroup]]; + + runSynchronouslyOnContextQueue(_movieWriterContext, ^{ + [_movieWriterContext useAsCurrentContext]; + + if ([GPUImageContext supportsFastTextureUpload]) + { + colorSwizzlingProgram = [_movieWriterContext programForVertexShaderString:kGPUImageVertexShaderString fragmentShaderString:kGPUImagePassthroughFragmentShaderString]; + } + else + { + colorSwizzlingProgram = [_movieWriterContext programForVertexShaderString:kGPUImageVertexShaderString fragmentShaderString:kGPUImageColorSwizzlingFragmentShaderString]; + } + + if (!colorSwizzlingProgram.initialized) + { + [colorSwizzlingProgram addAttribute:@"position"]; + [colorSwizzlingProgram addAttribute:@"inputTextureCoordinate"]; + + if (![colorSwizzlingProgram link]) + { + NSString *progLog = [colorSwizzlingProgram programLog]; + NSLog(@"Program link log: %@", progLog); + NSString *fragLog = [colorSwizzlingProgram fragmentShaderLog]; + NSLog(@"Fragment shader compile log: %@", fragLog); + NSString *vertLog = [colorSwizzlingProgram vertexShaderLog]; + NSLog(@"Vertex shader compile log: %@", vertLog); + colorSwizzlingProgram = nil; + NSAssert(NO, @"Filter shader link failed"); + } + } + + colorSwizzlingPositionAttribute = [colorSwizzlingProgram attributeIndex:@"position"]; + colorSwizzlingTextureCoordinateAttribute = [colorSwizzlingProgram attributeIndex:@"inputTextureCoordinate"]; + colorSwizzlingInputTextureUniform = [colorSwizzlingProgram uniformIndex:@"inputImageTexture"]; + + [_movieWriterContext setContextShaderProgram:colorSwizzlingProgram]; + + glEnableVertexAttribArray(colorSwizzlingPositionAttribute); + glEnableVertexAttribArray(colorSwizzlingTextureCoordinateAttribute); + }); + + [self initializeMovieWithOutputSettings:outputSettings]; + + return self; +} + +- (void)dealloc; +{ + [self destroyDataFBO]; + +#if !OS_OBJECT_USE_OBJC + if( audioQueue != NULL ) + { + dispatch_release(audioQueue); + } + if( videoQueue != NULL ) + { + dispatch_release(videoQueue); + } +#endif +} + +#pragma mark - +#pragma mark Movie recording + +- (void)initializeMovieWithOutputSettings:(NSDictionary *)outputSettings; +{ + isRecording = NO; + + self.enabled = YES; + NSError *error = nil; + assetWriter = [[AVAssetWriter alloc] initWithURL:movieURL fileType:fileType error:&error]; + if (error != nil) + { + NSLog(@"Error: %@", error); + if (failureBlock) + { + failureBlock(error); + } + else + { + if(self.delegate && [self.delegate respondsToSelector:@selector(movieRecordingFailedWithError:)]) + { + [self.delegate movieRecordingFailedWithError:error]; + } + } + } + + // Set this to make sure that a functional movie is produced, even if the recording is cut off mid-stream. Only the last second should be lost in that case. + assetWriter.movieFragmentInterval = CMTimeMakeWithSeconds(1.0, 1000); + + // use default output settings if none specified + if (outputSettings == nil) + { + NSMutableDictionary *settings = [[NSMutableDictionary alloc] init]; + [settings setObject:AVVideoCodecH264 forKey:AVVideoCodecKey]; + [settings setObject:[NSNumber numberWithInt:videoSize.width] forKey:AVVideoWidthKey]; + [settings setObject:[NSNumber numberWithInt:videoSize.height] forKey:AVVideoHeightKey]; + outputSettings = settings; + } + // custom output settings specified + else + { + __unused NSString *videoCodec = [outputSettings objectForKey:AVVideoCodecKey]; + __unused NSNumber *width = [outputSettings objectForKey:AVVideoWidthKey]; + __unused NSNumber *height = [outputSettings objectForKey:AVVideoHeightKey]; + + NSAssert(videoCodec && width && height, @"OutputSettings is missing required parameters."); + + if( [outputSettings objectForKey:@"EncodingLiveVideo"] ) { + NSMutableDictionary *tmp = [outputSettings mutableCopy]; + [tmp removeObjectForKey:@"EncodingLiveVideo"]; + outputSettings = tmp; + } + } + + /* + NSDictionary *videoCleanApertureSettings = [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithInt:videoSize.width], AVVideoCleanApertureWidthKey, + [NSNumber numberWithInt:videoSize.height], AVVideoCleanApertureHeightKey, + [NSNumber numberWithInt:0], AVVideoCleanApertureHorizontalOffsetKey, + [NSNumber numberWithInt:0], AVVideoCleanApertureVerticalOffsetKey, + nil]; + + NSDictionary *videoAspectRatioSettings = [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithInt:3], AVVideoPixelAspectRatioHorizontalSpacingKey, + [NSNumber numberWithInt:3], AVVideoPixelAspectRatioVerticalSpacingKey, + nil]; + + NSMutableDictionary * compressionProperties = [[NSMutableDictionary alloc] init]; + [compressionProperties setObject:videoCleanApertureSettings forKey:AVVideoCleanApertureKey]; + [compressionProperties setObject:videoAspectRatioSettings forKey:AVVideoPixelAspectRatioKey]; + [compressionProperties setObject:[NSNumber numberWithInt: 2000000] forKey:AVVideoAverageBitRateKey]; + [compressionProperties setObject:[NSNumber numberWithInt: 16] forKey:AVVideoMaxKeyFrameIntervalKey]; + [compressionProperties setObject:AVVideoProfileLevelH264Main31 forKey:AVVideoProfileLevelKey]; + + [outputSettings setObject:compressionProperties forKey:AVVideoCompressionPropertiesKey]; + */ + + assetWriterVideoInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:outputSettings]; + assetWriterVideoInput.expectsMediaDataInRealTime = _encodingLiveVideo; + + // You need to use BGRA for the video in order to get realtime encoding. I use a color-swizzling shader to line up glReadPixels' normal RGBA output with the movie input's BGRA. + NSDictionary *sourcePixelBufferAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey, + [NSNumber numberWithInt:videoSize.width], kCVPixelBufferWidthKey, + [NSNumber numberWithInt:videoSize.height], kCVPixelBufferHeightKey, + nil]; +// NSDictionary *sourcePixelBufferAttributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:kCVPixelFormatType_32ARGB], kCVPixelBufferPixelFormatTypeKey, +// nil]; + + assetWriterPixelBufferInput = [AVAssetWriterInputPixelBufferAdaptor assetWriterInputPixelBufferAdaptorWithAssetWriterInput:assetWriterVideoInput sourcePixelBufferAttributes:sourcePixelBufferAttributesDictionary]; + + [assetWriter addInput:assetWriterVideoInput]; +} + +- (void)setEncodingLiveVideo:(BOOL) value +{ + _encodingLiveVideo = value; + if (isRecording) { + NSAssert(NO, @"Can not change Encoding Live Video while recording"); + } + else + { + assetWriterVideoInput.expectsMediaDataInRealTime = _encodingLiveVideo; + assetWriterAudioInput.expectsMediaDataInRealTime = _encodingLiveVideo; + } +} + +- (void)startRecording; +{ + alreadyFinishedRecording = NO; + startTime = kCMTimeInvalid; + runSynchronouslyOnContextQueue(_movieWriterContext, ^{ + if (audioInputReadyCallback == NULL) + { + [assetWriter startWriting]; + } + }); + isRecording = YES; + // [assetWriter startSessionAtSourceTime:kCMTimeZero]; +} + +- (void)startRecordingInOrientation:(CGAffineTransform)orientationTransform; +{ + assetWriterVideoInput.transform = orientationTransform; + + [self startRecording]; +} + +- (void)cancelRecording; +{ + if (assetWriter.status == AVAssetWriterStatusCompleted) + { + return; + } + + isRecording = NO; + runSynchronouslyOnContextQueue(_movieWriterContext, ^{ + alreadyFinishedRecording = YES; + + if( assetWriter.status == AVAssetWriterStatusWriting && ! videoEncodingIsFinished ) + { + videoEncodingIsFinished = YES; + [assetWriterVideoInput markAsFinished]; + } + if( assetWriter.status == AVAssetWriterStatusWriting && ! audioEncodingIsFinished ) + { + audioEncodingIsFinished = YES; + [assetWriterAudioInput markAsFinished]; + } + [assetWriter cancelWriting]; + }); +} + +- (void)finishRecording; +{ + [self finishRecordingWithCompletionHandler:NULL]; +} + +- (void)finishRecordingWithCompletionHandler:(void (^)(void))handler; +{ + runSynchronouslyOnContextQueue(_movieWriterContext, ^{ + isRecording = NO; + + if (assetWriter.status == AVAssetWriterStatusCompleted || assetWriter.status == AVAssetWriterStatusCancelled || assetWriter.status == AVAssetWriterStatusUnknown) + { + if (handler) + runAsynchronouslyOnContextQueue(_movieWriterContext, handler); + return; + } + if( assetWriter.status == AVAssetWriterStatusWriting && ! videoEncodingIsFinished ) + { + videoEncodingIsFinished = YES; + [assetWriterVideoInput markAsFinished]; + } + if( assetWriter.status == AVAssetWriterStatusWriting && ! audioEncodingIsFinished ) + { + audioEncodingIsFinished = YES; + [assetWriterAudioInput markAsFinished]; + } +#if (!defined(__IPHONE_6_0) || (__IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_6_0)) + // Not iOS 6 SDK + [assetWriter finishWriting]; + if (handler) + runAsynchronouslyOnContextQueue(_movieWriterContext,handler); +#else + // iOS 6 SDK + if ([assetWriter respondsToSelector:@selector(finishWritingWithCompletionHandler:)]) { + // Running iOS 6 + [assetWriter finishWritingWithCompletionHandler:(handler ?: ^{ })]; + } + else { + // Not running iOS 6 +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + [assetWriter finishWriting]; +#pragma clang diagnostic pop + if (handler) + runAsynchronouslyOnContextQueue(_movieWriterContext, handler); + } +#endif + }); +} + +- (void)processAudioBuffer:(CMSampleBufferRef)audioBuffer; +{ + if (!isRecording || _paused) + { + return; + } + +// if (_hasAudioTrack && CMTIME_IS_VALID(startTime)) + if (_hasAudioTrack) + { + CFRetain(audioBuffer); + + CMTime currentSampleTime = CMSampleBufferGetOutputPresentationTimeStamp(audioBuffer); + + if (CMTIME_IS_INVALID(startTime)) + { + runSynchronouslyOnContextQueue(_movieWriterContext, ^{ + if ((audioInputReadyCallback == NULL) && (assetWriter.status != AVAssetWriterStatusWriting)) + { + [assetWriter startWriting]; + } + [assetWriter startSessionAtSourceTime:currentSampleTime]; + startTime = currentSampleTime; + }); + } + + if (!assetWriterAudioInput.readyForMoreMediaData && _encodingLiveVideo) + { + NSLog(@"1: Had to drop an audio frame: %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, currentSampleTime))); + if (_shouldInvalidateAudioSampleWhenDone) + { + CMSampleBufferInvalidate(audioBuffer); + } + CFRelease(audioBuffer); + return; + } + + if (discont) { + discont = NO; + + CMTime current; + if (offsetTime.value > 0) { + current = CMTimeSubtract(currentSampleTime, offsetTime); + } else { + current = currentSampleTime; + } + + CMTime offset = CMTimeSubtract(current, previousAudioTime); + + if (offsetTime.value == 0) { + offsetTime = offset; + } else { + offsetTime = CMTimeAdd(offsetTime, offset); + } + } + + if (offsetTime.value > 0) { + CFRelease(audioBuffer); + audioBuffer = [self adjustTime:audioBuffer by:offsetTime]; + CFRetain(audioBuffer); + } + + // record most recent time so we know the length of the pause + currentSampleTime = CMSampleBufferGetPresentationTimeStamp(audioBuffer); + + previousAudioTime = currentSampleTime; + + //if the consumer wants to do something with the audio samples before writing, let him. + if (self.audioProcessingCallback) { + //need to introspect into the opaque CMBlockBuffer structure to find its raw sample buffers. + CMBlockBufferRef buffer = CMSampleBufferGetDataBuffer(audioBuffer); + CMItemCount numSamplesInBuffer = CMSampleBufferGetNumSamples(audioBuffer); + AudioBufferList audioBufferList; + + CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(audioBuffer, + NULL, + &audioBufferList, + sizeof(audioBufferList), + NULL, + NULL, + kCMSampleBufferFlag_AudioBufferList_Assure16ByteAlignment, + &buffer + ); + //passing a live pointer to the audio buffers, try to process them in-place or we might have syncing issues. + for (int bufferCount=0; bufferCount < audioBufferList.mNumberBuffers; bufferCount++) { + SInt16 *samples = (SInt16 *)audioBufferList.mBuffers[bufferCount].mData; + self.audioProcessingCallback(&samples, numSamplesInBuffer); + } + } + +// NSLog(@"Recorded audio sample time: %lld, %d, %lld", currentSampleTime.value, currentSampleTime.timescale, currentSampleTime.epoch); + void(^write)() = ^() { + while( ! assetWriterAudioInput.readyForMoreMediaData && ! _encodingLiveVideo && ! audioEncodingIsFinished ) { + NSDate *maxDate = [NSDate dateWithTimeIntervalSinceNow:0.5]; + //NSLog(@"audio waiting..."); + [[NSRunLoop currentRunLoop] runUntilDate:maxDate]; + } + if (!assetWriterAudioInput.readyForMoreMediaData) + { + NSLog(@"2: Had to drop an audio frame %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, currentSampleTime))); + } + else if(assetWriter.status == AVAssetWriterStatusWriting) + { + if (![assetWriterAudioInput appendSampleBuffer:audioBuffer]) + NSLog(@"Problem appending audio buffer at time: %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, currentSampleTime))); + } + else + { + //NSLog(@"Wrote an audio frame %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, currentSampleTime))); + } + + if (_shouldInvalidateAudioSampleWhenDone) + { + CMSampleBufferInvalidate(audioBuffer); + } + CFRelease(audioBuffer); + }; +// runAsynchronouslyOnContextQueue(_movieWriterContext, write); + if( _encodingLiveVideo ) + + { + runAsynchronouslyOnContextQueue(_movieWriterContext, write); + } + else + { + write(); + } + } +} + +- (void)enableSynchronizationCallbacks; +{ + if (videoInputReadyCallback != NULL) + { + if( assetWriter.status != AVAssetWriterStatusWriting ) + { + [assetWriter startWriting]; + } + videoQueue = dispatch_queue_create("com.sunsetlakesoftware.GPUImage.videoReadingQueue", GPUImageDefaultQueueAttribute()); + [assetWriterVideoInput requestMediaDataWhenReadyOnQueue:videoQueue usingBlock:^{ + if( _paused ) + { + //NSLog(@"video requestMediaDataWhenReadyOnQueue paused"); + // if we don't sleep, we'll get called back almost immediately, chewing up CPU + usleep(10000); + return; + } + //NSLog(@"video requestMediaDataWhenReadyOnQueue begin"); + while( assetWriterVideoInput.readyForMoreMediaData && ! _paused ) + { + if( videoInputReadyCallback && ! videoInputReadyCallback() && ! videoEncodingIsFinished ) + { + runAsynchronouslyOnContextQueue(_movieWriterContext, ^{ + if( assetWriter.status == AVAssetWriterStatusWriting && ! videoEncodingIsFinished ) + { + videoEncodingIsFinished = YES; + [assetWriterVideoInput markAsFinished]; + } + }); + } + } + //NSLog(@"video requestMediaDataWhenReadyOnQueue end"); + }]; + } + + if (audioInputReadyCallback != NULL) + { + audioQueue = dispatch_queue_create("com.sunsetlakesoftware.GPUImage.audioReadingQueue", GPUImageDefaultQueueAttribute()); + [assetWriterAudioInput requestMediaDataWhenReadyOnQueue:audioQueue usingBlock:^{ + if( _paused ) + { + //NSLog(@"audio requestMediaDataWhenReadyOnQueue paused"); + // if we don't sleep, we'll get called back almost immediately, chewing up CPU + usleep(10000); + return; + } + //NSLog(@"audio requestMediaDataWhenReadyOnQueue begin"); + while( assetWriterAudioInput.readyForMoreMediaData && ! _paused ) + { + if( audioInputReadyCallback && ! audioInputReadyCallback() && ! audioEncodingIsFinished ) + { + runAsynchronouslyOnContextQueue(_movieWriterContext, ^{ + if( assetWriter.status == AVAssetWriterStatusWriting && ! audioEncodingIsFinished ) + { + audioEncodingIsFinished = YES; + [assetWriterAudioInput markAsFinished]; + } + }); + } + } + //NSLog(@"audio requestMediaDataWhenReadyOnQueue end"); + }]; + } + +} + +#pragma mark - +#pragma mark Frame rendering + +- (void)createDataFBO; +{ + glActiveTexture(GL_TEXTURE1); + glGenFramebuffers(1, &movieFramebuffer); + glBindFramebuffer(GL_FRAMEBUFFER, movieFramebuffer); + + if ([GPUImageContext supportsFastTextureUpload]) + { + // Code originally sourced from http://allmybrain.com/2011/12/08/rendering-to-a-texture-with-ios-5-texture-cache-api/ + + + CVPixelBufferPoolCreatePixelBuffer (NULL, [assetWriterPixelBufferInput pixelBufferPool], &renderTarget); + + /* AVAssetWriter will use BT.601 conversion matrix for RGB to YCbCr conversion + * regardless of the kCVImageBufferYCbCrMatrixKey value. + * Tagging the resulting video file as BT.601, is the best option right now. + * Creating a proper BT.709 video is not possible at the moment. + */ + CVBufferSetAttachment(renderTarget, kCVImageBufferColorPrimariesKey, kCVImageBufferColorPrimaries_ITU_R_709_2, kCVAttachmentMode_ShouldPropagate); + CVBufferSetAttachment(renderTarget, kCVImageBufferYCbCrMatrixKey, kCVImageBufferYCbCrMatrix_ITU_R_601_4, kCVAttachmentMode_ShouldPropagate); + CVBufferSetAttachment(renderTarget, kCVImageBufferTransferFunctionKey, kCVImageBufferTransferFunction_ITU_R_709_2, kCVAttachmentMode_ShouldPropagate); + + CVOpenGLESTextureCacheCreateTextureFromImage (kCFAllocatorDefault, [_movieWriterContext coreVideoTextureCache], renderTarget, + NULL, // texture attributes + GL_TEXTURE_2D, + GL_RGBA, // opengl format + (int)videoSize.width, + (int)videoSize.height, + GL_BGRA, // native iOS format + GL_UNSIGNED_BYTE, + 0, + &renderTexture); + + glBindTexture(CVOpenGLESTextureGetTarget(renderTexture), CVOpenGLESTextureGetName(renderTexture)); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, CVOpenGLESTextureGetName(renderTexture), 0); + } + else + { + glGenRenderbuffers(1, &movieRenderbuffer); + glBindRenderbuffer(GL_RENDERBUFFER, movieRenderbuffer); + glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_OES, (int)videoSize.width, (int)videoSize.height); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, movieRenderbuffer); + } + + + __unused GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + + NSAssert(status == GL_FRAMEBUFFER_COMPLETE, @"Incomplete filter FBO: %d", status); +} + +- (void)destroyDataFBO; +{ + runSynchronouslyOnContextQueue(_movieWriterContext, ^{ + [_movieWriterContext useAsCurrentContext]; + + if (movieFramebuffer) + { + glDeleteFramebuffers(1, &movieFramebuffer); + movieFramebuffer = 0; + } + + if (movieRenderbuffer) + { + glDeleteRenderbuffers(1, &movieRenderbuffer); + movieRenderbuffer = 0; + } + + if ([GPUImageContext supportsFastTextureUpload]) + { + if (renderTexture) + { + CFRelease(renderTexture); + } + if (renderTarget) + { + CVPixelBufferRelease(renderTarget); + } + + } + }); +} + +- (void)setFilterFBO; +{ + if (!movieFramebuffer) + { + [self createDataFBO]; + } + + glBindFramebuffer(GL_FRAMEBUFFER, movieFramebuffer); + + glViewport(0, 0, (int)videoSize.width, (int)videoSize.height); +} + +- (void)renderAtInternalSizeUsingFramebuffer:(GPUImageFramebuffer *)inputFramebufferToUse; +{ + [_movieWriterContext useAsCurrentContext]; + [self setFilterFBO]; + + [_movieWriterContext setContextShaderProgram:colorSwizzlingProgram]; + + glClearColor(1.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + // This needs to be flipped to write out to video correctly + static const GLfloat squareVertices[] = { + -1.0f, -1.0f, + 1.0f, -1.0f, + -1.0f, 1.0f, + 1.0f, 1.0f, + }; + + const GLfloat *textureCoordinates = [GPUImageFilter textureCoordinatesForRotation:inputRotation]; + + glActiveTexture(GL_TEXTURE4); + glBindTexture(GL_TEXTURE_2D, [inputFramebufferToUse texture]); + glUniform1i(colorSwizzlingInputTextureUniform, 4); + +// NSLog(@"Movie writer framebuffer: %@", inputFramebufferToUse); + + glVertexAttribPointer(colorSwizzlingPositionAttribute, 2, GL_FLOAT, 0, 0, squareVertices); + glVertexAttribPointer(colorSwizzlingTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, textureCoordinates); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + glFinish(); +} + +#pragma mark - +#pragma mark GPUImageInput protocol + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + if (!isRecording || _paused) + { + [firstInputFramebuffer unlock]; + return; + } + + if (discont) { + discont = NO; + CMTime current; + + if (offsetTime.value > 0) { + current = CMTimeSubtract(frameTime, offsetTime); + } else { + current = frameTime; + } + + CMTime offset = CMTimeSubtract(current, previousFrameTime); + + if (offsetTime.value == 0) { + offsetTime = offset; + } else { + offsetTime = CMTimeAdd(offsetTime, offset); + } + } + + if (offsetTime.value > 0) { + frameTime = CMTimeSubtract(frameTime, offsetTime); + } + + // Drop frames forced by images and other things with no time constants + // Also, if two consecutive times with the same value are added to the movie, it aborts recording, so I bail on that case + if ( (CMTIME_IS_INVALID(frameTime)) || (CMTIME_COMPARE_INLINE(frameTime, ==, previousFrameTime)) || (CMTIME_IS_INDEFINITE(frameTime)) ) + { + [firstInputFramebuffer unlock]; + return; + } + + if (CMTIME_IS_INVALID(startTime)) + { + runSynchronouslyOnContextQueue(_movieWriterContext, ^{ + if ((videoInputReadyCallback == NULL) && (assetWriter.status != AVAssetWriterStatusWriting)) + { + [assetWriter startWriting]; + } + + [assetWriter startSessionAtSourceTime:frameTime]; + startTime = frameTime; + }); + } + + GPUImageFramebuffer *inputFramebufferForBlock = firstInputFramebuffer; + glFinish(); + + runAsynchronouslyOnContextQueue(_movieWriterContext, ^{ + if (!assetWriterVideoInput.readyForMoreMediaData && _encodingLiveVideo) + { + [inputFramebufferForBlock unlock]; + NSLog(@"1: Had to drop a video frame: %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, frameTime))); + return; + } + + // Render the frame with swizzled colors, so that they can be uploaded quickly as BGRA frames + [_movieWriterContext useAsCurrentContext]; + [self renderAtInternalSizeUsingFramebuffer:inputFramebufferForBlock]; + + CVPixelBufferRef pixel_buffer = NULL; + + if ([GPUImageContext supportsFastTextureUpload]) + { + pixel_buffer = renderTarget; + CVPixelBufferLockBaseAddress(pixel_buffer, 0); + } + else + { + CVReturn status = CVPixelBufferPoolCreatePixelBuffer (NULL, [assetWriterPixelBufferInput pixelBufferPool], &pixel_buffer); + if ((pixel_buffer == NULL) || (status != kCVReturnSuccess)) + { + CVPixelBufferRelease(pixel_buffer); + return; + } + else + { + CVPixelBufferLockBaseAddress(pixel_buffer, 0); + + GLubyte *pixelBufferData = (GLubyte *)CVPixelBufferGetBaseAddress(pixel_buffer); + glReadPixels(0, 0, videoSize.width, videoSize.height, GL_RGBA, GL_UNSIGNED_BYTE, pixelBufferData); + } + } + + void(^write)() = ^() { + while( ! assetWriterVideoInput.readyForMoreMediaData && ! _encodingLiveVideo && ! videoEncodingIsFinished ) { + NSDate *maxDate = [NSDate dateWithTimeIntervalSinceNow:0.1]; + // NSLog(@"video waiting..."); + [[NSRunLoop currentRunLoop] runUntilDate:maxDate]; + } + if (!assetWriterVideoInput.readyForMoreMediaData) + { + NSLog(@"2: Had to drop a video frame: %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, frameTime))); + } + else if(self.assetWriter.status == AVAssetWriterStatusWriting) + { + if (![assetWriterPixelBufferInput appendPixelBuffer:pixel_buffer withPresentationTime:frameTime]) + NSLog(@"Problem appending pixel buffer at time: %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, frameTime))); + } + else + { + NSLog(@"Couldn't write a frame"); + //NSLog(@"Wrote a video frame: %@", CFBridgingRelease(CMTimeCopyDescription(kCFAllocatorDefault, frameTime))); + } + CVPixelBufferUnlockBaseAddress(pixel_buffer, 0); + + previousFrameTime = frameTime; + + if (![GPUImageContext supportsFastTextureUpload]) + { + CVPixelBufferRelease(pixel_buffer); + } + }; + + write(); + + [inputFramebufferForBlock unlock]; + }); +} + +- (NSInteger)nextAvailableTextureIndex; +{ + return 0; +} + +- (void)setInputFramebuffer:(GPUImageFramebuffer *)newInputFramebuffer atIndex:(NSInteger)textureIndex; +{ + [newInputFramebuffer lock]; +// runSynchronouslyOnContextQueue(_movieWriterContext, ^{ + firstInputFramebuffer = newInputFramebuffer; +// }); +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + inputRotation = newInputRotation; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ +} + +- (CGSize)maximumOutputSize; +{ + return videoSize; +} + +- (void)endProcessing +{ + if (completionBlock) + { + if (!alreadyFinishedRecording) + { + alreadyFinishedRecording = YES; + completionBlock(); + } + } + else + { + if (_delegate && [_delegate respondsToSelector:@selector(movieRecordingCompleted)]) + { + [_delegate movieRecordingCompleted]; + } + } +} + +- (BOOL)shouldIgnoreUpdatesToThisTarget; +{ + return NO; +} + +- (BOOL)wantsMonochromeInput; +{ + return NO; +} + +- (void)setCurrentlyReceivingMonochromeInput:(BOOL)newValue; +{ + +} + +#pragma mark - +#pragma mark Accessors + +- (void)setHasAudioTrack:(BOOL)newValue +{ + [self setHasAudioTrack:newValue audioSettings:nil]; +} + +- (void)setHasAudioTrack:(BOOL)newValue audioSettings:(NSDictionary *)audioOutputSettings; +{ + _hasAudioTrack = newValue; + + if (_hasAudioTrack) + { + if (_shouldPassthroughAudio) + { + // Do not set any settings so audio will be the same as passthrough + audioOutputSettings = nil; + } + else if (audioOutputSettings == nil) + { + AVAudioSession *sharedAudioSession = [AVAudioSession sharedInstance]; + double preferredHardwareSampleRate; + + if ([sharedAudioSession respondsToSelector:@selector(sampleRate)]) + { + preferredHardwareSampleRate = [sharedAudioSession sampleRate]; + } + else + { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + preferredHardwareSampleRate = [[AVAudioSession sharedInstance] currentHardwareSampleRate]; +#pragma clang diagnostic pop + } + + AudioChannelLayout acl; + bzero( &acl, sizeof(acl)); + acl.mChannelLayoutTag = kAudioChannelLayoutTag_Mono; + + audioOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys: + [ NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey, + [ NSNumber numberWithInt: 1 ], AVNumberOfChannelsKey, + [ NSNumber numberWithFloat: preferredHardwareSampleRate ], AVSampleRateKey, + [ NSData dataWithBytes: &acl length: sizeof( acl ) ], AVChannelLayoutKey, + //[ NSNumber numberWithInt:AVAudioQualityLow], AVEncoderAudioQualityKey, + [ NSNumber numberWithInt: 64000 ], AVEncoderBitRateKey, + nil]; +/* + AudioChannelLayout acl; + bzero( &acl, sizeof(acl)); + acl.mChannelLayoutTag = kAudioChannelLayoutTag_Mono; + + audioOutputSettings = [NSDictionary dictionaryWithObjectsAndKeys: + [ NSNumber numberWithInt: kAudioFormatMPEG4AAC ], AVFormatIDKey, + [ NSNumber numberWithInt: 1 ], AVNumberOfChannelsKey, + [ NSNumber numberWithFloat: 44100.0 ], AVSampleRateKey, + [ NSNumber numberWithInt: 64000 ], AVEncoderBitRateKey, + [ NSData dataWithBytes: &acl length: sizeof( acl ) ], AVChannelLayoutKey, + nil];*/ + } + + assetWriterAudioInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeAudio outputSettings:audioOutputSettings]; + [assetWriter addInput:assetWriterAudioInput]; + assetWriterAudioInput.expectsMediaDataInRealTime = _encodingLiveVideo; + } + else + { + // Remove audio track if it exists + } +} + +- (NSArray*)metaData { + return assetWriter.metadata; +} + +- (void)setMetaData:(NSArray*)metaData { + assetWriter.metadata = metaData; +} + +- (CMTime)duration { + if( ! CMTIME_IS_VALID(startTime) ) + return kCMTimeZero; + if( ! CMTIME_IS_NEGATIVE_INFINITY(previousFrameTime) ) + return CMTimeSubtract(previousFrameTime, startTime); + if( ! CMTIME_IS_NEGATIVE_INFINITY(previousAudioTime) ) + return CMTimeSubtract(previousAudioTime, startTime); + return kCMTimeZero; +} + +- (CGAffineTransform)transform { + return assetWriterVideoInput.transform; +} + +- (void)setTransform:(CGAffineTransform)transform { + assetWriterVideoInput.transform = transform; +} + +- (AVAssetWriter*)assetWriter { + return assetWriter; +} + +- (void)setPaused:(BOOL)newValue { + if (_paused != newValue) { + _paused = newValue; + + if (_paused) { + discont = YES; + } + } +} + +- (CMSampleBufferRef)adjustTime:(CMSampleBufferRef) sample by:(CMTime) offset { + CMItemCount count; + CMSampleBufferGetSampleTimingInfoArray(sample, 0, nil, &count); + CMSampleTimingInfo* pInfo = malloc(sizeof(CMSampleTimingInfo) * count); + CMSampleBufferGetSampleTimingInfoArray(sample, count, pInfo, &count); + + for (CMItemCount i = 0; i < count; i++) { + pInfo[i].decodeTimeStamp = CMTimeSubtract(pInfo[i].decodeTimeStamp, offset); + pInfo[i].presentationTimeStamp = CMTimeSubtract(pInfo[i].presentationTimeStamp, offset); + } + + CMSampleBufferRef sout; + CMSampleBufferCreateCopyWithNewTiming(nil, sample, count, pInfo, &sout); + free(pInfo); + + return sout; +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture+TextureSubimage.h b/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture+TextureSubimage.h new file mode 100644 index 00000000..03c631bc --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture+TextureSubimage.h @@ -0,0 +1,19 @@ +// +// GPUImagePicture+TextureSubimage.h +// GPUImage +// +// Created by Jack Wu on 2014-05-28. +// Copyright (c) 2014 Brad Larson. All rights reserved. +// + +#import "GPUImagePicture.h" + +@interface GPUImagePicture (TextureSubimage) + +- (void)replaceTextureWithSubimage:(UIImage*)subimage; +- (void)replaceTextureWithSubCGImage:(CGImageRef)subimageSource; + +- (void)replaceTextureWithSubimage:(UIImage*)subimage inRect:(CGRect)subRect; +- (void)replaceTextureWithSubCGImage:(CGImageRef)subimageSource inRect:(CGRect)subRect; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture+TextureSubimage.m b/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture+TextureSubimage.m new file mode 100644 index 00000000..71ef8f97 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture+TextureSubimage.m @@ -0,0 +1,103 @@ +// +// GPUImagePicture+TextureSubimage.m +// GPUImage +// +// Created by Jack Wu on 2014-05-28. +// Copyright (c) 2014 Brad Larson. All rights reserved. +// + +#import "GPUImagePicture+TextureSubimage.h" + +@implementation GPUImagePicture (TextureSubimage) + +- (void)replaceTextureWithSubimage:(UIImage*)subimage { + return [self replaceTextureWithSubCGImage:[subimage CGImage]]; +} + +- (void)replaceTextureWithSubCGImage:(CGImageRef)subimageSource { + CGRect rect = (CGRect) {.origin = CGPointZero, .size = (CGSize){.width = CGImageGetWidth(subimageSource), .height = CGImageGetHeight(subimageSource)}}; + return [self replaceTextureWithSubCGImage:subimageSource inRect:rect]; +} + +- (void)replaceTextureWithSubimage:(UIImage*)subimage inRect:(CGRect)subRect { + return [self replaceTextureWithSubCGImage:[subimage CGImage] inRect:subRect]; +} + +- (void)replaceTextureWithSubCGImage:(CGImageRef)subimageSource inRect:(CGRect)subRect { + NSAssert(outputFramebuffer, @"Picture must be initialized first before replacing subtexture"); + NSAssert(self.framebufferForOutput.textureOptions.internalFormat == GL_RGBA, @"For replacing subtexture the internal texture format must be GL_RGBA."); + + CGRect subimageRect = (CGRect){.origin = CGPointZero, .size = (CGSize){.width = CGImageGetWidth(subimageSource), .height = CGImageGetHeight(subimageSource)}}; + NSAssert(!CGRectIsEmpty(subimageRect), @"Passed sub image must not be empty - it should be at least 1px tall and wide"); + NSAssert(!CGRectIsEmpty(subRect), @"Passed sub rect must not be empty"); + + NSAssert(CGSizeEqualToSize(subimageRect.size, subRect.size), @"Subimage size must match the size of sub rect"); + + // We don't have to worry about scaling the subimage or finding a power of two size. + // The initialization has taken care of that for us. + + dispatch_semaphore_signal(imageUpdateSemaphore); + + BOOL shouldRedrawUsingCoreGraphics = NO; + + // Since internal format is always RGBA, we need the input data in RGBA as well. + CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(subimageSource); + CGBitmapInfo byteOrderInfo = bitmapInfo & kCGBitmapByteOrderMask; + if (byteOrderInfo != kCGBitmapByteOrderDefault && byteOrderInfo != kCGBitmapByteOrder32Big) { + shouldRedrawUsingCoreGraphics = YES; + } + else { + CGImageAlphaInfo alphaInfo = bitmapInfo & kCGBitmapAlphaInfoMask; + if (alphaInfo != kCGImageAlphaPremultipliedLast && alphaInfo != kCGImageAlphaLast && alphaInfo != kCGImageAlphaNoneSkipLast) { + shouldRedrawUsingCoreGraphics = YES; + } + } + + GLubyte *imageData = NULL; + CFDataRef dataFromImageDataProvider; + if (shouldRedrawUsingCoreGraphics) + { + // For resized or incompatible image: redraw + imageData = (GLubyte *) calloc(1, (int)subimageRect.size.width * (int)subimageRect.size.height * 4); + + CGColorSpaceRef genericRGBColorspace = CGColorSpaceCreateDeviceRGB(); + + CGContextRef imageContext = CGBitmapContextCreate(imageData, (size_t)subimageRect.size.width, (size_t)subimageRect.size.height, 8, (size_t)subimageRect.size.width * 4, genericRGBColorspace, kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedLast); + + CGContextDrawImage(imageContext, CGRectMake(0.0, 0.0, subimageRect.size.width, subimageRect.size.height), subimageSource); + CGContextRelease(imageContext); + CGColorSpaceRelease(genericRGBColorspace); + } + else + { + // Access the raw image bytes directly + dataFromImageDataProvider = CGDataProviderCopyData(CGImageGetDataProvider(subimageSource)); + imageData = (GLubyte *)CFDataGetBytePtr(dataFromImageDataProvider); + } + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + [outputFramebuffer disableReferenceCounting]; + + glBindTexture(GL_TEXTURE_2D, [outputFramebuffer texture]); + + // no need to use self.outputTextureOptions here since pictures need this texture formats and type + glTexSubImage2D(GL_TEXTURE_2D, 0, subRect.origin.x, subRect.origin.y, (GLint)subRect.size.width, subRect.size.height, GL_RGBA, GL_UNSIGNED_BYTE, imageData); + + if (self.shouldSmoothlyScaleOutput) + { + glGenerateMipmap(GL_TEXTURE_2D); + } + glBindTexture(GL_TEXTURE_2D, 0); + }); + + if (shouldRedrawUsingCoreGraphics) + { + free(imageData); + } + else + { + CFRelease(dataFromImageDataProvider); + } +} +@end diff --git a/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture.h b/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture.h new file mode 100755 index 00000000..4c4b9942 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture.h @@ -0,0 +1,38 @@ +#import +#import "GPUImageOutput.h" + + +@interface GPUImagePicture : GPUImageOutput +{ + CGSize pixelSizeOfImage; + BOOL hasProcessedImage; + + dispatch_semaphore_t imageUpdateSemaphore; +} + +// Initialization and teardown +- (id)initWithURL:(NSURL *)url; +- (id)initWithImage:(UIImage *)newImageSource; +- (id)initWithCGImage:(CGImageRef)newImageSource; +- (id)initWithImage:(UIImage *)newImageSource smoothlyScaleOutput:(BOOL)smoothlyScaleOutput; +- (id)initWithCGImage:(CGImageRef)newImageSource smoothlyScaleOutput:(BOOL)smoothlyScaleOutput; +- (id)initWithImage:(UIImage *)newImageSource removePremultiplication:(BOOL)removePremultiplication; +- (id)initWithCGImage:(CGImageRef)newImageSource removePremultiplication:(BOOL)removePremultiplication; +- (id)initWithImage:(UIImage *)newImageSource smoothlyScaleOutput:(BOOL)smoothlyScaleOutput removePremultiplication:(BOOL)removePremultiplication; +- (id)initWithCGImage:(CGImageRef)newImageSource smoothlyScaleOutput:(BOOL)smoothlyScaleOutput removePremultiplication:(BOOL)removePremultiplication; + +// Image rendering +- (void)processImage; +- (CGSize)outputImageSize; + +/** + * Process image with all targets and filters asynchronously + * The completion handler is called after processing finished in the + * GPU's dispatch queue - and only if this method did not return NO. + * + * @returns NO if resource is blocked and processing is discarded, YES otherwise + */ +- (BOOL)processImageWithCompletionHandler:(void (^)(void))completion; +- (void)processImageUpToFilter:(GPUImageOutput *)finalFilterInChain withCompletionHandler:(void (^)(UIImage *processedImage))block; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture.m b/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture.m new file mode 100755 index 00000000..c525f4dc --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/iOS/GPUImagePicture.m @@ -0,0 +1,371 @@ +#import "GPUImagePicture.h" + +@implementation GPUImagePicture + +#pragma mark - +#pragma mark Initialization and teardown + +- (id)initWithURL:(NSURL *)url; +{ + NSData *imageData = [[NSData alloc] initWithContentsOfURL:url]; + + if (!(self = [self initWithData:imageData])) + { + return nil; + } + + return self; +} + +- (id)initWithData:(NSData *)imageData; +{ + UIImage *inputImage = [[UIImage alloc] initWithData:imageData]; + + if (!(self = [self initWithImage:inputImage])) + { + return nil; + } + + return self; +} + +- (id)initWithImage:(UIImage *)newImageSource; +{ + if (!(self = [self initWithImage:newImageSource smoothlyScaleOutput:NO])) + { + return nil; + } + + return self; +} + +- (id)initWithCGImage:(CGImageRef)newImageSource; +{ + if (!(self = [self initWithCGImage:newImageSource smoothlyScaleOutput:NO])) + { + return nil; + } + return self; +} + +- (id)initWithImage:(UIImage *)newImageSource smoothlyScaleOutput:(BOOL)smoothlyScaleOutput; +{ + return [self initWithCGImage:[newImageSource CGImage] smoothlyScaleOutput:smoothlyScaleOutput]; +} + +- (id)initWithCGImage:(CGImageRef)newImageSource smoothlyScaleOutput:(BOOL)smoothlyScaleOutput; +{ + return [self initWithCGImage:newImageSource smoothlyScaleOutput:smoothlyScaleOutput removePremultiplication:NO]; +} + +- (id)initWithImage:(UIImage *)newImageSource removePremultiplication:(BOOL)removePremultiplication; +{ + return [self initWithCGImage:[newImageSource CGImage] smoothlyScaleOutput:NO removePremultiplication:removePremultiplication]; +} + +- (id)initWithCGImage:(CGImageRef)newImageSource removePremultiplication:(BOOL)removePremultiplication; +{ + return [self initWithCGImage:newImageSource smoothlyScaleOutput:NO removePremultiplication:removePremultiplication]; +} + +- (id)initWithImage:(UIImage *)newImageSource smoothlyScaleOutput:(BOOL)smoothlyScaleOutput removePremultiplication:(BOOL)removePremultiplication; +{ + return [self initWithCGImage:[newImageSource CGImage] smoothlyScaleOutput:smoothlyScaleOutput removePremultiplication:removePremultiplication]; +} + +- (id)initWithCGImage:(CGImageRef)newImageSource smoothlyScaleOutput:(BOOL)smoothlyScaleOutput removePremultiplication:(BOOL)removePremultiplication; +{ + if (!(self = [super init])) + { + return nil; + } + + hasProcessedImage = NO; + self.shouldSmoothlyScaleOutput = smoothlyScaleOutput; + imageUpdateSemaphore = dispatch_semaphore_create(0); + dispatch_semaphore_signal(imageUpdateSemaphore); + + + // TODO: Dispatch this whole thing asynchronously to move image loading off main thread + CGFloat widthOfImage = CGImageGetWidth(newImageSource); + CGFloat heightOfImage = CGImageGetHeight(newImageSource); + + // If passed an empty image reference, CGContextDrawImage will fail in future versions of the SDK. + NSAssert( widthOfImage > 0 && heightOfImage > 0, @"Passed image must not be empty - it should be at least 1px tall and wide"); + + pixelSizeOfImage = CGSizeMake(widthOfImage, heightOfImage); + CGSize pixelSizeToUseForTexture = pixelSizeOfImage; + + BOOL shouldRedrawUsingCoreGraphics = NO; + + // For now, deal with images larger than the maximum texture size by resizing to be within that limit + CGSize scaledImageSizeToFitOnGPU = [GPUImageContext sizeThatFitsWithinATextureForSize:pixelSizeOfImage]; + if (!CGSizeEqualToSize(scaledImageSizeToFitOnGPU, pixelSizeOfImage)) + { + pixelSizeOfImage = scaledImageSizeToFitOnGPU; + pixelSizeToUseForTexture = pixelSizeOfImage; + shouldRedrawUsingCoreGraphics = YES; + } + + if (self.shouldSmoothlyScaleOutput) + { + // In order to use mipmaps, you need to provide power-of-two textures, so convert to the next largest power of two and stretch to fill + CGFloat powerClosestToWidth = ceil(log2(pixelSizeOfImage.width)); + CGFloat powerClosestToHeight = ceil(log2(pixelSizeOfImage.height)); + + pixelSizeToUseForTexture = CGSizeMake(pow(2.0, powerClosestToWidth), pow(2.0, powerClosestToHeight)); + + shouldRedrawUsingCoreGraphics = YES; + } + + GLubyte *imageData = NULL; + CFDataRef dataFromImageDataProvider = NULL; + GLenum format = GL_BGRA; + BOOL isLitteEndian = YES; + BOOL alphaFirst = NO; + BOOL premultiplied = NO; + + if (!shouldRedrawUsingCoreGraphics) { + /* Check that the memory layout is compatible with GL, as we cannot use glPixelStore to + * tell GL about the memory layout with GLES. + */ + if (CGImageGetBytesPerRow(newImageSource) != CGImageGetWidth(newImageSource) * 4 || + CGImageGetBitsPerPixel(newImageSource) != 32 || + CGImageGetBitsPerComponent(newImageSource) != 8) + { + shouldRedrawUsingCoreGraphics = YES; + } else { + /* Check that the bitmap pixel format is compatible with GL */ + CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(newImageSource); + if ((bitmapInfo & kCGBitmapFloatComponents) != 0) { + /* We don't support float components for use directly in GL */ + shouldRedrawUsingCoreGraphics = YES; + } else { + CGBitmapInfo byteOrderInfo = bitmapInfo & kCGBitmapByteOrderMask; + if (byteOrderInfo == kCGBitmapByteOrder32Little) { + /* Little endian, for alpha-first we can use this bitmap directly in GL */ + CGImageAlphaInfo alphaInfo = bitmapInfo & kCGBitmapAlphaInfoMask; + if (alphaInfo != kCGImageAlphaPremultipliedFirst && alphaInfo != kCGImageAlphaFirst && + alphaInfo != kCGImageAlphaNoneSkipFirst) { + shouldRedrawUsingCoreGraphics = YES; + } + } else if (byteOrderInfo == kCGBitmapByteOrderDefault || byteOrderInfo == kCGBitmapByteOrder32Big) { + isLitteEndian = NO; + /* Big endian, for alpha-last we can use this bitmap directly in GL */ + CGImageAlphaInfo alphaInfo = bitmapInfo & kCGBitmapAlphaInfoMask; + if (alphaInfo != kCGImageAlphaPremultipliedLast && alphaInfo != kCGImageAlphaLast && + alphaInfo != kCGImageAlphaNoneSkipLast) { + shouldRedrawUsingCoreGraphics = YES; + } else { + /* Can access directly using GL_RGBA pixel format */ + premultiplied = alphaInfo == kCGImageAlphaPremultipliedLast || alphaInfo == kCGImageAlphaPremultipliedLast; + alphaFirst = alphaInfo == kCGImageAlphaFirst || alphaInfo == kCGImageAlphaPremultipliedFirst; + format = GL_RGBA; + } + } + } + } + } + + // CFAbsoluteTime elapsedTime, startTime = CFAbsoluteTimeGetCurrent(); + + if (shouldRedrawUsingCoreGraphics) + { + // For resized or incompatible image: redraw + imageData = (GLubyte *) calloc(1, (int)pixelSizeToUseForTexture.width * (int)pixelSizeToUseForTexture.height * 4); + + CGColorSpaceRef genericRGBColorspace = CGColorSpaceCreateDeviceRGB(); + + CGContextRef imageContext = CGBitmapContextCreate(imageData, (size_t)pixelSizeToUseForTexture.width, (size_t)pixelSizeToUseForTexture.height, 8, (size_t)pixelSizeToUseForTexture.width * 4, genericRGBColorspace, kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst); + // CGContextSetBlendMode(imageContext, kCGBlendModeCopy); // From Technical Q&A QA1708: http://developer.apple.com/library/ios/#qa/qa1708/_index.html + CGContextDrawImage(imageContext, CGRectMake(0.0, 0.0, pixelSizeToUseForTexture.width, pixelSizeToUseForTexture.height), newImageSource); + CGContextRelease(imageContext); + CGColorSpaceRelease(genericRGBColorspace); + isLitteEndian = YES; + alphaFirst = YES; + premultiplied = YES; + } + else + { + // Access the raw image bytes directly + dataFromImageDataProvider = CGDataProviderCopyData(CGImageGetDataProvider(newImageSource)); + imageData = (GLubyte *)CFDataGetBytePtr(dataFromImageDataProvider); + } + + if (removePremultiplication && premultiplied) { + NSUInteger totalNumberOfPixels = round(pixelSizeToUseForTexture.width * pixelSizeToUseForTexture.height); + uint32_t *pixelP = (uint32_t *)imageData; + uint32_t pixel; + CGFloat srcR, srcG, srcB, srcA; + + for (NSUInteger idx=0; idx> 24) / 255.0f; + } + else { + srcA = (CGFloat)(pixel & 0x000000ff) / 255.0f; + pixel >>= 8; + } + + srcR = (CGFloat)((pixel & 0x00ff0000) >> 16) / 255.0f; + srcG = (CGFloat)((pixel & 0x0000ff00) >> 8) / 255.0f; + srcB = (CGFloat)(pixel & 0x000000ff) / 255.0f; + + srcR /= srcA; srcG /= srcA; srcB /= srcA; + + pixel = (uint32_t)(srcR * 255.0) << 16; + pixel |= (uint32_t)(srcG * 255.0) << 8; + pixel |= (uint32_t)(srcB * 255.0); + + if (alphaFirst) { + pixel |= (uint32_t)(srcA * 255.0) << 24; + } + else { + pixel <<= 8; + pixel |= (uint32_t)(srcA * 255.0); + } + *pixelP = isLitteEndian ? CFSwapInt32HostToLittle(pixel) : CFSwapInt32HostToBig(pixel); + } + } + + // elapsedTime = (CFAbsoluteTimeGetCurrent() - startTime) * 1000.0; + // NSLog(@"Core Graphics drawing time: %f", elapsedTime); + + // CGFloat currentRedTotal = 0.0f, currentGreenTotal = 0.0f, currentBlueTotal = 0.0f, currentAlphaTotal = 0.0f; + // NSUInteger totalNumberOfPixels = round(pixelSizeToUseForTexture.width * pixelSizeToUseForTexture.height); + // + // for (NSUInteger currentPixel = 0; currentPixel < totalNumberOfPixels; currentPixel++) + // { + // currentBlueTotal += (CGFloat)imageData[(currentPixel * 4)] / 255.0f; + // currentGreenTotal += (CGFloat)imageData[(currentPixel * 4) + 1] / 255.0f; + // currentRedTotal += (CGFloat)imageData[(currentPixel * 4 + 2)] / 255.0f; + // currentAlphaTotal += (CGFloat)imageData[(currentPixel * 4) + 3] / 255.0f; + // } + // + // NSLog(@"Debug, average input image red: %f, green: %f, blue: %f, alpha: %f", currentRedTotal / (CGFloat)totalNumberOfPixels, currentGreenTotal / (CGFloat)totalNumberOfPixels, currentBlueTotal / (CGFloat)totalNumberOfPixels, currentAlphaTotal / (CGFloat)totalNumberOfPixels); + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + + outputFramebuffer = [[GPUImageContext sharedFramebufferCache] fetchFramebufferForSize:pixelSizeToUseForTexture onlyTexture:YES]; + [outputFramebuffer disableReferenceCounting]; + + glBindTexture(GL_TEXTURE_2D, [outputFramebuffer texture]); + if (self.shouldSmoothlyScaleOutput) + { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + } + // no need to use self.outputTextureOptions here since pictures need this texture formats and type + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, (int)pixelSizeToUseForTexture.width, (int)pixelSizeToUseForTexture.height, 0, format, GL_UNSIGNED_BYTE, imageData); + + if (self.shouldSmoothlyScaleOutput) + { + glGenerateMipmap(GL_TEXTURE_2D); + } + glBindTexture(GL_TEXTURE_2D, 0); + }); + + if (shouldRedrawUsingCoreGraphics) + { + free(imageData); + } + else + { + if (dataFromImageDataProvider) + { + CFRelease(dataFromImageDataProvider); + } + } + + return self; +} + +// ARC forbids explicit message send of 'release'; since iOS 6 even for dispatch_release() calls: stripping it out in that case is required. +- (void)dealloc; +{ + [outputFramebuffer enableReferenceCounting]; + [outputFramebuffer unlock]; + +#if !OS_OBJECT_USE_OBJC + if (imageUpdateSemaphore != NULL) + { + dispatch_release(imageUpdateSemaphore); + } +#endif +} + +#pragma mark - +#pragma mark Image rendering + +- (void)removeAllTargets; +{ + [super removeAllTargets]; + hasProcessedImage = NO; +} + +- (void)processImage; +{ + [self processImageWithCompletionHandler:nil]; +} + +- (BOOL)processImageWithCompletionHandler:(void (^)(void))completion; +{ + hasProcessedImage = YES; + + // dispatch_semaphore_wait(imageUpdateSemaphore, DISPATCH_TIME_FOREVER); + + if (dispatch_semaphore_wait(imageUpdateSemaphore, DISPATCH_TIME_NOW) != 0) + { + return NO; + } + + runAsynchronouslyOnVideoProcessingQueue(^{ + for (id currentTarget in targets) + { + NSInteger indexOfObject = [targets indexOfObject:currentTarget]; + NSInteger textureIndexOfTarget = [[targetTextureIndices objectAtIndex:indexOfObject] integerValue]; + + [currentTarget setCurrentlyReceivingMonochromeInput:NO]; + [currentTarget setInputSize:pixelSizeOfImage atIndex:textureIndexOfTarget]; + [currentTarget setInputFramebuffer:outputFramebuffer atIndex:textureIndexOfTarget]; + [currentTarget newFrameReadyAtTime:kCMTimeIndefinite atIndex:textureIndexOfTarget]; + } + + dispatch_semaphore_signal(imageUpdateSemaphore); + + if (completion != nil) { + completion(); + } + }); + + return YES; +} + +- (void)processImageUpToFilter:(GPUImageOutput *)finalFilterInChain withCompletionHandler:(void (^)(UIImage *processedImage))block; +{ + [finalFilterInChain useNextFrameForImageCapture]; + [self processImageWithCompletionHandler:^{ + UIImage *imageFromFilter = [finalFilterInChain imageFromCurrentFramebuffer]; + block(imageFromFilter); + }]; +} + +- (CGSize)outputImageSize; +{ + return pixelSizeOfImage; +} + +- (void)addTarget:(id)newTarget atTextureLocation:(NSInteger)textureLocation; +{ + [super addTarget:newTarget atTextureLocation:textureLocation]; + + if (hasProcessedImage) + { + [newTarget setInputSize:pixelSizeOfImage atIndex:textureLocation]; + [newTarget newFrameReadyAtTime:kCMTimeIndefinite atIndex:textureLocation]; + } +} + +@end diff --git a/LFLiveKit/Vendor/GPUImage/iOS/GPUImageView.h b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageView.h new file mode 100755 index 00000000..b42651d3 --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageView.h @@ -0,0 +1,41 @@ +#import +#import "GPUImageContext.h" + +typedef NS_ENUM(NSUInteger, GPUImageFillModeType) { + kGPUImageFillModeStretch, // Stretch to fill the full view, which may distort the image outside of its normal aspect ratio + kGPUImageFillModePreserveAspectRatio, // Maintains the aspect ratio of the source image, adding bars of the specified background color + kGPUImageFillModePreserveAspectRatioAndFill // Maintains the aspect ratio of the source image, zooming in on its center to fill the view +}; + + + +/** + UIView subclass to use as an endpoint for displaying GPUImage outputs + */ +@interface GPUImageView : UIView +{ + GPUImageRotationMode inputRotation; +} + +/** The fill mode dictates how images are fit in the view, with the default being kGPUImageFillModePreserveAspectRatio + */ +@property(readwrite, nonatomic) GPUImageFillModeType fillMode; + +/** This calculates the current display size, in pixels, taking into account Retina scaling factors + */ +@property(readonly, nonatomic) CGSize sizeInPixels; + +@property(nonatomic) BOOL enabled; + +/** Handling fill mode + + @param redComponent Red component for background color + @param greenComponent Green component for background color + @param blueComponent Blue component for background color + @param alphaComponent Alpha component for background color + */ +- (void)setBackgroundColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; + +- (void)setCurrentlyReceivingMonochromeInput:(BOOL)newValue; + +@end diff --git a/LFLiveKit/Vendor/GPUImage/iOS/GPUImageView.m b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageView.m new file mode 100755 index 00000000..e092b80e --- /dev/null +++ b/LFLiveKit/Vendor/GPUImage/iOS/GPUImageView.m @@ -0,0 +1,484 @@ +#import "GPUImageView.h" +#import +#import +#import "GPUImageContext.h" +#import "GPUImageFilter.h" +#import + +#pragma mark - +#pragma mark Private methods and instance variables + +@interface GPUImageView () +{ + GPUImageFramebuffer *inputFramebufferForDisplay; + GLuint displayRenderbuffer, displayFramebuffer; + + GLProgram *displayProgram; + GLint displayPositionAttribute, displayTextureCoordinateAttribute; + GLint displayInputTextureUniform; + + CGSize inputImageSize; + GLfloat imageVertices[8]; + GLfloat backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha; + + CGSize boundsSizeAtFrameBufferEpoch; +} + +@property (assign, nonatomic) NSUInteger aspectRatio; + +// Initialization and teardown +- (void)commonInit; + +// Managing the display FBOs +- (void)createDisplayFramebuffer; +- (void)destroyDisplayFramebuffer; + +// Handling fill mode +- (void)recalculateViewGeometry; + +@end + +@implementation GPUImageView + +@synthesize aspectRatio; +@synthesize sizeInPixels = _sizeInPixels; +@synthesize fillMode = _fillMode; +@synthesize enabled; + +#pragma mark - +#pragma mark Initialization and teardown + ++ (Class)layerClass +{ + return [CAEAGLLayer class]; +} + +- (id)initWithFrame:(CGRect)frame +{ + if (!(self = [super initWithFrame:frame])) + { + return nil; + } + + [self commonInit]; + + return self; +} + +-(id)initWithCoder:(NSCoder *)coder +{ + if (!(self = [super initWithCoder:coder])) + { + return nil; + } + + [self commonInit]; + + return self; +} + +- (void)commonInit; +{ + // Set scaling to account for Retina display + if ([self respondsToSelector:@selector(setContentScaleFactor:)]) + { + self.contentScaleFactor = [[UIScreen mainScreen] scale]; + } + + inputRotation = kGPUImageNoRotation; + self.opaque = YES; + self.hidden = NO; + CAEAGLLayer *eaglLayer = (CAEAGLLayer *)self.layer; + eaglLayer.opaque = YES; + eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil]; + + self.enabled = YES; + + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext useImageProcessingContext]; + + displayProgram = [[GPUImageContext sharedImageProcessingContext] programForVertexShaderString:kGPUImageVertexShaderString fragmentShaderString:kGPUImagePassthroughFragmentShaderString]; + if (!displayProgram.initialized) + { + [displayProgram addAttribute:@"position"]; + [displayProgram addAttribute:@"inputTextureCoordinate"]; + + if (![displayProgram link]) + { + NSString *progLog = [displayProgram programLog]; + NSLog(@"Program link log: %@", progLog); + NSString *fragLog = [displayProgram fragmentShaderLog]; + NSLog(@"Fragment shader compile log: %@", fragLog); + NSString *vertLog = [displayProgram vertexShaderLog]; + NSLog(@"Vertex shader compile log: %@", vertLog); + displayProgram = nil; + NSAssert(NO, @"Filter shader link failed"); + } + } + + displayPositionAttribute = [displayProgram attributeIndex:@"position"]; + displayTextureCoordinateAttribute = [displayProgram attributeIndex:@"inputTextureCoordinate"]; + displayInputTextureUniform = [displayProgram uniformIndex:@"inputImageTexture"]; // This does assume a name of "inputTexture" for the fragment shader + + [GPUImageContext setActiveShaderProgram:displayProgram]; + glEnableVertexAttribArray(displayPositionAttribute); + glEnableVertexAttribArray(displayTextureCoordinateAttribute); + + [self setBackgroundColorRed:0.0 green:0.0 blue:0.0 alpha:1.0]; + _fillMode = kGPUImageFillModePreserveAspectRatio; + [self createDisplayFramebuffer]; + }); +} + +- (void)layoutSubviews { + [super layoutSubviews]; + + // The frame buffer needs to be trashed and re-created when the view size changes. + if (!CGSizeEqualToSize(self.bounds.size, boundsSizeAtFrameBufferEpoch) && + !CGSizeEqualToSize(self.bounds.size, CGSizeZero)) { + runSynchronouslyOnVideoProcessingQueue(^{ + [self destroyDisplayFramebuffer]; + [self createDisplayFramebuffer]; + }); + } else if (!CGSizeEqualToSize(self.bounds.size, CGSizeZero)) { + [self recalculateViewGeometry]; + } +} + +- (void)dealloc +{ + runSynchronouslyOnVideoProcessingQueue(^{ + [self destroyDisplayFramebuffer]; + }); +} + +#pragma mark - +#pragma mark Managing the display FBOs + +- (void)createDisplayFramebuffer; +{ + [GPUImageContext useImageProcessingContext]; + + glGenFramebuffers(1, &displayFramebuffer); + glBindFramebuffer(GL_FRAMEBUFFER, displayFramebuffer); + + glGenRenderbuffers(1, &displayRenderbuffer); + glBindRenderbuffer(GL_RENDERBUFFER, displayRenderbuffer); + + [[[GPUImageContext sharedImageProcessingContext] context] renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer]; + + GLint backingWidth, backingHeight; + + glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &backingWidth); + glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &backingHeight); + + if ( (backingWidth == 0) || (backingHeight == 0) ) + { + [self destroyDisplayFramebuffer]; + return; + } + + _sizeInPixels.width = (CGFloat)backingWidth; + _sizeInPixels.height = (CGFloat)backingHeight; + +// NSLog(@"Backing width: %d, height: %d", backingWidth, backingHeight); + + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, displayRenderbuffer); + + __unused GLuint framebufferCreationStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER); + NSAssert(framebufferCreationStatus == GL_FRAMEBUFFER_COMPLETE, @"Failure with display framebuffer generation for display of size: %f, %f", self.bounds.size.width, self.bounds.size.height); + boundsSizeAtFrameBufferEpoch = self.bounds.size; + + [self recalculateViewGeometry]; +} + +- (void)destroyDisplayFramebuffer; +{ + [GPUImageContext useImageProcessingContext]; + + if (displayFramebuffer) + { + glDeleteFramebuffers(1, &displayFramebuffer); + displayFramebuffer = 0; + } + + if (displayRenderbuffer) + { + glDeleteRenderbuffers(1, &displayRenderbuffer); + displayRenderbuffer = 0; + } +} + +- (void)setDisplayFramebuffer; +{ + if (!displayFramebuffer) + { + [self createDisplayFramebuffer]; + } + + glBindFramebuffer(GL_FRAMEBUFFER, displayFramebuffer); + + glViewport(0, 0, (GLint)_sizeInPixels.width, (GLint)_sizeInPixels.height); +} + +- (void)presentFramebuffer; +{ + glBindRenderbuffer(GL_RENDERBUFFER, displayRenderbuffer); + [[GPUImageContext sharedImageProcessingContext] presentBufferForDisplay]; +} + +#pragma mark - +#pragma mark Handling fill mode + +- (void)recalculateViewGeometry; +{ + runSynchronouslyOnVideoProcessingQueue(^{ + CGFloat heightScaling, widthScaling; + + CGSize currentViewSize = self.bounds.size; + + // CGFloat imageAspectRatio = inputImageSize.width / inputImageSize.height; + // CGFloat viewAspectRatio = currentViewSize.width / currentViewSize.height; + + CGRect insetRect = AVMakeRectWithAspectRatioInsideRect(inputImageSize, self.bounds); + + switch(_fillMode) + { + case kGPUImageFillModeStretch: + { + widthScaling = 1.0; + heightScaling = 1.0; + }; break; + case kGPUImageFillModePreserveAspectRatio: + { + widthScaling = insetRect.size.width / currentViewSize.width; + heightScaling = insetRect.size.height / currentViewSize.height; + }; break; + case kGPUImageFillModePreserveAspectRatioAndFill: + { + // CGFloat widthHolder = insetRect.size.width / currentViewSize.width; + widthScaling = currentViewSize.height / insetRect.size.height; + heightScaling = currentViewSize.width / insetRect.size.width; + }; break; + } + + imageVertices[0] = -widthScaling; + imageVertices[1] = -heightScaling; + imageVertices[2] = widthScaling; + imageVertices[3] = -heightScaling; + imageVertices[4] = -widthScaling; + imageVertices[5] = heightScaling; + imageVertices[6] = widthScaling; + imageVertices[7] = heightScaling; + }); + +// static const GLfloat imageVertices[] = { +// -1.0f, -1.0f, +// 1.0f, -1.0f, +// -1.0f, 1.0f, +// 1.0f, 1.0f, +// }; +} + +- (void)setBackgroundColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; +{ + backgroundColorRed = redComponent; + backgroundColorGreen = greenComponent; + backgroundColorBlue = blueComponent; + backgroundColorAlpha = alphaComponent; +} + ++ (const GLfloat *)textureCoordinatesForRotation:(GPUImageRotationMode)rotationMode; +{ +// static const GLfloat noRotationTextureCoordinates[] = { +// 0.0f, 0.0f, +// 1.0f, 0.0f, +// 0.0f, 1.0f, +// 1.0f, 1.0f, +// }; + + static const GLfloat noRotationTextureCoordinates[] = { + 0.0f, 1.0f, + 1.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 0.0f, + }; + + static const GLfloat rotateRightTextureCoordinates[] = { + 1.0f, 1.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 0.0f, 0.0f, + }; + + static const GLfloat rotateLeftTextureCoordinates[] = { + 0.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 0.0f, + 1.0f, 1.0f, + }; + + static const GLfloat verticalFlipTextureCoordinates[] = { + 0.0f, 0.0f, + 1.0f, 0.0f, + 0.0f, 1.0f, + 1.0f, 1.0f, + }; + + static const GLfloat horizontalFlipTextureCoordinates[] = { + 1.0f, 1.0f, + 0.0f, 1.0f, + 1.0f, 0.0f, + 0.0f, 0.0f, + }; + + static const GLfloat rotateRightVerticalFlipTextureCoordinates[] = { + 1.0f, 0.0f, + 1.0f, 1.0f, + 0.0f, 0.0f, + 0.0f, 1.0f, + }; + + static const GLfloat rotateRightHorizontalFlipTextureCoordinates[] = { + 0.0f, 1.0f, + 0.0f, 0.0f, + 1.0f, 1.0f, + 1.0f, 0.0f, + }; + + static const GLfloat rotate180TextureCoordinates[] = { + 1.0f, 0.0f, + 0.0f, 0.0f, + 1.0f, 1.0f, + 0.0f, 1.0f, + }; + + switch(rotationMode) + { + case kGPUImageNoRotation: return noRotationTextureCoordinates; + case kGPUImageRotateLeft: return rotateLeftTextureCoordinates; + case kGPUImageRotateRight: return rotateRightTextureCoordinates; + case kGPUImageFlipVertical: return verticalFlipTextureCoordinates; + case kGPUImageFlipHorizonal: return horizontalFlipTextureCoordinates; + case kGPUImageRotateRightFlipVertical: return rotateRightVerticalFlipTextureCoordinates; + case kGPUImageRotateRightFlipHorizontal: return rotateRightHorizontalFlipTextureCoordinates; + case kGPUImageRotate180: return rotate180TextureCoordinates; + } +} + +#pragma mark - +#pragma mark GPUInput protocol + +- (void)newFrameReadyAtTime:(CMTime)frameTime atIndex:(NSInteger)textureIndex; +{ + runSynchronouslyOnVideoProcessingQueue(^{ + [GPUImageContext setActiveShaderProgram:displayProgram]; + [self setDisplayFramebuffer]; + + glClearColor(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glActiveTexture(GL_TEXTURE4); + glBindTexture(GL_TEXTURE_2D, [inputFramebufferForDisplay texture]); + glUniform1i(displayInputTextureUniform, 4); + + glVertexAttribPointer(displayPositionAttribute, 2, GL_FLOAT, 0, 0, imageVertices); + glVertexAttribPointer(displayTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, [GPUImageView textureCoordinatesForRotation:inputRotation]); + + glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + + [self presentFramebuffer]; + [inputFramebufferForDisplay unlock]; + inputFramebufferForDisplay = nil; + }); +} + +- (NSInteger)nextAvailableTextureIndex; +{ + return 0; +} + +- (void)setInputFramebuffer:(GPUImageFramebuffer *)newInputFramebuffer atIndex:(NSInteger)textureIndex; +{ + inputFramebufferForDisplay = newInputFramebuffer; + [inputFramebufferForDisplay lock]; +} + +- (void)setInputRotation:(GPUImageRotationMode)newInputRotation atIndex:(NSInteger)textureIndex; +{ + inputRotation = newInputRotation; +} + +- (void)setInputSize:(CGSize)newSize atIndex:(NSInteger)textureIndex; +{ + runSynchronouslyOnVideoProcessingQueue(^{ + CGSize rotatedSize = newSize; + + if (GPUImageRotationSwapsWidthAndHeight(inputRotation)) + { + rotatedSize.width = newSize.height; + rotatedSize.height = newSize.width; + } + + if (!CGSizeEqualToSize(inputImageSize, rotatedSize)) + { + inputImageSize = rotatedSize; + [self recalculateViewGeometry]; + } + }); +} + +- (CGSize)maximumOutputSize; +{ + if ([self respondsToSelector:@selector(setContentScaleFactor:)]) + { + CGSize pointSize = self.bounds.size; + return CGSizeMake(self.contentScaleFactor * pointSize.width, self.contentScaleFactor * pointSize.height); + } + else + { + return self.bounds.size; + } +} + +- (void)endProcessing +{ +} + +- (BOOL)shouldIgnoreUpdatesToThisTarget; +{ + return NO; +} + +- (BOOL)wantsMonochromeInput; +{ + return NO; +} + +- (void)setCurrentlyReceivingMonochromeInput:(BOOL)newValue; +{ + +} + +#pragma mark - +#pragma mark Accessors + +- (CGSize)sizeInPixels; +{ + if (CGSizeEqualToSize(_sizeInPixels, CGSizeZero)) + { + return [self maximumOutputSize]; + } + else + { + return _sizeInPixels; + } +} + +- (void)setFillMode:(GPUImageFillModeType)newValue; +{ + _fillMode = newValue; + [self recalculateViewGeometry]; +} + +@end diff --git a/LFLiveKit/Vendor/pili-librtmp/amf.c b/LFLiveKit/Vendor/pili-librtmp/amf.c new file mode 100644 index 00000000..18630ce2 --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/amf.c @@ -0,0 +1,1037 @@ +/* + * Copyright (C) 2005-2008 Team XBMC + * http://www.xbmc.org + * Copyright (C) 2008-2009 Andrej Stepanchuk + * Copyright (C) 2009-2010 Howard Chu + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +#include +#include +#include + +#include "amf.h" +#include "bytes.h" +#include "log.h" +#include "rtmp_sys.h" + +static const AMFObjectProperty AMFProp_Invalid = {{0, 0}, AMF_INVALID}; +static const AVal AV_empty = {0, 0}; + +/* Data is Big-Endian */ +unsigned short + AMF_DecodeInt16(const char *data) { + unsigned char *c = (unsigned char *)data; + unsigned short val; + val = (c[0] << 8) | c[1]; + return val; +} + +unsigned int + AMF_DecodeInt24(const char *data) { + unsigned char *c = (unsigned char *)data; + unsigned int val; + val = (c[0] << 16) | (c[1] << 8) | c[2]; + return val; +} + +unsigned int + AMF_DecodeInt32(const char *data) { + unsigned char *c = (unsigned char *)data; + unsigned int val; + val = (c[0] << 24) | (c[1] << 16) | (c[2] << 8) | c[3]; + return val; +} + +void AMF_DecodeString(const char *data, AVal *bv) { + bv->av_len = AMF_DecodeInt16(data); + bv->av_val = (bv->av_len > 0) ? (char *)data + 2 : NULL; +} + +void AMF_DecodeLongString(const char *data, AVal *bv) { + bv->av_len = AMF_DecodeInt32(data); + bv->av_val = (bv->av_len > 0) ? (char *)data + 4 : NULL; +} + +double + AMF_DecodeNumber(const char *data) { + double dVal; +#if __FLOAT_WORD_ORDER == __BYTE_ORDER +#if __BYTE_ORDER == __BIG_ENDIAN + memcpy(&dVal, data, 8); +#elif __BYTE_ORDER == __LITTLE_ENDIAN + unsigned char *ci, *co; + ci = (unsigned char *)data; + co = (unsigned char *)&dVal; + co[0] = ci[7]; + co[1] = ci[6]; + co[2] = ci[5]; + co[3] = ci[4]; + co[4] = ci[3]; + co[5] = ci[2]; + co[6] = ci[1]; + co[7] = ci[0]; +#endif +#else +#if __BYTE_ORDER == __LITTLE_ENDIAN /* __FLOAT_WORD_ORER == __BIG_ENDIAN */ + unsigned char *ci, *co; + ci = (unsigned char *)data; + co = (unsigned char *)&dVal; + co[0] = ci[3]; + co[1] = ci[2]; + co[2] = ci[1]; + co[3] = ci[0]; + co[4] = ci[7]; + co[5] = ci[6]; + co[6] = ci[5]; + co[7] = ci[4]; +#else /* __BYTE_ORDER == __BIG_ENDIAN && __FLOAT_WORD_ORER == __LITTLE_ENDIAN */ + unsigned char *ci, *co; + ci = (unsigned char *)data; + co = (unsigned char *)&dVal; + co[0] = ci[4]; + co[1] = ci[5]; + co[2] = ci[6]; + co[3] = ci[7]; + co[4] = ci[0]; + co[5] = ci[1]; + co[6] = ci[2]; + co[7] = ci[3]; +#endif +#endif + return dVal; +} + +int AMF_DecodeBoolean(const char *data) { + return *data != 0; +} + +char * + AMF_EncodeInt16(char *output, char *outend, short nVal) { + if (output + 2 > outend) + return NULL; + + output[1] = nVal & 0xff; + output[0] = nVal >> 8; + return output + 2; +} + +char * + AMF_EncodeInt24(char *output, char *outend, int nVal) { + if (output + 3 > outend) + return NULL; + + output[2] = nVal & 0xff; + output[1] = nVal >> 8; + output[0] = nVal >> 16; + return output + 3; +} + +char * + AMF_EncodeInt32(char *output, char *outend, int nVal) { + if (output + 4 > outend) + return NULL; + + output[3] = nVal & 0xff; + output[2] = nVal >> 8; + output[1] = nVal >> 16; + output[0] = nVal >> 24; + return output + 4; +} + +char * + AMF_EncodeString(char *output, char *outend, const AVal *bv) { + if ((bv->av_len < 65536 && output + 1 + 2 + bv->av_len > outend) || + output + 1 + 4 + bv->av_len > outend) + return NULL; + + if (bv->av_len < 65536) { + *output++ = AMF_STRING; + + output = AMF_EncodeInt16(output, outend, bv->av_len); + } else { + *output++ = AMF_LONG_STRING; + + output = AMF_EncodeInt32(output, outend, bv->av_len); + } + memcpy(output, bv->av_val, bv->av_len); + output += bv->av_len; + + return output; +} + +char * + AMF_EncodeNumber(char *output, char *outend, double dVal) { + if (output + 1 + 8 > outend) + return NULL; + + *output++ = AMF_NUMBER; /* type: Number */ + +#if __FLOAT_WORD_ORDER == __BYTE_ORDER +#if __BYTE_ORDER == __BIG_ENDIAN + memcpy(output, &dVal, 8); +#elif __BYTE_ORDER == __LITTLE_ENDIAN + { + unsigned char *ci, *co; + ci = (unsigned char *)&dVal; + co = (unsigned char *)output; + co[0] = ci[7]; + co[1] = ci[6]; + co[2] = ci[5]; + co[3] = ci[4]; + co[4] = ci[3]; + co[5] = ci[2]; + co[6] = ci[1]; + co[7] = ci[0]; + } +#endif +#else +#if __BYTE_ORDER == __LITTLE_ENDIAN /* __FLOAT_WORD_ORER == __BIG_ENDIAN */ + { + unsigned char *ci, *co; + ci = (unsigned char *)&dVal; + co = (unsigned char *)output; + co[0] = ci[3]; + co[1] = ci[2]; + co[2] = ci[1]; + co[3] = ci[0]; + co[4] = ci[7]; + co[5] = ci[6]; + co[6] = ci[5]; + co[7] = ci[4]; + } +#else /* __BYTE_ORDER == __BIG_ENDIAN && __FLOAT_WORD_ORER == __LITTLE_ENDIAN */ + { + unsigned char *ci, *co; + ci = (unsigned char *)&dVal; + co = (unsigned char *)output; + co[0] = ci[4]; + co[1] = ci[5]; + co[2] = ci[6]; + co[3] = ci[7]; + co[4] = ci[0]; + co[5] = ci[1]; + co[6] = ci[2]; + co[7] = ci[3]; + } +#endif +#endif + + return output + 8; +} + +char * + AMF_EncodeBoolean(char *output, char *outend, int bVal) { + if (output + 2 > outend) + return NULL; + + *output++ = AMF_BOOLEAN; + + *output++ = bVal ? 0x01 : 0x00; + + return output; +} + +char * + AMF_EncodeNamedString(char *output, char *outend, const AVal *strName, const AVal *strValue) { + if (output + 2 + strName->av_len > outend) + return NULL; + output = AMF_EncodeInt16(output, outend, strName->av_len); + + memcpy(output, strName->av_val, strName->av_len); + output += strName->av_len; + + return AMF_EncodeString(output, outend, strValue); +} + +char * + AMF_EncodeNamedNumber(char *output, char *outend, const AVal *strName, double dVal) { + if (output + 2 + strName->av_len > outend) + return NULL; + output = AMF_EncodeInt16(output, outend, strName->av_len); + + memcpy(output, strName->av_val, strName->av_len); + output += strName->av_len; + + return AMF_EncodeNumber(output, outend, dVal); +} + +char * + AMF_EncodeNamedBoolean(char *output, char *outend, const AVal *strName, int bVal) { + if (output + 2 + strName->av_len > outend) + return NULL; + output = AMF_EncodeInt16(output, outend, strName->av_len); + + memcpy(output, strName->av_val, strName->av_len); + output += strName->av_len; + + return AMF_EncodeBoolean(output, outend, bVal); +} + +void AMFProp_GetName(AMFObjectProperty *prop, AVal *name) { + *name = prop->p_name; +} + +void AMFProp_SetName(AMFObjectProperty *prop, AVal *name) { + prop->p_name = *name; +} + +AMFDataType + AMFProp_GetType(AMFObjectProperty *prop) { + return prop->p_type; +} + +double + AMFProp_GetNumber(AMFObjectProperty *prop) { + return prop->p_vu.p_number; +} + +int AMFProp_GetBoolean(AMFObjectProperty *prop) { + return prop->p_vu.p_number != 0; +} + +void AMFProp_GetString(AMFObjectProperty *prop, AVal *str) { + *str = prop->p_vu.p_aval; +} + +void AMFProp_GetObject(AMFObjectProperty *prop, AMFObject *obj) { + *obj = prop->p_vu.p_object; +} + +int AMFProp_IsValid(AMFObjectProperty *prop) { + return prop->p_type != AMF_INVALID; +} + +char * + AMFProp_Encode(AMFObjectProperty *prop, char *pBuffer, char *pBufEnd) { + if (prop->p_type == AMF_INVALID) + return NULL; + + if (prop->p_type != AMF_NULL && pBuffer + prop->p_name.av_len + 2 + 1 >= pBufEnd) + return NULL; + + if (prop->p_type != AMF_NULL && prop->p_name.av_len) { + *pBuffer++ = prop->p_name.av_len >> 8; + *pBuffer++ = prop->p_name.av_len & 0xff; + memcpy(pBuffer, prop->p_name.av_val, prop->p_name.av_len); + pBuffer += prop->p_name.av_len; + } + + switch (prop->p_type) { + case AMF_NUMBER: + pBuffer = AMF_EncodeNumber(pBuffer, pBufEnd, prop->p_vu.p_number); + break; + + case AMF_BOOLEAN: + pBuffer = AMF_EncodeBoolean(pBuffer, pBufEnd, prop->p_vu.p_number != 0); + break; + + case AMF_STRING: + pBuffer = AMF_EncodeString(pBuffer, pBufEnd, &prop->p_vu.p_aval); + break; + + case AMF_NULL: + if (pBuffer + 1 >= pBufEnd) + return NULL; + *pBuffer++ = AMF_NULL; + break; + + case AMF_OBJECT: + pBuffer = AMF_Encode(&prop->p_vu.p_object, pBuffer, pBufEnd); + break; + + default: + RTMP_Log(RTMP_LOGERROR, "%s, invalid type. %d", __FUNCTION__, prop->p_type); + pBuffer = NULL; + }; + + return pBuffer; +} + +#define AMF3_INTEGER_MAX 268435455 +#define AMF3_INTEGER_MIN -268435456 + +int AMF3ReadInteger(const char *data, int32_t *valp) { + int i = 0; + int32_t val = 0; + + while (i <= 2) { /* handle first 3 bytes */ + if (data[i] & 0x80) { /* byte used */ + val <<= 7; /* shift up */ + val |= (data[i] & 0x7f); /* add bits */ + i++; + } else { + break; + } + } + + if (i > 2) { /* use 4th byte, all 8bits */ + val <<= 8; + val |= data[3]; + + /* range check */ + if (val > AMF3_INTEGER_MAX) + val -= (1 << 29); + } else { /* use 7bits of last unparsed byte (0xxxxxxx) */ + val <<= 7; + val |= data[i]; + } + + *valp = val; + + return i > 2 ? 4 : i + 1; +} + +int AMF3ReadString(const char *data, AVal *str) { + int32_t ref = 0; + int len; + assert(str != 0); + + len = AMF3ReadInteger(data, &ref); + data += len; + + if ((ref & 0x1) == 0) { /* reference: 0xxx */ + uint32_t refIndex = (ref >> 1); + RTMP_Log(RTMP_LOGDEBUG, + "%s, string reference, index: %d, not supported, ignoring!", + __FUNCTION__, refIndex); + return len; + } else { + uint32_t nSize = (ref >> 1); + + str->av_val = (char *)data; + str->av_len = nSize; + + return len + nSize; + } + return len; +} + +int AMF3Prop_Decode(AMFObjectProperty *prop, const char *pBuffer, int nSize, + int bDecodeName) { + int nOriginalSize = nSize; + AMF3DataType type; + + prop->p_name.av_len = 0; + prop->p_name.av_val = NULL; + + if (nSize == 0 || !pBuffer) { + RTMP_Log(RTMP_LOGDEBUG, "empty buffer/no buffer pointer!"); + return -1; + } + + /* decode name */ + if (bDecodeName) { + AVal name; + int nRes = AMF3ReadString(pBuffer, &name); + + if (name.av_len <= 0) + return nRes; + + prop->p_name = name; + pBuffer += nRes; + nSize -= nRes; + } + + /* decode */ + type = *pBuffer++; + nSize--; + + switch (type) { + case AMF3_UNDEFINED: + case AMF3_NULL: + prop->p_type = AMF_NULL; + break; + case AMF3_FALSE: + prop->p_type = AMF_BOOLEAN; + prop->p_vu.p_number = 0.0; + break; + case AMF3_TRUE: + prop->p_type = AMF_BOOLEAN; + prop->p_vu.p_number = 1.0; + break; + case AMF3_INTEGER: { + int32_t res = 0; + int len = AMF3ReadInteger(pBuffer, &res); + prop->p_vu.p_number = (double)res; + prop->p_type = AMF_NUMBER; + nSize -= len; + break; + } + case AMF3_DOUBLE: + if (nSize < 8) + return -1; + prop->p_vu.p_number = AMF_DecodeNumber(pBuffer); + prop->p_type = AMF_NUMBER; + nSize -= 8; + break; + case AMF3_STRING: + case AMF3_XML_DOC: + case AMF3_XML: { + int len = AMF3ReadString(pBuffer, &prop->p_vu.p_aval); + prop->p_type = AMF_STRING; + nSize -= len; + break; + } + case AMF3_DATE: { + int32_t res = 0; + int len = AMF3ReadInteger(pBuffer, &res); + + nSize -= len; + pBuffer += len; + + if ((res & 0x1) == 0) { /* reference */ + uint32_t nIndex = (res >> 1); + RTMP_Log(RTMP_LOGDEBUG, "AMF3_DATE reference: %d, not supported!", nIndex); + } else { + if (nSize < 8) + return -1; + + prop->p_vu.p_number = AMF_DecodeNumber(pBuffer); + nSize -= 8; + prop->p_type = AMF_NUMBER; + } + break; + } + case AMF3_OBJECT: { + int nRes = AMF3_Decode(&prop->p_vu.p_object, pBuffer, nSize, TRUE); + if (nRes == -1) + return -1; + nSize -= nRes; + prop->p_type = AMF_OBJECT; + break; + } + case AMF3_ARRAY: + case AMF3_BYTE_ARRAY: + default: + RTMP_Log(RTMP_LOGDEBUG, "%s - AMF3 unknown/unsupported datatype 0x%02x, @0x%08X", + __FUNCTION__, (unsigned char)(*pBuffer), pBuffer); + return -1; + } + + return nOriginalSize - nSize; +} + +int AMFProp_Decode(AMFObjectProperty *prop, const char *pBuffer, int nSize, + int bDecodeName) { + int nOriginalSize = nSize; + int nRes; + + prop->p_name.av_len = 0; + prop->p_name.av_val = NULL; + + if (nSize == 0 || !pBuffer) { + RTMP_Log(RTMP_LOGDEBUG, "%s: Empty buffer/no buffer pointer!", __FUNCTION__); + return -1; + } + + if (bDecodeName && nSize < 4) { /* at least name (length + at least 1 byte) and 1 byte of data */ + RTMP_Log(RTMP_LOGDEBUG, + "%s: Not enough data for decoding with name, less than 4 bytes!", + __FUNCTION__); + return -1; + } + + if (bDecodeName) { + unsigned short nNameSize = AMF_DecodeInt16(pBuffer); + if (nNameSize > nSize - 2) { + RTMP_Log(RTMP_LOGDEBUG, + "%s: Name size out of range: namesize (%d) > len (%d) - 2", + __FUNCTION__, nNameSize, nSize); + return -1; + } + + AMF_DecodeString(pBuffer, &prop->p_name); + nSize -= 2 + nNameSize; + pBuffer += 2 + nNameSize; + } + + if (nSize == 0) { + return -1; + } + + nSize--; + + prop->p_type = *pBuffer++; + switch (prop->p_type) { + case AMF_NUMBER: + if (nSize < 8) + return -1; + prop->p_vu.p_number = AMF_DecodeNumber(pBuffer); + nSize -= 8; + break; + case AMF_BOOLEAN: + if (nSize < 1) + return -1; + prop->p_vu.p_number = (double)AMF_DecodeBoolean(pBuffer); + nSize--; + break; + case AMF_STRING: { + unsigned short nStringSize = AMF_DecodeInt16(pBuffer); + + if (nSize < (long)nStringSize + 2) + return -1; + AMF_DecodeString(pBuffer, &prop->p_vu.p_aval); + nSize -= (2 + nStringSize); + break; + } + case AMF_OBJECT: { + int nRes = AMF_Decode(&prop->p_vu.p_object, pBuffer, nSize, TRUE); + if (nRes == -1) + return -1; + nSize -= nRes; + break; + } + case AMF_MOVIECLIP: { + RTMP_Log(RTMP_LOGERROR, "AMF_MOVIECLIP reserved!"); + return -1; + break; + } + case AMF_NULL: + case AMF_UNDEFINED: + case AMF_UNSUPPORTED: + prop->p_type = AMF_NULL; + break; + case AMF_REFERENCE: { + RTMP_Log(RTMP_LOGERROR, "AMF_REFERENCE not supported!"); + return -1; + break; + } + case AMF_ECMA_ARRAY: { + nSize -= 4; + + /* next comes the rest, mixed array has a final 0x000009 mark and names, so its an object */ + nRes = AMF_Decode(&prop->p_vu.p_object, pBuffer + 4, nSize, TRUE); + if (nRes == -1) + return -1; + nSize -= nRes; + prop->p_type = AMF_OBJECT; + break; + } + case AMF_OBJECT_END: { + return -1; + break; + } + case AMF_STRICT_ARRAY: { + unsigned int nArrayLen = AMF_DecodeInt32(pBuffer); + nSize -= 4; + + nRes = AMF_DecodeArray(&prop->p_vu.p_object, pBuffer + 4, nSize, + nArrayLen, FALSE); + if (nRes == -1) + return -1; + nSize -= nRes; + prop->p_type = AMF_OBJECT; + break; + } + case AMF_DATE: { + RTMP_Log(RTMP_LOGDEBUG, "AMF_DATE"); + + if (nSize < 10) + return -1; + + prop->p_vu.p_number = AMF_DecodeNumber(pBuffer); + prop->p_UTCoffset = AMF_DecodeInt16(pBuffer + 8); + + nSize -= 10; + break; + } + case AMF_LONG_STRING: { + unsigned int nStringSize = AMF_DecodeInt32(pBuffer); + if (nSize < (long)nStringSize + 4) + return -1; + AMF_DecodeLongString(pBuffer, &prop->p_vu.p_aval); + nSize -= (4 + nStringSize); + prop->p_type = AMF_STRING; + break; + } + case AMF_RECORDSET: { + RTMP_Log(RTMP_LOGERROR, "AMF_RECORDSET reserved!"); + return -1; + break; + } + case AMF_XML_DOC: { + RTMP_Log(RTMP_LOGERROR, "AMF_XML_DOC not supported!"); + return -1; + break; + } + case AMF_TYPED_OBJECT: { + RTMP_Log(RTMP_LOGERROR, "AMF_TYPED_OBJECT not supported!"); + return -1; + break; + } + case AMF_AVMPLUS: { + int nRes = AMF3_Decode(&prop->p_vu.p_object, pBuffer, nSize, TRUE); + if (nRes == -1) + return -1; + nSize -= nRes; + prop->p_type = AMF_OBJECT; + break; + } + default: + RTMP_Log(RTMP_LOGDEBUG, "%s - unknown datatype 0x%02x, @0x%08X", __FUNCTION__, + prop->p_type, pBuffer - 1); + return -1; + } + + return nOriginalSize - nSize; +} + +void AMFProp_Dump(AMFObjectProperty *prop) { + char strRes[256]; + char str[256]; + AVal name; + + if (prop->p_type == AMF_INVALID) { + RTMP_Log(RTMP_LOGDEBUG, "Property: INVALID"); + return; + } + + if (prop->p_type == AMF_NULL) { + RTMP_Log(RTMP_LOGDEBUG, "Property: NULL"); + return; + } + + if (prop->p_name.av_len) { + name = prop->p_name; + } else { + name.av_val = "no-name."; + name.av_len = sizeof("no-name.") - 1; + } + if (name.av_len > 18) + name.av_len = 18; + + snprintf(strRes, 255, "Name: %18.*s, ", name.av_len, name.av_val); + + if (prop->p_type == AMF_OBJECT) { + RTMP_Log(RTMP_LOGDEBUG, "Property: <%sOBJECT>", strRes); + AMF_Dump(&prop->p_vu.p_object); + return; + } + + switch (prop->p_type) { + case AMF_NUMBER: + snprintf(str, 255, "NUMBER:\t%.2f", prop->p_vu.p_number); + break; + case AMF_BOOLEAN: + snprintf(str, 255, "BOOLEAN:\t%s", + prop->p_vu.p_number != 0.0 ? "TRUE" : "FALSE"); + break; + case AMF_STRING: + snprintf(str, 255, "STRING:\t%.*s", prop->p_vu.p_aval.av_len, + prop->p_vu.p_aval.av_val); + break; + case AMF_DATE: + snprintf(str, 255, "DATE:\ttimestamp: %.2f, UTC offset: %d", + prop->p_vu.p_number, prop->p_UTCoffset); + break; + default: + snprintf(str, 255, "INVALID TYPE 0x%02x", (unsigned char)prop->p_type); + } + + RTMP_Log(RTMP_LOGDEBUG, "Property: <%s%s>", strRes, str); +} + +void AMFProp_Reset(AMFObjectProperty *prop) { + if (prop->p_type == AMF_OBJECT) + AMF_Reset(&prop->p_vu.p_object); + else { + prop->p_vu.p_aval.av_len = 0; + prop->p_vu.p_aval.av_val = NULL; + } + prop->p_type = AMF_INVALID; +} + +/* AMFObject */ + +char * + AMF_Encode(AMFObject *obj, char *pBuffer, char *pBufEnd) { + int i; + + if (pBuffer + 4 >= pBufEnd) + return NULL; + + *pBuffer++ = AMF_OBJECT; + + for (i = 0; i < obj->o_num; i++) { + char *res = AMFProp_Encode(&obj->o_props[i], pBuffer, pBufEnd); + if (res == NULL) { + RTMP_Log(RTMP_LOGERROR, "AMF_Encode - failed to encode property in index %d", + i); + break; + } else { + pBuffer = res; + } + } + + if (pBuffer + 3 >= pBufEnd) + return NULL; /* no room for the end marker */ + + pBuffer = AMF_EncodeInt24(pBuffer, pBufEnd, AMF_OBJECT_END); + + return pBuffer; +} + +int AMF_DecodeArray(AMFObject *obj, const char *pBuffer, int nSize, + int nArrayLen, int bDecodeName) { + int nOriginalSize = nSize; + int bError = FALSE; + + obj->o_num = 0; + obj->o_props = NULL; + while (nArrayLen > 0) { + AMFObjectProperty prop; + int nRes; + nArrayLen--; + + nRes = AMFProp_Decode(&prop, pBuffer, nSize, bDecodeName); + if (nRes == -1) + bError = TRUE; + else { + nSize -= nRes; + pBuffer += nRes; + AMF_AddProp(obj, &prop); + } + } + if (bError) + return -1; + + return nOriginalSize - nSize; +} + +int AMF3_Decode(AMFObject *obj, const char *pBuffer, int nSize, int bAMFData) { + int nOriginalSize = nSize; + int32_t ref; + int len; + + obj->o_num = 0; + obj->o_props = NULL; + if (bAMFData) { + if (*pBuffer != AMF3_OBJECT) + RTMP_Log(RTMP_LOGERROR, + "AMF3 Object encapsulated in AMF stream does not start with AMF3_OBJECT!"); + pBuffer++; + nSize--; + } + + ref = 0; + len = AMF3ReadInteger(pBuffer, &ref); + pBuffer += len; + nSize -= len; + + if ((ref & 1) == 0) { /* object reference, 0xxx */ + uint32_t objectIndex = (ref >> 1); + + RTMP_Log(RTMP_LOGDEBUG, "Object reference, index: %d", objectIndex); + } else /* object instance */ + { + int32_t classRef = (ref >> 1); + + AMF3ClassDef cd = {{0, 0}}; + AMFObjectProperty prop; + + if ((classRef & 0x1) == 0) { /* class reference */ + uint32_t classIndex = (classRef >> 1); + RTMP_Log(RTMP_LOGDEBUG, "Class reference: %d", classIndex); + } else { + int32_t classExtRef = (classRef >> 1); + int i; + + cd.cd_externalizable = (classExtRef & 0x1) == 1; + cd.cd_dynamic = ((classExtRef >> 1) & 0x1) == 1; + + cd.cd_num = classExtRef >> 2; + + /* class name */ + + len = AMF3ReadString(pBuffer, &cd.cd_name); + nSize -= len; + pBuffer += len; + + /*std::string str = className; */ + + RTMP_Log(RTMP_LOGDEBUG, + "Class name: %s, externalizable: %d, dynamic: %d, classMembers: %d", + cd.cd_name.av_val, cd.cd_externalizable, cd.cd_dynamic, + cd.cd_num); + + for (i = 0; i < cd.cd_num; i++) { + AVal memberName; + len = AMF3ReadString(pBuffer, &memberName); + RTMP_Log(RTMP_LOGDEBUG, "Member: %s", memberName.av_val); + AMF3CD_AddProp(&cd, &memberName); + nSize -= len; + pBuffer += len; + } + } + + /* add as referencable object */ + + if (cd.cd_externalizable) { + int nRes; + AVal name = AVC("DEFAULT_ATTRIBUTE"); + + RTMP_Log(RTMP_LOGDEBUG, "Externalizable, TODO check"); + + nRes = AMF3Prop_Decode(&prop, pBuffer, nSize, FALSE); + if (nRes == -1) + RTMP_Log(RTMP_LOGDEBUG, "%s, failed to decode AMF3 property!", + __FUNCTION__); + else { + nSize -= nRes; + pBuffer += nRes; + } + + AMFProp_SetName(&prop, &name); + AMF_AddProp(obj, &prop); + } else { + int nRes, i; + for (i = 0; i < cd.cd_num; i++) /* non-dynamic */ + { + nRes = AMF3Prop_Decode(&prop, pBuffer, nSize, FALSE); + if (nRes == -1) + RTMP_Log(RTMP_LOGDEBUG, "%s, failed to decode AMF3 property!", + __FUNCTION__); + + AMFProp_SetName(&prop, AMF3CD_GetProp(&cd, i)); + AMF_AddProp(obj, &prop); + + pBuffer += nRes; + nSize -= nRes; + } + if (cd.cd_dynamic) { + int len = 0; + + do { + nRes = AMF3Prop_Decode(&prop, pBuffer, nSize, TRUE); + AMF_AddProp(obj, &prop); + + pBuffer += nRes; + nSize -= nRes; + + len = prop.p_name.av_len; + } while (len > 0); + } + } + RTMP_Log(RTMP_LOGDEBUG, "class object!"); + } + return nOriginalSize - nSize; +} + +int AMF_Decode(AMFObject *obj, const char *pBuffer, int nSize, int bDecodeName) { + int nOriginalSize = nSize; + int bError = FALSE; /* if there is an error while decoding - try to at least find the end mark AMF_OBJECT_END */ + + obj->o_num = 0; + obj->o_props = NULL; + while (nSize > 0) { + AMFObjectProperty prop; + int nRes; + + if (nSize >= 3 && AMF_DecodeInt24(pBuffer) == AMF_OBJECT_END) { + nSize -= 3; + bError = FALSE; + break; + } + + if (bError) { + RTMP_Log(RTMP_LOGERROR, + "DECODING ERROR, IGNORING BYTES UNTIL NEXT KNOWN PATTERN!"); + nSize--; + pBuffer++; + continue; + } + + nRes = AMFProp_Decode(&prop, pBuffer, nSize, bDecodeName); + if (nRes == -1) + bError = TRUE; + else { + nSize -= nRes; + pBuffer += nRes; + AMF_AddProp(obj, &prop); + } + } + + if (bError) + return -1; + + return nOriginalSize - nSize; +} + +void AMF_AddProp(AMFObject *obj, const AMFObjectProperty *prop) { + if (!(obj->o_num & 0x0f)) + obj->o_props = + realloc(obj->o_props, (obj->o_num + 16) * sizeof(AMFObjectProperty)); + obj->o_props[obj->o_num++] = *prop; +} + +int AMF_CountProp(AMFObject *obj) { + return obj->o_num; +} + +AMFObjectProperty * + AMF_GetProp(AMFObject *obj, const AVal *name, int nIndex) { + if (nIndex >= 0) { + if (nIndex <= obj->o_num) + return &obj->o_props[nIndex]; + } else { + int n; + for (n = 0; n < obj->o_num; n++) { + if (AVMATCH(&obj->o_props[n].p_name, name)) + return &obj->o_props[n]; + } + } + + return (AMFObjectProperty *)&AMFProp_Invalid; +} + +void AMF_Dump(AMFObject *obj) { + int n; + RTMP_Log(RTMP_LOGDEBUG, "(object begin)"); + for (n = 0; n < obj->o_num; n++) { + AMFProp_Dump(&obj->o_props[n]); + } + RTMP_Log(RTMP_LOGDEBUG, "(object end)"); +} + +void AMF_Reset(AMFObject *obj) { + int n; + for (n = 0; n < obj->o_num; n++) { + AMFProp_Reset(&obj->o_props[n]); + } + free(obj->o_props); + obj->o_props = NULL; + obj->o_num = 0; +} + +/* AMF3ClassDefinition */ + +void AMF3CD_AddProp(AMF3ClassDef *cd, AVal *prop) { + if (!(cd->cd_num & 0x0f)) + cd->cd_props = realloc(cd->cd_props, (cd->cd_num + 16) * sizeof(AVal)); + cd->cd_props[cd->cd_num++] = *prop; +} + +AVal * + AMF3CD_GetProp(AMF3ClassDef *cd, int nIndex) { + if (nIndex >= cd->cd_num) + return (AVal *)&AV_empty; + return &cd->cd_props[nIndex]; +} diff --git a/LFLiveKit/Vendor/pili-librtmp/amf.h b/LFLiveKit/Vendor/pili-librtmp/amf.h new file mode 100644 index 00000000..77f93e84 --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/amf.h @@ -0,0 +1,180 @@ +#ifndef __AMF_H__ +#define __AMF_H__ +/* + * Copyright (C) 2005-2008 Team XBMC + * http://www.xbmc.org + * Copyright (C) 2008-2009 Andrej Stepanchuk + * Copyright (C) 2009-2010 Howard Chu + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +#include + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + AMF_NUMBER = 0, + AMF_BOOLEAN, + AMF_STRING, + AMF_OBJECT, + AMF_MOVIECLIP, /* reserved, not used */ + AMF_NULL, + AMF_UNDEFINED, + AMF_REFERENCE, + AMF_ECMA_ARRAY, + AMF_OBJECT_END, + AMF_STRICT_ARRAY, + AMF_DATE, + AMF_LONG_STRING, + AMF_UNSUPPORTED, + AMF_RECORDSET, /* reserved, not used */ + AMF_XML_DOC, + AMF_TYPED_OBJECT, + AMF_AVMPLUS, /* switch to AMF3 */ + AMF_INVALID = 0xff +} AMFDataType; + +typedef enum { + AMF3_UNDEFINED = 0, + AMF3_NULL, + AMF3_FALSE, + AMF3_TRUE, + AMF3_INTEGER, + AMF3_DOUBLE, + AMF3_STRING, + AMF3_XML_DOC, + AMF3_DATE, + AMF3_ARRAY, + AMF3_OBJECT, + AMF3_XML, + AMF3_BYTE_ARRAY +} AMF3DataType; + +typedef struct AVal { + char *av_val; + int av_len; +} AVal; +#define AVC(str) \ + { str, sizeof(str) - 1 } +#define AVMATCH(a1, a2) \ + ((a1)->av_len == (a2)->av_len && \ + !memcmp((a1)->av_val, (a2)->av_val, (a1)->av_len)) + +struct AMFObjectProperty; + +typedef struct AMFObject { + int o_num; + struct AMFObjectProperty *o_props; +} AMFObject; + +typedef struct AMFObjectProperty { + AVal p_name; + AMFDataType p_type; + union { + double p_number; + AVal p_aval; + AMFObject p_object; + } p_vu; + int16_t p_UTCoffset; +} AMFObjectProperty; + +char *AMF_EncodeString(char *output, char *outend, const AVal *str); +char *AMF_EncodeNumber(char *output, char *outend, double dVal); +char *AMF_EncodeInt16(char *output, char *outend, short nVal); +char *AMF_EncodeInt24(char *output, char *outend, int nVal); +char *AMF_EncodeInt32(char *output, char *outend, int nVal); +char *AMF_EncodeBoolean(char *output, char *outend, int bVal); + +/* Shortcuts for AMFProp_Encode */ +char *AMF_EncodeNamedString(char *output, char *outend, const AVal *name, + const AVal *value); +char *AMF_EncodeNamedNumber(char *output, char *outend, const AVal *name, + double dVal); +char *AMF_EncodeNamedBoolean(char *output, char *outend, const AVal *name, + int bVal); + +unsigned short AMF_DecodeInt16(const char *data); +unsigned int AMF_DecodeInt24(const char *data); +unsigned int AMF_DecodeInt32(const char *data); +void AMF_DecodeString(const char *data, AVal *str); +void AMF_DecodeLongString(const char *data, AVal *str); +int AMF_DecodeBoolean(const char *data); +double AMF_DecodeNumber(const char *data); + +char *AMF_Encode(AMFObject *obj, char *pBuffer, char *pBufEnd); +int AMF_Decode(AMFObject *obj, const char *pBuffer, int nSize, int bDecodeName); +int AMF_DecodeArray(AMFObject *obj, const char *pBuffer, int nSize, + int nArrayLen, int bDecodeName); +int AMF3_Decode(AMFObject *obj, const char *pBuffer, int nSize, + int bDecodeName); +void AMF_Dump(AMFObject *obj); +void AMF_Reset(AMFObject *obj); + +void AMF_AddProp(AMFObject *obj, const AMFObjectProperty *prop); +int AMF_CountProp(AMFObject *obj); +AMFObjectProperty *AMF_GetProp(AMFObject *obj, const AVal *name, int nIndex); + +AMFDataType AMFProp_GetType(AMFObjectProperty *prop); +void AMFProp_SetNumber(AMFObjectProperty *prop, double dval); +void AMFProp_SetBoolean(AMFObjectProperty *prop, int bflag); +void AMFProp_SetString(AMFObjectProperty *prop, AVal *str); +void AMFProp_SetObject(AMFObjectProperty *prop, AMFObject *obj); + +void AMFProp_GetName(AMFObjectProperty *prop, AVal *name); +void AMFProp_SetName(AMFObjectProperty *prop, AVal *name); +double AMFProp_GetNumber(AMFObjectProperty *prop); +int AMFProp_GetBoolean(AMFObjectProperty *prop); +void AMFProp_GetString(AMFObjectProperty *prop, AVal *str); +void AMFProp_GetObject(AMFObjectProperty *prop, AMFObject *obj); + +int AMFProp_IsValid(AMFObjectProperty *prop); + +char *AMFProp_Encode(AMFObjectProperty *prop, char *pBuffer, char *pBufEnd); +int AMF3Prop_Decode(AMFObjectProperty *prop, const char *pBuffer, int nSize, + int bDecodeName); +int AMFProp_Decode(AMFObjectProperty *prop, const char *pBuffer, int nSize, + int bDecodeName); + +void AMFProp_Dump(AMFObjectProperty *prop); +void AMFProp_Reset(AMFObjectProperty *prop); + +typedef struct AMF3ClassDef { + AVal cd_name; + char cd_externalizable; + char cd_dynamic; + int cd_num; + AVal *cd_props; +} AMF3ClassDef; + +void AMF3CD_AddProp(AMF3ClassDef *cd, AVal *prop); +AVal *AMF3CD_GetProp(AMF3ClassDef *cd, int idx); + +#ifdef __cplusplus +} +#endif + +#endif /* __AMF_H__ */ diff --git a/LFLiveKit/Vendor/pili-librtmp/bytes.h b/LFLiveKit/Vendor/pili-librtmp/bytes.h new file mode 100644 index 00000000..87221cf1 --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/bytes.h @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2005-2008 Team XBMC + * http://www.xbmc.org + * Copyright (C) 2008-2009 Andrej Stepanchuk + * Copyright (C) 2009-2010 Howard Chu + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +#ifndef __BYTES_H__ +#define __BYTES_H__ + +#include + +#ifdef _WIN32 +/* Windows is little endian only */ +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __BYTE_ORDER __LITTLE_ENDIAN +#define __FLOAT_WORD_ORDER __BYTE_ORDER + +typedef unsigned char uint8_t; + +#else /* !_WIN32 */ + +#include + +#if defined(BYTE_ORDER) && !defined(__BYTE_ORDER) +#define __BYTE_ORDER BYTE_ORDER +#endif + +#if defined(BIG_ENDIAN) && !defined(__BIG_ENDIAN) +#define __BIG_ENDIAN BIG_ENDIAN +#endif + +#if defined(LITTLE_ENDIAN) && !defined(__LITTLE_ENDIAN) +#define __LITTLE_ENDIAN LITTLE_ENDIAN +#endif + +#endif /* !_WIN32 */ + +/* define default endianness */ +#ifndef __LITTLE_ENDIAN +#define __LITTLE_ENDIAN 1234 +#endif + +#ifndef __BIG_ENDIAN +#define __BIG_ENDIAN 4321 +#endif + +#ifndef __BYTE_ORDER +#warning "Byte order not defined on your system, assuming little endian!" +#define __BYTE_ORDER __LITTLE_ENDIAN +#endif + +/* ok, we assume to have the same float word order and byte order if float word + * order is not defined */ +#ifndef __FLOAT_WORD_ORDER +#warning "Float word order not defined, assuming the same as byte order!" +#define __FLOAT_WORD_ORDER __BYTE_ORDER +#endif + +#if !defined(__BYTE_ORDER) || !defined(__FLOAT_WORD_ORDER) +#error "Undefined byte or float word order!" +#endif + +#if __FLOAT_WORD_ORDER != __BIG_ENDIAN && __FLOAT_WORD_ORDER != __LITTLE_ENDIAN +#error "Unknown/unsupported float word order!" +#endif + +#if __BYTE_ORDER != __BIG_ENDIAN && __BYTE_ORDER != __LITTLE_ENDIAN +#error "Unknown/unsupported byte order!" +#endif + +#endif diff --git a/LFLiveKit/Vendor/pili-librtmp/dh.h b/LFLiveKit/Vendor/pili-librtmp/dh.h new file mode 100644 index 00000000..d7aeb5a5 --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/dh.h @@ -0,0 +1,345 @@ +/* RTMPDump - Diffie-Hellmann Key Exchange + * Copyright (C) 2009 Andrej Stepanchuk + * Copyright (C) 2009-2010 Howard Chu + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +#include +#include +#include +#include +#include + +#ifdef USE_POLARSSL +#include +typedef mpi *MP_t; +#define MP_new(m) \ + m = malloc(sizeof(mpi)); \ + mpi_init(m, NULL) +#define MP_set_w(mpi, w) mpi_lset(mpi, w) +#define MP_cmp(u, v) mpi_cmp_mpi(u, v) +#define MP_set(u, v) mpi_copy(u, v) +#define MP_sub_w(mpi, w) mpi_sub_int(mpi, mpi, w) +#define MP_cmp_1(mpi) mpi_cmp_int(mpi, 1) +#define MP_modexp(r, y, q, p) mpi_exp_mod(r, y, q, p, NULL) +#define MP_free(mpi) \ + mpi_free(mpi, NULL); \ + free(mpi) +#define MP_gethex(u, hex, res) \ + MP_new(u); \ + res = mpi_read_string(u, 16, hex) == 0 +#define MP_bytes(u) mpi_size(u) +#define MP_setbin(u, buf, len) mpi_write_binary(u, buf, len) +#define MP_getbin(u, buf, len) \ + MP_new(u); \ + mpi_read_binary(u, buf, len) + +typedef struct MDH { + MP_t p; + MP_t g; + MP_t pub_key; + MP_t priv_key; + long length; + dhm_context ctx; +} MDH; + +#define MDH_new() calloc(1, sizeof(MDH)) +#define MDH_free(vp) \ + { \ + MDH *dh = vp; \ + dhm_free(&dh->ctx); \ + MP_free(dh->p); \ + MP_free(dh->g); \ + MP_free(dh->pub_key); \ + MP_free(dh->priv_key); \ + free(dh); \ + } + +static int MDH_generate_key(MDH *dh) { + unsigned char out[2]; + MP_set(&dh->ctx.P, dh->p); + MP_set(&dh->ctx.G, dh->g); + dh->ctx.len = 128; + dhm_make_public(&dh->ctx, 1024, out, 1, havege_rand, &RTMP_TLS_ctx->hs); + MP_new(dh->pub_key); + MP_new(dh->priv_key); + MP_set(dh->pub_key, &dh->ctx.GX); + MP_set(dh->priv_key, &dh->ctx.X); + return 1; +} + +static int MDH_compute_key(uint8_t *secret, size_t len, MP_t pub, MDH *dh) { + int n = len; + MP_set(&dh->ctx.GY, pub); + dhm_calc_secret(&dh->ctx, secret, &n); + return 0; +} + +#elif defined(USE_GNUTLS) +#include +typedef gcry_mpi_t MP_t; +#define MP_new(m) m = gcry_mpi_new(1) +#define MP_set_w(mpi, w) gcry_mpi_set_ui(mpi, w) +#define MP_cmp(u, v) gcry_mpi_cmp(u, v) +#define MP_set(u, v) gcry_mpi_set(u, v) +#define MP_sub_w(mpi, w) gcry_mpi_sub_ui(mpi, mpi, w) +#define MP_cmp_1(mpi) gcry_mpi_cmp_ui(mpi, 1) +#define MP_modexp(r, y, q, p) gcry_mpi_powm(r, y, q, p) +#define MP_free(mpi) gcry_mpi_release(mpi) +#define MP_gethex(u, hex, res) \ + res = (gcry_mpi_scan(&u, GCRYMPI_FMT_HEX, hex, 0, 0) == 0) +#define MP_bytes(u) (gcry_mpi_get_nbits(u) + 7) / 8 +#define MP_setbin(u, buf, len) \ + gcry_mpi_print(GCRYMPI_FMT_USG, buf, len, NULL, u) +#define MP_getbin(u, buf, len) \ + gcry_mpi_scan(&u, GCRYMPI_FMT_USG, buf, len, NULL) + +typedef struct MDH { + MP_t p; + MP_t g; + MP_t pub_key; + MP_t priv_key; + long length; +} MDH; + +#define MDH_new() calloc(1, sizeof(MDH)) +#define MDH_free(dh) \ + do { \ + MP_free(((MDH *)(dh))->p); \ + MP_free(((MDH *)(dh))->g); \ + MP_free(((MDH *)(dh))->pub_key); \ + MP_free(((MDH *)(dh))->priv_key); \ + free(dh); \ + } while (0) + +extern MP_t gnutls_calc_dh_secret(MP_t *priv, MP_t g, MP_t p); +extern MP_t gnutls_calc_dh_key(MP_t y, MP_t x, MP_t p); + +#define MDH_generate_key(dh) \ + (dh->pub_key = gnutls_calc_dh_secret(&dh->priv_key, dh->g, dh->p)) +static int MDH_compute_key(uint8_t *secret, size_t len, MP_t pub, MDH *dh) { + MP_t sec = gnutls_calc_dh_key(pub, dh->priv_key, dh->p); + if (sec) { + MP_setbin(sec, secret, len); + MP_free(sec); + return 0; + } else + return -1; +} + +#else /* USE_OPENSSL */ +#include +#include + +typedef BIGNUM *MP_t; +#define MP_new(m) m = BN_new() +#define MP_set_w(mpi, w) BN_set_word(mpi, w) +#define MP_cmp(u, v) BN_cmp(u, v) +#define MP_set(u, v) BN_copy(u, v) +#define MP_sub_w(mpi, w) BN_sub_word(mpi, w) +#define MP_cmp_1(mpi) BN_cmp(mpi, BN_value_one()) +#define MP_modexp(r, y, q, p) \ + do { \ + BN_CTX *ctx = BN_CTX_new(); \ + BN_mod_exp(r, y, q, p, ctx); \ + BN_CTX_free(ctx); \ + } while (0) +#define MP_free(mpi) BN_free(mpi) +#define MP_gethex(u, hex, res) res = BN_hex2bn(&u, hex) +#define MP_bytes(u) BN_num_bytes(u) +#define MP_setbin(u, buf, len) BN_bn2bin(u, buf) +#define MP_getbin(u, buf, len) u = BN_bin2bn(buf, len, 0) + +#define MDH DH +#define MDH_new() DH_new() +#define MDH_free(dh) DH_free(dh) +#define MDH_generate_key(dh) DH_generate_key(dh) +#define MDH_compute_key(secret, seclen, pub, dh) DH_compute_key(secret, pub, dh) + +#endif + +#include "dhgroups.h" +#include "log.h" + +/* RFC 2631, Section 2.1.5, http://www.ietf.org/rfc/rfc2631.txt */ +static int isValidPublicKey(MP_t y, MP_t p, MP_t q) { + int ret = TRUE; + MP_t bn; + assert(y); + + MP_new(bn); + assert(bn); + + /* y must lie in [2,p-1] */ + MP_set_w(bn, 1); + if (MP_cmp(y, bn) < 0) { + RTMP_Log(RTMP_LOGERROR, "DH public key must be at least 2"); + ret = FALSE; + goto failed; + } + + /* bn = p-2 */ + MP_set(bn, p); + MP_sub_w(bn, 1); + if (MP_cmp(y, bn) > 0) { + RTMP_Log(RTMP_LOGERROR, "DH public key must be at most p-2"); + ret = FALSE; + goto failed; + } + + /* Verify with Sophie-Germain prime + * + * This is a nice test to make sure the public key position is calculated + * correctly. This test will fail in about 50% of the cases if applied to + * random data. + */ + if (q) { + /* y must fulfill y^q mod p = 1 */ + MP_modexp(bn, y, q, p); + + if (MP_cmp_1(bn) != 0) { + RTMP_Log(RTMP_LOGWARNING, "DH public key does not fulfill y^q mod p = 1"); + } + } + +failed: + MP_free(bn); + return ret; +} + +static MDH *DHInit(int nKeyBits) { + size_t res; + MDH *dh = MDH_new(); + + if (!dh) + goto failed; + + MP_new(dh->g); + + if (!dh->g) + goto failed; + + MP_gethex(dh->p, P1024, res); /* prime P1024, see dhgroups.h */ + if (!res) { + goto failed; + } + + MP_set_w(dh->g, 2); /* base 2 */ + + dh->length = nKeyBits; + return dh; + +failed: + if (dh) + MDH_free(dh); + + return 0; +} + +static int DHGenerateKey(MDH *dh) { + size_t res = 0; + if (!dh) + return 0; + + while (!res) { + MP_t q1 = NULL; + + if (!MDH_generate_key(dh)) + return 0; + + MP_gethex(q1, Q1024, res); + assert(res); + + res = isValidPublicKey(dh->pub_key, dh->p, q1); + if (!res) { + MP_free(dh->pub_key); + MP_free(dh->priv_key); + dh->pub_key = dh->priv_key = 0; + } + + MP_free(q1); + } + return 1; +} + +/* fill pubkey with the public key in BIG ENDIAN order + * 00 00 00 00 00 x1 x2 x3 ..... + */ + +static int DHGetPublicKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen) { + int len; + if (!dh || !dh->pub_key) + return 0; + + len = MP_bytes(dh->pub_key); + if (len <= 0 || len > (int)nPubkeyLen) + return 0; + + memset(pubkey, 0, nPubkeyLen); + MP_setbin(dh->pub_key, pubkey + (nPubkeyLen - len), len); + return 1; +} + +#if 0 /* unused */ +static int +DHGetPrivateKey(MDH *dh, uint8_t *privkey, size_t nPrivkeyLen) +{ + if (!dh || !dh->priv_key) + return 0; + + int len = MP_bytes(dh->priv_key); + if (len <= 0 || len > (int) nPrivkeyLen) + return 0; + + memset(privkey, 0, nPrivkeyLen); + MP_setbin(dh->priv_key, privkey + (nPrivkeyLen - len), len); + return 1; +} +#endif + +/* computes the shared secret key from the private MDH value and the + * other party's public key (pubkey) + */ +static int DHComputeSharedSecretKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen, + uint8_t *secret) { + MP_t q1 = NULL, pubkeyBn = NULL; + size_t len; + int res; + + if (!dh || !secret || nPubkeyLen >= INT_MAX) + return -1; + + MP_getbin(pubkeyBn, pubkey, nPubkeyLen); + if (!pubkeyBn) + return -1; + + MP_gethex(q1, Q1024, len); + assert(len); + + if (isValidPublicKey(pubkeyBn, dh->p, q1)) + res = MDH_compute_key(secret, nPubkeyLen, pubkeyBn, dh); + else + res = -1; + + MP_free(q1); + MP_free(pubkeyBn); + + return res; +} diff --git a/LFLiveKit/Vendor/pili-librtmp/dhgroups.h b/LFLiveKit/Vendor/pili-librtmp/dhgroups.h new file mode 100644 index 00000000..f3d0293f --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/dhgroups.h @@ -0,0 +1,198 @@ +/* librtmp - Diffie-Hellmann Key Exchange + * Copyright (C) 2009 Andrej Stepanchuk + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +/* from RFC 3526, see http://www.ietf.org/rfc/rfc3526.txt */ + +/* 2^768 - 2 ^704 - 1 + 2^64 * { [2^638 pi] + 149686 } */ +#define P768 \ + "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ + "E485B576625E7EC6F44C42E9A63A3620FFFFFFFFFFFFFFFF" + +/* 2^1024 - 2^960 - 1 + 2^64 * { [2^894 pi] + 129093 } */ +#define P1024 \ + "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381" \ + "FFFFFFFFFFFFFFFF" + +/* Group morder largest prime factor: */ +#define Q1024 \ + "7FFFFFFFFFFFFFFFE487ED5110B4611A62633145C06E0E68" \ + "948127044533E63A0105DF531D89CD9128A5043CC71A026E" \ + "F7CA8CD9E69D218D98158536F92F8A1BA7F09AB6B6A8E122" \ + "F242DABB312F3F637A262174D31BF6B585FFAE5B7A035BF6" \ + "F71C35FDAD44CFD2D74F9208BE258FF324943328F67329C0" \ + "FFFFFFFFFFFFFFFF" + +/* 2^1536 - 2^1472 - 1 + 2^64 * { [2^1406 pi] + 741804 } */ +#define P1536 \ + "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \ + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \ + "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \ + "670C354E4ABC9804F1746C08CA237327FFFFFFFFFFFFFFFF" + +/* 2^2048 - 2^1984 - 1 + 2^64 * { [2^1918 pi] + 124476 } */ +#define P2048 \ + "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \ + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \ + "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \ + "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \ + "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \ + "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \ + "15728E5A8AACAA68FFFFFFFFFFFFFFFF" + +/* 2^3072 - 2^3008 - 1 + 2^64 * { [2^2942 pi] + 1690314 } */ +#define P3072 \ + "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \ + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \ + "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \ + "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \ + "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \ + "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \ + "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \ + "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \ + "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \ + "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \ + "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \ + "43DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF" + +/* 2^4096 - 2^4032 - 1 + 2^64 * { [2^3966 pi] + 240904 } */ +#define P4096 \ + "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \ + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \ + "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \ + "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \ + "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \ + "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \ + "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \ + "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \ + "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \ + "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \ + "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \ + "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" \ + "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" \ + "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" \ + "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" \ + "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" \ + "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934063199" \ + "FFFFFFFFFFFFFFFF" + +/* 2^6144 - 2^6080 - 1 + 2^64 * { [2^6014 pi] + 929484 } */ +#define P6144 \ + "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \ + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \ + "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \ + "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \ + "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \ + "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \ + "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \ + "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \ + "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \ + "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \ + "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \ + "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" \ + "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" \ + "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" \ + "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" \ + "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" \ + "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934028492" \ + "36C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BD" \ + "F8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831" \ + "179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1B" \ + "DB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF" \ + "5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6" \ + "D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F3" \ + "23A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA" \ + "CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE328" \ + "06A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55C" \ + "DA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE" \ + "12BF2D5B0B7474D6E694F91E6DCC4024FFFFFFFFFFFFFFFF" + +/* 2^8192 - 2^8128 - 1 + 2^64 * { [2^8062 pi] + 4743158 } */ +#define P8192 \ + "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD1" \ + "29024E088A67CC74020BBEA63B139B22514A08798E3404DD" \ + "EF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245" \ + "E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7ED" \ + "EE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3D" \ + "C2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F" \ + "83655D23DCA3AD961C62F356208552BB9ED529077096966D" \ + "670C354E4ABC9804F1746C08CA18217C32905E462E36CE3B" \ + "E39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9" \ + "DE2BCBF6955817183995497CEA956AE515D2261898FA0510" \ + "15728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64" \ + "ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7" \ + "ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6B" \ + "F12FFA06D98A0864D87602733EC86A64521F2B18177B200C" \ + "BBE117577A615D6C770988C0BAD946E208E24FA074E5AB31" \ + "43DB5BFCE0FD108E4B82D120A92108011A723C12A787E6D7" \ + "88719A10BDBA5B2699C327186AF4E23C1A946834B6150BDA" \ + "2583E9CA2AD44CE8DBBBC2DB04DE8EF92E8EFC141FBECAA6" \ + "287C59474E6BC05D99B2964FA090C3A2233BA186515BE7ED" \ + "1F612970CEE2D7AFB81BDD762170481CD0069127D5B05AA9" \ + "93B4EA988D8FDDC186FFB7DC90A6C08F4DF435C934028492" \ + "36C3FAB4D27C7026C1D4DCB2602646DEC9751E763DBA37BD" \ + "F8FF9406AD9E530EE5DB382F413001AEB06A53ED9027D831" \ + "179727B0865A8918DA3EDBEBCF9B14ED44CE6CBACED4BB1B" \ + "DB7F1447E6CC254B332051512BD7AF426FB8F401378CD2BF" \ + "5983CA01C64B92ECF032EA15D1721D03F482D7CE6E74FEF6" \ + "D55E702F46980C82B5A84031900B1C9E59E7C97FBEC7E8F3" \ + "23A97A7E36CC88BE0F1D45B7FF585AC54BD407B22B4154AA" \ + "CC8F6D7EBF48E1D814CC5ED20F8037E0A79715EEF29BE328" \ + "06A1D58BB7C5DA76F550AA3D8A1FBFF0EB19CCB1A313D55C" \ + "DA56C9EC2EF29632387FE8D76E3C0468043E8F663F4860EE" \ + "12BF2D5B0B7474D6E694F91E6DBE115974A3926F12FEE5E4" \ + "38777CB6A932DF8CD8BEC4D073B931BA3BC832B68D9DD300" \ + "741FA7BF8AFC47ED2576F6936BA424663AAB639C5AE4F568" \ + "3423B4742BF1C978238F16CBE39D652DE3FDB8BEFC848AD9" \ + "22222E04A4037C0713EB57A81A23F0C73473FC646CEA306B" \ + "4BCBC8862F8385DDFA9D4B7FA2C087E879683303ED5BDD3A" \ + "062B3CF5B3A278A66D2A13F83F44F82DDF310EE074AB6A36" \ + "4597E899A0255DC164F31CC50846851DF9AB48195DED7EA1" \ + "B1D510BD7EE74D73FAF36BC31ECFA268359046F4EB879F92" \ + "4009438B481C6CD7889A002ED5EE382BC9190DA6FC026E47" \ + "9558E4475677E9AA9E3050E2765694DFC81F56E880B96E71" \ + "60C980DD98EDD3DFFFFFFFFFFFFFFFFF" diff --git a/LFLiveKit/Vendor/pili-librtmp/error.c b/LFLiveKit/Vendor/pili-librtmp/error.c new file mode 100644 index 00000000..0b4cafdf --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/error.c @@ -0,0 +1,20 @@ +#include "error.h" +#include +#include + +void RTMPError_Alloc(RTMPError *error, size_t msg_size) { + RTMPError_Free(error); + + error->code = 0; + error->message = (char *)malloc(msg_size + 1); + memset(error->message, 0, msg_size); +} + +void RTMPError_Free(RTMPError *error) { + if (error) { + if (error->message) { + free(error->message); + error->message = NULL; + } + } +} diff --git a/LFLiveKit/Vendor/pili-librtmp/error.h b/LFLiveKit/Vendor/pili-librtmp/error.h new file mode 100644 index 00000000..4ec31fda --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/error.h @@ -0,0 +1,45 @@ +#ifndef __ERROR_H__ +#define __ERROR_H__ + +#include + +typedef struct RTMPError { + int code; + char *message; +} RTMPError; + +void RTMPError_Alloc(RTMPError *error, size_t msg_size); +void RTMPError_Free(RTMPError *error); + +// error defines +enum { + RTMPErrorUnknow = -1, // "Unknow error" + RTMPErrorUnknowOption = -999, // "Unknown option %s" + RTMPErrorAccessDNSFailed = -1000, // "Failed to access the DNS. (addr: %s)" + RTMPErrorFailedToConnectSocket = + -1001, // "Failed to connect socket. %d (%s)" + RTMPErrorSocksNegotiationFailed = -1002, // "Socks negotiation failed" + RTMPErrorFailedToCreateSocket = + -1003, // "Failed to create socket. %d (%s)" + RTMPErrorHandshakeFailed = -1004, // "Handshake failed" + RTMPErrorRTMPConnectFailed = -1005, // "RTMP connect failed" + RTMPErrorSendFailed = -1006, // "Send error %d (%s), (%d bytes)" + RTMPErrorServerRequestedClose = -1007, // "RTMP server requested close" + RTMPErrorNetStreamFailed = -1008, // "NetStream failed" + RTMPErrorNetStreamPlayFailed = -1009, // "NetStream play failed" + RTMPErrorNetStreamPlayStreamNotFound = + -1010, // "NetStream play stream not found" + RTMPErrorNetConnectionConnectInvalidApp = + -1011, // "NetConnection connect invalip app" + RTMPErrorSanityFailed = + -1012, // "Sanity failed. Trying to send header of type: 0x%02X" + RTMPErrorSocketClosedByPeer = -1013, // "RTMP socket closed by peer" + RTMPErrorRTMPConnectStreamFailed = -1014, // "RTMP connect stream failed" + RTMPErrorSocketTimeout = -1015, // "RTMP socket timeout" + + // SSL errors + RTMPErrorTLSConnectFailed = -1200, // "TLS_Connect failed" + RTMPErrorNoSSLOrTLSSupport = -1201, // "No SSL/TLS support" +}; + +#endif diff --git a/LFLiveKit/Vendor/pili-librtmp/handshake.h b/LFLiveKit/Vendor/pili-librtmp/handshake.h new file mode 100644 index 00000000..f791cf74 --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/handshake.h @@ -0,0 +1,1034 @@ +/* + * Copyright (C) 2008-2009 Andrej Stepanchuk + * Copyright (C) 2009-2010 Howard Chu + * Copyright (C) 2010 + * 2a665470ced7adb7156fcef47f8199a6371c117b8a79e399a2771e0b36384090 + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +/* This file is #included in rtmp.c, it is not meant to be compiled alone */ + +#ifdef USE_POLARSSL +#include +#include +#ifndef SHA256_DIGEST_LENGTH +#define SHA256_DIGEST_LENGTH 32 +#endif +#define HMAC_CTX sha2_context +#define HMAC_setup(ctx, key, len) \ + sha2_hmac_starts(&ctx, (unsigned char *)key, len, 0) +#define HMAC_crunch(ctx, buf, len) sha2_hmac_update(&ctx, buf, len) +#define HMAC_finish(ctx, dig, dlen) \ + dlen = SHA256_DIGEST_LENGTH; \ + sha2_hmac_finish(&ctx, dig) + +typedef arc4_context *RC4_handle; +#define RC4_alloc(h) *h = malloc(sizeof(arc4_context)) +#define RC4_setkey(h, l, k) arc4_setup(h, k, l) +#define RC4_encrypt(h, l, d) \ + arc4_crypt(h, l, (unsigned char *)d, (unsigned char *)d) +#define RC4_encrypt2(h, l, s, d) \ + arc4_crypt(h, l, (unsigned char *)s, (unsigned char *)d) +#define RC4_free(h) free(h) + +#elif defined(USE_GNUTLS) +#include +#ifndef SHA256_DIGEST_LENGTH +#define SHA256_DIGEST_LENGTH 32 +#endif +#define HMAC_CTX gcry_md_hd_t +#define HMAC_setup(ctx, key, len) \ + gcry_md_open(&ctx, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC); \ + gcry_md_setkey(ctx, key, len) +#define HMAC_crunch(ctx, buf, len) gcry_md_write(ctx, buf, len) +#define HMAC_finish(ctx, dig, dlen) \ + dlen = SHA256_DIGEST_LENGTH; \ + memcpy(dig, gcry_md_read(ctx, 0), dlen); \ + gcry_md_close(ctx) + +typedef gcry_cipher_hd_t RC4_handle; +#define RC4_alloc(h) \ + gcry_cipher_open(h, GCRY_CIPHER_ARCFOUR, GCRY_CIPHER_MODE_STREAM, 0) +#define RC4_setkey(h, l, k) gcry_cipher_setkey(h, k, l) +#define RC4_encrypt(h, l, d) gcry_cipher_encrypt(h, (void *)d, l, NULL, 0) +#define RC4_encrypt2(h, l, s, d) \ + gcry_cipher_encrypt(h, (void *)d, l, (void *)s, l) +#define RC4_free(h) gcry_cipher_close(h) + +#else /* USE_OPENSSL */ +#include +#include +#include +#if OPENSSL_VERSION_NUMBER < 0x0090800 || !defined(SHA256_DIGEST_LENGTH) +#error Your OpenSSL is too old, need 0.9.8 or newer with SHA256 +#endif +#define HMAC_setup(ctx, key, len) \ + HMAC_CTX_init(&ctx); \ + HMAC_Init_ex(&ctx, key, len, EVP_sha256(), 0) +#define HMAC_crunch(ctx, buf, len) HMAC_Update(&ctx, buf, len) +#define HMAC_finish(ctx, dig, dlen) \ + HMAC_Final(&ctx, dig, &dlen); \ + HMAC_CTX_cleanup(&ctx) + +typedef RC4_KEY *RC4_handle; +#define RC4_alloc(h) *h = malloc(sizeof(RC4_KEY)) +#define RC4_setkey(h, l, k) RC4_set_key(h, l, k) +#define RC4_encrypt(h, l, d) RC4(h, l, (uint8_t *)d, (uint8_t *)d) +#define RC4_encrypt2(h, l, s, d) RC4(h, l, (uint8_t *)s, (uint8_t *)d) +#define RC4_free(h) free(h) +#endif + +#define FP10 + +#include "dh.h" + +static const uint8_t GenuineFMSKey[] = { + 0x47, 0x65, 0x6e, 0x75, 0x69, 0x6e, 0x65, 0x20, 0x41, 0x64, 0x6f, + 0x62, 0x65, 0x20, 0x46, 0x6c, 0x61, 0x73, 0x68, 0x20, 0x4d, 0x65, + 0x64, 0x69, 0x61, 0x20, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x20, + 0x30, 0x30, 0x31, /* Genuine Adobe Flash Media Server 001 */ + + 0xf0, 0xee, 0xc2, 0x4a, 0x80, 0x68, 0xbe, 0xe8, 0x2e, 0x00, 0xd0, + 0xd1, 0x02, 0x9e, 0x7e, 0x57, 0x6e, 0xec, 0x5d, 0x2d, 0x29, 0x80, + 0x6f, 0xab, 0x93, 0xb8, 0xe6, 0x36, 0xcf, 0xeb, 0x31, 0xae}; /* 68 */ + +static const uint8_t GenuineFPKey[] = { + 0x47, 0x65, 0x6E, 0x75, 0x69, 0x6E, 0x65, 0x20, 0x41, 0x64, 0x6F, + 0x62, 0x65, 0x20, 0x46, 0x6C, 0x61, 0x73, 0x68, 0x20, 0x50, 0x6C, + 0x61, 0x79, 0x65, 0x72, 0x20, 0x30, 0x30, 0x31, /* Genuine Adobe Flash + Player 001 */ + 0xF0, 0xEE, 0xC2, 0x4A, 0x80, 0x68, 0xBE, 0xE8, 0x2E, 0x00, 0xD0, + 0xD1, 0x02, 0x9E, 0x7E, 0x57, 0x6E, 0xEC, 0x5D, 0x2D, 0x29, 0x80, + 0x6F, 0xAB, 0x93, 0xB8, 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE}; /* 62 */ + +static void InitRC4Encryption(uint8_t *secretKey, uint8_t *pubKeyIn, + uint8_t *pubKeyOut, RC4_handle *rc4keyIn, + RC4_handle *rc4keyOut) { + uint8_t digest[SHA256_DIGEST_LENGTH]; + unsigned int digestLen = 0; + HMAC_CTX ctx; + + RC4_alloc(rc4keyIn); + RC4_alloc(rc4keyOut); + + HMAC_setup(ctx, secretKey, 128); + HMAC_crunch(ctx, pubKeyIn, 128); + HMAC_finish(ctx, digest, digestLen); + + RTMP_Log(RTMP_LOGDEBUG, "RC4 Out Key: "); + RTMP_LogHex(RTMP_LOGDEBUG, digest, 16); + + RC4_setkey(*rc4keyOut, 16, digest); + + HMAC_setup(ctx, secretKey, 128); + HMAC_crunch(ctx, pubKeyOut, 128); + HMAC_finish(ctx, digest, digestLen); + + RTMP_Log(RTMP_LOGDEBUG, "RC4 In Key: "); + RTMP_LogHex(RTMP_LOGDEBUG, digest, 16); + + RC4_setkey(*rc4keyIn, 16, digest); +} + +typedef unsigned int(getoff)(uint8_t *buf, unsigned int len); + +static unsigned int GetDHOffset2(uint8_t *handshake, unsigned int len) { + unsigned int offset = 0; + uint8_t *ptr = handshake + 768; + unsigned int res; + + assert(RTMP_SIG_SIZE <= len); + + offset += (*ptr); + ptr++; + offset += (*ptr); + ptr++; + offset += (*ptr); + ptr++; + offset += (*ptr); + + res = (offset % 632) + 8; + + if (res + 128 > 767) { + RTMP_Log(RTMP_LOGERROR, + "%s: Couldn't calculate correct DH offset (got %d), exiting!", + __FUNCTION__, res); + exit(1); + } + return res; +} + +static unsigned int GetDigestOffset2(uint8_t *handshake, unsigned int len) { + unsigned int offset = 0; + uint8_t *ptr = handshake + 772; + unsigned int res; + + offset += (*ptr); + ptr++; + offset += (*ptr); + ptr++; + offset += (*ptr); + ptr++; + offset += (*ptr); + + res = (offset % 728) + 776; + + if (res + 32 > 1535) { + RTMP_Log(RTMP_LOGERROR, + "%s: Couldn't calculate correct digest offset (got %d), exiting", + __FUNCTION__, res); + exit(1); + } + return res; +} + +static unsigned int GetDHOffset1(uint8_t *handshake, unsigned int len) { + unsigned int offset = 0; + uint8_t *ptr = handshake + 1532; + unsigned int res; + + assert(RTMP_SIG_SIZE <= len); + + offset += (*ptr); + ptr++; + offset += (*ptr); + ptr++; + offset += (*ptr); + ptr++; + offset += (*ptr); + + res = (offset % 632) + 772; + + if (res + 128 > 1531) { + RTMP_Log(RTMP_LOGERROR, + "%s: Couldn't calculate DH offset (got %d), exiting!", + __FUNCTION__, res); + exit(1); + } + + return res; +} + +static unsigned int GetDigestOffset1(uint8_t *handshake, unsigned int len) { + unsigned int offset = 0; + uint8_t *ptr = handshake + 8; + unsigned int res; + + assert(12 <= len); + + offset += (*ptr); + ptr++; + offset += (*ptr); + ptr++; + offset += (*ptr); + ptr++; + offset += (*ptr); + + res = (offset % 728) + 12; + + if (res + 32 > 771) { + RTMP_Log(RTMP_LOGERROR, + "%s: Couldn't calculate digest offset (got %d), exiting!", + __FUNCTION__, res); + exit(1); + } + + return res; +} + +static getoff *digoff[] = {GetDigestOffset1, GetDigestOffset2}; +static getoff *dhoff[] = {GetDHOffset1, GetDHOffset2}; + +static void HMACsha256(const uint8_t *message, size_t messageLen, + const uint8_t *key, size_t keylen, uint8_t *digest) { + unsigned int digestLen; + HMAC_CTX ctx; + + HMAC_setup(ctx, key, keylen); + HMAC_crunch(ctx, message, messageLen); + HMAC_finish(ctx, digest, digestLen); + + assert(digestLen == 32); +} + +static void CalculateDigest(unsigned int digestPos, uint8_t *handshakeMessage, + const uint8_t *key, size_t keyLen, + uint8_t *digest) { + const int messageLen = RTMP_SIG_SIZE - SHA256_DIGEST_LENGTH; + uint8_t message[RTMP_SIG_SIZE - SHA256_DIGEST_LENGTH]; + + memcpy(message, handshakeMessage, digestPos); + memcpy(message + digestPos, + &handshakeMessage[digestPos + SHA256_DIGEST_LENGTH], + messageLen - digestPos); + + HMACsha256(message, messageLen, key, keyLen, digest); +} + +static int VerifyDigest(unsigned int digestPos, uint8_t *handshakeMessage, + const uint8_t *key, size_t keyLen) { + uint8_t calcDigest[SHA256_DIGEST_LENGTH]; + + CalculateDigest(digestPos, handshakeMessage, key, keyLen, calcDigest); + + return memcmp(&handshakeMessage[digestPos], calcDigest, + SHA256_DIGEST_LENGTH) == 0; +} + +/* handshake + * + * Type = [1 bytes] plain: 0x03, encrypted: 0x06, 0x08, 0x09 + * -------------------------------------------------------------------- [1536 + * bytes] + * Uptime = [4 bytes] big endian unsigned number, uptime + * Version = [4 bytes] each byte represents a version number, e.g. + * 9.0.124.0 + * ... + * + */ + +static const uint32_t rtmpe8_keys[16][4] = { + {0xbff034b2, 0x11d9081f, 0xccdfb795, 0x748de732}, + {0x086a5eb6, 0x1743090e, 0x6ef05ab8, 0xfe5a39e2}, + {0x7b10956f, 0x76ce0521, 0x2388a73a, 0x440149a1}, + {0xa943f317, 0xebf11bb2, 0xa691a5ee, 0x17f36339}, + {0x7a30e00a, 0xb529e22c, 0xa087aea5, 0xc0cb79ac}, + {0xbdce0c23, 0x2febdeff, 0x1cfaae16, 0x1123239d}, + {0x55dd3f7b, 0x77e7e62e, 0x9bb8c499, 0xc9481ee4}, + {0x407bb6b4, 0x71e89136, 0xa7aebf55, 0xca33b839}, + {0xfcf6bdc3, 0xb63c3697, 0x7ce4f825, 0x04d959b2}, + {0x28e091fd, 0x41954c4c, 0x7fb7db00, 0xe3a066f8}, + {0x57845b76, 0x4f251b03, 0x46d45bcd, 0xa2c30d29}, + {0x0acceef8, 0xda55b546, 0x03473452, 0x5863713b}, + {0xb82075dc, 0xa75f1fee, 0xd84268e8, 0xa72a44cc}, + {0x07cf6e9e, 0xa16d7b25, 0x9fa7ae6c, 0xd92f5629}, + {0xfeb1eae4, 0x8c8c3ce1, 0x4e0064a7, 0x6a387c2a}, + {0x893a9427, 0xcc3013a2, 0xf106385b, 0xa829f927}}; + +/* RTMPE type 8 uses XTEA on the regular signature + * http://en.wikipedia.org/wiki/XTEA + */ +static void rtmpe8_sig(uint8_t *in, uint8_t *out, int keyid) { + unsigned int i, num_rounds = 32; + uint32_t v0, v1, sum = 0, delta = 0x9E3779B9; + uint32_t const *k; + + v0 = in[0] | (in[1] << 8) | (in[2] << 16) | (in[3] << 24); + v1 = in[4] | (in[5] << 8) | (in[6] << 16) | (in[7] << 24); + k = rtmpe8_keys[keyid]; + + for (i = 0; i < num_rounds; i++) { + v0 += (((v1 << 4) ^ (v1 >> 5)) + v1) ^ (sum + k[sum & 3]); + sum += delta; + v1 += (((v0 << 4) ^ (v0 >> 5)) + v0) ^ (sum + k[(sum >> 11) & 3]); + } + + out[0] = v0; + v0 >>= 8; + out[1] = v0; + v0 >>= 8; + out[2] = v0; + v0 >>= 8; + out[3] = v0; + + out[4] = v1; + v1 >>= 8; + out[5] = v1; + v1 >>= 8; + out[6] = v1; + v1 >>= 8; + out[7] = v1; +} + +static int HandShake(RTMP *r, int FP9HandShake) { + int i, offalg = 0; + int dhposClient = 0; + int digestPosClient = 0; + int encrypted = r->Link.protocol & RTMP_FEATURE_ENC; + + RC4_handle keyIn = 0; + RC4_handle keyOut = 0; + + int32_t *ip; + uint32_t uptime; + + uint8_t clientbuf[RTMP_SIG_SIZE + 4], *clientsig = clientbuf + 4; + uint8_t serversig[RTMP_SIG_SIZE], client2[RTMP_SIG_SIZE], *reply; + uint8_t type; + getoff *getdh = NULL, *getdig = NULL; + + if (encrypted || r->Link.SWFSize) + FP9HandShake = TRUE; + else + FP9HandShake = FALSE; + + r->Link.rc4keyIn = r->Link.rc4keyOut = 0; + + if (encrypted) { + clientsig[-1] = 0x06; /* 0x08 is RTMPE as well */ + offalg = 1; + } else + clientsig[-1] = 0x03; + + uptime = htonl(RTMP_GetTime()); + memcpy(clientsig, &uptime, 4); + + if (FP9HandShake) { + /* set version to at least 9.0.115.0 */ + if (encrypted) { + clientsig[4] = 128; + clientsig[6] = 3; + } else { + clientsig[4] = 10; + clientsig[6] = 45; + } + clientsig[5] = 0; + clientsig[7] = 2; + + RTMP_Log(RTMP_LOGDEBUG, "%s: Client type: %02X", __FUNCTION__, + clientsig[-1]); + getdig = digoff[offalg]; + getdh = dhoff[offalg]; + } else { + memset(&clientsig[4], 0, 4); + } + +/* generate random data */ +#ifdef _DEBUG + memset(clientsig + 8, 0, RTMP_SIG_SIZE - 8); +#else + ip = (int32_t *)(clientsig + 8); + for (i = 2; i < RTMP_SIG_SIZE / 4; i++) + *ip++ = rand(); +#endif + + /* set handshake digest */ + if (FP9HandShake) { + if (encrypted) { + /* generate Diffie-Hellmann parameters */ + r->Link.dh = DHInit(1024); + if (!r->Link.dh) { + RTMP_Log(RTMP_LOGERROR, "%s: Couldn't initialize Diffie-Hellmann!", + __FUNCTION__); + return FALSE; + } + + dhposClient = getdh(clientsig, RTMP_SIG_SIZE); + RTMP_Log(RTMP_LOGDEBUG, "%s: DH pubkey position: %d", __FUNCTION__, + dhposClient); + + if (!DHGenerateKey(r->Link.dh)) { + RTMP_Log(RTMP_LOGERROR, + "%s: Couldn't generate Diffie-Hellmann public key!", + __FUNCTION__); + return FALSE; + } + + if (!DHGetPublicKey(r->Link.dh, &clientsig[dhposClient], 128)) { + RTMP_Log(RTMP_LOGERROR, "%s: Couldn't write public key!", __FUNCTION__); + return FALSE; + } + } + + digestPosClient = + getdig(clientsig, RTMP_SIG_SIZE); /* reuse this value in verification */ + RTMP_Log(RTMP_LOGDEBUG, "%s: Client digest offset: %d", __FUNCTION__, + digestPosClient); + + CalculateDigest(digestPosClient, clientsig, GenuineFPKey, 30, + &clientsig[digestPosClient]); + + RTMP_Log(RTMP_LOGDEBUG, "%s: Initial client digest: ", __FUNCTION__); + RTMP_LogHex(RTMP_LOGDEBUG, clientsig + digestPosClient, + SHA256_DIGEST_LENGTH); + } + +#ifdef _DEBUG + RTMP_Log(RTMP_LOGDEBUG, "Clientsig: "); + RTMP_LogHex(RTMP_LOGDEBUG, clientsig, RTMP_SIG_SIZE); +#endif + + if (!WriteN(r, (char *)clientsig - 1, RTMP_SIG_SIZE + 1)) + return FALSE; + + if (ReadN(r, (char *)&type, 1) != 1) /* 0x03 or 0x06 */ + return FALSE; + + RTMP_Log(RTMP_LOGDEBUG, "%s: Type Answer : %02X", __FUNCTION__, type); + + if (type != clientsig[-1]) + RTMP_Log(RTMP_LOGWARNING, + "%s: Type mismatch: client sent %d, server answered %d", + __FUNCTION__, clientsig[-1], type); + + if (ReadN(r, (char *)serversig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE) + return FALSE; + + /* decode server response */ + memcpy(&uptime, serversig, 4); + uptime = ntohl(uptime); + + RTMP_Log(RTMP_LOGDEBUG, "%s: Server Uptime : %d", __FUNCTION__, uptime); + RTMP_Log(RTMP_LOGDEBUG, "%s: FMS Version : %d.%d.%d.%d", __FUNCTION__, + serversig[4], serversig[5], serversig[6], serversig[7]); + + if (FP9HandShake && type == 3 && !serversig[4]) + FP9HandShake = FALSE; + +#ifdef _DEBUG + RTMP_Log(RTMP_LOGDEBUG, "Server signature:"); + RTMP_LogHex(RTMP_LOGDEBUG, serversig, RTMP_SIG_SIZE); +#endif + + if (FP9HandShake) { + uint8_t digestResp[SHA256_DIGEST_LENGTH]; + uint8_t *signatureResp = NULL; + + /* we have to use this signature now to find the correct algorithms for + * getting the digest and DH positions */ + int digestPosServer = getdig(serversig, RTMP_SIG_SIZE); + + if (!VerifyDigest(digestPosServer, serversig, GenuineFMSKey, 36)) { + RTMP_Log(RTMP_LOGWARNING, "Trying different position for server digest!"); + offalg ^= 1; + getdig = digoff[offalg]; + getdh = dhoff[offalg]; + digestPosServer = getdig(serversig, RTMP_SIG_SIZE); + + if (!VerifyDigest(digestPosServer, serversig, GenuineFMSKey, 36)) { + RTMP_Log( + RTMP_LOGERROR, + "Couldn't verify the server digest"); /* continuing anyway will + probably fail */ + return FALSE; + } + } + + /* generate SWFVerification token (SHA256 HMAC hash of decompressed SWF, key + * are the last 32 bytes of the server handshake) */ + if (r->Link.SWFSize) { + const char swfVerify[] = {0x01, 0x01}; + char *vend = r->Link.SWFVerificationResponse + + sizeof(r->Link.SWFVerificationResponse); + + memcpy(r->Link.SWFVerificationResponse, swfVerify, 2); + AMF_EncodeInt32(&r->Link.SWFVerificationResponse[2], vend, + r->Link.SWFSize); + AMF_EncodeInt32(&r->Link.SWFVerificationResponse[6], vend, + r->Link.SWFSize); + HMACsha256(r->Link.SWFHash, SHA256_DIGEST_LENGTH, + &serversig[RTMP_SIG_SIZE - SHA256_DIGEST_LENGTH], + SHA256_DIGEST_LENGTH, + (uint8_t *)&r->Link.SWFVerificationResponse[10]); + } + + /* do Diffie-Hellmann Key exchange for encrypted RTMP */ + if (encrypted) { + /* compute secret key */ + uint8_t secretKey[128] = {0}; + int len, dhposServer; + + dhposServer = getdh(serversig, RTMP_SIG_SIZE); + RTMP_Log(RTMP_LOGDEBUG, "%s: Server DH public key offset: %d", + __FUNCTION__, dhposServer); + len = DHComputeSharedSecretKey(r->Link.dh, &serversig[dhposServer], 128, + secretKey); + if (len < 0) { + RTMP_Log(RTMP_LOGDEBUG, "%s: Wrong secret key position!", __FUNCTION__); + return FALSE; + } + + RTMP_Log(RTMP_LOGDEBUG, "%s: Secret key: ", __FUNCTION__); + RTMP_LogHex(RTMP_LOGDEBUG, secretKey, 128); + + InitRC4Encryption(secretKey, (uint8_t *)&serversig[dhposServer], + (uint8_t *)&clientsig[dhposClient], &keyIn, &keyOut); + } + + reply = client2; +#ifdef _DEBUG + memset(reply, 0xff, RTMP_SIG_SIZE); +#else + ip = (int32_t *)reply; + for (i = 0; i < RTMP_SIG_SIZE / 4; i++) + *ip++ = rand(); +#endif + /* calculate response now */ + signatureResp = reply + RTMP_SIG_SIZE - SHA256_DIGEST_LENGTH; + + HMACsha256(&serversig[digestPosServer], SHA256_DIGEST_LENGTH, GenuineFPKey, + sizeof(GenuineFPKey), digestResp); + HMACsha256(reply, RTMP_SIG_SIZE - SHA256_DIGEST_LENGTH, digestResp, + SHA256_DIGEST_LENGTH, signatureResp); + + /* some info output */ + RTMP_Log(RTMP_LOGDEBUG, + "%s: Calculated digest key from secure key and server digest: ", + __FUNCTION__); + RTMP_LogHex(RTMP_LOGDEBUG, digestResp, SHA256_DIGEST_LENGTH); + +#ifdef FP10 + if (type == 8) { + uint8_t *dptr = digestResp; + uint8_t *sig = signatureResp; + /* encrypt signatureResp */ + for (i = 0; i < SHA256_DIGEST_LENGTH; i += 8) + rtmpe8_sig(sig + i, sig + i, dptr[i] % 15); + } +#if 0 + else if (type == 9)) + { + uint8_t *dptr = digestResp; + uint8_t *sig = signatureResp; + /* encrypt signatureResp */ + for (i=0; iLink.rc4keyIn = keyIn; + r->Link.rc4keyOut = keyOut; + + /* update the keystreams */ + if (r->Link.rc4keyIn) { + RC4_encrypt(r->Link.rc4keyIn, RTMP_SIG_SIZE, (uint8_t *)buff); + } + + if (r->Link.rc4keyOut) { + RC4_encrypt(r->Link.rc4keyOut, RTMP_SIG_SIZE, (uint8_t *)buff); + } + } + } else { + if (memcmp(serversig, clientsig, RTMP_SIG_SIZE) != 0) { + RTMP_Log(RTMP_LOGWARNING, "%s: client signature does not match!", + __FUNCTION__); + } + } + + RTMP_Log(RTMP_LOGDEBUG, "%s: Handshaking finished....", __FUNCTION__); + return TRUE; +} + +static int SHandShake(RTMP *r) { + int i, offalg = 0; + int dhposServer = 0; + int digestPosServer = 0; + RC4_handle keyIn = 0; + RC4_handle keyOut = 0; + int FP9HandShake = FALSE; + int encrypted; + int32_t *ip; + + uint8_t clientsig[RTMP_SIG_SIZE]; + uint8_t serverbuf[RTMP_SIG_SIZE + 4], *serversig = serverbuf + 4; + uint8_t type; + uint32_t uptime; + getoff *getdh = NULL, *getdig = NULL; + + if (ReadN(r, (char *)&type, 1) != 1) /* 0x03 or 0x06 */ + return FALSE; + + if (ReadN(r, (char *)clientsig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE) + return FALSE; + + RTMP_Log(RTMP_LOGDEBUG, "%s: Type Requested : %02X", __FUNCTION__, type); + RTMP_LogHex(RTMP_LOGDEBUG2, clientsig, RTMP_SIG_SIZE); + + if (type == 3) { + encrypted = FALSE; + } else if (type == 6 || type == 8) { + offalg = 1; + encrypted = TRUE; + FP9HandShake = TRUE; + r->Link.protocol |= RTMP_FEATURE_ENC; + /* use FP10 if client is capable */ + if (clientsig[4] == 128) + type = 8; + } else { + RTMP_Log(RTMP_LOGERROR, "%s: Unknown version %02x", __FUNCTION__, type); + return FALSE; + } + + if (!FP9HandShake && clientsig[4]) + FP9HandShake = TRUE; + + serversig[-1] = type; + + r->Link.rc4keyIn = r->Link.rc4keyOut = 0; + + uptime = htonl(RTMP_GetTime()); + memcpy(serversig, &uptime, 4); + + if (FP9HandShake) { + /* Server version */ + serversig[4] = 3; + serversig[5] = 5; + serversig[6] = 1; + serversig[7] = 1; + + getdig = digoff[offalg]; + getdh = dhoff[offalg]; + } else { + memset(&serversig[4], 0, 4); + } + +/* generate random data */ +#ifdef _DEBUG + memset(serversig + 8, 0, RTMP_SIG_SIZE - 8); +#else + ip = (int32_t *)(serversig + 8); + for (i = 2; i < RTMP_SIG_SIZE / 4; i++) + *ip++ = rand(); +#endif + + /* set handshake digest */ + if (FP9HandShake) { + if (encrypted) { + /* generate Diffie-Hellmann parameters */ + r->Link.dh = DHInit(1024); + if (!r->Link.dh) { + RTMP_Log(RTMP_LOGERROR, "%s: Couldn't initialize Diffie-Hellmann!", + __FUNCTION__); + return FALSE; + } + + dhposServer = getdh(serversig, RTMP_SIG_SIZE); + RTMP_Log(RTMP_LOGDEBUG, "%s: DH pubkey position: %d", __FUNCTION__, + dhposServer); + + if (!DHGenerateKey(r->Link.dh)) { + RTMP_Log(RTMP_LOGERROR, + "%s: Couldn't generate Diffie-Hellmann public key!", + __FUNCTION__); + return FALSE; + } + + if (!DHGetPublicKey(r->Link.dh, (uint8_t *)&serversig[dhposServer], + 128)) { + RTMP_Log(RTMP_LOGERROR, "%s: Couldn't write public key!", __FUNCTION__); + return FALSE; + } + } + + digestPosServer = + getdig(serversig, RTMP_SIG_SIZE); /* reuse this value in verification */ + RTMP_Log(RTMP_LOGDEBUG, "%s: Server digest offset: %d", __FUNCTION__, + digestPosServer); + + CalculateDigest(digestPosServer, serversig, GenuineFMSKey, 36, + &serversig[digestPosServer]); + + RTMP_Log(RTMP_LOGDEBUG, "%s: Initial server digest: ", __FUNCTION__); + RTMP_LogHex(RTMP_LOGDEBUG, serversig + digestPosServer, + SHA256_DIGEST_LENGTH); + } + + RTMP_Log(RTMP_LOGDEBUG2, "Serversig: "); + RTMP_LogHex(RTMP_LOGDEBUG2, serversig, RTMP_SIG_SIZE); + + if (!WriteN(r, (char *)serversig - 1, RTMP_SIG_SIZE + 1)) + return FALSE; + + /* decode client response */ + memcpy(&uptime, clientsig, 4); + uptime = ntohl(uptime); + + RTMP_Log(RTMP_LOGDEBUG, "%s: Client Uptime : %d", __FUNCTION__, uptime); + RTMP_Log(RTMP_LOGDEBUG, "%s: Player Version: %d.%d.%d.%d", __FUNCTION__, + clientsig[4], clientsig[5], clientsig[6], clientsig[7]); + + if (FP9HandShake) { + uint8_t digestResp[SHA256_DIGEST_LENGTH]; + uint8_t *signatureResp = NULL; + + /* we have to use this signature now to find the correct algorithms for + * getting the digest and DH positions */ + int digestPosClient = getdig(clientsig, RTMP_SIG_SIZE); + + if (!VerifyDigest(digestPosClient, clientsig, GenuineFPKey, 30)) { + RTMP_Log(RTMP_LOGWARNING, "Trying different position for client digest!"); + offalg ^= 1; + getdig = digoff[offalg]; + getdh = dhoff[offalg]; + + digestPosClient = getdig(clientsig, RTMP_SIG_SIZE); + + if (!VerifyDigest(digestPosClient, clientsig, GenuineFPKey, 30)) { + RTMP_Log( + RTMP_LOGERROR, + "Couldn't verify the client digest"); /* continuing anyway will + probably fail */ + return FALSE; + } + } + + /* generate SWFVerification token (SHA256 HMAC hash of decompressed SWF, key + * are the last 32 bytes of the server handshake) */ + if (r->Link.SWFSize) { + const char swfVerify[] = {0x01, 0x01}; + char *vend = r->Link.SWFVerificationResponse + + sizeof(r->Link.SWFVerificationResponse); + + memcpy(r->Link.SWFVerificationResponse, swfVerify, 2); + AMF_EncodeInt32(&r->Link.SWFVerificationResponse[2], vend, + r->Link.SWFSize); + AMF_EncodeInt32(&r->Link.SWFVerificationResponse[6], vend, + r->Link.SWFSize); + HMACsha256(r->Link.SWFHash, SHA256_DIGEST_LENGTH, + &serversig[RTMP_SIG_SIZE - SHA256_DIGEST_LENGTH], + SHA256_DIGEST_LENGTH, + (uint8_t *)&r->Link.SWFVerificationResponse[10]); + } + + /* do Diffie-Hellmann Key exchange for encrypted RTMP */ + if (encrypted) { + int dhposClient, len; + /* compute secret key */ + uint8_t secretKey[128] = {0}; + + dhposClient = getdh(clientsig, RTMP_SIG_SIZE); + RTMP_Log(RTMP_LOGDEBUG, "%s: Client DH public key offset: %d", + __FUNCTION__, dhposClient); + len = DHComputeSharedSecretKey( + r->Link.dh, (uint8_t *)&clientsig[dhposClient], 128, secretKey); + if (len < 0) { + RTMP_Log(RTMP_LOGDEBUG, "%s: Wrong secret key position!", __FUNCTION__); + return FALSE; + } + + RTMP_Log(RTMP_LOGDEBUG, "%s: Secret key: ", __FUNCTION__); + RTMP_LogHex(RTMP_LOGDEBUG, secretKey, 128); + + InitRC4Encryption(secretKey, (uint8_t *)&clientsig[dhposClient], + (uint8_t *)&serversig[dhposServer], &keyIn, &keyOut); + } + + /* calculate response now */ + signatureResp = clientsig + RTMP_SIG_SIZE - SHA256_DIGEST_LENGTH; + + HMACsha256(&clientsig[digestPosClient], SHA256_DIGEST_LENGTH, GenuineFMSKey, + sizeof(GenuineFMSKey), digestResp); + HMACsha256(clientsig, RTMP_SIG_SIZE - SHA256_DIGEST_LENGTH, digestResp, + SHA256_DIGEST_LENGTH, signatureResp); +#ifdef FP10 + if (type == 8) { + uint8_t *dptr = digestResp; + uint8_t *sig = signatureResp; + /* encrypt signatureResp */ + for (i = 0; i < SHA256_DIGEST_LENGTH; i += 8) + rtmpe8_sig(sig + i, sig + i, dptr[i] % 15); + } +#if 0 + else if (type == 9)) + { + uint8_t *dptr = digestResp; + uint8_t *sig = signatureResp; + /* encrypt signatureResp */ + for (i=0; iLink.rc4keyIn = keyIn; + r->Link.rc4keyOut = keyOut; + + /* update the keystreams */ + if (r->Link.rc4keyIn) { + RC4_encrypt(r->Link.rc4keyIn, RTMP_SIG_SIZE, (uint8_t *)buff); + } + + if (r->Link.rc4keyOut) { + RC4_encrypt(r->Link.rc4keyOut, RTMP_SIG_SIZE, (uint8_t *)buff); + } + } + } else { + if (memcmp(serversig, clientsig, RTMP_SIG_SIZE) != 0) { + RTMP_Log(RTMP_LOGWARNING, "%s: client signature does not match!", + __FUNCTION__); + } + } + + RTMP_Log(RTMP_LOGDEBUG, "%s: Handshaking finished....", __FUNCTION__); + return TRUE; +} diff --git a/LFLiveKit/Vendor/pili-librtmp/hashswf.c b/LFLiveKit/Vendor/pili-librtmp/hashswf.c new file mode 100644 index 00000000..88d20c7f --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/hashswf.c @@ -0,0 +1,626 @@ +/* + * Copyright (C) 2009-2010 Howard Chu + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +#include +#include +#include +#include +#include + +#include "http.h" +#include "log.h" +#include "rtmp_sys.h" + +#ifdef CRYPTO +#ifdef USE_POLARSSL +#include +#ifndef SHA256_DIGEST_LENGTH +#define SHA256_DIGEST_LENGTH 32 +#endif +#define HMAC_CTX sha2_context +#define HMAC_setup(ctx, key, len) sha2_hmac_starts(&ctx, (unsigned char *)key, len, 0) +#define HMAC_crunch(ctx, buf, len) sha2_hmac_update(&ctx, buf, len) +#define HMAC_finish(ctx, dig, dlen) \ + dlen = SHA256_DIGEST_LENGTH; \ + sha2_hmac_finish(&ctx, dig) +#define HMAC_close(ctx) +#elif defined(USE_GNUTLS) +#include +#include +#ifndef SHA256_DIGEST_LENGTH +#define SHA256_DIGEST_LENGTH 32 +#endif +#define HMAC_CTX gcry_md_hd_t +#define HMAC_setup(ctx, key, len) \ + gcry_md_open(&ctx, GCRY_MD_SHA256, GCRY_MD_FLAG_HMAC); \ + gcry_md_setkey(ctx, key, len) +#define HMAC_crunch(ctx, buf, len) gcry_md_write(ctx, buf, len) +#define HMAC_finish(ctx, dig, dlen) \ + dlen = SHA256_DIGEST_LENGTH; \ + memcpy(dig, gcry_md_read(ctx, 0), dlen) +#define HMAC_close(ctx) gcry_md_close(ctx) +#else /* USE_OPENSSL */ +#include +#include +#include +#include +#define HMAC_setup(ctx, key, len) \ + HMAC_CTX_init(&ctx); \ + HMAC_Init_ex(&ctx, (unsigned char *)key, len, EVP_sha256(), 0) +#define HMAC_crunch(ctx, buf, len) HMAC_Update(&ctx, (unsigned char *)buf, len) +#define HMAC_finish(ctx, dig, dlen) HMAC_Final(&ctx, (unsigned char *)dig, &dlen); +#define HMAC_close(ctx) HMAC_CTX_cleanup(&ctx) +#endif + +extern void RTMP_TLS_Init(); +extern TLS_CTX RTMP_TLS_ctx; + +#endif /* CRYPTO */ + +#include + +#define AGENT "Mozilla/5.0" + +HTTPResult + HTTP_get(struct HTTP_ctx *http, const char *url, HTTP_read_callback *cb) { + char *host, *path; + char *p1, *p2; + char hbuf[256]; + int port = 80; +#ifdef CRYPTO + int ssl = 0; +#endif + int hlen, flen = 0; + int rc, i; + int len_known; + HTTPResult ret = HTTPRES_OK; + // struct sockaddr_in sa; + PILI_RTMPSockBuf sb = {0}; + + http->status = -1; + + // memset(&sa, 0, sizeof(struct sockaddr_in)); + // sa.sin_family = AF_INET; + + /* we only handle http here */ + if (strncasecmp(url, "http", 4)) + return HTTPRES_BAD_REQUEST; + + if (url[4] == 's') { +#ifdef CRYPTO + ssl = 1; + port = 443; + if (!RTMP_TLS_ctx) + RTMP_TLS_Init(); +#else + return HTTPRES_BAD_REQUEST; +#endif + } + + p1 = strchr(url + 4, ':'); + if (!p1 || strncmp(p1, "://", 3)) + return HTTPRES_BAD_REQUEST; + + host = p1 + 3; + path = strchr(host, '/'); + hlen = path - host; + strncpy(hbuf, host, hlen); + hbuf[hlen] = '\0'; + host = hbuf; + p1 = strrchr(host, ':'); + if (p1) { + *p1++ = '\0'; + port = atoi(p1); + } + + // sa.sin_addr.s_addr = inet_addr(host); + // if (sa.sin_addr.s_addr == INADDR_NONE) + // { + // struct hostent *hp = gethostbyname(host); + // if (!hp || !hp->h_addr) + // return HTTPRES_LOST_CONNECTION; + // sa.sin_addr = *(struct in_addr *)hp->h_addr; + // } + // sa.sin_port = htons(port); + struct addrinfo hints = {0}, *ai, *cur_ai; + char portstr[10]; + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + snprintf(portstr, sizeof(portstr), "%d", port); + ret = getaddrinfo(host, portstr, &hints, &ai); + if (ret != 0) { + return HTTPRES_LOST_CONNECTION; + } + + cur_ai = ai; + + sb.sb_socket = socket(cur_ai->ai_family, + cur_ai->ai_socktype, + cur_ai->ai_protocol); + // sb.sb_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (sb.sb_socket == -1) { + freeaddrinfo(ai); + return HTTPRES_LOST_CONNECTION; + } + i = sprintf(sb.sb_buf, + "GET %s HTTP/1.0\r\nUser-Agent: %s\r\nHost: %s\r\nReferrer: %.*s\r\n", + path, AGENT, host, (int)(path - url + 1), url); + if (http->date[0]) + i += sprintf(sb.sb_buf + i, "If-Modified-Since: %s\r\n", http->date); + i += sprintf(sb.sb_buf + i, "\r\n"); + + if (cur_ai->ai_family == AF_INET6) { + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)cur_ai->ai_addr; + in6->sin6_port = htons(port); + } + + if (connect(sb.sb_socket, cur_ai->ai_addr, cur_ai->ai_addrlen) < 0) { + ret = HTTPRES_LOST_CONNECTION; + goto leave; + } +#ifdef CRYPTO + if (ssl) { +#ifdef NO_SSL + RTMP_Log(RTMP_LOGERROR, "%s, No SSL/TLS support", __FUNCTION__); + ret = HTTPRES_BAD_REQUEST; + goto leave; +#else + TLS_client(RTMP_TLS_ctx, sb.sb_ssl); + TLS_setfd(sb.sb_ssl, sb.sb_socket); + if ((i = TLS_connect(sb.sb_ssl)) < 0) { + RTMP_Log(RTMP_LOGERROR, "%s, TLS_Connect failed", __FUNCTION__); + ret = HTTPRES_LOST_CONNECTION; + goto leave; + } +#endif + } +#endif + PILI_RTMPSockBuf_Send(&sb, sb.sb_buf, i); + +/* set timeout */ +#define HTTP_TIMEOUT 5 + { + SET_RCVTIMEO(tv, HTTP_TIMEOUT); + if (setsockopt(sb.sb_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv))) { + RTMP_Log(RTMP_LOGERROR, "%s, Setting socket timeout to %ds failed!", + __FUNCTION__, HTTP_TIMEOUT); + } + } + + sb.sb_size = 0; + sb.sb_timedout = FALSE; + if (PILI_RTMPSockBuf_Fill(&sb) < 1) { + ret = HTTPRES_LOST_CONNECTION; + goto leave; + } + if (strncmp(sb.sb_buf, "HTTP/1", 6)) { + ret = HTTPRES_BAD_REQUEST; + goto leave; + } + + p1 = strchr(sb.sb_buf, ' '); + rc = atoi(p1 + 1); + http->status = rc; + + if (rc >= 300) { + if (rc == 304) { + ret = HTTPRES_OK_NOT_MODIFIED; + goto leave; + } else if (rc == 404) + ret = HTTPRES_NOT_FOUND; + else if (rc >= 500) + ret = HTTPRES_SERVER_ERROR; + else if (rc >= 400) + ret = HTTPRES_BAD_REQUEST; + else + ret = HTTPRES_REDIRECTED; + } + + p1 = memchr(sb.sb_buf, '\n', sb.sb_size); + if (!p1) { + ret = HTTPRES_BAD_REQUEST; + goto leave; + } + sb.sb_start = p1 + 1; + sb.sb_size -= sb.sb_start - sb.sb_buf; + + while ((p2 = memchr(sb.sb_start, '\r', sb.sb_size))) { + if (*sb.sb_start == '\r') { + sb.sb_start += 2; + sb.sb_size -= 2; + break; + } else if (!strncasecmp(sb.sb_start, "Content-Length: ", sizeof("Content-Length: ") - 1)) { + flen = atoi(sb.sb_start + sizeof("Content-Length: ") - 1); + } else if (!strncasecmp(sb.sb_start, "Last-Modified: ", sizeof("Last-Modified: ") - 1)) { + *p2 = '\0'; + strcpy(http->date, sb.sb_start + sizeof("Last-Modified: ") - 1); + } + p2 += 2; + sb.sb_size -= p2 - sb.sb_start; + sb.sb_start = p2; + if (sb.sb_size < 1) { + if (PILI_RTMPSockBuf_Fill(&sb) < 1) { + ret = HTTPRES_LOST_CONNECTION; + goto leave; + } + } + } + + len_known = flen > 0; + while ((!len_known || flen > 0) && + (sb.sb_size > 0 || PILI_RTMPSockBuf_Fill(&sb) > 0)) { + cb(sb.sb_start, 1, sb.sb_size, http->data); + if (len_known) + flen -= sb.sb_size; + http->size += sb.sb_size; + sb.sb_size = 0; + } + + if (flen > 0) + ret = HTTPRES_LOST_CONNECTION; + +leave: + PILI_RTMPSockBuf_Close(&sb); + freeaddrinfo(ai); + return ret; +} + +#ifdef CRYPTO + +#define CHUNK 16384 + +struct info { + z_stream *zs; + HMAC_CTX ctx; + int first; + int zlib; + int size; +}; + +static size_t + swfcrunch(void *ptr, size_t size, size_t nmemb, void *stream) { + struct info *i = stream; + char *p = ptr; + size_t len = size * nmemb; + + if (i->first) { + i->first = 0; + /* compressed? */ + if (!strncmp(p, "CWS", 3)) { + *p = 'F'; + i->zlib = 1; + } + HMAC_crunch(i->ctx, (unsigned char *)p, 8); + p += 8; + len -= 8; + i->size = 8; + } + + if (i->zlib) { + unsigned char out[CHUNK]; + i->zs->next_in = (unsigned char *)p; + i->zs->avail_in = len; + do { + i->zs->avail_out = CHUNK; + i->zs->next_out = out; + inflate(i->zs, Z_NO_FLUSH); + len = CHUNK - i->zs->avail_out; + i->size += len; + HMAC_crunch(i->ctx, out, len); + } while (i->zs->avail_out == 0); + } else { + i->size += len; + HMAC_crunch(i->ctx, (unsigned char *)p, len); + } + return size * nmemb; +} + +static int tzoff; +static int tzchecked; + +#define JAN02_1980 318340800 + +static const char *monthtab[12] = {"Jan", "Feb", "Mar", + "Apr", "May", "Jun", + "Jul", "Aug", "Sep", + "Oct", "Nov", "Dec"}; +static const char *days[] = + {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; + +/* Parse an HTTP datestamp into Unix time */ +static time_t + make_unix_time(char *s) { + struct tm time; + int i, ysub = 1900, fmt = 0; + char *month; + char *n; + time_t res; + + if (s[3] != ' ') { + fmt = 1; + if (s[3] != ',') + ysub = 0; + } + for (n = s; *n; ++n) + if (*n == '-' || *n == ':') + *n = ' '; + + time.tm_mon = 0; + n = strchr(s, ' '); + if (fmt) { + /* Day, DD-MMM-YYYY HH:MM:SS GMT */ + time.tm_mday = strtol(n + 1, &n, 0); + month = n + 1; + n = strchr(month, ' '); + time.tm_year = strtol(n + 1, &n, 0); + time.tm_hour = strtol(n + 1, &n, 0); + time.tm_min = strtol(n + 1, &n, 0); + time.tm_sec = strtol(n + 1, NULL, 0); + } else { + /* Unix ctime() format. Does not conform to HTTP spec. */ + /* Day MMM DD HH:MM:SS YYYY */ + month = n + 1; + n = strchr(month, ' '); + while (isspace(*n)) + n++; + time.tm_mday = strtol(n, &n, 0); + time.tm_hour = strtol(n + 1, &n, 0); + time.tm_min = strtol(n + 1, &n, 0); + time.tm_sec = strtol(n + 1, &n, 0); + time.tm_year = strtol(n + 1, NULL, 0); + } + if (time.tm_year > 100) + time.tm_year -= ysub; + + for (i = 0; i < 12; i++) + if (!strncasecmp(month, monthtab[i], 3)) { + time.tm_mon = i; + break; + } + time.tm_isdst = 0; /* daylight saving is never in effect in GMT */ + + /* this is normally the value of extern int timezone, but some + * braindead C libraries don't provide it. + */ + if (!tzchecked) { + struct tm *tc; + time_t then = JAN02_1980; + tc = localtime(&then); + tzoff = (12 - tc->tm_hour) * 3600 + tc->tm_min * 60 + tc->tm_sec; + tzchecked = 1; + } + res = mktime(&time); + /* Unfortunately, mktime() assumes the input is in local time, + * not GMT, so we have to correct it here. + */ + if (res != -1) + res += tzoff; + return res; +} + +/* Convert a Unix time to a network time string + * Weekday, DD-MMM-YYYY HH:MM:SS GMT + */ +void strtime(time_t *t, char *s) { + struct tm *tm; + + tm = gmtime((time_t *)t); + sprintf(s, "%s, %02d %s %d %02d:%02d:%02d GMT", + days[tm->tm_wday], tm->tm_mday, monthtab[tm->tm_mon], + tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec); +} + +#define HEX2BIN(a) (((a)&0x40) ? ((a)&0xf) + 9 : ((a)&0xf)) + +int RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash, + int age) { + FILE *f = NULL; + char *path, date[64], cctim[64]; + long pos = 0; + time_t ctim = -1, cnow; + int i, got = 0, ret = 0; + unsigned int hlen; + struct info in = {0}; + struct HTTP_ctx http = {0}; + HTTPResult httpres; + z_stream zs = {0}; + AVal home, hpre; + + date[0] = '\0'; +#ifdef _WIN32 +#ifdef _XBOX + hpre.av_val = "Q:"; + hpre.av_len = 2; + home.av_val = "\\UserData"; +#else + hpre.av_val = getenv("HOMEDRIVE"); + hpre.av_len = strlen(hpre.av_val); + home.av_val = getenv("HOMEPATH"); +#endif +#define DIRSEP "\\" + +#else /* !_WIN32 */ + hpre.av_val = ""; + hpre.av_len = 0; + home.av_val = getenv("HOME"); +#define DIRSEP "/" +#endif + if (!home.av_val) + home.av_val = "."; + home.av_len = strlen(home.av_val); + + /* SWF hash info is cached in a fixed-format file. + * url: + * ctim: HTTP datestamp of when we last checked it. + * date: HTTP datestamp of the SWF's last modification. + * size: SWF size in hex + * hash: SWF hash in hex + * + * These fields must be present in this order. All fields + * besides URL are fixed size. + */ + path = malloc(hpre.av_len + home.av_len + sizeof(DIRSEP ".swfinfo")); + sprintf(path, "%s%s" DIRSEP ".swfinfo", hpre.av_val, home.av_val); + + f = fopen(path, "r+"); + while (f) { + char buf[4096], *file, *p; + + file = strchr(url, '/'); + if (!file) + break; + file += 2; + file = strchr(file, '/'); + if (!file) + break; + file++; + hlen = file - url; + p = strrchr(file, '/'); + if (p) + file = p; + else + file--; + + while (fgets(buf, sizeof(buf), f)) { + char *r1; + + got = 0; + + if (strncmp(buf, "url: ", 5)) + continue; + if (strncmp(buf + 5, url, hlen)) + continue; + r1 = strrchr(buf, '/'); + i = strlen(r1); + r1[--i] = '\0'; + if (strncmp(r1, file, i)) + continue; + pos = ftell(f); + while (got < 4 && fgets(buf, sizeof(buf), f)) { + if (!strncmp(buf, "size: ", 6)) { + *size = strtol(buf + 6, NULL, 16); + got++; + } else if (!strncmp(buf, "hash: ", 6)) { + unsigned char *ptr = hash, *in = (unsigned char *)buf + 6; + int l = strlen((char *)in) - 1; + for (i = 0; i < l; i += 2) + *ptr++ = (HEX2BIN(in[i]) << 4) | HEX2BIN(in[i + 1]); + got++; + } else if (!strncmp(buf, "date: ", 6)) { + buf[strlen(buf) - 1] = '\0'; + strncpy(date, buf + 6, sizeof(date)); + got++; + } else if (!strncmp(buf, "ctim: ", 6)) { + buf[strlen(buf) - 1] = '\0'; + ctim = make_unix_time(buf + 6); + got++; + } else if (!strncmp(buf, "url: ", 5)) + break; + } + break; + } + break; + } + + cnow = time(NULL); + /* If we got a cache time, see if it's young enough to use directly */ + if (age && ctim > 0) { + ctim = cnow - ctim; + ctim /= 3600 * 24; /* seconds to days */ + if (ctim < age) /* ok, it's new enough */ + goto out; + } + + in.first = 1; + HMAC_setup(in.ctx, "Genuine Adobe Flash Player 001", 30); + inflateInit(&zs); + in.zs = &zs; + + http.date = date; + http.data = ∈ + + httpres = HTTP_get(&http, url, swfcrunch); + + inflateEnd(&zs); + + if (httpres != HTTPRES_OK && httpres != HTTPRES_OK_NOT_MODIFIED) { + ret = -1; + if (httpres == HTTPRES_LOST_CONNECTION) + RTMP_Log(RTMP_LOGERROR, "%s: connection lost while downloading swfurl %s", + __FUNCTION__, url); + else if (httpres == HTTPRES_NOT_FOUND) + RTMP_Log(RTMP_LOGERROR, "%s: swfurl %s not found", __FUNCTION__, url); + else + RTMP_Log(RTMP_LOGERROR, "%s: couldn't contact swfurl %s (HTTP error %d)", + __FUNCTION__, url, http.status); + } else { + if (got && pos) + fseek(f, pos, SEEK_SET); + else { + char *q; + if (!f) + f = fopen(path, "w"); + if (!f) { + int err = errno; + RTMP_Log(RTMP_LOGERROR, + "%s: couldn't open %s for writing, errno %d (%s)", + __FUNCTION__, path, err, strerror(err)); + ret = -1; + goto out; + } + fseek(f, 0, SEEK_END); + q = strchr(url, '?'); + if (q) + i = q - url; + else + i = strlen(url); + + fprintf(f, "url: %.*s\n", i, url); + } + strtime(&cnow, cctim); + fprintf(f, "ctim: %s\n", cctim); + + if (!in.first) { + HMAC_finish(in.ctx, hash, hlen); + *size = in.size; + + fprintf(f, "date: %s\n", date); + fprintf(f, "size: %08x\n", in.size); + fprintf(f, "hash: "); + for (i = 0; i < SHA256_DIGEST_LENGTH; i++) + fprintf(f, "%02x", hash[i]); + fprintf(f, "\n"); + } + } + HMAC_close(in.ctx); +out: + free(path); + if (f) + fclose(f); + return ret; +} +#else +int RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash, + int age) { + return -1; +} +#endif diff --git a/LFLiveKit/Vendor/pili-librtmp/http.h b/LFLiveKit/Vendor/pili-librtmp/http.h new file mode 100644 index 00000000..1eb7a462 --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/http.h @@ -0,0 +1,49 @@ +#ifndef __RTMP_HTTP_H__ +#define __RTMP_HTTP_H__ +/* + * Copyright (C) 2010 Howard Chu + * Copyright (C) 2010 Antti Ajanki + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +typedef enum { + HTTPRES_OK, /* result OK */ + HTTPRES_OK_NOT_MODIFIED, /* not modified since last request */ + HTTPRES_NOT_FOUND, /* not found */ + HTTPRES_BAD_REQUEST, /* client error */ + HTTPRES_SERVER_ERROR, /* server reported an error */ + HTTPRES_REDIRECTED, /* resource has been moved */ + HTTPRES_LOST_CONNECTION /* connection lost while waiting for data */ +} HTTPResult; + +struct HTTP_ctx { + char *date; + int size; + int status; + void *data; +}; + +typedef size_t(HTTP_read_callback)(void *ptr, size_t size, size_t nmemb, + void *stream); + +HTTPResult HTTP_get(struct HTTP_ctx *http, const char *url, + HTTP_read_callback *cb); + +#endif diff --git a/LFLiveKit/Vendor/pili-librtmp/log.c b/LFLiveKit/Vendor/pili-librtmp/log.c new file mode 100644 index 00000000..d3934366 --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/log.c @@ -0,0 +1,209 @@ +/* + * Copyright (C) 2008-2009 Andrej Stepanchuk + * Copyright (C) 2009-2010 Howard Chu + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +#include +#include +#include +#include +#include + +#include "log.h" +#include "rtmp_sys.h" + +#define MAX_PRINT_LEN 2048 + +RTMP_LogLevel RTMP_debuglevel = RTMP_LOGERROR; + +static int neednl; + +static FILE *fmsg; + +static RTMP_LogCallback rtmp_log_default, *cb = rtmp_log_default; + +static const char *levels[] = { + "CRIT", "ERROR", "WARNING", "INFO", + "DEBUG", "DEBUG2"}; + +static void rtmp_log_default(int level, const char *format, va_list vl) { + char str[MAX_PRINT_LEN] = ""; + + vsnprintf(str, MAX_PRINT_LEN - 1, format, vl); + + /* Filter out 'no-name' */ + if (RTMP_debuglevel < RTMP_LOGALL && strstr(str, "no-name") != NULL) + return; + + if (!fmsg) fmsg = stderr; + + if (level <= RTMP_debuglevel) { + if (neednl) { + putc('\n', fmsg); + neednl = 0; + } + fprintf(fmsg, "%s: %s\n", levels[level], str); +#ifdef _DEBUG + fflush(fmsg); +#endif + } +} + +void RTMP_LogSetOutput(FILE *file) { + fmsg = file; +} + +void RTMP_LogSetLevel(RTMP_LogLevel level) { + RTMP_debuglevel = level; +} + +void RTMP_LogSetCallback(RTMP_LogCallback *cbp) { + cb = cbp; +} + +RTMP_LogLevel RTMP_LogGetLevel() { + return RTMP_debuglevel; +} + +void RTMP_Log(int level, const char *format, ...) { + va_list args; + va_start(args, format); + cb(level, format, args); + va_end(args); +} + +static const char hexdig[] = "0123456789abcdef"; + +void RTMP_LogHex(int level, const uint8_t *data, unsigned long len) { + unsigned long i; + char line[50], *ptr; + + if (level > RTMP_debuglevel) + return; + + ptr = line; + + for (i = 0; i < len; i++) { + *ptr++ = hexdig[0x0f & (data[i] >> 4)]; + *ptr++ = hexdig[0x0f & data[i]]; + if ((i & 0x0f) == 0x0f) { + *ptr = '\0'; + ptr = line; + RTMP_Log(level, "%s", line); + } else { + *ptr++ = ' '; + } + } + if (i & 0x0f) { + *ptr = '\0'; + RTMP_Log(level, "%s", line); + } +} + +void RTMP_LogHexString(int level, const uint8_t *data, unsigned long len) { +#define BP_OFFSET 9 +#define BP_GRAPH 60 +#define BP_LEN 80 + char line[BP_LEN]; + unsigned long i; + + if (!data || level > RTMP_debuglevel) + return; + + /* in case len is zero */ + line[0] = '\0'; + + for (i = 0; i < len; i++) { + int n = i % 16; + unsigned off; + + if (!n) { + if (i) RTMP_Log(level, "%s", line); + memset(line, ' ', sizeof(line) - 2); + line[sizeof(line) - 2] = '\0'; + + off = i % 0x0ffffU; + + line[2] = hexdig[0x0f & (off >> 12)]; + line[3] = hexdig[0x0f & (off >> 8)]; + line[4] = hexdig[0x0f & (off >> 4)]; + line[5] = hexdig[0x0f & off]; + line[6] = ':'; + } + + off = BP_OFFSET + n * 3 + ((n >= 8) ? 1 : 0); + line[off] = hexdig[0x0f & (data[i] >> 4)]; + line[off + 1] = hexdig[0x0f & data[i]]; + + off = BP_GRAPH + n + ((n >= 8) ? 1 : 0); + + if (isprint(data[i])) { + line[BP_GRAPH + n] = data[i]; + } else { + line[BP_GRAPH + n] = '.'; + } + } + + RTMP_Log(level, "%s", line); +} + +/* These should only be used by apps, never by the library itself */ +void RTMP_LogPrintf(const char *format, ...) { + char str[MAX_PRINT_LEN] = ""; + int len; + va_list args; + va_start(args, format); + len = vsnprintf(str, MAX_PRINT_LEN - 1, format, args); + va_end(args); + + if (RTMP_debuglevel == RTMP_LOGCRIT) + return; + + if (!fmsg) fmsg = stderr; + + if (neednl) { + putc('\n', fmsg); + neednl = 0; + } + + if (len > MAX_PRINT_LEN - 1) + len = MAX_PRINT_LEN - 1; + fprintf(fmsg, "%s", str); + if (str[len - 1] == '\n') + fflush(fmsg); +} + +void RTMP_LogStatus(const char *format, ...) { + char str[MAX_PRINT_LEN] = ""; + va_list args; + va_start(args, format); + vsnprintf(str, MAX_PRINT_LEN - 1, format, args); + va_end(args); + + if (RTMP_debuglevel == RTMP_LOGCRIT) + return; + + if (!fmsg) fmsg = stderr; + + fprintf(fmsg, "%s", str); + fflush(fmsg); + neednl = 1; +} diff --git a/LFLiveKit/Vendor/pili-librtmp/log.h b/LFLiveKit/Vendor/pili-librtmp/log.h new file mode 100644 index 00000000..f7daf375 --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/log.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2008-2009 Andrej Stepanchuk + * Copyright (C) 2009-2010 Howard Chu + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +#ifndef __RTMP_LOG_H__ +#define __RTMP_LOG_H__ + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif +/* Enable this to get full debugging output */ +/* #define _DEBUG */ + +#ifdef _DEBUG +#undef NODEBUG +#endif + +typedef enum { + RTMP_LOGCRIT = 0, + RTMP_LOGERROR, + RTMP_LOGWARNING, + RTMP_LOGINFO, + RTMP_LOGDEBUG, + RTMP_LOGDEBUG2, + RTMP_LOGALL +} RTMP_LogLevel; + +extern RTMP_LogLevel RTMP_debuglevel; + +typedef void(RTMP_LogCallback)(int level, const char *fmt, va_list); +void RTMP_LogSetCallback(RTMP_LogCallback *cb); +void RTMP_LogSetOutput(FILE *file); +void RTMP_LogPrintf(const char *format, ...); +void RTMP_LogStatus(const char *format, ...); +void RTMP_Log(int level, const char *format, ...); +void RTMP_LogHex(int level, const uint8_t *data, unsigned long len); +void RTMP_LogHexString(int level, const uint8_t *data, unsigned long len); +void RTMP_LogSetLevel(RTMP_LogLevel lvl); +RTMP_LogLevel RTMP_LogGetLevel(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/LFLiveKit/Vendor/pili-librtmp/parseurl.c b/LFLiveKit/Vendor/pili-librtmp/parseurl.c new file mode 100644 index 00000000..0e50352b --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/parseurl.c @@ -0,0 +1,312 @@ +/* + * Copyright (C) 2009 Andrej Stepanchuk + * Copyright (C) 2009-2010 Howard Chu + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +#include +#include + +#include +#include + +#include "log.h" +#include "rtmp_sys.h" + +int PILI_RTMP_ParseURL2(const char *url, int *protocol, AVal *host, unsigned int *port, + AVal *playpath, AVal *app, AVal *domainName) { + char *p, *end, *col, *ques, *slash; + + RTMP_Log(RTMP_LOGDEBUG, "Parsing..."); + + *protocol = RTMP_PROTOCOL_RTMP; + *port = 0; + playpath->av_len = 0; + playpath->av_val = NULL; + app->av_len = 0; + app->av_val = NULL; + + /* Old School Parsing */ + + /* look for usual :// pattern */ + p = strstr(url, "://"); + if (!p) { + RTMP_Log(RTMP_LOGERROR, "RTMP URL: No :// in url!"); + return FALSE; + } + { + int len = (int)(p - url); + + if (len == 4 && strncasecmp(url, "rtmp", 4) == 0) + *protocol = RTMP_PROTOCOL_RTMP; + else if (len == 5 && strncasecmp(url, "rtmpt", 5) == 0) + *protocol = RTMP_PROTOCOL_RTMPT; + else if (len == 5 && strncasecmp(url, "rtmps", 5) == 0) + *protocol = RTMP_PROTOCOL_RTMPS; + else if (len == 5 && strncasecmp(url, "rtmpe", 5) == 0) + *protocol = RTMP_PROTOCOL_RTMPE; + else if (len == 5 && strncasecmp(url, "rtmfp", 5) == 0) + *protocol = RTMP_PROTOCOL_RTMFP; + else if (len == 6 && strncasecmp(url, "rtmpte", 6) == 0) + *protocol = RTMP_PROTOCOL_RTMPTE; + else if (len == 6 && strncasecmp(url, "rtmpts", 6) == 0) + *protocol = RTMP_PROTOCOL_RTMPTS; + else { + RTMP_Log(RTMP_LOGWARNING, "Unknown protocol!\n"); + goto parsehost; + } + } + + RTMP_Log(RTMP_LOGDEBUG, "Parsed protocol: %d", *protocol); + +parsehost: + /* let's get the hostname */ + p += 3; + + /* check for sudden death */ + if (*p == 0) { + RTMP_Log(RTMP_LOGWARNING, "No hostname in URL!"); + return FALSE; + } + + end = p + strlen(p); + col = strchr(p, ':'); + ques = strchr(p, '?'); + slash = strchr(p, '/'); + + { + int hostlen; + if (slash) + hostlen = slash - p; + else + hostlen = end - p; + if (col && col - p < hostlen) + hostlen = col - p; + + if (hostlen < 256) { + host->av_val = p; + host->av_len = hostlen; + RTMP_Log(RTMP_LOGDEBUG, "Parsed host : %.*s", hostlen, host->av_val); + } else { + RTMP_Log(RTMP_LOGWARNING, "Hostname exceeds 255 characters!"); + } + + p += hostlen; + } + + /* get the port number if available */ + if (*p == ':') { + unsigned int p2; + p++; + p2 = atoi(p); + if (p2 > 65535) { + RTMP_Log(RTMP_LOGWARNING, "Invalid port number!"); + } else { + *port = p2; + } + } + + if (!slash) { + RTMP_Log(RTMP_LOGWARNING, "No application or playpath in URL!"); + return TRUE; + } + p = slash + 1; + + /** parse domain + + * rtmp://host:[port]/app/...?domain=a.com + + * use domain to replace host + + */ + + if (domainName != NULL && ques != NULL) { + char *domain = strstr(ques, "domain="); + if (domain) { + end = domain - 1; + domain += 7; //skip "domain=" + char *domain_end = strchr(domain, '&'); + int host_len = 0; + if (domain_end) { + host_len = domain_end - domain; + } else { + host_len = strlen(domain); + } + if (host_len < 256) { + domainName->av_val = domain; + domainName->av_len = host_len; + RTMP_Log(RTMP_LOGDEBUG, "Parsed host and domain : %.*s", host_len, host->av_val); + } + } + } + + { + /* parse application + * + * rtmp://host[:port]/app[/appinstance][/...] + * application = app[/appinstance] + */ + + char *slash2, *slash3 = NULL; + int applen, appnamelen; + + slash2 = strchr(p, '/'); + if (slash2) + slash3 = strchr(slash2 + 1, '/'); + + applen = end - p; /* ondemand, pass all parameters as app */ + appnamelen = applen; /* ondemand length */ + + if (ques && strstr(p, "slist=")) { /* whatever it is, the '?' and slist= means we need to use everything as app and parse plapath from slist= */ + appnamelen = ques - p; + } else if (strncmp(p, "ondemand/", 9) == 0) { + /* app = ondemand/foobar, only pass app=ondemand */ + applen = 8; + appnamelen = 8; + } else { /* app!=ondemand, so app is app[/appinstance] */ + if (slash3) + appnamelen = slash3 - p; + else if (slash2) + appnamelen = slash2 - p; + + applen = appnamelen; + } + + app->av_val = p; + app->av_len = applen; + RTMP_Log(RTMP_LOGDEBUG, "Parsed app : %.*s", applen, p); + + p += appnamelen; + } + + if (*p == '/') + p++; + + if (end - p) { + AVal av = {p, end - p}; + PILI_RTMP_ParsePlaypath(&av, playpath); + } + + return TRUE; +} + +/* + * Extracts playpath from RTMP URL. playpath is the file part of the + * URL, i.e. the part that comes after rtmp://host:port/app/ + * + * Returns the stream name in a format understood by FMS. The name is + * the playpath part of the URL with formatting depending on the stream + * type: + * + * mp4 streams: prepend "mp4:", remove extension + * mp3 streams: prepend "mp3:", remove extension + * flv streams: remove extension + */ +void PILI_RTMP_ParsePlaypath(AVal *in, AVal *out) { + int addMP4 = 0; + int addMP3 = 0; + int subExt = 0; + const char *playpath = in->av_val; + const char *temp, *q, *ext = NULL; + const char *ppstart = playpath; + char *streamname, *destptr, *p; + + int pplen = in->av_len; + + out->av_val = NULL; + out->av_len = 0; + + if ((*ppstart == '?') && + (temp = strstr(ppstart, "slist=")) != 0) { + ppstart = temp + 6; + pplen = strlen(ppstart); + + temp = strchr(ppstart, '&'); + if (temp) { + pplen = temp - ppstart; + } + } + + q = strchr(ppstart, '?'); + if (pplen >= 4) { + if (q) + ext = q - 4; + else + ext = &ppstart[pplen - 4]; + if ((strncmp(ext, ".f4v", 4) == 0) || + (strncmp(ext, ".mp4", 4) == 0)) { + addMP4 = 1; + subExt = 1; + /* Only remove .flv from rtmp URL, not slist params */ + } else if ((ppstart == playpath) && + (strncmp(ext, ".flv", 4) == 0)) { + subExt = 1; + } else if (strncmp(ext, ".mp3", 4) == 0) { + addMP3 = 1; + subExt = 1; + } + } + + streamname = (char *)malloc((pplen + 4 + 1) * sizeof(char)); + if (!streamname) + return; + + destptr = streamname; + if (addMP4) { + if (strncmp(ppstart, "mp4:", 4)) { + strcpy(destptr, "mp4:"); + destptr += 4; + } else { + subExt = 0; + } + } else if (addMP3) { + if (strncmp(ppstart, "mp3:", 4)) { + strcpy(destptr, "mp3:"); + destptr += 4; + } else { + subExt = 0; + } + } + + for (p = (char *)ppstart; pplen > 0;) { + /* skip extension */ + if (subExt && p == ext) { + p += 4; + pplen -= 4; + continue; + } + if (*p == '%') { + unsigned int c; + sscanf(p + 1, "%02x", &c); + *destptr++ = c; + pplen -= 3; + p += 3; + } else { + *destptr++ = *p++; + pplen--; + } + } + *destptr = '\0'; + + out->av_val = streamname; + out->av_len = destptr - streamname; +} + +int PILI_RTMP_ParseURL(const char *url, int *protocol, AVal *host, + unsigned int *port, AVal *playpath, AVal *app) { + return PILI_RTMP_ParseURL2(url, protocol, host, port, playpath, app, NULL); +} diff --git a/LFLiveKit/Vendor/pili-librtmp/rtmp.c b/LFLiveKit/Vendor/pili-librtmp/rtmp.c new file mode 100644 index 00000000..5043885b --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/rtmp.c @@ -0,0 +1,4136 @@ +/* + * Copyright (C) 2005-2008 Team XBMC + * http://www.xbmc.org + * Copyright (C) 2008-2009 Andrej Stepanchuk + * Copyright (C) 2009-2010 Howard Chu + * + * This file is part of librtmp. + * + * libPILI_RTMP is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * libPILI_RTMP is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libPILI_RTMP see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +#include +#include +#include +#include + +#include "log.h" +#include "rtmp_sys.h" + +#ifdef CRYPTO +#ifdef USE_POLARSSL +#include +#elif defined(USE_GNUTLS) +#include +#else /* USE_OPENSSL */ +#include +#include +#endif +TLS_CTX RTMP_TLS_ctx; +#endif + +#define RTMP_SIG_SIZE 1536 +#define RTMP_LARGE_HEADER_SIZE 12 + +static const int packetSize[] = {12, 8, 4, 1}; + +int PILI_RTMP_ctrlC; + +const char PILI_RTMPProtocolStrings[][7] = { + "RTMP", + "RTMPT", + "RTMPE", + "RTMPTE", + "RTMPS", + "RTMPTS", + "", + "", + "RTMFP"}; + +const char PILI_RTMPProtocolStringsLower[][7] = { + "rtmp", + "rtmpt", + "rtmpe", + "rtmpte", + "rtmps", + "rtmpts", + "", + "", + "rtmfp"}; + +static const char *RTMPT_cmds[] = { + "open", + "send", + "idle", + "close"}; + +typedef enum { + RTMPT_OPEN = 0, + RTMPT_SEND, + RTMPT_IDLE, + RTMPT_CLOSE +} RTMPTCmd; + +static int DumpMetaData(AMFObject *obj); +static int HandShake(PILI_RTMP *r, int FP9HandShake, RTMPError *error); +static int SocksNegotiate(PILI_RTMP *r, RTMPError *error); + +static int SendConnectPacket(PILI_RTMP *r, PILI_RTMPPacket *cp, RTMPError *error); +static int SendCheckBW(PILI_RTMP *r, RTMPError *error); +static int SendCheckBWResult(PILI_RTMP *r, double txn, RTMPError *error); +static int SendDeleteStream(PILI_RTMP *r, double dStreamId, RTMPError *error); +static int SendFCSubscribe(PILI_RTMP *r, AVal *subscribepath, RTMPError *error); +static int SendPlay(PILI_RTMP *r, RTMPError *error); +static int SendBytesReceived(PILI_RTMP *r, RTMPError *error); + +#if 0 /* unused */ +static int SendBGHasStream(PILI_RTMP *r, double dId, AVal *playpath); +#endif + +static int HandleInvoke(PILI_RTMP *r, const char *body, unsigned int nBodySize); +static int HandleMetadata(PILI_RTMP *r, char *body, unsigned int len); +static void HandleChangeChunkSize(PILI_RTMP *r, const PILI_RTMPPacket *packet); +static void HandleAudio(PILI_RTMP *r, const PILI_RTMPPacket *packet); +static void HandleVideo(PILI_RTMP *r, const PILI_RTMPPacket *packet); +static void HandleCtrl(PILI_RTMP *r, const PILI_RTMPPacket *packet); +static void HandleServerBW(PILI_RTMP *r, const PILI_RTMPPacket *packet); +static void HandleClientBW(PILI_RTMP *r, const PILI_RTMPPacket *packet); + +static int ReadN(PILI_RTMP *r, char *buffer, int n); +static int WriteN(PILI_RTMP *r, const char *buffer, int n, RTMPError *error); + +static void DecodeTEA(AVal *key, AVal *text); + +static int HTTP_Post(PILI_RTMP *r, RTMPTCmd cmd, const char *buf, int len); +static int HTTP_read(PILI_RTMP *r, int fill); + +#ifndef _WIN32 +static int clk_tck; +#endif + +#ifdef CRYPTO +#include "handshake.h" +#endif + +uint32_t + PILI_RTMP_GetTime() { +#ifdef _DEBUG + return 0; +#elif defined(_WIN32) + return timeGetTime(); +#else + struct tms t; + if (!clk_tck) clk_tck = sysconf(_SC_CLK_TCK); + return times(&t) * 1000 / clk_tck; +#endif +} + +void PILI_RTMP_UserInterrupt() { + PILI_RTMP_ctrlC = TRUE; +} + +void PILI_RTMPPacket_Reset(PILI_RTMPPacket *p) { + p->m_headerType = 0; + p->m_packetType = 0; + p->m_nChannel = 0; + p->m_nTimeStamp = 0; + p->m_nInfoField2 = 0; + p->m_hasAbsTimestamp = FALSE; + p->m_nBodySize = 0; + p->m_nBytesRead = 0; +} + +int PILI_RTMPPacket_Alloc(PILI_RTMPPacket *p, int nSize) { + char *ptr = calloc(1, nSize + RTMP_MAX_HEADER_SIZE); + if (!ptr) + return FALSE; + p->m_body = ptr + RTMP_MAX_HEADER_SIZE; + p->m_nBytesRead = 0; + return TRUE; +} + +void PILI_RTMPPacket_Free(PILI_RTMPPacket *p) { + if (p->m_body) { + free(p->m_body - RTMP_MAX_HEADER_SIZE); + p->m_body = NULL; + } +} + +void PILI_RTMPPacket_Dump(PILI_RTMPPacket *p) { + RTMP_Log(RTMP_LOGDEBUG, + "PILI_RTMP PACKET: packet type: 0x%02x. channel: 0x%02x. info 1: %d info 2: %d. Body size: %lu. body: 0x%02x", + p->m_packetType, p->m_nChannel, p->m_nTimeStamp, p->m_nInfoField2, + p->m_nBodySize, p->m_body ? (unsigned char)p->m_body[0] : 0); +} + +int PILI_RTMP_LibVersion() { + return RTMP_LIB_VERSION; +} + +void PILI_RTMP_TLS_Init() { +#ifdef CRYPTO +#ifdef USE_POLARSSL + /* Do this regardless of NO_SSL, we use havege for rtmpe too */ + RTMP_TLS_ctx = calloc(1, sizeof(struct tls_ctx)); + havege_init(&RTMP_TLS_ctx->hs); +#elif defined(USE_GNUTLS) && !defined(NO_SSL) + /* Technically we need to initialize libgcrypt ourselves if + * we're not going to call gnutls_global_init(). Ignoring this + * for now. + */ + gnutls_global_init(); + RTMP_TLS_ctx = malloc(sizeof(struct tls_ctx)); + gnutls_certificate_allocate_credentials(&RTMP_TLS_ctx->cred); + gnutls_priority_init(&RTMP_TLS_ctx->prios, "NORMAL", NULL); + gnutls_certificate_set_x509_trust_file(RTMP_TLS_ctx->cred, + "ca.pem", GNUTLS_X509_FMT_PEM); +#elif !defined(NO_SSL) /* USE_OPENSSL */ + /* libcrypto doesn't need anything special */ + SSL_load_error_strings(); + SSL_library_init(); + OpenSSL_add_all_digests(); + RTMP_TLS_ctx = SSL_CTX_new(SSLv23_method()); + SSL_CTX_set_options(RTMP_TLS_ctx, SSL_OP_ALL); + SSL_CTX_set_default_verify_paths(RTMP_TLS_ctx); +#endif +#endif +} + +PILI_RTMP * + PILI_RTMP_Alloc() { + return calloc(1, sizeof(PILI_RTMP)); +} + +void PILI_RTMP_Free(PILI_RTMP *r) { + r->m_errorCallback = NULL; + r->m_userData = NULL; + RTMPError_Free(r->m_error); + r->m_error = NULL; + + free(r); +} + +void PILI_RTMP_Init(PILI_RTMP *r) { +#ifdef CRYPTO + if (!RTMP_TLS_ctx) + RTMP_TLS_Init(); +#endif + + memset(r, 0, sizeof(PILI_RTMP)); + r->m_sb.sb_socket = -1; + r->m_inChunkSize = RTMP_DEFAULT_CHUNKSIZE; + r->m_outChunkSize = RTMP_DEFAULT_CHUNKSIZE; + r->m_nBufferMS = 30000; + r->m_nClientBW = 2500000; + r->m_nClientBW2 = 2; + r->m_nServerBW = 2500000; + r->m_fAudioCodecs = 3191.0; + r->m_fVideoCodecs = 252.0; + r->Link.timeout = 10; + r->Link.send_timeout = 10; + r->Link.swfAge = 30; + + r->m_errorCallback = NULL; + r->m_error = NULL; + r->m_userData = NULL; + r->m_is_closing = 0; + r->m_tcp_nodelay = 1; + + r->m_connCallback = NULL; + r->ip = 0; +} + +void PILI_RTMP_EnableWrite(PILI_RTMP *r) { + r->Link.protocol |= RTMP_FEATURE_WRITE; +} + +double + PILI_RTMP_GetDuration(PILI_RTMP *r) { + return r->m_fDuration; +} + +int PILI_RTMP_IsConnected(PILI_RTMP *r) { + return r->m_sb.sb_socket != -1; +} + +int PILI_RTMP_Socket(PILI_RTMP *r) { + return r->m_sb.sb_socket; +} + +int PILI_RTMP_IsTimedout(PILI_RTMP *r) { + return r->m_sb.sb_timedout; +} + +void PILI_RTMP_SetBufferMS(PILI_RTMP *r, int size) { + r->m_nBufferMS = size; +} + +void PILI_RTMP_UpdateBufferMS(PILI_RTMP *r, RTMPError *error) { + PILI_RTMP_SendCtrl(r, 3, r->m_stream_id, r->m_nBufferMS, error); +} + +#undef OSS +#ifdef _WIN32 +#define OSS "WIN" +#elif defined(__sun__) +#define OSS "SOL" +#elif defined(__APPLE__) +#define OSS "MAC" +#elif defined(__linux__) +#define OSS "LNX" +#else +#define OSS "GNU" +#endif +#define DEF_VERSTR OSS " 10,0,32,18" +static const char DEFAULT_FLASH_VER[] = DEF_VERSTR; +const AVal RTMP_DefaultFlashVer = + {(char *)DEFAULT_FLASH_VER, sizeof(DEFAULT_FLASH_VER) - 1}; + +void PILI_RTMP_SetupStream(PILI_RTMP *r, + int protocol, + AVal *host, + unsigned int port, + AVal *sockshost, + AVal *playpath, + AVal *tcUrl, + AVal *swfUrl, + AVal *pageUrl, + AVal *app, + AVal *auth, + AVal *swfSHA256Hash, + uint32_t swfSize, + AVal *flashVer, + AVal *subscribepath, + int dStart, + int dStop, int bLiveStream, long int timeout) { + RTMP_Log(RTMP_LOGDEBUG, "Protocol : %s", PILI_RTMPProtocolStrings[protocol & 7]); + RTMP_Log(RTMP_LOGDEBUG, "Hostname : %.*s", host->av_len, host->av_val); + RTMP_Log(RTMP_LOGDEBUG, "Port : %d", port); + RTMP_Log(RTMP_LOGDEBUG, "Playpath : %s", playpath->av_val); + + if (tcUrl && tcUrl->av_val) + RTMP_Log(RTMP_LOGDEBUG, "tcUrl : %s", tcUrl->av_val); + if (swfUrl && swfUrl->av_val) + RTMP_Log(RTMP_LOGDEBUG, "swfUrl : %s", swfUrl->av_val); + if (pageUrl && pageUrl->av_val) + RTMP_Log(RTMP_LOGDEBUG, "pageUrl : %s", pageUrl->av_val); + if (app && app->av_val) + RTMP_Log(RTMP_LOGDEBUG, "app : %.*s", app->av_len, app->av_val); + if (auth && auth->av_val) + RTMP_Log(RTMP_LOGDEBUG, "auth : %s", auth->av_val); + if (subscribepath && subscribepath->av_val) + RTMP_Log(RTMP_LOGDEBUG, "subscribepath : %s", subscribepath->av_val); + if (flashVer && flashVer->av_val) + RTMP_Log(RTMP_LOGDEBUG, "flashVer : %s", flashVer->av_val); + if (dStart > 0) + RTMP_Log(RTMP_LOGDEBUG, "StartTime : %d msec", dStart); + if (dStop > 0) + RTMP_Log(RTMP_LOGDEBUG, "StopTime : %d msec", dStop); + + RTMP_Log(RTMP_LOGDEBUG, "live : %s", bLiveStream ? "yes" : "no"); + RTMP_Log(RTMP_LOGDEBUG, "timeout : %d sec", timeout); + +#ifdef CRYPTO + if (swfSHA256Hash != NULL && swfSize > 0) { + memcpy(r->Link.SWFHash, swfSHA256Hash->av_val, sizeof(r->Link.SWFHash)); + r->Link.SWFSize = swfSize; + RTMP_Log(RTMP_LOGDEBUG, "SWFSHA256:"); + RTMP_LogHex(RTMP_LOGDEBUG, r->Link.SWFHash, sizeof(r->Link.SWFHash)); + RTMP_Log(RTMP_LOGDEBUG, "SWFSize : %lu", r->Link.SWFSize); + } else { + r->Link.SWFSize = 0; + } +#endif + + if (sockshost->av_len) { + const char *socksport = strchr(sockshost->av_val, ':'); + char *hostname = strdup(sockshost->av_val); + + if (socksport) + hostname[socksport - sockshost->av_val] = '\0'; + r->Link.sockshost.av_val = hostname; + r->Link.sockshost.av_len = strlen(hostname); + + r->Link.socksport = socksport ? atoi(socksport + 1) : 1080; + RTMP_Log(RTMP_LOGDEBUG, "Connecting via SOCKS proxy: %s:%d", r->Link.sockshost.av_val, + r->Link.socksport); + } else { + r->Link.sockshost.av_val = NULL; + r->Link.sockshost.av_len = 0; + r->Link.socksport = 0; + } + + if (tcUrl && tcUrl->av_len) + r->Link.tcUrl = *tcUrl; + if (swfUrl && swfUrl->av_len) + r->Link.swfUrl = *swfUrl; + if (pageUrl && pageUrl->av_len) + r->Link.pageUrl = *pageUrl; + if (app && app->av_len) + r->Link.app = *app; + if (auth && auth->av_len) { + r->Link.auth = *auth; + r->Link.lFlags |= RTMP_LF_AUTH; + } + if (flashVer && flashVer->av_len) + r->Link.flashVer = *flashVer; + else + r->Link.flashVer = RTMP_DefaultFlashVer; + if (subscribepath && subscribepath->av_len) + r->Link.subscribepath = *subscribepath; + r->Link.seekTime = dStart; + r->Link.stopTime = dStop; + if (bLiveStream) + r->Link.lFlags |= RTMP_LF_LIVE; + r->Link.timeout = timeout; + + r->Link.protocol = protocol; + r->Link.hostname = *host; + r->Link.port = port; + r->Link.playpath = *playpath; + + if (r->Link.port == 0) { + if (protocol & RTMP_FEATURE_SSL) + r->Link.port = 443; + else if (protocol & RTMP_FEATURE_HTTP) + r->Link.port = 80; + else + r->Link.port = 1935; + } +} + +enum { OPT_STR = 0, + OPT_INT, + OPT_BOOL, + OPT_CONN }; +static const char *optinfo[] = { + "string", "integer", "boolean", "AMF"}; + +#define OFF(x) offsetof(struct PILI_RTMP, x) + +static struct urlopt { + AVal name; + off_t off; + int otype; + int omisc; + char *use; +} options[] = { + {AVC("socks"), OFF(Link.sockshost), OPT_STR, 0, + "Use the specified SOCKS proxy"}, + {AVC("app"), OFF(Link.app), OPT_STR, 0, + "Name of target app on server"}, + {AVC("tcUrl"), OFF(Link.tcUrl), OPT_STR, 0, + "URL to played stream"}, + {AVC("pageUrl"), OFF(Link.pageUrl), OPT_STR, 0, + "URL of played media's web page"}, + {AVC("swfUrl"), OFF(Link.swfUrl), OPT_STR, 0, + "URL to player SWF file"}, + {AVC("flashver"), OFF(Link.flashVer), OPT_STR, 0, + "Flash version string (default " DEF_VERSTR ")"}, + {AVC("conn"), OFF(Link.extras), OPT_CONN, 0, + "Append arbitrary AMF data to Connect message"}, + {AVC("playpath"), OFF(Link.playpath), OPT_STR, 0, + "Path to target media on server"}, + {AVC("playlist"), OFF(Link.lFlags), OPT_BOOL, RTMP_LF_PLST, + "Set playlist before play command"}, + {AVC("live"), OFF(Link.lFlags), OPT_BOOL, RTMP_LF_LIVE, + "Stream is live, no seeking possible"}, + {AVC("subscribe"), OFF(Link.subscribepath), OPT_STR, 0, + "Stream to subscribe to"}, + {AVC("token"), OFF(Link.token), OPT_STR, 0, + "Key for SecureToken response"}, + {AVC("swfVfy"), OFF(Link.lFlags), OPT_BOOL, RTMP_LF_SWFV, + "Perform SWF Verification"}, + {AVC("swfAge"), OFF(Link.swfAge), OPT_INT, 0, + "Number of days to use cached SWF hash"}, + {AVC("start"), OFF(Link.seekTime), OPT_INT, 0, + "Stream start position in milliseconds"}, + {AVC("stop"), OFF(Link.stopTime), OPT_INT, 0, + "Stream stop position in milliseconds"}, + {AVC("buffer"), OFF(m_nBufferMS), OPT_INT, 0, + "Buffer time in milliseconds"}, + {AVC("timeout"), OFF(Link.timeout), OPT_INT, 0, + "Session timeout in seconds"}, + {{NULL, 0}, 0, 0}}; + +static const AVal truth[] = { + AVC("1"), + AVC("on"), + AVC("yes"), + AVC("true"), + {0, 0}}; + +static void RTMP_OptUsage() { + int i; + + RTMP_Log(RTMP_LOGERROR, "Valid PILI_RTMP options are:\n"); + for (i = 0; options[i].name.av_len; i++) { + RTMP_Log(RTMP_LOGERROR, "%10s %-7s %s\n", options[i].name.av_val, + optinfo[options[i].otype], options[i].use); + } +} + +static int + parseAMF(AMFObject *obj, AVal *av, int *depth) { + AMFObjectProperty prop = {{0, 0}}; + int i; + char *p, *arg = av->av_val; + + if (arg[1] == ':') { + p = (char *)arg + 2; + switch (arg[0]) { + case 'B': + prop.p_type = AMF_BOOLEAN; + prop.p_vu.p_number = atoi(p); + break; + case 'S': + prop.p_type = AMF_STRING; + prop.p_vu.p_aval.av_val = p; + prop.p_vu.p_aval.av_len = av->av_len - (p - arg); + break; + case 'N': + prop.p_type = AMF_NUMBER; + prop.p_vu.p_number = strtod(p, NULL); + break; + case 'Z': + prop.p_type = AMF_NULL; + break; + case 'O': + i = atoi(p); + if (i) { + prop.p_type = AMF_OBJECT; + } else { + (*depth)--; + return 0; + } + break; + default: + return -1; + } + } else if (arg[2] == ':' && arg[0] == 'N') { + p = strchr(arg + 3, ':'); + if (!p || !*depth) + return -1; + prop.p_name.av_val = (char *)arg + 3; + prop.p_name.av_len = p - (arg + 3); + + p++; + switch (arg[1]) { + case 'B': + prop.p_type = AMF_BOOLEAN; + prop.p_vu.p_number = atoi(p); + break; + case 'S': + prop.p_type = AMF_STRING; + prop.p_vu.p_aval.av_val = p; + prop.p_vu.p_aval.av_len = av->av_len - (p - arg); + break; + case 'N': + prop.p_type = AMF_NUMBER; + prop.p_vu.p_number = strtod(p, NULL); + break; + case 'O': + prop.p_type = AMF_OBJECT; + break; + default: + return -1; + } + } else + return -1; + + if (*depth) { + AMFObject *o2; + for (i = 0; i < *depth; i++) { + o2 = &obj->o_props[obj->o_num - 1].p_vu.p_object; + obj = o2; + } + } + AMF_AddProp(obj, &prop); + if (prop.p_type == AMF_OBJECT) + (*depth)++; + return 0; +} + +int RTMP_SetOpt(PILI_RTMP *r, const AVal *opt, AVal *arg, RTMPError *error) { + int i; + void *v; + + for (i = 0; options[i].name.av_len; i++) { + if (opt->av_len != options[i].name.av_len) continue; + if (strcasecmp(opt->av_val, options[i].name.av_val)) continue; + v = (char *)r + options[i].off; + switch (options[i].otype) { + case OPT_STR: { + AVal *aptr = v; + *aptr = *arg; + } break; + case OPT_INT: { + long l = strtol(arg->av_val, NULL, 0); + *(int *)v = l; + } break; + case OPT_BOOL: { + int j, fl; + fl = *(int *)v; + for (j = 0; truth[j].av_len; j++) { + if (arg->av_len != truth[j].av_len) continue; + if (strcasecmp(arg->av_val, truth[j].av_val)) continue; + fl |= options[i].omisc; + break; + } + *(int *)v = fl; + } break; + case OPT_CONN: + if (parseAMF(&r->Link.extras, arg, &r->Link.edepth)) + return FALSE; + break; + } + break; + } + if (!options[i].name.av_len) { + if (error) { + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "Unknown option "); + strcat(msg, opt->av_val); + RTMPError_Alloc(error, strlen(msg)); + error->code = RTMPErrorUnknowOption; + strcpy(error->message, msg); + } + + RTMP_Log(RTMP_LOGERROR, "Unknown option %s", opt->av_val); + RTMP_OptUsage(); + return FALSE; + } + + return TRUE; +} + +int PILI_RTMP_SetupURL(PILI_RTMP *r, const char *url, RTMPError *error) { + AVal opt, arg; + char *p1, *p2, *ptr = strchr(url, ' '); + int ret, len; + unsigned int port = 0; + + if (ptr) + *ptr = '\0'; + + len = (int)strlen(url); + ret = PILI_RTMP_ParseURL2(url, &r->Link.protocol, &r->Link.hostname, + &port, &r->Link.playpath0, &r->Link.app, &r->Link.domain); + if (!ret) + return ret; + r->Link.port = port; + r->Link.playpath = r->Link.playpath0; + + while (ptr) { + *ptr++ = '\0'; + p1 = ptr; + p2 = strchr(p1, '='); + if (!p2) + break; + opt.av_val = p1; + opt.av_len = p2 - p1; + *p2++ = '\0'; + arg.av_val = p2; + ptr = strchr(p2, ' '); + if (ptr) { + *ptr = '\0'; + arg.av_len = ptr - p2; + /* skip repeated spaces */ + while (ptr[1] == ' ') + *ptr++ = '\0'; + } else { + arg.av_len = strlen(p2); + } + + /* unescape */ + port = arg.av_len; + for (p1 = p2; port > 0;) { + if (*p1 == '\\') { + unsigned int c; + if (port < 3) + return FALSE; + sscanf(p1 + 1, "%02x", &c); + *p2++ = c; + port -= 3; + p1 += 3; + } else { + *p2++ = *p1++; + port--; + } + } + arg.av_len = p2 - arg.av_val; + + ret = RTMP_SetOpt(r, &opt, &arg, error); + if (!ret) + return ret; + } + + if (!r->Link.tcUrl.av_len) { + r->Link.tcUrl.av_val = url; + if (r->Link.app.av_len) { + AVal *domain = &r->Link.domain; + if (domain->av_len == 0 && r->Link.app.av_val < url + len) { + /* if app is part of original url, just use it */ + r->Link.tcUrl.av_len = r->Link.app.av_len + (r->Link.app.av_val - url); + } else { + if (domain->av_len == 0) { + domain = &r->Link.hostname; + } + if (r->Link.port = 0) { + r->Link.port = 1935; + } + len = domain->av_len + r->Link.app.av_len + sizeof("rtmpte://:65535/"); + r->Link.tcUrl.av_val = malloc(len); + r->Link.tcUrl.av_len = snprintf(r->Link.tcUrl.av_val, len, + "%s://%.*s:%d/%.*s", + PILI_RTMPProtocolStringsLower[r->Link.protocol], + domain->av_len, domain->av_val, + r->Link.port, + r->Link.app.av_len, r->Link.app.av_val); + r->Link.lFlags |= RTMP_LF_FTCU; + } + } else { + r->Link.tcUrl.av_len = strlen(url); + } + } + +#ifdef CRYPTO + if ((r->Link.lFlags & RTMP_LF_SWFV) && r->Link.swfUrl.av_len) + RTMP_HashSWF(r->Link.swfUrl.av_val, &r->Link.SWFSize, + (unsigned char *)r->Link.SWFHash, r->Link.swfAge); +#endif + + if (r->Link.port == 0) { + if (r->Link.protocol & RTMP_FEATURE_SSL) + r->Link.port = 443; + else if (r->Link.protocol & RTMP_FEATURE_HTTP) + r->Link.port = 80; + else + r->Link.port = 1935; + } + return TRUE; +} + +static int add_addr_info(PILI_RTMP *r, struct addrinfo *hints, struct addrinfo **ai, AVal *host, int port, RTMPError *error) { + char *hostname; + int ret = TRUE; + if (host->av_val[host->av_len]) { + hostname = malloc(host->av_len + 1); + memcpy(hostname, host->av_val, host->av_len); + hostname[host->av_len] = '\0'; + } else { + hostname = host->av_val; + } + + struct addrinfo *cur_ai; + char portstr[10]; + snprintf(portstr, sizeof(portstr), "%d", port); + int addrret = getaddrinfo(hostname, portstr, hints, ai); + if (addrret != 0) { + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "Problem accessing the DNS. addr: "); + strcat(msg, hostname); + + RTMPError_Alloc(error, strlen(msg)); + error->code = RTMPErrorAccessDNSFailed; + strcpy(error->message, msg); + RTMP_Log(RTMP_LOGERROR, "Problem accessing the DNS. (addr: %s)", hostname); + ret = FALSE; + } + + if (hostname != host->av_val) { + free(hostname); + } + return ret; +} + +int PILI_RTMP_Connect0(PILI_RTMP *r, struct addrinfo *ai, unsigned short port, RTMPError *error) { + r->m_sb.sb_timedout = FALSE; + r->m_pausing = 0; + r->m_fDuration = 0.0; + + r->m_sb.sb_socket = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + if (ai->ai_family == AF_INET6) { + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)ai->ai_addr; + in6->sin6_port = htons(port); + } + if (r->m_sb.sb_socket != -1) { + if (connect(r->m_sb.sb_socket, ai->ai_addr, ai->ai_addrlen) < 0) { + int err = GetSockError(); + + if (error) { + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "Failed to connect socket. "); + strcat(msg, strerror(err)); + RTMPError_Alloc(error, strlen(msg)); + error->code = RTMPErrorFailedToConnectSocket; + strcpy(error->message, msg); + } + + RTMP_Log(RTMP_LOGERROR, "%s, failed to connect socket. %d (%s)", + __FUNCTION__, err, strerror(err)); + + PILI_RTMP_Close(r, NULL); + return FALSE; + } + + if (r->Link.socksport) { + RTMP_Log(RTMP_LOGDEBUG, "%s ... SOCKS negotiation", __FUNCTION__); + if (!SocksNegotiate(r, error)) { + if (error) { + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "Socks negotiation failed."); + RTMPError_Alloc(error, strlen(msg)); + error->code = RTMPErrorSocksNegotiationFailed; + strcpy(error->message, msg); + } + + RTMP_Log(RTMP_LOGERROR, "%s, SOCKS negotiation failed.", __FUNCTION__); + PILI_RTMP_Close(r, NULL); + return FALSE; + } + } + } else { + int err = GetSockError(); + + if (error) { + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "Failed to create socket. "); + strcat(msg, strerror(err)); + RTMPError_Alloc(error, strlen(msg)); + error->code = RTMPErrorFailedToCreateSocket; + strcpy(error->message, msg); + } + + RTMP_Log(RTMP_LOGERROR, "%s, failed to create socket. Error: %d (%s)", __FUNCTION__, err, strerror(err)); + + return FALSE; + } + + /* set receive timeout */ + { + SET_RCVTIMEO(tv, r->Link.timeout); + if (setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv))) { + RTMP_Log(RTMP_LOGERROR, "%s, Setting socket recieve timeout to %ds failed!", + __FUNCTION__, r->Link.timeout); + } + } + + /* set send timeout*/ + { + struct timeval timeout; + timeout.tv_sec = r->Link.send_timeout; + timeout.tv_usec = 0; + + if (setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout))) { + RTMP_Log(RTMP_LOGERROR, "%s, Setting socket send timeout to %ds failed!", + __FUNCTION__, r->Link.timeout); + } + } + + /* ignore sigpipe */ + int kOne = 1; +#ifdef __linux + setsockopt(r->m_sb.sb_socket, SOL_SOCKET, MSG_NOSIGNAL, &kOne, sizeof(kOne)); +#else + setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_NOSIGPIPE, &kOne, sizeof(kOne)); +#endif + if (r->m_tcp_nodelay) { + int on = 1; + setsockopt(r->m_sb.sb_socket, IPPROTO_TCP, TCP_NODELAY, (char *)&on, sizeof(on)); + } + + return TRUE; +} + +int PILI_RTMP_Connect1(PILI_RTMP *r, PILI_RTMPPacket *cp, RTMPError *error) { + if (r->Link.protocol & RTMP_FEATURE_SSL) { +#if defined(CRYPTO) && !defined(NO_SSL) + TLS_client(RTMP_TLS_ctx, r->m_sb.sb_ssl); + TLS_setfd(r->m_sb.sb_ssl, r->m_sb.sb_socket); + if (TLS_connect(r->m_sb.sb_ssl) < 0) { + if (error) { + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "TLS_Connect failed."); + RTMPError_Alloc(error, strlen(msg)); + error->code = RTMPErrorTLSConnectFailed; + strcpy(error->message, msg); + } + + RTMP_Log(RTMP_LOGERROR, "%s, TLS_Connect failed", __FUNCTION__); + RTMP_Close(r, NULL); + return FALSE; + } +#else + if (error) { + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "No SSL/TLS support."); + RTMPError_Alloc(error, strlen(msg)); + error->code = RTMPErrorNoSSLOrTLSSupport; + strcpy(error->message, msg); + } + + RTMP_Log(RTMP_LOGERROR, "%s, no SSL/TLS support", __FUNCTION__); + PILI_RTMP_Close(r, NULL); + return FALSE; + +#endif + } + if (r->Link.protocol & RTMP_FEATURE_HTTP) { + r->m_msgCounter = 1; + r->m_clientID.av_val = NULL; + r->m_clientID.av_len = 0; + HTTP_Post(r, RTMPT_OPEN, "", 1); + HTTP_read(r, 1); + r->m_msgCounter = 0; + } + RTMP_Log(RTMP_LOGDEBUG, "%s, ... connected, handshaking", __FUNCTION__); + if (!HandShake(r, TRUE, error)) { + if (error) { + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "Handshake failed."); + RTMPError_Alloc(error, strlen(msg)); + error->code = RTMPErrorHandshakeFailed; + strcpy(error->message, msg); + } + + RTMP_Log(RTMP_LOGERROR, "%s, handshake failed.", __FUNCTION__); + PILI_RTMP_Close(r, NULL); + return FALSE; + } + RTMP_Log(RTMP_LOGDEBUG, "%s, handshaked", __FUNCTION__); + + if (!SendConnectPacket(r, cp, error)) { + if (error) { + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "PILI_RTMP connect failed."); + RTMPError_Alloc(error, strlen(msg)); + error->code = RTMPErrorRTMPConnectFailed; + strcpy(error->message, msg); + } + RTMP_Log(RTMP_LOGERROR, "%s, PILI_RTMP connect failed.", __FUNCTION__); + PILI_RTMP_Close(r, NULL); + return FALSE; + } + return TRUE; +} + +int PILI_RTMP_Connect(PILI_RTMP *r, PILI_RTMPPacket *cp, RTMPError *error) { + struct PILI_CONNECTION_TIME conn_time; + if (!r->Link.hostname.av_len) + return FALSE; + + struct addrinfo hints = {0}, *ai, *cur_ai; + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_DEFAULT; + unsigned short port; + if (r->Link.socksport) { + port = r->Link.socksport; + /* Connect via SOCKS */ + if (!add_addr_info(r, &hints, &ai, &r->Link.sockshost, r->Link.socksport, error)) { + return FALSE; + } + } else { + port = r->Link.port; + /* Connect directly */ + if (!add_addr_info(r, &hints, &ai, &r->Link.hostname, r->Link.port, error)) { + return FALSE; + } + } + r->ip = 0; //useless for ipv6 + cur_ai = ai; + + int t1 = PILI_RTMP_GetTime(); + if (!PILI_RTMP_Connect0(r, cur_ai, port, error)) { + freeaddrinfo(ai); + return FALSE; + } + conn_time.connect_time = PILI_RTMP_GetTime() - t1; + r->m_bSendCounter = TRUE; + + int t2 = PILI_RTMP_GetTime(); + int ret = PILI_RTMP_Connect1(r, cp, error); + conn_time.handshake_time = PILI_RTMP_GetTime() - t2; + + if (r->m_connCallback != NULL) { + r->m_connCallback(&conn_time, r->m_userData); + } + freeaddrinfo(ai); + return ret; +} + +//useless +static int + SocksNegotiate(PILI_RTMP *r, RTMPError *error) { + // unsigned long addr; + // struct sockaddr_in service; + // memset(&service, 0, sizeof(struct sockaddr_in)); + // + // add_addr_info(r, &service, &r->Link.hostname, r->Link.port, error); + // addr = htonl(service.sin_addr.s_addr); + // + // { + // char packet[] = { + // 4, 1, /* SOCKS 4, connect */ + // (r->Link.port >> 8) & 0xFF, + // (r->Link.port) & 0xFF, + // (char)(addr >> 24) & 0xFF, (char)(addr >> 16) & 0xFF, + // (char)(addr >> 8) & 0xFF, (char)addr & 0xFF, + // 0 + // }; /* NULL terminate */ + // + // WriteN(r, packet, sizeof packet, error); + // + // if (ReadN(r, packet, 8) != 8) + // return FALSE; + // + // if (packet[0] == 0 && packet[1] == 90) + // { + // return TRUE; + // } + // else + // { + // RTMP_Log(RTMP_LOGERROR, "%s, SOCKS returned error code %d", packet[1]); + // return FALSE; + // } + // } + return 0; +} + +int PILI_RTMP_ConnectStream(PILI_RTMP *r, int seekTime, RTMPError *error) { + PILI_RTMPPacket packet = {0}; + + /* seekTime was already set by SetupStream / SetupURL. + * This is only needed by ReconnectStream. + */ + if (seekTime > 0) + r->Link.seekTime = seekTime; + + r->m_mediaChannel = 0; + + while (!r->m_bPlaying && PILI_RTMP_IsConnected(r) && PILI_RTMP_ReadPacket(r, &packet)) { + if (RTMPPacket_IsReady(&packet)) { + if (!packet.m_nBodySize) + continue; + if ((packet.m_packetType == RTMP_PACKET_TYPE_AUDIO) || + (packet.m_packetType == RTMP_PACKET_TYPE_VIDEO) || + (packet.m_packetType == RTMP_PACKET_TYPE_INFO)) { + RTMP_Log(RTMP_LOGWARNING, "Received FLV packet before play()! Ignoring."); + PILI_RTMPPacket_Free(&packet); + continue; + } + + PILI_RTMP_ClientPacket(r, &packet); + PILI_RTMPPacket_Free(&packet); + } + } + + if (!r->m_bPlaying && error) { + char *msg = "PILI_RTMP connect stream failed."; + RTMPError_Alloc(error, strlen(msg)); + error->code = RTMPErrorRTMPConnectStreamFailed; + strcpy(error->message, msg); + } + + return r->m_bPlaying; +} + +int PILI_RTMP_ReconnectStream(PILI_RTMP *r, int seekTime, RTMPError *error) { + PILI_RTMP_DeleteStream(r, error); + + PILI_RTMP_SendCreateStream(r, error); + + return PILI_RTMP_ConnectStream(r, seekTime, error); +} + +int PILI_RTMP_ToggleStream(PILI_RTMP *r, RTMPError *error) { + int res; + + if (!r->m_pausing) { + res = PILI_RTMP_SendPause(r, TRUE, r->m_pauseStamp, error); + if (!res) + return res; + + r->m_pausing = 1; + sleep(1); + } + res = PILI_RTMP_SendPause(r, FALSE, r->m_pauseStamp, error); + r->m_pausing = 3; + return res; +} + +void PILI_RTMP_DeleteStream(PILI_RTMP *r, RTMPError *error) { + if (r->m_stream_id < 0) + return; + + r->m_bPlaying = FALSE; + + SendDeleteStream(r, r->m_stream_id, error); + r->m_stream_id = -1; +} + +int PILI_RTMP_GetNextMediaPacket(PILI_RTMP *r, PILI_RTMPPacket *packet) { + int bHasMediaPacket = 0; + + while (!bHasMediaPacket && PILI_RTMP_IsConnected(r) && PILI_RTMP_ReadPacket(r, packet)) { + if (!RTMPPacket_IsReady(packet)) { + continue; + } + + bHasMediaPacket = PILI_RTMP_ClientPacket(r, packet); + + if (!bHasMediaPacket) { + PILI_RTMPPacket_Free(packet); + } else if (r->m_pausing == 3) { + if (packet->m_nTimeStamp <= r->m_mediaStamp) { + bHasMediaPacket = 0; +#ifdef _DEBUG + RTMP_Log(RTMP_LOGDEBUG, + "Skipped type: %02X, size: %d, TS: %d ms, abs TS: %d, pause: %d ms", + packet->m_packetType, packet->m_nBodySize, + packet->m_nTimeStamp, packet->m_hasAbsTimestamp, + r->m_mediaStamp); +#endif + continue; + } + r->m_pausing = 0; + } + } + + if (bHasMediaPacket) + r->m_bPlaying = TRUE; + else if (r->m_sb.sb_timedout && !r->m_pausing) + r->m_pauseStamp = r->m_channelTimestamp[r->m_mediaChannel]; + + return bHasMediaPacket; +} + +int PILI_RTMP_ClientPacket(PILI_RTMP *r, PILI_RTMPPacket *packet) { + int bHasMediaPacket = 0; + switch (packet->m_packetType) { + case 0x01: + /* chunk size */ + HandleChangeChunkSize(r, packet); + break; + + case 0x03: + /* bytes read report */ + RTMP_Log(RTMP_LOGDEBUG, "%s, received: bytes read report", __FUNCTION__); + break; + + case 0x04: + /* ctrl */ + HandleCtrl(r, packet); + break; + + case 0x05: + /* server bw */ + HandleServerBW(r, packet); + break; + + case 0x06: + /* client bw */ + HandleClientBW(r, packet); + break; + + case 0x08: + /* audio data */ + /*RTMP_Log(RTMP_LOGDEBUG, "%s, received: audio %lu bytes", __FUNCTION__, packet.m_nBodySize); */ + HandleAudio(r, packet); + bHasMediaPacket = 1; + if (!r->m_mediaChannel) + r->m_mediaChannel = packet->m_nChannel; + if (!r->m_pausing) + r->m_mediaStamp = packet->m_nTimeStamp; + break; + + case 0x09: + /* video data */ + /*RTMP_Log(RTMP_LOGDEBUG, "%s, received: video %lu bytes", __FUNCTION__, packet.m_nBodySize); */ + HandleVideo(r, packet); + bHasMediaPacket = 1; + if (!r->m_mediaChannel) + r->m_mediaChannel = packet->m_nChannel; + if (!r->m_pausing) + r->m_mediaStamp = packet->m_nTimeStamp; + break; + + case 0x0F: /* flex stream send */ + RTMP_Log(RTMP_LOGDEBUG, + "%s, flex stream send, size %lu bytes, not supported, ignoring", + __FUNCTION__, packet->m_nBodySize); + break; + + case 0x10: /* flex shared object */ + RTMP_Log(RTMP_LOGDEBUG, + "%s, flex shared object, size %lu bytes, not supported, ignoring", + __FUNCTION__, packet->m_nBodySize); + break; + + case 0x11: /* flex message */ + { + RTMP_Log(RTMP_LOGDEBUG, + "%s, flex message, size %lu bytes, not fully supported", + __FUNCTION__, packet->m_nBodySize); +/*RTMP_LogHex(packet.m_body, packet.m_nBodySize); */ + +/* some DEBUG code */ +#if 0 + RTMP_LIB_AMFObject obj; + int nRes = obj.Decode(packet.m_body+1, packet.m_nBodySize-1); + if(nRes < 0) { + RTMP_Log(RTMP_LOGERROR, "%s, error decoding AMF3 packet", __FUNCTION__); + /*return; */ + } + + obj.Dump(); +#endif + + if (HandleInvoke(r, packet->m_body + 1, packet->m_nBodySize - 1) == 1) + bHasMediaPacket = 2; + break; + } + case 0x12: + /* metadata (notify) */ + RTMP_Log(RTMP_LOGDEBUG, "%s, received: notify %lu bytes", __FUNCTION__, + packet->m_nBodySize); + if (HandleMetadata(r, packet->m_body, packet->m_nBodySize)) + bHasMediaPacket = 1; + break; + + case 0x13: + RTMP_Log(RTMP_LOGDEBUG, "%s, shared object, not supported, ignoring", + __FUNCTION__); + break; + + case 0x14: + /* invoke */ + RTMP_Log(RTMP_LOGDEBUG, "%s, received: invoke %lu bytes", __FUNCTION__, + packet->m_nBodySize); + /*RTMP_LogHex(packet.m_body, packet.m_nBodySize); */ + + if (HandleInvoke(r, packet->m_body, packet->m_nBodySize) == 1) + bHasMediaPacket = 2; + break; + + case 0x16: { + /* go through FLV packets and handle metadata packets */ + unsigned int pos = 0; + uint32_t nTimeStamp = packet->m_nTimeStamp; + + while (pos + 11 < packet->m_nBodySize) { + uint32_t dataSize = AMF_DecodeInt24(packet->m_body + pos + 1); /* size without header (11) and prevTagSize (4) */ + + if (pos + 11 + dataSize + 4 > packet->m_nBodySize) { + RTMP_Log(RTMP_LOGWARNING, "Stream corrupt?!"); + break; + } + if (packet->m_body[pos] == 0x12) { + HandleMetadata(r, packet->m_body + pos + 11, dataSize); + } else if (packet->m_body[pos] == 8 || packet->m_body[pos] == 9) { + nTimeStamp = AMF_DecodeInt24(packet->m_body + pos + 4); + nTimeStamp |= (packet->m_body[pos + 7] << 24); + } + pos += (11 + dataSize + 4); + } + if (!r->m_pausing) + r->m_mediaStamp = nTimeStamp; + + /* FLV tag(s) */ + /*RTMP_Log(RTMP_LOGDEBUG, "%s, received: FLV tag(s) %lu bytes", __FUNCTION__, packet.m_nBodySize); */ + bHasMediaPacket = 1; + break; + } + default: + RTMP_Log(RTMP_LOGDEBUG, "%s, unknown packet type received: 0x%02x", __FUNCTION__, + packet->m_packetType); +#ifdef _DEBUG + RTMP_LogHex(RTMP_LOGDEBUG, packet->m_body, packet->m_nBodySize); +#endif + } + + return bHasMediaPacket; +} + +#ifdef _DEBUG +extern FILE *netstackdump; +extern FILE *netstackdump_read; +#endif + +static int + ReadN(PILI_RTMP *r, char *buffer, int n) { + int nOriginalSize = n; + int avail; + char *ptr; + + r->m_sb.sb_timedout = FALSE; + +#ifdef _DEBUG + memset(buffer, 0, n); +#endif + + ptr = buffer; + while (n > 0) { + int nBytes = 0, nRead; + if (r->Link.protocol & RTMP_FEATURE_HTTP) { + while (!r->m_resplen) { + if (r->m_sb.sb_size < 144) { + if (!r->m_unackd) + HTTP_Post(r, RTMPT_IDLE, "", 1); + if (PILI_RTMPSockBuf_Fill(&r->m_sb) < 1) { + if (!r->m_sb.sb_timedout) { + PILI_RTMP_Close(r, NULL); + } else { + RTMPError error = {0}; + + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "PILI_RTMP socket timeout"); + RTMPError_Alloc(&error, strlen(msg)); + error.code = RTMPErrorSocketTimeout; + strcpy(error.message, msg); + + PILI_RTMP_Close(r, &error); + + RTMPError_Free(&error); + } + + return 0; + } + } + HTTP_read(r, 0); + } + if (r->m_resplen && !r->m_sb.sb_size) + PILI_RTMPSockBuf_Fill(&r->m_sb); + avail = r->m_sb.sb_size; + if (avail > r->m_resplen) + avail = r->m_resplen; + } else { + avail = r->m_sb.sb_size; + if (avail == 0) { + if (PILI_RTMPSockBuf_Fill(&r->m_sb) < 1) { + if (!r->m_sb.sb_timedout) { + PILI_RTMP_Close(r, NULL); + } else { + RTMPError error = {0}; + + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "PILI_RTMP socket timeout"); + RTMPError_Alloc(&error, strlen(msg)); + error.code = RTMPErrorSocketTimeout; + strcpy(error.message, msg); + + PILI_RTMP_Close(r, &error); + + RTMPError_Free(&error); + } + + return 0; + } + avail = r->m_sb.sb_size; + } + } + nRead = ((n < avail) ? n : avail); + if (nRead > 0) { + memcpy(ptr, r->m_sb.sb_start, nRead); + r->m_sb.sb_start += nRead; + r->m_sb.sb_size -= nRead; + nBytes = nRead; + r->m_nBytesIn += nRead; + if (r->m_bSendCounter && r->m_nBytesIn > r->m_nBytesInSent + r->m_nClientBW / 2) + SendBytesReceived(r, NULL); + } +/*RTMP_Log(RTMP_LOGDEBUG, "%s: %d bytes\n", __FUNCTION__, nBytes); */ +#ifdef _DEBUG + fwrite(ptr, 1, nBytes, netstackdump_read); +#endif + + if (nBytes == 0) { + RTMP_Log(RTMP_LOGDEBUG, "%s, PILI_RTMP socket closed by peer", __FUNCTION__); + /*goto again; */ + RTMPError error = {0}; + + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "PILI_RTMP socket closed by peer. "); + RTMPError_Alloc(&error, strlen(msg)); + error.code = RTMPErrorSocketClosedByPeer; + strcpy(error.message, msg); + + PILI_RTMP_Close(r, &error); + + RTMPError_Free(&error); + break; + } + + if (r->Link.protocol & RTMP_FEATURE_HTTP) + r->m_resplen -= nBytes; + +#ifdef CRYPTO + if (r->Link.rc4keyIn) { + RC4_encrypt(r->Link.rc4keyIn, nBytes, ptr); + } +#endif + + n -= nBytes; + ptr += nBytes; + } + + return nOriginalSize - n; +} + +static int + WriteN(PILI_RTMP *r, const char *buffer, int n, RTMPError *error) { + const char *ptr = buffer; +#ifdef CRYPTO + char *encrypted = 0; + char buf[RTMP_BUFFER_CACHE_SIZE]; + + if (r->Link.rc4keyOut) { + if (n > sizeof(buf)) + encrypted = (char *)malloc(n); + else + encrypted = (char *)buf; + ptr = encrypted; + RC4_encrypt2(r->Link.rc4keyOut, n, buffer, ptr); + } +#endif + + while (n > 0) { + int nBytes; + + if (r->Link.protocol & RTMP_FEATURE_HTTP) + nBytes = HTTP_Post(r, RTMPT_SEND, ptr, n); + else + nBytes = PILI_RTMPSockBuf_Send(&r->m_sb, ptr, n); + /*RTMP_Log(RTMP_LOGDEBUG, "%s: %d\n", __FUNCTION__, nBytes); */ + + if (nBytes < 0) { + int sockerr = GetSockError(); + RTMP_Log(RTMP_LOGERROR, "%s, PILI_RTMP send error %d, %s, (%d bytes)", __FUNCTION__, + sockerr, strerror(sockerr), n); + + if (sockerr == EINTR && !PILI_RTMP_ctrlC) + continue; + + if (error) { + char msg[100]; + memset(msg, 0, 100); + strcat(msg, "PILI_RTMP send error. socket error: "); + strcat(msg, strerror(sockerr)); + RTMPError_Alloc(error, strlen(msg)); + error->code = RTMPErrorSendFailed; + strcpy(error->message, msg); + } + + PILI_RTMP_Close(r, error); + + RTMPError_Free(error); + + n = 1; + break; + } + + if (nBytes == 0) + break; + + n -= nBytes; + ptr += nBytes; + } + +#ifdef CRYPTO + if (encrypted && encrypted != buf) + free(encrypted); +#endif + + return n == 0; +} + +#define SAVC(x) static const AVal av_##x = AVC(#x) + +SAVC(app); +SAVC(connect); +SAVC(flashVer); +SAVC(swfUrl); +SAVC(pageUrl); +SAVC(tcUrl); +SAVC(fpad); +SAVC(capabilities); +SAVC(audioCodecs); +SAVC(videoCodecs); +SAVC(videoFunction); +SAVC(objectEncoding); +SAVC(secureToken); +SAVC(secureTokenResponse); +SAVC(type); +SAVC(nonprivate); + +static int + SendConnectPacket(PILI_RTMP *r, PILI_RTMPPacket *cp, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[4096], *pend = pbuf + sizeof(pbuf); + char *enc; + + if (cp) + return PILI_RTMP_SendPacket(r, cp, TRUE, error); + + packet.m_nChannel = 0x03; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_LARGE; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_connect); + enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); + *enc++ = AMF_OBJECT; + + enc = AMF_EncodeNamedString(enc, pend, &av_app, &r->Link.app); + if (!enc) + return FALSE; + if (r->Link.protocol & RTMP_FEATURE_WRITE) { + enc = AMF_EncodeNamedString(enc, pend, &av_type, &av_nonprivate); + if (!enc) + return FALSE; + } + if (r->Link.flashVer.av_len) { + enc = AMF_EncodeNamedString(enc, pend, &av_flashVer, &r->Link.flashVer); + if (!enc) + return FALSE; + } + if (r->Link.swfUrl.av_len) { + enc = AMF_EncodeNamedString(enc, pend, &av_swfUrl, &r->Link.swfUrl); + if (!enc) + return FALSE; + } + if (r->Link.tcUrl.av_len) { + enc = AMF_EncodeNamedString(enc, pend, &av_tcUrl, &r->Link.tcUrl); + if (!enc) + return FALSE; + } + if (!(r->Link.protocol & RTMP_FEATURE_WRITE)) { + enc = AMF_EncodeNamedBoolean(enc, pend, &av_fpad, FALSE); + if (!enc) + return FALSE; + enc = AMF_EncodeNamedNumber(enc, pend, &av_capabilities, 15.0); + if (!enc) + return FALSE; + enc = AMF_EncodeNamedNumber(enc, pend, &av_audioCodecs, r->m_fAudioCodecs); + if (!enc) + return FALSE; + enc = AMF_EncodeNamedNumber(enc, pend, &av_videoCodecs, r->m_fVideoCodecs); + if (!enc) + return FALSE; + enc = AMF_EncodeNamedNumber(enc, pend, &av_videoFunction, 1.0); + if (!enc) + return FALSE; + if (r->Link.pageUrl.av_len) { + enc = AMF_EncodeNamedString(enc, pend, &av_pageUrl, &r->Link.pageUrl); + if (!enc) + return FALSE; + } + } + if (r->m_fEncoding != 0.0 || r->m_bSendEncoding) { /* AMF0, AMF3 not fully supported yet */ + enc = AMF_EncodeNamedNumber(enc, pend, &av_objectEncoding, r->m_fEncoding); + if (!enc) + return FALSE; + } + if (enc + 3 >= pend) + return FALSE; + *enc++ = 0; + *enc++ = 0; /* end of object - 0x00 0x00 0x09 */ + *enc++ = AMF_OBJECT_END; + + /* add auth string */ + if (r->Link.auth.av_len) { + enc = AMF_EncodeBoolean(enc, pend, r->Link.lFlags & RTMP_LF_AUTH); + if (!enc) + return FALSE; + enc = AMF_EncodeString(enc, pend, &r->Link.auth); + if (!enc) + return FALSE; + } + if (r->Link.extras.o_num) { + int i; + for (i = 0; i < r->Link.extras.o_num; i++) { + enc = AMFProp_Encode(&r->Link.extras.o_props[i], enc, pend); + if (!enc) + return FALSE; + } + } + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, TRUE, error); +} + +#if 0 /* unused */ +SAVC(bgHasStream); + +static int +SendBGHasStream(PILI_RTMP *r, double dId, AVal *playpath) +{ + PILI_RTMPPacket packet; + char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x03; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_bgHasStream); + enc = AMF_EncodeNumber(enc, pend, dId); + *enc++ = AMF_NULL; + + enc = AMF_EncodeString(enc, pend, playpath); + if (enc == NULL) + return FALSE; + + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, TRUE); +} +#endif + +SAVC(createStream); + +int PILI_RTMP_SendCreateStream(PILI_RTMP *r, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x03; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_createStream); + enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); + *enc++ = AMF_NULL; /* NULL */ + + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, TRUE, error); +} + +SAVC(FCSubscribe); + +static int + SendFCSubscribe(PILI_RTMP *r, AVal *subscribepath, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[512], *pend = pbuf + sizeof(pbuf); + char *enc; + packet.m_nChannel = 0x03; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + RTMP_Log(RTMP_LOGDEBUG, "FCSubscribe: %s", subscribepath->av_val); + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_FCSubscribe); + enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); + *enc++ = AMF_NULL; + enc = AMF_EncodeString(enc, pend, subscribepath); + + if (!enc) + return FALSE; + + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, TRUE, error); +} + +SAVC(releaseStream); + +static int + SendReleaseStream(PILI_RTMP *r, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x03; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_releaseStream); + enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); + *enc++ = AMF_NULL; + enc = AMF_EncodeString(enc, pend, &r->Link.playpath); + if (!enc) + return FALSE; + + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, FALSE, error); +} + +SAVC(FCPublish); + +static int + SendFCPublish(PILI_RTMP *r, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x03; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_FCPublish); + enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); + *enc++ = AMF_NULL; + enc = AMF_EncodeString(enc, pend, &r->Link.playpath); + if (!enc) + return FALSE; + + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, FALSE, error); +} + +SAVC(FCUnpublish); + +static int + SendFCUnpublish(PILI_RTMP *r, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x03; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_FCUnpublish); + enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); + *enc++ = AMF_NULL; + enc = AMF_EncodeString(enc, pend, &r->Link.playpath); + if (!enc) + return FALSE; + + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, FALSE, error); +} + +SAVC(publish); +SAVC(live); +SAVC(record); + +static int + SendPublish(PILI_RTMP *r, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x04; /* source channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_LARGE; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = r->m_stream_id; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_publish); + enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); + *enc++ = AMF_NULL; + enc = AMF_EncodeString(enc, pend, &r->Link.playpath); + if (!enc) + return FALSE; + + /* FIXME: should we choose live based on Link.lFlags & RTMP_LF_LIVE? */ + enc = AMF_EncodeString(enc, pend, &av_live); + if (!enc) + return FALSE; + + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, TRUE, error); +} + +SAVC(deleteStream); + +static int + SendDeleteStream(PILI_RTMP *r, double dStreamId, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x03; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_deleteStream); + enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); + *enc++ = AMF_NULL; + enc = AMF_EncodeNumber(enc, pend, dStreamId); + + packet.m_nBodySize = enc - packet.m_body; + + /* no response expected */ + return PILI_RTMP_SendPacket(r, &packet, FALSE, error); +} + +SAVC(pause); + +int PILI_RTMP_SendPause(PILI_RTMP *r, int DoPause, int iTime, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x08; /* video channel */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x14; /* invoke */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_pause); + enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); + *enc++ = AMF_NULL; + enc = AMF_EncodeBoolean(enc, pend, DoPause); + enc = AMF_EncodeNumber(enc, pend, (double)iTime); + + packet.m_nBodySize = enc - packet.m_body; + + RTMP_Log(RTMP_LOGDEBUG, "%s, %d, pauseTime=%d", __FUNCTION__, DoPause, iTime); + return PILI_RTMP_SendPacket(r, &packet, TRUE, error); +} + +int PILI_RTMP_Pause(PILI_RTMP *r, int DoPause, RTMPError *error) { + if (DoPause) + r->m_pauseStamp = r->m_channelTimestamp[r->m_mediaChannel]; + return PILI_RTMP_SendPause(r, DoPause, r->m_pauseStamp, error); +} + +SAVC(seek); + +int PILI_RTMP_SendSeek(PILI_RTMP *r, int iTime, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x08; /* video channel */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x14; /* invoke */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_seek); + enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); + *enc++ = AMF_NULL; + enc = AMF_EncodeNumber(enc, pend, (double)iTime); + + packet.m_nBodySize = enc - packet.m_body; + + r->m_read.flags |= RTMP_READ_SEEKING; + r->m_read.nResumeTS = 0; + + return PILI_RTMP_SendPacket(r, &packet, TRUE, error); +} + +int PILI_RTMP_SendServerBW(PILI_RTMP *r, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[256], *pend = pbuf + sizeof(pbuf); + + packet.m_nChannel = 0x02; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_LARGE; + packet.m_packetType = 0x05; /* Server BW */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + packet.m_nBodySize = 4; + + AMF_EncodeInt32(packet.m_body, pend, r->m_nServerBW); + return PILI_RTMP_SendPacket(r, &packet, FALSE, error); +} + +int PILI_RTMP_SendClientBW(PILI_RTMP *r, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[256], *pend = pbuf + sizeof(pbuf); + + packet.m_nChannel = 0x02; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_LARGE; + packet.m_packetType = 0x06; /* Client BW */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + packet.m_nBodySize = 5; + + AMF_EncodeInt32(packet.m_body, pend, r->m_nClientBW); + packet.m_body[4] = r->m_nClientBW2; + return PILI_RTMP_SendPacket(r, &packet, FALSE, error); +} + +static int + SendBytesReceived(PILI_RTMP *r, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[256], *pend = pbuf + sizeof(pbuf); + + packet.m_nChannel = 0x02; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x03; /* bytes in */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + packet.m_nBodySize = 4; + + AMF_EncodeInt32(packet.m_body, pend, r->m_nBytesIn); /* hard coded for now */ + r->m_nBytesInSent = r->m_nBytesIn; + + /*RTMP_Log(RTMP_LOGDEBUG, "Send bytes report. 0x%x (%d bytes)", (unsigned int)m_nBytesIn, m_nBytesIn); */ + return PILI_RTMP_SendPacket(r, &packet, FALSE, error); +} + +SAVC(_checkbw); + +static int + SendCheckBW(PILI_RTMP *r, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x03; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_LARGE; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0; /* RTMP_GetTime(); */ + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av__checkbw); + enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); + *enc++ = AMF_NULL; + + packet.m_nBodySize = enc - packet.m_body; + + /* triggers _onbwcheck and eventually results in _onbwdone */ + return PILI_RTMP_SendPacket(r, &packet, FALSE, error); +} + +SAVC(_result); + +static int + SendCheckBWResult(PILI_RTMP *r, double txn, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x03; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0x16 * r->m_nBWCheckCounter; /* temp inc value. till we figure it out. */ + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av__result); + enc = AMF_EncodeNumber(enc, pend, txn); + *enc++ = AMF_NULL; + enc = AMF_EncodeNumber(enc, pend, (double)r->m_nBWCheckCounter++); + + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, FALSE, error); +} + +SAVC(ping); +SAVC(pong); + +static int + SendPong(PILI_RTMP *r, double txn, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[256], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x03; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0x16 * r->m_nBWCheckCounter; /* temp inc value. till we figure it out. */ + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_pong); + enc = AMF_EncodeNumber(enc, pend, txn); + *enc++ = AMF_NULL; + + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, FALSE, error); +} + +SAVC(play); + +static int + SendPlay(PILI_RTMP *r, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x08; /* we make 8 our stream channel */ + packet.m_headerType = RTMP_PACKET_SIZE_LARGE; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = r->m_stream_id; /*0x01000000; */ + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_play); + enc = AMF_EncodeNumber(enc, pend, ++r->m_numInvokes); + *enc++ = AMF_NULL; + + RTMP_Log(RTMP_LOGDEBUG, "%s, seekTime=%d, stopTime=%d, sending play: %s", + __FUNCTION__, r->Link.seekTime, r->Link.stopTime, + r->Link.playpath.av_val); + enc = AMF_EncodeString(enc, pend, &r->Link.playpath); + if (!enc) + return FALSE; + + /* Optional parameters start and len. + * + * start: -2, -1, 0, positive number + * -2: looks for a live stream, then a recorded stream, + * if not found any open a live stream + * -1: plays a live stream + * >=0: plays a recorded streams from 'start' milliseconds + */ + if (r->Link.lFlags & RTMP_LF_LIVE) + enc = AMF_EncodeNumber(enc, pend, -1000.0); + else { + if (r->Link.seekTime > 0.0) + enc = AMF_EncodeNumber(enc, pend, r->Link.seekTime); /* resume from here */ + else + enc = AMF_EncodeNumber(enc, pend, 0.0); /*-2000.0);*/ /* recorded as default, -2000.0 is not reliable since that freezes the player if the stream is not found */ + } + if (!enc) + return FALSE; + + /* len: -1, 0, positive number + * -1: plays live or recorded stream to the end (default) + * 0: plays a frame 'start' ms away from the beginning + * >0: plays a live or recoded stream for 'len' milliseconds + */ + /*enc += EncodeNumber(enc, -1.0); */ /* len */ + if (r->Link.stopTime) { + enc = AMF_EncodeNumber(enc, pend, r->Link.stopTime - r->Link.seekTime); + if (!enc) + return FALSE; + } + + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, TRUE, error); +} + +SAVC(set_playlist); +SAVC(0); + +static int + SendPlaylist(PILI_RTMP *r, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x08; /* we make 8 our stream channel */ + packet.m_headerType = RTMP_PACKET_SIZE_LARGE; + packet.m_packetType = 0x14; /* INVOKE */ + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = r->m_stream_id; /*0x01000000; */ + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_set_playlist); + enc = AMF_EncodeNumber(enc, pend, 0); + *enc++ = AMF_NULL; + *enc++ = AMF_ECMA_ARRAY; + *enc++ = 0; + *enc++ = 0; + *enc++ = 0; + *enc++ = AMF_OBJECT; + enc = AMF_EncodeNamedString(enc, pend, &av_0, &r->Link.playpath); + if (!enc) + return FALSE; + if (enc + 3 >= pend) + return FALSE; + *enc++ = 0; + *enc++ = 0; + *enc++ = AMF_OBJECT_END; + + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, TRUE, error); +} + +static int + SendSecureTokenResponse(PILI_RTMP *r, AVal *resp, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[1024], *pend = pbuf + sizeof(pbuf); + char *enc; + + packet.m_nChannel = 0x03; /* control channel (invoke) */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x14; + packet.m_nTimeStamp = 0; + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + enc = packet.m_body; + enc = AMF_EncodeString(enc, pend, &av_secureTokenResponse); + enc = AMF_EncodeNumber(enc, pend, 0.0); + *enc++ = AMF_NULL; + enc = AMF_EncodeString(enc, pend, resp); + if (!enc) + return FALSE; + + packet.m_nBodySize = enc - packet.m_body; + + return PILI_RTMP_SendPacket(r, &packet, FALSE, error); +} + +/* +from http://jira.red5.org/confluence/display/docs/Ping: + +Ping is the most mysterious message in PILI_RTMP and till now we haven't fully interpreted it yet. In summary, Ping message is used as a special command that are exchanged between client and server. This page aims to document all known Ping messages. Expect the list to grow. + +The type of Ping packet is 0x4 and contains two mandatory parameters and two optional parameters. The first parameter is the type of Ping and in short integer. The second parameter is the target of the ping. As Ping is always sent in Channel 2 (control channel) and the target object in PILI_RTMP header is always 0 which means the Connection object, it's necessary to put an extra parameter to indicate the exact target object the Ping is sent to. The second parameter takes this responsibility. The value has the same meaning as the target object field in PILI_RTMP header. (The second value could also be used as other purposes, like RTT Ping/Pong. It is used as the timestamp.) The third and fourth parameters are optional and could be looked upon as the parameter of the Ping packet. Below is an unexhausted list of Ping messages. + + * type 0: Clear the stream. No third and fourth parameters. The second parameter could be 0. After the connection is established, a Ping 0,0 will be sent from server to client. The message will also be sent to client on the start of Play and in response of a Seek or Pause/Resume request. This Ping tells client to re-calibrate the clock with the timestamp of the next packet server sends. + * type 1: Tell the stream to clear the playing buffer. + * type 3: Buffer time of the client. The third parameter is the buffer time in millisecond. + * type 4: Reset a stream. Used together with type 0 in the case of VOD. Often sent before type 0. + * type 6: Ping the client from server. The second parameter is the current time. + * type 7: Pong reply from client. The second parameter is the time the server sent with his ping request. + * type 26: SWFVerification request + * type 27: SWFVerification response +*/ +int PILI_RTMP_SendCtrl(PILI_RTMP *r, short nType, unsigned int nObject, unsigned int nTime, RTMPError *error) { + PILI_RTMPPacket packet; + char pbuf[256], *pend = pbuf + sizeof(pbuf); + int nSize; + char *buf; + + RTMP_Log(RTMP_LOGDEBUG, "sending ctrl. type: 0x%04x", (unsigned short)nType); + + packet.m_nChannel = 0x02; /* control channel (ping) */ + packet.m_headerType = RTMP_PACKET_SIZE_MEDIUM; + packet.m_packetType = 0x04; /* ctrl */ + packet.m_nTimeStamp = 0; /* RTMP_GetTime(); */ + packet.m_nInfoField2 = 0; + packet.m_hasAbsTimestamp = 0; + packet.m_body = pbuf + RTMP_MAX_HEADER_SIZE; + + switch (nType) { + case 0x03: + nSize = 10; + break; /* buffer time */ + case 0x1A: + nSize = 3; + break; /* SWF verify request */ + case 0x1B: + nSize = 44; + break; /* SWF verify response */ + default: + nSize = 6; + break; + } + + packet.m_nBodySize = nSize; + + buf = packet.m_body; + buf = AMF_EncodeInt16(buf, pend, nType); + + if (nType == 0x1B) { +#ifdef CRYPTO + memcpy(buf, r->Link.SWFVerificationResponse, 42); + RTMP_Log(RTMP_LOGDEBUG, "Sending SWFVerification response: "); + RTMP_LogHex(RTMP_LOGDEBUG, (uint8_t *)packet.m_body, packet.m_nBodySize); +#endif + } else if (nType == 0x1A) { + *buf = nObject & 0xff; + } else { + if (nSize > 2) + buf = AMF_EncodeInt32(buf, pend, nObject); + + if (nSize > 6) + buf = AMF_EncodeInt32(buf, pend, nTime); + } + + return PILI_RTMP_SendPacket(r, &packet, FALSE, error); +} + +static void + AV_erase(PILI_RTMP_METHOD *vals, int *num, int i, int freeit) { + if (freeit) + free(vals[i].name.av_val); + (*num)--; + for (; i < *num; i++) { + vals[i] = vals[i + 1]; + } + vals[i].name.av_val = NULL; + vals[i].name.av_len = 0; + vals[i].num = 0; +} + +void PILI_RTMP_DropRequest(PILI_RTMP *r, int i, int freeit) { + AV_erase(r->m_methodCalls, &r->m_numCalls, i, freeit); +} + +static void + AV_queue(PILI_RTMP_METHOD **vals, int *num, AVal *av, int txn) { + char *tmp; + if (!(*num & 0x0f)) + *vals = realloc(*vals, (*num + 16) * sizeof(PILI_RTMP_METHOD)); + tmp = malloc(av->av_len + 1); + memcpy(tmp, av->av_val, av->av_len); + tmp[av->av_len] = '\0'; + (*vals)[*num].num = txn; + (*vals)[*num].name.av_len = av->av_len; + (*vals)[(*num)++].name.av_val = tmp; +} + +static void + AV_clear(PILI_RTMP_METHOD *vals, int num) { + int i; + for (i = 0; i < num; i++) + free(vals[i].name.av_val); + free(vals); +} + +SAVC(onBWDone); +SAVC(onFCSubscribe); +SAVC(onFCUnsubscribe); +SAVC(_onbwcheck); +SAVC(_onbwdone); +SAVC(_error); +SAVC(close); +SAVC(code); +SAVC(level); +SAVC(onStatus); +SAVC(playlist_ready); +static const AVal av_NetStream_Failed = AVC("NetStream.Failed"); +static const AVal av_NetStream_Play_Failed = AVC("NetStream.Play.Failed"); +static const AVal av_NetStream_Play_StreamNotFound = + AVC("NetStream.Play.StreamNotFound"); +static const AVal av_NetConnection_Connect_InvalidApp = + AVC("NetConnection.Connect.InvalidApp"); +static const AVal av_NetStream_Play_Start = AVC("NetStream.Play.Start"); +static const AVal av_NetStream_Play_Complete = AVC("NetStream.Play.Complete"); +static const AVal av_NetStream_Play_Stop = AVC("NetStream.Play.Stop"); +static const AVal av_NetStream_Seek_Notify = AVC("NetStream.Seek.Notify"); +static const AVal av_NetStream_Pause_Notify = AVC("NetStream.Pause.Notify"); +static const AVal av_NetStream_Play_UnpublishNotify = + AVC("NetStream.Play.UnpublishNotify"); +static const AVal av_NetStream_Publish_Start = AVC("NetStream.Publish.Start"); + +/* Returns 0 for OK/Failed/error, 1 for 'Stop or Complete' */ +static int + HandleInvoke(PILI_RTMP *r, const char *body, unsigned int nBodySize) { + AMFObject obj; + AVal method; + int txn; + int ret = 0, nRes; + if (body[0] != 0x02) /* make sure it is a string method name we start with */ + { + RTMP_Log(RTMP_LOGWARNING, "%s, Sanity failed. no string method in invoke packet", + __FUNCTION__); + return 0; + } + + nRes = AMF_Decode(&obj, body, nBodySize, FALSE); + if (nRes < 0) { + RTMP_Log(RTMP_LOGERROR, "%s, error decoding invoke packet", __FUNCTION__); + return 0; + } + + AMF_Dump(&obj); + AMFProp_GetString(AMF_GetProp(&obj, NULL, 0), &method); + txn = (int)AMFProp_GetNumber(AMF_GetProp(&obj, NULL, 1)); + RTMP_Log(RTMP_LOGDEBUG, "%s, server invoking <%s>", __FUNCTION__, method.av_val); + + RTMPError error = {0}; + + if (AVMATCH(&method, &av__result)) { + AVal methodInvoked = {0}; + int i; + + for (i = 0; i < r->m_numCalls; i++) { + if (r->m_methodCalls[i].num == txn) { + methodInvoked = r->m_methodCalls[i].name; + AV_erase(r->m_methodCalls, &r->m_numCalls, i, FALSE); + break; + } + } + if (!methodInvoked.av_val) { + RTMP_Log(RTMP_LOGDEBUG, "%s, received result id %d without matching request", + __FUNCTION__, txn); + goto leave; + } + + RTMP_Log(RTMP_LOGDEBUG, "%s, received result for method call <%s>", __FUNCTION__, + methodInvoked.av_val); + + if (AVMATCH(&methodInvoked, &av_connect)) { + if (r->Link.token.av_len) { + AMFObjectProperty p; + if (PILI_RTMP_FindFirstMatchingProperty(&obj, &av_secureToken, &p)) { + DecodeTEA(&r->Link.token, &p.p_vu.p_aval); + SendSecureTokenResponse(r, &p.p_vu.p_aval, &error); + } + } + if (r->Link.protocol & RTMP_FEATURE_WRITE) { + SendReleaseStream(r, &error); + SendFCPublish(r, &error); + } else { + PILI_RTMP_SendServerBW(r, &error); + PILI_RTMP_SendCtrl(r, 3, 0, 300, &error); + } + PILI_RTMP_SendCreateStream(r, &error); + + if (!(r->Link.protocol & RTMP_FEATURE_WRITE)) { + /* Send the FCSubscribe if live stream or if subscribepath is set */ + if (r->Link.subscribepath.av_len) + SendFCSubscribe(r, &r->Link.subscribepath, &error); + else if (r->Link.lFlags & RTMP_LF_LIVE) + SendFCSubscribe(r, &r->Link.playpath, &error); + } + } else if (AVMATCH(&methodInvoked, &av_createStream)) { + r->m_stream_id = (int)AMFProp_GetNumber(AMF_GetProp(&obj, NULL, 3)); + + if (r->Link.protocol & RTMP_FEATURE_WRITE) { + SendPublish(r, &error); + } else { + if (r->Link.lFlags & RTMP_LF_PLST) + SendPlaylist(r, &error); + SendPlay(r, &error); + PILI_RTMP_SendCtrl(r, 3, r->m_stream_id, r->m_nBufferMS, &error); + } + } else if (AVMATCH(&methodInvoked, &av_play) || + AVMATCH(&methodInvoked, &av_publish)) { + r->m_bPlaying = TRUE; + } + free(methodInvoked.av_val); + } else if (AVMATCH(&method, &av_onBWDone)) { + if (!r->m_nBWCheckCounter) + SendCheckBW(r, &error); + } else if (AVMATCH(&method, &av_onFCSubscribe)) { + /* SendOnFCSubscribe(); */ + } else if (AVMATCH(&method, &av_onFCUnsubscribe)) { + PILI_RTMP_Close(r, NULL); + ret = 1; + } else if (AVMATCH(&method, &av_ping)) { + SendPong(r, txn, &error); + } else if (AVMATCH(&method, &av__onbwcheck)) { + SendCheckBWResult(r, txn, &error); + } else if (AVMATCH(&method, &av__onbwdone)) { + int i; + for (i = 0; i < r->m_numCalls; i++) + if (AVMATCH(&r->m_methodCalls[i].name, &av__checkbw)) { + AV_erase(r->m_methodCalls, &r->m_numCalls, i, TRUE); + break; + } + } else if (AVMATCH(&method, &av__error)) { + RTMP_Log(RTMP_LOGERROR, "PILI_RTMP server sent error"); + } else if (AVMATCH(&method, &av_close)) { + RTMP_Log(RTMP_LOGERROR, "PILI_RTMP server requested close"); + RTMPError error = {0}; + char *msg = "PILI_RTMP server requested close."; + RTMPError_Alloc(&error, strlen(msg)); + error.code = RTMPErrorServerRequestedClose; + strcpy(error.message, msg); + + PILI_RTMP_Close(r, &error); + + RTMPError_Free(&error); + } else if (AVMATCH(&method, &av_onStatus)) { + AMFObject obj2; + AVal code, level; + AMFProp_GetObject(AMF_GetProp(&obj, NULL, 3), &obj2); + AMFProp_GetString(AMF_GetProp(&obj2, &av_code, -1), &code); + AMFProp_GetString(AMF_GetProp(&obj2, &av_level, -1), &level); + + RTMP_Log(RTMP_LOGDEBUG, "%s, onStatus: %s", __FUNCTION__, code.av_val); + if (AVMATCH(&code, &av_NetStream_Failed) || AVMATCH(&code, &av_NetStream_Play_Failed) || AVMATCH(&code, &av_NetStream_Play_StreamNotFound) || AVMATCH(&code, &av_NetConnection_Connect_InvalidApp)) { + r->m_stream_id = -1; + + int err_code; + char msg[100]; + memset(msg, 0, 100); + + if (AVMATCH(&code, &av_NetStream_Failed)) { + err_code = RTMPErrorNetStreamFailed; + strcpy(msg, "NetStream failed."); + } else if (AVMATCH(&code, &av_NetStream_Play_Failed)) { + err_code = RTMPErrorNetStreamPlayFailed; + strcpy(msg, "NetStream play failed."); + } else if (AVMATCH(&code, &av_NetStream_Play_StreamNotFound)) { + err_code = RTMPErrorNetStreamPlayStreamNotFound; + strcpy(msg, "NetStream play stream not found."); + } else if (AVMATCH(&code, &av_NetConnection_Connect_InvalidApp)) { + err_code = RTMPErrorNetConnectionConnectInvalidApp; + strcpy(msg, "NetConnection connect invalip app."); + } else { + err_code = RTMPErrorUnknow; + strcpy(msg, "Unknow error."); + } + + RTMPError_Alloc(&error, strlen(msg)); + error.code = err_code; + strcpy(error.message, msg); + + PILI_RTMP_Close(r, &error); + + RTMPError_Free(&error); + + RTMP_Log(RTMP_LOGERROR, "Closing connection: %s", code.av_val); + } + + else if (AVMATCH(&code, &av_NetStream_Play_Start)) { + int i; + r->m_bPlaying = TRUE; + for (i = 0; i < r->m_numCalls; i++) { + if (AVMATCH(&r->m_methodCalls[i].name, &av_play)) { + AV_erase(r->m_methodCalls, &r->m_numCalls, i, TRUE); + break; + } + } + } + + else if (AVMATCH(&code, &av_NetStream_Publish_Start)) { + int i; + r->m_bPlaying = TRUE; + for (i = 0; i < r->m_numCalls; i++) { + if (AVMATCH(&r->m_methodCalls[i].name, &av_publish)) { + AV_erase(r->m_methodCalls, &r->m_numCalls, i, TRUE); + break; + } + } + } + + /* Return 1 if this is a Play.Complete or Play.Stop */ + else if (AVMATCH(&code, &av_NetStream_Play_Complete) || AVMATCH(&code, &av_NetStream_Play_Stop) || AVMATCH(&code, &av_NetStream_Play_UnpublishNotify)) { + PILI_RTMP_Close(r, NULL); + ret = 1; + } + + else if (AVMATCH(&code, &av_NetStream_Seek_Notify)) { + r->m_read.flags &= ~RTMP_READ_SEEKING; + } + + else if (AVMATCH(&code, &av_NetStream_Pause_Notify)) { + if (r->m_pausing == 1 || r->m_pausing == 2) { + PILI_RTMP_SendPause(r, FALSE, r->m_pauseStamp, &error); + r->m_pausing = 3; + } + } + } else if (AVMATCH(&method, &av_playlist_ready)) { + int i; + for (i = 0; i < r->m_numCalls; i++) { + if (AVMATCH(&r->m_methodCalls[i].name, &av_set_playlist)) { + AV_erase(r->m_methodCalls, &r->m_numCalls, i, TRUE); + break; + } + } + } else { + } +leave: + AMF_Reset(&obj); + return ret; +} + +int PILI_RTMP_FindFirstMatchingProperty(AMFObject *obj, const AVal *name, + AMFObjectProperty *p) { + int n; + /* this is a small object search to locate the "duration" property */ + for (n = 0; n < obj->o_num; n++) { + AMFObjectProperty *prop = AMF_GetProp(obj, NULL, n); + + if (AVMATCH(&prop->p_name, name)) { + *p = *prop; + return TRUE; + } + + if (prop->p_type == AMF_OBJECT) { + if (PILI_RTMP_FindFirstMatchingProperty(&prop->p_vu.p_object, name, p)) + return TRUE; + } + } + return FALSE; +} + +/* Like above, but only check if name is a prefix of property */ +int PILI_RTMP_FindPrefixProperty(AMFObject *obj, const AVal *name, + AMFObjectProperty *p) { + int n; + for (n = 0; n < obj->o_num; n++) { + AMFObjectProperty *prop = AMF_GetProp(obj, NULL, n); + + if (prop->p_name.av_len > name->av_len && + !memcmp(prop->p_name.av_val, name->av_val, name->av_len)) { + *p = *prop; + return TRUE; + } + + if (prop->p_type == AMF_OBJECT) { + if (PILI_RTMP_FindPrefixProperty(&prop->p_vu.p_object, name, p)) + return TRUE; + } + } + return FALSE; +} + +static int + DumpMetaData(AMFObject *obj) { + AMFObjectProperty *prop; + int n; + for (n = 0; n < obj->o_num; n++) { + prop = AMF_GetProp(obj, NULL, n); + if (prop->p_type != AMF_OBJECT) { + char str[256] = ""; + switch (prop->p_type) { + case AMF_NUMBER: + snprintf(str, 255, "%.2f", prop->p_vu.p_number); + break; + case AMF_BOOLEAN: + snprintf(str, 255, "%s", + prop->p_vu.p_number != 0. ? "TRUE" : "FALSE"); + break; + case AMF_STRING: + snprintf(str, 255, "%.*s", prop->p_vu.p_aval.av_len, + prop->p_vu.p_aval.av_val); + break; + case AMF_DATE: + snprintf(str, 255, "timestamp:%.2f", prop->p_vu.p_number); + break; + default: + snprintf(str, 255, "INVALID TYPE 0x%02x", + (unsigned char)prop->p_type); + } + if (prop->p_name.av_len) { + /* chomp */ + if (strlen(str) >= 1 && str[strlen(str) - 1] == '\n') + str[strlen(str) - 1] = '\0'; + RTMP_Log(RTMP_LOGINFO, " %-22.*s%s", prop->p_name.av_len, + prop->p_name.av_val, str); + } + } else { + if (prop->p_name.av_len) + RTMP_Log(RTMP_LOGINFO, "%.*s:", prop->p_name.av_len, prop->p_name.av_val); + DumpMetaData(&prop->p_vu.p_object); + } + } + return FALSE; +} + +SAVC(onMetaData); +SAVC(duration); +SAVC(video); +SAVC(audio); + +static int + HandleMetadata(PILI_RTMP *r, char *body, unsigned int len) { + /* allright we get some info here, so parse it and print it */ + /* also keep duration or filesize to make a nice progress bar */ + + AMFObject obj; + AVal metastring; + int ret = FALSE; + + int nRes = AMF_Decode(&obj, body, len, FALSE); + if (nRes < 0) { + RTMP_Log(RTMP_LOGERROR, "%s, error decoding meta data packet", __FUNCTION__); + return FALSE; + } + + AMF_Dump(&obj); + AMFProp_GetString(AMF_GetProp(&obj, NULL, 0), &metastring); + + if (AVMATCH(&metastring, &av_onMetaData)) { + AMFObjectProperty prop; + /* Show metadata */ + RTMP_Log(RTMP_LOGINFO, "Metadata:"); + DumpMetaData(&obj); + if (PILI_RTMP_FindFirstMatchingProperty(&obj, &av_duration, &prop)) { + r->m_fDuration = prop.p_vu.p_number; + /*RTMP_Log(RTMP_LOGDEBUG, "Set duration: %.2f", m_fDuration); */ + } + /* Search for audio or video tags */ + if (PILI_RTMP_FindPrefixProperty(&obj, &av_video, &prop)) + r->m_read.dataType |= 1; + if (PILI_RTMP_FindPrefixProperty(&obj, &av_audio, &prop)) + r->m_read.dataType |= 4; + ret = TRUE; + } + AMF_Reset(&obj); + return ret; +} + +static void + HandleChangeChunkSize(PILI_RTMP *r, const PILI_RTMPPacket *packet) { + if (packet->m_nBodySize >= 4) { + r->m_inChunkSize = AMF_DecodeInt32(packet->m_body); + RTMP_Log(RTMP_LOGDEBUG, "%s, received: chunk size change to %d", __FUNCTION__, + r->m_inChunkSize); + } +} + +static void + HandleAudio(PILI_RTMP *r, const PILI_RTMPPacket *packet) { +} + +static void + HandleVideo(PILI_RTMP *r, const PILI_RTMPPacket *packet) { +} + +static void + HandleCtrl(PILI_RTMP *r, const PILI_RTMPPacket *packet) { + short nType = -1; + unsigned int tmp; + if (packet->m_body && packet->m_nBodySize >= 2) + nType = AMF_DecodeInt16(packet->m_body); + RTMP_Log(RTMP_LOGDEBUG, "%s, received ctrl. type: %d, len: %d", __FUNCTION__, nType, + packet->m_nBodySize); + /*RTMP_LogHex(packet.m_body, packet.m_nBodySize); */ + + if (packet->m_nBodySize >= 6) { + switch (nType) { + case 0: + tmp = AMF_DecodeInt32(packet->m_body + 2); + RTMP_Log(RTMP_LOGDEBUG, "%s, Stream Begin %d", __FUNCTION__, tmp); + break; + + case 1: + tmp = AMF_DecodeInt32(packet->m_body + 2); + RTMP_Log(RTMP_LOGDEBUG, "%s, Stream EOF %d", __FUNCTION__, tmp); + if (r->m_pausing == 1) + r->m_pausing = 2; + break; + + case 2: + tmp = AMF_DecodeInt32(packet->m_body + 2); + RTMP_Log(RTMP_LOGDEBUG, "%s, Stream Dry %d", __FUNCTION__, tmp); + break; + + case 4: + tmp = AMF_DecodeInt32(packet->m_body + 2); + RTMP_Log(RTMP_LOGDEBUG, "%s, Stream IsRecorded %d", __FUNCTION__, tmp); + break; + + case 6: /* server ping. reply with pong. */ + tmp = AMF_DecodeInt32(packet->m_body + 2); + RTMP_Log(RTMP_LOGDEBUG, "%s, Ping %d", __FUNCTION__, tmp); + PILI_RTMP_SendCtrl(r, 0x07, tmp, 0, NULL); + break; + + /* FMS 3.5 servers send the following two controls to let the client + * know when the server has sent a complete buffer. I.e., when the + * server has sent an amount of data equal to m_nBufferMS in duration. + * The server meters its output so that data arrives at the client + * in realtime and no faster. + * + * The rtmpdump program tries to set m_nBufferMS as large as + * possible, to force the server to send data as fast as possible. + * In practice, the server appears to cap this at about 1 hour's + * worth of data. After the server has sent a complete buffer, and + * sends this BufferEmpty message, it will wait until the play + * duration of that buffer has passed before sending a new buffer. + * The BufferReady message will be sent when the new buffer starts. + * (There is no BufferReady message for the very first buffer; + * presumably the Stream Begin message is sufficient for that + * purpose.) + * + * If the network speed is much faster than the data bitrate, then + * there may be long delays between the end of one buffer and the + * start of the next. + * + * Since usually the network allows data to be sent at + * faster than realtime, and rtmpdump wants to download the data + * as fast as possible, we use this RTMP_LF_BUFX hack: when we + * get the BufferEmpty message, we send a Pause followed by an + * Unpause. This causes the server to send the next buffer immediately + * instead of waiting for the full duration to elapse. (That's + * also the purpose of the ToggleStream function, which rtmpdump + * calls if we get a read timeout.) + * + * Media player apps don't need this hack since they are just + * going to play the data in realtime anyway. It also doesn't work + * for live streams since they obviously can only be sent in + * realtime. And it's all moot if the network speed is actually + * slower than the media bitrate. + */ + case 31: + tmp = AMF_DecodeInt32(packet->m_body + 2); + RTMP_Log(RTMP_LOGDEBUG, "%s, Stream BufferEmpty %d", __FUNCTION__, tmp); + if (!(r->Link.lFlags & RTMP_LF_BUFX)) + break; + if (!r->m_pausing) { + r->m_pauseStamp = r->m_channelTimestamp[r->m_mediaChannel]; + PILI_RTMP_SendPause(r, TRUE, r->m_pauseStamp, NULL); + r->m_pausing = 1; + } else if (r->m_pausing == 2) { + PILI_RTMP_SendPause(r, FALSE, r->m_pauseStamp, NULL); + r->m_pausing = 3; + } + break; + + case 32: + tmp = AMF_DecodeInt32(packet->m_body + 2); + RTMP_Log(RTMP_LOGDEBUG, "%s, Stream BufferReady %d", __FUNCTION__, tmp); + break; + + default: + tmp = AMF_DecodeInt32(packet->m_body + 2); + RTMP_Log(RTMP_LOGDEBUG, "%s, Stream xx %d", __FUNCTION__, tmp); + break; + } + } + + if (nType == 0x1A) { + RTMP_Log(RTMP_LOGDEBUG, "%s, SWFVerification ping received: ", __FUNCTION__); +#ifdef CRYPTO + /*RTMP_LogHex(packet.m_body, packet.m_nBodySize); */ + + /* respond with HMAC SHA256 of decompressed SWF, key is the 30byte player key, also the last 30 bytes of the server handshake are applied */ + if (r->Link.SWFSize) { + PILI_RTMP_SendCtrl(r, 0x1B, 0, 0); + } else { + RTMP_Log(RTMP_LOGERROR, + "%s: Ignoring SWFVerification request, use --swfVfy!", + __FUNCTION__); + } +#else + RTMP_Log(RTMP_LOGERROR, + "%s: Ignoring SWFVerification request, no CRYPTO support!", + __FUNCTION__); +#endif + } +} + +static void + HandleServerBW(PILI_RTMP *r, const PILI_RTMPPacket *packet) { + r->m_nServerBW = AMF_DecodeInt32(packet->m_body); + RTMP_Log(RTMP_LOGDEBUG, "%s: server BW = %d", __FUNCTION__, r->m_nServerBW); +} + +static void + HandleClientBW(PILI_RTMP *r, const PILI_RTMPPacket *packet) { + r->m_nClientBW = AMF_DecodeInt32(packet->m_body); + if (packet->m_nBodySize > 4) + r->m_nClientBW2 = packet->m_body[4]; + else + r->m_nClientBW2 = -1; + RTMP_Log(RTMP_LOGDEBUG, "%s: client BW = %d %d", __FUNCTION__, r->m_nClientBW, + r->m_nClientBW2); +} + +static int + DecodeInt32LE(const char *data) { + unsigned char *c = (unsigned char *)data; + unsigned int val; + + val = (c[3] << 24) | (c[2] << 16) | (c[1] << 8) | c[0]; + return val; +} + +static int + EncodeInt32LE(char *output, int nVal) { + output[0] = nVal; + nVal >>= 8; + output[1] = nVal; + nVal >>= 8; + output[2] = nVal; + nVal >>= 8; + output[3] = nVal; + return 4; +} + +int PILI_RTMP_ReadPacket(PILI_RTMP *r, PILI_RTMPPacket *packet) { + uint8_t hbuf[RTMP_MAX_HEADER_SIZE] = {0}; + char *header = (char *)hbuf; + int nSize, hSize, nToRead, nChunk; + int didAlloc = FALSE; + + RTMP_Log(RTMP_LOGDEBUG2, "%s: fd=%d", __FUNCTION__, r->m_sb.sb_socket); + + if (ReadN(r, (char *)hbuf, 1) == 0) { + RTMP_Log(RTMP_LOGERROR, "%s, failed to read PILI_RTMP packet header", __FUNCTION__); + return FALSE; + } + + packet->m_headerType = (hbuf[0] & 0xc0) >> 6; + packet->m_nChannel = (hbuf[0] & 0x3f); + header++; + if (packet->m_nChannel == 0) { + if (ReadN(r, (char *)&hbuf[1], 1) != 1) { + RTMP_Log(RTMP_LOGERROR, "%s, failed to read PILI_RTMP packet header 2nd byte", + __FUNCTION__); + return FALSE; + } + packet->m_nChannel = hbuf[1]; + packet->m_nChannel += 64; + header++; + } else if (packet->m_nChannel == 1) { + int tmp; + if (ReadN(r, (char *)&hbuf[1], 2) != 2) { + RTMP_Log(RTMP_LOGERROR, "%s, failed to read PILI_RTMP packet header 3nd byte", + __FUNCTION__); + return FALSE; + } + tmp = (hbuf[2] << 8) + hbuf[1]; + packet->m_nChannel = tmp + 64; + RTMP_Log(RTMP_LOGDEBUG, "%s, m_nChannel: %0x", __FUNCTION__, packet->m_nChannel); + header += 2; + } + + nSize = packetSize[packet->m_headerType]; + + if (nSize == RTMP_LARGE_HEADER_SIZE) /* if we get a full header the timestamp is absolute */ + packet->m_hasAbsTimestamp = TRUE; + + else if (nSize < RTMP_LARGE_HEADER_SIZE) { /* using values from the last message of this channel */ + if (r->m_vecChannelsIn[packet->m_nChannel]) + memcpy(packet, r->m_vecChannelsIn[packet->m_nChannel], + sizeof(PILI_RTMPPacket)); + } + + nSize--; + + if (nSize > 0 && ReadN(r, header, nSize) != nSize) { + RTMP_Log(RTMP_LOGERROR, "%s, failed to read PILI_RTMP packet header. type: %x", + __FUNCTION__, (unsigned int)hbuf[0]); + return FALSE; + } + + hSize = nSize + (header - (char *)hbuf); + + if (nSize >= 3) { + packet->m_nTimeStamp = AMF_DecodeInt24(header); + + /*RTMP_Log(RTMP_LOGDEBUG, "%s, reading PILI_RTMP packet chunk on channel %x, headersz %i, timestamp %i, abs timestamp %i", __FUNCTION__, packet.m_nChannel, nSize, packet.m_nTimeStamp, packet.m_hasAbsTimestamp); */ + + if (nSize >= 6) { + packet->m_nBodySize = AMF_DecodeInt24(header + 3); + packet->m_nBytesRead = 0; + PILI_RTMPPacket_Free(packet); + + if (nSize > 6) { + packet->m_packetType = header[6]; + + if (nSize == 11) + packet->m_nInfoField2 = DecodeInt32LE(header + 7); + } + } + if (packet->m_nTimeStamp == 0xffffff) { + if (ReadN(r, header + nSize, 4) != 4) { + RTMP_Log(RTMP_LOGERROR, "%s, failed to read extended timestamp", + __FUNCTION__); + return FALSE; + } + packet->m_nTimeStamp = AMF_DecodeInt32(header + nSize); + hSize += 4; + } + } + + RTMP_LogHexString(RTMP_LOGDEBUG2, (uint8_t *)hbuf, hSize); + + if (packet->m_nBodySize > 0 && packet->m_body == NULL) { + if (!PILI_RTMPPacket_Alloc(packet, packet->m_nBodySize)) { + RTMP_Log(RTMP_LOGDEBUG, "%s, failed to allocate packet", __FUNCTION__); + return FALSE; + } + didAlloc = TRUE; + packet->m_headerType = (hbuf[0] & 0xc0) >> 6; + } + + nToRead = packet->m_nBodySize - packet->m_nBytesRead; + nChunk = r->m_inChunkSize; + if (nToRead < nChunk) + nChunk = nToRead; + + /* Does the caller want the raw chunk? */ + if (packet->m_chunk) { + packet->m_chunk->c_headerSize = hSize; + memcpy(packet->m_chunk->c_header, hbuf, hSize); + packet->m_chunk->c_chunk = packet->m_body + packet->m_nBytesRead; + packet->m_chunk->c_chunkSize = nChunk; + } + + if (ReadN(r, packet->m_body + packet->m_nBytesRead, nChunk) != nChunk) { + RTMP_Log(RTMP_LOGERROR, "%s, failed to read PILI_RTMP packet body. len: %lu", + __FUNCTION__, packet->m_nBodySize); + return FALSE; + } + + RTMP_LogHexString(RTMP_LOGDEBUG2, (uint8_t *)packet->m_body + packet->m_nBytesRead, nChunk); + + packet->m_nBytesRead += nChunk; + + /* keep the packet as ref for other packets on this channel */ + if (!r->m_vecChannelsIn[packet->m_nChannel]) + r->m_vecChannelsIn[packet->m_nChannel] = malloc(sizeof(PILI_RTMPPacket)); + memcpy(r->m_vecChannelsIn[packet->m_nChannel], packet, sizeof(PILI_RTMPPacket)); + + if (RTMPPacket_IsReady(packet)) { + /* make packet's timestamp absolute */ + if (!packet->m_hasAbsTimestamp) + packet->m_nTimeStamp += r->m_channelTimestamp[packet->m_nChannel]; /* timestamps seem to be always relative!! */ + + r->m_channelTimestamp[packet->m_nChannel] = packet->m_nTimeStamp; + + /* reset the data from the stored packet. we keep the header since we may use it later if a new packet for this channel */ + /* arrives and requests to re-use some info (small packet header) */ + r->m_vecChannelsIn[packet->m_nChannel]->m_body = NULL; + r->m_vecChannelsIn[packet->m_nChannel]->m_nBytesRead = 0; + r->m_vecChannelsIn[packet->m_nChannel]->m_hasAbsTimestamp = FALSE; /* can only be false if we reuse header */ + } else { + packet->m_body = NULL; /* so it won't be erased on free */ + } + + return TRUE; +} + +#ifndef CRYPTO +static int + HandShake(PILI_RTMP *r, int FP9HandShake, RTMPError *error) { + int i; + uint32_t uptime, suptime; + int bMatch; + char type; + char clientbuf[RTMP_SIG_SIZE + 1], *clientsig = clientbuf + 1; + char serversig[RTMP_SIG_SIZE]; + + clientbuf[0] = 0x03; /* not encrypted */ + + uptime = htonl(PILI_RTMP_GetTime()); + memcpy(clientsig, &uptime, 4); + + memset(&clientsig[4], 0, 4); + +#ifdef _DEBUG + for (i = 8; i < RTMP_SIG_SIZE; i++) + clientsig[i] = 0xff; +#else + for (i = 8; i < RTMP_SIG_SIZE; i++) + clientsig[i] = (char)(rand() % 256); +#endif + + if (!WriteN(r, clientbuf, RTMP_SIG_SIZE + 1, error)) + return FALSE; + + if (ReadN(r, &type, 1) != 1) /* 0x03 or 0x06 */ + return FALSE; + + RTMP_Log(RTMP_LOGDEBUG, "%s: Type Answer : %02X", __FUNCTION__, type); + + if (type != clientbuf[0]) + RTMP_Log(RTMP_LOGWARNING, "%s: Type mismatch: client sent %d, server answered %d", + __FUNCTION__, clientbuf[0], type); + + if (ReadN(r, serversig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE) + return FALSE; + + /* decode server response */ + + memcpy(&suptime, serversig, 4); + suptime = ntohl(suptime); + + RTMP_Log(RTMP_LOGDEBUG, "%s: Server Uptime : %d", __FUNCTION__, suptime); + RTMP_Log(RTMP_LOGDEBUG, "%s: FMS Version : %d.%d.%d.%d", __FUNCTION__, + serversig[4], serversig[5], serversig[6], serversig[7]); + + /* 2nd part of handshake */ + if (!WriteN(r, serversig, RTMP_SIG_SIZE, error)) + return FALSE; + + if (ReadN(r, serversig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE) + return FALSE; + + bMatch = (memcmp(serversig, clientsig, RTMP_SIG_SIZE) == 0); + if (!bMatch) { + RTMP_Log(RTMP_LOGWARNING, "%s, client signature does not match!", __FUNCTION__); + } + return TRUE; +} + +static int + SHandShake(PILI_RTMP *r, RTMPError *error) { + int i; + char serverbuf[RTMP_SIG_SIZE + 1], *serversig = serverbuf + 1; + char clientsig[RTMP_SIG_SIZE]; + uint32_t uptime; + int bMatch; + + if (ReadN(r, serverbuf, 1) != 1) /* 0x03 or 0x06 */ + return FALSE; + + RTMP_Log(RTMP_LOGDEBUG, "%s: Type Request : %02X", __FUNCTION__, serverbuf[0]); + + if (serverbuf[0] != 3) { + RTMP_Log(RTMP_LOGERROR, "%s: Type unknown: client sent %02X", + __FUNCTION__, serverbuf[0]); + return FALSE; + } + + uptime = htonl(PILI_RTMP_GetTime()); + memcpy(serversig, &uptime, 4); + + memset(&serversig[4], 0, 4); +#ifdef _DEBUG + for (i = 8; i < RTMP_SIG_SIZE; i++) + serversig[i] = 0xff; +#else + for (i = 8; i < RTMP_SIG_SIZE; i++) + serversig[i] = (char)(rand() % 256); +#endif + + if (!WriteN(r, serverbuf, RTMP_SIG_SIZE + 1, error)) + return FALSE; + + if (ReadN(r, clientsig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE) + return FALSE; + + /* decode client response */ + + memcpy(&uptime, clientsig, 4); + uptime = ntohl(uptime); + + RTMP_Log(RTMP_LOGDEBUG, "%s: Client Uptime : %d", __FUNCTION__, uptime); + RTMP_Log(RTMP_LOGDEBUG, "%s: Player Version: %d.%d.%d.%d", __FUNCTION__, + clientsig[4], clientsig[5], clientsig[6], clientsig[7]); + + /* 2nd part of handshake */ + if (!WriteN(r, clientsig, RTMP_SIG_SIZE, error)) + return FALSE; + + if (ReadN(r, clientsig, RTMP_SIG_SIZE) != RTMP_SIG_SIZE) + return FALSE; + + bMatch = (memcmp(serversig, clientsig, RTMP_SIG_SIZE) == 0); + if (!bMatch) { + RTMP_Log(RTMP_LOGWARNING, "%s, client signature does not match!", __FUNCTION__); + } + return TRUE; +} +#endif + +int PILI_RTMP_SendChunk(PILI_RTMP *r, PILI_RTMPChunk *chunk, RTMPError *error) { + int wrote; + char hbuf[RTMP_MAX_HEADER_SIZE]; + + RTMP_Log(RTMP_LOGDEBUG2, "%s: fd=%d, size=%d", __FUNCTION__, r->m_sb.sb_socket, + chunk->c_chunkSize); + RTMP_LogHexString(RTMP_LOGDEBUG2, (uint8_t *)chunk->c_header, chunk->c_headerSize); + if (chunk->c_chunkSize) { + char *ptr = chunk->c_chunk - chunk->c_headerSize; + RTMP_LogHexString(RTMP_LOGDEBUG2, (uint8_t *)chunk->c_chunk, chunk->c_chunkSize); + /* save header bytes we're about to overwrite */ + memcpy(hbuf, ptr, chunk->c_headerSize); + memcpy(ptr, chunk->c_header, chunk->c_headerSize); + wrote = WriteN(r, ptr, chunk->c_headerSize + chunk->c_chunkSize, error); + memcpy(ptr, hbuf, chunk->c_headerSize); + } else + wrote = WriteN(r, chunk->c_header, chunk->c_headerSize, error); + return wrote; +} + +int PILI_RTMP_SendPacket(PILI_RTMP *r, PILI_RTMPPacket *packet, int queue, RTMPError *error) { + const PILI_RTMPPacket *prevPacket = r->m_vecChannelsOut[packet->m_nChannel]; + uint32_t last = 0; + int nSize; + int hSize, cSize; + char *header, *hptr, *hend, hbuf[RTMP_MAX_HEADER_SIZE], c; + uint32_t t; + char *buffer, *tbuf = NULL, *toff = NULL; + int nChunkSize; + int tlen; + + if (prevPacket && packet->m_headerType != RTMP_PACKET_SIZE_LARGE) { + /* compress a bit by using the prev packet's attributes */ + if (prevPacket->m_nBodySize == packet->m_nBodySize && prevPacket->m_packetType == packet->m_packetType && packet->m_headerType == RTMP_PACKET_SIZE_MEDIUM) + packet->m_headerType = RTMP_PACKET_SIZE_SMALL; + + if (prevPacket->m_nTimeStamp == packet->m_nTimeStamp && packet->m_headerType == RTMP_PACKET_SIZE_SMALL) + packet->m_headerType = RTMP_PACKET_SIZE_MINIMUM; + last = prevPacket->m_nTimeStamp; + } + + if (packet->m_headerType > 3) /* sanity */ + { + if (error) { + char *msg = "Sanity failed."; + RTMPError_Alloc(error, strlen(msg)); + error->code = RTMPErrorSanityFailed; + strcpy(error->message, msg); + } + + RTMP_Log(RTMP_LOGERROR, "sanity failed!! trying to send header of type: 0x%02x.", + (unsigned char)packet->m_headerType); + + return FALSE; + } + + nSize = packetSize[packet->m_headerType]; + hSize = nSize; + cSize = 0; + t = packet->m_nTimeStamp - last; + + if (packet->m_body) { + header = packet->m_body - nSize; + hend = packet->m_body; + } else { + header = hbuf + 6; + hend = hbuf + sizeof(hbuf); + } + + if (packet->m_nChannel > 319) + cSize = 2; + else if (packet->m_nChannel > 63) + cSize = 1; + if (cSize) { + header -= cSize; + hSize += cSize; + } + + if (nSize > 1 && t >= 0xffffff) { + header -= 4; + hSize += 4; + } + + hptr = header; + c = packet->m_headerType << 6; + switch (cSize) { + case 0: + c |= packet->m_nChannel; + break; + case 1: + break; + case 2: + c |= 1; + break; + } + *hptr++ = c; + if (cSize) { + int tmp = packet->m_nChannel - 64; + *hptr++ = tmp & 0xff; + if (cSize == 2) + *hptr++ = tmp >> 8; + } + + if (nSize > 1) { + hptr = AMF_EncodeInt24(hptr, hend, t > 0xffffff ? 0xffffff : t); + } + + if (nSize > 4) { + hptr = AMF_EncodeInt24(hptr, hend, packet->m_nBodySize); + *hptr++ = packet->m_packetType; + } + + if (nSize > 8) + hptr += EncodeInt32LE(hptr, packet->m_nInfoField2); + + if (nSize > 1 && t >= 0xffffff) + hptr = AMF_EncodeInt32(hptr, hend, t); + + nSize = packet->m_nBodySize; + buffer = packet->m_body; + nChunkSize = r->m_outChunkSize; + + RTMP_Log(RTMP_LOGDEBUG2, "%s: fd=%d, size=%d", __FUNCTION__, r->m_sb.sb_socket, + nSize); + /* send all chunks in one HTTP request */ + if (r->Link.protocol & RTMP_FEATURE_HTTP) { + int chunks = (nSize + nChunkSize - 1) / nChunkSize; + if (chunks > 1) { + tlen = chunks * (cSize + 1) + nSize + hSize; + tbuf = malloc(tlen); + if (!tbuf) + return FALSE; + toff = tbuf; + } + } + while (nSize + hSize) { + int wrote; + + if (nSize < nChunkSize) + nChunkSize = nSize; + + RTMP_LogHexString(RTMP_LOGDEBUG2, (uint8_t *)header, hSize); + RTMP_LogHexString(RTMP_LOGDEBUG2, (uint8_t *)buffer, nChunkSize); + if (tbuf) { + memcpy(toff, header, nChunkSize + hSize); + toff += nChunkSize + hSize; + } else { + wrote = WriteN(r, header, nChunkSize + hSize, error); + if (!wrote) + return FALSE; + } + nSize -= nChunkSize; + buffer += nChunkSize; + hSize = 0; + + if (nSize > 0) { + header = buffer - 1; + hSize = 1; + if (cSize) { + header -= cSize; + hSize += cSize; + } + *header = (0xc0 | c); + if (cSize) { + int tmp = packet->m_nChannel - 64; + header[1] = tmp & 0xff; + if (cSize == 2) + header[2] = tmp >> 8; + } + } + } + if (tbuf) { + int wrote = WriteN(r, tbuf, toff - tbuf, error); + free(tbuf); + tbuf = NULL; + if (!wrote) + return FALSE; + } + + /* we invoked a remote method */ + if (packet->m_packetType == 0x14) { + AVal method; + char *ptr; + ptr = packet->m_body + 1; + AMF_DecodeString(ptr, &method); + RTMP_Log(RTMP_LOGDEBUG, "Invoking %s", method.av_val); + /* keep it in call queue till result arrives */ + if (queue) { + int txn; + ptr += 3 + method.av_len; + txn = (int)AMF_DecodeNumber(ptr); + AV_queue(&r->m_methodCalls, &r->m_numCalls, &method, txn); + } + } + + if (!r->m_vecChannelsOut[packet->m_nChannel]) + r->m_vecChannelsOut[packet->m_nChannel] = malloc(sizeof(PILI_RTMPPacket)); + memcpy(r->m_vecChannelsOut[packet->m_nChannel], packet, sizeof(PILI_RTMPPacket)); + return TRUE; +} + +int PILI_RTMP_Serve(PILI_RTMP *r, RTMPError *error) { + return SHandShake(r, error); +} + +void PILI_RTMP_Close(PILI_RTMP *r, RTMPError *error) { + if (r->m_is_closing) { + return; + } + r->m_is_closing = 1; + int i; + if (PILI_RTMP_IsConnected(r)) { + if (r->m_stream_id > 0) { + if ((r->Link.protocol & RTMP_FEATURE_WRITE)) + SendFCUnpublish(r, NULL); + i = r->m_stream_id; + r->m_stream_id = 0; + SendDeleteStream(r, i, NULL); + } + if (r->m_clientID.av_val) { + HTTP_Post(r, RTMPT_CLOSE, "", 1); + free(r->m_clientID.av_val); + r->m_clientID.av_val = NULL; + r->m_clientID.av_len = 0; + } + PILI_RTMPSockBuf_Close(&r->m_sb); + + if (error && r->m_errorCallback) { + r->m_errorCallback(error, r->m_userData); + } + } + + r->m_stream_id = -1; + r->m_sb.sb_socket = -1; + r->m_nBWCheckCounter = 0; + r->m_nBytesIn = 0; + r->m_nBytesInSent = 0; + + if (r->m_read.flags & RTMP_READ_HEADER) { + free(r->m_read.buf); + r->m_read.buf = NULL; + } + r->m_read.dataType = 0; + r->m_read.flags = 0; + r->m_read.status = 0; + r->m_read.nResumeTS = 0; + r->m_read.nIgnoredFrameCounter = 0; + r->m_read.nIgnoredFlvFrameCounter = 0; + + r->m_write.m_nBytesRead = 0; + PILI_RTMPPacket_Free(&r->m_write); + + for (i = 0; i < RTMP_CHANNELS; i++) { + if (r->m_vecChannelsIn[i]) { + PILI_RTMPPacket_Free(r->m_vecChannelsIn[i]); + free(r->m_vecChannelsIn[i]); + r->m_vecChannelsIn[i] = NULL; + } + if (r->m_vecChannelsOut[i]) { + free(r->m_vecChannelsOut[i]); + r->m_vecChannelsOut[i] = NULL; + } + } + AV_clear(r->m_methodCalls, r->m_numCalls); + r->m_methodCalls = NULL; + r->m_numCalls = 0; + r->m_numInvokes = 0; + + r->m_bPlaying = FALSE; + r->m_sb.sb_size = 0; + + r->m_msgCounter = 0; + r->m_resplen = 0; + r->m_unackd = 0; + + free(r->Link.playpath0.av_val); + r->Link.playpath0.av_val = NULL; + + if (r->Link.lFlags & RTMP_LF_FTCU) { + free(r->Link.tcUrl.av_val); + r->Link.tcUrl.av_val = NULL; + r->Link.lFlags ^= RTMP_LF_FTCU; + } + +#ifdef CRYPTO + if (r->Link.dh) { + MDH_free(r->Link.dh); + r->Link.dh = NULL; + } + if (r->Link.rc4keyIn) { + RC4_free(r->Link.rc4keyIn); + r->Link.rc4keyIn = NULL; + } + if (r->Link.rc4keyOut) { + RC4_free(r->Link.rc4keyOut); + r->Link.rc4keyOut = NULL; + } +#endif +} + +int PILI_RTMPSockBuf_Fill(PILI_RTMPSockBuf *sb) { + int nBytes; + + if (!sb->sb_size) + sb->sb_start = sb->sb_buf; + + while (1) { + nBytes = sizeof(sb->sb_buf) - sb->sb_size - (sb->sb_start - sb->sb_buf); +#if defined(CRYPTO) && !defined(NO_SSL) + if (sb->sb_ssl) { + nBytes = TLS_read(sb->sb_ssl, sb->sb_start + sb->sb_size, nBytes); + } else +#endif + { + nBytes = recv(sb->sb_socket, sb->sb_start + sb->sb_size, nBytes, 0); + } + if (nBytes != -1) { + sb->sb_size += nBytes; + } else { + int sockerr = GetSockError(); + RTMP_Log(RTMP_LOGDEBUG, "%s, recv returned %d. GetSockError(): %d (%s)", + __FUNCTION__, nBytes, sockerr, strerror(sockerr)); + if (sockerr == EINTR && !PILI_RTMP_ctrlC) + continue; + + if (sockerr == EWOULDBLOCK || sockerr == EAGAIN) { + sb->sb_timedout = TRUE; + nBytes = 0; + } + } + break; + } + + return nBytes; +} + +int PILI_RTMPSockBuf_Send(PILI_RTMPSockBuf *sb, const char *buf, int len) { + int rc; + +#ifdef _DEBUG + fwrite(buf, 1, len, netstackdump); +#endif + +#if defined(CRYPTO) && !defined(NO_SSL) + if (sb->sb_ssl) { + rc = TLS_write(sb->sb_ssl, buf, len); + } else +#endif + { + rc = send(sb->sb_socket, buf, len, 0); + } + return rc; +} + +int PILI_RTMPSockBuf_Close(PILI_RTMPSockBuf *sb) { +#if defined(CRYPTO) && !defined(NO_SSL) + if (sb->sb_ssl) { + TLS_shutdown(sb->sb_ssl); + TLS_close(sb->sb_ssl); + sb->sb_ssl = NULL; + } +#endif + return closesocket(sb->sb_socket); +} + +#define HEX2BIN(a) (((a)&0x40) ? ((a)&0xf) + 9 : ((a)&0xf)) + +static void + DecodeTEA(AVal *key, AVal *text) { + uint32_t *v, k[4] = {0}, u; + uint32_t z, y, sum = 0, e, DELTA = 0x9e3779b9; + int32_t p, q; + int i, n; + unsigned char *ptr, *out; + + /* prep key: pack 1st 16 chars into 4 LittleEndian ints */ + ptr = (unsigned char *)key->av_val; + u = 0; + n = 0; + v = k; + p = key->av_len > 16 ? 16 : key->av_len; + for (i = 0; i < p; i++) { + u |= ptr[i] << (n * 8); + if (n == 3) { + *v++ = u; + u = 0; + n = 0; + } else { + n++; + } + } + /* any trailing chars */ + if (u) + *v = u; + + /* prep text: hex2bin, multiples of 4 */ + n = (text->av_len + 7) / 8; + out = malloc(n * 8); + ptr = (unsigned char *)text->av_val; + v = (uint32_t *)out; + for (i = 0; i < n; i++) { + u = (HEX2BIN(ptr[0]) << 4) + HEX2BIN(ptr[1]); + u |= ((HEX2BIN(ptr[2]) << 4) + HEX2BIN(ptr[3])) << 8; + u |= ((HEX2BIN(ptr[4]) << 4) + HEX2BIN(ptr[5])) << 16; + u |= ((HEX2BIN(ptr[6]) << 4) + HEX2BIN(ptr[7])) << 24; + *v++ = u; + ptr += 8; + } + v = (uint32_t *)out; + +/* http://www.movable-type.co.uk/scripts/tea-block.html */ +#define MX (((z >> 5) ^ (y << 2)) + ((y >> 3) ^ (z << 4))) ^ ((sum ^ y) + (k[(p & 3) ^ e] ^ z)); + z = v[n - 1]; + y = v[0]; + q = 6 + 52 / n; + sum = q * DELTA; + while (sum != 0) { + e = sum >> 2 & 3; + for (p = n - 1; p > 0; p--) + z = v[p - 1], y = v[p] -= MX; + z = v[n - 1]; + y = v[0] -= MX; + sum -= DELTA; + } + + text->av_len /= 2; + memcpy(text->av_val, out, text->av_len); + free(out); +} + +static int + HTTP_Post(PILI_RTMP *r, RTMPTCmd cmd, const char *buf, int len) { + char hbuf[512]; + int hlen = snprintf(hbuf, sizeof(hbuf), "POST /%s%s/%d HTTP/1.1\r\n" + "Host: %.*s:%d\r\n" + "Accept: */*\r\n" + "User-Agent: Shockwave Flash\n" + "Connection: Keep-Alive\n" + "Cache-Control: no-cache\r\n" + "Content-type: application/x-fcs\r\n" + "Content-length: %d\r\n\r\n", + RTMPT_cmds[cmd], + r->m_clientID.av_val ? r->m_clientID.av_val : "", + r->m_msgCounter, r->Link.hostname.av_len, r->Link.hostname.av_val, + r->Link.port, len); + PILI_RTMPSockBuf_Send(&r->m_sb, hbuf, hlen); + hlen = PILI_RTMPSockBuf_Send(&r->m_sb, buf, len); + r->m_msgCounter++; + r->m_unackd++; + return hlen; +} + +static int + HTTP_read(PILI_RTMP *r, int fill) { + char *ptr; + int hlen; + + if (fill) + PILI_RTMPSockBuf_Fill(&r->m_sb); + if (r->m_sb.sb_size < 144) + return -1; + if (strncmp(r->m_sb.sb_start, "HTTP/1.1 200 ", 13)) + return -1; + ptr = strstr(r->m_sb.sb_start, "Content-Length:"); + if (!ptr) + return -1; + hlen = atoi(ptr + 16); + ptr = strstr(ptr, "\r\n\r\n"); + if (!ptr) + return -1; + ptr += 4; + r->m_sb.sb_size -= ptr - r->m_sb.sb_start; + r->m_sb.sb_start = ptr; + r->m_unackd--; + + if (!r->m_clientID.av_val) { + r->m_clientID.av_len = hlen; + r->m_clientID.av_val = malloc(hlen + 1); + if (!r->m_clientID.av_val) + return -1; + r->m_clientID.av_val[0] = '/'; + memcpy(r->m_clientID.av_val + 1, ptr, hlen - 1); + r->m_clientID.av_val[hlen] = 0; + r->m_sb.sb_size = 0; + } else { + r->m_polling = *ptr++; + r->m_resplen = hlen - 1; + r->m_sb.sb_start++; + r->m_sb.sb_size--; + } + return 0; +} + +#define MAX_IGNORED_FRAMES 50 + +/* Read from the stream until we get a media packet. + * Returns -3 if Play.Close/Stop, -2 if fatal error, -1 if no more media + * packets, 0 if ignorable error, >0 if there is a media packet + */ +static int + Read_1_Packet(PILI_RTMP *r, char *buf, unsigned int buflen) { + uint32_t prevTagSize = 0; + int rtnGetNextMediaPacket = 0, ret = RTMP_READ_EOF; + PILI_RTMPPacket packet = {0}; + int recopy = FALSE; + unsigned int size; + char *ptr, *pend; + uint32_t nTimeStamp = 0; + unsigned int len; + + rtnGetNextMediaPacket = PILI_RTMP_GetNextMediaPacket(r, &packet); + while (rtnGetNextMediaPacket) { + char *packetBody = packet.m_body; + unsigned int nPacketLen = packet.m_nBodySize; + + /* Return -3 if this was completed nicely with invoke message + * Play.Stop or Play.Complete + */ + if (rtnGetNextMediaPacket == 2) { + RTMP_Log(RTMP_LOGDEBUG, + "Got Play.Complete or Play.Stop from server. " + "Assuming stream is complete"); + ret = RTMP_READ_COMPLETE; + break; + } + + r->m_read.dataType |= (((packet.m_packetType == 0x08) << 2) | + (packet.m_packetType == 0x09)); + + if (packet.m_packetType == 0x09 && nPacketLen <= 5) { + RTMP_Log(RTMP_LOGDEBUG, "ignoring too small video packet: size: %d", + nPacketLen); + ret = RTMP_READ_IGNORE; + break; + } + if (packet.m_packetType == 0x08 && nPacketLen <= 1) { + RTMP_Log(RTMP_LOGDEBUG, "ignoring too small audio packet: size: %d", + nPacketLen); + ret = RTMP_READ_IGNORE; + break; + } + + if (r->m_read.flags & RTMP_READ_SEEKING) { + ret = RTMP_READ_IGNORE; + break; + } +#ifdef _DEBUG + RTMP_Log(RTMP_LOGDEBUG, "type: %02X, size: %d, TS: %d ms, abs TS: %d", + packet.m_packetType, nPacketLen, packet.m_nTimeStamp, + packet.m_hasAbsTimestamp); + if (packet.m_packetType == 0x09) + RTMP_Log(RTMP_LOGDEBUG, "frametype: %02X", (*packetBody & 0xf0)); +#endif + + if (r->m_read.flags & RTMP_READ_RESUME) { + /* check the header if we get one */ + if (packet.m_nTimeStamp == 0) { + if (r->m_read.nMetaHeaderSize > 0 && packet.m_packetType == 0x12) { + AMFObject metaObj; + int nRes = + AMF_Decode(&metaObj, packetBody, nPacketLen, FALSE); + if (nRes >= 0) { + AVal metastring; + AMFProp_GetString(AMF_GetProp(&metaObj, NULL, 0), + &metastring); + + if (AVMATCH(&metastring, &av_onMetaData)) { + /* compare */ + if ((r->m_read.nMetaHeaderSize != nPacketLen) || + (memcmp(r->m_read.metaHeader, packetBody, + r->m_read.nMetaHeaderSize) != 0)) { + ret = RTMP_READ_ERROR; + } + } + AMF_Reset(&metaObj); + if (ret == RTMP_READ_ERROR) + break; + } + } + + /* check first keyframe to make sure we got the right position + * in the stream! (the first non ignored frame) + */ + if (r->m_read.nInitialFrameSize > 0) { + /* video or audio data */ + if (packet.m_packetType == r->m_read.initialFrameType && r->m_read.nInitialFrameSize == nPacketLen) { + /* we don't compare the sizes since the packet can + * contain several FLV packets, just make sure the + * first frame is our keyframe (which we are going + * to rewrite) + */ + if (memcmp(r->m_read.initialFrame, packetBody, + r->m_read.nInitialFrameSize) == 0) { + RTMP_Log(RTMP_LOGDEBUG, "Checked keyframe successfully!"); + r->m_read.flags |= RTMP_READ_GOTKF; + /* ignore it! (what about audio data after it? it is + * handled by ignoring all 0ms frames, see below) + */ + ret = RTMP_READ_IGNORE; + break; + } + } + + /* hande FLV streams, even though the server resends the + * keyframe as an extra video packet it is also included + * in the first FLV stream chunk and we have to compare + * it and filter it out !! + */ + if (packet.m_packetType == 0x16) { + /* basically we have to find the keyframe with the + * correct TS being nResumeTS + */ + unsigned int pos = 0; + uint32_t ts = 0; + + while (pos + 11 < nPacketLen) { + /* size without header (11) and prevTagSize (4) */ + uint32_t dataSize = + AMF_DecodeInt24(packetBody + pos + 1); + ts = AMF_DecodeInt24(packetBody + pos + 4); + ts |= (packetBody[pos + 7] << 24); + +#ifdef _DEBUG + RTMP_Log(RTMP_LOGDEBUG, + "keyframe search: FLV Packet: type %02X, dataSize: %d, timeStamp: %d ms", + packetBody[pos], dataSize, ts); +#endif + /* ok, is it a keyframe?: + * well doesn't work for audio! + */ + if (packetBody[pos /*6928, test 0 */] == + r->m_read.initialFrameType + /* && (packetBody[11]&0xf0) == 0x10 */) { + if (ts == r->m_read.nResumeTS) { + RTMP_Log(RTMP_LOGDEBUG, + "Found keyframe with resume-keyframe timestamp!"); + if (r->m_read.nInitialFrameSize != dataSize || memcmp(r->m_read.initialFrame, packetBody + pos + 11, r->m_read.nInitialFrameSize) != 0) { + RTMP_Log(RTMP_LOGERROR, + "FLV Stream: Keyframe doesn't match!"); + ret = RTMP_READ_ERROR; + break; + } + r->m_read.flags |= RTMP_READ_GOTFLVK; + + /* skip this packet? + * check whether skippable: + */ + if (pos + 11 + dataSize + 4 > nPacketLen) { + RTMP_Log(RTMP_LOGWARNING, + "Non skipable packet since it doesn't end with chunk, stream corrupt!"); + ret = RTMP_READ_ERROR; + break; + } + packetBody += (pos + 11 + dataSize + 4); + nPacketLen -= (pos + 11 + dataSize + 4); + + goto stopKeyframeSearch; + + } else if (r->m_read.nResumeTS < ts) { + /* the timestamp ts will only increase with + * further packets, wait for seek + */ + goto stopKeyframeSearch; + } + } + pos += (11 + dataSize + 4); + } + if (ts < r->m_read.nResumeTS) { + RTMP_Log(RTMP_LOGERROR, + "First packet does not contain keyframe, all " + "timestamps are smaller than the keyframe " + "timestamp; probably the resume seek failed?"); + } + stopKeyframeSearch:; + if (!(r->m_read.flags & RTMP_READ_GOTFLVK)) { + RTMP_Log(RTMP_LOGERROR, + "Couldn't find the seeked keyframe in this chunk!"); + ret = RTMP_READ_IGNORE; + break; + } + } + } + } + + if (packet.m_nTimeStamp > 0 && (r->m_read.flags & (RTMP_READ_GOTKF | RTMP_READ_GOTFLVK))) { + /* another problem is that the server can actually change from + * 09/08 video/audio packets to an FLV stream or vice versa and + * our keyframe check will prevent us from going along with the + * new stream if we resumed. + * + * in this case set the 'found keyframe' variables to true. + * We assume that if we found one keyframe somewhere and were + * already beyond TS > 0 we have written data to the output + * which means we can accept all forthcoming data including the + * change between 08/09 <-> FLV packets + */ + r->m_read.flags |= (RTMP_READ_GOTKF | RTMP_READ_GOTFLVK); + } + + /* skip till we find our keyframe + * (seeking might put us somewhere before it) + */ + if (!(r->m_read.flags & RTMP_READ_GOTKF) && + packet.m_packetType != 0x16) { + RTMP_Log(RTMP_LOGWARNING, + "Stream does not start with requested frame, ignoring data... "); + r->m_read.nIgnoredFrameCounter++; + if (r->m_read.nIgnoredFrameCounter > MAX_IGNORED_FRAMES) + ret = RTMP_READ_ERROR; /* fatal error, couldn't continue stream */ + else + ret = RTMP_READ_IGNORE; + break; + } + /* ok, do the same for FLV streams */ + if (!(r->m_read.flags & RTMP_READ_GOTFLVK) && + packet.m_packetType == 0x16) { + RTMP_Log(RTMP_LOGWARNING, + "Stream does not start with requested FLV frame, ignoring data... "); + r->m_read.nIgnoredFlvFrameCounter++; + if (r->m_read.nIgnoredFlvFrameCounter > MAX_IGNORED_FRAMES) + ret = RTMP_READ_ERROR; + else + ret = RTMP_READ_IGNORE; + break; + } + + /* we have to ignore the 0ms frames since these are the first + * keyframes; we've got these so don't mess around with multiple + * copies sent by the server to us! (if the keyframe is found at a + * later position there is only one copy and it will be ignored by + * the preceding if clause) + */ + if (!(r->m_read.flags & RTMP_READ_NO_IGNORE) && + packet.m_packetType != 0x16) { /* exclude type 0x16 (FLV) since it can + * contain several FLV packets */ + if (packet.m_nTimeStamp == 0) { + ret = RTMP_READ_IGNORE; + break; + } else { + /* stop ignoring packets */ + r->m_read.flags |= RTMP_READ_NO_IGNORE; + } + } + } + + /* calculate packet size and allocate slop buffer if necessary */ + size = nPacketLen + + ((packet.m_packetType == 0x08 || packet.m_packetType == 0x09 || packet.m_packetType == 0x12) ? 11 : 0) + + (packet.m_packetType != 0x16 ? 4 : 0); + + if (size + 4 > buflen) { + /* the extra 4 is for the case of an FLV stream without a last + * prevTagSize (we need extra 4 bytes to append it) */ + r->m_read.buf = malloc(size + 4); + if (r->m_read.buf == 0) { + RTMP_Log(RTMP_LOGERROR, "Couldn't allocate memory!"); + ret = RTMP_READ_ERROR; /* fatal error */ + break; + } + recopy = TRUE; + ptr = r->m_read.buf; + } else { + ptr = buf; + } + pend = ptr + size + 4; + + /* use to return timestamp of last processed packet */ + + /* audio (0x08), video (0x09) or metadata (0x12) packets : + * construct 11 byte header then add PILI_RTMP packet's data */ + if (packet.m_packetType == 0x08 || packet.m_packetType == 0x09 || packet.m_packetType == 0x12) { + nTimeStamp = r->m_read.nResumeTS + packet.m_nTimeStamp; + prevTagSize = 11 + nPacketLen; + + *ptr = packet.m_packetType; + ptr++; + ptr = AMF_EncodeInt24(ptr, pend, nPacketLen); + +#if 0 + if(packet.m_packetType == 0x09) { /* video */ + + /* H264 fix: */ + if((packetBody[0] & 0x0f) == 7) { /* CodecId = H264 */ + uint8_t packetType = *(packetBody+1); + + uint32_t ts = AMF_DecodeInt24(packetBody+2); /* composition time */ + int32_t cts = (ts+0xff800000)^0xff800000; + RTMP_Log(RTMP_LOGDEBUG, "cts : %d\n", cts); + + nTimeStamp -= cts; + /* get rid of the composition time */ + CRTMP::EncodeInt24(packetBody+2, 0); + } + RTMP_Log(RTMP_LOGDEBUG, "VIDEO: nTimeStamp: 0x%08X (%d)\n", nTimeStamp, nTimeStamp); + } +#endif + + ptr = AMF_EncodeInt24(ptr, pend, nTimeStamp); + *ptr = (char)((nTimeStamp & 0xFF000000) >> 24); + ptr++; + + /* stream id */ + ptr = AMF_EncodeInt24(ptr, pend, 0); + } + + memcpy(ptr, packetBody, nPacketLen); + len = nPacketLen; + + /* correct tagSize and obtain timestamp if we have an FLV stream */ + if (packet.m_packetType == 0x16) { + unsigned int pos = 0; + int delta; + + /* grab first timestamp and see if it needs fixing */ + nTimeStamp = AMF_DecodeInt24(packetBody + 4); + nTimeStamp |= (packetBody[7] << 24); + delta = packet.m_nTimeStamp - nTimeStamp; + + while (pos + 11 < nPacketLen) { + /* size without header (11) and without prevTagSize (4) */ + uint32_t dataSize = AMF_DecodeInt24(packetBody + pos + 1); + nTimeStamp = AMF_DecodeInt24(packetBody + pos + 4); + nTimeStamp |= (packetBody[pos + 7] << 24); + + if (delta) { + nTimeStamp += delta; + AMF_EncodeInt24(ptr + pos + 4, pend, nTimeStamp); + ptr[pos + 7] = nTimeStamp >> 24; + } + + /* set data type */ + r->m_read.dataType |= (((*(packetBody + pos) == 0x08) << 2) | + (*(packetBody + pos) == 0x09)); + + if (pos + 11 + dataSize + 4 > nPacketLen) { + if (pos + 11 + dataSize > nPacketLen) { + RTMP_Log(RTMP_LOGERROR, + "Wrong data size (%lu), stream corrupted, aborting!", + dataSize); + ret = RTMP_READ_ERROR; + break; + } + RTMP_Log(RTMP_LOGWARNING, "No tagSize found, appending!"); + + /* we have to append a last tagSize! */ + prevTagSize = dataSize + 11; + AMF_EncodeInt32(ptr + pos + 11 + dataSize, pend, + prevTagSize); + size += 4; + len += 4; + } else { + prevTagSize = + AMF_DecodeInt32(packetBody + pos + 11 + dataSize); + +#ifdef _DEBUG + RTMP_Log(RTMP_LOGDEBUG, + "FLV Packet: type %02X, dataSize: %lu, tagSize: %lu, timeStamp: %lu ms", + (unsigned char)packetBody[pos], dataSize, prevTagSize, + nTimeStamp); +#endif + + if (prevTagSize != (dataSize + 11)) { +#ifdef _DEBUG + RTMP_Log(RTMP_LOGWARNING, + "Tag and data size are not consitent, writing tag size according to dataSize+11: %d", + dataSize + 11); +#endif + + prevTagSize = dataSize + 11; + AMF_EncodeInt32(ptr + pos + 11 + dataSize, pend, + prevTagSize); + } + } + + pos += prevTagSize + 4; /*(11+dataSize+4); */ + } + } + ptr += len; + + if (packet.m_packetType != 0x16) { + /* FLV tag packets contain their own prevTagSize */ + AMF_EncodeInt32(ptr, pend, prevTagSize); + } + + /* In non-live this nTimeStamp can contain an absolute TS. + * Update ext timestamp with this absolute offset in non-live mode + * otherwise report the relative one + */ + /* RTMP_Log(RTMP_LOGDEBUG, "type: %02X, size: %d, pktTS: %dms, TS: %dms, bLiveStream: %d", packet.m_packetType, nPacketLen, packet.m_nTimeStamp, nTimeStamp, r->Link.lFlags & RTMP_LF_LIVE); */ + r->m_read.timestamp = (r->Link.lFlags & RTMP_LF_LIVE) ? packet.m_nTimeStamp : nTimeStamp; + + ret = size; + break; + } + + if (rtnGetNextMediaPacket) + PILI_RTMPPacket_Free(&packet); + + if (recopy) { + len = ret > buflen ? buflen : ret; + memcpy(buf, r->m_read.buf, len); + r->m_read.bufpos = r->m_read.buf + len; + r->m_read.buflen = ret - len; + } + return ret; +} + +static const char flvHeader[] = {'F', 'L', 'V', 0x01, + 0x00, /* 0x04 == audio, 0x01 == video */ + 0x00, 0x00, 0x00, 0x09, + 0x00, 0x00, 0x00, 0x00}; + +#define HEADERBUF (128 * 1024) +int PILI_RTMP_Read(PILI_RTMP *r, char *buf, int size) { + int nRead = 0, total = 0; + +/* can't continue */ +fail: + switch (r->m_read.status) { + case RTMP_READ_EOF: + case RTMP_READ_COMPLETE: + return 0; + case RTMP_READ_ERROR: /* corrupted stream, resume failed */ + SetSockError(EINVAL); + return -1; + default: + break; + } + + if ((r->m_read.flags & RTMP_READ_SEEKING) && r->m_read.buf) { + /* drop whatever's here */ + free(r->m_read.buf); + r->m_read.buf = NULL; + r->m_read.bufpos = NULL; + r->m_read.buflen = 0; + } + + /* If there's leftover data buffered, use it up */ + if (r->m_read.buf) { + nRead = r->m_read.buflen; + if (nRead > size) + nRead = size; + memcpy(buf, r->m_read.bufpos, nRead); + r->m_read.buflen -= nRead; + if (!r->m_read.buflen) { + free(r->m_read.buf); + r->m_read.buf = NULL; + r->m_read.bufpos = NULL; + } else { + r->m_read.bufpos += nRead; + } + buf += nRead; + total += nRead; + size -= nRead; + } + + while (size > 0 && (nRead = Read_1_Packet(r, buf, size)) >= 0) { + if (!nRead) continue; + buf += nRead; + total += nRead; + size -= nRead; + break; + } + if (nRead < 0) + r->m_read.status = nRead; + + if (size < 0) + total += size; + return total; +} + +static const AVal av_setDataFrame = AVC("@setDataFrame"); + +int PILI_RTMP_Write(PILI_RTMP *r, const char *buf, int size, RTMPError *error) { + PILI_RTMPPacket *pkt = &r->m_write; + char *pend, *enc; + int s2 = size, ret, num; + + pkt->m_nChannel = 0x04; /* source channel */ + pkt->m_nInfoField2 = r->m_stream_id; + + while (s2) { + if (!pkt->m_nBytesRead) { + if (size < 11) { + /* FLV pkt too small */ + return 0; + } + + if (buf[0] == 'F' && buf[1] == 'L' && buf[2] == 'V') { + buf += 13; + s2 -= 13; + } + + pkt->m_packetType = *buf++; + pkt->m_nBodySize = AMF_DecodeInt24(buf); + buf += 3; + pkt->m_nTimeStamp = AMF_DecodeInt24(buf); + buf += 3; + pkt->m_nTimeStamp |= *buf++ << 24; + buf += 3; + s2 -= 11; + + if (((pkt->m_packetType == 0x08 || pkt->m_packetType == 0x09) && + !pkt->m_nTimeStamp) || + pkt->m_packetType == 0x12) { + pkt->m_headerType = RTMP_PACKET_SIZE_LARGE; + if (pkt->m_packetType == 0x12) + pkt->m_nBodySize += 16; + } else { + pkt->m_headerType = RTMP_PACKET_SIZE_MEDIUM; + } + + if (!PILI_RTMPPacket_Alloc(pkt, pkt->m_nBodySize)) { + RTMP_Log(RTMP_LOGDEBUG, "%s, failed to allocate packet", __FUNCTION__); + return FALSE; + } + enc = pkt->m_body; + pend = enc + pkt->m_nBodySize; + if (pkt->m_packetType == 0x12) { + enc = AMF_EncodeString(enc, pend, &av_setDataFrame); + pkt->m_nBytesRead = enc - pkt->m_body; + } + } else { + enc = pkt->m_body + pkt->m_nBytesRead; + } + num = pkt->m_nBodySize - pkt->m_nBytesRead; + if (num > s2) + num = s2; + memcpy(enc, buf, num); + pkt->m_nBytesRead += num; + s2 -= num; + buf += num; + if (pkt->m_nBytesRead == pkt->m_nBodySize) { + ret = PILI_RTMP_SendPacket(r, pkt, FALSE, error); + PILI_RTMPPacket_Free(pkt); + pkt->m_nBytesRead = 0; + if (!ret) + return -1; + buf += 4; + s2 -= 4; + if (s2 < 0) + break; + } + } + return size + s2; +} diff --git a/LFLiveKit/Vendor/pili-librtmp/rtmp.h b/LFLiveKit/Vendor/pili-librtmp/rtmp.h new file mode 100644 index 00000000..d415e16c --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/rtmp.h @@ -0,0 +1,356 @@ +#ifndef __RTMP_H__ +#define __RTMP_H__ +/* + * Copyright (C) 2005-2008 Team XBMC + * http://www.xbmc.org + * Copyright (C) 2008-2009 Andrej Stepanchuk + * Copyright (C) 2009-2010 Howard Chu + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +#define NO_CRYPTO + +#if !defined(NO_CRYPTO) && !defined(CRYPTO) +#define CRYPTO +#endif + +#include +#include +#include + +#include "amf.h" +#include "error.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define RTMP_LIB_VERSION 0x020300 /* 2.3 */ + +#define RTMP_FEATURE_HTTP 0x01 +#define RTMP_FEATURE_ENC 0x02 +#define RTMP_FEATURE_SSL 0x04 +#define RTMP_FEATURE_MFP 0x08 /* not yet supported */ +#define RTMP_FEATURE_WRITE 0x10 /* publish, not play */ +#define RTMP_FEATURE_HTTP2 0x20 /* server-side rtmpt */ + +#define RTMP_PROTOCOL_UNDEFINED -1 +#define RTMP_PROTOCOL_RTMP 0 +#define RTMP_PROTOCOL_RTMPE RTMP_FEATURE_ENC +#define RTMP_PROTOCOL_RTMPT RTMP_FEATURE_HTTP +#define RTMP_PROTOCOL_RTMPS RTMP_FEATURE_SSL +#define RTMP_PROTOCOL_RTMPTE (RTMP_FEATURE_HTTP | RTMP_FEATURE_ENC) +#define RTMP_PROTOCOL_RTMPTS (RTMP_FEATURE_HTTP | RTMP_FEATURE_SSL) +#define RTMP_PROTOCOL_RTMFP RTMP_FEATURE_MFP + +#define RTMP_DEFAULT_CHUNKSIZE 128 + +/* needs to fit largest number of bytes recv() may return */ +#define RTMP_BUFFER_CACHE_SIZE (16 * 1024) + +#define RTMP_CHANNELS 65600 + +extern const char PILI_RTMPProtocolStringsLower[][7]; +extern const AVal PILI_RTMP_DefaultFlashVer; +extern int PILI_RTMP_ctrlC; + +uint32_t PILI_RTMP_GetTime(void); + +#define RTMP_PACKET_TYPE_AUDIO 0x08 +#define RTMP_PACKET_TYPE_VIDEO 0x09 +#define RTMP_PACKET_TYPE_INFO 0x12 + +#define RTMP_MAX_HEADER_SIZE 18 + +#define RTMP_PACKET_SIZE_LARGE 0 +#define RTMP_PACKET_SIZE_MEDIUM 1 +#define RTMP_PACKET_SIZE_SMALL 2 +#define RTMP_PACKET_SIZE_MINIMUM 3 + +typedef struct PILI_RTMPChunk { + int c_headerSize; + int c_chunkSize; + char *c_chunk; + char c_header[RTMP_MAX_HEADER_SIZE]; +} PILI_RTMPChunk; + +typedef struct PILI_RTMPPacket { + uint8_t m_headerType; + uint8_t m_packetType; + uint8_t m_hasAbsTimestamp; /* timestamp absolute or relative? */ + int m_nChannel; + uint32_t m_nTimeStamp; /* timestamp */ + int32_t m_nInfoField2; /* last 4 bytes in a long header */ + uint32_t m_nBodySize; + uint32_t m_nBytesRead; + PILI_RTMPChunk *m_chunk; + char *m_body; +} PILI_RTMPPacket; + +typedef struct PILI_RTMPSockBuf { + int sb_socket; + int sb_size; /* number of unprocessed bytes in buffer */ + char *sb_start; /* pointer into sb_pBuffer of next byte to process */ + char sb_buf[RTMP_BUFFER_CACHE_SIZE]; /* data read from socket */ + int sb_timedout; + void *sb_ssl; +} PILI_RTMPSockBuf; + +void PILI_RTMPPacket_Reset(PILI_RTMPPacket *p); +void PILI_RTMPPacket_Dump(PILI_RTMPPacket *p); +int PILI_RTMPPacket_Alloc(PILI_RTMPPacket *p, int nSize); +void PILI_RTMPPacket_Free(PILI_RTMPPacket *p); + +#define RTMPPacket_IsReady(a) ((a)->m_nBytesRead == (a)->m_nBodySize) + +typedef struct PILI_RTMP_LNK { + AVal hostname; + AVal domain; + AVal sockshost; + + AVal playpath0; /* parsed from URL */ + AVal playpath; /* passed in explicitly */ + AVal tcUrl; + AVal swfUrl; + AVal pageUrl; + AVal app; + AVal auth; + AVal flashVer; + AVal subscribepath; + AVal token; + AMFObject extras; + int edepth; + + int seekTime; + int stopTime; + +#define RTMP_LF_AUTH 0x0001 /* using auth param */ +#define RTMP_LF_LIVE 0x0002 /* stream is live */ +#define RTMP_LF_SWFV 0x0004 /* do SWF verification */ +#define RTMP_LF_PLST 0x0008 /* send playlist before play */ +#define RTMP_LF_BUFX 0x0010 /* toggle stream on BufferEmpty msg */ +#define RTMP_LF_FTCU 0x0020 /* free tcUrl on close */ + int lFlags; + + int swfAge; + + int protocol; + int timeout; /* connection timeout in seconds */ + int send_timeout; /* send data timeout */ + + unsigned short socksport; + unsigned short port; + +#ifdef CRYPTO +#define RTMP_SWF_HASHLEN 32 + void *dh; /* for encryption */ + void *rc4keyIn; + void *rc4keyOut; + + uint32_t SWFSize; + uint8_t SWFHash[RTMP_SWF_HASHLEN]; + char SWFVerificationResponse[RTMP_SWF_HASHLEN + 10]; +#endif +} PILI_RTMP_LNK; + +/* state for read() wrapper */ +typedef struct PILI_RTMP_READ { + char *buf; + char *bufpos; + unsigned int buflen; + uint32_t timestamp; + uint8_t dataType; + uint8_t flags; +#define RTMP_READ_HEADER 0x01 +#define RTMP_READ_RESUME 0x02 +#define RTMP_READ_NO_IGNORE 0x04 +#define RTMP_READ_GOTKF 0x08 +#define RTMP_READ_GOTFLVK 0x10 +#define RTMP_READ_SEEKING 0x20 + int8_t status; +#define RTMP_READ_COMPLETE -3 +#define RTMP_READ_ERROR -2 +#define RTMP_READ_EOF -1 +#define RTMP_READ_IGNORE 0 + + /* if bResume == TRUE */ + uint8_t initialFrameType; + uint32_t nResumeTS; + char *metaHeader; + char *initialFrame; + uint32_t nMetaHeaderSize; + uint32_t nInitialFrameSize; + uint32_t nIgnoredFrameCounter; + uint32_t nIgnoredFlvFrameCounter; +} PILI_RTMP_READ; + +typedef struct PILI_RTMP_METHOD { + AVal name; + int num; +} PILI_RTMP_METHOD; + +typedef void (*PILI_RTMPErrorCallback)(RTMPError *error, void *userData); + +typedef struct PILI_CONNECTION_TIME { + uint32_t connect_time; + uint32_t handshake_time; +} PILI_CONNECTION_TIME; + +typedef void (*PILI_RTMP_ConnectionTimeCallback)( + PILI_CONNECTION_TIME *conn_time, void *userData); + +typedef struct PILI_RTMP { + int m_inChunkSize; + int m_outChunkSize; + int m_nBWCheckCounter; + int m_nBytesIn; + int m_nBytesInSent; + int m_nBufferMS; + int m_stream_id; /* returned in _result from createStream */ + int m_mediaChannel; + uint32_t m_mediaStamp; + uint32_t m_pauseStamp; + int m_pausing; + int m_nServerBW; + int m_nClientBW; + uint8_t m_nClientBW2; + uint8_t m_bPlaying; + uint8_t m_bSendEncoding; + uint8_t m_bSendCounter; + + int m_numInvokes; + int m_numCalls; + PILI_RTMP_METHOD *m_methodCalls; /* remote method calls queue */ + + PILI_RTMPPacket *m_vecChannelsIn[RTMP_CHANNELS]; + PILI_RTMPPacket *m_vecChannelsOut[RTMP_CHANNELS]; + int m_channelTimestamp[RTMP_CHANNELS]; /* abs timestamp of last packet */ + + double m_fAudioCodecs; /* audioCodecs for the connect packet */ + double m_fVideoCodecs; /* videoCodecs for the connect packet */ + double m_fEncoding; /* AMF0 or AMF3 */ + + double m_fDuration; /* duration of stream in seconds */ + + int m_msgCounter; /* RTMPT stuff */ + int m_polling; + int m_resplen; + int m_unackd; + AVal m_clientID; + + PILI_RTMP_READ m_read; + PILI_RTMPPacket m_write; + PILI_RTMPSockBuf m_sb; + PILI_RTMP_LNK Link; + + PILI_RTMPErrorCallback m_errorCallback; + PILI_RTMP_ConnectionTimeCallback m_connCallback; + RTMPError *m_error; + void *m_userData; + int m_is_closing; + int m_tcp_nodelay; + uint32_t ip; +} PILI_RTMP; + +int PILI_RTMP_ParseURL(const char *url, int *protocol, AVal *host, + unsigned int *port, AVal *playpath, AVal *app); + +int PILI_RTMP_ParseURL2(const char *url, int *protocol, AVal *host, + unsigned int *port, AVal *playpath, AVal *app, AVal *domain); + +void PILI_RTMP_ParsePlaypath(AVal *in, AVal *out); +void PILI_RTMP_SetBufferMS(PILI_RTMP *r, int size); +void PILI_RTMP_UpdateBufferMS(PILI_RTMP *r, RTMPError *error); + +int PILI_RTMP_SetOpt(PILI_RTMP *r, const AVal *opt, AVal *arg, + RTMPError *error); +int PILI_RTMP_SetupURL(PILI_RTMP *r, const char *url, RTMPError *error); +void PILI_RTMP_SetupStream(PILI_RTMP *r, int protocol, AVal *hostname, + unsigned int port, AVal *sockshost, AVal *playpath, + AVal *tcUrl, AVal *swfUrl, AVal *pageUrl, AVal *app, + AVal *auth, AVal *swfSHA256Hash, uint32_t swfSize, + AVal *flashVer, AVal *subscribepath, int dStart, + int dStop, int bLiveStream, long int timeout); + +int PILI_RTMP_Connect(PILI_RTMP *r, PILI_RTMPPacket *cp, RTMPError *error); +struct sockaddr; +int PILI_RTMP_Connect0(PILI_RTMP *r, struct addrinfo *ai, unsigned short port, + RTMPError *error); +int PILI_RTMP_Connect1(PILI_RTMP *r, PILI_RTMPPacket *cp, RTMPError *error); +int PILI_RTMP_Serve(PILI_RTMP *r, RTMPError *error); + +int PILI_RTMP_ReadPacket(PILI_RTMP *r, PILI_RTMPPacket *packet); +int PILI_RTMP_SendPacket(PILI_RTMP *r, PILI_RTMPPacket *packet, int queue, + RTMPError *error); +int PILI_RTMP_SendChunk(PILI_RTMP *r, PILI_RTMPChunk *chunk, RTMPError *error); +int PILI_RTMP_IsConnected(PILI_RTMP *r); +int PILI_RTMP_Socket(PILI_RTMP *r); +int PILI_RTMP_IsTimedout(PILI_RTMP *r); +double PILI_RTMP_GetDuration(PILI_RTMP *r); +int PILI_RTMP_ToggleStream(PILI_RTMP *r, RTMPError *error); + +int PILI_RTMP_ConnectStream(PILI_RTMP *r, int seekTime, RTMPError *error); +int PILI_RTMP_ReconnectStream(PILI_RTMP *r, int seekTime, RTMPError *error); +void PILI_RTMP_DeleteStream(PILI_RTMP *r, RTMPError *error); +int PILI_RTMP_GetNextMediaPacket(PILI_RTMP *r, PILI_RTMPPacket *packet); +int PILI_RTMP_ClientPacket(PILI_RTMP *r, PILI_RTMPPacket *packet); + +void PILI_RTMP_Init(PILI_RTMP *r); +void PILI_RTMP_Close(PILI_RTMP *r, RTMPError *error); +PILI_RTMP *PILI_RTMP_Alloc(void); +void PILI_RTMP_Free(PILI_RTMP *r); +void PILI_RTMP_EnableWrite(PILI_RTMP *r); + +int PILI_RTMP_LibVersion(void); +void PILI_RTMP_UserInterrupt(void); /* user typed Ctrl-C */ + +int PILI_RTMP_SendCtrl(PILI_RTMP *r, short nType, unsigned int nObject, + unsigned int nTime, RTMPError *error); + +/* caller probably doesn't know current timestamp, should + * just use RTMP_Pause instead + */ +int PILI_RTMP_SendPause(PILI_RTMP *r, int DoPause, int dTime, RTMPError *error); +int PILI_RTMP_Pause(PILI_RTMP *r, int DoPause, RTMPError *error); + +int PILI_RTMP_FindFirstMatchingProperty(AMFObject *obj, const AVal *name, + AMFObjectProperty *p); + +int PILI_RTMPSockBuf_Fill(PILI_RTMPSockBuf *sb); +int PILI_RTMPSockBuf_Send(PILI_RTMPSockBuf *sb, const char *buf, int len); +int PILI_RTMPSockBuf_Close(PILI_RTMPSockBuf *sb); + +int PILI_RTMP_SendCreateStream(PILI_RTMP *r, RTMPError *error); +int PILI_RTMP_SendSeek(PILI_RTMP *r, int dTime, RTMPError *error); +int PILI_RTMP_SendServerBW(PILI_RTMP *r, RTMPError *error); +int PILI_RTMP_SendClientBW(PILI_RTMP *r, RTMPError *error); +void PILI_RTMP_DropRequest(PILI_RTMP *r, int i, int freeit); +int PILI_RTMP_Read(PILI_RTMP *r, char *buf, int size); +int PILI_RTMP_Write(PILI_RTMP *r, const char *buf, int size, RTMPError *error); + +/* hashswf.c */ +int PILI_RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash, + int age); + +#ifdef __cplusplus +}; +#endif + +#endif diff --git a/LFLiveKit/Vendor/pili-librtmp/rtmp_sys.h b/LFLiveKit/Vendor/pili-librtmp/rtmp_sys.h new file mode 100644 index 00000000..880457c3 --- /dev/null +++ b/LFLiveKit/Vendor/pili-librtmp/rtmp_sys.h @@ -0,0 +1,123 @@ +#ifndef __RTMP_SYS_H__ +#define __RTMP_SYS_H__ +/* + * Copyright (C) 2010 Howard Chu + * + * This file is part of librtmp. + * + * librtmp is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1, + * or (at your option) any later version. + * + * librtmp is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with librtmp see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/lgpl.html + */ + +#ifdef _WIN32 + +#ifdef _XBOX +#include +#include +#define snprintf _snprintf +#define strcasecmp stricmp +#define strncasecmp strnicmp +#define vsnprintf _vsnprintf + +#else /* !_XBOX */ +#include +#include +#endif + +#define GetSockError() WSAGetLastError() +#define SetSockError(e) WSASetLastError(e) +#define setsockopt(a, b, c, d, e) (setsockopt)(a, b, c, (const char *)d, (int)e) +#define EWOULDBLOCK \ + WSAETIMEDOUT /* we don't use nonblocking, but we do use timeouts */ +#define sleep(n) Sleep(n * 1000) +#define msleep(n) Sleep(n) +#define SET_RCVTIMEO(tv, s) int tv = s * 1000 +#else /* !_WIN32 */ +#include +#include +#include +#include +#include +#include +#include +#include +#define GetSockError() errno +#define SetSockError(e) errno = e +#undef closesocket +#define closesocket(s) close(s) +#define msleep(n) usleep(n * 1000) +#define SET_RCVTIMEO(tv, s) struct timeval tv = {s, 0} +#endif + +#include "rtmp.h" + +#ifdef USE_POLARSSL +#include +#include +#include +typedef struct tls_ctx { + havege_state hs; + ssl_session ssn; +} tls_ctx; +#define TLS_CTX tls_ctx * +#define TLS_client(ctx, s) \ + s = malloc(sizeof(ssl_context)); \ + ssl_init(s); \ + ssl_set_endpoint(s, SSL_IS_CLIENT); \ + ssl_set_authmode(s, SSL_VERIFY_NONE); \ + ssl_set_rng(s, havege_rand, &ctx->hs); \ + ssl_set_ciphers(s, ssl_default_ciphers); \ + ssl_set_session(s, 1, 600, &ctx->ssn) +#define TLS_setfd(s, fd) ssl_set_bio(s, net_recv, &fd, net_send, &fd) +#define TLS_connect(s) ssl_handshake(s) +#define TLS_read(s, b, l) ssl_read(s, (unsigned char *)b, l) +#define TLS_write(s, b, l) ssl_write(s, (unsigned char *)b, l) +#define TLS_shutdown(s) ssl_close_notify(s) +#define TLS_close(s) \ + ssl_free(s); \ + free(s) + +#elif defined(USE_GNUTLS) +#include +typedef struct tls_ctx { + gnutls_certificate_credentials_t cred; + gnutls_priority_t prios; +} tls_ctx; +#define TLS_CTX tls_ctx * +#define TLS_client(ctx, s) \ + gnutls_init((gnutls_session_t *)(&s), GNUTLS_CLIENT); \ + gnutls_priority_set(s, ctx->prios); \ + gnutls_credentials_set(s, GNUTLS_CRD_CERTIFICATE, ctx->cred) +#define TLS_setfd(s, fd) \ + gnutls_transport_set_ptr(s, (gnutls_transport_ptr_t)(long)fd) +#define TLS_connect(s) gnutls_handshake(s) +#define TLS_read(s, b, l) gnutls_record_recv(s, b, l) +#define TLS_write(s, b, l) gnutls_record_send(s, b, l) +#define TLS_shutdown(s) gnutls_bye(s, GNUTLS_SHUT_RDWR) +#define TLS_close(s) gnutls_deinit(s) + +#else /* USE_OPENSSL */ +#define TLS_CTX SSL_CTX * +#define TLS_client(ctx, s) s = SSL_new(ctx) +#define TLS_setfd(s, fd) SSL_set_fd(s, fd) +#define TLS_connect(s) SSL_connect(s) +#define TLS_read(s, b, l) SSL_read(s, b, l) +#define TLS_write(s, b, l) SSL_write(s, b, l) +#define TLS_shutdown(s) SSL_shutdown(s) +#define TLS_close(s) SSL_free(s) + +#endif +#endif diff --git a/LFLiveKit/capture/LFAudioCapture.m b/LFLiveKit/capture/LFAudioCapture.m index 50f91bab..df32b488 100755 --- a/LFLiveKit/capture/LFAudioCapture.m +++ b/LFLiveKit/capture/LFAudioCapture.m @@ -46,8 +46,8 @@ - (instancetype)initWithAudioConfiguration:(LFLiveAudioConfiguration *)configura NSError *error = nil; [session setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; - - [session setMode:AVAudioSessionModeVideoRecording error:&error]; + + [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil]; if (![session setActive:YES error:&error]) { [self handleAudioComponentCreationFailure]; @@ -55,7 +55,7 @@ - (instancetype)initWithAudioConfiguration:(LFLiveAudioConfiguration *)configura AudioComponentDescription acd; acd.componentType = kAudioUnitType_Output; - acd.componentSubType = kAudioUnitSubType_RemoteIO; + acd.componentSubType = kAudioUnitSubType_VoiceProcessingIO; acd.componentManufacturer = kAudioUnitManufacturer_Apple; acd.componentFlags = 0; acd.componentFlagsMask = 0; @@ -124,6 +124,7 @@ - (void)setRunning:(BOOL)running { dispatch_async(self.taskQueue, ^{ self.isRunning = YES; NSLog(@"MicrophoneSource: startRunning"); + [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; AudioOutputUnitStart(self.componetInstance); }); } else { diff --git a/LFLiveKit/capture/LFVideoCapture.m b/LFLiveKit/capture/LFVideoCapture.m index 68970a9c..95ca4e52 100755 --- a/LFLiveKit/capture/LFVideoCapture.m +++ b/LFLiveKit/capture/LFVideoCapture.m @@ -33,22 +33,23 @@ @implementation LFVideoCapture - (instancetype)initWithVideoConfiguration:(LFLiveVideoConfiguration *)configuration { if (self = [super init]) { _configuration = configuration; + if([self pixelBufferImageSize].width < configuration.videoSize.width || [self pixelBufferImageSize].height < configuration.videoSize.height){ + @throw [NSException exceptionWithName:@"当前videoSize大小出错" reason:@"LFLiveVideoConfiguration videoSize error" userInfo:nil]; + return nil; + } + _videoCamera = [[GPUImageVideoCamera alloc] initWithSessionPreset:_configuration.avSessionPreset cameraPosition:AVCaptureDevicePositionFront]; UIInterfaceOrientation statusBar = [[UIApplication sharedApplication] statusBarOrientation]; if (configuration.landscape) { if (statusBar != UIInterfaceOrientationLandscapeLeft && statusBar != UIInterfaceOrientationLandscapeRight) { - NSLog(@"当前设置方向出错"); - NSLog(@"当前设置方向出错"); - NSLog(@"当前设置方向出错"); + @throw [NSException exceptionWithName:@"当前设置方向出错" reason:@"LFLiveVideoConfiguration landscape error" userInfo:nil]; _videoCamera.outputImageOrientation = UIInterfaceOrientationLandscapeLeft; } else { _videoCamera.outputImageOrientation = statusBar; } } else { if (statusBar != UIInterfaceOrientationPortrait && statusBar != UIInterfaceOrientationPortraitUpsideDown) { - NSLog(@"当前设置方向出错"); - NSLog(@"当前设置方向出错"); - NSLog(@"当前设置方向出错"); + @throw [NSException exceptionWithName:@"当前设置方向出错" reason:@"LFLiveVideoConfiguration landscape error" userInfo:nil]; _videoCamera.outputImageOrientation = UIInterfaceOrientationPortrait; } else { _videoCamera.outputImageOrientation = statusBar; @@ -203,7 +204,6 @@ - (CGFloat)zoomScale { } - (void)setBeautyFace:(BOOL)beautyFace { - if (_beautyFace == beautyFace) return; _beautyFace = beautyFace; [_filter removeAllTargets]; @@ -227,18 +227,18 @@ - (void)setBeautyFace:(BOOL)beautyFace { }]; } - if (_configuration.isClipVideo) { - if (_configuration.landscape) { - _cropfilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0.125, 0, 0.75, 1)]; - } else { - _cropfilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(0, 0.125, 1, 0.75)]; - } + CGSize imageSize = [self pixelBufferImageSize]; + CGFloat cropLeft = (imageSize.width - self.configuration.videoSize.width)/2.0/imageSize.width; + CGFloat cropTop = (imageSize.height - self.configuration.videoSize.height)/2.0/imageSize.height; + + if(cropLeft == 0 && cropTop == 0){ + [_videoCamera addTarget:_filter]; + }else{ + _cropfilter = [[GPUImageCropFilter alloc] initWithCropRegion:CGRectMake(cropLeft, cropTop, 1 - cropLeft*2, 1 - cropTop*2)]; [_videoCamera addTarget:_cropfilter]; [_cropfilter addTarget:_filter]; - } else { - [_videoCamera addTarget:_filter]; } - + if (_beautyFace) { [_filter addTarget:_output]; [_output addTarget:_gpuImageView]; @@ -300,4 +300,34 @@ - (void)statusBarChanged:(NSNotification *)notification { } } +#pragma mark -- +- (CGSize)pixelBufferImageSize{ + CGSize videoSize = CGSizeZero; + switch (self.configuration.sessionPreset) { + case LFCaptureSessionPreset360x640: + { + videoSize = CGSizeMake(480, 640); + } + break; + case LFCaptureSessionPreset540x960: + { + videoSize = CGSizeMake(540, 960); + } + break; + case LFCaptureSessionPreset720x1280: + { + videoSize = CGSizeMake(720, 1280); + } + break; + + default: + break; + } + + if(self.configuration.landscape){ + return CGSizeMake(videoSize.height, videoSize.width); + } + return videoSize; +} + @end diff --git a/LFLiveKit/coder/LFHardwareVideoEncoder.m b/LFLiveKit/coder/LFHardwareVideoEncoder.m index ac6c08a1..444e0af2 100755 --- a/LFLiveKit/coder/LFHardwareVideoEncoder.m +++ b/LFLiveKit/coder/LFHardwareVideoEncoder.m @@ -61,7 +61,7 @@ - (void)initCompressionSession { _currentVideoBitRate = _configuration.videoBitRate; VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_MaxKeyFrameInterval, (__bridge CFTypeRef)@(_configuration.videoMaxKeyframeInterval)); - VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration, (__bridge CFTypeRef)@(_configuration.videoMaxKeyframeInterval)); + VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration, (__bridge CFTypeRef)@(_configuration.videoMaxKeyframeInterval/_configuration.videoFrameRate)); VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_ExpectedFrameRate, (__bridge CFTypeRef)@(_configuration.videoFrameRate)); VTSessionSetProperty(compressionSession, kVTCompressionPropertyKey_AverageBitRate, (__bridge CFTypeRef)@(_configuration.videoBitRate)); NSArray *limit = @[@(_configuration.videoBitRate * 1.5/8), @(1)]; diff --git a/LFLiveKit/configuration/LFLiveVideoConfiguration.h b/LFLiveKit/configuration/LFLiveVideoConfiguration.h index b7d0e260..991e4ac6 100755 --- a/LFLiveKit/configuration/LFLiveVideoConfiguration.h +++ b/LFLiveKit/configuration/LFLiveVideoConfiguration.h @@ -90,7 +90,4 @@ typedef NS_ENUM (NSUInteger, LFLiveVideoQuality){ ///< ≈sde3分辨率 @property (nonatomic, assign, readonly) NSString *avSessionPreset; -///< 是否裁剪 -@property (nonatomic, assign, readonly) BOOL isClipVideo; - @end diff --git a/LFLiveKit/configuration/LFLiveVideoConfiguration.m b/LFLiveKit/configuration/LFLiveVideoConfiguration.m index c5406963..8e1db306 100755 --- a/LFLiveKit/configuration/LFLiveVideoConfiguration.m +++ b/LFLiveKit/configuration/LFLiveVideoConfiguration.m @@ -213,10 +213,6 @@ - (LFLiveVideoSessionPreset)supportSessionPreset:(LFLiveVideoSessionPreset)sessi return sessionPreset; } -- (BOOL)isClipVideo { - return self.sessionPreset == LFCaptureSessionPreset360x640 ? YES : NO; -} - #pragma mark -- encoder - (void)encodeWithCoder:(NSCoder *)aCoder { [aCoder encodeObject:[NSValue valueWithCGSize:self.videoSize] forKey:@"videoSize"]; @@ -248,7 +244,6 @@ - (NSUInteger)hash { @(self.videoBitRate), @(self.videoMaxBitRate), @(self.videoMinBitRate), - @(self.isClipVideo), self.avSessionPreset, @(self.sessionPreset), @(self.landscape), ]; @@ -274,7 +269,6 @@ - (BOOL)isEqual:(id)other { object.videoBitRate == self.videoBitRate && object.videoMaxBitRate == self.videoMaxBitRate && object.videoMinBitRate == self.videoMinBitRate && - object.isClipVideo == self.isClipVideo && [object.avSessionPreset isEqualToString:self.avSessionPreset] && object.sessionPreset == self.sessionPreset && object.landscape == self.landscape; @@ -297,7 +291,6 @@ - (NSString *)description { [desc appendFormat:@" videoBitRate:%zi", self.videoBitRate]; [desc appendFormat:@" videoMaxBitRate:%zi", self.videoMaxBitRate]; [desc appendFormat:@" videoMinBitRate:%zi", self.videoMinBitRate]; - [desc appendFormat:@" isClipVideo:%zi", self.isClipVideo]; [desc appendFormat:@" avSessionPreset:%@", self.avSessionPreset]; [desc appendFormat:@" sessionPreset:%zi", self.sessionPreset]; [desc appendFormat:@" landscape:%zi", self.landscape]; diff --git a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.pbxproj b/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.pbxproj index fff24717..f89b37ec 100644 --- a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.pbxproj +++ b/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 7ACB1193D70CF46C9676CB29 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5C04F65629D3881D5F25ADE1 /* libPods.a */; }; 81E848D8BD2C446C2DD4876A /* libPods-LFLiveKitDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6FD9F92833FE7856CDDD3CED /* libPods-LFLiveKitDemo.a */; }; B2D23E7F1D348F3D00B34CA8 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B2D23E7E1D348F3D00B34CA8 /* main.m */; }; B2D23E821D348F3D00B34CA8 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B2D23E811D348F3D00B34CA8 /* AppDelegate.m */; }; @@ -31,7 +30,6 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ - 5C04F65629D3881D5F25ADE1 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; 6FD9F92833FE7856CDDD3CED /* libPods-LFLiveKitDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LFLiveKitDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 8FAAEBE1A4F099C69588B394 /* Pods-LFLiveKitDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKitDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKitDemo/Pods-LFLiveKitDemo.release.xcconfig"; sourceTree = ""; }; AFD491825C5DB2AD871189B5 /* Pods-LFLiveKitDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKitDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKitDemo/Pods-LFLiveKitDemo.debug.xcconfig"; sourceTree = ""; }; @@ -69,7 +67,6 @@ buildActionMask = 2147483647; files = ( 81E848D8BD2C446C2DD4876A /* libPods-LFLiveKitDemo.a in Frameworks */, - 7ACB1193D70CF46C9676CB29 /* libPods.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -171,7 +168,6 @@ isa = PBXGroup; children = ( 6FD9F92833FE7856CDDD3CED /* libPods-LFLiveKitDemo.a */, - 5C04F65629D3881D5F25ADE1 /* libPods.a */, ); name = Frameworks; sourceTree = ""; @@ -183,11 +179,12 @@ isa = PBXNativeTarget; buildConfigurationList = B2D23E911D348F3D00B34CA8 /* Build configuration list for PBXNativeTarget "LFLiveKitDemo" */; buildPhases = ( - 6A9D2ED37E623D4A31A8D2C9 /* Check Pods Manifest.lock */, + 6A9D2ED37E623D4A31A8D2C9 /* 📦 Check Pods Manifest.lock */, B2D23E761D348F3D00B34CA8 /* Sources */, B2D23E771D348F3D00B34CA8 /* Frameworks */, B2D23E781D348F3D00B34CA8 /* Resources */, - 34EEB2C8F5E0D371D13B66CA /* Copy Pods Resources */, + 34EEB2C8F5E0D371D13B66CA /* 📦 Copy Pods Resources */, + 7336E9C92EDCA6C7449F2624 /* 📦 Embed Pods Frameworks */, ); buildRules = ( ); @@ -254,29 +251,29 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 34EEB2C8F5E0D371D13B66CA /* Copy Pods Resources */ = { + 34EEB2C8F5E0D371D13B66CA /* 📦 Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Copy Pods Resources"; + name = "📦 Copy Pods Resources"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LFLiveKitDemo/Pods-LFLiveKitDemo-resources.sh\"\n"; showEnvVarsInLog = 0; }; - 6A9D2ED37E623D4A31A8D2C9 /* Check Pods Manifest.lock */ = { + 6A9D2ED37E623D4A31A8D2C9 /* 📦 Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Check Pods Manifest.lock"; + name = "📦 Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; @@ -284,6 +281,21 @@ shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; + 7336E9C92EDCA6C7449F2624 /* 📦 Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "📦 Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LFLiveKitDemo/Pods-LFLiveKitDemo-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ diff --git a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/xcuserdata/a1.xcuserdatad/xcschemes/LFLiveKitDemo.xcscheme b/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/xcuserdata/a1.xcuserdatad/xcschemes/LFLiveKitDemo.xcscheme new file mode 100644 index 00000000..86a692b7 --- /dev/null +++ b/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/xcuserdata/a1.xcuserdatad/xcschemes/LFLiveKitDemo.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/xcuserdata/a1.xcuserdatad/xcschemes/xcschememanagement.plist b/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/xcuserdata/a1.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..68810366 --- /dev/null +++ b/LFLiveKitDemo/LFLiveKitDemo.xcodeproj/xcuserdata/a1.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + LFLiveKitDemo.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + B2D23E791D348F3D00B34CA8 + + primary + + + + + diff --git a/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/xcuserdata/a1.xcuserdatad/UserInterfaceState.xcuserstate b/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/xcuserdata/a1.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000..e20b6620 Binary files /dev/null and b/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/xcuserdata/a1.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate b/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate index 59e059bc..7ec83d5e 100644 Binary files a/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate and b/LFLiveKitDemo/LFLiveKitDemo.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/LFLiveKitDemo/LFLiveKitDemo/Icon.png b/LFLiveKitDemo/LFLiveKitDemo/Icon.png new file mode 100644 index 00000000..2fe52d75 Binary files /dev/null and b/LFLiveKitDemo/LFLiveKitDemo/Icon.png differ diff --git a/LFLiveKitDemo/Podfile b/LFLiveKitDemo/Podfile index d1c9b6da..4ee1693d 100755 --- a/LFLiveKitDemo/Podfile +++ b/LFLiveKitDemo/Podfile @@ -2,7 +2,6 @@ source 'https://github.com/CocoaPods/Specs.git' platform :ios,'7.0' target 'LFLiveKitDemo' do - +pod 'LFLiveKit', path: '../' end -pod 'LFLiveKit', path: '../' \ No newline at end of file diff --git a/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj b/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj index 3ec30eb6..627df507 100644 --- a/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj +++ b/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 768D63AD7BD5B7D2959CC88D /* libPods-LFLiveKitSwiftDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 051291DCF26E653942D6929D /* libPods-LFLiveKitSwiftDemo.a */; }; B289F1BE1D3DCD3000D9C7A5 /* camra_beauty@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B289F1B61D3DCD3000D9C7A5 /* camra_beauty@2x.png */; }; B289F1BF1D3DCD3000D9C7A5 /* camra_beauty@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = B289F1B71D3DCD3000D9C7A5 /* camra_beauty@3x.png */; }; B289F1C01D3DCD3000D9C7A5 /* camra_beauty_close@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B289F1B81D3DCD3000D9C7A5 /* camra_beauty_close@2x.png */; }; @@ -20,10 +21,12 @@ B2C8FACA1D3DB8B3008D44B5 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B2C8FAC81D3DB8B3008D44B5 /* Main.storyboard */; }; B2C8FACC1D3DB8B3008D44B5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B2C8FACB1D3DB8B3008D44B5 /* Assets.xcassets */; }; B2C8FACF1D3DB8B4008D44B5 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B2C8FACD1D3DB8B4008D44B5 /* LaunchScreen.storyboard */; }; - D76381970CDF6883DA800952 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C703895C713844AE5F37BC53 /* libPods.a */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 051291DCF26E653942D6929D /* libPods-LFLiveKitSwiftDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-LFLiveKitSwiftDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 19A8327F404723C1C4B67B2C /* Pods-LFLiveKitSwiftDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKitSwiftDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo.release.xcconfig"; sourceTree = ""; }; + B16B5A0921F8F93D139F7961 /* Pods-LFLiveKitSwiftDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LFLiveKitSwiftDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo.debug.xcconfig"; sourceTree = ""; }; B289F1B61D3DCD3000D9C7A5 /* camra_beauty@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty@2x.png"; sourceTree = ""; }; B289F1B71D3DCD3000D9C7A5 /* camra_beauty@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty@3x.png"; sourceTree = ""; }; B289F1B81D3DCD3000D9C7A5 /* camra_beauty_close@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "camra_beauty_close@2x.png"; sourceTree = ""; }; @@ -40,9 +43,6 @@ B2C8FACE1D3DB8B4008D44B5 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; B2C8FAD01D3DB8B4008D44B5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; B2C8FAD61D3DB9D6008D44B5 /* LFLiveKitSwiftDemo-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LFLiveKitSwiftDemo-Bridging-Header.h"; sourceTree = ""; }; - C5E86117C8AB61338C12909E /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; - C703895C713844AE5F37BC53 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; - FD5AE5787FDCE4BA8C28E2EE /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -50,7 +50,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - D76381970CDF6883DA800952 /* libPods.a in Frameworks */, + 768D63AD7BD5B7D2959CC88D /* libPods-LFLiveKitSwiftDemo.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -60,8 +60,8 @@ 0044BAB3BCE83EE63FB6F37C /* Pods */ = { isa = PBXGroup; children = ( - FD5AE5787FDCE4BA8C28E2EE /* Pods.debug.xcconfig */, - C5E86117C8AB61338C12909E /* Pods.release.xcconfig */, + B16B5A0921F8F93D139F7961 /* Pods-LFLiveKitSwiftDemo.debug.xcconfig */, + 19A8327F404723C1C4B67B2C /* Pods-LFLiveKitSwiftDemo.release.xcconfig */, ); name = Pods; sourceTree = ""; @@ -69,7 +69,7 @@ 656DB83DA3620FA72C6B7CF7 /* Frameworks */ = { isa = PBXGroup; children = ( - C703895C713844AE5F37BC53 /* libPods.a */, + 051291DCF26E653942D6929D /* libPods-LFLiveKitSwiftDemo.a */, ); name = Frameworks; sourceTree = ""; @@ -129,11 +129,12 @@ isa = PBXNativeTarget; buildConfigurationList = B2C8FAD31D3DB8B4008D44B5 /* Build configuration list for PBXNativeTarget "LFLiveKitSwiftDemo" */; buildPhases = ( - BAC96C6840291F2B616FE902 /* Check Pods Manifest.lock */, + BAC96C6840291F2B616FE902 /* 📦 Check Pods Manifest.lock */, B2C8FABD1D3DB8B3008D44B5 /* Sources */, B2C8FABE1D3DB8B3008D44B5 /* Frameworks */, B2C8FABF1D3DB8B3008D44B5 /* Resources */, - 7490D167BE18C3C7DC2FE381 /* Copy Pods Resources */, + 7490D167BE18C3C7DC2FE381 /* 📦 Copy Pods Resources */, + 5683F74F0FF045A7193DAAD0 /* 📦 Embed Pods Frameworks */, ); buildRules = ( ); @@ -199,29 +200,44 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 7490D167BE18C3C7DC2FE381 /* Copy Pods Resources */ = { + 5683F74F0FF045A7193DAAD0 /* 📦 Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Copy Pods Resources"; + name = "📦 Embed Pods Frameworks"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods/Pods-resources.sh\"\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; - BAC96C6840291F2B616FE902 /* Check Pods Manifest.lock */ = { + 7490D167BE18C3C7DC2FE381 /* 📦 Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "Check Pods Manifest.lock"; + name = "📦 Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-LFLiveKitSwiftDemo/Pods-LFLiveKitSwiftDemo-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; + BAC96C6840291F2B616FE902 /* 📦 Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "📦 Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; @@ -348,7 +364,7 @@ }; B2C8FAD41D3DB8B4008D44B5 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = FD5AE5787FDCE4BA8C28E2EE /* Pods.debug.xcconfig */; + baseConfigurationReference = B16B5A0921F8F93D139F7961 /* Pods-LFLiveKitSwiftDemo.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; @@ -364,7 +380,7 @@ }; B2C8FAD51D3DB8B4008D44B5 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = C5E86117C8AB61338C12909E /* Pods.release.xcconfig */; + baseConfigurationReference = 19A8327F404723C1C4B67B2C /* Pods-LFLiveKitSwiftDemo.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; diff --git a/LFLiveKitSwiftDemo/Podfile b/LFLiveKitSwiftDemo/Podfile index cf2bcce5..0602d100 100755 --- a/LFLiveKitSwiftDemo/Podfile +++ b/LFLiveKitSwiftDemo/Podfile @@ -1,4 +1,6 @@ source 'https://github.com/CocoaPods/Specs.git' platform :ios,'7.0' -pod 'LFLiveKit', path: '../' \ No newline at end of file +target 'LFLiveKitSwiftDemo' do +pod 'LFLiveKit', path: '../' +end diff --git a/Podfile b/Podfile deleted file mode 100755 index e315c172..00000000 --- a/Podfile +++ /dev/null @@ -1,10 +0,0 @@ -source 'https://github.com/CocoaPods/Specs.git' -platform :ios,'7.0' - -target 'LFLiveKit' do - -end - -pod 'pili-librtmp', '~> 1.0.3' -pod 'LMGPUImage', '~> 0.1.9' - diff --git a/README.md b/README.md index b541aa91..eb44d8ce 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,14 @@ +LFLiveKit +============== +![icon~](https://raw.github.com/LaiFengiOS/LFLiveKit/master/LFLiveKitDemo/LFLiveKitDemo/Icon.png) + [![Build Status](https://travis-ci.org/LaiFengiOS/LFLiveKit.svg)](https://travis-ci.org/LaiFengiOS/LFLiveKit)  [![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/chenliming777/LFLiveKit/master/LICENSE)  [![CocoaPods](http://img.shields.io/cocoapods/v/LFLiveKit.svg?style=flat)](http://cocoapods.org/?q=LFLiveKit)  -[![Support](https://img.shields.io/badge/support-ios8%2B-orange.svg)](https://www.apple.com/nl/ios/)  +[![Support](https://img.shields.io/badge/ios-7-orange.svg)](https://www.apple.com/nl/ios/)  ![platform](https://img.shields.io/badge/platform-ios-ff69b4.svg)  -## LFLiveKit **LFLiveKit is a opensource RTMP streaming SDK for iOS.** @@ -26,6 +29,9 @@ - [x] Swift Support - [ ] ~~FLV package and send~~ +## Requirements + - iOS 7.0+ + - Xcode 7.3 ## Installation @@ -33,80 +39,96 @@ # To integrate LFLiveKit into your Xcode project using CocoaPods, specify it in your Podfile: source 'https://github.com/CocoaPods/Specs.git' - platform :ios, '8.0' + platform :ios, '7.0' pod 'LFLiveKit' # Then, run the following command: $ pod install -## Architecture: +#### Carthage + 1. Add `github "LaiFengiOS/LFLiveKit"` to your Cartfile. + 2. Run `carthage update --platform ios` and add the framework to your project. + 3. Import \. + + +#### Manually - capture: LFAudioCapture and LFVideoCapture - encode: LFHardwareAudioEncoder and LFHardwareVideoEncoder - publish: LFStreamRtmpSocket + 1. Download all the files in the `LFLiveKit` subdirectory. + 2. Add the source files to your Xcode project. + 3. Link with required frameworks: + * UIKit + * Foundation + * AVFoundation + * VideoToolbox + * AudioToolbox + * libz -## Usage: +## Usage example + #### Objective-C -``` -- (LFLiveSession*)session { - if (!_session) { - _session = [[LFLiveSession alloc] initWithAudioConfiguration:[LFLiveAudioConfiguration defaultConfiguration] videoConfiguration:[LFLiveVideoConfiguration defaultConfiguration]]; - _session.preView = self; - _session.delegate = self; + + - (LFLiveSession*)session { + if (!_session) { + _session = [[LFLiveSession alloc] initWithAudioConfiguration:[LFLiveAudioConfiguration defaultConfiguration] videoConfiguration:[LFLiveVideoConfiguration defaultConfiguration]]; + _session.preView = self; + _session.delegate = self; + } + return _session; } - return _session; -} - -- (void)startLive { - LFLiveStreamInfo *streamInfo = [LFLiveStreamInfo new]; - streamInfo.url = @"your server rtmp url"; - [self.session startLive:streamInfo]; -} - -- (void)stopLive { - [self.session stopLive]; -} - -//MARK: - CallBack: -- (void)liveSession:(nullable LFLiveSession *)session liveStateDidChange: (LFLiveState)state; -- (void)liveSession:(nullable LFLiveSession *)session debugInfo:(nullable LFLiveDebug*)debugInfo; -- (void)liveSession:(nullable LFLiveSession*)session errorCode:(LFLiveSocketErrorCode)errorCode; - -``` + + - (void)startLive { + LFLiveStreamInfo *streamInfo = [LFLiveStreamInfo new]; + streamInfo.url = @"your server rtmp url"; + [self.session startLive:streamInfo]; + } + + - (void)stopLive { + [self.session stopLive]; + } + + //MARK: - CallBack: + - (void)liveSession:(nullable LFLiveSession *)session liveStateDidChange: (LFLiveState)state; + - (void)liveSession:(nullable LFLiveSession *)session debugInfo:(nullable LFLiveDebug*)debugInfo; + - (void)liveSession:(nullable LFLiveSession*)session errorCode:(LFLiveSocketErrorCode)errorCode; + #### Swift -``` -// import LFLiveKit in [ProjectName]-Bridging-Header.h -import + // import LFLiveKit in [ProjectName]-Bridging-Header.h + import + + //MARK: - Getters and Setters + lazy var session: LFLiveSession = { + let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration() + let videoConfiguration = LFLiveVideoConfiguration.defaultConfigurationForQuality(LFLiveVideoQuality.Low3, landscape: false) + let session = LFLiveSession(audioConfiguration: audioConfiguration, videoConfiguration: videoConfiguration) + + session?.delegate = self + session?.preView = self.view + return session! + }() + + //MARK: - Event + func startLive() -> Void { + let stream = LFLiveStreamInfo() + stream.url = "your server rtmp url"; + session.startLive(stream) + } + + func stopLive() -> Void { + session.stopLive() + } + + //MARK: - Callback + func liveSession(session: LFLiveSession?, debugInfo: LFLiveDebug?) + func liveSession(session: LFLiveSession?, errorCode: LFLiveSocketErrorCode) + func liveSession(session: LFLiveSession?, liveStateDidChange state: LFLiveState) + + +## Release History + * 2.0.0 + * CHANGE: modify bugs,support ios7 live. -//MARK: - Getters and Setters -lazy var session: LFLiveSession = { - let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration() - let videoConfiguration = LFLiveVideoConfiguration.defaultConfigurationForQuality(LFLiveVideoQuality.Low3, landscape: false) - let session = LFLiveSession(audioConfiguration: audioConfiguration, videoConfiguration: videoConfiguration) - - session?.delegate = self - session?.preView = self.view - return session! -}() - -//MARK: - Event -func startLive() -> Void { - let stream = LFLiveStreamInfo() - stream.url = "your server rtmp url"; - session.startLive(stream) -} - -func stopLive() -> Void { - session.stopLive() -} - -//MARK: - Callback -func liveSession(session: LFLiveSession?, debugInfo: LFLiveDebug?) -func liveSession(session: LFLiveSession?, errorCode: LFLiveSocketErrorCode) -func liveSession(session: LFLiveSession?, liveStateDidChange state: LFLiveState) -``` ## License **LFLiveKit is released under the MIT license. See LICENSE for details.**